Fossil

Hex Artifact Content
Login

Artifact 183cf5e5ad2ae111ce018f3f33f79e4640a26c4280e556e19371c3c1b06164e1:


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 36 20 44 2e 20 52 69 63 68  (c) 2006 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 53 69 6d 70 6c 69 66 69 65 64 20 42 53 44 20   Simplified BSD 
00a0: 4c 69 63 65 6e 73 65 20 28 61 6c 73 6f 0a 2a 2a  License (also.**
00b0: 20 6b 6e 6f 77 6e 20 61 73 20 74 68 65 20 22 32   known as the "2
00c0: 2d 43 6c 61 75 73 65 20 4c 69 63 65 6e 73 65 22  -Clause License"
00d0: 20 6f 72 20 22 46 72 65 65 42 53 44 20 4c 69 63   or "FreeBSD Lic
00e0: 65 6e 73 65 22 2e 29 0a 2a 2a 0a 2a 2a 20 54 68  ense".).**.** Th
00f0: 69 73 20 70 72 6f 67 72 61 6d 20 69 73 20 64 69  is program is di
0100: 73 74 72 69 62 75 74 65 64 20 69 6e 20 74 68 65  stributed in the
0110: 20 68 6f 70 65 20 74 68 61 74 20 69 74 20 77 69   hope that it wi
0120: 6c 6c 20 62 65 20 75 73 65 66 75 6c 2c 0a 2a 2a  ll be useful,.**
0130: 20 62 75 74 20 77 69 74 68 6f 75 74 20 61 6e 79   but without any
0140: 20 77 61 72 72 61 6e 74 79 3b 20 77 69 74 68 6f   warranty; witho
0150: 75 74 20 65 76 65 6e 20 74 68 65 20 69 6d 70 6c  ut even the impl
0160: 69 65 64 20 77 61 72 72 61 6e 74 79 20 6f 66 0a  ied warranty of.
0170: 2a 2a 20 6d 65 72 63 68 61 6e 74 61 62 69 6c 69  ** merchantabili
0180: 74 79 20 6f 72 20 66 69 74 6e 65 73 73 20 66 6f  ty or fitness fo
0190: 72 20 61 20 70 61 72 74 69 63 75 6c 61 72 20 70  r a particular p
01a0: 75 72 70 6f 73 65 2e 0a 2a 2a 0a 2a 2a 20 41 75  urpose..**.** Au
01b0: 74 68 6f 72 20 63 6f 6e 74 61 63 74 20 69 6e 66  thor contact inf
01c0: 6f 72 6d 61 74 69 6f 6e 3a 0a 2a 2a 20 20 20 64  ormation:.**   d
01d0: 72 68 40 68 77 61 63 69 2e 63 6f 6d 0a 2a 2a 20  rh@hwaci.com.** 
01e0: 20 20 68 74 74 70 3a 2f 2f 77 77 77 2e 68 77 61    http://www.hwa
01f0: 63 69 2e 63 6f 6d 2f 64 72 68 2f 0a 2a 2a 0a 2a  ci.com/drh/.**.*
0200: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a  ****************
0210: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a  ****************
0220: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a  ****************
0230: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a  ****************
0240: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 0a 2a  **************.*
0250: 2a 0a 2a 2a 20 54 68 69 73 20 6d 6f 64 75 6c 65  *.** This module
0260: 20 63 6f 64 65 73 20 74 68 65 20 6d 61 69 6e 28   codes the main(
0270: 29 20 70 72 6f 63 65 64 75 72 65 20 74 68 61 74  ) procedure that
0280: 20 72 75 6e 73 20 66 69 72 73 74 20 77 68 65 6e   runs first when
0290: 20 74 68 65 0a 2a 2a 20 70 72 6f 67 72 61 6d 20   the.** program 
02a0: 69 73 20 69 6e 76 6f 6b 65 64 2e 0a 2a 2f 0a 23  is invoked..*/.#
02b0: 69 6e 63 6c 75 64 65 20 22 56 45 52 53 49 4f 4e  include "VERSION
02c0: 2e 68 22 0a 23 69 6e 63 6c 75 64 65 20 22 63 6f  .h".#include "co
02d0: 6e 66 69 67 2e 68 22 0a 23 69 66 20 64 65 66 69  nfig.h".#if defi
02e0: 6e 65 64 28 5f 57 49 4e 33 32 29 0a 23 20 20 69  ned(_WIN32).#  i
02f0: 6e 63 6c 75 64 65 20 3c 77 69 6e 64 6f 77 73 2e  nclude <windows.
0300: 68 3e 0a 23 20 20 69 6e 63 6c 75 64 65 20 3c 69  h>.#  include <i
0310: 6f 2e 68 3e 0a 23 20 20 64 65 66 69 6e 65 20 69  o.h>.#  define i
0320: 73 61 74 74 79 28 68 29 20 5f 69 73 61 74 74 79  satty(h) _isatty
0330: 28 68 29 0a 23 20 20 64 65 66 69 6e 65 20 47 45  (h).#  define GE
0340: 54 50 49 44 20 28 69 6e 74 29 47 65 74 43 75 72  TPID (int)GetCur
0350: 72 65 6e 74 50 72 6f 63 65 73 73 49 64 0a 23 65  rentProcessId.#e
0360: 6e 64 69 66 0a 23 69 6e 63 6c 75 64 65 20 22 6d  ndif.#include "m
0370: 61 69 6e 2e 68 22 0a 23 69 6e 63 6c 75 64 65 20  ain.h".#include 
0380: 3c 73 74 72 69 6e 67 2e 68 3e 0a 23 69 6e 63 6c  <string.h>.#incl
0390: 75 64 65 20 3c 74 69 6d 65 2e 68 3e 0a 23 69 6e  ude <time.h>.#in
03a0: 63 6c 75 64 65 20 3c 66 63 6e 74 6c 2e 68 3e 0a  clude <fcntl.h>.
03b0: 23 69 6e 63 6c 75 64 65 20 3c 73 79 73 2f 74 79  #include <sys/ty
03c0: 70 65 73 2e 68 3e 0a 23 69 6e 63 6c 75 64 65 20  pes.h>.#include 
03d0: 3c 73 79 73 2f 73 74 61 74 2e 68 3e 0a 23 69 6e  <sys/stat.h>.#in
03e0: 63 6c 75 64 65 20 3c 73 74 64 6c 69 62 2e 68 3e  clude <stdlib.h>
03f0: 20 2f 2a 20 61 74 65 78 69 74 28 29 20 2a 2f 0a   /* atexit() */.
0400: 23 69 66 20 21 64 65 66 69 6e 65 64 28 5f 57 49  #if !defined(_WI
0410: 4e 33 32 29 0a 23 20 20 69 6e 63 6c 75 64 65 20  N32).#  include 
0420: 3c 65 72 72 6e 6f 2e 68 3e 20 2f 2a 20 65 72 72  <errno.h> /* err
0430: 6e 6f 20 67 6c 6f 62 61 6c 20 2a 2f 0a 23 20 20  no global */.#  
0440: 69 6e 63 6c 75 64 65 20 3c 75 6e 69 73 74 64 2e  include <unistd.
0450: 68 3e 0a 23 20 20 69 6e 63 6c 75 64 65 20 3c 73  h>.#  include <s
0460: 69 67 6e 61 6c 2e 68 3e 0a 23 20 20 64 65 66 69  ignal.h>.#  defi
0470: 6e 65 20 47 45 54 50 49 44 20 67 65 74 70 69 64  ne GETPID getpid
0480: 0a 23 65 6e 64 69 66 0a 23 69 66 64 65 66 20 46  .#endif.#ifdef F
0490: 4f 53 53 49 4c 5f 45 4e 41 42 4c 45 5f 53 53 4c  OSSIL_ENABLE_SSL
04a0: 0a 23 20 20 69 6e 63 6c 75 64 65 20 22 6f 70 65  .#  include "ope
04b0: 6e 73 73 6c 2f 63 72 79 70 74 6f 2e 68 22 0a 23  nssl/crypto.h".#
04c0: 65 6e 64 69 66 0a 23 69 66 20 64 65 66 69 6e 65  endif.#if define
04d0: 64 28 46 4f 53 53 49 4c 5f 45 4e 41 42 4c 45 5f  d(FOSSIL_ENABLE_
04e0: 4d 49 4e 49 5a 29 0a 23 20 20 64 65 66 69 6e 65  MINIZ).#  define
04f0: 20 4d 49 4e 49 5a 5f 48 45 41 44 45 52 5f 46 49   MINIZ_HEADER_FI
0500: 4c 45 5f 4f 4e 4c 59 0a 23 20 20 69 6e 63 6c 75  LE_ONLY.#  inclu
0510: 64 65 20 22 6d 69 6e 69 7a 2e 63 22 0a 23 65 6c  de "miniz.c".#el
0520: 73 65 0a 23 20 20 69 6e 63 6c 75 64 65 20 3c 7a  se.#  include <z
0530: 6c 69 62 2e 68 3e 0a 23 65 6e 64 69 66 0a 23 69  lib.h>.#endif.#i
0540: 66 20 49 4e 54 45 52 46 41 43 45 0a 23 69 66 64  f INTERFACE.#ifd
0550: 65 66 20 46 4f 53 53 49 4c 5f 45 4e 41 42 4c 45  ef FOSSIL_ENABLE
0560: 5f 54 43 4c 0a 23 20 20 69 6e 63 6c 75 64 65 20  _TCL.#  include 
0570: 22 74 63 6c 2e 68 22 0a 23 65 6e 64 69 66 0a 23  "tcl.h".#endif.#
0580: 69 66 64 65 66 20 46 4f 53 53 49 4c 5f 45 4e 41  ifdef FOSSIL_ENA
0590: 42 4c 45 5f 4a 53 4f 4e 0a 23 20 20 69 6e 63 6c  BLE_JSON.#  incl
05a0: 75 64 65 20 22 63 73 6f 6e 5f 61 6d 61 6c 67 61  ude "cson_amalga
05b0: 6d 61 74 69 6f 6e 2e 68 22 20 2f 2a 20 4a 53 4f  mation.h" /* JSO
05c0: 4e 20 41 50 49 2e 20 2a 2f 0a 23 20 20 69 6e 63  N API. */.#  inc
05d0: 6c 75 64 65 20 22 6a 73 6f 6e 5f 64 65 74 61 69  lude "json_detai
05e0: 6c 2e 68 22 0a 23 65 6e 64 69 66 0a 23 69 66 64  l.h".#endif.#ifd
05f0: 65 66 20 48 41 56 45 5f 42 41 43 4b 54 52 41 43  ef HAVE_BACKTRAC
0600: 45 0a 23 20 69 6e 63 6c 75 64 65 20 3c 65 78 65  E.# include <exe
0610: 63 69 6e 66 6f 2e 68 3e 0a 23 65 6e 64 69 66 0a  cinfo.h>.#endif.
0620: 0a 2f 2a 0a 2a 2a 20 4d 61 78 69 6d 75 6d 20 6e  ./*.** Maximum n
0630: 75 6d 62 65 72 20 6f 66 20 61 75 78 69 6c 69 61  umber of auxilia
0640: 72 79 20 70 61 72 61 6d 65 74 65 72 73 20 6f 6e  ry parameters on
0650: 20 72 65 70 6f 72 74 73 0a 2a 2f 0a 23 64 65 66   reports.*/.#def
0660: 69 6e 65 20 4d 58 5f 41 55 58 20 20 35 0a 0a 2f  ine MX_AUX  5../
0670: 2a 0a 2a 2a 20 48 6f 6c 64 73 20 66 6c 61 67 73  *.** Holds flags
0680: 20 66 6f 72 20 66 6f 73 73 69 6c 20 75 73 65 72   for fossil user
0690: 20 70 65 72 6d 69 73 73 69 6f 6e 73 2e 0a 2a 2f   permissions..*/
06a0: 0a 73 74 72 75 63 74 20 46 6f 73 73 69 6c 55 73  .struct FossilUs
06b0: 65 72 50 65 72 6d 73 20 7b 0a 20 20 63 68 61 72  erPerms {.  char
06c0: 20 53 65 74 75 70 3b 20 20 20 20 20 20 20 20 20   Setup;         
06d0: 20 20 20 2f 2a 20 73 3a 20 75 73 65 20 53 65 74     /* s: use Set
06e0: 75 70 20 73 63 72 65 65 6e 73 20 6f 6e 20 77 65  up screens on we
06f0: 62 20 69 6e 74 65 72 66 61 63 65 20 2a 2f 0a 20  b interface */. 
0700: 20 63 68 61 72 20 41 64 6d 69 6e 3b 20 20 20 20   char Admin;    
0710: 20 20 20 20 20 20 20 20 2f 2a 20 61 3a 20 61 64          /* a: ad
0720: 6d 69 6e 69 73 74 72 61 74 69 76 65 20 70 65 72  ministrative per
0730: 6d 69 73 73 69 6f 6e 20 2a 2f 0a 20 20 63 68 61  mission */.  cha
0740: 72 20 44 65 6c 65 74 65 3b 20 20 20 20 20 20 20  r Delete;       
0750: 20 20 20 20 2f 2a 20 64 3a 20 64 65 6c 65 74 65      /* d: delete
0760: 20 77 69 6b 69 20 6f 72 20 74 69 63 6b 65 74 73   wiki or tickets
0770: 20 2a 2f 0a 20 20 63 68 61 72 20 50 61 73 73 77   */.  char Passw
0780: 6f 72 64 3b 20 20 20 20 20 20 20 20 20 2f 2a 20  ord;         /* 
0790: 70 3a 20 63 68 61 6e 67 65 20 70 61 73 73 77 6f  p: change passwo
07a0: 72 64 20 2a 2f 0a 20 20 63 68 61 72 20 51 75 65  rd */.  char Que
07b0: 72 79 3b 20 20 20 20 20 20 20 20 20 20 20 20 2f  ry;            /
07c0: 2a 20 71 3a 20 63 72 65 61 74 65 20 6e 65 77 20  * q: create new 
07d0: 72 65 70 6f 72 74 73 20 2a 2f 0a 20 20 63 68 61  reports */.  cha
07e0: 72 20 57 72 69 74 65 3b 20 20 20 20 20 20 20 20  r Write;        
07f0: 20 20 20 20 2f 2a 20 69 3a 20 78 66 65 72 20 69      /* i: xfer i
0800: 6e 62 6f 75 6e 64 2e 20 63 68 65 63 6b 2d 69 6e  nbound. check-in
0810: 20 2a 2f 0a 20 20 63 68 61 72 20 52 65 61 64 3b   */.  char Read;
0820: 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20               /* 
0830: 6f 3a 20 78 66 65 72 20 6f 75 74 62 6f 75 6e 64  o: xfer outbound
0840: 2e 20 63 68 65 63 6b 2d 6f 75 74 20 2a 2f 0a 20  . check-out */. 
0850: 20 63 68 61 72 20 48 79 70 65 72 6c 69 6e 6b 3b   char Hyperlink;
0860: 20 20 20 20 20 20 20 20 2f 2a 20 68 3a 20 65 6e          /* h: en
0870: 61 62 6c 65 20 74 68 65 20 64 69 73 70 6c 61 79  able the display
0880: 20 6f 66 20 68 79 70 65 72 6c 69 6e 6b 73 20 2a   of hyperlinks *
0890: 2f 0a 20 20 63 68 61 72 20 43 6c 6f 6e 65 3b 20  /.  char Clone; 
08a0: 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 67 3a             /* g:
08b0: 20 63 6c 6f 6e 65 20 2a 2f 0a 20 20 63 68 61 72   clone */.  char
08c0: 20 52 64 57 69 6b 69 3b 20 20 20 20 20 20 20 20   RdWiki;        
08d0: 20 20 20 2f 2a 20 6a 3a 20 76 69 65 77 20 77 69     /* j: view wi
08e0: 6b 69 20 76 69 61 20 77 65 62 20 2a 2f 0a 20 20  ki via web */.  
08f0: 63 68 61 72 20 4e 65 77 57 69 6b 69 3b 20 20 20  char NewWiki;   
0900: 20 20 20 20 20 20 20 2f 2a 20 66 3a 20 63 72 65         /* f: cre
0910: 61 74 65 20 6e 65 77 20 77 69 6b 69 20 76 69 61  ate new wiki via
0920: 20 77 65 62 20 2a 2f 0a 20 20 63 68 61 72 20 41   web */.  char A
0930: 70 6e 64 57 69 6b 69 3b 20 20 20 20 20 20 20 20  pndWiki;        
0940: 20 2f 2a 20 6d 3a 20 61 70 70 65 6e 64 20 74 6f   /* m: append to
0950: 20 77 69 6b 69 20 76 69 61 20 77 65 62 20 2a 2f   wiki via web */
0960: 0a 20 20 63 68 61 72 20 57 72 57 69 6b 69 3b 20  .  char WrWiki; 
0970: 20 20 20 20 20 20 20 20 20 20 2f 2a 20 6b 3a 20            /* k: 
0980: 65 64 69 74 20 77 69 6b 69 20 76 69 61 20 77 65  edit wiki via we
0990: 62 20 2a 2f 0a 20 20 63 68 61 72 20 4d 6f 64 57  b */.  char ModW
09a0: 69 6b 69 3b 20 20 20 20 20 20 20 20 20 20 2f 2a  iki;          /*
09b0: 20 6c 3a 20 61 70 70 72 6f 76 65 20 61 6e 64 20   l: approve and 
09c0: 70 75 62 6c 69 73 68 20 77 69 6b 69 20 63 6f 6e  publish wiki con
09d0: 74 65 6e 74 20 28 4d 6f 64 65 72 61 74 6f 72 29  tent (Moderator)
09e0: 20 2a 2f 0a 20 20 63 68 61 72 20 52 64 54 6b 74   */.  char RdTkt
09f0: 3b 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20  ;            /* 
0a00: 72 3a 20 76 69 65 77 20 74 69 63 6b 65 74 73 20  r: view tickets 
0a10: 76 69 61 20 77 65 62 20 2a 2f 0a 20 20 63 68 61  via web */.  cha
0a20: 72 20 4e 65 77 54 6b 74 3b 20 20 20 20 20 20 20  r NewTkt;       
0a30: 20 20 20 20 2f 2a 20 6e 3a 20 63 72 65 61 74 65      /* n: create
0a40: 20 6e 65 77 20 74 69 63 6b 65 74 73 20 2a 2f 0a   new tickets */.
0a50: 20 20 63 68 61 72 20 41 70 6e 64 54 6b 74 3b 20    char ApndTkt; 
0a60: 20 20 20 20 20 20 20 20 20 2f 2a 20 63 3a 20 61           /* c: a
0a70: 70 70 65 6e 64 20 74 6f 20 74 69 63 6b 65 74 73  ppend to tickets
0a80: 20 76 69 61 20 74 68 65 20 77 65 62 20 2a 2f 0a   via the web */.
0a90: 20 20 63 68 61 72 20 57 72 54 6b 74 3b 20 20 20    char WrTkt;   
0aa0: 20 20 20 20 20 20 20 20 20 2f 2a 20 77 3a 20 6d           /* w: m
0ab0: 61 6b 65 20 63 68 61 6e 67 65 73 20 74 6f 20 74  ake changes to t
0ac0: 69 63 6b 65 74 73 20 76 69 61 20 77 65 62 20 2a  ickets via web *
0ad0: 2f 0a 20 20 63 68 61 72 20 4d 6f 64 54 6b 74 3b  /.  char ModTkt;
0ae0: 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 71 3a             /* q:
0af0: 20 61 70 70 72 6f 76 65 20 61 6e 64 20 70 75 62   approve and pub
0b00: 6c 69 73 68 20 74 69 63 6b 65 74 20 63 68 61 6e  lish ticket chan
0b10: 67 65 73 20 28 4d 6f 64 65 72 61 74 6f 72 29 20  ges (Moderator) 
0b20: 2a 2f 0a 20 20 63 68 61 72 20 41 74 74 61 63 68  */.  char Attach
0b30: 3b 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 62  ;           /* b
0b40: 3a 20 61 64 64 20 61 74 74 61 63 68 6d 65 6e 74  : add attachment
0b50: 73 20 2a 2f 0a 20 20 63 68 61 72 20 54 6b 74 46  s */.  char TktF
0b60: 6d 74 3b 20 20 20 20 20 20 20 20 20 20 20 2f 2a  mt;           /*
0b70: 20 74 3a 20 63 72 65 61 74 65 20 6e 65 77 20 74   t: create new t
0b80: 69 63 6b 65 74 20 72 65 70 6f 72 74 20 66 6f 72  icket report for
0b90: 6d 61 74 73 20 2a 2f 0a 20 20 63 68 61 72 20 52  mats */.  char R
0ba0: 64 41 64 64 72 3b 20 20 20 20 20 20 20 20 20 20  dAddr;          
0bb0: 20 2f 2a 20 65 3a 20 72 65 61 64 20 65 6d 61 69   /* e: read emai
0bc0: 6c 20 61 64 64 72 65 73 73 65 73 20 6f 72 20 6f  l addresses or o
0bd0: 74 68 65 72 20 70 72 69 76 61 74 65 20 64 61 74  ther private dat
0be0: 61 20 2a 2f 0a 20 20 63 68 61 72 20 5a 69 70 3b  a */.  char Zip;
0bf0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a                /*
0c00: 20 7a 3a 20 64 6f 77 6e 6c 6f 61 64 20 7a 69 70   z: download zip
0c10: 70 65 64 20 61 72 74 69 66 61 63 74 20 76 69 61  ped artifact via
0c20: 20 2f 7a 69 70 20 55 52 4c 20 2a 2f 0a 20 20 63   /zip URL */.  c
0c30: 68 61 72 20 50 72 69 76 61 74 65 3b 20 20 20 20  har Private;    
0c40: 20 20 20 20 20 20 2f 2a 20 78 3a 20 63 61 6e 20        /* x: can 
0c50: 73 65 6e 64 20 61 6e 64 20 72 65 63 65 69 76 65  send and receive
0c60: 20 70 72 69 76 61 74 65 20 63 6f 6e 74 65 6e 74   private content
0c70: 20 2a 2f 0a 20 20 63 68 61 72 20 57 72 55 6e 76   */.  char WrUnv
0c80: 65 72 3b 20 20 20 20 20 20 20 20 20 20 2f 2a 20  er;          /* 
0c90: 79 3a 20 63 61 6e 20 70 75 73 68 20 75 6e 76 65  y: can push unve
0ca0: 72 73 69 6f 6e 65 64 20 63 6f 6e 74 65 6e 74 20  rsioned content 
0cb0: 2a 2f 0a 20 20 63 68 61 72 20 52 64 46 6f 72 75  */.  char RdForu
0cc0: 6d 3b 20 20 20 20 20 20 20 20 20 20 2f 2a 20 32  m;          /* 2
0cd0: 3a 20 52 65 61 64 20 66 6f 72 75 6d 20 70 6f 73  : Read forum pos
0ce0: 74 73 20 2a 2f 0a 20 20 63 68 61 72 20 57 72 46  ts */.  char WrF
0cf0: 6f 72 75 6d 3b 20 20 20 20 20 20 20 20 20 20 2f  orum;          /
0d00: 2a 20 33 3a 20 43 72 65 61 74 65 20 6e 65 77 20  * 3: Create new 
0d10: 66 6f 72 75 6d 20 70 6f 73 74 73 20 2a 2f 0a 20  forum posts */. 
0d20: 20 63 68 61 72 20 57 72 54 46 6f 72 75 6d 3b 20   char WrTForum; 
0d30: 20 20 20 20 20 20 20 20 2f 2a 20 34 3a 20 50 6f          /* 4: Po
0d40: 73 74 20 74 6f 20 66 6f 72 75 6d 73 20 6e 6f 74  st to forums not
0d50: 20 73 75 62 6a 65 63 74 20 74 6f 20 6d 6f 64 65   subject to mode
0d60: 72 61 74 69 6f 6e 20 2a 2f 0a 20 20 63 68 61 72  ration */.  char
0d70: 20 4d 6f 64 46 6f 72 75 6d 3b 20 20 20 20 20 20   ModForum;      
0d80: 20 20 20 2f 2a 20 35 3a 20 4d 6f 64 65 72 61 74     /* 5: Moderat
0d90: 65 20 28 61 70 70 72 6f 76 65 20 6f 72 20 72 65  e (approve or re
0da0: 6a 65 63 74 29 20 66 6f 72 75 6d 20 70 6f 73 74  ject) forum post
0db0: 73 20 2a 2f 0a 20 20 63 68 61 72 20 41 64 6d 69  s */.  char Admi
0dc0: 6e 46 6f 72 75 6d 3b 20 20 20 20 20 20 20 2f 2a  nForum;       /*
0dd0: 20 36 3a 20 53 65 74 20 6f 72 20 72 65 6d 6f 76   6: Set or remov
0de0: 65 20 63 61 70 61 62 69 6c 69 74 79 20 34 20 6f  e capability 4 o
0df0: 6e 20 6f 74 68 65 72 20 75 73 65 72 73 20 2a 2f  n other users */
0e00: 0a 20 20 63 68 61 72 20 45 6d 61 69 6c 41 6c 65  .  char EmailAle
0e10: 72 74 3b 20 20 20 20 20 20 20 2f 2a 20 37 3a 20  rt;       /* 7: 
0e20: 53 69 67 6e 20 75 70 20 66 6f 72 20 65 6d 61 69  Sign up for emai
0e30: 6c 20 6e 6f 74 69 66 69 63 61 74 69 6f 6e 73 20  l notifications 
0e40: 2a 2f 0a 20 20 63 68 61 72 20 41 6e 6e 6f 75 6e  */.  char Announ
0e50: 63 65 3b 20 20 20 20 20 20 20 20 20 2f 2a 20 41  ce;         /* A
0e60: 3a 20 53 65 6e 64 20 61 6e 6e 6f 75 6e 63 65 6d  : Send announcem
0e70: 65 6e 74 73 20 2a 2f 0a 20 20 63 68 61 72 20 44  ents */.  char D
0e80: 65 62 75 67 3b 20 20 20 20 20 20 20 20 20 20 20  ebug;           
0e90: 20 2f 2a 20 44 3a 20 73 68 6f 77 20 65 78 74 72   /* D: show extr
0ea0: 61 20 46 6f 73 73 69 6c 20 64 65 62 75 67 67 69  a Fossil debuggi
0eb0: 6e 67 20 66 65 61 74 75 72 65 73 20 2a 2f 0a 20  ng features */. 
0ec0: 20 2f 2a 20 54 68 65 73 65 20 6c 61 73 74 20 74   /* These last t
0ed0: 77 6f 20 61 72 65 20 69 6e 63 6c 75 64 65 64 20  wo are included 
0ee0: 74 6f 20 62 6c 6f 63 6b 20 69 6e 66 69 6e 69 74  to block infinit
0ef0: 65 20 72 65 63 75 72 73 69 6f 6e 20 2a 2f 0a 20  e recursion */. 
0f00: 20 63 68 61 72 20 58 52 65 61 64 65 72 3b 20 20   char XReader;  
0f10: 20 20 20 20 20 20 20 20 2f 2a 20 75 3a 20 49 6e          /* u: In
0f20: 68 65 72 69 74 20 61 6c 6c 20 70 72 69 76 69 6c  herit all privil
0f30: 65 67 65 73 20 6f 66 20 22 72 65 61 64 65 72 22  eges of "reader"
0f40: 20 2a 2f 0a 20 20 63 68 61 72 20 58 44 65 76 65   */.  char XDeve
0f50: 6c 6f 70 65 72 3b 20 20 20 20 20 20 20 2f 2a 20  loper;       /* 
0f60: 76 3a 20 49 6e 68 65 72 69 74 20 61 6c 6c 20 70  v: Inherit all p
0f70: 72 69 76 69 6c 65 67 65 73 20 6f 66 20 22 64 65  rivileges of "de
0f80: 76 65 6c 6f 70 65 72 22 20 2a 2f 0a 7d 3b 0a 0a  veloper" */.};..
0f90: 23 69 66 64 65 66 20 46 4f 53 53 49 4c 5f 45 4e  #ifdef FOSSIL_EN
0fa0: 41 42 4c 45 5f 54 43 4c 0a 2f 2a 0a 2a 2a 20 41  ABLE_TCL./*.** A
0fb0: 6c 6c 20 54 63 6c 20 72 65 6c 61 74 65 64 20 63  ll Tcl related c
0fc0: 6f 6e 74 65 78 74 20 69 6e 66 6f 72 6d 61 74 69  ontext informati
0fd0: 6f 6e 20 69 73 20 69 6e 20 74 68 69 73 20 73 74  on is in this st
0fe0: 72 75 63 74 75 72 65 2e 20 20 54 68 69 73 20 73  ructure.  This s
0ff0: 74 72 75 63 74 75 72 65 0a 2a 2a 20 64 65 66 69  tructure.** defi
1000: 6e 69 74 69 6f 6e 20 68 61 73 20 62 65 65 6e 20  nition has been 
1010: 63 6f 70 69 65 64 20 66 72 6f 6d 20 61 6e 64 20  copied from and 
1020: 73 68 6f 75 6c 64 20 62 65 20 6b 65 70 74 20 69  should be kept i
1030: 6e 20 73 79 6e 63 20 77 69 74 68 20 74 68 65 20  n sync with the 
1040: 6f 6e 65 20 69 6e 0a 2a 2a 20 22 74 68 5f 74 63  one in.** "th_tc
1050: 6c 2e 63 22 2e 0a 2a 2f 0a 73 74 72 75 63 74 20  l.c"..*/.struct 
1060: 54 63 6c 43 6f 6e 74 65 78 74 20 7b 0a 20 20 69  TclContext {.  i
1070: 6e 74 20 61 72 67 63 3b 20 20 20 20 20 20 20 20  nt argc;        
1080: 20 20 20 20 20 20 2f 2a 20 4e 75 6d 62 65 72 20        /* Number 
1090: 6f 66 20 6f 72 69 67 69 6e 61 6c 20 28 65 78 70  of original (exp
10a0: 61 6e 64 65 64 29 20 61 72 67 75 6d 65 6e 74 73  anded) arguments
10b0: 2e 20 2a 2f 0a 20 20 63 68 61 72 20 2a 2a 61 72  . */.  char **ar
10c0: 67 76 3b 20 20 20 20 20 20 20 20 20 20 20 2f 2a  gv;           /*
10d0: 20 46 75 6c 6c 20 63 6f 70 79 20 6f 66 20 74 68   Full copy of th
10e0: 65 20 6f 72 69 67 69 6e 61 6c 20 28 65 78 70 61  e original (expa
10f0: 6e 64 65 64 29 20 61 72 67 75 6d 65 6e 74 73 2e  nded) arguments.
1100: 20 2a 2f 0a 20 20 76 6f 69 64 20 2a 68 4c 69 62   */.  void *hLib
1110: 72 61 72 79 3b 20 20 20 20 20 20 20 20 2f 2a 20  rary;        /* 
1120: 54 68 65 20 54 63 6c 20 6c 69 62 72 61 72 79 20  The Tcl library 
1130: 6d 6f 64 75 6c 65 20 68 61 6e 64 6c 65 2e 20 2a  module handle. *
1140: 2f 0a 20 20 76 6f 69 64 20 2a 78 46 69 6e 64 45  /.  void *xFindE
1150: 78 65 63 75 74 61 62 6c 65 3b 20 2f 2a 20 53 65  xecutable; /* Se
1160: 65 20 74 63 6c 5f 46 69 6e 64 45 78 65 63 75 74  e tcl_FindExecut
1170: 61 62 6c 65 50 72 6f 63 20 69 6e 20 74 68 5f 74  ableProc in th_t
1180: 63 6c 2e 63 2e 20 2a 2f 0a 20 20 76 6f 69 64 20  cl.c. */.  void 
1190: 2a 78 43 72 65 61 74 65 49 6e 74 65 72 70 3b 20  *xCreateInterp; 
11a0: 20 20 2f 2a 20 53 65 65 20 74 63 6c 5f 43 72 65    /* See tcl_Cre
11b0: 61 74 65 49 6e 74 65 72 70 50 72 6f 63 20 69 6e  ateInterpProc in
11c0: 20 74 68 5f 74 63 6c 2e 63 2e 20 2a 2f 0a 20 20   th_tcl.c. */.  
11d0: 76 6f 69 64 20 2a 78 44 65 6c 65 74 65 49 6e 74  void *xDeleteInt
11e0: 65 72 70 3b 20 20 20 2f 2a 20 53 65 65 20 74 63  erp;   /* See tc
11f0: 6c 5f 44 65 6c 65 74 65 49 6e 74 65 72 70 50 72  l_DeleteInterpPr
1200: 6f 63 20 69 6e 20 74 68 5f 74 63 6c 2e 63 2e 20  oc in th_tcl.c. 
1210: 2a 2f 0a 20 20 76 6f 69 64 20 2a 78 46 69 6e 61  */.  void *xFina
1220: 6c 69 7a 65 3b 20 20 20 20 20 20 20 2f 2a 20 53  lize;       /* S
1230: 65 65 20 74 63 6c 5f 46 69 6e 61 6c 69 7a 65 50  ee tcl_FinalizeP
1240: 72 6f 63 20 69 6e 20 74 68 5f 74 63 6c 2e 63 2e  roc in th_tcl.c.
1250: 20 2a 2f 0a 20 20 54 63 6c 5f 49 6e 74 65 72 70   */.  Tcl_Interp
1260: 20 2a 69 6e 74 65 72 70 3b 20 20 20 20 2f 2a 20   *interp;    /* 
1270: 54 68 65 20 6f 6e 2d 64 65 6d 61 6e 64 20 63 72  The on-demand cr
1280: 65 61 74 65 64 20 54 63 6c 20 69 6e 74 65 72 70  eated Tcl interp
1290: 72 65 74 65 72 2e 20 2a 2f 0a 20 20 69 6e 74 20  reter. */.  int 
12a0: 75 73 65 4f 62 6a 50 72 6f 63 3b 20 20 20 20 20  useObjProc;     
12b0: 20 20 20 2f 2a 20 4e 6f 6e 2d 7a 65 72 6f 20 69     /* Non-zero i
12c0: 66 20 61 6e 20 6f 62 6a 50 72 6f 63 20 63 61 6e  f an objProc can
12d0: 20 62 65 20 63 61 6c 6c 65 64 20 64 69 72 65 63   be called direc
12e0: 74 6c 79 2e 20 2a 2f 0a 20 20 69 6e 74 20 75 73  tly. */.  int us
12f0: 65 54 69 70 32 38 35 3b 20 20 20 20 20 20 20 20  eTip285;        
1300: 20 2f 2a 20 4e 6f 6e 2d 7a 65 72 6f 20 69 66 20   /* Non-zero if 
1310: 54 49 50 20 23 32 38 35 20 69 73 20 61 76 61 69  TIP #285 is avai
1320: 6c 61 62 6c 65 2e 20 2a 2f 0a 20 20 63 68 61 72  lable. */.  char
1330: 20 2a 73 65 74 75 70 3b 20 20 20 20 20 20 20 20   *setup;        
1340: 20 20 20 2f 2a 20 54 68 65 20 6f 70 74 69 6f 6e     /* The option
1350: 61 6c 20 54 63 6c 20 73 65 74 75 70 20 73 63 72  al Tcl setup scr
1360: 69 70 74 2e 20 2a 2f 0a 20 20 76 6f 69 64 20 2a  ipt. */.  void *
1370: 78 50 72 65 45 76 61 6c 3b 20 20 20 20 20 20 20  xPreEval;       
1380: 20 2f 2a 20 4f 70 74 69 6f 6e 61 6c 2c 20 63 61   /* Optional, ca
1390: 6c 6c 65 64 20 62 65 66 6f 72 65 20 54 63 6c 5f  lled before Tcl_
13a0: 45 76 61 6c 2a 28 29 2e 20 2a 2f 0a 20 20 76 6f  Eval*(). */.  vo
13b0: 69 64 20 2a 70 50 72 65 43 6f 6e 74 65 78 74 3b  id *pPreContext;
13c0: 20 20 20 20 20 2f 2a 20 4f 70 74 69 6f 6e 61 6c       /* Optional
13d0: 2c 20 70 72 6f 76 69 64 65 64 20 74 6f 20 78 50  , provided to xP
13e0: 72 65 45 76 61 6c 28 29 2e 20 2a 2f 0a 20 20 76  reEval(). */.  v
13f0: 6f 69 64 20 2a 78 50 6f 73 74 45 76 61 6c 3b 20  oid *xPostEval; 
1400: 20 20 20 20 20 20 2f 2a 20 4f 70 74 69 6f 6e 61        /* Optiona
1410: 6c 2c 20 63 61 6c 6c 65 64 20 61 66 74 65 72 20  l, called after 
1420: 54 63 6c 5f 45 76 61 6c 2a 28 29 2e 20 2a 2f 0a  Tcl_Eval*(). */.
1430: 20 20 76 6f 69 64 20 2a 70 50 6f 73 74 43 6f 6e    void *pPostCon
1440: 74 65 78 74 3b 20 20 20 20 2f 2a 20 4f 70 74 69  text;    /* Opti
1450: 6f 6e 61 6c 2c 20 70 72 6f 76 69 64 65 64 20 74  onal, provided t
1460: 6f 20 78 50 6f 73 74 45 76 61 6c 28 29 2e 20 2a  o xPostEval(). *
1470: 2f 0a 7d 3b 0a 23 65 6e 64 69 66 0a 0a 73 74 72  /.};.#endif..str
1480: 75 63 74 20 47 6c 6f 62 61 6c 20 7b 0a 20 20 69  uct Global {.  i
1490: 6e 74 20 61 72 67 63 3b 20 63 68 61 72 20 2a 2a  nt argc; char **
14a0: 61 72 67 76 3b 20 20 2f 2a 20 43 6f 6d 6d 61 6e  argv;  /* Comman
14b0: 64 2d 6c 69 6e 65 20 61 72 67 75 6d 65 6e 74 73  d-line arguments
14c0: 20 74 6f 20 74 68 65 20 70 72 6f 67 72 61 6d 20   to the program 
14d0: 2a 2f 0a 20 20 63 68 61 72 20 2a 6e 61 6d 65 4f  */.  char *nameO
14e0: 66 45 78 65 3b 20 20 20 20 20 20 20 20 2f 2a 20  fExe;        /* 
14f0: 46 75 6c 6c 20 70 61 74 68 20 6f 66 20 65 78 65  Full path of exe
1500: 63 75 74 61 62 6c 65 2e 20 2a 2f 0a 20 20 63 6f  cutable. */.  co
1510: 6e 73 74 20 63 68 61 72 20 2a 7a 45 72 72 6c 6f  nst char *zErrlo
1520: 67 3b 20 20 20 20 2f 2a 20 4c 6f 67 20 65 72 72  g;    /* Log err
1530: 6f 72 73 20 74 6f 20 74 68 69 73 20 66 69 6c 65  ors to this file
1540: 2c 20 69 66 20 6e 6f 74 20 4e 55 4c 4c 20 2a 2f  , if not NULL */
1550: 0a 20 20 69 6e 74 20 69 73 43 6f 6e 73 74 3b 20  .  int isConst; 
1560: 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 54 72             /* Tr
1570: 75 65 20 69 66 20 74 68 65 20 6f 75 74 70 75 74  ue if the output
1580: 20 69 73 20 75 6e 63 68 61 6e 67 69 6e 67 20 26   is unchanging &
1590: 20 63 61 63 68 65 61 62 6c 65 20 2a 2f 0a 20 20   cacheable */.  
15a0: 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a 56 66 73  const char *zVfs
15b0: 4e 61 6d 65 3b 20 20 20 2f 2a 20 54 68 65 20 56  Name;   /* The V
15c0: 46 53 20 74 6f 20 75 73 65 20 66 6f 72 20 64 61  FS to use for da
15d0: 74 61 62 61 73 65 20 63 6f 6e 6e 65 63 74 69 6f  tabase connectio
15e0: 6e 73 20 2a 2f 0a 20 20 73 71 6c 69 74 65 33 20  ns */.  sqlite3 
15f0: 2a 64 62 3b 20 20 20 20 20 20 20 20 20 20 20 20  *db;            
1600: 2f 2a 20 54 68 65 20 63 6f 6e 6e 65 63 74 69 6f  /* The connectio
1610: 6e 20 74 6f 20 74 68 65 20 64 61 74 61 62 61 73  n to the databas
1620: 65 73 20 2a 2f 0a 20 20 73 71 6c 69 74 65 33 20  es */.  sqlite3 
1630: 2a 64 62 43 6f 6e 66 69 67 3b 20 20 20 20 20 20  *dbConfig;      
1640: 2f 2a 20 53 65 70 61 72 61 74 65 20 63 6f 6e 6e  /* Separate conn
1650: 65 63 74 69 6f 6e 20 66 6f 72 20 67 6c 6f 62 61  ection for globa
1660: 6c 5f 63 6f 6e 66 69 67 20 74 61 62 6c 65 20 2a  l_config table *
1670: 2f 0a 20 20 63 68 61 72 20 2a 7a 41 75 78 53 63  /.  char *zAuxSc
1680: 68 65 6d 61 3b 20 20 20 20 20 20 20 2f 2a 20 4d  hema;       /* M
1690: 61 69 6e 20 72 65 70 6f 73 69 74 6f 72 79 20 61  ain repository a
16a0: 75 78 2d 73 63 68 65 6d 61 20 2a 2f 0a 20 20 69  ux-schema */.  i
16b0: 6e 74 20 64 62 49 67 6e 6f 72 65 45 72 72 6f 72  nt dbIgnoreError
16c0: 73 3b 20 20 20 20 20 2f 2a 20 49 67 6e 6f 72 65  s;     /* Ignore
16d0: 20 64 61 74 61 62 61 73 65 20 65 72 72 6f 72 73   database errors
16e0: 20 69 66 20 74 72 75 65 20 2a 2f 0a 20 20 63 6f   if true */.  co
16f0: 6e 73 74 20 63 68 61 72 20 2a 7a 43 6f 6e 66 69  nst char *zConfi
1700: 67 44 62 4e 61 6d 65 3b 2f 2a 20 50 61 74 68 20  gDbName;/* Path 
1710: 6f 66 20 74 68 65 20 63 6f 6e 66 69 67 20 64 61  of the config da
1720: 74 61 62 61 73 65 2e 20 4e 55 4c 4c 20 69 66 20  tabase. NULL if 
1730: 6e 6f 74 20 6f 70 65 6e 20 2a 2f 0a 20 20 73 71  not open */.  sq
1740: 6c 69 74 65 33 5f 69 6e 74 36 34 20 6e 6f 77 3b  lite3_int64 now;
1750: 20 20 20 20 20 20 2f 2a 20 53 65 63 6f 6e 64 73        /* Seconds
1760: 20 73 69 6e 63 65 20 31 39 37 30 20 2a 2f 0a 20   since 1970 */. 
1770: 20 69 6e 74 20 72 65 70 6f 73 69 74 6f 72 79 4f   int repositoryO
1780: 70 65 6e 3b 20 20 20 20 20 2f 2a 20 54 72 75 65  pen;     /* True
1790: 20 69 66 20 74 68 65 20 6d 61 69 6e 20 72 65 70   if the main rep
17a0: 6f 73 69 74 6f 72 79 20 64 61 74 61 62 61 73 65  ository database
17b0: 20 69 73 20 6f 70 65 6e 20 2a 2f 0a 20 20 75 6e   is open */.  un
17c0: 73 69 67 6e 65 64 20 69 52 65 70 6f 44 61 74 61  signed iRepoData
17d0: 56 65 72 73 3b 20 20 2f 2a 20 49 6e 69 74 69 61  Vers;  /* Initia
17e0: 6c 20 64 61 74 61 20 76 65 72 73 69 6f 6e 20 66  l data version f
17f0: 6f 72 20 72 65 70 6f 73 69 74 6f 72 79 20 64 61  or repository da
1800: 74 61 62 61 73 65 20 2a 2f 0a 20 20 63 68 61 72  tabase */.  char
1810: 20 2a 7a 52 65 70 6f 73 69 74 6f 72 79 4f 70 74   *zRepositoryOpt
1820: 69 6f 6e 3b 20 2f 2a 20 4d 6f 73 74 20 72 65 63  ion; /* Most rec
1830: 65 6e 74 20 63 61 63 68 65 64 20 72 65 70 6f 73  ent cached repos
1840: 69 74 6f 72 79 20 6f 70 74 69 6f 6e 20 76 61 6c  itory option val
1850: 75 65 20 2a 2f 0a 20 20 63 68 61 72 20 2a 7a 52  ue */.  char *zR
1860: 65 70 6f 73 69 74 6f 72 79 4e 61 6d 65 3b 20 20  epositoryName;  
1870: 2f 2a 20 4e 61 6d 65 20 6f 66 20 74 68 65 20 72  /* Name of the r
1880: 65 70 6f 73 69 74 6f 72 79 20 64 61 74 61 62 61  epository databa
1890: 73 65 20 66 69 6c 65 20 2a 2f 0a 20 20 63 68 61  se file */.  cha
18a0: 72 20 2a 7a 4c 6f 63 61 6c 44 62 4e 61 6d 65 3b  r *zLocalDbName;
18b0: 20 20 20 20 20 2f 2a 20 4e 61 6d 65 20 6f 66 20       /* Name of 
18c0: 74 68 65 20 6c 6f 63 61 6c 20 64 61 74 61 62 61  the local databa
18d0: 73 65 20 66 69 6c 65 20 2a 2f 0a 20 20 63 68 61  se file */.  cha
18e0: 72 20 2a 7a 4f 70 65 6e 52 65 76 69 73 69 6f 6e  r *zOpenRevision
18f0: 3b 20 20 20 20 2f 2a 20 43 68 65 63 6b 2d 69 6e  ;    /* Check-in
1900: 20 76 65 72 73 69 6f 6e 20 74 6f 20 75 73 65 20   version to use 
1910: 64 75 72 69 6e 67 20 64 61 74 61 62 61 73 65 20  during database 
1920: 6f 70 65 6e 20 2a 2f 0a 20 20 69 6e 74 20 6c 6f  open */.  int lo
1930: 63 61 6c 4f 70 65 6e 3b 20 20 20 20 20 20 20 20  calOpen;        
1940: 20 20 2f 2a 20 54 72 75 65 20 69 66 20 74 68 65    /* True if the
1950: 20 6c 6f 63 61 6c 20 64 61 74 61 62 61 73 65 20   local database 
1960: 69 73 20 6f 70 65 6e 20 2a 2f 0a 20 20 63 68 61  is open */.  cha
1970: 72 20 2a 7a 4c 6f 63 61 6c 52 6f 6f 74 3b 20 20  r *zLocalRoot;  
1980: 20 20 20 20 20 2f 2a 20 54 68 65 20 64 69 72 65       /* The dire
1990: 63 74 6f 72 79 20 68 6f 6c 64 69 6e 67 20 74 68  ctory holding th
19a0: 65 20 20 6c 6f 63 61 6c 20 64 61 74 61 62 61 73  e  local databas
19b0: 65 20 2a 2f 0a 20 20 69 6e 74 20 6d 69 6e 50 72  e */.  int minPr
19c0: 65 66 69 78 3b 20 20 20 20 20 20 20 20 20 20 2f  efix;          /
19d0: 2a 20 4e 75 6d 62 65 72 20 6f 66 20 64 69 67 69  * Number of digi
19e0: 74 73 20 6e 65 65 64 65 64 20 66 6f 72 20 61 20  ts needed for a 
19f0: 64 69 73 74 69 6e 63 74 20 55 55 49 44 20 2a 2f  distinct UUID */
1a00: 0a 20 20 69 6e 74 20 65 48 61 73 68 50 6f 6c 69  .  int eHashPoli
1a10: 63 79 3b 20 20 20 20 20 20 20 20 2f 2a 20 43 75  cy;        /* Cu
1a20: 72 72 65 6e 74 20 68 61 73 68 20 70 6f 6c 69 63  rrent hash polic
1a30: 79 2e 20 20 4f 6e 65 20 6f 66 20 48 50 4f 4c 49  y.  One of HPOLI
1a40: 43 59 5f 2a 20 2a 2f 0a 20 20 69 6e 74 20 66 53  CY_* */.  int fS
1a50: 71 6c 54 72 61 63 65 3b 20 20 20 20 20 20 20 20  qlTrace;        
1a60: 20 20 2f 2a 20 54 72 75 65 20 69 66 20 2d 2d 73    /* True if --s
1a70: 71 6c 74 72 61 63 65 20 66 6c 61 67 20 69 73 20  qltrace flag is 
1a80: 70 72 65 73 65 6e 74 20 2a 2f 0a 20 20 69 6e 74  present */.  int
1a90: 20 66 53 71 6c 53 74 61 74 73 3b 20 20 20 20 20   fSqlStats;     
1aa0: 20 20 20 20 20 2f 2a 20 54 72 75 65 20 69 66 20       /* True if 
1ab0: 2d 2d 73 71 6c 74 72 61 63 65 20 6f 72 20 2d 2d  --sqltrace or --
1ac0: 73 71 6c 73 74 61 74 73 20 61 72 65 20 70 72 65  sqlstats are pre
1ad0: 73 65 6e 74 20 2a 2f 0a 20 20 69 6e 74 20 66 53  sent */.  int fS
1ae0: 71 6c 50 72 69 6e 74 3b 20 20 20 20 20 20 20 20  qlPrint;        
1af0: 20 20 2f 2a 20 54 72 75 65 20 69 66 20 2d 2d 73    /* True if --s
1b00: 71 6c 70 72 69 6e 74 20 66 6c 61 67 20 69 73 20  qlprint flag is 
1b10: 70 72 65 73 65 6e 74 20 2a 2f 0a 20 20 69 6e 74  present */.  int
1b20: 20 66 43 67 69 54 72 61 63 65 3b 20 20 20 20 20   fCgiTrace;     
1b30: 20 20 20 20 20 2f 2a 20 54 72 75 65 20 69 66 20       /* True if 
1b40: 2d 2d 63 67 69 74 72 61 63 65 20 69 73 20 65 6e  --cgitrace is en
1b50: 61 62 6c 65 64 20 2a 2f 0a 20 20 69 6e 74 20 66  abled */.  int f
1b60: 51 75 69 65 74 3b 20 20 20 20 20 20 20 20 20 20  Quiet;          
1b70: 20 20 20 2f 2a 20 54 72 75 65 20 69 66 20 2d 71     /* True if -q
1b80: 75 69 65 74 20 66 6c 61 67 20 69 73 20 70 72 65  uiet flag is pre
1b90: 73 65 6e 74 20 2a 2f 0a 20 20 69 6e 74 20 66 4a  sent */.  int fJ
1ba0: 61 69 6c 3b 20 20 20 20 20 20 20 20 20 20 20 20  ail;            
1bb0: 20 20 2f 2a 20 54 72 75 65 20 69 66 20 72 75 6e    /* True if run
1bc0: 6e 69 6e 67 20 77 69 74 68 20 61 20 63 68 72 6f  ning with a chro
1bd0: 6f 74 20 6a 61 69 6c 20 2a 2f 0a 20 20 69 6e 74  ot jail */.  int
1be0: 20 66 48 74 74 70 54 72 61 63 65 3b 20 20 20 20   fHttpTrace;    
1bf0: 20 20 20 20 20 2f 2a 20 54 72 61 63 65 20 6f 75       /* Trace ou
1c00: 74 62 6f 75 6e 64 20 48 54 54 50 20 72 65 71 75  tbound HTTP requ
1c10: 65 73 74 73 20 2a 2f 0a 20 20 69 6e 74 20 66 41  ests */.  int fA
1c20: 6e 79 54 72 61 63 65 3b 20 20 20 20 20 20 20 20  nyTrace;        
1c30: 20 20 2f 2a 20 41 6e 79 20 6b 69 6e 64 20 6f 66    /* Any kind of
1c40: 20 74 72 61 63 69 6e 67 20 2a 2f 0a 20 20 63 68   tracing */.  ch
1c50: 61 72 20 2a 7a 48 74 74 70 41 75 74 68 3b 20 20  ar *zHttpAuth;  
1c60: 20 20 20 20 20 20 2f 2a 20 48 54 54 50 20 41 75        /* HTTP Au
1c70: 74 68 6f 72 69 7a 61 74 69 6f 6e 20 75 73 65 72  thorization user
1c80: 3a 70 61 73 73 20 69 6e 66 6f 72 6d 61 74 69 6f  :pass informatio
1c90: 6e 20 2a 2f 0a 20 20 69 6e 74 20 66 53 79 73 74  n */.  int fSyst
1ca0: 65 6d 54 72 61 63 65 3b 20 20 20 20 20 20 20 2f  emTrace;       /
1cb0: 2a 20 54 72 61 63 65 20 63 61 6c 6c 73 20 74 6f  * Trace calls to
1cc0: 20 66 6f 73 73 69 6c 5f 73 79 73 74 65 6d 28 29   fossil_system()
1cd0: 2c 20 2d 2d 73 79 73 74 65 6d 74 72 61 63 65 20  , --systemtrace 
1ce0: 2a 2f 0a 20 20 69 6e 74 20 66 53 73 68 54 72 61  */.  int fSshTra
1cf0: 63 65 3b 20 20 20 20 20 20 20 20 20 20 2f 2a 20  ce;          /* 
1d00: 54 72 61 63 65 20 74 68 65 20 53 53 48 20 73 65  Trace the SSH se
1d10: 74 75 70 20 74 72 61 66 66 69 63 20 2a 2f 0a 20  tup traffic */. 
1d20: 20 69 6e 74 20 66 53 73 68 43 6c 69 65 6e 74 3b   int fSshClient;
1d30: 20 20 20 20 20 20 20 20 20 2f 2a 20 48 54 54 50           /* HTTP
1d40: 20 63 6c 69 65 6e 74 20 66 6c 61 67 73 20 66 6f   client flags fo
1d50: 72 20 53 53 48 20 63 6c 69 65 6e 74 20 2a 2f 0a  r SSH client */.
1d60: 20 20 69 6e 74 20 66 4e 6f 48 74 74 70 43 6f 6d    int fNoHttpCom
1d70: 70 72 65 73 73 3b 20 20 20 20 2f 2a 20 44 6f 20  press;    /* Do 
1d80: 6e 6f 74 20 63 6f 6d 70 72 65 73 73 20 48 54 54  not compress HTT
1d90: 50 20 74 72 61 66 66 69 63 20 28 66 6f 72 20 64  P traffic (for d
1da0: 65 62 75 67 67 69 6e 67 29 20 2a 2f 0a 20 20 63  ebugging) */.  c
1db0: 68 61 72 20 2a 7a 53 73 68 43 6d 64 3b 20 20 20  har *zSshCmd;   
1dc0: 20 20 20 20 20 20 20 2f 2a 20 53 53 48 20 63 6f         /* SSH co
1dd0: 6d 6d 61 6e 64 20 73 74 72 69 6e 67 20 2a 2f 0a  mmand string */.
1de0: 20 20 69 6e 74 20 66 4e 6f 53 79 6e 63 3b 20 20    int fNoSync;  
1df0: 20 20 20 20 20 20 20 20 20 20 2f 2a 20 44 6f 20            /* Do 
1e00: 6e 6f 74 20 64 6f 20 61 6e 20 61 75 74 6f 73 79  not do an autosy
1e10: 6e 63 20 65 76 65 72 2e 20 20 2d 2d 6e 6f 73 79  nc ever.  --nosy
1e20: 6e 63 20 2a 2f 0a 20 20 69 6e 74 20 66 49 50 76  nc */.  int fIPv
1e30: 34 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 20  4;              
1e40: 2f 2a 20 55 73 65 20 6f 6e 6c 79 20 49 50 76 34  /* Use only IPv4
1e50: 2c 20 6e 6f 74 20 49 50 76 36 2e 20 2d 2d 69 70  , not IPv6. --ip
1e60: 76 34 20 2a 2f 0a 20 20 63 68 61 72 20 2a 7a 50  v4 */.  char *zP
1e70: 61 74 68 3b 20 20 20 20 20 20 20 20 20 20 20 20  ath;            
1e80: 2f 2a 20 4e 61 6d 65 20 6f 66 20 77 65 62 70 61  /* Name of webpa
1e90: 67 65 20 62 65 69 6e 67 20 73 65 72 76 65 64 20  ge being served 
1ea0: 2a 2f 0a 20 20 63 68 61 72 20 2a 7a 45 78 74 72  */.  char *zExtr
1eb0: 61 3b 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20  a;           /* 
1ec0: 45 78 74 72 61 20 70 61 74 68 20 69 6e 66 6f 72  Extra path infor
1ed0: 6d 61 74 69 6f 6e 20 70 61 73 74 20 74 68 65 20  mation past the 
1ee0: 77 65 62 70 61 67 65 20 6e 61 6d 65 20 2a 2f 0a  webpage name */.
1ef0: 20 20 63 68 61 72 20 2a 7a 42 61 73 65 55 52 4c    char *zBaseURL
1f00: 3b 20 20 20 20 20 20 20 20 20 2f 2a 20 46 75 6c  ;         /* Ful
1f10: 6c 20 74 65 78 74 20 6f 66 20 74 68 65 20 55 52  l text of the UR
1f20: 4c 20 62 65 69 6e 67 20 73 65 72 76 65 64 20 2a  L being served *
1f30: 2f 0a 20 20 63 68 61 72 20 2a 7a 48 74 74 70 73  /.  char *zHttps
1f40: 55 52 4c 3b 20 20 20 20 20 20 20 20 2f 2a 20 7a  URL;        /* z
1f50: 42 61 73 65 55 52 4c 20 74 72 61 6e 73 6c 61 74  BaseURL translat
1f60: 65 64 20 74 6f 20 68 74 74 70 73 3a 20 2a 2f 0a  ed to https: */.
1f70: 20 20 63 68 61 72 20 2a 7a 54 6f 70 3b 20 20 20    char *zTop;   
1f80: 20 20 20 20 20 20 20 20 20 20 2f 2a 20 50 61 72            /* Par
1f90: 65 6e 74 20 64 69 72 65 63 74 6f 72 79 20 6f 66  ent directory of
1fa0: 20 7a 50 61 74 68 20 2a 2f 0a 20 20 63 6f 6e 73   zPath */.  cons
1fb0: 74 20 63 68 61 72 20 2a 7a 45 78 74 52 6f 6f 74  t char *zExtRoot
1fc0: 3b 20 20 20 2f 2a 20 44 6f 63 75 6d 65 6e 74 20  ;   /* Document 
1fd0: 72 6f 6f 74 20 66 6f 72 20 74 68 65 20 2f 65 78  root for the /ex
1fe0: 74 20 73 75 62 2d 77 65 62 73 69 74 65 20 2a 2f  t sub-website */
1ff0: 0a 20 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a  .  const char *z
2000: 43 6f 6e 74 65 6e 74 54 79 70 65 3b 20 20 2f 2a  ContentType;  /*
2010: 20 54 68 65 20 63 6f 6e 74 65 6e 74 20 74 79 70   The content typ
2020: 65 20 6f 66 20 74 68 65 20 69 6e 70 75 74 20 48  e of the input H
2030: 54 54 50 20 72 65 71 75 65 73 74 20 2a 2f 0a 20  TTP request */. 
2040: 20 69 6e 74 20 69 45 72 72 50 72 69 6f 72 69 74   int iErrPriorit
2050: 79 3b 20 20 20 20 20 20 20 2f 2a 20 50 72 69 6f  y;       /* Prio
2060: 72 69 74 79 20 6f 66 20 63 75 72 72 65 6e 74 20  rity of current 
2070: 65 72 72 6f 72 20 6d 65 73 73 61 67 65 20 2a 2f  error message */
2080: 0a 20 20 63 68 61 72 20 2a 7a 45 72 72 4d 73 67  .  char *zErrMsg
2090: 3b 20 20 20 20 20 20 20 20 20 20 2f 2a 20 54 65  ;          /* Te
20a0: 78 74 20 6f 66 20 61 6e 20 65 72 72 6f 72 20 6d  xt of an error m
20b0: 65 73 73 61 67 65 20 2a 2f 0a 20 20 69 6e 74 20  essage */.  int 
20c0: 73 73 6c 4e 6f 74 41 76 61 69 6c 61 62 6c 65 3b  sslNotAvailable;
20d0: 20 20 20 20 2f 2a 20 53 53 4c 20 69 73 20 6e 6f      /* SSL is no
20e0: 74 20 61 76 61 69 6c 61 62 6c 65 2e 20 20 44 6f  t available.  Do
20f0: 20 6e 6f 74 20 72 65 64 69 72 65 63 74 20 74 6f   not redirect to
2100: 20 68 74 74 70 73 3a 20 2a 2f 0a 20 20 42 6c 6f   https: */.  Blo
2110: 62 20 63 67 69 49 6e 3b 20 20 20 20 20 20 20 20  b cgiIn;        
2120: 20 20 20 20 20 2f 2a 20 49 6e 70 75 74 20 74 6f       /* Input to
2130: 20 61 6e 20 78 66 65 72 20 77 77 77 20 6d 65 74   an xfer www met
2140: 68 6f 64 20 2a 2f 0a 20 20 69 6e 74 20 63 67 69  hod */.  int cgi
2150: 4f 75 74 70 75 74 3b 20 20 20 20 20 20 20 20 20  Output;         
2160: 20 2f 2a 20 30 3a 20 63 6f 6d 6d 61 6e 64 2d 6c   /* 0: command-l
2170: 69 6e 65 20 31 3a 20 43 47 49 2e 20 32 3a 20 61  ine 1: CGI. 2: a
2180: 66 74 65 72 20 43 47 49 20 2a 2f 0a 20 20 69 6e  fter CGI */.  in
2190: 74 20 78 66 65 72 50 61 6e 69 63 3b 20 20 20 20  t xferPanic;    
21a0: 20 20 20 20 20 20 2f 2a 20 57 72 69 74 65 20 65        /* Write e
21b0: 72 72 6f 72 20 6d 65 73 73 61 67 65 73 20 69 6e  rror messages in
21c0: 20 58 46 45 52 20 70 72 6f 74 6f 63 6f 6c 20 2a   XFER protocol *
21d0: 2f 0a 20 20 69 6e 74 20 66 75 6c 6c 48 74 74 70  /.  int fullHttp
21e0: 52 65 70 6c 79 3b 20 20 20 20 20 20 2f 2a 20 54  Reply;      /* T
21f0: 72 75 65 20 66 6f 72 20 66 75 6c 6c 20 48 54 54  rue for full HTT
2200: 50 20 72 65 70 6c 79 2e 20 20 46 61 6c 73 65 20  P reply.  False 
2210: 66 6f 72 20 43 47 49 20 72 65 70 6c 79 20 2a 2f  for CGI reply */
2220: 0a 20 20 54 68 5f 49 6e 74 65 72 70 20 2a 69 6e  .  Th_Interp *in
2230: 74 65 72 70 3b 20 20 20 20 20 20 2f 2a 20 54 68  terp;      /* Th
2240: 65 20 54 48 31 20 69 6e 74 65 72 70 72 65 74 65  e TH1 interprete
2250: 72 20 2a 2f 0a 20 20 63 68 61 72 20 2a 74 68 31  r */.  char *th1
2260: 53 65 74 75 70 3b 20 20 20 20 20 20 20 20 20 2f  Setup;         /
2270: 2a 20 54 68 65 20 54 48 31 20 70 6f 73 74 2d 63  * The TH1 post-c
2280: 72 65 61 74 69 6f 6e 20 73 65 74 75 70 20 73 63  reation setup sc
2290: 72 69 70 74 2c 20 69 66 20 61 6e 79 20 2a 2f 0a  ript, if any */.
22a0: 20 20 69 6e 74 20 74 68 31 46 6c 61 67 73 3b 20    int th1Flags; 
22b0: 20 20 20 20 20 20 20 20 20 20 2f 2a 20 54 68 65            /* The
22c0: 20 54 48 31 20 69 6e 74 65 67 72 61 74 69 6f 6e   TH1 integration
22d0: 20 73 74 61 74 65 20 66 6c 61 67 73 20 2a 2f 0a   state flags */.
22e0: 20 20 46 49 4c 45 20 2a 68 74 74 70 49 6e 3b 20    FILE *httpIn; 
22f0: 20 20 20 20 20 20 20 20 20 20 2f 2a 20 41 63 63            /* Acc
2300: 65 70 74 20 48 54 54 50 20 69 6e 70 75 74 20 66  ept HTTP input f
2310: 72 6f 6d 20 68 65 72 65 20 2a 2f 0a 20 20 46 49  rom here */.  FI
2320: 4c 45 20 2a 68 74 74 70 4f 75 74 3b 20 20 20 20  LE *httpOut;    
2330: 20 20 20 20 20 20 2f 2a 20 53 65 6e 64 20 48 54        /* Send HT
2340: 54 50 20 6f 75 74 70 75 74 20 68 65 72 65 20 2a  TP output here *
2350: 2f 0a 20 20 69 6e 74 20 78 6c 69 6e 6b 43 6c 75  /.  int xlinkClu
2360: 73 74 65 72 4f 6e 6c 79 3b 20 20 20 2f 2a 20 53  sterOnly;   /* S
2370: 65 74 20 77 68 65 6e 20 63 6c 6f 6e 69 6e 67 2e  et when cloning.
2380: 20 20 4f 6e 6c 79 20 70 72 6f 63 65 73 73 20 63    Only process c
2390: 6c 75 73 74 65 72 73 20 2a 2f 0a 20 20 69 6e 74  lusters */.  int
23a0: 20 66 54 69 6d 65 46 6f 72 6d 61 74 3b 20 20 20   fTimeFormat;   
23b0: 20 20 20 20 20 2f 2a 20 31 20 66 6f 72 20 55 54       /* 1 for UT
23c0: 43 2e 20 20 32 20 66 6f 72 20 6c 6f 63 61 6c 74  C.  2 for localt
23d0: 69 6d 65 2e 20 20 30 20 6e 6f 74 20 79 65 74 20  ime.  0 not yet 
23e0: 73 65 6c 65 63 74 65 64 20 2a 2f 0a 20 20 69 6e  selected */.  in
23f0: 74 20 2a 61 43 6f 6d 6d 69 74 46 69 6c 65 3b 20  t *aCommitFile; 
2400: 20 20 20 20 20 20 2f 2a 20 41 72 72 61 79 20 6f        /* Array o
2410: 66 20 66 69 6c 65 73 20 74 6f 20 62 65 20 63 6f  f files to be co
2420: 6d 6d 69 74 74 65 64 20 2a 2f 0a 20 20 69 6e 74  mmitted */.  int
2430: 20 6d 61 72 6b 50 72 69 76 61 74 65 3b 20 20 20   markPrivate;   
2440: 20 20 20 20 20 2f 2a 20 41 6c 6c 20 6e 65 77 20       /* All new 
2450: 61 72 74 69 66 61 63 74 73 20 61 72 65 20 70 72  artifacts are pr
2460: 69 76 61 74 65 20 69 66 20 74 72 75 65 20 2a 2f  ivate if true */
2470: 0a 20 20 63 68 61 72 20 2a 63 6b 69 6e 4c 6f 63  .  char *ckinLoc
2480: 6b 46 61 69 6c 3b 20 20 20 20 20 2f 2a 20 43 68  kFail;     /* Ch
2490: 65 63 6b 2d 69 6e 20 6c 6f 63 6b 20 66 61 69 6c  eck-in lock fail
24a0: 75 72 65 20 72 65 63 65 69 76 65 64 20 66 72 6f  ure received fro
24b0: 6d 20 73 65 72 76 65 72 20 2a 2f 0a 20 20 69 6e  m server */.  in
24c0: 74 20 63 6c 6f 63 6b 53 6b 65 77 53 65 65 6e 3b  t clockSkewSeen;
24d0: 20 20 20 20 20 20 2f 2a 20 54 72 75 65 20 69 66        /* True if
24e0: 20 63 6c 6f 63 6b 73 20 6f 6e 20 63 6c 69 65 6e   clocks on clien
24f0: 74 20 61 6e 64 20 73 65 72 76 65 72 20 6f 75 74  t and server out
2500: 20 6f 66 20 73 79 6e 63 20 2a 2f 0a 20 20 69 6e   of sync */.  in
2510: 74 20 77 69 6b 69 46 6c 61 67 73 3b 20 20 20 20  t wikiFlags;    
2520: 20 20 20 20 20 20 2f 2a 20 57 69 6b 69 20 63 6f        /* Wiki co
2530: 6e 76 65 72 73 69 6f 6e 20 66 6c 61 67 73 20 61  nversion flags a
2540: 70 70 6c 69 65 64 20 74 6f 20 25 57 20 2a 2f 0a  pplied to %W */.
2550: 20 20 63 68 61 72 20 69 73 48 54 54 50 3b 20 20    char isHTTP;  
2560: 20 20 20 20 20 20 20 20 20 20 2f 2a 20 54 72 75            /* Tru
2570: 65 20 69 66 20 73 65 72 76 65 72 2f 43 47 49 20  e if server/CGI 
2580: 6d 6f 64 65 73 2c 20 65 6c 73 65 20 61 73 73 75  modes, else assu
2590: 6d 65 20 43 4c 49 2e 20 2a 2f 0a 20 20 63 68 61  me CLI. */.  cha
25a0: 72 20 6a 61 76 61 73 63 72 69 70 74 48 79 70 65  r javascriptHype
25b0: 72 6c 69 6e 6b 3b 20 2f 2a 20 49 66 20 74 72 75  rlink; /* If tru
25c0: 65 2c 20 73 65 74 20 68 72 65 66 3d 20 75 73 69  e, set href= usi
25d0: 6e 67 20 73 63 72 69 70 74 2c 20 6e 6f 74 20 48  ng script, not H
25e0: 54 4d 4c 20 2a 2f 0a 20 20 42 6c 6f 62 20 68 74  TML */.  Blob ht
25f0: 74 70 48 65 61 64 65 72 3b 20 20 20 20 20 20 20  tpHeader;       
2600: 20 2f 2a 20 43 6f 6d 70 6c 65 74 65 20 74 65 78   /* Complete tex
2610: 74 20 6f 66 20 74 68 65 20 48 54 54 50 20 72 65  t of the HTTP re
2620: 71 75 65 73 74 20 68 65 61 64 65 72 20 2a 2f 0a  quest header */.
2630: 20 20 55 72 6c 44 61 74 61 20 75 72 6c 3b 20 20    UrlData url;  
2640: 20 20 20 20 20 20 20 20 20 20 2f 2a 20 49 6e 66            /* Inf
2650: 6f 72 6d 61 74 69 6f 6e 20 61 62 6f 75 74 20 63  ormation about c
2660: 75 72 72 65 6e 74 20 55 52 4c 20 2a 2f 0a 20 20  urrent URL */.  
2670: 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a 4c 6f 67  const char *zLog
2680: 69 6e 3b 20 20 20 20 20 2f 2a 20 4c 6f 67 69 6e  in;     /* Login
2690: 20 6e 61 6d 65 2e 20 20 4e 55 4c 4c 20 6f 72 20   name.  NULL or 
26a0: 22 22 20 69 66 20 6e 6f 74 20 6c 6f 67 67 65 64  "" if not logged
26b0: 20 69 6e 2e 20 2a 2f 0a 20 20 63 6f 6e 73 74 20   in. */.  const 
26c0: 63 68 61 72 20 2a 7a 53 53 4c 49 64 65 6e 74 69  char *zSSLIdenti
26d0: 74 79 3b 20 20 2f 2a 20 56 61 6c 75 65 20 6f 66  ty;  /* Value of
26e0: 20 2d 2d 73 73 6c 2d 69 64 65 6e 74 69 74 79 20   --ssl-identity 
26f0: 6f 70 74 69 6f 6e 2c 20 66 69 6c 65 6e 61 6d 65  option, filename
2700: 20 6f 66 0a 20 20 20 20 20 20 20 20 20 20 20 20   of.            
2710: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
2720: 20 2a 2a 20 53 53 4c 20 63 6c 69 65 6e 74 20 69   ** SSL client i
2730: 64 65 6e 74 69 74 79 20 2a 2f 0a 20 20 69 6e 74  dentity */.  int
2740: 20 75 73 65 4c 6f 63 61 6c 61 75 74 68 3b 20 20   useLocalauth;  
2750: 20 20 20 20 20 2f 2a 20 4e 6f 20 6c 6f 67 69 6e       /* No login
2760: 20 72 65 71 75 69 72 65 64 20 69 66 20 66 72 6f   required if fro
2770: 6d 20 31 32 37 2e 30 2e 30 2e 31 20 2a 2f 0a 20  m 127.0.0.1 */. 
2780: 20 69 6e 74 20 6e 6f 50 73 77 64 3b 20 20 20 20   int noPswd;    
2790: 20 20 20 20 20 20 20 20 20 2f 2a 20 4c 6f 67 67           /* Logg
27a0: 65 64 20 69 6e 20 77 69 74 68 6f 75 74 20 70 61  ed in without pa
27b0: 73 73 77 6f 72 64 20 28 6f 6e 20 31 32 37 2e 30  ssword (on 127.0
27c0: 2e 30 2e 31 29 20 2a 2f 0a 20 20 69 6e 74 20 75  .0.1) */.  int u
27d0: 73 65 72 55 69 64 3b 20 20 20 20 20 20 20 20 20  serUid;         
27e0: 20 20 20 2f 2a 20 49 6e 74 65 67 65 72 20 75 73     /* Integer us
27f0: 65 72 20 69 64 20 2a 2f 0a 20 20 69 6e 74 20 69  er id */.  int i
2800: 73 48 75 6d 61 6e 3b 20 20 20 20 20 20 20 20 20  sHuman;         
2810: 20 20 20 2f 2a 20 54 72 75 65 20 69 66 20 61 63     /* True if ac
2820: 63 65 73 73 20 62 79 20 61 20 68 75 6d 61 6e 2c  cess by a human,
2830: 20 6e 6f 74 20 61 20 73 70 69 64 65 72 20 6f 72   not a spider or
2840: 20 62 6f 74 20 2a 2f 0a 20 20 69 6e 74 20 63 6f   bot */.  int co
2850: 6d 46 6d 74 46 6c 61 67 73 3b 20 20 20 20 20 20  mFmtFlags;      
2860: 20 20 2f 2a 20 5a 65 72 6f 20 6f 72 20 6d 6f 72    /* Zero or mor
2870: 65 20 22 43 4f 4d 4d 45 4e 54 5f 50 52 49 4e 54  e "COMMENT_PRINT
2880: 5f 2a 22 20 62 69 74 20 66 6c 61 67 73 2c 20 73  _*" bit flags, s
2890: 68 6f 75 6c 64 20 62 65 0a 20 20 20 20 20 20 20  hould be.       
28a0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
28b0: 20 20 20 2a 2a 20 61 63 63 65 73 73 65 64 20 74     ** accessed t
28c0: 68 72 6f 75 67 68 20 67 65 74 5f 63 6f 6d 6d 65  hrough get_comme
28d0: 6e 74 5f 66 6f 72 6d 61 74 28 29 2e 20 2a 2f 0a  nt_format(). */.
28e0: 0a 20 20 2f 2a 20 49 6e 66 6f 72 6d 61 74 69 6f  .  /* Informatio
28f0: 6e 20 75 73 65 64 20 74 6f 20 70 6f 70 75 6c 61  n used to popula
2900: 74 65 20 74 68 65 20 52 43 56 46 52 4f 4d 20 74  te the RCVFROM t
2910: 61 62 6c 65 20 2a 2f 0a 20 20 69 6e 74 20 72 63  able */.  int rc
2920: 76 69 64 3b 20 20 20 20 20 20 20 20 20 20 20 20  vid;            
2930: 20 20 2f 2a 20 54 68 65 20 72 63 76 69 64 2e 20    /* The rcvid. 
2940: 20 30 20 69 66 20 6e 6f 74 20 79 65 74 20 64 65   0 if not yet de
2950: 66 69 6e 65 64 2e 20 2a 2f 0a 20 20 63 68 61 72  fined. */.  char
2960: 20 2a 7a 49 70 41 64 64 72 3b 20 20 20 20 20 20   *zIpAddr;      
2970: 20 20 20 20 2f 2a 20 54 68 65 20 72 65 6d 6f 74      /* The remot
2980: 65 20 49 50 20 61 64 64 72 65 73 73 20 2a 2f 0a  e IP address */.
2990: 20 20 63 68 61 72 20 2a 7a 4e 6f 6e 63 65 3b 20    char *zNonce; 
29a0: 20 20 20 20 20 20 20 20 20 20 2f 2a 20 54 68 65            /* The
29b0: 20 6e 6f 6e 63 65 20 75 73 65 64 20 66 6f 72 20   nonce used for 
29c0: 6c 6f 67 69 6e 20 2a 2f 0a 0a 20 20 2f 2a 20 70  login */..  /* p
29d0: 65 72 6d 69 73 73 69 6f 6e 73 20 61 76 61 69 6c  ermissions avail
29e0: 61 62 6c 65 20 74 6f 20 63 75 72 72 65 6e 74 20  able to current 
29f0: 75 73 65 72 20 2a 2f 0a 20 20 73 74 72 75 63 74  user */.  struct
2a00: 20 46 6f 73 73 69 6c 55 73 65 72 50 65 72 6d 73   FossilUserPerms
2a10: 20 70 65 72 6d 3b 0a 0a 20 20 2f 2a 20 70 65 72   perm;..  /* per
2a20: 6d 69 73 73 69 6f 6e 73 20 61 76 61 69 6c 61 62  missions availab
2a30: 6c 65 20 74 6f 20 63 75 72 72 65 6e 74 20 75 73  le to current us
2a40: 65 72 20 6f 72 20 74 6f 20 22 61 6e 6f 6e 79 6d  er or to "anonym
2a50: 6f 75 73 22 2e 0a 20 20 2a 2a 20 54 68 69 73 20  ous"..  ** This 
2a60: 69 73 20 74 68 65 20 6c 6f 67 69 63 61 6c 20 75  is the logical u
2a70: 6e 69 6f 6e 20 6f 66 20 70 65 72 6d 20 70 65 72  nion of perm per
2a80: 6d 69 73 73 69 6f 6e 73 20 61 62 6f 76 65 20 77  missions above w
2a90: 69 74 68 0a 20 20 2a 2a 20 74 68 65 20 76 61 6c  ith.  ** the val
2aa0: 75 65 20 74 68 61 74 20 70 65 72 6d 20 77 6f 75  ue that perm wou
2ab0: 6c 64 20 74 61 6b 65 20 69 66 20 67 2e 7a 4c 6f  ld take if g.zLo
2ac0: 67 69 6e 20 77 65 72 65 20 22 61 6e 6f 6e 79 6d  gin were "anonym
2ad0: 6f 75 73 22 2e 20 2a 2f 0a 20 20 73 74 72 75 63  ous". */.  struc
2ae0: 74 20 46 6f 73 73 69 6c 55 73 65 72 50 65 72 6d  t FossilUserPerm
2af0: 73 20 61 6e 6f 6e 3b 0a 0a 23 69 66 64 65 66 20  s anon;..#ifdef 
2b00: 46 4f 53 53 49 4c 5f 45 4e 41 42 4c 45 5f 54 43  FOSSIL_ENABLE_TC
2b10: 4c 0a 20 20 2f 2a 20 61 6c 6c 20 54 63 6c 20 72  L.  /* all Tcl r
2b20: 65 6c 61 74 65 64 20 63 6f 6e 74 65 78 74 20 6e  elated context n
2b30: 65 63 65 73 73 61 72 79 20 66 6f 72 20 69 6e 74  ecessary for int
2b40: 65 67 72 61 74 69 6f 6e 20 2a 2f 0a 20 20 73 74  egration */.  st
2b50: 72 75 63 74 20 54 63 6c 43 6f 6e 74 65 78 74 20  ruct TclContext 
2b60: 74 63 6c 3b 0a 23 65 6e 64 69 66 0a 0a 20 20 2f  tcl;.#endif..  /
2b70: 2a 20 46 6f 72 20 64 65 66 65 6e 73 65 20 61 67  * For defense ag
2b80: 61 69 6e 73 74 20 43 72 6f 73 73 2d 73 69 74 65  ainst Cross-site
2b90: 20 52 65 71 75 65 73 74 20 46 6f 72 67 65 72 79   Request Forgery
2ba0: 20 61 74 74 61 63 6b 73 20 2a 2f 0a 20 20 63 68   attacks */.  ch
2bb0: 61 72 20 7a 43 73 72 66 54 6f 6b 65 6e 5b 31 32  ar zCsrfToken[12
2bc0: 5d 3b 20 20 20 20 2f 2a 20 56 61 6c 75 65 20 6f  ];    /* Value o
2bd0: 66 20 74 68 65 20 61 6e 74 69 2d 43 53 52 46 20  f the anti-CSRF 
2be0: 74 6f 6b 65 6e 20 2a 2f 0a 20 20 69 6e 74 20 6f  token */.  int o
2bf0: 6b 43 73 72 66 3b 20 20 20 20 20 20 20 20 20 20  kCsrf;          
2c00: 20 20 20 2f 2a 20 41 6e 74 69 2d 43 53 52 46 20     /* Anti-CSRF 
2c10: 74 6f 6b 65 6e 20 69 73 20 70 72 65 73 65 6e 74  token is present
2c20: 20 61 6e 64 20 76 61 6c 69 64 20 2a 2f 0a 0a 20   and valid */.. 
2c30: 20 69 6e 74 20 70 61 72 73 65 43 6e 74 5b 31 30   int parseCnt[10
2c40: 5d 3b 20 20 20 20 20 20 20 2f 2a 20 43 6f 75 6e  ];       /* Coun
2c50: 74 73 20 6f 66 20 61 72 74 69 66 61 63 74 73 20  ts of artifacts 
2c60: 70 61 72 73 65 64 20 2a 2f 0a 20 20 46 49 4c 45  parsed */.  FILE
2c70: 20 2a 66 44 65 62 75 67 3b 20 20 20 20 20 20 20   *fDebug;       
2c80: 20 20 20 20 2f 2a 20 57 72 69 74 65 20 64 65 62      /* Write deb
2c90: 75 67 20 69 6e 66 6f 72 6d 61 74 69 6f 6e 20 68  ug information h
2ca0: 65 72 65 2c 20 69 66 20 74 68 65 20 66 69 6c 65  ere, if the file
2cb0: 20 65 78 69 73 74 73 20 2a 2f 0a 23 69 66 64 65   exists */.#ifde
2cc0: 66 20 46 4f 53 53 49 4c 5f 45 4e 41 42 4c 45 5f  f FOSSIL_ENABLE_
2cd0: 54 48 31 5f 48 4f 4f 4b 53 0a 20 20 69 6e 74 20  TH1_HOOKS.  int 
2ce0: 66 4e 6f 54 68 48 6f 6f 6b 3b 20 20 20 20 20 20  fNoThHook;      
2cf0: 20 20 20 20 2f 2a 20 44 69 73 61 62 6c 65 20 61      /* Disable a
2d00: 6c 6c 20 54 48 31 20 63 6f 6d 6d 61 6e 64 2f 77  ll TH1 command/w
2d10: 65 62 70 61 67 65 20 68 6f 6f 6b 73 20 2a 2f 0a  ebpage hooks */.
2d20: 23 65 6e 64 69 66 0a 20 20 69 6e 74 20 74 68 54  #endif.  int thT
2d30: 72 61 63 65 3b 20 20 20 20 20 20 20 20 20 20 20  race;           
2d40: 20 2f 2a 20 54 72 75 65 20 74 6f 20 65 6e 61 62   /* True to enab
2d50: 6c 65 20 54 48 31 20 64 65 62 75 67 67 69 6e 67  le TH1 debugging
2d60: 20 6f 75 74 70 75 74 20 2a 2f 0a 20 20 42 6c 6f   output */.  Blo
2d70: 62 20 74 68 4c 6f 67 3b 20 20 20 20 20 20 20 20  b thLog;        
2d80: 20 20 20 20 20 2f 2a 20 54 65 78 74 20 6f 66 20       /* Text of 
2d90: 74 68 65 20 54 48 31 20 64 65 62 75 67 67 69 6e  the TH1 debuggin
2da0: 67 20 6f 75 74 70 75 74 20 2a 2f 0a 0a 20 20 69  g output */..  i
2db0: 6e 74 20 69 73 48 6f 6d 65 3b 20 20 20 20 20 20  nt isHome;      
2dc0: 20 20 20 20 20 20 20 2f 2a 20 54 72 75 65 20 69         /* True i
2dd0: 66 20 72 65 6e 64 65 72 69 6e 67 20 74 68 65 20  f rendering the 
2de0: 22 68 6f 6d 65 22 20 70 61 67 65 20 2a 2f 0a 0a  "home" page */..
2df0: 20 20 2f 2a 20 53 74 6f 72 61 67 65 20 66 6f 72    /* Storage for
2e00: 20 74 68 65 20 61 75 78 28 29 20 61 6e 64 2f 6f   the aux() and/o
2e10: 72 20 6f 70 74 69 6f 6e 28 29 20 53 51 4c 20 66  r option() SQL f
2e20: 75 6e 63 74 69 6f 6e 20 61 72 67 75 6d 65 6e 74  unction argument
2e30: 73 20 2a 2f 0a 20 20 69 6e 74 20 6e 41 75 78 3b  s */.  int nAux;
2e40: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
2e50: 20 20 20 20 2f 2a 20 4e 75 6d 62 65 72 20 6f 66      /* Number of
2e60: 20 64 69 73 74 69 6e 63 74 20 61 75 78 28 29 20   distinct aux() 
2e70: 6f 72 20 6f 70 74 69 6f 6e 28 29 20 76 61 6c 75  or option() valu
2e80: 65 73 20 2a 2f 0a 20 20 63 6f 6e 73 74 20 63 68  es */.  const ch
2e90: 61 72 20 2a 61 7a 41 75 78 4e 61 6d 65 5b 4d 58  ar *azAuxName[MX
2ea0: 5f 41 55 58 5d 3b 20 2f 2a 20 4e 61 6d 65 20 6f  _AUX]; /* Name o
2eb0: 66 20 65 61 63 68 20 61 75 78 28 29 20 6f 72 20  f each aux() or 
2ec0: 6f 70 74 69 6f 6e 28 29 20 76 61 6c 75 65 20 2a  option() value *
2ed0: 2f 0a 20 20 63 68 61 72 20 2a 61 7a 41 75 78 50  /.  char *azAuxP
2ee0: 61 72 61 6d 5b 4d 58 5f 41 55 58 5d 3b 20 20 20  aram[MX_AUX];   
2ef0: 20 20 20 2f 2a 20 50 61 72 61 6d 20 6f 66 20 65     /* Param of e
2f00: 61 63 68 20 61 75 78 28 29 20 6f 72 20 6f 70 74  ach aux() or opt
2f10: 69 6f 6e 28 29 20 76 61 6c 75 65 20 2a 2f 0a 20  ion() value */. 
2f20: 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 61 7a 41   const char *azA
2f30: 75 78 56 61 6c 5b 4d 58 5f 41 55 58 5d 3b 20 20  uxVal[MX_AUX];  
2f40: 2f 2a 20 56 61 6c 75 65 20 6f 66 20 65 61 63 68  /* Value of each
2f50: 20 61 75 78 28 29 20 6f 72 20 6f 70 74 69 6f 6e   aux() or option
2f60: 28 29 20 76 61 6c 75 65 20 2a 2f 0a 20 20 63 6f  () value */.  co
2f70: 6e 73 74 20 63 68 61 72 20 2a 2a 61 7a 41 75 78  nst char **azAux
2f80: 4f 70 74 5b 4d 58 5f 41 55 58 5d 3b 20 2f 2a 20  Opt[MX_AUX]; /* 
2f90: 4f 70 74 69 6f 6e 73 20 6f 66 20 65 61 63 68 20  Options of each 
2fa0: 6f 70 74 69 6f 6e 28 29 20 76 61 6c 75 65 20 2a  option() value *
2fb0: 2f 0a 20 20 69 6e 74 20 61 6e 41 75 78 43 6f 6c  /.  int anAuxCol
2fc0: 73 5b 4d 58 5f 41 55 58 5d 3b 20 20 20 20 20 20  s[MX_AUX];      
2fd0: 20 20 20 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 20     /* Number of 
2fe0: 63 6f 6c 75 6d 6e 73 20 66 6f 72 20 6f 70 74 69  columns for opti
2ff0: 6f 6e 28 29 20 76 61 6c 75 65 73 20 2a 2f 0a 20  on() values */. 
3000: 20 69 6e 74 20 61 6c 6c 6f 77 53 79 6d 6c 69 6e   int allowSymlin
3010: 6b 73 3b 20 20 20 20 20 20 20 20 20 20 20 20 20  ks;             
3020: 2f 2a 20 43 61 63 68 65 64 20 22 61 6c 6c 6f 77  /* Cached "allow
3030: 2d 73 79 6d 6c 69 6e 6b 73 22 20 6f 70 74 69 6f  -symlinks" optio
3040: 6e 20 2a 2f 0a 20 20 69 6e 74 20 6d 61 69 6e 54  n */.  int mainT
3050: 69 6d 65 72 49 64 3b 20 20 20 20 20 20 20 20 20  imerId;         
3060: 20 20 20 20 20 20 2f 2a 20 53 65 74 20 74 6f 20        /* Set to 
3070: 66 6f 73 73 69 6c 5f 74 69 6d 65 72 5f 73 74 61  fossil_timer_sta
3080: 72 74 28 29 20 2a 2f 0a 20 20 69 6e 74 20 6e 50  rt() */.  int nP
3090: 65 6e 64 69 6e 67 52 65 71 75 65 73 74 3b 20 20  endingRequest;  
30a0: 20 20 20 20 20 20 20 20 20 2f 2a 20 23 20 6f 66           /* # of
30b0: 20 48 54 54 50 20 72 65 71 75 65 73 74 73 20 69   HTTP requests i
30c0: 6e 20 22 66 6f 73 73 69 6c 20 73 65 72 76 65 72  n "fossil server
30d0: 22 20 2a 2f 0a 20 20 69 6e 74 20 6e 52 65 71 75  " */.  int nRequ
30e0: 65 73 74 3b 20 20 20 20 20 20 20 20 20 20 20 20  est;            
30f0: 20 20 20 20 20 20 2f 2a 20 54 6f 74 61 6c 20 23        /* Total #
3100: 20 6f 66 20 48 54 54 50 20 72 65 71 75 65 73 74   of HTTP request
3110: 20 2a 2f 0a 23 69 66 64 65 66 20 46 4f 53 53 49   */.#ifdef FOSSI
3120: 4c 5f 45 4e 41 42 4c 45 5f 4a 53 4f 4e 0a 20 20  L_ENABLE_JSON.  
3130: 73 74 72 75 63 74 20 46 6f 73 73 69 6c 4a 73 6f  struct FossilJso
3140: 6e 42 69 74 73 20 7b 0a 20 20 20 20 69 6e 74 20  nBits {.    int 
3150: 69 73 4a 73 6f 6e 4d 6f 64 65 3b 20 20 20 20 20  isJsonMode;     
3160: 20 20 20 20 20 20 20 2f 2a 20 54 72 75 65 20 69         /* True i
3170: 66 20 72 75 6e 6e 69 6e 67 20 69 6e 20 4a 53 4f  f running in JSO
3180: 4e 20 6d 6f 64 65 2c 20 65 6c 73 65 0a 20 20 20  N mode, else.   
3190: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
31a0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 66                 f
31b0: 61 6c 73 65 2e 20 54 68 69 73 20 63 68 61 6e 67  alse. This chang
31c0: 65 73 20 68 6f 77 20 65 72 72 6f 72 73 20 61 72  es how errors ar
31d0: 65 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20  e.              
31e0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
31f0: 20 20 20 20 72 65 70 6f 72 74 65 64 2e 20 49 6e      reported. In
3200: 20 4a 53 4f 4e 20 6d 6f 64 65 20 77 65 20 74 72   JSON mode we tr
3210: 79 20 74 6f 0a 20 20 20 20 20 20 20 20 20 20 20  y to.           
3220: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
3230: 20 20 20 20 20 20 20 61 6c 77 61 79 73 20 6f 75         always ou
3240: 74 70 75 74 20 4a 53 4f 4e 2d 66 6f 72 6d 20 65  tput JSON-form e
3250: 72 72 6f 72 0a 20 20 20 20 20 20 20 20 20 20 20  rror.           
3260: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
3270: 20 20 20 20 20 20 20 72 65 73 70 6f 6e 73 65 73         responses
3280: 20 61 6e 64 20 61 6c 77 61 79 73 20 65 78 69 74   and always exit
3290: 28 29 20 77 69 74 68 0a 20 20 20 20 20 20 20 20  () with.        
32a0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
32b0: 20 20 20 20 20 20 20 20 20 20 63 6f 64 65 20 30            code 0
32c0: 20 74 6f 20 61 76 6f 69 64 20 61 6e 20 48 54 54   to avoid an HTT
32d0: 50 20 35 30 30 20 65 72 72 6f 72 2e 0a 20 20 20  P 500 error..   
32e0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
32f0: 20 20 20 20 20 20 20 20 20 20 20 20 2a 2f 0a 20              */. 
3300: 20 20 20 69 6e 74 20 72 65 73 75 6c 74 43 6f 64     int resultCod
3310: 65 3b 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a  e;            /*
3320: 20 75 73 65 64 20 66 6f 72 20 70 61 73 73 69 6e   used for passin
3330: 67 20 62 61 63 6b 20 73 70 65 63 69 66 69 63 20  g back specific 
3340: 63 6f 64 65 73 0a 20 20 20 20 20 20 20 20 20 20  codes.          
3350: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
3360: 20 20 20 20 20 2a 2a 20 66 72 6f 6d 20 2f 6a 73       ** from /js
3370: 6f 6e 20 63 61 6c 6c 62 61 63 6b 73 2e 20 2a 2f  on callbacks. */
3380: 0a 20 20 20 20 69 6e 74 20 65 72 72 6f 72 44 65  .    int errorDe
3390: 74 61 69 6c 50 61 72 61 6e 6f 69 61 3b 20 20 20  tailParanoia;   
33a0: 2f 2a 20 30 3d 66 75 6c 6c 20 65 72 72 6f 72 20  /* 0=full error 
33b0: 63 6f 64 65 73 2c 20 31 3d 25 31 30 2c 20 32 3d  codes, 1=%10, 2=
33c0: 25 31 30 30 2c 20 33 3d 25 31 30 30 30 20 2a 2f  %100, 3=%1000 */
33d0: 0a 20 20 20 20 63 73 6f 6e 5f 6f 75 74 70 75 74  .    cson_output
33e0: 5f 6f 70 74 20 6f 75 74 4f 70 74 3b 20 20 20 20  _opt outOpt;    
33f0: 2f 2a 20 66 6f 72 6d 61 74 74 69 6e 67 20 6f 70  /* formatting op
3400: 74 69 6f 6e 73 20 66 6f 72 20 4a 53 4f 4e 20 6d  tions for JSON m
3410: 6f 64 65 2e 20 2a 2f 0a 20 20 20 20 63 73 6f 6e  ode. */.    cson
3420: 5f 76 61 6c 75 65 20 2a 61 75 74 68 54 6f 6b 65  _value *authToke
3430: 6e 3b 20 20 20 20 20 2f 2a 20 61 75 74 68 65 6e  n;     /* authen
3440: 74 69 63 61 74 69 6f 6e 20 74 6f 6b 65 6e 20 2a  tication token *
3450: 2f 0a 20 20 20 20 63 6f 6e 73 74 20 63 68 61 72  /.    const char
3460: 20 2a 6a 73 6f 6e 70 3b 20 20 20 20 20 20 20 20   *jsonp;        
3470: 20 2f 2a 20 4e 61 6d 65 20 6f 66 20 4a 53 4f 4e   /* Name of JSON
3480: 50 20 66 75 6e 63 74 69 6f 6e 20 77 72 61 70 70  P function wrapp
3490: 65 72 2e 20 2a 2f 0a 20 20 20 20 75 6e 73 69 67  er. */.    unsig
34a0: 6e 65 64 20 63 68 61 72 20 64 69 73 70 61 74 63  ned char dispatc
34b0: 68 44 65 70 74 68 20 2f 2a 20 54 65 6c 6c 73 20  hDepth /* Tells 
34c0: 4a 53 4f 4e 20 63 6f 6d 6d 61 6e 64 20 64 69 73  JSON command dis
34d0: 70 61 74 63 68 69 6e 67 0a 20 20 20 20 20 20 20  patching.       
34e0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
34f0: 20 20 20 20 20 20 20 20 20 20 20 20 77 68 69 63              whic
3500: 68 20 61 72 67 75 6d 65 6e 74 20 77 65 20 61 72  h argument we ar
3510: 65 20 63 75 72 72 65 6e 74 6c 79 0a 20 20 20 20  e currently.    
3520: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
3530: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 77                 w
3540: 6f 72 6b 69 6e 67 20 6f 6e 2e 20 46 6f 72 20 74  orking on. For t
3550: 68 69 73 20 70 75 72 70 6f 73 65 2c 20 61 72 67  his purpose, arg
3560: 23 30 0a 20 20 20 20 20 20 20 20 20 20 20 20 20  #0.             
3570: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
3580: 20 20 20 20 20 20 69 73 20 74 68 65 20 22 6a 73        is the "js
3590: 6f 6e 22 20 70 61 74 68 2f 43 4c 49 20 61 72 67  on" path/CLI arg
35a0: 2e 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20  ..              
35b0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
35c0: 20 20 2a 2f 3b 0a 20 20 20 20 73 74 72 75 63 74    */;.    struct
35d0: 20 7b 20 20 20 20 20 20 20 20 20 20 20 20 20 20   {              
35e0: 20 20 20 20 20 2f 2a 20 22 67 61 72 62 61 67 65       /* "garbage
35f0: 20 63 6f 6c 6c 65 63 74 6f 72 22 20 2a 2f 0a 20   collector" */. 
3600: 20 20 20 20 20 63 73 6f 6e 5f 76 61 6c 75 65 20       cson_value 
3610: 2a 76 3b 0a 20 20 20 20 20 20 63 73 6f 6e 5f 61  *v;.      cson_a
3620: 72 72 61 79 20 2a 61 3b 0a 20 20 20 20 7d 20 67  rray *a;.    } g
3630: 63 3b 0a 20 20 20 20 73 74 72 75 63 74 20 7b 20  c;.    struct { 
3640: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
3650: 20 20 2f 2a 20 4a 53 4f 4e 20 50 4f 53 54 20 64    /* JSON POST d
3660: 61 74 61 2e 20 2a 2f 0a 20 20 20 20 20 20 63 73  ata. */.      cs
3670: 6f 6e 5f 76 61 6c 75 65 20 2a 76 3b 0a 20 20 20  on_value *v;.   
3680: 20 20 20 63 73 6f 6e 5f 61 72 72 61 79 20 2a 61     cson_array *a
3690: 3b 0a 20 20 20 20 20 20 69 6e 74 20 6f 66 66 73  ;.      int offs
36a0: 65 74 3b 20 20 20 20 20 20 20 20 20 20 20 20 20  et;             
36b0: 20 2f 2a 20 54 65 6c 6c 73 20 75 73 20 77 68 69   /* Tells us whi
36c0: 63 68 20 50 41 54 48 5f 49 4e 46 4f 2f 43 4c 49  ch PATH_INFO/CLI
36d0: 20 61 72 67 73 0a 20 20 20 20 20 20 20 20 20 20   args.          
36e0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
36f0: 20 20 20 20 20 20 20 20 70 61 72 74 20 68 6f 6c          part hol
3700: 64 73 20 74 68 65 20 22 6a 73 6f 6e 22 20 63 6f  ds the "json" co
3710: 6d 6d 61 6e 64 2c 20 73 6f 0a 20 20 20 20 20 20  mmand, so.      
3720: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
3730: 20 20 20 20 20 20 20 20 20 20 20 20 74 68 61 74              that
3740: 20 77 65 20 63 61 6e 20 61 63 63 6f 75 6e 74 20   we can account 
3750: 66 6f 72 20 73 75 62 2d 72 65 70 6f 73 0a 20 20  for sub-repos.  
3760: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
3770: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
3780: 61 6e 64 20 70 61 74 68 20 70 72 65 66 69 78 65  and path prefixe
3790: 73 2e 20 20 54 68 69 73 20 69 73 20 68 61 6e 64  s.  This is hand
37a0: 6c 65 64 0a 20 20 20 20 20 20 20 20 20 20 20 20  led.            
37b0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
37c0: 20 20 20 20 20 20 64 69 66 66 65 72 65 6e 74 6c        differentl
37d0: 79 20 66 6f 72 20 43 4c 49 20 61 6e 64 20 43 47  y for CLI and CG
37e0: 49 20 6d 6f 64 65 73 2e 0a 20 20 20 20 20 20 20  I modes..       
37f0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
3800: 20 20 20 20 20 20 20 20 2a 2f 0a 20 20 20 20 20          */.     
3810: 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 63 6f 6d   const char *com
3820: 6d 61 6e 64 53 74 72 20 20 20 2f 2a 22 63 6f 6d  mandStr   /*"com
3830: 6d 61 6e 64 22 20 72 65 71 75 65 73 74 20 70 61  mand" request pa
3840: 72 61 6d 2e 2a 2f 3b 0a 20 20 20 20 7d 20 63 6d  ram.*/;.    } cm
3850: 64 3b 0a 20 20 20 20 73 74 72 75 63 74 20 7b 20  d;.    struct { 
3860: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
3870: 20 20 2f 2a 20 4a 53 4f 4e 20 50 4f 53 54 20 64    /* JSON POST d
3880: 61 74 61 2e 20 2a 2f 0a 20 20 20 20 20 20 63 73  ata. */.      cs
3890: 6f 6e 5f 76 61 6c 75 65 20 2a 76 3b 0a 20 20 20  on_value *v;.   
38a0: 20 20 20 63 73 6f 6e 5f 6f 62 6a 65 63 74 20 2a     cson_object *
38b0: 6f 3b 0a 20 20 20 20 7d 20 70 6f 73 74 3b 0a 20  o;.    } post;. 
38c0: 20 20 20 73 74 72 75 63 74 20 7b 20 20 20 20 20     struct {     
38d0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a                /*
38e0: 20 47 45 54 2f 43 4f 4f 4b 49 45 20 70 61 72 61   GET/COOKIE para
38f0: 6d 73 20 69 6e 20 4a 53 4f 4e 20 6d 6f 64 65 2e  ms in JSON mode.
3900: 20 2a 2f 0a 20 20 20 20 20 20 63 73 6f 6e 5f 76   */.      cson_v
3910: 61 6c 75 65 20 2a 76 3b 0a 20 20 20 20 20 20 63  alue *v;.      c
3920: 73 6f 6e 5f 6f 62 6a 65 63 74 20 2a 6f 3b 0a 20  son_object *o;. 
3930: 20 20 20 7d 20 70 61 72 61 6d 3b 0a 20 20 20 20     } param;.    
3940: 73 74 72 75 63 74 20 7b 0a 20 20 20 20 20 20 63  struct {.      c
3950: 73 6f 6e 5f 76 61 6c 75 65 20 2a 76 3b 0a 20 20  son_value *v;.  
3960: 20 20 20 20 63 73 6f 6e 5f 6f 62 6a 65 63 74 20      cson_object 
3970: 2a 6f 3b 0a 20 20 20 20 7d 20 72 65 71 50 61 79  *o;.    } reqPay
3980: 6c 6f 61 64 3b 20 20 20 20 20 20 20 20 20 20 20  load;           
3990: 20 20 20 2f 2a 20 72 65 71 75 65 73 74 20 70 61     /* request pa
39a0: 79 6c 6f 61 64 20 6f 62 6a 65 63 74 20 28 69 66  yload object (if
39b0: 20 61 6e 79 29 20 2a 2f 0a 20 20 20 20 63 73 6f   any) */.    cso
39c0: 6e 5f 61 72 72 61 79 20 2a 77 61 72 6e 69 6e 67  n_array *warning
39d0: 73 3b 20 20 20 20 20 20 2f 2a 20 72 65 73 70 6f  s;      /* respo
39e0: 6e 73 65 20 77 61 72 6e 69 6e 67 73 20 2a 2f 0a  nse warnings */.
39f0: 20 20 20 20 69 6e 74 20 74 69 6d 65 72 49 64 3b      int timerId;
3a00: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f                 /
3a10: 2a 20 66 65 74 63 68 65 64 20 66 72 6f 6d 20 66  * fetched from f
3a20: 6f 73 73 69 6c 5f 74 69 6d 65 72 5f 73 74 61 72  ossil_timer_star
3a30: 74 28 29 20 2a 2f 0a 20 20 7d 20 6a 73 6f 6e 3b  t() */.  } json;
3a40: 0a 23 65 6e 64 69 66 20 2f 2a 20 46 4f 53 53 49  .#endif /* FOSSI
3a50: 4c 5f 45 4e 41 42 4c 45 5f 4a 53 4f 4e 20 2a 2f  L_ENABLE_JSON */
3a60: 0a 7d 3b 0a 0a 2f 2a 0a 2a 2a 20 4d 61 63 72 6f  .};../*.** Macro
3a70: 20 66 6f 72 20 64 65 62 75 67 67 69 6e 67 3a 0a   for debugging:.
3a80: 2a 2f 0a 23 64 65 66 69 6e 65 20 43 47 49 44 45  */.#define CGIDE
3a90: 42 55 47 28 58 29 20 20 69 66 28 20 67 2e 66 44  BUG(X)  if( g.fD
3aa0: 65 62 75 67 20 29 20 63 67 69 5f 64 65 62 75 67  ebug ) cgi_debug
3ab0: 20 58 0a 0a 23 65 6e 64 69 66 0a 0a 47 6c 6f 62   X..#endif..Glob
3ac0: 61 6c 20 67 3b 0a 0a 2f 2a 0a 2a 2a 20 61 74 65  al g;../*.** ate
3ad0: 78 69 74 28 29 20 68 61 6e 64 6c 65 72 20 77 68  xit() handler wh
3ae0: 69 63 68 20 66 72 65 65 73 20 75 70 20 22 73 6f  ich frees up "so
3af0: 6d 65 22 20 6f 66 20 74 68 65 20 72 65 73 6f 75  me" of the resou
3b00: 72 63 65 73 0a 2a 2a 20 75 73 65 64 20 62 79 20  rces.** used by 
3b10: 66 6f 73 73 69 6c 2e 0a 2a 2f 0a 73 74 61 74 69  fossil..*/.stati
3b20: 63 20 76 6f 69 64 20 66 6f 73 73 69 6c 5f 61 74  c void fossil_at
3b30: 65 78 69 74 28 76 6f 69 64 29 20 7b 0a 23 69 66  exit(void) {.#if
3b40: 20 55 53 45 5f 53 45 45 0a 20 20 2f 2a 0a 20 20   USE_SEE.  /*.  
3b50: 2a 2a 20 5a 65 72 6f 2c 20 75 6e 6c 6f 63 6b 2c  ** Zero, unlock,
3b60: 20 61 6e 64 20 66 72 65 65 20 74 68 65 20 73 61   and free the sa
3b70: 76 65 64 20 64 61 74 61 62 61 73 65 20 65 6e 63  ved database enc
3b80: 72 79 70 74 69 6f 6e 20 6b 65 79 20 6e 6f 77 2e  ryption key now.
3b90: 0a 20 20 2a 2f 0a 20 20 64 62 5f 75 6e 73 61 76  .  */.  db_unsav
3ba0: 65 5f 65 6e 63 72 79 70 74 69 6f 6e 5f 6b 65 79  e_encryption_key
3bb0: 28 29 3b 0a 23 65 6e 64 69 66 0a 23 69 66 20 64  ();.#endif.#if d
3bc0: 65 66 69 6e 65 64 28 5f 57 49 4e 33 32 29 20 7c  efined(_WIN32) |
3bd0: 7c 20 64 65 66 69 6e 65 64 28 5f 5f 42 49 4f 4e  | defined(__BION
3be0: 49 43 5f 5f 29 0a 20 20 2f 2a 0a 20 20 2a 2a 20  IC__).  /*.  ** 
3bf0: 46 72 65 65 20 74 68 65 20 73 65 63 75 72 65 20  Free the secure 
3c00: 67 65 74 70 61 73 73 28 29 20 62 75 66 66 65 72  getpass() buffer
3c10: 20 6e 6f 77 2e 0a 20 20 2a 2f 0a 20 20 66 72 65   now..  */.  fre
3c20: 65 70 61 73 73 28 29 3b 0a 23 65 6e 64 69 66 0a  epass();.#endif.
3c30: 23 69 66 20 64 65 66 69 6e 65 64 28 5f 57 49 4e  #if defined(_WIN
3c40: 33 32 29 20 26 26 20 21 64 65 66 69 6e 65 64 28  32) && !defined(
3c50: 5f 57 49 4e 36 34 29 20 26 26 20 64 65 66 69 6e  _WIN64) && defin
3c60: 65 64 28 46 4f 53 53 49 4c 5f 45 4e 41 42 4c 45  ed(FOSSIL_ENABLE
3c70: 5f 54 43 4c 29 20 26 26 20 5c 0a 20 20 20 20 64  _TCL) && \.    d
3c80: 65 66 69 6e 65 64 28 55 53 45 5f 54 43 4c 5f 53  efined(USE_TCL_S
3c90: 54 55 42 53 29 0a 20 20 2f 2a 0a 20 20 2a 2a 20  TUBS).  /*.  ** 
3ca0: 49 66 20 54 63 6c 20 69 73 20 63 6f 6d 70 69 6c  If Tcl is compil
3cb0: 65 64 20 6f 6e 20 57 69 6e 64 6f 77 73 20 75 73  ed on Windows us
3cc0: 69 6e 67 20 74 68 65 20 6c 61 74 65 73 74 20 4d  ing the latest M
3cd0: 69 6e 47 57 2c 20 46 6f 73 73 69 6c 20 63 61 6e  inGW, Fossil can
3ce0: 20 63 72 61 73 68 0a 20 20 2a 2a 20 77 68 65 6e   crash.  ** when
3cf0: 20 65 78 69 74 69 6e 67 20 77 68 69 6c 65 20 61   exiting while a
3d00: 20 73 74 75 62 73 2d 65 6e 61 62 6c 65 64 20 54   stubs-enabled T
3d10: 63 6c 20 69 73 20 73 74 69 6c 6c 20 6c 6f 61 64  cl is still load
3d20: 65 64 2e 20 20 54 68 69 73 20 69 73 20 64 75 65  ed.  This is due
3d30: 20 74 6f 0a 20 20 2a 2a 20 61 20 62 75 67 20 69   to.  ** a bug i
3d40: 6e 20 4d 69 6e 47 57 2c 20 73 65 65 3a 0a 20 20  n MinGW, see:.  
3d50: 2a 2a 0a 20 20 2a 2a 20 20 20 20 20 68 74 74 70  **.  **     http
3d60: 3a 2f 2f 63 6f 6d 6d 65 6e 74 73 2e 67 6d 61 6e  ://comments.gman
3d70: 65 2e 6f 72 67 2f 67 6d 61 6e 65 2e 63 6f 6d 70  e.org/gmane.comp
3d80: 2e 67 6e 75 2e 6d 69 6e 67 77 2e 75 73 65 72 2f  .gnu.mingw.user/
3d90: 34 31 37 32 34 0a 20 20 2a 2a 0a 20 20 2a 2a 20  41724.  **.  ** 
3da0: 54 68 65 20 77 6f 72 6b 61 72 6f 75 6e 64 20 69  The workaround i
3db0: 73 20 74 6f 20 6d 61 6e 75 61 6c 6c 79 20 75 6e  s to manually un
3dc0: 6c 6f 61 64 20 74 68 65 20 6c 6f 61 64 65 64 20  load the loaded 
3dd0: 54 63 6c 20 6c 69 62 72 61 72 79 20 70 72 69 6f  Tcl library prio
3de0: 72 20 74 6f 0a 20 20 2a 2a 20 65 78 69 74 69 6e  r to.  ** exitin
3df0: 67 20 74 68 65 20 70 72 6f 63 65 73 73 2e 20 20  g the process.  
3e00: 54 68 69 73 20 69 73 73 75 65 20 64 6f 65 73 20  This issue does 
3e10: 6e 6f 74 20 69 6d 70 61 63 74 20 36 34 2d 62 69  not impact 64-bi
3e20: 74 20 57 69 6e 64 6f 77 73 2e 0a 20 20 2a 2f 0a  t Windows..  */.
3e30: 20 20 75 6e 6c 6f 61 64 54 63 6c 28 67 2e 69 6e    unloadTcl(g.in
3e40: 74 65 72 70 2c 20 26 67 2e 74 63 6c 29 3b 0a 23  terp, &g.tcl);.#
3e50: 65 6e 64 69 66 0a 23 69 66 64 65 66 20 46 4f 53  endif.#ifdef FOS
3e60: 53 49 4c 5f 45 4e 41 42 4c 45 5f 4a 53 4f 4e 0a  SIL_ENABLE_JSON.
3e70: 20 20 63 73 6f 6e 5f 76 61 6c 75 65 5f 66 72 65    cson_value_fre
3e80: 65 28 67 2e 6a 73 6f 6e 2e 67 63 2e 76 29 3b 0a  e(g.json.gc.v);.
3e90: 20 20 6d 65 6d 73 65 74 28 26 67 2e 6a 73 6f 6e    memset(&g.json
3ea0: 2c 20 30 2c 20 73 69 7a 65 6f 66 28 67 2e 6a 73  , 0, sizeof(g.js
3eb0: 6f 6e 29 29 3b 0a 23 65 6e 64 69 66 0a 20 20 66  on));.#endif.  f
3ec0: 72 65 65 28 67 2e 7a 45 72 72 4d 73 67 29 3b 0a  ree(g.zErrMsg);.
3ed0: 20 20 69 66 28 67 2e 64 62 29 7b 0a 20 20 20 20    if(g.db){.    
3ee0: 64 62 5f 63 6c 6f 73 65 28 30 29 3b 0a 20 20 7d  db_close(0);.  }
3ef0: 0a 20 20 2f 2a 0a 20 20 2a 2a 20 46 49 58 4d 45  .  /*.  ** FIXME
3f00: 3a 20 54 68 65 20 6e 65 78 74 20 74 77 6f 20 6c  : The next two l
3f10: 69 6e 65 73 20 63 61 6e 6e 6f 74 20 61 6c 77 61  ines cannot alwa
3f20: 79 73 20 62 65 20 65 6e 61 62 6c 65 64 3b 20 68  ys be enabled; h
3f30: 6f 77 65 76 65 72 2c 20 74 68 65 79 0a 20 20 2a  owever, they.  *
3f40: 2a 20 20 20 20 20 20 20 20 61 72 65 20 76 65 72  *        are ver
3f50: 79 20 75 73 65 66 75 6c 20 66 6f 72 20 74 72 61  y useful for tra
3f60: 63 6b 69 6e 67 20 64 6f 77 6e 20 54 48 31 20 6d  cking down TH1 m
3f70: 65 6d 6f 72 79 20 6c 65 61 6b 73 2e 0a 20 20 2a  emory leaks..  *
3f80: 2f 0a 20 20 69 66 28 20 66 6f 73 73 69 6c 5f 67  /.  if( fossil_g
3f90: 65 74 65 6e 76 28 22 54 48 31 5f 44 45 4c 45 54  etenv("TH1_DELET
3fa0: 45 5f 49 4e 54 45 52 50 22 29 21 3d 30 20 29 7b  E_INTERP")!=0 ){
3fb0: 0a 20 20 20 20 69 66 28 20 67 2e 69 6e 74 65 72  .    if( g.inter
3fc0: 70 20 29 7b 0a 20 20 20 20 20 20 54 68 5f 44 65  p ){.      Th_De
3fd0: 6c 65 74 65 49 6e 74 65 72 70 28 67 2e 69 6e 74  leteInterp(g.int
3fe0: 65 72 70 29 3b 20 67 2e 69 6e 74 65 72 70 20 3d  erp); g.interp =
3ff0: 20 30 3b 0a 20 20 20 20 7d 0a 20 20 20 20 61 73   0;.    }.    as
4000: 73 65 72 74 28 20 54 68 5f 47 65 74 4f 75 74 73  sert( Th_GetOuts
4010: 74 61 6e 64 69 6e 67 4d 61 6c 6c 6f 63 28 29 3d  tandingMalloc()=
4020: 3d 30 20 29 3b 0a 20 20 7d 0a 7d 0a 0a 2f 2a 0a  =0 );.  }.}../*.
4030: 2a 2a 20 43 6f 6e 76 65 72 74 20 61 6c 6c 20 61  ** Convert all a
4040: 72 67 75 6d 65 6e 74 73 20 66 72 6f 6d 20 6d 62  rguments from mb
4050: 63 73 20 28 6f 72 20 75 6e 69 63 6f 64 65 29 20  cs (or unicode) 
4060: 74 6f 20 55 54 46 2d 38 2e 20 54 68 65 6e 0a 2a  to UTF-8. Then.*
4070: 2a 20 73 65 61 72 63 68 20 67 2e 61 72 67 76 20  * search g.argv 
4080: 66 6f 72 20 61 72 67 75 6d 65 6e 74 73 20 22 2d  for arguments "-
4090: 2d 61 72 67 73 20 46 49 4c 45 4e 41 4d 45 22 2e  -args FILENAME".
40a0: 20 49 66 20 66 6f 75 6e 64 2c 20 74 68 65 6e 0a   If found, then.
40b0: 2a 2a 20 28 31 29 20 72 65 6d 6f 76 65 20 74 68  ** (1) remove th
40c0: 65 20 74 77 6f 20 61 72 67 75 6d 65 6e 74 73 20  e two arguments 
40d0: 66 72 6f 6d 20 67 2e 61 72 67 76 0a 2a 2a 20 28  from g.argv.** (
40e0: 32 29 20 52 65 61 64 20 74 68 65 20 66 69 6c 65  2) Read the file
40f0: 20 46 49 4c 45 4e 41 4d 45 0a 2a 2a 20 28 33 29   FILENAME.** (3)
4100: 20 55 73 65 20 74 68 65 20 63 6f 6e 74 65 6e 74   Use the content
4110: 73 20 6f 66 20 46 49 4c 45 20 74 6f 20 72 65 70  s of FILE to rep
4120: 6c 61 63 65 20 74 68 65 20 74 77 6f 20 72 65 6d  lace the two rem
4130: 6f 76 65 64 20 61 72 67 75 6d 65 6e 74 73 3a 0a  oved arguments:.
4140: 2a 2a 20 20 20 20 20 28 61 29 20 49 67 6e 6f 72  **     (a) Ignor
4150: 65 20 62 6c 61 6e 6b 20 6c 69 6e 65 73 20 69 6e  e blank lines in
4160: 20 74 68 65 20 66 69 6c 65 0a 2a 2a 20 20 20 20   the file.**    
4170: 20 28 62 29 20 45 61 63 68 20 6e 6f 6e 2d 65 6d   (b) Each non-em
4180: 70 74 79 20 6c 69 6e 65 20 6f 66 20 74 68 65 20  pty line of the 
4190: 66 69 6c 65 20 69 73 20 61 6e 20 61 72 67 75 6d  file is an argum
41a0: 65 6e 74 2c 20 65 78 63 65 70 74 0a 2a 2a 20 20  ent, except.**  
41b0: 20 20 20 28 63 29 20 49 66 20 74 68 65 20 6c 69     (c) If the li
41c0: 6e 65 20 62 65 67 69 6e 73 20 77 69 74 68 20 22  ne begins with "
41d0: 2d 22 20 61 6e 64 20 63 6f 6e 74 61 69 6e 73 20  -" and contains 
41e0: 61 20 73 70 61 63 65 2c 20 69 74 20 69 73 20 62  a space, it is b
41f0: 72 6f 6b 65 6e 0a 2a 2a 20 20 20 20 20 20 20 20  roken.**        
4200: 20 69 6e 74 6f 20 74 77 6f 20 61 72 67 75 6d 65   into two argume
4210: 6e 74 73 20 61 74 20 74 68 65 20 73 70 61 63 65  nts at the space
4220: 2e 0a 2a 2f 0a 73 74 61 74 69 63 20 76 6f 69 64  ..*/.static void
4230: 20 65 78 70 61 6e 64 5f 61 72 67 73 5f 6f 70 74   expand_args_opt
4240: 69 6f 6e 28 69 6e 74 20 61 72 67 63 2c 20 76 6f  ion(int argc, vo
4250: 69 64 20 2a 61 72 67 76 29 7b 0a 20 20 42 6c 6f  id *argv){.  Blo
4260: 62 20 66 69 6c 65 20 3d 20 65 6d 70 74 79 5f 62  b file = empty_b
4270: 6c 6f 62 3b 20 20 20 2f 2a 20 43 6f 6e 74 65 6e  lob;   /* Conten
4280: 74 20 6f 66 20 74 68 65 20 66 69 6c 65 20 2a 2f  t of the file */
4290: 0a 20 20 42 6c 6f 62 20 6c 69 6e 65 20 3d 20 65  .  Blob line = e
42a0: 6d 70 74 79 5f 62 6c 6f 62 3b 20 20 20 2f 2a 20  mpty_blob;   /* 
42b0: 4f 6e 65 20 6c 69 6e 65 20 6f 66 20 74 68 65 20  One line of the 
42c0: 66 69 6c 65 20 2a 2f 0a 20 20 75 6e 73 69 67 6e  file */.  unsign
42d0: 65 64 20 69 6e 74 20 6e 4c 69 6e 65 3b 20 20 20  ed int nLine;   
42e0: 20 20 20 20 2f 2a 20 4e 75 6d 62 65 72 20 6f 66      /* Number of
42f0: 20 6c 69 6e 65 73 20 69 6e 20 74 68 65 20 66 69   lines in the fi
4300: 6c 65 2a 2f 0a 20 20 75 6e 73 69 67 6e 65 64 20  le*/.  unsigned 
4310: 69 6e 74 20 69 2c 20 6a 2c 20 6b 3b 20 20 20 20  int i, j, k;    
4320: 20 2f 2a 20 4c 6f 6f 70 20 63 6f 75 6e 74 65 72   /* Loop counter
4330: 73 20 2a 2f 0a 20 20 69 6e 74 20 6e 3b 20 20 20  s */.  int n;   
4340: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
4350: 20 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 20 62 79   /* Number of by
4360: 74 65 73 20 69 6e 20 6f 6e 65 20 6c 69 6e 65 20  tes in one line 
4370: 2a 2f 0a 20 20 75 6e 73 69 67 6e 65 64 20 69 6e  */.  unsigned in
4380: 74 20 6e 41 72 67 3b 20 20 20 20 20 20 20 20 2f  t nArg;        /
4390: 2a 20 4e 75 6d 62 65 72 20 6f 66 20 6e 65 77 20  * Number of new 
43a0: 61 72 67 75 6d 65 6e 74 73 20 2a 2f 0a 20 20 63  arguments */.  c
43b0: 68 61 72 20 2a 7a 3b 20 20 20 20 20 20 20 20 20  har *z;         
43c0: 20 20 20 20 20 20 20 20 20 2f 2a 20 47 65 6e 65           /* Gene
43d0: 72 61 6c 20 75 73 65 20 73 74 72 69 6e 67 20 70  ral use string p
43e0: 6f 69 6e 74 65 72 20 2a 2f 0a 20 20 63 68 61 72  ointer */.  char
43f0: 20 2a 2a 6e 65 77 41 72 67 76 3b 20 20 20 20 20   **newArgv;     
4400: 20 20 20 20 20 20 2f 2a 20 4e 65 77 20 65 78 70        /* New exp
4410: 61 6e 64 65 64 20 67 2e 61 72 67 76 20 75 6e 64  anded g.argv und
4420: 65 72 20 63 6f 6e 73 74 72 75 63 74 69 6f 6e 20  er construction 
4430: 2a 2f 0a 20 20 63 6f 6e 73 74 20 63 68 61 72 20  */.  const char 
4440: 2a 7a 46 69 6c 65 4e 61 6d 65 3b 20 20 20 20 2f  *zFileName;    /
4450: 2a 20 69 6e 70 75 74 20 66 69 6c 65 20 6e 61 6d  * input file nam
4460: 65 20 2a 2f 0a 20 20 46 49 4c 45 20 2a 69 6e 46  e */.  FILE *inF
4470: 69 6c 65 3b 20 20 20 20 20 20 20 20 20 20 20 20  ile;            
4480: 20 2f 2a 20 69 6e 70 75 74 20 46 49 4c 45 20 2a   /* input FILE *
4490: 2f 0a 23 69 66 20 64 65 66 69 6e 65 64 28 5f 57  /.#if defined(_W
44a0: 49 4e 33 32 29 0a 20 20 77 63 68 61 72 5f 74 20  IN32).  wchar_t 
44b0: 62 75 66 5b 4d 41 58 5f 50 41 54 48 5d 3b 0a 23  buf[MAX_PATH];.#
44c0: 65 6e 64 69 66 0a 0a 20 20 67 2e 61 72 67 63 20  endif..  g.argc 
44d0: 3d 20 61 72 67 63 3b 0a 20 20 67 2e 61 72 67 76  = argc;.  g.argv
44e0: 20 3d 20 61 72 67 76 3b 0a 20 20 73 71 6c 69 74   = argv;.  sqlit
44f0: 65 33 5f 69 6e 69 74 69 61 6c 69 7a 65 28 29 3b  e3_initialize();
4500: 0a 23 69 66 20 64 65 66 69 6e 65 64 28 5f 57 49  .#if defined(_WI
4510: 4e 33 32 29 20 26 26 20 64 65 66 69 6e 65 64 28  N32) && defined(
4520: 42 52 4f 4b 45 4e 5f 4d 49 4e 47 57 5f 43 4d 44  BROKEN_MINGW_CMD
4530: 4c 49 4e 45 29 0a 20 20 66 6f 72 28 69 3d 30 3b  LINE).  for(i=0;
4540: 20 69 3c 67 2e 61 72 67 63 3b 20 69 2b 2b 29 20   i<g.argc; i++) 
4550: 67 2e 61 72 67 76 5b 69 5d 20 3d 20 66 6f 73 73  g.argv[i] = foss
4560: 69 6c 5f 6d 62 63 73 5f 74 6f 5f 75 74 66 38 28  il_mbcs_to_utf8(
4570: 67 2e 61 72 67 76 5b 69 5d 29 3b 0a 23 65 6c 73  g.argv[i]);.#els
4580: 65 0a 20 20 66 6f 72 28 69 3d 30 3b 20 69 3c 67  e.  for(i=0; i<g
4590: 2e 61 72 67 63 3b 20 69 2b 2b 29 20 67 2e 61 72  .argc; i++) g.ar
45a0: 67 76 5b 69 5d 20 3d 20 66 6f 73 73 69 6c 5f 70  gv[i] = fossil_p
45b0: 61 74 68 5f 74 6f 5f 75 74 66 38 28 67 2e 61 72  ath_to_utf8(g.ar
45c0: 67 76 5b 69 5d 29 3b 0a 23 65 6e 64 69 66 0a 23  gv[i]);.#endif.#
45d0: 69 66 20 64 65 66 69 6e 65 64 28 5f 57 49 4e 33  if defined(_WIN3
45e0: 32 29 0a 20 20 47 65 74 4d 6f 64 75 6c 65 46 69  2).  GetModuleFi
45f0: 6c 65 4e 61 6d 65 57 28 4e 55 4c 4c 2c 20 62 75  leNameW(NULL, bu
4600: 66 2c 20 4d 41 58 5f 50 41 54 48 29 3b 0a 20 20  f, MAX_PATH);.  
4610: 67 2e 6e 61 6d 65 4f 66 45 78 65 20 3d 20 66 6f  g.nameOfExe = fo
4620: 73 73 69 6c 5f 70 61 74 68 5f 74 6f 5f 75 74 66  ssil_path_to_utf
4630: 38 28 62 75 66 29 3b 0a 23 65 6c 73 65 0a 20 20  8(buf);.#else.  
4640: 67 2e 6e 61 6d 65 4f 66 45 78 65 20 3d 20 67 2e  g.nameOfExe = g.
4650: 61 72 67 76 5b 30 5d 3b 0a 23 65 6e 64 69 66 0a  argv[0];.#endif.
4660: 20 20 66 6f 72 28 69 3d 31 3b 20 69 3c 67 2e 61    for(i=1; i<g.a
4670: 72 67 63 2d 31 3b 20 69 2b 2b 29 7b 0a 20 20 20  rgc-1; i++){.   
4680: 20 7a 20 3d 20 67 2e 61 72 67 76 5b 69 5d 3b 0a   z = g.argv[i];.
4690: 20 20 20 20 69 66 28 20 7a 5b 30 5d 21 3d 27 2d      if( z[0]!='-
46a0: 27 20 29 20 63 6f 6e 74 69 6e 75 65 3b 0a 20 20  ' ) continue;.  
46b0: 20 20 7a 2b 2b 3b 0a 20 20 20 20 69 66 28 20 7a    z++;.    if( z
46c0: 5b 30 5d 3d 3d 27 2d 27 20 29 20 7a 2b 2b 3b 0a  [0]=='-' ) z++;.
46d0: 20 20 20 20 69 66 28 20 7a 5b 30 5d 3d 3d 30 20      if( z[0]==0 
46e0: 29 20 72 65 74 75 72 6e 3b 20 20 20 2f 2a 20 53  ) return;   /* S
46f0: 74 6f 70 20 73 65 61 72 63 68 69 6e 67 20 61 74  top searching at
4700: 20 22 2d 2d 22 20 2a 2f 0a 20 20 20 20 69 66 28   "--" */.    if(
4710: 20 66 6f 73 73 69 6c 5f 73 74 72 63 6d 70 28 7a   fossil_strcmp(z
4720: 2c 20 22 61 72 67 73 22 29 3d 3d 30 20 29 20 62  , "args")==0 ) b
4730: 72 65 61 6b 3b 0a 20 20 7d 0a 20 20 69 66 28 20  reak;.  }.  if( 
4740: 69 3e 3d 67 2e 61 72 67 63 2d 31 20 29 20 72 65  i>=g.argc-1 ) re
4750: 74 75 72 6e 3b 0a 0a 20 20 7a 46 69 6c 65 4e 61  turn;..  zFileNa
4760: 6d 65 20 3d 20 67 2e 61 72 67 76 5b 69 2b 31 5d  me = g.argv[i+1]
4770: 3b 0a 20 20 69 66 28 20 73 74 72 63 6d 70 28 7a  ;.  if( strcmp(z
4780: 46 69 6c 65 4e 61 6d 65 2c 22 2d 22 29 3d 3d 30  FileName,"-")==0
4790: 20 29 7b 0a 20 20 20 20 69 6e 46 69 6c 65 20 3d   ){.    inFile =
47a0: 20 73 74 64 69 6e 3b 0a 20 20 7d 65 6c 73 65 20   stdin;.  }else 
47b0: 69 66 28 20 21 66 69 6c 65 5f 69 73 66 69 6c 65  if( !file_isfile
47c0: 28 7a 46 69 6c 65 4e 61 6d 65 2c 20 45 78 74 46  (zFileName, ExtF
47d0: 49 4c 45 29 20 29 7b 0a 20 20 20 20 66 6f 73 73  ILE) ){.    foss
47e0: 69 6c 5f 66 61 74 61 6c 28 22 4e 6f 74 20 61 6e  il_fatal("Not an
47f0: 20 6f 72 64 69 6e 61 72 79 20 66 69 6c 65 3a 20   ordinary file: 
4800: 5c 22 25 73 5c 22 22 2c 20 7a 46 69 6c 65 4e 61  \"%s\"", zFileNa
4810: 6d 65 29 3b 0a 20 20 7d 65 6c 73 65 7b 0a 20 20  me);.  }else{.  
4820: 20 20 69 6e 46 69 6c 65 20 3d 20 66 6f 73 73 69    inFile = fossi
4830: 6c 5f 66 6f 70 65 6e 28 7a 46 69 6c 65 4e 61 6d  l_fopen(zFileNam
4840: 65 2c 22 72 62 22 29 3b 0a 20 20 20 20 69 66 28  e,"rb");.    if(
4850: 20 69 6e 46 69 6c 65 3d 3d 30 20 29 7b 0a 20 20   inFile==0 ){.  
4860: 20 20 20 20 66 6f 73 73 69 6c 5f 66 61 74 61 6c      fossil_fatal
4870: 28 22 43 61 6e 6e 6f 74 20 6f 70 65 6e 20 2d 61  ("Cannot open -a
4880: 72 67 73 20 66 69 6c 65 20 5b 25 73 5d 22 2c 20  rgs file [%s]", 
4890: 7a 46 69 6c 65 4e 61 6d 65 29 3b 0a 20 20 20 20  zFileName);.    
48a0: 7d 0a 20 20 7d 0a 20 20 62 6c 6f 62 5f 72 65 61  }.  }.  blob_rea
48b0: 64 5f 66 72 6f 6d 5f 63 68 61 6e 6e 65 6c 28 26  d_from_channel(&
48c0: 66 69 6c 65 2c 20 69 6e 46 69 6c 65 2c 20 2d 31  file, inFile, -1
48d0: 29 3b 0a 20 20 69 66 28 73 74 64 69 6e 20 21 3d  );.  if(stdin !=
48e0: 20 69 6e 46 69 6c 65 29 7b 0a 20 20 20 20 66 63   inFile){.    fc
48f0: 6c 6f 73 65 28 69 6e 46 69 6c 65 29 3b 0a 20 20  lose(inFile);.  
4900: 7d 0a 20 20 69 6e 46 69 6c 65 20 3d 20 4e 55 4c  }.  inFile = NUL
4910: 4c 3b 0a 20 20 62 6c 6f 62 5f 74 6f 5f 75 74 66  L;.  blob_to_utf
4920: 38 5f 6e 6f 5f 62 6f 6d 28 26 66 69 6c 65 2c 20  8_no_bom(&file, 
4930: 31 29 3b 0a 20 20 7a 20 3d 20 62 6c 6f 62 5f 73  1);.  z = blob_s
4940: 74 72 28 26 66 69 6c 65 29 3b 0a 20 20 66 6f 72  tr(&file);.  for
4950: 28 6b 3d 30 2c 20 6e 4c 69 6e 65 3d 31 3b 20 7a  (k=0, nLine=1; z
4960: 5b 6b 5d 3b 20 6b 2b 2b 29 20 69 66 28 20 7a 5b  [k]; k++) if( z[
4970: 6b 5d 3d 3d 27 5c 6e 27 20 29 20 6e 4c 69 6e 65  k]=='\n' ) nLine
4980: 2b 2b 3b 0a 20 20 69 66 28 20 6e 4c 69 6e 65 3e  ++;.  if( nLine>
4990: 31 30 30 30 30 30 30 30 30 20 29 20 66 6f 73 73  100000000 ) foss
49a0: 69 6c 5f 66 61 74 61 6c 28 22 74 6f 6f 20 6d 61  il_fatal("too ma
49b0: 6e 79 20 63 6f 6d 6d 61 6e 64 2d 6c 69 6e 65 20  ny command-line 
49c0: 61 72 67 75 6d 65 6e 74 73 22 29 3b 0a 20 20 6e  arguments");.  n
49d0: 41 72 67 20 3d 20 67 2e 61 72 67 63 20 2b 20 6e  Arg = g.argc + n
49e0: 4c 69 6e 65 2a 32 3b 0a 20 20 6e 65 77 41 72 67  Line*2;.  newArg
49f0: 76 20 3d 20 66 6f 73 73 69 6c 5f 6d 61 6c 6c 6f  v = fossil_mallo
4a00: 63 28 20 73 69 7a 65 6f 66 28 63 68 61 72 2a 29  c( sizeof(char*)
4a10: 2a 6e 41 72 67 20 29 3b 0a 20 20 66 6f 72 28 6a  *nArg );.  for(j
4a20: 3d 30 3b 20 6a 3c 69 3b 20 6a 2b 2b 29 20 6e 65  =0; j<i; j++) ne
4a30: 77 41 72 67 76 5b 6a 5d 20 3d 20 67 2e 61 72 67  wArgv[j] = g.arg
4a40: 76 5b 6a 5d 3b 0a 0a 20 20 62 6c 6f 62 5f 72 65  v[j];..  blob_re
4a50: 77 69 6e 64 28 26 66 69 6c 65 29 3b 0a 20 20 77  wind(&file);.  w
4a60: 68 69 6c 65 28 20 28 6e 20 3d 20 62 6c 6f 62 5f  hile( (n = blob_
4a70: 6c 69 6e 65 28 26 66 69 6c 65 2c 20 26 6c 69 6e  line(&file, &lin
4a80: 65 29 29 3e 30 20 29 7b 0a 20 20 20 20 69 66 28  e))>0 ){.    if(
4a90: 20 6e 3c 31 20 29 7b 0a 20 20 20 20 20 20 2f 2a   n<1 ){.      /*
4aa0: 20 52 65 6d 69 6e 64 65 72 3a 20 63 6f 72 6e 65   Reminder: corne
4ab0: 72 2d 63 61 73 65 3a 20 61 20 6c 69 6e 65 20 77  r-case: a line w
4ac0: 69 74 68 20 31 20 62 79 74 65 20 61 6e 64 20 6e  ith 1 byte and n
4ad0: 6f 20 6e 65 77 6c 69 6e 65 2e 20 2a 2f 0a 20 20  o newline. */.  
4ae0: 20 20 20 20 63 6f 6e 74 69 6e 75 65 3b 0a 20 20      continue;.  
4af0: 20 20 7d 0a 20 20 20 20 7a 20 3d 20 62 6c 6f 62    }.    z = blob
4b00: 5f 62 75 66 66 65 72 28 26 6c 69 6e 65 29 3b 0a  _buffer(&line);.
4b10: 20 20 20 20 69 66 28 27 5c 6e 27 3d 3d 7a 5b 6e      if('\n'==z[n
4b20: 2d 31 5d 29 7b 0a 20 20 20 20 20 20 7a 5b 6e 2d  -1]){.      z[n-
4b30: 31 5d 20 3d 20 30 3b 0a 20 20 20 20 7d 0a 0a 20  1] = 0;.    }.. 
4b40: 20 20 20 69 66 28 28 6e 3e 31 29 20 26 26 20 28     if((n>1) && (
4b50: 27 5c 72 27 3d 3d 7a 5b 6e 2d 32 5d 29 29 7b 0a  '\r'==z[n-2])){.
4b60: 20 20 20 20 20 20 69 66 28 6e 3d 3d 32 29 20 63        if(n==2) c
4b70: 6f 6e 74 69 6e 75 65 20 2f 2a 65 6d 70 74 79 20  ontinue /*empty 
4b80: 6c 69 6e 65 2a 2f 3b 0a 20 20 20 20 20 20 7a 5b  line*/;.      z[
4b90: 6e 2d 32 5d 20 3d 20 30 3b 0a 20 20 20 20 7d 0a  n-2] = 0;.    }.
4ba0: 20 20 20 20 69 66 28 21 7a 5b 30 5d 29 20 63 6f      if(!z[0]) co
4bb0: 6e 74 69 6e 75 65 3b 0a 20 20 20 20 69 66 28 20  ntinue;.    if( 
4bc0: 6a 3e 3d 6e 41 72 67 20 29 7b 0a 20 20 20 20 20  j>=nArg ){.     
4bd0: 20 66 6f 73 73 69 6c 5f 66 61 74 61 6c 28 22 6d   fossil_fatal("m
4be0: 61 6c 66 6f 72 6d 65 64 20 63 6f 6d 6d 61 6e 64  alformed command
4bf0: 2d 6c 69 6e 65 20 61 72 67 75 6d 65 6e 74 73 22  -line arguments"
4c00: 29 3b 0a 20 20 20 20 7d 0a 20 20 20 20 6e 65 77  );.    }.    new
4c10: 41 72 67 76 5b 6a 2b 2b 5d 20 3d 20 7a 3b 0a 20  Argv[j++] = z;. 
4c20: 20 20 20 69 66 28 20 7a 5b 30 5d 3d 3d 27 2d 27     if( z[0]=='-'
4c30: 20 29 7b 0a 20 20 20 20 20 20 66 6f 72 28 6b 3d   ){.      for(k=
4c40: 31 3b 20 7a 5b 6b 5d 20 26 26 20 21 66 6f 73 73  1; z[k] && !foss
4c50: 69 6c 5f 69 73 73 70 61 63 65 28 7a 5b 6b 5d 29  il_isspace(z[k])
4c60: 3b 20 6b 2b 2b 29 7b 7d 0a 20 20 20 20 20 20 69  ; k++){}.      i
4c70: 66 28 20 7a 5b 6b 5d 20 29 7b 0a 20 20 20 20 20  f( z[k] ){.     
4c80: 20 20 20 7a 5b 6b 5d 20 3d 20 30 3b 0a 20 20 20     z[k] = 0;.   
4c90: 20 20 20 20 20 6b 2b 2b 3b 0a 20 20 20 20 20 20       k++;.      
4ca0: 20 20 69 66 28 20 7a 5b 6b 5d 20 29 20 6e 65 77    if( z[k] ) new
4cb0: 41 72 67 76 5b 6a 2b 2b 5d 20 3d 20 26 7a 5b 6b  Argv[j++] = &z[k
4cc0: 5d 3b 0a 20 20 20 20 20 20 7d 0a 20 20 20 20 7d  ];.      }.    }
4cd0: 0a 20 20 7d 0a 20 20 69 20 2b 3d 20 32 3b 0a 20  .  }.  i += 2;. 
4ce0: 20 77 68 69 6c 65 28 20 69 3c 67 2e 61 72 67 63   while( i<g.argc
4cf0: 20 29 20 6e 65 77 41 72 67 76 5b 6a 2b 2b 5d 20   ) newArgv[j++] 
4d00: 3d 20 67 2e 61 72 67 76 5b 69 2b 2b 5d 3b 0a 20  = g.argv[i++];. 
4d10: 20 6e 65 77 41 72 67 76 5b 6a 5d 20 3d 20 30 3b   newArgv[j] = 0;
4d20: 0a 20 20 67 2e 61 72 67 63 20 3d 20 6a 3b 0a 20  .  g.argc = j;. 
4d30: 20 67 2e 61 72 67 76 20 3d 20 6e 65 77 41 72 67   g.argv = newArg
4d40: 76 3b 0a 7d 0a 0a 23 69 66 64 65 66 20 46 4f 53  v;.}..#ifdef FOS
4d50: 53 49 4c 5f 45 4e 41 42 4c 45 5f 54 43 4c 0a 2f  SIL_ENABLE_TCL./
4d60: 2a 0a 2a 2a 20 4d 61 6b 65 20 61 20 64 65 65 70  *.** Make a deep
4d70: 20 63 6f 70 79 20 6f 66 20 74 68 65 20 70 72 6f   copy of the pro
4d80: 76 69 64 65 64 20 61 72 67 75 6d 65 6e 74 20 61  vided argument a
4d90: 72 72 61 79 20 61 6e 64 20 72 65 74 75 72 6e 20  rray and return 
4da0: 69 74 2e 0a 2a 2f 0a 73 74 61 74 69 63 20 63 68  it..*/.static ch
4db0: 61 72 20 2a 2a 63 6f 70 79 5f 61 72 67 73 28 69  ar **copy_args(i
4dc0: 6e 74 20 61 72 67 63 2c 20 63 68 61 72 20 2a 2a  nt argc, char **
4dd0: 61 72 67 76 29 7b 0a 20 20 63 68 61 72 20 2a 2a  argv){.  char **
4de0: 7a 4e 65 77 41 72 67 76 3b 0a 20 20 69 6e 74 20  zNewArgv;.  int 
4df0: 69 3b 0a 20 20 7a 4e 65 77 41 72 67 76 20 3d 20  i;.  zNewArgv = 
4e00: 66 6f 73 73 69 6c 5f 6d 61 6c 6c 6f 63 28 20 73  fossil_malloc( s
4e10: 69 7a 65 6f 66 28 63 68 61 72 2a 29 2a 28 61 72  izeof(char*)*(ar
4e20: 67 63 2b 31 29 20 29 3b 0a 20 20 6d 65 6d 73 65  gc+1) );.  memse
4e30: 74 28 7a 4e 65 77 41 72 67 76 2c 20 30 2c 20 73  t(zNewArgv, 0, s
4e40: 69 7a 65 6f 66 28 63 68 61 72 2a 29 2a 28 61 72  izeof(char*)*(ar
4e50: 67 63 2b 31 29 29 3b 0a 20 20 66 6f 72 28 69 3d  gc+1));.  for(i=
4e60: 30 3b 20 69 3c 61 72 67 63 3b 20 69 2b 2b 29 7b  0; i<argc; i++){
4e70: 0a 20 20 20 20 7a 4e 65 77 41 72 67 76 5b 69 5d  .    zNewArgv[i]
4e80: 20 3d 20 66 6f 73 73 69 6c 5f 73 74 72 64 75 70   = fossil_strdup
4e90: 28 61 72 67 76 5b 69 5d 29 3b 0a 20 20 7d 0a 20  (argv[i]);.  }. 
4ea0: 20 72 65 74 75 72 6e 20 7a 4e 65 77 41 72 67 76   return zNewArgv
4eb0: 3b 0a 7d 0a 23 65 6e 64 69 66 0a 0a 2f 2a 0a 2a  ;.}.#endif../*.*
4ec0: 2a 20 52 65 74 75 72 6e 73 20 61 20 6e 61 6d 65  * Returns a name
4ed0: 20 66 6f 72 20 61 20 53 51 4c 69 74 65 20 72 65   for a SQLite re
4ee0: 74 75 72 6e 20 63 6f 64 65 2e 0a 2a 2f 0a 73 74  turn code..*/.st
4ef0: 61 74 69 63 20 63 6f 6e 73 74 20 63 68 61 72 20  atic const char 
4f00: 2a 66 6f 73 73 69 6c 5f 73 71 6c 69 74 65 5f 72  *fossil_sqlite_r
4f10: 65 74 75 72 6e 5f 63 6f 64 65 5f 6e 61 6d 65 28  eturn_code_name(
4f20: 69 6e 74 20 72 63 29 7b 0a 20 20 73 74 61 74 69  int rc){.  stati
4f30: 63 20 63 68 61 72 20 7a 43 6f 64 65 5b 33 30 5d  c char zCode[30]
4f40: 3b 0a 20 20 73 77 69 74 63 68 28 20 72 63 20 26  ;.  switch( rc &
4f50: 20 30 78 66 66 20 29 7b 0a 20 20 20 20 63 61 73   0xff ){.    cas
4f60: 65 20 53 51 4c 49 54 45 5f 4f 4b 3a 20 20 20 20  e SQLITE_OK:    
4f70: 20 20 20 20 20 72 65 74 75 72 6e 20 22 53 51 4c       return "SQL
4f80: 49 54 45 5f 4f 4b 22 3b 0a 20 20 20 20 63 61 73  ITE_OK";.    cas
4f90: 65 20 53 51 4c 49 54 45 5f 45 52 52 4f 52 3a 20  e SQLITE_ERROR: 
4fa0: 20 20 20 20 20 72 65 74 75 72 6e 20 22 53 51 4c       return "SQL
4fb0: 49 54 45 5f 45 52 52 4f 52 22 3b 0a 20 20 20 20  ITE_ERROR";.    
4fc0: 63 61 73 65 20 53 51 4c 49 54 45 5f 49 4e 54 45  case SQLITE_INTE
4fd0: 52 4e 41 4c 3a 20 20 20 72 65 74 75 72 6e 20 22  RNAL:   return "
4fe0: 53 51 4c 49 54 45 5f 49 4e 54 45 52 4e 41 4c 22  SQLITE_INTERNAL"
4ff0: 3b 0a 20 20 20 20 63 61 73 65 20 53 51 4c 49 54  ;.    case SQLIT
5000: 45 5f 50 45 52 4d 3a 20 20 20 20 20 20 20 72 65  E_PERM:       re
5010: 74 75 72 6e 20 22 53 51 4c 49 54 45 5f 50 45 52  turn "SQLITE_PER
5020: 4d 22 3b 0a 20 20 20 20 63 61 73 65 20 53 51 4c  M";.    case SQL
5030: 49 54 45 5f 41 42 4f 52 54 3a 20 20 20 20 20 20  ITE_ABORT:      
5040: 72 65 74 75 72 6e 20 22 53 51 4c 49 54 45 5f 41  return "SQLITE_A
5050: 42 4f 52 54 22 3b 0a 20 20 20 20 63 61 73 65 20  BORT";.    case 
5060: 53 51 4c 49 54 45 5f 42 55 53 59 3a 20 20 20 20  SQLITE_BUSY:    
5070: 20 20 20 72 65 74 75 72 6e 20 22 53 51 4c 49 54     return "SQLIT
5080: 45 5f 42 55 53 59 22 3b 0a 20 20 20 20 63 61 73  E_BUSY";.    cas
5090: 65 20 53 51 4c 49 54 45 5f 4c 4f 43 4b 45 44 3a  e SQLITE_LOCKED:
50a0: 20 20 20 20 20 72 65 74 75 72 6e 20 22 53 51 4c       return "SQL
50b0: 49 54 45 5f 4c 4f 43 4b 45 44 22 3b 0a 20 20 20  ITE_LOCKED";.   
50c0: 20 63 61 73 65 20 53 51 4c 49 54 45 5f 4e 4f 4d   case SQLITE_NOM
50d0: 45 4d 3a 20 20 20 20 20 20 72 65 74 75 72 6e 20  EM:      return 
50e0: 22 53 51 4c 49 54 45 5f 4e 4f 4d 45 4d 22 3b 0a  "SQLITE_NOMEM";.
50f0: 20 20 20 20 63 61 73 65 20 53 51 4c 49 54 45 5f      case SQLITE_
5100: 52 45 41 44 4f 4e 4c 59 3a 20 20 20 72 65 74 75  READONLY:   retu
5110: 72 6e 20 22 53 51 4c 49 54 45 5f 52 45 41 44 4f  rn "SQLITE_READO
5120: 4e 4c 59 22 3b 0a 20 20 20 20 63 61 73 65 20 53  NLY";.    case S
5130: 51 4c 49 54 45 5f 49 4e 54 45 52 52 55 50 54 3a  QLITE_INTERRUPT:
5140: 20 20 72 65 74 75 72 6e 20 22 53 51 4c 49 54 45    return "SQLITE
5150: 5f 49 4e 54 45 52 52 55 50 54 22 3b 0a 20 20 20  _INTERRUPT";.   
5160: 20 63 61 73 65 20 53 51 4c 49 54 45 5f 49 4f 45   case SQLITE_IOE
5170: 52 52 3a 20 20 20 20 20 20 72 65 74 75 72 6e 20  RR:      return 
5180: 22 53 51 4c 49 54 45 5f 49 4f 45 52 52 22 3b 0a  "SQLITE_IOERR";.
5190: 20 20 20 20 63 61 73 65 20 53 51 4c 49 54 45 5f      case SQLITE_
51a0: 43 4f 52 52 55 50 54 3a 20 20 20 20 72 65 74 75  CORRUPT:    retu
51b0: 72 6e 20 22 53 51 4c 49 54 45 5f 43 4f 52 52 55  rn "SQLITE_CORRU
51c0: 50 54 22 3b 0a 20 20 20 20 63 61 73 65 20 53 51  PT";.    case SQ
51d0: 4c 49 54 45 5f 4e 4f 54 46 4f 55 4e 44 3a 20 20  LITE_NOTFOUND:  
51e0: 20 72 65 74 75 72 6e 20 22 53 51 4c 49 54 45 5f   return "SQLITE_
51f0: 4e 4f 54 46 4f 55 4e 44 22 3b 0a 20 20 20 20 63  NOTFOUND";.    c
5200: 61 73 65 20 53 51 4c 49 54 45 5f 46 55 4c 4c 3a  ase SQLITE_FULL:
5210: 20 20 20 20 20 20 20 72 65 74 75 72 6e 20 22 53         return "S
5220: 51 4c 49 54 45 5f 46 55 4c 4c 22 3b 0a 20 20 20  QLITE_FULL";.   
5230: 20 63 61 73 65 20 53 51 4c 49 54 45 5f 43 41 4e   case SQLITE_CAN
5240: 54 4f 50 45 4e 3a 20 20 20 72 65 74 75 72 6e 20  TOPEN:   return 
5250: 22 53 51 4c 49 54 45 5f 43 41 4e 54 4f 50 45 4e  "SQLITE_CANTOPEN
5260: 22 3b 0a 20 20 20 20 63 61 73 65 20 53 51 4c 49  ";.    case SQLI
5270: 54 45 5f 50 52 4f 54 4f 43 4f 4c 3a 20 20 20 72  TE_PROTOCOL:   r
5280: 65 74 75 72 6e 20 22 53 51 4c 49 54 45 5f 50 52  eturn "SQLITE_PR
5290: 4f 54 4f 43 4f 4c 22 3b 0a 20 20 20 20 63 61 73  OTOCOL";.    cas
52a0: 65 20 53 51 4c 49 54 45 5f 45 4d 50 54 59 3a 20  e SQLITE_EMPTY: 
52b0: 20 20 20 20 20 72 65 74 75 72 6e 20 22 53 51 4c       return "SQL
52c0: 49 54 45 5f 45 4d 50 54 59 22 3b 0a 20 20 20 20  ITE_EMPTY";.    
52d0: 63 61 73 65 20 53 51 4c 49 54 45 5f 53 43 48 45  case SQLITE_SCHE
52e0: 4d 41 3a 20 20 20 20 20 72 65 74 75 72 6e 20 22  MA:     return "
52f0: 53 51 4c 49 54 45 5f 53 43 48 45 4d 41 22 3b 0a  SQLITE_SCHEMA";.
5300: 20 20 20 20 63 61 73 65 20 53 51 4c 49 54 45 5f      case SQLITE_
5310: 54 4f 4f 42 49 47 3a 20 20 20 20 20 72 65 74 75  TOOBIG:     retu
5320: 72 6e 20 22 53 51 4c 49 54 45 5f 54 4f 4f 42 49  rn "SQLITE_TOOBI
5330: 47 22 3b 0a 20 20 20 20 63 61 73 65 20 53 51 4c  G";.    case SQL
5340: 49 54 45 5f 43 4f 4e 53 54 52 41 49 4e 54 3a 20  ITE_CONSTRAINT: 
5350: 72 65 74 75 72 6e 20 22 53 51 4c 49 54 45 5f 43  return "SQLITE_C
5360: 4f 4e 53 54 52 41 49 4e 54 22 3b 0a 20 20 20 20  ONSTRAINT";.    
5370: 63 61 73 65 20 53 51 4c 49 54 45 5f 4d 49 53 4d  case SQLITE_MISM
5380: 41 54 43 48 3a 20 20 20 72 65 74 75 72 6e 20 22  ATCH:   return "
5390: 53 51 4c 49 54 45 5f 4d 49 53 4d 41 54 43 48 22  SQLITE_MISMATCH"
53a0: 3b 0a 20 20 20 20 63 61 73 65 20 53 51 4c 49 54  ;.    case SQLIT
53b0: 45 5f 4d 49 53 55 53 45 3a 20 20 20 20 20 72 65  E_MISUSE:     re
53c0: 74 75 72 6e 20 22 53 51 4c 49 54 45 5f 4d 49 53  turn "SQLITE_MIS
53d0: 55 53 45 22 3b 0a 20 20 20 20 63 61 73 65 20 53  USE";.    case S
53e0: 51 4c 49 54 45 5f 4e 4f 4c 46 53 3a 20 20 20 20  QLITE_NOLFS:    
53f0: 20 20 72 65 74 75 72 6e 20 22 53 51 4c 49 54 45    return "SQLITE
5400: 5f 4e 4f 4c 46 53 22 3b 0a 20 20 20 20 63 61 73  _NOLFS";.    cas
5410: 65 20 53 51 4c 49 54 45 5f 41 55 54 48 3a 20 20  e SQLITE_AUTH:  
5420: 20 20 20 20 20 72 65 74 75 72 6e 20 22 53 51 4c       return "SQL
5430: 49 54 45 5f 41 55 54 48 22 3b 0a 20 20 20 20 63  ITE_AUTH";.    c
5440: 61 73 65 20 53 51 4c 49 54 45 5f 46 4f 52 4d 41  ase SQLITE_FORMA
5450: 54 3a 20 20 20 20 20 72 65 74 75 72 6e 20 22 53  T:     return "S
5460: 51 4c 49 54 45 5f 46 4f 52 4d 41 54 22 3b 0a 20  QLITE_FORMAT";. 
5470: 20 20 20 63 61 73 65 20 53 51 4c 49 54 45 5f 52     case SQLITE_R
5480: 41 4e 47 45 3a 20 20 20 20 20 20 72 65 74 75 72  ANGE:      retur
5490: 6e 20 22 53 51 4c 49 54 45 5f 52 41 4e 47 45 22  n "SQLITE_RANGE"
54a0: 3b 0a 20 20 20 20 63 61 73 65 20 53 51 4c 49 54  ;.    case SQLIT
54b0: 45 5f 4e 4f 54 41 44 42 3a 20 20 20 20 20 72 65  E_NOTADB:     re
54c0: 74 75 72 6e 20 22 53 51 4c 49 54 45 5f 4e 4f 54  turn "SQLITE_NOT
54d0: 41 44 42 22 3b 0a 20 20 20 20 63 61 73 65 20 53  ADB";.    case S
54e0: 51 4c 49 54 45 5f 4e 4f 54 49 43 45 3a 20 20 20  QLITE_NOTICE:   
54f0: 20 20 72 65 74 75 72 6e 20 22 53 51 4c 49 54 45    return "SQLITE
5500: 5f 4e 4f 54 49 43 45 22 3b 0a 20 20 20 20 63 61  _NOTICE";.    ca
5510: 73 65 20 53 51 4c 49 54 45 5f 57 41 52 4e 49 4e  se SQLITE_WARNIN
5520: 47 3a 20 20 20 20 72 65 74 75 72 6e 20 22 53 51  G:    return "SQ
5530: 4c 49 54 45 5f 57 41 52 4e 49 4e 47 22 3b 0a 20  LITE_WARNING";. 
5540: 20 20 20 63 61 73 65 20 53 51 4c 49 54 45 5f 52     case SQLITE_R
5550: 4f 57 3a 20 20 20 20 20 20 20 20 72 65 74 75 72  OW:        retur
5560: 6e 20 22 53 51 4c 49 54 45 5f 52 4f 57 22 3b 0a  n "SQLITE_ROW";.
5570: 20 20 20 20 63 61 73 65 20 53 51 4c 49 54 45 5f      case SQLITE_
5580: 44 4f 4e 45 3a 20 20 20 20 20 20 20 72 65 74 75  DONE:       retu
5590: 72 6e 20 22 53 51 4c 49 54 45 5f 44 4f 4e 45 22  rn "SQLITE_DONE"
55a0: 3b 0a 20 20 20 20 64 65 66 61 75 6c 74 3a 20 7b  ;.    default: {
55b0: 0a 20 20 20 20 20 20 73 71 6c 69 74 65 33 5f 73  .      sqlite3_s
55c0: 6e 70 72 69 6e 74 66 28 73 69 7a 65 6f 66 28 7a  nprintf(sizeof(z
55d0: 43 6f 64 65 29 2c 20 7a 43 6f 64 65 2c 20 22 53  Code), zCode, "S
55e0: 51 4c 69 74 65 20 72 65 74 75 72 6e 20 63 6f 64  QLite return cod
55f0: 65 20 25 64 22 2c 20 72 63 29 3b 0a 20 20 20 20  e %d", rc);.    
5600: 7d 0a 20 20 7d 0a 20 20 72 65 74 75 72 6e 20 7a  }.  }.  return z
5610: 43 6f 64 65 3b 0a 7d 0a 0a 2f 2a 20 45 72 72 6f  Code;.}../* Erro
5620: 72 20 6c 6f 67 73 20 66 72 6f 6d 20 53 51 4c 69  r logs from SQLi
5630: 74 65 20 2a 2f 0a 73 74 61 74 69 63 20 76 6f 69  te */.static voi
5640: 64 20 66 6f 73 73 69 6c 5f 73 71 6c 69 74 65 5f  d fossil_sqlite_
5650: 6c 6f 67 28 76 6f 69 64 20 2a 6e 6f 74 55 73 65  log(void *notUse
5660: 64 2c 20 69 6e 74 20 69 43 6f 64 65 2c 20 63 6f  d, int iCode, co
5670: 6e 73 74 20 63 68 61 72 20 2a 7a 45 72 72 6d 73  nst char *zErrms
5680: 67 29 7b 0a 20 20 73 71 6c 69 74 65 33 5f 73 74  g){.  sqlite3_st
5690: 6d 74 20 2a 70 3b 0a 20 20 42 6c 6f 62 20 6d 73  mt *p;.  Blob ms
56a0: 67 3b 0a 23 69 66 64 65 66 20 5f 5f 41 50 50 4c  g;.#ifdef __APPL
56b0: 45 5f 5f 0a 20 20 2f 2a 20 44 69 73 61 62 6c 65  E__.  /* Disable
56c0: 20 74 68 65 20 66 69 6c 65 20 61 6c 69 61 73 20   the file alias 
56d0: 77 61 72 6e 69 6e 67 20 6f 6e 20 61 70 70 6c 65  warning on apple
56e0: 20 70 72 6f 64 75 63 74 73 20 62 65 63 61 75 73   products becaus
56f0: 65 20 54 69 6d 65 20 4d 61 63 68 69 6e 65 0a 20  e Time Machine. 
5700: 20 2a 2a 20 63 72 65 61 74 65 73 20 6c 6f 74 73   ** creates lots
5710: 20 6f 66 20 61 6c 69 61 73 65 73 20 61 6e 64 20   of aliases and 
5720: 74 68 65 20 77 61 72 6e 69 6e 67 73 20 61 6c 61  the warnings ala
5730: 72 6d 20 70 65 6f 70 6c 65 2e 20 2a 2f 0a 20 20  rm people. */.  
5740: 69 66 28 20 69 43 6f 64 65 3d 3d 53 51 4c 49 54  if( iCode==SQLIT
5750: 45 5f 57 41 52 4e 49 4e 47 20 29 20 72 65 74 75  E_WARNING ) retu
5760: 72 6e 3b 0a 23 65 6e 64 69 66 0a 23 69 66 6e 64  rn;.#endif.#ifnd
5770: 65 66 20 46 4f 53 53 49 4c 5f 44 45 42 55 47 0a  ef FOSSIL_DEBUG.
5780: 20 20 2f 2a 20 44 69 73 61 62 6c 65 20 74 68 65    /* Disable the
5790: 20 61 75 74 6f 6d 61 74 69 63 20 69 6e 64 65 78   automatic index
57a0: 20 77 61 72 6e 69 6e 67 20 65 78 63 65 70 74 20   warning except 
57b0: 69 6e 20 46 4f 53 53 49 4c 5f 44 45 42 55 47 20  in FOSSIL_DEBUG 
57c0: 62 75 69 6c 64 73 2e 20 2a 2f 0a 20 20 69 66 28  builds. */.  if(
57d0: 20 69 43 6f 64 65 3d 3d 53 51 4c 49 54 45 5f 57   iCode==SQLITE_W
57e0: 41 52 4e 49 4e 47 5f 41 55 54 4f 49 4e 44 45 58  ARNING_AUTOINDEX
57f0: 20 29 20 72 65 74 75 72 6e 3b 0a 23 65 6e 64 69   ) return;.#endi
5800: 66 0a 20 20 69 66 28 20 69 43 6f 64 65 3d 3d 53  f.  if( iCode==S
5810: 51 4c 49 54 45 5f 53 43 48 45 4d 41 20 29 20 72  QLITE_SCHEMA ) r
5820: 65 74 75 72 6e 3b 0a 20 20 69 66 28 20 67 2e 64  eturn;.  if( g.d
5830: 62 49 67 6e 6f 72 65 45 72 72 6f 72 73 20 29 20  bIgnoreErrors ) 
5840: 72 65 74 75 72 6e 3b 0a 23 69 66 64 65 66 20 53  return;.#ifdef S
5850: 51 4c 49 54 45 5f 52 45 41 44 4f 4e 4c 59 5f 44  QLITE_READONLY_D
5860: 49 52 45 43 54 4f 52 59 0a 20 20 69 66 28 20 69  IRECTORY.  if( i
5870: 43 6f 64 65 3d 3d 53 51 4c 49 54 45 5f 52 45 41  Code==SQLITE_REA
5880: 44 4f 4e 4c 59 5f 44 49 52 45 43 54 4f 52 59 20  DONLY_DIRECTORY 
5890: 29 7b 0a 20 20 20 20 7a 45 72 72 6d 73 67 20 3d  ){.    zErrmsg =
58a0: 20 22 64 61 74 61 62 61 73 65 20 69 73 20 69 6e   "database is in
58b0: 20 61 20 72 65 61 64 2d 6f 6e 6c 79 20 64 69 72   a read-only dir
58c0: 65 63 74 6f 72 79 22 3b 0a 20 20 7d 0a 23 65 6e  ectory";.  }.#en
58d0: 64 69 66 0a 20 20 62 6c 6f 62 5f 69 6e 69 74 28  dif.  blob_init(
58e0: 26 6d 73 67 2c 20 30 2c 20 30 29 3b 0a 20 20 62  &msg, 0, 0);.  b
58f0: 6c 6f 62 5f 61 70 70 65 6e 64 66 28 26 6d 73 67  lob_appendf(&msg
5900: 2c 20 22 25 73 28 25 64 29 3a 20 25 73 22 2c 0a  , "%s(%d): %s",.
5910: 20 20 20 20 20 66 6f 73 73 69 6c 5f 73 71 6c 69       fossil_sqli
5920: 74 65 5f 72 65 74 75 72 6e 5f 63 6f 64 65 5f 6e  te_return_code_n
5930: 61 6d 65 28 69 43 6f 64 65 29 2c 20 69 43 6f 64  ame(iCode), iCod
5940: 65 2c 20 7a 45 72 72 6d 73 67 29 3b 0a 20 20 69  e, zErrmsg);.  i
5950: 66 28 20 67 2e 64 62 20 29 7b 0a 20 20 20 20 66  f( g.db ){.    f
5960: 6f 72 28 70 3d 73 71 6c 69 74 65 33 5f 6e 65 78  or(p=sqlite3_nex
5970: 74 5f 73 74 6d 74 28 67 2e 64 62 2c 20 30 29 3b  t_stmt(g.db, 0);
5980: 20 70 3b 20 70 3d 73 71 6c 69 74 65 33 5f 6e 65   p; p=sqlite3_ne
5990: 78 74 5f 73 74 6d 74 28 67 2e 64 62 2c 70 29 29  xt_stmt(g.db,p))
59a0: 7b 0a 20 20 20 20 20 20 63 6f 6e 73 74 20 63 68  {.      const ch
59b0: 61 72 20 2a 7a 53 71 6c 3b 0a 20 20 20 20 20 20  ar *zSql;.      
59c0: 69 66 28 20 21 73 71 6c 69 74 65 33 5f 73 74 6d  if( !sqlite3_stm
59d0: 74 5f 62 75 73 79 28 70 29 20 29 20 63 6f 6e 74  t_busy(p) ) cont
59e0: 69 6e 75 65 3b 0a 20 20 20 20 20 20 7a 53 71 6c  inue;.      zSql
59f0: 20 3d 20 73 71 6c 69 74 65 33 5f 73 71 6c 28 70   = sqlite3_sql(p
5a00: 29 3b 0a 20 20 20 20 20 20 69 66 28 20 7a 53 71  );.      if( zSq
5a10: 6c 3d 3d 30 20 29 20 63 6f 6e 74 69 6e 75 65 3b  l==0 ) continue;
5a20: 0a 20 20 20 20 20 20 62 6c 6f 62 5f 61 70 70 65  .      blob_appe
5a30: 6e 64 66 28 26 6d 73 67 2c 20 22 5c 6e 53 51 4c  ndf(&msg, "\nSQL
5a40: 3a 20 25 73 22 2c 20 7a 53 71 6c 29 3b 0a 20 20  : %s", zSql);.  
5a50: 20 20 7d 0a 20 20 7d 0a 20 20 66 6f 73 73 69 6c    }.  }.  fossil
5a60: 5f 77 61 72 6e 69 6e 67 28 22 25 73 22 2c 20 62  _warning("%s", b
5a70: 6c 6f 62 5f 73 74 72 28 26 6d 73 67 29 29 3b 0a  lob_str(&msg));.
5a80: 20 20 62 6c 6f 62 5f 72 65 73 65 74 28 26 6d 73    blob_reset(&ms
5a90: 67 29 3b 0a 7d 0a 0a 2f 2a 0a 2a 2a 20 54 68 69  g);.}../*.** Thi
5aa0: 73 20 66 75 6e 63 74 69 6f 6e 20 61 74 74 65 6d  s function attem
5ab0: 70 74 73 20 74 6f 20 66 69 6e 64 20 63 6f 6d 6d  pts to find comm
5ac0: 61 6e 64 20 6c 69 6e 65 20 6f 70 74 69 6f 6e 73  and line options
5ad0: 20 6b 6e 6f 77 6e 20 74 6f 20 63 6f 6e 74 61 69   known to contai
5ae0: 6e 0a 2a 2a 20 62 69 74 77 69 73 65 20 66 6c 61  n.** bitwise fla
5af0: 67 73 20 61 6e 64 20 69 6e 69 74 69 61 6c 69 7a  gs and initializ
5b00: 65 73 20 74 68 65 20 61 73 73 6f 63 69 61 74 65  es the associate
5b10: 64 20 67 6c 6f 62 61 6c 20 76 61 72 69 61 62 6c  d global variabl
5b20: 65 73 2e 20 20 41 66 74 65 72 0a 2a 2a 20 74 68  es.  After.** th
5b30: 69 73 20 66 75 6e 63 74 69 6f 6e 20 65 78 65 63  is function exec
5b40: 75 74 65 73 2c 20 61 6c 6c 20 67 6c 6f 62 61 6c  utes, all global
5b50: 20 76 61 72 69 61 62 6c 65 73 20 28 69 2e 65 2e   variables (i.e.
5b60: 20 69 6e 20 74 68 65 20 22 67 22 20 73 74 72 75   in the "g" stru
5b70: 63 74 29 0a 2a 2a 20 63 6f 6e 74 61 69 6e 69 6e  ct).** containin
5b80: 67 20 6f 70 74 69 6f 6e 2d 73 65 74 74 61 62 6c  g option-settabl
5b90: 65 20 62 69 74 77 69 73 65 20 66 6c 61 67 20 66  e bitwise flag f
5ba0: 69 65 6c 64 73 20 6d 75 73 74 20 62 65 20 69 6e  ields must be in
5bb0: 69 74 69 61 6c 69 7a 65 64 2e 0a 2a 2f 0a 73 74  itialized..*/.st
5bc0: 61 74 69 63 20 76 6f 69 64 20 66 6f 73 73 69 6c  atic void fossil
5bd0: 5f 69 6e 69 74 5f 66 6c 61 67 73 5f 66 72 6f 6d  _init_flags_from
5be0: 5f 6f 70 74 69 6f 6e 73 28 76 6f 69 64 29 7b 0a  _options(void){.
5bf0: 20 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a 56    const char *zV
5c00: 61 6c 75 65 20 3d 20 66 69 6e 64 5f 6f 70 74 69  alue = find_opti
5c10: 6f 6e 28 22 63 6f 6d 66 6d 74 66 6c 61 67 73 22  on("comfmtflags"
5c20: 2c 20 30 2c 20 31 29 3b 0a 20 20 69 66 28 20 7a  , 0, 1);.  if( z
5c30: 56 61 6c 75 65 3d 3d 30 20 29 7b 0a 20 20 20 20  Value==0 ){.    
5c40: 7a 56 61 6c 75 65 20 3d 20 66 69 6e 64 5f 6f 70  zValue = find_op
5c50: 74 69 6f 6e 28 22 63 6f 6d 6d 65 6e 74 2d 66 6f  tion("comment-fo
5c60: 72 6d 61 74 22 2c 20 30 2c 20 31 29 3b 0a 20 20  rmat", 0, 1);.  
5c70: 7d 0a 20 20 69 66 28 20 7a 56 61 6c 75 65 20 29  }.  if( zValue )
5c80: 7b 0a 20 20 20 20 67 2e 63 6f 6d 46 6d 74 46 6c  {.    g.comFmtFl
5c90: 61 67 73 20 3d 20 61 74 6f 69 28 7a 56 61 6c 75  ags = atoi(zValu
5ca0: 65 29 3b 0a 20 20 7d 65 6c 73 65 7b 0a 20 20 20  e);.  }else{.   
5cb0: 20 67 2e 63 6f 6d 46 6d 74 46 6c 61 67 73 20 3d   g.comFmtFlags =
5cc0: 20 43 4f 4d 4d 45 4e 54 5f 50 52 49 4e 54 5f 55   COMMENT_PRINT_U
5cd0: 4e 53 45 54 3b 20 20 20 2f 2a 20 43 6f 6d 6d 61  NSET;   /* Comma
5ce0: 6e 64 2d 6c 69 6e 65 20 6f 70 74 69 6f 6e 20 6e  nd-line option n
5cf0: 6f 74 20 66 6f 75 6e 64 2e 20 2a 2f 0a 20 20 7d  ot found. */.  }
5d00: 0a 7d 0a 0a 2f 2a 0a 2a 2a 20 43 68 65 63 6b 20  .}../*.** Check 
5d10: 74 6f 20 73 65 65 20 69 66 20 74 68 65 20 46 6f  to see if the Fo
5d20: 73 73 69 6c 20 62 69 6e 61 72 79 20 63 6f 6e 74  ssil binary cont
5d30: 61 69 6e 73 20 61 6e 20 61 70 70 65 6e 64 65 64  ains an appended
5d40: 20 72 65 70 6f 73 69 74 6f 72 79 0a 2a 2a 20 66   repository.** f
5d50: 69 6c 65 20 75 73 69 6e 67 20 74 68 65 20 61 70  ile using the ap
5d60: 70 65 6e 64 76 66 73 20 65 78 74 65 6e 73 69 6f  pendvfs extensio
5d70: 6e 2e 20 20 49 66 20 73 6f 2c 20 63 68 61 6e 67  n.  If so, chang
5d80: 65 20 63 6f 6d 6d 61 6e 64 2d 6c 69 6e 65 20 61  e command-line a
5d90: 72 67 75 6d 65 6e 74 73 0a 2a 2a 20 74 6f 20 63  rguments.** to c
5da0: 61 75 73 65 20 46 6f 73 73 69 6c 20 74 6f 20 6c  ause Fossil to l
5db0: 61 75 6e 63 68 20 77 69 74 68 20 22 66 6f 73 73  aunch with "foss
5dc0: 69 6c 20 75 69 22 20 6f 6e 20 74 68 61 74 20 72  il ui" on that r
5dd0: 65 70 6f 2e 0a 2a 2f 0a 73 74 61 74 69 63 20 69  epo..*/.static i
5de0: 6e 74 20 66 6f 73 73 69 6c 45 78 65 48 61 73 41  nt fossilExeHasA
5df0: 70 70 65 6e 64 65 64 52 65 70 6f 28 76 6f 69 64  ppendedRepo(void
5e00: 29 7b 0a 20 20 65 78 74 65 72 6e 20 69 6e 74 20  ){.  extern int 
5e10: 64 65 64 75 63 65 44 61 74 61 62 61 73 65 54 79  deduceDatabaseTy
5e20: 70 65 28 63 6f 6e 73 74 20 63 68 61 72 2a 2c 69  pe(const char*,i
5e30: 6e 74 29 3b 0a 20 20 69 66 28 20 32 3d 3d 64 65  nt);.  if( 2==de
5e40: 64 75 63 65 44 61 74 61 62 61 73 65 54 79 70 65  duceDatabaseType
5e50: 28 67 2e 6e 61 6d 65 4f 66 45 78 65 2c 30 29 20  (g.nameOfExe,0) 
5e60: 29 7b 0a 20 20 20 20 73 74 61 74 69 63 20 63 68  ){.    static ch
5e70: 61 72 20 2a 61 7a 41 6c 74 41 72 67 76 5b 5d 20  ar *azAltArgv[] 
5e80: 3d 20 7b 20 30 2c 20 22 75 69 22 2c 20 30 2c 20  = { 0, "ui", 0, 
5e90: 30 20 7d 3b 0a 20 20 20 20 61 7a 41 6c 74 41 72  0 };.    azAltAr
5ea0: 67 76 5b 30 5d 20 3d 20 67 2e 6e 61 6d 65 4f 66  gv[0] = g.nameOf
5eb0: 45 78 65 3b 0a 20 20 20 20 61 7a 41 6c 74 41 72  Exe;.    azAltAr
5ec0: 67 76 5b 32 5d 20 3d 20 67 2e 6e 61 6d 65 4f 66  gv[2] = g.nameOf
5ed0: 45 78 65 3b 0a 20 20 20 20 67 2e 61 72 67 76 20  Exe;.    g.argv 
5ee0: 3d 20 61 7a 41 6c 74 41 72 67 76 3b 0a 20 20 20  = azAltArgv;.   
5ef0: 20 67 2e 61 72 67 63 20 3d 20 33 3b 0a 20 20 20   g.argc = 3;.   
5f00: 20 72 65 74 75 72 6e 20 31 3b 0a 20 20 7d 65 6c   return 1;.  }el
5f10: 73 65 7b 0a 20 20 20 20 72 65 74 75 72 6e 20 30  se{.    return 0
5f20: 3b 0a 20 20 7d 0a 7d 0a 0a 2f 2a 0a 2a 2a 20 54  ;.  }.}../*.** T
5f30: 68 69 73 20 70 72 6f 63 65 64 75 72 65 20 72 75  his procedure ru
5f40: 6e 73 20 66 69 72 73 74 2e 0a 2a 2f 0a 23 69 66  ns first..*/.#if
5f50: 20 64 65 66 69 6e 65 64 28 5f 57 49 4e 33 32 29   defined(_WIN32)
5f60: 20 26 26 20 21 64 65 66 69 6e 65 64 28 42 52 4f   && !defined(BRO
5f70: 4b 45 4e 5f 4d 49 4e 47 57 5f 43 4d 44 4c 49 4e  KEN_MINGW_CMDLIN
5f80: 45 29 0a 69 6e 74 20 5f 64 6f 77 69 6c 64 63 61  E).int _dowildca
5f90: 72 64 20 3d 20 2d 31 3b 20 2f 2a 20 54 68 69 73  rd = -1; /* This
5fa0: 20 74 75 72 6e 73 20 6f 6e 20 63 6f 6d 6d 61 6e   turns on comman
5fb0: 64 2d 6c 69 6e 65 20 67 6c 6f 62 62 69 6e 67 20  d-line globbing 
5fc0: 69 6e 20 4d 69 6e 47 57 2d 77 36 34 20 2a 2f 0a  in MinGW-w64 */.
5fd0: 69 6e 74 20 77 6d 61 69 6e 28 69 6e 74 20 61 72  int wmain(int ar
5fe0: 67 63 2c 20 77 63 68 61 72 5f 74 20 2a 2a 61 72  gc, wchar_t **ar
5ff0: 67 76 29 0a 23 65 6c 73 65 0a 23 69 66 20 64 65  gv).#else.#if de
6000: 66 69 6e 65 64 28 5f 57 49 4e 33 32 29 0a 69 6e  fined(_WIN32).in
6010: 74 20 5f 43 52 54 5f 67 6c 6f 62 20 3d 20 30 78  t _CRT_glob = 0x
6020: 30 30 30 31 3b 20 2f 2a 20 53 65 65 20 4d 69 6e  0001; /* See Min
6030: 47 57 20 62 75 67 20 23 32 30 36 32 20 2a 2f 0a  GW bug #2062 */.
6040: 23 65 6e 64 69 66 0a 69 6e 74 20 6d 61 69 6e 28  #endif.int main(
6050: 69 6e 74 20 61 72 67 63 2c 20 63 68 61 72 20 2a  int argc, char *
6060: 2a 61 72 67 76 29 0a 23 65 6e 64 69 66 0a 7b 0a  *argv).#endif.{.
6070: 20 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a 43    const char *zC
6080: 6d 64 4e 61 6d 65 20 3d 20 22 75 6e 6b 6e 6f 77  mdName = "unknow
6090: 6e 22 3b 0a 20 20 63 6f 6e 73 74 20 43 6d 64 4f  n";.  const CmdO
60a0: 72 50 61 67 65 20 2a 70 43 6d 64 20 3d 20 30 3b  rPage *pCmd = 0;
60b0: 0a 20 20 69 6e 74 20 72 63 3b 0a 0a 23 69 66 20  .  int rc;..#if 
60c0: 21 64 65 66 69 6e 65 64 28 5f 57 49 4e 33 32 5f  !defined(_WIN32_
60d0: 57 43 45 29 0a 20 20 69 66 28 20 66 6f 73 73 69  WCE).  if( fossi
60e0: 6c 5f 67 65 74 65 6e 76 28 22 46 4f 53 53 49 4c  l_getenv("FOSSIL
60f0: 5f 42 52 45 41 4b 22 29 20 29 7b 0a 20 20 20 20  _BREAK") ){.    
6100: 69 66 28 20 69 73 61 74 74 79 28 30 29 20 26 26  if( isatty(0) &&
6110: 20 69 73 61 74 74 79 28 32 29 20 29 7b 0a 20 20   isatty(2) ){.  
6120: 20 20 20 20 66 70 72 69 6e 74 66 28 73 74 64 65      fprintf(stde
6130: 72 72 2c 0a 20 20 20 20 20 20 20 20 20 20 22 61  rr,.          "a
6140: 74 74 61 63 68 20 64 65 62 75 67 67 65 72 20 74  ttach debugger t
6150: 6f 20 70 72 6f 63 65 73 73 20 25 64 20 61 6e 64  o process %d and
6160: 20 70 72 65 73 73 20 61 6e 79 20 6b 65 79 20 74   press any key t
6170: 6f 20 63 6f 6e 74 69 6e 75 65 2e 5c 6e 22 2c 0a  o continue.\n",.
6180: 20 20 20 20 20 20 20 20 20 20 47 45 54 50 49 44            GETPID
6190: 28 29 29 3b 0a 20 20 20 20 20 20 66 67 65 74 63  ());.      fgetc
61a0: 28 73 74 64 69 6e 29 3b 0a 20 20 20 20 7d 65 6c  (stdin);.    }el
61b0: 73 65 7b 0a 23 69 66 20 64 65 66 69 6e 65 64 28  se{.#if defined(
61c0: 5f 57 49 4e 33 32 29 20 7c 7c 20 64 65 66 69 6e  _WIN32) || defin
61d0: 65 64 28 57 49 4e 33 32 29 0a 20 20 20 20 20 20  ed(WIN32).      
61e0: 44 65 62 75 67 42 72 65 61 6b 28 29 3b 0a 23 65  DebugBreak();.#e
61f0: 6c 69 66 20 64 65 66 69 6e 65 64 28 53 49 47 54  lif defined(SIGT
6200: 52 41 50 29 0a 20 20 20 20 20 20 72 61 69 73 65  RAP).      raise
6210: 28 53 49 47 54 52 41 50 29 3b 0a 23 65 6e 64 69  (SIGTRAP);.#endi
6220: 66 0a 20 20 20 20 7d 0a 20 20 7d 0a 23 65 6e 64  f.    }.  }.#end
6230: 69 66 0a 0a 20 20 66 6f 73 73 69 6c 5f 6c 69 6d  if..  fossil_lim
6240: 69 74 5f 6d 65 6d 6f 72 79 28 31 29 3b 0a 20 20  it_memory(1);.  
6250: 69 66 28 20 73 71 6c 69 74 65 33 5f 6c 69 62 76  if( sqlite3_libv
6260: 65 72 73 69 6f 6e 5f 6e 75 6d 62 65 72 28 29 3c  ersion_number()<
6270: 33 30 31 34 30 30 30 20 29 7b 0a 20 20 20 20 66  3014000 ){.    f
6280: 6f 73 73 69 6c 5f 70 61 6e 69 63 28 22 55 6e 73  ossil_panic("Uns
6290: 75 69 74 61 62 6c 65 20 53 51 4c 69 74 65 20 76  uitable SQLite v
62a0: 65 72 73 69 6f 6e 20 25 73 2c 20 6d 75 73 74 20  ersion %s, must 
62b0: 62 65 20 61 74 20 6c 65 61 73 74 20 33 2e 31 34  be at least 3.14
62c0: 2e 30 22 2c 0a 20 20 20 20 20 20 20 20 20 20 20  .0",.           
62d0: 20 20 20 20 20 20 73 71 6c 69 74 65 33 5f 6c 69        sqlite3_li
62e0: 62 76 65 72 73 69 6f 6e 28 29 29 3b 0a 20 20 7d  bversion());.  }
62f0: 0a 20 20 73 71 6c 69 74 65 33 5f 63 6f 6e 66 69  .  sqlite3_confi
6300: 67 28 53 51 4c 49 54 45 5f 43 4f 4e 46 49 47 5f  g(SQLITE_CONFIG_
6310: 4d 55 4c 54 49 54 48 52 45 41 44 29 3b 0a 20 20  MULTITHREAD);.  
6320: 73 71 6c 69 74 65 33 5f 63 6f 6e 66 69 67 28 53  sqlite3_config(S
6330: 51 4c 49 54 45 5f 43 4f 4e 46 49 47 5f 4c 4f 47  QLITE_CONFIG_LOG
6340: 2c 20 66 6f 73 73 69 6c 5f 73 71 6c 69 74 65 5f  , fossil_sqlite_
6350: 6c 6f 67 2c 20 30 29 3b 0a 20 20 6d 65 6d 73 65  log, 0);.  memse
6360: 74 28 26 67 2c 20 30 2c 20 73 69 7a 65 6f 66 28  t(&g, 0, sizeof(
6370: 67 29 29 3b 0a 20 20 67 2e 6e 6f 77 20 3d 20 74  g));.  g.now = t
6380: 69 6d 65 28 30 29 3b 0a 20 20 67 2e 68 74 74 70  ime(0);.  g.http
6390: 48 65 61 64 65 72 20 3d 20 65 6d 70 74 79 5f 62  Header = empty_b
63a0: 6c 6f 62 3b 0a 23 69 66 64 65 66 20 46 4f 53 53  lob;.#ifdef FOSS
63b0: 49 4c 5f 45 4e 41 42 4c 45 5f 4a 53 4f 4e 0a 23  IL_ENABLE_JSON.#
63c0: 69 66 20 64 65 66 69 6e 65 64 28 4e 44 45 42 55  if defined(NDEBU
63d0: 47 29 0a 20 20 67 2e 6a 73 6f 6e 2e 65 72 72 6f  G).  g.json.erro
63e0: 72 44 65 74 61 69 6c 50 61 72 61 6e 6f 69 61 20  rDetailParanoia 
63f0: 3d 20 32 20 2f 2a 20 46 49 58 4d 45 3a 20 6d 61  = 2 /* FIXME: ma
6400: 6b 65 20 63 6f 6e 66 69 67 75 72 61 62 6c 65 0a  ke configurable.
6410: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
6420: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
6430: 20 20 20 20 4f 6e 65 20 70 72 6f 62 6c 65 6d 20      One problem 
6440: 77 65 20 68 61 76 65 20 68 65 72 65 20 69 73 20  we have here is 
6450: 74 68 61 74 20 74 68 69 73 0a 20 20 20 20 20 20  that this.      
6460: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
6470: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 63 6f                co
6480: 64 65 20 69 73 20 6e 65 65 64 65 64 20 62 65 66  de is needed bef
6490: 6f 72 65 20 74 68 65 20 64 62 20 69 73 20 6f 70  ore the db is op
64a0: 65 6e 65 64 2c 0a 20 20 20 20 20 20 20 20 20 20  ened,.          
64b0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
64c0: 20 20 20 20 20 20 20 20 20 20 73 6f 20 77 65 20            so we 
64d0: 63 61 6e 27 74 20 73 71 6c 20 66 6f 72 20 69 74  can't sql for it
64e0: 2e 2a 2f 3b 0a 23 65 6c 73 65 0a 20 20 67 2e 6a  .*/;.#else.  g.j
64f0: 73 6f 6e 2e 65 72 72 6f 72 44 65 74 61 69 6c 50  son.errorDetailP
6500: 61 72 61 6e 6f 69 61 20 3d 20 30 3b 0a 23 65 6e  aranoia = 0;.#en
6510: 64 69 66 0a 20 20 67 2e 6a 73 6f 6e 2e 6f 75 74  dif.  g.json.out
6520: 4f 70 74 20 3d 20 63 73 6f 6e 5f 6f 75 74 70 75  Opt = cson_outpu
6530: 74 5f 6f 70 74 5f 65 6d 70 74 79 3b 0a 20 20 67  t_opt_empty;.  g
6540: 2e 6a 73 6f 6e 2e 6f 75 74 4f 70 74 2e 61 64 64  .json.outOpt.add
6550: 4e 65 77 6c 69 6e 65 20 3d 20 31 3b 0a 20 20 67  Newline = 1;.  g
6560: 2e 6a 73 6f 6e 2e 6f 75 74 4f 70 74 2e 69 6e 64  .json.outOpt.ind
6570: 65 6e 74 61 74 69 6f 6e 20 3d 20 31 20 2f 2a 20  entation = 1 /* 
6580: 69 6e 20 43 47 49 2f 73 65 72 76 65 72 20 6d 6f  in CGI/server mo
6590: 64 65 20 74 68 69 73 20 63 61 6e 20 62 65 20 63  de this can be c
65a0: 6f 6e 66 69 67 75 72 65 64 20 2a 2f 3b 0a 23 65  onfigured */;.#e
65b0: 6e 64 69 66 20 2f 2a 20 46 4f 53 53 49 4c 5f 45  ndif /* FOSSIL_E
65c0: 4e 41 42 4c 45 5f 4a 53 4f 4e 20 2a 2f 0a 20 20  NABLE_JSON */.  
65d0: 65 78 70 61 6e 64 5f 61 72 67 73 5f 6f 70 74 69  expand_args_opti
65e0: 6f 6e 28 61 72 67 63 2c 20 61 72 67 76 29 3b 0a  on(argc, argv);.
65f0: 23 69 66 64 65 66 20 46 4f 53 53 49 4c 5f 45 4e  #ifdef FOSSIL_EN
6600: 41 42 4c 45 5f 54 43 4c 0a 20 20 6d 65 6d 73 65  ABLE_TCL.  memse
6610: 74 28 26 67 2e 74 63 6c 2c 20 30 2c 20 73 69 7a  t(&g.tcl, 0, siz
6620: 65 6f 66 28 54 63 6c 43 6f 6e 74 65 78 74 29 29  eof(TclContext))
6630: 3b 0a 20 20 67 2e 74 63 6c 2e 61 72 67 63 20 3d  ;.  g.tcl.argc =
6640: 20 67 2e 61 72 67 63 3b 0a 20 20 67 2e 74 63 6c   g.argc;.  g.tcl
6650: 2e 61 72 67 76 20 3d 20 63 6f 70 79 5f 61 72 67  .argv = copy_arg
6660: 73 28 67 2e 61 72 67 63 2c 20 67 2e 61 72 67 76  s(g.argc, g.argv
6670: 29 3b 20 2f 2a 20 73 61 76 65 20 66 75 6c 6c 20  ); /* save full 
6680: 61 72 67 75 6d 65 6e 74 73 20 2a 2f 0a 23 65 6e  arguments */.#en
6690: 64 69 66 0a 20 20 67 2e 6d 61 69 6e 54 69 6d 65  dif.  g.mainTime
66a0: 72 49 64 20 3d 20 66 6f 73 73 69 6c 5f 74 69 6d  rId = fossil_tim
66b0: 65 72 5f 73 74 61 72 74 28 29 3b 0a 20 20 63 61  er_start();.  ca
66c0: 70 74 75 72 65 5f 63 61 73 65 5f 73 65 6e 73 69  pture_case_sensi
66d0: 74 69 76 65 5f 6f 70 74 69 6f 6e 28 29 3b 0a 20  tive_option();. 
66e0: 20 67 2e 7a 56 66 73 4e 61 6d 65 20 3d 20 66 69   g.zVfsName = fi
66f0: 6e 64 5f 6f 70 74 69 6f 6e 28 22 76 66 73 22 2c  nd_option("vfs",
6700: 30 2c 31 29 3b 0a 20 20 69 66 28 20 67 2e 7a 56  0,1);.  if( g.zV
6710: 66 73 4e 61 6d 65 3d 3d 30 20 29 7b 0a 20 20 20  fsName==0 ){.   
6720: 20 67 2e 7a 56 66 73 4e 61 6d 65 20 3d 20 66 6f   g.zVfsName = fo
6730: 73 73 69 6c 5f 67 65 74 65 6e 76 28 22 46 4f 53  ssil_getenv("FOS
6740: 53 49 4c 5f 56 46 53 22 29 3b 0a 20 20 7d 0a 20  SIL_VFS");.  }. 
6750: 20 69 66 28 20 67 2e 7a 56 66 73 4e 61 6d 65 20   if( g.zVfsName 
6760: 29 7b 0a 20 20 20 20 73 71 6c 69 74 65 33 5f 76  ){.    sqlite3_v
6770: 66 73 20 2a 70 56 66 73 20 3d 20 73 71 6c 69 74  fs *pVfs = sqlit
6780: 65 33 5f 76 66 73 5f 66 69 6e 64 28 67 2e 7a 56  e3_vfs_find(g.zV
6790: 66 73 4e 61 6d 65 29 3b 0a 20 20 20 20 69 66 28  fsName);.    if(
67a0: 20 70 56 66 73 20 29 7b 0a 20 20 20 20 20 20 73   pVfs ){.      s
67b0: 71 6c 69 74 65 33 5f 76 66 73 5f 72 65 67 69 73  qlite3_vfs_regis
67c0: 74 65 72 28 70 56 66 73 2c 20 31 29 3b 0a 20 20  ter(pVfs, 1);.  
67d0: 20 20 7d 65 6c 73 65 7b 0a 20 20 20 20 20 20 66    }else{.      f
67e0: 6f 73 73 69 6c 5f 66 61 74 61 6c 28 22 6e 6f 20  ossil_fatal("no 
67f0: 73 75 63 68 20 56 46 53 3a 20 5c 22 25 73 5c 22  such VFS: \"%s\"
6800: 22 2c 20 67 2e 7a 56 66 73 4e 61 6d 65 29 3b 0a  ", g.zVfsName);.
6810: 20 20 20 20 7d 0a 20 20 7d 0a 20 20 69 66 28 20      }.  }.  if( 
6820: 66 6f 73 73 69 6c 5f 67 65 74 65 6e 76 28 22 47  fossil_getenv("G
6830: 41 54 45 57 41 59 5f 49 4e 54 45 52 46 41 43 45  ATEWAY_INTERFACE
6840: 22 29 21 3d 30 20 26 26 20 21 66 69 6e 64 5f 6f  ")!=0 && !find_o
6850: 70 74 69 6f 6e 28 22 6e 6f 63 67 69 22 2c 20 30  ption("nocgi", 0
6860: 2c 20 30 29 29 7b 0a 20 20 20 20 7a 43 6d 64 4e  , 0)){.    zCmdN
6870: 61 6d 65 20 3d 20 22 63 67 69 22 3b 0a 20 20 20  ame = "cgi";.   
6880: 20 67 2e 69 73 48 54 54 50 20 3d 20 31 3b 0a 20   g.isHTTP = 1;. 
6890: 20 7d 65 6c 73 65 20 69 66 28 20 67 2e 61 72 67   }else if( g.arg
68a0: 63 3c 32 20 26 26 20 21 66 6f 73 73 69 6c 45 78  c<2 && !fossilEx
68b0: 65 48 61 73 41 70 70 65 6e 64 65 64 52 65 70 6f  eHasAppendedRepo
68c0: 28 29 20 29 7b 0a 20 20 20 20 66 6f 73 73 69 6c  () ){.    fossil
68d0: 5f 70 72 69 6e 74 28 0a 20 20 20 20 20 20 20 22  _print(.       "
68e0: 55 73 61 67 65 3a 20 25 73 20 43 4f 4d 4d 41 4e  Usage: %s COMMAN
68f0: 44 20 2e 2e 2e 5c 6e 22 0a 20 20 20 20 20 20 20  D ...\n".       
6900: 22 20 20 20 6f 72 3a 20 25 73 20 68 65 6c 70 20  "   or: %s help 
6910: 20 20 20 20 20 20 20 20 20 20 2d 2d 20 66 6f 72            -- for
6920: 20 61 20 6c 69 73 74 20 6f 66 20 63 6f 6d 6d 6f   a list of commo
6930: 6e 20 63 6f 6d 6d 61 6e 64 73 5c 6e 22 0a 20 20  n commands\n".  
6940: 20 20 20 20 20 22 20 20 20 6f 72 3a 20 25 73 20       "   or: %s 
6950: 68 65 6c 70 20 43 4f 4d 4d 41 4e 44 20 20 20 2d  help COMMAND   -
6960: 2d 20 66 6f 72 20 68 65 6c 70 20 77 69 74 68 20  - for help with 
6970: 74 68 65 20 6e 61 6d 65 64 20 63 6f 6d 6d 61 6e  the named comman
6980: 64 5c 6e 22 2c 0a 20 20 20 20 20 20 20 67 2e 61  d\n",.       g.a
6990: 72 67 76 5b 30 5d 2c 20 67 2e 61 72 67 76 5b 30  rgv[0], g.argv[0
69a0: 5d 2c 20 67 2e 61 72 67 76 5b 30 5d 29 3b 0a 20  ], g.argv[0]);. 
69b0: 20 20 20 66 6f 73 73 69 6c 5f 70 72 69 6e 74 28     fossil_print(
69c0: 0a 20 20 20 20 20 20 22 5c 6e 43 6f 6d 6d 61 6e  .      "\nComman
69d0: 64 73 20 61 6e 64 20 66 69 6c 65 6e 61 6d 65 73  ds and filenames
69e0: 20 6d 61 79 20 62 65 20 70 61 73 73 65 64 20 6f   may be passed o
69f0: 6e 20 74 6f 20 66 6f 73 73 69 6c 20 66 72 6f 6d  n to fossil from
6a00: 20 61 20 66 69 6c 65 5c 6e 22 0a 20 20 20 20 20   a file\n".     
6a10: 20 22 62 79 20 75 73 69 6e 67 3a 5c 6e 22 0a 20   "by using:\n". 
6a20: 20 20 20 20 20 22 5c 6e 20 20 20 20 25 73 20 2d       "\n    %s -
6a30: 2d 61 72 67 73 20 46 49 4c 45 4e 41 4d 45 20 2e  -args FILENAME .
6a40: 2e 2e 5c 6e 22 2c 0a 20 20 20 20 20 20 67 2e 61  ..\n",.      g.a
6a50: 72 67 76 5b 30 5d 0a 20 20 20 20 29 3b 0a 20 20  rgv[0].    );.  
6a60: 20 20 66 6f 73 73 69 6c 5f 70 72 69 6e 74 28 0a    fossil_print(.
6a70: 20 20 20 20 20 20 22 5c 6e 45 61 63 68 20 6c 69        "\nEach li
6a80: 6e 65 20 6f 66 20 74 68 65 20 66 69 6c 65 20 69  ne of the file i
6a90: 73 20 61 73 73 75 6d 65 64 20 74 6f 20 62 65 20  s assumed to be 
6aa0: 61 20 66 69 6c 65 6e 61 6d 65 20 75 6e 6c 65 73  a filename unles
6ab0: 73 20 69 74 20 73 74 61 72 74 73 5c 6e 22 0a 20  s it starts\n". 
6ac0: 20 20 20 20 20 22 77 69 74 68 20 27 2d 27 20 61       "with '-' a
6ad0: 6e 64 20 63 6f 6e 74 61 69 6e 73 20 61 20 73 70  nd contains a sp
6ae0: 61 63 65 2c 20 69 6e 20 77 68 69 63 68 20 63 61  ace, in which ca
6af0: 73 65 20 69 74 20 69 73 20 61 73 73 75 6d 65 64  se it is assumed
6b00: 20 74 6f 20 62 65 5c 6e 22 0a 20 20 20 20 20 20   to be\n".      
6b10: 22 61 6e 6f 74 68 65 72 20 66 6c 61 67 20 61 6e  "another flag an
6b20: 64 20 69 73 20 74 72 65 61 74 65 64 20 61 73 20  d is treated as 
6b30: 73 75 63 68 2e 20 2d 2d 61 72 67 73 20 46 49 4c  such. --args FIL
6b40: 45 4e 41 4d 45 20 6d 61 79 20 62 65 20 75 73 65  ENAME may be use
6b50: 64 5c 6e 22 0a 20 20 20 20 20 20 22 69 6e 20 63  d\n".      "in c
6b60: 6f 6e 6a 75 6e 63 74 69 6f 6e 20 77 69 74 68 20  onjunction with 
6b70: 61 6e 79 20 6f 74 68 65 72 20 66 6c 61 67 73 2e  any other flags.
6b80: 5c 6e 22 29 3b 0a 20 20 20 20 66 6f 73 73 69 6c  \n");.    fossil
6b90: 5f 65 78 69 74 28 31 29 3b 0a 20 20 7d 65 6c 73  _exit(1);.  }els
6ba0: 65 7b 0a 20 20 20 20 63 6f 6e 73 74 20 63 68 61  e{.    const cha
6bb0: 72 20 2a 7a 43 68 64 69 72 20 3d 20 66 69 6e 64  r *zChdir = find
6bc0: 5f 6f 70 74 69 6f 6e 28 22 63 68 64 69 72 22 2c  _option("chdir",
6bd0: 30 2c 31 29 3b 0a 20 20 20 20 67 2e 69 73 48 54  0,1);.    g.isHT
6be0: 54 50 20 3d 20 30 3b 0a 20 20 20 20 67 2e 72 63  TP = 0;.    g.rc
6bf0: 76 69 64 20 3d 20 30 3b 0a 20 20 20 20 67 2e 66  vid = 0;.    g.f
6c00: 51 75 69 65 74 20 3d 20 66 69 6e 64 5f 6f 70 74  Quiet = find_opt
6c10: 69 6f 6e 28 22 71 75 69 65 74 22 2c 20 30 2c 20  ion("quiet", 0, 
6c20: 30 29 21 3d 30 3b 0a 20 20 20 20 67 2e 66 53 71  0)!=0;.    g.fSq
6c30: 6c 54 72 61 63 65 20 3d 20 66 69 6e 64 5f 6f 70  lTrace = find_op
6c40: 74 69 6f 6e 28 22 73 71 6c 74 72 61 63 65 22 2c  tion("sqltrace",
6c50: 20 30 2c 20 30 29 21 3d 30 3b 0a 20 20 20 20 67   0, 0)!=0;.    g
6c60: 2e 66 53 71 6c 53 74 61 74 73 20 3d 20 66 69 6e  .fSqlStats = fin
6c70: 64 5f 6f 70 74 69 6f 6e 28 22 73 71 6c 73 74 61  d_option("sqlsta
6c80: 74 73 22 2c 20 30 2c 20 30 29 21 3d 30 3b 0a 20  ts", 0, 0)!=0;. 
6c90: 20 20 20 67 2e 66 53 79 73 74 65 6d 54 72 61 63     g.fSystemTrac
6ca0: 65 20 3d 20 66 69 6e 64 5f 6f 70 74 69 6f 6e 28  e = find_option(
6cb0: 22 73 79 73 74 65 6d 74 72 61 63 65 22 2c 20 30  "systemtrace", 0
6cc0: 2c 20 30 29 21 3d 30 3b 0a 20 20 20 20 67 2e 66  , 0)!=0;.    g.f
6cd0: 53 73 68 54 72 61 63 65 20 3d 20 66 69 6e 64 5f  SshTrace = find_
6ce0: 6f 70 74 69 6f 6e 28 22 73 73 68 74 72 61 63 65  option("sshtrace
6cf0: 22 2c 20 30 2c 20 30 29 21 3d 30 3b 0a 20 20 20  ", 0, 0)!=0;.   
6d00: 20 67 2e 66 43 67 69 54 72 61 63 65 20 3d 20 66   g.fCgiTrace = f
6d10: 69 6e 64 5f 6f 70 74 69 6f 6e 28 22 63 67 69 74  ind_option("cgit
6d20: 72 61 63 65 22 2c 20 30 2c 20 30 29 21 3d 30 3b  race", 0, 0)!=0;
6d30: 0a 20 20 20 20 67 2e 66 53 73 68 43 6c 69 65 6e  .    g.fSshClien
6d40: 74 20 3d 20 30 3b 0a 20 20 20 20 67 2e 7a 53 73  t = 0;.    g.zSs
6d50: 68 43 6d 64 20 3d 20 30 3b 0a 20 20 20 20 69 66  hCmd = 0;.    if
6d60: 28 20 67 2e 66 53 71 6c 54 72 61 63 65 20 29 20  ( g.fSqlTrace ) 
6d70: 67 2e 66 53 71 6c 53 74 61 74 73 20 3d 20 31 3b  g.fSqlStats = 1;
6d80: 0a 20 20 20 20 67 2e 66 48 74 74 70 54 72 61 63  .    g.fHttpTrac
6d90: 65 20 3d 20 66 69 6e 64 5f 6f 70 74 69 6f 6e 28  e = find_option(
6da0: 22 68 74 74 70 74 72 61 63 65 22 2c 20 30 2c 20  "httptrace", 0, 
6db0: 30 29 21 3d 30 3b 0a 23 69 66 64 65 66 20 46 4f  0)!=0;.#ifdef FO
6dc0: 53 53 49 4c 5f 45 4e 41 42 4c 45 5f 54 48 31 5f  SSIL_ENABLE_TH1_
6dd0: 48 4f 4f 4b 53 0a 20 20 20 20 67 2e 66 4e 6f 54  HOOKS.    g.fNoT
6de0: 68 48 6f 6f 6b 20 3d 20 66 69 6e 64 5f 6f 70 74  hHook = find_opt
6df0: 69 6f 6e 28 22 6e 6f 2d 74 68 2d 68 6f 6f 6b 22  ion("no-th-hook"
6e00: 2c 20 30 2c 20 30 29 21 3d 30 3b 0a 23 65 6e 64  , 0, 0)!=0;.#end
6e10: 69 66 0a 20 20 20 20 67 2e 66 41 6e 79 54 72 61  if.    g.fAnyTra
6e20: 63 65 20 3d 20 67 2e 66 53 71 6c 54 72 61 63 65  ce = g.fSqlTrace
6e30: 7c 67 2e 66 53 79 73 74 65 6d 54 72 61 63 65 7c  |g.fSystemTrace|
6e40: 67 2e 66 53 73 68 54 72 61 63 65 7c 0a 20 20 20  g.fSshTrace|.   
6e50: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 67                 g
6e60: 2e 66 48 74 74 70 54 72 61 63 65 7c 67 2e 66 43  .fHttpTrace|g.fC
6e70: 67 69 54 72 61 63 65 3b 0a 20 20 20 20 67 2e 7a  giTrace;.    g.z
6e80: 48 74 74 70 41 75 74 68 20 3d 20 30 3b 0a 20 20  HttpAuth = 0;.  
6e90: 20 20 67 2e 7a 4c 6f 67 69 6e 20 3d 20 66 69 6e    g.zLogin = fin
6ea0: 64 5f 6f 70 74 69 6f 6e 28 22 75 73 65 72 22 2c  d_option("user",
6eb0: 20 22 55 22 2c 20 31 29 3b 0a 20 20 20 20 67 2e   "U", 1);.    g.
6ec0: 7a 53 53 4c 49 64 65 6e 74 69 74 79 20 3d 20 66  zSSLIdentity = f
6ed0: 69 6e 64 5f 6f 70 74 69 6f 6e 28 22 73 73 6c 2d  ind_option("ssl-
6ee0: 69 64 65 6e 74 69 74 79 22 2c 20 30 2c 20 31 29  identity", 0, 1)
6ef0: 3b 0a 20 20 20 20 67 2e 7a 45 72 72 6c 6f 67 20  ;.    g.zErrlog 
6f00: 3d 20 66 69 6e 64 5f 6f 70 74 69 6f 6e 28 22 65  = find_option("e
6f10: 72 72 6f 72 6c 6f 67 22 2c 20 30 2c 20 31 29 3b  rrorlog", 0, 1);
6f20: 0a 20 20 20 20 66 6f 73 73 69 6c 5f 69 6e 69 74  .    fossil_init
6f30: 5f 66 6c 61 67 73 5f 66 72 6f 6d 5f 6f 70 74 69  _flags_from_opti
6f40: 6f 6e 73 28 29 3b 0a 20 20 20 20 69 66 28 20 66  ons();.    if( f
6f50: 69 6e 64 5f 6f 70 74 69 6f 6e 28 22 75 74 63 22  ind_option("utc"
6f60: 2c 30 2c 30 29 20 29 20 67 2e 66 54 69 6d 65 46  ,0,0) ) g.fTimeF
6f70: 6f 72 6d 61 74 20 3d 20 31 3b 0a 20 20 20 20 69  ormat = 1;.    i
6f80: 66 28 20 66 69 6e 64 5f 6f 70 74 69 6f 6e 28 22  f( find_option("
6f90: 6c 6f 63 61 6c 74 69 6d 65 22 2c 30 2c 30 29 20  localtime",0,0) 
6fa0: 29 20 67 2e 66 54 69 6d 65 46 6f 72 6d 61 74 20  ) g.fTimeFormat 
6fb0: 3d 20 32 3b 0a 20 20 20 20 69 66 28 20 7a 43 68  = 2;.    if( zCh
6fc0: 64 69 72 20 26 26 20 66 69 6c 65 5f 63 68 64 69  dir && file_chdi
6fd0: 72 28 7a 43 68 64 69 72 2c 20 30 29 20 29 7b 0a  r(zChdir, 0) ){.
6fe0: 20 20 20 20 20 20 66 6f 73 73 69 6c 5f 66 61 74        fossil_fat
6ff0: 61 6c 28 22 75 6e 61 62 6c 65 20 74 6f 20 63 68  al("unable to ch
7000: 61 6e 67 65 20 64 69 72 65 63 74 6f 72 69 65 73  ange directories
7010: 20 74 6f 20 25 73 22 2c 20 7a 43 68 64 69 72 29   to %s", zChdir)
7020: 3b 0a 20 20 20 20 7d 0a 20 20 20 20 69 66 28 20  ;.    }.    if( 
7030: 66 69 6e 64 5f 6f 70 74 69 6f 6e 28 22 68 65 6c  find_option("hel
7040: 70 22 2c 30 2c 30 29 21 3d 30 20 29 7b 0a 20 20  p",0,0)!=0 ){.  
7050: 20 20 20 20 2f 2a 20 49 66 20 2d 2d 68 65 6c 70      /* If --help
7060: 20 69 73 20 66 6f 75 6e 64 20 61 6e 79 77 68 65   is found anywhe
7070: 72 65 20 6f 6e 20 74 68 65 20 63 6f 6d 6d 61 6e  re on the comman
7080: 64 20 6c 69 6e 65 2c 20 74 72 61 6e 73 6c 61 74  d line, translat
7090: 65 20 74 68 65 20 63 6f 6d 6d 61 6e 64 0a 20 20  e the command.  
70a0: 20 20 20 20 20 2a 20 74 6f 20 22 66 6f 73 73 69       * to "fossi
70b0: 6c 20 68 65 6c 70 20 63 6d 64 6e 61 6d 65 22 20  l help cmdname" 
70c0: 77 68 65 72 65 20 22 63 6d 64 6e 61 6d 65 22 20  where "cmdname" 
70d0: 69 73 20 74 68 65 20 66 69 72 73 74 20 61 72 67  is the first arg
70e0: 75 6d 65 6e 74 20 74 68 61 74 0a 20 20 20 20 20  ument that.     
70f0: 20 20 2a 20 64 6f 65 73 20 6e 6f 74 20 62 65 67    * does not beg
7100: 69 6e 20 77 69 74 68 20 61 20 22 2d 22 20 63 68  in with a "-" ch
7110: 61 72 61 63 74 65 72 2e 20 20 49 66 20 61 6c 6c  aracter.  If all
7120: 20 61 72 67 75 6d 65 6e 74 73 20 73 74 61 72 74   arguments start
7130: 20 77 69 74 68 20 22 2d 22 2c 0a 20 20 20 20 20   with "-",.     
7140: 20 20 2a 20 74 72 61 6e 73 6c 61 74 65 20 74 6f    * translate to
7150: 20 22 66 6f 73 73 69 6c 20 68 65 6c 70 20 61 72   "fossil help ar
7160: 67 76 5b 31 5d 20 61 72 67 76 5b 32 5d 2e 2e 2e  gv[1] argv[2]...
7170: 22 2e 20 2a 2f 0a 20 20 20 20 20 20 69 6e 74 20  ". */.      int 
7180: 69 2c 20 6e 4e 65 77 41 72 67 63 3b 0a 20 20 20  i, nNewArgc;.   
7190: 20 20 20 63 68 61 72 20 2a 2a 7a 4e 65 77 41 72     char **zNewAr
71a0: 67 76 20 3d 20 66 6f 73 73 69 6c 5f 6d 61 6c 6c  gv = fossil_mall
71b0: 6f 63 28 20 73 69 7a 65 6f 66 28 63 68 61 72 2a  oc( sizeof(char*
71c0: 29 2a 28 67 2e 61 72 67 63 2b 32 29 20 29 3b 0a  )*(g.argc+2) );.
71d0: 20 20 20 20 20 20 7a 4e 65 77 41 72 67 76 5b 30        zNewArgv[0
71e0: 5d 20 3d 20 67 2e 61 72 67 76 5b 30 5d 3b 0a 20  ] = g.argv[0];. 
71f0: 20 20 20 20 20 7a 4e 65 77 41 72 67 76 5b 31 5d       zNewArgv[1]
7200: 20 3d 20 22 68 65 6c 70 22 3b 0a 20 20 20 20 20   = "help";.     
7210: 20 66 6f 72 28 69 3d 31 3b 20 69 3c 67 2e 61 72   for(i=1; i<g.ar
7220: 67 63 3b 20 69 2b 2b 29 7b 0a 20 20 20 20 20 20  gc; i++){.      
7230: 20 20 69 66 28 20 67 2e 61 72 67 76 5b 69 5d 5b    if( g.argv[i][
7240: 30 5d 21 3d 27 2d 27 20 29 7b 0a 20 20 20 20 20  0]!='-' ){.     
7250: 20 20 20 20 20 6e 4e 65 77 41 72 67 63 20 3d 20       nNewArgc = 
7260: 33 3b 0a 20 20 20 20 20 20 20 20 20 20 7a 4e 65  3;.          zNe
7270: 77 41 72 67 76 5b 32 5d 20 3d 20 67 2e 61 72 67  wArgv[2] = g.arg
7280: 76 5b 69 5d 3b 0a 20 20 20 20 20 20 20 20 20 20  v[i];.          
7290: 7a 4e 65 77 41 72 67 76 5b 33 5d 20 3d 20 30 3b  zNewArgv[3] = 0;
72a0: 0a 20 20 20 20 20 20 20 20 20 20 62 72 65 61 6b  .          break
72b0: 3b 0a 20 20 20 20 20 20 20 20 7d 0a 20 20 20 20  ;.        }.    
72c0: 20 20 7d 0a 20 20 20 20 20 20 69 66 28 20 69 3d    }.      if( i=
72d0: 3d 67 2e 61 72 67 63 20 29 7b 0a 20 20 20 20 20  =g.argc ){.     
72e0: 20 20 20 66 6f 72 28 69 3d 31 3b 20 69 3c 67 2e     for(i=1; i<g.
72f0: 61 72 67 63 3b 20 69 2b 2b 29 20 7a 4e 65 77 41  argc; i++) zNewA
7300: 72 67 76 5b 69 2b 31 5d 20 3d 20 67 2e 61 72 67  rgv[i+1] = g.arg
7310: 76 5b 69 5d 3b 0a 20 20 20 20 20 20 20 20 6e 4e  v[i];.        nN
7320: 65 77 41 72 67 63 20 3d 20 67 2e 61 72 67 63 2b  ewArgc = g.argc+
7330: 31 3b 0a 20 20 20 20 20 20 20 20 7a 4e 65 77 41  1;.        zNewA
7340: 72 67 76 5b 69 2b 31 5d 20 3d 20 30 3b 0a 20 20  rgv[i+1] = 0;.  
7350: 20 20 20 20 7d 0a 20 20 20 20 20 20 67 2e 61 72      }.      g.ar
7360: 67 63 20 3d 20 6e 4e 65 77 41 72 67 63 3b 0a 20  gc = nNewArgc;. 
7370: 20 20 20 20 20 67 2e 61 72 67 76 20 3d 20 7a 4e       g.argv = zN
7380: 65 77 41 72 67 76 3b 0a 20 20 20 20 7d 0a 20 20  ewArgv;.    }.  
7390: 20 20 7a 43 6d 64 4e 61 6d 65 20 3d 20 67 2e 61    zCmdName = g.a
73a0: 72 67 76 5b 31 5d 3b 0a 20 20 7d 0a 23 69 66 6e  rgv[1];.  }.#ifn
73b0: 64 65 66 20 5f 57 49 4e 33 32 0a 20 20 2f 2a 20  def _WIN32.  /* 
73c0: 54 68 65 72 65 20 69 73 20 61 20 62 75 67 20 69  There is a bug i
73d0: 6e 20 73 74 75 6e 6e 65 6c 34 20 69 6e 20 77 68  n stunnel4 in wh
73e0: 69 63 68 20 69 74 20 73 6f 6d 65 74 69 6d 65 73  ich it sometimes
73f0: 20 73 74 61 72 74 73 20 75 70 20 63 6c 69 65 6e   starts up clien
7400: 74 0a 20 20 2a 2a 20 70 72 6f 63 65 73 73 65 73  t.  ** processes
7410: 20 77 69 74 68 6f 75 74 20 66 69 72 73 74 20 6f   without first o
7420: 70 65 6e 69 6e 67 20 66 69 6c 65 20 64 65 73 63  pening file desc
7430: 72 69 70 74 6f 72 20 32 20 28 73 74 61 6e 64 61  riptor 2 (standa
7440: 72 64 20 65 72 72 6f 72 29 2e 0a 20 20 2a 2a 20  rd error)..  ** 
7450: 49 66 20 74 68 69 73 20 68 61 70 70 65 6e 73 2c  If this happens,
7460: 20 61 6e 64 20 61 20 73 75 62 73 65 71 75 65 6e   and a subsequen
7470: 74 20 6f 70 65 6e 28 29 20 6f 66 20 61 20 64 61  t open() of a da
7480: 74 61 62 61 73 65 20 72 65 74 75 72 6e 73 20 66  tabase returns f
7490: 69 6c 65 0a 20 20 2a 2a 20 64 65 73 63 72 69 70  ile.  ** descrip
74a0: 74 6f 72 20 32 2c 20 61 6e 64 20 74 68 65 6e 20  tor 2, and then 
74b0: 61 6e 20 61 73 73 65 72 74 28 29 20 66 69 72 65  an assert() fire
74c0: 73 20 61 6e 64 20 77 72 69 74 65 73 20 6f 6e 20  s and writes on 
74d0: 66 64 20 32 2c 20 74 68 61 74 0a 20 20 2a 2a 20  fd 2, that.  ** 
74e0: 63 61 6e 20 63 6f 72 72 75 70 74 20 74 68 65 20  can corrupt the 
74f0: 64 61 74 61 20 66 69 6c 65 2e 20 20 54 6f 20 61  data file.  To a
7500: 76 6f 69 64 20 74 68 69 73 20 70 72 6f 62 6c 65  void this proble
7510: 6d 2c 20 6d 61 6b 65 20 73 75 72 65 20 6f 70 65  m, make sure ope
7520: 6e 28 29 0a 20 20 2a 2a 20 77 69 6c 6c 20 6e 65  n().  ** will ne
7530: 76 65 72 20 72 65 74 75 72 6e 20 66 69 6c 65 20  ver return file 
7540: 64 65 73 63 72 69 70 74 6f 72 20 32 20 6f 72 20  descriptor 2 or 
7550: 6c 65 73 73 2e 20 2a 2f 0a 20 20 69 66 28 20 21  less. */.  if( !
7560: 69 73 5f 76 61 6c 69 64 5f 66 64 28 32 29 20 29  is_valid_fd(2) )
7570: 7b 0a 20 20 20 20 69 6e 74 20 6e 54 72 79 20 3d  {.    int nTry =
7580: 20 30 3b 0a 20 20 20 20 69 6e 74 20 66 64 20 3d   0;.    int fd =
7590: 20 30 3b 0a 20 20 20 20 69 6e 74 20 78 20 3d 20   0;.    int x = 
75a0: 30 3b 0a 20 20 20 20 64 6f 7b 0a 20 20 20 20 20  0;.    do{.     
75b0: 20 66 64 20 3d 20 6f 70 65 6e 28 22 2f 64 65 76   fd = open("/dev
75c0: 2f 6e 75 6c 6c 22 2c 4f 5f 57 52 4f 4e 4c 59 29  /null",O_WRONLY)
75d0: 3b 0a 20 20 20 20 20 20 69 66 28 20 66 64 3e 3d  ;.      if( fd>=
75e0: 32 20 29 20 62 72 65 61 6b 3b 0a 20 20 20 20 20  2 ) break;.     
75f0: 20 69 66 28 20 66 64 3c 30 20 29 20 78 20 3d 20   if( fd<0 ) x = 
7600: 65 72 72 6e 6f 3b 0a 20 20 20 20 7d 77 68 69 6c  errno;.    }whil
7610: 65 28 20 6e 54 72 79 2b 2b 20 3c 20 32 20 29 3b  e( nTry++ < 2 );
7620: 0a 20 20 20 20 69 66 28 20 66 64 3c 32 20 29 7b  .    if( fd<2 ){
7630: 0a 20 20 20 20 20 20 67 2e 63 67 69 4f 75 74 70  .      g.cgiOutp
7640: 75 74 20 3d 20 31 3b 0a 20 20 20 20 20 20 67 2e  ut = 1;.      g.
7650: 68 74 74 70 4f 75 74 20 3d 20 73 74 64 6f 75 74  httpOut = stdout
7660: 3b 0a 20 20 20 20 20 20 67 2e 66 75 6c 6c 48 74  ;.      g.fullHt
7670: 74 70 52 65 70 6c 79 20 3d 20 21 67 2e 69 73 48  tpReply = !g.isH
7680: 54 54 50 3b 0a 20 20 20 20 20 20 66 6f 73 73 69  TTP;.      fossi
7690: 6c 5f 70 61 6e 69 63 28 22 66 69 6c 65 20 64 65  l_panic("file de
76a0: 73 63 72 69 70 74 6f 72 20 32 20 69 73 20 6e 6f  scriptor 2 is no
76b0: 74 20 6f 70 65 6e 2e 20 28 66 64 3d 25 64 2c 20  t open. (fd=%d, 
76c0: 65 72 72 6e 6f 3d 25 64 29 22 2c 0a 20 20 20 20  errno=%d)",.    
76d0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 66                 f
76e0: 64 2c 20 78 29 3b 0a 20 20 20 20 7d 0a 20 20 7d  d, x);.    }.  }
76f0: 0a 23 65 6e 64 69 66 0a 20 20 72 63 20 3d 20 64  .#endif.  rc = d
7700: 69 73 70 61 74 63 68 5f 6e 61 6d 65 5f 73 65 61  ispatch_name_sea
7710: 72 63 68 28 7a 43 6d 64 4e 61 6d 65 2c 20 43 4d  rch(zCmdName, CM
7720: 44 46 4c 41 47 5f 43 4f 4d 4d 41 4e 44 7c 43 4d  DFLAG_COMMAND|CM
7730: 44 46 4c 41 47 5f 50 52 45 46 49 58 2c 20 26 70  DFLAG_PREFIX, &p
7740: 43 6d 64 29 3b 0a 20 20 69 66 28 20 72 63 3d 3d  Cmd);.  if( rc==
7750: 31 20 29 7b 0a 23 69 66 64 65 66 20 46 4f 53 53  1 ){.#ifdef FOSS
7760: 49 4c 5f 45 4e 41 42 4c 45 5f 54 48 31 5f 48 4f  IL_ENABLE_TH1_HO
7770: 4f 4b 53 0a 20 20 20 20 69 66 28 20 21 67 2e 69  OKS.    if( !g.i
7780: 73 48 54 54 50 20 26 26 20 21 67 2e 66 4e 6f 54  sHTTP && !g.fNoT
7790: 68 48 6f 6f 6b 20 29 7b 0a 20 20 20 20 20 20 72  hHook ){.      r
77a0: 63 20 3d 20 54 68 5f 43 6f 6d 6d 61 6e 64 48 6f  c = Th_CommandHo
77b0: 6f 6b 28 7a 43 6d 64 4e 61 6d 65 2c 20 30 29 3b  ok(zCmdName, 0);
77c0: 0a 20 20 20 20 7d 65 6c 73 65 7b 0a 20 20 20 20  .    }else{.    
77d0: 20 20 72 63 20 3d 20 54 48 5f 4f 4b 3b 0a 20 20    rc = TH_OK;.  
77e0: 20 20 7d 0a 20 20 20 20 69 66 28 20 72 63 3d 3d    }.    if( rc==
77f0: 54 48 5f 4f 4b 20 7c 7c 20 72 63 3d 3d 54 48 5f  TH_OK || rc==TH_
7800: 52 45 54 55 52 4e 20 7c 7c 20 72 63 3d 3d 54 48  RETURN || rc==TH
7810: 5f 43 4f 4e 54 49 4e 55 45 20 29 7b 0a 20 20 20  _CONTINUE ){.   
7820: 20 20 20 69 66 28 20 72 63 3d 3d 54 48 5f 4f 4b     if( rc==TH_OK
7830: 20 7c 7c 20 72 63 3d 3d 54 48 5f 52 45 54 55 52   || rc==TH_RETUR
7840: 4e 20 29 7b 0a 23 65 6e 64 69 66 0a 20 20 20 20  N ){.#endif.    
7850: 20 20 20 20 66 6f 73 73 69 6c 5f 66 61 74 61 6c      fossil_fatal
7860: 28 22 25 73 3a 20 75 6e 6b 6e 6f 77 6e 20 63 6f  ("%s: unknown co
7870: 6d 6d 61 6e 64 3a 20 25 73 5c 6e 22 0a 20 20 20  mmand: %s\n".   
7880: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
7890: 20 20 22 25 73 3a 20 75 73 65 20 5c 22 68 65 6c    "%s: use \"hel
78a0: 70 5c 22 20 66 6f 72 20 6d 6f 72 65 20 69 6e 66  p\" for more inf
78b0: 6f 72 6d 61 74 69 6f 6e 22 2c 0a 20 20 20 20 20  ormation",.     
78c0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
78d0: 67 2e 61 72 67 76 5b 30 5d 2c 20 7a 43 6d 64 4e  g.argv[0], zCmdN
78e0: 61 6d 65 2c 20 67 2e 61 72 67 76 5b 30 5d 29 3b  ame, g.argv[0]);
78f0: 0a 23 69 66 64 65 66 20 46 4f 53 53 49 4c 5f 45  .#ifdef FOSSIL_E
7900: 4e 41 42 4c 45 5f 54 48 31 5f 48 4f 4f 4b 53 0a  NABLE_TH1_HOOKS.
7910: 20 20 20 20 20 20 7d 0a 20 20 20 20 20 20 69 66        }.      if
7920: 28 20 21 67 2e 69 73 48 54 54 50 20 26 26 20 21  ( !g.isHTTP && !
7930: 67 2e 66 4e 6f 54 68 48 6f 6f 6b 20 26 26 20 28  g.fNoThHook && (
7940: 72 63 3d 3d 54 48 5f 4f 4b 20 7c 7c 20 72 63 3d  rc==TH_OK || rc=
7950: 3d 54 48 5f 43 4f 4e 54 49 4e 55 45 29 20 29 7b  =TH_CONTINUE) ){
7960: 0a 20 20 20 20 20 20 20 20 54 68 5f 43 6f 6d 6d  .        Th_Comm
7970: 61 6e 64 4e 6f 74 69 66 79 28 7a 43 6d 64 4e 61  andNotify(zCmdNa
7980: 6d 65 2c 20 30 29 3b 0a 20 20 20 20 20 20 7d 0a  me, 0);.      }.
7990: 20 20 20 20 7d 0a 20 20 20 20 66 6f 73 73 69 6c      }.    fossil
79a0: 5f 65 78 69 74 28 30 29 3b 0a 23 65 6e 64 69 66  _exit(0);.#endif
79b0: 0a 20 20 7d 65 6c 73 65 20 69 66 28 20 72 63 3d  .  }else if( rc=
79c0: 3d 32 20 29 7b 0a 20 20 20 20 42 6c 6f 62 20 63  =2 ){.    Blob c
79d0: 6f 75 6c 64 62 65 3b 0a 20 20 20 20 62 6c 6f 62  ouldbe;.    blob
79e0: 5f 69 6e 69 74 28 26 63 6f 75 6c 64 62 65 2c 30  _init(&couldbe,0
79f0: 2c 30 29 3b 0a 20 20 20 20 64 69 73 70 61 74 63  ,0);.    dispatc
7a00: 68 5f 6d 61 74 63 68 69 6e 67 5f 6e 61 6d 65 73  h_matching_names
7a10: 28 7a 43 6d 64 4e 61 6d 65 2c 20 26 63 6f 75 6c  (zCmdName, &coul
7a20: 64 62 65 29 3b 0a 20 20 20 20 66 6f 73 73 69 6c  dbe);.    fossil
7a30: 5f 70 72 69 6e 74 28 22 25 73 3a 20 61 6d 62 69  _print("%s: ambi
7a40: 67 75 6f 75 73 20 63 6f 6d 6d 61 6e 64 20 70 72  guous command pr
7a50: 65 66 69 78 3a 20 25 73 5c 6e 22 0a 20 20 20 20  efix: %s\n".    
7a60: 20 20 20 20 20 20 20 20 20 20 20 20 20 22 25 73               "%s
7a70: 3a 20 63 6f 75 6c 64 20 62 65 20 61 6e 79 20 6f  : could be any o
7a80: 66 3a 25 73 5c 6e 22 0a 20 20 20 20 20 20 20 20  f:%s\n".        
7a90: 20 20 20 20 20 20 20 20 20 22 25 73 3a 20 75 73           "%s: us
7aa0: 65 20 5c 22 68 65 6c 70 5c 22 20 66 6f 72 20 6d  e \"help\" for m
7ab0: 6f 72 65 20 69 6e 66 6f 72 6d 61 74 69 6f 6e 5c  ore information\
7ac0: 6e 22 2c 0a 20 20 20 20 20 20 20 20 20 20 20 20  n",.            
7ad0: 20 20 20 20 20 67 2e 61 72 67 76 5b 30 5d 2c 20       g.argv[0], 
7ae0: 7a 43 6d 64 4e 61 6d 65 2c 20 67 2e 61 72 67 76  zCmdName, g.argv
7af0: 5b 30 5d 2c 20 62 6c 6f 62 5f 73 74 72 28 26 63  [0], blob_str(&c
7b00: 6f 75 6c 64 62 65 29 2c 20 67 2e 61 72 67 76 5b  ouldbe), g.argv[
7b10: 30 5d 29 3b 0a 20 20 20 20 66 6f 73 73 69 6c 5f  0]);.    fossil_
7b20: 65 78 69 74 28 31 29 3b 0a 20 20 7d 0a 20 20 61  exit(1);.  }.  a
7b30: 74 65 78 69 74 28 20 66 6f 73 73 69 6c 5f 61 74  texit( fossil_at
7b40: 65 78 69 74 20 29 3b 0a 23 69 66 64 65 66 20 46  exit );.#ifdef F
7b50: 4f 53 53 49 4c 5f 45 4e 41 42 4c 45 5f 54 48 31  OSSIL_ENABLE_TH1
7b60: 5f 48 4f 4f 4b 53 0a 20 20 2f 2a 0a 20 20 2a 2a  _HOOKS.  /*.  **
7b70: 20 54 68 65 20 54 48 31 20 72 65 74 75 72 6e 20   The TH1 return 
7b80: 63 6f 64 65 73 20 66 72 6f 6d 20 74 68 65 20 68  codes from the h
7b90: 6f 6f 6b 20 77 69 6c 6c 20 62 65 20 68 61 6e 64  ook will be hand
7ba0: 6c 65 64 20 61 73 20 66 6f 6c 6c 6f 77 73 3a 0a  led as follows:.
7bb0: 20 20 2a 2a 0a 20 20 2a 2a 20 54 48 5f 4f 4b 3a    **.  ** TH_OK:
7bc0: 20 54 68 65 20 78 46 75 6e 63 28 29 20 61 6e 64   The xFunc() and
7bd0: 20 74 68 65 20 54 48 31 20 6e 6f 74 69 66 69 63   the TH1 notific
7be0: 61 74 69 6f 6e 20 77 69 6c 6c 20 62 6f 74 68 20  ation will both 
7bf0: 62 65 20 65 78 65 63 75 74 65 64 2e 0a 20 20 2a  be executed..  *
7c00: 2a 0a 20 20 2a 2a 20 54 48 5f 45 52 52 4f 52 3a  *.  ** TH_ERROR:
7c10: 20 54 68 65 20 78 46 75 6e 63 28 29 20 77 69 6c   The xFunc() wil
7c20: 6c 20 62 65 20 73 6b 69 70 70 65 64 2c 20 74 68  l be skipped, th
7c30: 65 20 54 48 31 20 6e 6f 74 69 66 69 63 61 74 69  e TH1 notificati
7c40: 6f 6e 20 77 69 6c 6c 20 62 65 0a 20 20 2a 2a 20  on will be.  ** 
7c50: 20 20 20 20 20 20 20 20 20 20 73 6b 69 70 70 65            skippe
7c60: 64 2e 20 20 49 66 20 74 68 65 20 78 46 75 6e 63  d.  If the xFunc
7c70: 28 29 20 69 73 20 62 65 69 6e 67 20 68 6f 6f 6b  () is being hook
7c80: 65 64 2c 20 74 68 65 20 65 72 72 6f 72 20 6d 65  ed, the error me
7c90: 73 73 61 67 65 0a 20 20 2a 2a 20 20 20 20 20 20  ssage.  **      
7ca0: 20 20 20 20 20 77 69 6c 6c 20 62 65 20 65 6d 69       will be emi
7cb0: 74 74 65 64 2e 0a 20 20 2a 2a 0a 20 20 2a 2a 20  tted..  **.  ** 
7cc0: 54 48 5f 42 52 45 41 4b 3a 20 54 68 65 20 78 46  TH_BREAK: The xF
7cd0: 75 6e 63 28 29 20 61 6e 64 20 74 68 65 20 54 48  unc() and the TH
7ce0: 31 20 6e 6f 74 69 66 69 63 61 74 69 6f 6e 20 77  1 notification w
7cf0: 69 6c 6c 20 62 6f 74 68 20 62 65 20 73 6b 69 70  ill both be skip
7d00: 70 65 64 2e 0a 20 20 2a 2a 0a 20 20 2a 2a 20 54  ped..  **.  ** T
7d10: 48 5f 52 45 54 55 52 4e 3a 20 54 68 65 20 78 46  H_RETURN: The xF
7d20: 75 6e 63 28 29 20 77 69 6c 6c 20 62 65 20 65 78  unc() will be ex
7d30: 65 63 75 74 65 64 2c 20 74 68 65 20 54 48 31 20  ecuted, the TH1 
7d40: 6e 6f 74 69 66 69 63 61 74 69 6f 6e 20 77 69 6c  notification wil
7d50: 6c 20 62 65 0a 20 20 2a 2a 20 20 20 20 20 20 20  l be.  **       
7d60: 20 20 20 20 20 73 6b 69 70 70 65 64 2e 0a 20 20       skipped..  
7d70: 2a 2a 0a 20 20 2a 2a 20 54 48 5f 43 4f 4e 54 49  **.  ** TH_CONTI
7d80: 4e 55 45 3a 20 54 68 65 20 78 46 75 6e 63 28 29  NUE: The xFunc()
7d90: 20 77 69 6c 6c 20 62 65 20 73 6b 69 70 70 65 64   will be skipped
7da0: 2c 20 74 68 65 20 54 48 31 20 6e 6f 74 69 66 69  , the TH1 notifi
7db0: 63 61 74 69 6f 6e 20 77 69 6c 6c 20 62 65 0a 20  cation will be. 
7dc0: 20 2a 2a 20 20 20 20 20 20 20 20 20 20 20 20 20   **             
7dd0: 20 65 78 65 63 75 74 65 64 2e 0a 20 20 2a 2f 0a   executed..  */.
7de0: 20 20 69 66 28 20 21 67 2e 69 73 48 54 54 50 20    if( !g.isHTTP 
7df0: 26 26 20 21 67 2e 66 4e 6f 54 68 48 6f 6f 6b 20  && !g.fNoThHook 
7e00: 29 7b 0a 20 20 20 20 72 63 20 3d 20 54 68 5f 43  ){.    rc = Th_C
7e10: 6f 6d 6d 61 6e 64 48 6f 6f 6b 28 70 43 6d 64 2d  ommandHook(pCmd-
7e20: 3e 7a 4e 61 6d 65 2c 20 70 43 6d 64 2d 3e 65 43  >zName, pCmd->eC
7e30: 6d 64 46 6c 61 67 73 29 3b 0a 20 20 7d 65 6c 73  mdFlags);.  }els
7e40: 65 7b 0a 20 20 20 20 72 63 20 3d 20 54 48 5f 4f  e{.    rc = TH_O
7e50: 4b 3b 0a 20 20 7d 0a 20 20 69 66 28 20 72 63 3d  K;.  }.  if( rc=
7e60: 3d 54 48 5f 4f 4b 20 7c 7c 20 72 63 3d 3d 54 48  =TH_OK || rc==TH
7e70: 5f 52 45 54 55 52 4e 20 7c 7c 20 72 63 3d 3d 54  _RETURN || rc==T
7e80: 48 5f 43 4f 4e 54 49 4e 55 45 20 29 7b 0a 20 20  H_CONTINUE ){.  
7e90: 20 20 69 66 28 20 72 63 3d 3d 54 48 5f 4f 4b 20    if( rc==TH_OK 
7ea0: 7c 7c 20 72 63 3d 3d 54 48 5f 52 45 54 55 52 4e  || rc==TH_RETURN
7eb0: 20 29 7b 0a 23 65 6e 64 69 66 0a 20 20 20 20 20   ){.#endif.     
7ec0: 20 70 43 6d 64 2d 3e 78 46 75 6e 63 28 29 3b 0a   pCmd->xFunc();.
7ed0: 23 69 66 64 65 66 20 46 4f 53 53 49 4c 5f 45 4e  #ifdef FOSSIL_EN
7ee0: 41 42 4c 45 5f 54 48 31 5f 48 4f 4f 4b 53 0a 20  ABLE_TH1_HOOKS. 
7ef0: 20 20 20 7d 0a 20 20 20 20 69 66 28 20 21 67 2e     }.    if( !g.
7f00: 69 73 48 54 54 50 20 26 26 20 21 67 2e 66 4e 6f  isHTTP && !g.fNo
7f10: 54 68 48 6f 6f 6b 20 26 26 20 28 72 63 3d 3d 54  ThHook && (rc==T
7f20: 48 5f 4f 4b 20 7c 7c 20 72 63 3d 3d 54 48 5f 43  H_OK || rc==TH_C
7f30: 4f 4e 54 49 4e 55 45 29 20 29 7b 0a 20 20 20 20  ONTINUE) ){.    
7f40: 20 20 54 68 5f 43 6f 6d 6d 61 6e 64 4e 6f 74 69    Th_CommandNoti
7f50: 66 79 28 70 43 6d 64 2d 3e 7a 4e 61 6d 65 2c 20  fy(pCmd->zName, 
7f60: 70 43 6d 64 2d 3e 65 43 6d 64 46 6c 61 67 73 29  pCmd->eCmdFlags)
7f70: 3b 0a 20 20 20 20 7d 0a 20 20 7d 0a 23 65 6e 64  ;.    }.  }.#end
7f80: 69 66 0a 20 20 66 6f 73 73 69 6c 5f 65 78 69 74  if.  fossil_exit
7f90: 28 30 29 3b 0a 20 20 2f 2a 4e 4f 54 5f 52 45 41  (0);.  /*NOT_REA
7fa0: 43 48 45 44 2a 2f 0a 20 20 72 65 74 75 72 6e 20  CHED*/.  return 
7fb0: 30 3b 0a 7d 0a 0a 2f 2a 0a 2a 2a 20 50 72 69 6e  0;.}../*.** Prin
7fc0: 74 20 61 20 75 73 61 67 65 20 63 6f 6d 6d 65 6e  t a usage commen
7fd0: 74 20 61 6e 64 20 71 75 69 74 0a 2a 2f 0a 76 6f  t and quit.*/.vo
7fe0: 69 64 20 75 73 61 67 65 28 63 6f 6e 73 74 20 63  id usage(const c
7ff0: 68 61 72 20 2a 7a 46 6f 72 6d 61 74 29 7b 0a 20  har *zFormat){. 
8000: 20 66 6f 73 73 69 6c 5f 66 61 74 61 6c 28 22 55   fossil_fatal("U
8010: 73 61 67 65 3a 20 25 73 20 25 73 20 25 73 22 2c  sage: %s %s %s",
8020: 20 67 2e 61 72 67 76 5b 30 5d 2c 20 67 2e 61 72   g.argv[0], g.ar
8030: 67 76 5b 31 5d 2c 20 7a 46 6f 72 6d 61 74 29 3b  gv[1], zFormat);
8040: 0a 7d 0a 0a 2f 2a 0a 2a 2a 20 52 65 6d 6f 76 65  .}../*.** Remove
8050: 20 6e 20 65 6c 65 6d 65 6e 74 73 20 66 72 6f 6d   n elements from
8060: 20 67 2e 61 72 67 76 20 62 65 67 69 6e 6e 69 6e   g.argv beginnin
8070: 67 20 77 69 74 68 20 74 68 65 20 69 2d 74 68 20  g with the i-th 
8080: 65 6c 65 6d 65 6e 74 2e 0a 2a 2f 0a 73 74 61 74  element..*/.stat
8090: 69 63 20 76 6f 69 64 20 72 65 6d 6f 76 65 5f 66  ic void remove_f
80a0: 72 6f 6d 5f 61 72 67 76 28 69 6e 74 20 69 2c 20  rom_argv(int i, 
80b0: 69 6e 74 20 6e 29 7b 0a 20 20 69 6e 74 20 6a 3b  int n){.  int j;
80c0: 0a 20 20 66 6f 72 28 6a 3d 69 2b 6e 3b 20 6a 3c  .  for(j=i+n; j<
80d0: 67 2e 61 72 67 63 3b 20 69 2b 2b 2c 20 6a 2b 2b  g.argc; i++, j++
80e0: 29 7b 0a 20 20 20 20 67 2e 61 72 67 76 5b 69 5d  ){.    g.argv[i]
80f0: 20 3d 20 67 2e 61 72 67 76 5b 6a 5d 3b 0a 20 20   = g.argv[j];.  
8100: 7d 0a 20 20 67 2e 61 72 67 63 20 3d 20 69 3b 0a  }.  g.argc = i;.
8110: 7d 0a 0a 0a 2f 2a 0a 2a 2a 20 4c 6f 6f 6b 20 66  }.../*.** Look f
8120: 6f 72 20 61 20 63 6f 6d 6d 61 6e 64 2d 6c 69 6e  or a command-lin
8130: 65 20 6f 70 74 69 6f 6e 2e 20 20 49 66 20 70 72  e option.  If pr
8140: 65 73 65 6e 74 2c 20 72 65 74 75 72 6e 20 61 20  esent, return a 
8150: 70 6f 69 6e 74 65 72 2e 0a 2a 2a 20 52 65 74 75  pointer..** Retu
8160: 72 6e 20 4e 55 4c 4c 20 69 66 20 6d 69 73 73 69  rn NULL if missi
8170: 6e 67 2e 0a 2a 2a 0a 2a 2a 20 68 61 73 41 72 67  ng..**.** hasArg
8180: 3d 3d 30 20 6d 65 61 6e 73 20 74 68 65 20 6f 70  ==0 means the op
8190: 74 69 6f 6e 20 69 73 20 61 20 66 6c 61 67 2e 20  tion is a flag. 
81a0: 20 49 74 20 69 73 20 65 69 74 68 65 72 20 70 72   It is either pr
81b0: 65 73 65 6e 74 20 6f 72 20 6e 6f 74 2e 0a 2a 2a  esent or not..**
81c0: 20 68 61 73 41 72 67 3d 3d 31 20 6d 65 61 6e 73   hasArg==1 means
81d0: 20 74 68 65 20 6f 70 74 69 6f 6e 20 68 61 73 20   the option has 
81e0: 61 6e 20 61 72 67 75 6d 65 6e 74 2e 20 20 52 65  an argument.  Re
81f0: 74 75 72 6e 20 61 20 70 6f 69 6e 74 65 72 20 74  turn a pointer t
8200: 6f 20 74 68 65 0a 2a 2a 20 61 72 67 75 6d 65 6e  o the.** argumen
8210: 74 2e 0a 2a 2f 0a 63 6f 6e 73 74 20 63 68 61 72  t..*/.const char
8220: 20 2a 66 69 6e 64 5f 6f 70 74 69 6f 6e 28 63 6f   *find_option(co
8230: 6e 73 74 20 63 68 61 72 20 2a 7a 4c 6f 6e 67 2c  nst char *zLong,
8240: 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a 53 68   const char *zSh
8250: 6f 72 74 2c 20 69 6e 74 20 68 61 73 41 72 67 29  ort, int hasArg)
8260: 7b 0a 20 20 69 6e 74 20 69 3b 0a 20 20 69 6e 74  {.  int i;.  int
8270: 20 6e 4c 6f 6e 67 3b 0a 20 20 63 6f 6e 73 74 20   nLong;.  const 
8280: 63 68 61 72 20 2a 7a 52 65 74 75 72 6e 20 3d 20  char *zReturn = 
8290: 30 3b 0a 20 20 61 73 73 65 72 74 28 20 68 61 73  0;.  assert( has
82a0: 41 72 67 3d 3d 30 20 7c 7c 20 68 61 73 41 72 67  Arg==0 || hasArg
82b0: 3d 3d 31 20 29 3b 0a 20 20 6e 4c 6f 6e 67 20 3d  ==1 );.  nLong =
82c0: 20 73 74 72 6c 65 6e 28 7a 4c 6f 6e 67 29 3b 0a   strlen(zLong);.
82d0: 20 20 66 6f 72 28 69 3d 31 3b 20 69 3c 67 2e 61    for(i=1; i<g.a
82e0: 72 67 63 3b 20 69 2b 2b 29 7b 0a 20 20 20 20 63  rgc; i++){.    c
82f0: 68 61 72 20 2a 7a 3b 0a 20 20 20 20 69 66 28 20  har *z;.    if( 
8300: 69 2b 68 61 73 41 72 67 20 3e 3d 20 67 2e 61 72  i+hasArg >= g.ar
8310: 67 63 20 29 20 62 72 65 61 6b 3b 0a 20 20 20 20  gc ) break;.    
8320: 7a 20 3d 20 67 2e 61 72 67 76 5b 69 5d 3b 0a 20  z = g.argv[i];. 
8330: 20 20 20 69 66 28 20 7a 5b 30 5d 21 3d 27 2d 27     if( z[0]!='-'
8340: 20 29 20 63 6f 6e 74 69 6e 75 65 3b 0a 20 20 20   ) continue;.   
8350: 20 7a 2b 2b 3b 0a 20 20 20 20 69 66 28 20 7a 5b   z++;.    if( z[
8360: 30 5d 3d 3d 27 2d 27 20 29 7b 0a 20 20 20 20 20  0]=='-' ){.     
8370: 20 69 66 28 20 7a 5b 31 5d 3d 3d 30 20 29 7b 0a   if( z[1]==0 ){.
8380: 20 20 20 20 20 20 20 20 72 65 6d 6f 76 65 5f 66          remove_f
8390: 72 6f 6d 5f 61 72 67 76 28 69 2c 20 31 29 3b 0a  rom_argv(i, 1);.
83a0: 20 20 20 20 20 20 20 20 62 72 65 61 6b 3b 0a 20          break;. 
83b0: 20 20 20 20 20 7d 0a 20 20 20 20 20 20 7a 2b 2b       }.      z++
83c0: 3b 0a 20 20 20 20 7d 0a 20 20 20 20 69 66 28 20  ;.    }.    if( 
83d0: 73 74 72 6e 63 6d 70 28 7a 2c 7a 4c 6f 6e 67 2c  strncmp(z,zLong,
83e0: 6e 4c 6f 6e 67 29 3d 3d 30 20 29 7b 0a 20 20 20  nLong)==0 ){.   
83f0: 20 20 20 69 66 28 20 68 61 73 41 72 67 20 26 26     if( hasArg &&
8400: 20 7a 5b 6e 4c 6f 6e 67 5d 3d 3d 27 3d 27 20 29   z[nLong]=='=' )
8410: 7b 0a 20 20 20 20 20 20 20 20 7a 52 65 74 75 72  {.        zRetur
8420: 6e 20 3d 20 26 7a 5b 6e 4c 6f 6e 67 2b 31 5d 3b  n = &z[nLong+1];
8430: 0a 20 20 20 20 20 20 20 20 72 65 6d 6f 76 65 5f  .        remove_
8440: 66 72 6f 6d 5f 61 72 67 76 28 69 2c 20 31 29 3b  from_argv(i, 1);
8450: 0a 20 20 20 20 20 20 20 20 62 72 65 61 6b 3b 0a  .        break;.
8460: 20 20 20 20 20 20 7d 65 6c 73 65 20 69 66 28 20        }else if( 
8470: 7a 5b 6e 4c 6f 6e 67 5d 3d 3d 30 20 29 7b 0a 20  z[nLong]==0 ){. 
8480: 20 20 20 20 20 20 20 7a 52 65 74 75 72 6e 20 3d         zReturn =
8490: 20 67 2e 61 72 67 76 5b 69 2b 68 61 73 41 72 67   g.argv[i+hasArg
84a0: 5d 3b 0a 20 20 20 20 20 20 20 20 72 65 6d 6f 76  ];.        remov
84b0: 65 5f 66 72 6f 6d 5f 61 72 67 76 28 69 2c 20 31  e_from_argv(i, 1
84c0: 2b 68 61 73 41 72 67 29 3b 0a 20 20 20 20 20 20  +hasArg);.      
84d0: 20 20 62 72 65 61 6b 3b 0a 20 20 20 20 20 20 7d    break;.      }
84e0: 0a 20 20 20 20 7d 65 6c 73 65 20 69 66 28 20 66  .    }else if( f
84f0: 6f 73 73 69 6c 5f 73 74 72 63 6d 70 28 7a 2c 7a  ossil_strcmp(z,z
8500: 53 68 6f 72 74 29 3d 3d 30 20 29 7b 0a 20 20 20  Short)==0 ){.   
8510: 20 20 20 7a 52 65 74 75 72 6e 20 3d 20 67 2e 61     zReturn = g.a
8520: 72 67 76 5b 69 2b 68 61 73 41 72 67 5d 3b 0a 20  rgv[i+hasArg];. 
8530: 20 20 20 20 20 72 65 6d 6f 76 65 5f 66 72 6f 6d       remove_from
8540: 5f 61 72 67 76 28 69 2c 20 31 2b 68 61 73 41 72  _argv(i, 1+hasAr
8550: 67 29 3b 0a 20 20 20 20 20 20 62 72 65 61 6b 3b  g);.      break;
8560: 0a 20 20 20 20 7d 0a 20 20 7d 0a 20 20 72 65 74  .    }.  }.  ret
8570: 75 72 6e 20 7a 52 65 74 75 72 6e 3b 0a 7d 0a 0a  urn zReturn;.}..
8580: 2f 2a 20 52 65 74 75 72 6e 20 74 72 75 65 20 69  /* Return true i
8590: 66 20 7a 4f 70 74 69 6f 6e 20 65 78 69 73 74 73  f zOption exists
85a0: 20 69 6e 20 74 68 65 20 63 6f 6d 6d 61 6e 64 2d   in the command-
85b0: 6c 69 6e 65 20 61 72 67 75 6d 65 6e 74 73 2c 0a  line arguments,.
85c0: 2a 2a 20 62 75 74 20 64 6f 20 6e 6f 74 20 72 65  ** but do not re
85d0: 6d 6f 76 65 20 69 74 20 66 72 6f 6d 20 74 68 65  move it from the
85e0: 20 6c 69 73 74 20 6f 72 20 6f 74 68 65 72 77 69   list or otherwi
85f0: 73 65 20 70 72 6f 63 65 73 73 20 69 74 2e 0a 2a  se process it..*
8600: 2f 0a 69 6e 74 20 68 61 73 5f 6f 70 74 69 6f 6e  /.int has_option
8610: 28 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a 4f 70  (const char *zOp
8620: 74 69 6f 6e 29 7b 0a 20 20 69 6e 74 20 69 3b 0a  tion){.  int i;.
8630: 20 20 69 6e 74 20 6e 20 3d 20 28 69 6e 74 29 73    int n = (int)s
8640: 74 72 6c 65 6e 28 7a 4f 70 74 69 6f 6e 29 3b 0a  trlen(zOption);.
8650: 20 20 66 6f 72 28 69 3d 31 3b 20 69 3c 67 2e 61    for(i=1; i<g.a
8660: 72 67 63 3b 20 69 2b 2b 29 7b 0a 20 20 20 20 63  rgc; i++){.    c
8670: 68 61 72 20 2a 7a 20 3d 20 67 2e 61 72 67 76 5b  har *z = g.argv[
8680: 69 5d 3b 0a 20 20 20 20 69 66 28 20 7a 5b 30 5d  i];.    if( z[0]
8690: 21 3d 27 2d 27 20 29 20 63 6f 6e 74 69 6e 75 65  !='-' ) continue
86a0: 3b 0a 20 20 20 20 7a 2b 2b 3b 0a 20 20 20 20 69  ;.    z++;.    i
86b0: 66 28 20 7a 5b 30 5d 3d 3d 27 2d 27 20 29 20 7a  f( z[0]=='-' ) z
86c0: 2b 2b 3b 0a 20 20 20 20 69 66 28 20 73 74 72 6e  ++;.    if( strn
86d0: 63 6d 70 28 7a 2c 7a 4f 70 74 69 6f 6e 2c 6e 29  cmp(z,zOption,n)
86e0: 3d 3d 30 20 26 26 20 28 7a 5b 6e 5d 3d 3d 30 20  ==0 && (z[n]==0 
86f0: 7c 7c 20 7a 5b 6e 5d 3d 3d 27 3d 27 29 20 29 20  || z[n]=='=') ) 
8700: 72 65 74 75 72 6e 20 31 3b 0a 20 20 7d 0a 20 20  return 1;.  }.  
8710: 72 65 74 75 72 6e 20 30 3b 0a 7d 0a 0a 2f 2a 0a  return 0;.}../*.
8720: 2a 2a 20 4c 6f 6f 6b 20 66 6f 72 20 6d 75 6c 74  ** Look for mult
8730: 69 70 6c 65 20 6f 63 63 75 72 72 65 6e 63 65 73  iple occurrences
8740: 20 6f 66 20 61 20 63 6f 6d 6d 61 6e 64 2d 6c 69   of a command-li
8750: 6e 65 20 6f 70 74 69 6f 6e 20 77 69 74 68 20 74  ne option with t
8760: 68 65 0a 2a 2a 20 63 6f 72 72 65 73 70 6f 6e 64  he.** correspond
8770: 69 6e 67 20 61 72 67 75 6d 65 6e 74 2e 0a 2a 2a  ing argument..**
8780: 0a 2a 2a 20 52 65 74 75 72 6e 20 61 20 6d 61 6c  .** Return a mal
8790: 6c 6f 63 20 61 6c 6c 6f 63 61 74 65 64 20 61 72  loc allocated ar
87a0: 72 61 79 20 6f 66 20 70 6f 69 6e 74 65 72 73 20  ray of pointers 
87b0: 74 6f 20 74 68 65 20 61 72 67 75 6d 65 6e 74 73  to the arguments
87c0: 2e 0a 2a 2a 0a 2a 2a 20 70 6e 55 73 65 64 41 72  ..**.** pnUsedAr
87d0: 67 73 20 69 73 20 75 73 65 64 20 74 6f 20 73 74  gs is used to st
87e0: 6f 72 65 20 74 68 65 20 6e 75 6d 62 65 72 20 6f  ore the number o
87f0: 66 20 6d 61 74 63 68 65 64 20 61 72 67 75 6d 65  f matched argume
8800: 6e 74 73 2e 0a 2a 2a 0a 2a 2a 20 43 61 6c 6c 65  nts..**.** Calle
8810: 72 20 69 73 20 72 65 73 70 6f 6e 73 69 62 6c 65  r is responsible
8820: 20 74 6f 20 66 72 65 65 20 61 6c 6c 6f 63 61 74   to free allocat
8830: 65 64 20 6d 65 6d 6f 72 79 2e 0a 2a 2f 0a 63 6f  ed memory..*/.co
8840: 6e 73 74 20 63 68 61 72 20 2a 2a 66 69 6e 64 5f  nst char **find_
8850: 72 65 70 65 61 74 61 62 6c 65 5f 6f 70 74 69 6f  repeatable_optio
8860: 6e 28 0a 20 20 63 6f 6e 73 74 20 63 68 61 72 20  n(.  const char 
8870: 2a 7a 4c 6f 6e 67 2c 0a 20 20 63 6f 6e 73 74 20  *zLong,.  const 
8880: 63 68 61 72 20 2a 7a 53 68 6f 72 74 2c 0a 20 20  char *zShort,.  
8890: 69 6e 74 20 2a 70 6e 55 73 65 64 41 72 67 73 0a  int *pnUsedArgs.
88a0: 29 7b 0a 20 20 63 6f 6e 73 74 20 63 68 61 72 20  ){.  const char 
88b0: 2a 7a 4f 70 74 69 6f 6e 3b 0a 20 20 63 6f 6e 73  *zOption;.  cons
88c0: 74 20 63 68 61 72 20 2a 2a 70 7a 41 72 67 73 20  t char **pzArgs 
88d0: 3d 20 30 3b 0a 20 20 69 6e 74 20 6e 41 6c 6c 6f  = 0;.  int nAllo
88e0: 63 41 72 67 73 20 3d 20 30 3b 0a 20 20 69 6e 74  cArgs = 0;.  int
88f0: 20 6e 55 73 65 64 41 72 67 73 20 3d 20 30 3b 0a   nUsedArgs = 0;.
8900: 0a 20 20 77 68 69 6c 65 28 20 28 7a 4f 70 74 69  .  while( (zOpti
8910: 6f 6e 20 3d 20 66 69 6e 64 5f 6f 70 74 69 6f 6e  on = find_option
8920: 28 7a 4c 6f 6e 67 2c 20 7a 53 68 6f 72 74 2c 20  (zLong, zShort, 
8930: 31 29 29 21 3d 30 20 29 7b 0a 20 20 20 20 69 66  1))!=0 ){.    if
8940: 28 20 70 7a 41 72 67 73 3d 3d 30 20 26 26 20 6e  ( pzArgs==0 && n
8950: 41 6c 6c 6f 63 41 72 67 73 3d 3d 30 20 29 7b 0a  AllocArgs==0 ){.
8960: 20 20 20 20 20 20 6e 41 6c 6c 6f 63 41 72 67 73        nAllocArgs
8970: 20 3d 20 31 3b 0a 20 20 20 20 20 20 70 7a 41 72   = 1;.      pzAr
8980: 67 73 20 3d 20 66 6f 73 73 69 6c 5f 6d 61 6c 6c  gs = fossil_mall
8990: 6f 63 28 20 6e 41 6c 6c 6f 63 41 72 67 73 2a 73  oc( nAllocArgs*s
89a0: 69 7a 65 6f 66 28 70 7a 41 72 67 73 5b 30 5d 29  izeof(pzArgs[0])
89b0: 20 29 3b 0a 20 20 20 20 7d 65 6c 73 65 20 69 66   );.    }else if
89c0: 28 20 6e 41 6c 6c 6f 63 41 72 67 73 3c 3d 6e 55  ( nAllocArgs<=nU
89d0: 73 65 64 41 72 67 73 20 29 7b 0a 20 20 20 20 20  sedArgs ){.     
89e0: 20 6e 41 6c 6c 6f 63 41 72 67 73 20 3d 20 6e 41   nAllocArgs = nA
89f0: 6c 6c 6f 63 41 72 67 73 2a 32 3b 0a 20 20 20 20  llocArgs*2;.    
8a00: 20 20 70 7a 41 72 67 73 20 3d 20 66 6f 73 73 69    pzArgs = fossi
8a10: 6c 5f 72 65 61 6c 6c 6f 63 28 20 28 76 6f 69 64  l_realloc( (void
8a20: 20 2a 29 70 7a 41 72 67 73 2c 20 6e 41 6c 6c 6f   *)pzArgs, nAllo
8a30: 63 41 72 67 73 2a 73 69 7a 65 6f 66 28 70 7a 41  cArgs*sizeof(pzA
8a40: 72 67 73 5b 30 5d 29 20 29 3b 0a 20 20 20 20 7d  rgs[0]) );.    }
8a50: 0a 20 20 20 20 70 7a 41 72 67 73 5b 6e 55 73 65  .    pzArgs[nUse
8a60: 64 41 72 67 73 2b 2b 5d 20 3d 20 7a 4f 70 74 69  dArgs++] = zOpti
8a70: 6f 6e 3b 0a 20 20 7d 0a 20 20 2a 70 6e 55 73 65  on;.  }.  *pnUse
8a80: 64 41 72 67 73 20 3d 20 6e 55 73 65 64 41 72 67  dArgs = nUsedArg
8a90: 73 3b 0a 20 20 72 65 74 75 72 6e 20 70 7a 41 72  s;.  return pzAr
8aa0: 67 73 3b 0a 7d 0a 0a 2f 2a 0a 2a 2a 20 4c 6f 6f  gs;.}../*.** Loo
8ab0: 6b 20 66 6f 72 20 61 20 72 65 70 6f 73 69 74 6f  k for a reposito
8ac0: 72 79 20 63 6f 6d 6d 61 6e 64 2d 6c 69 6e 65 20  ry command-line 
8ad0: 6f 70 74 69 6f 6e 2e 20 20 49 66 20 70 72 65 73  option.  If pres
8ae0: 65 6e 74 2c 20 5b 72 65 2d 5d 63 61 63 68 65 20  ent, [re-]cache 
8af0: 69 74 20 69 6e 0a 2a 2a 20 74 68 65 20 67 6c 6f  it in.** the glo
8b00: 62 61 6c 20 73 74 61 74 65 20 61 6e 64 20 72 65  bal state and re
8b10: 74 75 72 6e 20 74 68 65 20 6e 65 77 20 70 6f 69  turn the new poi
8b20: 6e 74 65 72 2c 20 66 72 65 65 69 6e 67 20 61 6e  nter, freeing an
8b30: 79 20 70 72 65 76 69 6f 75 73 20 76 61 6c 75 65  y previous value
8b40: 2e 0a 2a 2a 20 49 66 20 61 62 73 65 6e 74 20 61  ..** If absent a
8b50: 6e 64 20 74 68 65 72 65 20 69 73 20 6e 6f 20 63  nd there is no c
8b60: 61 63 68 65 64 20 76 61 6c 75 65 2c 20 72 65 74  ached value, ret
8b70: 75 72 6e 20 4e 55 4c 4c 2e 0a 2a 2f 0a 63 6f 6e  urn NULL..*/.con
8b80: 73 74 20 63 68 61 72 20 2a 66 69 6e 64 5f 72 65  st char *find_re
8b90: 70 6f 73 69 74 6f 72 79 5f 6f 70 74 69 6f 6e 28  pository_option(
8ba0: 29 7b 0a 20 20 63 6f 6e 73 74 20 63 68 61 72 20  ){.  const char 
8bb0: 2a 7a 52 65 70 6f 73 69 74 6f 72 79 20 3d 20 66  *zRepository = f
8bc0: 69 6e 64 5f 6f 70 74 69 6f 6e 28 22 72 65 70 6f  ind_option("repo
8bd0: 73 69 74 6f 72 79 22 2c 20 22 52 22 2c 20 31 29  sitory", "R", 1)
8be0: 3b 0a 20 20 69 66 28 20 7a 52 65 70 6f 73 69 74  ;.  if( zReposit
8bf0: 6f 72 79 20 29 7b 0a 20 20 20 20 69 66 28 20 67  ory ){.    if( g
8c00: 2e 7a 52 65 70 6f 73 69 74 6f 72 79 4f 70 74 69  .zRepositoryOpti
8c10: 6f 6e 20 29 20 66 6f 73 73 69 6c 5f 66 72 65 65  on ) fossil_free
8c20: 28 67 2e 7a 52 65 70 6f 73 69 74 6f 72 79 4f 70  (g.zRepositoryOp
8c30: 74 69 6f 6e 29 3b 0a 20 20 20 20 67 2e 7a 52 65  tion);.    g.zRe
8c40: 70 6f 73 69 74 6f 72 79 4f 70 74 69 6f 6e 20 3d  positoryOption =
8c50: 20 6d 70 72 69 6e 74 66 28 22 25 73 22 2c 20 7a   mprintf("%s", z
8c60: 52 65 70 6f 73 69 74 6f 72 79 29 3b 0a 20 20 7d  Repository);.  }
8c70: 0a 20 20 72 65 74 75 72 6e 20 67 2e 7a 52 65 70  .  return g.zRep
8c80: 6f 73 69 74 6f 72 79 4f 70 74 69 6f 6e 3b 0a 7d  ositoryOption;.}
8c90: 0a 0a 2f 2a 0a 2a 2a 20 56 65 72 69 66 79 20 74  ../*.** Verify t
8ca0: 68 61 74 20 74 68 65 72 65 20 61 72 65 20 6e 6f  hat there are no
8cb0: 20 75 6e 70 72 6f 63 65 73 73 65 64 20 63 6f 6d   unprocessed com
8cc0: 6d 61 6e 64 2d 6c 69 6e 65 20 6f 70 74 69 6f 6e  mand-line option
8cd0: 73 2e 20 20 49 66 0a 2a 2a 20 41 6e 79 20 72 65  s.  If.** Any re
8ce0: 6d 61 69 6e 69 6e 67 20 63 6f 6d 6d 61 6e 64 2d  maining command-
8cf0: 6c 69 6e 65 20 61 72 67 75 6d 65 6e 74 20 62 65  line argument be
8d00: 67 69 6e 73 20 77 69 74 68 20 22 2d 22 20 70 72  gins with "-" pr
8d10: 69 6e 74 0a 2a 2a 20 61 6e 20 65 72 72 6f 72 20  int.** an error 
8d20: 6d 65 73 73 61 67 65 20 61 6e 64 20 71 75 69 74  message and quit
8d30: 2e 0a 2a 2f 0a 76 6f 69 64 20 76 65 72 69 66 79  ..*/.void verify
8d40: 5f 61 6c 6c 5f 6f 70 74 69 6f 6e 73 28 76 6f 69  _all_options(voi
8d50: 64 29 7b 0a 20 20 69 6e 74 20 69 3b 0a 20 20 66  d){.  int i;.  f
8d60: 6f 72 28 69 3d 31 3b 20 69 3c 67 2e 61 72 67 63  or(i=1; i<g.argc
8d70: 3b 20 69 2b 2b 29 7b 0a 20 20 20 20 69 66 28 20  ; i++){.    if( 
8d80: 67 2e 61 72 67 76 5b 69 5d 5b 30 5d 3d 3d 27 2d  g.argv[i][0]=='-
8d90: 27 20 26 26 20 67 2e 61 72 67 76 5b 69 5d 5b 31  ' && g.argv[i][1
8da0: 5d 21 3d 30 20 29 7b 0a 20 20 20 20 20 20 66 6f  ]!=0 ){.      fo
8db0: 73 73 69 6c 5f 66 61 74 61 6c 28 0a 20 20 20 20  ssil_fatal(.    
8dc0: 20 20 20 20 22 75 6e 72 65 63 6f 67 6e 69 7a 65      "unrecognize
8dd0: 64 20 63 6f 6d 6d 61 6e 64 2d 6c 69 6e 65 20 6f  d command-line o
8de0: 70 74 69 6f 6e 2c 20 6f 72 20 6d 69 73 73 69 6e  ption, or missin
8df0: 67 20 61 72 67 75 6d 65 6e 74 3a 20 25 73 22 2c  g argument: %s",
8e00: 0a 20 20 20 20 20 20 20 20 67 2e 61 72 67 76 5b  .        g.argv[
8e10: 69 5d 29 3b 0a 20 20 20 20 7d 0a 20 20 7d 0a 7d  i]);.    }.  }.}
8e20: 0a 0a 0a 2f 2a 0a 2a 2a 20 54 68 69 73 20 66 75  .../*.** This fu
8e30: 6e 63 74 69 6f 6e 20 72 65 74 75 72 6e 73 20 61  nction returns a
8e40: 20 68 75 6d 61 6e 20 72 65 61 64 61 62 6c 65 20   human readable 
8e50: 76 65 72 73 69 6f 6e 20 73 74 72 69 6e 67 2e 0a  version string..
8e60: 2a 2f 0a 63 6f 6e 73 74 20 63 68 61 72 20 2a 67  */.const char *g
8e70: 65 74 5f 76 65 72 73 69 6f 6e 28 29 7b 0a 20 20  et_version(){.  
8e80: 73 74 61 74 69 63 20 63 6f 6e 73 74 20 63 68 61  static const cha
8e90: 72 20 76 65 72 73 69 6f 6e 5b 5d 20 3d 20 52 45  r version[] = RE
8ea0: 4c 45 41 53 45 5f 56 45 52 53 49 4f 4e 20 22 20  LEASE_VERSION " 
8eb0: 22 20 4d 41 4e 49 46 45 53 54 5f 56 45 52 53 49  " MANIFEST_VERSI
8ec0: 4f 4e 20 22 20 22 0a 20 20 20 20 20 20 20 20 20  ON " ".         
8ed0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
8ee0: 20 20 20 20 20 20 20 4d 41 4e 49 46 45 53 54 5f         MANIFEST_
8ef0: 44 41 54 45 20 22 20 55 54 43 22 3b 0a 20 20 72  DATE " UTC";.  r
8f00: 65 74 75 72 6e 20 76 65 72 73 69 6f 6e 3b 0a 7d  eturn version;.}
8f10: 0a 0a 2f 2a 0a 2a 2a 20 54 68 69 73 20 66 75 6e  ../*.** This fun
8f20: 63 74 69 6f 6e 20 70 6f 70 75 6c 61 74 65 73 20  ction populates 
8f30: 61 20 62 6c 6f 62 20 77 69 74 68 20 76 65 72 73  a blob with vers
8f40: 69 6f 6e 20 69 6e 66 6f 72 6d 61 74 69 6f 6e 2e  ion information.
8f50: 20 20 49 74 20 69 73 20 75 73 65 64 20 62 79 0a    It is used by.
8f60: 2a 2a 20 74 68 65 20 22 76 65 72 73 69 6f 6e 22  ** the "version"
8f70: 20 63 6f 6d 6d 61 6e 64 20 61 6e 64 20 22 74 65   command and "te
8f80: 73 74 2d 76 65 72 73 69 6f 6e 22 20 77 65 62 20  st-version" web 
8f90: 70 61 67 65 2e 20 20 49 74 20 61 73 73 75 6d 65  page.  It assume
8fa0: 73 20 74 68 65 20 62 6c 6f 62 0a 2a 2a 20 70 61  s the blob.** pa
8fb0: 73 73 65 64 20 74 6f 20 69 74 20 69 73 20 75 6e  ssed to it is un
8fc0: 69 6e 69 74 69 61 6c 69 7a 65 64 3b 20 6f 74 68  initialized; oth
8fd0: 65 72 77 69 73 65 2c 20 69 74 20 77 69 6c 6c 20  erwise, it will 
8fe0: 6c 65 61 6b 20 6d 65 6d 6f 72 79 2e 0a 2a 2f 0a  leak memory..*/.
8ff0: 73 74 61 74 69 63 20 76 6f 69 64 20 67 65 74 5f  static void get_
9000: 76 65 72 73 69 6f 6e 5f 62 6c 6f 62 28 0a 20 20  version_blob(.  
9010: 42 6c 6f 62 20 2a 70 4f 75 74 2c 20 20 20 20 20  Blob *pOut,     
9020: 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 57              /* W
9030: 72 69 74 65 20 74 68 65 20 6d 61 6e 69 66 65 73  rite the manifes
9040: 74 20 68 65 72 65 20 2a 2f 0a 20 20 69 6e 74 20  t here */.  int 
9050: 62 56 65 72 62 6f 73 65 20 20 20 20 20 20 20 20  bVerbose        
9060: 20 20 20 20 20 20 20 20 2f 2a 20 4e 6f 6e 2d 7a          /* Non-z
9070: 65 72 6f 20 66 6f 72 20 66 75 6c 6c 20 69 6e 66  ero for full inf
9080: 6f 72 6d 61 74 69 6f 6e 2e 20 2a 2f 0a 29 7b 0a  ormation. */.){.
9090: 23 69 66 20 64 65 66 69 6e 65 64 28 46 4f 53 53  #if defined(FOSS
90a0: 49 4c 5f 45 4e 41 42 4c 45 5f 54 43 4c 29 0a 20  IL_ENABLE_TCL). 
90b0: 20 69 6e 74 20 72 63 3b 0a 20 20 63 6f 6e 73 74   int rc;.  const
90c0: 20 63 68 61 72 20 2a 7a 52 63 3b 0a 23 65 6e 64   char *zRc;.#end
90d0: 69 66 0a 20 20 53 74 6d 74 20 71 3b 0a 20 20 73  if.  Stmt q;.  s
90e0: 69 7a 65 5f 74 20 70 61 67 65 53 69 7a 65 20 3d  ize_t pageSize =
90f0: 20 30 3b 0a 20 20 62 6c 6f 62 5f 7a 65 72 6f 28   0;.  blob_zero(
9100: 70 4f 75 74 29 3b 0a 20 20 62 6c 6f 62 5f 61 70  pOut);.  blob_ap
9110: 70 65 6e 64 66 28 70 4f 75 74 2c 20 22 54 68 69  pendf(pOut, "Thi
9120: 73 20 69 73 20 66 6f 73 73 69 6c 20 76 65 72 73  s is fossil vers
9130: 69 6f 6e 20 25 73 5c 6e 22 2c 20 67 65 74 5f 76  ion %s\n", get_v
9140: 65 72 73 69 6f 6e 28 29 29 3b 0a 20 20 69 66 28  ersion());.  if(
9150: 20 21 62 56 65 72 62 6f 73 65 20 29 20 72 65 74   !bVerbose ) ret
9160: 75 72 6e 3b 0a 20 20 62 6c 6f 62 5f 61 70 70 65  urn;.  blob_appe
9170: 6e 64 66 28 70 4f 75 74 2c 20 22 43 6f 6d 70 69  ndf(pOut, "Compi
9180: 6c 65 64 20 6f 6e 20 25 73 20 25 73 20 75 73 69  led on %s %s usi
9190: 6e 67 20 25 73 20 28 25 64 2d 62 69 74 29 5c 6e  ng %s (%d-bit)\n
91a0: 22 2c 0a 20 20 20 20 20 20 20 20 20 20 20 20 20  ",.             
91b0: 20 20 5f 5f 44 41 54 45 5f 5f 2c 20 5f 5f 54 49    __DATE__, __TI
91c0: 4d 45 5f 5f 2c 20 43 4f 4d 50 49 4c 45 52 5f 4e  ME__, COMPILER_N
91d0: 41 4d 45 2c 20 73 69 7a 65 6f 66 28 76 6f 69 64  AME, sizeof(void
91e0: 2a 29 2a 38 29 3b 0a 20 20 62 6c 6f 62 5f 61 70  *)*8);.  blob_ap
91f0: 70 65 6e 64 66 28 70 4f 75 74 2c 20 22 53 63 68  pendf(pOut, "Sch
9200: 65 6d 61 20 76 65 72 73 69 6f 6e 20 25 73 5c 6e  ema version %s\n
9210: 22 2c 20 41 55 58 5f 53 43 48 45 4d 41 5f 4d 41  ", AUX_SCHEMA_MA
9220: 58 29 3b 0a 20 20 66 6f 73 73 69 6c 5f 67 65 74  X);.  fossil_get
9230: 5f 70 61 67 65 5f 73 69 7a 65 28 26 70 61 67 65  _page_size(&page
9240: 53 69 7a 65 29 3b 0a 20 20 62 6c 6f 62 5f 61 70  Size);.  blob_ap
9250: 70 65 6e 64 66 28 70 4f 75 74 2c 20 22 44 65 74  pendf(pOut, "Det
9260: 65 63 74 65 64 20 6d 65 6d 6f 72 79 20 70 61 67  ected memory pag
9270: 65 20 73 69 7a 65 20 69 73 20 25 6c 75 20 62 79  e size is %lu by
9280: 74 65 73 5c 6e 22 2c 0a 20 20 20 20 20 20 20 20  tes\n",.        
9290: 20 20 20 20 20 20 20 28 75 6e 73 69 67 6e 65 64         (unsigned
92a0: 20 6c 6f 6e 67 29 70 61 67 65 53 69 7a 65 29 3b   long)pageSize);
92b0: 0a 23 69 66 20 64 65 66 69 6e 65 64 28 46 4f 53  .#if defined(FOS
92c0: 53 49 4c 5f 45 4e 41 42 4c 45 5f 4d 49 4e 49 5a  SIL_ENABLE_MINIZ
92d0: 29 0a 20 20 62 6c 6f 62 5f 61 70 70 65 6e 64 66  ).  blob_appendf
92e0: 28 70 4f 75 74 2c 20 22 6d 69 6e 69 7a 20 25 73  (pOut, "miniz %s
92f0: 2c 20 6c 6f 61 64 65 64 20 25 73 5c 6e 22 2c 20  , loaded %s\n", 
9300: 4d 5a 5f 56 45 52 53 49 4f 4e 2c 20 6d 7a 5f 76  MZ_VERSION, mz_v
9310: 65 72 73 69 6f 6e 28 29 29 3b 0a 23 65 6c 73 65  ersion());.#else
9320: 0a 20 20 62 6c 6f 62 5f 61 70 70 65 6e 64 66 28  .  blob_appendf(
9330: 70 4f 75 74 2c 20 22 7a 6c 69 62 20 25 73 2c 20  pOut, "zlib %s, 
9340: 6c 6f 61 64 65 64 20 25 73 5c 6e 22 2c 20 5a 4c  loaded %s\n", ZL
9350: 49 42 5f 56 45 52 53 49 4f 4e 2c 20 7a 6c 69 62  IB_VERSION, zlib
9360: 56 65 72 73 69 6f 6e 28 29 29 3b 0a 23 65 6e 64  Version());.#end
9370: 69 66 0a 23 69 66 20 46 4f 53 53 49 4c 5f 48 41  if.#if FOSSIL_HA
9380: 52 44 45 4e 45 44 5f 53 48 41 31 0a 20 20 62 6c  RDENED_SHA1.  bl
9390: 6f 62 5f 61 70 70 65 6e 64 66 28 70 4f 75 74 2c  ob_appendf(pOut,
93a0: 20 22 68 61 72 64 65 6e 65 64 2d 53 48 41 31 20   "hardened-SHA1 
93b0: 62 79 20 4d 61 72 63 20 53 74 65 76 65 6e 73 20  by Marc Stevens 
93c0: 61 6e 64 20 44 61 6e 20 53 68 75 6d 6f 77 5c 6e  and Dan Shumow\n
93d0: 22 29 3b 0a 23 65 6e 64 69 66 0a 23 69 66 20 64  ");.#endif.#if d
93e0: 65 66 69 6e 65 64 28 46 4f 53 53 49 4c 5f 45 4e  efined(FOSSIL_EN
93f0: 41 42 4c 45 5f 53 53 4c 29 0a 20 20 62 6c 6f 62  ABLE_SSL).  blob
9400: 5f 61 70 70 65 6e 64 66 28 70 4f 75 74 2c 20 22  _appendf(pOut, "
9410: 53 53 4c 20 28 25 73 29 5c 6e 22 2c 20 53 53 4c  SSL (%s)\n", SSL
9420: 65 61 79 5f 76 65 72 73 69 6f 6e 28 53 53 4c 45  eay_version(SSLE
9430: 41 59 5f 56 45 52 53 49 4f 4e 29 29 3b 0a 23 65  AY_VERSION));.#e
9440: 6e 64 69 66 0a 23 69 66 20 64 65 66 69 6e 65 64  ndif.#if defined
9450: 28 46 4f 53 53 49 4c 5f 48 41 56 45 5f 46 55 53  (FOSSIL_HAVE_FUS
9460: 45 46 53 29 0a 20 20 62 6c 6f 62 5f 61 70 70 65  EFS).  blob_appe
9470: 6e 64 66 28 70 4f 75 74 2c 20 22 6c 69 62 66 75  ndf(pOut, "libfu
9480: 73 65 20 25 73 2c 20 6c 6f 61 64 65 64 20 25 73  se %s, loaded %s
9490: 5c 6e 22 2c 20 66 75 73 65 66 73 5f 69 6e 63 5f  \n", fusefs_inc_
94a0: 76 65 72 73 69 6f 6e 28 29 2c 0a 20 20 20 20 20  version(),.     
94b0: 20 20 20 20 20 20 20 20 20 20 66 75 73 65 66 73            fusefs
94c0: 5f 6c 69 62 5f 76 65 72 73 69 6f 6e 28 29 29 3b  _lib_version());
94d0: 0a 23 65 6e 64 69 66 0a 23 69 66 20 64 65 66 69  .#endif.#if defi
94e0: 6e 65 64 28 46 4f 53 53 49 4c 5f 44 45 42 55 47  ned(FOSSIL_DEBUG
94f0: 29 0a 20 20 62 6c 6f 62 5f 61 70 70 65 6e 64 28  ).  blob_append(
9500: 70 4f 75 74 2c 20 22 46 4f 53 53 49 4c 5f 44 45  pOut, "FOSSIL_DE
9510: 42 55 47 5c 6e 22 2c 20 2d 31 29 3b 0a 23 65 6e  BUG\n", -1);.#en
9520: 64 69 66 0a 23 69 66 20 64 65 66 69 6e 65 64 28  dif.#if defined(
9530: 46 4f 53 53 49 4c 5f 45 4e 41 42 4c 45 5f 44 45  FOSSIL_ENABLE_DE
9540: 4c 54 41 5f 43 4b 53 55 4d 5f 54 45 53 54 29 0a  LTA_CKSUM_TEST).
9550: 20 20 62 6c 6f 62 5f 61 70 70 65 6e 64 28 70 4f    blob_append(pO
9560: 75 74 2c 20 22 46 4f 53 53 49 4c 5f 45 4e 41 42  ut, "FOSSIL_ENAB
9570: 4c 45 5f 44 45 4c 54 41 5f 43 4b 53 55 4d 5f 54  LE_DELTA_CKSUM_T
9580: 45 53 54 5c 6e 22 2c 20 2d 31 29 3b 0a 23 65 6e  EST\n", -1);.#en
9590: 64 69 66 0a 23 69 66 20 64 65 66 69 6e 65 64 28  dif.#if defined(
95a0: 46 4f 53 53 49 4c 5f 45 4e 41 42 4c 45 5f 4c 45  FOSSIL_ENABLE_LE
95b0: 47 41 43 59 5f 4d 56 5f 52 4d 29 0a 20 20 62 6c  GACY_MV_RM).  bl
95c0: 6f 62 5f 61 70 70 65 6e 64 28 70 4f 75 74 2c 20  ob_append(pOut, 
95d0: 22 46 4f 53 53 49 4c 5f 45 4e 41 42 4c 45 5f 4c  "FOSSIL_ENABLE_L
95e0: 45 47 41 43 59 5f 4d 56 5f 52 4d 5c 6e 22 2c 20  EGACY_MV_RM\n", 
95f0: 2d 31 29 3b 0a 23 65 6e 64 69 66 0a 23 69 66 20  -1);.#endif.#if 
9600: 64 65 66 69 6e 65 64 28 46 4f 53 53 49 4c 5f 45  defined(FOSSIL_E
9610: 4e 41 42 4c 45 5f 45 58 45 43 5f 52 45 4c 5f 50  NABLE_EXEC_REL_P
9620: 41 54 48 53 29 0a 20 20 62 6c 6f 62 5f 61 70 70  ATHS).  blob_app
9630: 65 6e 64 28 70 4f 75 74 2c 20 22 46 4f 53 53 49  end(pOut, "FOSSI
9640: 4c 5f 45 4e 41 42 4c 45 5f 45 58 45 43 5f 52 45  L_ENABLE_EXEC_RE
9650: 4c 5f 50 41 54 48 53 5c 6e 22 2c 20 2d 31 29 3b  L_PATHS\n", -1);
9660: 0a 23 65 6e 64 69 66 0a 23 69 66 20 64 65 66 69  .#endif.#if defi
9670: 6e 65 64 28 46 4f 53 53 49 4c 5f 45 4e 41 42 4c  ned(FOSSIL_ENABL
9680: 45 5f 54 48 31 5f 44 4f 43 53 29 0a 20 20 62 6c  E_TH1_DOCS).  bl
9690: 6f 62 5f 61 70 70 65 6e 64 28 70 4f 75 74 2c 20  ob_append(pOut, 
96a0: 22 46 4f 53 53 49 4c 5f 45 4e 41 42 4c 45 5f 54  "FOSSIL_ENABLE_T
96b0: 48 31 5f 44 4f 43 53 5c 6e 22 2c 20 2d 31 29 3b  H1_DOCS\n", -1);
96c0: 0a 23 65 6e 64 69 66 0a 23 69 66 20 64 65 66 69  .#endif.#if defi
96d0: 6e 65 64 28 46 4f 53 53 49 4c 5f 45 4e 41 42 4c  ned(FOSSIL_ENABL
96e0: 45 5f 54 48 31 5f 48 4f 4f 4b 53 29 0a 20 20 62  E_TH1_HOOKS).  b
96f0: 6c 6f 62 5f 61 70 70 65 6e 64 28 70 4f 75 74 2c  lob_append(pOut,
9700: 20 22 46 4f 53 53 49 4c 5f 45 4e 41 42 4c 45 5f   "FOSSIL_ENABLE_
9710: 54 48 31 5f 48 4f 4f 4b 53 5c 6e 22 2c 20 2d 31  TH1_HOOKS\n", -1
9720: 29 3b 0a 23 65 6e 64 69 66 0a 23 69 66 20 64 65  );.#endif.#if de
9730: 66 69 6e 65 64 28 46 4f 53 53 49 4c 5f 45 4e 41  fined(FOSSIL_ENA
9740: 42 4c 45 5f 54 43 4c 29 0a 20 20 54 68 5f 46 6f  BLE_TCL).  Th_Fo
9750: 73 73 69 6c 49 6e 69 74 28 54 48 5f 49 4e 49 54  ssilInit(TH_INIT
9760: 5f 44 45 46 41 55 4c 54 20 7c 20 54 48 5f 49 4e  _DEFAULT | TH_IN
9770: 49 54 5f 46 4f 52 43 45 5f 54 43 4c 29 3b 0a 20  IT_FORCE_TCL);. 
9780: 20 72 63 20 3d 20 54 68 5f 45 76 61 6c 28 67 2e   rc = Th_Eval(g.
9790: 69 6e 74 65 72 70 2c 20 30 2c 20 22 74 63 6c 49  interp, 0, "tclI
97a0: 6e 76 6f 6b 65 20 69 6e 66 6f 20 70 61 74 63 68  nvoke info patch
97b0: 6c 65 76 65 6c 22 2c 20 2d 31 29 3b 0a 20 20 7a  level", -1);.  z
97c0: 52 63 20 3d 20 54 68 5f 52 65 74 75 72 6e 43 6f  Rc = Th_ReturnCo
97d0: 64 65 4e 61 6d 65 28 72 63 2c 20 30 29 3b 0a 20  deName(rc, 0);. 
97e0: 20 62 6c 6f 62 5f 61 70 70 65 6e 64 66 28 70 4f   blob_appendf(pO
97f0: 75 74 2c 20 22 54 43 4c 20 28 54 63 6c 20 25 73  ut, "TCL (Tcl %s
9800: 2c 20 6c 6f 61 64 65 64 20 25 73 3a 20 25 73 29  , loaded %s: %s)
9810: 5c 6e 22 2c 0a 20 20 20 20 54 43 4c 5f 50 41 54  \n",.    TCL_PAT
9820: 43 48 5f 4c 45 56 45 4c 2c 20 7a 52 63 2c 20 54  CH_LEVEL, zRc, T
9830: 68 5f 47 65 74 52 65 73 75 6c 74 28 67 2e 69 6e  h_GetResult(g.in
9840: 74 65 72 70 2c 20 30 29 0a 20 20 29 3b 0a 23 65  terp, 0).  );.#e
9850: 6e 64 69 66 0a 23 69 66 20 64 65 66 69 6e 65 64  ndif.#if defined
9860: 28 55 53 45 5f 54 43 4c 5f 53 54 55 42 53 29 0a  (USE_TCL_STUBS).
9870: 20 20 62 6c 6f 62 5f 61 70 70 65 6e 64 28 70 4f    blob_append(pO
9880: 75 74 2c 20 22 55 53 45 5f 54 43 4c 5f 53 54 55  ut, "USE_TCL_STU
9890: 42 53 5c 6e 22 2c 20 2d 31 29 3b 0a 23 65 6e 64  BS\n", -1);.#end
98a0: 69 66 0a 23 69 66 20 64 65 66 69 6e 65 64 28 46  if.#if defined(F
98b0: 4f 53 53 49 4c 5f 45 4e 41 42 4c 45 5f 54 43 4c  OSSIL_ENABLE_TCL
98c0: 5f 53 54 55 42 53 29 0a 20 20 62 6c 6f 62 5f 61  _STUBS).  blob_a
98d0: 70 70 65 6e 64 28 70 4f 75 74 2c 20 22 46 4f 53  ppend(pOut, "FOS
98e0: 53 49 4c 5f 54 43 4c 5f 53 54 55 42 53 5c 6e 22  SIL_TCL_STUBS\n"
98f0: 2c 20 2d 31 29 3b 0a 23 65 6e 64 69 66 0a 23 69  , -1);.#endif.#i
9900: 66 20 64 65 66 69 6e 65 64 28 46 4f 53 53 49 4c  f defined(FOSSIL
9910: 5f 45 4e 41 42 4c 45 5f 54 43 4c 5f 50 52 49 56  _ENABLE_TCL_PRIV
9920: 41 54 45 5f 53 54 55 42 53 29 0a 20 20 62 6c 6f  ATE_STUBS).  blo
9930: 62 5f 61 70 70 65 6e 64 28 70 4f 75 74 2c 20 22  b_append(pOut, "
9940: 46 4f 53 53 49 4c 5f 45 4e 41 42 4c 45 5f 54 43  FOSSIL_ENABLE_TC
9950: 4c 5f 50 52 49 56 41 54 45 5f 53 54 55 42 53 5c  L_PRIVATE_STUBS\
9960: 6e 22 2c 20 2d 31 29 3b 0a 23 65 6e 64 69 66 0a  n", -1);.#endif.
9970: 23 69 66 20 64 65 66 69 6e 65 64 28 46 4f 53 53  #if defined(FOSS
9980: 49 4c 5f 45 4e 41 42 4c 45 5f 4a 53 4f 4e 29 0a  IL_ENABLE_JSON).
9990: 20 20 62 6c 6f 62 5f 61 70 70 65 6e 64 66 28 70    blob_appendf(p
99a0: 4f 75 74 2c 20 22 4a 53 4f 4e 20 28 41 50 49 20  Out, "JSON (API 
99b0: 25 73 29 5c 6e 22 2c 20 46 4f 53 53 49 4c 5f 4a  %s)\n", FOSSIL_J
99c0: 53 4f 4e 5f 41 50 49 5f 56 45 52 53 49 4f 4e 29  SON_API_VERSION)
99d0: 3b 0a 23 65 6e 64 69 66 0a 23 69 66 20 64 65 66  ;.#endif.#if def
99e0: 69 6e 65 64 28 42 52 4f 4b 45 4e 5f 4d 49 4e 47  ined(BROKEN_MING
99f0: 57 5f 43 4d 44 4c 49 4e 45 29 0a 20 20 62 6c 6f  W_CMDLINE).  blo
9a00: 62 5f 61 70 70 65 6e 64 28 70 4f 75 74 2c 20 22  b_append(pOut, "
9a10: 4d 42 43 53 5f 43 4f 4d 4d 41 4e 44 5f 4c 49 4e  MBCS_COMMAND_LIN
9a20: 45 5c 6e 22 2c 20 2d 31 29 3b 0a 23 65 6c 73 65  E\n", -1);.#else
9a30: 0a 20 20 62 6c 6f 62 5f 61 70 70 65 6e 64 28 70  .  blob_append(p
9a40: 4f 75 74 2c 20 22 55 4e 49 43 4f 44 45 5f 43 4f  Out, "UNICODE_CO
9a50: 4d 4d 41 4e 44 5f 4c 49 4e 45 5c 6e 22 2c 20 2d  MMAND_LINE\n", -
9a60: 31 29 3b 0a 23 65 6e 64 69 66 0a 23 69 66 20 64  1);.#endif.#if d
9a70: 65 66 69 6e 65 64 28 46 4f 53 53 49 4c 5f 44 59  efined(FOSSIL_DY
9a80: 4e 41 4d 49 43 5f 42 55 49 4c 44 29 0a 20 20 62  NAMIC_BUILD).  b
9a90: 6c 6f 62 5f 61 70 70 65 6e 64 28 70 4f 75 74 2c  lob_append(pOut,
9aa0: 20 22 46 4f 53 53 49 4c 5f 44 59 4e 41 4d 49 43   "FOSSIL_DYNAMIC
9ab0: 5f 42 55 49 4c 44 5c 6e 22 2c 20 2d 31 29 3b 0a  _BUILD\n", -1);.
9ac0: 23 65 6c 73 65 0a 20 20 62 6c 6f 62 5f 61 70 70  #else.  blob_app
9ad0: 65 6e 64 28 70 4f 75 74 2c 20 22 46 4f 53 53 49  end(pOut, "FOSSI
9ae0: 4c 5f 53 54 41 54 49 43 5f 42 55 49 4c 44 5c 6e  L_STATIC_BUILD\n
9af0: 22 2c 20 2d 31 29 3b 0a 23 65 6e 64 69 66 0a 23  ", -1);.#endif.#
9b00: 69 66 20 64 65 66 69 6e 65 64 28 48 41 56 45 5f  if defined(HAVE_
9b10: 50 4c 45 44 47 45 29 0a 20 20 62 6c 6f 62 5f 61  PLEDGE).  blob_a
9b20: 70 70 65 6e 64 28 70 4f 75 74 2c 20 22 48 41 56  ppend(pOut, "HAV
9b30: 45 5f 50 4c 45 44 47 45 5c 6e 22 2c 20 2d 31 29  E_PLEDGE\n", -1)
9b40: 3b 0a 23 65 6e 64 69 66 0a 23 69 66 20 64 65 66  ;.#endif.#if def
9b50: 69 6e 65 64 28 55 53 45 5f 4d 4d 41 4e 5f 48 29  ined(USE_MMAN_H)
9b60: 0a 20 20 62 6c 6f 62 5f 61 70 70 65 6e 64 28 70  .  blob_append(p
9b70: 4f 75 74 2c 20 22 55 53 45 5f 4d 4d 41 4e 5f 48  Out, "USE_MMAN_H
9b80: 5c 6e 22 2c 20 2d 31 29 3b 0a 23 65 6e 64 69 66  \n", -1);.#endif
9b90: 0a 23 69 66 20 64 65 66 69 6e 65 64 28 55 53 45  .#if defined(USE
9ba0: 5f 53 45 45 29 0a 20 20 62 6c 6f 62 5f 61 70 70  _SEE).  blob_app
9bb0: 65 6e 64 28 70 4f 75 74 2c 20 22 55 53 45 5f 53  end(pOut, "USE_S
9bc0: 45 45 5c 6e 22 2c 20 2d 31 29 3b 0a 23 65 6e 64  EE\n", -1);.#end
9bd0: 69 66 0a 23 69 66 20 64 65 66 69 6e 65 64 28 46  if.#if defined(F
9be0: 4f 53 53 49 4c 5f 41 4c 4c 4f 57 5f 4f 55 54 5f  OSSIL_ALLOW_OUT_
9bf0: 4f 46 5f 4f 52 44 45 52 5f 44 41 54 45 53 29 0a  OF_ORDER_DATES).
9c00: 20 20 62 6c 6f 62 5f 61 70 70 65 6e 64 28 70 4f    blob_append(pO
9c10: 75 74 2c 20 22 46 4f 53 53 49 4c 5f 41 4c 4c 4f  ut, "FOSSIL_ALLO
9c20: 57 5f 4f 55 54 5f 4f 46 5f 4f 52 44 45 52 5f 44  W_OUT_OF_ORDER_D
9c30: 41 54 45 53 5c 6e 22 29 3b 0a 23 65 6e 64 69 66  ATES\n");.#endif
9c40: 0a 20 20 62 6c 6f 62 5f 61 70 70 65 6e 64 66 28  .  blob_appendf(
9c50: 70 4f 75 74 2c 20 22 53 51 4c 69 74 65 20 25 73  pOut, "SQLite %s
9c60: 20 25 2e 33 30 73 5c 6e 22 2c 20 73 71 6c 69 74   %.30s\n", sqlit
9c70: 65 33 5f 6c 69 62 76 65 72 73 69 6f 6e 28 29 2c  e3_libversion(),
9c80: 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20  .               
9c90: 73 71 6c 69 74 65 33 5f 73 6f 75 72 63 65 69 64  sqlite3_sourceid
9ca0: 28 29 29 3b 0a 20 20 69 66 28 20 67 2e 64 62 3d  ());.  if( g.db=
9cb0: 3d 30 20 29 20 73 71 6c 69 74 65 33 5f 6f 70 65  =0 ) sqlite3_ope
9cc0: 6e 28 22 3a 6d 65 6d 6f 72 79 3a 22 2c 20 26 67  n(":memory:", &g
9cd0: 2e 64 62 29 3b 0a 20 20 64 62 5f 70 72 65 70 61  .db);.  db_prepa
9ce0: 72 65 28 26 71 2c 0a 20 20 20 20 20 22 70 72 61  re(&q,.     "pra
9cf0: 67 6d 61 20 63 6f 6d 70 69 6c 65 5f 6f 70 74 69  gma compile_opti
9d00: 6f 6e 73 22 29 3b 0a 20 20 77 68 69 6c 65 28 20  ons");.  while( 
9d10: 64 62 5f 73 74 65 70 28 26 71 29 3d 3d 53 51 4c  db_step(&q)==SQL
9d20: 49 54 45 5f 52 4f 57 20 29 7b 0a 20 20 20 20 63  ITE_ROW ){.    c
9d30: 6f 6e 73 74 20 63 68 61 72 20 2a 74 65 78 74 20  onst char *text 
9d40: 3d 20 64 62 5f 63 6f 6c 75 6d 6e 5f 74 65 78 74  = db_column_text
9d50: 28 26 71 2c 20 30 29 3b 0a 20 20 20 20 69 66 28  (&q, 0);.    if(
9d60: 20 73 74 72 6e 63 6d 70 28 74 65 78 74 2c 20 22   strncmp(text, "
9d70: 43 4f 4d 50 49 4c 45 52 22 2c 20 38 29 20 29 7b  COMPILER", 8) ){
9d80: 0a 20 20 20 20 20 20 62 6c 6f 62 5f 61 70 70 65  .      blob_appe
9d90: 6e 64 66 28 70 4f 75 74 2c 20 22 53 51 4c 49 54  ndf(pOut, "SQLIT
9da0: 45 5f 25 73 5c 6e 22 2c 20 74 65 78 74 29 3b 0a  E_%s\n", text);.
9db0: 20 20 20 20 7d 0a 20 20 7d 0a 20 20 64 62 5f 66      }.  }.  db_f
9dc0: 69 6e 61 6c 69 7a 65 28 26 71 29 3b 0a 7d 0a 0a  inalize(&q);.}..
9dd0: 2f 2a 0a 2a 2a 20 54 68 69 73 20 66 75 6e 63 74  /*.** This funct
9de0: 69 6f 6e 20 72 65 74 75 72 6e 73 20 74 68 65 20  ion returns the 
9df0: 75 73 65 72 2d 61 67 65 6e 74 20 73 74 72 69 6e  user-agent strin
9e00: 67 20 66 6f 72 20 46 6f 73 73 69 6c 2c 20 66 6f  g for Fossil, fo
9e10: 72 0a 2a 2a 20 75 73 65 20 69 6e 20 48 54 54 50  r.** use in HTTP
9e20: 28 53 29 20 72 65 71 75 65 73 74 73 2e 0a 2a 2f  (S) requests..*/
9e30: 0a 63 6f 6e 73 74 20 63 68 61 72 20 2a 67 65 74  .const char *get
9e40: 5f 75 73 65 72 5f 61 67 65 6e 74 28 29 7b 0a 20  _user_agent(){. 
9e50: 20 73 74 61 74 69 63 20 63 6f 6e 73 74 20 63 68   static const ch
9e60: 61 72 20 76 65 72 73 69 6f 6e 5b 5d 20 3d 20 22  ar version[] = "
9e70: 46 6f 73 73 69 6c 2f 22 20 52 45 4c 45 41 53 45  Fossil/" RELEASE
9e80: 5f 56 45 52 53 49 4f 4e 20 22 20 28 22 20 4d 41  _VERSION " (" MA
9e90: 4e 49 46 45 53 54 5f 44 41 54 45 0a 20 20 20 20  NIFEST_DATE.    
9ea0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
9eb0: 20 20 20 20 20 20 20 20 20 20 20 20 22 20 22 20              " " 
9ec0: 4d 41 4e 49 46 45 53 54 5f 56 45 52 53 49 4f 4e  MANIFEST_VERSION
9ed0: 20 22 29 22 3b 0a 20 20 72 65 74 75 72 6e 20 76   ")";.  return v
9ee0: 65 72 73 69 6f 6e 3b 0a 7d 0a 0a 0a 2f 2a 0a 2a  ersion;.}.../*.*
9ef0: 2a 20 43 4f 4d 4d 41 4e 44 3a 20 76 65 72 73 69  * COMMAND: versi
9f00: 6f 6e 0a 2a 2a 0a 2a 2a 20 55 73 61 67 65 3a 20  on.**.** Usage: 
9f10: 25 66 6f 73 73 69 6c 20 76 65 72 73 69 6f 6e 20  %fossil version 
9f20: 3f 2d 76 65 72 62 6f 73 65 7c 2d 76 3f 0a 2a 2a  ?-verbose|-v?.**
9f30: 0a 2a 2a 20 50 72 69 6e 74 20 74 68 65 20 73 6f  .** Print the so
9f40: 75 72 63 65 20 63 6f 64 65 20 76 65 72 73 69 6f  urce code versio
9f50: 6e 20 6e 75 6d 62 65 72 20 66 6f 72 20 74 68 65  n number for the
9f60: 20 66 6f 73 73 69 6c 20 65 78 65 63 75 74 61 62   fossil executab
9f70: 6c 65 2e 0a 2a 2a 20 49 66 20 74 68 65 20 76 65  le..** If the ve
9f80: 72 62 6f 73 65 20 6f 70 74 69 6f 6e 20 69 73 20  rbose option is 
9f90: 73 70 65 63 69 66 69 65 64 2c 20 61 64 64 69 74  specified, addit
9fa0: 69 6f 6e 61 6c 20 64 65 74 61 69 6c 73 20 77 69  ional details wi
9fb0: 6c 6c 0a 2a 2a 20 62 65 20 6f 75 74 70 75 74 20  ll.** be output 
9fc0: 61 62 6f 75 74 20 77 68 61 74 20 6f 70 74 69 6f  about what optio
9fd0: 6e 61 6c 20 66 65 61 74 75 72 65 73 20 74 68 69  nal features thi
9fe0: 73 20 62 69 6e 61 72 79 20 77 61 73 20 63 6f 6d  s binary was com
9ff0: 70 69 6c 65 64 0a 2a 2a 20 77 69 74 68 0a 2a 2f  piled.** with.*/
a000: 0a 76 6f 69 64 20 76 65 72 73 69 6f 6e 5f 63 6d  .void version_cm
a010: 64 28 76 6f 69 64 29 7b 0a 20 20 42 6c 6f 62 20  d(void){.  Blob 
a020: 76 65 72 73 69 6f 6e 49 6e 66 6f 3b 0a 20 20 69  versionInfo;.  i
a030: 6e 74 20 76 65 72 62 6f 73 65 46 6c 61 67 20 3d  nt verboseFlag =
a040: 20 66 69 6e 64 5f 6f 70 74 69 6f 6e 28 22 76 65   find_option("ve
a050: 72 62 6f 73 65 22 2c 22 76 22 2c 30 29 21 3d 30  rbose","v",0)!=0
a060: 3b 0a 0a 20 20 2f 2a 20 57 65 20 73 68 6f 75 6c  ;..  /* We shoul
a070: 64 20 62 65 20 64 6f 6e 65 20 77 69 74 68 20 6f  d be done with o
a080: 70 74 69 6f 6e 73 2e 2e 20 2a 2f 0a 20 20 76 65  ptions.. */.  ve
a090: 72 69 66 79 5f 61 6c 6c 5f 6f 70 74 69 6f 6e 73  rify_all_options
a0a0: 28 29 3b 0a 20 20 67 65 74 5f 76 65 72 73 69 6f  ();.  get_versio
a0b0: 6e 5f 62 6c 6f 62 28 26 76 65 72 73 69 6f 6e 49  n_blob(&versionI
a0c0: 6e 66 6f 2c 20 76 65 72 62 6f 73 65 46 6c 61 67  nfo, verboseFlag
a0d0: 29 3b 0a 20 20 66 6f 73 73 69 6c 5f 70 72 69 6e  );.  fossil_prin
a0e0: 74 28 22 25 73 22 2c 20 62 6c 6f 62 5f 73 74 72  t("%s", blob_str
a0f0: 28 26 76 65 72 73 69 6f 6e 49 6e 66 6f 29 29 3b  (&versionInfo));
a100: 0a 7d 0a 0a 0a 2f 2a 0a 2a 2a 20 57 45 42 50 41  .}.../*.** WEBPA
a110: 47 45 3a 20 76 65 72 73 69 6f 6e 0a 2a 2a 0a 2a  GE: version.**.*
a120: 2a 20 53 68 6f 77 20 74 68 65 20 76 65 72 73 69  * Show the versi
a130: 6f 6e 20 69 6e 66 6f 72 6d 61 74 69 6f 6e 20 66  on information f
a140: 6f 72 20 46 6f 73 73 69 6c 2e 0a 2a 2a 0a 2a 2a  or Fossil..**.**
a150: 20 51 75 65 72 79 20 70 61 72 61 6d 65 74 65 72   Query parameter
a160: 73 3a 0a 2a 2a 0a 2a 2a 20 20 20 20 76 65 72 62  s:.**.**    verb
a170: 6f 73 65 20 20 20 20 20 20 20 53 68 6f 77 20 64  ose       Show d
a180: 65 74 61 69 6c 73 0a 2a 2f 0a 76 6f 69 64 20 74  etails.*/.void t
a190: 65 73 74 5f 76 65 72 73 69 6f 6e 5f 70 61 67 65  est_version_page
a1a0: 28 76 6f 69 64 29 7b 0a 20 20 42 6c 6f 62 20 76  (void){.  Blob v
a1b0: 65 72 73 69 6f 6e 49 6e 66 6f 3b 0a 20 20 69 6e  ersionInfo;.  in
a1c0: 74 20 76 65 72 62 6f 73 65 46 6c 61 67 3b 0a 0a  t verboseFlag;..
a1d0: 20 20 6c 6f 67 69 6e 5f 63 68 65 63 6b 5f 63 72    login_check_cr
a1e0: 65 64 65 6e 74 69 61 6c 73 28 29 3b 0a 20 20 69  edentials();.  i
a1f0: 66 28 20 21 67 2e 70 65 72 6d 2e 52 65 61 64 20  f( !g.perm.Read 
a200: 29 7b 20 6c 6f 67 69 6e 5f 6e 65 65 64 65 64 28  ){ login_needed(
a210: 67 2e 61 6e 6f 6e 2e 52 65 61 64 29 3b 20 72 65  g.anon.Read); re
a220: 74 75 72 6e 3b 20 7d 0a 20 20 76 65 72 62 6f 73  turn; }.  verbos
a230: 65 46 6c 61 67 20 3d 20 50 44 28 22 76 65 72 62  eFlag = PD("verb
a240: 6f 73 65 22 2c 20 30 29 20 21 3d 20 30 3b 0a 20  ose", 0) != 0;. 
a250: 20 73 74 79 6c 65 5f 68 65 61 64 65 72 28 22 56   style_header("V
a260: 65 72 73 69 6f 6e 20 49 6e 66 6f 72 6d 61 74 69  ersion Informati
a270: 6f 6e 22 29 3b 0a 20 20 73 74 79 6c 65 5f 73 75  on");.  style_su
a280: 62 6d 65 6e 75 5f 65 6c 65 6d 65 6e 74 28 22 53  bmenu_element("S
a290: 74 61 74 22 2c 20 22 73 74 61 74 22 29 3b 0a 20  tat", "stat");. 
a2a0: 20 67 65 74 5f 76 65 72 73 69 6f 6e 5f 62 6c 6f   get_version_blo
a2b0: 62 28 26 76 65 72 73 69 6f 6e 49 6e 66 6f 2c 20  b(&versionInfo, 
a2c0: 76 65 72 62 6f 73 65 46 6c 61 67 29 3b 0a 20 20  verboseFlag);.  
a2d0: 40 20 3c 70 72 65 3e 0a 20 20 40 20 25 68 28 62  @ <pre>.  @ %h(b
a2e0: 6c 6f 62 5f 73 74 72 28 26 76 65 72 73 69 6f 6e  lob_str(&version
a2f0: 49 6e 66 6f 29 29 0a 20 20 40 20 3c 2f 70 72 65  Info)).  @ </pre
a300: 3e 0a 20 20 73 74 79 6c 65 5f 66 6f 6f 74 65 72  >.  style_footer
a310: 28 29 3b 0a 7d 0a 0a 0a 2f 2a 0a 2a 2a 20 53 65  ();.}.../*.** Se
a320: 74 20 74 68 65 20 67 2e 7a 42 61 73 65 55 52 4c  t the g.zBaseURL
a330: 20 76 61 6c 75 65 20 74 6f 20 74 68 65 20 66 75   value to the fu
a340: 6c 6c 20 55 52 4c 20 66 6f 72 20 74 68 65 20 74  ll URL for the t
a350: 6f 70 6c 65 76 65 6c 20 6f 66 0a 2a 2a 20 74 68  oplevel of.** th
a360: 65 20 66 6f 73 73 69 6c 20 74 72 65 65 2e 20 20  e fossil tree.  
a370: 53 65 74 20 67 2e 7a 54 6f 70 20 74 6f 20 67 2e  Set g.zTop to g.
a380: 7a 42 61 73 65 55 52 4c 20 77 69 74 68 6f 75 74  zBaseURL without
a390: 20 74 68 65 0a 2a 2a 20 6c 65 61 64 69 6e 67 20   the.** leading 
a3a0: 22 68 74 74 70 3a 2f 2f 22 20 61 6e 64 20 74 68  "http://" and th
a3b0: 65 20 68 6f 73 74 20 61 6e 64 20 70 6f 72 74 2e  e host and port.
a3c0: 0a 2a 2a 0a 2a 2a 20 54 68 65 20 67 2e 7a 42 61  .**.** The g.zBa
a3d0: 73 65 55 52 4c 20 69 73 20 6e 6f 72 6d 61 6c 6c  seURL is normall
a3e0: 79 20 73 65 74 20 62 61 73 65 64 20 6f 6e 20 48  y set based on H
a3f0: 54 54 50 5f 48 4f 53 54 20 61 6e 64 20 53 43 52  TTP_HOST and SCR
a400: 49 50 54 5f 4e 41 4d 45 0a 2a 2a 20 65 6e 76 69  IPT_NAME.** envi
a410: 72 6f 6e 6d 65 6e 74 20 76 61 72 69 61 62 6c 65  ronment variable
a420: 73 2e 20 20 48 6f 77 65 76 65 72 2c 20 69 66 20  s.  However, if 
a430: 7a 41 6c 74 42 61 73 65 20 69 73 20 6e 6f 74 20  zAltBase is not 
a440: 4e 55 4c 4c 20 74 68 65 6e 20 69 74 0a 2a 2a 20  NULL then it.** 
a450: 69 73 20 74 68 65 20 61 72 67 75 6d 65 6e 74 20  is the argument 
a460: 74 6f 20 74 68 65 20 2d 2d 62 61 73 65 75 72 6c  to the --baseurl
a470: 20 6f 70 74 69 6f 6e 20 63 6f 6d 6d 61 6e 64 2d   option command-
a480: 6c 69 6e 65 20 6f 70 74 69 6f 6e 20 61 6e 64 0a  line option and.
a490: 2a 2a 20 67 2e 7a 42 61 73 65 55 52 4c 20 61 6e  ** g.zBaseURL an
a4a0: 64 20 67 2e 7a 54 6f 70 20 69 73 20 73 65 74 20  d g.zTop is set 
a4b0: 66 72 6f 6d 20 74 68 61 74 20 69 6e 73 74 65 61  from that instea
a4c0: 64 2e 0a 2a 2f 0a 73 74 61 74 69 63 20 76 6f 69  d..*/.static voi
a4d0: 64 20 73 65 74 5f 62 61 73 65 5f 75 72 6c 28 63  d set_base_url(c
a4e0: 6f 6e 73 74 20 63 68 61 72 20 2a 7a 41 6c 74 42  onst char *zAltB
a4f0: 61 73 65 29 7b 0a 20 20 69 6e 74 20 69 3b 0a 20  ase){.  int i;. 
a500: 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a 48 6f   const char *zHo
a510: 73 74 3b 0a 20 20 63 6f 6e 73 74 20 63 68 61 72  st;.  const char
a520: 20 2a 7a 4d 6f 64 65 3b 0a 20 20 63 6f 6e 73 74   *zMode;.  const
a530: 20 63 68 61 72 20 2a 7a 43 75 72 3b 0a 0a 20 20   char *zCur;..  
a540: 69 66 28 20 67 2e 7a 42 61 73 65 55 52 4c 21 3d  if( g.zBaseURL!=
a550: 30 20 29 20 72 65 74 75 72 6e 3b 0a 20 20 69 66  0 ) return;.  if
a560: 28 20 7a 41 6c 74 42 61 73 65 20 29 7b 0a 20 20  ( zAltBase ){.  
a570: 20 20 69 6e 74 20 69 2c 20 6e 2c 20 63 3b 0a 20    int i, n, c;. 
a580: 20 20 20 67 2e 7a 54 6f 70 20 3d 20 67 2e 7a 42     g.zTop = g.zB
a590: 61 73 65 55 52 4c 20 3d 20 6d 70 72 69 6e 74 66  aseURL = mprintf
a5a0: 28 22 25 73 22 2c 20 7a 41 6c 74 42 61 73 65 29  ("%s", zAltBase)
a5b0: 3b 0a 20 20 20 20 69 66 28 20 73 74 72 6e 63 6d  ;.    if( strncm
a5c0: 70 28 67 2e 7a 54 6f 70 2c 20 22 68 74 74 70 3a  p(g.zTop, "http:
a5d0: 2f 2f 22 2c 20 37 29 3d 3d 30 20 29 7b 0a 20 20  //", 7)==0 ){.  
a5e0: 20 20 20 20 2f 2a 20 69 74 20 69 73 20 48 54 54      /* it is HTT
a5f0: 50 2c 20 72 65 70 6c 61 63 65 20 70 72 65 66 69  P, replace prefi
a600: 78 20 77 69 74 68 20 48 54 54 50 53 2e 20 2a 2f  x with HTTPS. */
a610: 0a 20 20 20 20 20 20 67 2e 7a 48 74 74 70 73 55  .      g.zHttpsU
a620: 52 4c 20 3d 20 6d 70 72 69 6e 74 66 28 22 68 74  RL = mprintf("ht
a630: 74 70 73 3a 2f 2f 25 73 22 2c 20 26 67 2e 7a 54  tps://%s", &g.zT
a640: 6f 70 5b 37 5d 29 3b 0a 20 20 20 20 7d 65 6c 73  op[7]);.    }els
a650: 65 20 69 66 28 20 73 74 72 6e 63 6d 70 28 67 2e  e if( strncmp(g.
a660: 7a 54 6f 70 2c 20 22 68 74 74 70 73 3a 2f 2f 22  zTop, "https://"
a670: 2c 20 38 29 3d 3d 30 20 29 7b 0a 20 20 20 20 20  , 8)==0 ){.     
a680: 20 2f 2a 20 69 74 20 69 73 20 61 6c 72 65 61 64   /* it is alread
a690: 79 20 48 54 54 50 53 2c 20 75 73 65 20 69 74 2e  y HTTPS, use it.
a6a0: 20 2a 2f 0a 20 20 20 20 20 20 67 2e 7a 48 74 74   */.      g.zHtt
a6b0: 70 73 55 52 4c 20 3d 20 6d 70 72 69 6e 74 66 28  psURL = mprintf(
a6c0: 22 25 73 22 2c 20 67 2e 7a 54 6f 70 29 3b 0a 20  "%s", g.zTop);. 
a6d0: 20 20 20 7d 65 6c 73 65 7b 0a 20 20 20 20 20 20     }else{.      
a6e0: 66 6f 73 73 69 6c 5f 66 61 74 61 6c 28 22 61 72  fossil_fatal("ar
a6f0: 67 75 6d 65 6e 74 20 74 6f 20 2d 2d 62 61 73 65  gument to --base
a700: 75 72 6c 20 73 68 6f 75 6c 64 20 62 65 20 27 68  url should be 'h
a710: 74 74 70 3a 2f 2f 68 6f 73 74 2f 70 61 74 68 27  ttp://host/path'
a720: 22 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20  ".              
a730: 20 20 20 20 20 22 20 6f 72 20 27 68 74 74 70 73       " or 'https
a740: 3a 2f 2f 68 6f 73 74 2f 70 61 74 68 27 22 29 3b  ://host/path'");
a750: 0a 20 20 20 20 7d 0a 20 20 20 20 66 6f 72 28 69  .    }.    for(i
a760: 3d 6e 3d 30 3b 20 28 63 20 3d 20 67 2e 7a 54 6f  =n=0; (c = g.zTo
a770: 70 5b 69 5d 29 21 3d 30 3b 20 69 2b 2b 29 7b 0a  p[i])!=0; i++){.
a780: 20 20 20 20 20 20 69 66 28 20 63 3d 3d 27 2f 27        if( c=='/'
a790: 20 29 7b 0a 20 20 20 20 20 20 20 20 6e 2b 2b 3b   ){.        n++;
a7a0: 0a 20 20 20 20 20 20 20 20 69 66 28 20 6e 3d 3d  .        if( n==
a7b0: 33 20 29 7b 0a 20 20 20 20 20 20 20 20 20 20 67  3 ){.          g
a7c0: 2e 7a 54 6f 70 20 2b 3d 20 69 3b 0a 20 20 20 20  .zTop += i;.    
a7d0: 20 20 20 20 20 20 62 72 65 61 6b 3b 0a 20 20 20        break;.   
a7e0: 20 20 20 20 20 7d 0a 20 20 20 20 20 20 7d 0a 20       }.      }. 
a7f0: 20 20 20 7d 0a 20 20 20 20 69 66 28 20 67 2e 7a     }.    if( g.z
a800: 54 6f 70 3d 3d 67 2e 7a 42 61 73 65 55 52 4c 20  Top==g.zBaseURL 
a810: 29 7b 0a 20 20 20 20 20 20 66 6f 73 73 69 6c 5f  ){.      fossil_
a820: 66 61 74 61 6c 28 22 61 72 67 75 6d 65 6e 74 20  fatal("argument 
a830: 74 6f 20 2d 2d 62 61 73 65 75 72 6c 20 73 68 6f  to --baseurl sho
a840: 75 6c 64 20 62 65 20 27 68 74 74 70 3a 2f 2f 68  uld be 'http://h
a850: 6f 73 74 2f 70 61 74 68 27 22 0a 20 20 20 20 20  ost/path'".     
a860: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 22 20                " 
a870: 6f 72 20 27 68 74 74 70 73 3a 2f 2f 68 6f 73 74  or 'https://host
a880: 2f 70 61 74 68 27 22 29 3b 0a 20 20 20 20 7d 0a  /path'");.    }.
a890: 20 20 20 20 69 66 28 20 67 2e 7a 54 6f 70 5b 31      if( g.zTop[1
a8a0: 5d 3d 3d 30 20 29 20 67 2e 7a 54 6f 70 2b 2b 3b  ]==0 ) g.zTop++;
a8b0: 0a 20 20 7d 65 6c 73 65 7b 0a 20 20 20 20 7a 48  .  }else{.    zH
a8c0: 6f 73 74 20 3d 20 50 44 28 22 48 54 54 50 5f 48  ost = PD("HTTP_H
a8d0: 4f 53 54 22 2c 22 22 29 3b 0a 20 20 20 20 7a 4d  OST","");.    zM
a8e0: 6f 64 65 20 3d 20 50 44 28 22 48 54 54 50 53 22  ode = PD("HTTPS"
a8f0: 2c 22 6f 66 66 22 29 3b 0a 20 20 20 20 7a 43 75  ,"off");.    zCu
a900: 72 20 3d 20 50 44 28 22 53 43 52 49 50 54 5f 4e  r = PD("SCRIPT_N
a910: 41 4d 45 22 2c 22 2f 22 29 3b 0a 20 20 20 20 69  AME","/");.    i
a920: 20 3d 20 73 74 72 6c 65 6e 28 7a 43 75 72 29 3b   = strlen(zCur);
a930: 0a 20 20 20 20 77 68 69 6c 65 28 20 69 3e 30 20  .    while( i>0 
a940: 26 26 20 7a 43 75 72 5b 69 2d 31 5d 3d 3d 27 2f  && zCur[i-1]=='/
a950: 27 20 29 20 69 2d 2d 3b 0a 20 20 20 20 69 66 28  ' ) i--;.    if(
a960: 20 66 6f 73 73 69 6c 5f 73 74 72 69 63 6d 70 28   fossil_stricmp(
a970: 7a 4d 6f 64 65 2c 22 6f 6e 22 29 3d 3d 30 20 29  zMode,"on")==0 )
a980: 7b 0a 20 20 20 20 20 20 67 2e 7a 42 61 73 65 55  {.      g.zBaseU
a990: 52 4c 20 3d 20 6d 70 72 69 6e 74 66 28 22 68 74  RL = mprintf("ht
a9a0: 74 70 73 3a 2f 2f 25 73 25 2e 2a 73 22 2c 20 7a  tps://%s%.*s", z
a9b0: 48 6f 73 74 2c 20 69 2c 20 7a 43 75 72 29 3b 0a  Host, i, zCur);.
a9c0: 20 20 20 20 20 20 67 2e 7a 54 6f 70 20 3d 20 26        g.zTop = &
a9d0: 67 2e 7a 42 61 73 65 55 52 4c 5b 38 2b 73 74 72  g.zBaseURL[8+str
a9e0: 6c 65 6e 28 7a 48 6f 73 74 29 5d 3b 0a 20 20 20  len(zHost)];.   
a9f0: 20 20 20 67 2e 7a 48 74 74 70 73 55 52 4c 20 3d     g.zHttpsURL =
aa00: 20 67 2e 7a 42 61 73 65 55 52 4c 3b 0a 20 20 20   g.zBaseURL;.   
aa10: 20 7d 65 6c 73 65 7b 0a 20 20 20 20 20 20 67 2e   }else{.      g.
aa20: 7a 42 61 73 65 55 52 4c 20 3d 20 6d 70 72 69 6e  zBaseURL = mprin
aa30: 74 66 28 22 68 74 74 70 3a 2f 2f 25 73 25 2e 2a  tf("http://%s%.*
aa40: 73 22 2c 20 7a 48 6f 73 74 2c 20 69 2c 20 7a 43  s", zHost, i, zC
aa50: 75 72 29 3b 0a 20 20 20 20 20 20 67 2e 7a 54 6f  ur);.      g.zTo
aa60: 70 20 3d 20 26 67 2e 7a 42 61 73 65 55 52 4c 5b  p = &g.zBaseURL[
aa70: 37 2b 73 74 72 6c 65 6e 28 7a 48 6f 73 74 29 5d  7+strlen(zHost)]
aa80: 3b 0a 20 20 20 20 20 20 67 2e 7a 48 74 74 70 73  ;.      g.zHttps
aa90: 55 52 4c 20 3d 20 6d 70 72 69 6e 74 66 28 22 68  URL = mprintf("h
aaa0: 74 74 70 73 3a 2f 2f 25 73 25 2e 2a 73 22 2c 20  ttps://%s%.*s", 
aab0: 7a 48 6f 73 74 2c 20 69 2c 20 7a 43 75 72 29 3b  zHost, i, zCur);
aac0: 0a 20 20 20 20 7d 0a 20 20 7d 0a 20 20 69 66 28  .    }.  }.  if(
aad0: 20 64 62 5f 69 73 5f 77 72 69 74 65 61 62 6c 65   db_is_writeable
aae0: 28 22 72 65 70 6f 73 69 74 6f 72 79 22 29 20 29  ("repository") )
aaf0: 7b 0a 20 20 20 20 69 66 28 20 21 64 62 5f 65 78  {.    if( !db_ex
ab00: 69 73 74 73 28 22 53 45 4c 45 43 54 20 31 20 46  ists("SELECT 1 F
ab10: 52 4f 4d 20 63 6f 6e 66 69 67 20 57 48 45 52 45  ROM config WHERE
ab20: 20 6e 61 6d 65 3d 27 62 61 73 65 75 72 6c 3a 25   name='baseurl:%
ab30: 71 27 22 2c 20 67 2e 7a 42 61 73 65 55 52 4c 29  q'", g.zBaseURL)
ab40: 29 7b 0a 20 20 20 20 20 20 64 62 5f 6d 75 6c 74  ){.      db_mult
ab50: 69 5f 65 78 65 63 28 22 49 4e 53 45 52 54 20 49  i_exec("INSERT I
ab60: 4e 54 4f 20 63 6f 6e 66 69 67 28 6e 61 6d 65 2c  NTO config(name,
ab70: 76 61 6c 75 65 2c 6d 74 69 6d 65 29 22 0a 20 20  value,mtime)".  
ab80: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
ab90: 20 20 22 56 41 4c 55 45 53 28 27 62 61 73 65 75    "VALUES('baseu
aba0: 72 6c 3a 25 71 27 2c 31 2c 6e 6f 77 28 29 29 22  rl:%q',1,now())"
abb0: 2c 20 67 2e 7a 42 61 73 65 55 52 4c 29 3b 0a 20  , g.zBaseURL);. 
abc0: 20 20 20 7d 65 6c 73 65 7b 0a 20 20 20 20 20 20     }else{.      
abd0: 64 62 5f 6f 70 74 69 6f 6e 61 6c 5f 73 71 6c 28  db_optional_sql(
abe0: 22 72 65 70 6f 73 69 74 6f 72 79 22 2c 0a 20 20  "repository",.  
abf0: 20 20 20 20 20 20 20 20 20 22 52 45 50 4c 41 43           "REPLAC
ac00: 45 20 49 4e 54 4f 20 63 6f 6e 66 69 67 28 6e 61  E INTO config(na
ac10: 6d 65 2c 76 61 6c 75 65 2c 6d 74 69 6d 65 29 22  me,value,mtime)"
ac20: 0a 20 20 20 20 20 20 20 20 20 20 20 22 56 41 4c  .           "VAL
ac30: 55 45 53 28 27 62 61 73 65 75 72 6c 3a 25 71 27  UES('baseurl:%q'
ac40: 2c 31 2c 6e 6f 77 28 29 29 22 2c 20 67 2e 7a 42  ,1,now())", g.zB
ac50: 61 73 65 55 52 4c 0a 20 20 20 20 20 20 29 3b 0a  aseURL.      );.
ac60: 20 20 20 20 7d 0a 20 20 7d 0a 7d 0a 0a 2f 2a 0a      }.  }.}../*.
ac70: 2a 2a 20 53 65 6e 64 20 61 6e 20 48 54 54 50 20  ** Send an HTTP 
ac80: 72 65 64 69 72 65 63 74 20 62 61 63 6b 20 74 6f  redirect back to
ac90: 20 74 68 65 20 64 65 73 69 67 6e 61 74 65 64 20   the designated 
aca0: 49 6e 64 65 78 20 50 61 67 65 2e 0a 2a 2f 0a 4e  Index Page..*/.N
acb0: 4f 52 45 54 55 52 4e 20 76 6f 69 64 20 66 6f 73  ORETURN void fos
acc0: 73 69 6c 5f 72 65 64 69 72 65 63 74 5f 68 6f 6d  sil_redirect_hom
acd0: 65 28 76 6f 69 64 29 7b 0a 20 20 63 67 69 5f 72  e(void){.  cgi_r
ace0: 65 64 69 72 65 63 74 66 28 22 25 73 25 73 22 2c  edirectf("%s%s",
acf0: 20 67 2e 7a 54 6f 70 2c 20 64 62 5f 67 65 74 28   g.zTop, db_get(
ad00: 22 69 6e 64 65 78 2d 70 61 67 65 22 2c 20 22 2f  "index-page", "/
ad10: 69 6e 64 65 78 22 29 29 3b 0a 7d 0a 0a 2f 2a 0a  index"));.}../*.
ad20: 2a 2a 20 49 66 20 72 75 6e 6e 69 6e 67 20 61 73  ** If running as
ad30: 20 72 6f 6f 74 2c 20 63 68 72 6f 6f 74 20 74 6f   root, chroot to
ad40: 20 74 68 65 20 64 69 72 65 63 74 6f 72 79 20 63   the directory c
ad50: 6f 6e 74 61 69 6e 69 6e 67 20 74 68 65 0a 2a 2a  ontaining the.**
ad60: 20 72 65 70 6f 73 69 74 6f 72 79 20 7a 52 65 70   repository zRep
ad70: 6f 20 61 6e 64 20 74 68 65 6e 20 64 72 6f 70 20  o and then drop 
ad80: 72 6f 6f 74 20 70 72 69 76 69 6c 65 67 65 73 2e  root privileges.
ad90: 20 20 52 65 74 75 72 6e 20 74 68 65 0a 2a 2a 20    Return the.** 
ada0: 6e 65 77 20 72 65 70 6f 73 69 74 6f 72 79 20 6e  new repository n
adb0: 61 6d 65 2e 0a 2a 2a 0a 2a 2a 20 7a 52 65 70 6f  ame..**.** zRepo
adc0: 20 6d 69 67 68 74 20 62 65 20 61 20 64 69 72 65   might be a dire
add0: 63 74 6f 72 79 20 69 74 73 65 6c 66 2e 20 20 49  ctory itself.  I
ade0: 6e 20 74 68 61 74 20 63 61 73 65 20 63 68 72 6f  n that case chro
adf0: 6f 74 20 69 6e 74 6f 0a 2a 2a 20 74 68 65 20 64  ot into.** the d
ae00: 69 72 65 63 74 6f 72 79 20 7a 52 65 70 6f 2e 0a  irectory zRepo..
ae10: 2a 2a 0a 2a 2a 20 41 73 73 75 6d 65 20 74 68 65  **.** Assume the
ae20: 20 75 73 65 72 2d 69 64 20 61 6e 64 20 67 72 6f   user-id and gro
ae30: 75 70 2d 69 64 20 6f 66 20 74 68 65 20 72 65 70  up-id of the rep
ae40: 6f 73 69 74 6f 72 79 2c 20 6f 72 20 69 66 20 7a  ository, or if z
ae50: 52 65 70 6f 0a 2a 2a 20 69 73 20 61 20 64 69 72  Repo.** is a dir
ae60: 65 63 74 6f 72 79 2c 20 6f 66 20 74 68 61 74 20  ectory, of that 
ae70: 64 69 72 65 63 74 6f 72 79 2e 0a 2a 2a 0a 2a 2a  directory..**.**
ae80: 20 54 68 65 20 6e 6f 4a 61 69 6c 20 66 6c 61 67   The noJail flag
ae90: 20 6d 65 61 6e 73 20 74 68 61 74 20 74 68 65 20   means that the 
aea0: 63 68 72 6f 6f 74 20 6a 61 69 6c 20 69 73 20 6e  chroot jail is n
aeb0: 6f 74 20 65 6e 74 65 72 65 64 2e 20 20 42 75 74  ot entered.  But
aec0: 0a 2a 2a 20 70 72 69 76 69 6c 65 67 65 73 20 61  .** privileges a
aed0: 72 65 20 73 74 69 6c 6c 20 6c 6f 77 65 72 65 64  re still lowered
aee0: 20 74 6f 20 74 68 61 74 20 6f 66 20 74 68 65 20   to that of the 
aef0: 75 73 65 72 2d 69 64 20 61 6e 64 20 67 72 6f 75  user-id and grou
af00: 70 2d 69 64 0a 2a 2a 20 6f 66 20 74 68 65 20 72  p-id.** of the r
af10: 65 70 6f 73 69 74 6f 72 79 20 66 69 6c 65 2e 0a  epository file..
af20: 2a 2f 0a 63 68 61 72 20 2a 65 6e 74 65 72 5f 63  */.char *enter_c
af30: 68 72 6f 6f 74 5f 6a 61 69 6c 28 63 68 61 72 20  hroot_jail(char 
af40: 2a 7a 52 65 70 6f 2c 20 69 6e 74 20 6e 6f 4a 61  *zRepo, int noJa
af50: 69 6c 29 7b 0a 23 69 66 20 21 64 65 66 69 6e 65  il){.#if !define
af60: 64 28 5f 57 49 4e 33 32 29 0a 20 20 69 66 28 20  d(_WIN32).  if( 
af70: 67 65 74 75 69 64 28 29 3d 3d 30 20 29 7b 0a 20  getuid()==0 ){. 
af80: 20 20 20 69 6e 74 20 69 3b 0a 20 20 20 20 73 74     int i;.    st
af90: 72 75 63 74 20 73 74 61 74 20 73 53 74 61 74 3b  ruct stat sStat;
afa0: 0a 20 20 20 20 42 6c 6f 62 20 64 69 72 3b 0a 20  .    Blob dir;. 
afb0: 20 20 20 63 68 61 72 20 2a 7a 44 69 72 3b 0a 20     char *zDir;. 
afc0: 20 20 20 69 66 28 20 67 2e 64 62 21 3d 30 20 29     if( g.db!=0 )
afd0: 7b 0a 20 20 20 20 20 20 64 62 5f 63 6c 6f 73 65  {.      db_close
afe0: 28 31 29 3b 0a 20 20 20 20 7d 0a 0a 20 20 20 20  (1);.    }..    
aff0: 66 69 6c 65 5f 63 61 6e 6f 6e 69 63 61 6c 5f 6e  file_canonical_n
b000: 61 6d 65 28 7a 52 65 70 6f 2c 20 26 64 69 72 2c  ame(zRepo, &dir,
b010: 20 30 29 3b 0a 20 20 20 20 7a 44 69 72 20 3d 20   0);.    zDir = 
b020: 62 6c 6f 62 5f 73 74 72 28 26 64 69 72 29 3b 0a  blob_str(&dir);.
b030: 20 20 20 20 69 66 28 20 21 6e 6f 4a 61 69 6c 20      if( !noJail 
b040: 29 7b 0a 20 20 20 20 20 20 69 66 28 20 66 69 6c  ){.      if( fil
b050: 65 5f 69 73 64 69 72 28 7a 44 69 72 2c 20 45 78  e_isdir(zDir, Ex
b060: 74 46 49 4c 45 29 3d 3d 31 20 29 7b 0a 20 20 20  tFILE)==1 ){.   
b070: 20 20 20 20 20 69 66 28 20 66 69 6c 65 5f 63 68       if( file_ch
b080: 64 69 72 28 7a 44 69 72 2c 20 31 29 20 29 7b 0a  dir(zDir, 1) ){.
b090: 20 20 20 20 20 20 20 20 20 20 66 6f 73 73 69 6c            fossil
b0a0: 5f 70 61 6e 69 63 28 22 75 6e 61 62 6c 65 20 74  _panic("unable t
b0b0: 6f 20 63 68 72 6f 6f 74 20 69 6e 74 6f 20 25 73  o chroot into %s
b0c0: 22 2c 20 7a 44 69 72 29 3b 0a 20 20 20 20 20 20  ", zDir);.      
b0d0: 20 20 7d 0a 20 20 20 20 20 20 20 20 67 2e 66 4a    }.        g.fJ
b0e0: 61 69 6c 20 3d 20 31 3b 0a 20 20 20 20 20 20 20  ail = 1;.       
b0f0: 20 7a 52 65 70 6f 20 3d 20 22 2f 22 3b 0a 20 20   zRepo = "/";.  
b100: 20 20 20 20 7d 65 6c 73 65 7b 0a 20 20 20 20 20      }else{.     
b110: 20 20 20 66 6f 72 28 69 3d 73 74 72 6c 65 6e 28     for(i=strlen(
b120: 7a 44 69 72 29 2d 31 3b 20 69 3e 30 20 26 26 20  zDir)-1; i>0 && 
b130: 7a 44 69 72 5b 69 5d 21 3d 27 2f 27 3b 20 69 2d  zDir[i]!='/'; i-
b140: 2d 29 7b 7d 0a 20 20 20 20 20 20 20 20 69 66 28  -){}.        if(
b150: 20 7a 44 69 72 5b 69 5d 21 3d 27 2f 27 20 29 20   zDir[i]!='/' ) 
b160: 66 6f 73 73 69 6c 5f 70 61 6e 69 63 28 22 62 61  fossil_panic("ba
b170: 64 20 72 65 70 6f 73 69 74 6f 72 79 20 6e 61 6d  d repository nam
b180: 65 3a 20 25 73 22 2c 20 7a 52 65 70 6f 29 3b 0a  e: %s", zRepo);.
b190: 20 20 20 20 20 20 20 20 69 66 28 20 69 3e 30 20          if( i>0 
b1a0: 29 7b 0a 20 20 20 20 20 20 20 20 20 20 7a 44 69  ){.          zDi
b1b0: 72 5b 69 5d 20 3d 20 30 3b 0a 20 20 20 20 20 20  r[i] = 0;.      
b1c0: 20 20 20 20 69 66 28 20 66 69 6c 65 5f 63 68 64      if( file_chd
b1d0: 69 72 28 7a 44 69 72 2c 20 31 29 20 29 7b 0a 20  ir(zDir, 1) ){. 
b1e0: 20 20 20 20 20 20 20 20 20 20 20 66 6f 73 73 69             fossi
b1f0: 6c 5f 70 61 6e 69 63 28 22 75 6e 61 62 6c 65 20  l_panic("unable 
b200: 74 6f 20 63 68 72 6f 6f 74 20 69 6e 74 6f 20 25  to chroot into %
b210: 73 22 2c 20 7a 44 69 72 29 3b 0a 20 20 20 20 20  s", zDir);.     
b220: 20 20 20 20 20 7d 0a 20 20 20 20 20 20 20 20 20       }.         
b230: 20 7a 44 69 72 5b 69 5d 20 3d 20 27 2f 27 3b 0a   zDir[i] = '/';.
b240: 20 20 20 20 20 20 20 20 7d 0a 20 20 20 20 20 20          }.      
b250: 20 20 7a 52 65 70 6f 20 3d 20 26 7a 44 69 72 5b    zRepo = &zDir[
b260: 69 5d 3b 0a 20 20 20 20 20 20 7d 0a 20 20 20 20  i];.      }.    
b270: 7d 0a 20 20 20 20 69 66 28 20 73 74 61 74 28 7a  }.    if( stat(z
b280: 52 65 70 6f 2c 20 26 73 53 74 61 74 29 21 3d 30  Repo, &sStat)!=0
b290: 20 29 7b 0a 20 20 20 20 20 20 66 6f 73 73 69 6c   ){.      fossil
b2a0: 5f 66 61 74 61 6c 28 22 63 61 6e 6e 6f 74 20 73  _fatal("cannot s
b2b0: 74 61 74 28 29 20 72 65 70 6f 73 69 74 6f 72 79  tat() repository
b2c0: 3a 20 25 73 22 2c 20 7a 52 65 70 6f 29 3b 0a 20  : %s", zRepo);. 
b2d0: 20 20 20 7d 0a 20 20 20 20 69 20 3d 20 73 65 74     }.    i = set
b2e0: 67 69 64 28 73 53 74 61 74 2e 73 74 5f 67 69 64  gid(sStat.st_gid
b2f0: 29 3b 0a 20 20 20 20 69 20 3d 20 69 20 7c 7c 20  );.    i = i || 
b300: 73 65 74 75 69 64 28 73 53 74 61 74 2e 73 74 5f  setuid(sStat.st_
b310: 75 69 64 29 3b 0a 20 20 20 20 69 66 28 69 29 7b  uid);.    if(i){
b320: 0a 20 20 20 20 20 20 66 6f 73 73 69 6c 5f 66 61  .      fossil_fa
b330: 74 61 6c 28 22 73 65 74 67 69 64 2f 75 69 64 28  tal("setgid/uid(
b340: 29 20 66 61 69 6c 65 64 20 77 69 74 68 20 65 72  ) failed with er
b350: 72 6e 6f 20 25 64 22 2c 20 65 72 72 6e 6f 29 3b  rno %d", errno);
b360: 0a 20 20 20 20 7d 0a 20 20 20 20 69 66 28 20 67  .    }.    if( g
b370: 2e 64 62 3d 3d 30 20 26 26 20 66 69 6c 65 5f 69  .db==0 && file_i
b380: 73 66 69 6c 65 28 7a 52 65 70 6f 2c 20 45 78 74  sfile(zRepo, Ext
b390: 46 49 4c 45 29 20 29 7b 0a 20 20 20 20 20 20 64  FILE) ){.      d
b3a0: 62 5f 6f 70 65 6e 5f 72 65 70 6f 73 69 74 6f 72  b_open_repositor
b3b0: 79 28 7a 52 65 70 6f 29 3b 0a 20 20 20 20 7d 0a  y(zRepo);.    }.
b3c0: 20 20 7d 0a 23 65 6e 64 69 66 0a 20 20 72 65 74    }.#endif.  ret
b3d0: 75 72 6e 20 7a 52 65 70 6f 3b 0a 7d 0a 0a 2f 2a  urn zRepo;.}../*
b3e0: 0a 2a 2a 20 43 61 6c 6c 65 64 20 77 68 65 6e 65  .** Called whene
b3f0: 76 65 72 20 61 20 63 72 61 73 68 20 69 73 20 65  ver a crash is e
b400: 6e 63 6f 75 6e 74 65 72 65 64 20 77 68 69 6c 65  ncountered while
b410: 20 70 72 6f 63 65 73 73 69 6e 67 20 61 20 77 65   processing a we
b420: 62 70 61 67 65 2e 0a 2a 2f 0a 76 6f 69 64 20 73  bpage..*/.void s
b430: 69 67 73 65 67 76 5f 68 61 6e 64 6c 65 72 28 69  igsegv_handler(i
b440: 6e 74 20 78 29 7b 0a 23 69 66 20 48 41 56 45 5f  nt x){.#if HAVE_
b450: 42 41 43 4b 54 52 41 43 45 0a 20 20 76 6f 69 64  BACKTRACE.  void
b460: 20 2a 61 72 72 61 79 5b 32 30 5d 3b 0a 20 20 73   *array[20];.  s
b470: 69 7a 65 5f 74 20 73 69 7a 65 3b 0a 20 20 63 68  ize_t size;.  ch
b480: 61 72 20 2a 2a 73 74 72 69 6e 67 73 3b 0a 20 20  ar **strings;.  
b490: 73 69 7a 65 5f 74 20 69 3b 0a 20 20 42 6c 6f 62  size_t i;.  Blob
b4a0: 20 6f 75 74 3b 0a 20 20 73 69 7a 65 20 3d 20 62   out;.  size = b
b4b0: 61 63 6b 74 72 61 63 65 28 61 72 72 61 79 2c 20  acktrace(array, 
b4c0: 73 69 7a 65 6f 66 28 61 72 72 61 79 29 2f 73 69  sizeof(array)/si
b4d0: 7a 65 6f 66 28 61 72 72 61 79 5b 30 5d 29 29 3b  zeof(array[0]));
b4e0: 0a 20 20 73 74 72 69 6e 67 73 20 3d 20 62 61 63  .  strings = bac
b4f0: 6b 74 72 61 63 65 5f 73 79 6d 62 6f 6c 73 28 61  ktrace_symbols(a
b500: 72 72 61 79 2c 20 73 69 7a 65 29 3b 0a 20 20 62  rray, size);.  b
b510: 6c 6f 62 5f 69 6e 69 74 28 26 6f 75 74 2c 20 30  lob_init(&out, 0
b520: 2c 20 30 29 3b 0a 20 20 62 6c 6f 62 5f 61 70 70  , 0);.  blob_app
b530: 65 6e 64 66 28 26 6f 75 74 2c 20 22 53 65 67 66  endf(&out, "Segf
b540: 61 75 6c 74 22 29 3b 0a 20 20 66 6f 72 28 69 3d  ault");.  for(i=
b550: 30 3b 20 69 3c 73 69 7a 65 3b 20 69 2b 2b 29 7b  0; i<size; i++){
b560: 0a 20 20 20 20 62 6c 6f 62 5f 61 70 70 65 6e 64  .    blob_append
b570: 66 28 26 6f 75 74 2c 20 22 5c 6e 28 25 64 29 20  f(&out, "\n(%d) 
b580: 25 73 22 2c 20 69 2c 20 73 74 72 69 6e 67 73 5b  %s", i, strings[
b590: 69 5d 29 3b 0a 20 20 7d 0a 20 20 66 6f 73 73 69  i]);.  }.  fossi
b5a0: 6c 5f 70 61 6e 69 63 28 22 25 73 22 2c 20 62 6c  l_panic("%s", bl
b5b0: 6f 62 5f 73 74 72 28 26 6f 75 74 29 29 3b 0a 23  ob_str(&out));.#
b5c0: 65 6c 73 65 0a 20 20 66 6f 73 73 69 6c 5f 70 61  else.  fossil_pa
b5d0: 6e 69 63 28 22 53 65 67 66 61 75 6c 74 22 29 3b  nic("Segfault");
b5e0: 0a 23 65 6e 64 69 66 0a 20 20 65 78 69 74 28 31  .#endif.  exit(1
b5f0: 29 3b 0a 7d 0a 0a 2f 2a 0a 2a 2a 20 43 61 6c 6c  );.}../*.** Call
b600: 65 64 20 69 66 20 61 20 73 65 72 76 65 72 20 67  ed if a server g
b610: 65 74 73 20 61 20 53 49 47 50 49 50 45 2e 20 20  ets a SIGPIPE.  
b620: 54 68 69 73 20 6f 66 74 65 6e 20 68 61 70 70 65  This often happe
b630: 6e 73 20 77 68 65 6e 20 61 20 63 6c 69 65 6e 74  ns when a client
b640: 0a 2a 2a 20 77 65 62 62 72 6f 77 73 65 72 20 6f  .** webbrowser o
b650: 70 65 6e 73 20 61 20 63 6f 6e 6e 65 63 74 69 6f  pens a connectio
b660: 6e 20 62 75 74 20 6e 65 76 65 72 20 73 65 6e 64  n but never send
b670: 73 20 74 68 65 20 48 54 54 50 20 72 65 71 75 65  s the HTTP reque
b680: 73 74 0a 2a 2f 0a 76 6f 69 64 20 73 69 67 70 69  st.*/.void sigpi
b690: 70 65 5f 68 61 6e 64 6c 65 72 28 69 6e 74 20 78  pe_handler(int x
b6a0: 29 7b 0a 23 69 66 6e 64 65 66 20 5f 57 49 4e 33  ){.#ifndef _WIN3
b6b0: 32 0a 20 20 69 66 28 20 67 2e 66 41 6e 79 54 72  2.  if( g.fAnyTr
b6c0: 61 63 65 20 29 7b 0a 20 20 20 20 66 70 72 69 6e  ace ){.    fprin
b6d0: 74 66 28 73 74 64 65 72 72 2c 22 2f 2a 2a 2a 2a  tf(stderr,"/****
b6e0: 2a 20 73 69 67 70 69 70 65 20 72 65 63 65 69 76  * sigpipe receiv
b6f0: 65 64 20 62 79 20 73 75 62 70 72 6f 63 65 73 73  ed by subprocess
b700: 20 25 64 20 2a 2a 2a 2a 5c 6e 22 2c 20 67 65 74   %d ****\n", get
b710: 70 69 64 28 29 29 3b 0a 20 20 7d 0a 23 65 6e 64  pid());.  }.#end
b720: 69 66 0a 20 20 64 62 5f 70 61 6e 69 63 5f 63 6c  if.  db_panic_cl
b730: 6f 73 65 28 29 3b 0a 20 20 65 78 69 74 28 31 29  ose();.  exit(1)
b740: 3b 0a 7d 0a 0a 2f 2a 0a 2a 2a 20 52 65 74 75 72  ;.}../*.** Retur
b750: 6e 20 74 72 75 65 20 69 66 20 69 74 20 69 73 20  n true if it is 
b760: 61 70 70 72 6f 70 72 69 61 74 65 20 74 6f 20 72  appropriate to r
b770: 65 64 69 72 65 63 74 20 72 65 71 75 65 73 74 73  edirect requests
b780: 20 74 6f 20 48 54 54 50 53 2e 0a 2a 2a 0a 2a 2a   to HTTPS..**.**
b790: 20 52 65 64 69 72 65 63 74 20 74 6f 20 68 74 74   Redirect to htt
b7a0: 70 73 20 69 73 20 61 70 70 72 6f 70 72 69 61 74  ps is appropriat
b7b0: 65 20 69 66 20 61 6c 6c 20 6f 66 20 74 68 65 20  e if all of the 
b7c0: 61 62 6f 76 65 20 61 72 65 20 74 72 75 65 3a 0a  above are true:.
b7d0: 2a 2a 20 20 20 20 28 31 29 20 54 68 65 20 72 65  **    (1) The re
b7e0: 64 69 72 65 63 74 2d 74 6f 2d 68 74 74 70 73 20  direct-to-https 
b7f0: 66 6c 61 67 20 68 61 73 20 61 20 76 61 6c 75 64  flag has a valud
b800: 20 6f 66 20 69 4c 65 76 65 6c 20 6f 72 20 67 72   of iLevel or gr
b810: 65 61 74 65 72 2e 0a 2a 2a 20 20 20 20 28 32 29  eater..**    (2)
b820: 20 54 68 65 20 63 75 72 72 65 6e 74 20 63 6f 6e   The current con
b830: 6e 65 63 74 69 6f 6e 20 69 73 20 68 74 74 70 2c  nection is http,
b840: 20 6e 6f 74 20 68 74 74 70 73 20 6f 72 20 73 73   not https or ss
b850: 68 0a 2a 2a 20 20 20 20 28 33 29 20 54 68 65 20  h.**    (3) The 
b860: 73 73 6c 4e 6f 74 41 76 61 69 6c 61 62 6c 65 20  sslNotAvailable 
b870: 66 6c 61 67 20 69 73 20 63 6c 65 61 72 0a 2a 2f  flag is clear.*/
b880: 0a 69 6e 74 20 66 6f 73 73 69 6c 5f 77 61 6e 74  .int fossil_want
b890: 73 5f 68 74 74 70 73 28 69 6e 74 20 69 4c 65 76  s_https(int iLev
b8a0: 65 6c 29 7b 0a 20 20 69 66 28 20 67 2e 73 73 6c  el){.  if( g.ssl
b8b0: 4e 6f 74 41 76 61 69 6c 61 62 6c 65 20 29 20 72  NotAvailable ) r
b8c0: 65 74 75 72 6e 20 30 3b 0a 20 20 69 66 28 20 64  eturn 0;.  if( d
b8d0: 62 5f 67 65 74 5f 69 6e 74 28 22 72 65 64 69 72  b_get_int("redir
b8e0: 65 63 74 2d 74 6f 2d 68 74 74 70 73 22 2c 30 29  ect-to-https",0)
b8f0: 3c 69 4c 65 76 65 6c 20 29 20 72 65 74 75 72 6e  <iLevel ) return
b900: 20 30 3b 0a 20 20 69 66 28 20 50 28 22 48 54 54   0;.  if( P("HTT
b910: 50 53 22 29 21 3d 30 20 29 20 72 65 74 75 72 6e  PS")!=0 ) return
b920: 20 30 3b 0a 20 20 72 65 74 75 72 6e 20 31 3b 0a   0;.  return 1;.
b930: 7d 0a 0a 2f 2a 0a 2a 2a 20 52 65 64 69 72 65 63  }../*.** Redirec
b940: 74 20 74 6f 20 74 68 65 20 65 71 75 69 76 61 6c  t to the equival
b950: 65 6e 74 20 48 54 54 50 53 20 72 65 71 75 65 73  ent HTTPS reques
b960: 74 20 69 66 20 74 68 65 20 63 75 72 72 65 6e 74  t if the current
b970: 20 63 6f 6e 6e 65 63 74 69 6f 6e 20 69 73 0a 2a   connection is.*
b980: 2a 20 69 6e 73 65 63 75 72 65 20 61 6e 64 20 69  * insecure and i
b990: 66 20 74 68 65 20 72 65 64 69 72 65 63 74 2d 74  f the redirect-t
b9a0: 6f 2d 68 74 74 70 73 20 66 6c 61 67 20 67 72 65  o-https flag gre
b9b0: 61 74 65 72 20 74 68 61 6e 20 6f 72 20 65 71 75  ater than or equ
b9c0: 61 6c 20 74 6f 20 0a 2a 2a 20 69 4c 65 76 65 6c  al to .** iLevel
b9d0: 2e 20 20 69 4c 65 76 65 6c 20 69 73 20 31 20 66  .  iLevel is 1 f
b9e0: 6f 72 20 2f 6c 6f 67 69 6e 20 70 61 67 65 73 20  or /login pages 
b9f0: 61 6e 64 20 32 20 66 6f 72 20 65 76 65 72 79 20  and 2 for every 
ba00: 6f 74 68 65 72 20 70 61 67 65 2e 0a 2a 2f 0a 69  other page..*/.i
ba10: 6e 74 20 66 6f 73 73 69 6c 5f 72 65 64 69 72 65  nt fossil_redire
ba20: 63 74 5f 74 6f 5f 68 74 74 70 73 5f 69 66 5f 6e  ct_to_https_if_n
ba30: 65 65 64 65 64 28 69 6e 74 20 69 4c 65 76 65 6c  eeded(int iLevel
ba40: 29 7b 0a 20 20 69 66 28 20 66 6f 73 73 69 6c 5f  ){.  if( fossil_
ba50: 77 61 6e 74 73 5f 68 74 74 70 73 28 69 4c 65 76  wants_https(iLev
ba60: 65 6c 29 20 29 7b 0a 20 20 20 20 63 6f 6e 73 74  el) ){.    const
ba70: 20 63 68 61 72 20 2a 7a 51 53 20 3d 20 50 28 22   char *zQS = P("
ba80: 51 55 45 52 59 5f 53 54 52 49 4e 47 22 29 3b 0a  QUERY_STRING");.
ba90: 20 20 20 20 63 68 61 72 20 2a 7a 55 52 4c 3b 0a      char *zURL;.
baa0: 20 20 20 20 69 66 28 20 7a 51 53 3d 3d 30 20 7c      if( zQS==0 |
bab0: 7c 20 7a 51 53 5b 30 5d 3d 3d 30 20 29 7b 0a 20  | zQS[0]==0 ){. 
bac0: 20 20 20 20 20 7a 55 52 4c 20 3d 20 6d 70 72 69       zURL = mpri
bad0: 6e 74 66 28 22 25 73 25 54 22 2c 20 67 2e 7a 48  ntf("%s%T", g.zH
bae0: 74 74 70 73 55 52 4c 2c 20 50 28 22 50 41 54 48  ttpsURL, P("PATH
baf0: 5f 49 4e 46 4f 22 29 29 3b 0a 20 20 20 20 7d 65  _INFO"));.    }e
bb00: 6c 73 65 20 69 66 28 20 7a 51 53 5b 30 5d 21 3d  lse if( zQS[0]!=
bb10: 30 20 29 7b 0a 20 20 20 20 20 20 7a 55 52 4c 20  0 ){.      zURL 
bb20: 3d 20 6d 70 72 69 6e 74 66 28 22 25 73 25 54 3f  = mprintf("%s%T?
bb30: 25 73 22 2c 20 67 2e 7a 48 74 74 70 73 55 52 4c  %s", g.zHttpsURL
bb40: 2c 20 50 28 22 50 41 54 48 5f 49 4e 46 4f 22 29  , P("PATH_INFO")
bb50: 2c 20 7a 51 53 29 3b 0a 20 20 20 20 7d 0a 20 20  , zQS);.    }.  
bb60: 20 20 63 67 69 5f 72 65 64 69 72 65 63 74 5f 77    cgi_redirect_w
bb70: 69 74 68 5f 73 74 61 74 75 73 28 7a 55 52 4c 2c  ith_status(zURL,
bb80: 20 33 30 31 2c 20 22 4d 6f 76 65 64 20 50 65 72   301, "Moved Per
bb90: 6d 61 6e 65 6e 74 6c 79 22 29 3b 0a 20 20 20 20  manently");.    
bba0: 72 65 74 75 72 6e 20 31 3b 0a 20 20 7d 0a 20 20  return 1;.  }.  
bbb0: 72 65 74 75 72 6e 20 30 3b 0a 7d 0a 0a 2f 2a 0a  return 0;.}../*.
bbc0: 2a 2a 20 50 72 65 63 6f 6e 64 69 74 69 6f 6e 73  ** Preconditions
bbd0: 3a 0a 2a 2a 0a 2a 2a 20 20 2a 20 45 6e 76 69 72  :.**.**  * Envir
bbe0: 6f 6e 6d 65 6e 74 20 76 61 72 69 61 62 6c 65 73  onment variables
bbf0: 20 61 72 65 20 73 65 74 20 75 70 20 61 63 63 6f   are set up acco
bc00: 72 64 69 6e 67 20 74 6f 20 74 68 65 20 43 47 49  rding to the CGI
bc10: 20 73 74 61 6e 64 61 72 64 2e 0a 2a 2a 0a 2a 2a   standard..**.**
bc20: 20 49 66 20 74 68 65 20 72 65 70 6f 73 69 74 6f   If the reposito
bc30: 72 79 20 69 73 20 6b 6e 6f 77 6e 2c 20 69 74 20  ry is known, it 
bc40: 68 61 73 20 61 6c 72 65 61 64 79 20 62 65 65 6e  has already been
bc50: 20 6f 70 65 6e 65 64 2e 20 20 49 66 20 75 6e 6b   opened.  If unk
bc60: 6e 6f 77 6e 2c 0a 2a 2a 20 74 68 65 6e 20 67 2e  nown,.** then g.
bc70: 7a 52 65 70 6f 73 69 74 6f 72 79 4e 61 6d 65 20  zRepositoryName 
bc80: 68 6f 6c 64 73 20 74 68 65 20 64 69 72 65 63 74  holds the direct
bc90: 6f 72 79 20 74 68 61 74 20 63 6f 6e 74 61 69 6e  ory that contain
bca0: 73 20 74 68 65 20 72 65 70 6f 73 69 74 6f 72 79  s the repository
bcb0: 0a 2a 2a 20 61 6e 64 20 74 68 65 20 61 63 74 75  .** and the actu
bcc0: 61 6c 20 72 65 70 6f 73 69 74 6f 72 79 20 69 73  al repository is
bcd0: 20 74 61 6b 65 6e 20 66 72 6f 6d 20 74 68 65 20   taken from the 
bce0: 66 69 72 73 74 20 65 6c 65 6d 65 6e 74 20 6f 66  first element of
bcf0: 20 50 41 54 48 5f 49 4e 46 4f 2e 0a 2a 2a 0a 2a   PATH_INFO..**.*
bd00: 2a 20 50 72 6f 63 65 73 73 20 74 68 65 20 77 65  * Process the we
bd10: 62 70 61 67 65 20 73 70 65 63 69 66 69 65 64 20  bpage specified 
bd20: 62 79 20 74 68 65 20 50 41 54 48 5f 49 4e 46 4f  by the PATH_INFO
bd30: 20 6f 72 20 52 45 51 55 45 53 54 5f 55 52 49 0a   or REQUEST_URI.
bd40: 2a 2a 20 65 6e 76 69 72 6f 6e 6d 65 6e 74 20 76  ** environment v
bd50: 61 72 69 61 62 6c 65 2e 0a 2a 2a 0a 2a 2a 20 49  ariable..**.** I
bd60: 66 20 74 68 65 20 72 65 70 6f 73 69 74 6f 72 79  f the repository
bd70: 20 69 73 20 6e 6f 74 20 6b 6e 6f 77 6e 2c 20 74   is not known, t
bd80: 68 65 6e 20 61 20 73 65 61 72 63 68 20 69 73 20  hen a search is 
bd90: 64 6f 6e 65 20 74 68 72 6f 75 67 68 20 74 68 65  done through the
bda0: 0a 2a 2a 20 66 69 6c 65 20 68 69 65 72 61 72 63  .** file hierarc
bdb0: 68 79 20 72 6f 6f 74 65 64 20 61 74 20 67 2e 7a  hy rooted at g.z
bdc0: 52 65 70 6f 73 69 74 6f 72 79 4e 61 6d 65 20 66  RepositoryName f
bdd0: 6f 72 20 61 20 73 75 69 74 61 62 6c 65 20 72 65  or a suitable re
bde0: 70 6f 73 69 74 6f 72 79 0a 2a 2a 20 77 69 74 68  pository.** with
bdf0: 20 61 20 6e 61 6d 65 20 6f 66 20 24 70 72 65 66   a name of $pref
be00: 69 78 2e 66 6f 73 73 69 6c 2c 20 77 68 65 72 65  ix.fossil, where
be10: 20 24 70 72 65 66 69 78 20 69 73 20 61 6e 79 20   $prefix is any 
be20: 70 72 65 66 69 78 20 6f 66 20 50 41 54 48 5f 49  prefix of PATH_I
be30: 4e 46 4f 2e 0a 2a 2a 20 4f 72 2c 20 69 66 20 61  NFO..** Or, if a
be40: 6e 20 6f 72 64 69 6e 61 72 79 20 66 69 6c 65 20  n ordinary file 
be50: 6e 61 6d 65 64 20 24 70 72 65 66 69 78 20 69 73  named $prefix is
be60: 20 66 6f 75 6e 64 2c 20 61 6e 64 20 24 70 72 65   found, and $pre
be70: 66 69 78 20 6d 61 74 63 68 65 73 0a 2a 2a 20 70  fix matches.** p
be80: 46 69 6c 65 47 6c 6f 62 20 61 6e 64 20 24 70 72  FileGlob and $pr
be90: 65 66 69 78 20 64 6f 65 73 20 6e 6f 74 20 6d 61  efix does not ma
bea0: 74 63 68 20 22 2a 2e 66 6f 73 73 69 6c 2a 22 20  tch "*.fossil*" 
beb0: 61 6e 64 20 74 68 65 20 6d 69 6d 65 74 79 70 65  and the mimetype
bec0: 20 6f 66 0a 2a 2a 20 24 70 72 65 66 69 78 20 63   of.** $prefix c
bed0: 61 6e 20 62 65 20 64 65 74 65 72 6d 69 6e 65 64  an be determined
bee0: 20 66 72 6f 6d 20 69 74 73 20 73 75 66 66 69 78   from its suffix
bef0: 2c 20 74 68 65 6e 20 74 68 65 20 66 69 6c 65 20  , then the file 
bf00: 24 70 72 65 66 69 78 20 69 73 0a 2a 2a 20 72 65  $prefix is.** re
bf10: 74 75 72 6e 65 64 20 61 73 20 73 74 61 74 69 63  turned as static
bf20: 20 74 65 78 74 2e 0a 2a 2a 0a 2a 2a 20 49 66 20   text..**.** If 
bf30: 6e 6f 20 73 75 69 74 61 62 6c 65 20 77 65 62 70  no suitable webp
bf40: 61 67 65 20 69 73 20 66 6f 75 6e 64 2c 20 74 72  age is found, tr
bf50: 79 20 74 6f 20 72 65 64 69 72 65 63 74 20 74 6f  y to redirect to
bf60: 20 7a 4e 6f 74 46 6f 75 6e 64 2e 0a 2a 2f 0a 73   zNotFound..*/.s
bf70: 74 61 74 69 63 20 76 6f 69 64 20 70 72 6f 63 65  tatic void proce
bf80: 73 73 5f 6f 6e 65 5f 77 65 62 5f 70 61 67 65 28  ss_one_web_page(
bf90: 0a 20 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a  .  const char *z
bfa0: 4e 6f 74 46 6f 75 6e 64 2c 20 20 20 20 20 20 2f  NotFound,      /
bfb0: 2a 20 52 65 64 69 72 65 63 74 20 68 65 72 65 20  * Redirect here 
bfc0: 6f 6e 20 61 20 34 30 34 20 69 66 20 6e 6f 74 20  on a 404 if not 
bfd0: 4e 55 4c 4c 20 2a 2f 0a 20 20 47 6c 6f 62 20 2a  NULL */.  Glob *
bfe0: 70 46 69 6c 65 47 6c 6f 62 2c 20 20 20 20 20 20  pFileGlob,      
bff0: 20 20 20 20 20 20 2f 2a 20 44 65 6c 69 76 65 72        /* Deliver
c000: 20 73 74 61 74 69 63 20 66 69 6c 65 73 20 6d 61   static files ma
c010: 74 63 68 69 6e 67 20 2a 2f 0a 20 20 69 6e 74 20  tching */.  int 
c020: 61 6c 6c 6f 77 52 65 70 6f 4c 69 73 74 20 20 20  allowRepoList   
c030: 20 20 20 20 20 20 20 20 2f 2a 20 53 65 6e 64 20          /* Send 
c040: 72 65 70 6f 20 6c 69 73 74 20 66 6f 72 20 22 2f  repo list for "/
c050: 22 20 55 52 4c 20 2a 2f 0a 29 7b 0a 20 20 63 6f  " URL */.){.  co
c060: 6e 73 74 20 63 68 61 72 20 2a 7a 50 61 74 68 49  nst char *zPathI
c070: 6e 66 6f 20 3d 20 50 44 28 22 50 41 54 48 5f 49  nfo = PD("PATH_I
c080: 4e 46 4f 22 2c 20 22 22 29 3b 0a 20 20 63 68 61  NFO", "");.  cha
c090: 72 20 2a 7a 50 61 74 68 20 3d 20 4e 55 4c 4c 3b  r *zPath = NULL;
c0a0: 0a 20 20 69 6e 74 20 69 3b 0a 20 20 63 6f 6e 73  .  int i;.  cons
c0b0: 74 20 43 6d 64 4f 72 50 61 67 65 20 2a 70 43 6d  t CmdOrPage *pCm
c0c0: 64 20 3d 20 30 3b 0a 20 20 63 6f 6e 73 74 20 63  d = 0;.  const c
c0d0: 68 61 72 20 2a 7a 42 61 73 65 20 3d 20 67 2e 7a  har *zBase = g.z
c0e0: 52 65 70 6f 73 69 74 6f 72 79 4e 61 6d 65 3b 0a  RepositoryName;.
c0f0: 0a 23 69 66 20 21 64 65 66 69 6e 65 64 28 5f 57  .#if !defined(_W
c100: 49 4e 33 32 29 0a 20 20 73 69 67 6e 61 6c 28 53  IN32).  signal(S
c110: 49 47 53 45 47 56 2c 20 73 69 67 73 65 67 76 5f  IGSEGV, sigsegv_
c120: 68 61 6e 64 6c 65 72 29 3b 0a 23 65 6e 64 69 66  handler);.#endif
c130: 0a 0a 20 20 2f 2a 20 48 61 6e 64 6c 65 20 75 6e  ..  /* Handle un
c140: 69 76 65 72 73 61 6c 20 71 75 65 72 79 20 70 61  iversal query pa
c150: 72 61 6d 65 74 65 72 73 20 2a 2f 0a 20 20 69 66  rameters */.  if
c160: 28 20 50 42 28 22 75 74 63 22 29 20 29 7b 0a 20  ( PB("utc") ){. 
c170: 20 20 20 67 2e 66 54 69 6d 65 46 6f 72 6d 61 74     g.fTimeFormat
c180: 20 3d 20 31 3b 0a 20 20 7d 65 6c 73 65 20 69 66   = 1;.  }else if
c190: 28 20 50 42 28 22 6c 6f 63 61 6c 74 69 6d 65 22  ( PB("localtime"
c1a0: 29 20 29 7b 0a 20 20 20 20 67 2e 66 54 69 6d 65  ) ){.    g.fTime
c1b0: 46 6f 72 6d 61 74 20 3d 20 32 3b 0a 20 20 7d 0a  Format = 2;.  }.
c1c0: 0a 20 20 2f 2a 20 49 66 20 74 68 65 20 72 65 70  .  /* If the rep
c1d0: 6f 73 69 74 6f 72 79 20 68 61 73 20 6e 6f 74 20  ository has not 
c1e0: 62 65 65 6e 20 6f 70 65 6e 65 64 20 61 6c 72 65  been opened alre
c1f0: 61 64 79 2c 20 74 68 65 6e 20 66 69 6e 64 20 74  ady, then find t
c200: 68 65 0a 20 20 2a 2a 20 72 65 70 6f 73 69 74 6f  he.  ** reposito
c210: 72 79 20 62 61 73 65 64 20 6f 6e 20 74 68 65 20  ry based on the 
c220: 66 69 72 73 74 20 65 6c 65 6d 65 6e 74 20 6f 66  first element of
c230: 20 50 41 54 48 5f 49 4e 46 4f 20 61 6e 64 20 6f   PATH_INFO and o
c240: 70 65 6e 20 69 74 2e 0a 20 20 2a 2f 0a 20 20 69  pen it..  */.  i
c250: 66 28 20 21 67 2e 72 65 70 6f 73 69 74 6f 72 79  f( !g.repository
c260: 4f 70 65 6e 20 29 7b 0a 20 20 20 20 63 68 61 72  Open ){.    char
c270: 20 2a 7a 52 65 70 6f 3b 20 20 20 20 20 20 20 20   *zRepo;        
c280: 20 20 20 20 20 20 20 2f 2a 20 43 61 6e 64 69 64         /* Candid
c290: 61 74 65 20 72 65 70 6f 73 69 74 6f 72 79 20 6e  ate repository n
c2a0: 61 6d 65 20 2a 2f 0a 20 20 20 20 63 68 61 72 20  ame */.    char 
c2b0: 2a 7a 54 6f 46 72 65 65 20 3d 20 30 3b 20 20 20  *zToFree = 0;   
c2c0: 20 20 20 20 20 20 2f 2a 20 4d 61 6c 6c 6f 63 65        /* Malloce
c2d0: 64 20 6d 65 6d 6f 72 79 20 74 68 61 74 20 6e 65  d memory that ne
c2e0: 65 64 73 20 74 6f 20 62 65 20 66 72 65 65 64 20  eds to be freed 
c2f0: 2a 2f 0a 20 20 20 20 63 6f 6e 73 74 20 63 68 61  */.    const cha
c300: 72 20 2a 7a 43 6c 65 61 6e 52 65 70 6f 3b 20 20  r *zCleanRepo;  
c310: 20 20 2f 2a 20 7a 52 65 70 6f 20 77 69 74 68 20    /* zRepo with 
c320: 73 75 72 70 6c 75 73 20 6c 65 61 64 69 6e 67 20  surplus leading 
c330: 22 2f 22 20 72 65 6d 6f 76 65 64 20 2a 2f 0a 20  "/" removed */. 
c340: 20 20 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a     const char *z
c350: 4f 6c 64 53 63 72 69 70 74 20 3d 20 50 44 28 22  OldScript = PD("
c360: 53 43 52 49 50 54 5f 4e 41 4d 45 22 2c 20 22 22  SCRIPT_NAME", ""
c370: 29 3b 20 20 2f 2a 20 4f 72 69 67 69 6e 61 6c 20  );  /* Original 
c380: 53 43 52 49 50 54 5f 4e 41 4d 45 20 2a 2f 0a 20  SCRIPT_NAME */. 
c390: 20 20 20 63 68 61 72 20 2a 7a 4e 65 77 53 63 72     char *zNewScr
c3a0: 69 70 74 3b 20 20 20 20 20 20 20 20 20 20 2f 2a  ipt;          /*
c3b0: 20 52 65 76 69 73 65 64 20 53 43 52 49 50 54 5f   Revised SCRIPT_
c3c0: 4e 41 4d 45 20 61 66 74 65 72 20 70 72 6f 63 65  NAME after proce
c3d0: 73 73 69 6e 67 20 2a 2f 0a 20 20 20 20 69 6e 74  ssing */.    int
c3e0: 20 6a 2c 20 6b 3b 20 20 20 20 20 20 20 20 20 20   j, k;          
c3f0: 20 20 20 20 20 20 20 20 2f 2a 20 4c 6f 6f 70 20          /* Loop 
c400: 76 61 72 69 61 62 6c 65 73 20 2a 2f 0a 20 20 20  variables */.   
c410: 20 69 36 34 20 73 7a 46 69 6c 65 3b 20 20 20 20   i64 szFile;    
c420: 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 46              /* F
c430: 69 6c 65 20 73 69 7a 65 20 6f 66 20 74 68 65 20  ile size of the 
c440: 63 61 6e 64 69 64 61 74 65 20 72 65 70 6f 73 69  candidate reposi
c450: 74 6f 72 79 20 2a 2f 0a 0a 20 20 20 20 69 20 3d  tory */..    i =
c460: 20 7a 50 61 74 68 49 6e 66 6f 5b 30 5d 21 3d 30   zPathInfo[0]!=0
c470: 3b 0a 20 20 20 20 69 66 28 20 66 6f 73 73 69 6c  ;.    if( fossil
c480: 5f 73 74 72 63 6d 70 28 67 2e 7a 52 65 70 6f 73  _strcmp(g.zRepos
c490: 69 74 6f 72 79 4e 61 6d 65 2c 20 22 2f 22 29 3d  itoryName, "/")=
c4a0: 3d 30 20 29 7b 0a 20 20 20 20 20 20 7a 42 61 73  =0 ){.      zBas
c4b0: 65 2b 2b 3b 0a 23 69 66 20 64 65 66 69 6e 65 64  e++;.#if defined
c4c0: 28 5f 57 49 4e 33 32 29 20 7c 7c 20 64 65 66 69  (_WIN32) || defi
c4d0: 6e 65 64 28 5f 5f 43 59 47 57 49 4e 5f 5f 29 0a  ned(__CYGWIN__).
c4e0: 20 20 20 20 20 20 69 66 28 20 73 71 6c 69 74 65        if( sqlite
c4f0: 33 5f 73 74 72 67 6c 6f 62 28 22 2f 5b 61 2d 7a  3_strglob("/[a-z
c500: 41 2d 5a 5d 3a 2f 2a 22 2c 20 7a 50 61 74 68 49  A-Z]:/*", zPathI
c510: 6e 66 6f 29 3d 3d 30 20 29 20 69 20 3d 20 34 3b  nfo)==0 ) i = 4;
c520: 0a 23 65 6e 64 69 66 0a 20 20 20 20 7d 0a 20 20  .#endif.    }.  
c530: 20 20 77 68 69 6c 65 28 20 31 20 29 7b 0a 20 20    while( 1 ){.  
c540: 20 20 20 20 77 68 69 6c 65 28 20 7a 50 61 74 68      while( zPath
c550: 49 6e 66 6f 5b 69 5d 20 26 26 20 7a 50 61 74 68  Info[i] && zPath
c560: 49 6e 66 6f 5b 69 5d 21 3d 27 2f 27 20 29 7b 20  Info[i]!='/' ){ 
c570: 69 2b 2b 3b 20 7d 0a 0a 20 20 20 20 20 20 2f 2a  i++; }..      /*
c580: 20 54 68 65 20 63 61 6e 64 69 64 61 74 65 20 72   The candidate r
c590: 65 70 6f 73 69 74 6f 72 79 20 6e 61 6d 65 20 69  epository name i
c5a0: 73 20 73 6f 6d 65 20 70 72 65 66 69 78 20 6f 66  s some prefix of
c5b0: 20 74 68 65 20 50 41 54 48 5f 49 4e 46 4f 0a 20   the PATH_INFO. 
c5c0: 20 20 20 20 20 2a 2a 20 77 69 74 68 20 22 2e 66       ** with ".f
c5d0: 6f 73 73 69 6c 22 20 61 70 70 65 6e 64 65 64 20  ossil" appended 
c5e0: 2a 2f 0a 20 20 20 20 20 20 7a 52 65 70 6f 20 3d  */.      zRepo =
c5f0: 20 7a 54 6f 46 72 65 65 20 3d 20 6d 70 72 69 6e   zToFree = mprin
c600: 74 66 28 22 25 73 25 2e 2a 73 2e 66 6f 73 73 69  tf("%s%.*s.fossi
c610: 6c 22 2c 7a 42 61 73 65 2c 69 2c 7a 50 61 74 68  l",zBase,i,zPath
c620: 49 6e 66 6f 29 3b 0a 20 20 20 20 20 20 69 66 28  Info);.      if(
c630: 20 67 2e 66 48 74 74 70 54 72 61 63 65 20 29 7b   g.fHttpTrace ){
c640: 0a 20 20 20 20 20 20 20 20 40 20 3c 21 2d 2d 20  .        @ <!-- 
c650: 4c 6f 6f 6b 69 6e 67 20 66 6f 72 20 72 65 70 6f  Looking for repo
c660: 73 69 74 6f 72 79 20 6e 61 6d 65 64 20 22 25 68  sitory named "%h
c670: 28 7a 52 65 70 6f 29 22 20 2d 2d 3e 0a 20 20 20  (zRepo)" -->.   
c680: 20 20 20 20 20 66 70 72 69 6e 74 66 28 73 74 64       fprintf(std
c690: 65 72 72 2c 20 22 23 20 6c 6f 6f 6b 69 6e 67 20  err, "# looking 
c6a0: 66 6f 72 20 72 65 70 6f 73 69 74 6f 72 79 20 6e  for repository n
c6b0: 61 6d 65 64 20 5c 22 25 73 5c 22 5c 6e 22 2c 20  amed \"%s\"\n", 
c6c0: 7a 52 65 70 6f 29 3b 0a 20 20 20 20 20 20 7d 0a  zRepo);.      }.
c6d0: 0a 0a 20 20 20 20 20 20 2f 2a 20 46 6f 72 20 73  ..      /* For s
c6e0: 61 66 65 74 79 20 2d 2d 20 74 6f 20 70 72 65 76  afety -- to prev
c6f0: 65 6e 74 20 61 6e 20 61 74 74 61 63 6b 65 72 20  ent an attacker 
c700: 66 72 6f 6d 20 61 63 63 65 73 73 69 6e 67 20 61  from accessing a
c710: 72 62 69 74 72 61 72 79 20 64 69 73 6b 0a 20 20  rbitrary disk.  
c720: 20 20 20 20 2a 2a 20 66 69 6c 65 73 20 62 79 20      ** files by 
c730: 73 65 6e 64 69 6e 67 20 61 20 6d 61 6c 69 63 69  sending a malici
c740: 6f 75 73 6c 79 20 63 72 61 66 74 65 64 20 72 65  ously crafted re
c750: 71 75 65 73 74 20 55 52 49 20 74 6f 20 61 20 70  quest URI to a p
c760: 75 62 6c 69 63 0a 20 20 20 20 20 20 2a 2a 20 73  ublic.      ** s
c770: 65 72 76 65 72 20 2d 2d 20 6d 61 6b 65 20 73 75  erver -- make su
c780: 72 65 20 74 68 65 20 72 65 70 6f 73 69 74 6f 72  re the repositor
c790: 79 20 62 61 73 65 6e 61 6d 65 20 63 6f 6e 74 61  y basename conta
c7a0: 69 6e 73 20 6e 6f 0a 20 20 20 20 20 20 2a 2a 20  ins no.      ** 
c7b0: 63 68 61 72 61 63 74 65 72 73 20 6f 74 68 65 72  characters other
c7c0: 20 74 68 61 6e 20 61 6c 70 68 61 6e 75 6d 65 72   than alphanumer
c7d0: 69 63 73 2c 20 22 2f 22 2c 20 22 5f 22 2c 20 22  ics, "/", "_", "
c7e0: 2d 22 2c 20 61 6e 64 20 22 2e 22 2c 20 61 6e 64  -", and ".", and
c7f0: 0a 20 20 20 20 20 20 2a 2a 20 74 68 61 74 20 22  .      ** that "
c800: 2d 22 20 6e 65 76 65 72 20 6f 63 63 75 72 73 20  -" never occurs 
c810: 69 6d 6d 65 64 69 61 74 65 6c 79 20 61 66 74 65  immediately afte
c820: 72 20 61 20 22 2f 22 20 61 6e 64 20 74 68 61 74  r a "/" and that
c830: 20 22 2e 22 20 69 73 20 61 6c 77 61 79 73 0a 20   "." is always. 
c840: 20 20 20 20 20 2a 2a 20 73 75 72 72 6f 75 6e 64       ** surround
c850: 65 64 20 62 79 20 74 77 6f 20 61 6c 70 68 61 6e  ed by two alphan
c860: 75 6d 65 72 69 63 73 2e 20 20 41 6e 79 20 63 68  umerics.  Any ch
c870: 61 72 61 63 74 65 72 20 74 68 61 74 20 64 6f 65  aracter that doe
c880: 73 20 6e 6f 74 0a 20 20 20 20 20 20 2a 2a 20 73  s not.      ** s
c890: 61 74 69 73 66 79 20 74 68 65 73 65 20 63 6f 6e  atisfy these con
c8a0: 73 74 72 61 69 6e 74 73 20 69 73 20 63 6f 6e 76  straints is conv
c8b0: 65 72 74 65 64 20 69 6e 74 6f 20 22 5f 22 2e 0a  erted into "_"..
c8c0: 20 20 20 20 20 20 2a 2f 0a 20 20 20 20 20 20 73        */.      s
c8d0: 7a 46 69 6c 65 20 3d 20 30 3b 0a 20 20 20 20 20  zFile = 0;.     
c8e0: 20 66 6f 72 28 6a 3d 73 74 72 6c 65 6e 28 7a 42   for(j=strlen(zB
c8f0: 61 73 65 29 2b 31 2c 20 6b 3d 30 3b 20 7a 52 65  ase)+1, k=0; zRe
c900: 70 6f 5b 6a 5d 20 26 26 20 6b 3c 69 2d 31 3b 20  po[j] && k<i-1; 
c910: 6a 2b 2b 2c 20 6b 2b 2b 29 7b 0a 20 20 20 20 20  j++, k++){.     
c920: 20 20 20 63 68 61 72 20 63 20 3d 20 7a 52 65 70     char c = zRep
c930: 6f 5b 6a 5d 3b 0a 20 20 20 20 20 20 20 20 69 66  o[j];.        if
c940: 28 20 66 6f 73 73 69 6c 5f 69 73 61 6c 6e 75 6d  ( fossil_isalnum
c950: 28 63 29 20 29 20 63 6f 6e 74 69 6e 75 65 3b 0a  (c) ) continue;.
c960: 23 69 66 20 64 65 66 69 6e 65 64 28 5f 57 49 4e  #if defined(_WIN
c970: 33 32 29 20 7c 7c 20 64 65 66 69 6e 65 64 28 5f  32) || defined(_
c980: 5f 43 59 47 57 49 4e 5f 5f 29 0a 20 20 20 20 20  _CYGWIN__).     
c990: 20 20 20 2f 2a 20 41 6c 6c 6f 77 20 6e 61 6d 65     /* Allow name
c9a0: 73 20 74 6f 20 62 65 67 69 6e 20 77 69 74 68 20  s to begin with 
c9b0: 22 2f 58 3a 2f 22 20 6f 6e 20 77 69 6e 64 6f 77  "/X:/" on window
c9c0: 73 20 2a 2f 0a 20 20 20 20 20 20 20 20 69 66 28  s */.        if(
c9d0: 20 63 3d 3d 27 3a 27 20 26 26 20 6a 3d 3d 32 20   c==':' && j==2 
c9e0: 26 26 20 73 71 6c 69 74 65 33 5f 73 74 72 67 6c  && sqlite3_strgl
c9f0: 6f 62 28 22 2f 5b 61 2d 7a 41 2d 5a 5d 3a 2f 2a  ob("/[a-zA-Z]:/*
ca00: 22 2c 20 7a 52 65 70 6f 29 3d 3d 30 20 29 7b 0a  ", zRepo)==0 ){.
ca10: 20 20 20 20 20 20 20 20 20 20 63 6f 6e 74 69 6e            contin
ca20: 75 65 3b 0a 20 20 20 20 20 20 20 20 7d 0a 23 65  ue;.        }.#e
ca30: 6e 64 69 66 0a 20 20 20 20 20 20 20 20 69 66 28  ndif.        if(
ca40: 20 63 3d 3d 27 2f 27 20 29 20 63 6f 6e 74 69 6e   c=='/' ) contin
ca50: 75 65 3b 0a 20 20 20 20 20 20 20 20 69 66 28 20  ue;.        if( 
ca60: 63 3d 3d 27 5f 27 20 29 20 63 6f 6e 74 69 6e 75  c=='_' ) continu
ca70: 65 3b 0a 20 20 20 20 20 20 20 20 69 66 28 20 63  e;.        if( c
ca80: 3d 3d 27 2d 27 20 26 26 20 7a 52 65 70 6f 5b 6a  =='-' && zRepo[j
ca90: 2d 31 5d 21 3d 27 2f 27 20 29 20 63 6f 6e 74 69  -1]!='/' ) conti
caa0: 6e 75 65 3b 0a 20 20 20 20 20 20 20 20 69 66 28  nue;.        if(
cab0: 20 63 3d 3d 27 2e 27 20 26 26 20 66 6f 73 73 69   c=='.' && fossi
cac0: 6c 5f 69 73 61 6c 6e 75 6d 28 7a 52 65 70 6f 5b  l_isalnum(zRepo[
cad0: 6a 2d 31 5d 29 20 26 26 20 66 6f 73 73 69 6c 5f  j-1]) && fossil_
cae0: 69 73 61 6c 6e 75 6d 28 7a 52 65 70 6f 5b 6a 2b  isalnum(zRepo[j+
caf0: 31 5d 29 29 7b 0a 20 20 20 20 20 20 20 20 20 20  1])){.          
cb00: 63 6f 6e 74 69 6e 75 65 3b 0a 20 20 20 20 20 20  continue;.      
cb10: 20 20 7d 0a 20 20 20 20 20 20 20 20 2f 2a 20 49    }.        /* I
cb20: 66 20 77 65 20 72 65 61 63 68 20 74 68 69 73 20  f we reach this 
cb30: 70 6f 69 6e 74 2c 20 69 74 20 6d 65 61 6e 73 20  point, it means 
cb40: 74 68 61 74 20 74 68 65 20 72 65 71 75 65 73 74  that the request
cb50: 20 55 52 49 20 63 6f 6e 74 61 69 6e 73 0a 20 20   URI contains.  
cb60: 20 20 20 20 20 20 2a 2a 20 61 6e 20 69 6c 6c 65        ** an ille
cb70: 67 61 6c 20 63 68 61 72 61 63 74 65 72 20 6f 72  gal character or
cb80: 20 63 68 61 72 61 63 74 65 72 20 63 6f 6d 62 69   character combi
cb90: 6e 61 74 69 6f 6e 2e 20 20 50 72 6f 76 6f 6b 65  nation.  Provoke
cba0: 20 61 0a 20 20 20 20 20 20 20 20 2a 2a 20 22 4e   a.        ** "N
cbb0: 6f 74 20 46 6f 75 6e 64 22 20 65 72 72 6f 72 2e  ot Found" error.
cbc0: 20 2a 2f 0a 20 20 20 20 20 20 20 20 73 7a 46 69   */.        szFi
cbd0: 6c 65 20 3d 20 31 3b 0a 20 20 20 20 20 20 20 20  le = 1;.        
cbe0: 69 66 28 20 67 2e 66 48 74 74 70 54 72 61 63 65  if( g.fHttpTrace
cbf0: 20 29 7b 0a 20 20 20 20 20 20 20 20 20 20 40 20   ){.          @ 
cc00: 3c 21 2d 2d 20 55 6e 73 61 66 65 20 70 61 74 68  <!-- Unsafe path
cc10: 6e 61 6d 65 20 72 65 6a 65 63 74 65 64 3a 20 22  name rejected: "
cc20: 25 68 28 7a 52 65 70 6f 29 22 20 2d 2d 3e 0a 20  %h(zRepo)" -->. 
cc30: 20 20 20 20 20 20 20 20 20 66 70 72 69 6e 74 66           fprintf
cc40: 28 73 74 64 65 72 72 2c 20 22 23 20 75 6e 73 61  (stderr, "# unsa
cc50: 66 65 20 70 61 74 68 6e 61 6d 65 20 72 65 6a 65  fe pathname reje
cc60: 63 74 65 64 3a 20 25 73 5c 6e 22 2c 20 7a 52 65  cted: %s\n", zRe
cc70: 70 6f 29 3b 0a 20 20 20 20 20 20 20 20 7d 0a 20  po);.        }. 
cc80: 20 20 20 20 20 20 20 62 72 65 61 6b 3b 0a 20 20         break;.  
cc90: 20 20 20 20 7d 0a 0a 20 20 20 20 20 20 2f 2a 20      }..      /* 
cca0: 43 68 65 63 6b 20 74 6f 20 73 65 65 20 69 66 20  Check to see if 
ccb0: 61 20 66 69 6c 65 20 6e 61 6d 65 20 7a 52 65 70  a file name zRep
ccc0: 6f 20 65 78 69 73 74 73 2e 20 20 49 66 20 61 20  o exists.  If a 
ccd0: 66 69 6c 65 20 6e 61 6d 65 64 20 7a 52 65 70 6f  file named zRepo
cce0: 0a 20 20 20 20 20 20 2a 2a 20 64 6f 65 73 20 6e  .      ** does n
ccf0: 6f 74 20 65 78 69 73 74 2c 20 73 7a 46 69 6c 65  ot exist, szFile
cd00: 20 77 69 6c 6c 20 62 65 63 6f 6d 65 20 2d 31 2e   will become -1.
cd10: 20 20 49 66 20 74 68 65 20 66 69 6c 65 20 64 6f    If the file do
cd20: 65 73 20 65 78 69 73 74 2c 0a 20 20 20 20 20 20  es exist,.      
cd30: 2a 2a 20 74 68 65 6e 20 73 7a 46 69 6c 65 20 77  ** then szFile w
cd40: 69 6c 6c 20 62 65 63 6f 6d 65 20 7a 65 72 6f 20  ill become zero 
cd50: 28 66 6f 72 20 61 6e 20 65 6d 70 74 79 20 66 69  (for an empty fi
cd60: 6c 65 29 20 6f 72 20 70 6f 73 69 74 69 76 65 2e  le) or positive.
cd70: 0a 20 20 20 20 20 20 2a 2a 20 53 70 65 63 69 61  .      ** Specia
cd80: 6c 20 63 61 73 65 3a 20 20 41 73 73 75 6d 65 20  l case:  Assume 
cd90: 61 6e 79 20 66 69 6c 65 20 77 69 74 68 20 61 20  any file with a 
cda0: 62 61 73 65 6e 61 6d 65 20 6f 66 20 22 2e 66 6f  basename of ".fo
cdb0: 73 73 69 6c 22 20 64 6f 65 73 0a 20 20 20 20 20  ssil" does.     
cdc0: 20 2a 2a 20 6e 6f 74 20 65 78 69 73 74 2e 0a 20   ** not exist.. 
cdd0: 20 20 20 20 20 2a 2f 0a 20 20 20 20 20 20 7a 43       */.      zC
cde0: 6c 65 61 6e 52 65 70 6f 20 3d 20 66 69 6c 65 5f  leanRepo = file_
cdf0: 63 6c 65 61 6e 75 70 5f 66 75 6c 6c 70 61 74 68  cleanup_fullpath
ce00: 28 7a 52 65 70 6f 29 3b 0a 20 20 20 20 20 20 69  (zRepo);.      i
ce10: 66 28 20 73 7a 46 69 6c 65 3d 3d 30 20 26 26 20  f( szFile==0 && 
ce20: 73 71 6c 69 74 65 33 5f 73 74 72 67 6c 6f 62 28  sqlite3_strglob(
ce30: 22 2a 2f 2e 66 6f 73 73 69 6c 22 2c 7a 52 65 70  "*/.fossil",zRep
ce40: 6f 29 21 3d 30 20 29 7b 0a 20 20 20 20 20 20 20  o)!=0 ){.       
ce50: 20 73 7a 46 69 6c 65 20 3d 20 66 69 6c 65 5f 73   szFile = file_s
ce60: 69 7a 65 28 7a 43 6c 65 61 6e 52 65 70 6f 2c 20  ize(zCleanRepo, 
ce70: 45 78 74 46 49 4c 45 29 3b 0a 20 20 20 20 20 20  ExtFILE);.      
ce80: 20 20 69 66 28 20 67 2e 66 48 74 74 70 54 72 61    if( g.fHttpTra
ce90: 63 65 20 29 7b 0a 20 20 20 20 20 20 20 20 20 20  ce ){.          
cea0: 63 68 61 72 20 7a 42 75 66 5b 32 34 5d 3b 0a 20  char zBuf[24];. 
ceb0: 20 20 20 20 20 20 20 20 20 73 71 6c 69 74 65 33           sqlite3
cec0: 5f 73 6e 70 72 69 6e 74 66 28 73 69 7a 65 6f 66  _snprintf(sizeof
ced0: 28 7a 42 75 66 29 2c 20 7a 42 75 66 2c 20 22 25  (zBuf), zBuf, "%
cee0: 6c 6c 64 22 2c 20 73 7a 46 69 6c 65 29 3b 0a 20  lld", szFile);. 
cef0: 20 20 20 20 20 20 20 20 20 40 20 3c 21 2d 2d 20           @ <!-- 
cf00: 66 69 6c 65 5f 73 69 7a 65 28 25 68 28 7a 43 6c  file_size(%h(zCl
cf10: 65 61 6e 52 65 70 6f 29 29 20 69 73 20 25 73 28  eanRepo)) is %s(
cf20: 7a 42 75 66 29 20 2d 2d 3e 0a 20 20 20 20 20 20  zBuf) -->.      
cf30: 20 20 20 20 66 70 72 69 6e 74 66 28 73 74 64 65      fprintf(stde
cf40: 72 72 2c 20 22 23 20 66 69 6c 65 5f 73 69 7a 65  rr, "# file_size
cf50: 28 25 73 29 20 3d 20 25 73 5c 6e 22 2c 20 7a 43  (%s) = %s\n", zC
cf60: 6c 65 61 6e 52 65 70 6f 2c 20 7a 42 75 66 29 3b  leanRepo, zBuf);
cf70: 0a 20 20 20 20 20 20 20 20 7d 0a 20 20 20 20 20  .        }.     
cf80: 20 7d 0a 0a 20 20 20 20 20 20 2f 2a 20 49 66 20   }..      /* If 
cf90: 6e 6f 20 66 69 6c 65 20 6e 61 6d 65 64 20 62 79  no file named by
cfa0: 20 7a 52 65 70 6f 20 65 78 69 73 74 73 2c 20 72   zRepo exists, r
cfb0: 65 6d 6f 76 65 20 74 68 65 20 61 64 64 65 64 20  emove the added 
cfc0: 22 2e 66 6f 73 73 69 6c 22 20 73 75 66 66 69 78  ".fossil" suffix
cfd0: 0a 20 20 20 20 20 20 2a 2a 20 61 6e 64 20 63 68  .      ** and ch
cfe0: 65 63 6b 20 74 6f 20 73 65 65 20 69 66 20 74 68  eck to see if th
cff0: 65 72 65 20 69 73 20 61 20 66 69 6c 65 20 6f 72  ere is a file or
d000: 20 64 69 72 65 63 74 6f 72 79 20 77 69 74 68 20   directory with 
d010: 74 68 65 20 73 61 6d 65 0a 20 20 20 20 20 20 2a  the same.      *
d020: 2a 20 6e 61 6d 65 20 61 73 20 74 68 65 20 72 61  * name as the ra
d030: 77 20 50 41 54 48 5f 49 4e 46 4f 20 74 65 78 74  w PATH_INFO text
d040: 2e 0a 20 20 20 20 20 20 2a 2f 0a 20 20 20 20 20  ..      */.     
d050: 20 69 66 28 20 73 7a 46 69 6c 65 3c 30 20 26 26   if( szFile<0 &&
d060: 20 69 3e 30 20 29 7b 0a 20 20 20 20 20 20 20 20   i>0 ){.        
d070: 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a 4d 69 6d  const char *zMim
d080: 65 74 79 70 65 3b 0a 20 20 20 20 20 20 20 20 61  etype;.        a
d090: 73 73 65 72 74 28 20 66 6f 73 73 69 6c 5f 73 74  ssert( fossil_st
d0a0: 72 63 6d 70 28 26 7a 52 65 70 6f 5b 6a 5d 2c 20  rcmp(&zRepo[j], 
d0b0: 22 2e 66 6f 73 73 69 6c 22 29 3d 3d 30 20 29 3b  ".fossil")==0 );
d0c0: 0a 20 20 20 20 20 20 20 20 7a 52 65 70 6f 5b 6a  .        zRepo[j
d0d0: 5d 20 3d 20 30 3b 20 20 2f 2a 20 52 65 6d 6f 76  ] = 0;  /* Remov
d0e0: 65 20 74 68 65 20 22 2e 66 6f 73 73 69 6c 22 20  e the ".fossil" 
d0f0: 73 75 66 66 69 78 20 2a 2f 0a 0a 20 20 20 20 20  suffix */..     
d100: 20 20 20 2f 2a 20 54 68 65 20 50 41 54 48 5f 49     /* The PATH_I
d110: 4e 46 4f 20 70 72 65 66 69 78 20 73 65 65 6e 20  NFO prefix seen 
d120: 73 6f 20 66 61 72 20 69 73 20 61 20 76 61 6c 69  so far is a vali
d130: 64 20 64 69 72 65 63 74 6f 72 79 2e 0a 20 20 20  d directory..   
d140: 20 20 20 20 20 2a 2a 20 43 6f 6e 74 69 6e 75 65       ** Continue
d150: 20 74 68 65 20 6c 6f 6f 70 20 77 69 74 68 20 74   the loop with t
d160: 68 65 20 6e 65 78 74 20 65 6c 65 6d 65 6e 74 20  he next element 
d170: 6f 66 20 74 68 65 20 50 41 54 48 5f 49 4e 46 4f  of the PATH_INFO
d180: 20 2a 2f 0a 20 20 20 20 20 20 20 20 69 66 28 20   */.        if( 
d190: 7a 50 61 74 68 49 6e 66 6f 5b 69 5d 3d 3d 27 2f  zPathInfo[i]=='/
d1a0: 27 20 26 26 20 66 69 6c 65 5f 69 73 64 69 72 28  ' && file_isdir(
d1b0: 7a 43 6c 65 61 6e 52 65 70 6f 2c 20 45 78 74 46  zCleanRepo, ExtF
d1c0: 49 4c 45 29 3d 3d 31 20 29 7b 0a 20 20 20 20 20  ILE)==1 ){.     
d1d0: 20 20 20 20 20 66 6f 73 73 69 6c 5f 66 72 65 65       fossil_free
d1e0: 28 7a 54 6f 46 72 65 65 29 3b 0a 20 20 20 20 20  (zToFree);.     
d1f0: 20 20 20 20 20 69 2b 2b 3b 0a 20 20 20 20 20 20       i++;.      
d200: 20 20 20 20 63 6f 6e 74 69 6e 75 65 3b 0a 20 20      continue;.  
d210: 20 20 20 20 20 20 7d 0a 0a 20 20 20 20 20 20 20        }..       
d220: 20 2f 2a 20 49 66 20 7a 52 65 70 6f 20 69 73 20   /* If zRepo is 
d230: 74 68 65 20 6e 61 6d 65 20 6f 66 20 61 6e 20 6f  the name of an o
d240: 72 64 69 6e 61 72 79 20 66 69 6c 65 20 74 68 61  rdinary file tha
d250: 74 20 6d 61 74 63 68 65 73 20 74 68 65 0a 20 20  t matches the.  
d260: 20 20 20 20 20 20 2a 2a 20 22 2d 2d 66 69 6c 65        ** "--file
d270: 20 47 4c 4f 42 22 20 70 61 74 74 65 72 6e 2c 20   GLOB" pattern, 
d280: 74 68 65 6e 20 74 68 65 20 43 47 49 20 72 65 70  then the CGI rep
d290: 6c 79 20 69 73 20 74 68 65 20 74 65 78 74 20 6f  ly is the text o
d2a0: 66 0a 20 20 20 20 20 20 20 20 2a 2a 20 6f 66 20  f.        ** of 
d2b0: 74 68 65 20 66 69 6c 65 2e 0a 20 20 20 20 20 20  the file..      
d2c0: 20 20 2a 2a 0a 20 20 20 20 20 20 20 20 2a 2a 20    **.        ** 
d2d0: 46 6f 72 20 73 61 66 65 74 79 2c 20 64 6f 20 6e  For safety, do n
d2e0: 6f 74 20 61 6c 6c 6f 77 20 61 6e 79 20 66 69 6c  ot allow any fil
d2f0: 65 20 77 68 6f 73 65 20 6e 61 6d 65 20 63 6f 6e  e whose name con
d300: 74 61 69 6e 73 20 22 2e 66 6f 73 73 69 6c 22 0a  tains ".fossil".
d310: 20 20 20 20 20 20 20 20 2a 2a 20 74 6f 20 62 65          ** to be
d320: 20 72 65 74 75 72 6e 65 64 20 74 68 69 73 20 77   returned this w
d330: 61 79 2c 20 74 6f 20 70 72 65 76 65 6e 74 20 63  ay, to prevent c
d340: 6f 6d 70 6c 65 74 65 20 72 65 70 6f 73 69 74 6f  omplete reposito
d350: 72 69 65 73 20 66 72 6f 6d 0a 20 20 20 20 20 20  ries from.      
d360: 20 20 2a 2a 20 62 65 69 6e 67 20 64 65 6c 69 76    ** being deliv
d370: 65 72 65 64 20 61 63 63 69 64 65 6e 74 6c 79 2e  ered accidently.
d380: 20 20 54 68 69 73 20 69 73 20 6e 6f 74 20 69 6e    This is not in
d390: 74 65 6e 64 65 64 20 74 6f 20 62 65 20 61 0a 20  tended to be a. 
d3a0: 20 20 20 20 20 20 20 2a 2a 20 67 65 6e 65 72 61         ** genera
d3b0: 6c 2d 70 75 72 70 6f 73 65 20 77 65 62 20 73 65  l-purpose web se
d3c0: 72 76 65 72 2e 20 20 54 68 65 20 22 2d 2d 66 69  rver.  The "--fi
d3d0: 6c 65 20 47 4c 4f 42 22 20 6d 65 63 68 61 6e 69  le GLOB" mechani
d3e0: 73 6d 20 69 73 0a 20 20 20 20 20 20 20 20 2a 2a  sm is.        **
d3f0: 20 64 65 73 69 67 6e 65 64 20 74 6f 20 61 6c 6c   designed to all
d400: 6f 77 20 74 68 65 20 64 65 6c 69 76 65 72 79 20  ow the delivery 
d410: 6f 66 20 61 20 66 65 77 20 73 74 61 74 69 63 20  of a few static 
d420: 69 6d 61 67 65 73 20 6f 72 20 48 54 4d 4c 0a 20  images or HTML. 
d430: 20 20 20 20 20 20 20 2a 2a 20 70 61 67 65 73 2e         ** pages.
d440: 0a 20 20 20 20 20 20 20 20 2a 2f 0a 20 20 20 20  .        */.    
d450: 20 20 20 20 69 66 28 20 70 46 69 6c 65 47 6c 6f      if( pFileGlo
d460: 62 21 3d 30 0a 20 20 20 20 20 20 20 20 20 26 26  b!=0.         &&
d470: 20 66 69 6c 65 5f 69 73 66 69 6c 65 28 7a 43 6c   file_isfile(zCl
d480: 65 61 6e 52 65 70 6f 2c 20 45 78 74 46 49 4c 45  eanRepo, ExtFILE
d490: 29 0a 20 20 20 20 20 20 20 20 20 26 26 20 67 6c  ).         && gl
d4a0: 6f 62 5f 6d 61 74 63 68 28 70 46 69 6c 65 47 6c  ob_match(pFileGl
d4b0: 6f 62 2c 20 66 69 6c 65 5f 63 6c 65 61 6e 75 70  ob, file_cleanup
d4c0: 5f 66 75 6c 6c 70 61 74 68 28 7a 52 65 70 6f 29  _fullpath(zRepo)
d4d0: 29 0a 20 20 20 20 20 20 20 20 20 26 26 20 73 71  ).         && sq
d4e0: 6c 69 74 65 33 5f 73 74 72 67 6c 6f 62 28 22 2a  lite3_strglob("*
d4f0: 2e 66 6f 73 73 69 6c 2a 22 2c 7a 52 65 70 6f 29  .fossil*",zRepo)
d500: 21 3d 30 0a 20 20 20 20 20 20 20 20 20 26 26 20  !=0.         && 
d510: 28 7a 4d 69 6d 65 74 79 70 65 20 3d 20 6d 69 6d  (zMimetype = mim
d520: 65 74 79 70 65 5f 66 72 6f 6d 5f 6e 61 6d 65 28  etype_from_name(
d530: 7a 52 65 70 6f 29 29 21 3d 30 0a 20 20 20 20 20  zRepo))!=0.     
d540: 20 20 20 20 26 26 20 73 74 72 63 6d 70 28 7a 4d      && strcmp(zM
d550: 69 6d 65 74 79 70 65 2c 20 22 61 70 70 6c 69 63  imetype, "applic
d560: 61 74 69 6f 6e 2f 78 2d 66 6f 73 73 69 6c 2d 61  ation/x-fossil-a
d570: 72 74 69 66 61 63 74 22 29 21 3d 30 0a 20 20 20  rtifact")!=0.   
d580: 20 20 20 20 20 29 7b 0a 20 20 20 20 20 20 20 20       ){.        
d590: 20 20 42 6c 6f 62 20 63 6f 6e 74 65 6e 74 3b 0a    Blob content;.
d5a0: 20 20 20 20 20 20 20 20 20 20 62 6c 6f 62 5f 72            blob_r
d5b0: 65 61 64 5f 66 72 6f 6d 5f 66 69 6c 65 28 26 63  ead_from_file(&c
d5c0: 6f 6e 74 65 6e 74 2c 20 66 69 6c 65 5f 63 6c 65  ontent, file_cle
d5d0: 61 6e 75 70 5f 66 75 6c 6c 70 61 74 68 28 7a 52  anup_fullpath(zR
d5e0: 65 70 6f 29 2c 20 45 78 74 46 49 4c 45 29 3b 0a  epo), ExtFILE);.
d5f0: 20 20 20 20 20 20 20 20 20 20 63 67 69 5f 73 65            cgi_se
d600: 74 5f 63 6f 6e 74 65 6e 74 5f 74 79 70 65 28 7a  t_content_type(z
d610: 4d 69 6d 65 74 79 70 65 29 3b 0a 20 20 20 20 20  Mimetype);.     
d620: 20 20 20 20 20 63 67 69 5f 73 65 74 5f 63 6f 6e       cgi_set_con
d630: 74 65 6e 74 28 26 63 6f 6e 74 65 6e 74 29 3b 0a  tent(&content);.
d640: 20 20 20 20 20 20 20 20 20 20 63 67 69 5f 72 65            cgi_re
d650: 70 6c 79 28 29 3b 0a 20 20 20 20 20 20 20 20 20  ply();.         
d660: 20 72 65 74 75 72 6e 3b 0a 20 20 20 20 20 20 20   return;.       
d670: 20 7d 0a 20 20 20 20 20 20 20 20 7a 52 65 70 6f   }.        zRepo
d680: 5b 6a 5d 20 3d 20 27 2e 27 3b 0a 20 20 20 20 20  [j] = '.';.     
d690: 20 7d 0a 0a 20 20 20 20 20 20 2f 2a 20 49 66 20   }..      /* If 
d6a0: 77 65 20 72 65 61 63 68 20 74 68 69 73 20 70 6f  we reach this po
d6b0: 69 6e 74 2c 20 69 74 20 6d 65 61 6e 73 20 74 68  int, it means th
d6c0: 61 74 20 74 68 65 20 73 65 61 72 63 68 20 6f 66  at the search of
d6d0: 20 74 68 65 20 50 41 54 48 5f 49 4e 46 4f 0a 20   the PATH_INFO. 
d6e0: 20 20 20 20 20 2a 2a 20 73 74 72 69 6e 67 20 69       ** string i
d6f0: 73 20 66 69 6e 69 73 68 65 64 2e 20 20 45 69 74  s finished.  Eit
d700: 68 65 72 20 7a 52 65 70 6f 20 63 6f 6e 74 61 69  her zRepo contai
d710: 6e 73 20 74 68 65 20 6e 61 6d 65 20 6f 66 20 74  ns the name of t
d720: 68 65 0a 20 20 20 20 20 20 2a 2a 20 72 65 70 6f  he.      ** repo
d730: 73 69 74 6f 72 79 20 74 6f 20 62 65 20 75 73 65  sitory to be use
d740: 64 2c 20 6f 72 20 65 6c 73 65 20 6e 6f 20 72 65  d, or else no re
d750: 70 6f 73 69 74 6f 72 79 20 63 6f 75 6c 64 20 62  pository could b
d760: 65 20 66 6f 75 6e 64 20 61 6e 0a 20 20 20 20 20  e found an.     
d770: 20 2a 2a 20 73 6f 6d 65 20 6b 69 6e 64 20 6f 66   ** some kind of
d780: 20 65 72 72 6f 72 20 72 65 73 70 6f 6e 73 65 20   error response 
d790: 69 73 20 72 65 71 75 69 72 65 64 2e 0a 20 20 20  is required..   
d7a0: 20 20 20 2a 2f 0a 20 20 20 20 20 20 69 66 28 20     */.      if( 
d7b0: 73 7a 46 69 6c 65 3c 31 30 32 34 20 29 7b 0a 20  szFile<1024 ){. 
d7c0: 20 20 20 20 20 20 20 73 65 74 5f 62 61 73 65 5f         set_base_
d7d0: 75 72 6c 28 30 29 3b 0a 20 20 20 20 20 20 20 20  url(0);.        
d7e0: 69 66 28 20 73 74 72 63 6d 70 28 7a 50 61 74 68  if( strcmp(zPath
d7f0: 49 6e 66 6f 2c 22 2f 22 29 3d 3d 30 0a 20 20 20  Info,"/")==0.   
d800: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 26                 &
d810: 26 20 61 6c 6c 6f 77 52 65 70 6f 4c 69 73 74 0a  & allowRepoList.
d820: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
d830: 20 20 26 26 20 72 65 70 6f 5f 6c 69 73 74 5f 70    && repo_list_p
d840: 61 67 65 28 29 20 29 7b 0a 20 20 20 20 20 20 20  age() ){.       
d850: 20 20 20 2f 2a 20 57 69 6c 6c 20 72 65 74 75 72     /* Will retur
d860: 6e 20 61 20 6c 69 73 74 20 6f 66 20 72 65 70 6f  n a list of repo
d870: 73 69 74 6f 72 69 65 73 20 2a 2f 0a 20 20 20 20  sitories */.    
d880: 20 20 20 20 7d 65 6c 73 65 20 69 66 28 20 7a 4e      }else if( zN
d890: 6f 74 46 6f 75 6e 64 20 29 7b 0a 20 20 20 20 20  otFound ){.     
d8a0: 20 20 20 20 20 63 67 69 5f 72 65 64 69 72 65 63       cgi_redirec
d8b0: 74 28 7a 4e 6f 74 46 6f 75 6e 64 29 3b 0a 20 20  t(zNotFound);.  
d8c0: 20 20 20 20 20 20 7d 65 6c 73 65 7b 0a 23 69 66        }else{.#if
d8d0: 64 65 66 20 46 4f 53 53 49 4c 5f 45 4e 41 42 4c  def FOSSIL_ENABL
d8e0: 45 5f 4a 53 4f 4e 0a 20 20 20 20 20 20 20 20 20  E_JSON.         
d8f0: 20 69 66 28 67 2e 6a 73 6f 6e 2e 69 73 4a 73 6f   if(g.json.isJso
d900: 6e 4d 6f 64 65 29 7b 0a 20 20 20 20 20 20 20 20  nMode){.        
d910: 20 20 20 20 6a 73 6f 6e 5f 65 72 72 28 46 53 4c      json_err(FSL
d920: 5f 4a 53 4f 4e 5f 45 5f 52 45 53 4f 55 52 43 45  _JSON_E_RESOURCE
d930: 5f 4e 4f 54 5f 46 4f 55 4e 44 2c 4e 55 4c 4c 2c  _NOT_FOUND,NULL,
d940: 31 29 3b 0a 20 20 20 20 20 20 20 20 20 20 20 20  1);.            
d950: 72 65 74 75 72 6e 3b 0a 20 20 20 20 20 20 20 20  return;.        
d960: 20 20 7d 0a 23 65 6e 64 69 66 0a 20 20 20 20 20    }.#endif.     
d970: 20 20 20 20 20 40 20 3c 68 74 6d 6c 3e 3c 68 65       @ <html><he
d980: 61 64 3e 0a 20 20 20 20 20 20 20 20 20 20 40 20  ad>.          @ 
d990: 3c 6d 65 74 61 20 6e 61 6d 65 3d 22 76 69 65 77  <meta name="view
d9a0: 70 6f 72 74 22 20 5c 0a 20 20 20 20 20 20 20 20  port" \.        
d9b0: 20 20 40 20 63 6f 6e 74 65 6e 74 3d 22 77 69 64    @ content="wid
d9c0: 74 68 3d 64 65 76 69 63 65 2d 77 69 64 74 68 2c  th=device-width,
d9d0: 20 69 6e 69 74 69 61 6c 2d 73 63 61 6c 65 3d 31   initial-scale=1
d9e0: 2e 30 22 3e 0a 20 20 20 20 20 20 20 20 20 20 40  .0">.          @
d9f0: 20 3c 2f 68 65 61 64 3e 3c 62 6f 64 79 3e 0a 20   </head><body>. 
da00: 20 20 20 20 20 20 20 20 20 40 20 3c 68 31 3e 4e           @ <h1>N
da10: 6f 74 20 46 6f 75 6e 64 3c 2f 68 31 3e 0a 20 20  ot Found</h1>.  
da20: 20 20 20 20 20 20 20 20 40 20 3c 2f 62 6f 64 79          @ </body
da30: 3e 0a 20 20 20 20 20 20 20 20 20 20 63 67 69 5f  >.          cgi_
da40: 73 65 74 5f 73 74 61 74 75 73 28 34 30 34 2c 20  set_status(404, 
da50: 22 6e 6f 74 20 66 6f 75 6e 64 22 29 3b 0a 20 20  "not found");.  
da60: 20 20 20 20 20 20 20 20 63 67 69 5f 72 65 70 6c          cgi_repl
da70: 79 28 29 3b 0a 20 20 20 20 20 20 20 20 7d 0a 20  y();.        }. 
da80: 20 20 20 20 20 20 20 72 65 74 75 72 6e 3b 0a 20         return;. 
da90: 20 20 20 20 20 7d 0a 20 20 20 20 20 20 62 72 65       }.      bre
daa0: 61 6b 3b 0a 20 20 20 20 7d 0a 0a 20 20 20 20 2f  ak;.    }..    /
dab0: 2a 20 41 64 64 20 74 68 65 20 72 65 70 6f 73 69  * Add the reposi
dac0: 74 6f 72 79 20 6e 61 6d 65 20 28 77 69 74 68 6f  tory name (witho
dad0: 75 74 20 74 68 65 20 22 2e 66 6f 73 73 69 6c 22  ut the ".fossil"
dae0: 20 73 75 66 66 69 78 29 20 74 6f 20 74 68 65 20   suffix) to the 
daf0: 65 6e 64 0a 20 20 20 20 2a 2a 20 6f 66 20 53 43  end.    ** of SC
db00: 52 49 50 54 5f 4e 41 4d 45 20 61 6e 64 20 67 2e  RIPT_NAME and g.
db10: 7a 54 6f 70 20 61 6e 64 20 67 2e 7a 42 61 73 65  zTop and g.zBase
db20: 55 52 4c 20 61 6e 64 20 72 65 6d 6f 76 65 20 74  URL and remove t
db30: 68 65 20 72 65 70 6f 73 69 74 6f 72 79 0a 20 20  he repository.  
db40: 20 20 2a 2a 20 6e 61 6d 65 20 66 72 6f 6d 20 74    ** name from t
db50: 68 65 20 62 65 67 69 6e 6e 69 6e 67 20 6f 66 20  he beginning of 
db60: 50 41 54 48 5f 49 4e 46 4f 2e 0a 20 20 20 20 2a  PATH_INFO..    *
db70: 2f 0a 20 20 20 20 7a 4e 65 77 53 63 72 69 70 74  /.    zNewScript
db80: 20 3d 20 6d 70 72 69 6e 74 66 28 22 25 73 25 2e   = mprintf("%s%.
db90: 2a 73 22 2c 20 7a 4f 6c 64 53 63 72 69 70 74 2c  *s", zOldScript,
dba0: 20 69 2c 20 7a 50 61 74 68 49 6e 66 6f 29 3b 0a   i, zPathInfo);.
dbb0: 20 20 20 20 69 66 28 20 67 2e 7a 54 6f 70 20 29      if( g.zTop )
dbc0: 20 67 2e 7a 54 6f 70 20 3d 20 6d 70 72 69 6e 74   g.zTop = mprint
dbd0: 66 28 22 25 73 25 2e 2a 73 22 2c 20 67 2e 7a 54  f("%s%.*s", g.zT
dbe0: 6f 70 2c 20 69 2c 20 7a 50 61 74 68 49 6e 66 6f  op, i, zPathInfo
dbf0: 29 3b 0a 20 20 20 20 69 66 28 20 67 2e 7a 42 61  );.    if( g.zBa
dc00: 73 65 55 52 4c 20 29 20 67 2e 7a 42 61 73 65 55  seURL ) g.zBaseU
dc10: 52 4c 20 3d 20 6d 70 72 69 6e 74 66 28 22 25 73  RL = mprintf("%s
dc20: 25 2e 2a 73 22 2c 20 67 2e 7a 42 61 73 65 55 52  %.*s", g.zBaseUR
dc30: 4c 2c 20 69 2c 20 7a 50 61 74 68 49 6e 66 6f 29  L, i, zPathInfo)
dc40: 3b 0a 20 20 20 20 63 67 69 5f 72 65 70 6c 61 63  ;.    cgi_replac
dc50: 65 5f 70 61 72 61 6d 65 74 65 72 28 22 50 41 54  e_parameter("PAT
dc60: 48 5f 49 4e 46 4f 22 2c 20 26 7a 50 61 74 68 49  H_INFO", &zPathI
dc70: 6e 66 6f 5b 69 2b 31 5d 29 3b 0a 20 20 20 20 7a  nfo[i+1]);.    z
dc80: 50 61 74 68 49 6e 66 6f 20 2b 3d 20 69 3b 0a 20  PathInfo += i;. 
dc90: 20 20 20 63 67 69 5f 72 65 70 6c 61 63 65 5f 70     cgi_replace_p
dca0: 61 72 61 6d 65 74 65 72 28 22 53 43 52 49 50 54  arameter("SCRIPT
dcb0: 5f 4e 41 4d 45 22 2c 20 7a 4e 65 77 53 63 72 69  _NAME", zNewScri
dcc0: 70 74 29 3b 0a 20 20 20 20 64 62 5f 6f 70 65 6e  pt);.    db_open
dcd0: 5f 72 65 70 6f 73 69 74 6f 72 79 28 66 69 6c 65  _repository(file
dce0: 5f 63 6c 65 61 6e 75 70 5f 66 75 6c 6c 70 61 74  _cleanup_fullpat
dcf0: 68 28 7a 52 65 70 6f 29 29 3b 0a 20 20 20 20 69  h(zRepo));.    i
dd00: 66 28 20 67 2e 66 48 74 74 70 54 72 61 63 65 20  f( g.fHttpTrace 
dd10: 29 7b 0a 20 20 20 20 20 20 40 20 3c 21 2d 2d 20  ){.      @ <!-- 
dd20: 72 65 70 6f 73 69 74 6f 72 79 3a 20 22 25 68 28  repository: "%h(
dd30: 7a 52 65 70 6f 29 22 20 2d 2d 3e 0a 20 20 20 20  zRepo)" -->.    
dd40: 20 20 40 20 3c 21 2d 2d 20 74 72 61 6e 73 6c 61    @ <!-- transla
dd50: 74 65 64 20 50 41 54 48 5f 49 4e 46 4f 3a 20 22  ted PATH_INFO: "
dd60: 25 68 28 7a 50 61 74 68 49 6e 66 6f 29 22 20 2d  %h(zPathInfo)" -
dd70: 2d 3e 0a 20 20 20 20 20 20 40 20 3c 21 2d 2d 20  ->.      @ <!-- 
dd80: 74 72 61 6e 73 6c 61 74 65 64 20 53 43 52 49 50  translated SCRIP
dd90: 54 5f 4e 41 4d 45 3a 20 22 25 68 28 7a 4e 65 77  T_NAME: "%h(zNew
dda0: 53 63 72 69 70 74 29 22 20 2d 2d 3e 0a 20 20 20  Script)" -->.   
ddb0: 20 20 20 66 70 72 69 6e 74 66 28 73 74 64 65 72     fprintf(stder
ddc0: 72 2c 0a 20 20 20 20 20 20 20 20 20 20 22 23 20  r,.          "# 
ddd0: 72 65 70 6f 73 69 74 6f 72 79 3a 20 5b 25 73 5d  repository: [%s]
dde0: 5c 6e 22 0a 20 20 20 20 20 20 20 20 20 20 22 23  \n".          "#
ddf0: 20 74 72 61 6e 73 6c 61 74 65 64 20 50 41 54 48   translated PATH
de00: 5f 49 4e 46 4f 20 3d 20 5b 25 73 5d 5c 6e 22 0a  _INFO = [%s]\n".
de10: 20 20 20 20 20 20 20 20 20 20 22 23 20 74 72 61            "# tra
de20: 6e 73 6c 61 74 65 64 20 53 43 52 49 50 54 5f 4e  nslated SCRIPT_N
de30: 41 4d 45 20 3d 20 5b 25 73 5d 5c 6e 22 2c 0a 20  AME = [%s]\n",. 
de40: 20 20 20 20 20 20 20 20 20 7a 52 65 70 6f 2c 20           zRepo, 
de50: 7a 50 61 74 68 49 6e 66 6f 2c 20 7a 4e 65 77 53  zPathInfo, zNewS
de60: 63 72 69 70 74 29 3b 0a 20 20 20 20 20 20 69 66  cript);.      if
de70: 28 20 67 2e 7a 54 6f 70 20 29 7b 0a 20 20 20 20  ( g.zTop ){.    
de80: 20 20 20 20 40 20 3c 21 2d 2d 20 74 72 61 6e 73      @ <!-- trans
de90: 6c 61 74 65 64 20 67 2e 7a 54 6f 70 3a 20 22 25  lated g.zTop: "%
dea0: 68 28 67 2e 7a 54 6f 70 29 22 20 2d 2d 3e 0a 20  h(g.zTop)" -->. 
deb0: 20 20 20 20 20 20 20 66 70 72 69 6e 74 66 28 73         fprintf(s
dec0: 74 64 65 72 72 2c 20 22 23 20 74 72 61 6e 73 6c  tderr, "# transl
ded0: 61 74 65 64 20 67 2e 7a 54 6f 70 20 3d 20 5b 25  ated g.zTop = [%
dee0: 73 5d 5c 6e 22 2c 20 67 2e 7a 54 6f 70 29 3b 0a  s]\n", g.zTop);.
def0: 20 20 20 20 20 20 7d 0a 20 20 20 20 20 20 69 66        }.      if
df00: 28 20 67 2e 7a 42 61 73 65 55 52 4c 20 29 7b 0a  ( g.zBaseURL ){.
df10: 20 20 20 20 20 20 20 20 40 20 3c 21 2d 2d 20 74          @ <!-- t
df20: 72 61 6e 73 6c 61 74 65 64 20 67 2e 7a 42 61 73  ranslated g.zBas
df30: 65 55 52 4c 3a 20 22 25 68 28 67 2e 7a 42 61 73  eURL: "%h(g.zBas
df40: 65 55 52 4c 29 22 20 2d 2d 3e 0a 20 20 20 20 20  eURL)" -->.     
df50: 20 20 20 66 70 72 69 6e 74 66 28 73 74 64 65 72     fprintf(stder
df60: 72 2c 20 22 23 20 74 72 61 6e 73 6c 61 74 65 64  r, "# translated
df70: 20 67 2e 7a 42 61 73 65 55 52 4c 20 3d 20 5b 25   g.zBaseURL = [%
df80: 73 5d 5c 6e 22 2c 20 67 2e 7a 42 61 73 65 55 52  s]\n", g.zBaseUR
df90: 4c 29 3b 0a 20 20 20 20 20 20 7d 0a 20 20 20 20  L);.      }.    
dfa0: 7d 0a 20 20 7d 0a 0a 20 20 2f 2a 20 41 74 20 74  }.  }..  /* At t
dfb0: 68 69 73 20 70 6f 69 6e 74 2c 20 74 68 65 20 61  his point, the a
dfc0: 70 70 72 6f 70 72 69 61 74 65 20 72 65 70 6f 73  ppropriate repos
dfd0: 69 74 6f 72 79 20 64 61 74 61 62 61 73 65 20 66  itory database f
dfe0: 69 6c 65 20 77 69 6c 6c 20 68 61 76 65 0a 20 20  ile will have.  
dff0: 2a 2a 20 62 65 65 6e 20 6f 70 65 6e 65 64 2e 0a  ** been opened..
e000: 20 20 2a 2a 0a 20 20 2a 2a 20 43 68 65 63 6b 20    **.  ** Check 
e010: 74 6f 20 73 65 65 20 69 66 20 74 68 65 20 74 68  to see if the th
e020: 65 20 50 41 54 48 5f 49 4e 46 4f 20 62 65 67 69  e PATH_INFO begi
e030: 6e 73 20 77 69 74 68 20 22 64 72 61 66 74 5b 31  ns with "draft[1
e040: 2d 39 5d 22 20 61 6e 64 20 69 66 0a 20 20 2a 2a  -9]" and if.  **
e050: 20 73 6f 20 61 63 74 69 76 61 74 65 20 74 68 65   so activate the
e060: 20 73 70 65 63 69 61 6c 20 68 61 6e 64 6c 69 6e   special handlin
e070: 67 20 66 6f 72 20 64 72 61 66 74 20 73 6b 69 6e  g for draft skin
e080: 73 0a 20 20 2a 2f 0a 20 20 69 66 28 20 7a 50 61  s.  */.  if( zPa
e090: 74 68 49 6e 66 6f 20 26 26 20 73 74 72 6e 63 6d  thInfo && strncm
e0a0: 70 28 7a 50 61 74 68 49 6e 66 6f 2c 22 2f 64 72  p(zPathInfo,"/dr
e0b0: 61 66 74 22 2c 36 29 3d 3d 30 0a 20 20 20 26 26  aft",6)==0.   &&
e0c0: 20 7a 50 61 74 68 49 6e 66 6f 5b 36 5d 3e 3d 27   zPathInfo[6]>='
e0d0: 31 27 20 26 26 20 7a 50 61 74 68 49 6e 66 6f 5b  1' && zPathInfo[
e0e0: 36 5d 3c 3d 27 39 27 0a 20 20 20 26 26 20 28 7a  6]<='9'.   && (z
e0f0: 50 61 74 68 49 6e 66 6f 5b 37 5d 3d 3d 27 2f 27  PathInfo[7]=='/'
e100: 20 7c 7c 20 7a 50 61 74 68 49 6e 66 6f 5b 37 5d   || zPathInfo[7]
e110: 3d 3d 30 29 0a 20 20 29 7b 0a 20 20 20 20 69 6e  ==0).  ){.    in
e120: 74 20 69 53 6b 69 6e 20 3d 20 7a 50 61 74 68 49  t iSkin = zPathI
e130: 6e 66 6f 5b 36 5d 20 2d 20 27 30 27 3b 0a 20 20  nfo[6] - '0';.  
e140: 20 20 63 68 61 72 20 2a 7a 4e 65 77 53 63 72 69    char *zNewScri
e150: 70 74 3b 0a 20 20 20 20 73 6b 69 6e 5f 75 73 65  pt;.    skin_use
e160: 5f 64 72 61 66 74 28 69 53 6b 69 6e 29 3b 0a 20  _draft(iSkin);. 
e170: 20 20 20 7a 4e 65 77 53 63 72 69 70 74 20 3d 20     zNewScript = 
e180: 6d 70 72 69 6e 74 66 28 22 25 54 2f 64 72 61 66  mprintf("%T/draf
e190: 74 25 64 22 2c 20 50 28 22 53 43 52 49 50 54 5f  t%d", P("SCRIPT_
e1a0: 4e 41 4d 45 22 29 2c 20 69 53 6b 69 6e 29 3b 0a  NAME"), iSkin);.
e1b0: 20 20 20 20 69 66 28 20 67 2e 7a 54 6f 70 20 29      if( g.zTop )
e1c0: 20 67 2e 7a 54 6f 70 20 3d 20 6d 70 72 69 6e 74   g.zTop = mprint
e1d0: 66 28 22 25 73 2f 64 72 61 66 74 25 64 22 2c 20  f("%s/draft%d", 
e1e0: 67 2e 7a 54 6f 70 2c 20 69 53 6b 69 6e 29 3b 0a  g.zTop, iSkin);.
e1f0: 20 20 20 20 69 66 28 20 67 2e 7a 42 61 73 65 55      if( g.zBaseU
e200: 52 4c 20 29 20 67 2e 7a 42 61 73 65 55 52 4c 20  RL ) g.zBaseURL 
e210: 3d 20 6d 70 72 69 6e 74 66 28 22 25 73 2f 64 72  = mprintf("%s/dr
e220: 61 66 74 25 64 22 2c 20 67 2e 7a 42 61 73 65 55  aft%d", g.zBaseU
e230: 52 4c 2c 20 69 53 6b 69 6e 29 3b 0a 20 20 20 20  RL, iSkin);.    
e240: 7a 50 61 74 68 49 6e 66 6f 20 2b 3d 20 37 3b 0a  zPathInfo += 7;.
e250: 20 20 20 20 63 67 69 5f 72 65 70 6c 61 63 65 5f      cgi_replace_
e260: 70 61 72 61 6d 65 74 65 72 28 22 50 41 54 48 5f  parameter("PATH_
e270: 49 4e 46 4f 22 2c 20 7a 50 61 74 68 49 6e 66 6f  INFO", zPathInfo
e280: 29 3b 0a 20 20 20 20 63 67 69 5f 72 65 70 6c 61  );.    cgi_repla
e290: 63 65 5f 70 61 72 61 6d 65 74 65 72 28 22 53 43  ce_parameter("SC
e2a0: 52 49 50 54 5f 4e 41 4d 45 22 2c 20 7a 4e 65 77  RIPT_NAME", zNew
e2b0: 53 63 72 69 70 74 29 3b 0a 20 20 7d 0a 0a 20 20  Script);.  }..  
e2c0: 2f 2a 20 49 66 20 74 68 65 20 63 6f 6e 74 65 6e  /* If the conten
e2d0: 74 20 74 79 70 65 20 69 73 20 61 70 70 6c 69 63  t type is applic
e2e0: 61 74 69 6f 6e 2f 78 2d 66 6f 73 73 69 6c 20 6f  ation/x-fossil o
e2f0: 72 20 0a 20 20 2a 2a 20 61 70 70 6c 69 63 61 74  r .  ** applicat
e300: 69 6f 6e 2f 78 2d 66 6f 73 73 69 6c 2d 64 65 62  ion/x-fossil-deb
e310: 75 67 2c 20 74 68 65 6e 20 61 20 73 79 6e 63 2f  ug, then a sync/
e320: 70 75 73 68 2f 70 75 6c 6c 2f 63 6c 6f 6e 65 20  push/pull/clone 
e330: 69 73 0a 20 20 2a 2a 20 64 65 73 69 72 65 64 2c  is.  ** desired,
e340: 20 73 6f 20 64 65 66 61 75 6c 74 20 74 68 65 20   so default the 
e350: 50 41 54 48 5f 49 4e 46 4f 20 74 6f 20 2f 78 66  PATH_INFO to /xf
e360: 65 72 0a 20 20 2a 2f 0a 20 20 69 66 28 20 67 2e  er.  */.  if( g.
e370: 7a 43 6f 6e 74 65 6e 74 54 79 70 65 20 26 26 0a  zContentType &&.
e380: 20 20 20 20 20 20 73 74 72 6e 63 6d 70 28 67 2e        strncmp(g.
e390: 7a 43 6f 6e 74 65 6e 74 54 79 70 65 2c 20 22 61  zContentType, "a
e3a0: 70 70 6c 69 63 61 74 69 6f 6e 2f 78 2d 66 6f 73  pplication/x-fos
e3b0: 73 69 6c 22 2c 20 32 30 29 3d 3d 30 20 29 7b 0a  sil", 20)==0 ){.
e3c0: 20 20 20 20 2f 2a 20 53 70 65 63 69 61 6c 20 63      /* Special c
e3d0: 61 73 65 3a 20 20 49 66 20 74 68 65 20 63 6f 6e  ase:  If the con
e3e0: 74 65 6e 74 20 6d 69 6d 65 74 79 70 65 20 73 68  tent mimetype sh
e3f0: 6f 77 73 20 74 68 61 74 20 69 74 20 69 73 20 22  ows that it is "
e400: 66 6f 73 73 69 6c 20 73 79 6e 63 22 0a 20 20 20  fossil sync".   
e410: 20 2a 2a 20 70 61 79 6c 6f 61 64 2c 20 74 68 65   ** payload, the
e420: 6e 20 70 72 65 74 65 6e 64 20 74 68 61 74 20 74  n pretend that t
e430: 68 65 20 50 41 54 48 5f 49 4e 46 4f 20 69 73 20  he PATH_INFO is 
e440: 2f 78 66 65 72 20 73 6f 20 74 68 61 74 20 77 65  /xfer so that we
e450: 20 61 6c 77 61 79 73 0a 20 20 20 20 2a 2a 20 69   always.    ** i
e460: 6e 76 6f 6b 65 20 74 68 65 20 73 79 6e 63 20 70  nvoke the sync p
e470: 61 67 65 2e 20 2a 2f 0a 20 20 20 20 7a 50 61 74  age. */.    zPat
e480: 68 49 6e 66 6f 20 3d 20 22 2f 78 66 65 72 22 3b  hInfo = "/xfer";
e490: 0a 20 20 7d 0a 0a 20 20 2f 2a 20 55 73 65 20 74  .  }..  /* Use t
e4a0: 68 65 20 66 69 72 73 74 20 65 6c 65 6d 65 6e 74  he first element
e4b0: 20 6f 66 20 50 41 54 48 5f 49 4e 46 4f 20 61 73   of PATH_INFO as
e4c0: 20 74 68 65 20 70 61 67 65 20 6e 61 6d 65 0a 20   the page name. 
e4d0: 20 2a 2a 20 61 6e 64 20 64 65 6c 69 76 65 72 20   ** and deliver 
e4e0: 74 68 65 20 61 70 70 72 6f 70 72 69 61 74 65 20  the appropriate 
e4f0: 70 61 67 65 20 62 61 63 6b 20 74 6f 20 74 68 65  page back to the
e500: 20 75 73 65 72 2e 0a 20 20 2a 2f 0a 20 20 73 65   user..  */.  se
e510: 74 5f 62 61 73 65 5f 75 72 6c 28 30 29 3b 0a 20  t_base_url(0);. 
e520: 20 69 66 28 20 66 6f 73 73 69 6c 5f 72 65 64 69   if( fossil_redi
e530: 72 65 63 74 5f 74 6f 5f 68 74 74 70 73 5f 69 66  rect_to_https_if
e540: 5f 6e 65 65 64 65 64 28 32 29 20 29 20 72 65 74  _needed(2) ) ret
e550: 75 72 6e 3b 0a 20 20 69 66 28 20 7a 50 61 74 68  urn;.  if( zPath
e560: 49 6e 66 6f 3d 3d 30 20 7c 7c 20 7a 50 61 74 68  Info==0 || zPath
e570: 49 6e 66 6f 5b 30 5d 3d 3d 30 0a 20 20 20 20 20  Info[0]==0.     
e580: 20 7c 7c 20 28 7a 50 61 74 68 49 6e 66 6f 5b 30   || (zPathInfo[0
e590: 5d 3d 3d 27 2f 27 20 26 26 20 7a 50 61 74 68 49  ]=='/' && zPathI
e5a0: 6e 66 6f 5b 31 5d 3d 3d 30 29 20 29 7b 0a 20 20  nfo[1]==0) ){.  
e5b0: 20 20 2f 2a 20 53 65 63 6f 6e 64 20 73 70 65 63    /* Second spec
e5c0: 69 61 6c 20 63 61 73 65 3a 20 49 66 20 74 68 65  ial case: If the
e5d0: 20 50 41 54 48 5f 49 4e 46 4f 20 69 73 20 62 6c   PATH_INFO is bl
e5e0: 61 6e 6b 2c 20 69 73 73 75 65 20 61 20 72 65 64  ank, issue a red
e5f0: 69 72 65 63 74 20 74 6f 0a 20 20 20 20 2a 2a 20  irect to.    ** 
e600: 74 68 65 20 68 6f 6d 65 20 70 61 67 65 20 69 64  the home page id
e610: 65 6e 74 69 66 69 65 64 20 62 79 20 74 68 65 20  entified by the 
e620: 22 69 6e 64 65 78 2d 70 61 67 65 22 20 73 65 74  "index-page" set
e630: 74 69 6e 67 20 69 6e 20 74 68 65 20 72 65 70 6f  ting in the repo
e640: 73 69 74 6f 72 79 0a 20 20 20 20 2a 2a 20 43 4f  sitory.    ** CO
e650: 4e 46 49 47 20 74 61 62 6c 65 2c 20 74 6f 20 22  NFIG table, to "
e660: 2f 69 6e 64 65 78 22 20 69 66 20 74 68 65 72 65  /index" if there
e670: 20 6e 6f 20 22 69 6e 64 65 78 2d 70 61 67 65 22   no "index-page"
e680: 20 73 65 74 74 69 6e 67 2e 20 2a 2f 0a 23 69 66   setting. */.#if
e690: 64 65 66 20 46 4f 53 53 49 4c 5f 45 4e 41 42 4c  def FOSSIL_ENABL
e6a0: 45 5f 4a 53 4f 4e 0a 20 20 20 20 69 66 28 67 2e  E_JSON.    if(g.
e6b0: 6a 73 6f 6e 2e 69 73 4a 73 6f 6e 4d 6f 64 65 29  json.isJsonMode)
e6c0: 7b 0a 20 20 20 20 20 20 6a 73 6f 6e 5f 65 72 72  {.      json_err
e6d0: 28 46 53 4c 5f 4a 53 4f 4e 5f 45 5f 52 45 53 4f  (FSL_JSON_E_RESO
e6e0: 55 52 43 45 5f 4e 4f 54 5f 46 4f 55 4e 44 2c 4e  URCE_NOT_FOUND,N
e6f0: 55 4c 4c 2c 31 29 3b 0a 20 20 20 20 20 20 66 6f  ULL,1);.      fo
e700: 73 73 69 6c 5f 65 78 69 74 28 30 29 3b 0a 20 20  ssil_exit(0);.  
e710: 20 20 7d 0a 23 65 6e 64 69 66 0a 20 20 20 20 66    }.#endif.    f
e720: 6f 73 73 69 6c 5f 72 65 64 69 72 65 63 74 5f 68  ossil_redirect_h
e730: 6f 6d 65 28 29 20 2f 2a 64 6f 65 73 20 6e 6f 74  ome() /*does not
e740: 20 72 65 74 75 72 6e 2a 2f 3b 0a 20 20 7d 65 6c   return*/;.  }el
e750: 73 65 7b 0a 20 20 20 20 7a 50 61 74 68 20 3d 20  se{.    zPath = 
e760: 6d 70 72 69 6e 74 66 28 22 25 73 22 2c 20 7a 50  mprintf("%s", zP
e770: 61 74 68 49 6e 66 6f 29 3b 0a 20 20 7d 0a 0a 20  athInfo);.  }.. 
e780: 20 2f 2a 20 4d 61 6b 65 20 67 2e 7a 50 61 74 68   /* Make g.zPath
e790: 20 70 6f 69 6e 74 20 74 6f 20 74 68 65 20 66 69   point to the fi
e7a0: 72 73 74 20 65 6c 65 6d 65 6e 74 20 6f 66 20 74  rst element of t
e7b0: 68 65 20 70 61 74 68 2e 20 20 4d 61 6b 65 0a 20  he path.  Make. 
e7c0: 20 2a 2a 20 67 2e 7a 45 78 74 72 61 20 70 6f 69   ** g.zExtra poi
e7d0: 6e 74 20 74 6f 20 65 76 65 72 79 74 68 69 6e 67  nt to everything
e7e0: 20 70 61 73 74 20 74 68 61 74 20 70 6f 69 6e 74   past that point
e7f0: 2e 0a 20 20 2a 2f 0a 20 20 77 68 69 6c 65 28 31  ..  */.  while(1
e800: 29 7b 0a 20 20 20 20 67 2e 7a 50 61 74 68 20 3d  ){.    g.zPath =
e810: 20 26 7a 50 61 74 68 5b 31 5d 3b 0a 20 20 20 20   &zPath[1];.    
e820: 66 6f 72 28 69 3d 31 3b 20 7a 50 61 74 68 5b 69  for(i=1; zPath[i
e830: 5d 20 26 26 20 7a 50 61 74 68 5b 69 5d 21 3d 27  ] && zPath[i]!='
e840: 2f 27 3b 20 69 2b 2b 29 7b 7d 0a 20 20 20 20 69  /'; i++){}.    i
e850: 66 28 20 7a 50 61 74 68 5b 69 5d 3d 3d 27 2f 27  f( zPath[i]=='/'
e860: 20 29 7b 0a 20 20 20 20 20 20 7a 50 61 74 68 5b   ){.      zPath[
e870: 69 5d 20 3d 20 30 3b 0a 20 20 20 20 20 20 67 2e  i] = 0;.      g.
e880: 7a 45 78 74 72 61 20 3d 20 26 7a 50 61 74 68 5b  zExtra = &zPath[
e890: 69 2b 31 5d 3b 0a 20 20 20 20 7d 65 6c 73 65 7b  i+1];.    }else{
e8a0: 0a 20 20 20 20 20 20 67 2e 7a 45 78 74 72 61 20  .      g.zExtra 
e8b0: 3d 20 30 3b 0a 20 20 20 20 7d 0a 20 20 20 20 62  = 0;.    }.    b
e8c0: 72 65 61 6b 3b 0a 20 20 7d 0a 23 69 66 64 65 66  reak;.  }.#ifdef
e8d0: 20 46 4f 53 53 49 4c 5f 45 4e 41 42 4c 45 5f 4a   FOSSIL_ENABLE_J
e8e0: 53 4f 4e 0a 20 20 2f 2a 0a 20 20 2a 2a 20 57 6f  SON.  /*.  ** Wo
e8f0: 72 6b 61 72 6f 75 6e 64 20 74 6f 20 61 6c 6c 6f  rkaround to allo
e900: 77 20 75 73 20 74 6f 20 63 75 73 74 6f 6d 69 7a  w us to customiz
e910: 65 20 73 6f 6d 65 20 66 6f 6c 6c 6f 77 69 6e 67  e some following
e920: 20 62 65 68 61 76 69 6f 75 72 20 66 6f 72 0a 20   behaviour for. 
e930: 20 2a 2a 20 4a 53 4f 4e 20 6d 6f 64 65 2e 20 20   ** JSON mode.  
e940: 54 68 65 20 70 72 6f 62 6c 65 6d 20 69 73 2c 20  The problem is, 
e950: 77 65 20 64 6f 6e 27 74 20 61 6c 77 61 79 73 20  we don't always 
e960: 6b 6e 6f 77 20 69 66 20 77 65 27 72 65 20 69 6e  know if we're in
e970: 20 4a 53 4f 4e 0a 20 20 2a 2a 20 6d 6f 64 65 20   JSON.  ** mode 
e980: 61 74 20 74 68 69 73 20 70 6f 69 6e 74 20 28 6e  at this point (n
e990: 61 6d 65 6c 79 2c 20 66 6f 72 20 47 45 54 20 6d  amely, for GET m
e9a0: 6f 64 65 20 77 65 20 64 6f 6e 27 74 20 6b 6e 6f  ode we don't kno
e9b0: 77 20 62 75 74 20 50 4f 53 54 0a 20 20 2a 2a 20  w but POST.  ** 
e9c0: 77 65 20 64 6f 29 2c 20 73 6f 20 77 65 20 73 6e  we do), so we sn
e9d0: 6f 6f 70 20 67 2e 7a 50 61 74 68 20 61 6e 64 20  oop g.zPath and 
e9e0: 63 68 65 61 74 20 61 20 62 69 74 2e 0a 20 20 2a  cheat a bit..  *
e9f0: 2f 0a 20 20 69 66 28 20 21 67 2e 6a 73 6f 6e 2e  /.  if( !g.json.
ea00: 69 73 4a 73 6f 6e 4d 6f 64 65 20 26 26 20 67 2e  isJsonMode && g.
ea10: 7a 50 61 74 68 20 26 26 20 28 30 3d 3d 73 74 72  zPath && (0==str
ea20: 6e 63 6d 70 28 22 6a 73 6f 6e 22 2c 67 2e 7a 50  ncmp("json",g.zP
ea30: 61 74 68 2c 34 29 29 20 29 7b 0a 20 20 20 20 67  ath,4)) ){.    g
ea40: 2e 6a 73 6f 6e 2e 69 73 4a 73 6f 6e 4d 6f 64 65  .json.isJsonMode
ea50: 20 3d 20 31 3b 0a 20 20 7d 0a 23 65 6e 64 69 66   = 1;.  }.#endif
ea60: 0a 20 20 69 66 28 20 67 2e 7a 45 78 74 72 61 20  .  if( g.zExtra 
ea70: 29 7b 0a 20 20 20 20 2f 2a 20 43 47 49 20 70 61  ){.    /* CGI pa
ea80: 72 61 6d 65 74 65 72 73 20 67 65 74 20 74 68 69  rameters get thi
ea90: 73 20 74 72 65 61 74 6d 65 6e 74 20 65 6c 73 65  s treatment else
eaa0: 77 68 65 72 65 2c 20 62 75 74 20 70 6c 61 63 65  where, but place
eab0: 73 20 6c 69 6b 65 20 67 65 74 66 69 6c 65 0a 20  s like getfile. 
eac0: 20 20 20 2a 2a 20 77 69 6c 6c 20 75 73 65 20 67     ** will use g
ead0: 2e 7a 45 78 74 72 61 20 64 69 72 65 63 74 6c 79  .zExtra directly
eae0: 2e 0a 20 20 20 20 2a 2a 20 52 65 6d 69 6e 64 65  ..    ** Reminde
eaf0: 72 3a 20 74 68 65 20 6c 6f 67 69 6e 20 6d 65 63  r: the login mec
eb00: 68 61 6e 69 73 6d 20 75 73 65 73 20 27 6e 61 6d  hanism uses 'nam
eb10: 65 27 20 64 69 66 66 65 72 65 6e 74 6c 79 2c 20  e' differently, 
eb20: 61 6e 64 20 6d 61 79 0a 20 20 20 20 2a 2a 20 65  and may.    ** e
eb30: 76 65 6e 74 75 61 6c 6c 79 20 68 61 76 65 20 61  ventually have a
eb40: 20 70 72 6f 62 6c 65 6d 2f 63 6f 6c 6c 69 73 69   problem/collisi
eb50: 6f 6e 20 77 69 74 68 20 74 68 69 73 2e 0a 20 20  on with this..  
eb60: 20 20 2a 2a 0a 20 20 20 20 2a 2a 20 44 69 73 61    **.    ** Disa
eb70: 62 6c 65 64 20 62 79 20 73 74 65 70 68 61 6e 20  bled by stephan 
eb80: 77 68 65 6e 20 72 75 6e 6e 69 6e 67 20 69 6e 20  when running in 
eb90: 4a 53 4f 4e 20 6d 6f 64 65 20 62 65 63 61 75 73  JSON mode becaus
eba0: 65 20 74 68 69 73 0a 20 20 20 20 2a 2a 20 70 61  e this.    ** pa
ebb0: 72 74 69 63 75 6c 61 72 20 70 61 72 61 6d 65 74  rticular paramet
ebc0: 65 72 20 6e 61 6d 65 20 69 73 20 76 65 72 79 20  er name is very 
ebd0: 63 6f 6d 6d 6f 6e 20 61 6e 64 20 69 20 68 61 76  common and i hav
ebe0: 65 20 68 61 64 20 6e 6f 20 65 6e 64 0a 20 20 20  e had no end.   
ebf0: 20 2a 2a 20 6f 66 20 67 72 69 65 66 20 77 69 74   ** of grief wit
ec00: 68 20 74 68 69 73 20 68 61 6e 64 6c 69 6e 67 2e  h this handling.
ec10: 20 54 68 65 20 4a 53 4f 4e 20 41 50 49 20 6e 65   The JSON API ne
ec20: 76 65 72 20 72 65 6c 69 65 73 20 6f 6e 20 74 68  ver relies on th
ec30: 65 0a 20 20 20 20 2a 2a 20 68 61 6e 64 6c 69 6e  e.    ** handlin
ec40: 67 20 62 65 6c 6f 77 2c 20 61 6e 64 20 62 79 20  g below, and by 
ec50: 64 69 73 61 62 6c 69 6e 67 20 69 74 20 69 6e 20  disabling it in 
ec60: 4a 53 4f 4e 20 6d 6f 64 65 20 49 20 63 61 6e 20  JSON mode I can 
ec70: 72 65 6d 6f 76 65 0a 20 20 20 20 2a 2a 20 6c 6f  remove.    ** lo
ec80: 74 73 20 6f 66 20 73 70 65 63 69 61 6c 2d 63 61  ts of special-ca
ec90: 73 65 20 68 61 6e 64 6c 69 6e 67 20 69 6e 20 73  se handling in s
eca0: 65 76 65 72 61 6c 20 4a 53 4f 4e 20 68 61 6e 64  everal JSON hand
ecb0: 6c 65 72 73 2e 0a 20 20 20 20 2a 2f 0a 23 69 66  lers..    */.#if
ecc0: 64 65 66 20 46 4f 53 53 49 4c 5f 45 4e 41 42 4c  def FOSSIL_ENABL
ecd0: 45 5f 4a 53 4f 4e 0a 20 20 20 20 69 66 28 21 67  E_JSON.    if(!g
ece0: 2e 6a 73 6f 6e 2e 69 73 4a 73 6f 6e 4d 6f 64 65  .json.isJsonMode
ecf0: 29 7b 0a 23 65 6e 64 69 66 0a 20 20 20 20 20 20  ){.#endif.      
ed00: 64 65 68 74 74 70 69 7a 65 28 67 2e 7a 45 78 74  dehttpize(g.zExt
ed10: 72 61 29 3b 0a 20 20 20 20 20 20 63 67 69 5f 73  ra);.      cgi_s
ed20: 65 74 5f 70 61 72 61 6d 65 74 65 72 5f 6e 6f 63  et_parameter_noc
ed30: 6f 70 79 28 22 6e 61 6d 65 22 2c 20 67 2e 7a 45  opy("name", g.zE
ed40: 78 74 72 61 2c 20 31 29 3b 0a 23 69 66 64 65 66  xtra, 1);.#ifdef
ed50: 20 46 4f 53 53 49 4c 5f 45 4e 41 42 4c 45 5f 4a   FOSSIL_ENABLE_J
ed60: 53 4f 4e 0a 20 20 20 20 7d 0a 23 65 6e 64 69 66  SON.    }.#endif
ed70: 0a 20 20 7d 0a 0a 20 20 2f 2a 20 4c 6f 63 61 74  .  }..  /* Locat
ed80: 65 20 74 68 65 20 6d 65 74 68 6f 64 20 73 70 65  e the method spe
ed90: 63 69 66 69 65 64 20 62 79 20 74 68 65 20 70 61  cified by the pa
eda0: 74 68 20 61 6e 64 20 65 78 65 63 75 74 65 20 74  th and execute t
edb0: 68 65 20 66 75 6e 63 74 69 6f 6e 0a 20 20 2a 2a  he function.  **
edc0: 20 74 68 61 74 20 69 6d 70 6c 65 6d 65 6e 74 73   that implements
edd0: 20 74 68 61 74 20 6d 65 74 68 6f 64 2e 0a 20 20   that method..  
ede0: 2a 2f 0a 20 20 69 66 28 20 64 69 73 70 61 74 63  */.  if( dispatc
edf0: 68 5f 6e 61 6d 65 5f 73 65 61 72 63 68 28 67 2e  h_name_search(g.
ee00: 7a 50 61 74 68 2d 31 2c 20 43 4d 44 46 4c 41 47  zPath-1, CMDFLAG
ee10: 5f 57 45 42 50 41 47 45 2c 20 26 70 43 6d 64 29  _WEBPAGE, &pCmd)
ee20: 0a 20 20 20 26 26 20 64 69 73 70 61 74 63 68 5f  .   && dispatch_
ee30: 61 6c 69 61 73 28 67 2e 7a 50 61 74 68 2d 31 2c  alias(g.zPath-1,
ee40: 20 26 70 43 6d 64 29 0a 20 20 29 7b 0a 23 69 66   &pCmd).  ){.#if
ee50: 64 65 66 20 46 4f 53 53 49 4c 5f 45 4e 41 42 4c  def FOSSIL_ENABL
ee60: 45 5f 4a 53 4f 4e 0a 20 20 20 20 69 66 28 67 2e  E_JSON.    if(g.
ee70: 6a 73 6f 6e 2e 69 73 4a 73 6f 6e 4d 6f 64 65 29  json.isJsonMode)
ee80: 7b 0a 20 20 20 20 20 20 6a 73 6f 6e 5f 65 72 72  {.      json_err
ee90: 28 46 53 4c 5f 4a 53 4f 4e 5f 45 5f 52 45 53 4f  (FSL_JSON_E_RESO
eea0: 55 52 43 45 5f 4e 4f 54 5f 46 4f 55 4e 44 2c 4e  URCE_NOT_FOUND,N
eeb0: 55 4c 4c 2c 30 29 3b 0a 20 20 20 20 7d 65 6c 73  ULL,0);.    }els
eec0: 65 0a 23 65 6e 64 69 66 0a 20 20 20 20 7b 0a 23  e.#endif.    {.#
eed0: 69 66 64 65 66 20 46 4f 53 53 49 4c 5f 45 4e 41  ifdef FOSSIL_ENA
eee0: 42 4c 45 5f 54 48 31 5f 48 4f 4f 4b 53 0a 20 20  BLE_TH1_HOOKS.  
eef0: 20 20 20 20 69 6e 74 20 72 63 3b 0a 20 20 20 20      int rc;.    
ef00: 20 20 69 66 28 20 21 67 2e 66 4e 6f 54 68 48 6f    if( !g.fNoThHo
ef10: 6f 6b 20 29 7b 0a 20 20 20 20 20 20 20 20 72 63  ok ){.        rc
ef20: 20 3d 20 54 68 5f 57 65 62 70 61 67 65 48 6f 6f   = Th_WebpageHoo
ef30: 6b 28 67 2e 7a 50 61 74 68 2c 20 30 29 3b 0a 20  k(g.zPath, 0);. 
ef40: 20 20 20 20 20 7d 65 6c 73 65 7b 0a 20 20 20 20       }else{.    
ef50: 20 20 20 20 72 63 20 3d 20 54 48 5f 4f 4b 3b 0a      rc = TH_OK;.
ef60: 20 20 20 20 20 20 7d 0a 20 20 20 20 20 20 69 66        }.      if
ef70: 28 20 72 63 3d 3d 54 48 5f 4f 4b 20 7c 7c 20 72  ( rc==TH_OK || r
ef80: 63 3d 3d 54 48 5f 52 45 54 55 52 4e 20 7c 7c 20  c==TH_RETURN || 
ef90: 72 63 3d 3d 54 48 5f 43 4f 4e 54 49 4e 55 45 20  rc==TH_CONTINUE 
efa0: 29 7b 0a 20 20 20 20 20 20 20 20 69 66 28 20 72  ){.        if( r
efb0: 63 3d 3d 54 48 5f 4f 4b 20 7c 7c 20 72 63 3d 3d  c==TH_OK || rc==
efc0: 54 48 5f 52 45 54 55 52 4e 20 29 7b 0a 23 65 6e  TH_RETURN ){.#en
efd0: 64 69 66 0a 20 20 20 20 20 20 20 20 20 20 63 67  dif.          cg
efe0: 69 5f 73 65 74 5f 73 74 61 74 75 73 28 34 30 34  i_set_status(404
eff0: 2c 22 4e 6f 74 20 46 6f 75 6e 64 22 29 3b 0a 20  ,"Not Found");. 
f000: 20 20 20 20 20 20 20 20 20 40 20 3c 68 31 3e 4e           @ <h1>N
f010: 6f 74 20 46 6f 75 6e 64 3c 2f 68 31 3e 0a 20 20  ot Found</h1>.  
f020: 20 20 20 20 20 20 20 20 40 20 3c 70 3e 50 61 67          @ <p>Pag
f030: 65 20 6e 6f 74 20 66 6f 75 6e 64 3a 20 25 68 28  e not found: %h(
f040: 67 2e 7a 50 61 74 68 29 3c 2f 70 3e 0a 23 69 66  g.zPath)</p>.#if
f050: 64 65 66 20 46 4f 53 53 49 4c 5f 45 4e 41 42 4c  def FOSSIL_ENABL
f060: 45 5f 54 48 31 5f 48 4f 4f 4b 53 0a 20 20 20 20  E_TH1_HOOKS.    
f070: 20 20 20 20 7d 0a 20 20 20 20 20 20 20 20 69 66      }.        if
f080: 28 20 21 67 2e 66 4e 6f 54 68 48 6f 6f 6b 20 26  ( !g.fNoThHook &
f090: 26 20 28 72 63 3d 3d 54 48 5f 4f 4b 20 7c 7c 20  & (rc==TH_OK || 
f0a0: 72 63 3d 3d 54 48 5f 43 4f 4e 54 49 4e 55 45 29  rc==TH_CONTINUE)
f0b0: 20 29 7b 0a 20 20 20 20 20 20 20 20 20 20 54 68   ){.          Th
f0c0: 5f 57 65 62 70 61 67 65 4e 6f 74 69 66 79 28 67  _WebpageNotify(g
f0d0: 2e 7a 50 61 74 68 2c 20 30 29 3b 0a 20 20 20 20  .zPath, 0);.    
f0e0: 20 20 20 20 7d 0a 20 20 20 20 20 20 7d 0a 23 65      }.      }.#e
f0f0: 6e 64 69 66 0a 20 20 20 20 7d 0a 20 20 7d 65 6c  ndif.    }.  }el
f100: 73 65 20 69 66 28 20 70 43 6d 64 2d 3e 78 46 75  se if( pCmd->xFu
f110: 6e 63 21 3d 70 61 67 65 5f 78 66 65 72 20 26 26  nc!=page_xfer &&
f120: 20 64 62 5f 73 63 68 65 6d 61 5f 69 73 5f 6f 75   db_schema_is_ou
f130: 74 6f 66 64 61 74 65 28 29 20 29 7b 0a 23 69 66  tofdate() ){.#if
f140: 64 65 66 20 46 4f 53 53 49 4c 5f 45 4e 41 42 4c  def FOSSIL_ENABL
f150: 45 5f 4a 53 4f 4e 0a 20 20 20 20 69 66 28 67 2e  E_JSON.    if(g.
f160: 6a 73 6f 6e 2e 69 73 4a 73 6f 6e 4d 6f 64 65 29  json.isJsonMode)
f170: 7b 0a 20 20 20 20 20 20 6a 73 6f 6e 5f 65 72 72  {.      json_err
f180: 28 46 53 4c 5f 4a 53 4f 4e 5f 45 5f 44 42 5f 4e  (FSL_JSON_E_DB_N
f190: 45 45 44 53 5f 52 45 42 55 49 4c 44 2c 4e 55 4c  EEDS_REBUILD,NUL
f1a0: 4c 2c 30 29 3b 0a 20 20 20 20 7d 65 6c 73 65 0a  L,0);.    }else.
f1b0: 23 65 6e 64 69 66 0a 20 20 20 20 7b 0a 20 20 20  #endif.    {.   
f1c0: 20 20 20 40 20 3c 68 31 3e 53 65 72 76 65 72 20     @ <h1>Server 
f1d0: 43 6f 6e 66 69 67 75 72 61 74 69 6f 6e 20 45 72  Configuration Er
f1e0: 72 6f 72 3c 2f 68 31 3e 0a 20 20 20 20 20 20 40  ror</h1>.      @
f1f0: 20 3c 70 3e 54 68 65 20 64 61 74 61 62 61 73 65   <p>The database
f200: 20 73 63 68 65 6d 61 20 6f 6e 20 74 68 65 20 73   schema on the s
f210: 65 72 76 65 72 20 69 73 20 6f 75 74 2d 6f 66 2d  erver is out-of-
f220: 64 61 74 65 2e 20 20 50 6c 65 61 73 65 20 61 73  date.  Please as
f230: 6b 0a 20 20 20 20 20 20 40 20 74 68 65 20 61 64  k.      @ the ad
f240: 6d 69 6e 69 73 74 72 61 74 6f 72 20 74 6f 20 72  ministrator to r
f250: 75 6e 20 3c 62 3e 66 6f 73 73 69 6c 20 72 65 62  un <b>fossil reb
f260: 75 69 6c 64 3c 2f 62 3e 2e 3c 2f 70 3e 0a 20 20  uild</b>.</p>.  
f270: 20 20 7d 0a 20 20 7d 65 6c 73 65 7b 0a 20 20 20    }.  }else{.   
f280: 20 69 66 28 20 28 70 43 6d 64 2d 3e 65 43 6d 64   if( (pCmd->eCmd
f290: 46 6c 61 67 73 20 26 20 43 4d 44 46 4c 41 47 5f  Flags & CMDFLAG_
f2a0: 52 41 57 43 4f 4e 54 45 4e 54 29 3d 3d 30 20 29  RAWCONTENT)==0 )
f2b0: 7b 0a 20 20 20 20 20 20 63 67 69 5f 64 65 63 6f  {.      cgi_deco
f2c0: 64 65 5f 70 6f 73 74 5f 70 61 72 61 6d 65 74 65  de_post_paramete
f2d0: 72 73 28 29 3b 0a 20 20 20 20 7d 0a 20 20 20 20  rs();.    }.    
f2e0: 69 66 28 20 67 2e 66 43 67 69 54 72 61 63 65 20  if( g.fCgiTrace 
f2f0: 29 7b 0a 20 20 20 20 20 20 66 6f 73 73 69 6c 5f  ){.      fossil_
f300: 74 72 61 63 65 28 22 23 23 23 23 23 23 23 23 20  trace("######## 
f310: 43 61 6c 6c 69 6e 67 20 25 73 20 23 23 23 23 23  Calling %s #####
f320: 23 23 23 23 5c 6e 22 2c 20 70 43 6d 64 2d 3e 7a  ####\n", pCmd->z
f330: 4e 61 6d 65 29 3b 0a 20 20 20 20 20 20 63 67 69  Name);.      cgi
f340: 5f 70 72 69 6e 74 5f 61 6c 6c 28 31 2c 20 31 29  _print_all(1, 1)
f350: 3b 0a 20 20 20 20 7d 0a 23 69 66 64 65 66 20 46  ;.    }.#ifdef F
f360: 4f 53 53 49 4c 5f 45 4e 41 42 4c 45 5f 54 48 31  OSSIL_ENABLE_TH1
f370: 5f 48 4f 4f 4b 53 0a 20 20 20 20 7b 0a 20 20 20  _HOOKS.    {.   
f380: 20 20 20 2f 2a 0a 20 20 20 20 20 20 2a 2a 20 54     /*.      ** T
f390: 68 65 20 54 48 31 20 72 65 74 75 72 6e 20 63 6f  he TH1 return co
f3a0: 64 65 73 20 66 72 6f 6d 20 74 68 65 20 68 6f 6f  des from the hoo
f3b0: 6b 20 77 69 6c 6c 20 62 65 20 68 61 6e 64 6c 65  k will be handle
f3c0: 64 20 61 73 20 66 6f 6c 6c 6f 77 73 3a 0a 20 20  d as follows:.  
f3d0: 20 20 20 20 2a 2a 0a 20 20 20 20 20 20 2a 2a 20      **.      ** 
f3e0: 54 48 5f 4f 4b 3a 20 54 68 65 20 78 46 75 6e 63  TH_OK: The xFunc
f3f0: 28 29 20 61 6e 64 20 74 68 65 20 54 48 31 20 6e  () and the TH1 n
f400: 6f 74 69 66 69 63 61 74 69 6f 6e 20 77 69 6c 6c  otification will
f410: 20 62 6f 74 68 20 62 65 20 65 78 65 63 75 74 65   both be execute
f420: 64 2e 0a 20 20 20 20 20 20 2a 2a 0a 20 20 20 20  d..      **.    
f430: 20 20 2a 2a 20 54 48 5f 45 52 52 4f 52 3a 20 54    ** TH_ERROR: T
f440: 68 65 20 78 46 75 6e 63 28 29 20 77 69 6c 6c 20  he xFunc() will 
f450: 62 65 20 73 6b 69 70 70 65 64 2c 20 74 68 65 20  be skipped, the 
f460: 54 48 31 20 6e 6f 74 69 66 69 63 61 74 69 6f 6e  TH1 notification
f470: 20 77 69 6c 6c 20 62 65 0a 20 20 20 20 20 20 2a   will be.      *
f480: 2a 20 20 20 20 20 20 20 20 20 20 20 73 6b 69 70  *           skip
f490: 70 65 64 2e 20 20 49 66 20 74 68 65 20 78 46 75  ped.  If the xFu
f4a0: 6e 63 28 29 20 69 73 20 62 65 69 6e 67 20 68 6f  nc() is being ho
f4b0: 6f 6b 65 64 2c 20 74 68 65 20 65 72 72 6f 72 20  oked, the error 
f4c0: 6d 65 73 73 61 67 65 0a 20 20 20 20 20 20 2a 2a  message.      **
f4d0: 20 20 20 20 20 20 20 20 20 20 20 77 69 6c 6c 20             will 
f4e0: 62 65 20 65 6d 69 74 74 65 64 2e 0a 20 20 20 20  be emitted..    
f4f0: 20 20 2a 2a 0a 20 20 20 20 20 20 2a 2a 20 54 48    **.      ** TH
f500: 5f 42 52 45 41 4b 3a 20 54 68 65 20 78 46 75 6e  _BREAK: The xFun
f510: 63 28 29 20 61 6e 64 20 74 68 65 20 54 48 31 20  c() and the TH1 
f520: 6e 6f 74 69 66 69 63 61 74 69 6f 6e 20 77 69 6c  notification wil
f530: 6c 20 62 6f 74 68 20 62 65 20 73 6b 69 70 70 65  l both be skippe
f540: 64 2e 0a 20 20 20 20 20 20 2a 2a 0a 20 20 20 20  d..      **.    
f550: 20 20 2a 2a 20 54 48 5f 52 45 54 55 52 4e 3a 20    ** TH_RETURN: 
f560: 54 68 65 20 78 46 75 6e 63 28 29 20 77 69 6c 6c  The xFunc() will
f570: 20 62 65 20 65 78 65 63 75 74 65 64 2c 20 74 68   be executed, th
f580: 65 20 54 48 31 20 6e 6f 74 69 66 69 63 61 74 69  e TH1 notificati
f590: 6f 6e 20 77 69 6c 6c 20 62 65 0a 20 20 20 20 20  on will be.     
f5a0: 20 2a 2a 20 20 20 20 20 20 20 20 20 20 20 20 73   **            s
f5b0: 6b 69 70 70 65 64 2e 0a 20 20 20 20 20 20 2a 2a  kipped..      **
f5c0: 0a 20 20 20 20 20 20 2a 2a 20 54 48 5f 43 4f 4e  .      ** TH_CON
f5d0: 54 49 4e 55 45 3a 20 54 68 65 20 78 46 75 6e 63  TINUE: The xFunc
f5e0: 28 29 20 77 69 6c 6c 20 62 65 20 73 6b 69 70 70  () will be skipp
f5f0: 65 64 2c 20 74 68 65 20 54 48 31 20 6e 6f 74 69  ed, the TH1 noti
f600: 66 69 63 61 74 69 6f 6e 20 77 69 6c 6c 20 62 65  fication will be
f610: 0a 20 20 20 20 20 20 2a 2a 20 20 20 20 20 20 20  .      **       
f620: 20 20 20 20 20 20 20 65 78 65 63 75 74 65 64 2e         executed.
f630: 0a 20 20 20 20 20 20 2a 2f 0a 20 20 20 20 20 20  .      */.      
f640: 69 6e 74 20 72 63 3b 0a 20 20 20 20 20 20 69 66  int rc;.      if
f650: 28 20 21 67 2e 66 4e 6f 54 68 48 6f 6f 6b 20 29  ( !g.fNoThHook )
f660: 7b 0a 20 20 20 20 20 20 20 20 72 63 20 3d 20 54  {.        rc = T
f670: 68 5f 57 65 62 70 61 67 65 48 6f 6f 6b 28 70 43  h_WebpageHook(pC
f680: 6d 64 2d 3e 7a 4e 61 6d 65 2b 31 2c 20 70 43 6d  md->zName+1, pCm
f690: 64 2d 3e 65 43 6d 64 46 6c 61 67 73 29 3b 0a 20  d->eCmdFlags);. 
f6a0: 20 20 20 20 20 7d 65 6c 73 65 7b 0a 20 20 20 20       }else{.    
f6b0: 20 20 20 20 72 63 20 3d 20 54 48 5f 4f 4b 3b 0a      rc = TH_OK;.
f6c0: 20 20 20 20 20 20 7d 0a 20 20 20 20 20 20 69 66        }.      if
f6d0: 28 20 72 63 3d 3d 54 48 5f 4f 4b 20 7c 7c 20 72  ( rc==TH_OK || r
f6e0: 63 3d 3d 54 48 5f 52 45 54 55 52 4e 20 7c 7c 20  c==TH_RETURN || 
f6f0: 72 63 3d 3d 54 48 5f 43 4f 4e 54 49 4e 55 45 20  rc==TH_CONTINUE 
f700: 29 7b 0a 20 20 20 20 20 20 20 20 69 66 28 20 72  ){.        if( r
f710: 63 3d 3d 54 48 5f 4f 4b 20 7c 7c 20 72 63 3d 3d  c==TH_OK || rc==
f720: 54 48 5f 52 45 54 55 52 4e 20 29 7b 0a 23 65 6e  TH_RETURN ){.#en
f730: 64 69 66 0a 20 20 20 20 20 20 20 20 20 20 70 43  dif.          pC
f740: 6d 64 2d 3e 78 46 75 6e 63 28 29 3b 0a 23 69 66  md->xFunc();.#if
f750: 64 65 66 20 46 4f 53 53 49 4c 5f 45 4e 41 42 4c  def FOSSIL_ENABL
f760: 45 5f 54 48 31 5f 48 4f 4f 4b 53 0a 20 20 20 20  E_TH1_HOOKS.    
f770: 20 20 20 20 7d 0a 20 20 20 20 20 20 20 20 69 66      }.        if
f780: 28 20 21 67 2e 66 4e 6f 54 68 48 6f 6f 6b 20 26  ( !g.fNoThHook &
f790: 26 20 28 72 63 3d 3d 54 48 5f 4f 4b 20 7c 7c 20  & (rc==TH_OK || 
f7a0: 72 63 3d 3d 54 48 5f 43 4f 4e 54 49 4e 55 45 29  rc==TH_CONTINUE)
f7b0: 20 29 7b 0a 20 20 20 20 20 20 20 20 20 20 54 68   ){.          Th
f7c0: 5f 57 65 62 70 61 67 65 4e 6f 74 69 66 79 28 70  _WebpageNotify(p
f7d0: 43 6d 64 2d 3e 7a 4e 61 6d 65 2b 31 2c 20 70 43  Cmd->zName+1, pC
f7e0: 6d 64 2d 3e 65 43 6d 64 46 6c 61 67 73 29 3b 0a  md->eCmdFlags);.
f7f0: 20 20 20 20 20 20 20 20 7d 0a 20 20 20 20 20 20          }.      
f800: 7d 0a 20 20 20 20 7d 0a 23 65 6e 64 69 66 0a 20  }.    }.#endif. 
f810: 20 7d 0a 0a 20 20 2f 2a 20 52 65 74 75 72 6e 20   }..  /* Return 
f820: 74 68 65 20 72 65 73 75 6c 74 2e 0a 20 20 2a 2f  the result..  */
f830: 0a 20 20 63 67 69 5f 72 65 70 6c 79 28 29 3b 0a  .  cgi_reply();.
f840: 7d 0a 0a 2f 2a 20 49 66 20 74 68 65 20 43 47 49  }../* If the CGI
f850: 20 70 72 6f 67 72 61 6d 20 63 6f 6e 74 61 69 6e   program contain
f860: 73 20 6f 6e 65 20 6f 72 20 6d 6f 72 65 20 6c 69  s one or more li
f870: 6e 65 73 20 6f 66 20 74 68 65 20 66 6f 72 6d 0a  nes of the form.
f880: 2a 2a 0a 2a 2a 20 20 20 20 72 65 64 69 72 65 63  **.**    redirec
f890: 74 3a 20 20 72 65 70 6f 73 69 74 6f 72 79 2d 66  t:  repository-f
f8a0: 69 6c 65 6e 61 6d 65 20 20 68 74 74 70 3a 2f 2f  ilename  http://
f8b0: 68 6f 73 74 6e 61 6d 65 2f 70 61 74 68 2f 25 73  hostname/path/%s
f8c0: 0a 2a 2a 0a 2a 2a 20 74 68 65 6e 20 63 6f 6e 74  .**.** then cont
f8d0: 72 6f 6c 20 6a 75 6d 70 73 20 68 65 72 65 2e 20  rol jumps here. 
f8e0: 20 53 65 61 72 63 68 20 65 61 63 68 20 72 65 70   Search each rep
f8f0: 6f 73 69 74 6f 72 79 20 66 6f 72 20 61 6e 20 61  ository for an a
f900: 72 74 69 66 61 63 74 20 49 44 0a 2a 2a 20 6f 72  rtifact ID.** or
f910: 20 74 69 63 6b 65 74 20 49 44 20 74 68 61 74 20   ticket ID that 
f920: 6d 61 74 63 68 65 73 20 74 68 65 20 22 6e 61 6d  matches the "nam
f930: 65 22 20 43 47 49 20 70 61 72 61 6d 65 74 65 72  e" CGI parameter
f940: 20 61 6e 64 20 66 6f 72 20 74 68 65 0a 2a 2a 20   and for the.** 
f950: 66 69 72 73 74 20 6d 61 74 63 68 2c 20 72 65 64  first match, red
f960: 69 72 65 63 74 20 74 6f 20 74 68 65 20 63 6f 72  irect to the cor
f970: 72 65 73 70 6f 6e 64 69 6e 67 20 55 52 4c 20 77  responding URL w
f980: 69 74 68 20 74 68 65 20 22 6e 61 6d 65 22 20 43  ith the "name" C
f990: 47 49 0a 2a 2a 20 70 61 72 61 6d 65 74 65 72 20  GI.** parameter 
f9a0: 69 6e 73 65 72 74 65 64 2e 20 20 50 61 69 6e 74  inserted.  Paint
f9b0: 20 61 6e 20 65 72 72 6f 72 20 70 61 67 65 20 69   an error page i
f9c0: 66 20 6e 6f 20 6d 61 74 63 68 20 69 73 20 66 6f  f no match is fo
f9d0: 75 6e 64 2e 0a 2a 2a 0a 2a 2a 20 49 66 20 74 68  und..**.** If th
f9e0: 65 72 65 20 69 73 20 61 20 6c 69 6e 65 20 6f 66  ere is a line of
f9f0: 20 74 68 65 20 66 6f 72 6d 3a 0a 2a 2a 0a 2a 2a   the form:.**.**
fa00: 20 20 20 20 72 65 64 69 72 65 63 74 3a 20 2a 20      redirect: * 
fa10: 55 52 4c 0a 2a 2a 0a 2a 2a 20 54 68 65 6e 20 61  URL.**.** Then a
fa20: 20 72 65 64 69 72 65 63 74 20 69 73 20 6d 61 64   redirect is mad
fa30: 65 20 74 6f 20 55 52 4c 20 69 66 20 6e 6f 20 6d  e to URL if no m
fa40: 61 74 63 68 20 69 73 20 66 6f 75 6e 64 2e 20 20  atch is found.  
fa50: 4f 74 68 65 72 77 69 73 65 20 61 0a 2a 2a 20 76  Otherwise a.** v
fa60: 65 72 79 20 70 72 69 6d 69 74 69 76 65 20 65 72  ery primitive er
fa70: 72 6f 72 20 6d 65 73 73 61 67 65 20 69 73 20 72  ror message is r
fa80: 65 74 75 72 6e 65 64 2e 0a 2a 2f 0a 73 74 61 74  eturned..*/.stat
fa90: 69 63 20 76 6f 69 64 20 72 65 64 69 72 65 63 74  ic void redirect
faa0: 5f 77 65 62 5f 70 61 67 65 28 69 6e 74 20 6e 52  _web_page(int nR
fab0: 65 64 69 72 65 63 74 2c 20 63 68 61 72 20 2a 2a  edirect, char **
fac0: 61 7a 52 65 64 69 72 65 63 74 29 7b 0a 20 20 69  azRedirect){.  i
fad0: 6e 74 20 69 3b 20 20 20 20 20 20 20 20 20 20 20  nt i;           
fae0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
faf0: 20 20 2f 2a 20 4c 6f 6f 70 20 63 6f 75 6e 74 65    /* Loop counte
fb00: 72 20 2a 2f 0a 20 20 63 6f 6e 73 74 20 63 68 61  r */.  const cha
fb10: 72 20 2a 7a 4e 6f 74 46 6f 75 6e 64 20 3d 20 30  r *zNotFound = 0
fb20: 3b 20 20 20 20 20 20 20 20 20 2f 2a 20 4e 6f 74  ;         /* Not
fb30: 20 66 6f 75 6e 64 20 55 52 4c 20 2a 2f 0a 20 20   found URL */.  
fb40: 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a 4e 61 6d  const char *zNam
fb50: 65 20 3d 20 50 28 22 6e 61 6d 65 22 29 3b 0a 20  e = P("name");. 
fb60: 20 73 65 74 5f 62 61 73 65 5f 75 72 6c 28 30 29   set_base_url(0)
fb70: 3b 0a 20 20 69 66 28 20 7a 4e 61 6d 65 3d 3d 30  ;.  if( zName==0
fb80: 20 29 7b 0a 20 20 20 20 7a 4e 61 6d 65 20 3d 20   ){.    zName = 
fb90: 50 28 22 53 43 52 49 50 54 5f 4e 41 4d 45 22 29  P("SCRIPT_NAME")
fba0: 3b 0a 20 20 20 20 69 66 28 20 7a 4e 61 6d 65 20  ;.    if( zName 
fbb0: 26 26 20 7a 4e 61 6d 65 5b 30 5d 3d 3d 27 2f 27  && zName[0]=='/'
fbc0: 20 29 20 7a 4e 61 6d 65 2b 2b 3b 0a 20 20 7d 0a   ) zName++;.  }.
fbd0: 20 20 69 66 28 20 7a 4e 61 6d 65 20 26 26 20 76    if( zName && v
fbe0: 61 6c 69 64 61 74 65 31 36 28 7a 4e 61 6d 65 2c  alidate16(zName,
fbf0: 20 73 74 72 6c 65 6e 28 7a 4e 61 6d 65 29 29 20   strlen(zName)) 
fc00: 29 7b 0a 20 20 20 20 66 6f 72 28 69 3d 30 3b 20  ){.    for(i=0; 
fc10: 69 3c 6e 52 65 64 69 72 65 63 74 3b 20 69 2b 2b  i<nRedirect; i++
fc20: 29 7b 0a 20 20 20 20 20 20 69 66 28 20 66 6f 73  ){.      if( fos
fc30: 73 69 6c 5f 73 74 72 63 6d 70 28 61 7a 52 65 64  sil_strcmp(azRed
fc40: 69 72 65 63 74 5b 69 2a 32 5d 2c 22 2a 22 29 3d  irect[i*2],"*")=
fc50: 3d 30 20 29 7b 0a 20 20 20 20 20 20 20 20 7a 4e  =0 ){.        zN
fc60: 6f 74 46 6f 75 6e 64 20 3d 20 61 7a 52 65 64 69  otFound = azRedi
fc70: 72 65 63 74 5b 69 2a 32 2b 31 5d 3b 0a 20 20 20  rect[i*2+1];.   
fc80: 20 20 20 20 20 63 6f 6e 74 69 6e 75 65 3b 0a 20       continue;. 
fc90: 20 20 20 20 20 7d 0a 20 20 20 20 20 20 64 62 5f       }.      db_
fca0: 6f 70 65 6e 5f 72 65 70 6f 73 69 74 6f 72 79 28  open_repository(
fcb0: 61 7a 52 65 64 69 72 65 63 74 5b 69 2a 32 5d 29  azRedirect[i*2])
fcc0: 3b 0a 20 20 20 20 20 20 69 66 28 20 64 62 5f 65  ;.      if( db_e
fcd0: 78 69 73 74 73 28 22 53 45 4c 45 43 54 20 31 20  xists("SELECT 1 
fce0: 46 52 4f 4d 20 62 6c 6f 62 20 57 48 45 52 45 20  FROM blob WHERE 
fcf0: 75 75 69 64 20 47 4c 4f 42 20 27 25 71 2a 27 22  uuid GLOB '%q*'"
fd00: 2c 20 7a 4e 61 6d 65 29 20 7c 7c 0a 20 20 20 20  , zName) ||.    
fd10: 20 20 20 20 20 20 64 62 5f 65 78 69 73 74 73 28        db_exists(
fd20: 22 53 45 4c 45 43 54 20 31 20 46 52 4f 4d 20 74  "SELECT 1 FROM t
fd30: 69 63 6b 65 74 20 57 48 45 52 45 20 74 6b 74 5f  icket WHERE tkt_
fd40: 75 75 69 64 20 47 4c 4f 42 20 27 25 71 2a 27 22  uuid GLOB '%q*'"
fd50: 2c 20 7a 4e 61 6d 65 29 20 29 7b 0a 20 20 20 20  , zName) ){.    
fd60: 20 20 20 20 63 67 69 5f 72 65 64 69 72 65 63 74      cgi_redirect
fd70: 66 28 61 7a 52 65 64 69 72 65 63 74 5b 69 2a 32  f(azRedirect[i*2
fd80: 2b 31 5d 20 2f 2a 77 6f 72 6b 73 2d 6c 69 6b 65  +1] /*works-like
fd90: 3a 22 25 73 22 2a 2f 2c 20 7a 4e 61 6d 65 29 3b  :"%s"*/, zName);
fda0: 0a 20 20 20 20 20 20 20 20 72 65 74 75 72 6e 3b  .        return;
fdb0: 0a 20 20 20 20 20 20 7d 0a 20 20 20 20 20 20 64  .      }.      d
fdc0: 62 5f 63 6c 6f 73 65 28 31 29 3b 0a 20 20 20 20  b_close(1);.    
fdd0: 7d 0a 20 20 7d 0a 20 20 69 66 28 20 7a 4e 6f 74  }.  }.  if( zNot
fde0: 46 6f 75 6e 64 20 29 7b 0a 20 20 20 20 63 67 69  Found ){.    cgi
fdf0: 5f 72 65 64 69 72 65 63 74 66 28 7a 4e 6f 74 46  _redirectf(zNotF
fe00: 6f 75 6e 64 20 2f 2a 77 6f 72 6b 73 2d 6c 69 6b  ound /*works-lik
fe10: 65 3a 22 25 73 22 2a 2f 2c 20 7a 4e 61 6d 65 29  e:"%s"*/, zName)
fe20: 3b 0a 20 20 7d 65 6c 73 65 7b 0a 20 20 20 20 40  ;.  }else{.    @
fe30: 20 3c 68 74 6d 6c 3e 0a 20 20 20 20 40 20 3c 68   <html>.    @ <h
fe40: 65 61 64 3e 3c 74 69 74 6c 65 3e 4e 6f 20 53 75  ead><title>No Su
fe50: 63 68 20 4f 62 6a 65 63 74 3c 2f 74 69 74 6c 65  ch Object</title
fe60: 3e 3c 2f 68 65 61 64 3e 0a 20 20 20 20 40 20 3c  ></head>.    @ <
fe70: 62 6f 64 79 3e 0a 20 20 20 20 40 20 3c 70 3e 4e  body>.    @ <p>N
fe80: 6f 20 73 75 63 68 20 6f 62 6a 65 63 74 3a 20 3c  o such object: <
fe90: 62 3e 25 68 28 7a 4e 61 6d 65 29 3c 2f 62 3e 3c  b>%h(zName)</b><
fea0: 2f 70 3e 0a 20 20 20 20 40 20 3c 2f 62 6f 64 79  /p>.    @ </body
feb0: 3e 0a 20 20 20 20 63 67 69 5f 72 65 70 6c 79 28  >.    cgi_reply(
fec0: 29 3b 0a 20 20 7d 0a 7d 0a 0a 2f 2a 0a 2a 2a 20  );.  }.}../*.** 
fed0: 43 4f 4d 4d 41 4e 44 3a 20 63 67 69 2a 0a 2a 2a  COMMAND: cgi*.**
fee0: 0a 2a 2a 20 55 73 61 67 65 3a 20 25 66 6f 73 73  .** Usage: %foss
fef0: 69 6c 20 3f 63 67 69 3f 20 46 49 4c 45 0a 2a 2a  il ?cgi? FILE.**
ff00: 0a 2a 2a 20 54 68 69 73 20 63 6f 6d 6d 61 6e 64  .** This command
ff10: 20 63 61 75 73 65 73 20 46 6f 73 73 69 6c 20 74   causes Fossil t
ff20: 6f 20 67 65 6e 65 72 61 74 65 20 72 65 70 6c 79  o generate reply
ff30: 20 74 6f 20 61 20 43 47 49 20 72 65 71 75 65 73   to a CGI reques
ff40: 74 2e 0a 2a 2a 0a 2a 2a 20 54 68 65 20 46 49 4c  t..**.** The FIL
ff50: 45 20 61 72 67 75 6d 65 6e 74 20 69 73 20 74 68  E argument is th
ff60: 65 20 6e 61 6d 65 20 6f 66 20 61 20 63 6f 6e 74  e name of a cont
ff70: 72 6f 6c 20 66 69 6c 65 20 74 68 61 74 20 70 72  rol file that pr
ff80: 6f 76 69 64 65 73 20 46 6f 73 73 69 6c 0a 2a 2a  ovides Fossil.**
ff90: 20 77 69 74 68 20 69 6d 70 6f 72 74 61 6e 74 20   with important 
ffa0: 69 6e 66 6f 72 6d 61 74 69 6f 6e 20 73 75 63 68  information such
ffb0: 20 61 73 20 77 68 65 72 65 20 74 6f 20 66 69 6e   as where to fin
ffc0: 64 20 69 74 73 20 72 65 70 6f 73 69 74 6f 72 79  d its repository
ffd0: 2e 20 20 49 6e 0a 2a 2a 20 61 20 74 79 70 69 63  .  In.** a typic
ffe0: 61 6c 20 43 47 49 20 64 65 70 6c 6f 79 6d 65 6e  al CGI deploymen
fff0: 74 2c 20 46 49 4c 45 20 69 73 20 74 68 65 20 6e  t, FILE is the n
10000 61 6d 65 20 6f 66 20 74 68 65 20 43 47 49 20 73  ame of the CGI s
10010 63 72 69 70 74 20 61 6e 64 20 77 69 6c 6c 0a 2a  cript and will.*
10020 2a 20 74 79 70 69 63 61 6c 6c 79 20 6c 6f 6f 6b  * typically look
10030 20 73 6f 6d 65 74 68 69 6e 67 20 6c 69 6b 65 20   something like 
10040 74 68 69 73 3a 0a 2a 2a 0a 2a 2a 20 20 20 20 20  this:.**.**     
10050 20 23 21 2f 75 73 72 2f 62 69 6e 2f 66 6f 73 73   #!/usr/bin/foss
10060 69 6c 0a 2a 2a 20 20 20 20 20 20 72 65 70 6f 73  il.**      repos
10070 69 74 6f 72 79 3a 20 2f 68 6f 6d 65 2f 73 6f 6d  itory: /home/som
10080 65 62 6f 64 79 2f 70 72 6f 6a 65 63 74 2e 64 62  ebody/project.db
10090 0a 2a 2a 0a 2a 2a 20 54 68 65 20 63 6f 6d 6d 61  .**.** The comma
100a0 6e 64 20 6e 61 6d 65 2c 20 22 63 67 69 22 2c 20  nd name, "cgi", 
100b0 6d 61 79 20 62 65 20 6f 6d 69 74 74 65 64 20 69  may be omitted i
100c0 66 20 74 68 65 20 47 41 54 45 57 41 59 5f 49 4e  f the GATEWAY_IN
100d0 54 45 52 46 41 43 45 0a 2a 2a 20 65 6e 76 69 72  TERFACE.** envir
100e0 6f 6e 6d 65 6e 74 20 76 61 72 69 61 62 6c 65 20  onment variable 
100f0 69 73 20 73 65 74 20 74 6f 20 22 43 47 49 22 2c  is set to "CGI",
10100 20 77 68 69 63 68 20 73 68 6f 75 6c 64 20 61 6c   which should al
10110 77 61 79 73 20 62 65 20 74 68 65 0a 2a 2a 20 63  ways be the.** c
10120 61 73 65 20 66 6f 72 20 43 47 49 20 73 63 72 69  ase for CGI scri
10130 70 74 73 20 72 75 6e 20 62 79 20 61 20 77 65 62  pts run by a web
10140 73 65 72 76 65 72 2e 20 20 46 6f 73 73 69 6c 20  server.  Fossil 
10150 69 67 6e 6f 72 65 73 20 61 6e 79 20 6c 69 6e 65  ignores any line
10160 73 0a 2a 2a 20 74 68 61 74 20 62 65 67 69 6e 20  s.** that begin 
10170 77 69 74 68 20 22 23 22 2e 0a 2a 2a 0a 2a 2a 20  with "#"..**.** 
10180 54 68 65 20 66 6f 6c 6c 6f 77 69 6e 67 20 63 6f  The following co
10190 6e 74 72 6f 6c 20 6c 69 6e 65 73 20 61 72 65 20  ntrol lines are 
101a0 72 65 63 6f 67 6e 69 7a 65 64 3a 0a 2a 2a 0a 2a  recognized:.**.*
101b0 2a 20 20 20 20 72 65 70 6f 73 69 74 6f 72 79 3a  *    repository:
101c0 20 50 41 54 48 20 20 20 20 20 20 20 20 20 4e 61   PATH         Na
101d0 6d 65 20 6f 66 20 74 68 65 20 46 6f 73 73 69 6c  me of the Fossil
101e0 20 72 65 70 6f 73 69 74 6f 72 79 0a 2a 2a 0a 2a   repository.**.*
101f0 2a 20 20 20 20 64 69 72 65 63 74 6f 72 79 3a 20  *    directory: 
10200 20 50 41 54 48 20 20 20 20 20 20 20 20 20 4e 61   PATH         Na
10210 6d 65 20 6f 66 20 61 20 64 69 72 65 63 74 6f 72  me of a director
10220 79 20 63 6f 6e 74 61 69 6e 69 6e 67 20 6d 61 6e  y containing man
10230 79 20 46 6f 73 73 69 6c 0a 2a 2a 20 20 20 20 20  y Fossil.**     
10240 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
10250 20 20 20 20 20 20 20 20 72 65 70 6f 73 69 74 6f          reposito
10260 72 69 65 73 20 77 68 6f 73 65 20 6e 61 6d 65 73  ries whose names
10270 20 61 6c 6c 20 65 6e 64 20 77 69 74 68 20 22 2e   all end with ".
10280 66 6f 73 73 69 6c 22 2e 0a 2a 2a 20 20 20 20 20  fossil"..**     
10290 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
102a0 20 20 20 20 20 20 20 20 54 68 65 72 65 20 73 68          There sh
102b0 6f 75 6c 64 20 6f 6e 6c 79 20 62 65 20 6f 6e 65  ould only be one
102c0 20 6f 66 20 22 72 65 70 6f 73 69 74 6f 72 79 3a   of "repository:
102d0 22 0a 2a 2a 20 20 20 20 20 20 20 20 20 20 20 20  ".**            
102e0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
102f0 20 6f 72 20 22 64 69 72 65 63 74 6f 72 79 3a 22   or "directory:"
10300 0a 2a 2a 0a 2a 2a 20 20 20 20 6e 6f 74 66 6f 75  .**.**    notfou
10310 6e 64 3a 20 55 52 4c 20 20 20 20 20 20 20 20 20  nd: URL         
10320 20 20 20 57 68 65 6e 20 69 6e 20 22 64 69 72 65     When in "dire
10330 63 74 6f 72 79 3a 22 20 6d 6f 64 65 2c 20 72 65  ctory:" mode, re
10340 64 69 72 65 63 74 20 74 6f 0a 2a 2a 20 20 20 20  direct to.**    
10350 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
10360 20 20 20 20 20 20 20 20 20 55 52 4c 20 69 66 20           URL if 
10370 6e 6f 20 73 75 69 74 61 62 6c 65 20 72 65 70 6f  no suitable repo
10380 73 69 74 6f 72 79 20 69 73 20 66 6f 75 6e 64 2e  sitory is found.
10390 0a 2a 2a 0a 2a 2a 20 20 20 20 72 65 70 6f 6c 69  .**.**    repoli
103a0 73 74 20 20 20 20 20 20 20 20 20 20 20 20 20 20  st              
103b0 20 20 20 57 68 65 6e 20 69 6e 20 22 64 69 72 65     When in "dire
103c0 63 74 6f 72 79 3a 22 20 6d 6f 64 65 2c 20 64 69  ctory:" mode, di
103d0 73 70 6c 61 79 20 61 20 70 61 67 65 0a 2a 2a 20  splay a page.** 
103e0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
103f0 20 20 20 20 20 20 20 20 20 20 20 20 73 68 6f 77              show
10400 69 6e 67 20 61 20 6c 69 73 74 20 6f 66 20 61 76  ing a list of av
10410 61 69 6c 61 62 6c 65 20 72 65 70 6f 73 69 74 6f  ailable reposito
10420 72 69 65 73 20 69 66 0a 2a 2a 20 20 20 20 20 20  ries if.**      
10430 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
10440 20 20 20 20 20 20 20 74 68 65 20 55 52 4c 20 69         the URL i
10450 73 20 22 2f 22 2e 0a 2a 2a 0a 2a 2a 20 20 20 20  s "/"..**.**    
10460 6c 6f 63 61 6c 61 75 74 68 20 20 20 20 20 20 20  localauth       
10470 20 20 20 20 20 20 20 20 20 47 72 61 6e 74 20 61           Grant a
10480 64 6d 69 6e 69 73 74 72 61 74 6f 72 20 70 72 69  dministrator pri
10490 76 69 6c 65 67 65 73 20 74 6f 20 63 6f 6e 6e 65  vileges to conne
104a0 63 74 69 6f 6e 73 0a 2a 2a 20 20 20 20 20 20 20  ctions.**       
104b0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
104c0 20 20 20 20 20 20 66 72 6f 6d 20 31 32 37 2e 30        from 127.0
104d0 2e 30 2e 31 20 6f 72 20 3a 3a 31 2e 0a 2a 2a 0a  .0.1 or ::1..**.
104e0 2a 2a 20 20 20 20 73 6b 69 6e 3a 20 4c 41 42 45  **    skin: LABE
104f0 4c 20 20 20 20 20 20 20 20 20 20 20 20 20 20 55  L              U
10500 73 65 20 74 68 65 20 62 75 69 6c 74 2d 69 6e 20  se the built-in 
10510 73 6b 69 6e 20 63 61 6c 6c 65 64 20 4c 41 42 45  skin called LABE
10520 4c 20 72 61 74 68 65 72 20 74 68 61 6e 0a 2a 2a  L rather than.**
10530 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
10540 20 20 20 20 20 20 20 20 20 20 20 20 20 74 68 65               the
10550 20 64 65 66 61 75 6c 74 2e 20 20 49 66 20 74 68   default.  If th
10560 65 72 65 20 61 72 65 20 6e 6f 20 73 6b 69 6e 73  ere are no skins
10570 20 63 61 6c 6c 65 64 20 4c 41 42 45 4c 0a 2a 2a   called LABEL.**
10580 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
10590 20 20 20 20 20 20 20 20 20 20 20 20 20 74 68 65               the
105a0 6e 20 74 68 69 73 20 6c 69 6e 65 20 69 73 20 61  n this line is a
105b0 20 6e 6f 2d 6f 70 2e 0a 2a 2a 0a 2a 2a 20 20 20   no-op..**.**   
105c0 20 66 69 6c 65 73 3a 20 47 4c 4f 42 4c 49 53 54   files: GLOBLIST
105d0 20 20 20 20 20 20 20 20 20 20 47 4c 4f 42 4c 49            GLOBLI
105e0 53 54 20 69 73 20 61 20 63 6f 6d 6d 61 2d 73 65  ST is a comma-se
105f0 70 61 72 61 74 65 64 20 6c 69 73 74 20 6f 66 20  parated list of 
10600 47 4c 4f 42 0a 2a 2a 20 20 20 20 20 20 20 20 20  GLOB.**         
10610 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
10620 20 20 20 20 70 61 74 74 65 72 6e 73 20 74 68 61      patterns tha
10630 74 20 73 70 65 63 69 66 79 20 66 69 6c 65 73 20  t specify files 
10640 74 68 61 74 20 63 61 6e 20 62 65 0a 2a 2a 20 20  that can be.**  
10650 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
10660 20 20 20 20 20 20 20 20 20 20 20 72 65 74 75 72             retur
10670 6e 65 64 20 76 65 72 62 61 74 69 6d 2e 20 20 54  ned verbatim.  T
10680 68 69 73 20 66 65 61 74 75 72 65 20 61 6c 6c 6f  his feature allo
10690 77 73 20 46 6f 73 73 69 6c 0a 2a 2a 20 20 20 20  ws Fossil.**    
106a0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
106b0 20 20 20 20 20 20 20 20 20 74 6f 20 61 63 74 20           to act 
106c0 61 73 20 61 20 77 65 62 20 73 65 72 76 65 72 20  as a web server 
106d0 72 65 74 75 72 6e 69 6e 67 20 73 74 61 74 69 63  returning static
106e0 0a 2a 2a 20 20 20 20 20 20 20 20 20 20 20 20 20  .**             
106f0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
10700 63 6f 6e 74 65 6e 74 2e 0a 2a 2a 0a 2a 2a 20 20  content..**.**  
10710 20 20 73 65 74 65 6e 76 3a 20 4e 41 4d 45 20 56    setenv: NAME V
10720 41 4c 55 45 20 20 20 20 20 20 20 53 65 74 20 65  ALUE       Set e
10730 6e 76 69 72 6f 6e 6d 65 6e 74 20 76 61 72 69 61  nvironment varia
10740 62 6c 65 20 4e 41 4d 45 20 74 6f 20 56 41 4c 55  ble NAME to VALU
10750 45 2e 20 20 4f 72 0a 2a 2a 20 20 20 20 20 20 20  E.  Or.**       
10760 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
10770 20 20 20 20 20 20 69 66 20 56 41 4c 55 45 20 69        if VALUE i
10780 73 20 6f 6d 69 74 74 65 64 2c 20 75 6e 73 65 74  s omitted, unset
10790 20 4e 41 4d 45 2e 0a 2a 2a 0a 2a 2a 20 20 20 20   NAME..**.**    
107a0 48 4f 4d 45 3a 20 50 41 54 48 20 20 20 20 20 20  HOME: PATH      
107b0 20 20 20 20 20 20 20 20 20 53 68 6f 72 74 68 61           Shortha
107c0 6e 64 20 66 6f 72 20 22 73 65 74 65 6e 76 3a 20  nd for "setenv: 
107d0 48 4f 4d 45 20 50 41 54 48 22 0a 2a 2a 0a 2a 2a  HOME PATH".**.**
107e0 20 20 20 20 64 65 62 75 67 3a 20 46 49 4c 45 20      debug: FILE 
107f0 20 20 20 20 20 20 20 20 20 20 20 20 20 43 61 75               Cau
10800 73 69 6e 67 20 64 65 62 75 67 67 69 6e 67 20 69  sing debugging i
10810 6e 66 6f 72 6d 61 74 69 6f 6e 20 74 6f 20 62 65  nformation to be
10820 20 77 72 69 74 74 65 6e 0a 2a 2a 20 20 20 20 20   written.**     
10830 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
10840 20 20 20 20 20 20 20 20 69 6e 74 6f 20 46 49 4c          into FIL
10850 45 2e 0a 2a 2a 0a 2a 2a 20 20 20 20 65 72 72 6f  E..**.**    erro
10860 72 6c 6f 67 3a 20 46 49 4c 45 20 20 20 20 20 20  rlog: FILE      
10870 20 20 20 20 20 57 61 72 6e 69 6e 67 73 2c 20 65       Warnings, e
10880 72 72 6f 72 73 2c 20 61 6e 64 20 70 61 6e 69 63  rrors, and panic
10890 73 20 77 72 69 74 74 65 6e 20 74 6f 20 46 49 4c  s written to FIL
108a0 45 2e 0a 2a 2a 0a 2a 2a 20 20 20 20 65 78 74 72  E..**.**    extr
108b0 6f 6f 74 3a 20 44 49 52 20 20 20 20 20 20 20 20  oot: DIR        
108c0 20 20 20 20 20 44 69 72 65 63 74 6f 72 79 20 74       Directory t
108d0 68 61 74 20 69 73 20 74 68 65 20 72 6f 6f 74 20  hat is the root 
108e0 6f 66 20 74 68 65 20 73 75 62 2d 43 47 49 20 74  of the sub-CGI t
108f0 72 65 65 0a 2a 2a 20 20 20 20 20 20 20 20 20 20  ree.**          
10900 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
10910 20 20 20 6f 6e 20 74 68 65 20 2f 65 78 74 20 70     on the /ext p
10920 61 67 65 2e 0a 2a 2a 0a 2a 2a 20 20 20 20 72 65  age..**.**    re
10930 64 69 72 65 63 74 3a 20 52 45 50 4f 20 55 52 4c  direct: REPO URL
10940 20 20 20 20 20 20 20 45 78 74 72 61 63 74 20 74         Extract t
10950 68 65 20 22 6e 61 6d 65 22 20 71 75 65 72 79 20  he "name" query 
10960 70 61 72 61 6d 65 74 65 72 20 61 6e 64 20 73 65  parameter and se
10970 61 72 63 68 0a 2a 2a 20 20 20 20 20 20 20 20 20  arch.**         
10980 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
10990 20 20 20 20 52 45 50 4f 20 66 6f 72 20 61 20 63      REPO for a c
109a0 68 65 63 6b 2d 69 6e 20 6f 72 20 74 69 63 6b 65  heck-in or ticke
109b0 74 20 74 68 61 74 20 6d 61 74 63 68 65 73 20 74  t that matches t
109c0 68 65 0a 2a 2a 20 20 20 20 20 20 20 20 20 20 20  he.**           
109d0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
109e0 20 20 76 61 6c 75 65 20 6f 66 20 22 6e 61 6d 65    value of "name
109f0 22 2c 20 74 68 65 6e 20 72 65 64 69 72 65 63 74  ", then redirect
10a00 20 74 6f 20 55 52 4c 2e 20 20 54 68 65 72 65 0a   to URL.  There.
10a10 2a 2a 20 20 20 20 20 20 20 20 20 20 20 20 20 20  **              
10a20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 63                 c
10a30 61 6e 20 62 65 20 6d 75 6c 74 69 70 6c 65 20 22  an be multiple "
10a40 72 65 64 69 72 65 63 74 3a 22 20 6c 69 6e 65 73  redirect:" lines
10a50 20 74 68 61 74 20 61 72 65 0a 2a 2a 20 20 20 20   that are.**    
10a60 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
10a70 20 20 20 20 20 20 20 20 20 70 72 6f 63 65 73 73           process
10a80 65 64 20 69 6e 20 6f 72 64 65 72 2e 20 20 49 66  ed in order.  If
10a90 20 74 68 65 20 52 45 50 4f 20 69 73 20 22 2a 22   the REPO is "*"
10aa0 2c 20 74 68 65 6e 0a 2a 2a 20 20 20 20 20 20 20  , then.**       
10ab0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
10ac0 20 20 20 20 20 20 61 6e 20 75 6e 63 6f 6e 64 69        an uncondi
10ad0 74 69 6f 6e 61 6c 20 72 65 64 69 72 65 63 74 20  tional redirect 
10ae0 74 6f 20 55 52 4c 20 69 73 20 74 61 6b 65 6e 2e  to URL is taken.
10af0 0a 2a 2a 0a 2a 2a 20 4d 6f 73 74 20 43 47 49 20  .**.** Most CGI 
10b00 66 69 6c 65 73 20 63 6f 6e 74 61 69 6e 20 6f 6e  files contain on
10b10 6c 79 20 61 20 22 72 65 70 6f 73 69 74 6f 72 79  ly a "repository
10b20 3a 22 20 6c 69 6e 65 2e 20 20 49 74 20 69 73 20  :" line.  It is 
10b30 75 6e 63 6f 6d 6d 6f 6e 20 74 6f 0a 2a 2a 20 75  uncommon to.** u
10b40 73 65 20 61 6e 79 20 6f 74 68 65 72 20 6f 70 74  se any other opt
10b50 69 6f 6e 2e 0a 2a 2a 0a 2a 2a 20 53 65 65 20 61  ion..**.** See a
10b60 6c 73 6f 3a 20 68 74 74 70 2c 20 73 65 72 76 65  lso: http, serve
10b70 72 2c 20 77 69 6e 73 72 76 0a 2a 2f 0a 76 6f 69  r, winsrv.*/.voi
10b80 64 20 63 6d 64 5f 63 67 69 28 76 6f 69 64 29 7b  d cmd_cgi(void){
10b90 0a 20 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a  .  const char *z
10ba0 46 69 6c 65 3b 0a 20 20 63 6f 6e 73 74 20 63 68  File;.  const ch
10bb0 61 72 20 2a 7a 4e 6f 74 46 6f 75 6e 64 20 3d 20  ar *zNotFound = 
10bc0 30 3b 0a 20 20 63 68 61 72 20 2a 2a 61 7a 52 65  0;.  char **azRe
10bd0 64 69 72 65 63 74 20 3d 20 30 3b 20 20 20 20 20  direct = 0;     
10be0 20 20 20 20 20 20 20 20 2f 2a 20 4c 69 73 74 20          /* List 
10bf0 6f 66 20 72 65 70 6f 73 69 74 6f 72 69 65 73 20  of repositories 
10c00 74 6f 20 72 65 64 69 72 65 63 74 20 74 6f 20 2a  to redirect to *
10c10 2f 0a 20 20 69 6e 74 20 6e 52 65 64 69 72 65 63  /.  int nRedirec
10c20 74 20 3d 20 30 3b 20 20 20 20 20 20 20 20 20 20  t = 0;          
10c30 20 20 20 20 20 20 20 2f 2a 20 4e 75 6d 62 65 72         /* Number
10c40 20 6f 66 20 65 6e 74 72 69 65 73 20 69 6e 20 61   of entries in a
10c50 7a 52 65 64 69 72 65 63 74 20 2a 2f 0a 20 20 47  zRedirect */.  G
10c60 6c 6f 62 20 2a 70 46 69 6c 65 47 6c 6f 62 20 3d  lob *pFileGlob =
10c70 20 30 3b 20 20 20 20 20 20 20 20 20 20 20 20 20   0;             
10c80 20 20 2f 2a 20 50 61 74 74 65 72 6e 20 66 6f 72    /* Pattern for
10c90 20 66 69 6c 65 73 20 2a 2f 0a 20 20 69 6e 74 20   files */.  int 
10ca0 61 6c 6c 6f 77 52 65 70 6f 4c 69 73 74 20 3d 20  allowRepoList = 
10cb0 30 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 2f  0;             /
10cc0 2a 20 41 6c 6c 6f 77 20 6c 69 73 74 73 20 6f 66  * Allow lists of
10cd0 20 72 65 70 6f 73 69 74 6f 72 79 20 66 69 6c 65   repository file
10ce0 73 20 2a 2f 0a 20 20 42 6c 6f 62 20 63 6f 6e 66  s */.  Blob conf
10cf0 69 67 2c 20 6c 69 6e 65 2c 20 6b 65 79 2c 20 76  ig, line, key, v
10d00 61 6c 75 65 2c 20 76 61 6c 75 65 32 3b 0a 20 20  alue, value2;.  
10d10 69 66 28 20 67 2e 61 72 67 63 3d 3d 33 20 26 26  if( g.argc==3 &&
10d20 20 66 6f 73 73 69 6c 5f 73 74 72 63 6d 70 28 67   fossil_strcmp(g
10d30 2e 61 72 67 76 5b 31 5d 2c 22 63 67 69 22 29 3d  .argv[1],"cgi")=
10d40 3d 30 20 29 7b 0a 20 20 20 20 7a 46 69 6c 65 20  =0 ){.    zFile 
10d50 3d 20 67 2e 61 72 67 76 5b 32 5d 3b 0a 20 20 7d  = g.argv[2];.  }
10d60 65 6c 73 65 7b 0a 20 20 20 20 7a 46 69 6c 65 20  else{.    zFile 
10d70 3d 20 67 2e 61 72 67 76 5b 31 5d 3b 0a 20 20 7d  = g.argv[1];.  }
10d80 0a 20 20 67 2e 68 74 74 70 4f 75 74 20 3d 20 73  .  g.httpOut = s
10d90 74 64 6f 75 74 3b 0a 20 20 67 2e 68 74 74 70 49  tdout;.  g.httpI
10da0 6e 20 3d 20 73 74 64 69 6e 3b 0a 20 20 66 6f 73  n = stdin;.  fos
10db0 73 69 6c 5f 62 69 6e 61 72 79 5f 6d 6f 64 65 28  sil_binary_mode(
10dc0 67 2e 68 74 74 70 4f 75 74 29 3b 0a 20 20 66 6f  g.httpOut);.  fo
10dd0 73 73 69 6c 5f 62 69 6e 61 72 79 5f 6d 6f 64 65  ssil_binary_mode
10de0 28 67 2e 68 74 74 70 49 6e 29 3b 0a 20 20 67 2e  (g.httpIn);.  g.
10df0 63 67 69 4f 75 74 70 75 74 20 3d 20 31 3b 0a 20  cgiOutput = 1;. 
10e00 20 62 6c 6f 62 5f 72 65 61 64 5f 66 72 6f 6d 5f   blob_read_from_
10e10 66 69 6c 65 28 26 63 6f 6e 66 69 67 2c 20 7a 46  file(&config, zF
10e20 69 6c 65 2c 20 45 78 74 46 49 4c 45 29 3b 0a 20  ile, ExtFILE);. 
10e30 20 77 68 69 6c 65 28 20 62 6c 6f 62 5f 6c 69 6e   while( blob_lin
10e40 65 28 26 63 6f 6e 66 69 67 2c 20 26 6c 69 6e 65  e(&config, &line
10e50 29 20 29 7b 0a 20 20 20 20 69 66 28 20 21 62 6c  ) ){.    if( !bl
10e60 6f 62 5f 74 6f 6b 65 6e 28 26 6c 69 6e 65 2c 20  ob_token(&line, 
10e70 26 6b 65 79 29 20 29 20 63 6f 6e 74 69 6e 75 65  &key) ) continue
10e80 3b 0a 20 20 20 20 69 66 28 20 62 6c 6f 62 5f 62  ;.    if( blob_b
10e90 75 66 66 65 72 28 26 6b 65 79 29 5b 30 5d 3d 3d  uffer(&key)[0]==
10ea0 27 23 27 20 29 20 63 6f 6e 74 69 6e 75 65 3b 0a  '#' ) continue;.
10eb0 20 20 20 20 69 66 28 20 62 6c 6f 62 5f 65 71 28      if( blob_eq(
10ec0 26 6b 65 79 2c 20 22 72 65 70 6f 73 69 74 6f 72  &key, "repositor
10ed0 79 3a 22 29 20 26 26 20 62 6c 6f 62 5f 74 61 69  y:") && blob_tai
10ee0 6c 28 26 6c 69 6e 65 2c 20 26 76 61 6c 75 65 29  l(&line, &value)
10ef0 20 29 7b 0a 20 20 20 20 20 20 2f 2a 20 72 65 70   ){.      /* rep
10f00 6f 73 69 74 6f 72 79 3a 20 46 49 4c 45 4e 41 4d  ository: FILENAM
10f10 45 0a 20 20 20 20 20 20 2a 2a 0a 20 20 20 20 20  E.      **.     
10f20 20 2a 2a 20 54 68 65 20 6e 61 6d 65 20 6f 66 20   ** The name of 
10f30 74 68 65 20 46 6f 73 73 69 6c 20 72 65 70 6f 73  the Fossil repos
10f40 69 74 6f 72 79 20 74 6f 20 62 65 20 73 65 72 76  itory to be serv
10f50 65 64 20 76 69 61 20 43 47 49 2e 20 20 4d 6f 73  ed via CGI.  Mos
10f60 74 0a 20 20 20 20 20 20 2a 2a 20 66 6f 73 73 69  t.      ** fossi
10f70 6c 20 43 47 49 20 73 63 72 69 70 74 73 20 68 61  l CGI scripts ha
10f80 76 65 20 61 20 73 69 6e 67 6c 65 20 6e 6f 6e 2d  ve a single non-
10f90 63 6f 6d 6d 65 6e 74 20 6c 69 6e 65 20 74 68 61  comment line tha
10fa0 74 20 63 6f 6e 74 61 69 6e 73 0a 20 20 20 20 20  t contains.     
10fb0 20 2a 2a 20 74 68 69 73 20 6f 6e 65 20 65 6e 74   ** this one ent
10fc0 72 79 2e 0a 20 20 20 20 20 20 2a 2f 0a 20 20 20  ry..      */.   
10fd0 20 20 20 62 6c 6f 62 5f 74 72 69 6d 28 26 76 61     blob_trim(&va
10fe0 6c 75 65 29 3b 0a 20 20 20 20 20 20 64 62 5f 6f  lue);.      db_o
10ff0 70 65 6e 5f 72 65 70 6f 73 69 74 6f 72 79 28 62  pen_repository(b
11000 6c 6f 62 5f 73 74 72 28 26 76 61 6c 75 65 29 29  lob_str(&value))
11010 3b 0a 20 20 20 20 20 20 62 6c 6f 62 5f 72 65 73  ;.      blob_res
11020 65 74 28 26 76 61 6c 75 65 29 3b 0a 20 20 20 20  et(&value);.    
11030 20 20 63 6f 6e 74 69 6e 75 65 3b 0a 20 20 20 20    continue;.    
11040 7d 0a 20 20 20 20 69 66 28 20 62 6c 6f 62 5f 65  }.    if( blob_e
11050 71 28 26 6b 65 79 2c 20 22 64 69 72 65 63 74 6f  q(&key, "directo
11060 72 79 3a 22 29 20 26 26 20 62 6c 6f 62 5f 74 6f  ry:") && blob_to
11070 6b 65 6e 28 26 6c 69 6e 65 2c 20 26 76 61 6c 75  ken(&line, &valu
11080 65 29 20 29 7b 0a 20 20 20 20 20 20 2f 2a 20 64  e) ){.      /* d
11090 69 72 65 63 74 6f 72 79 3a 20 44 49 52 45 43 54  irectory: DIRECT
110a0 4f 52 59 0a 20 20 20 20 20 20 2a 2a 0a 20 20 20  ORY.      **.   
110b0 20 20 20 2a 2a 20 49 66 20 72 65 70 6f 73 69 74     ** If reposit
110c0 6f 72 79 3a 20 69 73 20 6f 6d 69 74 74 65 64 2c  ory: is omitted,
110d0 20 74 68 65 6e 20 74 65 72 6d 73 20 6f 66 20 74   then terms of t
110e0 68 65 20 50 41 54 48 5f 49 4e 46 4f 20 63 67 69  he PATH_INFO cgi
110f0 20 70 61 72 61 6d 65 74 65 72 0a 20 20 20 20 20   parameter.     
11100 20 2a 2a 20 61 72 65 20 61 70 70 65 6e 64 65 64   ** are appended
11110 20 74 6f 20 44 49 52 45 43 54 4f 52 59 20 6c 6f   to DIRECTORY lo
11120 6f 6b 69 6e 67 20 66 6f 72 20 61 20 72 65 70 6f  oking for a repo
11130 73 69 74 6f 72 79 20 28 77 68 6f 73 65 20 6e 61  sitory (whose na
11140 6d 65 20 65 6e 64 73 0a 20 20 20 20 20 20 2a 2a  me ends.      **
11150 20 69 6e 20 22 2e 66 6f 73 73 69 6c 22 29 20 6f   in ".fossil") o
11160 72 20 61 20 66 69 6c 65 20 69 6e 20 22 66 69 6c  r a file in "fil
11170 65 73 3a 22 2e 0a 20 20 20 20 20 20 2a 2f 0a 20  es:"..      */. 
11180 20 20 20 20 20 64 62 5f 63 6c 6f 73 65 28 31 29       db_close(1)
11190 3b 0a 20 20 20 20 20 20 67 2e 7a 52 65 70 6f 73  ;.      g.zRepos
111a0 69 74 6f 72 79 4e 61 6d 65 20 3d 20 6d 70 72 69  itoryName = mpri
111b0 6e 74 66 28 22 25 73 22 2c 20 62 6c 6f 62 5f 73  ntf("%s", blob_s
111c0 74 72 28 26 76 61 6c 75 65 29 29 3b 0a 20 20 20  tr(&value));.   
111d0 20 20 20 62 6c 6f 62 5f 72 65 73 65 74 28 26 76     blob_reset(&v
111e0 61 6c 75 65 29 3b 0a 20 20 20 20 20 20 63 6f 6e  alue);.      con
111f0 74 69 6e 75 65 3b 0a 20 20 20 20 7d 0a 20 20 20  tinue;.    }.   
11200 20 69 66 28 20 62 6c 6f 62 5f 65 71 28 26 6b 65   if( blob_eq(&ke
11210 79 2c 20 22 6e 6f 74 66 6f 75 6e 64 3a 22 29 20  y, "notfound:") 
11220 26 26 20 62 6c 6f 62 5f 74 6f 6b 65 6e 28 26 6c  && blob_token(&l
11230 69 6e 65 2c 20 26 76 61 6c 75 65 29 20 29 7b 0a  ine, &value) ){.
11240 20 20 20 20 20 20 2f 2a 20 6e 6f 74 66 6f 75 6e        /* notfoun
11250 64 3a 20 55 52 4c 0a 20 20 20 20 20 20 2a 2a 0a  d: URL.      **.
11260 20 20 20 20 20 20 2a 2a 20 49 66 20 75 73 69 6e        ** If usin
11270 67 20 64 69 72 65 63 74 6f 72 79 3a 20 61 6e 64  g directory: and
11280 20 6e 6f 20 73 75 69 74 61 62 6c 65 20 72 65 70   no suitable rep
11290 6f 73 69 74 6f 72 79 20 6f 72 20 66 69 6c 65 20  ository or file 
112a0 69 73 20 66 6f 75 6e 64 2c 0a 20 20 20 20 20 20  is found,.      
112b0 2a 2a 20 74 68 65 6e 20 72 65 64 69 72 65 63 74  ** then redirect
112c0 20 74 6f 20 55 52 4c 2e 0a 20 20 20 20 20 20 2a   to URL..      *
112d0 2f 0a 20 20 20 20 20 20 7a 4e 6f 74 46 6f 75 6e  /.      zNotFoun
112e0 64 20 3d 20 6d 70 72 69 6e 74 66 28 22 25 73 22  d = mprintf("%s"
112f0 2c 20 62 6c 6f 62 5f 73 74 72 28 26 76 61 6c 75  , blob_str(&valu
11300 65 29 29 3b 0a 20 20 20 20 20 20 62 6c 6f 62 5f  e));.      blob_
11310 72 65 73 65 74 28 26 76 61 6c 75 65 29 3b 0a 20  reset(&value);. 
11320 20 20 20 20 20 63 6f 6e 74 69 6e 75 65 3b 0a 20       continue;. 
11330 20 20 20 7d 0a 20 20 20 20 69 66 28 20 62 6c 6f     }.    if( blo
11340 62 5f 65 71 28 26 6b 65 79 2c 20 22 6c 6f 63 61  b_eq(&key, "loca
11350 6c 61 75 74 68 22 29 20 29 7b 0a 20 20 20 20 20  lauth") ){.     
11360 20 2f 2a 20 6c 6f 63 61 6c 61 75 74 68 0a 20 20   /* localauth.  
11370 20 20 20 20 2a 2a 0a 20 20 20 20 20 20 2a 2a 20      **.      ** 
11380 47 72 61 6e 74 20 22 61 64 6d 69 6e 69 73 74 72  Grant "administr
11390 61 74 6f 72 22 20 70 72 69 76 69 6c 65 67 65 73  ator" privileges
113a0 20 74 6f 20 75 73 65 72 73 20 63 6f 6e 6e 65 63   to users connec
113b0 74 69 6e 67 20 77 69 74 68 20 48 54 54 50 0a 20  ting with HTTP. 
113c0 20 20 20 20 20 2a 2a 20 66 72 6f 6d 20 49 50 20       ** from IP 
113d0 61 64 64 72 65 73 73 20 31 32 37 2e 30 2e 30 2e  address 127.0.0.
113e0 31 2e 20 20 44 6f 20 6e 6f 74 20 62 6f 74 68 65  1.  Do not bothe
113f0 72 20 63 68 65 63 6b 69 6e 67 20 63 72 65 64 65  r checking crede
11400 6e 74 69 61 6c 73 2e 0a 20 20 20 20 20 20 2a 2f  ntials..      */
11410 0a 20 20 20 20 20 20 67 2e 75 73 65 4c 6f 63 61  .      g.useLoca
11420 6c 61 75 74 68 20 3d 20 31 3b 0a 20 20 20 20 20  lauth = 1;.     
11430 20 63 6f 6e 74 69 6e 75 65 3b 0a 20 20 20 20 7d   continue;.    }
11440 0a 20 20 20 20 69 66 28 20 62 6c 6f 62 5f 65 71  .    if( blob_eq
11450 28 26 6b 65 79 2c 20 22 72 65 70 6f 6c 69 73 74  (&key, "repolist
11460 22 29 20 29 7b 0a 20 20 20 20 20 20 2f 2a 20 72  ") ){.      /* r
11470 65 70 6f 6c 69 73 74 0a 20 20 20 20 20 20 2a 2a  epolist.      **
11480 0a 20 20 20 20 20 20 2a 2a 20 49 66 20 75 73 69  .      ** If usi
11490 6e 67 20 22 64 69 72 65 63 74 6f 72 79 3a 22 20  ng "directory:" 
114a0 61 6e 64 20 74 68 65 20 55 52 4c 20 69 73 20 22  and the URL is "
114b0 2f 22 20 74 68 65 6e 20 67 65 6e 65 72 61 74 65  /" then generate
114c0 20 61 20 70 61 67 65 0a 20 20 20 20 20 20 2a 2a   a page.      **
114d0 20 73 68 6f 77 69 6e 67 20 61 20 6c 69 73 74 20   showing a list 
114e0 6f 66 20 61 76 61 69 6c 61 62 6c 65 20 72 65 70  of available rep
114f0 6f 73 69 74 6f 72 69 65 73 2e 0a 20 20 20 20 20  ositories..     
11500 20 2a 2f 0a 20 20 20 20 20 20 61 6c 6c 6f 77 52   */.      allowR
11510 65 70 6f 4c 69 73 74 20 3d 20 31 3b 0a 20 20 20  epoList = 1;.   
11520 20 20 20 63 6f 6e 74 69 6e 75 65 3b 0a 20 20 20     continue;.   
11530 20 7d 0a 20 20 20 20 69 66 28 20 62 6c 6f 62 5f   }.    if( blob_
11540 65 71 28 26 6b 65 79 2c 20 22 72 65 64 69 72 65  eq(&key, "redire
11550 63 74 3a 22 29 20 26 26 20 62 6c 6f 62 5f 74 6f  ct:") && blob_to
11560 6b 65 6e 28 26 6c 69 6e 65 2c 20 26 76 61 6c 75  ken(&line, &valu
11570 65 29 0a 20 20 20 20 20 20 20 20 20 20 20 20 26  e).            &
11580 26 20 62 6c 6f 62 5f 74 6f 6b 65 6e 28 26 6c 69  & blob_token(&li
11590 6e 65 2c 20 26 76 61 6c 75 65 32 29 20 29 7b 0a  ne, &value2) ){.
115a0 20 20 20 20 20 20 2f 2a 20 53 65 65 20 74 68 65        /* See the
115b0 20 68 65 61 64 65 72 20 63 6f 6d 6d 65 6e 74 20   header comment 
115c0 6f 6e 20 74 68 65 20 72 65 64 69 72 65 63 74 5f  on the redirect_
115d0 77 65 62 5f 70 61 67 65 28 29 20 66 75 6e 63 74  web_page() funct
115e0 69 6f 6e 0a 20 20 20 20 20 20 2a 2a 20 61 62 6f  ion.      ** abo
115f0 76 65 20 66 6f 72 20 64 65 74 61 69 6c 73 2e 20  ve for details. 
11600 2a 2f 0a 20 20 20 20 20 20 6e 52 65 64 69 72 65  */.      nRedire
11610 63 74 2b 2b 3b 0a 20 20 20 20 20 20 61 7a 52 65  ct++;.      azRe
11620 64 69 72 65 63 74 20 3d 20 66 6f 73 73 69 6c 5f  direct = fossil_
11630 72 65 61 6c 6c 6f 63 28 61 7a 52 65 64 69 72 65  realloc(azRedire
11640 63 74 2c 20 32 2a 6e 52 65 64 69 72 65 63 74 2a  ct, 2*nRedirect*
11650 73 69 7a 65 6f 66 28 63 68 61 72 2a 29 29 3b 0a  sizeof(char*));.
11660 20 20 20 20 20 20 61 7a 52 65 64 69 72 65 63 74        azRedirect
11670 5b 6e 52 65 64 69 72 65 63 74 2a 32 2d 32 5d 20  [nRedirect*2-2] 
11680 3d 20 6d 70 72 69 6e 74 66 28 22 25 73 22 2c 20  = mprintf("%s", 
11690 62 6c 6f 62 5f 73 74 72 28 26 76 61 6c 75 65 29  blob_str(&value)
116a0 29 3b 0a 20 20 20 20 20 20 61 7a 52 65 64 69 72  );.      azRedir
116b0 65 63 74 5b 6e 52 65 64 69 72 65 63 74 2a 32 2d  ect[nRedirect*2-
116c0 31 5d 20 3d 20 6d 70 72 69 6e 74 66 28 22 25 73  1] = mprintf("%s
116d0 22 2c 20 62 6c 6f 62 5f 73 74 72 28 26 76 61 6c  ", blob_str(&val
116e0 75 65 32 29 29 3b 0a 20 20 20 20 20 20 62 6c 6f  ue2));.      blo
116f0 62 5f 72 65 73 65 74 28 26 76 61 6c 75 65 29 3b  b_reset(&value);
11700 0a 20 20 20 20 20 20 62 6c 6f 62 5f 72 65 73 65  .      blob_rese
11710 74 28 26 76 61 6c 75 65 32 29 3b 0a 20 20 20 20  t(&value2);.    
11720 20 20 63 6f 6e 74 69 6e 75 65 3b 0a 20 20 20 20    continue;.    
11730 7d 0a 20 20 20 20 69 66 28 20 62 6c 6f 62 5f 65  }.    if( blob_e
11740 71 28 26 6b 65 79 2c 20 22 66 69 6c 65 73 3a 22  q(&key, "files:"
11750 29 20 26 26 20 62 6c 6f 62 5f 74 6f 6b 65 6e 28  ) && blob_token(
11760 26 6c 69 6e 65 2c 20 26 76 61 6c 75 65 29 20 29  &line, &value) )
11770 7b 0a 20 20 20 20 20 20 2f 2a 20 66 69 6c 65 73  {.      /* files
11780 3a 20 47 4c 4f 42 4c 49 53 54 0a 20 20 20 20 20  : GLOBLIST.     
11790 20 2a 2a 0a 20 20 20 20 20 20 2a 2a 20 47 4c 4f   **.      ** GLO
117a0 42 4c 49 53 54 20 69 73 20 61 20 63 6f 6d 6d 61  BLIST is a comma
117b0 2d 73 65 70 61 72 61 74 65 64 20 6c 69 73 74 20  -separated list 
117c0 6f 66 20 66 69 6c 65 6e 61 6d 65 20 67 6c 6f 62  of filename glob
117d0 73 2e 20 20 46 6f 72 0a 20 20 20 20 20 20 2a 2a  s.  For.      **
117e0 20 65 78 61 6d 70 6c 65 3a 20 20 2a 2e 68 74 6d   example:  *.htm
117f0 6c 2c 2a 2e 63 73 73 2c 2a 2e 6a 73 0a 20 20 20  l,*.css,*.js.   
11800 20 20 20 2a 2a 0a 20 20 20 20 20 20 2a 2a 20 49     **.      ** I
11810 66 20 74 68 65 20 72 65 70 6f 73 69 74 6f 72 79  f the repository
11820 3a 20 6c 69 6e 65 20 69 73 20 6f 6d 69 74 74 65  : line is omitte
11830 64 20 61 6e 64 20 74 68 65 6e 20 50 41 54 48 5f  d and then PATH_
11840 49 4e 46 4f 20 69 73 20 73 65 61 72 63 68 65 64  INFO is searched
11850 0a 20 20 20 20 20 20 2a 2a 20 66 6f 72 20 66 69  .      ** for fi
11860 6c 65 73 20 74 68 61 74 20 6d 61 74 63 68 20 61  les that match a
11870 6e 79 20 6f 66 20 74 68 65 73 65 20 47 4c 4f 42  ny of these GLOB
11880 73 20 61 6e 64 20 69 66 20 61 6e 79 20 73 75 63  s and if any suc
11890 68 20 66 69 6c 65 20 69 73 0a 20 20 20 20 20 20  h file is.      
118a0 2a 2a 20 66 6f 75 6e 64 20 69 74 20 69 73 20 72  ** found it is r
118b0 65 74 75 72 6e 65 64 20 76 65 72 62 61 74 69 6d  eturned verbatim
118c0 2e 20 20 54 68 69 73 20 66 65 61 74 75 72 65 20  .  This feature 
118d0 61 6c 6c 6f 77 73 20 22 66 6f 73 73 69 6c 20 73  allows "fossil s
118e0 65 72 76 65 72 22 0a 20 20 20 20 20 20 2a 2a 20  erver".      ** 
118f0 74 6f 20 66 75 6e 63 74 69 6f 6e 20 61 73 20 61  to function as a
11900 20 70 72 69 6d 69 74 69 76 65 20 77 65 62 2d 73   primitive web-s
11910 65 72 76 65 72 20 64 65 6c 69 76 65 72 69 6e 67  erver delivering
11920 20 61 72 62 69 74 72 61 72 79 20 63 6f 6e 74 65   arbitrary conte
11930 6e 74 2e 0a 20 20 20 20 20 20 2a 2f 0a 20 20 20  nt..      */.   
11940 20 20 20 70 46 69 6c 65 47 6c 6f 62 20 3d 20 67     pFileGlob = g
11950 6c 6f 62 5f 63 72 65 61 74 65 28 62 6c 6f 62 5f  lob_create(blob_
11960 73 74 72 28 26 76 61 6c 75 65 29 29 3b 0a 20 20  str(&value));.  
11970 20 20 20 20 62 6c 6f 62 5f 72 65 73 65 74 28 26      blob_reset(&
11980 76 61 6c 75 65 29 3b 0a 20 20 20 20 20 20 63 6f  value);.      co
11990 6e 74 69 6e 75 65 3b 0a 20 20 20 20 7d 0a 20 20  ntinue;.    }.  
119a0 20 20 69 66 28 20 62 6c 6f 62 5f 65 71 28 26 6b    if( blob_eq(&k
119b0 65 79 2c 20 22 73 65 74 65 6e 76 3a 22 29 20 26  ey, "setenv:") &
119c0 26 20 62 6c 6f 62 5f 74 6f 6b 65 6e 28 26 6c 69  & blob_token(&li
119d0 6e 65 2c 20 26 76 61 6c 75 65 29 20 29 7b 0a 20  ne, &value) ){. 
119e0 20 20 20 20 20 2f 2a 20 73 65 74 65 6e 76 3a 20       /* setenv: 
119f0 4e 41 4d 45 20 56 41 4c 55 45 0a 20 20 20 20 20  NAME VALUE.     
11a00 20 2a 2a 20 73 65 74 65 6e 76 3a 20 4e 41 4d 45   ** setenv: NAME
11a10 0a 20 20 20 20 20 20 2a 2a 0a 20 20 20 20 20 20  .      **.      
11a20 2a 2a 20 53 65 74 73 20 65 6e 76 69 72 6f 6e 6d  ** Sets environm
11a30 65 6e 74 20 76 61 72 69 61 62 6c 65 20 4e 41 4d  ent variable NAM
11a40 45 20 74 6f 20 56 41 4c 55 45 2e 20 20 49 66 20  E to VALUE.  If 
11a50 56 41 4c 55 45 20 69 73 20 6f 6d 69 74 74 65 64  VALUE is omitted
11a60 2c 20 74 68 65 6e 0a 20 20 20 20 20 20 2a 2a 20  , then.      ** 
11a70 74 68 65 20 65 6e 76 69 72 6f 6e 6d 65 6e 74 20  the environment 
11a80 76 61 72 69 61 62 6c 65 20 69 73 20 75 6e 73 65  variable is unse
11a90 74 2e 0a 20 20 20 20 20 20 2a 2f 0a 20 20 20 20  t..      */.    
11aa0 20 20 62 6c 6f 62 5f 74 6f 6b 65 6e 28 26 6c 69    blob_token(&li
11ab0 6e 65 2c 26 76 61 6c 75 65 32 29 3b 0a 20 20 20  ne,&value2);.   
11ac0 20 20 20 66 6f 73 73 69 6c 5f 73 65 74 65 6e 76     fossil_setenv
11ad0 28 62 6c 6f 62 5f 73 74 72 28 26 76 61 6c 75 65  (blob_str(&value
11ae0 29 2c 20 62 6c 6f 62 5f 73 74 72 28 26 76 61 6c  ), blob_str(&val
11af0 75 65 32 29 29 3b 0a 20 20 20 20 20 20 62 6c 6f  ue2));.      blo
11b00 62 5f 72 65 73 65 74 28 26 76 61 6c 75 65 29 3b  b_reset(&value);
11b10 0a 20 20 20 20 20 20 62 6c 6f 62 5f 72 65 73 65  .      blob_rese
11b20 74 28 26 76 61 6c 75 65 32 29 3b 0a 20 20 20 20  t(&value2);.    
11b30 20 20 63 6f 6e 74 69 6e 75 65 3b 0a 20 20 20 20    continue;.    
11b40 7d 0a 20 20 20 20 69 66 28 20 62 6c 6f 62 5f 65  }.    if( blob_e
11b50 71 28 26 6b 65 79 2c 20 22 64 65 62 75 67 3a 22  q(&key, "debug:"
11b60 29 20 26 26 20 62 6c 6f 62 5f 74 6f 6b 65 6e 28  ) && blob_token(
11b70 26 6c 69 6e 65 2c 20 26 76 61 6c 75 65 29 20 29  &line, &value) )
11b80 7b 0a 20 20 20 20 20 20 2f 2a 20 64 65 62 75 67  {.      /* debug
11b90 3a 20 46 49 4c 45 4e 41 4d 45 0a 20 20 20 20 20  : FILENAME.     
11ba0 20 2a 2a 0a 20 20 20 20 20 20 2a 2a 20 43 61 75   **.      ** Cau
11bb0 73 65 73 20 6f 75 74 70 75 74 20 66 72 6f 6d 20  ses output from 
11bc0 63 67 69 5f 64 65 62 75 67 28 29 20 61 6e 64 20  cgi_debug() and 
11bd0 43 47 49 44 45 42 55 47 28 28 29 29 20 63 61 6c  CGIDEBUG(()) cal
11be0 6c 73 20 74 6f 20 67 6f 0a 20 20 20 20 20 20 2a  ls to go.      *
11bf0 2a 20 69 6e 74 6f 20 46 49 4c 45 4e 41 4d 45 2e  * into FILENAME.
11c00 0a 20 20 20 20 20 20 2a 2f 0a 20 20 20 20 20 20  .      */.      
11c10 67 2e 66 44 65 62 75 67 20 3d 20 66 6f 73 73 69  g.fDebug = fossi
11c20 6c 5f 66 6f 70 65 6e 28 62 6c 6f 62 5f 73 74 72  l_fopen(blob_str
11c30 28 26 76 61 6c 75 65 29 2c 20 22 61 62 22 29 3b  (&value), "ab");
11c40 0a 20 20 20 20 20 20 62 6c 6f 62 5f 72 65 73 65  .      blob_rese
11c50 74 28 26 76 61 6c 75 65 29 3b 0a 20 20 20 20 20  t(&value);.     
11c60 20 63 6f 6e 74 69 6e 75 65 3b 0a 20 20 20 20 7d   continue;.    }
11c70 0a 20 20 20 20 69 66 28 20 62 6c 6f 62 5f 65 71  .    if( blob_eq
11c80 28 26 6b 65 79 2c 20 22 65 72 72 6f 72 6c 6f 67  (&key, "errorlog
11c90 3a 22 29 20 26 26 20 62 6c 6f 62 5f 74 6f 6b 65  :") && blob_toke
11ca0 6e 28 26 6c 69 6e 65 2c 20 26 76 61 6c 75 65 29  n(&line, &value)
11cb0 20 29 7b 0a 20 20 20 20 20 20 2f 2a 20 65 72 72   ){.      /* err
11cc0 6f 72 6c 6f 67 3a 20 46 49 4c 45 4e 41 4d 45 0a  orlog: FILENAME.
11cd0 20 20 20 20 20 20 2a 2a 0a 20 20 20 20 20 20 2a        **.      *
11ce0 2a 20 43 61 75 73 65 73 20 6d 65 73 73 61 67 65  * Causes message
11cf0 73 20 66 72 6f 6d 20 77 61 72 6e 69 6e 67 73 2c  s from warnings,
11d00 20 65 72 72 6f 72 73 2c 20 61 6e 64 20 70 61 6e   errors, and pan
11d10 69 63 73 20 74 6f 20 62 65 20 61 70 70 65 6e 64  ics to be append
11d20 65 64 0a 20 20 20 20 20 20 2a 2a 20 74 6f 20 46  ed.      ** to F
11d30 49 4c 45 4e 41 4d 45 2e 0a 20 20 20 20 20 20 2a  ILENAME..      *
11d40 2f 0a 20 20 20 20 20 20 67 2e 7a 45 72 72 6c 6f  /.      g.zErrlo
11d50 67 20 3d 20 6d 70 72 69 6e 74 66 28 22 25 73 22  g = mprintf("%s"
11d60 2c 20 62 6c 6f 62 5f 73 74 72 28 26 76 61 6c 75  , blob_str(&valu
11d70 65 29 29 3b 0a 20 20 20 20 20 20 62 6c 6f 62 5f  e));.      blob_
11d80 72 65 73 65 74 28 26 76 61 6c 75 65 29 3b 0a 20  reset(&value);. 
11d90 20 20 20 20 20 63 6f 6e 74 69 6e 75 65 3b 0a 20       continue;. 
11da0 20 20 20 7d 0a 20 20 20 20 69 66 28 20 62 6c 6f     }.    if( blo
11db0 62 5f 65 71 28 26 6b 65 79 2c 20 22 65 78 74 72  b_eq(&key, "extr
11dc0 6f 6f 74 3a 22 29 20 26 26 20 62 6c 6f 62 5f 74  oot:") && blob_t
11dd0 6f 6b 65 6e 28 26 6c 69 6e 65 2c 20 26 76 61 6c  oken(&line, &val
11de0 75 65 29 20 29 7b 0a 20 20 20 20 20 20 2f 2a 20  ue) ){.      /* 
11df0 65 78 74 72 6f 6f 74 3a 20 44 49 52 45 43 54 4f  extroot: DIRECTO
11e00 52 59 0a 20 20 20 20 20 20 2a 2a 0a 20 20 20 20  RY.      **.    
11e10 20 20 2a 2a 20 45 6e 61 62 6c 65 73 20 74 68 65    ** Enables the
11e20 20 2f 65 78 74 20 77 65 62 70 61 67 65 20 74 6f   /ext webpage to
11e30 20 75 73 65 20 73 75 62 2d 63 67 69 20 72 6f 6f   use sub-cgi roo
11e40 74 65 64 20 61 74 20 44 49 52 45 43 54 4f 52 59  ted at DIRECTORY
11e50 0a 20 20 20 20 20 20 2a 2f 0a 20 20 20 20 20 20  .      */.      
11e60 67 2e 7a 45 78 74 52 6f 6f 74 20 3d 20 6d 70 72  g.zExtRoot = mpr
11e70 69 6e 74 66 28 22 25 73 22 2c 20 62 6c 6f 62 5f  intf("%s", blob_
11e80 73 74 72 28 26 76 61 6c 75 65 29 29 3b 0a 20 20  str(&value));.  
11e90 20 20 20 20 62 6c 6f 62 5f 72 65 73 65 74 28 26      blob_reset(&
11ea0 76 61 6c 75 65 29 3b 0a 20 20 20 20 20 20 63 6f  value);.      co
11eb0 6e 74 69 6e 75 65 3b 0a 20 20 20 20 7d 0a 20 20  ntinue;.    }.  
11ec0 20 20 69 66 28 20 62 6c 6f 62 5f 65 71 28 26 6b    if( blob_eq(&k
11ed0 65 79 2c 20 22 48 4f 4d 45 3a 22 29 20 26 26 20  ey, "HOME:") && 
11ee0 62 6c 6f 62 5f 74 6f 6b 65 6e 28 26 6c 69 6e 65  blob_token(&line
11ef0 2c 20 26 76 61 6c 75 65 29 20 29 7b 0a 20 20 20  , &value) ){.   
11f00 20 20 20 2f 2a 20 48 4f 4d 45 3a 20 56 41 4c 55     /* HOME: VALU
11f10 45 0a 20 20 20 20 20 20 2a 2a 0a 20 20 20 20 20  E.      **.     
11f20 20 2a 2a 20 53 65 74 20 43 47 49 20 70 61 72 61   ** Set CGI para
11f30 6d 65 74 65 72 20 22 48 4f 4d 45 22 20 74 6f 20  meter "HOME" to 
11f40 56 41 4c 55 45 2e 20 20 54 68 69 73 20 69 73 20  VALUE.  This is 
11f50 6c 65 67 61 63 79 2e 20 20 55 73 65 0a 20 20 20  legacy.  Use.   
11f60 20 20 20 2a 2a 20 73 65 74 65 6e 76 3a 20 69 6e     ** setenv: in
11f70 73 74 65 61 64 2e 0a 20 20 20 20 20 20 2a 2f 0a  stead..      */.
11f80 20 20 20 20 20 20 63 67 69 5f 73 65 74 65 6e 76        cgi_setenv
11f90 28 22 48 4f 4d 45 22 2c 20 62 6c 6f 62 5f 73 74  ("HOME", blob_st
11fa0 72 28 26 76 61 6c 75 65 29 29 3b 0a 20 20 20 20  r(&value));.    
11fb0 20 20 62 6c 6f 62 5f 72 65 73 65 74 28 26 76 61    blob_reset(&va
11fc0 6c 75 65 29 3b 0a 20 20 20 20 20 20 63 6f 6e 74  lue);.      cont
11fd0 69 6e 75 65 3b 0a 20 20 20 20 7d 0a 20 20 20 20  inue;.    }.    
11fe0 69 66 28 20 62 6c 6f 62 5f 65 71 28 26 6b 65 79  if( blob_eq(&key
11ff0 2c 20 22 73 6b 69 6e 3a 22 29 20 26 26 20 62 6c  , "skin:") && bl
12000 6f 62 5f 74 6f 6b 65 6e 28 26 6c 69 6e 65 2c 20  ob_token(&line, 
12010 26 76 61 6c 75 65 29 20 29 7b 0a 20 20 20 20 20  &value) ){.     
12020 20 2f 2a 20 73 6b 69 6e 3a 20 4c 41 42 45 4c 0a   /* skin: LABEL.
12030 20 20 20 20 20 20 2a 2a 0a 20 20 20 20 20 20 2a        **.      *
12040 2a 20 55 73 65 20 6f 6e 65 20 6f 66 20 74 68 65  * Use one of the
12050 20 62 75 69 6c 74 2d 69 6e 20 73 6b 69 6e 73 20   built-in skins 
12060 64 65 66 69 6e 65 64 20 62 79 20 4c 41 42 45 4c  defined by LABEL
12070 2e 20 20 4c 41 42 45 4c 20 69 73 20 74 68 65 0a  .  LABEL is the.
12080 20 20 20 20 20 20 2a 2a 20 6e 61 6d 65 20 6f 66        ** name of
12090 20 74 68 65 20 73 75 62 64 69 72 65 63 74 6f 72   the subdirector
120a0 79 20 75 6e 64 65 72 20 74 68 65 20 73 6b 69 6e  y under the skin
120b0 73 2f 20 64 69 72 65 63 74 6f 72 79 20 74 68 61  s/ directory tha
120c0 74 20 68 6f 6c 64 73 0a 20 20 20 20 20 20 2a 2a  t holds.      **
120d0 20 74 68 65 20 65 6c 65 6d 65 6e 74 73 20 6f 66   the elements of
120e0 20 74 68 65 20 62 75 69 6c 74 2d 69 6e 20 73 6b   the built-in sk
120f0 69 6e 2e 20 20 49 66 20 4c 41 42 45 4c 20 64 6f  in.  If LABEL do
12100 65 73 20 6e 6f 74 20 6d 61 74 63 68 2c 0a 20 20  es not match,.  
12110 20 20 20 20 2a 2a 20 74 68 69 73 20 64 69 72 65      ** this dire
12120 63 74 69 76 65 20 69 73 20 61 20 73 69 6c 65 6e  ctive is a silen
12130 74 20 6e 6f 2d 6f 70 2e 0a 20 20 20 20 20 20 2a  t no-op..      *
12140 2f 0a 20 20 20 20 20 20 73 6b 69 6e 5f 75 73 65  /.      skin_use
12150 5f 61 6c 74 65 72 6e 61 74 69 76 65 28 62 6c 6f  _alternative(blo
12160 62 5f 73 74 72 28 26 76 61 6c 75 65 29 29 3b 0a  b_str(&value));.
12170 20 20 20 20 20 20 62 6c 6f 62 5f 72 65 73 65 74        blob_reset
12180 28 26 76 61 6c 75 65 29 3b 0a 20 20 20 20 20 20  (&value);.      
12190 63 6f 6e 74 69 6e 75 65 3b 0a 20 20 20 20 7d 0a  continue;.    }.
121a0 20 20 7d 0a 20 20 62 6c 6f 62 5f 72 65 73 65 74    }.  blob_reset
121b0 28 26 63 6f 6e 66 69 67 29 3b 0a 20 20 69 66 28  (&config);.  if(
121c0 20 67 2e 64 62 3d 3d 30 20 26 26 20 67 2e 7a 52   g.db==0 && g.zR
121d0 65 70 6f 73 69 74 6f 72 79 4e 61 6d 65 3d 3d 30  epositoryName==0
121e0 20 26 26 20 6e 52 65 64 69 72 65 63 74 3d 3d 30   && nRedirect==0
121f0 20 29 7b 0a 20 20 20 20 63 67 69 5f 70 61 6e 69   ){.    cgi_pani
12200 63 28 22 55 6e 61 62 6c 65 20 74 6f 20 66 69 6e  c("Unable to fin
12210 64 20 6f 72 20 6f 70 65 6e 20 74 68 65 20 70 72  d or open the pr
12220 6f 6a 65 63 74 20 72 65 70 6f 73 69 74 6f 72 79  oject repository
12230 22 29 3b 0a 20 20 7d 0a 20 20 63 67 69 5f 69 6e  ");.  }.  cgi_in
12240 69 74 28 29 3b 0a 20 20 69 66 28 20 6e 52 65 64  it();.  if( nRed
12250 69 72 65 63 74 20 29 7b 0a 20 20 20 20 72 65 64  irect ){.    red
12260 69 72 65 63 74 5f 77 65 62 5f 70 61 67 65 28 6e  irect_web_page(n
12270 52 65 64 69 72 65 63 74 2c 20 61 7a 52 65 64 69  Redirect, azRedi
12280 72 65 63 74 29 3b 0a 20 20 7d 65 6c 73 65 7b 0a  rect);.  }else{.
12290 20 20 20 20 70 72 6f 63 65 73 73 5f 6f 6e 65 5f      process_one_
122a0 77 65 62 5f 70 61 67 65 28 7a 4e 6f 74 46 6f 75  web_page(zNotFou
122b0 6e 64 2c 20 70 46 69 6c 65 47 6c 6f 62 2c 20 61  nd, pFileGlob, a
122c0 6c 6c 6f 77 52 65 70 6f 4c 69 73 74 29 3b 0a 20  llowRepoList);. 
122d0 20 7d 0a 7d 0a 0a 2f 2a 0a 2a 2a 20 49 66 20 67   }.}../*.** If g
122e0 2e 61 72 67 76 5b 61 72 67 5d 20 65 78 69 73 74  .argv[arg] exist
122f0 73 20 74 68 65 6e 20 69 74 20 69 73 20 65 69 74  s then it is eit
12300 68 65 72 20 74 68 65 20 6e 61 6d 65 20 6f 66 20  her the name of 
12310 61 20 72 65 70 6f 73 69 74 6f 72 79 0a 2a 2a 20  a repository.** 
12320 74 68 61 74 20 77 69 6c 6c 20 62 65 20 75 73 65  that will be use
12330 64 20 62 79 20 61 20 73 65 72 76 65 72 2c 20 6f  d by a server, o
12340 72 20 65 6c 73 65 20 69 74 20 69 73 20 61 20 64  r else it is a d
12350 69 72 65 63 74 6f 72 79 20 74 68 61 74 0a 2a 2a  irectory that.**
12360 20 63 6f 6e 74 61 69 6e 73 20 6d 75 6c 74 69 70   contains multip
12370 6c 65 20 72 65 70 6f 73 69 74 6f 72 69 65 73 20  le repositories 
12380 74 68 61 74 20 63 61 6e 20 62 65 20 73 65 72 76  that can be serv
12390 65 64 2e 20 20 49 66 20 67 2e 61 72 67 76 5b 61  ed.  If g.argv[a
123a0 72 67 5d 0a 2a 2a 20 69 73 20 61 20 64 69 72 65  rg].** is a dire
123b0 63 74 6f 72 79 2c 20 74 68 65 20 72 65 70 6f 73  ctory, the repos
123c0 69 74 6f 72 69 65 73 20 69 74 20 63 6f 6e 74 61  itories it conta
123d0 69 6e 73 20 6d 75 73 74 20 62 65 20 6e 61 6d 65  ins must be name
123e0 64 0a 2a 2a 20 22 2a 2e 66 6f 73 73 69 6c 22 2e  d.** "*.fossil".
123f0 20 20 49 66 20 67 2e 61 72 67 76 5b 61 72 67 5d    If g.argv[arg]
12400 20 64 6f 65 73 20 6e 6f 74 20 65 78 69 73 74 2c   does not exist,
12410 20 74 68 65 6e 20 77 65 20 6d 75 73 74 20 62 65   then we must be
12420 20 77 69 74 68 69 6e 0a 2a 2a 20 61 6e 20 6f 70   within.** an op
12430 65 6e 20 63 68 65 63 6b 2d 6f 75 74 20 61 6e 64  en check-out and
12440 20 74 68 65 20 72 65 70 6f 73 69 74 6f 72 79 20   the repository 
12450 74 6f 20 73 65 72 76 65 20 69 73 20 74 68 65 20  to serve is the 
12460 72 65 70 6f 73 69 74 6f 72 79 20 6f 66 0a 2a 2a  repository of.**
12470 20 74 68 61 74 20 63 68 65 63 6b 2d 6f 75 74 2e   that check-out.
12480 0a 2a 2a 0a 2a 2a 20 4f 70 65 6e 20 74 68 65 20  .**.** Open the 
12490 72 65 70 6f 73 69 74 6f 72 79 20 74 6f 20 62 65  repository to be
124a0 20 73 65 72 76 65 64 20 69 66 20 69 74 20 69 73   served if it is
124b0 20 6b 6e 6f 77 6e 2e 20 20 49 66 20 67 2e 61 72   known.  If g.ar
124c0 67 76 5b 61 72 67 5d 20 69 73 0a 2a 2a 20 61 20  gv[arg] is.** a 
124d0 64 69 72 65 63 74 6f 72 79 20 66 75 6c 6c 20 6f  directory full o
124e0 66 20 72 65 70 6f 73 69 74 6f 72 69 65 73 2c 20  f repositories, 
124f0 74 68 65 6e 20 73 65 74 20 67 2e 7a 52 65 70 6f  then set g.zRepo
12500 73 69 74 6f 72 79 4e 61 6d 65 20 74 6f 0a 2a 2a  sitoryName to.**
12510 20 74 68 65 20 6e 61 6d 65 20 6f 66 20 74 68 61   the name of tha
12520 74 20 64 69 72 65 63 74 6f 72 79 20 61 6e 64 20  t directory and 
12530 74 68 65 20 73 70 65 63 69 66 69 63 20 72 65 70  the specific rep
12540 6f 73 69 74 6f 72 79 20 77 69 6c 6c 20 62 65 0a  ository will be.
12550 2a 2a 20 6f 70 65 6e 65 64 20 6c 61 74 65 72 20  ** opened later 
12560 62 79 20 70 72 6f 63 65 73 73 5f 6f 6e 65 5f 77  by process_one_w
12570 65 62 5f 70 61 67 65 28 29 20 62 61 73 65 64 20  eb_page() based 
12580 6f 6e 20 74 68 65 20 63 6f 6e 74 65 6e 74 20 6f  on the content o
12590 66 0a 2a 2a 20 74 68 65 20 50 41 54 48 5f 49 4e  f.** the PATH_IN
125a0 46 4f 20 76 61 72 69 61 62 6c 65 2e 0a 2a 2a 0a  FO variable..**.
125b0 2a 2a 20 49 66 20 74 68 65 20 66 43 72 65 61 74  ** If the fCreat
125c0 65 20 66 6c 61 67 20 69 73 20 73 65 74 2c 20 74  e flag is set, t
125d0 68 65 6e 20 63 72 65 61 74 65 20 74 68 65 20 72  hen create the r
125e0 65 70 6f 73 69 74 6f 72 79 20 69 66 20 69 74 0a  epository if it.
125f0 2a 2a 20 64 6f 65 73 20 6e 6f 74 20 61 6c 72 65  ** does not alre
12600 61 64 79 20 65 78 69 73 74 2e 20 41 6c 77 61 79  ady exist. Alway
12610 73 20 75 73 65 20 22 61 75 74 6f 22 20 68 61 73  s use "auto" has
12620 68 2d 70 6f 6c 69 63 79 20 69 6e 20 74 68 69 73  h-policy in this
12630 20 63 61 73 65 2e 0a 2a 2f 0a 73 74 61 74 69 63   case..*/.static
12640 20 76 6f 69 64 20 66 69 6e 64 5f 73 65 72 76 65   void find_serve
12650 72 5f 72 65 70 6f 73 69 74 6f 72 79 28 69 6e 74  r_repository(int
12660 20 61 72 67 2c 20 69 6e 74 20 66 43 72 65 61 74   arg, int fCreat
12670 65 29 7b 0a 20 20 69 66 28 20 67 2e 61 72 67 63  e){.  if( g.argc
12680 3c 3d 61 72 67 20 29 7b 0a 20 20 20 20 64 62 5f  <=arg ){.    db_
12690 6d 75 73 74 5f 62 65 5f 77 69 74 68 69 6e 5f 74  must_be_within_t
126a0 72 65 65 28 29 3b 0a 20 20 7d 65 6c 73 65 7b 0a  ree();.  }else{.
126b0 20 20 20 20 63 6f 6e 73 74 20 63 68 61 72 20 2a      const char *
126c0 7a 52 65 70 6f 20 3d 20 67 2e 61 72 67 76 5b 61  zRepo = g.argv[a
126d0 72 67 5d 3b 0a 20 20 20 20 69 6e 74 20 69 73 44  rg];.    int isD
126e0 69 72 20 3d 20 66 69 6c 65 5f 69 73 64 69 72 28  ir = file_isdir(
126f0 7a 52 65 70 6f 2c 20 45 78 74 46 49 4c 45 29 3b  zRepo, ExtFILE);
12700 0a 20 20 20 20 69 66 28 20 69 73 44 69 72 3d 3d  .    if( isDir==
12710 31 20 29 7b 0a 20 20 20 20 20 20 67 2e 7a 52 65  1 ){.      g.zRe
12720 70 6f 73 69 74 6f 72 79 4e 61 6d 65 20 3d 20 6d  positoryName = m
12730 70 72 69 6e 74 66 28 22 25 73 22 2c 20 7a 52 65  printf("%s", zRe
12740 70 6f 29 3b 0a 20 20 20 20 20 20 66 69 6c 65 5f  po);.      file_
12750 73 69 6d 70 6c 69 66 79 5f 6e 61 6d 65 28 67 2e  simplify_name(g.
12760 7a 52 65 70 6f 73 69 74 6f 72 79 4e 61 6d 65 2c  zRepositoryName,
12770 20 2d 31 2c 20 30 29 3b 0a 20 20 20 20 7d 65 6c   -1, 0);.    }el
12780 73 65 7b 0a 20 20 20 20 20 20 69 66 28 20 69 73  se{.      if( is
12790 44 69 72 3d 3d 30 20 26 26 20 66 43 72 65 61 74  Dir==0 && fCreat
127a0 65 20 29 7b 0a 20 20 20 20 20 20 20 20 63 6f 6e  e ){.        con
127b0 73 74 20 63 68 61 72 20 2a 7a 50 61 73 73 77 6f  st char *zPasswo
127c0 72 64 3b 0a 20 20 20 20 20 20 20 20 64 62 5f 63  rd;.        db_c
127d0 72 65 61 74 65 5f 72 65 70 6f 73 69 74 6f 72 79  reate_repository
127e0 28 7a 52 65 70 6f 29 3b 0a 20 20 20 20 20 20 20  (zRepo);.       
127f0 20 64 62 5f 6f 70 65 6e 5f 72 65 70 6f 73 69 74   db_open_reposit
12800 6f 72 79 28 7a 52 65 70 6f 29 3b 0a 20 20 20 20  ory(zRepo);.    
12810 20 20 20 20 64 62 5f 62 65 67 69 6e 5f 74 72 61      db_begin_tra
12820 6e 73 61 63 74 69 6f 6e 28 29 3b 0a 20 20 20 20  nsaction();.    
12830 20 20 20 20 67 2e 65 48 61 73 68 50 6f 6c 69 63      g.eHashPolic
12840 79 20 3d 20 48 50 4f 4c 49 43 59 5f 53 48 41 33  y = HPOLICY_SHA3
12850 3b 0a 20 20 20 20 20 20 20 20 64 62 5f 73 65 74  ;.        db_set
12860 5f 69 6e 74 28 22 68 61 73 68 2d 70 6f 6c 69 63  _int("hash-polic
12870 79 22 2c 20 48 50 4f 4c 49 43 59 5f 53 48 41 33  y", HPOLICY_SHA3
12880 2c 20 30 29 3b 0a 20 20 20 20 20 20 20 20 64 62  , 0);.        db
12890 5f 69 6e 69 74 69 61 6c 5f 73 65 74 75 70 28 30  _initial_setup(0
128a0 2c 20 22 6e 6f 77 22 2c 20 67 2e 7a 4c 6f 67 69  , "now", g.zLogi
128b0 6e 29 3b 0a 20 20 20 20 20 20 20 20 64 62 5f 65  n);.        db_e
128c0 6e 64 5f 74 72 61 6e 73 61 63 74 69 6f 6e 28 30  nd_transaction(0
128d0 29 3b 0a 20 20 20 20 20 20 20 20 66 6f 73 73 69  );.        fossi
128e0 6c 5f 70 72 69 6e 74 28 22 70 72 6f 6a 65 63 74  l_print("project
128f0 2d 69 64 3a 20 25 73 5c 6e 22 2c 20 64 62 5f 67  -id: %s\n", db_g
12900 65 74 28 22 70 72 6f 6a 65 63 74 2d 63 6f 64 65  et("project-code
12910 22 2c 20 30 29 29 3b 0a 20 20 20 20 20 20 20 20  ", 0));.        
12920 66 6f 73 73 69 6c 5f 70 72 69 6e 74 28 22 73 65  fossil_print("se
12930 72 76 65 72 2d 69 64 3a 20 20 25 73 5c 6e 22 2c  rver-id:  %s\n",
12940 20 64 62 5f 67 65 74 28 22 73 65 72 76 65 72 2d   db_get("server-
12950 63 6f 64 65 22 2c 20 30 29 29 3b 0a 20 20 20 20  code", 0));.    
12960 20 20 20 20 7a 50 61 73 73 77 6f 72 64 20 3d 20      zPassword = 
12970 64 62 5f 74 65 78 74 28 30 2c 20 22 53 45 4c 45  db_text(0, "SELE
12980 43 54 20 70 77 20 46 52 4f 4d 20 75 73 65 72 20  CT pw FROM user 
12990 57 48 45 52 45 20 6c 6f 67 69 6e 3d 25 51 22 2c  WHERE login=%Q",
129a0 20 67 2e 7a 4c 6f 67 69 6e 29 3b 0a 20 20 20 20   g.zLogin);.    
129b0 20 20 20 20 66 6f 73 73 69 6c 5f 70 72 69 6e 74      fossil_print
129c0 28 22 61 64 6d 69 6e 2d 75 73 65 72 3a 20 25 73  ("admin-user: %s
129d0 20 28 69 6e 69 74 69 61 6c 20 70 61 73 73 77 6f   (initial passwo
129e0 72 64 20 69 73 20 5c 22 25 73 5c 22 29 5c 6e 22  rd is \"%s\")\n"
129f0 2c 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20  ,.              
12a00 20 20 20 20 20 20 20 67 2e 7a 4c 6f 67 69 6e 2c         g.zLogin,
12a10 20 7a 50 61 73 73 77 6f 72 64 29 3b 0a 20 20 20   zPassword);.   
12a20 20 20 20 20 20 63 61 63 68 65 5f 69 6e 69 74 69       cache_initi
12a30 61 6c 69 7a 65 28 29 3b 0a 20 20 20 20 20 20 20  alize();.       
12a40 20 67 2e 7a 4c 6f 67 69 6e 20 3d 20 30 3b 0a 20   g.zLogin = 0;. 
12a50 20 20 20 20 20 20 20 67 2e 75 73 65 72 55 69 64         g.userUid
12a60 20 3d 20 30 3b 0a 20 20 20 20 20 20 7d 65 6c 73   = 0;.      }els
12a70 65 7b 0a 20 20 20 20 20 20 20 20 64 62 5f 6f 70  e{.        db_op
12a80 65 6e 5f 72 65 70 6f 73 69 74 6f 72 79 28 7a 52  en_repository(zR
12a90 65 70 6f 29 3b 0a 20 20 20 20 20 20 7d 0a 20 20  epo);.      }.  
12aa0 20 20 7d 0a 20 20 7d 0a 7d 0a 0a 23 69 66 20 64    }.  }.}..#if d
12ab0 65 66 69 6e 65 64 28 5f 57 49 4e 33 32 29 20 26  efined(_WIN32) &
12ac0 26 20 55 53 45 5f 53 45 45 0a 2f 2a 0a 2a 2a 20  & USE_SEE./*.** 
12ad0 54 68 69 73 20 66 75 6e 63 74 69 6f 6e 20 61 74  This function at
12ae0 74 65 6d 70 74 73 20 74 6f 20 70 61 72 73 65 20  tempts to parse 
12af0 61 20 73 74 72 69 6e 67 20 76 61 6c 75 65 20 69  a string value i
12b00 6e 20 74 68 65 20 66 6f 6c 6c 6f 77 69 6e 67 0a  n the following.
12b10 2a 2a 20 66 6f 72 6d 61 74 3a 0a 2a 2a 0a 2a 2a  ** format:.**.**
12b20 20 20 20 20 20 22 25 6c 75 3a 25 70 3a 25 75 22       "%lu:%p:%u"
12b30 0a 2a 2a 0a 2a 2a 20 54 68 65 72 65 20 61 72 65  .**.** There are
12b40 20 74 68 72 65 65 20 70 61 72 74 73 2c 20 77 68   three parts, wh
12b50 69 63 68 20 6d 75 73 74 20 62 65 20 64 65 6c 69  ich must be deli
12b60 6d 69 74 65 64 20 62 79 20 63 6f 6c 6f 6e 73 2e  mited by colons.
12b70 20 20 54 68 65 0a 2a 2a 20 66 69 72 73 74 20 70    The.** first p
12b80 61 72 74 20 69 73 20 61 6e 20 75 6e 73 69 67 6e  art is an unsign
12b90 65 64 20 6c 6f 6e 67 20 69 6e 74 65 67 65 72 20  ed long integer 
12ba0 69 6e 20 62 61 73 65 2d 31 30 20 28 64 65 63 69  in base-10 (deci
12bb0 6d 61 6c 29 20 66 6f 72 6d 61 74 2e 0a 2a 2a 20  mal) format..** 
12bc0 54 68 65 20 73 65 63 6f 6e 64 20 70 61 72 74 20  The second part 
12bd0 69 73 20 61 20 6e 75 6d 65 72 69 63 61 6c 20 72  is a numerical r
12be0 65 70 72 65 73 65 6e 74 61 74 69 6f 6e 20 6f 66  epresentation of
12bf0 20 61 20 6e 61 74 69 76 65 20 70 6f 69 6e 74 65   a native pointe
12c00 72 2c 0a 2a 2a 20 69 6e 20 74 68 65 20 61 70 70  r,.** in the app
12c10 72 6f 70 72 69 61 74 65 20 69 6d 70 6c 65 6d 65  ropriate impleme
12c20 6e 74 61 74 69 6f 6e 20 64 65 66 69 6e 65 64 20  ntation defined 
12c30 66 6f 72 6d 61 74 2e 20 20 54 68 65 20 74 68 69  format.  The thi
12c40 72 64 20 70 61 72 74 0a 2a 2a 20 69 73 20 61 6e  rd part.** is an
12c50 20 75 6e 73 69 67 6e 65 64 20 69 6e 74 65 67 65   unsigned intege
12c60 72 20 69 6e 20 62 61 73 65 2d 31 30 20 28 64 65  r in base-10 (de
12c70 63 69 6d 61 6c 29 20 66 6f 72 6d 61 74 2e 0a 2a  cimal) format..*
12c80 2a 0a 2a 2a 20 49 66 20 74 68 65 20 73 70 65 63  *.** If the spec
12c90 69 66 69 65 64 20 76 61 6c 75 65 20 63 61 6e 6e  ified value cann
12ca0 6f 74 20 62 65 20 70 61 72 73 65 64 2c 20 66 6f  ot be parsed, fo
12cb0 72 20 61 6e 79 20 72 65 61 73 6f 6e 2c 20 61 20  r any reason, a 
12cc0 66 61 74 61 6c 0a 2a 2a 20 65 72 72 6f 72 20 77  fatal.** error w
12cd0 69 6c 6c 20 62 65 20 72 61 69 73 65 64 20 61 6e  ill be raised an
12ce0 64 20 74 68 65 20 70 72 6f 63 65 73 73 20 77 69  d the process wi
12cf0 6c 6c 20 62 65 20 74 65 72 6d 69 6e 61 74 65 64  ll be terminated
12d00 2e 0a 2a 2f 0a 76 6f 69 64 20 70 61 72 73 65 5f  ..*/.void parse_
12d10 70 69 64 5f 6b 65 79 5f 76 61 6c 75 65 28 0a 20  pid_key_value(. 
12d20 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a 50 69   const char *zPi
12d30 64 4b 65 79 2c 20 2f 2a 20 54 68 65 20 76 61 6c  dKey, /* The val
12d40 75 65 20 74 6f 20 62 65 20 70 61 72 73 65 64 2e  ue to be parsed.
12d50 20 2a 2f 0a 20 20 44 57 4f 52 44 20 2a 70 50 72   */.  DWORD *pPr
12d60 6f 63 65 73 73 49 64 2c 20 20 20 2f 2a 20 54 68  ocessId,   /* Th
12d70 65 20 65 78 74 72 61 63 74 65 64 20 70 72 6f 63  e extracted proc
12d80 65 73 73 20 69 64 65 6e 74 69 66 69 65 72 2e 20  ess identifier. 
12d90 2a 2f 0a 20 20 4c 50 56 4f 49 44 20 2a 70 70 41  */.  LPVOID *ppA
12da0 64 64 72 65 73 73 2c 20 20 20 2f 2a 20 54 68 65  ddress,   /* The
12db0 20 65 78 74 72 61 63 74 65 64 20 70 6f 69 6e 74   extracted point
12dc0 65 72 20 76 61 6c 75 65 2e 20 2a 2f 0a 20 20 53  er value. */.  S
12dd0 49 5a 45 5f 54 20 2a 70 6e 53 69 7a 65 20 20 20  IZE_T *pnSize   
12de0 20 20 20 20 2f 2a 20 54 68 65 20 65 78 74 72 61      /* The extra
12df0 63 74 65 64 20 73 69 7a 65 20 76 61 6c 75 65 2e  cted size value.
12e00 20 2a 2f 0a 29 7b 0a 20 20 75 6e 73 69 67 6e 65   */.){.  unsigne
12e10 64 20 69 6e 74 20 6e 53 69 7a 65 20 3d 20 30 3b  d int nSize = 0;
12e20 0a 20 20 69 66 28 20 73 73 63 61 6e 66 28 7a 50  .  if( sscanf(zP
12e30 69 64 4b 65 79 2c 20 22 25 6c 75 3a 25 70 3a 25  idKey, "%lu:%p:%
12e40 75 22 2c 20 70 50 72 6f 63 65 73 73 49 64 2c 20  u", pProcessId, 
12e50 70 70 41 64 64 72 65 73 73 2c 20 26 6e 53 69 7a  ppAddress, &nSiz
12e60 65 29 3d 3d 33 20 29 7b 0a 20 20 20 20 2a 70 6e  e)==3 ){.    *pn
12e70 53 69 7a 65 20 3d 20 28 53 49 5a 45 5f 54 29 6e  Size = (SIZE_T)n
12e80 53 69 7a 65 3b 0a 20 20 7d 65 6c 73 65 7b 0a 20  Size;.  }else{. 
12e90 20 20 20 66 6f 73 73 69 6c 5f 66 61 74 61 6c 28     fossil_fatal(
12ea0 22 66 61 69 6c 65 64 20 74 6f 20 70 61 72 73 65  "failed to parse
12eb0 20 70 69 64 20 6b 65 79 22 29 3b 0a 20 20 7d 0a   pid key");.  }.
12ec0 7d 0a 23 65 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a 20  }.#endif../*.** 
12ed0 43 4f 4d 4d 41 4e 44 3a 20 68 74 74 70 2a 0a 2a  COMMAND: http*.*
12ee0 2a 0a 2a 2a 20 55 73 61 67 65 3a 20 25 66 6f 73  *.** Usage: %fos
12ef0 73 69 6c 20 68 74 74 70 20 3f 52 45 50 4f 53 49  sil http ?REPOSI
12f00 54 4f 52 59 3f 20 3f 4f 50 54 49 4f 4e 53 3f 0a  TORY? ?OPTIONS?.
12f10 2a 2a 0a 2a 2a 20 48 61 6e 64 6c 65 20 61 20 73  **.** Handle a s
12f20 69 6e 67 6c 65 20 48 54 54 50 20 72 65 71 75 65  ingle HTTP reque
12f30 73 74 20 61 70 70 65 61 72 69 6e 67 20 6f 6e 20  st appearing on 
12f40 73 74 64 69 6e 2e 20 20 54 68 65 20 72 65 73 75  stdin.  The resu
12f50 6c 74 69 6e 67 20 77 65 62 70 61 67 65 0a 2a 2a  lting webpage.**
12f60 20 69 73 20 64 65 6c 69 76 65 72 65 64 20 6f 6e   is delivered on
12f70 20 73 74 64 6f 75 74 2e 20 20 54 68 69 73 20 6d   stdout.  This m
12f80 65 74 68 6f 64 20 69 73 20 75 73 65 64 20 74 6f  ethod is used to
12f90 20 6c 61 75 6e 63 68 20 61 6e 20 48 54 54 50 20   launch an HTTP 
12fa0 72 65 71 75 65 73 74 0a 2a 2a 20 68 61 6e 64 6c  request.** handl
12fb0 65 72 20 66 72 6f 6d 20 69 6e 65 74 64 2c 20 66  er from inetd, f
12fc0 6f 72 20 65 78 61 6d 70 6c 65 2e 20 20 54 68 65  or example.  The
12fd0 20 61 72 67 75 6d 65 6e 74 20 69 73 20 74 68 65   argument is the
12fe0 20 6e 61 6d 65 20 6f 66 20 74 68 65 0a 2a 2a 20   name of the.** 
12ff0 72 65 70 6f 73 69 74 6f 72 79 2e 0a 2a 2a 0a 2a  repository..**.*
13000 2a 20 49 66 20 52 45 50 4f 53 49 54 4f 52 59 20  * If REPOSITORY 
13010 69 73 20 61 20 64 69 72 65 63 74 6f 72 79 20 74  is a directory t
13020 68 61 74 20 63 6f 6e 74 61 69 6e 73 20 6f 6e 65  hat contains one
13030 20 6f 72 20 6d 6f 72 65 20 72 65 70 6f 73 69 74   or more reposit
13040 6f 72 69 65 73 2c 0a 2a 2a 20 65 69 74 68 65 72  ories,.** either
13050 20 64 69 72 65 63 74 6c 79 20 69 6e 20 52 45 50   directly in REP
13060 4f 53 49 54 4f 52 59 20 69 74 73 65 6c 66 20 6f  OSITORY itself o
13070 72 20 69 6e 20 73 75 62 64 69 72 65 63 74 6f 72  r in subdirector
13080 69 65 73 2c 20 61 6e 64 0a 2a 2a 20 77 69 74 68  ies, and.** with
13090 20 6e 61 6d 65 73 20 6f 66 20 74 68 65 20 66 6f   names of the fo
130a0 72 6d 20 22 2a 2e 66 6f 73 73 69 6c 22 20 74 68  rm "*.fossil" th
130b0 65 6e 20 61 20 70 72 65 66 69 78 20 6f 66 20 74  en a prefix of t
130c0 68 65 20 55 52 4c 20 70 61 74 68 6e 61 6d 65 0a  he URL pathname.
130d0 2a 2a 20 73 65 6c 65 63 74 73 20 66 72 6f 6d 20  ** selects from 
130e0 61 6d 6f 6e 67 20 74 68 65 20 76 61 72 69 6f 75  among the variou
130f0 73 20 72 65 70 6f 73 69 74 6f 72 69 65 73 2e 20  s repositories. 
13100 20 49 66 20 74 68 65 20 70 61 74 68 6e 61 6d 65   If the pathname
13110 20 64 6f 65 73 0a 2a 2a 20 6e 6f 74 20 73 65 6c   does.** not sel
13120 65 63 74 20 61 20 76 61 6c 69 64 20 72 65 70 6f  ect a valid repo
13130 73 69 74 6f 72 79 20 61 6e 64 20 74 68 65 20 2d  sitory and the -
13140 2d 6e 6f 74 66 6f 75 6e 64 20 6f 70 74 69 6f 6e  -notfound option
13150 20 69 73 20 61 76 61 69 6c 61 62 6c 65 2c 0a 2a   is available,.*
13160 2a 20 74 68 65 6e 20 74 68 65 20 73 65 72 76 65  * then the serve
13170 72 20 72 65 64 69 72 65 63 74 73 20 28 48 54 54  r redirects (HTT
13180 50 20 63 6f 64 65 20 33 30 32 29 20 74 6f 20 74  P code 302) to t
13190 68 65 20 55 52 4c 20 6f 66 20 2d 2d 6e 6f 74 66  he URL of --notf
131a0 6f 75 6e 64 2e 0a 2a 2a 20 57 68 65 6e 20 52 45  ound..** When RE
131b0 50 4f 53 49 54 4f 52 59 20 69 73 20 61 20 64 69  POSITORY is a di
131c0 72 65 63 74 6f 72 79 2c 20 74 68 65 20 70 61 74  rectory, the pat
131d0 68 6e 61 6d 65 20 6d 75 73 74 20 63 6f 6e 74 61  hname must conta
131e0 69 6e 20 6f 6e 6c 79 0a 2a 2a 20 61 6c 70 68 61  in only.** alpha
131f0 6e 75 6d 65 72 69 63 73 2c 20 22 5f 22 2c 20 22  numerics, "_", "
13200 2f 22 2c 20 22 2d 22 20 61 6e 64 20 22 2e 22 20  /", "-" and "." 
13210 61 6e 64 20 6e 6f 20 22 2d 22 20 6d 61 79 20 6f  and no "-" may o
13220 63 63 75 72 20 61 66 74 65 72 20 61 20 22 2f 22  ccur after a "/"
13230 0a 2a 2a 20 61 6e 64 20 65 76 65 72 79 20 22 2e  .** and every ".
13240 22 20 6d 75 73 74 20 62 65 20 73 75 72 72 6f 75  " must be surrou
13250 6e 64 65 64 20 6f 6e 20 62 6f 74 68 20 73 69 64  nded on both sid
13260 65 73 20 62 79 20 61 6c 70 68 61 6e 75 6d 65 72  es by alphanumer
13270 69 63 73 20 6f 72 20 65 6c 73 65 0a 2a 2a 20 61  ics or else.** a
13280 20 34 30 34 20 65 72 72 6f 72 20 69 73 20 72 65   404 error is re
13290 74 75 72 6e 65 64 2e 20 20 53 74 61 74 69 63 20  turned.  Static 
132a0 63 6f 6e 74 65 6e 74 20 66 69 6c 65 73 20 69 6e  content files in
132b0 20 74 68 65 20 64 69 72 65 63 74 6f 72 79 20 61   the directory a
132c0 72 65 0a 2a 2a 20 72 65 74 75 72 6e 65 64 20 69  re.** returned i
132d0 66 20 74 68 65 79 20 6d 61 74 63 68 20 63 6f 6d  f they match com
132e0 6d 61 2d 73 65 70 61 72 61 74 65 20 47 4c 4f 42  ma-separate GLOB
132f0 20 70 61 74 74 65 72 6e 20 73 70 65 63 69 66 69   pattern specifi
13300 65 64 20 62 79 20 2d 2d 66 69 6c 65 73 0a 2a 2a  ed by --files.**
13310 20 61 6e 64 20 64 6f 20 6e 6f 74 20 6d 61 74 63   and do not matc
13320 68 20 22 2a 2e 66 6f 73 73 69 6c 2a 22 20 61 6e  h "*.fossil*" an
13330 64 20 68 61 76 65 20 61 20 77 65 6c 6c 2d 6b 6e  d have a well-kn
13340 6f 77 6e 20 73 75 66 66 69 78 2e 0a 2a 2a 0a 2a  own suffix..**.*
13350 2a 20 54 68 65 20 2d 2d 68 6f 73 74 20 6f 70 74  * The --host opt
13360 69 6f 6e 20 63 61 6e 20 62 65 20 75 73 65 64 20  ion can be used 
13370 74 6f 20 73 70 65 63 69 66 79 20 74 68 65 20 68  to specify the h
13380 6f 73 74 6e 61 6d 65 20 66 6f 72 20 74 68 65 20  ostname for the 
13390 73 65 72 76 65 72 2e 0a 2a 2a 20 54 68 65 20 2d  server..** The -
133a0 2d 68 74 74 70 73 20 6f 70 74 69 6f 6e 20 69 6e  -https option in
133b0 64 69 63 61 74 65 73 20 74 68 61 74 20 74 68 65  dicates that the
133c0 20 72 65 71 75 65 73 74 20 63 61 6d 65 20 66 72   request came fr
133d0 6f 6d 20 48 54 54 50 53 20 72 61 74 68 65 72 0a  om HTTPS rather.
133e0 2a 2a 20 74 68 61 6e 20 48 54 54 50 2e 20 49 66  ** than HTTP. If
133f0 20 2d 2d 6e 6f 73 73 6c 20 69 73 20 67 69 76 65   --nossl is give
13400 6e 2c 20 74 68 65 6e 20 53 53 4c 20 63 6f 6e 6e  n, then SSL conn
13410 65 63 74 69 6f 6e 73 20 77 69 6c 6c 20 6e 6f 74  ections will not
13420 20 62 65 20 61 76 61 69 6c 61 62 6c 65 2c 0a 2a   be available,.*
13430 2a 20 74 68 75 73 20 61 6c 73 6f 20 6e 6f 20 72  * thus also no r
13440 65 64 69 72 65 63 74 69 6e 67 20 66 72 6f 6d 20  edirecting from 
13450 68 74 74 70 3a 20 74 6f 20 68 74 74 70 73 3a 20  http: to https: 
13460 77 69 6c 6c 20 74 61 6b 65 20 70 6c 61 63 65 2e  will take place.
13470 0a 2a 2a 0a 2a 2a 20 49 66 20 74 68 65 20 2d 2d  .**.** If the --
13480 6c 6f 63 61 6c 61 75 74 68 20 6f 70 74 69 6f 6e  localauth option
13490 20 69 73 20 67 69 76 65 6e 2c 20 74 68 65 6e 20   is given, then 
134a0 61 75 74 6f 6d 61 74 69 63 20 6c 6f 67 69 6e 20  automatic login 
134b0 69 73 20 70 65 72 66 6f 72 6d 65 64 0a 2a 2a 20  is performed.** 
134c0 66 6f 72 20 72 65 71 75 65 73 74 73 20 63 6f 6d  for requests com
134d0 69 6e 67 20 66 72 6f 6d 20 6c 6f 63 61 6c 68 6f  ing from localho
134e0 73 74 2c 20 69 66 20 74 68 65 20 22 6c 6f 63 61  st, if the "loca
134f0 6c 61 75 74 68 22 20 73 65 74 74 69 6e 67 20 69  lauth" setting i
13500 73 20 6e 6f 74 0a 2a 2a 20 65 6e 61 62 6c 65 64  s not.** enabled
13510 2e 0a 2a 2a 0a 2a 2a 20 4f 70 74 69 6f 6e 73 3a  ..**.** Options:
13520 0a 2a 2a 20 20 20 2d 2d 62 61 73 65 75 72 6c 20  .**   --baseurl 
13530 55 52 4c 20 20 20 20 62 61 73 65 20 55 52 4c 20  URL    base URL 
13540 28 75 73 65 66 75 6c 20 77 69 74 68 20 72 65 76  (useful with rev
13550 65 72 73 65 20 70 72 6f 78 69 65 73 29 0a 2a 2a  erse proxies).**
13560 20 20 20 2d 2d 65 78 74 72 6f 6f 74 20 44 49 52     --extroot DIR
13570 20 20 20 20 64 6f 63 75 6d 65 6e 74 20 72 6f 6f      document roo
13580 74 20 66 6f 72 20 74 68 65 20 2f 65 78 74 20 65  t for the /ext e
13590 78 74 65 6e 73 69 6f 6e 20 6d 65 63 68 61 6e 69  xtension mechani
135a0 73 6d 0a 2a 2a 20 20 20 2d 2d 66 69 6c 65 73 20  sm.**   --files 
135b0 47 4c 4f 42 20 20 20 20 20 63 6f 6d 6d 61 2d 73  GLOB     comma-s
135c0 65 70 61 72 61 74 65 20 67 6c 6f 62 20 70 61 74  eparate glob pat
135d0 74 65 72 6e 73 20 66 6f 72 20 73 74 61 74 69 63  terns for static
135e0 20 66 69 6c 65 20 74 6f 20 73 65 72 76 65 0a 2a   file to serve.*
135f0 2a 20 20 20 2d 2d 68 6f 73 74 20 4e 41 4d 45 20  *   --host NAME 
13600 20 20 20 20 20 73 70 65 63 69 66 79 20 68 6f 73       specify hos
13610 74 6e 61 6d 65 20 6f 66 20 74 68 65 20 73 65 72  tname of the ser
13620 76 65 72 0a 2a 2a 20 20 20 2d 2d 68 74 74 70 73  ver.**   --https
13630 20 20 20 20 20 20 20 20 20 20 73 69 67 6e 61 6c            signal
13640 20 61 20 72 65 71 75 65 73 74 20 63 6f 6d 69 6e   a request comin
13650 67 20 69 6e 20 76 69 61 20 68 74 74 70 73 0a 2a  g in via https.*
13660 2a 20 20 20 2d 2d 69 6e 20 46 49 4c 45 20 20 20  *   --in FILE   
13670 20 20 20 20 20 54 61 6b 65 20 69 6e 70 75 74 20       Take input 
13680 66 72 6f 6d 20 46 49 4c 45 20 69 6e 73 74 65 61  from FILE instea
13690 64 20 6f 66 20 73 74 61 6e 64 61 72 64 20 69 6e  d of standard in
136a0 70 75 74 0a 2a 2a 20 20 20 2d 2d 69 70 61 64 64  put.**   --ipadd
136b0 72 20 41 44 44 52 20 20 20 20 41 73 73 75 6d 65  r ADDR    Assume
136c0 20 74 68 65 20 72 65 71 75 65 73 74 20 63 6f 6d   the request com
136d0 65 73 20 66 72 6f 6d 20 74 68 65 20 67 69 76 65  es from the give
136e0 6e 20 49 50 20 61 64 64 72 65 73 73 0a 2a 2a 20  n IP address.** 
136f0 20 20 2d 2d 6c 6f 63 61 6c 61 75 74 68 20 20 20    --localauth   
13700 20 20 20 65 6e 61 62 6c 65 20 61 75 74 6f 6d 61     enable automa
13710 74 69 63 20 6c 6f 67 69 6e 20 66 6f 72 20 6c 6f  tic login for lo
13720 63 61 6c 20 63 6f 6e 6e 65 63 74 69 6f 6e 73 0a  cal connections.
13730 2a 2a 20 20 20 2d 2d 6e 6f 63 6f 6d 70 72 65 73  **   --nocompres
13740 73 20 20 20 20 20 64 6f 20 6e 6f 74 20 63 6f 6d  s     do not com
13750 70 72 65 73 73 20 48 54 54 50 20 72 65 70 6c 69  press HTTP repli
13760 65 73 0a 2a 2a 20 20 20 2d 2d 6e 6f 64 65 6c 61  es.**   --nodela
13770 79 20 20 20 20 20 20 20 20 6f 6d 69 74 20 62 61  y        omit ba
13780 63 6b 6f 66 66 69 63 65 20 70 72 6f 63 65 73 73  ckoffice process
13790 69 6e 67 20 69 66 20 69 74 20 77 6f 75 6c 64 20  ing if it would 
137a0 64 65 6c 61 79 20 70 72 6f 63 65 73 73 20 65 78  delay process ex
137b0 69 74 0a 2a 2a 20 20 20 2d 2d 6e 6f 6a 61 69 6c  it.**   --nojail
137c0 20 20 20 20 20 20 20 20 20 64 72 6f 70 20 72 6f           drop ro
137d0 6f 74 20 70 72 69 76 69 6c 65 67 65 20 62 75 74  ot privilege but
137e0 20 64 6f 20 6e 6f 74 20 65 6e 74 65 72 20 74 68   do not enter th
137f0 65 20 63 68 72 6f 6f 74 20 6a 61 69 6c 0a 2a 2a  e chroot jail.**
13800 20 20 20 2d 2d 6e 6f 73 73 6c 20 20 20 20 20 20     --nossl      
13810 20 20 20 20 73 69 67 6e 61 6c 20 74 68 61 74 20      signal that 
13820 6e 6f 20 53 53 4c 20 63 6f 6e 6e 65 63 74 69 6f  no SSL connectio
13830 6e 73 20 61 72 65 20 61 76 61 69 6c 61 62 6c 65  ns are available
13840 0a 2a 2a 20 20 20 2d 2d 6e 6f 74 66 6f 75 6e 64  .**   --notfound
13850 20 55 52 4c 20 20 20 75 73 65 20 55 52 4c 20 61   URL   use URL a
13860 73 20 22 48 54 54 50 20 34 30 34 2c 20 6f 62 6a  s "HTTP 404, obj
13870 65 63 74 20 6e 6f 74 20 66 6f 75 6e 64 22 20 70  ect not found" p
13880 61 67 65 2e 0a 2a 2a 20 20 20 2d 2d 6f 75 74 20  age..**   --out 
13890 46 49 4c 45 20 20 20 20 20 20 20 77 72 69 74 65  FILE       write
138a0 20 72 65 73 75 6c 74 73 20 74 6f 20 46 49 4c 45   results to FILE
138b0 20 69 6e 73 74 65 61 64 20 6f 66 20 74 6f 20 73   instead of to s
138c0 74 61 6e 64 61 72 64 20 6f 75 74 70 75 74 0a 2a  tandard output.*
138d0 2a 20 20 20 2d 2d 72 65 70 6f 6c 69 73 74 20 20  *   --repolist  
138e0 20 20 20 20 20 49 66 20 52 45 50 4f 53 49 54 4f       If REPOSITO
138f0 52 59 20 69 73 20 64 69 72 65 63 74 6f 72 79 2c  RY is directory,
13900 20 55 52 4c 20 22 2f 22 20 6c 69 73 74 73 20 61   URL "/" lists a
13910 6c 6c 20 72 65 70 6f 73 0a 2a 2a 20 20 20 2d 2d  ll repos.**   --
13920 73 63 67 69 20 20 20 20 20 20 20 20 20 20 20 49  scgi           I
13930 6e 74 65 72 70 72 65 74 20 69 6e 70 75 74 20 61  nterpret input a
13940 73 20 53 43 47 49 20 72 61 74 68 65 72 20 74 68  s SCGI rather th
13950 61 6e 20 48 54 54 50 0a 2a 2a 20 20 20 2d 2d 73  an HTTP.**   --s
13960 6b 69 6e 20 4c 41 42 45 4c 20 20 20 20 20 55 73  kin LABEL     Us
13970 65 20 6f 76 65 72 72 69 64 65 20 73 6b 69 6e 20  e override skin 
13980 4c 41 42 45 4c 0a 2a 2a 20 20 20 2d 2d 74 68 2d  LABEL.**   --th-
13990 74 72 61 63 65 20 20 20 20 20 20 20 74 72 61 63  trace       trac
139a0 65 20 54 48 31 20 65 78 65 63 75 74 69 6f 6e 20  e TH1 execution 
139b0 28 66 6f 72 20 64 65 62 75 67 67 69 6e 67 20 70  (for debugging p
139c0 75 72 70 6f 73 65 73 29 0a 2a 2a 20 20 20 2d 2d  urposes).**   --
139d0 75 73 65 70 69 64 6b 65 79 20 20 20 20 20 20 55  usepidkey      U
139e0 73 65 20 73 61 76 65 64 20 65 6e 63 72 79 70 74  se saved encrypt
139f0 69 6f 6e 20 6b 65 79 20 66 72 6f 6d 20 70 61 72  ion key from par
13a00 65 6e 74 20 70 72 6f 63 65 73 73 2e 20 20 54 68  ent process.  Th
13a10 69 73 20 69 73 0a 2a 2a 20 20 20 20 20 20 20 20  is is.**        
13a20 20 20 20 20 20 20 20 20 20 20 20 20 6f 6e 6c 79              only
13a30 20 6e 65 63 65 73 73 61 72 79 20 77 68 65 6e 20   necessary when 
13a40 75 73 69 6e 67 20 53 45 45 20 6f 6e 20 57 69 6e  using SEE on Win
13a50 64 6f 77 73 2e 0a 2a 2a 0a 2a 2a 20 53 65 65 20  dows..**.** See 
13a60 61 6c 73 6f 3a 20 63 67 69 2c 20 73 65 72 76 65  also: cgi, serve
13a70 72 2c 20 77 69 6e 73 72 76 0a 2a 2f 0a 76 6f 69  r, winsrv.*/.voi
13a80 64 20 63 6d 64 5f 68 74 74 70 28 76 6f 69 64 29  d cmd_http(void)
13a90 7b 0a 20 20 63 6f 6e 73 74 20 63 68 61 72 20 2a  {.  const char *
13aa0 7a 49 70 41 64 64 72 20 3d 20 30 3b 0a 20 20 63  zIpAddr = 0;.  c
13ab0 6f 6e 73 74 20 63 68 61 72 20 2a 7a 4e 6f 74 46  onst char *zNotF
13ac0 6f 75 6e 64 3b 0a 20 20 63 6f 6e 73 74 20 63 68  ound;.  const ch
13ad0 61 72 20 2a 7a 48 6f 73 74 3b 0a 20 20 63 6f 6e  ar *zHost;.  con
13ae0 73 74 20 63 68 61 72 20 2a 7a 41 6c 74 42 61 73  st char *zAltBas
13af0 65 3b 0a 20 20 63 6f 6e 73 74 20 63 68 61 72 20  e;.  const char 
13b00 2a 7a 46 69 6c 65 47 6c 6f 62 3b 0a 20 20 63 6f  *zFileGlob;.  co
13b10 6e 73 74 20 63 68 61 72 20 2a 7a 49 6e 46 69 6c  nst char *zInFil
13b20 65 3b 0a 20 20 63 6f 6e 73 74 20 63 68 61 72 20  e;.  const char 
13b30 2a 7a 4f 75 74 46 69 6c 65 3b 0a 20 20 69 6e 74  *zOutFile;.  int
13b40 20 75 73 65 53 43 47 49 3b 0a 20 20 69 6e 74 20   useSCGI;.  int 
13b50 6e 6f 4a 61 69 6c 3b 0a 20 20 69 6e 74 20 61 6c  noJail;.  int al
13b60 6c 6f 77 52 65 70 6f 4c 69 73 74 3b 0a 23 69 66  lowRepoList;.#if
13b70 20 64 65 66 69 6e 65 64 28 5f 57 49 4e 33 32 29   defined(_WIN32)
13b80 20 26 26 20 55 53 45 5f 53 45 45 0a 20 20 63 6f   && USE_SEE.  co
13b90 6e 73 74 20 63 68 61 72 20 2a 7a 50 69 64 4b 65  nst char *zPidKe
13ba0 79 3b 0a 23 65 6e 64 69 66 0a 0a 20 20 54 68 5f  y;.#endif..  Th_
13bb0 49 6e 69 74 54 72 61 63 65 4c 6f 67 28 29 3b 0a  InitTraceLog();.
13bc0 0a 20 20 2f 2a 20 54 68 65 20 77 69 6e 68 74 74  .  /* The winhtt
13bd0 70 20 6d 6f 64 75 6c 65 20 70 61 73 73 65 73 20  p module passes 
13be0 74 68 65 20 2d 2d 66 69 6c 65 73 20 6f 70 74 69  the --files opti
13bf0 6f 6e 20 61 73 20 2d 2d 66 69 6c 65 73 2d 75 72  on as --files-ur
13c00 6c 65 6e 63 20 77 69 74 68 0a 20 20 2a 2a 20 74  lenc with.  ** t
13c10 68 65 20 61 72 67 75 6d 65 6e 74 20 62 65 69 6e  he argument bein
13c20 67 20 55 52 4c 20 65 6e 63 6f 64 65 64 2c 20 74  g URL encoded, t
13c30 6f 20 61 76 6f 69 64 20 77 69 6c 64 63 61 72 64  o avoid wildcard
13c40 20 65 78 70 61 6e 73 69 6f 6e 20 69 6e 20 74 68   expansion in th
13c50 65 0a 20 20 2a 2a 20 73 68 65 6c 6c 2e 20 20 54  e.  ** shell.  T
13c60 68 69 73 20 6f 70 74 69 6f 6e 20 69 73 20 66 6f  his option is fo
13c70 72 20 69 6e 74 65 72 6e 61 6c 20 75 73 65 20 61  r internal use a
13c80 6e 64 20 69 73 20 75 6e 64 6f 63 75 6d 65 6e 74  nd is undocument
13c90 65 64 2e 0a 20 20 2a 2f 0a 20 20 7a 46 69 6c 65  ed..  */.  zFile
13ca0 47 6c 6f 62 20 3d 20 66 69 6e 64 5f 6f 70 74 69  Glob = find_opti
13cb0 6f 6e 28 22 66 69 6c 65 73 2d 75 72 6c 65 6e 63  on("files-urlenc
13cc0 22 2c 30 2c 31 29 3b 0a 20 20 69 66 28 20 7a 46  ",0,1);.  if( zF
13cd0 69 6c 65 47 6c 6f 62 20 29 7b 0a 20 20 20 20 63  ileGlob ){.    c
13ce0 68 61 72 20 2a 7a 20 3d 20 6d 70 72 69 6e 74 66  har *z = mprintf
13cf0 28 22 25 73 22 2c 20 7a 46 69 6c 65 47 6c 6f 62  ("%s", zFileGlob
13d00 29 3b 0a 20 20 20 20 64 65 68 74 74 70 69 7a 65  );.    dehttpize
13d10 28 7a 29 3b 0a 20 20 20 20 7a 46 69 6c 65 47 6c  (z);.    zFileGl
13d20 6f 62 20 3d 20 7a 3b 0a 20 20 7d 65 6c 73 65 7b  ob = z;.  }else{
13d30 0a 20 20 20 20 7a 46 69 6c 65 47 6c 6f 62 20 3d  .    zFileGlob =
13d40 20 66 69 6e 64 5f 6f 70 74 69 6f 6e 28 22 66 69   find_option("fi
13d50 6c 65 73 22 2c 30 2c 31 29 3b 0a 20 20 7d 0a 20  les",0,1);.  }. 
13d60 20 73 6b 69 6e 5f 6f 76 65 72 72 69 64 65 28 29   skin_override()
13d70 3b 0a 20 20 7a 4e 6f 74 46 6f 75 6e 64 20 3d 20  ;.  zNotFound = 
13d80 66 69 6e 64 5f 6f 70 74 69 6f 6e 28 22 6e 6f 74  find_option("not
13d90 66 6f 75 6e 64 22 2c 20 30 2c 20 31 29 3b 0a 20  found", 0, 1);. 
13da0 20 6e 6f 4a 61 69 6c 20 3d 20 66 69 6e 64 5f 6f   noJail = find_o
13db0 70 74 69 6f 6e 28 22 6e 6f 6a 61 69 6c 22 2c 30  ption("nojail",0
13dc0 2c 30 29 21 3d 30 3b 0a 20 20 61 6c 6c 6f 77 52  ,0)!=0;.  allowR
13dd0 65 70 6f 4c 69 73 74 20 3d 20 66 69 6e 64 5f 6f  epoList = find_o
13de0 70 74 69 6f 6e 28 22 72 65 70 6f 6c 69 73 74 22  ption("repolist"
13df0 2c 30 2c 30 29 21 3d 30 3b 0a 20 20 67 2e 75 73  ,0,0)!=0;.  g.us
13e00 65 4c 6f 63 61 6c 61 75 74 68 20 3d 20 66 69 6e  eLocalauth = fin
13e10 64 5f 6f 70 74 69 6f 6e 28 22 6c 6f 63 61 6c 61  d_option("locala
13e20 75 74 68 22 2c 20 30 2c 20 30 29 21 3d 30 3b 0a  uth", 0, 0)!=0;.
13e30 20 20 67 2e 73 73 6c 4e 6f 74 41 76 61 69 6c 61    g.sslNotAvaila
13e40 62 6c 65 20 3d 20 66 69 6e 64 5f 6f 70 74 69 6f  ble = find_optio
13e50 6e 28 22 6e 6f 73 73 6c 22 2c 20 30 2c 20 30 29  n("nossl", 0, 0)
13e60 21 3d 30 3b 0a 20 20 67 2e 66 4e 6f 48 74 74 70  !=0;.  g.fNoHttp
13e70 43 6f 6d 70 72 65 73 73 20 3d 20 66 69 6e 64 5f  Compress = find_
13e80 6f 70 74 69 6f 6e 28 22 6e 6f 63 6f 6d 70 72 65  option("nocompre
13e90 73 73 22 2c 30 2c 30 29 21 3d 30 3b 0a 20 20 67  ss",0,0)!=0;.  g
13ea0 2e 7a 45 78 74 52 6f 6f 74 20 3d 20 66 69 6e 64  .zExtRoot = find
13eb0 5f 6f 70 74 69 6f 6e 28 22 65 78 74 72 6f 6f 74  _option("extroot
13ec0 22 2c 30 2c 31 29 3b 0a 20 20 7a 49 6e 46 69 6c  ",0,1);.  zInFil
13ed0 65 20 3d 20 66 69 6e 64 5f 6f 70 74 69 6f 6e 28  e = find_option(
13ee0 22 69 6e 22 2c 30 2c 31 29 3b 0a 20 20 69 66 28  "in",0,1);.  if(
13ef0 20 7a 49 6e 46 69 6c 65 20 29 7b 0a 20 20 20 20   zInFile ){.    
13f00 62 61 63 6b 6f 66 66 69 63 65 5f 64 69 73 61 62  backoffice_disab
13f10 6c 65 28 29 3b 0a 20 20 20 20 67 2e 68 74 74 70  le();.    g.http
13f20 49 6e 20 3d 20 66 6f 73 73 69 6c 5f 66 6f 70 65  In = fossil_fope
13f30 6e 28 7a 49 6e 46 69 6c 65 2c 20 22 72 62 22 29  n(zInFile, "rb")
13f40 3b 0a 20 20 20 20 69 66 28 20 67 2e 68 74 74 70  ;.    if( g.http
13f50 49 6e 3d 3d 30 20 29 20 66 6f 73 73 69 6c 5f 66  In==0 ) fossil_f
13f60 61 74 61 6c 28 22 63 61 6e 6e 6f 74 20 6f 70 65  atal("cannot ope
13f70 6e 20 5c 22 25 73 5c 22 20 66 6f 72 20 72 65 61  n \"%s\" for rea
13f80 64 69 6e 67 22 2c 20 7a 49 6e 46 69 6c 65 29 3b  ding", zInFile);
13f90 0a 20 20 7d 65 6c 73 65 7b 0a 20 20 20 20 67 2e  .  }else{.    g.
13fa0 68 74 74 70 49 6e 20 3d 20 73 74 64 69 6e 3b 0a  httpIn = stdin;.
13fb0 20 20 7d 0a 20 20 7a 4f 75 74 46 69 6c 65 20 3d    }.  zOutFile =
13fc0 20 66 69 6e 64 5f 6f 70 74 69 6f 6e 28 22 6f 75   find_option("ou
13fd0 74 22 2c 30 2c 31 29 3b 0a 20 20 69 66 28 20 7a  t",0,1);.  if( z
13fe0 4f 75 74 46 69 6c 65 20 29 7b 0a 20 20 20 20 67  OutFile ){.    g
13ff0 2e 68 74 74 70 4f 75 74 20 3d 20 66 6f 73 73 69  .httpOut = fossi
14000 6c 5f 66 6f 70 65 6e 28 7a 4f 75 74 46 69 6c 65  l_fopen(zOutFile
14010 2c 20 22 77 62 22 29 3b 0a 20 20 20 20 69 66 28  , "wb");.    if(
14020 20 67 2e 68 74 74 70 4f 75 74 3d 3d 30 20 29 20   g.httpOut==0 ) 
14030 66 6f 73 73 69 6c 5f 66 61 74 61 6c 28 22 63 61  fossil_fatal("ca
14040 6e 6e 6f 74 20 6f 70 65 6e 20 5c 22 25 73 5c 22  nnot open \"%s\"
14050 20 66 6f 72 20 77 72 69 74 69 6e 67 22 2c 20 7a   for writing", z
14060 4f 75 74 46 69 6c 65 29 3b 0a 20 20 7d 65 6c 73  OutFile);.  }els
14070 65 7b 0a 20 20 20 20 67 2e 68 74 74 70 4f 75 74  e{.    g.httpOut
14080 20 3d 20 73 74 64 6f 75 74 3b 0a 20 20 7d 0a 20   = stdout;.  }. 
14090 20 7a 49 70 41 64 64 72 20 3d 20 66 69 6e 64 5f   zIpAddr = find_
140a0 6f 70 74 69 6f 6e 28 22 69 70 61 64 64 72 22 2c  option("ipaddr",
140b0 30 2c 31 29 3b 0a 20 20 75 73 65 53 43 47 49 20  0,1);.  useSCGI 
140c0 3d 20 66 69 6e 64 5f 6f 70 74 69 6f 6e 28 22 73  = find_option("s
140d0 63 67 69 22 2c 20 30 2c 20 30 29 21 3d 30 3b 0a  cgi", 0, 0)!=0;.
140e0 20 20 7a 41 6c 74 42 61 73 65 20 3d 20 66 69 6e    zAltBase = fin
140f0 64 5f 6f 70 74 69 6f 6e 28 22 62 61 73 65 75 72  d_option("baseur
14100 6c 22 2c 20 30 2c 20 31 29 3b 0a 20 20 69 66 28  l", 0, 1);.  if(
14110 20 66 69 6e 64 5f 6f 70 74 69 6f 6e 28 22 6e 6f   find_option("no
14120 64 65 6c 61 79 22 2c 30 2c 30 29 21 3d 30 20 29  delay",0,0)!=0 )
14130 20 62 61 63 6b 6f 66 66 69 63 65 5f 6e 6f 5f 64   backoffice_no_d
14140 65 6c 61 79 28 29 3b 0a 20 20 69 66 28 20 7a 41  elay();.  if( zA
14150 6c 74 42 61 73 65 20 29 20 73 65 74 5f 62 61 73  ltBase ) set_bas
14160 65 5f 75 72 6c 28 7a 41 6c 74 42 61 73 65 29 3b  e_url(zAltBase);
14170 0a 20 20 69 66 28 20 66 69 6e 64 5f 6f 70 74 69  .  if( find_opti
14180 6f 6e 28 22 68 74 74 70 73 22 2c 30 2c 30 29 21  on("https",0,0)!
14190 3d 30 20 29 7b 0a 20 20 20 20 7a 49 70 41 64 64  =0 ){.    zIpAdd
141a0 72 20 3d 20 66 6f 73 73 69 6c 5f 67 65 74 65 6e  r = fossil_geten
141b0 76 28 22 52 45 4d 4f 54 45 5f 48 4f 53 54 22 29  v("REMOTE_HOST")
141c0 3b 20 2f 2a 20 46 72 6f 6d 20 73 74 75 6e 6e 65  ; /* From stunne
141d0 6c 20 2a 2f 0a 20 20 20 20 63 67 69 5f 72 65 70  l */.    cgi_rep
141e0 6c 61 63 65 5f 70 61 72 61 6d 65 74 65 72 28 22  lace_parameter("
141f0 48 54 54 50 53 22 2c 22 6f 6e 22 29 3b 0a 20 20  HTTPS","on");.  
14200 7d 0a 20 20 7a 48 6f 73 74 20 3d 20 66 69 6e 64  }.  zHost = find
14210 5f 6f 70 74 69 6f 6e 28 22 68 6f 73 74 22 2c 20  _option("host", 
14220 30 2c 20 31 29 3b 0a 20 20 69 66 28 20 7a 48 6f  0, 1);.  if( zHo
14230 73 74 20 29 20 63 67 69 5f 72 65 70 6c 61 63 65  st ) cgi_replace
14240 5f 70 61 72 61 6d 65 74 65 72 28 22 48 54 54 50  _parameter("HTTP
14250 5f 48 4f 53 54 22 2c 7a 48 6f 73 74 29 3b 0a 0a  _HOST",zHost);..
14260 23 69 66 20 64 65 66 69 6e 65 64 28 5f 57 49 4e  #if defined(_WIN
14270 33 32 29 20 26 26 20 55 53 45 5f 53 45 45 0a 20  32) && USE_SEE. 
14280 20 7a 50 69 64 4b 65 79 20 3d 20 66 69 6e 64 5f   zPidKey = find_
14290 6f 70 74 69 6f 6e 28 22 75 73 65 70 69 64 6b 65  option("usepidke
142a0 79 22 2c 20 30 2c 20 31 29 3b 0a 20 20 69 66 28  y", 0, 1);.  if(
142b0 20 7a 50 69 64 4b 65 79 20 29 7b 0a 20 20 20 20   zPidKey ){.    
142c0 44 57 4f 52 44 20 70 72 6f 63 65 73 73 49 64 20  DWORD processId 
142d0 3d 20 30 3b 0a 20 20 20 20 4c 50 56 4f 49 44 20  = 0;.    LPVOID 
142e0 70 41 64 64 72 65 73 73 20 3d 20 4e 55 4c 4c 3b  pAddress = NULL;
142f0 0a 20 20 20 20 53 49 5a 45 5f 54 20 6e 53 69 7a  .    SIZE_T nSiz
14300 65 20 3d 20 30 3b 0a 20 20 20 20 70 61 72 73 65  e = 0;.    parse
14310 5f 70 69 64 5f 6b 65 79 5f 76 61 6c 75 65 28 7a  _pid_key_value(z
14320 50 69 64 4b 65 79 2c 20 26 70 72 6f 63 65 73 73  PidKey, &process
14330 49 64 2c 20 26 70 41 64 64 72 65 73 73 2c 20 26  Id, &pAddress, &
14340 6e 53 69 7a 65 29 3b 0a 20 20 20 20 64 62 5f 72  nSize);.    db_r
14350 65 61 64 5f 73 61 76 65 64 5f 65 6e 63 72 79 70  ead_saved_encryp
14360 74 69 6f 6e 5f 6b 65 79 5f 66 72 6f 6d 5f 70 72  tion_key_from_pr
14370 6f 63 65 73 73 28 70 72 6f 63 65 73 73 49 64 2c  ocess(processId,
14380 20 70 41 64 64 72 65 73 73 2c 20 6e 53 69 7a 65   pAddress, nSize
14390 29 3b 0a 20 20 7d 0a 23 65 6e 64 69 66 0a 0a 20  );.  }.#endif.. 
143a0 20 2f 2a 20 57 65 20 73 68 6f 75 6c 64 20 62 65   /* We should be
143b0 20 64 6f 6e 65 20 77 69 74 68 20 6f 70 74 69 6f   done with optio
143c0 6e 73 2e 2e 20 2a 2f 0a 20 20 76 65 72 69 66 79  ns.. */.  verify
143d0 5f 61 6c 6c 5f 6f 70 74 69 6f 6e 73 28 29 3b 0a  _all_options();.
143e0 0a 20 20 69 66 28 20 67 2e 61 72 67 63 21 3d 32  .  if( g.argc!=2
143f0 20 26 26 20 67 2e 61 72 67 63 21 3d 33 20 29 20   && g.argc!=3 ) 
14400 75 73 61 67 65 28 22 3f 52 45 50 4f 53 49 54 4f  usage("?REPOSITO
14410 52 59 3f 22 29 3b 0a 20 20 67 2e 63 67 69 4f 75  RY?");.  g.cgiOu
14420 74 70 75 74 20 3d 20 31 3b 0a 20 20 67 2e 66 75  tput = 1;.  g.fu
14430 6c 6c 48 74 74 70 52 65 70 6c 79 20 3d 20 31 3b  llHttpReply = 1;
14440 0a 20 20 66 69 6e 64 5f 73 65 72 76 65 72 5f 72  .  find_server_r
14450 65 70 6f 73 69 74 6f 72 79 28 32 2c 20 30 29 3b  epository(2, 0);
14460 0a 20 20 69 66 28 20 7a 49 70 41 64 64 72 3d 3d  .  if( zIpAddr==
14470 30 20 29 7b 0a 20 20 20 20 7a 49 70 41 64 64 72  0 ){.    zIpAddr
14480 20 3d 20 63 67 69 5f 73 73 68 5f 72 65 6d 6f 74   = cgi_ssh_remot
14490 65 5f 61 64 64 72 28 30 29 3b 0a 20 20 20 20 69  e_addr(0);.    i
144a0 66 28 20 7a 49 70 41 64 64 72 20 26 26 20 7a 49  f( zIpAddr && zI
144b0 70 41 64 64 72 5b 30 5d 20 29 7b 0a 20 20 20 20  pAddr[0] ){.    
144c0 20 20 67 2e 66 53 73 68 43 6c 69 65 6e 74 20 7c    g.fSshClient |
144d0 3d 20 43 47 49 5f 53 53 48 5f 43 4c 49 45 4e 54  = CGI_SSH_CLIENT
144e0 3b 0a 20 20 20 20 7d 0a 20 20 7d 0a 20 20 67 2e  ;.    }.  }.  g.
144f0 7a 52 65 70 6f 73 69 74 6f 72 79 4e 61 6d 65 20  zRepositoryName 
14500 3d 20 65 6e 74 65 72 5f 63 68 72 6f 6f 74 5f 6a  = enter_chroot_j
14510 61 69 6c 28 67 2e 7a 52 65 70 6f 73 69 74 6f 72  ail(g.zRepositor
14520 79 4e 61 6d 65 2c 20 6e 6f 4a 61 69 6c 29 3b 0a  yName, noJail);.
14530 20 20 69 66 28 20 75 73 65 53 43 47 49 20 29 7b    if( useSCGI ){
14540 0a 20 20 20 20 63 67 69 5f 68 61 6e 64 6c 65 5f  .    cgi_handle_
14550 73 63 67 69 5f 72 65 71 75 65 73 74 28 29 3b 0a  scgi_request();.
14560 20 20 7d 65 6c 73 65 20 69 66 28 20 67 2e 66 53    }else if( g.fS
14570 73 68 43 6c 69 65 6e 74 20 26 20 43 47 49 5f 53  shClient & CGI_S
14580 53 48 5f 43 4c 49 45 4e 54 20 29 7b 0a 20 20 20  SH_CLIENT ){.   
14590 20 73 73 68 5f 72 65 71 75 65 73 74 5f 6c 6f 6f   ssh_request_loo
145a0 70 28 7a 49 70 41 64 64 72 2c 20 67 6c 6f 62 5f  p(zIpAddr, glob_
145b0 63 72 65 61 74 65 28 7a 46 69 6c 65 47 6c 6f 62  create(zFileGlob
145c0 29 29 3b 0a 20 20 7d 65 6c 73 65 7b 0a 20 20 20  ));.  }else{.   
145d0 20 63 67 69 5f 68 61 6e 64 6c 65 5f 68 74 74 70   cgi_handle_http
145e0 5f 72 65 71 75 65 73 74 28 7a 49 70 41 64 64 72  _request(zIpAddr
145f0 29 3b 0a 20 20 7d 0a 20 20 70 72 6f 63 65 73 73  );.  }.  process
14600 5f 6f 6e 65 5f 77 65 62 5f 70 61 67 65 28 7a 4e  _one_web_page(zN
14610 6f 74 46 6f 75 6e 64 2c 20 67 6c 6f 62 5f 63 72  otFound, glob_cr
14620 65 61 74 65 28 7a 46 69 6c 65 47 6c 6f 62 29 2c  eate(zFileGlob),
14630 20 61 6c 6c 6f 77 52 65 70 6f 4c 69 73 74 29 3b   allowRepoList);
14640 0a 7d 0a 0a 2f 2a 0a 2a 2a 20 50 72 6f 63 65 73  .}../*.** Proces
14650 73 20 61 6c 6c 20 72 65 71 75 65 73 74 73 20 69  s all requests i
14660 6e 20 61 20 73 69 6e 67 6c 65 20 53 53 48 20 63  n a single SSH c
14670 6f 6e 6e 65 63 74 69 6f 6e 20 69 66 20 70 6f 73  onnection if pos
14680 73 69 62 6c 65 2e 0a 2a 2f 0a 76 6f 69 64 20 73  sible..*/.void s
14690 73 68 5f 72 65 71 75 65 73 74 5f 6c 6f 6f 70 28  sh_request_loop(
146a0 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a 49 70 41  const char *zIpA
146b0 64 64 72 2c 20 47 6c 6f 62 20 2a 46 69 6c 65 47  ddr, Glob *FileG
146c0 6c 6f 62 29 7b 0a 20 20 62 6c 6f 62 5f 7a 65 72  lob){.  blob_zer
146d0 6f 28 26 67 2e 63 67 69 49 6e 29 3b 0a 20 20 64  o(&g.cgiIn);.  d
146e0 6f 7b 0a 20 20 20 20 63 67 69 5f 68 61 6e 64 6c  o{.    cgi_handl
146f0 65 5f 73 73 68 5f 68 74 74 70 5f 72 65 71 75 65  e_ssh_http_reque
14700 73 74 28 7a 49 70 41 64 64 72 29 3b 0a 20 20 20  st(zIpAddr);.   
14710 20 70 72 6f 63 65 73 73 5f 6f 6e 65 5f 77 65 62   process_one_web
14720 5f 70 61 67 65 28 30 2c 20 46 69 6c 65 47 6c 6f  _page(0, FileGlo
14730 62 2c 20 30 29 3b 0a 20 20 20 20 62 6c 6f 62 5f  b, 0);.    blob_
14740 72 65 73 65 74 28 26 67 2e 63 67 69 49 6e 29 3b  reset(&g.cgiIn);
14750 0a 20 20 7d 20 77 68 69 6c 65 20 28 20 67 2e 66  .  } while ( g.f
14760 53 73 68 43 6c 69 65 6e 74 20 26 20 43 47 49 5f  SshClient & CGI_
14770 53 53 48 5f 46 4f 53 53 49 4c 20 7c 7c 0a 20 20  SSH_FOSSIL ||.  
14780 20 20 20 20 20 20 20 20 67 2e 66 53 73 68 43 6c          g.fSshCl
14790 69 65 6e 74 20 26 20 43 47 49 5f 53 53 48 5f 43  ient & CGI_SSH_C
147a0 4f 4d 50 41 54 20 29 3b 0a 7d 0a 0a 2f 2a 0a 2a  OMPAT );.}../*.*
147b0 2a 20 4e 6f 74 65 20 74 68 61 74 20 74 68 65 20  * Note that the 
147c0 66 6f 6c 6c 6f 77 69 6e 67 20 63 6f 6d 6d 61 6e  following comman
147d0 64 20 69 73 20 75 73 65 64 20 62 79 20 73 73 68  d is used by ssh
147e0 3a 2f 2f 20 70 72 6f 63 65 73 73 69 6e 67 2e 0a  :// processing..
147f0 2a 2a 0a 2a 2a 20 43 4f 4d 4d 41 4e 44 3a 20 74  **.** COMMAND: t
14800 65 73 74 2d 68 74 74 70 0a 2a 2a 0a 2a 2a 20 57  est-http.**.** W
14810 6f 72 6b 73 20 6c 69 6b 65 20 74 68 65 20 68 74  orks like the ht
14820 74 70 20 63 6f 6d 6d 61 6e 64 20 62 75 74 20 67  tp command but g
14830 69 76 65 73 20 73 65 74 75 70 20 70 65 72 6d 69  ives setup permi
14840 73 73 69 6f 6e 20 74 6f 20 61 6c 6c 20 75 73 65  ssion to all use
14850 72 73 2e 0a 2a 2a 0a 2a 2a 20 4f 70 74 69 6f 6e  rs..**.** Option
14860 73 3a 0a 2a 2a 20 20 20 2d 2d 74 68 2d 74 72 61  s:.**   --th-tra
14870 63 65 20 20 20 20 20 20 20 20 20 20 74 72 61 63  ce          trac
14880 65 20 54 48 31 20 65 78 65 63 75 74 69 6f 6e 20  e TH1 execution 
14890 28 66 6f 72 20 64 65 62 75 67 67 69 6e 67 20 70  (for debugging p
148a0 75 72 70 6f 73 65 73 29 0a 2a 2a 0a 2a 2f 0a 76  urposes).**.*/.v
148b0 6f 69 64 20 63 6d 64 5f 74 65 73 74 5f 68 74 74  oid cmd_test_htt
148c0 70 28 76 6f 69 64 29 7b 0a 20 20 63 6f 6e 73 74  p(void){.  const
148d0 20 63 68 61 72 20 2a 7a 49 70 41 64 64 72 3b 20   char *zIpAddr; 
148e0 20 20 20 2f 2a 20 49 50 20 61 64 64 72 65 73 73     /* IP address
148f0 20 6f 66 20 72 65 6d 6f 74 65 20 63 6c 69 65 6e   of remote clien
14900 74 20 2a 2f 0a 0a 20 20 54 68 5f 49 6e 69 74 54  t */..  Th_InitT
14910 72 61 63 65 4c 6f 67 28 29 3b 0a 20 20 6c 6f 67  raceLog();.  log
14920 69 6e 5f 73 65 74 5f 63 61 70 61 62 69 6c 69 74  in_set_capabilit
14930 69 65 73 28 22 73 78 22 2c 20 30 29 3b 0a 20 20  ies("sx", 0);.  
14940 67 2e 75 73 65 4c 6f 63 61 6c 61 75 74 68 20 3d  g.useLocalauth =
14950 20 31 3b 0a 20 20 67 2e 68 74 74 70 49 6e 20 3d   1;.  g.httpIn =
14960 20 73 74 64 69 6e 3b 0a 20 20 67 2e 68 74 74 70   stdin;.  g.http
14970 4f 75 74 20 3d 20 73 74 64 6f 75 74 3b 0a 20 20  Out = stdout;.  
14980 67 2e 7a 45 78 74 52 6f 6f 74 20 3d 20 66 69 6e  g.zExtRoot = fin
14990 64 5f 6f 70 74 69 6f 6e 28 22 65 78 74 72 6f 6f  d_option("extroo
149a0 74 22 2c 30 2c 31 29 3b 0a 20 20 66 69 6e 64 5f  t",0,1);.  find_
149b0 73 65 72 76 65 72 5f 72 65 70 6f 73 69 74 6f 72  server_repositor
149c0 79 28 32 2c 20 30 29 3b 0a 20 20 67 2e 63 67 69  y(2, 0);.  g.cgi
149d0 4f 75 74 70 75 74 20 3d 20 31 3b 0a 20 20 67 2e  Output = 1;.  g.
149e0 66 4e 6f 48 74 74 70 43 6f 6d 70 72 65 73 73 20  fNoHttpCompress 
149f0 3d 20 31 3b 0a 20 20 67 2e 66 75 6c 6c 48 74 74  = 1;.  g.fullHtt
14a00 70 52 65 70 6c 79 20 3d 20 31 3b 0a 20 20 7a 49  pReply = 1;.  zI
14a10 70 41 64 64 72 20 3d 20 63 67 69 5f 73 73 68 5f  pAddr = cgi_ssh_
14a20 72 65 6d 6f 74 65 5f 61 64 64 72 28 30 29 3b 0a  remote_addr(0);.
14a30 20 20 69 66 28 20 7a 49 70 41 64 64 72 20 26 26    if( zIpAddr &&
14a40 20 7a 49 70 41 64 64 72 5b 30 5d 20 29 7b 0a 20   zIpAddr[0] ){. 
14a50 20 20 20 67 2e 66 53 73 68 43 6c 69 65 6e 74 20     g.fSshClient 
14a60 7c 3d 20 43 47 49 5f 53 53 48 5f 43 4c 49 45 4e  |= CGI_SSH_CLIEN
14a70 54 3b 0a 20 20 20 20 73 73 68 5f 72 65 71 75 65  T;.    ssh_reque
14a80 73 74 5f 6c 6f 6f 70 28 7a 49 70 41 64 64 72 2c  st_loop(zIpAddr,
14a90 20 30 29 3b 0a 20 20 7d 65 6c 73 65 7b 0a 20 20   0);.  }else{.  
14aa0 20 20 63 67 69 5f 73 65 74 5f 70 61 72 61 6d 65    cgi_set_parame
14ab0 74 65 72 28 22 52 45 4d 4f 54 45 5f 41 44 44 52  ter("REMOTE_ADDR
14ac0 22 2c 20 22 31 32 37 2e 30 2e 30 2e 31 22 29 3b  ", "127.0.0.1");
14ad0 0a 20 20 20 20 63 67 69 5f 68 61 6e 64 6c 65 5f  .    cgi_handle_
14ae0 68 74 74 70 5f 72 65 71 75 65 73 74 28 30 29 3b  http_request(0);
14af0 0a 20 20 20 20 70 72 6f 63 65 73 73 5f 6f 6e 65  .    process_one
14b00 5f 77 65 62 5f 70 61 67 65 28 30 2c 20 30 2c 20  _web_page(0, 0, 
14b10 30 29 3b 0a 20 20 7d 0a 7d 0a 0a 23 69 66 20 21  0);.  }.}..#if !
14b20 64 65 66 69 6e 65 64 28 5f 57 49 4e 33 32 29 0a  defined(_WIN32).
14b30 23 69 66 20 21 64 65 66 69 6e 65 64 28 5f 5f 44  #if !defined(__D
14b40 41 52 57 49 4e 5f 5f 29 20 26 26 20 21 64 65 66  ARWIN__) && !def
14b50 69 6e 65 64 28 5f 5f 41 50 50 4c 45 5f 5f 29 20  ined(__APPLE__) 
14b60 26 26 20 21 64 65 66 69 6e 65 64 28 5f 5f 48 41  && !defined(__HA
14b70 49 4b 55 5f 5f 29 0a 2f 2a 0a 2a 2a 20 53 65 61  IKU__)./*.** Sea
14b80 72 63 68 20 66 6f 72 20 61 6e 20 65 78 65 63 75  rch for an execu
14b90 74 61 62 6c 65 20 6f 6e 20 74 68 65 20 50 41 54  table on the PAT
14ba0 48 20 65 6e 76 69 72 6f 6e 6d 65 6e 74 20 76 61  H environment va
14bb0 72 69 61 62 6c 65 2e 0a 2a 2a 20 52 65 74 75 72  riable..** Retur
14bc0 6e 20 74 72 75 65 20 28 31 29 20 69 66 20 66 6f  n true (1) if fo
14bd0 75 6e 64 20 61 6e 64 20 66 61 6c 73 65 20 28 30  und and false (0
14be0 29 20 69 66 20 6e 6f 74 20 66 6f 75 6e 64 2e 0a  ) if not found..
14bf0 2a 2f 0a 73 74 61 74 69 63 20 69 6e 74 20 62 69  */.static int bi
14c00 6e 61 72 79 4f 6e 50 61 74 68 28 63 6f 6e 73 74  naryOnPath(const
14c10 20 63 68 61 72 20 2a 7a 42 69 6e 61 72 79 29 7b   char *zBinary){
14c20 0a 20 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a  .  const char *z
14c30 50 61 74 68 20 3d 20 66 6f 73 73 69 6c 5f 67 65  Path = fossil_ge
14c40 74 65 6e 76 28 22 50 41 54 48 22 29 3b 0a 20 20  tenv("PATH");.  
14c50 63 68 61 72 20 2a 7a 46 75 6c 6c 3b 0a 20 20 69  char *zFull;.  i
14c60 6e 74 20 69 3b 0a 20 20 69 6e 74 20 62 45 78 69  nt i;.  int bExi
14c70 73 74 73 3b 0a 20 20 77 68 69 6c 65 28 20 7a 50  sts;.  while( zP
14c80 61 74 68 20 26 26 20 7a 50 61 74 68 5b 30 5d 20  ath && zPath[0] 
14c90 29 7b 0a 20 20 20 20 77 68 69 6c 65 28 20 7a 50  ){.    while( zP
14ca0 61 74 68 5b 30 5d 3d 3d 27 3a 27 20 29 20 7a 50  ath[0]==':' ) zP
14cb0 61 74 68 2b 2b 3b 0a 20 20 20 20 66 6f 72 28 69  ath++;.    for(i
14cc0 3d 30 3b 20 7a 50 61 74 68 5b 69 5d 20 26 26 20  =0; zPath[i] && 
14cd0 7a 50 61 74 68 5b 69 5d 21 3d 27 3a 27 3b 20 69  zPath[i]!=':'; i
14ce0 2b 2b 29 7b 7d 0a 20 20 20 20 7a 46 75 6c 6c 20  ++){}.    zFull 
14cf0 3d 20 6d 70 72 69 6e 74 66 28 22 25 2e 2a 73 2f  = mprintf("%.*s/
14d00 25 73 22 2c 20 69 2c 20 7a 50 61 74 68 2c 20 7a  %s", i, zPath, z
14d10 42 69 6e 61 72 79 29 3b 0a 20 20 20 20 62 45 78  Binary);.    bEx
14d20 69 73 74 73 20 3d 20 66 69 6c 65 5f 61 63 63 65  ists = file_acce
14d30 73 73 28 7a 46 75 6c 6c 2c 20 58 5f 4f 4b 29 3b  ss(zFull, X_OK);
14d40 0a 20 20 20 20 66 6f 73 73 69 6c 5f 66 72 65 65  .    fossil_free
14d50 28 7a 46 75 6c 6c 29 3b 0a 20 20 20 20 69 66 28  (zFull);.    if(
14d60 20 62 45 78 69 73 74 73 3d 3d 30 20 29 20 72 65   bExists==0 ) re
14d70 74 75 72 6e 20 31 3b 0a 20 20 20 20 7a 50 61 74  turn 1;.    zPat
14d80 68 20 2b 3d 20 69 3b 0a 20 20 7d 0a 20 20 72 65  h += i;.  }.  re
14d90 74 75 72 6e 20 30 3b 0a 7d 0a 23 65 6e 64 69 66  turn 0;.}.#endif
14da0 0a 23 65 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 53  .#endif../*.** S
14db0 65 6e 64 20 61 20 74 69 6d 65 2d 6f 75 74 20 72  end a time-out r
14dc0 65 70 6c 79 0a 2a 2f 0a 76 6f 69 64 20 73 69 67  eply.*/.void sig
14dd0 61 6c 72 6d 5f 68 61 6e 64 6c 65 72 28 69 6e 74  alrm_handler(int
14de0 20 78 29 7b 0a 20 20 66 6f 73 73 69 6c 5f 70 61   x){.  fossil_pa
14df0 6e 69 63 28 22 54 49 4d 45 4f 55 54 22 29 3b 0a  nic("TIMEOUT");.
14e00 7d 0a 0a 2f 2a 0a 2a 2a 20 43 4f 4d 4d 41 4e 44  }../*.** COMMAND
14e10 3a 20 73 65 72 76 65 72 2a 0a 2a 2a 20 43 4f 4d  : server*.** COM
14e20 4d 41 4e 44 3a 20 75 69 0a 2a 2a 0a 2a 2a 20 55  MAND: ui.**.** U
14e30 73 61 67 65 3a 20 25 66 6f 73 73 69 6c 20 73 65  sage: %fossil se
14e40 72 76 65 72 20 3f 4f 50 54 49 4f 4e 53 3f 20 3f  rver ?OPTIONS? ?
14e50 52 45 50 4f 53 49 54 4f 52 59 3f 0a 2a 2a 20 20  REPOSITORY?.**  
14e60 20 20 6f 72 3a 20 25 66 6f 73 73 69 6c 20 75 69    or: %fossil ui
14e70 20 3f 4f 50 54 49 4f 4e 53 3f 20 3f 52 45 50 4f   ?OPTIONS? ?REPO
14e80 53 49 54 4f 52 59 3f 0a 2a 2a 0a 2a 2a 20 4f 70  SITORY?.**.** Op
14e90 65 6e 20 61 20 73 6f 63 6b 65 74 20 61 6e 64 20  en a socket and 
14ea0 62 65 67 69 6e 20 6c 69 73 74 65 6e 69 6e 67 20  begin listening 
14eb0 61 6e 64 20 72 65 73 70 6f 6e 64 69 6e 67 20 74  and responding t
14ec0 6f 20 48 54 54 50 20 72 65 71 75 65 73 74 73 20  o HTTP requests 
14ed0 6f 6e 0a 2a 2a 20 54 43 50 20 70 6f 72 74 20 38  on.** TCP port 8
14ee0 30 38 30 2c 20 6f 72 20 6f 6e 20 61 6e 79 20 6f  080, or on any o
14ef0 74 68 65 72 20 54 43 50 20 70 6f 72 74 20 64 65  ther TCP port de
14f00 66 69 6e 65 64 20 62 79 20 74 68 65 20 2d 50 20  fined by the -P 
14f10 6f 72 0a 2a 2a 20 2d 2d 70 6f 72 74 20 6f 70 74  or.** --port opt
14f20 69 6f 6e 2e 20 20 54 68 65 20 6f 70 74 69 6f 6e  ion.  The option
14f30 61 6c 20 61 72 67 75 6d 65 6e 74 20 69 73 20 74  al argument is t
14f40 68 65 20 6e 61 6d 65 20 6f 66 20 74 68 65 20 72  he name of the r
14f50 65 70 6f 73 69 74 6f 72 79 2e 0a 2a 2a 20 54 68  epository..** Th
14f60 65 20 72 65 70 6f 73 69 74 6f 72 79 20 61 72 67  e repository arg
14f70 75 6d 65 6e 74 20 6d 61 79 20 62 65 20 6f 6d 69  ument may be omi
14f80 74 74 65 64 20 69 66 20 74 68 65 20 77 6f 72 6b  tted if the work
14f90 69 6e 67 20 64 69 72 65 63 74 6f 72 79 20 69 73  ing directory is
14fa0 0a 2a 2a 20 77 69 74 68 69 6e 20 61 6e 20 6f 70  .** within an op
14fb0 65 6e 20 63 68 65 63 6b 6f 75 74 2e 0a 2a 2a 0a  en checkout..**.
14fc0 2a 2a 20 54 68 65 20 22 75 69 22 20 63 6f 6d 6d  ** The "ui" comm
14fd0 61 6e 64 20 61 75 74 6f 6d 61 74 69 63 61 6c 6c  and automaticall
14fe0 79 20 73 74 61 72 74 73 20 61 20 77 65 62 20 62  y starts a web b
14ff0 72 6f 77 73 65 72 20 61 66 74 65 72 20 69 6e 69  rowser after ini
15000 74 69 61 6c 69 7a 69 6e 67 0a 2a 2a 20 74 68 65  tializing.** the
15010 20 77 65 62 20 73 65 72 76 65 72 2e 20 20 54 68   web server.  Th
15020 65 20 22 75 69 22 20 63 6f 6d 6d 61 6e 64 20 61  e "ui" command a
15030 6c 73 6f 20 62 69 6e 64 73 20 74 6f 20 31 32 37  lso binds to 127
15040 2e 30 2e 30 2e 31 20 61 6e 64 20 73 6f 20 77 69  .0.0.1 and so wi
15050 6c 6c 0a 2a 2a 20 6f 6e 6c 79 20 70 72 6f 63 65  ll.** only proce
15060 73 73 20 48 54 54 50 20 74 72 61 66 66 69 63 20  ss HTTP traffic 
15070 66 72 6f 6d 20 74 68 65 20 6c 6f 63 61 6c 20 6d  from the local m
15080 61 63 68 69 6e 65 2e 0a 2a 2a 0a 2a 2a 20 54 68  achine..**.** Th
15090 65 20 52 45 50 4f 53 49 54 4f 52 59 20 63 61 6e  e REPOSITORY can
150a0 20 62 65 20 61 20 64 69 72 65 63 74 6f 72 79 20   be a directory 
150b0 28 61 6b 61 20 66 6f 6c 64 65 72 29 20 74 68 61  (aka folder) tha
150c0 74 20 63 6f 6e 74 61 69 6e 73 20 6f 6e 65 20 6f  t contains one o
150d0 72 0a 2a 2a 20 6d 6f 72 65 20 72 65 70 6f 73 69  r.** more reposi
150e0 74 6f 72 69 65 73 20 77 69 74 68 20 6e 61 6d 65  tories with name
150f0 73 20 65 6e 64 69 6e 67 20 69 6e 20 22 2e 66 6f  s ending in ".fo
15100 73 73 69 6c 22 2e 20 20 49 6e 20 74 68 69 73 20  ssil".  In this 
15110 63 61 73 65 2c 20 61 0a 2a 2a 20 70 72 65 66 69  case, a.** prefi
15120 78 20 6f 66 20 74 68 65 20 55 52 4c 20 70 61 74  x of the URL pat
15130 68 6e 61 6d 65 20 69 73 20 75 73 65 64 20 74 6f  hname is used to
15140 20 73 65 61 72 63 68 20 74 68 65 20 64 69 72 65   search the dire
15150 63 74 6f 72 79 20 66 6f 72 20 61 6e 0a 2a 2a 20  ctory for an.** 
15160 61 70 70 72 6f 70 72 69 61 74 65 20 72 65 70 6f  appropriate repo
15170 73 69 74 6f 72 79 2e 20 20 54 6f 20 74 68 77 61  sitory.  To thwa
15180 72 74 20 6d 69 73 63 68 69 65 66 2c 20 74 68 65  rt mischief, the
15190 20 70 61 74 68 6e 61 6d 65 20 69 6e 20 74 68 65   pathname in the
151a0 20 55 52 4c 20 6d 75 73 74 0a 2a 2a 20 63 6f 6e   URL must.** con
151b0 74 61 69 6e 20 6f 6e 6c 79 20 61 6c 70 68 61 6e  tain only alphan
151c0 75 6d 65 72 69 63 73 2c 20 22 5f 22 2c 20 22 2f  umerics, "_", "/
151d0 22 2c 20 22 2d 22 2c 20 61 6e 64 20 22 2e 22 2c  ", "-", and ".",
151e0 20 61 6e 64 20 6e 6f 20 22 2d 22 20 6d 61 79 0a   and no "-" may.
151f0 2a 2a 20 6f 63 63 75 72 20 61 66 74 65 72 20 22  ** occur after "
15200 2f 22 2c 20 61 6e 64 20 65 76 65 72 79 20 22 2e  /", and every ".
15210 22 20 6d 75 73 74 20 62 65 20 73 75 72 72 6f 75  " must be surrou
15220 6e 64 65 64 20 6f 6e 20 62 6f 74 68 20 73 69 64  nded on both sid
15230 65 73 20 62 79 0a 2a 2a 20 61 6c 70 68 61 6e 75  es by.** alphanu
15240 6d 65 72 69 63 73 2e 20 20 41 6e 79 20 70 61 74  merics.  Any pat
15250 68 6e 61 6d 65 20 74 68 61 74 20 64 6f 65 73 20  hname that does 
15260 6e 6f 74 20 73 61 74 69 73 66 79 20 74 68 65 73  not satisfy thes
15270 65 20 63 6f 6e 73 74 72 61 69 6e 74 73 0a 2a 2a  e constraints.**
15280 20 72 65 73 75 6c 74 73 20 69 6e 20 61 20 34 30   results in a 40
15290 34 20 65 72 72 6f 72 2e 20 20 46 69 6c 65 73 20  4 error.  Files 
152a0 69 6e 20 52 45 50 4f 53 49 54 4f 52 59 20 74 68  in REPOSITORY th
152b0 61 74 20 6d 61 74 63 68 20 74 68 65 20 63 6f 6d  at match the com
152c0 6d 61 2d 73 65 70 61 72 61 74 65 64 0a 2a 2a 20  ma-separated.** 
152d0 6c 69 73 74 20 6f 66 20 67 6c 6f 62 20 70 61 74  list of glob pat
152e0 74 65 72 6e 73 20 67 69 76 65 6e 20 62 79 20 2d  terns given by -
152f0 2d 66 69 6c 65 73 20 61 6e 64 20 74 68 61 74 20  -files and that 
15300 68 61 76 65 20 6b 6e 6f 77 6e 20 73 75 66 66 69  have known suffi
15310 78 65 73 0a 2a 2a 20 73 75 63 68 20 61 73 20 22  xes.** such as "
15320 2e 74 78 74 22 20 6f 72 20 22 2e 68 74 6d 6c 22  .txt" or ".html"
15330 20 6f 72 20 22 2e 6a 70 65 67 22 20 61 6e 64 20   or ".jpeg" and 
15340 64 6f 20 6e 6f 74 20 6d 61 74 63 68 20 74 68 65  do not match the
15350 20 70 61 74 74 65 72 6e 0a 2a 2a 20 22 2a 2e 66   pattern.** "*.f
15360 6f 73 73 69 6c 2a 22 20 77 69 6c 6c 20 62 65 20  ossil*" will be 
15370 73 65 72 76 65 64 20 61 73 20 73 74 61 74 69 63  served as static
15380 20 63 6f 6e 74 65 6e 74 2e 20 20 57 69 74 68 20   content.  With 
15390 74 68 65 20 22 75 69 22 20 63 6f 6d 6d 61 6e 64  the "ui" command
153a0 2c 0a 2a 2a 20 74 68 65 20 52 45 50 4f 53 49 54  ,.** the REPOSIT
153b0 4f 52 59 20 63 61 6e 20 6f 6e 6c 79 20 62 65 20  ORY can only be 
153c0 61 20 64 69 72 65 63 74 6f 72 79 20 69 66 20 74  a directory if t
153d0 68 65 20 2d 2d 6e 6f 74 66 6f 75 6e 64 20 6f 70  he --notfound op
153e0 74 69 6f 6e 20 69 73 0a 2a 2a 20 61 6c 73 6f 20  tion is.** also 
153f0 70 72 65 73 65 6e 74 2e 0a 2a 2a 0a 2a 2a 20 46  present..**.** F
15400 6f 72 20 74 68 65 20 73 70 65 63 69 61 6c 20 63  or the special c
15410 61 73 65 20 52 45 50 4f 53 49 54 4f 52 59 20 6e  ase REPOSITORY n
15420 61 6d 65 20 6f 66 20 22 2f 22 2c 20 74 68 65 20  ame of "/", the 
15430 6c 69 73 74 20 67 6c 6f 62 61 6c 20 63 6f 6e 66  list global conf
15440 69 67 75 72 61 74 69 6f 6e 0a 2a 2a 20 64 61 74  iguration.** dat
15450 61 62 61 73 65 20 69 73 20 63 6f 6e 73 75 6c 74  abase is consult
15460 65 64 20 66 6f 72 20 61 20 6c 69 73 74 20 6f 66  ed for a list of
15470 20 61 6c 6c 20 6b 6e 6f 77 6e 20 72 65 70 6f 73   all known repos
15480 69 74 6f 72 69 65 73 2e 20 20 54 68 65 20 2d 2d  itories.  The --
15490 72 65 70 6f 6c 69 73 74 0a 2a 2a 20 6f 70 74 69  repolist.** opti
154a0 6f 6e 20 69 73 20 69 6d 70 6c 69 65 64 20 62 79  on is implied by
154b0 20 74 68 69 73 20 73 70 65 63 69 61 6c 20 63 61   this special ca
154c0 73 65 2e 20 20 53 65 65 20 61 6c 73 6f 20 74 68  se.  See also th
154d0 65 20 22 66 6f 73 73 69 6c 20 61 6c 6c 20 75 69  e "fossil all ui
154e0 22 0a 2a 2a 20 63 6f 6d 6d 61 6e 64 2e 0a 2a 2a  ".** command..**
154f0 0a 2a 2a 20 42 79 20 64 65 66 61 75 6c 74 2c 20  .** By default, 
15500 74 68 65 20 22 75 69 22 20 63 6f 6d 6d 61 6e 64  the "ui" command
15510 20 70 72 6f 76 69 64 65 73 20 66 75 6c 6c 20 61   provides full a
15520 64 6d 69 6e 69 73 74 72 61 74 69 76 65 20 61 63  dministrative ac
15530 63 65 73 73 20 77 69 74 68 6f 75 74 0a 2a 2a 20  cess without.** 
15540 68 61 76 69 6e 67 20 74 6f 20 6c 6f 67 20 69 6e  having to log in
15550 2e 20 20 54 68 69 73 20 63 61 6e 20 62 65 20 64  .  This can be d
15560 69 73 61 62 6c 65 64 20 62 79 20 74 75 72 6e 69  isabled by turni
15570 6e 67 20 6f 66 66 20 74 68 65 20 22 6c 6f 63 61  ng off the "loca
15580 6c 61 75 74 68 22 0a 2a 2a 20 73 65 74 74 69 6e  lauth".** settin
15590 67 2e 20 20 41 75 74 6f 6d 61 74 69 63 20 6c 6f  g.  Automatic lo
155a0 67 69 6e 20 66 6f 72 20 74 68 65 20 22 73 65 72  gin for the "ser
155b0 76 65 72 22 20 63 6f 6d 6d 61 6e 64 20 69 73 20  ver" command is 
155c0 61 76 61 69 6c 61 62 6c 65 20 69 66 20 74 68 65  available if the
155d0 0a 2a 2a 20 2d 2d 6c 6f 63 61 6c 61 75 74 68 20  .** --localauth 
155e0 6f 70 74 69 6f 6e 20 69 73 20 70 72 65 73 65 6e  option is presen
155f0 74 20 61 6e 64 20 74 68 65 20 22 6c 6f 63 61 6c  t and the "local
15600 61 75 74 68 22 20 73 65 74 74 69 6e 67 20 69 73  auth" setting is
15610 20 6f 66 66 20 61 6e 64 20 74 68 65 0a 2a 2a 20   off and the.** 
15620 63 6f 6e 6e 65 63 74 69 6f 6e 20 69 73 20 66 72  connection is fr
15630 6f 6d 20 6c 6f 63 61 6c 68 6f 73 74 2e 20 20 54  om localhost.  T
15640 68 65 20 22 75 69 22 20 63 6f 6d 6d 61 6e 64 20  he "ui" command 
15650 61 6c 73 6f 20 65 6e 61 62 6c 65 73 20 2d 2d 72  also enables --r
15660 65 70 6f 6c 69 73 74 0a 2a 2a 20 62 79 20 64 65  epolist.** by de
15670 66 61 75 6c 74 2e 0a 2a 2a 0a 2a 2a 20 4f 70 74  fault..**.** Opt
15680 69 6f 6e 73 3a 0a 2a 2a 20 20 20 2d 2d 62 61 73  ions:.**   --bas
15690 65 75 72 6c 20 55 52 4c 20 20 20 20 20 20 20 55  eurl URL       U
156a0 73 65 20 55 52 4c 20 61 73 20 74 68 65 20 62 61  se URL as the ba
156b0 73 65 20 28 75 73 65 66 75 6c 20 66 6f 72 20 72  se (useful for r
156c0 65 76 65 72 73 65 20 70 72 6f 78 69 65 73 29 0a  everse proxies).
156d0 2a 2a 20 20 20 2d 2d 63 72 65 61 74 65 20 20 20  **   --create   
156e0 20 20 20 20 20 20 20 20 20 43 72 65 61 74 65 20           Create 
156f0 61 20 6e 65 77 20 52 45 50 4f 53 49 54 4f 52 59  a new REPOSITORY
15700 20 69 66 20 69 74 20 64 6f 65 73 20 6e 6f 74 20   if it does not 
15710 61 6c 72 65 61 64 79 20 65 78 69 73 74 0a 2a 2a  already exist.**
15720 20 20 20 2d 2d 65 78 74 72 6f 6f 74 20 44 49 52     --extroot DIR
15730 20 20 20 20 20 20 20 44 6f 63 75 6d 65 6e 74 20         Document 
15740 72 6f 6f 74 20 66 6f 72 20 74 68 65 20 2f 65 78  root for the /ex
15750 74 20 65 78 74 65 6e 73 69 6f 6e 20 6d 65 63 68  t extension mech
15760 61 6e 69 73 6d 0a 2a 2a 20 20 20 2d 2d 66 69 6c  anism.**   --fil
15770 65 73 20 47 4c 4f 42 4c 49 53 54 20 20 20 20 43  es GLOBLIST    C
15780 6f 6d 6d 61 2d 73 65 70 61 72 61 74 65 64 20 6c  omma-separated l
15790 69 73 74 20 6f 66 20 67 6c 6f 62 20 70 61 74 74  ist of glob patt
157a0 65 72 6e 73 20 66 6f 72 20 73 74 61 74 69 63 20  erns for static 
157b0 66 69 6c 65 73 0a 2a 2a 20 20 20 2d 2d 6c 6f 63  files.**   --loc
157c0 61 6c 61 75 74 68 20 20 20 20 20 20 20 20 20 65  alauth         e
157d0 6e 61 62 6c 65 20 61 75 74 6f 6d 61 74 69 63 20  nable automatic 
157e0 6c 6f 67 69 6e 20 66 6f 72 20 72 65 71 75 65 73  login for reques
157f0 74 73 20 66 72 6f 6d 20 6c 6f 63 61 6c 68 6f 73  ts from localhos
15800 74 0a 2a 2a 20 20 20 2d 2d 6c 6f 63 61 6c 68 6f  t.**   --localho
15810 73 74 20 20 20 20 20 20 20 20 20 6c 69 73 74 65  st         liste
15820 6e 20 6f 6e 20 31 32 37 2e 30 2e 30 2e 31 20 6f  n on 127.0.0.1 o
15830 6e 6c 79 20 28 61 6c 77 61 79 73 20 74 72 75 65  nly (always true
15840 20 66 6f 72 20 22 75 69 22 29 0a 2a 2a 20 20 20   for "ui").**   
15850 2d 2d 68 74 74 70 73 20 20 20 20 20 20 20 20 20  --https         
15860 20 20 20 20 49 6e 64 69 63 61 74 65 73 20 74 68      Indicates th
15870 61 74 20 74 68 65 20 69 6e 70 75 74 20 69 73 20  at the input is 
15880 63 6f 6d 69 6e 67 20 74 68 72 6f 75 67 68 20 61  coming through a
15890 20 72 65 76 65 72 73 65 0a 2a 2a 20 20 20 20 20   reverse.**     
158a0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
158b0 20 20 70 72 6f 78 79 20 74 68 61 74 20 68 61 73    proxy that has
158c0 20 61 6c 72 65 61 64 79 20 74 72 61 6e 73 6c 61   already transla
158d0 74 65 64 20 48 54 54 50 53 20 69 6e 74 6f 20 48  ted HTTPS into H
158e0 54 54 50 2e 0a 2a 2a 20 20 20 2d 2d 6d 61 78 2d  TTP..**   --max-
158f0 6c 61 74 65 6e 63 79 20 4e 20 20 20 20 20 44 6f  latency N     Do
15900 20 6e 6f 74 20 6c 65 74 20 61 6e 79 20 73 69 6e   not let any sin
15910 67 6c 65 20 48 54 54 50 20 72 65 71 75 65 73 74  gle HTTP request
15920 20 72 75 6e 20 66 6f 72 20 6d 6f 72 65 20 74 68   run for more th
15930 61 6e 20 4e 0a 2a 2a 20 20 20 20 20 20 20 20 20  an N.**         
15940 20 20 20 20 20 20 20 20 20 20 20 20 20 20 73 65                se
15950 63 6f 6e 64 73 20 28 6f 6e 6c 79 20 77 6f 72 6b  conds (only work
15960 73 20 6f 6e 20 75 6e 69 78 29 0a 2a 2a 20 20 20  s on unix).**   
15970 2d 2d 6e 6f 63 6f 6d 70 72 65 73 73 20 20 20 20  --nocompress    
15980 20 20 20 20 44 6f 20 6e 6f 74 20 63 6f 6d 70 72      Do not compr
15990 65 73 73 20 48 54 54 50 20 72 65 70 6c 69 65 73  ess HTTP replies
159a0 0a 2a 2a 20 20 20 2d 2d 6e 6f 6a 61 69 6c 20 20  .**   --nojail  
159b0 20 20 20 20 20 20 20 20 20 20 44 72 6f 70 20 72            Drop r
159c0 6f 6f 74 20 70 72 69 76 69 6c 65 67 65 73 20 62  oot privileges b
159d0 75 74 20 64 6f 20 6e 6f 74 20 65 6e 74 65 72 20  ut do not enter 
159e0 74 68 65 20 63 68 72 6f 6f 74 20 6a 61 69 6c 0a  the chroot jail.
159f0 2a 2a 20 20 20 2d 2d 6e 6f 73 73 6c 20 20 20 20  **   --nossl    
15a00 20 20 20 20 20 20 20 20 20 73 69 67 6e 61 6c 20           signal 
15a10 74 68 61 74 20 6e 6f 20 53 53 4c 20 63 6f 6e 6e  that no SSL conn
15a20 65 63 74 69 6f 6e 73 20 61 72 65 20 61 76 61 69  ections are avai
15a30 6c 61 62 6c 65 20 28 41 6c 77 61 79 73 0a 2a 2a  lable (Always.**
15a40 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
15a50 20 20 20 20 20 20 20 73 65 74 20 62 79 20 64 65         set by de
15a60 66 61 75 6c 74 20 66 6f 72 20 74 68 65 20 22 75  fault for the "u
15a70 69 22 20 63 6f 6d 6d 61 6e 64 29 0a 2a 2a 20 20  i" command).**  
15a80 20 2d 2d 6e 6f 74 66 6f 75 6e 64 20 55 52 4c 20   --notfound URL 
15a90 20 20 20 20 20 52 65 64 69 72 65 63 74 0a 2a 2a       Redirect.**
15aa0 20 20 20 2d 2d 70 61 67 65 20 50 41 47 45 20 20     --page PAGE  
15ab0 20 20 20 20 20 20 20 53 74 61 72 74 20 22 75 69         Start "ui
15ac0 22 20 6f 6e 20 50 41 47 45 2e 20 20 65 78 3a 20  " on PAGE.  ex: 
15ad0 2d 2d 70 61 67 65 20 22 74 69 6d 65 6c 69 6e 65  --page "timeline
15ae0 3f 79 3d 63 69 22 0a 2a 2a 20 20 20 2d 50 7c 2d  ?y=ci".**   -P|-
15af0 2d 70 6f 72 74 20 54 43 50 50 4f 52 54 20 20 20  -port TCPPORT   
15b00 6c 69 73 74 65 6e 20 74 6f 20 72 65 71 75 65 73  listen to reques
15b10 74 20 6f 6e 20 70 6f 72 74 20 54 43 50 50 4f 52  t on port TCPPOR
15b20 54 0a 2a 2a 20 20 20 2d 2d 74 68 2d 74 72 61 63  T.**   --th-trac
15b30 65 20 20 20 20 20 20 20 20 20 20 74 72 61 63 65  e          trace
15b40 20 54 48 31 20 65 78 65 63 75 74 69 6f 6e 20 28   TH1 execution (
15b50 66 6f 72 20 64 65 62 75 67 67 69 6e 67 20 70 75  for debugging pu
15b60 72 70 6f 73 65 73 29 0a 2a 2a 20 20 20 2d 2d 72  rposes).**   --r
15b70 65 70 6f 6c 69 73 74 20 20 20 20 20 20 20 20 20  epolist         
15b80 20 49 66 20 52 45 50 4f 53 49 54 4f 52 59 20 69   If REPOSITORY i
15b90 73 20 64 69 72 2c 20 55 52 4c 20 22 2f 22 20 6c  s dir, URL "/" l
15ba0 69 73 74 73 20 72 65 70 6f 73 2e 0a 2a 2a 20 20  ists repos..**  
15bb0 20 2d 2d 73 63 67 69 20 20 20 20 20 20 20 20 20   --scgi         
15bc0 20 20 20 20 20 41 63 63 65 70 74 20 53 43 47 49       Accept SCGI
15bd0 20 72 61 74 68 65 72 20 74 68 61 6e 20 48 54 54   rather than HTT
15be0 50 0a 2a 2a 20 20 20 2d 2d 73 6b 69 6e 20 4c 41  P.**   --skin LA
15bf0 42 45 4c 20 20 20 20 20 20 20 20 55 73 65 20 6f  BEL        Use o
15c00 76 65 72 72 69 64 65 20 73 6b 69 6e 20 4c 41 42  verride skin LAB
15c10 45 4c 0a 2a 2a 20 20 20 2d 2d 75 73 65 70 69 64  EL.**   --usepid
15c20 6b 65 79 20 20 20 20 20 20 20 20 20 55 73 65 20  key         Use 
15c30 73 61 76 65 64 20 65 6e 63 72 79 70 74 69 6f 6e  saved encryption
15c40 20 6b 65 79 20 66 72 6f 6d 20 70 61 72 65 6e 74   key from parent
15c50 20 70 72 6f 63 65 73 73 2e 20 20 54 68 69 73 20   process.  This 
15c60 69 73 0a 2a 2a 20 20 20 20 20 20 20 20 20 20 20  is.**           
15c70 20 20 20 20 20 20 20 20 20 20 20 20 6f 6e 6c 79              only
15c80 20 6e 65 63 65 73 73 61 72 79 20 77 68 65 6e 20   necessary when 
15c90 75 73 69 6e 67 20 53 45 45 20 6f 6e 20 57 69 6e  using SEE on Win
15ca0 64 6f 77 73 2e 0a 2a 2a 0a 2a 2a 20 53 65 65 20  dows..**.** See 
15cb0 61 6c 73 6f 3a 20 63 67 69 2c 20 68 74 74 70 2c  also: cgi, http,
15cc0 20 77 69 6e 73 72 76 0a 2a 2f 0a 76 6f 69 64 20   winsrv.*/.void 
15cd0 63 6d 64 5f 77 65 62 73 65 72 76 65 72 28 76 6f  cmd_webserver(vo
15ce0 69 64 29 7b 0a 20 20 69 6e 74 20 69 50 6f 72 74  id){.  int iPort
15cf0 2c 20 6d 78 50 6f 72 74 3b 20 20 20 20 20 20 20  , mxPort;       
15d00 20 2f 2a 20 52 61 6e 67 65 20 6f 66 20 54 43 50   /* Range of TCP
15d10 20 70 6f 72 74 73 20 61 6c 6c 6f 77 65 64 20 2a   ports allowed *
15d20 2f 0a 20 20 63 6f 6e 73 74 20 63 68 61 72 20 2a  /.  const char *
15d30 7a 50 6f 72 74 3b 20 20 20 20 20 20 20 20 2f 2a  zPort;        /*
15d40 20 56 61 6c 75 65 20 6f 66 20 74 68 65 20 2d 2d   Value of the --
15d50 70 6f 72 74 20 6f 70 74 69 6f 6e 20 2a 2f 0a 20  port option */. 
15d60 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a 42 72   const char *zBr
15d70 6f 77 73 65 72 3b 20 20 20 20 20 2f 2a 20 4e 61  owser;     /* Na
15d80 6d 65 20 6f 66 20 77 65 62 20 62 72 6f 77 73 65  me of web browse
15d90 72 20 70 72 6f 67 72 61 6d 20 2a 2f 0a 20 20 63  r program */.  c
15da0 68 61 72 20 2a 7a 42 72 6f 77 73 65 72 43 6d 64  har *zBrowserCmd
15db0 20 3d 20 30 3b 20 20 20 20 2f 2a 20 43 6f 6d 6d   = 0;    /* Comm
15dc0 61 6e 64 20 74 6f 20 6c 61 75 6e 63 68 20 74 68  and to launch th
15dd0 65 20 77 65 62 20 62 72 6f 77 73 65 72 20 2a 2f  e web browser */
15de0 0a 20 20 69 6e 74 20 69 73 55 69 43 6d 64 3b 20  .  int isUiCmd; 
15df0 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20               /* 
15e00 54 72 75 65 20 69 66 20 63 6f 6d 6d 61 6e 64 20  True if command 
15e10 69 73 20 22 75 69 22 2c 20 6e 6f 74 20 22 73 65  is "ui", not "se
15e20 72 76 65 72 27 20 2a 2f 0a 20 20 63 6f 6e 73 74  rver' */.  const
15e30 20 63 68 61 72 20 2a 7a 4e 6f 74 46 6f 75 6e 64   char *zNotFound
15e40 3b 20 20 20 20 2f 2a 20 54 68 65 20 2d 2d 6e 6f  ;    /* The --no
15e50 74 66 6f 75 6e 64 20 6f 70 74 69 6f 6e 20 6f 72  tfound option or
15e60 20 4e 55 4c 4c 20 2a 2f 0a 20 20 69 6e 74 20 66   NULL */.  int f
15e70 6c 61 67 73 20 3d 20 30 3b 20 20 20 20 20 20 20  lags = 0;       
15e80 20 20 20 20 20 2f 2a 20 53 65 72 76 65 72 20 66       /* Server f
15e90 6c 61 67 73 20 2a 2f 0a 23 69 66 20 21 64 65 66  lags */.#if !def
15ea0 69 6e 65 64 28 5f 57 49 4e 33 32 29 0a 20 20 69  ined(_WIN32).  i
15eb0 6e 74 20 6e 6f 4a 61 69 6c 3b 20 20 20 20 20 20  nt noJail;      
15ec0 20 20 20 20 20 20 20 20 20 2f 2a 20 44 6f 20 6e           /* Do n
15ed0 6f 74 20 65 6e 74 65 72 20 74 68 65 20 63 68 72  ot enter the chr
15ee0 6f 6f 74 20 6a 61 69 6c 20 2a 2f 0a 20 20 63 6f  oot jail */.  co
15ef0 6e 73 74 20 63 68 61 72 20 2a 7a 4d 61 78 4c 61  nst char *zMaxLa
15f00 74 65 6e 63 79 3b 20 20 20 2f 2a 20 4d 61 78 69  tency;   /* Maxi
15f10 6d 75 6d 20 72 75 6e 74 69 6d 65 20 6f 66 20 61  mum runtime of a
15f20 6e 79 20 73 69 6e 67 6c 65 20 48 54 54 50 20 72  ny single HTTP r
15f30 65 71 75 65 73 74 20 2a 2f 0a 23 65 6e 64 69 66  equest */.#endif
15f40 0a 20 20 69 6e 74 20 61 6c 6c 6f 77 52 65 70 6f  .  int allowRepo
15f50 4c 69 73 74 3b 20 20 20 20 20 20 20 20 20 2f 2a  List;         /*
15f60 20 4c 69 73 74 20 72 65 70 6f 73 69 74 6f 72 69   List repositori
15f70 65 73 20 6f 6e 20 55 52 4c 20 22 2f 22 20 2a 2f  es on URL "/" */
15f80 0a 20 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a  .  const char *z
15f90 41 6c 74 42 61 73 65 3b 20 20 20 20 20 20 2f 2a  AltBase;      /*
15fa0 20 41 72 67 75 6d 65 6e 74 20 74 6f 20 74 68 65   Argument to the
15fb0 20 2d 2d 62 61 73 65 75 72 6c 20 6f 70 74 69 6f   --baseurl optio
15fc0 6e 20 2a 2f 0a 20 20 63 6f 6e 73 74 20 63 68 61  n */.  const cha
15fd0 72 20 2a 7a 46 69 6c 65 47 6c 6f 62 3b 20 20 20  r *zFileGlob;   
15fe0 20 20 2f 2a 20 53 74 61 74 69 63 20 63 6f 6e 74    /* Static cont
15ff0 65 6e 74 20 6d 75 73 74 20 6d 61 74 63 68 20 74  ent must match t
16000 68 69 73 20 2a 2f 0a 20 20 63 68 61 72 20 2a 7a  his */.  char *z
16010 49 70 41 64 64 72 20 3d 20 30 3b 20 20 20 20 20  IpAddr = 0;     
16020 20 20 20 20 2f 2a 20 42 69 6e 64 20 74 6f 20 74      /* Bind to t
16030 68 69 73 20 49 50 20 61 64 64 72 65 73 73 20 2a  his IP address *
16040 2f 0a 20 20 69 6e 74 20 66 43 72 65 61 74 65 20  /.  int fCreate 
16050 3d 20 30 3b 20 20 20 20 20 20 20 20 20 20 20 2f  = 0;           /
16060 2a 20 54 68 65 20 2d 2d 63 72 65 61 74 65 20 66  * The --create f
16070 6c 61 67 20 2a 2f 0a 20 20 63 6f 6e 73 74 20 63  lag */.  const c
16080 68 61 72 20 2a 7a 49 6e 69 74 50 61 67 65 20 3d  har *zInitPage =
16090 20 30 3b 20 2f 2a 20 53 74 61 72 74 20 6f 6e 20   0; /* Start on 
160a0 74 68 69 73 20 70 61 67 65 2e 20 20 2d 2d 70 61  this page.  --pa
160b0 67 65 20 6f 70 74 69 6f 6e 20 2a 2f 0a 23 69 66  ge option */.#if
160c0 20 64 65 66 69 6e 65 64 28 5f 57 49 4e 33 32 29   defined(_WIN32)
160d0 20 26 26 20 55 53 45 5f 53 45 45 0a 20 20 63 6f   && USE_SEE.  co
160e0 6e 73 74 20 63 68 61 72 20 2a 7a 50 69 64 4b 65  nst char *zPidKe
160f0 79 3b 0a 23 65 6e 64 69 66 0a 0a 23 69 66 20 64  y;.#endif..#if d
16100 65 66 69 6e 65 64 28 5f 57 49 4e 33 32 29 0a 20  efined(_WIN32). 
16110 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a 53 74   const char *zSt
16120 6f 70 70 65 72 46 69 6c 65 3b 20 20 20 20 2f 2a  opperFile;    /*
16130 20 4e 61 6d 65 20 6f 66 20 66 69 6c 65 20 75 73   Name of file us
16140 65 64 20 74 6f 20 74 65 72 6d 69 6e 61 74 65 20  ed to terminate 
16150 73 65 72 76 65 72 20 2a 2f 0a 20 20 7a 53 74 6f  server */.  zSto
16160 70 70 65 72 46 69 6c 65 20 3d 20 66 69 6e 64 5f  pperFile = find_
16170 6f 70 74 69 6f 6e 28 22 73 74 6f 70 70 65 72 22  option("stopper"
16180 2c 20 30 2c 20 31 29 3b 0a 23 65 6e 64 69 66 0a  , 0, 1);.#endif.
16190 0a 20 20 69 66 28 20 67 2e 7a 45 72 72 6c 6f 67  .  if( g.zErrlog
161a0 3d 3d 30 20 29 7b 0a 20 20 20 20 67 2e 7a 45 72  ==0 ){.    g.zEr
161b0 72 6c 6f 67 20 3d 20 22 2d 22 3b 0a 20 20 7d 0a  rlog = "-";.  }.
161c0 20 20 67 2e 7a 45 78 74 52 6f 6f 74 20 3d 20 66    g.zExtRoot = f
161d0 69 6e 64 5f 6f 70 74 69 6f 6e 28 22 65 78 74 72  ind_option("extr
161e0 6f 6f 74 22 2c 30 2c 31 29 3b 0a 20 20 7a 46 69  oot",0,1);.  zFi
161f0 6c 65 47 6c 6f 62 20 3d 20 66 69 6e 64 5f 6f 70  leGlob = find_op
16200 74 69 6f 6e 28 22 66 69 6c 65 73 2d 75 72 6c 65  tion("files-urle
16210 6e 63 22 2c 30 2c 31 29 3b 0a 20 20 69 66 28 20  nc",0,1);.  if( 
16220 7a 46 69 6c 65 47 6c 6f 62 20 29 7b 0a 20 20 20  zFileGlob ){.   
16230 20 63 68 61 72 20 2a 7a 20 3d 20 6d 70 72 69 6e   char *z = mprin
16240 74 66 28 22 25 73 22 2c 20 7a 46 69 6c 65 47 6c  tf("%s", zFileGl
16250 6f 62 29 3b 0a 20 20 20 20 64 65 68 74 74 70 69  ob);.    dehttpi
16260 7a 65 28 7a 29 3b 0a 20 20 20 20 7a 46 69 6c 65  ze(z);.    zFile
16270 47 6c 6f 62 20 3d 20 7a 3b 0a 20 20 7d 65 6c 73  Glob = z;.  }els
16280 65 7b 0a 20 20 20 20 7a 46 69 6c 65 47 6c 6f 62  e{.    zFileGlob
16290 20 3d 20 66 69 6e 64 5f 6f 70 74 69 6f 6e 28 22   = find_option("
162a0 66 69 6c 65 73 22 2c 30 2c 31 29 3b 0a 20 20 7d  files",0,1);.  }
162b0 0a 20 20 73 6b 69 6e 5f 6f 76 65 72 72 69 64 65  .  skin_override
162c0 28 29 3b 0a 23 69 66 20 21 64 65 66 69 6e 65 64  ();.#if !defined
162d0 28 5f 57 49 4e 33 32 29 0a 20 20 6e 6f 4a 61 69  (_WIN32).  noJai
162e0 6c 20 3d 20 66 69 6e 64 5f 6f 70 74 69 6f 6e 28  l = find_option(
162f0 22 6e 6f 6a 61 69 6c 22 2c 30 2c 30 29 21 3d 30  "nojail",0,0)!=0
16300 3b 0a 20 20 7a 4d 61 78 4c 61 74 65 6e 63 79 20  ;.  zMaxLatency 
16310 3d 20 66 69 6e 64 5f 6f 70 74 69 6f 6e 28 22 6d  = find_option("m
16320 61 78 2d 6c 61 74 65 6e 63 79 22 2c 30 2c 31 29  ax-latency",0,1)
16330 3b 0a 23 65 6e 64 69 66 0a 20 20 67 2e 75 73 65  ;.#endif.  g.use
16340 4c 6f 63 61 6c 61 75 74 68 20 3d 20 66 69 6e 64  Localauth = find
16350 5f 6f 70 74 69 6f 6e 28 22 6c 6f 63 61 6c 61 75  _option("localau
16360 74 68 22 2c 20 30 2c 20 30 29 21 3d 30 3b 0a 20  th", 0, 0)!=0;. 
16370 20 54 68 5f 49 6e 69 74 54 72 61 63 65 4c 6f 67   Th_InitTraceLog
16380 28 29 3b 0a 20 20 7a 50 6f 72 74 20 3d 20 66 69  ();.  zPort = fi
16390 6e 64 5f 6f 70 74 69 6f 6e 28 22 70 6f 72 74 22  nd_option("port"
163a0 2c 20 22 50 22 2c 20 31 29 3b 0a 20 20 69 73 55  , "P", 1);.  isU
163b0 69 43 6d 64 20 3d 20 67 2e 61 72 67 76 5b 31 5d  iCmd = g.argv[1]
163c0 5b 30 5d 3d 3d 27 75 27 3b 0a 20 20 69 66 28 20  [0]=='u';.  if( 
163d0 69 73 55 69 43 6d 64 20 29 7b 0a 20 20 20 20 7a  isUiCmd ){.    z
163e0 49 6e 69 74 50 61 67 65 20 3d 20 66 69 6e 64 5f  InitPage = find_
163f0 6f 70 74 69 6f 6e 28 22 70 61 67 65 22 2c 20 30  option("page", 0
16400 2c 20 31 29 3b 0a 20 20 7d 0a 20 20 7a 4e 6f 74  , 1);.  }.  zNot
16410 46 6f 75 6e 64 20 3d 20 66 69 6e 64 5f 6f 70 74  Found = find_opt
16420 69 6f 6e 28 22 6e 6f 74 66 6f 75 6e 64 22 2c 20  ion("notfound", 
16430 30 2c 20 31 29 3b 0a 20 20 61 6c 6c 6f 77 52 65  0, 1);.  allowRe
16440 70 6f 4c 69 73 74 20 3d 20 66 69 6e 64 5f 6f 70  poList = find_op
16450 74 69 6f 6e 28 22 72 65 70 6f 6c 69 73 74 22 2c  tion("repolist",
16460 30 2c 30 29 21 3d 30 3b 0a 20 20 69 66 28 20 66  0,0)!=0;.  if( f
16470 69 6e 64 5f 6f 70 74 69 6f 6e 28 22 6e 6f 63 6f  ind_option("noco
16480 6d 70 72 65 73 73 22 2c 30 2c 30 29 21 3d 30 20  mpress",0,0)!=0 
16490 29 20 67 2e 66 4e 6f 48 74 74 70 43 6f 6d 70 72  ) g.fNoHttpCompr
164a0 65 73 73 20 3d 20 31 3b 0a 20 20 7a 41 6c 74 42  ess = 1;.  zAltB
164b0 61 73 65 20 3d 20 66 69 6e 64 5f 6f 70 74 69 6f  ase = find_optio
164c0 6e 28 22 62 61 73 65 75 72 6c 22 2c 20 30 2c 20  n("baseurl", 0, 
164d0 31 29 3b 0a 20 20 66 43 72 65 61 74 65 20 3d 20  1);.  fCreate = 
164e0 66 69 6e 64 5f 6f 70 74 69 6f 6e 28 22 63 72 65  find_option("cre
164f0 61 74 65 22 2c 30 2c 30 29 21 3d 30 3b 0a 20 20  ate",0,0)!=0;.  
16500 69 66 28 20 66 69 6e 64 5f 6f 70 74 69 6f 6e 28  if( find_option(
16510 22 73 63 67 69 22 2c 20 30 2c 20 30 29 21 3d 30  "scgi", 0, 0)!=0
16520 20 29 20 66 6c 61 67 73 20 7c 3d 20 48 54 54 50   ) flags |= HTTP
16530 5f 53 45 52 56 45 52 5f 53 43 47 49 3b 0a 20 20  _SERVER_SCGI;.  
16540 69 66 28 20 7a 41 6c 74 42 61 73 65 20 29 7b 0a  if( zAltBase ){.
16550 20 20 20 20 73 65 74 5f 62 61 73 65 5f 75 72 6c      set_base_url
16560 28 7a 41 6c 74 42 61 73 65 29 3b 0a 20 20 7d 0a  (zAltBase);.  }.
16570 20 20 67 2e 73 73 6c 4e 6f 74 41 76 61 69 6c 61    g.sslNotAvaila
16580 62 6c 65 20 3d 20 66 69 6e 64 5f 6f 70 74 69 6f  ble = find_optio
16590 6e 28 22 6e 6f 73 73 6c 22 2c 20 30 2c 20 30 29  n("nossl", 0, 0)
165a0 21 3d 30 20 7c 7c 20 69 73 55 69 43 6d 64 3b 0a  !=0 || isUiCmd;.
165b0 20 20 69 66 28 20 66 69 6e 64 5f 6f 70 74 69 6f    if( find_optio
165c0 6e 28 22 68 74 74 70 73 22 2c 30 2c 30 29 21 3d  n("https",0,0)!=
165d0 30 20 29 7b 0a 20 20 20 20 63 67 69 5f 72 65 70  0 ){.    cgi_rep
165e0 6c 61 63 65 5f 70 61 72 61 6d 65 74 65 72 28 22  lace_parameter("
165f0 48 54 54 50 53 22 2c 22 6f 6e 22 29 3b 0a 20 20  HTTPS","on");.  
16600 7d 0a 20 20 69 66 28 20 66 69 6e 64 5f 6f 70 74  }.  if( find_opt
16610 69 6f 6e 28 22 6c 6f 63 61 6c 68 6f 73 74 22 2c  ion("localhost",
16620 20 30 2c 20 30 29 21 3d 30 20 29 7b 0a 20 20 20   0, 0)!=0 ){.   
16630 20 66 6c 61 67 73 20 7c 3d 20 48 54 54 50 5f 53   flags |= HTTP_S
16640 45 52 56 45 52 5f 4c 4f 43 41 4c 48 4f 53 54 3b  ERVER_LOCALHOST;
16650 0a 20 20 7d 0a 0a 23 69 66 20 64 65 66 69 6e 65  .  }..#if define
16660 64 28 5f 57 49 4e 33 32 29 20 26 26 20 55 53 45  d(_WIN32) && USE
16670 5f 53 45 45 0a 20 20 7a 50 69 64 4b 65 79 20 3d  _SEE.  zPidKey =
16680 20 66 69 6e 64 5f 6f 70 74 69 6f 6e 28 22 75 73   find_option("us
16690 65 70 69 64 6b 65 79 22 2c 20 30 2c 20 31 29 3b  epidkey", 0, 1);
166a0 0a 20 20 69 66 28 20 7a 50 69 64 4b 65 79 20 29  .  if( zPidKey )
166b0 7b 0a 20 20 20 20 44 57 4f 52 44 20 70 72 6f 63  {.    DWORD proc
166c0 65 73 73 49 64 20 3d 20 30 3b 0a 20 20 20 20 4c  essId = 0;.    L
166d0 50 56 4f 49 44 20 70 41 64 64 72 65 73 73 20 3d  PVOID pAddress =
166e0 20 4e 55 4c 4c 3b 0a 20 20 20 20 53 49 5a 45 5f   NULL;.    SIZE_
166f0 54 20 6e 53 69 7a 65 20 3d 20 30 3b 0a 20 20 20  T nSize = 0;.   
16700 20 70 61 72 73 65 5f 70 69 64 5f 6b 65 79 5f 76   parse_pid_key_v
16710 61 6c 75 65 28 7a 50 69 64 4b 65 79 2c 20 26 70  alue(zPidKey, &p
16720 72 6f 63 65 73 73 49 64 2c 20 26 70 41 64 64 72  rocessId, &pAddr
16730 65 73 73 2c 20 26 6e 53 69 7a 65 29 3b 0a 20 20  ess, &nSize);.  
16740 20 20 64 62 5f 72 65 61 64 5f 73 61 76 65 64 5f    db_read_saved_
16750 65 6e 63 72 79 70 74 69 6f 6e 5f 6b 65 79 5f 66  encryption_key_f
16760 72 6f 6d 5f 70 72 6f 63 65 73 73 28 70 72 6f 63  rom_process(proc
16770 65 73 73 49 64 2c 20 70 41 64 64 72 65 73 73 2c  essId, pAddress,
16780 20 6e 53 69 7a 65 29 3b 0a 20 20 7d 0a 23 65 6e   nSize);.  }.#en
16790 64 69 66 0a 0a 20 20 2f 2a 20 57 65 20 73 68 6f  dif..  /* We sho
167a0 75 6c 64 20 62 65 20 64 6f 6e 65 20 77 69 74 68  uld be done with
167b0 20 6f 70 74 69 6f 6e 73 2e 2e 20 2a 2f 0a 20 20   options.. */.  
167c0 76 65 72 69 66 79 5f 61 6c 6c 5f 6f 70 74 69 6f  verify_all_optio
167d0 6e 73 28 29 3b 0a 0a 20 20 69 66 28 20 67 2e 61  ns();..  if( g.a
167e0 72 67 63 21 3d 32 20 26 26 20 67 2e 61 72 67 63  rgc!=2 && g.argc
167f0 21 3d 33 20 29 20 75 73 61 67 65 28 22 3f 52 45  !=3 ) usage("?RE
16800 50 4f 53 49 54 4f 52 59 3f 22 29 3b 0a 20 20 69  POSITORY?");.  i
16810 66 28 20 69 73 55 69 43 6d 64 20 29 7b 0a 20 20  f( isUiCmd ){.  
16820 20 20 66 6c 61 67 73 20 7c 3d 20 48 54 54 50 5f    flags |= HTTP_
16830 53 45 52 56 45 52 5f 4c 4f 43 41 4c 48 4f 53 54  SERVER_LOCALHOST
16840 7c 48 54 54 50 5f 53 45 52 56 45 52 5f 52 45 50  |HTTP_SERVER_REP
16850 4f 4c 49 53 54 3b 0a 20 20 20 20 67 2e 75 73 65  OLIST;.    g.use
16860 4c 6f 63 61 6c 61 75 74 68 20 3d 20 31 3b 0a 20  Localauth = 1;. 
16870 20 20 20 61 6c 6c 6f 77 52 65 70 6f 4c 69 73 74     allowRepoList
16880 20 3d 20 31 3b 0a 20 20 7d 0a 20 20 66 69 6e 64   = 1;.  }.  find
16890 5f 73 65 72 76 65 72 5f 72 65 70 6f 73 69 74 6f  _server_reposito
168a0 72 79 28 32 2c 20 66 43 72 65 61 74 65 29 3b 0a  ry(2, fCreate);.
168b0 20 20 69 66 28 20 7a 49 6e 69 74 50 61 67 65 3d    if( zInitPage=
168c0 3d 30 20 29 7b 0a 20 20 20 20 69 66 28 20 69 73  =0 ){.    if( is
168d0 55 69 43 6d 64 20 26 26 20 67 2e 6c 6f 63 61 6c  UiCmd && g.local
168e0 4f 70 65 6e 20 29 7b 0a 20 20 20 20 20 20 7a 49  Open ){.      zI
168f0 6e 69 74 50 61 67 65 20 3d 20 22 74 69 6d 65 6c  nitPage = "timel
16900 69 6e 65 3f 63 3d 63 75 72 72 65 6e 74 22 3b 0a  ine?c=current";.
16910 20 20 20 20 7d 65 6c 73 65 7b 0a 20 20 20 20 20      }else{.     
16920 20 7a 49 6e 69 74 50 61 67 65 20 3d 20 22 22 3b   zInitPage = "";
16930 0a 20 20 20 20 7d 0a 20 20 7d 0a 20 20 69 66 28  .    }.  }.  if(
16940 20 7a 50 6f 72 74 20 29 7b 0a 20 20 20 20 69 66   zPort ){.    if
16950 28 20 73 74 72 63 68 72 28 7a 50 6f 72 74 2c 27  ( strchr(zPort,'
16960 3a 27 29 20 29 7b 0a 20 20 20 20 20 20 69 6e 74  :') ){.      int
16970 20 69 3b 0a 20 20 20 20 20 20 66 6f 72 28 69 3d   i;.      for(i=
16980 73 74 72 6c 65 6e 28 7a 50 6f 72 74 29 2d 31 3b  strlen(zPort)-1;
16990 20 69 3e 3d 30 20 26 26 20 7a 50 6f 72 74 5b 69   i>=0 && zPort[i
169a0 5d 21 3d 27 3a 27 3b 20 69 2d 2d 29 7b 7d 0a 20  ]!=':'; i--){}. 
169b0 20 20 20 20 20 69 66 28 20 69 3e 30 20 29 7b 0a       if( i>0 ){.
169c0 20 20 20 20 20 20 20 20 69 66 28 20 7a 50 6f 72          if( zPor
169d0 74 5b 30 5d 3d 3d 27 5b 27 20 26 26 20 7a 50 6f  t[0]=='[' && zPo
169e0 72 74 5b 69 2d 31 5d 3d 3d 27 5d 27 20 29 7b 0a  rt[i-1]==']' ){.
169f0 20 20 20 20 20 20 20 20 20 20 7a 49 70 41 64 64            zIpAdd
16a00 72 20 3d 20 6d 70 72 69 6e 74 66 28 22 25 2e 2a  r = mprintf("%.*
16a10 73 22 2c 20 69 2d 32 2c 20 7a 50 6f 72 74 2b 31  s", i-2, zPort+1
16a20 29 3b 0a 20 20 20 20 20 20 20 20 7d 65 6c 73 65  );.        }else
16a30 7b 0a 20 20 20 20 20 20 20 20 20 20 7a 49 70 41  {.          zIpA
16a40 64 64 72 20 3d 20 6d 70 72 69 6e 74 66 28 22 25  ddr = mprintf("%
16a50 2e 2a 73 22 2c 20 69 2c 20 7a 50 6f 72 74 29 3b  .*s", i, zPort);
16a60 0a 20 20 20 20 20 20 20 20 7d 0a 20 20 20 20 20  .        }.     
16a70 20 20 20 7a 50 6f 72 74 20 2b 3d 20 69 2b 31 3b     zPort += i+1;
16a80 0a 20 20 20 20 20 20 7d 0a 20 20 20 20 7d 0a 20  .      }.    }. 
16a90 20 20 20 69 50 6f 72 74 20 3d 20 6d 78 50 6f 72     iPort = mxPor
16aa0 74 20 3d 20 61 74 6f 69 28 7a 50 6f 72 74 29 3b  t = atoi(zPort);
16ab0 0a 20 20 7d 65 6c 73 65 7b 0a 20 20 20 20 69 50  .  }else{.    iP
16ac0 6f 72 74 20 3d 20 64 62 5f 67 65 74 5f 69 6e 74  ort = db_get_int
16ad0 28 22 68 74 74 70 2d 70 6f 72 74 22 2c 20 38 30  ("http-port", 80
16ae0 38 30 29 3b 0a 20 20 20 20 6d 78 50 6f 72 74 20  80);.    mxPort 
16af0 3d 20 69 50 6f 72 74 2b 31 30 30 3b 0a 20 20 7d  = iPort+100;.  }
16b00 0a 23 69 66 20 21 64 65 66 69 6e 65 64 28 5f 57  .#if !defined(_W
16b10 49 4e 33 32 29 0a 20 20 2f 2a 20 55 6e 69 78 20  IN32).  /* Unix 
16b20 69 6d 70 6c 65 6d 65 6e 74 61 74 69 6f 6e 20 2a  implementation *
16b30 2f 0a 20 20 69 66 28 20 69 73 55 69 43 6d 64 20  /.  if( isUiCmd 
16b40 29 7b 0a 23 69 66 20 21 64 65 66 69 6e 65 64 28  ){.#if !defined(
16b50 5f 5f 44 41 52 57 49 4e 5f 5f 29 20 26 26 20 21  __DARWIN__) && !
16b60 64 65 66 69 6e 65 64 28 5f 5f 41 50 50 4c 45 5f  defined(__APPLE_
16b70 5f 29 20 26 26 20 21 64 65 66 69 6e 65 64 28 5f  _) && !defined(_
16b80 5f 48 41 49 4b 55 5f 5f 29 0a 20 20 20 20 7a 42  _HAIKU__).    zB
16b90 72 6f 77 73 65 72 20 3d 20 64 62 5f 67 65 74 28  rowser = db_get(
16ba0 22 77 65 62 2d 62 72 6f 77 73 65 72 22 2c 20 30  "web-browser", 0
16bb0 29 3b 0a 20 20 20 20 69 66 28 20 7a 42 72 6f 77  );.    if( zBrow
16bc0 73 65 72 3d 3d 30 20 29 7b 0a 20 20 20 20 20 20  ser==0 ){.      
16bd0 73 74 61 74 69 63 20 63 6f 6e 73 74 20 63 68 61  static const cha
16be0 72 20 2a 63 6f 6e 73 74 20 61 7a 42 72 6f 77 73  r *const azBrows
16bf0 65 72 50 72 6f 67 5b 5d 20 3d 0a 20 20 20 20 20  erProg[] =.     
16c00 20 20 20 20 20 7b 20 22 78 64 67 2d 6f 70 65 6e       { "xdg-open
16c10 22 2c 20 22 67 6e 6f 6d 65 2d 6f 70 65 6e 22 2c  ", "gnome-open",
16c20 20 22 66 69 72 65 66 6f 78 22 2c 20 22 67 6f 6f   "firefox", "goo
16c30 67 6c 65 2d 63 68 72 6f 6d 65 22 20 7d 3b 0a 20  gle-chrome" };. 
16c40 20 20 20 20 20 69 6e 74 20 69 3b 0a 20 20 20 20       int i;.    
16c50 20 20 7a 42 72 6f 77 73 65 72 20 3d 20 22 65 63    zBrowser = "ec
16c60 68 6f 22 3b 0a 20 20 20 20 20 20 66 6f 72 28 69  ho";.      for(i
16c70 3d 30 3b 20 69 3c 63 6f 75 6e 74 28 61 7a 42 72  =0; i<count(azBr
16c80 6f 77 73 65 72 50 72 6f 67 29 3b 20 69 2b 2b 29  owserProg); i++)
16c90 7b 0a 20 20 20 20 20 20 20 20 69 66 28 20 62 69  {.        if( bi
16ca0 6e 61 72 79 4f 6e 50 61 74 68 28 61 7a 42 72 6f  naryOnPath(azBro
16cb0 77 73 65 72 50 72 6f 67 5b 69 5d 29 20 29 7b 0a  wserProg[i]) ){.
16cc0 20 20 20 20 20 20 20 20 20 20 7a 42 72 6f 77 73            zBrows
16cd0 65 72 20 3d 20 61 7a 42 72 6f 77 73 65 72 50 72  er = azBrowserPr
16ce0 6f 67 5b 69 5d 3b 0a 20 20 20 20 20 20 20 20 20  og[i];.         
16cf0 20 62 72 65 61 6b 3b 0a 20 20 20 20 20 20 20 20   break;.        
16d00 7d 0a 20 20 20 20 20 20 7d 0a 20 20 20 20 7d 0a  }.      }.    }.
16d10 23 65 6c 73 65 0a 20 20 20 20 7a 42 72 6f 77 73  #else.    zBrows
16d20 65 72 20 3d 20 64 62 5f 67 65 74 28 22 77 65 62  er = db_get("web
16d30 2d 62 72 6f 77 73 65 72 22 2c 20 22 6f 70 65 6e  -browser", "open
16d40 22 29 3b 0a 23 65 6e 64 69 66 0a 20 20 20 20 69  ");.#endif.    i
16d50 66 28 20 7a 49 70 41 64 64 72 3d 3d 30 20 29 7b  f( zIpAddr==0 ){
16d60 0a 20 20 20 20 20 20 7a 42 72 6f 77 73 65 72 43  .      zBrowserC
16d70 6d 64 20 3d 20 6d 70 72 69 6e 74 66 28 22 25 73  md = mprintf("%s
16d80 20 68 74 74 70 3a 2f 2f 6c 6f 63 61 6c 68 6f 73   http://localhos
16d90 74 3a 25 25 64 2f 25 73 20 26 22 2c 0a 20 20 20  t:%%d/%s &",.   
16da0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
16db0 20 20 20 20 20 20 20 20 20 7a 42 72 6f 77 73 65           zBrowse
16dc0 72 2c 20 7a 49 6e 69 74 50 61 67 65 29 3b 0a 20  r, zInitPage);. 
16dd0 20 20 20 7d 65 6c 73 65 20 69 66 28 20 73 74 72     }else if( str
16de0 63 68 72 28 7a 49 70 41 64 64 72 2c 27 3a 27 29  chr(zIpAddr,':')
16df0 20 29 7b 0a 20 20 20 20 20 20 7a 42 72 6f 77 73   ){.      zBrows
16e00 65 72 43 6d 64 20 3d 20 6d 70 72 69 6e 74 66 28  erCmd = mprintf(
16e10 22 25 73 20 68 74 74 70 3a 2f 2f 5b 25 73 5d 3a  "%s http://[%s]:
16e20 25 25 64 2f 25 73 20 26 22 2c 0a 20 20 20 20 20  %%d/%s &",.     
16e30 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
16e40 20 20 20 20 20 20 20 7a 42 72 6f 77 73 65 72 2c         zBrowser,
16e50 20 7a 49 70 41 64 64 72 2c 20 7a 49 6e 69 74 50   zIpAddr, zInitP
16e60 61 67 65 29 3b 0a 20 20 20 20 7d 65 6c 73 65 7b  age);.    }else{
16e70 0a 20 20 20 20 20 20 7a 42 72 6f 77 73 65 72 43  .      zBrowserC
16e80 6d 64 20 3d 20 6d 70 72 69 6e 74 66 28 22 25 73  md = mprintf("%s
16e90 20 68 74 74 70 3a 2f 2f 25 73 3a 25 25 64 2f 25   http://%s:%%d/%
16ea0 73 20 26 22 2c 0a 20 20 20 20 20 20 20 20 20 20  s &",.          
16eb0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
16ec0 20 20 7a 42 72 6f 77 73 65 72 2c 20 7a 49 70 41    zBrowser, zIpA
16ed0 64 64 72 2c 20 7a 49 6e 69 74 50 61 67 65 29 3b  ddr, zInitPage);
16ee0 0a 20 20 20 20 7d 0a 20 20 7d 0a 20 20 69 66 28  .    }.  }.  if(
16ef0 20 67 2e 72 65 70 6f 73 69 74 6f 72 79 4f 70 65   g.repositoryOpe
16f00 6e 20 29 20 66 6c 61 67 73 20 7c 3d 20 48 54 54  n ) flags |= HTT
16f10 50 5f 53 45 52 56 45 52 5f 48 41 44 5f 52 45 50  P_SERVER_HAD_REP
16f20 4f 53 49 54 4f 52 59 3b 0a 20 20 69 66 28 20 67  OSITORY;.  if( g
16f30 2e 6c 6f 63 61 6c 4f 70 65 6e 20 29 20 66 6c 61  .localOpen ) fla
16f40 67 73 20 7c 3d 20 48 54 54 50 5f 53 45 52 56 45  gs |= HTTP_SERVE
16f50 52 5f 48 41 44 5f 43 48 45 43 4b 4f 55 54 3b 0a  R_HAD_CHECKOUT;.
16f60 20 20 64 62 5f 63 6c 6f 73 65 28 31 29 3b 0a 20    db_close(1);. 
16f70 20 69 66 28 20 63 67 69 5f 68 74 74 70 5f 73 65   if( cgi_http_se
16f80 72 76 65 72 28 69 50 6f 72 74 2c 20 6d 78 50 6f  rver(iPort, mxPo
16f90 72 74 2c 20 7a 42 72 6f 77 73 65 72 43 6d 64 2c  rt, zBrowserCmd,
16fa0 20 7a 49 70 41 64 64 72 2c 20 66 6c 61 67 73 29   zIpAddr, flags)
16fb0 20 29 7b 0a 20 20 20 20 66 6f 73 73 69 6c 5f 66   ){.    fossil_f
16fc0 61 74 61 6c 28 22 75 6e 61 62 6c 65 20 74 6f 20  atal("unable to 
16fd0 6c 69 73 74 65 6e 20 6f 6e 20 54 43 50 20 73 6f  listen on TCP so
16fe0 63 6b 65 74 20 25 64 22 2c 20 69 50 6f 72 74 29  cket %d", iPort)
16ff0 3b 0a 20 20 7d 0a 20 20 2f 2a 20 46 6f 72 20 74  ;.  }.  /* For t
17000 68 65 20 70 61 72 65 6e 74 20 70 72 6f 63 65 73  he parent proces
17010 73 2c 20 74 68 65 20 63 67 69 5f 68 74 74 70 5f  s, the cgi_http_
17020 73 65 72 76 65 72 28 29 20 63 6f 6d 6d 61 6e 64  server() command
17030 20 61 62 6f 76 65 20 6e 65 76 65 72 0a 20 20 2a   above never.  *
17040 2a 20 72 65 74 75 72 6e 73 20 28 65 78 63 65 70  * returns (excep
17050 74 20 69 6e 20 74 68 65 20 63 61 73 65 20 6f 66  t in the case of
17060 20 61 6e 20 65 72 72 6f 72 29 2e 20 20 49 6e 73   an error).  Ins
17070 74 65 61 64 2c 20 66 6f 72 20 65 61 63 68 20 69  tead, for each i
17080 6e 63 6f 6d 69 6e 67 0a 20 20 2a 2a 20 63 6c 69  ncoming.  ** cli
17090 65 6e 74 20 63 6f 6e 6e 65 63 74 69 6f 6e 2c 20  ent connection, 
170a0 61 20 63 68 69 6c 64 20 70 72 6f 63 65 73 73 20  a child process 
170b0 69 73 20 63 72 65 61 74 65 64 2c 20 66 69 6c 65  is created, file
170c0 20 64 65 73 63 72 69 70 74 6f 72 73 20 30 0a 20   descriptors 0. 
170d0 20 2a 2a 20 61 6e 64 20 31 20 61 72 65 20 62 6f   ** and 1 are bo
170e0 75 6e 64 20 74 6f 20 74 68 61 74 20 63 6f 6e 6e  und to that conn
170f0 65 63 74 69 6f 6e 2c 20 61 6e 64 20 74 68 65 20  ection, and the 
17100 63 68 69 6c 64 20 72 65 74 75 72 6e 73 2e 0a 20  child returns.. 
17110 20 2a 2a 0a 20 20 2a 2a 20 53 6f 2c 20 77 68 65   **.  ** So, whe
17120 6e 20 63 6f 6e 74 72 6f 6c 20 72 65 61 63 68 65  n control reache
17130 73 20 74 68 69 73 20 70 6f 69 6e 74 2c 20 77 65  s this point, we
17140 20 61 72 65 20 72 75 6e 6e 69 6e 67 20 61 73 20   are running as 
17150 61 0a 20 20 2a 2a 20 63 68 69 6c 64 20 70 72 6f  a.  ** child pro
17160 63 65 73 73 2c 20 74 68 65 20 48 54 54 50 20 6f  cess, the HTTP o
17170 72 20 53 43 47 49 20 72 65 71 75 65 73 74 20 69  r SCGI request i
17180 73 20 70 65 6e 64 69 6e 67 20 6f 6e 20 66 69 6c  s pending on fil
17190 65 0a 20 20 2a 2a 20 64 65 73 63 72 69 70 74 6f  e.  ** descripto
171a0 72 20 30 20 61 6e 64 20 74 68 65 20 72 65 70 6c  r 0 and the repl
171b0 79 20 73 68 6f 75 6c 64 20 62 65 20 77 72 69 74  y should be writ
171c0 74 65 6e 20 74 6f 20 66 69 6c 65 20 64 65 73 63  ten to file desc
171d0 72 69 70 74 6f 72 20 31 2e 0a 20 20 2a 2f 0a 20  riptor 1..  */. 
171e0 20 69 66 28 20 7a 4d 61 78 4c 61 74 65 6e 63 79   if( zMaxLatency
171f0 20 29 7b 0a 20 20 20 20 73 69 67 6e 61 6c 28 53   ){.    signal(S
17200 49 47 41 4c 52 4d 2c 20 73 69 67 61 6c 72 6d 5f  IGALRM, sigalrm_
17210 68 61 6e 64 6c 65 72 29 3b 0a 20 20 20 20 61 6c  handler);.    al
17220 61 72 6d 28 61 74 6f 69 28 7a 4d 61 78 4c 61 74  arm(atoi(zMaxLat
17230 65 6e 63 79 29 29 3b 0a 20 20 7d 0a 20 20 67 2e  ency));.  }.  g.
17240 68 74 74 70 49 6e 20 3d 20 73 74 64 69 6e 3b 0a  httpIn = stdin;.
17250 20 20 67 2e 68 74 74 70 4f 75 74 20 3d 20 73 74    g.httpOut = st
17260 64 6f 75 74 3b 0a 0a 23 69 66 20 21 64 65 66 69  dout;..#if !defi
17270 6e 65 64 28 5f 57 49 4e 33 32 29 0a 20 20 73 69  ned(_WIN32).  si
17280 67 6e 61 6c 28 53 49 47 53 45 47 56 2c 20 73 69  gnal(SIGSEGV, si
17290 67 73 65 67 76 5f 68 61 6e 64 6c 65 72 29 3b 0a  gsegv_handler);.
172a0 20 20 73 69 67 6e 61 6c 28 53 49 47 50 49 50 45    signal(SIGPIPE
172b0 2c 20 73 69 67 70 69 70 65 5f 68 61 6e 64 6c 65  , sigpipe_handle
172c0 72 29 3b 0a 23 65 6e 64 69 66 0a 0a 20 20 69 66  r);.#endif..  if
172d0 28 20 67 2e 66 41 6e 79 54 72 61 63 65 20 29 7b  ( g.fAnyTrace ){
172e0 0a 20 20 20 20 66 70 72 69 6e 74 66 28 73 74 64  .    fprintf(std
172f0 65 72 72 2c 20 22 2f 2a 2a 2a 2a 2a 20 53 75 62  err, "/***** Sub
17300 70 72 6f 63 65 73 73 20 25 64 20 2a 2a 2a 2a 2a  process %d *****
17310 2f 5c 6e 22 2c 20 67 65 74 70 69 64 28 29 29 3b  /\n", getpid());
17320 0a 20 20 7d 0a 20 20 67 2e 63 67 69 4f 75 74 70  .  }.  g.cgiOutp
17330 75 74 20 3d 20 31 3b 0a 20 20 66 69 6e 64 5f 73  ut = 1;.  find_s
17340 65 72 76 65 72 5f 72 65 70 6f 73 69 74 6f 72 79  erver_repository
17350 28 32 2c 20 30 29 3b 0a 20 20 69 66 28 20 66 6f  (2, 0);.  if( fo
17360 73 73 69 6c 5f 73 74 72 63 6d 70 28 67 2e 7a 52  ssil_strcmp(g.zR
17370 65 70 6f 73 69 74 6f 72 79 4e 61 6d 65 2c 22 2f  epositoryName,"/
17380 22 29 3d 3d 30 20 29 7b 0a 20 20 20 20 61 6c 6c  ")==0 ){.    all
17390 6f 77 52 65 70 6f 4c 69 73 74 20 3d 20 31 3b 0a  owRepoList = 1;.
173a0 20 20 7d 65 6c 73 65 7b 0a 20 20 20 20 67 2e 7a    }else{.    g.z
173b0 52 65 70 6f 73 69 74 6f 72 79 4e 61 6d 65 20 3d  RepositoryName =
173c0 20 65 6e 74 65 72 5f 63 68 72 6f 6f 74 5f 6a 61   enter_chroot_ja
173d0 69 6c 28 67 2e 7a 52 65 70 6f 73 69 74 6f 72 79  il(g.zRepository
173e0 4e 61 6d 65 2c 20 6e 6f 4a 61 69 6c 29 3b 0a 20  Name, noJail);. 
173f0 20 7d 0a 20 20 69 66 28 20 66 6c 61 67 73 20 26   }.  if( flags &
17400 20 48 54 54 50 5f 53 45 52 56 45 52 5f 53 43 47   HTTP_SERVER_SCG
17410 49 20 29 7b 0a 20 20 20 20 63 67 69 5f 68 61 6e  I ){.    cgi_han
17420 64 6c 65 5f 73 63 67 69 5f 72 65 71 75 65 73 74  dle_scgi_request
17430 28 29 3b 0a 20 20 7d 65 6c 73 65 7b 0a 20 20 20  ();.  }else{.   
17440 20 63 67 69 5f 68 61 6e 64 6c 65 5f 68 74 74 70   cgi_handle_http
17450 5f 72 65 71 75 65 73 74 28 30 29 3b 0a 20 20 7d  _request(0);.  }
17460 0a 20 20 70 72 6f 63 65 73 73 5f 6f 6e 65 5f 77  .  process_one_w
17470 65 62 5f 70 61 67 65 28 7a 4e 6f 74 46 6f 75 6e  eb_page(zNotFoun
17480 64 2c 20 67 6c 6f 62 5f 63 72 65 61 74 65 28 7a  d, glob_create(z
17490 46 69 6c 65 47 6c 6f 62 29 2c 20 61 6c 6c 6f 77  FileGlob), allow
174a0 52 65 70 6f 4c 69 73 74 29 3b 0a 20 20 69 66 28  RepoList);.  if(
174b0 20 67 2e 66 41 6e 79 54 72 61 63 65 20 29 7b 0a   g.fAnyTrace ){.
174c0 20 20 20 20 66 70 72 69 6e 74 66 28 73 74 64 65      fprintf(stde
174d0 72 72 2c 20 22 2f 2a 2a 2a 2a 2a 20 57 65 62 70  rr, "/***** Webp
174e0 61 67 65 20 66 69 6e 69 73 68 65 64 20 69 6e 20  age finished in 
174f0 73 75 62 70 72 6f 63 65 73 73 20 25 64 20 2a 2a  subprocess %d **
17500 2a 2a 2a 2f 5c 6e 22 2c 0a 20 20 20 20 20 20 20  ***/\n",.       
17510 20 20 20 20 20 67 65 74 70 69 64 28 29 29 3b 0a       getpid());.
17520 20 20 7d 0a 23 65 6c 73 65 0a 20 20 2f 2a 20 57    }.#else.  /* W
17530 69 6e 33 32 20 69 6d 70 6c 65 6d 65 6e 74 61 74  in32 implementat
17540 69 6f 6e 20 2a 2f 0a 20 20 69 66 28 20 69 73 55  ion */.  if( isU
17550 69 43 6d 64 20 29 7b 0a 20 20 20 20 7a 42 72 6f  iCmd ){.    zBro
17560 77 73 65 72 20 3d 20 64 62 5f 67 65 74 28 22 77  wser = db_get("w
17570 65 62 2d 62 72 6f 77 73 65 72 22 2c 20 22 73 74  eb-browser", "st
17580 61 72 74 22 29 3b 0a 20 20 20 20 69 66 28 20 7a  art");.    if( z
17590 49 70 41 64 64 72 3d 3d 30 20 29 7b 0a 20 20 20  IpAddr==0 ){.   
175a0 20 20 20 7a 42 72 6f 77 73 65 72 43 6d 64 20 3d     zBrowserCmd =
175b0 20 6d 70 72 69 6e 74 66 28 22 25 73 20 68 74 74   mprintf("%s htt
175c0 70 3a 2f 2f 6c 6f 63 61 6c 68 6f 73 74 3a 25 25  p://localhost:%%
175d0 64 2f 25 73 20 26 22 2c 0a 20 20 20 20 20 20 20  d/%s &",.       
175e0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
175f0 20 20 20 20 20 7a 42 72 6f 77 73 65 72 2c 20 7a       zBrowser, z
17600 49 6e 69 74 50 61 67 65 29 3b 0a 20 20 20 20 7d  InitPage);.    }
17610 65 6c 73 65 20 69 66 28 20 73 74 72 63 68 72 28  else if( strchr(
17620 7a 49 70 41 64 64 72 2c 27 3a 27 29 20 29 7b 0a  zIpAddr,':') ){.
17630 20 20 20 20 20 20 7a 42 72 6f 77 73 65 72 43 6d        zBrowserCm
17640 64 20 3d 20 6d 70 72 69 6e 74 66 28 22 25 73 20  d = mprintf("%s 
17650 68 74 74 70 3a 2f 2f 5b 25 73 5d 3a 25 25 64 2f  http://[%s]:%%d/
17660 25 73 20 26 22 2c 0a 20 20 20 20 20 20 20 20 20  %s &",.         
17670 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
17680 20 20 20 7a 42 72 6f 77 73 65 72 2c 20 7a 49 70     zBrowser, zIp
17690 41 64 64 72 2c 20 7a 49 6e 69 74 50 61 67 65 29  Addr, zInitPage)
176a0 3b 0a 20 20 20 20 7d 65 6c 73 65 7b 0a 20 20 20  ;.    }else{.   
176b0 20 20 20 7a 42 72 6f 77 73 65 72 43 6d 64 20 3d     zBrowserCmd =
176c0 20 6d 70 72 69 6e 74 66 28 22 25 73 20 68 74 74   mprintf("%s htt
176d0 70 3a 2f 2f 25 73 3a 25 25 64 2f 25 73 20 26 22  p://%s:%%d/%s &"
176e0 2c 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20  ,.              
176f0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 7a 42                zB
17700 72 6f 77 73 65 72 2c 20 7a 49 70 41 64 64 72 2c  rowser, zIpAddr,
17710 20 7a 49 6e 69 74 50 61 67 65 29 3b 0a 20 20 20   zInitPage);.   
17720 20 7d 0a 20 20 7d 0a 20 20 69 66 28 20 67 2e 72   }.  }.  if( g.r
17730 65 70 6f 73 69 74 6f 72 79 4f 70 65 6e 20 29 20  epositoryOpen ) 
17740 66 6c 61 67 73 20 7c 3d 20 48 54 54 50 5f 53 45  flags |= HTTP_SE
17750 52 56 45 52 5f 48 41 44 5f 52 45 50 4f 53 49 54  RVER_HAD_REPOSIT
17760 4f 52 59 3b 0a 20 20 69 66 28 20 67 2e 6c 6f 63  ORY;.  if( g.loc
17770 61 6c 4f 70 65 6e 20 29 20 66 6c 61 67 73 20 7c  alOpen ) flags |
17780 3d 20 48 54 54 50 5f 53 45 52 56 45 52 5f 48 41  = HTTP_SERVER_HA
17790 44 5f 43 48 45 43 4b 4f 55 54 3b 0a 20 20 64 62  D_CHECKOUT;.  db
177a0 5f 63 6c 6f 73 65 28 31 29 3b 0a 20 20 69 66 28  _close(1);.  if(
177b0 20 61 6c 6c 6f 77 52 65 70 6f 4c 69 73 74 20 29   allowRepoList )
177c0 7b 0a 20 20 20 20 66 6c 61 67 73 20 7c 3d 20 48  {.    flags |= H
177d0 54 54 50 5f 53 45 52 56 45 52 5f 52 45 50 4f 4c  TTP_SERVER_REPOL
177e0 49 53 54 3b 0a 20 20 7d 0a 20 20 69 66 28 20 77  IST;.  }.  if( w
177f0 69 6e 33 32 5f 68 74 74 70 5f 73 65 72 76 69 63  in32_http_servic
17800 65 28 69 50 6f 72 74 2c 20 7a 41 6c 74 42 61 73  e(iPort, zAltBas
17810 65 2c 20 7a 4e 6f 74 46 6f 75 6e 64 2c 20 7a 46  e, zNotFound, zF
17820 69 6c 65 47 6c 6f 62 2c 20 66 6c 61 67 73 29 20  ileGlob, flags) 
17830 29 7b 0a 20 20 20 20 77 69 6e 33 32 5f 68 74 74  ){.    win32_htt
17840 70 5f 73 65 72 76 65 72 28 69 50 6f 72 74 2c 20  p_server(iPort, 
17850 6d 78 50 6f 72 74 2c 20 7a 42 72 6f 77 73 65 72  mxPort, zBrowser
17860 43 6d 64 2c 20 7a 53 74 6f 70 70 65 72 46 69 6c  Cmd, zStopperFil
17870 65 2c 0a 20 20 20 20 20 20 20 20 20 20 20 20 20  e,.             
17880 20 20 20 20 20 20 20 20 20 7a 41 6c 74 42 61 73           zAltBas
17890 65 2c 20 7a 4e 6f 74 46 6f 75 6e 64 2c 20 7a 46  e, zNotFound, zF
178a0 69 6c 65 47 6c 6f 62 2c 20 7a 49 70 41 64 64 72  ileGlob, zIpAddr
178b0 2c 20 66 6c 61 67 73 29 3b 0a 20 20 7d 0a 23 65  , flags);.  }.#e
178c0 6e 64 69 66 0a 7d 0a 0a 2f 2a 0a 2a 2a 20 43 4f  ndif.}../*.** CO
178d0 4d 4d 41 4e 44 3a 20 74 65 73 74 2d 65 63 68 6f  MMAND: test-echo
178e0 0a 2a 2a 0a 2a 2a 20 55 73 61 67 65 3a 20 20 25  .**.** Usage:  %
178f0 66 6f 73 73 69 6c 20 74 65 73 74 2d 65 63 68 6f  fossil test-echo
17900 20 5b 2d 2d 68 65 78 5d 20 41 52 47 53 2e 2e 2e   [--hex] ARGS...
17910 0a 2a 2a 0a 2a 2a 20 45 63 68 6f 20 61 6c 6c 20  .**.** Echo all 
17920 63 6f 6d 6d 61 6e 64 2d 6c 69 6e 65 20 61 72 67  command-line arg
17930 75 6d 65 6e 74 73 20 28 65 6e 63 6c 6f 73 65 64  uments (enclosed
17940 20 69 6e 20 5b 2e 2e 2e 5d 29 20 74 6f 20 74 68   in [...]) to th
17950 65 20 73 63 72 65 65 6e 20 73 6f 20 74 68 61 74  e screen so that
17960 0a 2a 2a 20 77 69 6c 64 63 61 72 64 20 65 78 70  .** wildcard exp
17970 61 6e 73 69 6f 6e 20 62 65 68 61 76 69 6f 72 20  ansion behavior 
17980 6f 66 20 74 68 65 20 68 6f 73 74 20 73 68 65 6c  of the host shel
17990 6c 20 63 61 6e 20 62 65 20 69 6e 76 65 73 74 69  l can be investi
179a0 67 61 74 65 64 2e 0a 2a 2a 0a 2a 2a 20 57 69 74  gated..**.** Wit
179b0 68 20 74 68 65 20 2d 2d 68 65 78 20 6f 70 74 69  h the --hex opti
179c0 6f 6e 2c 20 73 68 6f 77 20 74 68 65 20 6f 75 74  on, show the out
179d0 70 75 74 20 61 73 20 68 65 78 61 64 65 63 69 6d  put as hexadecim
179e0 61 6c 2e 20 20 54 68 69 73 20 63 61 6e 20 62 65  al.  This can be
179f0 20 75 73 65 64 0a 2a 2a 20 74 6f 20 76 65 72 69   used.** to veri
17a00 66 79 20 74 68 65 20 66 6f 73 73 69 6c 5f 70 61  fy the fossil_pa
17a10 74 68 5f 74 6f 5f 75 74 66 38 28 29 20 72 6f 75  th_to_utf8() rou
17a20 74 69 6e 65 20 6f 6e 20 57 69 6e 64 6f 77 73 20  tine on Windows 
17a30 61 6e 64 20 4d 61 63 2e 0a 2a 2f 0a 76 6f 69 64  and Mac..*/.void
17a40 20 74 65 73 74 5f 65 63 68 6f 5f 63 6d 64 28 76   test_echo_cmd(v
17a50 6f 69 64 29 7b 0a 20 20 69 6e 74 20 69 2c 20 6a  oid){.  int i, j
17a60 3b 0a 20 20 69 66 28 20 66 69 6e 64 5f 6f 70 74  ;.  if( find_opt
17a70 69 6f 6e 28 22 68 65 78 22 2c 30 2c 30 29 3d 3d  ion("hex",0,0)==
17a80 30 20 29 7b 0a 20 20 20 20 66 6f 73 73 69 6c 5f  0 ){.    fossil_
17a90 70 72 69 6e 74 28 22 67 2e 6e 61 6d 65 4f 66 45  print("g.nameOfE
17aa0 78 65 20 3d 20 5b 25 73 5d 5c 6e 22 2c 20 67 2e  xe = [%s]\n", g.
17ab0 6e 61 6d 65 4f 66 45 78 65 29 3b 0a 20 20 20 20  nameOfExe);.    
17ac0 66 6f 72 28 69 3d 30 3b 20 69 3c 67 2e 61 72 67  for(i=0; i<g.arg
17ad0 63 3b 20 69 2b 2b 29 7b 0a 20 20 20 20 20 20 66  c; i++){.      f
17ae0 6f 73 73 69 6c 5f 70 72 69 6e 74 28 22 61 72 67  ossil_print("arg
17af0 76 5b 25 64 5d 20 3d 20 5b 25 73 5d 5c 6e 22 2c  v[%d] = [%s]\n",
17b00 20 69 2c 20 67 2e 61 72 67 76 5b 69 5d 29 3b 0a   i, g.argv[i]);.
17b10 20 20 20 20 7d 0a 20 20 7d 65 6c 73 65 7b 0a 20      }.  }else{. 
17b20 20 20 20 75 6e 73 69 67 6e 65 64 20 63 68 61 72     unsigned char
17b30 20 2a 7a 2c 20 63 3b 0a 20 20 20 20 66 6f 72 28   *z, c;.    for(
17b40 69 3d 30 3b 20 69 3c 67 2e 61 72 67 63 3b 20 69  i=0; i<g.argc; i
17b50 2b 2b 29 7b 0a 20 20 20 20 20 20 66 6f 73 73 69  ++){.      fossi
17b60 6c 5f 70 72 69 6e 74 28 22 61 72 67 76 5b 25 64  l_print("argv[%d
17b70 5d 20 3d 20 5b 22 2c 20 69 29 3b 0a 20 20 20 20  ] = [", i);.    
17b80 20 20 7a 20 3d 20 28 75 6e 73 69 67 6e 65 64 20    z = (unsigned 
17b90 63 68 61 72 2a 29 67 2e 61 72 67 76 5b 69 5d 3b  char*)g.argv[i];
17ba0 0a 20 20 20 20 20 20 66 6f 72 28 6a 3d 30 3b 20  .      for(j=0; 
17bb0 28 63 20 3d 20 7a 5b 6a 5d 29 21 3d 30 3b 20 6a  (c = z[j])!=0; j
17bc0 2b 2b 29 7b 0a 20 20 20 20 20 20 20 20 66 6f 73  ++){.        fos
17bd0 73 69 6c 5f 70 72 69 6e 74 28 22 25 30 32 78 22  sil_print("%02x"
17be0 2c 20 63 29 3b 0a 20 20 20 20 20 20 7d 0a 20 20  , c);.      }.  
17bf0 20 20 20 20 66 6f 73 73 69 6c 5f 70 72 69 6e 74      fossil_print
17c00 28 22 5d 5c 6e 22 29 3b 0a 20 20 20 20 7d 0a 20  ("]\n");.    }. 
17c10 20 7d 0a 7d 0a 0a 2f 2a 0a 2a 2a 20 57 45 42 50   }.}../*.** WEBP
17c20 41 47 45 3a 20 74 65 73 74 2d 77 61 72 6e 69 6e  AGE: test-warnin
17c30 67 0a 2a 2a 0a 2a 2a 20 54 65 73 74 20 65 72 72  g.**.** Test err
17c40 6f 72 20 61 6e 64 20 77 61 72 6e 69 6e 67 20 6c  or and warning l
17c50 6f 67 20 6f 70 65 72 61 74 69 6f 6e 2e 20 20 54  og operation.  T
17c60 68 69 73 20 77 65 62 70 61 67 65 20 69 73 20 61  his webpage is a
17c70 63 63 65 73 73 69 62 6c 65 20 74 6f 0a 2a 2a 20  ccessible to.** 
17c80 74 68 65 20 61 64 6d 69 6e 69 73 74 72 61 74 6f  the administrato
17c90 72 20 6f 6e 6c 79 2e 0a 2a 2a 0a 2a 2a 20 20 20  r only..**.**   
17ca0 20 20 63 61 73 65 3d 31 20 20 20 20 20 20 20 20    case=1        
17cb0 20 20 20 49 73 73 75 65 20 61 20 66 6f 73 73 69     Issue a fossi
17cc0 6c 5f 77 61 72 6e 69 6e 67 28 29 20 77 68 69 6c  l_warning() whil
17cd0 65 20 67 65 6e 65 72 61 74 69 6e 67 20 74 68 65  e generating the
17ce0 20 70 61 67 65 2e 0a 2a 2a 20 20 20 20 20 63 61   page..**     ca
17cf0 73 65 3d 32 20 20 20 20 20 20 20 20 20 20 20 45  se=2           E
17d00 78 74 72 61 20 64 62 5f 62 65 67 69 6e 5f 74 72  xtra db_begin_tr
17d10 61 6e 73 61 63 74 69 6f 6e 28 29 0a 2a 2a 20 20  ansaction().**  
17d20 20 20 20 63 61 73 65 3d 33 20 20 20 20 20 20 20     case=3       
17d30 20 20 20 20 45 78 74 72 61 20 64 62 5f 65 6e 64      Extra db_end
17d40 5f 74 72 61 6e 73 61 63 74 69 6f 6e 28 29 0a 2a  _transaction().*
17d50 2a 20 20 20 20 20 63 61 73 65 3d 34 20 20 20 20  *     case=4    
17d60 20 20 20 20 20 20 20 45 72 72 6f 72 20 64 75 72         Error dur
17d70 69 6e 67 20 53 51 4c 20 70 72 6f 63 65 73 73 69  ing SQL processi
17d80 6e 67 0a 2a 2a 20 20 20 20 20 63 61 73 65 3d 35  ng.**     case=5
17d90 20 20 20 20 20 20 20 20 20 20 20 43 61 6c 6c 20             Call 
17da0 74 68 65 20 73 65 67 66 61 75 6c 74 20 68 61 6e  the segfault han
17db0 64 6c 65 72 0a 2a 2a 20 20 20 20 20 63 61 73 65  dler.**     case
17dc0 3d 36 20 20 20 20 20 20 20 20 20 20 20 43 61 6c  =6           Cal
17dd0 6c 20 77 65 62 70 61 67 65 5f 61 73 73 65 72 74  l webpage_assert
17de0 28 29 0a 2a 2a 20 20 20 20 20 63 61 73 65 3d 37  ().**     case=7
17df0 20 20 20 20 20 20 20 20 20 20 20 43 61 6c 6c 20             Call 
17e00 77 65 62 70 61 67 65 5f 65 72 72 6f 72 28 29 0a  webpage_error().
17e10 2a 2f 0a 76 6f 69 64 20 74 65 73 74 5f 77 61 72  */.void test_war
17e20 6e 69 6e 67 5f 70 61 67 65 28 76 6f 69 64 29 7b  ning_page(void){
17e30 0a 20 20 69 6e 74 20 69 43 61 73 65 20 3d 20 61  .  int iCase = a
17e40 74 6f 69 28 50 44 28 22 63 61 73 65 22 2c 22 30  toi(PD("case","0
17e50 22 29 29 3b 0a 20 20 69 6e 74 20 69 3b 0a 20 20  "));.  int i;.  
17e60 6c 6f 67 69 6e 5f 63 68 65 63 6b 5f 63 72 65 64  login_check_cred
17e70 65 6e 74 69 61 6c 73 28 29 3b 0a 20 20 69 66 28  entials();.  if(
17e80 20 21 67 2e 70 65 72 6d 2e 41 64 6d 69 6e 20 29   !g.perm.Admin )
17e90 7b 0a 20 20 20 20 6c 6f 67 69 6e 5f 6e 65 65 64  {.    login_need
17ea0 65 64 28 30 29 3b 0a 20 20 20 20 72 65 74 75 72  ed(0);.    retur
17eb0 6e 3b 0a 20 20 7d 0a 20 20 73 74 79 6c 65 5f 68  n;.  }.  style_h
17ec0 65 61 64 65 72 28 22 57 61 72 6e 69 6e 67 20 54  eader("Warning T
17ed0 65 73 74 20 50 61 67 65 22 29 3b 0a 20 20 73 74  est Page");.  st
17ee0 79 6c 65 5f 73 75 62 6d 65 6e 75 5f 65 6c 65 6d  yle_submenu_elem
17ef0 65 6e 74 28 22 45 72 72 6f 72 20 4c 6f 67 22 2c  ent("Error Log",
17f00 22 25 52 2f 65 72 72 6f 72 6c 6f 67 22 29 3b 0a  "%R/errorlog");.
17f10 20 20 69 66 28 20 69 43 61 73 65 3c 31 20 7c 7c    if( iCase<1 ||
17f20 20 69 43 61 73 65 3e 34 20 29 7b 0a 20 20 20 20   iCase>4 ){.    
17f30 40 20 3c 70 3e 47 65 6e 65 72 61 74 65 20 61 20  @ <p>Generate a 
17f40 6d 65 73 73 61 67 65 20 74 6f 20 74 68 65 20 3c  message to the <
17f50 61 20 68 72 65 66 3d 22 25 52 2f 65 72 72 6f 72  a href="%R/error
17f60 6c 6f 67 22 3e 65 72 72 6f 72 20 6c 6f 67 3c 2f  log">error log</
17f70 61 3e 0a 20 20 20 20 40 20 62 79 20 63 6c 69 63  a>.    @ by clic
17f80 6b 69 6e 67 20 6f 6e 20 6f 6e 65 20 6f 66 20 74  king on one of t
17f90 68 65 20 66 6f 6c 6c 6f 77 69 6e 67 20 63 61 73  he following cas
17fa0 65 73 3a 0a 20 20 7d 65 6c 73 65 7b 0a 20 20 20  es:.  }else{.   
17fb0 20 40 20 3c 70 3e 54 68 69 73 20 69 73 20 74 68   @ <p>This is th
17fc0 65 20 74 65 73 74 20 70 61 67 65 20 66 6f 72 20  e test page for 
17fd0 63 61 73 65 3d 25 64 28 69 43 61 73 65 29 2e 20  case=%d(iCase). 
17fe0 20 41 6c 6c 20 70 6f 73 73 69 62 6c 65 20 63 61   All possible ca
17ff0 73 65 73 3a 0a 20 20 7d 0a 20 20 66 6f 72 28 69  ses:.  }.  for(i
18000 3d 31 3b 20 69 3c 3d 37 3b 20 69 2b 2b 29 7b 0a  =1; i<=7; i++){.
18010 20 20 20 20 40 20 3c 61 20 68 72 65 66 3d 27 2e      @ <a href='.
18020 2f 74 65 73 74 2d 77 61 72 6e 69 6e 67 3f 63 61  /test-warning?ca
18030 73 65 3d 25 64 28 69 29 27 3e 5b 25 64 28 69 29  se=%d(i)'>[%d(i)
18040 5d 3c 2f 61 3e 0a 20 20 7d 0a 20 20 40 20 3c 2f  ]</a>.  }.  @ </
18050 70 3e 0a 20 20 40 20 3c 70 3e 3c 6f 6c 3e 0a 20  p>.  @ <p><ol>. 
18060 20 40 20 3c 6c 69 20 76 61 6c 75 65 3d 27 31 27   @ <li value='1'
18070 3e 20 43 61 6c 6c 20 66 6f 73 73 69 6c 5f 77 61  > Call fossil_wa
18080 72 6e 69 6e 67 28 29 0a 20 20 69 66 28 20 69 43  rning().  if( iC
18090 61 73 65 3d 3d 31 20 29 7b 0a 20 20 20 20 66 6f  ase==1 ){.    fo
180a0 73 73 69 6c 5f 77 61 72 6e 69 6e 67 28 22 54 65  ssil_warning("Te
180b0 73 74 20 77 61 72 6e 69 6e 67 20 6d 65 73 73 61  st warning messa
180c0 67 65 20 66 72 6f 6d 20 2f 74 65 73 74 2d 77 61  ge from /test-wa
180d0 72 6e 69 6e 67 22 29 3b 0a 20 20 7d 0a 20 20 40  rning");.  }.  @
180e0 20 3c 6c 69 20 76 61 6c 75 65 3d 27 32 27 3e 20   <li value='2'> 
180f0 43 61 6c 6c 20 64 62 5f 62 65 67 69 6e 5f 74 72  Call db_begin_tr
18100 61 6e 73 61 63 74 69 6f 6e 28 29 0a 20 20 69 66  ansaction().  if
18110 28 20 69 43 61 73 65 3d 3d 32 20 29 7b 0a 20 20  ( iCase==2 ){.  
18120 20 20 64 62 5f 62 65 67 69 6e 5f 74 72 61 6e 73    db_begin_trans
18130 61 63 74 69 6f 6e 28 29 3b 0a 20 20 7d 0a 20 20  action();.  }.  
18140 40 20 3c 6c 69 20 76 61 6c 75 65 3d 27 33 27 3e  @ <li value='3'>
18150 20 43 61 6c 6c 20 64 62 5f 65 6e 64 5f 74 72 61   Call db_end_tra
18160 6e 73 61 63 74 69 6f 6e 28 29 0a 20 20 69 66 28  nsaction().  if(
18170 20 69 43 61 73 65 3d 3d 33 20 29 7b 0a 20 20 20   iCase==3 ){.   
18180 20 64 62 5f 65 6e 64 5f 74 72 61 6e 73 61 63 74   db_end_transact
18190 69 6f 6e 28 30 29 3b 0a 20 20 7d 0a 20 20 40 20  ion(0);.  }.  @ 
181a0 3c 6c 69 20 76 61 6c 75 65 3d 27 34 27 3e 20 77  <li value='4'> w
181b0 61 72 6e 69 6e 67 20 64 75 72 69 6e 67 20 53 51  arning during SQ
181c0 4c 0a 20 20 69 66 28 20 69 43 61 73 65 3d 3d 34  L.  if( iCase==4
181d0 20 29 7b 0a 20 20 20 20 53 74 6d 74 20 71 3b 0a   ){.    Stmt q;.
181e0 20 20 20 20 64 62 5f 70 72 65 70 61 72 65 28 26      db_prepare(&
181f0 71 2c 20 22 53 45 4c 45 43 54 20 75 75 69 64 20  q, "SELECT uuid 
18200 46 52 4f 4d 20 62 6c 6f 62 20 4c 49 4d 49 54 20  FROM blob LIMIT 
18210 35 22 29 3b 0a 20 20 20 20 64 62 5f 73 74 65 70  5");.    db_step
18220 28 26 71 29 3b 0a 20 20 20 20 73 71 6c 69 74 65  (&q);.    sqlite
18230 33 5f 6c 6f 67 28 53 51 4c 49 54 45 5f 45 52 52  3_log(SQLITE_ERR
18240 4f 52 2c 20 22 54 65 73 74 20 77 61 72 6e 69 6e  OR, "Test warnin
18250 67 20 6d 65 73 73 61 67 65 20 64 75 72 69 6e 67  g message during
18260 20 53 51 4c 22 29 3b 0a 20 20 20 20 64 62 5f 66   SQL");.    db_f
18270 69 6e 61 6c 69 7a 65 28 26 71 29 3b 0a 20 20 7d  inalize(&q);.  }
18280 0a 20 20 40 20 3c 6c 69 20 76 61 6c 75 65 3d 27  .  @ <li value='
18290 35 27 3e 20 73 69 6d 75 6c 61 74 65 20 73 65 67  5'> simulate seg
182a0 66 61 75 6c 74 20 68 61 6e 64 6c 69 6e 67 0a 20  fault handling. 
182b0 20 69 66 28 20 69 43 61 73 65 3d 3d 35 20 29 7b   if( iCase==5 ){
182c0 0a 20 20 20 20 73 69 67 73 65 67 76 5f 68 61 6e  .    sigsegv_han
182d0 64 6c 65 72 28 30 29 3b 0a 20 20 7d 0a 20 20 40  dler(0);.  }.  @
182e0 20 3c 6c 69 20 76 61 6c 75 65 3d 27 36 27 3e 20   <li value='6'> 
182f0 63 61 6c 6c 20 77 65 62 70 61 67 65 5f 61 73 73  call webpage_ass
18300 65 72 74 28 30 29 0a 20 20 69 66 28 20 69 43 61  ert(0).  if( iCa
18310 73 65 3d 3d 36 20 29 7b 0a 20 20 20 20 77 65 62  se==6 ){.    web
18320 70 61 67 65 5f 61 73 73 65 72 74 28 20 35 3d 3d  page_assert( 5==
18330 37 20 29 3b 0a 20 20 7d 0a 20 20 40 20 3c 6c 69  7 );.  }.  @ <li
18340 20 76 61 6c 75 65 3d 27 37 27 3e 20 63 61 6c 6c   value='7'> call
18350 20 77 65 62 70 61 67 65 5f 65 72 72 6f 72 28 29   webpage_error()
18360 22 0a 20 20 69 66 28 20 69 43 61 73 65 3d 3d 37  ".  if( iCase==7
18370 20 29 7b 0a 20 20 20 20 63 67 69 5f 72 65 73 65   ){.    cgi_rese
18380 74 5f 63 6f 6e 74 65 6e 74 28 29 3b 0a 20 20 20  t_content();.   
18390 20 77 65 62 70 61 67 65 5f 65 72 72 6f 72 28 22   webpage_error("
183a0 43 61 73 65 20 37 20 66 72 6f 6d 20 2f 74 65 73  Case 7 from /tes
183b0 74 2d 77 61 72 6e 69 6e 67 22 29 3b 0a 20 20 7d  t-warning");.  }
183c0 0a 20 20 40 20 3c 2f 6f 6c 3e 0a 20 20 40 20 3c  .  @ </ol>.  @ <
183d0 70 3e 45 6e 64 20 6f 66 20 74 65 73 74 3c 2f 70  p>End of test</p
183e0 3e 0a 20 20 73 74 79 6c 65 5f 66 6f 6f 74 65 72  >.  style_footer
183f0 28 29 3b 0a 7d 0a                                ();.}.