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 6e 63 6c 75 64 65 nfig.h".#include
02e0: 20 22 6d 61 69 6e 2e 68 22 0a 23 69 6e 63 6c 75 "main.h".#inclu
02f0: 64 65 20 3c 73 74 72 69 6e 67 2e 68 3e 0a 23 69 de <string.h>.#i
0300: 6e 63 6c 75 64 65 20 3c 74 69 6d 65 2e 68 3e 0a nclude <time.h>.
0310: 23 69 6e 63 6c 75 64 65 20 3c 66 63 6e 74 6c 2e #include <fcntl.
0320: 68 3e 0a 23 69 6e 63 6c 75 64 65 20 3c 73 79 73 h>.#include <sys
0330: 2f 74 79 70 65 73 2e 68 3e 0a 23 69 6e 63 6c 75 /types.h>.#inclu
0340: 64 65 20 3c 73 79 73 2f 73 74 61 74 2e 68 3e 0a de <sys/stat.h>.
0350: 23 69 6e 63 6c 75 64 65 20 3c 73 74 64 6c 69 62 #include <stdlib
0360: 2e 68 3e 20 2f 2a 20 61 74 65 78 69 74 28 29 20 .h> /* atexit()
0370: 2a 2f 0a 23 69 66 20 64 65 66 69 6e 65 64 28 5f */.#if defined(_
0380: 57 49 4e 33 32 29 0a 23 20 20 69 6e 63 6c 75 64 WIN32).# includ
0390: 65 20 3c 77 69 6e 64 6f 77 73 2e 68 3e 0a 23 65 e <windows.h>.#e
03a0: 6c 73 65 0a 23 20 20 69 6e 63 6c 75 64 65 20 3c lse.# include <
03b0: 65 72 72 6e 6f 2e 68 3e 20 2f 2a 20 65 72 72 6e errno.h> /* errn
03c0: 6f 20 67 6c 6f 62 61 6c 20 2a 2f 0a 23 65 6e 64 o global */.#end
03d0: 69 66 0a 23 69 66 64 65 66 20 46 4f 53 53 49 4c if.#ifdef FOSSIL
03e0: 5f 45 4e 41 42 4c 45 5f 53 53 4c 0a 23 20 20 69 _ENABLE_SSL.# i
03f0: 6e 63 6c 75 64 65 20 22 6f 70 65 6e 73 73 6c 2f nclude "openssl/
0400: 63 72 79 70 74 6f 2e 68 22 0a 23 65 6e 64 69 66 crypto.h".#endif
0410: 0a 23 69 66 20 64 65 66 69 6e 65 64 28 46 4f 53 .#if defined(FOS
0420: 53 49 4c 5f 45 4e 41 42 4c 45 5f 4d 49 4e 49 5a SIL_ENABLE_MINIZ
0430: 29 0a 23 20 20 64 65 66 69 6e 65 20 4d 49 4e 49 ).# define MINI
0440: 5a 5f 48 45 41 44 45 52 5f 46 49 4c 45 5f 4f 4e Z_HEADER_FILE_ON
0450: 4c 59 0a 23 20 20 69 6e 63 6c 75 64 65 20 22 6d LY.# include "m
0460: 69 6e 69 7a 2e 63 22 0a 23 65 6c 73 65 0a 23 20 iniz.c".#else.#
0470: 20 69 6e 63 6c 75 64 65 20 3c 7a 6c 69 62 2e 68 include <zlib.h
0480: 3e 0a 23 65 6e 64 69 66 0a 23 69 66 20 49 4e 54 >.#endif.#if INT
0490: 45 52 46 41 43 45 0a 23 69 66 64 65 66 20 46 4f ERFACE.#ifdef FO
04a0: 53 53 49 4c 5f 45 4e 41 42 4c 45 5f 54 43 4c 0a SSIL_ENABLE_TCL.
04b0: 23 20 20 69 6e 63 6c 75 64 65 20 22 74 63 6c 2e # include "tcl.
04c0: 68 22 0a 23 65 6e 64 69 66 0a 23 69 66 64 65 66 h".#endif.#ifdef
04d0: 20 46 4f 53 53 49 4c 5f 45 4e 41 42 4c 45 5f 4a FOSSIL_ENABLE_J
04e0: 53 4f 4e 0a 23 20 20 69 6e 63 6c 75 64 65 20 22 SON.# include "
04f0: 63 73 6f 6e 5f 61 6d 61 6c 67 61 6d 61 74 69 6f cson_amalgamatio
0500: 6e 2e 68 22 20 2f 2a 20 4a 53 4f 4e 20 41 50 49 n.h" /* JSON API
0510: 2e 20 2a 2f 0a 23 20 20 69 6e 63 6c 75 64 65 20 . */.# include
0520: 22 6a 73 6f 6e 5f 64 65 74 61 69 6c 2e 68 22 0a "json_detail.h".
0530: 23 65 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 4e 75 #endif../*.** Nu
0540: 6d 62 65 72 20 6f 66 20 65 6c 65 6d 65 6e 74 73 mber of elements
0550: 20 69 6e 20 61 6e 20 61 72 72 61 79 0a 2a 2f 0a in an array.*/.
0560: 23 64 65 66 69 6e 65 20 63 6f 75 6e 74 28 58 29 #define count(X)
0570: 20 20 28 73 69 7a 65 6f 66 28 58 29 2f 73 69 7a (sizeof(X)/siz
0580: 65 6f 66 28 58 5b 30 5d 29 29 0a 0a 2f 2a 0a 2a eof(X[0]))../*.*
0590: 2a 20 53 69 7a 65 20 6f 66 20 61 20 55 55 49 44 * Size of a UUID
05a0: 20 69 6e 20 63 68 61 72 61 63 74 65 72 73 0a 2a in characters.*
05b0: 2f 0a 23 64 65 66 69 6e 65 20 55 55 49 44 5f 53 /.#define UUID_S
05c0: 49 5a 45 20 34 30 0a 0a 2f 2a 0a 2a 2a 20 4d 61 IZE 40../*.** Ma
05d0: 78 69 6d 75 6d 20 6e 75 6d 62 65 72 20 6f 66 20 ximum number of
05e0: 61 75 78 69 6c 69 61 72 79 20 70 61 72 61 6d 65 auxiliary parame
05f0: 74 65 72 73 20 6f 6e 20 72 65 70 6f 72 74 73 0a ters on reports.
0600: 2a 2f 0a 23 64 65 66 69 6e 65 20 4d 58 5f 41 55 */.#define MX_AU
0610: 58 20 20 35 0a 0a 2f 2a 0a 2a 2a 20 48 6f 6c 64 X 5../*.** Hold
0620: 73 20 66 6c 61 67 73 20 66 6f 72 20 66 6f 73 73 s flags for foss
0630: 69 6c 20 75 73 65 72 20 70 65 72 6d 69 73 73 69 il user permissi
0640: 6f 6e 73 2e 0a 2a 2f 0a 73 74 72 75 63 74 20 46 ons..*/.struct F
0650: 6f 73 73 69 6c 55 73 65 72 50 65 72 6d 73 20 7b ossilUserPerms {
0660: 0a 20 20 63 68 61 72 20 53 65 74 75 70 3b 20 20 . char Setup;
0670: 20 20 20 20 20 20 20 20 20 20 2f 2a 20 73 3a 20 /* s:
0680: 75 73 65 20 53 65 74 75 70 20 73 63 72 65 65 6e use Setup screen
0690: 73 20 6f 6e 20 77 65 62 20 69 6e 74 65 72 66 61 s on web interfa
06a0: 63 65 20 2a 2f 0a 20 20 63 68 61 72 20 41 64 6d ce */. char Adm
06b0: 69 6e 3b 20 20 20 20 20 20 20 20 20 20 20 20 2f in; /
06c0: 2a 20 61 3a 20 61 64 6d 69 6e 69 73 74 72 61 74 * a: administrat
06d0: 69 76 65 20 70 65 72 6d 69 73 73 69 6f 6e 20 2a ive permission *
06e0: 2f 0a 20 20 63 68 61 72 20 44 65 6c 65 74 65 3b /. char Delete;
06f0: 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 64 3a /* d:
0700: 20 64 65 6c 65 74 65 20 77 69 6b 69 20 6f 72 20 delete wiki or
0710: 74 69 63 6b 65 74 73 20 2a 2f 0a 20 20 63 68 61 tickets */. cha
0720: 72 20 50 61 73 73 77 6f 72 64 3b 20 20 20 20 20 r Password;
0730: 20 20 20 20 2f 2a 20 70 3a 20 63 68 61 6e 67 65 /* p: change
0740: 20 70 61 73 73 77 6f 72 64 20 2a 2f 0a 20 20 63 password */. c
0750: 68 61 72 20 51 75 65 72 79 3b 20 20 20 20 20 20 har Query;
0760: 20 20 20 20 20 20 2f 2a 20 71 3a 20 63 72 65 61 /* q: crea
0770: 74 65 20 6e 65 77 20 72 65 70 6f 72 74 73 20 2a te new reports *
0780: 2f 0a 20 20 63 68 61 72 20 57 72 69 74 65 3b 20 /. char Write;
0790: 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 69 3a /* i:
07a0: 20 78 66 65 72 20 69 6e 62 6f 75 6e 64 2e 20 63 xfer inbound. c
07b0: 68 65 63 6b 2d 69 6e 20 2a 2f 0a 20 20 63 68 61 heck-in */. cha
07c0: 72 20 52 65 61 64 3b 20 20 20 20 20 20 20 20 20 r Read;
07d0: 20 20 20 20 2f 2a 20 6f 3a 20 78 66 65 72 20 6f /* o: xfer o
07e0: 75 74 62 6f 75 6e 64 2e 20 63 68 65 63 6b 2d 6f utbound. check-o
07f0: 75 74 20 2a 2f 0a 20 20 63 68 61 72 20 48 79 70 ut */. char Hyp
0800: 65 72 6c 69 6e 6b 3b 20 20 20 20 20 20 20 20 2f erlink; /
0810: 2a 20 68 3a 20 65 6e 61 62 6c 65 20 74 68 65 20 * h: enable the
0820: 64 69 73 70 6c 61 79 20 6f 66 20 68 79 70 65 72 display of hyper
0830: 6c 69 6e 6b 73 20 2a 2f 0a 20 20 63 68 61 72 20 links */. char
0840: 43 6c 6f 6e 65 3b 20 20 20 20 20 20 20 20 20 20 Clone;
0850: 20 20 2f 2a 20 67 3a 20 63 6c 6f 6e 65 20 2a 2f /* g: clone */
0860: 0a 20 20 63 68 61 72 20 52 64 57 69 6b 69 3b 20 . char RdWiki;
0870: 20 20 20 20 20 20 20 20 20 20 2f 2a 20 6a 3a 20 /* j:
0880: 76 69 65 77 20 77 69 6b 69 20 76 69 61 20 77 65 view wiki via we
0890: 62 20 2a 2f 0a 20 20 63 68 61 72 20 4e 65 77 57 b */. char NewW
08a0: 69 6b 69 3b 20 20 20 20 20 20 20 20 20 20 2f 2a iki; /*
08b0: 20 66 3a 20 63 72 65 61 74 65 20 6e 65 77 20 77 f: create new w
08c0: 69 6b 69 20 76 69 61 20 77 65 62 20 2a 2f 0a 20 iki via web */.
08d0: 20 63 68 61 72 20 41 70 6e 64 57 69 6b 69 3b 20 char ApndWiki;
08e0: 20 20 20 20 20 20 20 20 2f 2a 20 6d 3a 20 61 70 /* m: ap
08f0: 70 65 6e 64 20 74 6f 20 77 69 6b 69 20 76 69 61 pend to wiki via
0900: 20 77 65 62 20 2a 2f 0a 20 20 63 68 61 72 20 57 web */. char W
0910: 72 57 69 6b 69 3b 20 20 20 20 20 20 20 20 20 20 rWiki;
0920: 20 2f 2a 20 6b 3a 20 65 64 69 74 20 77 69 6b 69 /* k: edit wiki
0930: 20 76 69 61 20 77 65 62 20 2a 2f 0a 20 20 63 68 via web */. ch
0940: 61 72 20 4d 6f 64 57 69 6b 69 3b 20 20 20 20 20 ar ModWiki;
0950: 20 20 20 20 20 2f 2a 20 6c 3a 20 61 70 70 72 6f /* l: appro
0960: 76 65 20 61 6e 64 20 70 75 62 6c 69 73 68 20 77 ve and publish w
0970: 69 6b 69 20 63 6f 6e 74 65 6e 74 20 28 4d 6f 64 iki content (Mod
0980: 65 72 61 74 6f 72 29 20 2a 2f 0a 20 20 63 68 61 erator) */. cha
0990: 72 20 52 64 54 6b 74 3b 20 20 20 20 20 20 20 20 r RdTkt;
09a0: 20 20 20 20 2f 2a 20 72 3a 20 76 69 65 77 20 74 /* r: view t
09b0: 69 63 6b 65 74 73 20 76 69 61 20 77 65 62 20 2a ickets via web *
09c0: 2f 0a 20 20 63 68 61 72 20 4e 65 77 54 6b 74 3b /. char NewTkt;
09d0: 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 6e 3a /* n:
09e0: 20 63 72 65 61 74 65 20 6e 65 77 20 74 69 63 6b create new tick
09f0: 65 74 73 20 2a 2f 0a 20 20 63 68 61 72 20 41 70 ets */. char Ap
0a00: 6e 64 54 6b 74 3b 20 20 20 20 20 20 20 20 20 20 ndTkt;
0a10: 2f 2a 20 63 3a 20 61 70 70 65 6e 64 20 74 6f 20 /* c: append to
0a20: 74 69 63 6b 65 74 73 20 76 69 61 20 74 68 65 20 tickets via the
0a30: 77 65 62 20 2a 2f 0a 20 20 63 68 61 72 20 57 72 web */. char Wr
0a40: 54 6b 74 3b 20 20 20 20 20 20 20 20 20 20 20 20 Tkt;
0a50: 2f 2a 20 77 3a 20 6d 61 6b 65 20 63 68 61 6e 67 /* w: make chang
0a60: 65 73 20 74 6f 20 74 69 63 6b 65 74 73 20 76 69 es to tickets vi
0a70: 61 20 77 65 62 20 2a 2f 0a 20 20 63 68 61 72 20 a web */. char
0a80: 4d 6f 64 54 6b 74 3b 20 20 20 20 20 20 20 20 20 ModTkt;
0a90: 20 20 2f 2a 20 71 3a 20 61 70 70 72 6f 76 65 20 /* q: approve
0aa0: 61 6e 64 20 70 75 62 6c 69 73 68 20 74 69 63 6b and publish tick
0ab0: 65 74 20 63 68 61 6e 67 65 73 20 28 4d 6f 64 65 et changes (Mode
0ac0: 72 61 74 6f 72 29 20 2a 2f 0a 20 20 63 68 61 72 rator) */. char
0ad0: 20 41 74 74 61 63 68 3b 20 20 20 20 20 20 20 20 Attach;
0ae0: 20 20 20 2f 2a 20 62 3a 20 61 64 64 20 61 74 74 /* b: add att
0af0: 61 63 68 6d 65 6e 74 73 20 2a 2f 0a 20 20 63 68 achments */. ch
0b00: 61 72 20 54 6b 74 46 6d 74 3b 20 20 20 20 20 20 ar TktFmt;
0b10: 20 20 20 20 20 2f 2a 20 74 3a 20 63 72 65 61 74 /* t: creat
0b20: 65 20 6e 65 77 20 74 69 63 6b 65 74 20 72 65 70 e new ticket rep
0b30: 6f 72 74 20 66 6f 72 6d 61 74 73 20 2a 2f 0a 20 ort formats */.
0b40: 20 63 68 61 72 20 52 64 41 64 64 72 3b 20 20 20 char RdAddr;
0b50: 20 20 20 20 20 20 20 20 2f 2a 20 65 3a 20 72 65 /* e: re
0b60: 61 64 20 65 6d 61 69 6c 20 61 64 64 72 65 73 73 ad email address
0b70: 65 73 20 6f 72 20 6f 74 68 65 72 20 70 72 69 76 es or other priv
0b80: 61 74 65 20 64 61 74 61 20 2a 2f 0a 20 20 63 68 ate data */. ch
0b90: 61 72 20 5a 69 70 3b 20 20 20 20 20 20 20 20 20 ar Zip;
0ba0: 20 20 20 20 20 2f 2a 20 7a 3a 20 64 6f 77 6e 6c /* z: downl
0bb0: 6f 61 64 20 7a 69 70 70 65 64 20 61 72 74 69 66 oad zipped artif
0bc0: 61 63 74 20 76 69 61 20 2f 7a 69 70 20 55 52 4c act via /zip URL
0bd0: 20 2a 2f 0a 20 20 63 68 61 72 20 50 72 69 76 61 */. char Priva
0be0: 74 65 3b 20 20 20 20 20 20 20 20 20 20 2f 2a 20 te; /*
0bf0: 78 3a 20 63 61 6e 20 73 65 6e 64 20 61 6e 64 20 x: can send and
0c00: 72 65 63 65 69 76 65 20 70 72 69 76 61 74 65 20 receive private
0c10: 63 6f 6e 74 65 6e 74 20 2a 2f 0a 7d 3b 0a 0a 23 content */.};..#
0c20: 69 66 64 65 66 20 46 4f 53 53 49 4c 5f 45 4e 41 ifdef FOSSIL_ENA
0c30: 42 4c 45 5f 54 43 4c 0a 2f 2a 0a 2a 2a 20 41 6c BLE_TCL./*.** Al
0c40: 6c 20 54 63 6c 20 72 65 6c 61 74 65 64 20 63 6f l Tcl related co
0c50: 6e 74 65 78 74 20 69 6e 66 6f 72 6d 61 74 69 6f ntext informatio
0c60: 6e 20 69 73 20 69 6e 20 74 68 69 73 20 73 74 72 n is in this str
0c70: 75 63 74 75 72 65 2e 20 20 54 68 69 73 20 73 74 ucture. This st
0c80: 72 75 63 74 75 72 65 0a 2a 2a 20 64 65 66 69 6e ructure.** defin
0c90: 69 74 69 6f 6e 20 68 61 73 20 62 65 65 6e 20 63 ition has been c
0ca0: 6f 70 69 65 64 20 66 72 6f 6d 20 61 6e 64 20 73 opied from and s
0cb0: 68 6f 75 6c 64 20 62 65 20 6b 65 70 74 20 69 6e hould be kept in
0cc0: 20 73 79 6e 63 20 77 69 74 68 20 74 68 65 20 6f sync with the o
0cd0: 6e 65 20 69 6e 0a 2a 2a 20 22 74 68 5f 74 63 6c ne in.** "th_tcl
0ce0: 2e 63 22 2e 0a 2a 2f 0a 73 74 72 75 63 74 20 54 .c"..*/.struct T
0cf0: 63 6c 43 6f 6e 74 65 78 74 20 7b 0a 20 20 69 6e clContext {. in
0d00: 74 20 61 72 67 63 3b 20 20 20 20 20 20 20 20 20 t argc;
0d10: 20 20 20 20 20 2f 2a 20 4e 75 6d 62 65 72 20 6f /* Number o
0d20: 66 20 6f 72 69 67 69 6e 61 6c 20 28 65 78 70 61 f original (expa
0d30: 6e 64 65 64 29 20 61 72 67 75 6d 65 6e 74 73 2e nded) arguments.
0d40: 20 2a 2f 0a 20 20 63 68 61 72 20 2a 2a 61 72 67 */. char **arg
0d50: 76 3b 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 v; /*
0d60: 46 75 6c 6c 20 63 6f 70 79 20 6f 66 20 74 68 65 Full copy of the
0d70: 20 6f 72 69 67 69 6e 61 6c 20 28 65 78 70 61 6e original (expan
0d80: 64 65 64 29 20 61 72 67 75 6d 65 6e 74 73 2e 20 ded) arguments.
0d90: 2a 2f 0a 20 20 76 6f 69 64 20 2a 68 4c 69 62 72 */. void *hLibr
0da0: 61 72 79 3b 20 20 20 20 20 20 20 20 2f 2a 20 54 ary; /* T
0db0: 68 65 20 54 63 6c 20 6c 69 62 72 61 72 79 20 6d he Tcl library m
0dc0: 6f 64 75 6c 65 20 68 61 6e 64 6c 65 2e 20 2a 2f odule handle. */
0dd0: 0a 20 20 76 6f 69 64 20 2a 78 46 69 6e 64 45 78 . void *xFindEx
0de0: 65 63 75 74 61 62 6c 65 3b 20 2f 2a 20 53 65 65 ecutable; /* See
0df0: 20 74 63 6c 5f 46 69 6e 64 45 78 65 63 75 74 61 tcl_FindExecuta
0e00: 62 6c 65 50 72 6f 63 20 69 6e 20 74 68 5f 74 63 bleProc in th_tc
0e10: 6c 2e 63 2e 20 2a 2f 0a 20 20 76 6f 69 64 20 2a l.c. */. void *
0e20: 78 43 72 65 61 74 65 49 6e 74 65 72 70 3b 20 20 xCreateInterp;
0e30: 20 2f 2a 20 53 65 65 20 74 63 6c 5f 43 72 65 61 /* See tcl_Crea
0e40: 74 65 49 6e 74 65 72 70 50 72 6f 63 20 69 6e 20 teInterpProc in
0e50: 74 68 5f 74 63 6c 2e 63 2e 20 2a 2f 0a 20 20 76 th_tcl.c. */. v
0e60: 6f 69 64 20 2a 78 44 65 6c 65 74 65 49 6e 74 65 oid *xDeleteInte
0e70: 72 70 3b 20 20 20 2f 2a 20 53 65 65 20 74 63 6c rp; /* See tcl
0e80: 5f 44 65 6c 65 74 65 49 6e 74 65 72 70 50 72 6f _DeleteInterpPro
0e90: 63 20 69 6e 20 74 68 5f 74 63 6c 2e 63 2e 20 2a c in th_tcl.c. *
0ea0: 2f 0a 20 20 76 6f 69 64 20 2a 78 46 69 6e 61 6c /. void *xFinal
0eb0: 69 7a 65 3b 20 20 20 20 20 20 20 2f 2a 20 53 65 ize; /* Se
0ec0: 65 20 74 63 6c 5f 46 69 6e 61 6c 69 7a 65 50 72 e tcl_FinalizePr
0ed0: 6f 63 20 69 6e 20 74 68 5f 74 63 6c 2e 63 2e 20 oc in th_tcl.c.
0ee0: 2a 2f 0a 20 20 54 63 6c 5f 49 6e 74 65 72 70 20 */. Tcl_Interp
0ef0: 2a 69 6e 74 65 72 70 3b 20 20 20 20 2f 2a 20 54 *interp; /* T
0f00: 68 65 20 6f 6e 2d 64 65 6d 61 6e 64 20 63 72 65 he on-demand cre
0f10: 61 74 65 64 20 54 63 6c 20 69 6e 74 65 72 70 72 ated Tcl interpr
0f20: 65 74 65 72 2e 20 2a 2f 0a 20 20 69 6e 74 20 75 eter. */. int u
0f30: 73 65 4f 62 6a 50 72 6f 63 3b 20 20 20 20 20 20 seObjProc;
0f40: 20 20 2f 2a 20 4e 6f 6e 2d 7a 65 72 6f 20 69 66 /* Non-zero if
0f50: 20 61 6e 20 6f 62 6a 50 72 6f 63 20 63 61 6e 20 an objProc can
0f60: 62 65 20 63 61 6c 6c 65 64 20 64 69 72 65 63 74 be called direct
0f70: 6c 79 2e 20 2a 2f 0a 20 20 69 6e 74 20 75 73 65 ly. */. int use
0f80: 54 69 70 32 38 35 3b 20 20 20 20 20 20 20 20 20 Tip285;
0f90: 2f 2a 20 4e 6f 6e 2d 7a 65 72 6f 20 69 66 20 54 /* Non-zero if T
0fa0: 49 50 20 23 32 38 35 20 69 73 20 61 76 61 69 6c IP #285 is avail
0fb0: 61 62 6c 65 2e 20 2a 2f 0a 20 20 63 68 61 72 20 able. */. char
0fc0: 2a 73 65 74 75 70 3b 20 20 20 20 20 20 20 20 20 *setup;
0fd0: 20 20 2f 2a 20 54 68 65 20 6f 70 74 69 6f 6e 61 /* The optiona
0fe0: 6c 20 54 63 6c 20 73 65 74 75 70 20 73 63 72 69 l Tcl setup scri
0ff0: 70 74 2e 20 2a 2f 0a 20 20 76 6f 69 64 20 2a 78 pt. */. void *x
1000: 50 72 65 45 76 61 6c 3b 20 20 20 20 20 20 20 20 PreEval;
1010: 2f 2a 20 4f 70 74 69 6f 6e 61 6c 2c 20 63 61 6c /* Optional, cal
1020: 6c 65 64 20 62 65 66 6f 72 65 20 54 63 6c 5f 45 led before Tcl_E
1030: 76 61 6c 2a 28 29 2e 20 2a 2f 0a 20 20 76 6f 69 val*(). */. voi
1040: 64 20 2a 70 50 72 65 43 6f 6e 74 65 78 74 3b 20 d *pPreContext;
1050: 20 20 20 20 2f 2a 20 4f 70 74 69 6f 6e 61 6c 2c /* Optional,
1060: 20 70 72 6f 76 69 64 65 64 20 74 6f 20 78 50 72 provided to xPr
1070: 65 45 76 61 6c 28 29 2e 20 2a 2f 0a 20 20 76 6f eEval(). */. vo
1080: 69 64 20 2a 78 50 6f 73 74 45 76 61 6c 3b 20 20 id *xPostEval;
1090: 20 20 20 20 20 2f 2a 20 4f 70 74 69 6f 6e 61 6c /* Optional
10a0: 2c 20 63 61 6c 6c 65 64 20 61 66 74 65 72 20 54 , called after T
10b0: 63 6c 5f 45 76 61 6c 2a 28 29 2e 20 2a 2f 0a 20 cl_Eval*(). */.
10c0: 20 76 6f 69 64 20 2a 70 50 6f 73 74 43 6f 6e 74 void *pPostCont
10d0: 65 78 74 3b 20 20 20 20 2f 2a 20 4f 70 74 69 6f ext; /* Optio
10e0: 6e 61 6c 2c 20 70 72 6f 76 69 64 65 64 20 74 6f nal, provided to
10f0: 20 78 50 6f 73 74 45 76 61 6c 28 29 2e 20 2a 2f xPostEval(). */
1100: 0a 7d 3b 0a 23 65 6e 64 69 66 0a 0a 73 74 72 75 .};.#endif..stru
1110: 63 74 20 47 6c 6f 62 61 6c 20 7b 0a 20 20 69 6e ct Global {. in
1120: 74 20 61 72 67 63 3b 20 63 68 61 72 20 2a 2a 61 t argc; char **a
1130: 72 67 76 3b 20 20 2f 2a 20 43 6f 6d 6d 61 6e 64 rgv; /* Command
1140: 2d 6c 69 6e 65 20 61 72 67 75 6d 65 6e 74 73 20 -line arguments
1150: 74 6f 20 74 68 65 20 70 72 6f 67 72 61 6d 20 2a to the program *
1160: 2f 0a 20 20 63 68 61 72 20 2a 6e 61 6d 65 4f 66 /. char *nameOf
1170: 45 78 65 3b 20 20 20 20 20 20 20 20 2f 2a 20 46 Exe; /* F
1180: 75 6c 6c 20 70 61 74 68 20 6f 66 20 65 78 65 63 ull path of exec
1190: 75 74 61 62 6c 65 2e 20 2a 2f 0a 20 20 63 6f 6e utable. */. con
11a0: 73 74 20 63 68 61 72 20 2a 7a 45 72 72 6c 6f 67 st char *zErrlog
11b0: 3b 20 20 20 20 2f 2a 20 4c 6f 67 20 65 72 72 6f ; /* Log erro
11c0: 72 73 20 74 6f 20 74 68 69 73 20 66 69 6c 65 2c rs to this file,
11d0: 20 69 66 20 6e 6f 74 20 4e 55 4c 4c 20 2a 2f 0a if not NULL */.
11e0: 20 20 69 6e 74 20 69 73 43 6f 6e 73 74 3b 20 20 int isConst;
11f0: 20 20 20 20 20 20 20 20 20 20 2f 2a 20 54 72 75 /* Tru
1200: 65 20 69 66 20 74 68 65 20 6f 75 74 70 75 74 20 e if the output
1210: 69 73 20 75 6e 63 68 61 6e 67 69 6e 67 20 26 20 is unchanging &
1220: 63 61 63 68 65 61 62 6c 65 20 2a 2f 0a 20 20 63 cacheable */. c
1230: 6f 6e 73 74 20 63 68 61 72 20 2a 7a 56 66 73 4e onst char *zVfsN
1240: 61 6d 65 3b 20 20 20 2f 2a 20 54 68 65 20 56 46 ame; /* The VF
1250: 53 20 74 6f 20 75 73 65 20 66 6f 72 20 64 61 74 S to use for dat
1260: 61 62 61 73 65 20 63 6f 6e 6e 65 63 74 69 6f 6e abase connection
1270: 73 20 2a 2f 0a 20 20 73 71 6c 69 74 65 33 20 2a s */. sqlite3 *
1280: 64 62 3b 20 20 20 20 20 20 20 20 20 20 20 20 2f db; /
1290: 2a 20 54 68 65 20 63 6f 6e 6e 65 63 74 69 6f 6e * The connection
12a0: 20 74 6f 20 74 68 65 20 64 61 74 61 62 61 73 65 to the database
12b0: 73 20 2a 2f 0a 20 20 73 71 6c 69 74 65 33 20 2a s */. sqlite3 *
12c0: 64 62 43 6f 6e 66 69 67 3b 20 20 20 20 20 20 2f dbConfig; /
12d0: 2a 20 53 65 70 61 72 61 74 65 20 63 6f 6e 6e 65 * Separate conne
12e0: 63 74 69 6f 6e 20 66 6f 72 20 67 6c 6f 62 61 6c ction for global
12f0: 5f 63 6f 6e 66 69 67 20 74 61 62 6c 65 20 2a 2f _config table */
1300: 0a 20 20 63 68 61 72 20 2a 7a 41 75 78 53 63 68 . char *zAuxSch
1310: 65 6d 61 3b 20 20 20 20 20 20 20 2f 2a 20 4d 61 ema; /* Ma
1320: 69 6e 20 72 65 70 6f 73 69 74 6f 72 79 20 61 75 in repository au
1330: 78 2d 73 63 68 65 6d 61 20 2a 2f 0a 20 20 69 6e x-schema */. in
1340: 74 20 75 73 65 41 74 74 61 63 68 3b 20 20 20 20 t useAttach;
1350: 20 20 20 20 20 20 2f 2a 20 54 72 75 65 20 69 66 /* True if
1360: 20 67 6c 6f 62 61 6c 5f 63 6f 6e 66 69 67 20 69 global_config i
1370: 73 20 61 74 74 61 63 68 65 64 20 74 6f 20 72 65 s attached to re
1380: 70 6f 73 69 74 6f 72 79 20 2a 2f 0a 20 20 63 6f pository */. co
1390: 6e 73 74 20 63 68 61 72 20 2a 7a 43 6f 6e 66 69 nst char *zConfi
13a0: 67 44 62 4e 61 6d 65 3b 2f 2a 20 50 61 74 68 20 gDbName;/* Path
13b0: 6f 66 20 74 68 65 20 63 6f 6e 66 69 67 20 64 61 of the config da
13c0: 74 61 62 61 73 65 2e 20 4e 55 4c 4c 20 69 66 20 tabase. NULL if
13d0: 6e 6f 74 20 6f 70 65 6e 20 2a 2f 0a 20 20 73 71 not open */. sq
13e0: 6c 69 74 65 33 5f 69 6e 74 36 34 20 6e 6f 77 3b lite3_int64 now;
13f0: 20 20 20 20 20 20 2f 2a 20 53 65 63 6f 6e 64 73 /* Seconds
1400: 20 73 69 6e 63 65 20 31 39 37 30 20 2a 2f 0a 20 since 1970 */.
1410: 20 69 6e 74 20 72 65 70 6f 73 69 74 6f 72 79 4f int repositoryO
1420: 70 65 6e 3b 20 20 20 20 20 2f 2a 20 54 72 75 65 pen; /* True
1430: 20 69 66 20 74 68 65 20 6d 61 69 6e 20 72 65 70 if the main rep
1440: 6f 73 69 74 6f 72 79 20 64 61 74 61 62 61 73 65 ository database
1450: 20 69 73 20 6f 70 65 6e 20 2a 2f 0a 20 20 63 68 is open */. ch
1460: 61 72 20 2a 7a 52 65 70 6f 73 69 74 6f 72 79 4f ar *zRepositoryO
1470: 70 74 69 6f 6e 3b 20 2f 2a 20 4d 6f 73 74 20 72 ption; /* Most r
1480: 65 63 65 6e 74 20 63 61 63 68 65 64 20 72 65 70 ecent cached rep
1490: 6f 73 69 74 6f 72 79 20 6f 70 74 69 6f 6e 20 76 ository option v
14a0: 61 6c 75 65 20 2a 2f 0a 20 20 63 68 61 72 20 2a alue */. char *
14b0: 7a 52 65 70 6f 73 69 74 6f 72 79 4e 61 6d 65 3b zRepositoryName;
14c0: 20 20 2f 2a 20 4e 61 6d 65 20 6f 66 20 74 68 65 /* Name of the
14d0: 20 72 65 70 6f 73 69 74 6f 72 79 20 64 61 74 61 repository data
14e0: 62 61 73 65 20 2a 2f 0a 20 20 63 68 61 72 20 2a base */. char *
14f0: 7a 4c 6f 63 61 6c 44 62 4e 61 6d 65 3b 20 20 20 zLocalDbName;
1500: 20 20 2f 2a 20 4e 61 6d 65 20 6f 66 20 74 68 65 /* Name of the
1510: 20 6c 6f 63 61 6c 20 64 61 74 61 62 61 73 65 20 local database
1520: 2a 2f 0a 20 20 63 6f 6e 73 74 20 63 68 61 72 20 */. const char
1530: 2a 7a 4d 61 69 6e 44 62 54 79 70 65 3b 2f 2a 20 *zMainDbType;/*
1540: 22 63 6f 6e 66 69 67 64 62 22 2c 20 22 6c 6f 63 "configdb", "loc
1550: 61 6c 64 62 22 2c 20 6f 72 20 22 72 65 70 6f 73 aldb", or "repos
1560: 69 74 6f 72 79 22 20 2a 2f 0a 20 20 63 6f 6e 73 itory" */. cons
1570: 74 20 63 68 61 72 20 2a 7a 43 6f 6e 66 69 67 44 t char *zConfigD
1580: 62 54 79 70 65 3b 20 20 2f 2a 20 22 63 6f 6e 66 bType; /* "conf
1590: 69 67 64 62 22 2c 20 22 6c 6f 63 61 6c 64 62 22 igdb", "localdb"
15a0: 2c 20 6f 72 20 22 72 65 70 6f 73 69 74 6f 72 79 , or "repository
15b0: 22 20 2a 2f 0a 20 20 63 68 61 72 20 2a 7a 4f 70 " */. char *zOp
15c0: 65 6e 52 65 76 69 73 69 6f 6e 3b 20 20 20 20 2f enRevision; /
15d0: 2a 20 43 68 65 63 6b 2d 69 6e 20 76 65 72 73 69 * Check-in versi
15e0: 6f 6e 20 74 6f 20 75 73 65 20 64 75 72 69 6e 67 on to use during
15f0: 20 64 61 74 61 62 61 73 65 20 6f 70 65 6e 20 2a database open *
1600: 2f 0a 20 20 69 6e 74 20 6c 6f 63 61 6c 4f 70 65 /. int localOpe
1610: 6e 3b 20 20 20 20 20 20 20 20 20 20 2f 2a 20 54 n; /* T
1620: 72 75 65 20 69 66 20 74 68 65 20 6c 6f 63 61 6c rue if the local
1630: 20 64 61 74 61 62 61 73 65 20 69 73 20 6f 70 65 database is ope
1640: 6e 20 2a 2f 0a 20 20 63 68 61 72 20 2a 7a 4c 6f n */. char *zLo
1650: 63 61 6c 52 6f 6f 74 3b 20 20 20 20 20 20 20 2f calRoot; /
1660: 2a 20 54 68 65 20 64 69 72 65 63 74 6f 72 79 20 * The directory
1670: 68 6f 6c 64 69 6e 67 20 74 68 65 20 20 6c 6f 63 holding the loc
1680: 61 6c 20 64 61 74 61 62 61 73 65 20 2a 2f 0a 20 al database */.
1690: 20 69 6e 74 20 6d 69 6e 50 72 65 66 69 78 3b 20 int minPrefix;
16a0: 20 20 20 20 20 20 20 20 20 2f 2a 20 4e 75 6d 62 /* Numb
16b0: 65 72 20 6f 66 20 64 69 67 69 74 73 20 6e 65 65 er of digits nee
16c0: 64 65 64 20 66 6f 72 20 61 20 64 69 73 74 69 6e ded for a distin
16d0: 63 74 20 55 55 49 44 20 2a 2f 0a 20 20 69 6e 74 ct UUID */. int
16e0: 20 66 53 71 6c 54 72 61 63 65 3b 20 20 20 20 20 fSqlTrace;
16f0: 20 20 20 20 20 2f 2a 20 54 72 75 65 20 69 66 20 /* True if
1700: 2d 2d 73 71 6c 74 72 61 63 65 20 66 6c 61 67 20 --sqltrace flag
1710: 69 73 20 70 72 65 73 65 6e 74 20 2a 2f 0a 20 20 is present */.
1720: 69 6e 74 20 66 53 71 6c 53 74 61 74 73 3b 20 20 int fSqlStats;
1730: 20 20 20 20 20 20 20 20 2f 2a 20 54 72 75 65 20 /* True
1740: 69 66 20 2d 2d 73 71 6c 74 72 61 63 65 20 6f 72 if --sqltrace or
1750: 20 2d 2d 73 71 6c 73 74 61 74 73 20 61 72 65 20 --sqlstats are
1760: 70 72 65 73 65 6e 74 20 2a 2f 0a 20 20 69 6e 74 present */. int
1770: 20 66 53 71 6c 50 72 69 6e 74 3b 20 20 20 20 20 fSqlPrint;
1780: 20 20 20 20 20 2f 2a 20 54 72 75 65 20 69 66 20 /* True if
1790: 2d 73 71 6c 70 72 69 6e 74 20 66 6c 61 67 20 69 -sqlprint flag i
17a0: 73 20 70 72 65 73 65 6e 74 20 2a 2f 0a 20 20 69 s present */. i
17b0: 6e 74 20 66 51 75 69 65 74 3b 20 20 20 20 20 20 nt fQuiet;
17c0: 20 20 20 20 20 20 20 2f 2a 20 54 72 75 65 20 69 /* True i
17d0: 66 20 2d 71 75 69 65 74 20 66 6c 61 67 20 69 73 f -quiet flag is
17e0: 20 70 72 65 73 65 6e 74 20 2a 2f 0a 20 20 69 6e present */. in
17f0: 74 20 66 48 74 74 70 54 72 61 63 65 3b 20 20 20 t fHttpTrace;
1800: 20 20 20 20 20 20 2f 2a 20 54 72 61 63 65 20 6f /* Trace o
1810: 75 74 62 6f 75 6e 64 20 48 54 54 50 20 72 65 71 utbound HTTP req
1820: 75 65 73 74 73 20 2a 2f 0a 20 20 69 6e 74 20 66 uests */. int f
1830: 41 6e 79 54 72 61 63 65 3b 20 20 20 20 20 20 20 AnyTrace;
1840: 20 20 20 2f 2a 20 41 6e 79 20 6b 69 6e 64 20 6f /* Any kind o
1850: 66 20 74 72 61 63 69 6e 67 20 2a 2f 0a 20 20 63 f tracing */. c
1860: 68 61 72 20 2a 7a 48 74 74 70 41 75 74 68 3b 20 har *zHttpAuth;
1870: 20 20 20 20 20 20 20 2f 2a 20 48 54 54 50 20 41 /* HTTP A
1880: 75 74 68 6f 72 69 7a 61 74 69 6f 6e 20 75 73 65 uthorization use
1890: 72 3a 70 61 73 73 20 69 6e 66 6f 72 6d 61 74 69 r:pass informati
18a0: 6f 6e 20 2a 2f 0a 20 20 69 6e 74 20 66 53 79 73 on */. int fSys
18b0: 74 65 6d 54 72 61 63 65 3b 20 20 20 20 20 20 20 temTrace;
18c0: 2f 2a 20 54 72 61 63 65 20 63 61 6c 6c 73 20 74 /* Trace calls t
18d0: 6f 20 66 6f 73 73 69 6c 5f 73 79 73 74 65 6d 28 o fossil_system(
18e0: 29 2c 20 2d 2d 73 79 73 74 65 6d 74 72 61 63 65 ), --systemtrace
18f0: 20 2a 2f 0a 20 20 69 6e 74 20 66 53 73 68 54 72 */. int fSshTr
1900: 61 63 65 3b 20 20 20 20 20 20 20 20 20 20 2f 2a ace; /*
1910: 20 54 72 61 63 65 20 74 68 65 20 53 53 48 20 73 Trace the SSH s
1920: 65 74 75 70 20 74 72 61 66 66 69 63 20 2a 2f 0a etup traffic */.
1930: 20 20 69 6e 74 20 66 53 73 68 43 6c 69 65 6e 74 int fSshClient
1940: 3b 20 20 20 20 20 20 20 20 20 2f 2a 20 48 54 54 ; /* HTT
1950: 50 20 63 6c 69 65 6e 74 20 66 6c 61 67 73 20 66 P client flags f
1960: 6f 72 20 53 53 48 20 63 6c 69 65 6e 74 20 2a 2f or SSH client */
1970: 0a 20 20 63 68 61 72 20 2a 7a 53 73 68 43 6d 64 . char *zSshCmd
1980: 3b 20 20 20 20 20 20 20 20 20 20 2f 2a 20 53 53 ; /* SS
1990: 48 20 63 6f 6d 6d 61 6e 64 20 73 74 72 69 6e 67 H command string
19a0: 20 2a 2f 0a 20 20 69 6e 74 20 66 4e 6f 53 79 6e */. int fNoSyn
19b0: 63 3b 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a c; /*
19c0: 20 44 6f 20 6e 6f 74 20 64 6f 20 61 6e 20 61 75 Do not do an au
19d0: 74 6f 73 79 6e 63 20 65 76 65 72 2e 20 20 2d 2d tosync ever. --
19e0: 6e 6f 73 79 6e 63 20 2a 2f 0a 20 20 69 6e 74 20 nosync */. int
19f0: 66 49 50 76 34 3b 20 20 20 20 20 20 20 20 20 20 fIPv4;
1a00: 20 20 20 20 2f 2a 20 55 73 65 20 6f 6e 6c 79 20 /* Use only
1a10: 49 50 76 34 2c 20 6e 6f 74 20 49 50 76 36 2e 20 IPv4, not IPv6.
1a20: 2d 2d 69 70 76 34 20 2a 2f 0a 20 20 63 68 61 72 --ipv4 */. char
1a30: 20 2a 7a 50 61 74 68 3b 20 20 20 20 20 20 20 20 *zPath;
1a40: 20 20 20 20 2f 2a 20 4e 61 6d 65 20 6f 66 20 77 /* Name of w
1a50: 65 62 70 61 67 65 20 62 65 69 6e 67 20 73 65 72 ebpage being ser
1a60: 76 65 64 20 2a 2f 0a 20 20 63 68 61 72 20 2a 7a ved */. char *z
1a70: 45 78 74 72 61 3b 20 20 20 20 20 20 20 20 20 20 Extra;
1a80: 20 2f 2a 20 45 78 74 72 61 20 70 61 74 68 20 69 /* Extra path i
1a90: 6e 66 6f 72 6d 61 74 69 6f 6e 20 70 61 73 74 20 nformation past
1aa0: 74 68 65 20 77 65 62 70 61 67 65 20 6e 61 6d 65 the webpage name
1ab0: 20 2a 2f 0a 20 20 63 68 61 72 20 2a 7a 42 61 73 */. char *zBas
1ac0: 65 55 52 4c 3b 20 20 20 20 20 20 20 20 20 2f 2a eURL; /*
1ad0: 20 46 75 6c 6c 20 74 65 78 74 20 6f 66 20 74 68 Full text of th
1ae0: 65 20 55 52 4c 20 62 65 69 6e 67 20 73 65 72 76 e URL being serv
1af0: 65 64 20 2a 2f 0a 20 20 63 68 61 72 20 2a 7a 48 ed */. char *zH
1b00: 74 74 70 73 55 52 4c 3b 20 20 20 20 20 20 20 20 ttpsURL;
1b10: 2f 2a 20 7a 42 61 73 65 55 52 4c 20 74 72 61 6e /* zBaseURL tran
1b20: 73 6c 61 74 65 64 20 74 6f 20 68 74 74 70 73 3a slated to https:
1b30: 20 2a 2f 0a 20 20 63 68 61 72 20 2a 7a 54 6f 70 */. char *zTop
1b40: 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a ; /*
1b50: 20 50 61 72 65 6e 74 20 64 69 72 65 63 74 6f 72 Parent director
1b60: 79 20 6f 66 20 7a 50 61 74 68 20 2a 2f 0a 20 20 y of zPath */.
1b70: 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a 43 6f 6e const char *zCon
1b80: 74 65 6e 74 54 79 70 65 3b 20 20 2f 2a 20 54 68 tentType; /* Th
1b90: 65 20 63 6f 6e 74 65 6e 74 20 74 79 70 65 20 6f e content type o
1ba0: 66 20 74 68 65 20 69 6e 70 75 74 20 48 54 54 50 f the input HTTP
1bb0: 20 72 65 71 75 65 73 74 20 2a 2f 0a 20 20 69 6e request */. in
1bc0: 74 20 69 45 72 72 50 72 69 6f 72 69 74 79 3b 20 t iErrPriority;
1bd0: 20 20 20 20 20 20 2f 2a 20 50 72 69 6f 72 69 74 /* Priorit
1be0: 79 20 6f 66 20 63 75 72 72 65 6e 74 20 65 72 72 y of current err
1bf0: 6f 72 20 6d 65 73 73 61 67 65 20 2a 2f 0a 20 20 or message */.
1c00: 63 68 61 72 20 2a 7a 45 72 72 4d 73 67 3b 20 20 char *zErrMsg;
1c10: 20 20 20 20 20 20 20 20 2f 2a 20 54 65 78 74 20 /* Text
1c20: 6f 66 20 61 6e 20 65 72 72 6f 72 20 6d 65 73 73 of an error mess
1c30: 61 67 65 20 2a 2f 0a 20 20 69 6e 74 20 73 73 6c age */. int ssl
1c40: 4e 6f 74 41 76 61 69 6c 61 62 6c 65 3b 20 20 20 NotAvailable;
1c50: 20 2f 2a 20 53 53 4c 20 69 73 20 6e 6f 74 20 61 /* SSL is not a
1c60: 76 61 69 6c 61 62 6c 65 2e 20 20 44 6f 20 6e 6f vailable. Do no
1c70: 74 20 72 65 64 69 72 65 63 74 20 74 6f 20 68 74 t redirect to ht
1c80: 74 70 73 3a 20 2a 2f 0a 20 20 42 6c 6f 62 20 63 tps: */. Blob c
1c90: 67 69 49 6e 3b 20 20 20 20 20 20 20 20 20 20 20 giIn;
1ca0: 20 20 2f 2a 20 49 6e 70 75 74 20 74 6f 20 61 6e /* Input to an
1cb0: 20 78 66 65 72 20 77 77 77 20 6d 65 74 68 6f 64 xfer www method
1cc0: 20 2a 2f 0a 20 20 69 6e 74 20 63 67 69 4f 75 74 */. int cgiOut
1cd0: 70 75 74 3b 20 20 20 20 20 20 20 20 20 20 2f 2a put; /*
1ce0: 20 57 72 69 74 65 20 65 72 72 6f 72 20 61 6e 64 Write error and
1cf0: 20 73 74 61 74 75 73 20 6d 65 73 73 61 67 65 73 status messages
1d00: 20 74 6f 20 43 47 49 20 2a 2f 0a 20 20 69 6e 74 to CGI */. int
1d10: 20 78 66 65 72 50 61 6e 69 63 3b 20 20 20 20 20 xferPanic;
1d20: 20 20 20 20 20 2f 2a 20 57 72 69 74 65 20 65 72 /* Write er
1d30: 72 6f 72 20 6d 65 73 73 61 67 65 73 20 69 6e 20 ror messages in
1d40: 58 46 45 52 20 70 72 6f 74 6f 63 6f 6c 20 2a 2f XFER protocol */
1d50: 0a 20 20 69 6e 74 20 66 75 6c 6c 48 74 74 70 52 . int fullHttpR
1d60: 65 70 6c 79 3b 20 20 20 20 20 20 2f 2a 20 54 72 eply; /* Tr
1d70: 75 65 20 66 6f 72 20 66 75 6c 6c 20 48 54 54 50 ue for full HTTP
1d80: 20 72 65 70 6c 79 2e 20 20 46 61 6c 73 65 20 66 reply. False f
1d90: 6f 72 20 43 47 49 20 72 65 70 6c 79 20 2a 2f 0a or CGI reply */.
1da0: 20 20 54 68 5f 49 6e 74 65 72 70 20 2a 69 6e 74 Th_Interp *int
1db0: 65 72 70 3b 20 20 20 20 20 20 2f 2a 20 54 68 65 erp; /* The
1dc0: 20 54 48 31 20 69 6e 74 65 72 70 72 65 74 65 72 TH1 interpreter
1dd0: 20 2a 2f 0a 20 20 63 68 61 72 20 2a 74 68 31 53 */. char *th1S
1de0: 65 74 75 70 3b 20 20 20 20 20 20 20 20 20 2f 2a etup; /*
1df0: 20 54 68 65 20 54 48 31 20 70 6f 73 74 2d 63 72 The TH1 post-cr
1e00: 65 61 74 69 6f 6e 20 73 65 74 75 70 20 73 63 72 eation setup scr
1e10: 69 70 74 2c 20 69 66 20 61 6e 79 20 2a 2f 0a 20 ipt, if any */.
1e20: 20 69 6e 74 20 74 68 31 46 6c 61 67 73 3b 20 20 int th1Flags;
1e30: 20 20 20 20 20 20 20 20 20 2f 2a 20 54 68 65 20 /* The
1e40: 54 48 31 20 69 6e 74 65 67 72 61 74 69 6f 6e 20 TH1 integration
1e50: 73 74 61 74 65 20 66 6c 61 67 73 20 2a 2f 0a 20 state flags */.
1e60: 20 46 49 4c 45 20 2a 68 74 74 70 49 6e 3b 20 20 FILE *httpIn;
1e70: 20 20 20 20 20 20 20 20 20 2f 2a 20 41 63 63 65 /* Acce
1e80: 70 74 20 48 54 54 50 20 69 6e 70 75 74 20 66 72 pt HTTP input fr
1e90: 6f 6d 20 68 65 72 65 20 2a 2f 0a 20 20 46 49 4c om here */. FIL
1ea0: 45 20 2a 68 74 74 70 4f 75 74 3b 20 20 20 20 20 E *httpOut;
1eb0: 20 20 20 20 20 2f 2a 20 53 65 6e 64 20 48 54 54 /* Send HTT
1ec0: 50 20 6f 75 74 70 75 74 20 68 65 72 65 20 2a 2f P output here */
1ed0: 0a 20 20 69 6e 74 20 78 6c 69 6e 6b 43 6c 75 73 . int xlinkClus
1ee0: 74 65 72 4f 6e 6c 79 3b 20 20 20 2f 2a 20 53 65 terOnly; /* Se
1ef0: 74 20 77 68 65 6e 20 63 6c 6f 6e 69 6e 67 2e 20 t when cloning.
1f00: 20 4f 6e 6c 79 20 70 72 6f 63 65 73 73 20 63 6c Only process cl
1f10: 75 73 74 65 72 73 20 2a 2f 0a 20 20 69 6e 74 20 usters */. int
1f20: 66 54 69 6d 65 46 6f 72 6d 61 74 3b 20 20 20 20 fTimeFormat;
1f30: 20 20 20 20 2f 2a 20 31 20 66 6f 72 20 55 54 43 /* 1 for UTC
1f40: 2e 20 20 32 20 66 6f 72 20 6c 6f 63 61 6c 74 69 . 2 for localti
1f50: 6d 65 2e 20 20 30 20 6e 6f 74 20 79 65 74 20 73 me. 0 not yet s
1f60: 65 6c 65 63 74 65 64 20 2a 2f 0a 20 20 69 6e 74 elected */. int
1f70: 20 2a 61 43 6f 6d 6d 69 74 46 69 6c 65 3b 20 20 *aCommitFile;
1f80: 20 20 20 20 20 2f 2a 20 41 72 72 61 79 20 6f 66 /* Array of
1f90: 20 66 69 6c 65 73 20 74 6f 20 62 65 20 63 6f 6d files to be com
1fa0: 6d 69 74 74 65 64 20 2a 2f 0a 20 20 69 6e 74 20 mitted */. int
1fb0: 6d 61 72 6b 50 72 69 76 61 74 65 3b 20 20 20 20 markPrivate;
1fc0: 20 20 20 20 2f 2a 20 41 6c 6c 20 6e 65 77 20 61 /* All new a
1fd0: 72 74 69 66 61 63 74 73 20 61 72 65 20 70 72 69 rtifacts are pri
1fe0: 76 61 74 65 20 69 66 20 74 72 75 65 20 2a 2f 0a vate if true */.
1ff0: 20 20 69 6e 74 20 63 6c 6f 63 6b 53 6b 65 77 53 int clockSkewS
2000: 65 65 6e 3b 20 20 20 20 20 20 2f 2a 20 54 72 75 een; /* Tru
2010: 65 20 69 66 20 63 6c 6f 63 6b 73 20 6f 6e 20 63 e if clocks on c
2020: 6c 69 65 6e 74 20 61 6e 64 20 73 65 72 76 65 72 lient and server
2030: 20 6f 75 74 20 6f 66 20 73 79 6e 63 20 2a 2f 0a out of sync */.
2040: 20 20 69 6e 74 20 77 69 6b 69 46 6c 61 67 73 3b int wikiFlags;
2050: 20 20 20 20 20 20 20 20 20 20 2f 2a 20 57 69 6b /* Wik
2060: 69 20 63 6f 6e 76 65 72 73 69 6f 6e 20 66 6c 61 i conversion fla
2070: 67 73 20 61 70 70 6c 69 65 64 20 74 6f 20 25 57 gs applied to %W
2080: 20 2a 2f 0a 20 20 63 68 61 72 20 69 73 48 54 54 */. char isHTT
2090: 50 3b 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a P; /*
20a0: 20 54 72 75 65 20 69 66 20 73 65 72 76 65 72 2f True if server/
20b0: 43 47 49 20 6d 6f 64 65 73 2c 20 65 6c 73 65 20 CGI modes, else
20c0: 61 73 73 75 6d 65 20 43 4c 49 2e 20 2a 2f 0a 20 assume CLI. */.
20d0: 20 63 68 61 72 20 6a 61 76 61 73 63 72 69 70 74 char javascript
20e0: 48 79 70 65 72 6c 69 6e 6b 3b 20 2f 2a 20 49 66 Hyperlink; /* If
20f0: 20 74 72 75 65 2c 20 73 65 74 20 68 72 65 66 3d true, set href=
2100: 20 75 73 69 6e 67 20 73 63 72 69 70 74 2c 20 6e using script, n
2110: 6f 74 20 48 54 4d 4c 20 2a 2f 0a 20 20 42 6c 6f ot HTML */. Blo
2120: 62 20 68 74 74 70 48 65 61 64 65 72 3b 20 20 20 b httpHeader;
2130: 20 20 20 20 20 2f 2a 20 43 6f 6d 70 6c 65 74 65 /* Complete
2140: 20 74 65 78 74 20 6f 66 20 74 68 65 20 48 54 54 text of the HTT
2150: 50 20 72 65 71 75 65 73 74 20 68 65 61 64 65 72 P request header
2160: 20 2a 2f 0a 20 20 55 72 6c 44 61 74 61 20 75 72 */. UrlData ur
2170: 6c 3b 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a l; /*
2180: 20 49 6e 66 6f 72 6d 61 74 69 6f 6e 20 61 62 6f Information abo
2190: 75 74 20 63 75 72 72 65 6e 74 20 55 52 4c 20 2a ut current URL *
21a0: 2f 0a 20 20 63 6f 6e 73 74 20 63 68 61 72 20 2a /. const char *
21b0: 7a 4c 6f 67 69 6e 3b 20 20 20 20 20 2f 2a 20 4c zLogin; /* L
21c0: 6f 67 69 6e 20 6e 61 6d 65 2e 20 20 4e 55 4c 4c ogin name. NULL
21d0: 20 6f 72 20 22 22 20 69 66 20 6e 6f 74 20 6c 6f or "" if not lo
21e0: 67 67 65 64 20 69 6e 2e 20 2a 2f 0a 20 20 63 6f gged in. */. co
21f0: 6e 73 74 20 63 68 61 72 20 2a 7a 53 53 4c 49 64 nst char *zSSLId
2200: 65 6e 74 69 74 79 3b 20 20 2f 2a 20 56 61 6c 75 entity; /* Valu
2210: 65 20 6f 66 20 2d 2d 73 73 6c 2d 69 64 65 6e 74 e of --ssl-ident
2220: 69 74 79 20 6f 70 74 69 6f 6e 2c 20 66 69 6c 65 ity option, file
2230: 6e 61 6d 65 20 6f 66 0a 20 20 20 20 20 20 20 20 name of.
2240: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
2250: 20 20 20 20 20 2a 2a 20 53 53 4c 20 63 6c 69 65 ** SSL clie
2260: 6e 74 20 69 64 65 6e 74 69 74 79 20 2a 2f 0a 20 nt identity */.
2270: 20 69 6e 74 20 75 73 65 4c 6f 63 61 6c 61 75 74 int useLocalaut
2280: 68 3b 20 20 20 20 20 20 20 2f 2a 20 4e 6f 20 6c h; /* No l
2290: 6f 67 69 6e 20 72 65 71 75 69 72 65 64 20 69 66 ogin required if
22a0: 20 66 72 6f 6d 20 31 32 37 2e 30 2e 30 2e 31 20 from 127.0.0.1
22b0: 2a 2f 0a 20 20 69 6e 74 20 6e 6f 50 73 77 64 3b */. int noPswd;
22c0: 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 /*
22d0: 4c 6f 67 67 65 64 20 69 6e 20 77 69 74 68 6f 75 Logged in withou
22e0: 74 20 70 61 73 73 77 6f 72 64 20 28 6f 6e 20 31 t password (on 1
22f0: 32 37 2e 30 2e 30 2e 31 29 20 2a 2f 0a 20 20 69 27.0.0.1) */. i
2300: 6e 74 20 75 73 65 72 55 69 64 3b 20 20 20 20 20 nt userUid;
2310: 20 20 20 20 20 20 20 2f 2a 20 49 6e 74 65 67 65 /* Intege
2320: 72 20 75 73 65 72 20 69 64 20 2a 2f 0a 20 20 69 r user id */. i
2330: 6e 74 20 69 73 48 75 6d 61 6e 3b 20 20 20 20 20 nt isHuman;
2340: 20 20 20 20 20 20 20 2f 2a 20 54 72 75 65 20 69 /* True i
2350: 66 20 61 63 63 65 73 73 20 62 79 20 61 20 68 75 f access by a hu
2360: 6d 61 6e 2c 20 6e 6f 74 20 61 20 73 70 69 64 65 man, not a spide
2370: 72 20 6f 72 20 62 6f 74 20 2a 2f 0a 20 20 69 6e r or bot */. in
2380: 74 20 63 6f 6d 46 6d 74 46 6c 61 67 73 3b 20 20 t comFmtFlags;
2390: 20 20 20 20 20 20 2f 2a 20 5a 65 72 6f 20 6f 72 /* Zero or
23a0: 20 6d 6f 72 65 20 22 43 4f 4d 4d 45 4e 54 5f 50 more "COMMENT_P
23b0: 52 49 4e 54 5f 2a 22 20 62 69 74 20 66 6c 61 67 RINT_*" bit flag
23c0: 73 20 2a 2f 0a 0a 20 20 2f 2a 20 49 6e 66 6f 72 s */.. /* Infor
23d0: 6d 61 74 69 6f 6e 20 75 73 65 64 20 74 6f 20 70 mation used to p
23e0: 6f 70 75 6c 61 74 65 20 74 68 65 20 52 43 56 46 opulate the RCVF
23f0: 52 4f 4d 20 74 61 62 6c 65 20 2a 2f 0a 20 20 69 ROM table */. i
2400: 6e 74 20 72 63 76 69 64 3b 20 20 20 20 20 20 20 nt rcvid;
2410: 20 20 20 20 20 20 20 2f 2a 20 54 68 65 20 72 63 /* The rc
2420: 76 69 64 2e 20 20 30 20 69 66 20 6e 6f 74 20 79 vid. 0 if not y
2430: 65 74 20 64 65 66 69 6e 65 64 2e 20 2a 2f 0a 20 et defined. */.
2440: 20 63 68 61 72 20 2a 7a 49 70 41 64 64 72 3b 20 char *zIpAddr;
2450: 20 20 20 20 20 20 20 20 20 2f 2a 20 54 68 65 20 /* The
2460: 72 65 6d 6f 74 65 20 49 50 20 61 64 64 72 65 73 remote IP addres
2470: 73 20 2a 2f 0a 20 20 63 68 61 72 20 2a 7a 4e 6f s */. char *zNo
2480: 6e 63 65 3b 20 20 20 20 20 20 20 20 20 20 20 2f nce; /
2490: 2a 20 54 68 65 20 6e 6f 6e 63 65 20 75 73 65 64 * The nonce used
24a0: 20 66 6f 72 20 6c 6f 67 69 6e 20 2a 2f 0a 0a 20 for login */..
24b0: 20 2f 2a 20 70 65 72 6d 69 73 73 69 6f 6e 73 20 /* permissions
24c0: 61 76 61 69 6c 61 62 6c 65 20 74 6f 20 63 75 72 available to cur
24d0: 72 65 6e 74 20 75 73 65 72 20 2a 2f 0a 20 20 73 rent user */. s
24e0: 74 72 75 63 74 20 46 6f 73 73 69 6c 55 73 65 72 truct FossilUser
24f0: 50 65 72 6d 73 20 70 65 72 6d 3b 0a 0a 20 20 2f Perms perm;.. /
2500: 2a 20 70 65 72 6d 69 73 73 69 6f 6e 73 20 61 76 * permissions av
2510: 61 69 6c 61 62 6c 65 20 74 6f 20 63 75 72 72 65 ailable to curre
2520: 6e 74 20 75 73 65 72 20 6f 72 20 74 6f 20 22 61 nt user or to "a
2530: 6e 6f 6e 79 6d 6f 75 73 22 2e 0a 20 20 2a 2a 20 nonymous".. **
2540: 54 68 69 73 20 69 73 20 74 68 65 20 6c 6f 67 69 This is the logi
2550: 63 61 6c 20 75 6e 69 6f 6e 20 6f 66 20 70 65 72 cal union of per
2560: 6d 20 70 65 72 6d 69 73 73 69 6f 6e 73 20 61 62 m permissions ab
2570: 6f 76 65 20 77 69 74 68 0a 20 20 2a 2a 20 74 68 ove with. ** th
2580: 65 20 76 61 6c 75 65 20 74 68 61 74 20 70 65 72 e value that per
2590: 6d 20 77 6f 75 6c 64 20 74 61 6b 65 20 69 66 20 m would take if
25a0: 67 2e 7a 4c 6f 67 69 6e 20 77 65 72 65 20 22 61 g.zLogin were "a
25b0: 6e 6f 6e 79 6d 6f 75 73 22 2e 20 2a 2f 0a 20 20 nonymous". */.
25c0: 73 74 72 75 63 74 20 46 6f 73 73 69 6c 55 73 65 struct FossilUse
25d0: 72 50 65 72 6d 73 20 61 6e 6f 6e 3b 0a 0a 23 69 rPerms anon;..#i
25e0: 66 64 65 66 20 46 4f 53 53 49 4c 5f 45 4e 41 42 fdef FOSSIL_ENAB
25f0: 4c 45 5f 54 43 4c 0a 20 20 2f 2a 20 61 6c 6c 20 LE_TCL. /* all
2600: 54 63 6c 20 72 65 6c 61 74 65 64 20 63 6f 6e 74 Tcl related cont
2610: 65 78 74 20 6e 65 63 65 73 73 61 72 79 20 66 6f ext necessary fo
2620: 72 20 69 6e 74 65 67 72 61 74 69 6f 6e 20 2a 2f r integration */
2630: 0a 20 20 73 74 72 75 63 74 20 54 63 6c 43 6f 6e . struct TclCon
2640: 74 65 78 74 20 74 63 6c 3b 0a 23 65 6e 64 69 66 text tcl;.#endif
2650: 0a 0a 20 20 2f 2a 20 46 6f 72 20 64 65 66 65 6e .. /* For defen
2660: 73 65 20 61 67 61 69 6e 73 74 20 43 72 6f 73 73 se against Cross
2670: 2d 73 69 74 65 20 52 65 71 75 65 73 74 20 46 6f -site Request Fo
2680: 72 67 65 72 79 20 61 74 74 61 63 6b 73 20 2a 2f rgery attacks */
2690: 0a 20 20 63 68 61 72 20 7a 43 73 72 66 54 6f 6b . char zCsrfTok
26a0: 65 6e 5b 31 32 5d 3b 20 20 20 20 2f 2a 20 56 61 en[12]; /* Va
26b0: 6c 75 65 20 6f 66 20 74 68 65 20 61 6e 74 69 2d lue of the anti-
26c0: 43 53 52 46 20 74 6f 6b 65 6e 20 2a 2f 0a 20 20 CSRF token */.
26d0: 69 6e 74 20 6f 6b 43 73 72 66 3b 20 20 20 20 20 int okCsrf;
26e0: 20 20 20 20 20 20 20 20 2f 2a 20 41 6e 74 69 2d /* Anti-
26f0: 43 53 52 46 20 74 6f 6b 65 6e 20 69 73 20 70 72 CSRF token is pr
2700: 65 73 65 6e 74 20 61 6e 64 20 76 61 6c 69 64 20 esent and valid
2710: 2a 2f 0a 0a 20 20 69 6e 74 20 70 61 72 73 65 43 */.. int parseC
2720: 6e 74 5b 31 30 5d 3b 20 20 20 20 20 20 20 2f 2a nt[10]; /*
2730: 20 43 6f 75 6e 74 73 20 6f 66 20 61 72 74 69 66 Counts of artif
2740: 61 63 74 73 20 70 61 72 73 65 64 20 2a 2f 0a 20 acts parsed */.
2750: 20 46 49 4c 45 20 2a 66 44 65 62 75 67 3b 20 20 FILE *fDebug;
2760: 20 20 20 20 20 20 20 20 20 2f 2a 20 57 72 69 74 /* Writ
2770: 65 20 64 65 62 75 67 20 69 6e 66 6f 72 6d 61 74 e debug informat
2780: 69 6f 6e 20 68 65 72 65 2c 20 69 66 20 74 68 65 ion here, if the
2790: 20 66 69 6c 65 20 65 78 69 73 74 73 20 2a 2f 0a file exists */.
27a0: 23 69 66 64 65 66 20 46 4f 53 53 49 4c 5f 45 4e #ifdef FOSSIL_EN
27b0: 41 42 4c 45 5f 54 48 31 5f 48 4f 4f 4b 53 0a 20 ABLE_TH1_HOOKS.
27c0: 20 69 6e 74 20 66 4e 6f 54 68 48 6f 6f 6b 3b 20 int fNoThHook;
27d0: 20 20 20 20 20 20 20 20 20 2f 2a 20 44 69 73 61 /* Disa
27e0: 62 6c 65 20 61 6c 6c 20 54 48 31 20 63 6f 6d 6d ble all TH1 comm
27f0: 61 6e 64 2f 77 65 62 70 61 67 65 20 68 6f 6f 6b and/webpage hook
2800: 73 20 2a 2f 0a 23 65 6e 64 69 66 0a 20 20 69 6e s */.#endif. in
2810: 74 20 74 68 54 72 61 63 65 3b 20 20 20 20 20 20 t thTrace;
2820: 20 20 20 20 20 20 2f 2a 20 54 72 75 65 20 74 6f /* True to
2830: 20 65 6e 61 62 6c 65 20 54 48 31 20 64 65 62 75 enable TH1 debu
2840: 67 67 69 6e 67 20 6f 75 74 70 75 74 20 2a 2f 0a gging output */.
2850: 20 20 42 6c 6f 62 20 74 68 4c 6f 67 3b 20 20 20 Blob thLog;
2860: 20 20 20 20 20 20 20 20 20 20 2f 2a 20 54 65 78 /* Tex
2870: 74 20 6f 66 20 74 68 65 20 54 48 31 20 64 65 62 t of the TH1 deb
2880: 75 67 67 69 6e 67 20 6f 75 74 70 75 74 20 2a 2f ugging output */
2890: 0a 0a 20 20 69 6e 74 20 69 73 48 6f 6d 65 3b 20 .. int isHome;
28a0: 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 54 /* T
28b0: 72 75 65 20 69 66 20 72 65 6e 64 65 72 69 6e 67 rue if rendering
28c0: 20 74 68 65 20 22 68 6f 6d 65 22 20 70 61 67 65 the "home" page
28d0: 20 2a 2f 0a 0a 20 20 2f 2a 20 53 74 6f 72 61 67 */.. /* Storag
28e0: 65 20 66 6f 72 20 74 68 65 20 61 75 78 28 29 20 e for the aux()
28f0: 61 6e 64 2f 6f 72 20 6f 70 74 69 6f 6e 28 29 20 and/or option()
2900: 53 51 4c 20 66 75 6e 63 74 69 6f 6e 20 61 72 67 SQL function arg
2910: 75 6d 65 6e 74 73 20 2a 2f 0a 20 20 69 6e 74 20 uments */. int
2920: 6e 41 75 78 3b 20 20 20 20 20 20 20 20 20 20 20 nAux;
2930: 20 20 20 20 20 20 20 20 20 2f 2a 20 4e 75 6d 62 /* Numb
2940: 65 72 20 6f 66 20 64 69 73 74 69 6e 63 74 20 61 er of distinct a
2950: 75 78 28 29 20 6f 72 20 6f 70 74 69 6f 6e 28 29 ux() or option()
2960: 20 76 61 6c 75 65 73 20 2a 2f 0a 20 20 63 6f 6e values */. con
2970: 73 74 20 63 68 61 72 20 2a 61 7a 41 75 78 4e 61 st char *azAuxNa
2980: 6d 65 5b 4d 58 5f 41 55 58 5d 3b 20 2f 2a 20 4e me[MX_AUX]; /* N
2990: 61 6d 65 20 6f 66 20 65 61 63 68 20 61 75 78 28 ame of each aux(
29a0: 29 20 6f 72 20 6f 70 74 69 6f 6e 28 29 20 76 61 ) or option() va
29b0: 6c 75 65 20 2a 2f 0a 20 20 63 68 61 72 20 2a 61 lue */. char *a
29c0: 7a 41 75 78 50 61 72 61 6d 5b 4d 58 5f 41 55 58 zAuxParam[MX_AUX
29d0: 5d 3b 20 20 20 20 20 20 2f 2a 20 50 61 72 61 6d ]; /* Param
29e0: 20 6f 66 20 65 61 63 68 20 61 75 78 28 29 20 6f of each aux() o
29f0: 72 20 6f 70 74 69 6f 6e 28 29 20 76 61 6c 75 65 r option() value
2a00: 20 2a 2f 0a 20 20 63 6f 6e 73 74 20 63 68 61 72 */. const char
2a10: 20 2a 61 7a 41 75 78 56 61 6c 5b 4d 58 5f 41 55 *azAuxVal[MX_AU
2a20: 58 5d 3b 20 20 2f 2a 20 56 61 6c 75 65 20 6f 66 X]; /* Value of
2a30: 20 65 61 63 68 20 61 75 78 28 29 20 6f 72 20 6f each aux() or o
2a40: 70 74 69 6f 6e 28 29 20 76 61 6c 75 65 20 2a 2f ption() value */
2a50: 0a 20 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 2a . const char **
2a60: 61 7a 41 75 78 4f 70 74 5b 4d 58 5f 41 55 58 5d azAuxOpt[MX_AUX]
2a70: 3b 20 2f 2a 20 4f 70 74 69 6f 6e 73 20 6f 66 20 ; /* Options of
2a80: 65 61 63 68 20 6f 70 74 69 6f 6e 28 29 20 76 61 each option() va
2a90: 6c 75 65 20 2a 2f 0a 20 20 69 6e 74 20 61 6e 41 lue */. int anA
2aa0: 75 78 43 6f 6c 73 5b 4d 58 5f 41 55 58 5d 3b 20 uxCols[MX_AUX];
2ab0: 20 20 20 20 20 20 20 20 2f 2a 20 4e 75 6d 62 65 /* Numbe
2ac0: 72 20 6f 66 20 63 6f 6c 75 6d 6e 73 20 66 6f 72 r of columns for
2ad0: 20 6f 70 74 69 6f 6e 28 29 20 76 61 6c 75 65 73 option() values
2ae0: 20 2a 2f 0a 0a 20 20 69 6e 74 20 61 6c 6c 6f 77 */.. int allow
2af0: 53 79 6d 6c 69 6e 6b 73 3b 20 20 20 20 20 20 20 Symlinks;
2b00: 20 20 20 20 20 20 2f 2a 20 43 61 63 68 65 64 20 /* Cached
2b10: 22 61 6c 6c 6f 77 2d 73 79 6d 6c 69 6e 6b 73 22 "allow-symlinks"
2b20: 20 6f 70 74 69 6f 6e 20 2a 2f 0a 0a 20 20 69 6e option */.. in
2b30: 74 20 6d 61 69 6e 54 69 6d 65 72 49 64 3b 20 20 t mainTimerId;
2b40: 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 /*
2b50: 53 65 74 20 74 6f 20 66 6f 73 73 69 6c 5f 74 69 Set to fossil_ti
2b60: 6d 65 72 5f 73 74 61 72 74 28 29 20 2a 2f 0a 23 mer_start() */.#
2b70: 69 66 64 65 66 20 46 4f 53 53 49 4c 5f 45 4e 41 ifdef FOSSIL_ENA
2b80: 42 4c 45 5f 4a 53 4f 4e 0a 20 20 73 74 72 75 63 BLE_JSON. struc
2b90: 74 20 46 6f 73 73 69 6c 4a 73 6f 6e 42 69 74 73 t FossilJsonBits
2ba0: 20 7b 0a 20 20 20 20 69 6e 74 20 69 73 4a 73 6f {. int isJso
2bb0: 6e 4d 6f 64 65 3b 20 20 20 20 20 20 20 20 20 20 nMode;
2bc0: 20 20 2f 2a 20 54 72 75 65 20 69 66 20 72 75 6e /* True if run
2bd0: 6e 69 6e 67 20 69 6e 20 4a 53 4f 4e 20 6d 6f 64 ning in JSON mod
2be0: 65 2c 20 65 6c 73 65 0a 20 20 20 20 20 20 20 20 e, else.
2bf0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
2c00: 20 20 20 20 20 20 20 20 20 20 66 61 6c 73 65 2e false.
2c10: 20 54 68 69 73 20 63 68 61 6e 67 65 73 20 68 6f This changes ho
2c20: 77 20 65 72 72 6f 72 73 20 61 72 65 0a 20 20 20 w errors are.
2c30: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
2c40: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 72 r
2c50: 65 70 6f 72 74 65 64 2e 20 49 6e 20 4a 53 4f 4e eported. In JSON
2c60: 20 6d 6f 64 65 20 77 65 20 74 72 79 20 74 6f 0a mode we try to.
2c70: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
2c80: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
2c90: 20 20 61 6c 77 61 79 73 20 6f 75 74 70 75 74 20 always output
2ca0: 4a 53 4f 4e 2d 66 6f 72 6d 20 65 72 72 6f 72 0a JSON-form error.
2cb0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
2cc0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
2cd0: 20 20 72 65 73 70 6f 6e 73 65 73 20 61 6e 64 20 responses and
2ce0: 61 6c 77 61 79 73 20 65 78 69 74 28 29 20 77 69 always exit() wi
2cf0: 74 68 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 th.
2d00: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
2d10: 20 20 20 20 20 63 6f 64 65 20 30 20 74 6f 20 61 code 0 to a
2d20: 76 6f 69 64 20 61 6e 20 48 54 54 50 20 35 30 30 void an HTTP 500
2d30: 20 65 72 72 6f 72 2e 0a 20 20 20 20 20 20 20 20 error..
2d40: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
2d50: 20 20 20 20 20 20 20 2a 2f 0a 20 20 20 20 69 6e */. in
2d60: 74 20 72 65 73 75 6c 74 43 6f 64 65 3b 20 20 20 t resultCode;
2d70: 20 20 20 20 20 20 20 20 20 2f 2a 20 75 73 65 64 /* used
2d80: 20 66 6f 72 20 70 61 73 73 69 6e 67 20 62 61 63 for passing bac
2d90: 6b 20 73 70 65 63 69 66 69 63 20 63 6f 64 65 73 k specific codes
2da0: 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 .
2db0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
2dc0: 2a 2a 20 66 72 6f 6d 20 2f 6a 73 6f 6e 20 63 61 ** from /json ca
2dd0: 6c 6c 62 61 63 6b 73 2e 20 2a 2f 0a 20 20 20 20 llbacks. */.
2de0: 69 6e 74 20 65 72 72 6f 72 44 65 74 61 69 6c 50 int errorDetailP
2df0: 61 72 61 6e 6f 69 61 3b 20 20 20 2f 2a 20 30 3d aranoia; /* 0=
2e00: 66 75 6c 6c 20 65 72 72 6f 72 20 63 6f 64 65 73 full error codes
2e10: 2c 20 31 3d 25 31 30 2c 20 32 3d 25 31 30 30 2c , 1=%10, 2=%100,
2e20: 20 33 3d 25 31 30 30 30 20 2a 2f 0a 20 20 20 20 3=%1000 */.
2e30: 63 73 6f 6e 5f 6f 75 74 70 75 74 5f 6f 70 74 20 cson_output_opt
2e40: 6f 75 74 4f 70 74 3b 20 20 20 20 2f 2a 20 66 6f outOpt; /* fo
2e50: 72 6d 61 74 74 69 6e 67 20 6f 70 74 69 6f 6e 73 rmatting options
2e60: 20 66 6f 72 20 4a 53 4f 4e 20 6d 6f 64 65 2e 20 for JSON mode.
2e70: 2a 2f 0a 20 20 20 20 63 73 6f 6e 5f 76 61 6c 75 */. cson_valu
2e80: 65 20 2a 61 75 74 68 54 6f 6b 65 6e 3b 20 20 20 e *authToken;
2e90: 20 20 2f 2a 20 61 75 74 68 65 6e 74 69 63 61 74 /* authenticat
2ea0: 69 6f 6e 20 74 6f 6b 65 6e 20 2a 2f 0a 20 20 20 ion token */.
2eb0: 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 6a 73 6f const char *jso
2ec0: 6e 70 3b 20 20 20 20 20 20 20 20 20 2f 2a 20 4e np; /* N
2ed0: 61 6d 65 20 6f 66 20 4a 53 4f 4e 50 20 66 75 6e ame of JSONP fun
2ee0: 63 74 69 6f 6e 20 77 72 61 70 70 65 72 2e 20 2a ction wrapper. *
2ef0: 2f 0a 20 20 20 20 75 6e 73 69 67 6e 65 64 20 63 /. unsigned c
2f00: 68 61 72 20 64 69 73 70 61 74 63 68 44 65 70 74 har dispatchDept
2f10: 68 20 2f 2a 20 54 65 6c 6c 73 20 4a 53 4f 4e 20 h /* Tells JSON
2f20: 63 6f 6d 6d 61 6e 64 20 64 69 73 70 61 74 63 68 command dispatch
2f30: 69 6e 67 0a 20 20 20 20 20 20 20 20 20 20 20 20 ing.
2f40: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
2f50: 20 20 20 20 20 20 20 77 68 69 63 68 20 61 72 67 which arg
2f60: 75 6d 65 6e 74 20 77 65 20 61 72 65 20 63 75 72 ument we are cur
2f70: 72 65 6e 74 6c 79 0a 20 20 20 20 20 20 20 20 20 rently.
2f80: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
2f90: 20 20 20 20 20 20 20 20 20 20 77 6f 72 6b 69 6e workin
2fa0: 67 20 6f 6e 2e 20 46 6f 72 20 74 68 69 73 20 70 g on. For this p
2fb0: 75 72 70 6f 73 65 2c 20 61 72 67 23 30 0a 20 20 urpose, arg#0.
2fc0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
2fd0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
2fe0: 20 69 73 20 74 68 65 20 22 6a 73 6f 6e 22 20 70 is the "json" p
2ff0: 61 74 68 2f 43 4c 49 20 61 72 67 2e 0a 20 20 20 ath/CLI arg..
3000: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
3010: 20 20 20 20 20 20 20 20 20 20 20 20 20 2a 2f 3b */;
3020: 0a 20 20 20 20 73 74 72 75 63 74 20 7b 20 20 20 . struct {
3030: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
3040: 2f 2a 20 22 67 61 72 62 61 67 65 20 63 6f 6c 6c /* "garbage coll
3050: 65 63 74 6f 72 22 20 2a 2f 0a 20 20 20 20 20 20 ector" */.
3060: 63 73 6f 6e 5f 76 61 6c 75 65 20 2a 76 3b 0a 20 cson_value *v;.
3070: 20 20 20 20 20 63 73 6f 6e 5f 61 72 72 61 79 20 cson_array
3080: 2a 61 3b 0a 20 20 20 20 7d 20 67 63 3b 0a 20 20 *a;. } gc;.
3090: 20 20 73 74 72 75 63 74 20 7b 20 20 20 20 20 20 struct {
30a0: 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 /*
30b0: 4a 53 4f 4e 20 50 4f 53 54 20 64 61 74 61 2e 20 JSON POST data.
30c0: 2a 2f 0a 20 20 20 20 20 20 63 73 6f 6e 5f 76 61 */. cson_va
30d0: 6c 75 65 20 2a 76 3b 0a 20 20 20 20 20 20 63 73 lue *v;. cs
30e0: 6f 6e 5f 61 72 72 61 79 20 2a 61 3b 0a 20 20 20 on_array *a;.
30f0: 20 20 20 69 6e 74 20 6f 66 66 73 65 74 3b 20 20 int offset;
3100: 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 54 /* T
3110: 65 6c 6c 73 20 75 73 20 77 68 69 63 68 20 50 41 ells us which PA
3120: 54 48 5f 49 4e 46 4f 2f 43 4c 49 20 61 72 67 73 TH_INFO/CLI args
3130: 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 .
3140: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
3150: 20 20 20 70 61 72 74 20 68 6f 6c 64 73 20 74 68 part holds th
3160: 65 20 22 6a 73 6f 6e 22 20 63 6f 6d 6d 61 6e 64 e "json" command
3170: 2c 20 73 6f 0a 20 20 20 20 20 20 20 20 20 20 20 , so.
3180: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
3190: 20 20 20 20 20 20 20 74 68 61 74 20 77 65 20 63 that we c
31a0: 61 6e 20 61 63 63 6f 75 6e 74 20 66 6f 72 20 73 an account for s
31b0: 75 62 2d 72 65 70 6f 73 0a 20 20 20 20 20 20 20 ub-repos.
31c0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
31d0: 20 20 20 20 20 20 20 20 20 20 20 61 6e 64 20 70 and p
31e0: 61 74 68 20 70 72 65 66 69 78 65 73 2e 20 20 54 ath prefixes. T
31f0: 68 69 73 20 69 73 20 68 61 6e 64 6c 65 64 0a 20 his is handled.
3200: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
3210: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
3220: 20 64 69 66 66 65 72 65 6e 74 6c 79 20 66 6f 72 differently for
3230: 20 43 4c 49 20 61 6e 64 20 43 47 49 20 6d 6f 64 CLI and CGI mod
3240: 65 73 2e 0a 20 20 20 20 20 20 20 20 20 20 20 20 es..
3250: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
3260: 20 20 20 2a 2f 0a 20 20 20 20 20 20 63 6f 6e 73 */. cons
3270: 74 20 63 68 61 72 20 2a 63 6f 6d 6d 61 6e 64 53 t char *commandS
3280: 74 72 20 20 20 2f 2a 22 63 6f 6d 6d 61 6e 64 22 tr /*"command"
3290: 20 72 65 71 75 65 73 74 20 70 61 72 61 6d 2e 2a request param.*
32a0: 2f 3b 0a 20 20 20 20 7d 20 63 6d 64 3b 0a 20 20 /;. } cmd;.
32b0: 20 20 73 74 72 75 63 74 20 7b 20 20 20 20 20 20 struct {
32c0: 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 /*
32d0: 4a 53 4f 4e 20 50 4f 53 54 20 64 61 74 61 2e 20 JSON POST data.
32e0: 2a 2f 0a 20 20 20 20 20 20 63 73 6f 6e 5f 76 61 */. cson_va
32f0: 6c 75 65 20 2a 76 3b 0a 20 20 20 20 20 20 63 73 lue *v;. cs
3300: 6f 6e 5f 6f 62 6a 65 63 74 20 2a 6f 3b 0a 20 20 on_object *o;.
3310: 20 20 7d 20 70 6f 73 74 3b 0a 20 20 20 20 73 74 } post;. st
3320: 72 75 63 74 20 7b 20 20 20 20 20 20 20 20 20 20 ruct {
3330: 20 20 20 20 20 20 20 20 20 2f 2a 20 47 45 54 2f /* GET/
3340: 43 4f 4f 4b 49 45 20 70 61 72 61 6d 73 20 69 6e COOKIE params in
3350: 20 4a 53 4f 4e 20 6d 6f 64 65 2e 20 2a 2f 0a 20 JSON mode. */.
3360: 20 20 20 20 20 63 73 6f 6e 5f 76 61 6c 75 65 20 cson_value
3370: 2a 76 3b 0a 20 20 20 20 20 20 63 73 6f 6e 5f 6f *v;. cson_o
3380: 62 6a 65 63 74 20 2a 6f 3b 0a 20 20 20 20 7d 20 bject *o;. }
3390: 70 61 72 61 6d 3b 0a 20 20 20 20 73 74 72 75 63 param;. struc
33a0: 74 20 7b 0a 20 20 20 20 20 20 63 73 6f 6e 5f 76 t {. cson_v
33b0: 61 6c 75 65 20 2a 76 3b 0a 20 20 20 20 20 20 63 alue *v;. c
33c0: 73 6f 6e 5f 6f 62 6a 65 63 74 20 2a 6f 3b 0a 20 son_object *o;.
33d0: 20 20 20 7d 20 72 65 71 50 61 79 6c 6f 61 64 3b } reqPayload;
33e0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a /*
33f0: 20 72 65 71 75 65 73 74 20 70 61 79 6c 6f 61 64 request payload
3400: 20 6f 62 6a 65 63 74 20 28 69 66 20 61 6e 79 29 object (if any)
3410: 20 2a 2f 0a 20 20 20 20 63 73 6f 6e 5f 61 72 72 */. cson_arr
3420: 61 79 20 2a 77 61 72 6e 69 6e 67 73 3b 20 20 20 ay *warnings;
3430: 20 20 20 2f 2a 20 72 65 73 70 6f 6e 73 65 20 77 /* response w
3440: 61 72 6e 69 6e 67 73 20 2a 2f 0a 20 20 20 20 69 arnings */. i
3450: 6e 74 20 74 69 6d 65 72 49 64 3b 20 20 20 20 20 nt timerId;
3460: 20 20 20 20 20 20 20 20 20 20 2f 2a 20 66 65 74 /* fet
3470: 63 68 65 64 20 66 72 6f 6d 20 66 6f 73 73 69 6c ched from fossil
3480: 5f 74 69 6d 65 72 5f 73 74 61 72 74 28 29 20 2a _timer_start() *
3490: 2f 0a 20 20 7d 20 6a 73 6f 6e 3b 0a 23 65 6e 64 /. } json;.#end
34a0: 69 66 20 2f 2a 20 46 4f 53 53 49 4c 5f 45 4e 41 if /* FOSSIL_ENA
34b0: 42 4c 45 5f 4a 53 4f 4e 20 2a 2f 0a 7d 3b 0a 0a BLE_JSON */.};..
34c0: 2f 2a 0a 2a 2a 20 4d 61 63 72 6f 20 66 6f 72 20 /*.** Macro for
34d0: 64 65 62 75 67 67 69 6e 67 3a 0a 2a 2f 0a 23 64 debugging:.*/.#d
34e0: 65 66 69 6e 65 20 43 47 49 44 45 42 55 47 28 58 efine CGIDEBUG(X
34f0: 29 20 20 69 66 28 20 67 2e 66 44 65 62 75 67 20 ) if( g.fDebug
3500: 29 20 63 67 69 5f 64 65 62 75 67 20 58 0a 0a 23 ) cgi_debug X..#
3510: 65 6e 64 69 66 0a 0a 47 6c 6f 62 61 6c 20 67 3b endif..Global g;
3520: 0a 0a 2f 2a 0a 2a 2a 20 54 68 65 20 74 61 62 6c ../*.** The tabl
3530: 65 20 6f 66 20 77 65 62 20 70 61 67 65 73 20 73 e of web pages s
3540: 75 70 70 6f 72 74 65 64 20 62 79 20 74 68 69 73 upported by this
3550: 20 61 70 70 6c 69 63 61 74 69 6f 6e 20 69 73 20 application is
3560: 67 65 6e 65 72 61 74 65 64 0a 2a 2a 20 61 75 74 generated.** aut
3570: 6f 6d 61 74 69 63 61 6c 6c 79 20 62 79 20 74 68 omatically by th
3580: 65 20 22 6d 6b 69 6e 64 65 78 22 20 70 72 6f 67 e "mkindex" prog
3590: 72 61 6d 20 61 6e 64 20 77 72 69 74 74 65 6e 20 ram and written
35a0: 69 6e 74 6f 20 61 20 66 69 6c 65 0a 2a 2a 20 6e into a file.** n
35b0: 61 6d 65 64 20 22 70 61 67 65 5f 69 6e 64 65 78 amed "page_index
35c0: 2e 68 22 2e 20 20 57 65 20 69 6e 63 6c 75 64 65 .h". We include
35d0: 20 74 68 61 74 20 66 69 6c 65 20 68 65 72 65 20 that file here
35e0: 74 6f 20 67 65 74 20 61 63 63 65 73 73 0a 2a 2a to get access.**
35f0: 20 74 6f 20 74 68 65 20 74 61 62 6c 65 2e 0a 2a to the table..*
3600: 2f 0a 23 69 6e 63 6c 75 64 65 20 22 70 61 67 65 /.#include "page
3610: 5f 69 6e 64 65 78 2e 68 22 0a 0a 2f 2a 0a 2a 2a _index.h"../*.**
3620: 20 53 65 61 72 63 68 20 66 6f 72 20 61 20 66 75 Search for a fu
3630: 6e 63 74 69 6f 6e 20 77 68 6f 73 65 20 6e 61 6d nction whose nam
3640: 65 20 6d 61 74 63 68 65 73 20 7a 4e 61 6d 65 2e e matches zName.
3650: 20 20 57 72 69 74 65 20 61 20 70 6f 69 6e 74 65 Write a pointe
3660: 72 20 74 6f 0a 2a 2a 20 74 68 61 74 20 66 75 6e r to.** that fun
3670: 63 74 69 6f 6e 20 69 6e 74 6f 20 2a 70 78 46 75 ction into *pxFu
3680: 6e 63 20 61 6e 64 20 72 65 74 75 72 6e 20 30 2e nc and return 0.
3690: 20 20 49 66 20 6e 6f 20 6d 61 74 63 68 20 69 73 If no match is
36a0: 20 66 6f 75 6e 64 2c 0a 2a 2a 20 72 65 74 75 72 found,.** retur
36b0: 6e 20 31 2e 20 20 49 66 20 74 68 65 20 63 6f 6d n 1. If the com
36c0: 6d 61 6e 64 20 69 73 20 61 6d 62 69 67 75 6f 75 mand is ambiguou
36d0: 73 20 72 65 74 75 72 6e 20 32 3b 0a 2a 2a 0a 2a s return 2;.**.*
36e0: 2a 20 54 68 65 20 4e 61 6d 65 4d 61 70 20 73 74 * The NameMap st
36f0: 72 75 63 74 75 72 65 20 61 6e 64 20 74 68 65 20 ructure and the
3700: 74 61 62 6c 65 73 20 77 65 20 61 72 65 20 73 65 tables we are se
3710: 61 72 63 68 69 6e 67 20 61 67 61 69 6e 73 74 20 arching against
3720: 61 72 65 0a 2a 2a 20 64 65 66 69 6e 65 64 20 69 are.** defined i
3730: 6e 20 74 68 65 20 70 61 67 65 5f 69 6e 64 65 78 n the page_index
3740: 2e 68 20 68 65 61 64 65 72 20 66 69 6c 65 20 77 .h header file w
3750: 68 69 63 68 20 69 73 20 61 75 74 6f 6d 61 74 69 hich is automati
3760: 63 61 6c 6c 79 0a 2a 2a 20 67 65 6e 65 72 61 74 cally.** generat
3770: 65 64 20 62 79 20 6d 6b 69 6e 64 65 78 2e 63 20 ed by mkindex.c
3780: 70 72 6f 67 72 61 6d 2e 0a 2a 2f 0a 73 74 61 74 program..*/.stat
3790: 69 63 20 69 6e 74 20 6e 61 6d 65 5f 73 65 61 72 ic int name_sear
37a0: 63 68 28 0a 20 20 63 6f 6e 73 74 20 63 68 61 72 ch(. const char
37b0: 20 2a 7a 4e 61 6d 65 2c 20 20 20 20 20 20 20 2f *zName, /
37c0: 2a 20 54 68 65 20 6e 61 6d 65 20 77 65 20 61 72 * The name we ar
37d0: 65 20 6c 6f 6f 6b 69 6e 67 20 66 6f 72 20 2a 2f e looking for */
37e0: 0a 20 20 63 6f 6e 73 74 20 4e 61 6d 65 4d 61 70 . const NameMap
37f0: 20 2a 61 4d 61 70 2c 20 20 20 20 20 2f 2a 20 53 *aMap, /* S
3800: 65 61 72 63 68 20 69 6e 20 74 68 69 73 20 61 72 earch in this ar
3810: 72 61 79 20 2a 2f 0a 20 20 69 6e 74 20 6e 4d 61 ray */. int nMa
3820: 70 2c 20 20 20 20 20 20 20 20 20 20 20 20 20 20 p,
3830: 20 20 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 20 73 /* Number of s
3840: 6c 6f 74 73 20 69 6e 20 61 4d 61 70 5b 5d 20 2a lots in aMap[] *
3850: 2f 0a 20 20 69 6e 74 20 69 42 65 67 69 6e 2c 20 /. int iBegin,
3860: 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 /*
3870: 4c 6f 77 65 72 20 62 6f 75 6e 64 20 6f 6e 20 74 Lower bound on t
3880: 68 65 20 61 72 72 61 79 20 73 65 61 72 63 68 20 he array search
3890: 2a 2f 0a 20 20 69 6e 74 20 2a 70 49 6e 64 65 78 */. int *pIndex
38a0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a /*
38b0: 20 4f 55 54 3a 20 54 68 65 20 69 6e 64 65 78 20 OUT: The index
38c0: 69 6e 20 61 4d 61 70 5b 5d 20 6f 66 20 74 68 65 in aMap[] of the
38d0: 20 6d 61 74 63 68 20 2a 2f 0a 29 7b 0a 20 20 69 match */.){. i
38e0: 6e 74 20 75 70 72 2c 20 6c 77 72 2c 20 63 6e 74 nt upr, lwr, cnt
38f0: 2c 20 6d 2c 20 69 3b 0a 20 20 69 6e 74 20 6e 20 , m, i;. int n
3900: 3d 20 73 74 72 6c 65 6e 28 7a 4e 61 6d 65 29 3b = strlen(zName);
3910: 0a 20 20 6c 77 72 20 3d 20 69 42 65 67 69 6e 3b . lwr = iBegin;
3920: 0a 20 20 75 70 72 20 3d 20 6e 4d 61 70 2d 31 3b . upr = nMap-1;
3930: 0a 20 20 77 68 69 6c 65 28 20 6c 77 72 3c 3d 75 . while( lwr<=u
3940: 70 72 20 29 7b 0a 20 20 20 20 69 6e 74 20 6d 69 pr ){. int mi
3950: 64 2c 20 63 3b 0a 20 20 20 20 6d 69 64 20 3d 20 d, c;. mid =
3960: 28 75 70 72 2b 6c 77 72 29 2f 32 3b 0a 20 20 20 (upr+lwr)/2;.
3970: 20 63 20 3d 20 66 6f 73 73 69 6c 5f 73 74 72 63 c = fossil_strc
3980: 6d 70 28 7a 4e 61 6d 65 2c 20 61 4d 61 70 5b 6d mp(zName, aMap[m
3990: 69 64 5d 2e 7a 4e 61 6d 65 29 3b 0a 20 20 20 20 id].zName);.
39a0: 69 66 28 20 63 3d 3d 30 20 29 7b 0a 20 20 20 20 if( c==0 ){.
39b0: 20 20 2a 70 49 6e 64 65 78 20 3d 20 6d 69 64 3b *pIndex = mid;
39c0: 0a 20 20 20 20 20 20 72 65 74 75 72 6e 20 30 3b . return 0;
39d0: 0a 20 20 20 20 7d 65 6c 73 65 20 69 66 28 20 63 . }else if( c
39e0: 3c 30 20 29 7b 0a 20 20 20 20 20 20 75 70 72 20 <0 ){. upr
39f0: 3d 20 6d 69 64 20 2d 20 31 3b 0a 20 20 20 20 7d = mid - 1;. }
3a00: 65 6c 73 65 7b 0a 20 20 20 20 20 20 6c 77 72 20 else{. lwr
3a10: 3d 20 6d 69 64 20 2b 20 31 3b 0a 20 20 20 20 7d = mid + 1;. }
3a20: 0a 20 20 7d 0a 20 20 66 6f 72 28 6d 3d 63 6e 74 . }. for(m=cnt
3a30: 3d 30 2c 20 69 3d 75 70 72 2d 32 3b 20 63 6e 74 =0, i=upr-2; cnt
3a40: 3c 32 20 26 26 20 69 3c 3d 75 70 72 2b 33 20 26 <2 && i<=upr+3 &
3a50: 26 20 69 3c 6e 4d 61 70 3b 20 69 2b 2b 29 7b 0a & i<nMap; i++){.
3a60: 20 20 20 20 69 66 28 20 69 3c 69 42 65 67 69 6e if( i<iBegin
3a70: 20 29 20 63 6f 6e 74 69 6e 75 65 3b 0a 20 20 20 ) continue;.
3a80: 20 69 66 28 20 73 74 72 6e 63 6d 70 28 7a 4e 61 if( strncmp(zNa
3a90: 6d 65 2c 20 61 4d 61 70 5b 69 5d 2e 7a 4e 61 6d me, aMap[i].zNam
3aa0: 65 2c 20 6e 29 3d 3d 30 20 29 7b 0a 20 20 20 20 e, n)==0 ){.
3ab0: 20 20 6d 20 3d 20 69 3b 0a 20 20 20 20 20 20 63 m = i;. c
3ac0: 6e 74 2b 2b 3b 0a 20 20 20 20 7d 0a 20 20 7d 0a nt++;. }. }.
3ad0: 20 20 69 66 28 20 63 6e 74 3d 3d 31 20 29 7b 0a if( cnt==1 ){.
3ae0: 20 20 20 20 2a 70 49 6e 64 65 78 20 3d 20 6d 3b *pIndex = m;
3af0: 0a 20 20 20 20 72 65 74 75 72 6e 20 30 3b 0a 20 . return 0;.
3b00: 20 7d 0a 20 20 72 65 74 75 72 6e 20 31 2b 28 63 }. return 1+(c
3b10: 6e 74 3e 31 29 3b 0a 7d 0a 0a 2f 2a 0a 2a 2a 20 nt>1);.}../*.**
3b20: 61 74 65 78 69 74 28 29 20 68 61 6e 64 6c 65 72 atexit() handler
3b30: 20 77 68 69 63 68 20 66 72 65 65 73 20 75 70 20 which frees up
3b40: 22 73 6f 6d 65 22 20 6f 66 20 74 68 65 20 72 65 "some" of the re
3b50: 73 6f 75 72 63 65 73 0a 2a 2a 20 75 73 65 64 20 sources.** used
3b60: 62 79 20 66 6f 73 73 69 6c 2e 0a 2a 2f 0a 73 74 by fossil..*/.st
3b70: 61 74 69 63 20 76 6f 69 64 20 66 6f 73 73 69 6c atic void fossil
3b80: 5f 61 74 65 78 69 74 28 76 6f 69 64 29 20 7b 0a _atexit(void) {.
3b90: 23 69 66 20 64 65 66 69 6e 65 64 28 5f 57 49 4e #if defined(_WIN
3ba0: 33 32 29 20 26 26 20 21 64 65 66 69 6e 65 64 28 32) && !defined(
3bb0: 5f 57 49 4e 36 34 29 20 26 26 20 64 65 66 69 6e _WIN64) && defin
3bc0: 65 64 28 46 4f 53 53 49 4c 5f 45 4e 41 42 4c 45 ed(FOSSIL_ENABLE
3bd0: 5f 54 43 4c 29 20 26 26 20 5c 0a 20 20 20 20 64 _TCL) && \. d
3be0: 65 66 69 6e 65 64 28 55 53 45 5f 54 43 4c 5f 53 efined(USE_TCL_S
3bf0: 54 55 42 53 29 0a 20 20 2f 2a 0a 20 20 2a 2a 20 TUBS). /*. **
3c00: 49 66 20 54 63 6c 20 69 73 20 63 6f 6d 70 69 6c If Tcl is compil
3c10: 65 64 20 6f 6e 20 57 69 6e 64 6f 77 73 20 75 73 ed on Windows us
3c20: 69 6e 67 20 74 68 65 20 6c 61 74 65 73 74 20 4d ing the latest M
3c30: 69 6e 47 57 2c 20 46 6f 73 73 69 6c 20 63 61 6e inGW, Fossil can
3c40: 20 63 72 61 73 68 0a 20 20 2a 2a 20 77 68 65 6e crash. ** when
3c50: 20 65 78 69 74 69 6e 67 20 77 68 69 6c 65 20 61 exiting while a
3c60: 20 73 74 75 62 73 2d 65 6e 61 62 6c 65 64 20 54 stubs-enabled T
3c70: 63 6c 20 69 73 20 73 74 69 6c 6c 20 6c 6f 61 64 cl is still load
3c80: 65 64 2e 20 20 54 68 69 73 20 69 73 20 64 75 65 ed. This is due
3c90: 20 74 6f 0a 20 20 2a 2a 20 61 20 62 75 67 20 69 to. ** a bug i
3ca0: 6e 20 4d 69 6e 47 57 2c 20 73 65 65 3a 0a 20 20 n MinGW, see:.
3cb0: 2a 2a 0a 20 20 2a 2a 20 20 20 20 20 68 74 74 70 **. ** http
3cc0: 3a 2f 2f 63 6f 6d 6d 65 6e 74 73 2e 67 6d 61 6e ://comments.gman
3cd0: 65 2e 6f 72 67 2f 67 6d 61 6e 65 2e 63 6f 6d 70 e.org/gmane.comp
3ce0: 2e 67 6e 75 2e 6d 69 6e 67 77 2e 75 73 65 72 2f .gnu.mingw.user/
3cf0: 34 31 37 32 34 0a 20 20 2a 2a 0a 20 20 2a 2a 20 41724. **. **
3d00: 54 68 65 20 77 6f 72 6b 61 72 6f 75 6e 64 20 69 The workaround i
3d10: 73 20 74 6f 20 6d 61 6e 75 61 6c 6c 79 20 75 6e s to manually un
3d20: 6c 6f 61 64 20 74 68 65 20 6c 6f 61 64 65 64 20 load the loaded
3d30: 54 63 6c 20 6c 69 62 72 61 72 79 20 70 72 69 6f Tcl library prio
3d40: 72 20 74 6f 0a 20 20 2a 2a 20 65 78 69 74 69 6e r to. ** exitin
3d50: 67 20 74 68 65 20 70 72 6f 63 65 73 73 2e 20 20 g the process.
3d60: 54 68 69 73 20 69 73 73 75 65 20 64 6f 65 73 20 This issue does
3d70: 6e 6f 74 20 69 6d 70 61 63 74 20 36 34 2d 62 69 not impact 64-bi
3d80: 74 20 57 69 6e 64 6f 77 73 2e 0a 20 20 2a 2f 0a t Windows.. */.
3d90: 20 20 75 6e 6c 6f 61 64 54 63 6c 28 67 2e 69 6e unloadTcl(g.in
3da0: 74 65 72 70 2c 20 26 67 2e 74 63 6c 29 3b 0a 23 terp, &g.tcl);.#
3db0: 65 6e 64 69 66 0a 23 69 66 64 65 66 20 46 4f 53 endif.#ifdef FOS
3dc0: 53 49 4c 5f 45 4e 41 42 4c 45 5f 4a 53 4f 4e 0a SIL_ENABLE_JSON.
3dd0: 20 20 63 73 6f 6e 5f 76 61 6c 75 65 5f 66 72 65 cson_value_fre
3de0: 65 28 67 2e 6a 73 6f 6e 2e 67 63 2e 76 29 3b 0a e(g.json.gc.v);.
3df0: 20 20 6d 65 6d 73 65 74 28 26 67 2e 6a 73 6f 6e memset(&g.json
3e00: 2c 20 30 2c 20 73 69 7a 65 6f 66 28 67 2e 6a 73 , 0, sizeof(g.js
3e10: 6f 6e 29 29 3b 0a 23 65 6e 64 69 66 0a 20 20 66 on));.#endif. f
3e20: 72 65 65 28 67 2e 7a 45 72 72 4d 73 67 29 3b 0a ree(g.zErrMsg);.
3e30: 20 20 69 66 28 67 2e 64 62 29 7b 0a 20 20 20 20 if(g.db){.
3e40: 64 62 5f 63 6c 6f 73 65 28 30 29 3b 0a 20 20 7d db_close(0);. }
3e50: 0a 20 20 2f 2a 0a 20 20 2a 2a 20 46 49 58 4d 45 . /*. ** FIXME
3e60: 3a 20 54 68 65 20 6e 65 78 74 20 74 77 6f 20 6c : The next two l
3e70: 69 6e 65 73 20 63 61 6e 6e 6f 74 20 61 6c 77 61 ines cannot alwa
3e80: 79 73 20 62 65 20 65 6e 61 62 6c 65 64 3b 20 68 ys be enabled; h
3e90: 6f 77 65 76 65 72 2c 20 74 68 65 79 0a 20 20 2a owever, they. *
3ea0: 2a 20 20 20 20 20 20 20 20 61 72 65 20 76 65 72 * are ver
3eb0: 79 20 75 73 65 66 75 6c 20 66 6f 72 20 74 72 61 y useful for tra
3ec0: 63 6b 69 6e 67 20 64 6f 77 6e 20 54 48 31 20 6d cking down TH1 m
3ed0: 65 6d 6f 72 79 20 6c 65 61 6b 73 2e 0a 20 20 2a emory leaks.. *
3ee0: 2f 0a 20 20 69 66 28 20 66 6f 73 73 69 6c 5f 67 /. if( fossil_g
3ef0: 65 74 65 6e 76 28 22 54 48 31 5f 44 45 4c 45 54 etenv("TH1_DELET
3f00: 45 5f 49 4e 54 45 52 50 22 29 21 3d 30 20 29 7b E_INTERP")!=0 ){
3f10: 0a 20 20 20 20 69 66 28 20 67 2e 69 6e 74 65 72 . if( g.inter
3f20: 70 20 29 7b 0a 20 20 20 20 20 20 54 68 5f 44 65 p ){. Th_De
3f30: 6c 65 74 65 49 6e 74 65 72 70 28 67 2e 69 6e 74 leteInterp(g.int
3f40: 65 72 70 29 3b 20 67 2e 69 6e 74 65 72 70 20 3d erp); g.interp =
3f50: 20 30 3b 0a 20 20 20 20 7d 0a 20 20 20 20 61 73 0;. }. as
3f60: 73 65 72 74 28 20 54 68 5f 47 65 74 4f 75 74 73 sert( Th_GetOuts
3f70: 74 61 6e 64 69 6e 67 4d 61 6c 6c 6f 63 28 29 3d tandingMalloc()=
3f80: 3d 30 20 29 3b 0a 20 20 7d 0a 7d 0a 0a 2f 2a 0a =0 );. }.}../*.
3f90: 2a 2a 20 43 6f 6e 76 65 72 74 20 61 6c 6c 20 61 ** Convert all a
3fa0: 72 67 75 6d 65 6e 74 73 20 66 72 6f 6d 20 6d 62 rguments from mb
3fb0: 63 73 20 28 6f 72 20 75 6e 69 63 6f 64 65 29 20 cs (or unicode)
3fc0: 74 6f 20 55 54 46 2d 38 2e 20 54 68 65 6e 0a 2a to UTF-8. Then.*
3fd0: 2a 20 73 65 61 72 63 68 20 67 2e 61 72 67 76 20 * search g.argv
3fe0: 66 6f 72 20 61 72 67 75 6d 65 6e 74 73 20 22 2d for arguments "-
3ff0: 2d 61 72 67 73 20 46 49 4c 45 4e 41 4d 45 22 2e -args FILENAME".
4000: 20 49 66 20 66 6f 75 6e 64 2c 20 74 68 65 6e 0a If found, then.
4010: 2a 2a 20 28 31 29 20 72 65 6d 6f 76 65 20 74 68 ** (1) remove th
4020: 65 20 74 77 6f 20 61 72 67 75 6d 65 6e 74 73 20 e two arguments
4030: 66 72 6f 6d 20 67 2e 61 72 67 76 0a 2a 2a 20 28 from g.argv.** (
4040: 32 29 20 52 65 61 64 20 74 68 65 20 66 69 6c 65 2) Read the file
4050: 20 46 49 4c 45 4e 41 4d 45 0a 2a 2a 20 28 33 29 FILENAME.** (3)
4060: 20 55 73 65 20 74 68 65 20 63 6f 6e 74 65 6e 74 Use the content
4070: 73 20 6f 66 20 46 49 4c 45 20 74 6f 20 72 65 70 s of FILE to rep
4080: 6c 61 63 65 20 74 68 65 20 74 77 6f 20 72 65 6d lace the two rem
4090: 6f 76 65 64 20 61 72 67 75 6d 65 6e 74 73 3a 0a oved arguments:.
40a0: 2a 2a 20 20 20 20 20 28 61 29 20 49 67 6e 6f 72 ** (a) Ignor
40b0: 65 20 62 6c 61 6e 6b 20 6c 69 6e 65 73 20 69 6e e blank lines in
40c0: 20 74 68 65 20 66 69 6c 65 0a 2a 2a 20 20 20 20 the file.**
40d0: 20 28 62 29 20 45 61 63 68 20 6e 6f 6e 2d 65 6d (b) Each non-em
40e0: 70 74 79 20 6c 69 6e 65 20 6f 66 20 74 68 65 20 pty line of the
40f0: 66 69 6c 65 20 69 73 20 61 6e 20 61 72 67 75 6d file is an argum
4100: 65 6e 74 2c 20 65 78 63 65 70 74 0a 2a 2a 20 20 ent, except.**
4110: 20 20 20 28 63 29 20 49 66 20 74 68 65 20 6c 69 (c) If the li
4120: 6e 65 20 62 65 67 69 6e 73 20 77 69 74 68 20 22 ne begins with "
4130: 2d 22 20 61 6e 64 20 63 6f 6e 74 61 69 6e 73 20 -" and contains
4140: 61 20 73 70 61 63 65 2c 20 69 74 20 69 73 20 62 a space, it is b
4150: 72 6f 6b 65 6e 0a 2a 2a 20 20 20 20 20 20 20 20 roken.**
4160: 20 69 6e 74 6f 20 74 77 6f 20 61 72 67 75 6d 65 into two argume
4170: 6e 74 73 20 61 74 20 74 68 65 20 73 70 61 63 65 nts at the space
4180: 2e 0a 2a 2f 0a 73 74 61 74 69 63 20 76 6f 69 64 ..*/.static void
4190: 20 65 78 70 61 6e 64 5f 61 72 67 73 5f 6f 70 74 expand_args_opt
41a0: 69 6f 6e 28 69 6e 74 20 61 72 67 63 2c 20 76 6f ion(int argc, vo
41b0: 69 64 20 2a 61 72 67 76 29 7b 0a 20 20 42 6c 6f id *argv){. Blo
41c0: 62 20 66 69 6c 65 20 3d 20 65 6d 70 74 79 5f 62 b file = empty_b
41d0: 6c 6f 62 3b 20 20 20 2f 2a 20 43 6f 6e 74 65 6e lob; /* Conten
41e0: 74 20 6f 66 20 74 68 65 20 66 69 6c 65 20 2a 2f t of the file */
41f0: 0a 20 20 42 6c 6f 62 20 6c 69 6e 65 20 3d 20 65 . Blob line = e
4200: 6d 70 74 79 5f 62 6c 6f 62 3b 20 20 20 2f 2a 20 mpty_blob; /*
4210: 4f 6e 65 20 6c 69 6e 65 20 6f 66 20 74 68 65 20 One line of the
4220: 66 69 6c 65 20 2a 2f 0a 20 20 75 6e 73 69 67 6e file */. unsign
4230: 65 64 20 69 6e 74 20 6e 4c 69 6e 65 3b 20 20 20 ed int nLine;
4240: 20 20 20 20 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 /* Number of
4250: 20 6c 69 6e 65 73 20 69 6e 20 74 68 65 20 66 69 lines in the fi
4260: 6c 65 2a 2f 0a 20 20 75 6e 73 69 67 6e 65 64 20 le*/. unsigned
4270: 69 6e 74 20 69 2c 20 6a 2c 20 6b 3b 20 20 20 20 int i, j, k;
4280: 20 2f 2a 20 4c 6f 6f 70 20 63 6f 75 6e 74 65 72 /* Loop counter
4290: 73 20 2a 2f 0a 20 20 69 6e 74 20 6e 3b 20 20 20 s */. int n;
42a0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
42b0: 20 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 20 62 79 /* Number of by
42c0: 74 65 73 20 69 6e 20 6f 6e 65 20 6c 69 6e 65 20 tes in one line
42d0: 2a 2f 0a 20 20 63 68 61 72 20 2a 7a 3b 20 20 20 */. char *z;
42e0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f /
42f0: 2a 20 47 65 6e 65 72 61 6c 20 75 73 65 20 73 74 * General use st
4300: 72 69 6e 67 20 70 6f 69 6e 74 65 72 20 2a 2f 0a ring pointer */.
4310: 20 20 63 68 61 72 20 2a 2a 6e 65 77 41 72 67 76 char **newArgv
4320: 3b 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 4e ; /* N
4330: 65 77 20 65 78 70 61 6e 64 65 64 20 67 2e 61 72 ew expanded g.ar
4340: 67 76 20 75 6e 64 65 72 20 63 6f 6e 73 74 72 75 gv under constru
4350: 63 74 69 6f 6e 20 2a 2f 0a 20 20 63 6f 6e 73 74 ction */. const
4360: 20 63 68 61 72 20 2a 7a 46 69 6c 65 4e 61 6d 65 char *zFileName
4370: 3b 20 20 20 20 2f 2a 20 69 6e 70 75 74 20 66 69 ; /* input fi
4380: 6c 65 20 6e 61 6d 65 20 2a 2f 0a 20 20 46 49 4c le name */. FIL
4390: 45 20 2a 69 6e 46 69 6c 65 3b 20 20 20 20 20 20 E *inFile;
43a0: 20 20 20 20 20 20 20 2f 2a 20 69 6e 70 75 74 20 /* input
43b0: 46 49 4c 45 20 2a 2f 0a 23 69 66 20 64 65 66 69 FILE */.#if defi
43c0: 6e 65 64 28 5f 57 49 4e 33 32 29 0a 20 20 77 63 ned(_WIN32). wc
43d0: 68 61 72 5f 74 20 62 75 66 5b 4d 41 58 5f 50 41 har_t buf[MAX_PA
43e0: 54 48 5d 3b 0a 23 65 6e 64 69 66 0a 0a 20 20 67 TH];.#endif.. g
43f0: 2e 61 72 67 63 20 3d 20 61 72 67 63 3b 0a 20 20 .argc = argc;.
4400: 67 2e 61 72 67 76 20 3d 20 61 72 67 76 3b 0a 20 g.argv = argv;.
4410: 20 73 71 6c 69 74 65 33 5f 69 6e 69 74 69 61 6c sqlite3_initial
4420: 69 7a 65 28 29 3b 0a 23 69 66 20 64 65 66 69 6e ize();.#if defin
4430: 65 64 28 5f 57 49 4e 33 32 29 20 26 26 20 64 65 ed(_WIN32) && de
4440: 66 69 6e 65 64 28 42 52 4f 4b 45 4e 5f 4d 49 4e fined(BROKEN_MIN
4450: 47 57 5f 43 4d 44 4c 49 4e 45 29 0a 20 20 66 6f GW_CMDLINE). fo
4460: 72 28 69 3d 30 3b 20 69 3c 67 2e 61 72 67 63 3b r(i=0; i<g.argc;
4470: 20 69 2b 2b 29 20 67 2e 61 72 67 76 5b 69 5d 20 i++) g.argv[i]
4480: 3d 20 66 6f 73 73 69 6c 5f 6d 62 63 73 5f 74 6f = fossil_mbcs_to
4490: 5f 75 74 66 38 28 67 2e 61 72 67 76 5b 69 5d 29 _utf8(g.argv[i])
44a0: 3b 0a 23 65 6c 73 65 0a 20 20 66 6f 72 28 69 3d ;.#else. for(i=
44b0: 30 3b 20 69 3c 67 2e 61 72 67 63 3b 20 69 2b 2b 0; i<g.argc; i++
44c0: 29 20 67 2e 61 72 67 76 5b 69 5d 20 3d 20 66 6f ) g.argv[i] = fo
44d0: 73 73 69 6c 5f 70 61 74 68 5f 74 6f 5f 75 74 66 ssil_path_to_utf
44e0: 38 28 67 2e 61 72 67 76 5b 69 5d 29 3b 0a 23 65 8(g.argv[i]);.#e
44f0: 6e 64 69 66 0a 23 69 66 20 64 65 66 69 6e 65 64 ndif.#if defined
4500: 28 5f 57 49 4e 33 32 29 0a 20 20 47 65 74 4d 6f (_WIN32). GetMo
4510: 64 75 6c 65 46 69 6c 65 4e 61 6d 65 57 28 4e 55 duleFileNameW(NU
4520: 4c 4c 2c 20 62 75 66 2c 20 4d 41 58 5f 50 41 54 LL, buf, MAX_PAT
4530: 48 29 3b 0a 20 20 67 2e 6e 61 6d 65 4f 66 45 78 H);. g.nameOfEx
4540: 65 20 3d 20 66 6f 73 73 69 6c 5f 70 61 74 68 5f e = fossil_path_
4550: 74 6f 5f 75 74 66 38 28 62 75 66 29 3b 0a 23 65 to_utf8(buf);.#e
4560: 6c 73 65 0a 20 20 67 2e 6e 61 6d 65 4f 66 45 78 lse. g.nameOfEx
4570: 65 20 3d 20 67 2e 61 72 67 76 5b 30 5d 3b 0a 23 e = g.argv[0];.#
4580: 65 6e 64 69 66 0a 20 20 66 6f 72 28 69 3d 31 3b endif. for(i=1;
4590: 20 69 3c 67 2e 61 72 67 63 2d 31 3b 20 69 2b 2b i<g.argc-1; i++
45a0: 29 7b 0a 20 20 20 20 7a 20 3d 20 67 2e 61 72 67 ){. z = g.arg
45b0: 76 5b 69 5d 3b 0a 20 20 20 20 69 66 28 20 7a 5b v[i];. if( z[
45c0: 30 5d 21 3d 27 2d 27 20 29 20 63 6f 6e 74 69 6e 0]!='-' ) contin
45d0: 75 65 3b 0a 20 20 20 20 7a 2b 2b 3b 0a 20 20 20 ue;. z++;.
45e0: 20 69 66 28 20 7a 5b 30 5d 3d 3d 27 2d 27 20 29 if( z[0]=='-' )
45f0: 20 7a 2b 2b 3b 0a 20 20 20 20 69 66 28 20 7a 5b z++;. if( z[
4600: 30 5d 3d 3d 30 20 29 20 72 65 74 75 72 6e 3b 20 0]==0 ) return;
4610: 20 20 2f 2a 20 53 74 6f 70 20 73 65 61 72 63 68 /* Stop search
4620: 69 6e 67 20 61 74 20 22 2d 2d 22 20 2a 2f 0a 20 ing at "--" */.
4630: 20 20 20 69 66 28 20 66 6f 73 73 69 6c 5f 73 74 if( fossil_st
4640: 72 63 6d 70 28 7a 2c 20 22 61 72 67 73 22 29 3d rcmp(z, "args")=
4650: 3d 30 20 29 20 62 72 65 61 6b 3b 0a 20 20 7d 0a =0 ) break;. }.
4660: 20 20 69 66 28 20 69 3e 3d 67 2e 61 72 67 63 2d if( i>=g.argc-
4670: 31 20 29 20 72 65 74 75 72 6e 3b 0a 0a 20 20 7a 1 ) return;.. z
4680: 46 69 6c 65 4e 61 6d 65 20 3d 20 67 2e 61 72 67 FileName = g.arg
4690: 76 5b 69 2b 31 5d 3b 0a 20 20 69 6e 46 69 6c 65 v[i+1];. inFile
46a0: 20 3d 20 28 30 3d 3d 73 74 72 63 6d 70 28 22 2d = (0==strcmp("-
46b0: 22 2c 7a 46 69 6c 65 4e 61 6d 65 29 29 0a 20 20 ",zFileName)).
46c0: 20 20 3f 20 73 74 64 69 6e 0a 20 20 20 20 3a 20 ? stdin. :
46d0: 66 6f 73 73 69 6c 5f 66 6f 70 65 6e 28 7a 46 69 fossil_fopen(zFi
46e0: 6c 65 4e 61 6d 65 2c 22 72 62 22 29 3b 0a 20 20 leName,"rb");.
46f0: 69 66 28 21 69 6e 46 69 6c 65 29 7b 0a 20 20 20 if(!inFile){.
4700: 20 66 6f 73 73 69 6c 5f 66 61 74 61 6c 28 22 43 fossil_fatal("C
4710: 61 6e 6e 6f 74 20 6f 70 65 6e 20 2d 61 72 67 73 annot open -args
4720: 20 66 69 6c 65 20 5b 25 73 5d 22 2c 20 7a 46 69 file [%s]", zFi
4730: 6c 65 4e 61 6d 65 29 3b 0a 20 20 7d 65 6c 73 65 leName);. }else
4740: 7b 0a 20 20 20 20 62 6c 6f 62 5f 72 65 61 64 5f {. blob_read_
4750: 66 72 6f 6d 5f 63 68 61 6e 6e 65 6c 28 26 66 69 from_channel(&fi
4760: 6c 65 2c 20 69 6e 46 69 6c 65 2c 20 2d 31 29 3b le, inFile, -1);
4770: 0a 20 20 20 20 69 66 28 73 74 64 69 6e 20 21 3d . if(stdin !=
4780: 20 69 6e 46 69 6c 65 29 7b 0a 20 20 20 20 20 20 inFile){.
4790: 66 63 6c 6f 73 65 28 69 6e 46 69 6c 65 29 3b 0a fclose(inFile);.
47a0: 20 20 20 20 7d 0a 20 20 20 20 69 6e 46 69 6c 65 }. inFile
47b0: 20 3d 20 4e 55 4c 4c 3b 0a 20 20 7d 0a 20 20 62 = NULL;. }. b
47c0: 6c 6f 62 5f 74 6f 5f 75 74 66 38 5f 6e 6f 5f 62 lob_to_utf8_no_b
47d0: 6f 6d 28 26 66 69 6c 65 2c 20 31 29 3b 0a 20 20 om(&file, 1);.
47e0: 7a 20 3d 20 62 6c 6f 62 5f 73 74 72 28 26 66 69 z = blob_str(&fi
47f0: 6c 65 29 3b 0a 20 20 66 6f 72 28 6b 3d 30 2c 20 le);. for(k=0,
4800: 6e 4c 69 6e 65 3d 31 3b 20 7a 5b 6b 5d 3b 20 6b nLine=1; z[k]; k
4810: 2b 2b 29 20 69 66 28 20 7a 5b 6b 5d 3d 3d 27 5c ++) if( z[k]=='\
4820: 6e 27 20 29 20 6e 4c 69 6e 65 2b 2b 3b 0a 20 20 n' ) nLine++;.
4830: 6e 65 77 41 72 67 76 20 3d 20 66 6f 73 73 69 6c newArgv = fossil
4840: 5f 6d 61 6c 6c 6f 63 28 20 73 69 7a 65 6f 66 28 _malloc( sizeof(
4850: 63 68 61 72 2a 29 2a 28 67 2e 61 72 67 63 20 2b char*)*(g.argc +
4860: 20 6e 4c 69 6e 65 2a 32 29 20 29 3b 0a 20 20 66 nLine*2) );. f
4870: 6f 72 28 6a 3d 30 3b 20 6a 3c 69 3b 20 6a 2b 2b or(j=0; j<i; j++
4880: 29 20 6e 65 77 41 72 67 76 5b 6a 5d 20 3d 20 67 ) newArgv[j] = g
4890: 2e 61 72 67 76 5b 6a 5d 3b 0a 0a 20 20 62 6c 6f .argv[j];.. blo
48a0: 62 5f 72 65 77 69 6e 64 28 26 66 69 6c 65 29 3b b_rewind(&file);
48b0: 0a 20 20 77 68 69 6c 65 28 20 28 6e 20 3d 20 62 . while( (n = b
48c0: 6c 6f 62 5f 6c 69 6e 65 28 26 66 69 6c 65 2c 20 lob_line(&file,
48d0: 26 6c 69 6e 65 29 29 3e 30 20 29 7b 0a 20 20 20 &line))>0 ){.
48e0: 20 69 66 28 20 6e 3c 31 20 29 20 63 6f 6e 74 69 if( n<1 ) conti
48f0: 6e 75 65 0a 20 20 20 20 20 20 2f 2a 2a 0a 20 20 nue. /**.
4900: 20 20 20 20 20 2a 2a 20 52 65 6d 69 6e 64 65 72 ** Reminder
4910: 3a 20 63 6f 72 6e 65 72 2d 63 61 73 65 3a 20 61 : corner-case: a
4920: 20 6c 69 6e 65 20 77 69 74 68 20 31 20 62 79 74 line with 1 byt
4930: 65 20 61 6e 64 20 6e 6f 20 6e 65 77 6c 69 6e 65 e and no newline
4940: 2e 0a 20 20 20 20 20 20 20 2a 2f 3b 0a 20 20 20 .. */;.
4950: 20 7a 20 3d 20 62 6c 6f 62 5f 62 75 66 66 65 72 z = blob_buffer
4960: 28 26 6c 69 6e 65 29 3b 0a 20 20 20 20 69 66 28 (&line);. if(
4970: 27 5c 6e 27 3d 3d 7a 5b 6e 2d 31 5d 29 7b 0a 20 '\n'==z[n-1]){.
4980: 20 20 20 20 20 7a 5b 6e 2d 31 5d 20 3d 20 30 3b z[n-1] = 0;
4990: 0a 20 20 20 20 7d 0a 0a 20 20 20 20 69 66 28 28 . }.. if((
49a0: 6e 3e 31 29 20 26 26 20 28 27 5c 72 27 3d 3d 7a n>1) && ('\r'==z
49b0: 5b 6e 2d 32 5d 29 29 7b 0a 20 20 20 20 20 20 69 [n-2])){. i
49c0: 66 28 6e 3d 3d 32 29 20 63 6f 6e 74 69 6e 75 65 f(n==2) continue
49d0: 20 2f 2a 65 6d 70 74 79 20 6c 69 6e 65 2a 2f 3b /*empty line*/;
49e0: 0a 20 20 20 20 20 20 7a 5b 6e 2d 32 5d 20 3d 20 . z[n-2] =
49f0: 30 3b 0a 20 20 20 20 7d 0a 20 20 20 20 69 66 28 0;. }. if(
4a00: 21 7a 5b 30 5d 29 20 63 6f 6e 74 69 6e 75 65 3b !z[0]) continue;
4a10: 0a 20 20 20 20 6e 65 77 41 72 67 76 5b 6a 2b 2b . newArgv[j++
4a20: 5d 20 3d 20 7a 3b 0a 20 20 20 20 69 66 28 20 7a ] = z;. if( z
4a30: 5b 30 5d 3d 3d 27 2d 27 20 29 7b 0a 20 20 20 20 [0]=='-' ){.
4a40: 20 20 66 6f 72 28 6b 3d 31 3b 20 7a 5b 6b 5d 20 for(k=1; z[k]
4a50: 26 26 20 21 66 6f 73 73 69 6c 5f 69 73 73 70 61 && !fossil_isspa
4a60: 63 65 28 7a 5b 6b 5d 29 3b 20 6b 2b 2b 29 7b 7d ce(z[k]); k++){}
4a70: 0a 20 20 20 20 20 20 69 66 28 20 7a 5b 6b 5d 20 . if( z[k]
4a80: 29 7b 0a 20 20 20 20 20 20 20 20 7a 5b 6b 5d 20 ){. z[k]
4a90: 3d 20 30 3b 0a 20 20 20 20 20 20 20 20 6b 2b 2b = 0;. k++
4aa0: 3b 0a 20 20 20 20 20 20 20 20 69 66 28 20 7a 5b ;. if( z[
4ab0: 6b 5d 20 29 20 6e 65 77 41 72 67 76 5b 6a 2b 2b k] ) newArgv[j++
4ac0: 5d 20 3d 20 26 7a 5b 6b 5d 3b 0a 20 20 20 20 20 ] = &z[k];.
4ad0: 20 7d 0a 20 20 20 20 7d 0a 20 20 7d 0a 20 20 69 }. }. }. i
4ae0: 20 2b 3d 20 32 3b 0a 20 20 77 68 69 6c 65 28 20 += 2;. while(
4af0: 69 3c 67 2e 61 72 67 63 20 29 20 6e 65 77 41 72 i<g.argc ) newAr
4b00: 67 76 5b 6a 2b 2b 5d 20 3d 20 67 2e 61 72 67 76 gv[j++] = g.argv
4b10: 5b 69 2b 2b 5d 3b 0a 20 20 6e 65 77 41 72 67 76 [i++];. newArgv
4b20: 5b 6a 5d 20 3d 20 30 3b 0a 20 20 67 2e 61 72 67 [j] = 0;. g.arg
4b30: 63 20 3d 20 6a 3b 0a 20 20 67 2e 61 72 67 76 20 c = j;. g.argv
4b40: 3d 20 6e 65 77 41 72 67 76 3b 0a 7d 0a 0a 23 69 = newArgv;.}..#i
4b50: 66 64 65 66 20 46 4f 53 53 49 4c 5f 45 4e 41 42 fdef FOSSIL_ENAB
4b60: 4c 45 5f 54 43 4c 0a 2f 2a 0a 2a 2a 20 4d 61 6b LE_TCL./*.** Mak
4b70: 65 20 61 20 64 65 65 70 20 63 6f 70 79 20 6f 66 e a deep copy of
4b80: 20 74 68 65 20 70 72 6f 76 69 64 65 64 20 61 72 the provided ar
4b90: 67 75 6d 65 6e 74 20 61 72 72 61 79 20 61 6e 64 gument array and
4ba0: 20 72 65 74 75 72 6e 20 69 74 2e 0a 2a 2f 0a 73 return it..*/.s
4bb0: 74 61 74 69 63 20 63 68 61 72 20 2a 2a 63 6f 70 tatic char **cop
4bc0: 79 5f 61 72 67 73 28 69 6e 74 20 61 72 67 63 2c y_args(int argc,
4bd0: 20 63 68 61 72 20 2a 2a 61 72 67 76 29 7b 0a 20 char **argv){.
4be0: 20 63 68 61 72 20 2a 2a 7a 4e 65 77 41 72 67 76 char **zNewArgv
4bf0: 3b 0a 20 20 69 6e 74 20 69 3b 0a 20 20 7a 4e 65 ;. int i;. zNe
4c00: 77 41 72 67 76 20 3d 20 66 6f 73 73 69 6c 5f 6d wArgv = fossil_m
4c10: 61 6c 6c 6f 63 28 20 73 69 7a 65 6f 66 28 63 68 alloc( sizeof(ch
4c20: 61 72 2a 29 2a 28 61 72 67 63 2b 31 29 20 29 3b ar*)*(argc+1) );
4c30: 0a 20 20 6d 65 6d 73 65 74 28 7a 4e 65 77 41 72 . memset(zNewAr
4c40: 67 76 2c 20 30 2c 20 73 69 7a 65 6f 66 28 63 68 gv, 0, sizeof(ch
4c50: 61 72 2a 29 2a 28 61 72 67 63 2b 31 29 29 3b 0a ar*)*(argc+1));.
4c60: 20 20 66 6f 72 28 69 3d 30 3b 20 69 3c 61 72 67 for(i=0; i<arg
4c70: 63 3b 20 69 2b 2b 29 7b 0a 20 20 20 20 7a 4e 65 c; i++){. zNe
4c80: 77 41 72 67 76 5b 69 5d 20 3d 20 66 6f 73 73 69 wArgv[i] = fossi
4c90: 6c 5f 73 74 72 64 75 70 28 61 72 67 76 5b 69 5d l_strdup(argv[i]
4ca0: 29 3b 0a 20 20 7d 0a 20 20 72 65 74 75 72 6e 20 );. }. return
4cb0: 7a 4e 65 77 41 72 67 76 3b 0a 7d 0a 23 65 6e 64 zNewArgv;.}.#end
4cc0: 69 66 0a 0a 2f 2a 0a 2a 2a 20 52 65 74 75 72 6e if../*.** Return
4cd0: 73 20 61 20 6e 61 6d 65 20 66 6f 72 20 61 20 53 s a name for a S
4ce0: 51 4c 69 74 65 20 72 65 74 75 72 6e 20 63 6f 64 QLite return cod
4cf0: 65 2e 0a 2a 2f 0a 73 74 61 74 69 63 20 63 6f 6e e..*/.static con
4d00: 73 74 20 63 68 61 72 20 2a 66 6f 73 73 69 6c 5f st char *fossil_
4d10: 73 71 6c 69 74 65 5f 72 65 74 75 72 6e 5f 63 6f sqlite_return_co
4d20: 64 65 5f 6e 61 6d 65 28 69 6e 74 20 72 63 29 7b de_name(int rc){
4d30: 0a 20 20 73 74 61 74 69 63 20 63 68 61 72 20 7a . static char z
4d40: 43 6f 64 65 5b 33 30 5d 3b 0a 20 20 73 77 69 74 Code[30];. swit
4d50: 63 68 28 20 72 63 20 26 20 30 78 66 66 20 29 7b ch( rc & 0xff ){
4d60: 0a 20 20 20 20 63 61 73 65 20 53 51 4c 49 54 45 . case SQLITE
4d70: 5f 4f 4b 3a 20 20 20 20 20 20 20 20 20 72 65 74 _OK: ret
4d80: 75 72 6e 20 22 53 51 4c 49 54 45 5f 4f 4b 22 3b urn "SQLITE_OK";
4d90: 0a 20 20 20 20 63 61 73 65 20 53 51 4c 49 54 45 . case SQLITE
4da0: 5f 45 52 52 4f 52 3a 20 20 20 20 20 20 72 65 74 _ERROR: ret
4db0: 75 72 6e 20 22 53 51 4c 49 54 45 5f 45 52 52 4f urn "SQLITE_ERRO
4dc0: 52 22 3b 0a 20 20 20 20 63 61 73 65 20 53 51 4c R";. case SQL
4dd0: 49 54 45 5f 49 4e 54 45 52 4e 41 4c 3a 20 20 20 ITE_INTERNAL:
4de0: 72 65 74 75 72 6e 20 22 53 51 4c 49 54 45 5f 49 return "SQLITE_I
4df0: 4e 54 45 52 4e 41 4c 22 3b 0a 20 20 20 20 63 61 NTERNAL";. ca
4e00: 73 65 20 53 51 4c 49 54 45 5f 50 45 52 4d 3a 20 se SQLITE_PERM:
4e10: 20 20 20 20 20 20 72 65 74 75 72 6e 20 22 53 51 return "SQ
4e20: 4c 49 54 45 5f 50 45 52 4d 22 3b 0a 20 20 20 20 LITE_PERM";.
4e30: 63 61 73 65 20 53 51 4c 49 54 45 5f 41 42 4f 52 case SQLITE_ABOR
4e40: 54 3a 20 20 20 20 20 20 72 65 74 75 72 6e 20 22 T: return "
4e50: 53 51 4c 49 54 45 5f 41 42 4f 52 54 22 3b 0a 20 SQLITE_ABORT";.
4e60: 20 20 20 63 61 73 65 20 53 51 4c 49 54 45 5f 42 case SQLITE_B
4e70: 55 53 59 3a 20 20 20 20 20 20 20 72 65 74 75 72 USY: retur
4e80: 6e 20 22 53 51 4c 49 54 45 5f 42 55 53 59 22 3b n "SQLITE_BUSY";
4e90: 0a 20 20 20 20 63 61 73 65 20 53 51 4c 49 54 45 . case SQLITE
4ea0: 5f 4c 4f 43 4b 45 44 3a 20 20 20 20 20 72 65 74 _LOCKED: ret
4eb0: 75 72 6e 20 22 53 51 4c 49 54 45 5f 4c 4f 43 4b urn "SQLITE_LOCK
4ec0: 45 44 22 3b 0a 20 20 20 20 63 61 73 65 20 53 51 ED";. case SQ
4ed0: 4c 49 54 45 5f 4e 4f 4d 45 4d 3a 20 20 20 20 20 LITE_NOMEM:
4ee0: 20 72 65 74 75 72 6e 20 22 53 51 4c 49 54 45 5f return "SQLITE_
4ef0: 4e 4f 4d 45 4d 22 3b 0a 20 20 20 20 63 61 73 65 NOMEM";. case
4f00: 20 53 51 4c 49 54 45 5f 52 45 41 44 4f 4e 4c 59 SQLITE_READONLY
4f10: 3a 20 20 20 72 65 74 75 72 6e 20 22 53 51 4c 49 : return "SQLI
4f20: 54 45 5f 52 45 41 44 4f 4e 4c 59 22 3b 0a 20 20 TE_READONLY";.
4f30: 20 20 63 61 73 65 20 53 51 4c 49 54 45 5f 49 4e case SQLITE_IN
4f40: 54 45 52 52 55 50 54 3a 20 20 72 65 74 75 72 6e TERRUPT: return
4f50: 20 22 53 51 4c 49 54 45 5f 49 4e 54 45 52 52 55 "SQLITE_INTERRU
4f60: 50 54 22 3b 0a 20 20 20 20 63 61 73 65 20 53 51 PT";. case SQ
4f70: 4c 49 54 45 5f 49 4f 45 52 52 3a 20 20 20 20 20 LITE_IOERR:
4f80: 20 72 65 74 75 72 6e 20 22 53 51 4c 49 54 45 5f return "SQLITE_
4f90: 49 4f 45 52 52 22 3b 0a 20 20 20 20 63 61 73 65 IOERR";. case
4fa0: 20 53 51 4c 49 54 45 5f 43 4f 52 52 55 50 54 3a SQLITE_CORRUPT:
4fb0: 20 20 20 20 72 65 74 75 72 6e 20 22 53 51 4c 49 return "SQLI
4fc0: 54 45 5f 43 4f 52 52 55 50 54 22 3b 0a 20 20 20 TE_CORRUPT";.
4fd0: 20 63 61 73 65 20 53 51 4c 49 54 45 5f 4e 4f 54 case SQLITE_NOT
4fe0: 46 4f 55 4e 44 3a 20 20 20 72 65 74 75 72 6e 20 FOUND: return
4ff0: 22 53 51 4c 49 54 45 5f 4e 4f 54 46 4f 55 4e 44 "SQLITE_NOTFOUND
5000: 22 3b 0a 20 20 20 20 63 61 73 65 20 53 51 4c 49 ";. case SQLI
5010: 54 45 5f 46 55 4c 4c 3a 20 20 20 20 20 20 20 72 TE_FULL: r
5020: 65 74 75 72 6e 20 22 53 51 4c 49 54 45 5f 46 55 eturn "SQLITE_FU
5030: 4c 4c 22 3b 0a 20 20 20 20 63 61 73 65 20 53 51 LL";. case SQ
5040: 4c 49 54 45 5f 43 41 4e 54 4f 50 45 4e 3a 20 20 LITE_CANTOPEN:
5050: 20 72 65 74 75 72 6e 20 22 53 51 4c 49 54 45 5f return "SQLITE_
5060: 43 41 4e 54 4f 50 45 4e 22 3b 0a 20 20 20 20 63 CANTOPEN";. c
5070: 61 73 65 20 53 51 4c 49 54 45 5f 50 52 4f 54 4f ase SQLITE_PROTO
5080: 43 4f 4c 3a 20 20 20 72 65 74 75 72 6e 20 22 53 COL: return "S
5090: 51 4c 49 54 45 5f 50 52 4f 54 4f 43 4f 4c 22 3b QLITE_PROTOCOL";
50a0: 0a 20 20 20 20 63 61 73 65 20 53 51 4c 49 54 45 . case SQLITE
50b0: 5f 45 4d 50 54 59 3a 20 20 20 20 20 20 72 65 74 _EMPTY: ret
50c0: 75 72 6e 20 22 53 51 4c 49 54 45 5f 45 4d 50 54 urn "SQLITE_EMPT
50d0: 59 22 3b 0a 20 20 20 20 63 61 73 65 20 53 51 4c Y";. case SQL
50e0: 49 54 45 5f 53 43 48 45 4d 41 3a 20 20 20 20 20 ITE_SCHEMA:
50f0: 72 65 74 75 72 6e 20 22 53 51 4c 49 54 45 5f 53 return "SQLITE_S
5100: 43 48 45 4d 41 22 3b 0a 20 20 20 20 63 61 73 65 CHEMA";. case
5110: 20 53 51 4c 49 54 45 5f 54 4f 4f 42 49 47 3a 20 SQLITE_TOOBIG:
5120: 20 20 20 20 72 65 74 75 72 6e 20 22 53 51 4c 49 return "SQLI
5130: 54 45 5f 54 4f 4f 42 49 47 22 3b 0a 20 20 20 20 TE_TOOBIG";.
5140: 63 61 73 65 20 53 51 4c 49 54 45 5f 43 4f 4e 53 case SQLITE_CONS
5150: 54 52 41 49 4e 54 3a 20 72 65 74 75 72 6e 20 22 TRAINT: return "
5160: 53 51 4c 49 54 45 5f 43 4f 4e 53 54 52 41 49 4e SQLITE_CONSTRAIN
5170: 54 22 3b 0a 20 20 20 20 63 61 73 65 20 53 51 4c T";. case SQL
5180: 49 54 45 5f 4d 49 53 4d 41 54 43 48 3a 20 20 20 ITE_MISMATCH:
5190: 72 65 74 75 72 6e 20 22 53 51 4c 49 54 45 5f 4d return "SQLITE_M
51a0: 49 53 4d 41 54 43 48 22 3b 0a 20 20 20 20 63 61 ISMATCH";. ca
51b0: 73 65 20 53 51 4c 49 54 45 5f 4d 49 53 55 53 45 se SQLITE_MISUSE
51c0: 3a 20 20 20 20 20 72 65 74 75 72 6e 20 22 53 51 : return "SQ
51d0: 4c 49 54 45 5f 4d 49 53 55 53 45 22 3b 0a 20 20 LITE_MISUSE";.
51e0: 20 20 63 61 73 65 20 53 51 4c 49 54 45 5f 4e 4f case SQLITE_NO
51f0: 4c 46 53 3a 20 20 20 20 20 20 72 65 74 75 72 6e LFS: return
5200: 20 22 53 51 4c 49 54 45 5f 4e 4f 4c 46 53 22 3b "SQLITE_NOLFS";
5210: 0a 20 20 20 20 63 61 73 65 20 53 51 4c 49 54 45 . case SQLITE
5220: 5f 41 55 54 48 3a 20 20 20 20 20 20 20 72 65 74 _AUTH: ret
5230: 75 72 6e 20 22 53 51 4c 49 54 45 5f 41 55 54 48 urn "SQLITE_AUTH
5240: 22 3b 0a 20 20 20 20 63 61 73 65 20 53 51 4c 49 ";. case SQLI
5250: 54 45 5f 46 4f 52 4d 41 54 3a 20 20 20 20 20 72 TE_FORMAT: r
5260: 65 74 75 72 6e 20 22 53 51 4c 49 54 45 5f 46 4f eturn "SQLITE_FO
5270: 52 4d 41 54 22 3b 0a 20 20 20 20 63 61 73 65 20 RMAT";. case
5280: 53 51 4c 49 54 45 5f 52 41 4e 47 45 3a 20 20 20 SQLITE_RANGE:
5290: 20 20 20 72 65 74 75 72 6e 20 22 53 51 4c 49 54 return "SQLIT
52a0: 45 5f 52 41 4e 47 45 22 3b 0a 20 20 20 20 63 61 E_RANGE";. ca
52b0: 73 65 20 53 51 4c 49 54 45 5f 4e 4f 54 41 44 42 se SQLITE_NOTADB
52c0: 3a 20 20 20 20 20 72 65 74 75 72 6e 20 22 53 51 : return "SQ
52d0: 4c 49 54 45 5f 4e 4f 54 41 44 42 22 3b 0a 20 20 LITE_NOTADB";.
52e0: 20 20 63 61 73 65 20 53 51 4c 49 54 45 5f 4e 4f case SQLITE_NO
52f0: 54 49 43 45 3a 20 20 20 20 20 72 65 74 75 72 6e TICE: return
5300: 20 22 53 51 4c 49 54 45 5f 4e 4f 54 49 43 45 22 "SQLITE_NOTICE"
5310: 3b 0a 20 20 20 20 63 61 73 65 20 53 51 4c 49 54 ;. case SQLIT
5320: 45 5f 57 41 52 4e 49 4e 47 3a 20 20 20 20 72 65 E_WARNING: re
5330: 74 75 72 6e 20 22 53 51 4c 49 54 45 5f 57 41 52 turn "SQLITE_WAR
5340: 4e 49 4e 47 22 3b 0a 20 20 20 20 63 61 73 65 20 NING";. case
5350: 53 51 4c 49 54 45 5f 52 4f 57 3a 20 20 20 20 20 SQLITE_ROW:
5360: 20 20 20 72 65 74 75 72 6e 20 22 53 51 4c 49 54 return "SQLIT
5370: 45 5f 52 4f 57 22 3b 0a 20 20 20 20 63 61 73 65 E_ROW";. case
5380: 20 53 51 4c 49 54 45 5f 44 4f 4e 45 3a 20 20 20 SQLITE_DONE:
5390: 20 20 20 20 72 65 74 75 72 6e 20 22 53 51 4c 49 return "SQLI
53a0: 54 45 5f 44 4f 4e 45 22 3b 0a 20 20 20 20 64 65 TE_DONE";. de
53b0: 66 61 75 6c 74 3a 20 7b 0a 20 20 20 20 20 20 73 fault: {. s
53c0: 71 6c 69 74 65 33 5f 73 6e 70 72 69 6e 74 66 28 qlite3_snprintf(
53d0: 73 69 7a 65 6f 66 28 7a 43 6f 64 65 29 2c 20 7a sizeof(zCode), z
53e0: 43 6f 64 65 2c 20 22 53 51 4c 69 74 65 20 72 65 Code, "SQLite re
53f0: 74 75 72 6e 20 63 6f 64 65 20 25 64 22 2c 20 72 turn code %d", r
5400: 63 29 3b 0a 20 20 20 20 7d 0a 20 20 7d 0a 20 20 c);. }. }.
5410: 72 65 74 75 72 6e 20 7a 43 6f 64 65 3b 0a 7d 0a return zCode;.}.
5420: 0a 2f 2a 20 45 72 72 6f 72 20 6c 6f 67 73 20 66 ./* Error logs f
5430: 72 6f 6d 20 53 51 4c 69 74 65 20 2a 2f 0a 73 74 rom SQLite */.st
5440: 61 74 69 63 20 76 6f 69 64 20 66 6f 73 73 69 6c atic void fossil
5450: 5f 73 71 6c 69 74 65 5f 6c 6f 67 28 76 6f 69 64 _sqlite_log(void
5460: 20 2a 6e 6f 74 55 73 65 64 2c 20 69 6e 74 20 69 *notUsed, int i
5470: 43 6f 64 65 2c 20 63 6f 6e 73 74 20 63 68 61 72 Code, const char
5480: 20 2a 7a 45 72 72 6d 73 67 29 7b 0a 23 69 66 64 *zErrmsg){.#ifd
5490: 65 66 20 5f 5f 41 50 50 4c 45 5f 5f 0a 20 20 2f ef __APPLE__. /
54a0: 2a 20 44 69 73 61 62 6c 65 20 74 68 65 20 66 69 * Disable the fi
54b0: 6c 65 20 61 6c 69 61 73 20 77 61 72 6e 69 6e 67 le alias warning
54c0: 20 6f 6e 20 61 70 70 6c 65 20 70 72 6f 64 75 63 on apple produc
54d0: 74 73 20 62 65 63 61 75 73 65 20 54 69 6d 65 20 ts because Time
54e0: 4d 61 63 68 69 6e 65 0a 20 20 2a 2a 20 63 72 65 Machine. ** cre
54f0: 61 74 65 73 20 6c 6f 74 73 20 6f 66 20 61 6c 69 ates lots of ali
5500: 61 73 65 73 20 61 6e 64 20 74 68 65 20 77 61 72 ases and the war
5510: 6e 69 6e 67 20 61 6c 61 72 6d 73 20 70 65 6f 70 ning alarms peop
5520: 6c 65 2e 20 2a 2f 0a 20 20 69 66 28 20 69 43 6f le. */. if( iCo
5530: 64 65 3d 3d 53 51 4c 49 54 45 5f 57 41 52 4e 49 de==SQLITE_WARNI
5540: 4e 47 20 29 20 72 65 74 75 72 6e 3b 0a 23 65 6e NG ) return;.#en
5550: 64 69 66 0a 20 20 69 66 28 20 69 43 6f 64 65 3d dif. if( iCode=
5560: 3d 53 51 4c 49 54 45 5f 53 43 48 45 4d 41 20 29 =SQLITE_SCHEMA )
5570: 20 72 65 74 75 72 6e 3b 0a 20 20 66 6f 73 73 69 return;. fossi
5580: 6c 5f 77 61 72 6e 69 6e 67 28 22 25 73 3a 20 25 l_warning("%s: %
5590: 73 22 2c 20 66 6f 73 73 69 6c 5f 73 71 6c 69 74 s", fossil_sqlit
55a0: 65 5f 72 65 74 75 72 6e 5f 63 6f 64 65 5f 6e 61 e_return_code_na
55b0: 6d 65 28 69 43 6f 64 65 29 2c 20 7a 45 72 72 6d me(iCode), zErrm
55c0: 73 67 29 3b 0a 7d 0a 0a 2f 2a 0a 2a 2a 20 54 68 sg);.}../*.** Th
55d0: 69 73 20 66 75 6e 63 74 69 6f 6e 20 61 74 74 65 is function atte
55e0: 6d 70 74 73 20 74 6f 20 66 69 6e 64 20 63 6f 6d mpts to find com
55f0: 6d 61 6e 64 20 6c 69 6e 65 20 6f 70 74 69 6f 6e mand line option
5600: 73 20 6b 6e 6f 77 6e 20 74 6f 20 63 6f 6e 74 61 s known to conta
5610: 69 6e 0a 2a 2a 20 62 69 74 77 69 73 65 20 66 6c in.** bitwise fl
5620: 61 67 73 20 61 6e 64 20 69 6e 69 74 69 61 6c 69 ags and initiali
5630: 7a 65 73 20 74 68 65 20 61 73 73 6f 63 69 61 74 zes the associat
5640: 65 64 20 67 6c 6f 62 61 6c 20 76 61 72 69 61 62 ed global variab
5650: 6c 65 73 2e 20 20 41 66 74 65 72 0a 2a 2a 20 74 les. After.** t
5660: 68 69 73 20 66 75 6e 63 74 69 6f 6e 20 65 78 65 his function exe
5670: 63 75 74 65 73 2c 20 61 6c 6c 20 67 6c 6f 62 61 cutes, all globa
5680: 6c 20 76 61 72 69 61 62 6c 65 73 20 28 69 2e 65 l variables (i.e
5690: 2e 20 69 6e 20 74 68 65 20 22 67 22 20 73 74 72 . in the "g" str
56a0: 75 63 74 29 0a 2a 2a 20 63 6f 6e 74 61 69 6e 69 uct).** containi
56b0: 6e 67 20 6f 70 74 69 6f 6e 2d 73 65 74 74 61 62 ng option-settab
56c0: 6c 65 20 62 69 74 77 69 73 65 20 66 6c 61 67 20 le bitwise flag
56d0: 66 69 65 6c 64 73 20 6d 75 73 74 20 62 65 20 69 fields must be i
56e0: 6e 69 74 69 61 6c 69 7a 65 64 2e 0a 2a 2f 0a 73 nitialized..*/.s
56f0: 74 61 74 69 63 20 76 6f 69 64 20 66 6f 73 73 69 tatic void fossi
5700: 6c 5f 69 6e 69 74 5f 66 6c 61 67 73 5f 66 72 6f l_init_flags_fro
5710: 6d 5f 6f 70 74 69 6f 6e 73 28 76 6f 69 64 29 7b m_options(void){
5720: 0a 20 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a . const char *z
5730: 56 61 6c 75 65 20 3d 20 66 69 6e 64 5f 6f 70 74 Value = find_opt
5740: 69 6f 6e 28 22 63 6f 6d 66 6d 74 66 6c 61 67 73 ion("comfmtflags
5750: 22 2c 20 30 2c 20 31 29 3b 0a 20 20 69 66 28 20 ", 0, 1);. if(
5760: 7a 56 61 6c 75 65 20 29 7b 0a 20 20 20 20 67 2e zValue ){. g.
5770: 63 6f 6d 46 6d 74 46 6c 61 67 73 20 3d 20 61 74 comFmtFlags = at
5780: 6f 69 28 7a 56 61 6c 75 65 29 3b 0a 20 20 7d 65 oi(zValue);. }e
5790: 6c 73 65 7b 0a 20 20 20 20 67 2e 63 6f 6d 46 6d lse{. g.comFm
57a0: 74 46 6c 61 67 73 20 3d 20 43 4f 4d 4d 45 4e 54 tFlags = COMMENT
57b0: 5f 50 52 49 4e 54 5f 44 45 46 41 55 4c 54 3b 0a _PRINT_DEFAULT;.
57c0: 20 20 7d 0a 7d 0a 0a 2f 2a 0a 2a 2a 20 54 68 69 }.}../*.** Thi
57d0: 73 20 70 72 6f 63 65 64 75 72 65 20 72 75 6e 73 s procedure runs
57e0: 20 66 69 72 73 74 2e 0a 2a 2f 0a 23 69 66 20 64 first..*/.#if d
57f0: 65 66 69 6e 65 64 28 5f 57 49 4e 33 32 29 20 26 efined(_WIN32) &
5800: 26 20 21 64 65 66 69 6e 65 64 28 42 52 4f 4b 45 & !defined(BROKE
5810: 4e 5f 4d 49 4e 47 57 5f 43 4d 44 4c 49 4e 45 29 N_MINGW_CMDLINE)
5820: 0a 69 6e 74 20 5f 64 6f 77 69 6c 64 63 61 72 64 .int _dowildcard
5830: 20 3d 20 2d 31 3b 20 2f 2a 20 54 68 69 73 20 74 = -1; /* This t
5840: 75 72 6e 73 20 6f 6e 20 63 6f 6d 6d 61 6e 64 2d urns on command-
5850: 6c 69 6e 65 20 67 6c 6f 62 62 69 6e 67 20 69 6e line globbing in
5860: 20 4d 69 6e 47 57 2d 77 36 34 20 2a 2f 0a 69 6e MinGW-w64 */.in
5870: 74 20 77 6d 61 69 6e 28 69 6e 74 20 61 72 67 63 t wmain(int argc
5880: 2c 20 77 63 68 61 72 5f 74 20 2a 2a 61 72 67 76 , wchar_t **argv
5890: 29 0a 23 65 6c 73 65 0a 23 69 66 20 64 65 66 69 ).#else.#if defi
58a0: 6e 65 64 28 5f 57 49 4e 33 32 29 0a 69 6e 74 20 ned(_WIN32).int
58b0: 5f 43 52 54 5f 67 6c 6f 62 20 3d 20 30 78 30 30 _CRT_glob = 0x00
58c0: 30 31 3b 20 2f 2a 20 53 65 65 20 4d 69 6e 47 57 01; /* See MinGW
58d0: 20 62 75 67 20 23 32 30 36 32 20 2a 2f 0a 23 65 bug #2062 */.#e
58e0: 6e 64 69 66 0a 69 6e 74 20 6d 61 69 6e 28 69 6e ndif.int main(in
58f0: 74 20 61 72 67 63 2c 20 63 68 61 72 20 2a 2a 61 t argc, char **a
5900: 72 67 76 29 0a 23 65 6e 64 69 66 0a 7b 0a 20 20 rgv).#endif.{.
5910: 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a 43 6d 64 const char *zCmd
5920: 4e 61 6d 65 20 3d 20 22 75 6e 6b 6e 6f 77 6e 22 Name = "unknown"
5930: 3b 0a 20 20 69 6e 74 20 69 64 78 3b 0a 20 20 69 ;. int idx;. i
5940: 6e 74 20 72 63 3b 0a 20 20 69 66 28 20 73 71 6c nt rc;. if( sql
5950: 69 74 65 33 5f 6c 69 62 76 65 72 73 69 6f 6e 5f ite3_libversion_
5960: 6e 75 6d 62 65 72 28 29 3c 33 30 31 30 30 30 30 number()<3010000
5970: 20 29 7b 0a 20 20 20 20 66 6f 73 73 69 6c 5f 66 ){. fossil_f
5980: 61 74 61 6c 28 22 55 6e 73 75 69 74 61 62 6c 65 atal("Unsuitable
5990: 20 53 51 4c 69 74 65 20 76 65 72 73 69 6f 6e 20 SQLite version
59a0: 25 73 2c 20 6d 75 73 74 20 62 65 20 61 74 20 6c %s, must be at l
59b0: 65 61 73 74 20 33 2e 31 30 2e 30 22 2c 0a 20 20 east 3.10.0",.
59c0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 73 s
59d0: 71 6c 69 74 65 33 5f 6c 69 62 76 65 72 73 69 6f qlite3_libversio
59e0: 6e 28 29 29 3b 0a 20 20 7d 0a 20 20 73 71 6c 69 n());. }. sqli
59f0: 74 65 33 5f 63 6f 6e 66 69 67 28 53 51 4c 49 54 te3_config(SQLIT
5a00: 45 5f 43 4f 4e 46 49 47 5f 4d 55 4c 54 49 54 48 E_CONFIG_MULTITH
5a10: 52 45 41 44 29 3b 0a 20 20 73 71 6c 69 74 65 33 READ);. sqlite3
5a20: 5f 63 6f 6e 66 69 67 28 53 51 4c 49 54 45 5f 43 _config(SQLITE_C
5a30: 4f 4e 46 49 47 5f 4c 4f 47 2c 20 66 6f 73 73 69 ONFIG_LOG, fossi
5a40: 6c 5f 73 71 6c 69 74 65 5f 6c 6f 67 2c 20 30 29 l_sqlite_log, 0)
5a50: 3b 0a 20 20 6d 65 6d 73 65 74 28 26 67 2c 20 30 ;. memset(&g, 0
5a60: 2c 20 73 69 7a 65 6f 66 28 67 29 29 3b 0a 20 20 , sizeof(g));.
5a70: 67 2e 6e 6f 77 20 3d 20 74 69 6d 65 28 30 29 3b g.now = time(0);
5a80: 0a 20 20 67 2e 68 74 74 70 48 65 61 64 65 72 20 . g.httpHeader
5a90: 3d 20 65 6d 70 74 79 5f 62 6c 6f 62 3b 0a 23 69 = empty_blob;.#i
5aa0: 66 64 65 66 20 46 4f 53 53 49 4c 5f 45 4e 41 42 fdef FOSSIL_ENAB
5ab0: 4c 45 5f 4a 53 4f 4e 0a 23 69 66 20 64 65 66 69 LE_JSON.#if defi
5ac0: 6e 65 64 28 4e 44 45 42 55 47 29 0a 20 20 67 2e ned(NDEBUG). g.
5ad0: 6a 73 6f 6e 2e 65 72 72 6f 72 44 65 74 61 69 6c json.errorDetail
5ae0: 50 61 72 61 6e 6f 69 61 20 3d 20 32 20 2f 2a 20 Paranoia = 2 /*
5af0: 46 49 58 4d 45 3a 20 6d 61 6b 65 20 63 6f 6e 66 FIXME: make conf
5b00: 69 67 75 72 61 62 6c 65 0a 20 20 20 20 20 20 20 igurable.
5b10: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
5b20: 20 20 20 20 20 20 20 20 20 20 20 20 20 4f 6e 65 One
5b30: 20 70 72 6f 62 6c 65 6d 20 77 65 20 68 61 76 65 problem we have
5b40: 20 68 65 72 65 20 69 73 20 74 68 61 74 20 74 68 here is that th
5b50: 69 73 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 is.
5b60: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
5b70: 20 20 20 20 20 20 20 63 6f 64 65 20 69 73 20 6e code is n
5b80: 65 65 64 65 64 20 62 65 66 6f 72 65 20 74 68 65 eeded before the
5b90: 20 64 62 20 69 73 20 6f 70 65 6e 65 64 2c 0a 20 db is opened,.
5ba0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
5bb0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
5bc0: 20 20 20 73 6f 20 77 65 20 63 61 6e 27 74 20 73 so we can't s
5bd0: 71 6c 20 66 6f 72 20 69 74 2e 2a 2f 3b 0a 23 65 ql for it.*/;.#e
5be0: 6c 73 65 0a 20 20 67 2e 6a 73 6f 6e 2e 65 72 72 lse. g.json.err
5bf0: 6f 72 44 65 74 61 69 6c 50 61 72 61 6e 6f 69 61 orDetailParanoia
5c00: 20 3d 20 30 3b 0a 23 65 6e 64 69 66 0a 20 20 67 = 0;.#endif. g
5c10: 2e 6a 73 6f 6e 2e 6f 75 74 4f 70 74 20 3d 20 63 .json.outOpt = c
5c20: 73 6f 6e 5f 6f 75 74 70 75 74 5f 6f 70 74 5f 65 son_output_opt_e
5c30: 6d 70 74 79 3b 0a 20 20 67 2e 6a 73 6f 6e 2e 6f mpty;. g.json.o
5c40: 75 74 4f 70 74 2e 61 64 64 4e 65 77 6c 69 6e 65 utOpt.addNewline
5c50: 20 3d 20 31 3b 0a 20 20 67 2e 6a 73 6f 6e 2e 6f = 1;. g.json.o
5c60: 75 74 4f 70 74 2e 69 6e 64 65 6e 74 61 74 69 6f utOpt.indentatio
5c70: 6e 20 3d 20 31 20 2f 2a 20 69 6e 20 43 47 49 2f n = 1 /* in CGI/
5c80: 73 65 72 76 65 72 20 6d 6f 64 65 20 74 68 69 73 server mode this
5c90: 20 63 61 6e 20 62 65 20 63 6f 6e 66 69 67 75 72 can be configur
5ca0: 65 64 20 2a 2f 3b 0a 23 65 6e 64 69 66 20 2f 2a ed */;.#endif /*
5cb0: 20 46 4f 53 53 49 4c 5f 45 4e 41 42 4c 45 5f 4a FOSSIL_ENABLE_J
5cc0: 53 4f 4e 20 2a 2f 0a 20 20 65 78 70 61 6e 64 5f SON */. expand_
5cd0: 61 72 67 73 5f 6f 70 74 69 6f 6e 28 61 72 67 63 args_option(argc
5ce0: 2c 20 61 72 67 76 29 3b 0a 23 69 66 64 65 66 20 , argv);.#ifdef
5cf0: 46 4f 53 53 49 4c 5f 45 4e 41 42 4c 45 5f 54 43 FOSSIL_ENABLE_TC
5d00: 4c 0a 20 20 6d 65 6d 73 65 74 28 26 67 2e 74 63 L. memset(&g.tc
5d10: 6c 2c 20 30 2c 20 73 69 7a 65 6f 66 28 54 63 6c l, 0, sizeof(Tcl
5d20: 43 6f 6e 74 65 78 74 29 29 3b 0a 20 20 67 2e 74 Context));. g.t
5d30: 63 6c 2e 61 72 67 63 20 3d 20 67 2e 61 72 67 63 cl.argc = g.argc
5d40: 3b 0a 20 20 67 2e 74 63 6c 2e 61 72 67 76 20 3d ;. g.tcl.argv =
5d50: 20 63 6f 70 79 5f 61 72 67 73 28 67 2e 61 72 67 copy_args(g.arg
5d60: 63 2c 20 67 2e 61 72 67 76 29 3b 20 2f 2a 20 73 c, g.argv); /* s
5d70: 61 76 65 20 66 75 6c 6c 20 61 72 67 75 6d 65 6e ave full argumen
5d80: 74 73 20 2a 2f 0a 23 65 6e 64 69 66 0a 20 20 67 ts */.#endif. g
5d90: 2e 6d 61 69 6e 54 69 6d 65 72 49 64 20 3d 20 66 .mainTimerId = f
5da0: 6f 73 73 69 6c 5f 74 69 6d 65 72 5f 73 74 61 72 ossil_timer_star
5db0: 74 28 29 3b 0a 20 20 63 61 70 74 75 72 65 5f 63 t();. capture_c
5dc0: 61 73 65 5f 73 65 6e 73 69 74 69 76 65 5f 6f 70 ase_sensitive_op
5dd0: 74 69 6f 6e 28 29 3b 0a 20 20 67 2e 7a 56 66 73 tion();. g.zVfs
5de0: 4e 61 6d 65 20 3d 20 66 69 6e 64 5f 6f 70 74 69 Name = find_opti
5df0: 6f 6e 28 22 76 66 73 22 2c 30 2c 31 29 3b 0a 20 on("vfs",0,1);.
5e00: 20 69 66 28 20 67 2e 7a 56 66 73 4e 61 6d 65 3d if( g.zVfsName=
5e10: 3d 30 20 29 7b 0a 20 20 20 20 67 2e 7a 56 66 73 =0 ){. g.zVfs
5e20: 4e 61 6d 65 20 3d 20 66 6f 73 73 69 6c 5f 67 65 Name = fossil_ge
5e30: 74 65 6e 76 28 22 46 4f 53 53 49 4c 5f 56 46 53 tenv("FOSSIL_VFS
5e40: 22 29 3b 0a 20 20 7d 0a 20 20 69 66 28 20 67 2e ");. }. if( g.
5e50: 7a 56 66 73 4e 61 6d 65 20 29 7b 0a 20 20 20 20 zVfsName ){.
5e60: 73 71 6c 69 74 65 33 5f 76 66 73 20 2a 70 56 66 sqlite3_vfs *pVf
5e70: 73 20 3d 20 73 71 6c 69 74 65 33 5f 76 66 73 5f s = sqlite3_vfs_
5e80: 66 69 6e 64 28 67 2e 7a 56 66 73 4e 61 6d 65 29 find(g.zVfsName)
5e90: 3b 0a 20 20 20 20 69 66 28 20 70 56 66 73 20 29 ;. if( pVfs )
5ea0: 7b 0a 20 20 20 20 20 20 73 71 6c 69 74 65 33 5f {. sqlite3_
5eb0: 76 66 73 5f 72 65 67 69 73 74 65 72 28 70 56 66 vfs_register(pVf
5ec0: 73 2c 20 31 29 3b 0a 20 20 20 20 7d 65 6c 73 65 s, 1);. }else
5ed0: 7b 0a 20 20 20 20 20 20 66 6f 73 73 69 6c 5f 66 {. fossil_f
5ee0: 61 74 61 6c 28 22 6e 6f 20 73 75 63 68 20 56 46 atal("no such VF
5ef0: 53 3a 20 5c 22 25 73 5c 22 22 2c 20 67 2e 7a 56 S: \"%s\"", g.zV
5f00: 66 73 4e 61 6d 65 29 3b 0a 20 20 20 20 7d 0a 20 fsName);. }.
5f10: 20 7d 0a 20 20 69 66 28 20 66 6f 73 73 69 6c 5f }. if( fossil_
5f20: 67 65 74 65 6e 76 28 22 47 41 54 45 57 41 59 5f getenv("GATEWAY_
5f30: 49 4e 54 45 52 46 41 43 45 22 29 21 3d 30 20 26 INTERFACE")!=0 &
5f40: 26 20 21 66 69 6e 64 5f 6f 70 74 69 6f 6e 28 22 & !find_option("
5f50: 6e 6f 63 67 69 22 2c 20 30 2c 20 30 29 29 7b 0a nocgi", 0, 0)){.
5f60: 20 20 20 20 7a 43 6d 64 4e 61 6d 65 20 3d 20 22 zCmdName = "
5f70: 63 67 69 22 3b 0a 20 20 20 20 67 2e 69 73 48 54 cgi";. g.isHT
5f80: 54 50 20 3d 20 31 3b 0a 20 20 7d 65 6c 73 65 20 TP = 1;. }else
5f90: 69 66 28 20 67 2e 61 72 67 63 3c 32 20 29 7b 0a if( g.argc<2 ){.
5fa0: 20 20 20 20 66 6f 73 73 69 6c 5f 70 72 69 6e 74 fossil_print
5fb0: 28 0a 20 20 20 20 20 20 20 22 55 73 61 67 65 3a (. "Usage:
5fc0: 20 25 73 20 43 4f 4d 4d 41 4e 44 20 2e 2e 2e 5c %s COMMAND ...\
5fd0: 6e 22 0a 20 20 20 20 20 20 20 22 20 20 20 6f 72 n". " or
5fe0: 3a 20 25 73 20 68 65 6c 70 20 20 20 20 20 20 20 : %s help
5ff0: 20 20 20 20 2d 2d 20 66 6f 72 20 61 20 6c 69 73 -- for a lis
6000: 74 20 6f 66 20 63 6f 6d 6d 6f 6e 20 63 6f 6d 6d t of common comm
6010: 61 6e 64 73 5c 6e 22 0a 20 20 20 20 20 20 20 22 ands\n". "
6020: 20 20 20 6f 72 3a 20 25 73 20 68 65 6c 70 20 43 or: %s help C
6030: 4f 4d 4d 41 4e 44 20 20 20 2d 2d 20 66 6f 72 20 OMMAND -- for
6040: 68 65 6c 70 20 77 69 74 68 20 74 68 65 20 6e 61 help with the na
6050: 6d 65 64 20 63 6f 6d 6d 61 6e 64 5c 6e 22 2c 0a med command\n",.
6060: 20 20 20 20 20 20 20 67 2e 61 72 67 76 5b 30 5d g.argv[0]
6070: 2c 20 67 2e 61 72 67 76 5b 30 5d 2c 20 67 2e 61 , g.argv[0], g.a
6080: 72 67 76 5b 30 5d 29 3b 0a 20 20 20 20 66 6f 73 rgv[0]);. fos
6090: 73 69 6c 5f 70 72 69 6e 74 28 0a 20 20 20 20 20 sil_print(.
60a0: 20 22 5c 6e 43 6f 6d 6d 61 6e 64 73 20 61 6e 64 "\nCommands and
60b0: 20 66 69 6c 65 6e 61 6d 65 73 20 6d 61 79 20 62 filenames may b
60c0: 65 20 70 61 73 73 65 64 20 6f 6e 20 74 6f 20 66 e passed on to f
60d0: 6f 73 73 69 6c 20 66 72 6f 6d 20 61 20 66 69 6c ossil from a fil
60e0: 65 5c 6e 22 0a 20 20 20 20 20 20 22 62 79 20 75 e\n". "by u
60f0: 73 69 6e 67 3a 5c 6e 22 0a 20 20 20 20 20 20 22 sing:\n". "
6100: 5c 6e 20 20 20 20 25 73 20 2d 2d 61 72 67 73 20 \n %s --args
6110: 46 49 4c 45 4e 41 4d 45 20 2e 2e 2e 5c 6e 22 2c FILENAME ...\n",
6120: 0a 20 20 20 20 20 20 67 2e 61 72 67 76 5b 30 5d . g.argv[0]
6130: 0a 20 20 20 20 29 3b 0a 20 20 20 20 66 6f 73 73 . );. foss
6140: 69 6c 5f 70 72 69 6e 74 28 0a 20 20 20 20 20 20 il_print(.
6150: 22 5c 6e 45 61 63 68 20 6c 69 6e 65 20 6f 66 20 "\nEach line of
6160: 74 68 65 20 66 69 6c 65 20 69 73 20 61 73 73 75 the file is assu
6170: 6d 65 64 20 74 6f 20 62 65 20 61 20 66 69 6c 65 med to be a file
6180: 6e 61 6d 65 20 75 6e 6c 65 73 73 20 69 74 20 73 name unless it s
6190: 74 61 72 74 73 5c 6e 22 0a 20 20 20 20 20 20 22 tarts\n". "
61a0: 77 69 74 68 20 27 2d 27 20 61 6e 64 20 63 6f 6e with '-' and con
61b0: 74 61 69 6e 73 20 61 20 73 70 61 63 65 2c 20 69 tains a space, i
61c0: 6e 20 77 68 69 63 68 20 63 61 73 65 20 69 74 20 n which case it
61d0: 69 73 20 61 73 73 75 6d 65 64 20 74 6f 20 62 65 is assumed to be
61e0: 5c 6e 22 0a 20 20 20 20 20 20 22 61 6e 6f 74 68 \n". "anoth
61f0: 65 72 20 66 6c 61 67 20 61 6e 64 20 69 73 20 74 er flag and is t
6200: 72 65 61 74 65 64 20 61 73 20 73 75 63 68 2e 20 reated as such.
6210: 2d 2d 61 72 67 73 20 46 49 4c 45 4e 41 4d 45 20 --args FILENAME
6220: 6d 61 79 20 62 65 20 75 73 65 64 5c 6e 22 0a 20 may be used\n".
6230: 20 20 20 20 20 22 69 6e 20 63 6f 6e 6a 75 6e 63 "in conjunc
6240: 74 69 6f 6e 20 77 69 74 68 20 61 6e 79 20 6f 74 tion with any ot
6250: 68 65 72 20 66 6c 61 67 73 2e 5c 6e 22 29 3b 0a her flags.\n");.
6260: 20 20 20 20 66 6f 73 73 69 6c 5f 65 78 69 74 28 fossil_exit(
6270: 31 29 3b 0a 20 20 7d 65 6c 73 65 7b 0a 20 20 20 1);. }else{.
6280: 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a 43 68 const char *zCh
6290: 64 69 72 20 3d 20 66 69 6e 64 5f 6f 70 74 69 6f dir = find_optio
62a0: 6e 28 22 63 68 64 69 72 22 2c 30 2c 31 29 3b 0a n("chdir",0,1);.
62b0: 20 20 20 20 67 2e 69 73 48 54 54 50 20 3d 20 30 g.isHTTP = 0
62c0: 3b 0a 20 20 20 20 67 2e 72 63 76 69 64 20 3d 20 ;. g.rcvid =
62d0: 30 3b 0a 20 20 20 20 67 2e 66 51 75 69 65 74 20 0;. g.fQuiet
62e0: 3d 20 66 69 6e 64 5f 6f 70 74 69 6f 6e 28 22 71 = find_option("q
62f0: 75 69 65 74 22 2c 20 30 2c 20 30 29 21 3d 30 3b uiet", 0, 0)!=0;
6300: 0a 20 20 20 20 67 2e 66 53 71 6c 54 72 61 63 65 . g.fSqlTrace
6310: 20 3d 20 66 69 6e 64 5f 6f 70 74 69 6f 6e 28 22 = find_option("
6320: 73 71 6c 74 72 61 63 65 22 2c 20 30 2c 20 30 29 sqltrace", 0, 0)
6330: 21 3d 30 3b 0a 20 20 20 20 67 2e 66 53 71 6c 53 !=0;. g.fSqlS
6340: 74 61 74 73 20 3d 20 66 69 6e 64 5f 6f 70 74 69 tats = find_opti
6350: 6f 6e 28 22 73 71 6c 73 74 61 74 73 22 2c 20 30 on("sqlstats", 0
6360: 2c 20 30 29 21 3d 30 3b 0a 20 20 20 20 67 2e 66 , 0)!=0;. g.f
6370: 53 79 73 74 65 6d 54 72 61 63 65 20 3d 20 66 69 SystemTrace = fi
6380: 6e 64 5f 6f 70 74 69 6f 6e 28 22 73 79 73 74 65 nd_option("syste
6390: 6d 74 72 61 63 65 22 2c 20 30 2c 20 30 29 21 3d mtrace", 0, 0)!=
63a0: 30 3b 0a 20 20 20 20 67 2e 66 53 73 68 54 72 61 0;. g.fSshTra
63b0: 63 65 20 3d 20 66 69 6e 64 5f 6f 70 74 69 6f 6e ce = find_option
63c0: 28 22 73 73 68 74 72 61 63 65 22 2c 20 30 2c 20 ("sshtrace", 0,
63d0: 30 29 21 3d 30 3b 0a 20 20 20 20 67 2e 66 53 73 0)!=0;. g.fSs
63e0: 68 43 6c 69 65 6e 74 20 3d 20 30 3b 0a 20 20 20 hClient = 0;.
63f0: 20 67 2e 7a 53 73 68 43 6d 64 20 3d 20 30 3b 0a g.zSshCmd = 0;.
6400: 20 20 20 20 69 66 28 20 67 2e 66 53 71 6c 54 72 if( g.fSqlTr
6410: 61 63 65 20 29 20 67 2e 66 53 71 6c 53 74 61 74 ace ) g.fSqlStat
6420: 73 20 3d 20 31 3b 0a 20 20 20 20 67 2e 66 48 74 s = 1;. g.fHt
6430: 74 70 54 72 61 63 65 20 3d 20 66 69 6e 64 5f 6f tpTrace = find_o
6440: 70 74 69 6f 6e 28 22 68 74 74 70 74 72 61 63 65 ption("httptrace
6450: 22 2c 20 30 2c 20 30 29 21 3d 30 3b 0a 23 69 66 ", 0, 0)!=0;.#if
6460: 64 65 66 20 46 4f 53 53 49 4c 5f 45 4e 41 42 4c def FOSSIL_ENABL
6470: 45 5f 54 48 31 5f 48 4f 4f 4b 53 0a 20 20 20 20 E_TH1_HOOKS.
6480: 67 2e 66 4e 6f 54 68 48 6f 6f 6b 20 3d 20 66 69 g.fNoThHook = fi
6490: 6e 64 5f 6f 70 74 69 6f 6e 28 22 6e 6f 2d 74 68 nd_option("no-th
64a0: 2d 68 6f 6f 6b 22 2c 20 30 2c 20 30 29 21 3d 30 -hook", 0, 0)!=0
64b0: 3b 0a 23 65 6e 64 69 66 0a 20 20 20 20 67 2e 66 ;.#endif. g.f
64c0: 41 6e 79 54 72 61 63 65 20 3d 20 67 2e 66 53 71 AnyTrace = g.fSq
64d0: 6c 54 72 61 63 65 7c 67 2e 66 53 79 73 74 65 6d lTrace|g.fSystem
64e0: 54 72 61 63 65 7c 67 2e 66 53 73 68 54 72 61 63 Trace|g.fSshTrac
64f0: 65 7c 67 2e 66 48 74 74 70 54 72 61 63 65 3b 0a e|g.fHttpTrace;.
6500: 20 20 20 20 67 2e 7a 48 74 74 70 41 75 74 68 20 g.zHttpAuth
6510: 3d 20 30 3b 0a 20 20 20 20 67 2e 7a 4c 6f 67 69 = 0;. g.zLogi
6520: 6e 20 3d 20 66 69 6e 64 5f 6f 70 74 69 6f 6e 28 n = find_option(
6530: 22 75 73 65 72 22 2c 20 22 55 22 2c 20 31 29 3b "user", "U", 1);
6540: 0a 20 20 20 20 67 2e 7a 53 53 4c 49 64 65 6e 74 . g.zSSLIdent
6550: 69 74 79 20 3d 20 66 69 6e 64 5f 6f 70 74 69 6f ity = find_optio
6560: 6e 28 22 73 73 6c 2d 69 64 65 6e 74 69 74 79 22 n("ssl-identity"
6570: 2c 20 30 2c 20 31 29 3b 0a 20 20 20 20 67 2e 7a , 0, 1);. g.z
6580: 45 72 72 6c 6f 67 20 3d 20 66 69 6e 64 5f 6f 70 Errlog = find_op
6590: 74 69 6f 6e 28 22 65 72 72 6f 72 6c 6f 67 22 2c tion("errorlog",
65a0: 20 30 2c 20 31 29 3b 0a 20 20 20 20 66 6f 73 73 0, 1);. foss
65b0: 69 6c 5f 69 6e 69 74 5f 66 6c 61 67 73 5f 66 72 il_init_flags_fr
65c0: 6f 6d 5f 6f 70 74 69 6f 6e 73 28 29 3b 0a 20 20 om_options();.
65d0: 20 20 69 66 28 20 66 69 6e 64 5f 6f 70 74 69 6f if( find_optio
65e0: 6e 28 22 75 74 63 22 2c 30 2c 30 29 20 29 20 67 n("utc",0,0) ) g
65f0: 2e 66 54 69 6d 65 46 6f 72 6d 61 74 20 3d 20 31 .fTimeFormat = 1
6600: 3b 0a 20 20 20 20 69 66 28 20 66 69 6e 64 5f 6f ;. if( find_o
6610: 70 74 69 6f 6e 28 22 6c 6f 63 61 6c 74 69 6d 65 ption("localtime
6620: 22 2c 30 2c 30 29 20 29 20 67 2e 66 54 69 6d 65 ",0,0) ) g.fTime
6630: 46 6f 72 6d 61 74 20 3d 20 32 3b 0a 20 20 20 20 Format = 2;.
6640: 69 66 28 20 7a 43 68 64 69 72 20 26 26 20 66 69 if( zChdir && fi
6650: 6c 65 5f 63 68 64 69 72 28 7a 43 68 64 69 72 2c le_chdir(zChdir,
6660: 20 30 29 20 29 7b 0a 20 20 20 20 20 20 66 6f 73 0) ){. fos
6670: 73 69 6c 5f 66 61 74 61 6c 28 22 75 6e 61 62 6c sil_fatal("unabl
6680: 65 20 74 6f 20 63 68 61 6e 67 65 20 64 69 72 65 e to change dire
6690: 63 74 6f 72 69 65 73 20 74 6f 20 25 73 22 2c 20 ctories to %s",
66a0: 7a 43 68 64 69 72 29 3b 0a 20 20 20 20 7d 0a 20 zChdir);. }.
66b0: 20 20 20 69 66 28 20 66 69 6e 64 5f 6f 70 74 69 if( find_opti
66c0: 6f 6e 28 22 68 65 6c 70 22 2c 30 2c 30 29 21 3d on("help",0,0)!=
66d0: 30 20 29 7b 0a 20 20 20 20 20 20 2f 2a 20 49 66 0 ){. /* If
66e0: 20 2d 2d 68 65 6c 70 20 69 73 20 66 6f 75 6e 64 --help is found
66f0: 20 61 6e 79 77 68 65 72 65 20 6f 6e 20 74 68 65 anywhere on the
6700: 20 63 6f 6d 6d 61 6e 64 20 6c 69 6e 65 2c 20 74 command line, t
6710: 72 61 6e 73 6c 61 74 65 20 74 68 65 20 63 6f 6d ranslate the com
6720: 6d 61 6e 64 0a 20 20 20 20 20 20 20 2a 20 74 6f mand. * to
6730: 20 22 66 6f 73 73 69 6c 20 68 65 6c 70 20 63 6d "fossil help cm
6740: 64 6e 61 6d 65 22 20 77 68 65 72 65 20 22 63 6d dname" where "cm
6750: 64 6e 61 6d 65 22 20 69 73 20 74 68 65 20 66 69 dname" is the fi
6760: 72 73 74 20 61 72 67 75 6d 65 6e 74 20 74 68 61 rst argument tha
6770: 74 0a 20 20 20 20 20 20 20 2a 20 64 6f 65 73 20 t. * does
6780: 6e 6f 74 20 62 65 67 69 6e 20 77 69 74 68 20 61 not begin with a
6790: 20 22 2d 22 20 63 68 61 72 61 63 74 65 72 2e 20 "-" character.
67a0: 20 49 66 20 61 6c 6c 20 61 72 67 75 6d 65 6e 74 If all argument
67b0: 73 20 73 74 61 72 74 20 77 69 74 68 20 22 2d 22 s start with "-"
67c0: 2c 0a 20 20 20 20 20 20 20 2a 20 74 72 61 6e 73 ,. * trans
67d0: 6c 61 74 65 20 74 6f 20 22 66 6f 73 73 69 6c 20 late to "fossil
67e0: 68 65 6c 70 20 61 72 67 76 5b 31 5d 20 61 72 67 help argv[1] arg
67f0: 76 5b 32 5d 2e 2e 2e 22 2e 20 2a 2f 0a 20 20 20 v[2]...". */.
6800: 20 20 20 69 6e 74 20 69 2c 20 6e 4e 65 77 41 72 int i, nNewAr
6810: 67 63 3b 0a 20 20 20 20 20 20 63 68 61 72 20 2a gc;. char *
6820: 2a 7a 4e 65 77 41 72 67 76 20 3d 20 66 6f 73 73 *zNewArgv = foss
6830: 69 6c 5f 6d 61 6c 6c 6f 63 28 20 73 69 7a 65 6f il_malloc( sizeo
6840: 66 28 63 68 61 72 2a 29 2a 28 67 2e 61 72 67 63 f(char*)*(g.argc
6850: 2b 32 29 20 29 3b 0a 20 20 20 20 20 20 7a 4e 65 +2) );. zNe
6860: 77 41 72 67 76 5b 30 5d 20 3d 20 67 2e 61 72 67 wArgv[0] = g.arg
6870: 76 5b 30 5d 3b 0a 20 20 20 20 20 20 7a 4e 65 77 v[0];. zNew
6880: 41 72 67 76 5b 31 5d 20 3d 20 22 68 65 6c 70 22 Argv[1] = "help"
6890: 3b 0a 20 20 20 20 20 20 66 6f 72 28 69 3d 31 3b ;. for(i=1;
68a0: 20 69 3c 67 2e 61 72 67 63 3b 20 69 2b 2b 29 7b i<g.argc; i++){
68b0: 0a 20 20 20 20 20 20 20 20 69 66 28 20 67 2e 61 . if( g.a
68c0: 72 67 76 5b 69 5d 5b 30 5d 21 3d 27 2d 27 20 29 rgv[i][0]!='-' )
68d0: 7b 0a 20 20 20 20 20 20 20 20 20 20 6e 4e 65 77 {. nNew
68e0: 41 72 67 63 20 3d 20 33 3b 0a 20 20 20 20 20 20 Argc = 3;.
68f0: 20 20 20 20 7a 4e 65 77 41 72 67 76 5b 32 5d 20 zNewArgv[2]
6900: 3d 20 67 2e 61 72 67 76 5b 69 5d 3b 0a 20 20 20 = g.argv[i];.
6910: 20 20 20 20 20 20 20 7a 4e 65 77 41 72 67 76 5b zNewArgv[
6920: 33 5d 20 3d 20 30 3b 0a 20 20 20 20 20 20 20 20 3] = 0;.
6930: 20 20 62 72 65 61 6b 3b 0a 20 20 20 20 20 20 20 break;.
6940: 20 7d 0a 20 20 20 20 20 20 7d 0a 20 20 20 20 20 }. }.
6950: 20 69 66 28 20 69 3d 3d 67 2e 61 72 67 63 20 29 if( i==g.argc )
6960: 7b 0a 20 20 20 20 20 20 20 20 66 6f 72 28 69 3d {. for(i=
6970: 31 3b 20 69 3c 67 2e 61 72 67 63 3b 20 69 2b 2b 1; i<g.argc; i++
6980: 29 20 7a 4e 65 77 41 72 67 76 5b 69 2b 31 5d 20 ) zNewArgv[i+1]
6990: 3d 20 67 2e 61 72 67 76 5b 69 5d 3b 0a 20 20 20 = g.argv[i];.
69a0: 20 20 20 20 20 6e 4e 65 77 41 72 67 63 20 3d 20 nNewArgc =
69b0: 67 2e 61 72 67 63 2b 31 3b 0a 20 20 20 20 20 20 g.argc+1;.
69c0: 20 20 7a 4e 65 77 41 72 67 76 5b 69 2b 31 5d 20 zNewArgv[i+1]
69d0: 3d 20 30 3b 0a 20 20 20 20 20 20 7d 0a 20 20 20 = 0;. }.
69e0: 20 20 20 67 2e 61 72 67 63 20 3d 20 6e 4e 65 77 g.argc = nNew
69f0: 41 72 67 63 3b 0a 20 20 20 20 20 20 67 2e 61 72 Argc;. g.ar
6a00: 67 76 20 3d 20 7a 4e 65 77 41 72 67 76 3b 0a 20 gv = zNewArgv;.
6a10: 20 20 20 7d 0a 20 20 20 20 7a 43 6d 64 4e 61 6d }. zCmdNam
6a20: 65 20 3d 20 67 2e 61 72 67 76 5b 31 5d 3b 0a 20 e = g.argv[1];.
6a30: 20 7d 0a 23 69 66 6e 64 65 66 20 5f 57 49 4e 33 }.#ifndef _WIN3
6a40: 32 0a 20 20 2f 2a 20 54 68 65 72 65 20 69 73 20 2. /* There is
6a50: 61 20 62 75 67 20 69 6e 20 73 74 75 6e 6e 65 6c a bug in stunnel
6a60: 34 20 69 6e 20 77 68 69 63 68 20 69 74 20 73 6f 4 in which it so
6a70: 6d 65 74 69 6d 65 73 20 73 74 61 72 74 73 20 75 metimes starts u
6a80: 70 20 63 6c 69 65 6e 74 0a 20 20 2a 2a 20 70 72 p client. ** pr
6a90: 6f 63 65 73 73 65 73 20 77 69 74 68 6f 75 74 20 ocesses without
6aa0: 66 69 72 73 74 20 6f 70 65 6e 69 6e 67 20 66 69 first opening fi
6ab0: 6c 65 20 64 65 73 63 72 69 70 74 6f 72 20 32 20 le descriptor 2
6ac0: 28 73 74 61 6e 64 61 72 64 20 65 72 72 6f 72 29 (standard error)
6ad0: 2e 0a 20 20 2a 2a 20 49 66 20 74 68 69 73 20 68 .. ** If this h
6ae0: 61 70 70 65 6e 73 2c 20 61 6e 64 20 61 20 73 75 appens, and a su
6af0: 62 73 65 71 75 65 6e 74 20 6f 70 65 6e 28 29 20 bsequent open()
6b00: 6f 66 20 61 20 64 61 74 61 62 61 73 65 20 72 65 of a database re
6b10: 74 75 72 6e 73 20 66 69 6c 65 0a 20 20 2a 2a 20 turns file. **
6b20: 64 65 73 63 72 69 70 74 6f 72 20 32 2c 20 61 6e descriptor 2, an
6b30: 64 20 74 68 65 6e 20 61 6e 20 61 73 73 65 72 74 d then an assert
6b40: 28 29 20 66 69 72 65 73 20 61 6e 64 20 77 72 69 () fires and wri
6b50: 74 65 73 20 6f 6e 20 66 64 20 32 2c 20 74 68 61 tes on fd 2, tha
6b60: 74 0a 20 20 2a 2a 20 63 61 6e 20 63 6f 72 72 75 t. ** can corru
6b70: 70 74 20 74 68 65 20 64 61 74 61 20 66 69 6c 65 pt the data file
6b80: 2e 20 20 54 6f 20 61 76 6f 69 64 20 74 68 69 73 . To avoid this
6b90: 20 70 72 6f 62 6c 65 6d 2c 20 6d 61 6b 65 20 73 problem, make s
6ba0: 75 72 65 20 6f 70 65 6e 28 29 0a 20 20 2a 2a 20 ure open(). **
6bb0: 77 69 6c 6c 20 6e 65 76 65 72 20 72 65 74 75 72 will never retur
6bc0: 6e 20 66 69 6c 65 20 64 65 73 63 72 69 70 74 6f n file descripto
6bd0: 72 20 32 20 6f 72 20 6c 65 73 73 2e 20 2a 2f 0a r 2 or less. */.
6be0: 20 20 69 66 28 20 21 69 73 5f 76 61 6c 69 64 5f if( !is_valid_
6bf0: 66 64 28 32 29 20 29 7b 0a 20 20 20 20 69 6e 74 fd(2) ){. int
6c00: 20 6e 54 72 79 20 3d 20 30 3b 0a 20 20 20 20 69 nTry = 0;. i
6c10: 6e 74 20 66 64 20 3d 20 30 3b 0a 20 20 20 20 69 nt fd = 0;. i
6c20: 6e 74 20 78 20 3d 20 30 3b 0a 20 20 20 20 64 6f nt x = 0;. do
6c30: 7b 0a 20 20 20 20 20 20 66 64 20 3d 20 6f 70 65 {. fd = ope
6c40: 6e 28 22 2f 64 65 76 2f 6e 75 6c 6c 22 2c 4f 5f n("/dev/null",O_
6c50: 57 52 4f 4e 4c 59 29 3b 0a 20 20 20 20 20 20 69 WRONLY);. i
6c60: 66 28 20 66 64 3e 3d 32 20 29 20 62 72 65 61 6b f( fd>=2 ) break
6c70: 3b 0a 20 20 20 20 20 20 69 66 28 20 66 64 3c 30 ;. if( fd<0
6c80: 20 29 20 78 20 3d 20 65 72 72 6e 6f 3b 0a 20 20 ) x = errno;.
6c90: 20 20 7d 77 68 69 6c 65 28 20 6e 54 72 79 2b 2b }while( nTry++
6ca0: 20 3c 20 32 20 29 3b 0a 20 20 20 20 69 66 28 20 < 2 );. if(
6cb0: 66 64 3c 32 20 29 7b 0a 20 20 20 20 20 20 67 2e fd<2 ){. g.
6cc0: 63 67 69 4f 75 74 70 75 74 20 3d 20 31 3b 0a 20 cgiOutput = 1;.
6cd0: 20 20 20 20 20 67 2e 68 74 74 70 4f 75 74 20 3d g.httpOut =
6ce0: 20 73 74 64 6f 75 74 3b 0a 20 20 20 20 20 20 67 stdout;. g
6cf0: 2e 66 75 6c 6c 48 74 74 70 52 65 70 6c 79 20 3d .fullHttpReply =
6d00: 20 21 67 2e 69 73 48 54 54 50 3b 0a 20 20 20 20 !g.isHTTP;.
6d10: 20 20 66 6f 73 73 69 6c 5f 66 61 74 61 6c 28 22 fossil_fatal("
6d20: 66 69 6c 65 20 64 65 73 63 72 69 70 74 6f 72 20 file descriptor
6d30: 32 20 69 73 20 6e 6f 74 20 6f 70 65 6e 2e 20 28 2 is not open. (
6d40: 66 64 3d 25 64 2c 20 65 72 72 6e 6f 3d 25 64 29 fd=%d, errno=%d)
6d50: 22 2c 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 ",.
6d60: 20 20 20 20 20 20 66 64 2c 20 78 29 3b 0a 20 20 fd, x);.
6d70: 20 20 7d 0a 20 20 7d 0a 23 65 6e 64 69 66 0a 20 }. }.#endif.
6d80: 20 72 63 20 3d 20 6e 61 6d 65 5f 73 65 61 72 63 rc = name_searc
6d90: 68 28 7a 43 6d 64 4e 61 6d 65 2c 20 61 43 6f 6d h(zCmdName, aCom
6da0: 6d 61 6e 64 2c 20 63 6f 75 6e 74 28 61 43 6f 6d mand, count(aCom
6db0: 6d 61 6e 64 29 2c 20 46 4f 53 53 49 4c 5f 46 49 mand), FOSSIL_FI
6dc0: 52 53 54 5f 43 4d 44 2c 20 26 69 64 78 29 3b 0a RST_CMD, &idx);.
6dd0: 20 20 69 66 28 20 72 63 3d 3d 31 20 29 7b 0a 23 if( rc==1 ){.#
6de0: 69 66 64 65 66 20 46 4f 53 53 49 4c 5f 45 4e 41 ifdef FOSSIL_ENA
6df0: 42 4c 45 5f 54 48 31 5f 48 4f 4f 4b 53 0a 20 20 BLE_TH1_HOOKS.
6e00: 20 20 69 66 28 20 21 67 2e 69 73 48 54 54 50 20 if( !g.isHTTP
6e10: 26 26 20 21 67 2e 66 4e 6f 54 68 48 6f 6f 6b 20 && !g.fNoThHook
6e20: 29 7b 0a 20 20 20 20 20 20 72 63 20 3d 20 54 68 ){. rc = Th
6e30: 5f 43 6f 6d 6d 61 6e 64 48 6f 6f 6b 28 7a 43 6d _CommandHook(zCm
6e40: 64 4e 61 6d 65 2c 20 30 29 3b 0a 20 20 20 20 7d dName, 0);. }
6e50: 65 6c 73 65 7b 0a 20 20 20 20 20 20 72 63 20 3d else{. rc =
6e60: 20 54 48 5f 4f 4b 3b 0a 20 20 20 20 7d 0a 20 20 TH_OK;. }.
6e70: 20 20 69 66 28 20 72 63 3d 3d 54 48 5f 4f 4b 20 if( rc==TH_OK
6e80: 7c 7c 20 72 63 3d 3d 54 48 5f 52 45 54 55 52 4e || rc==TH_RETURN
6e90: 20 7c 7c 20 72 63 3d 3d 54 48 5f 43 4f 4e 54 49 || rc==TH_CONTI
6ea0: 4e 55 45 20 29 7b 0a 20 20 20 20 20 20 69 66 28 NUE ){. if(
6eb0: 20 72 63 3d 3d 54 48 5f 4f 4b 20 7c 7c 20 72 63 rc==TH_OK || rc
6ec0: 3d 3d 54 48 5f 52 45 54 55 52 4e 20 29 7b 0a 23 ==TH_RETURN ){.#
6ed0: 65 6e 64 69 66 0a 20 20 20 20 20 20 20 20 66 6f endif. fo
6ee0: 73 73 69 6c 5f 66 61 74 61 6c 28 22 25 73 3a 20 ssil_fatal("%s:
6ef0: 75 6e 6b 6e 6f 77 6e 20 63 6f 6d 6d 61 6e 64 3a unknown command:
6f00: 20 25 73 5c 6e 22 0a 20 20 20 20 20 20 20 20 20 %s\n".
6f10: 20 20 20 20 20 20 20 20 20 20 20 20 22 25 73 3a "%s:
6f20: 20 75 73 65 20 5c 22 68 65 6c 70 5c 22 20 66 6f use \"help\" fo
6f30: 72 20 6d 6f 72 65 20 69 6e 66 6f 72 6d 61 74 69 r more informati
6f40: 6f 6e 5c 6e 22 2c 0a 20 20 20 20 20 20 20 20 20 on\n",.
6f50: 20 20 20 20 20 20 20 20 20 20 20 20 67 2e 61 72 g.ar
6f60: 67 76 5b 30 5d 2c 20 7a 43 6d 64 4e 61 6d 65 2c gv[0], zCmdName,
6f70: 20 67 2e 61 72 67 76 5b 30 5d 29 3b 0a 23 69 66 g.argv[0]);.#if
6f80: 64 65 66 20 46 4f 53 53 49 4c 5f 45 4e 41 42 4c def FOSSIL_ENABL
6f90: 45 5f 54 48 31 5f 48 4f 4f 4b 53 0a 20 20 20 20 E_TH1_HOOKS.
6fa0: 20 20 7d 0a 20 20 20 20 20 20 69 66 28 20 21 67 }. if( !g
6fb0: 2e 69 73 48 54 54 50 20 26 26 20 21 67 2e 66 4e .isHTTP && !g.fN
6fc0: 6f 54 68 48 6f 6f 6b 20 26 26 20 28 72 63 3d 3d oThHook && (rc==
6fd0: 54 48 5f 4f 4b 20 7c 7c 20 72 63 3d 3d 54 48 5f TH_OK || rc==TH_
6fe0: 43 4f 4e 54 49 4e 55 45 29 20 29 7b 0a 20 20 20 CONTINUE) ){.
6ff0: 20 20 20 20 20 54 68 5f 43 6f 6d 6d 61 6e 64 4e Th_CommandN
7000: 6f 74 69 66 79 28 7a 43 6d 64 4e 61 6d 65 2c 20 otify(zCmdName,
7010: 30 29 3b 0a 20 20 20 20 20 20 7d 0a 20 20 20 20 0);. }.
7020: 7d 0a 20 20 20 20 66 6f 73 73 69 6c 5f 65 78 69 }. fossil_exi
7030: 74 28 30 29 3b 0a 23 65 6e 64 69 66 0a 20 20 7d t(0);.#endif. }
7040: 65 6c 73 65 20 69 66 28 20 72 63 3d 3d 32 20 29 else if( rc==2 )
7050: 7b 0a 20 20 20 20 69 6e 74 20 69 2c 20 6e 3b 0a {. int i, n;.
7060: 20 20 20 20 42 6c 6f 62 20 63 6f 75 6c 64 62 65 Blob couldbe
7070: 3b 0a 20 20 20 20 62 6c 6f 62 5f 7a 65 72 6f 28 ;. blob_zero(
7080: 26 63 6f 75 6c 64 62 65 29 3b 0a 20 20 20 20 6e &couldbe);. n
7090: 20 3d 20 73 74 72 6c 65 6e 28 7a 43 6d 64 4e 61 = strlen(zCmdNa
70a0: 6d 65 29 3b 0a 20 20 20 20 66 6f 72 28 69 3d 30 me);. for(i=0
70b0: 3b 20 69 3c 63 6f 75 6e 74 28 61 43 6f 6d 6d 61 ; i<count(aComma
70c0: 6e 64 29 3b 20 69 2b 2b 29 7b 0a 20 20 20 20 20 nd); i++){.
70d0: 20 69 66 28 20 6d 65 6d 63 6d 70 28 7a 43 6d 64 if( memcmp(zCmd
70e0: 4e 61 6d 65 2c 20 61 43 6f 6d 6d 61 6e 64 5b 69 Name, aCommand[i
70f0: 5d 2e 7a 4e 61 6d 65 2c 20 6e 29 3d 3d 30 20 29 ].zName, n)==0 )
7100: 7b 0a 20 20 20 20 20 20 20 20 62 6c 6f 62 5f 61 {. blob_a
7110: 70 70 65 6e 64 66 28 26 63 6f 75 6c 64 62 65 2c ppendf(&couldbe,
7120: 20 22 20 25 73 22 2c 20 61 43 6f 6d 6d 61 6e 64 " %s", aCommand
7130: 5b 69 5d 2e 7a 4e 61 6d 65 29 3b 0a 20 20 20 20 [i].zName);.
7140: 20 20 7d 0a 20 20 20 20 7d 0a 20 20 20 20 66 6f }. }. fo
7150: 73 73 69 6c 5f 70 72 69 6e 74 28 22 25 73 3a 20 ssil_print("%s:
7160: 61 6d 62 69 67 75 6f 75 73 20 63 6f 6d 6d 61 6e ambiguous comman
7170: 64 20 70 72 65 66 69 78 3a 20 25 73 5c 6e 22 0a d prefix: %s\n".
7180: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
7190: 20 22 25 73 3a 20 63 6f 75 6c 64 20 62 65 20 61 "%s: could be a
71a0: 6e 79 20 6f 66 3a 25 73 5c 6e 22 0a 20 20 20 20 ny of:%s\n".
71b0: 20 20 20 20 20 20 20 20 20 20 20 20 20 22 25 73 "%s
71c0: 3a 20 75 73 65 20 5c 22 68 65 6c 70 5c 22 20 66 : use \"help\" f
71d0: 6f 72 20 6d 6f 72 65 20 69 6e 66 6f 72 6d 61 74 or more informat
71e0: 69 6f 6e 5c 6e 22 2c 0a 20 20 20 20 20 20 20 20 ion\n",.
71f0: 20 20 20 20 20 20 20 20 20 67 2e 61 72 67 76 5b g.argv[
7200: 30 5d 2c 20 7a 43 6d 64 4e 61 6d 65 2c 20 67 2e 0], zCmdName, g.
7210: 61 72 67 76 5b 30 5d 2c 20 62 6c 6f 62 5f 73 74 argv[0], blob_st
7220: 72 28 26 63 6f 75 6c 64 62 65 29 2c 20 67 2e 61 r(&couldbe), g.a
7230: 72 67 76 5b 30 5d 29 3b 0a 20 20 20 20 66 6f 73 rgv[0]);. fos
7240: 73 69 6c 5f 65 78 69 74 28 31 29 3b 0a 20 20 7d sil_exit(1);. }
7250: 0a 20 20 61 74 65 78 69 74 28 20 66 6f 73 73 69 . atexit( fossi
7260: 6c 5f 61 74 65 78 69 74 20 29 3b 0a 23 69 66 64 l_atexit );.#ifd
7270: 65 66 20 46 4f 53 53 49 4c 5f 45 4e 41 42 4c 45 ef FOSSIL_ENABLE
7280: 5f 54 48 31 5f 48 4f 4f 4b 53 0a 20 20 2f 2a 0a _TH1_HOOKS. /*.
7290: 20 20 2a 2a 20 54 68 65 20 54 48 31 20 72 65 74 ** The TH1 ret
72a0: 75 72 6e 20 63 6f 64 65 73 20 66 72 6f 6d 20 74 urn codes from t
72b0: 68 65 20 68 6f 6f 6b 20 77 69 6c 6c 20 62 65 20 he hook will be
72c0: 68 61 6e 64 6c 65 64 20 61 73 20 66 6f 6c 6c 6f handled as follo
72d0: 77 73 3a 0a 20 20 2a 2a 0a 20 20 2a 2a 20 54 48 ws:. **. ** TH
72e0: 5f 4f 4b 3a 20 54 68 65 20 78 46 75 6e 63 28 29 _OK: The xFunc()
72f0: 20 61 6e 64 20 74 68 65 20 54 48 31 20 6e 6f 74 and the TH1 not
7300: 69 66 69 63 61 74 69 6f 6e 20 77 69 6c 6c 20 62 ification will b
7310: 6f 74 68 20 62 65 20 65 78 65 63 75 74 65 64 2e oth be executed.
7320: 0a 20 20 2a 2a 0a 20 20 2a 2a 20 54 48 5f 45 52 . **. ** TH_ER
7330: 52 4f 52 3a 20 54 68 65 20 78 46 75 6e 63 28 29 ROR: The xFunc()
7340: 20 77 69 6c 6c 20 62 65 20 65 78 65 63 75 74 65 will be execute
7350: 64 2c 20 74 68 65 20 54 48 31 20 6e 6f 74 69 66 d, the TH1 notif
7360: 69 63 61 74 69 6f 6e 20 77 69 6c 6c 20 62 65 0a ication will be.
7370: 20 20 2a 2a 20 20 20 20 20 20 20 20 20 20 20 73 ** s
7380: 6b 69 70 70 65 64 2e 20 20 49 66 20 74 68 65 20 kipped. If the
7390: 78 46 75 6e 63 28 29 20 69 73 20 62 65 69 6e 67 xFunc() is being
73a0: 20 68 6f 6f 6b 65 64 2c 20 74 68 65 20 65 72 72 hooked, the err
73b0: 6f 72 20 6d 65 73 73 61 67 65 0a 20 20 2a 2a 20 or message. **
73c0: 20 20 20 20 20 20 20 20 20 20 77 69 6c 6c 20 62 will b
73d0: 65 20 65 6d 69 74 74 65 64 2e 0a 20 20 2a 2a 0a e emitted.. **.
73e0: 20 20 2a 2a 20 54 48 5f 42 52 45 41 4b 3a 20 54 ** TH_BREAK: T
73f0: 68 65 20 78 46 75 6e 63 28 29 20 61 6e 64 20 74 he xFunc() and t
7400: 68 65 20 54 48 31 20 6e 6f 74 69 66 69 63 61 74 he TH1 notificat
7410: 69 6f 6e 20 77 69 6c 6c 20 62 6f 74 68 20 62 65 ion will both be
7420: 20 73 6b 69 70 70 65 64 2e 0a 20 20 2a 2a 0a 20 skipped.. **.
7430: 20 2a 2a 20 54 48 5f 52 45 54 55 52 4e 3a 20 54 ** TH_RETURN: T
7440: 68 65 20 78 46 75 6e 63 28 29 20 77 69 6c 6c 20 he xFunc() will
7450: 62 65 20 65 78 65 63 75 74 65 64 2c 20 74 68 65 be executed, the
7460: 20 54 48 31 20 6e 6f 74 69 66 69 63 61 74 69 6f TH1 notificatio
7470: 6e 20 77 69 6c 6c 20 62 65 0a 20 20 2a 2a 20 20 n will be. **
7480: 20 20 20 20 20 20 20 20 20 20 73 6b 69 70 70 65 skippe
7490: 64 2e 0a 20 20 2a 2a 0a 20 20 2a 2a 20 54 48 5f d.. **. ** TH_
74a0: 43 4f 4e 54 49 4e 55 45 3a 20 54 68 65 20 78 46 CONTINUE: The xF
74b0: 75 6e 63 28 29 20 77 69 6c 6c 20 62 65 20 73 6b unc() will be sk
74c0: 69 70 70 65 64 2c 20 74 68 65 20 54 48 31 20 6e ipped, the TH1 n
74d0: 6f 74 69 66 69 63 61 74 69 6f 6e 20 77 69 6c 6c otification will
74e0: 20 62 65 0a 20 20 2a 2a 20 20 20 20 20 20 20 20 be. **
74f0: 20 20 20 20 20 20 65 78 65 63 75 74 65 64 2e 0a executed..
7500: 20 20 2a 2f 0a 20 20 69 66 28 20 21 67 2e 69 73 */. if( !g.is
7510: 48 54 54 50 20 26 26 20 21 67 2e 66 4e 6f 54 68 HTTP && !g.fNoTh
7520: 48 6f 6f 6b 20 29 7b 0a 20 20 20 20 72 63 20 3d Hook ){. rc =
7530: 20 54 68 5f 43 6f 6d 6d 61 6e 64 48 6f 6f 6b 28 Th_CommandHook(
7540: 61 43 6f 6d 6d 61 6e 64 5b 69 64 78 5d 2e 7a 4e aCommand[idx].zN
7550: 61 6d 65 2c 20 61 43 6f 6d 6d 61 6e 64 5b 69 64 ame, aCommand[id
7560: 78 5d 2e 63 6d 64 46 6c 61 67 73 29 3b 0a 20 20 x].cmdFlags);.
7570: 7d 65 6c 73 65 7b 0a 20 20 20 20 72 63 20 3d 20 }else{. rc =
7580: 54 48 5f 4f 4b 3b 0a 20 20 7d 0a 20 20 69 66 28 TH_OK;. }. if(
7590: 20 72 63 3d 3d 54 48 5f 4f 4b 20 7c 7c 20 72 63 rc==TH_OK || rc
75a0: 3d 3d 54 48 5f 52 45 54 55 52 4e 20 7c 7c 20 72 ==TH_RETURN || r
75b0: 63 3d 3d 54 48 5f 43 4f 4e 54 49 4e 55 45 20 29 c==TH_CONTINUE )
75c0: 7b 0a 20 20 20 20 69 66 28 20 72 63 3d 3d 54 48 {. if( rc==TH
75d0: 5f 4f 4b 20 7c 7c 20 72 63 3d 3d 54 48 5f 52 45 _OK || rc==TH_RE
75e0: 54 55 52 4e 20 29 7b 0a 23 65 6e 64 69 66 0a 20 TURN ){.#endif.
75f0: 20 20 20 20 20 61 43 6f 6d 6d 61 6e 64 5b 69 64 aCommand[id
7600: 78 5d 2e 78 46 75 6e 63 28 29 3b 0a 23 69 66 64 x].xFunc();.#ifd
7610: 65 66 20 46 4f 53 53 49 4c 5f 45 4e 41 42 4c 45 ef FOSSIL_ENABLE
7620: 5f 54 48 31 5f 48 4f 4f 4b 53 0a 20 20 20 20 7d _TH1_HOOKS. }
7630: 0a 20 20 20 20 69 66 28 20 21 67 2e 69 73 48 54 . if( !g.isHT
7640: 54 50 20 26 26 20 21 67 2e 66 4e 6f 54 68 48 6f TP && !g.fNoThHo
7650: 6f 6b 20 26 26 20 28 72 63 3d 3d 54 48 5f 4f 4b ok && (rc==TH_OK
7660: 20 7c 7c 20 72 63 3d 3d 54 48 5f 43 4f 4e 54 49 || rc==TH_CONTI
7670: 4e 55 45 29 20 29 7b 0a 20 20 20 20 20 20 54 68 NUE) ){. Th
7680: 5f 43 6f 6d 6d 61 6e 64 4e 6f 74 69 66 79 28 61 _CommandNotify(a
7690: 43 6f 6d 6d 61 6e 64 5b 69 64 78 5d 2e 7a 4e 61 Command[idx].zNa
76a0: 6d 65 2c 20 61 43 6f 6d 6d 61 6e 64 5b 69 64 78 me, aCommand[idx
76b0: 5d 2e 63 6d 64 46 6c 61 67 73 29 3b 0a 20 20 20 ].cmdFlags);.
76c0: 20 7d 0a 20 20 7d 0a 23 65 6e 64 69 66 0a 20 20 }. }.#endif.
76d0: 66 6f 73 73 69 6c 5f 65 78 69 74 28 30 29 3b 0a fossil_exit(0);.
76e0: 20 20 2f 2a 4e 4f 54 5f 52 45 41 43 48 45 44 2a /*NOT_REACHED*
76f0: 2f 0a 20 20 72 65 74 75 72 6e 20 30 3b 0a 7d 0a /. return 0;.}.
7700: 0a 2f 2a 0a 2a 2a 20 50 72 69 6e 74 20 61 20 75 ./*.** Print a u
7710: 73 61 67 65 20 63 6f 6d 6d 65 6e 74 20 61 6e 64 sage comment and
7720: 20 71 75 69 74 0a 2a 2f 0a 76 6f 69 64 20 75 73 quit.*/.void us
7730: 61 67 65 28 63 6f 6e 73 74 20 63 68 61 72 20 2a age(const char *
7740: 7a 46 6f 72 6d 61 74 29 7b 0a 20 20 66 6f 73 73 zFormat){. foss
7750: 69 6c 5f 66 61 74 61 6c 28 22 55 73 61 67 65 3a il_fatal("Usage:
7760: 20 25 73 20 25 73 20 25 73 22 2c 20 67 2e 61 72 %s %s %s", g.ar
7770: 67 76 5b 30 5d 2c 20 67 2e 61 72 67 76 5b 31 5d gv[0], g.argv[1]
7780: 2c 20 7a 46 6f 72 6d 61 74 29 3b 0a 7d 0a 0a 2f , zFormat);.}../
7790: 2a 0a 2a 2a 20 52 65 6d 6f 76 65 20 6e 20 65 6c *.** Remove n el
77a0: 65 6d 65 6e 74 73 20 66 72 6f 6d 20 67 2e 61 72 ements from g.ar
77b0: 67 76 20 62 65 67 69 6e 6e 69 6e 67 20 77 69 74 gv beginning wit
77c0: 68 20 74 68 65 20 69 2d 74 68 20 65 6c 65 6d 65 h the i-th eleme
77d0: 6e 74 2e 0a 2a 2f 0a 73 74 61 74 69 63 20 76 6f nt..*/.static vo
77e0: 69 64 20 72 65 6d 6f 76 65 5f 66 72 6f 6d 5f 61 id remove_from_a
77f0: 72 67 76 28 69 6e 74 20 69 2c 20 69 6e 74 20 6e rgv(int i, int n
7800: 29 7b 0a 20 20 69 6e 74 20 6a 3b 0a 20 20 66 6f ){. int j;. fo
7810: 72 28 6a 3d 69 2b 6e 3b 20 6a 3c 67 2e 61 72 67 r(j=i+n; j<g.arg
7820: 63 3b 20 69 2b 2b 2c 20 6a 2b 2b 29 7b 0a 20 20 c; i++, j++){.
7830: 20 20 67 2e 61 72 67 76 5b 69 5d 20 3d 20 67 2e g.argv[i] = g.
7840: 61 72 67 76 5b 6a 5d 3b 0a 20 20 7d 0a 20 20 67 argv[j];. }. g
7850: 2e 61 72 67 63 20 3d 20 69 3b 0a 7d 0a 0a 0a 2f .argc = i;.}.../
7860: 2a 0a 2a 2a 20 4c 6f 6f 6b 20 66 6f 72 20 61 20 *.** Look for a
7870: 63 6f 6d 6d 61 6e 64 2d 6c 69 6e 65 20 6f 70 74 command-line opt
7880: 69 6f 6e 2e 20 20 49 66 20 70 72 65 73 65 6e 74 ion. If present
7890: 2c 20 72 65 74 75 72 6e 20 61 20 70 6f 69 6e 74 , return a point
78a0: 65 72 2e 0a 2a 2a 20 52 65 74 75 72 6e 20 4e 55 er..** Return NU
78b0: 4c 4c 20 69 66 20 6d 69 73 73 69 6e 67 2e 0a 2a LL if missing..*
78c0: 2a 0a 2a 2a 20 68 61 73 41 72 67 3d 3d 30 20 6d *.** hasArg==0 m
78d0: 65 61 6e 73 20 74 68 65 20 6f 70 74 69 6f 6e 20 eans the option
78e0: 69 73 20 61 20 66 6c 61 67 2e 20 20 49 74 20 69 is a flag. It i
78f0: 73 20 65 69 74 68 65 72 20 70 72 65 73 65 6e 74 s either present
7900: 20 6f 72 20 6e 6f 74 2e 0a 2a 2a 20 68 61 73 41 or not..** hasA
7910: 72 67 3d 3d 31 20 6d 65 61 6e 73 20 74 68 65 20 rg==1 means the
7920: 6f 70 74 69 6f 6e 20 68 61 73 20 61 6e 20 61 72 option has an ar
7930: 67 75 6d 65 6e 74 2e 20 20 52 65 74 75 72 6e 20 gument. Return
7940: 61 20 70 6f 69 6e 74 65 72 20 74 6f 20 74 68 65 a pointer to the
7950: 0a 2a 2a 20 61 72 67 75 6d 65 6e 74 2e 0a 2a 2f .** argument..*/
7960: 0a 63 6f 6e 73 74 20 63 68 61 72 20 2a 66 69 6e .const char *fin
7970: 64 5f 6f 70 74 69 6f 6e 28 63 6f 6e 73 74 20 63 d_option(const c
7980: 68 61 72 20 2a 7a 4c 6f 6e 67 2c 20 63 6f 6e 73 har *zLong, cons
7990: 74 20 63 68 61 72 20 2a 7a 53 68 6f 72 74 2c 20 t char *zShort,
79a0: 69 6e 74 20 68 61 73 41 72 67 29 7b 0a 20 20 69 int hasArg){. i
79b0: 6e 74 20 69 3b 0a 20 20 69 6e 74 20 6e 4c 6f 6e nt i;. int nLon
79c0: 67 3b 0a 20 20 63 6f 6e 73 74 20 63 68 61 72 20 g;. const char
79d0: 2a 7a 52 65 74 75 72 6e 20 3d 20 30 3b 0a 20 20 *zReturn = 0;.
79e0: 61 73 73 65 72 74 28 20 68 61 73 41 72 67 3d 3d assert( hasArg==
79f0: 30 20 7c 7c 20 68 61 73 41 72 67 3d 3d 31 20 29 0 || hasArg==1 )
7a00: 3b 0a 20 20 6e 4c 6f 6e 67 20 3d 20 73 74 72 6c ;. nLong = strl
7a10: 65 6e 28 7a 4c 6f 6e 67 29 3b 0a 20 20 66 6f 72 en(zLong);. for
7a20: 28 69 3d 31 3b 20 69 3c 67 2e 61 72 67 63 3b 20 (i=1; i<g.argc;
7a30: 69 2b 2b 29 7b 0a 20 20 20 20 63 68 61 72 20 2a i++){. char *
7a40: 7a 3b 0a 20 20 20 20 69 66 28 20 69 2b 68 61 73 z;. if( i+has
7a50: 41 72 67 20 3e 3d 20 67 2e 61 72 67 63 20 29 20 Arg >= g.argc )
7a60: 62 72 65 61 6b 3b 0a 20 20 20 20 7a 20 3d 20 67 break;. z = g
7a70: 2e 61 72 67 76 5b 69 5d 3b 0a 20 20 20 20 69 66 .argv[i];. if
7a80: 28 20 7a 5b 30 5d 21 3d 27 2d 27 20 29 20 63 6f ( z[0]!='-' ) co
7a90: 6e 74 69 6e 75 65 3b 0a 20 20 20 20 7a 2b 2b 3b ntinue;. z++;
7aa0: 0a 20 20 20 20 69 66 28 20 7a 5b 30 5d 3d 3d 27 . if( z[0]=='
7ab0: 2d 27 20 29 7b 0a 20 20 20 20 20 20 69 66 28 20 -' ){. if(
7ac0: 7a 5b 31 5d 3d 3d 30 20 29 7b 0a 20 20 20 20 20 z[1]==0 ){.
7ad0: 20 20 20 72 65 6d 6f 76 65 5f 66 72 6f 6d 5f 61 remove_from_a
7ae0: 72 67 76 28 69 2c 20 31 29 3b 0a 20 20 20 20 20 rgv(i, 1);.
7af0: 20 20 20 62 72 65 61 6b 3b 0a 20 20 20 20 20 20 break;.
7b00: 7d 0a 20 20 20 20 20 20 7a 2b 2b 3b 0a 20 20 20 }. z++;.
7b10: 20 7d 0a 20 20 20 20 69 66 28 20 73 74 72 6e 63 }. if( strnc
7b20: 6d 70 28 7a 2c 7a 4c 6f 6e 67 2c 6e 4c 6f 6e 67 mp(z,zLong,nLong
7b30: 29 3d 3d 30 20 29 7b 0a 20 20 20 20 20 20 69 66 )==0 ){. if
7b40: 28 20 68 61 73 41 72 67 20 26 26 20 7a 5b 6e 4c ( hasArg && z[nL
7b50: 6f 6e 67 5d 3d 3d 27 3d 27 20 29 7b 0a 20 20 20 ong]=='=' ){.
7b60: 20 20 20 20 20 7a 52 65 74 75 72 6e 20 3d 20 26 zReturn = &
7b70: 7a 5b 6e 4c 6f 6e 67 2b 31 5d 3b 0a 20 20 20 20 z[nLong+1];.
7b80: 20 20 20 20 72 65 6d 6f 76 65 5f 66 72 6f 6d 5f remove_from_
7b90: 61 72 67 76 28 69 2c 20 31 29 3b 0a 20 20 20 20 argv(i, 1);.
7ba0: 20 20 20 20 62 72 65 61 6b 3b 0a 20 20 20 20 20 break;.
7bb0: 20 7d 65 6c 73 65 20 69 66 28 20 7a 5b 6e 4c 6f }else if( z[nLo
7bc0: 6e 67 5d 3d 3d 30 20 29 7b 0a 20 20 20 20 20 20 ng]==0 ){.
7bd0: 20 20 7a 52 65 74 75 72 6e 20 3d 20 67 2e 61 72 zReturn = g.ar
7be0: 67 76 5b 69 2b 68 61 73 41 72 67 5d 3b 0a 20 20 gv[i+hasArg];.
7bf0: 20 20 20 20 20 20 72 65 6d 6f 76 65 5f 66 72 6f remove_fro
7c00: 6d 5f 61 72 67 76 28 69 2c 20 31 2b 68 61 73 41 m_argv(i, 1+hasA
7c10: 72 67 29 3b 0a 20 20 20 20 20 20 20 20 62 72 65 rg);. bre
7c20: 61 6b 3b 0a 20 20 20 20 20 20 7d 0a 20 20 20 20 ak;. }.
7c30: 7d 65 6c 73 65 20 69 66 28 20 66 6f 73 73 69 6c }else if( fossil
7c40: 5f 73 74 72 63 6d 70 28 7a 2c 7a 53 68 6f 72 74 _strcmp(z,zShort
7c50: 29 3d 3d 30 20 29 7b 0a 20 20 20 20 20 20 7a 52 )==0 ){. zR
7c60: 65 74 75 72 6e 20 3d 20 67 2e 61 72 67 76 5b 69 eturn = g.argv[i
7c70: 2b 68 61 73 41 72 67 5d 3b 0a 20 20 20 20 20 20 +hasArg];.
7c80: 72 65 6d 6f 76 65 5f 66 72 6f 6d 5f 61 72 67 76 remove_from_argv
7c90: 28 69 2c 20 31 2b 68 61 73 41 72 67 29 3b 0a 20 (i, 1+hasArg);.
7ca0: 20 20 20 20 20 62 72 65 61 6b 3b 0a 20 20 20 20 break;.
7cb0: 7d 0a 20 20 7d 0a 20 20 72 65 74 75 72 6e 20 7a }. }. return z
7cc0: 52 65 74 75 72 6e 3b 0a 7d 0a 0a 2f 2a 0a 2a 2a Return;.}../*.**
7cd0: 20 4c 6f 6f 6b 20 66 6f 72 20 6d 75 6c 74 69 70 Look for multip
7ce0: 6c 65 20 6f 63 63 75 72 72 65 6e 63 65 73 20 6f le occurrences o
7cf0: 66 20 61 20 63 6f 6d 6d 61 6e 64 2d 6c 69 6e 65 f a command-line
7d00: 20 6f 70 74 69 6f 6e 20 77 69 74 68 20 74 68 65 option with the
7d10: 0a 2a 2a 20 63 6f 72 72 65 73 70 6f 6e 64 69 6e .** correspondin
7d20: 67 20 61 72 67 75 6d 65 6e 74 2e 0a 2a 2a 0a 2a g argument..**.*
7d30: 2a 20 52 65 74 75 72 6e 20 61 20 6d 61 6c 6c 6f * Return a mallo
7d40: 63 20 61 6c 6c 6f 63 61 74 65 64 20 61 72 72 61 c allocated arra
7d50: 79 20 6f 66 20 70 6f 69 6e 74 65 72 73 20 74 6f y of pointers to
7d60: 20 74 68 65 20 61 72 67 75 6d 65 6e 74 73 2e 0a the arguments..
7d70: 2a 2a 0a 2a 2a 20 70 6e 55 73 65 64 41 72 67 73 **.** pnUsedArgs
7d80: 20 69 73 20 75 73 65 64 20 74 6f 20 73 74 6f 72 is used to stor
7d90: 65 20 74 68 65 20 6e 75 6d 62 65 72 20 6f 66 20 e the number of
7da0: 6d 61 74 63 68 65 64 20 61 72 67 75 6d 65 6e 74 matched argument
7db0: 73 2e 0a 2a 2a 0a 2a 2a 20 43 61 6c 6c 65 72 20 s..**.** Caller
7dc0: 69 73 20 72 65 73 70 6f 6e 73 69 62 6c 65 20 74 is responsible t
7dd0: 6f 20 66 72 65 65 20 61 6c 6c 6f 63 61 74 65 64 o free allocated
7de0: 20 6d 65 6d 6f 72 79 2e 0a 2a 2f 0a 63 6f 6e 73 memory..*/.cons
7df0: 74 20 63 68 61 72 20 2a 2a 66 69 6e 64 5f 72 65 t char **find_re
7e00: 70 65 61 74 61 62 6c 65 5f 6f 70 74 69 6f 6e 28 peatable_option(
7e10: 0a 20 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a . const char *z
7e20: 4c 6f 6e 67 2c 0a 20 20 63 6f 6e 73 74 20 63 68 Long,. const ch
7e30: 61 72 20 2a 7a 53 68 6f 72 74 2c 0a 20 20 69 6e ar *zShort,. in
7e40: 74 20 2a 70 6e 55 73 65 64 41 72 67 73 0a 29 7b t *pnUsedArgs.){
7e50: 0a 20 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a . const char *z
7e60: 4f 70 74 69 6f 6e 3b 0a 20 20 63 6f 6e 73 74 20 Option;. const
7e70: 63 68 61 72 20 2a 2a 70 7a 41 72 67 73 20 3d 20 char **pzArgs =
7e80: 30 3b 0a 20 20 69 6e 74 20 6e 41 6c 6c 6f 63 41 0;. int nAllocA
7e90: 72 67 73 20 3d 20 30 3b 0a 20 20 69 6e 74 20 6e rgs = 0;. int n
7ea0: 55 73 65 64 41 72 67 73 20 3d 20 30 3b 0a 0a 20 UsedArgs = 0;..
7eb0: 20 77 68 69 6c 65 28 20 28 7a 4f 70 74 69 6f 6e while( (zOption
7ec0: 20 3d 20 66 69 6e 64 5f 6f 70 74 69 6f 6e 28 7a = find_option(z
7ed0: 4c 6f 6e 67 2c 20 7a 53 68 6f 72 74 2c 20 31 29 Long, zShort, 1)
7ee0: 29 21 3d 30 20 29 7b 0a 20 20 20 20 69 66 28 20 )!=0 ){. if(
7ef0: 70 7a 41 72 67 73 3d 3d 30 20 26 26 20 6e 41 6c pzArgs==0 && nAl
7f00: 6c 6f 63 41 72 67 73 3d 3d 30 20 29 7b 0a 20 20 locArgs==0 ){.
7f10: 20 20 20 20 6e 41 6c 6c 6f 63 41 72 67 73 20 3d nAllocArgs =
7f20: 20 31 3b 0a 20 20 20 20 20 20 70 7a 41 72 67 73 1;. pzArgs
7f30: 20 3d 20 66 6f 73 73 69 6c 5f 6d 61 6c 6c 6f 63 = fossil_malloc
7f40: 28 20 6e 41 6c 6c 6f 63 41 72 67 73 2a 73 69 7a ( nAllocArgs*siz
7f50: 65 6f 66 28 70 7a 41 72 67 73 5b 30 5d 29 20 29 eof(pzArgs[0]) )
7f60: 3b 0a 20 20 20 20 7d 65 6c 73 65 20 69 66 28 20 ;. }else if(
7f70: 6e 41 6c 6c 6f 63 41 72 67 73 3c 3d 6e 55 73 65 nAllocArgs<=nUse
7f80: 64 41 72 67 73 20 29 7b 0a 20 20 20 20 20 20 6e dArgs ){. n
7f90: 41 6c 6c 6f 63 41 72 67 73 20 3d 20 6e 41 6c 6c AllocArgs = nAll
7fa0: 6f 63 41 72 67 73 2a 32 3b 0a 20 20 20 20 20 20 ocArgs*2;.
7fb0: 70 7a 41 72 67 73 20 3d 20 66 6f 73 73 69 6c 5f pzArgs = fossil_
7fc0: 72 65 61 6c 6c 6f 63 28 20 28 76 6f 69 64 20 2a realloc( (void *
7fd0: 29 70 7a 41 72 67 73 2c 20 6e 41 6c 6c 6f 63 41 )pzArgs, nAllocA
7fe0: 72 67 73 2a 73 69 7a 65 6f 66 28 70 7a 41 72 67 rgs*sizeof(pzArg
7ff0: 73 5b 30 5d 29 20 29 3b 0a 20 20 20 20 7d 0a 20 s[0]) );. }.
8000: 20 20 20 70 7a 41 72 67 73 5b 6e 55 73 65 64 41 pzArgs[nUsedA
8010: 72 67 73 2b 2b 5d 20 3d 20 7a 4f 70 74 69 6f 6e rgs++] = zOption
8020: 3b 0a 20 20 7d 0a 20 20 2a 70 6e 55 73 65 64 41 ;. }. *pnUsedA
8030: 72 67 73 20 3d 20 6e 55 73 65 64 41 72 67 73 3b rgs = nUsedArgs;
8040: 0a 20 20 72 65 74 75 72 6e 20 70 7a 41 72 67 73 . return pzArgs
8050: 3b 0a 7d 0a 0a 2f 2a 0a 2a 2a 20 4c 6f 6f 6b 20 ;.}../*.** Look
8060: 66 6f 72 20 61 20 72 65 70 6f 73 69 74 6f 72 79 for a repository
8070: 20 63 6f 6d 6d 61 6e 64 2d 6c 69 6e 65 20 6f 70 command-line op
8080: 74 69 6f 6e 2e 20 20 49 66 20 70 72 65 73 65 6e tion. If presen
8090: 74 2c 20 5b 72 65 2d 5d 63 61 63 68 65 20 69 74 t, [re-]cache it
80a0: 20 69 6e 0a 2a 2a 20 74 68 65 20 67 6c 6f 62 61 in.** the globa
80b0: 6c 20 73 74 61 74 65 20 61 6e 64 20 72 65 74 75 l state and retu
80c0: 72 6e 20 74 68 65 20 6e 65 77 20 70 6f 69 6e 74 rn the new point
80d0: 65 72 2c 20 66 72 65 65 69 6e 67 20 61 6e 79 20 er, freeing any
80e0: 70 72 65 76 69 6f 75 73 20 76 61 6c 75 65 2e 0a previous value..
80f0: 2a 2a 20 49 66 20 61 62 73 65 6e 74 20 61 6e 64 ** If absent and
8100: 20 74 68 65 72 65 20 69 73 20 6e 6f 20 63 61 63 there is no cac
8110: 68 65 64 20 76 61 6c 75 65 2c 20 72 65 74 75 72 hed value, retur
8120: 6e 20 4e 55 4c 4c 2e 0a 2a 2f 0a 63 6f 6e 73 74 n NULL..*/.const
8130: 20 63 68 61 72 20 2a 66 69 6e 64 5f 72 65 70 6f char *find_repo
8140: 73 69 74 6f 72 79 5f 6f 70 74 69 6f 6e 28 29 7b sitory_option(){
8150: 0a 20 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a . const char *z
8160: 52 65 70 6f 73 69 74 6f 72 79 20 3d 20 66 69 6e Repository = fin
8170: 64 5f 6f 70 74 69 6f 6e 28 22 72 65 70 6f 73 69 d_option("reposi
8180: 74 6f 72 79 22 2c 20 22 52 22 2c 20 31 29 3b 0a tory", "R", 1);.
8190: 20 20 69 66 28 20 7a 52 65 70 6f 73 69 74 6f 72 if( zRepositor
81a0: 79 20 29 7b 0a 20 20 20 20 69 66 28 20 67 2e 7a y ){. if( g.z
81b0: 52 65 70 6f 73 69 74 6f 72 79 4f 70 74 69 6f 6e RepositoryOption
81c0: 20 29 20 66 6f 73 73 69 6c 5f 66 72 65 65 28 67 ) fossil_free(g
81d0: 2e 7a 52 65 70 6f 73 69 74 6f 72 79 4f 70 74 69 .zRepositoryOpti
81e0: 6f 6e 29 3b 0a 20 20 20 20 67 2e 7a 52 65 70 6f on);. g.zRepo
81f0: 73 69 74 6f 72 79 4f 70 74 69 6f 6e 20 3d 20 6d sitoryOption = m
8200: 70 72 69 6e 74 66 28 22 25 73 22 2c 20 7a 52 65 printf("%s", zRe
8210: 70 6f 73 69 74 6f 72 79 29 3b 0a 20 20 7d 0a 20 pository);. }.
8220: 20 72 65 74 75 72 6e 20 67 2e 7a 52 65 70 6f 73 return g.zRepos
8230: 69 74 6f 72 79 4f 70 74 69 6f 6e 3b 0a 7d 0a 0a itoryOption;.}..
8240: 2f 2a 0a 2a 2a 20 56 65 72 69 66 79 20 74 68 61 /*.** Verify tha
8250: 74 20 74 68 65 72 65 20 61 72 65 20 6e 6f 20 75 t there are no u
8260: 6e 70 72 6f 63 65 73 73 65 64 20 63 6f 6d 6d 61 nprocessed comma
8270: 6e 64 2d 6c 69 6e 65 20 6f 70 74 69 6f 6e 73 2e nd-line options.
8280: 20 20 49 66 0a 2a 2a 20 41 6e 79 20 72 65 6d 61 If.** Any rema
8290: 69 6e 69 6e 67 20 63 6f 6d 6d 61 6e 64 2d 6c 69 ining command-li
82a0: 6e 65 20 61 72 67 75 6d 65 6e 74 20 62 65 67 69 ne argument begi
82b0: 6e 73 20 77 69 74 68 20 22 2d 22 20 70 72 69 6e ns with "-" prin
82c0: 74 0a 2a 2a 20 61 6e 20 65 72 72 6f 72 20 6d 65 t.** an error me
82d0: 73 73 61 67 65 20 61 6e 64 20 71 75 69 74 2e 0a ssage and quit..
82e0: 2a 2f 0a 76 6f 69 64 20 76 65 72 69 66 79 5f 61 */.void verify_a
82f0: 6c 6c 5f 6f 70 74 69 6f 6e 73 28 76 6f 69 64 29 ll_options(void)
8300: 7b 0a 20 20 69 6e 74 20 69 3b 0a 20 20 66 6f 72 {. int i;. for
8310: 28 69 3d 31 3b 20 69 3c 67 2e 61 72 67 63 3b 20 (i=1; i<g.argc;
8320: 69 2b 2b 29 7b 0a 20 20 20 20 69 66 28 20 67 2e i++){. if( g.
8330: 61 72 67 76 5b 69 5d 5b 30 5d 3d 3d 27 2d 27 20 argv[i][0]=='-'
8340: 29 7b 0a 20 20 20 20 20 20 66 6f 73 73 69 6c 5f ){. fossil_
8350: 66 61 74 61 6c 28 0a 20 20 20 20 20 20 20 20 22 fatal(. "
8360: 75 6e 72 65 63 6f 67 6e 69 7a 65 64 20 63 6f 6d unrecognized com
8370: 6d 61 6e 64 2d 6c 69 6e 65 20 6f 70 74 69 6f 6e mand-line option
8380: 2c 20 6f 72 20 6d 69 73 73 69 6e 67 20 61 72 67 , or missing arg
8390: 75 6d 65 6e 74 3a 20 25 73 22 2c 0a 20 20 20 20 ument: %s",.
83a0: 20 20 20 20 67 2e 61 72 67 76 5b 69 5d 29 3b 0a g.argv[i]);.
83b0: 20 20 20 20 7d 0a 20 20 7d 0a 7d 0a 0a 2f 2a 0a }. }.}../*.
83c0: 2a 2a 20 50 72 69 6e 74 20 61 20 6c 69 73 74 20 ** Print a list
83d0: 6f 66 20 77 6f 72 64 73 20 69 6e 20 6d 75 6c 74 of words in mult
83e0: 69 70 6c 65 20 63 6f 6c 75 6d 6e 73 2e 0a 2a 2f iple columns..*/
83f0: 0a 73 74 61 74 69 63 20 76 6f 69 64 20 6d 75 6c .static void mul
8400: 74 69 5f 63 6f 6c 75 6d 6e 5f 6c 69 73 74 28 63 ti_column_list(c
8410: 6f 6e 73 74 20 63 68 61 72 20 2a 2a 61 7a 57 6f onst char **azWo
8420: 72 64 2c 20 69 6e 74 20 6e 57 6f 72 64 29 7b 0a rd, int nWord){.
8430: 20 20 69 6e 74 20 69 2c 20 6a 2c 20 6c 65 6e 3b int i, j, len;
8440: 0a 20 20 69 6e 74 20 6d 78 4c 65 6e 20 3d 20 30 . int mxLen = 0
8450: 3b 0a 20 20 69 6e 74 20 6e 43 6f 6c 3b 0a 20 20 ;. int nCol;.
8460: 69 6e 74 20 6e 52 6f 77 3b 0a 20 20 66 6f 72 28 int nRow;. for(
8470: 69 3d 30 3b 20 69 3c 6e 57 6f 72 64 3b 20 69 2b i=0; i<nWord; i+
8480: 2b 29 7b 0a 20 20 20 20 6c 65 6e 20 3d 20 73 74 +){. len = st
8490: 72 6c 65 6e 28 61 7a 57 6f 72 64 5b 69 5d 29 3b rlen(azWord[i]);
84a0: 0a 20 20 20 20 69 66 28 20 6c 65 6e 3e 6d 78 4c . if( len>mxL
84b0: 65 6e 20 29 20 6d 78 4c 65 6e 20 3d 20 6c 65 6e en ) mxLen = len
84c0: 3b 0a 20 20 7d 0a 20 20 6e 43 6f 6c 20 3d 20 38 ;. }. nCol = 8
84d0: 30 2f 28 6d 78 4c 65 6e 2b 32 29 3b 0a 20 20 69 0/(mxLen+2);. i
84e0: 66 28 20 6e 43 6f 6c 3d 3d 30 20 29 20 6e 43 6f f( nCol==0 ) nCo
84f0: 6c 20 3d 20 31 3b 0a 20 20 6e 52 6f 77 20 3d 20 l = 1;. nRow =
8500: 28 6e 57 6f 72 64 20 2b 20 6e 43 6f 6c 20 2d 20 (nWord + nCol -
8510: 31 29 2f 6e 43 6f 6c 3b 0a 20 20 66 6f 72 28 69 1)/nCol;. for(i
8520: 3d 30 3b 20 69 3c 6e 52 6f 77 3b 20 69 2b 2b 29 =0; i<nRow; i++)
8530: 7b 0a 20 20 20 20 63 6f 6e 73 74 20 63 68 61 72 {. const char
8540: 20 2a 7a 53 70 61 63 65 72 20 3d 20 22 22 3b 0a *zSpacer = "";.
8550: 20 20 20 20 66 6f 72 28 6a 3d 69 3b 20 6a 3c 6e for(j=i; j<n
8560: 57 6f 72 64 3b 20 6a 2b 3d 6e 52 6f 77 29 7b 0a Word; j+=nRow){.
8570: 20 20 20 20 20 20 66 6f 73 73 69 6c 5f 70 72 69 fossil_pri
8580: 6e 74 28 22 25 73 25 2d 2a 73 22 2c 20 7a 53 70 nt("%s%-*s", zSp
8590: 61 63 65 72 2c 20 6d 78 4c 65 6e 2c 20 61 7a 57 acer, mxLen, azW
85a0: 6f 72 64 5b 6a 5d 29 3b 0a 20 20 20 20 20 20 7a ord[j]);. z
85b0: 53 70 61 63 65 72 20 3d 20 22 20 20 22 3b 0a 20 Spacer = " ";.
85c0: 20 20 20 7d 0a 20 20 20 20 66 6f 73 73 69 6c 5f }. fossil_
85d0: 70 72 69 6e 74 28 22 5c 6e 22 29 3b 0a 20 20 7d print("\n");. }
85e0: 0a 7d 0a 0a 2f 2a 0a 2a 2a 20 4c 69 73 74 20 6f .}../*.** List o
85f0: 66 20 63 6f 6d 6d 61 6e 64 73 20 73 74 61 72 74 f commands start
8600: 69 6e 67 20 77 69 74 68 20 7a 50 72 65 66 69 78 ing with zPrefix
8610: 2c 20 6f 72 20 61 6c 6c 20 63 6f 6d 6d 61 6e 64 , or all command
8620: 73 20 69 66 20 7a 50 72 65 66 69 78 20 69 73 20 s if zPrefix is
8630: 4e 55 4c 4c 2e 0a 2a 2f 0a 73 74 61 74 69 63 20 NULL..*/.static
8640: 76 6f 69 64 20 63 6f 6d 6d 61 6e 64 5f 6c 69 73 void command_lis
8650: 74 28 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a 50 t(const char *zP
8660: 72 65 66 69 78 2c 20 69 6e 74 20 63 6d 64 4d 61 refix, int cmdMa
8670: 73 6b 29 7b 0a 20 20 69 6e 74 20 69 2c 20 6e 43 sk){. int i, nC
8680: 6d 64 3b 0a 20 20 69 6e 74 20 6e 50 72 65 66 69 md;. int nPrefi
8690: 78 20 3d 20 7a 50 72 65 66 69 78 20 3f 20 73 74 x = zPrefix ? st
86a0: 72 6c 65 6e 28 7a 50 72 65 66 69 78 29 20 3a 20 rlen(zPrefix) :
86b0: 30 3b 0a 20 20 63 6f 6e 73 74 20 63 68 61 72 20 0;. const char
86c0: 2a 61 43 6d 64 5b 63 6f 75 6e 74 28 61 43 6f 6d *aCmd[count(aCom
86d0: 6d 61 6e 64 29 5d 3b 0a 20 20 66 6f 72 28 69 3d mand)];. for(i=
86e0: 6e 43 6d 64 3d 30 3b 20 69 3c 63 6f 75 6e 74 28 nCmd=0; i<count(
86f0: 61 43 6f 6d 6d 61 6e 64 29 3b 20 69 2b 2b 29 7b aCommand); i++){
8700: 0a 20 20 20 20 63 6f 6e 73 74 20 63 68 61 72 20 . const char
8710: 2a 7a 20 3d 20 61 43 6f 6d 6d 61 6e 64 5b 69 5d *z = aCommand[i]
8720: 2e 7a 4e 61 6d 65 3b 0a 20 20 20 20 69 66 28 20 .zName;. if(
8730: 28 61 43 6f 6d 6d 61 6e 64 5b 69 5d 2e 63 6d 64 (aCommand[i].cmd
8740: 46 6c 61 67 73 20 26 20 63 6d 64 4d 61 73 6b 29 Flags & cmdMask)
8750: 3d 3d 30 20 29 20 63 6f 6e 74 69 6e 75 65 3b 0a ==0 ) continue;.
8760: 20 20 20 20 69 66 28 20 7a 50 72 65 66 69 78 20 if( zPrefix
8770: 26 26 20 6d 65 6d 63 6d 70 28 7a 50 72 65 66 69 && memcmp(zPrefi
8780: 78 2c 20 7a 2c 20 6e 50 72 65 66 69 78 29 21 3d x, z, nPrefix)!=
8790: 30 20 29 20 63 6f 6e 74 69 6e 75 65 3b 0a 20 20 0 ) continue;.
87a0: 20 20 61 43 6d 64 5b 6e 43 6d 64 2b 2b 5d 20 3d aCmd[nCmd++] =
87b0: 20 61 43 6f 6d 6d 61 6e 64 5b 69 5d 2e 7a 4e 61 aCommand[i].zNa
87c0: 6d 65 3b 0a 20 20 7d 0a 20 20 6d 75 6c 74 69 5f me;. }. multi_
87d0: 63 6f 6c 75 6d 6e 5f 6c 69 73 74 28 61 43 6d 64 column_list(aCmd
87e0: 2c 20 6e 43 6d 64 29 3b 0a 7d 0a 0a 2f 2a 0a 2a , nCmd);.}../*.*
87f0: 2a 20 43 4f 4d 4d 41 4e 44 3a 20 74 65 73 74 2d * COMMAND: test-
8800: 6c 69 73 74 2d 77 65 62 70 61 67 65 0a 2a 2a 0a list-webpage.**.
8810: 2a 2a 20 4c 69 73 74 20 61 6c 6c 20 77 65 62 20 ** List all web
8820: 70 61 67 65 73 0a 2a 2f 0a 76 6f 69 64 20 63 6d pages.*/.void cm
8830: 64 5f 74 65 73 74 5f 77 65 62 70 61 67 65 5f 6c d_test_webpage_l
8840: 69 73 74 28 76 6f 69 64 29 7b 0a 20 20 69 6e 74 ist(void){. int
8850: 20 69 2c 20 6e 43 6d 64 3b 0a 20 20 63 6f 6e 73 i, nCmd;. cons
8860: 74 20 63 68 61 72 20 2a 61 43 6d 64 5b 63 6f 75 t char *aCmd[cou
8870: 6e 74 28 61 43 6f 6d 6d 61 6e 64 29 5d 3b 0a 20 nt(aCommand)];.
8880: 20 66 6f 72 28 69 3d 6e 43 6d 64 3d 30 3b 20 69 for(i=nCmd=0; i
8890: 3c 63 6f 75 6e 74 28 61 43 6f 6d 6d 61 6e 64 29 <count(aCommand)
88a0: 3b 20 69 2b 2b 29 7b 0a 20 20 20 20 69 66 28 30 ; i++){. if(0
88b0: 78 30 38 20 26 20 61 43 6f 6d 6d 61 6e 64 5b 69 x08 & aCommand[i
88c0: 5d 2e 63 6d 64 46 6c 61 67 73 29 7b 0a 20 20 20 ].cmdFlags){.
88d0: 20 20 20 61 43 6d 64 5b 6e 43 6d 64 2b 2b 5d 20 aCmd[nCmd++]
88e0: 3d 20 61 57 65 62 70 61 67 65 5b 69 5d 2e 7a 4e = aWebpage[i].zN
88f0: 61 6d 65 3b 0a 20 20 20 20 7d 0a 20 20 7d 0a 20 ame;. }. }.
8900: 20 61 73 73 65 72 74 28 6e 43 6d 64 20 26 26 20 assert(nCmd &&
8910: 22 70 61 67 65 20 6c 69 73 74 20 69 73 20 65 6d "page list is em
8920: 70 74 79 3f 22 29 3b 0a 20 20 6d 75 6c 74 69 5f pty?");. multi_
8930: 63 6f 6c 75 6d 6e 5f 6c 69 73 74 28 61 43 6d 64 column_list(aCmd
8940: 2c 20 6e 43 6d 64 29 3b 0a 7d 0a 0a 0a 0a 2f 2a , nCmd);.}..../*
8950: 0a 2a 2a 20 54 68 69 73 20 66 75 6e 63 74 69 6f .** This functio
8960: 6e 20 72 65 74 75 72 6e 73 20 61 20 68 75 6d 61 n returns a huma
8970: 6e 20 72 65 61 64 61 62 6c 65 20 76 65 72 73 69 n readable versi
8980: 6f 6e 20 73 74 72 69 6e 67 2e 0a 2a 2f 0a 63 6f on string..*/.co
8990: 6e 73 74 20 63 68 61 72 20 2a 67 65 74 5f 76 65 nst char *get_ve
89a0: 72 73 69 6f 6e 28 29 7b 0a 20 20 73 74 61 74 69 rsion(){. stati
89b0: 63 20 63 6f 6e 73 74 20 63 68 61 72 20 76 65 72 c const char ver
89c0: 73 69 6f 6e 5b 5d 20 3d 20 52 45 4c 45 41 53 45 sion[] = RELEASE
89d0: 5f 56 45 52 53 49 4f 4e 20 22 20 22 20 4d 41 4e _VERSION " " MAN
89e0: 49 46 45 53 54 5f 56 45 52 53 49 4f 4e 20 22 20 IFEST_VERSION "
89f0: 22 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 ".
8a00: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
8a10: 20 20 4d 41 4e 49 46 45 53 54 5f 44 41 54 45 20 MANIFEST_DATE
8a20: 22 20 55 54 43 22 3b 0a 20 20 72 65 74 75 72 6e " UTC";. return
8a30: 20 76 65 72 73 69 6f 6e 3b 0a 7d 0a 0a 2f 2a 0a version;.}../*.
8a40: 2a 2a 20 54 68 69 73 20 66 75 6e 63 74 69 6f 6e ** This function
8a50: 20 70 6f 70 75 6c 61 74 65 73 20 61 20 62 6c 6f populates a blo
8a60: 62 20 77 69 74 68 20 76 65 72 73 69 6f 6e 20 69 b with version i
8a70: 6e 66 6f 72 6d 61 74 69 6f 6e 2e 20 20 49 74 20 nformation. It
8a80: 69 73 20 75 73 65 64 20 62 79 0a 2a 2a 20 74 68 is used by.** th
8a90: 65 20 22 76 65 72 73 69 6f 6e 22 20 63 6f 6d 6d e "version" comm
8aa0: 61 6e 64 20 61 6e 64 20 22 74 65 73 74 2d 76 65 and and "test-ve
8ab0: 72 73 69 6f 6e 22 20 77 65 62 20 70 61 67 65 2e rsion" web page.
8ac0: 20 20 49 74 20 61 73 73 75 6d 65 73 20 74 68 65 It assumes the
8ad0: 20 62 6c 6f 62 0a 2a 2a 20 70 61 73 73 65 64 20 blob.** passed
8ae0: 74 6f 20 69 74 20 69 73 20 75 6e 69 6e 69 74 69 to it is uniniti
8af0: 61 6c 69 7a 65 64 3b 20 6f 74 68 65 72 77 69 73 alized; otherwis
8b00: 65 2c 20 69 74 20 77 69 6c 6c 20 6c 65 61 6b 20 e, it will leak
8b10: 6d 65 6d 6f 72 79 2e 0a 2a 2f 0a 73 74 61 74 69 memory..*/.stati
8b20: 63 20 76 6f 69 64 20 67 65 74 5f 76 65 72 73 69 c void get_versi
8b30: 6f 6e 5f 62 6c 6f 62 28 0a 20 20 42 6c 6f 62 20 on_blob(. Blob
8b40: 2a 70 4f 75 74 2c 20 20 20 20 20 20 20 20 20 20 *pOut,
8b50: 20 20 20 20 20 20 20 2f 2a 20 57 72 69 74 65 20 /* Write
8b60: 74 68 65 20 6d 61 6e 69 66 65 73 74 20 68 65 72 the manifest her
8b70: 65 20 2a 2f 0a 20 20 69 6e 74 20 62 56 65 72 62 e */. int bVerb
8b80: 6f 73 65 20 20 20 20 20 20 20 20 20 20 20 20 20 ose
8b90: 20 20 20 2f 2a 20 4e 6f 6e 2d 7a 65 72 6f 20 66 /* Non-zero f
8ba0: 6f 72 20 66 75 6c 6c 20 69 6e 66 6f 72 6d 61 74 or full informat
8bb0: 69 6f 6e 2e 20 2a 2f 0a 29 7b 0a 23 69 66 20 64 ion. */.){.#if d
8bc0: 65 66 69 6e 65 64 28 46 4f 53 53 49 4c 5f 45 4e efined(FOSSIL_EN
8bd0: 41 42 4c 45 5f 54 43 4c 29 0a 20 20 69 6e 74 20 ABLE_TCL). int
8be0: 72 63 3b 0a 20 20 63 6f 6e 73 74 20 63 68 61 72 rc;. const char
8bf0: 20 2a 7a 52 63 3b 0a 23 65 6e 64 69 66 0a 20 20 *zRc;.#endif.
8c00: 62 6c 6f 62 5f 7a 65 72 6f 28 70 4f 75 74 29 3b blob_zero(pOut);
8c10: 0a 20 20 62 6c 6f 62 5f 61 70 70 65 6e 64 66 28 . blob_appendf(
8c20: 70 4f 75 74 2c 20 22 54 68 69 73 20 69 73 20 66 pOut, "This is f
8c30: 6f 73 73 69 6c 20 76 65 72 73 69 6f 6e 20 25 73 ossil version %s
8c40: 5c 6e 22 2c 20 67 65 74 5f 76 65 72 73 69 6f 6e \n", get_version
8c50: 28 29 29 3b 0a 20 20 69 66 28 20 21 62 56 65 72 ());. if( !bVer
8c60: 62 6f 73 65 20 29 20 72 65 74 75 72 6e 3b 0a 20 bose ) return;.
8c70: 20 62 6c 6f 62 5f 61 70 70 65 6e 64 66 28 70 4f blob_appendf(pO
8c80: 75 74 2c 20 22 43 6f 6d 70 69 6c 65 64 20 6f 6e ut, "Compiled on
8c90: 20 25 73 20 25 73 20 75 73 69 6e 67 20 25 73 20 %s %s using %s
8ca0: 28 25 64 2d 62 69 74 29 5c 6e 22 2c 0a 20 20 20 (%d-bit)\n",.
8cb0: 20 20 20 20 20 20 20 20 20 20 20 20 5f 5f 44 41 __DA
8cc0: 54 45 5f 5f 2c 20 5f 5f 54 49 4d 45 5f 5f 2c 20 TE__, __TIME__,
8cd0: 43 4f 4d 50 49 4c 45 52 5f 4e 41 4d 45 2c 20 73 COMPILER_NAME, s
8ce0: 69 7a 65 6f 66 28 76 6f 69 64 2a 29 2a 38 29 3b izeof(void*)*8);
8cf0: 0a 20 20 62 6c 6f 62 5f 61 70 70 65 6e 64 66 28 . blob_appendf(
8d00: 70 4f 75 74 2c 20 22 53 51 4c 69 74 65 20 25 73 pOut, "SQLite %s
8d10: 20 25 2e 33 30 73 5c 6e 22 2c 20 73 71 6c 69 74 %.30s\n", sqlit
8d20: 65 33 5f 6c 69 62 76 65 72 73 69 6f 6e 28 29 2c e3_libversion(),
8d30: 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 .
8d40: 73 71 6c 69 74 65 33 5f 73 6f 75 72 63 65 69 64 sqlite3_sourceid
8d50: 28 29 29 3b 0a 20 20 62 6c 6f 62 5f 61 70 70 65 ());. blob_appe
8d60: 6e 64 66 28 70 4f 75 74 2c 20 22 53 63 68 65 6d ndf(pOut, "Schem
8d70: 61 20 76 65 72 73 69 6f 6e 20 25 73 5c 6e 22 2c a version %s\n",
8d80: 20 41 55 58 5f 53 43 48 45 4d 41 5f 4d 41 58 29 AUX_SCHEMA_MAX)
8d90: 3b 0a 23 69 66 20 64 65 66 69 6e 65 64 28 46 4f ;.#if defined(FO
8da0: 53 53 49 4c 5f 45 4e 41 42 4c 45 5f 4d 49 4e 49 SSIL_ENABLE_MINI
8db0: 5a 29 0a 20 20 62 6c 6f 62 5f 61 70 70 65 6e 64 Z). blob_append
8dc0: 66 28 70 4f 75 74 2c 20 22 6d 69 6e 69 7a 20 25 f(pOut, "miniz %
8dd0: 73 2c 20 6c 6f 61 64 65 64 20 25 73 5c 6e 22 2c s, loaded %s\n",
8de0: 20 4d 5a 5f 56 45 52 53 49 4f 4e 2c 20 6d 7a 5f MZ_VERSION, mz_
8df0: 76 65 72 73 69 6f 6e 28 29 29 3b 0a 23 65 6c 73 version());.#els
8e00: 65 0a 20 20 62 6c 6f 62 5f 61 70 70 65 6e 64 66 e. blob_appendf
8e10: 28 70 4f 75 74 2c 20 22 7a 6c 69 62 20 25 73 2c (pOut, "zlib %s,
8e20: 20 6c 6f 61 64 65 64 20 25 73 5c 6e 22 2c 20 5a loaded %s\n", Z
8e30: 4c 49 42 5f 56 45 52 53 49 4f 4e 2c 20 7a 6c 69 LIB_VERSION, zli
8e40: 62 56 65 72 73 69 6f 6e 28 29 29 3b 0a 23 65 6e bVersion());.#en
8e50: 64 69 66 0a 23 69 66 20 64 65 66 69 6e 65 64 28 dif.#if defined(
8e60: 46 4f 53 53 49 4c 5f 45 4e 41 42 4c 45 5f 53 53 FOSSIL_ENABLE_SS
8e70: 4c 29 0a 20 20 62 6c 6f 62 5f 61 70 70 65 6e 64 L). blob_append
8e80: 66 28 70 4f 75 74 2c 20 22 53 53 4c 20 28 25 73 f(pOut, "SSL (%s
8e90: 29 5c 6e 22 2c 20 53 53 4c 65 61 79 5f 76 65 72 )\n", SSLeay_ver
8ea0: 73 69 6f 6e 28 53 53 4c 45 41 59 5f 56 45 52 53 sion(SSLEAY_VERS
8eb0: 49 4f 4e 29 29 3b 0a 23 65 6e 64 69 66 0a 23 69 ION));.#endif.#i
8ec0: 66 20 64 65 66 69 6e 65 64 28 46 4f 53 53 49 4c f defined(FOSSIL
8ed0: 5f 45 4e 41 42 4c 45 5f 4c 45 47 41 43 59 5f 4d _ENABLE_LEGACY_M
8ee0: 56 5f 52 4d 29 0a 20 20 62 6c 6f 62 5f 61 70 70 V_RM). blob_app
8ef0: 65 6e 64 28 70 4f 75 74 2c 20 22 4c 45 47 41 43 end(pOut, "LEGAC
8f00: 59 5f 4d 56 5f 52 4d 5c 6e 22 2c 20 2d 31 29 3b Y_MV_RM\n", -1);
8f10: 0a 23 65 6e 64 69 66 0a 23 69 66 20 64 65 66 69 .#endif.#if defi
8f20: 6e 65 64 28 46 4f 53 53 49 4c 5f 45 4e 41 42 4c ned(FOSSIL_ENABL
8f30: 45 5f 45 58 45 43 5f 52 45 4c 5f 50 41 54 48 53 E_EXEC_REL_PATHS
8f40: 29 0a 20 20 62 6c 6f 62 5f 61 70 70 65 6e 64 28 ). blob_append(
8f50: 70 4f 75 74 2c 20 22 45 58 45 43 5f 52 45 4c 5f pOut, "EXEC_REL_
8f60: 50 41 54 48 53 5c 6e 22 2c 20 2d 31 29 3b 0a 23 PATHS\n", -1);.#
8f70: 65 6e 64 69 66 0a 23 69 66 20 64 65 66 69 6e 65 endif.#if define
8f80: 64 28 46 4f 53 53 49 4c 5f 45 4e 41 42 4c 45 5f d(FOSSIL_ENABLE_
8f90: 54 48 31 5f 44 4f 43 53 29 0a 20 20 62 6c 6f 62 TH1_DOCS). blob
8fa0: 5f 61 70 70 65 6e 64 28 70 4f 75 74 2c 20 22 54 _append(pOut, "T
8fb0: 48 31 5f 44 4f 43 53 5c 6e 22 2c 20 2d 31 29 3b H1_DOCS\n", -1);
8fc0: 0a 23 65 6e 64 69 66 0a 23 69 66 20 64 65 66 69 .#endif.#if defi
8fd0: 6e 65 64 28 46 4f 53 53 49 4c 5f 45 4e 41 42 4c ned(FOSSIL_ENABL
8fe0: 45 5f 54 48 31 5f 48 4f 4f 4b 53 29 0a 20 20 62 E_TH1_HOOKS). b
8ff0: 6c 6f 62 5f 61 70 70 65 6e 64 28 70 4f 75 74 2c lob_append(pOut,
9000: 20 22 54 48 31 5f 48 4f 4f 4b 53 5c 6e 22 2c 20 "TH1_HOOKS\n",
9010: 2d 31 29 3b 0a 23 65 6e 64 69 66 0a 23 69 66 20 -1);.#endif.#if
9020: 64 65 66 69 6e 65 64 28 46 4f 53 53 49 4c 5f 45 defined(FOSSIL_E
9030: 4e 41 42 4c 45 5f 54 43 4c 29 0a 20 20 54 68 5f NABLE_TCL). Th_
9040: 46 6f 73 73 69 6c 49 6e 69 74 28 54 48 5f 49 4e FossilInit(TH_IN
9050: 49 54 5f 44 45 46 41 55 4c 54 20 7c 20 54 48 5f IT_DEFAULT | TH_
9060: 49 4e 49 54 5f 46 4f 52 43 45 5f 54 43 4c 29 3b INIT_FORCE_TCL);
9070: 0a 20 20 72 63 20 3d 20 54 68 5f 45 76 61 6c 28 . rc = Th_Eval(
9080: 67 2e 69 6e 74 65 72 70 2c 20 30 2c 20 22 74 63 g.interp, 0, "tc
9090: 6c 49 6e 76 6f 6b 65 20 69 6e 66 6f 20 70 61 74 lInvoke info pat
90a0: 63 68 6c 65 76 65 6c 22 2c 20 2d 31 29 3b 0a 20 chlevel", -1);.
90b0: 20 7a 52 63 20 3d 20 54 68 5f 52 65 74 75 72 6e zRc = Th_Return
90c0: 43 6f 64 65 4e 61 6d 65 28 72 63 2c 20 30 29 3b CodeName(rc, 0);
90d0: 0a 20 20 62 6c 6f 62 5f 61 70 70 65 6e 64 66 28 . blob_appendf(
90e0: 70 4f 75 74 2c 20 22 54 43 4c 20 28 54 63 6c 20 pOut, "TCL (Tcl
90f0: 25 73 2c 20 6c 6f 61 64 65 64 20 25 73 3a 20 25 %s, loaded %s: %
9100: 73 29 5c 6e 22 2c 0a 20 20 20 20 54 43 4c 5f 50 s)\n",. TCL_P
9110: 41 54 43 48 5f 4c 45 56 45 4c 2c 20 7a 52 63 2c ATCH_LEVEL, zRc,
9120: 20 54 68 5f 47 65 74 52 65 73 75 6c 74 28 67 2e Th_GetResult(g.
9130: 69 6e 74 65 72 70 2c 20 30 29 0a 20 20 29 3b 0a interp, 0). );.
9140: 23 65 6e 64 69 66 0a 23 69 66 20 64 65 66 69 6e #endif.#if defin
9150: 65 64 28 55 53 45 5f 54 43 4c 5f 53 54 55 42 53 ed(USE_TCL_STUBS
9160: 29 0a 20 20 62 6c 6f 62 5f 61 70 70 65 6e 64 28 ). blob_append(
9170: 70 4f 75 74 2c 20 22 55 53 45 5f 54 43 4c 5f 53 pOut, "USE_TCL_S
9180: 54 55 42 53 5c 6e 22 2c 20 2d 31 29 3b 0a 23 65 TUBS\n", -1);.#e
9190: 6e 64 69 66 0a 23 69 66 20 64 65 66 69 6e 65 64 ndif.#if defined
91a0: 28 46 4f 53 53 49 4c 5f 45 4e 41 42 4c 45 5f 54 (FOSSIL_ENABLE_T
91b0: 43 4c 5f 53 54 55 42 53 29 0a 20 20 62 6c 6f 62 CL_STUBS). blob
91c0: 5f 61 70 70 65 6e 64 28 70 4f 75 74 2c 20 22 54 _append(pOut, "T
91d0: 43 4c 5f 53 54 55 42 53 5c 6e 22 2c 20 2d 31 29 CL_STUBS\n", -1)
91e0: 3b 0a 23 65 6e 64 69 66 0a 23 69 66 20 64 65 66 ;.#endif.#if def
91f0: 69 6e 65 64 28 46 4f 53 53 49 4c 5f 45 4e 41 42 ined(FOSSIL_ENAB
9200: 4c 45 5f 54 43 4c 5f 50 52 49 56 41 54 45 5f 53 LE_TCL_PRIVATE_S
9210: 54 55 42 53 29 0a 20 20 62 6c 6f 62 5f 61 70 70 TUBS). blob_app
9220: 65 6e 64 28 70 4f 75 74 2c 20 22 54 43 4c 5f 50 end(pOut, "TCL_P
9230: 52 49 56 41 54 45 5f 53 54 55 42 53 5c 6e 22 2c RIVATE_STUBS\n",
9240: 20 2d 31 29 3b 0a 23 65 6e 64 69 66 0a 23 69 66 -1);.#endif.#if
9250: 20 64 65 66 69 6e 65 64 28 46 4f 53 53 49 4c 5f defined(FOSSIL_
9260: 45 4e 41 42 4c 45 5f 4a 53 4f 4e 29 0a 20 20 62 ENABLE_JSON). b
9270: 6c 6f 62 5f 61 70 70 65 6e 64 66 28 70 4f 75 74 lob_appendf(pOut
9280: 2c 20 22 4a 53 4f 4e 20 28 41 50 49 20 25 73 29 , "JSON (API %s)
9290: 5c 6e 22 2c 20 46 4f 53 53 49 4c 5f 4a 53 4f 4e \n", FOSSIL_JSON
92a0: 5f 41 50 49 5f 56 45 52 53 49 4f 4e 29 3b 0a 23 _API_VERSION);.#
92b0: 65 6e 64 69 66 0a 23 69 66 20 64 65 66 69 6e 65 endif.#if define
92c0: 64 28 42 52 4f 4b 45 4e 5f 4d 49 4e 47 57 5f 43 d(BROKEN_MINGW_C
92d0: 4d 44 4c 49 4e 45 29 0a 20 20 62 6c 6f 62 5f 61 MDLINE). blob_a
92e0: 70 70 65 6e 64 28 70 4f 75 74 2c 20 22 4d 42 43 ppend(pOut, "MBC
92f0: 53 5f 43 4f 4d 4d 41 4e 44 5f 4c 49 4e 45 5c 6e S_COMMAND_LINE\n
9300: 22 2c 20 2d 31 29 3b 0a 23 65 6c 73 65 0a 20 20 ", -1);.#else.
9310: 62 6c 6f 62 5f 61 70 70 65 6e 64 28 70 4f 75 74 blob_append(pOut
9320: 2c 20 22 55 4e 49 43 4f 44 45 5f 43 4f 4d 4d 41 , "UNICODE_COMMA
9330: 4e 44 5f 4c 49 4e 45 5c 6e 22 2c 20 2d 31 29 3b ND_LINE\n", -1);
9340: 0a 23 65 6e 64 69 66 0a 23 69 66 20 64 65 66 69 .#endif.#if defi
9350: 6e 65 64 28 46 4f 53 53 49 4c 5f 44 59 4e 41 4d ned(FOSSIL_DYNAM
9360: 49 43 5f 42 55 49 4c 44 29 0a 20 20 62 6c 6f 62 IC_BUILD). blob
9370: 5f 61 70 70 65 6e 64 28 70 4f 75 74 2c 20 22 44 _append(pOut, "D
9380: 59 4e 41 4d 49 43 5f 42 55 49 4c 44 5c 6e 22 2c YNAMIC_BUILD\n",
9390: 20 2d 31 29 3b 0a 23 65 6c 73 65 0a 20 20 62 6c -1);.#else. bl
93a0: 6f 62 5f 61 70 70 65 6e 64 28 70 4f 75 74 2c 20 ob_append(pOut,
93b0: 22 53 54 41 54 49 43 5f 42 55 49 4c 44 5c 6e 22 "STATIC_BUILD\n"
93c0: 2c 20 2d 31 29 3b 0a 23 65 6e 64 69 66 0a 7d 0a , -1);.#endif.}.
93d0: 0a 2f 2a 0a 2a 2a 20 54 68 69 73 20 66 75 6e 63 ./*.** This func
93e0: 74 69 6f 6e 20 72 65 74 75 72 6e 73 20 74 68 65 tion returns the
93f0: 20 75 73 65 72 2d 61 67 65 6e 74 20 73 74 72 69 user-agent stri
9400: 6e 67 20 66 6f 72 20 46 6f 73 73 69 6c 2c 20 66 ng for Fossil, f
9410: 6f 72 0a 2a 2a 20 75 73 65 20 69 6e 20 48 54 54 or.** use in HTT
9420: 50 28 53 29 20 72 65 71 75 65 73 74 73 2e 0a 2a P(S) requests..*
9430: 2f 0a 63 6f 6e 73 74 20 63 68 61 72 20 2a 67 65 /.const char *ge
9440: 74 5f 75 73 65 72 5f 61 67 65 6e 74 28 29 7b 0a t_user_agent(){.
9450: 20 20 73 74 61 74 69 63 20 63 6f 6e 73 74 20 63 static const c
9460: 68 61 72 20 76 65 72 73 69 6f 6e 5b 5d 20 3d 20 har version[] =
9470: 22 46 6f 73 73 69 6c 2f 22 20 52 45 4c 45 41 53 "Fossil/" RELEAS
9480: 45 5f 56 45 52 53 49 4f 4e 20 22 20 28 22 20 4d E_VERSION " (" M
9490: 41 4e 49 46 45 53 54 5f 44 41 54 45 0a 20 20 20 ANIFEST_DATE.
94a0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
94b0: 20 20 20 20 20 20 20 20 20 20 20 20 20 22 20 22 " "
94c0: 20 4d 41 4e 49 46 45 53 54 5f 56 45 52 53 49 4f MANIFEST_VERSIO
94d0: 4e 20 22 29 22 3b 0a 20 20 72 65 74 75 72 6e 20 N ")";. return
94e0: 76 65 72 73 69 6f 6e 3b 0a 7d 0a 0a 0a 2f 2a 0a version;.}.../*.
94f0: 2a 2a 20 43 4f 4d 4d 41 4e 44 3a 20 76 65 72 73 ** COMMAND: vers
9500: 69 6f 6e 0a 2a 2a 0a 2a 2a 20 55 73 61 67 65 3a ion.**.** Usage:
9510: 20 25 66 6f 73 73 69 6c 20 76 65 72 73 69 6f 6e %fossil version
9520: 20 3f 2d 76 65 72 62 6f 73 65 7c 2d 76 3f 0a 2a ?-verbose|-v?.*
9530: 2a 0a 2a 2a 20 50 72 69 6e 74 20 74 68 65 20 73 *.** Print the s
9540: 6f 75 72 63 65 20 63 6f 64 65 20 76 65 72 73 69 ource code versi
9550: 6f 6e 20 6e 75 6d 62 65 72 20 66 6f 72 20 74 68 on number for th
9560: 65 20 66 6f 73 73 69 6c 20 65 78 65 63 75 74 61 e fossil executa
9570: 62 6c 65 2e 0a 2a 2a 20 49 66 20 74 68 65 20 76 ble..** If the v
9580: 65 72 62 6f 73 65 20 6f 70 74 69 6f 6e 20 69 73 erbose option is
9590: 20 73 70 65 63 69 66 69 65 64 2c 20 61 64 64 69 specified, addi
95a0: 74 69 6f 6e 61 6c 20 64 65 74 61 69 6c 73 20 77 tional details w
95b0: 69 6c 6c 0a 2a 2a 20 62 65 20 6f 75 74 70 75 74 ill.** be output
95c0: 20 61 62 6f 75 74 20 77 68 61 74 20 6f 70 74 69 about what opti
95d0: 6f 6e 61 6c 20 66 65 61 74 75 72 65 73 20 74 68 onal features th
95e0: 69 73 20 62 69 6e 61 72 79 20 77 61 73 20 63 6f is binary was co
95f0: 6d 70 69 6c 65 64 0a 2a 2a 20 77 69 74 68 0a 2a mpiled.** with.*
9600: 2f 0a 76 6f 69 64 20 76 65 72 73 69 6f 6e 5f 63 /.void version_c
9610: 6d 64 28 76 6f 69 64 29 7b 0a 20 20 42 6c 6f 62 md(void){. Blob
9620: 20 76 65 72 73 69 6f 6e 49 6e 66 6f 3b 0a 20 20 versionInfo;.
9630: 69 6e 74 20 76 65 72 62 6f 73 65 46 6c 61 67 20 int verboseFlag
9640: 3d 20 66 69 6e 64 5f 6f 70 74 69 6f 6e 28 22 76 = find_option("v
9650: 65 72 62 6f 73 65 22 2c 22 76 22 2c 30 29 21 3d erbose","v",0)!=
9660: 30 3b 0a 0a 20 20 2f 2a 20 57 65 20 73 68 6f 75 0;.. /* We shou
9670: 6c 64 20 62 65 20 64 6f 6e 65 20 77 69 74 68 20 ld be done with
9680: 6f 70 74 69 6f 6e 73 2e 2e 20 2a 2f 0a 20 20 76 options.. */. v
9690: 65 72 69 66 79 5f 61 6c 6c 5f 6f 70 74 69 6f 6e erify_all_option
96a0: 73 28 29 3b 0a 20 20 67 65 74 5f 76 65 72 73 69 s();. get_versi
96b0: 6f 6e 5f 62 6c 6f 62 28 26 76 65 72 73 69 6f 6e on_blob(&version
96c0: 49 6e 66 6f 2c 20 76 65 72 62 6f 73 65 46 6c 61 Info, verboseFla
96d0: 67 29 3b 0a 20 20 66 6f 73 73 69 6c 5f 70 72 69 g);. fossil_pri
96e0: 6e 74 28 22 25 73 22 2c 20 62 6c 6f 62 5f 73 74 nt("%s", blob_st
96f0: 72 28 26 76 65 72 73 69 6f 6e 49 6e 66 6f 29 29 r(&versionInfo))
9700: 3b 0a 7d 0a 0a 0a 2f 2a 0a 2a 2a 20 57 45 42 50 ;.}.../*.** WEBP
9710: 41 47 45 3a 20 74 65 73 74 2d 76 65 72 73 69 6f AGE: test-versio
9720: 6e 0a 2a 2a 0a 2a 2a 20 53 68 6f 77 20 74 68 65 n.**.** Show the
9730: 20 76 65 72 73 69 6f 6e 20 69 6e 66 6f 72 6d 61 version informa
9740: 74 69 6f 6e 20 66 6f 72 20 46 6f 73 73 69 6c 2e tion for Fossil.
9750: 0a 2a 2a 0a 2a 2a 20 51 75 65 72 79 20 70 61 72 .**.** Query par
9760: 61 6d 65 74 65 72 73 3a 0a 2a 2a 0a 2a 2a 20 20 ameters:.**.**
9770: 20 20 76 65 72 62 6f 73 65 20 20 20 20 20 20 20 verbose
9780: 53 68 6f 77 20 61 6c 6c 20 61 76 61 69 6c 61 62 Show all availab
9790: 6c 65 20 64 65 74 61 69 6c 73 2e 0a 2a 2f 0a 76 le details..*/.v
97a0: 6f 69 64 20 74 65 73 74 5f 76 65 72 73 69 6f 6e oid test_version
97b0: 5f 70 61 67 65 28 76 6f 69 64 29 7b 0a 20 20 42 _page(void){. B
97c0: 6c 6f 62 20 76 65 72 73 69 6f 6e 49 6e 66 6f 3b lob versionInfo;
97d0: 0a 20 20 69 6e 74 20 76 65 72 62 6f 73 65 46 6c . int verboseFl
97e0: 61 67 3b 0a 0a 20 20 6c 6f 67 69 6e 5f 63 68 65 ag;.. login_che
97f0: 63 6b 5f 63 72 65 64 65 6e 74 69 61 6c 73 28 29 ck_credentials()
9800: 3b 0a 20 20 69 66 28 20 21 67 2e 70 65 72 6d 2e ;. if( !g.perm.
9810: 52 65 61 64 20 29 7b 20 6c 6f 67 69 6e 5f 6e 65 Read ){ login_ne
9820: 65 64 65 64 28 67 2e 61 6e 6f 6e 2e 52 65 61 64 eded(g.anon.Read
9830: 29 3b 20 72 65 74 75 72 6e 3b 20 7d 0a 20 20 76 ); return; }. v
9840: 65 72 62 6f 73 65 46 6c 61 67 20 3d 20 50 28 22 erboseFlag = P("
9850: 76 65 72 62 6f 73 65 22 29 21 3d 30 3b 0a 20 20 verbose")!=0;.
9860: 73 74 79 6c 65 5f 68 65 61 64 65 72 28 22 56 65 style_header("Ve
9870: 72 73 69 6f 6e 20 49 6e 66 6f 72 6d 61 74 69 6f rsion Informatio
9880: 6e 22 29 3b 0a 20 20 67 65 74 5f 76 65 72 73 69 n");. get_versi
9890: 6f 6e 5f 62 6c 6f 62 28 26 76 65 72 73 69 6f 6e on_blob(&version
98a0: 49 6e 66 6f 2c 20 76 65 72 62 6f 73 65 46 6c 61 Info, verboseFla
98b0: 67 29 3b 0a 20 20 40 20 3c 62 6c 6f 63 6b 71 75 g);. @ <blockqu
98c0: 6f 74 65 3e 3c 70 72 65 3e 0a 20 20 40 20 25 68 ote><pre>. @ %h
98d0: 28 62 6c 6f 62 5f 73 74 72 28 26 76 65 72 73 69 (blob_str(&versi
98e0: 6f 6e 49 6e 66 6f 29 29 0a 20 20 40 20 3c 2f 70 onInfo)). @ </p
98f0: 72 65 3e 3c 2f 62 6c 6f 63 6b 71 75 6f 74 65 3e re></blockquote>
9900: 0a 20 20 73 74 79 6c 65 5f 66 6f 6f 74 65 72 28 . style_footer(
9910: 29 3b 0a 7d 0a 0a 0a 2f 2a 0a 2a 2a 20 43 4f 4d );.}.../*.** COM
9920: 4d 41 4e 44 3a 20 68 65 6c 70 0a 2a 2a 0a 2a 2a MAND: help.**.**
9930: 20 55 73 61 67 65 3a 20 25 66 6f 73 73 69 6c 20 Usage: %fossil
9940: 68 65 6c 70 20 43 4f 4d 4d 41 4e 44 0a 2a 2a 20 help COMMAND.**
9950: 20 20 20 6f 72 3a 20 25 66 6f 73 73 69 6c 20 43 or: %fossil C
9960: 4f 4d 4d 41 4e 44 20 2d 2d 68 65 6c 70 0a 2a 2a OMMAND --help.**
9970: 0a 2a 2a 20 44 69 73 70 6c 61 79 20 69 6e 66 6f .** Display info
9980: 72 6d 61 74 69 6f 6e 20 6f 6e 20 68 6f 77 20 74 rmation on how t
9990: 6f 20 75 73 65 20 43 4f 4d 4d 41 4e 44 2e 20 20 o use COMMAND.
99a0: 54 6f 20 64 69 73 70 6c 61 79 20 61 20 6c 69 73 To display a lis
99b0: 74 20 6f 66 0a 2a 2a 20 61 76 61 69 6c 61 62 6c t of.** availabl
99c0: 65 20 63 6f 6d 6d 61 6e 64 73 20 75 73 65 20 6f e commands use o
99d0: 6e 65 20 6f 66 3a 0a 2a 2a 0a 2a 2a 20 20 20 20 ne of:.**.**
99e0: 25 66 6f 73 73 69 6c 20 68 65 6c 70 20 20 20 20 %fossil help
99f0: 20 20 20 20 20 20 20 20 20 20 53 68 6f 77 20 63 Show c
9a00: 6f 6d 6d 6f 6e 20 63 6f 6d 6d 61 6e 64 73 0a 2a ommon commands.*
9a10: 2a 20 20 20 20 25 66 6f 73 73 69 6c 20 68 65 6c * %fossil hel
9a20: 70 20 2d 61 7c 2d 2d 61 6c 6c 20 20 20 20 20 53 p -a|--all S
9a30: 68 6f 77 20 62 6f 74 68 20 63 6f 6d 6d 6f 6e 20 how both common
9a40: 61 6e 64 20 61 75 78 69 6c 69 61 72 79 20 63 6f and auxiliary co
9a50: 6d 6d 61 6e 64 73 0a 2a 2a 20 20 20 20 25 66 6f mmands.** %fo
9a60: 73 73 69 6c 20 68 65 6c 70 20 2d 74 7c 2d 2d 74 ssil help -t|--t
9a70: 65 73 74 20 20 20 20 53 68 6f 77 20 74 65 73 74 est Show test
9a80: 20 63 6f 6d 6d 61 6e 64 73 20 6f 6e 6c 79 0a 2a commands only.*
9a90: 2a 20 20 20 20 25 66 6f 73 73 69 6c 20 68 65 6c * %fossil hel
9aa0: 70 20 2d 78 7c 2d 2d 61 75 78 20 20 20 20 20 53 p -x|--aux S
9ab0: 68 6f 77 20 61 75 78 69 6c 69 61 72 79 20 63 6f how auxiliary co
9ac0: 6d 6d 61 6e 64 73 20 6f 6e 6c 79 0a 2a 2a 20 20 mmands only.**
9ad0: 20 20 25 66 6f 73 73 69 6c 20 68 65 6c 70 20 2d %fossil help -
9ae0: 77 7c 2d 2d 77 77 77 20 20 20 20 20 53 68 6f 77 w|--www Show
9af0: 20 6c 69 73 74 20 6f 66 20 57 57 57 20 70 61 67 list of WWW pag
9b00: 65 73 0a 2a 2f 0a 76 6f 69 64 20 68 65 6c 70 5f es.*/.void help_
9b10: 63 6d 64 28 76 6f 69 64 29 7b 0a 20 20 69 6e 74 cmd(void){. int
9b20: 20 72 63 2c 20 69 64 78 2c 20 69 73 50 61 67 65 rc, idx, isPage
9b30: 20 3d 20 30 3b 0a 20 20 63 6f 6e 73 74 20 63 68 = 0;. const ch
9b40: 61 72 20 2a 7a 3b 0a 20 20 63 6f 6e 73 74 20 63 ar *z;. const c
9b50: 68 61 72 20 2a 7a 43 6d 64 4f 72 50 61 67 65 3b har *zCmdOrPage;
9b60: 0a 20 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a . const char *z
9b70: 43 6d 64 4f 72 50 61 67 65 50 6c 75 72 61 6c 3b CmdOrPagePlural;
9b80: 0a 20 20 69 66 28 20 67 2e 61 72 67 63 3c 33 20 . if( g.argc<3
9b90: 29 7b 0a 20 20 20 20 7a 20 3d 20 67 2e 61 72 67 ){. z = g.arg
9ba0: 76 5b 30 5d 3b 0a 20 20 20 20 66 6f 73 73 69 6c v[0];. fossil
9bb0: 5f 70 72 69 6e 74 28 0a 20 20 20 20 20 20 22 55 _print(. "U
9bc0: 73 61 67 65 3a 20 25 73 20 68 65 6c 70 20 43 4f sage: %s help CO
9bd0: 4d 4d 41 4e 44 5c 6e 22 0a 20 20 20 20 20 20 22 MMAND\n". "
9be0: 43 6f 6d 6d 6f 6e 20 43 4f 4d 4d 41 4e 44 73 3a Common COMMANDs:
9bf0: 20 20 28 75 73 65 20 5c 22 25 73 20 68 65 6c 70 (use \"%s help
9c00: 20 2d 61 7c 2d 2d 61 6c 6c 5c 22 20 66 6f 72 20 -a|--all\" for
9c10: 61 20 63 6f 6d 70 6c 65 74 65 20 6c 69 73 74 29 a complete list)
9c20: 5c 6e 22 2c 0a 20 20 20 20 20 20 7a 2c 20 7a 29 \n",. z, z)
9c30: 3b 0a 20 20 20 20 63 6f 6d 6d 61 6e 64 5f 6c 69 ;. command_li
9c40: 73 74 28 30 2c 20 43 4d 44 46 4c 41 47 5f 31 53 st(0, CMDFLAG_1S
9c50: 54 5f 54 49 45 52 29 3b 0a 20 20 20 20 76 65 72 T_TIER);. ver
9c60: 73 69 6f 6e 5f 63 6d 64 28 29 3b 0a 20 20 20 20 sion_cmd();.
9c70: 72 65 74 75 72 6e 3b 0a 20 20 7d 0a 20 20 69 66 return;. }. if
9c80: 28 20 66 69 6e 64 5f 6f 70 74 69 6f 6e 28 22 61 ( find_option("a
9c90: 6c 6c 22 2c 22 61 22 2c 30 29 20 29 7b 0a 20 20 ll","a",0) ){.
9ca0: 20 20 63 6f 6d 6d 61 6e 64 5f 6c 69 73 74 28 30 command_list(0
9cb0: 2c 20 43 4d 44 46 4c 41 47 5f 31 53 54 5f 54 49 , CMDFLAG_1ST_TI
9cc0: 45 52 20 7c 20 43 4d 44 46 4c 41 47 5f 32 4e 44 ER | CMDFLAG_2ND
9cd0: 5f 54 49 45 52 29 3b 0a 20 20 20 20 72 65 74 75 _TIER);. retu
9ce0: 72 6e 3b 0a 20 20 7d 0a 20 20 65 6c 73 65 20 69 rn;. }. else i
9cf0: 66 28 20 66 69 6e 64 5f 6f 70 74 69 6f 6e 28 22 f( find_option("
9d00: 77 77 77 22 2c 22 77 22 2c 30 29 20 29 7b 0a 20 www","w",0) ){.
9d10: 20 20 20 63 6f 6d 6d 61 6e 64 5f 6c 69 73 74 28 command_list(
9d20: 30 2c 20 43 4d 44 46 4c 41 47 5f 57 45 42 50 41 0, CMDFLAG_WEBPA
9d30: 47 45 29 3b 0a 20 20 20 20 72 65 74 75 72 6e 3b GE);. return;
9d40: 0a 20 20 7d 0a 20 20 65 6c 73 65 20 69 66 28 20 . }. else if(
9d50: 66 69 6e 64 5f 6f 70 74 69 6f 6e 28 22 61 75 78 find_option("aux
9d60: 22 2c 22 78 22 2c 30 29 20 29 7b 0a 20 20 20 20 ","x",0) ){.
9d70: 63 6f 6d 6d 61 6e 64 5f 6c 69 73 74 28 30 2c 20 command_list(0,
9d80: 43 4d 44 46 4c 41 47 5f 32 4e 44 5f 54 49 45 52 CMDFLAG_2ND_TIER
9d90: 29 3b 0a 20 20 20 20 72 65 74 75 72 6e 3b 0a 20 );. return;.
9da0: 20 7d 0a 20 20 65 6c 73 65 20 69 66 28 20 66 69 }. else if( fi
9db0: 6e 64 5f 6f 70 74 69 6f 6e 28 22 74 65 73 74 22 nd_option("test"
9dc0: 2c 22 74 22 2c 30 29 20 29 7b 0a 20 20 20 20 63 ,"t",0) ){. c
9dd0: 6f 6d 6d 61 6e 64 5f 6c 69 73 74 28 30 2c 20 43 ommand_list(0, C
9de0: 4d 44 46 4c 41 47 5f 54 45 53 54 29 3b 0a 20 20 MDFLAG_TEST);.
9df0: 20 20 72 65 74 75 72 6e 3b 0a 20 20 7d 0a 20 20 return;. }.
9e00: 69 73 50 61 67 65 20 3d 20 28 27 2f 27 20 3d 3d isPage = ('/' ==
9e10: 20 2a 67 2e 61 72 67 76 5b 32 5d 29 20 3f 20 31 *g.argv[2]) ? 1
9e20: 20 3a 20 30 3b 0a 20 20 69 66 28 69 73 50 61 67 : 0;. if(isPag
9e30: 65 29 7b 0a 20 20 20 20 7a 43 6d 64 4f 72 50 61 e){. zCmdOrPa
9e40: 67 65 20 3d 20 22 70 61 67 65 22 3b 0a 20 20 20 ge = "page";.
9e50: 20 7a 43 6d 64 4f 72 50 61 67 65 50 6c 75 72 61 zCmdOrPagePlura
9e60: 6c 20 3d 20 22 70 61 67 65 73 22 3b 0a 20 20 7d l = "pages";. }
9e70: 65 6c 73 65 7b 0a 20 20 20 20 7a 43 6d 64 4f 72 else{. zCmdOr
9e80: 50 61 67 65 20 3d 20 22 63 6f 6d 6d 61 6e 64 22 Page = "command"
9e90: 3b 0a 20 20 20 20 7a 43 6d 64 4f 72 50 61 67 65 ;. zCmdOrPage
9ea0: 50 6c 75 72 61 6c 20 3d 20 22 63 6f 6d 6d 61 6e Plural = "comman
9eb0: 64 73 22 3b 0a 20 20 7d 0a 20 20 72 63 20 3d 20 ds";. }. rc =
9ec0: 6e 61 6d 65 5f 73 65 61 72 63 68 28 67 2e 61 72 name_search(g.ar
9ed0: 67 76 5b 32 5d 2c 20 61 43 6f 6d 6d 61 6e 64 2c gv[2], aCommand,
9ee0: 20 63 6f 75 6e 74 28 61 43 6f 6d 6d 61 6e 64 29 count(aCommand)
9ef0: 2c 20 30 2c 20 26 69 64 78 29 3b 0a 20 20 69 66 , 0, &idx);. if
9f00: 28 20 72 63 3d 3d 31 20 29 7b 0a 20 20 20 20 66 ( rc==1 ){. f
9f10: 6f 73 73 69 6c 5f 70 72 69 6e 74 28 22 75 6e 6b ossil_print("unk
9f20: 6e 6f 77 6e 20 25 73 3a 20 25 73 5c 6e 41 76 61 nown %s: %s\nAva
9f30: 69 6c 61 62 6c 65 20 25 73 3a 5c 6e 22 2c 0a 20 ilable %s:\n",.
9f40: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
9f50: 7a 43 6d 64 4f 72 50 61 67 65 2c 20 67 2e 61 72 zCmdOrPage, g.ar
9f60: 67 76 5b 32 5d 2c 20 7a 43 6d 64 4f 72 50 61 67 gv[2], zCmdOrPag
9f70: 65 50 6c 75 72 61 6c 29 3b 0a 20 20 20 20 63 6f ePlural);. co
9f80: 6d 6d 61 6e 64 5f 6c 69 73 74 28 30 2c 20 69 73 mmand_list(0, is
9f90: 50 61 67 65 20 3f 20 43 4d 44 46 4c 41 47 5f 57 Page ? CMDFLAG_W
9fa0: 45 42 50 41 47 45 20 3a 20 28 30 78 66 66 20 26 EBPAGE : (0xff &
9fb0: 20 7e 43 4d 44 46 4c 41 47 5f 57 45 42 50 41 47 ~CMDFLAG_WEBPAG
9fc0: 45 29 29 3b 0a 20 20 20 20 66 6f 73 73 69 6c 5f E));. fossil_
9fd0: 65 78 69 74 28 31 29 3b 0a 20 20 7d 65 6c 73 65 exit(1);. }else
9fe0: 20 69 66 28 20 72 63 3d 3d 32 20 29 7b 0a 20 20 if( rc==2 ){.
9ff0: 20 20 66 6f 73 73 69 6c 5f 70 72 69 6e 74 28 22 fossil_print("
a000: 61 6d 62 69 67 75 6f 75 73 20 25 73 20 70 72 65 ambiguous %s pre
a010: 66 69 78 3a 20 25 73 5c 6e 4d 61 74 63 68 69 6e fix: %s\nMatchin
a020: 67 20 25 73 3a 5c 6e 22 2c 0a 20 20 20 20 20 20 g %s:\n",.
a030: 20 20 20 20 20 20 20 20 20 20 20 7a 43 6d 64 4f zCmdO
a040: 72 50 61 67 65 2c 20 67 2e 61 72 67 76 5b 32 5d rPage, g.argv[2]
a050: 2c 20 7a 43 6d 64 4f 72 50 61 67 65 50 6c 75 72 , zCmdOrPagePlur
a060: 61 6c 29 3b 0a 20 20 20 20 63 6f 6d 6d 61 6e 64 al);. command
a070: 5f 6c 69 73 74 28 67 2e 61 72 67 76 5b 32 5d 2c _list(g.argv[2],
a080: 20 30 78 66 66 29 3b 0a 20 20 20 20 66 6f 73 73 0xff);. foss
a090: 69 6c 5f 65 78 69 74 28 31 29 3b 0a 20 20 7d 0a il_exit(1);. }.
a0a0: 20 20 7a 20 3d 20 61 43 6d 64 48 65 6c 70 5b 69 z = aCmdHelp[i
a0b0: 64 78 5d 2e 7a 54 65 78 74 3b 0a 20 20 69 66 28 dx].zText;. if(
a0c0: 20 7a 3d 3d 30 20 29 7b 0a 20 20 20 20 66 6f 73 z==0 ){. fos
a0d0: 73 69 6c 5f 66 61 74 61 6c 28 22 6e 6f 20 68 65 sil_fatal("no he
a0e0: 6c 70 20 61 76 61 69 6c 61 62 6c 65 20 66 6f 72 lp available for
a0f0: 20 74 68 65 20 25 73 20 25 73 22 2c 0a 20 20 20 the %s %s",.
a100: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 61 43 aC
a110: 6f 6d 6d 61 6e 64 5b 69 64 78 5d 2e 7a 4e 61 6d ommand[idx].zNam
a120: 65 2c 20 7a 43 6d 64 4f 72 50 61 67 65 29 3b 0a e, zCmdOrPage);.
a130: 20 20 7d 0a 20 20 77 68 69 6c 65 28 20 2a 7a 20 }. while( *z
a140: 29 7b 0a 20 20 20 20 69 66 28 20 2a 7a 3d 3d 27 ){. if( *z=='
a150: 25 27 20 26 26 20 73 74 72 6e 63 6d 70 28 7a 2c %' && strncmp(z,
a160: 20 22 25 66 6f 73 73 69 6c 22 2c 20 37 29 3d 3d "%fossil", 7)==
a170: 30 20 29 7b 0a 20 20 20 20 20 20 66 6f 73 73 69 0 ){. fossi
a180: 6c 5f 70 72 69 6e 74 28 22 25 73 22 2c 20 67 2e l_print("%s", g.
a190: 61 72 67 76 5b 30 5d 29 3b 0a 20 20 20 20 20 20 argv[0]);.
a1a0: 7a 20 2b 3d 20 37 3b 0a 20 20 20 20 7d 65 6c 73 z += 7;. }els
a1b0: 65 7b 0a 20 20 20 20 20 20 70 75 74 63 68 61 72 e{. putchar
a1c0: 28 2a 7a 29 3b 0a 20 20 20 20 20 20 7a 2b 2b 3b (*z);. z++;
a1d0: 0a 20 20 20 20 7d 0a 20 20 7d 0a 20 20 70 75 74 . }. }. put
a1e0: 63 68 61 72 28 27 5c 6e 27 29 3b 0a 7d 0a 0a 2f char('\n');.}../
a1f0: 2a 0a 2a 2a 20 57 45 42 50 41 47 45 3a 20 68 65 *.** WEBPAGE: he
a200: 6c 70 0a 2a 2a 20 55 52 4c 3a 20 2f 68 65 6c 70 lp.** URL: /help
a210: 3f 6e 61 6d 65 3d 43 4d 44 0a 2a 2a 0a 2a 2a 20 ?name=CMD.**.**
a220: 53 68 6f 77 20 74 68 65 20 62 75 69 6c 74 2d 69 Show the built-i
a230: 6e 20 68 65 6c 70 20 74 65 78 74 20 66 6f 72 20 n help text for
a240: 43 4d 44 2e 20 20 43 4d 44 20 63 61 6e 20 62 65 CMD. CMD can be
a250: 20 61 20 63 6f 6d 6d 61 6e 64 2d 6c 69 6e 65 20 a command-line
a260: 69 6e 74 65 72 66 61 63 65 0a 2a 2a 20 63 6f 6d interface.** com
a270: 6d 61 6e 64 20 6f 72 20 61 20 70 61 67 65 20 6e mand or a page n
a280: 61 6d 65 20 66 72 6f 6d 20 74 68 65 20 77 65 62 ame from the web
a290: 20 69 6e 74 65 72 66 61 63 65 2e 0a 2a 2f 0a 76 interface..*/.v
a2a0: 6f 69 64 20 68 65 6c 70 5f 70 61 67 65 28 76 6f oid help_page(vo
a2b0: 69 64 29 7b 0a 20 20 63 6f 6e 73 74 20 63 68 61 id){. const cha
a2c0: 72 20 2a 7a 43 6d 64 20 3d 20 50 28 22 63 6d 64 r *zCmd = P("cmd
a2d0: 22 29 3b 0a 0a 20 20 69 66 28 20 7a 43 6d 64 3d ");.. if( zCmd=
a2e0: 3d 30 20 29 20 7a 43 6d 64 20 3d 20 50 28 22 6e =0 ) zCmd = P("n
a2f0: 61 6d 65 22 29 3b 0a 20 20 73 74 79 6c 65 5f 68 ame");. style_h
a300: 65 61 64 65 72 28 22 43 6f 6d 6d 61 6e 64 2d 6c eader("Command-l
a310: 69 6e 65 20 48 65 6c 70 22 29 3b 0a 20 20 69 66 ine Help");. if
a320: 28 20 7a 43 6d 64 20 29 7b 0a 20 20 20 20 69 6e ( zCmd ){. in
a330: 74 20 72 63 2c 20 69 64 78 3b 0a 20 20 20 20 63 t rc, idx;. c
a340: 68 61 72 20 2a 7a 2c 20 2a 73 2c 20 2a 64 3b 0a har *z, *s, *d;.
a350: 20 20 20 20 63 6f 6e 73 74 20 63 68 61 72 20 2a const char *
a360: 7a 43 6d 64 4f 72 50 61 67 65 20 3d 20 28 27 2f zCmdOrPage = ('/
a370: 27 3d 3d 2a 7a 43 6d 64 29 20 3f 20 22 70 61 67 '==*zCmd) ? "pag
a380: 65 22 20 3a 20 22 63 6f 6d 6d 61 6e 64 22 3b 0a e" : "command";.
a390: 20 20 20 20 73 74 79 6c 65 5f 73 75 62 6d 65 6e style_submen
a3a0: 75 5f 65 6c 65 6d 65 6e 74 28 22 43 6f 6d 6d 61 u_element("Comma
a3b0: 6e 64 2d 4c 69 73 74 22 2c 20 22 43 6f 6d 6d 61 nd-List", "Comma
a3c0: 6e 64 2d 4c 69 73 74 22 2c 20 22 25 73 2f 68 65 nd-List", "%s/he
a3d0: 6c 70 22 2c 20 67 2e 7a 54 6f 70 29 3b 0a 20 20 lp", g.zTop);.
a3e0: 20 20 40 20 3c 68 31 3e 54 68 65 20 22 25 73 28 @ <h1>The "%s(
a3f0: 7a 43 6d 64 29 22 20 25 73 28 7a 43 6d 64 4f 72 zCmd)" %s(zCmdOr
a400: 50 61 67 65 29 3a 3c 2f 68 31 3e 0a 20 20 20 20 Page):</h1>.
a410: 72 63 20 3d 20 6e 61 6d 65 5f 73 65 61 72 63 68 rc = name_search
a420: 28 7a 43 6d 64 2c 20 61 43 6f 6d 6d 61 6e 64 2c (zCmd, aCommand,
a430: 20 63 6f 75 6e 74 28 61 43 6f 6d 6d 61 6e 64 29 count(aCommand)
a440: 2c 20 30 2c 20 26 69 64 78 29 3b 0a 20 20 20 20 , 0, &idx);.
a450: 69 66 28 20 72 63 3d 3d 31 20 29 7b 0a 20 20 20 if( rc==1 ){.
a460: 20 20 20 40 20 75 6e 6b 6e 6f 77 6e 20 63 6f 6d @ unknown com
a470: 6d 61 6e 64 3a 20 25 73 28 7a 43 6d 64 29 0a 20 mand: %s(zCmd).
a480: 20 20 20 7d 65 6c 73 65 20 69 66 28 20 72 63 3d }else if( rc=
a490: 3d 32 20 29 7b 0a 20 20 20 20 20 20 40 20 61 6d =2 ){. @ am
a4a0: 62 69 67 75 6f 75 73 20 63 6f 6d 6d 61 6e 64 20 biguous command
a4b0: 70 72 65 66 69 78 3a 20 25 73 28 7a 43 6d 64 29 prefix: %s(zCmd)
a4c0: 0a 20 20 20 20 7d 65 6c 73 65 7b 0a 20 20 20 20 . }else{.
a4d0: 20 20 7a 20 3d 20 28 63 68 61 72 2a 29 61 43 6d z = (char*)aCm
a4e0: 64 48 65 6c 70 5b 69 64 78 5d 2e 7a 54 65 78 74 dHelp[idx].zText
a4f0: 3b 0a 20 20 20 20 20 20 69 66 28 20 7a 3d 3d 30 ;. if( z==0
a500: 20 29 7b 0a 20 20 20 20 20 20 20 20 40 20 6e 6f ){. @ no
a510: 20 68 65 6c 70 20 61 76 61 69 6c 61 62 6c 65 20 help available
a520: 66 6f 72 20 74 68 65 20 25 73 28 61 43 6f 6d 6d for the %s(aComm
a530: 61 6e 64 5b 69 64 78 5d 2e 7a 4e 61 6d 65 29 20 and[idx].zName)
a540: 63 6f 6d 6d 61 6e 64 0a 20 20 20 20 20 20 7d 65 command. }e
a550: 6c 73 65 7b 0a 20 20 20 20 20 20 20 20 7a 3d 73 lse{. z=s
a560: 3d 64 3d 6d 70 72 69 6e 74 66 28 22 25 73 22 2c =d=mprintf("%s",
a570: 7a 29 3b 0a 20 20 20 20 20 20 20 20 77 68 69 6c z);. whil
a580: 65 28 20 2a 73 20 29 7b 0a 20 20 20 20 20 20 20 e( *s ){.
a590: 20 20 20 69 66 28 20 2a 73 3d 3d 27 25 27 20 26 if( *s=='%' &
a5a0: 26 20 73 74 72 6e 63 6d 70 28 73 2c 20 22 25 66 & strncmp(s, "%f
a5b0: 6f 73 73 69 6c 22 2c 20 37 29 3d 3d 30 20 29 7b ossil", 7)==0 ){
a5c0: 0a 20 20 20 20 20 20 20 20 20 20 20 20 73 2b 2b . s++
a5d0: 3b 0a 20 20 20 20 20 20 20 20 20 20 7d 65 6c 73 ;. }els
a5e0: 65 7b 0a 20 20 20 20 20 20 20 20 20 20 20 20 2a e{. *
a5f0: 64 2b 2b 20 3d 20 2a 73 2b 2b 3b 0a 20 20 20 20 d++ = *s++;.
a600: 20 20 20 20 20 20 7d 0a 20 20 20 20 20 20 20 20 }.
a610: 7d 0a 20 20 20 20 20 20 20 20 2a 64 20 3d 20 30 }. *d = 0
a620: 3b 0a 20 20 20 20 20 20 20 20 40 20 3c 62 6c 6f ;. @ <blo
a630: 63 6b 71 75 6f 74 65 3e 3c 70 72 65 3e 0a 20 20 ckquote><pre>.
a640: 20 20 20 20 20 20 40 20 25 68 28 7a 29 0a 20 20 @ %h(z).
a650: 20 20 20 20 20 20 40 20 3c 2f 70 72 65 3e 3c 2f @ </pre></
a660: 62 6c 6f 63 6b 71 75 6f 74 65 3e 0a 20 20 20 20 blockquote>.
a670: 20 20 20 20 66 6f 73 73 69 6c 5f 66 72 65 65 28 fossil_free(
a680: 7a 29 3b 0a 20 20 20 20 20 20 7d 0a 20 20 20 20 z);. }.
a690: 7d 0a 20 20 7d 65 6c 73 65 7b 0a 20 20 20 20 69 }. }else{. i
a6a0: 6e 74 20 69 2c 20 6a 2c 20 6e 3b 0a 0a 20 20 20 nt i, j, n;..
a6b0: 20 40 20 3c 68 31 3e 41 76 61 69 6c 61 62 6c 65 @ <h1>Available
a6c0: 20 63 6f 6d 6d 61 6e 64 73 3a 3c 2f 68 31 3e 0a commands:</h1>.
a6d0: 20 20 20 20 40 20 3c 74 61 62 6c 65 20 62 6f 72 @ <table bor
a6e0: 64 65 72 3d 22 30 22 3e 3c 74 72 3e 0a 20 20 20 der="0"><tr>.
a6f0: 20 66 6f 72 28 69 3d 6a 3d 30 3b 20 69 3c 63 6f for(i=j=0; i<co
a700: 75 6e 74 28 61 43 6f 6d 6d 61 6e 64 29 3b 20 69 unt(aCommand); i
a710: 2b 2b 29 7b 0a 20 20 20 20 20 20 63 6f 6e 73 74 ++){. const
a720: 20 63 68 61 72 20 2a 7a 20 3d 20 61 43 6f 6d 6d char *z = aComm
a730: 61 6e 64 5b 69 5d 2e 7a 4e 61 6d 65 3b 0a 20 20 and[i].zName;.
a740: 20 20 20 20 69 66 28 20 27 2f 27 3d 3d 2a 7a 20 if( '/'==*z
a750: 7c 7c 20 73 74 72 6e 63 6d 70 28 7a 2c 22 74 65 || strncmp(z,"te
a760: 73 74 22 2c 34 29 3d 3d 30 20 29 20 63 6f 6e 74 st",4)==0 ) cont
a770: 69 6e 75 65 3b 0a 20 20 20 20 20 20 6a 2b 2b 3b inue;. j++;
a780: 0a 20 20 20 20 7d 0a 20 20 20 20 6e 20 3d 20 28 . }. n = (
a790: 6a 2b 36 29 2f 37 3b 0a 20 20 20 20 66 6f 72 28 j+6)/7;. for(
a7a0: 69 3d 6a 3d 30 3b 20 69 3c 63 6f 75 6e 74 28 61 i=j=0; i<count(a
a7b0: 43 6f 6d 6d 61 6e 64 29 3b 20 69 2b 2b 29 7b 0a Command); i++){.
a7c0: 20 20 20 20 20 20 63 6f 6e 73 74 20 63 68 61 72 const char
a7d0: 20 2a 7a 20 3d 20 61 43 6f 6d 6d 61 6e 64 5b 69 *z = aCommand[i
a7e0: 5d 2e 7a 4e 61 6d 65 3b 0a 20 20 20 20 20 20 69 ].zName;. i
a7f0: 66 28 20 27 2f 27 3d 3d 2a 7a 20 7c 7c 20 73 74 f( '/'==*z || st
a800: 72 6e 63 6d 70 28 7a 2c 22 74 65 73 74 22 2c 34 rncmp(z,"test",4
a810: 29 3d 3d 30 20 29 20 63 6f 6e 74 69 6e 75 65 3b )==0 ) continue;
a820: 0a 20 20 20 20 20 20 69 66 28 20 6a 3d 3d 30 20 . if( j==0
a830: 29 7b 0a 20 20 20 20 20 20 20 20 40 20 3c 74 64 ){. @ <td
a840: 20 76 61 6c 69 67 6e 3d 22 74 6f 70 22 3e 3c 75 valign="top"><u
a850: 6c 3e 0a 20 20 20 20 20 20 7d 0a 20 20 20 20 20 l>. }.
a860: 20 40 20 3c 6c 69 3e 3c 61 20 68 72 65 66 3d 22 @ <li><a href="
a870: 25 52 2f 68 65 6c 70 3f 63 6d 64 3d 25 73 28 7a %R/help?cmd=%s(z
a880: 29 22 3e 25 73 28 7a 29 3c 2f 61 3e 3c 2f 6c 69 )">%s(z)</a></li
a890: 3e 0a 20 20 20 20 20 20 6a 2b 2b 3b 0a 20 20 20 >. j++;.
a8a0: 20 20 20 69 66 28 20 6a 3e 3d 6e 20 29 7b 0a 20 if( j>=n ){.
a8b0: 20 20 20 20 20 20 20 40 20 3c 2f 75 6c 3e 3c 2f @ </ul></
a8c0: 74 64 3e 0a 20 20 20 20 20 20 20 20 6a 20 3d 20 td>. j =
a8d0: 30 3b 0a 20 20 20 20 20 20 7d 0a 20 20 20 20 7d 0;. }. }
a8e0: 0a 20 20 20 20 69 66 28 20 6a 3e 30 20 29 7b 0a . if( j>0 ){.
a8f0: 20 20 20 20 20 20 40 20 3c 2f 75 6c 3e 3c 2f 74 @ </ul></t
a900: 64 3e 0a 20 20 20 20 7d 0a 20 20 20 20 40 20 3c d>. }. @ <
a910: 2f 74 72 3e 3c 2f 74 61 62 6c 65 3e 0a 0a 20 20 /tr></table>..
a920: 20 20 40 20 3c 68 31 3e 41 76 61 69 6c 61 62 6c @ <h1>Availabl
a930: 65 20 77 65 62 20 55 49 20 70 61 67 65 73 3a 3c e web UI pages:<
a940: 2f 68 31 3e 0a 20 20 20 20 40 20 3c 74 61 62 6c /h1>. @ <tabl
a950: 65 20 62 6f 72 64 65 72 3d 22 30 22 3e 3c 74 72 e border="0"><tr
a960: 3e 0a 20 20 20 20 66 6f 72 28 69 3d 6a 3d 30 3b >. for(i=j=0;
a970: 20 69 3c 63 6f 75 6e 74 28 61 43 6f 6d 6d 61 6e i<count(aComman
a980: 64 29 3b 20 69 2b 2b 29 7b 0a 20 20 20 20 20 20 d); i++){.
a990: 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a 20 3d 20 const char *z =
a9a0: 61 43 6f 6d 6d 61 6e 64 5b 69 5d 2e 7a 4e 61 6d aCommand[i].zNam
a9b0: 65 3b 0a 20 20 20 20 20 20 69 66 28 20 27 2f 27 e;. if( '/'
a9c0: 21 3d 2a 7a 20 29 20 63 6f 6e 74 69 6e 75 65 3b !=*z ) continue;
a9d0: 0a 20 20 20 20 20 20 6a 2b 2b 3b 0a 20 20 20 20 . j++;.
a9e0: 7d 0a 20 20 20 20 6e 20 3d 20 28 6a 2b 34 29 2f }. n = (j+4)/
a9f0: 35 3b 0a 20 20 20 20 66 6f 72 28 69 3d 6a 3d 30 5;. for(i=j=0
aa00: 3b 20 69 3c 63 6f 75 6e 74 28 61 43 6f 6d 6d 61 ; i<count(aComma
aa10: 6e 64 29 3b 20 69 2b 2b 29 7b 0a 20 20 20 20 20 nd); i++){.
aa20: 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a 20 3d const char *z =
aa30: 20 61 43 6f 6d 6d 61 6e 64 5b 69 5d 2e 7a 4e 61 aCommand[i].zNa
aa40: 6d 65 3b 0a 20 20 20 20 20 20 69 66 28 20 27 2f me;. if( '/
aa50: 27 21 3d 2a 7a 20 29 20 63 6f 6e 74 69 6e 75 65 '!=*z ) continue
aa60: 3b 0a 20 20 20 20 20 20 69 66 28 20 6a 3d 3d 30 ;. if( j==0
aa70: 20 29 7b 0a 20 20 20 20 20 20 20 20 40 20 3c 74 ){. @ <t
aa80: 64 20 76 61 6c 69 67 6e 3d 22 74 6f 70 22 3e 3c d valign="top"><
aa90: 75 6c 3e 0a 20 20 20 20 20 20 7d 0a 20 20 20 20 ul>. }.
aaa0: 20 20 69 66 28 20 61 43 6d 64 48 65 6c 70 5b 69 if( aCmdHelp[i
aab0: 5d 2e 7a 54 65 78 74 20 26 26 20 2a 61 43 6d 64 ].zText && *aCmd
aac0: 48 65 6c 70 5b 69 5d 2e 7a 54 65 78 74 20 29 7b Help[i].zText ){
aad0: 0a 20 20 20 20 20 20 20 20 40 20 3c 6c 69 3e 3c . @ <li><
aae0: 61 20 68 72 65 66 3d 22 25 52 2f 68 65 6c 70 3f a href="%R/help?
aaf0: 63 6d 64 3d 25 73 28 7a 29 22 3e 25 73 28 7a 2b cmd=%s(z)">%s(z+
ab00: 31 29 3c 2f 61 3e 3c 2f 6c 69 3e 0a 20 20 20 20 1)</a></li>.
ab10: 20 20 7d 65 6c 73 65 7b 0a 20 20 20 20 20 20 20 }else{.
ab20: 20 40 20 3c 6c 69 3e 25 73 28 7a 2b 31 29 3c 2f @ <li>%s(z+1)</
ab30: 6c 69 3e 0a 20 20 20 20 20 20 7d 0a 20 20 20 20 li>. }.
ab40: 20 20 6a 2b 2b 3b 0a 20 20 20 20 20 20 69 66 28 j++;. if(
ab50: 20 6a 3e 3d 6e 20 29 7b 0a 20 20 20 20 20 20 20 j>=n ){.
ab60: 20 40 20 3c 2f 75 6c 3e 3c 2f 74 64 3e 0a 20 20 @ </ul></td>.
ab70: 20 20 20 20 20 20 6a 20 3d 20 30 3b 0a 20 20 20 j = 0;.
ab80: 20 20 20 7d 0a 20 20 20 20 7d 0a 20 20 20 20 69 }. }. i
ab90: 66 28 20 6a 3e 30 20 29 7b 0a 20 20 20 20 20 20 f( j>0 ){.
aba0: 40 20 3c 2f 75 6c 3e 3c 2f 74 64 3e 0a 20 20 20 @ </ul></td>.
abb0: 20 7d 0a 20 20 20 20 40 20 3c 2f 74 72 3e 3c 2f }. @ </tr></
abc0: 74 61 62 6c 65 3e 0a 0a 20 20 20 20 40 20 3c 68 table>.. @ <h
abd0: 31 3e 55 6e 73 75 70 70 6f 72 74 65 64 20 63 6f 1>Unsupported co
abe0: 6d 6d 61 6e 64 73 3a 3c 2f 68 31 3e 0a 20 20 20 mmands:</h1>.
abf0: 20 40 20 3c 74 61 62 6c 65 20 62 6f 72 64 65 72 @ <table border
ac00: 3d 22 30 22 3e 3c 74 72 3e 0a 20 20 20 20 66 6f ="0"><tr>. fo
ac10: 72 28 69 3d 6a 3d 30 3b 20 69 3c 63 6f 75 6e 74 r(i=j=0; i<count
ac20: 28 61 43 6f 6d 6d 61 6e 64 29 3b 20 69 2b 2b 29 (aCommand); i++)
ac30: 7b 0a 20 20 20 20 20 20 63 6f 6e 73 74 20 63 68 {. const ch
ac40: 61 72 20 2a 7a 20 3d 20 61 43 6f 6d 6d 61 6e 64 ar *z = aCommand
ac50: 5b 69 5d 2e 7a 4e 61 6d 65 3b 0a 20 20 20 20 20 [i].zName;.
ac60: 20 69 66 28 20 73 74 72 6e 63 6d 70 28 7a 2c 22 if( strncmp(z,"
ac70: 74 65 73 74 22 2c 34 29 21 3d 30 20 29 20 63 6f test",4)!=0 ) co
ac80: 6e 74 69 6e 75 65 3b 0a 20 20 20 20 20 20 6a 2b ntinue;. j+
ac90: 2b 3b 0a 20 20 20 20 7d 0a 20 20 20 20 6e 20 3d +;. }. n =
aca0: 20 28 6a 2b 33 29 2f 34 3b 0a 20 20 20 20 66 6f (j+3)/4;. fo
acb0: 72 28 69 3d 6a 3d 30 3b 20 69 3c 63 6f 75 6e 74 r(i=j=0; i<count
acc0: 28 61 43 6f 6d 6d 61 6e 64 29 3b 20 69 2b 2b 29 (aCommand); i++)
acd0: 7b 0a 20 20 20 20 20 20 63 6f 6e 73 74 20 63 68 {. const ch
ace0: 61 72 20 2a 7a 20 3d 20 61 43 6f 6d 6d 61 6e 64 ar *z = aCommand
acf0: 5b 69 5d 2e 7a 4e 61 6d 65 3b 0a 20 20 20 20 20 [i].zName;.
ad00: 20 69 66 28 20 73 74 72 6e 63 6d 70 28 7a 2c 22 if( strncmp(z,"
ad10: 74 65 73 74 22 2c 34 29 21 3d 30 20 29 20 63 6f test",4)!=0 ) co
ad20: 6e 74 69 6e 75 65 3b 0a 20 20 20 20 20 20 69 66 ntinue;. if
ad30: 28 20 6a 3d 3d 30 20 29 7b 0a 20 20 20 20 20 20 ( j==0 ){.
ad40: 20 20 40 20 3c 74 64 20 76 61 6c 69 67 6e 3d 22 @ <td valign="
ad50: 74 6f 70 22 3e 3c 75 6c 3e 0a 20 20 20 20 20 20 top"><ul>.
ad60: 7d 0a 20 20 20 20 20 20 69 66 28 20 61 43 6d 64 }. if( aCmd
ad70: 48 65 6c 70 5b 69 5d 2e 7a 54 65 78 74 20 26 26 Help[i].zText &&
ad80: 20 2a 61 43 6d 64 48 65 6c 70 5b 69 5d 2e 7a 54 *aCmdHelp[i].zT
ad90: 65 78 74 20 29 7b 0a 20 20 20 20 20 20 20 20 40 ext ){. @
ada0: 20 3c 6c 69 3e 3c 61 20 68 72 65 66 3d 22 25 52 <li><a href="%R
adb0: 2f 68 65 6c 70 3f 63 6d 64 3d 25 73 28 7a 29 22 /help?cmd=%s(z)"
adc0: 3e 25 73 28 7a 29 3c 2f 61 3e 3c 2f 6c 69 3e 0a >%s(z)</a></li>.
add0: 20 20 20 20 20 20 7d 65 6c 73 65 7b 0a 20 20 20 }else{.
ade0: 20 20 20 20 20 40 20 3c 6c 69 3e 25 73 28 7a 29 @ <li>%s(z)
adf0: 3c 2f 6c 69 3e 0a 20 20 20 20 20 20 7d 0a 20 20 </li>. }.
ae00: 20 20 20 20 6a 2b 2b 3b 0a 20 20 20 20 20 20 69 j++;. i
ae10: 66 28 20 6a 3e 3d 6e 20 29 7b 0a 20 20 20 20 20 f( j>=n ){.
ae20: 20 20 20 40 20 3c 2f 75 6c 3e 3c 2f 74 64 3e 0a @ </ul></td>.
ae30: 20 20 20 20 20 20 20 20 6a 20 3d 20 30 3b 0a 20 j = 0;.
ae40: 20 20 20 20 20 7d 0a 20 20 20 20 7d 0a 20 20 20 }. }.
ae50: 20 69 66 28 20 6a 3e 30 20 29 7b 0a 20 20 20 20 if( j>0 ){.
ae60: 20 20 40 20 3c 2f 75 6c 3e 3c 2f 74 64 3e 0a 20 @ </ul></td>.
ae70: 20 20 20 7d 0a 20 20 20 20 40 20 3c 2f 74 72 3e }. @ </tr>
ae80: 3c 2f 74 61 62 6c 65 3e 0a 0a 20 20 7d 0a 20 20 </table>.. }.
ae90: 73 74 79 6c 65 5f 66 6f 6f 74 65 72 28 29 3b 0a style_footer();.
aea0: 7d 0a 0a 2f 2a 0a 2a 2a 20 57 45 42 50 41 47 45 }../*.** WEBPAGE
aeb0: 3a 20 74 65 73 74 2d 61 6c 6c 2d 68 65 6c 70 0a : test-all-help.
aec0: 2a 2a 0a 2a 2a 20 53 68 6f 77 20 61 6c 6c 20 68 **.** Show all h
aed0: 65 6c 70 20 74 65 78 74 20 6f 6e 20 61 20 73 69 elp text on a si
aee0: 6e 67 6c 65 20 70 61 67 65 2e 20 20 55 73 65 66 ngle page. Usef
aef0: 75 6c 20 66 6f 72 20 70 72 6f 6f 66 2d 72 65 61 ul for proof-rea
af00: 64 69 6e 67 2e 0a 2a 2f 0a 76 6f 69 64 20 74 65 ding..*/.void te
af10: 73 74 5f 61 6c 6c 5f 68 65 6c 70 5f 70 61 67 65 st_all_help_page
af20: 28 76 6f 69 64 29 7b 0a 20 20 69 6e 74 20 69 3b (void){. int i;
af30: 0a 20 20 73 74 79 6c 65 5f 68 65 61 64 65 72 28 . style_header(
af40: 22 54 65 73 74 70 61 67 65 3a 20 41 6c 6c 20 48 "Testpage: All H
af50: 65 6c 70 20 54 65 78 74 22 29 3b 0a 20 20 66 6f elp Text");. fo
af60: 72 28 69 3d 30 3b 20 69 3c 63 6f 75 6e 74 28 61 r(i=0; i<count(a
af70: 43 6f 6d 6d 61 6e 64 29 3b 20 69 2b 2b 29 7b 0a Command); i++){.
af80: 20 20 20 20 69 66 28 20 6d 65 6d 63 6d 70 28 61 if( memcmp(a
af90: 43 6f 6d 6d 61 6e 64 5b 69 5d 2e 7a 4e 61 6d 65 Command[i].zName
afa0: 2c 20 22 74 65 73 74 22 2c 20 34 29 3d 3d 30 20 , "test", 4)==0
afb0: 29 20 63 6f 6e 74 69 6e 75 65 3b 0a 20 20 20 20 ) continue;.
afc0: 40 20 3c 68 32 3e 25 73 28 61 43 6f 6d 6d 61 6e @ <h2>%s(aComman
afd0: 64 5b 69 5d 2e 7a 4e 61 6d 65 29 3a 3c 2f 68 32 d[i].zName):</h2
afe0: 3e 0a 20 20 20 20 40 20 3c 62 6c 6f 63 6b 71 75 >. @ <blockqu
aff0: 6f 74 65 3e 3c 70 72 65 3e 0a 20 20 20 20 40 20 ote><pre>. @
b000: 25 68 28 61 43 6d 64 48 65 6c 70 5b 69 5d 2e 7a %h(aCmdHelp[i].z
b010: 54 65 78 74 29 0a 20 20 20 20 40 20 3c 2f 70 72 Text). @ </pr
b020: 65 3e 3c 2f 62 6c 6f 63 6b 71 75 6f 74 65 3e 0a e></blockquote>.
b030: 20 20 7d 0a 20 20 73 74 79 6c 65 5f 66 6f 6f 74 }. style_foot
b040: 65 72 28 29 3b 0a 7d 0a 0a 2f 2a 0a 2a 2a 20 53 er();.}../*.** S
b050: 65 74 20 74 68 65 20 67 2e 7a 42 61 73 65 55 52 et the g.zBaseUR
b060: 4c 20 76 61 6c 75 65 20 74 6f 20 74 68 65 20 66 L value to the f
b070: 75 6c 6c 20 55 52 4c 20 66 6f 72 20 74 68 65 20 ull URL for the
b080: 74 6f 70 6c 65 76 65 6c 20 6f 66 0a 2a 2a 20 74 toplevel of.** t
b090: 68 65 20 66 6f 73 73 69 6c 20 74 72 65 65 2e 20 he fossil tree.
b0a0: 20 53 65 74 20 67 2e 7a 54 6f 70 20 74 6f 20 67 Set g.zTop to g
b0b0: 2e 7a 42 61 73 65 55 52 4c 20 77 69 74 68 6f 75 .zBaseURL withou
b0c0: 74 20 74 68 65 0a 2a 2a 20 6c 65 61 64 69 6e 67 t the.** leading
b0d0: 20 22 68 74 74 70 3a 2f 2f 22 20 61 6e 64 20 74 "http://" and t
b0e0: 68 65 20 68 6f 73 74 20 61 6e 64 20 70 6f 72 74 he host and port
b0f0: 2e 0a 2a 2a 0a 2a 2a 20 54 68 65 20 67 2e 7a 42 ..**.** The g.zB
b100: 61 73 65 55 52 4c 20 69 73 20 6e 6f 72 6d 61 6c aseURL is normal
b110: 6c 79 20 73 65 74 20 62 61 73 65 64 20 6f 6e 20 ly set based on
b120: 48 54 54 50 5f 48 4f 53 54 20 61 6e 64 20 53 43 HTTP_HOST and SC
b130: 52 49 50 54 5f 4e 41 4d 45 0a 2a 2a 20 65 6e 76 RIPT_NAME.** env
b140: 69 72 6f 6e 6d 65 6e 74 20 76 61 72 69 61 62 6c ironment variabl
b150: 65 73 2e 20 20 48 6f 77 65 76 65 72 2c 20 69 66 es. However, if
b160: 20 7a 41 6c 74 42 61 73 65 20 69 73 20 6e 6f 74 zAltBase is not
b170: 20 4e 55 4c 4c 20 74 68 65 6e 20 69 74 0a 2a 2a NULL then it.**
b180: 20 69 73 20 74 68 65 20 61 72 67 75 6d 65 6e 74 is the argument
b190: 20 74 6f 20 74 68 65 20 2d 2d 62 61 73 65 75 72 to the --baseur
b1a0: 6c 20 6f 70 74 69 6f 6e 20 63 6f 6d 6d 61 6e 64 l option command
b1b0: 2d 6c 69 6e 65 20 6f 70 74 69 6f 6e 20 61 6e 64 -line option and
b1c0: 0a 2a 2a 20 67 2e 7a 42 61 73 65 55 52 4c 20 61 .** g.zBaseURL a
b1d0: 6e 64 20 67 2e 7a 54 6f 70 20 69 73 20 73 65 74 nd g.zTop is set
b1e0: 20 66 72 6f 6d 20 74 68 61 74 20 69 6e 73 74 65 from that inste
b1f0: 61 64 2e 0a 2a 2f 0a 73 74 61 74 69 63 20 76 6f ad..*/.static vo
b200: 69 64 20 73 65 74 5f 62 61 73 65 5f 75 72 6c 28 id set_base_url(
b210: 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a 41 6c 74 const char *zAlt
b220: 42 61 73 65 29 7b 0a 20 20 69 6e 74 20 69 3b 0a Base){. int i;.
b230: 20 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a 48 const char *zH
b240: 6f 73 74 3b 0a 20 20 63 6f 6e 73 74 20 63 68 61 ost;. const cha
b250: 72 20 2a 7a 4d 6f 64 65 3b 0a 20 20 63 6f 6e 73 r *zMode;. cons
b260: 74 20 63 68 61 72 20 2a 7a 43 75 72 3b 0a 0a 20 t char *zCur;..
b270: 20 69 66 28 20 67 2e 7a 42 61 73 65 55 52 4c 21 if( g.zBaseURL!
b280: 3d 30 20 29 20 72 65 74 75 72 6e 3b 0a 20 20 69 =0 ) return;. i
b290: 66 28 20 7a 41 6c 74 42 61 73 65 20 29 7b 0a 20 f( zAltBase ){.
b2a0: 20 20 20 69 6e 74 20 69 2c 20 6e 2c 20 63 3b 0a int i, n, c;.
b2b0: 20 20 20 20 67 2e 7a 54 6f 70 20 3d 20 67 2e 7a g.zTop = g.z
b2c0: 42 61 73 65 55 52 4c 20 3d 20 6d 70 72 69 6e 74 BaseURL = mprint
b2d0: 66 28 22 25 73 22 2c 20 7a 41 6c 74 42 61 73 65 f("%s", zAltBase
b2e0: 29 3b 0a 20 20 20 20 69 66 28 20 73 74 72 6e 63 );. if( strnc
b2f0: 6d 70 28 67 2e 7a 54 6f 70 2c 20 22 68 74 74 70 mp(g.zTop, "http
b300: 3a 2f 2f 22 2c 20 37 29 3d 3d 30 20 29 7b 0a 20 ://", 7)==0 ){.
b310: 20 20 20 20 20 2f 2a 20 69 74 20 69 73 20 48 54 /* it is HT
b320: 54 50 2c 20 72 65 70 6c 61 63 65 20 70 72 65 66 TP, replace pref
b330: 69 78 20 77 69 74 68 20 48 54 54 50 53 2e 20 2a ix with HTTPS. *
b340: 2f 0a 20 20 20 20 20 20 67 2e 7a 48 74 74 70 73 /. g.zHttps
b350: 55 52 4c 20 3d 20 6d 70 72 69 6e 74 66 28 22 68 URL = mprintf("h
b360: 74 74 70 73 3a 2f 2f 25 73 22 2c 20 26 67 2e 7a ttps://%s", &g.z
b370: 54 6f 70 5b 37 5d 29 3b 0a 20 20 20 20 7d 65 6c Top[7]);. }el
b380: 73 65 20 69 66 28 20 73 74 72 6e 63 6d 70 28 67 se if( strncmp(g
b390: 2e 7a 54 6f 70 2c 20 22 68 74 74 70 73 3a 2f 2f .zTop, "https://
b3a0: 22 2c 20 38 29 3d 3d 30 20 29 7b 0a 20 20 20 20 ", 8)==0 ){.
b3b0: 20 20 2f 2a 20 69 74 20 69 73 20 61 6c 72 65 61 /* it is alrea
b3c0: 64 79 20 48 54 54 50 53 2c 20 75 73 65 20 69 74 dy HTTPS, use it
b3d0: 2e 20 2a 2f 0a 20 20 20 20 20 20 67 2e 7a 48 74 . */. g.zHt
b3e0: 74 70 73 55 52 4c 20 3d 20 6d 70 72 69 6e 74 66 tpsURL = mprintf
b3f0: 28 22 25 73 22 2c 20 67 2e 7a 54 6f 70 29 3b 0a ("%s", g.zTop);.
b400: 20 20 20 20 7d 65 6c 73 65 7b 0a 20 20 20 20 20 }else{.
b410: 20 66 6f 73 73 69 6c 5f 66 61 74 61 6c 28 22 61 fossil_fatal("a
b420: 72 67 75 6d 65 6e 74 20 74 6f 20 2d 2d 62 61 73 rgument to --bas
b430: 65 75 72 6c 20 73 68 6f 75 6c 64 20 62 65 20 27 eurl should be '
b440: 68 74 74 70 3a 2f 2f 68 6f 73 74 2f 70 61 74 68 http://host/path
b450: 27 22 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 '".
b460: 20 20 20 20 20 20 22 20 6f 72 20 27 68 74 74 70 " or 'http
b470: 73 3a 2f 2f 68 6f 73 74 2f 70 61 74 68 27 22 29 s://host/path'")
b480: 3b 0a 20 20 20 20 7d 0a 20 20 20 20 66 6f 72 28 ;. }. for(
b490: 69 3d 6e 3d 30 3b 20 28 63 20 3d 20 67 2e 7a 54 i=n=0; (c = g.zT
b4a0: 6f 70 5b 69 5d 29 21 3d 30 3b 20 69 2b 2b 29 7b op[i])!=0; i++){
b4b0: 0a 20 20 20 20 20 20 69 66 28 20 63 3d 3d 27 2f . if( c=='/
b4c0: 27 20 29 7b 0a 20 20 20 20 20 20 20 20 6e 2b 2b ' ){. n++
b4d0: 3b 0a 20 20 20 20 20 20 20 20 69 66 28 20 6e 3d ;. if( n=
b4e0: 3d 33 20 29 7b 0a 20 20 20 20 20 20 20 20 20 20 =3 ){.
b4f0: 67 2e 7a 54 6f 70 20 2b 3d 20 69 3b 0a 20 20 20 g.zTop += i;.
b500: 20 20 20 20 20 20 20 62 72 65 61 6b 3b 0a 20 20 break;.
b510: 20 20 20 20 20 20 7d 0a 20 20 20 20 20 20 7d 0a }. }.
b520: 20 20 20 20 7d 0a 20 20 20 20 69 66 28 20 67 2e }. if( g.
b530: 7a 54 6f 70 3d 3d 67 2e 7a 42 61 73 65 55 52 4c zTop==g.zBaseURL
b540: 20 29 7b 0a 20 20 20 20 20 20 66 6f 73 73 69 6c ){. fossil
b550: 5f 66 61 74 61 6c 28 22 61 72 67 75 6d 65 6e 74 _fatal("argument
b560: 20 74 6f 20 2d 2d 62 61 73 65 75 72 6c 20 73 68 to --baseurl sh
b570: 6f 75 6c 64 20 62 65 20 27 68 74 74 70 3a 2f 2f ould be 'http://
b580: 68 6f 73 74 2f 70 61 74 68 27 22 0a 20 20 20 20 host/path'".
b590: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 22 "
b5a0: 20 6f 72 20 27 68 74 74 70 73 3a 2f 2f 68 6f 73 or 'https://hos
b5b0: 74 2f 70 61 74 68 27 22 29 3b 0a 20 20 20 20 7d t/path'");. }
b5c0: 0a 20 20 20 20 69 66 28 20 67 2e 7a 54 6f 70 5b . if( g.zTop[
b5d0: 31 5d 3d 3d 30 20 29 20 67 2e 7a 54 6f 70 2b 2b 1]==0 ) g.zTop++
b5e0: 3b 0a 20 20 7d 65 6c 73 65 7b 0a 20 20 20 20 7a ;. }else{. z
b5f0: 48 6f 73 74 20 3d 20 50 44 28 22 48 54 54 50 5f Host = PD("HTTP_
b600: 48 4f 53 54 22 2c 22 22 29 3b 0a 20 20 20 20 7a HOST","");. z
b610: 4d 6f 64 65 20 3d 20 50 44 28 22 48 54 54 50 53 Mode = PD("HTTPS
b620: 22 2c 22 6f 66 66 22 29 3b 0a 20 20 20 20 7a 43 ","off");. zC
b630: 75 72 20 3d 20 50 44 28 22 53 43 52 49 50 54 5f ur = PD("SCRIPT_
b640: 4e 41 4d 45 22 2c 22 2f 22 29 3b 0a 20 20 20 20 NAME","/");.
b650: 69 20 3d 20 73 74 72 6c 65 6e 28 7a 43 75 72 29 i = strlen(zCur)
b660: 3b 0a 20 20 20 20 77 68 69 6c 65 28 20 69 3e 30 ;. while( i>0
b670: 20 26 26 20 7a 43 75 72 5b 69 2d 31 5d 3d 3d 27 && zCur[i-1]=='
b680: 2f 27 20 29 20 69 2d 2d 3b 0a 20 20 20 20 69 66 /' ) i--;. if
b690: 28 20 66 6f 73 73 69 6c 5f 73 74 72 69 63 6d 70 ( fossil_stricmp
b6a0: 28 7a 4d 6f 64 65 2c 22 6f 6e 22 29 3d 3d 30 20 (zMode,"on")==0
b6b0: 29 7b 0a 20 20 20 20 20 20 67 2e 7a 42 61 73 65 ){. g.zBase
b6c0: 55 52 4c 20 3d 20 6d 70 72 69 6e 74 66 28 22 68 URL = mprintf("h
b6d0: 74 74 70 73 3a 2f 2f 25 73 25 2e 2a 73 22 2c 20 ttps://%s%.*s",
b6e0: 7a 48 6f 73 74 2c 20 69 2c 20 7a 43 75 72 29 3b zHost, i, zCur);
b6f0: 0a 20 20 20 20 20 20 67 2e 7a 54 6f 70 20 3d 20 . g.zTop =
b700: 26 67 2e 7a 42 61 73 65 55 52 4c 5b 38 2b 73 74 &g.zBaseURL[8+st
b710: 72 6c 65 6e 28 7a 48 6f 73 74 29 5d 3b 0a 20 20 rlen(zHost)];.
b720: 20 20 20 20 67 2e 7a 48 74 74 70 73 55 52 4c 20 g.zHttpsURL
b730: 3d 20 67 2e 7a 42 61 73 65 55 52 4c 3b 0a 20 20 = g.zBaseURL;.
b740: 20 20 7d 65 6c 73 65 7b 0a 20 20 20 20 20 20 67 }else{. g
b750: 2e 7a 42 61 73 65 55 52 4c 20 3d 20 6d 70 72 69 .zBaseURL = mpri
b760: 6e 74 66 28 22 68 74 74 70 3a 2f 2f 25 73 25 2e ntf("http://%s%.
b770: 2a 73 22 2c 20 7a 48 6f 73 74 2c 20 69 2c 20 7a *s", zHost, i, z
b780: 43 75 72 29 3b 0a 20 20 20 20 20 20 67 2e 7a 54 Cur);. g.zT
b790: 6f 70 20 3d 20 26 67 2e 7a 42 61 73 65 55 52 4c op = &g.zBaseURL
b7a0: 5b 37 2b 73 74 72 6c 65 6e 28 7a 48 6f 73 74 29 [7+strlen(zHost)
b7b0: 5d 3b 0a 20 20 20 20 20 20 67 2e 7a 48 74 74 70 ];. g.zHttp
b7c0: 73 55 52 4c 20 3d 20 6d 70 72 69 6e 74 66 28 22 sURL = mprintf("
b7d0: 68 74 74 70 73 3a 2f 2f 25 73 25 2e 2a 73 22 2c https://%s%.*s",
b7e0: 20 7a 48 6f 73 74 2c 20 69 2c 20 7a 43 75 72 29 zHost, i, zCur)
b7f0: 3b 0a 20 20 20 20 7d 0a 20 20 7d 0a 20 20 69 66 ;. }. }. if
b800: 28 20 64 62 5f 69 73 5f 77 72 69 74 65 61 62 6c ( db_is_writeabl
b810: 65 28 22 72 65 70 6f 73 69 74 6f 72 79 22 29 20 e("repository")
b820: 29 7b 0a 20 20 20 20 69 66 28 20 21 64 62 5f 65 ){. if( !db_e
b830: 78 69 73 74 73 28 22 53 45 4c 45 43 54 20 31 20 xists("SELECT 1
b840: 46 52 4f 4d 20 63 6f 6e 66 69 67 20 57 48 45 52 FROM config WHER
b850: 45 20 6e 61 6d 65 3d 27 62 61 73 65 75 72 6c 3a E name='baseurl:
b860: 25 71 27 22 2c 20 67 2e 7a 42 61 73 65 55 52 4c %q'", g.zBaseURL
b870: 29 29 7b 0a 20 20 20 20 20 20 64 62 5f 6d 75 6c )){. db_mul
b880: 74 69 5f 65 78 65 63 28 22 49 4e 53 45 52 54 20 ti_exec("INSERT
b890: 49 4e 54 4f 20 63 6f 6e 66 69 67 28 6e 61 6d 65 INTO config(name
b8a0: 2c 76 61 6c 75 65 2c 6d 74 69 6d 65 29 22 0a 20 ,value,mtime)".
b8b0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
b8c0: 20 20 20 22 56 41 4c 55 45 53 28 27 62 61 73 65 "VALUES('base
b8d0: 75 72 6c 3a 25 71 27 2c 31 2c 6e 6f 77 28 29 29 url:%q',1,now())
b8e0: 22 2c 20 67 2e 7a 42 61 73 65 55 52 4c 29 3b 0a ", g.zBaseURL);.
b8f0: 20 20 20 20 7d 65 6c 73 65 7b 0a 20 20 20 20 20 }else{.
b900: 20 64 62 5f 6f 70 74 69 6f 6e 61 6c 5f 73 71 6c db_optional_sql
b910: 28 22 72 65 70 6f 73 69 74 6f 72 79 22 2c 0a 20 ("repository",.
b920: 20 20 20 20 20 20 20 20 20 20 22 52 45 50 4c 41 "REPLA
b930: 43 45 20 49 4e 54 4f 20 63 6f 6e 66 69 67 28 6e CE INTO config(n
b940: 61 6d 65 2c 76 61 6c 75 65 2c 6d 74 69 6d 65 29 ame,value,mtime)
b950: 22 0a 20 20 20 20 20 20 20 20 20 20 20 22 56 41 ". "VA
b960: 4c 55 45 53 28 27 62 61 73 65 75 72 6c 3a 25 71 LUES('baseurl:%q
b970: 27 2c 31 2c 6e 6f 77 28 29 29 22 2c 20 67 2e 7a ',1,now())", g.z
b980: 42 61 73 65 55 52 4c 0a 20 20 20 20 20 20 29 3b BaseURL. );
b990: 0a 20 20 20 20 7d 0a 20 20 7d 0a 7d 0a 0a 2f 2a . }. }.}../*
b9a0: 0a 2a 2a 20 53 65 6e 64 20 61 6e 20 48 54 54 50 .** Send an HTTP
b9b0: 20 72 65 64 69 72 65 63 74 20 62 61 63 6b 20 74 redirect back t
b9c0: 6f 20 74 68 65 20 64 65 73 69 67 6e 61 74 65 64 o the designated
b9d0: 20 49 6e 64 65 78 20 50 61 67 65 2e 0a 2a 2f 0a Index Page..*/.
b9e0: 4e 4f 52 45 54 55 52 4e 20 76 6f 69 64 20 66 6f NORETURN void fo
b9f0: 73 73 69 6c 5f 72 65 64 69 72 65 63 74 5f 68 6f ssil_redirect_ho
ba00: 6d 65 28 76 6f 69 64 29 7b 0a 20 20 63 67 69 5f me(void){. cgi_
ba10: 72 65 64 69 72 65 63 74 66 28 22 25 73 25 73 22 redirectf("%s%s"
ba20: 2c 20 67 2e 7a 54 6f 70 2c 20 64 62 5f 67 65 74 , g.zTop, db_get
ba30: 28 22 69 6e 64 65 78 2d 70 61 67 65 22 2c 20 22 ("index-page", "
ba40: 2f 69 6e 64 65 78 22 29 29 3b 0a 7d 0a 0a 2f 2a /index"));.}../*
ba50: 0a 2a 2a 20 49 66 20 72 75 6e 6e 69 6e 67 20 61 .** If running a
ba60: 73 20 72 6f 6f 74 2c 20 63 68 72 6f 6f 74 20 74 s root, chroot t
ba70: 6f 20 74 68 65 20 64 69 72 65 63 74 6f 72 79 20 o the directory
ba80: 63 6f 6e 74 61 69 6e 69 6e 67 20 74 68 65 0a 2a containing the.*
ba90: 2a 20 72 65 70 6f 73 69 74 6f 72 79 20 7a 52 65 * repository zRe
baa0: 70 6f 20 61 6e 64 20 74 68 65 6e 20 64 72 6f 70 po and then drop
bab0: 20 72 6f 6f 74 20 70 72 69 76 69 6c 65 67 65 73 root privileges
bac0: 2e 20 20 52 65 74 75 72 6e 20 74 68 65 0a 2a 2a . Return the.**
bad0: 20 6e 65 77 20 72 65 70 6f 73 69 74 6f 72 79 20 new repository
bae0: 6e 61 6d 65 2e 0a 2a 2a 0a 2a 2a 20 7a 52 65 70 name..**.** zRep
baf0: 6f 20 6d 69 67 68 74 20 62 65 20 61 20 64 69 72 o might be a dir
bb00: 65 63 74 6f 72 79 20 69 74 73 65 6c 66 2e 20 20 ectory itself.
bb10: 49 6e 20 74 68 61 74 20 63 61 73 65 20 63 68 72 In that case chr
bb20: 6f 6f 74 20 69 6e 74 6f 0a 2a 2a 20 74 68 65 20 oot into.** the
bb30: 64 69 72 65 63 74 6f 72 79 20 7a 52 65 70 6f 2e directory zRepo.
bb40: 0a 2a 2a 0a 2a 2a 20 41 73 73 75 6d 65 20 74 68 .**.** Assume th
bb50: 65 20 75 73 65 72 2d 69 64 20 61 6e 64 20 67 72 e user-id and gr
bb60: 6f 75 70 2d 69 64 20 6f 66 20 74 68 65 20 72 65 oup-id of the re
bb70: 70 6f 73 69 74 6f 72 79 2c 20 6f 72 20 69 66 20 pository, or if
bb80: 7a 52 65 70 6f 0a 2a 2a 20 69 73 20 61 20 64 69 zRepo.** is a di
bb90: 72 65 63 74 6f 72 79 2c 20 6f 66 20 74 68 61 74 rectory, of that
bba0: 20 64 69 72 65 63 74 6f 72 79 2e 0a 2a 2a 0a 2a directory..**.*
bbb0: 2a 20 54 68 65 20 6e 6f 4a 61 69 6c 20 66 6c 61 * The noJail fla
bbc0: 67 20 6d 65 61 6e 73 20 74 68 61 74 20 74 68 65 g means that the
bbd0: 20 63 68 72 6f 6f 74 20 6a 61 69 6c 20 69 73 20 chroot jail is
bbe0: 6e 6f 74 20 65 6e 74 65 72 65 64 2e 20 20 42 75 not entered. Bu
bbf0: 74 0a 2a 2a 20 70 72 69 76 69 6c 65 67 65 73 20 t.** privileges
bc00: 61 72 65 20 73 74 69 6c 6c 20 6c 6f 77 65 72 65 are still lowere
bc10: 64 20 74 6f 20 74 68 61 74 20 6f 66 20 74 68 65 d to that of the
bc20: 20 75 73 65 72 2d 69 64 20 61 6e 64 20 67 72 6f user-id and gro
bc30: 75 70 2d 69 64 0a 2a 2a 20 6f 66 20 74 68 65 20 up-id.** of the
bc40: 72 65 70 6f 73 69 74 6f 72 79 20 66 69 6c 65 2e repository file.
bc50: 0a 2a 2f 0a 73 74 61 74 69 63 20 63 68 61 72 20 .*/.static char
bc60: 2a 65 6e 74 65 72 5f 63 68 72 6f 6f 74 5f 6a 61 *enter_chroot_ja
bc70: 69 6c 28 63 68 61 72 20 2a 7a 52 65 70 6f 2c 20 il(char *zRepo,
bc80: 69 6e 74 20 6e 6f 4a 61 69 6c 29 7b 0a 23 69 66 int noJail){.#if
bc90: 20 21 64 65 66 69 6e 65 64 28 5f 57 49 4e 33 32 !defined(_WIN32
bca0: 29 0a 20 20 69 66 28 20 67 65 74 75 69 64 28 29 ). if( getuid()
bcb0: 3d 3d 30 20 29 7b 0a 20 20 20 20 69 6e 74 20 69 ==0 ){. int i
bcc0: 3b 0a 20 20 20 20 73 74 72 75 63 74 20 73 74 61 ;. struct sta
bcd0: 74 20 73 53 74 61 74 3b 0a 20 20 20 20 42 6c 6f t sStat;. Blo
bce0: 62 20 64 69 72 3b 0a 20 20 20 20 63 68 61 72 20 b dir;. char
bcf0: 2a 7a 44 69 72 3b 0a 20 20 20 20 69 66 28 20 67 *zDir;. if( g
bd00: 2e 64 62 21 3d 30 20 29 7b 0a 20 20 20 20 20 20 .db!=0 ){.
bd10: 64 62 5f 63 6c 6f 73 65 28 31 29 3b 0a 20 20 20 db_close(1);.
bd20: 20 7d 0a 0a 20 20 20 20 66 69 6c 65 5f 63 61 6e }.. file_can
bd30: 6f 6e 69 63 61 6c 5f 6e 61 6d 65 28 7a 52 65 70 onical_name(zRep
bd40: 6f 2c 20 26 64 69 72 2c 20 30 29 3b 0a 20 20 20 o, &dir, 0);.
bd50: 20 7a 44 69 72 20 3d 20 62 6c 6f 62 5f 73 74 72 zDir = blob_str
bd60: 28 26 64 69 72 29 3b 0a 20 20 20 20 69 66 28 20 (&dir);. if(
bd70: 21 6e 6f 4a 61 69 6c 20 29 7b 0a 20 20 20 20 20 !noJail ){.
bd80: 20 69 66 28 20 66 69 6c 65 5f 69 73 64 69 72 28 if( file_isdir(
bd90: 7a 44 69 72 29 3d 3d 31 20 29 7b 0a 20 20 20 20 zDir)==1 ){.
bda0: 20 20 20 20 69 66 28 20 66 69 6c 65 5f 63 68 64 if( file_chd
bdb0: 69 72 28 7a 44 69 72 2c 20 31 29 20 29 7b 0a 20 ir(zDir, 1) ){.
bdc0: 20 20 20 20 20 20 20 20 20 66 6f 73 73 69 6c 5f fossil_
bdd0: 66 61 74 61 6c 28 22 75 6e 61 62 6c 65 20 74 6f fatal("unable to
bde0: 20 63 68 72 6f 6f 74 20 69 6e 74 6f 20 25 73 22 chroot into %s"
bdf0: 2c 20 7a 44 69 72 29 3b 0a 20 20 20 20 20 20 20 , zDir);.
be00: 20 7d 0a 20 20 20 20 20 20 20 20 7a 52 65 70 6f }. zRepo
be10: 20 3d 20 22 2f 22 3b 0a 20 20 20 20 20 20 7d 65 = "/";. }e
be20: 6c 73 65 7b 0a 20 20 20 20 20 20 20 20 66 6f 72 lse{. for
be30: 28 69 3d 73 74 72 6c 65 6e 28 7a 44 69 72 29 2d (i=strlen(zDir)-
be40: 31 3b 20 69 3e 30 20 26 26 20 7a 44 69 72 5b 69 1; i>0 && zDir[i
be50: 5d 21 3d 27 2f 27 3b 20 69 2d 2d 29 7b 7d 0a 20 ]!='/'; i--){}.
be60: 20 20 20 20 20 20 20 69 66 28 20 7a 44 69 72 5b if( zDir[
be70: 69 5d 21 3d 27 2f 27 20 29 20 66 6f 73 73 69 6c i]!='/' ) fossil
be80: 5f 66 61 74 61 6c 28 22 62 61 64 20 72 65 70 6f _fatal("bad repo
be90: 73 69 74 6f 72 79 20 6e 61 6d 65 3a 20 25 73 22 sitory name: %s"
bea0: 2c 20 7a 52 65 70 6f 29 3b 0a 20 20 20 20 20 20 , zRepo);.
beb0: 20 20 69 66 28 20 69 3e 30 20 29 7b 0a 20 20 20 if( i>0 ){.
bec0: 20 20 20 20 20 20 20 7a 44 69 72 5b 69 5d 20 3d zDir[i] =
bed0: 20 30 3b 0a 20 20 20 20 20 20 20 20 20 20 69 66 0;. if
bee0: 28 20 66 69 6c 65 5f 63 68 64 69 72 28 7a 44 69 ( file_chdir(zDi
bef0: 72 2c 20 31 29 20 29 7b 0a 20 20 20 20 20 20 20 r, 1) ){.
bf00: 20 20 20 20 20 66 6f 73 73 69 6c 5f 66 61 74 61 fossil_fata
bf10: 6c 28 22 75 6e 61 62 6c 65 20 74 6f 20 63 68 72 l("unable to chr
bf20: 6f 6f 74 20 69 6e 74 6f 20 25 73 22 2c 20 7a 44 oot into %s", zD
bf30: 69 72 29 3b 0a 20 20 20 20 20 20 20 20 20 20 7d ir);. }
bf40: 0a 20 20 20 20 20 20 20 20 20 20 7a 44 69 72 5b . zDir[
bf50: 69 5d 20 3d 20 27 2f 27 3b 0a 20 20 20 20 20 20 i] = '/';.
bf60: 20 20 7d 0a 20 20 20 20 20 20 20 20 7a 52 65 70 }. zRep
bf70: 6f 20 3d 20 26 7a 44 69 72 5b 69 5d 3b 0a 20 20 o = &zDir[i];.
bf80: 20 20 20 20 7d 0a 20 20 20 20 7d 0a 20 20 20 20 }. }.
bf90: 69 66 28 20 73 74 61 74 28 7a 52 65 70 6f 2c 20 if( stat(zRepo,
bfa0: 26 73 53 74 61 74 29 21 3d 30 20 29 7b 0a 20 20 &sStat)!=0 ){.
bfb0: 20 20 20 20 66 6f 73 73 69 6c 5f 66 61 74 61 6c fossil_fatal
bfc0: 28 22 63 61 6e 6e 6f 74 20 73 74 61 74 28 29 20 ("cannot stat()
bfd0: 72 65 70 6f 73 69 74 6f 72 79 3a 20 25 73 22 2c repository: %s",
bfe0: 20 7a 52 65 70 6f 29 3b 0a 20 20 20 20 7d 0a 20 zRepo);. }.
bff0: 20 20 20 69 20 3d 20 73 65 74 67 69 64 28 73 53 i = setgid(sS
c000: 74 61 74 2e 73 74 5f 67 69 64 29 3b 0a 20 20 20 tat.st_gid);.
c010: 20 69 20 3d 20 69 20 7c 7c 20 73 65 74 75 69 64 i = i || setuid
c020: 28 73 53 74 61 74 2e 73 74 5f 75 69 64 29 3b 0a (sStat.st_uid);.
c030: 20 20 20 20 69 66 28 69 29 7b 0a 20 20 20 20 20 if(i){.
c040: 20 66 6f 73 73 69 6c 5f 66 61 74 61 6c 28 22 73 fossil_fatal("s
c050: 65 74 67 69 64 2f 75 69 64 28 29 20 66 61 69 6c etgid/uid() fail
c060: 65 64 20 77 69 74 68 20 65 72 72 6e 6f 20 25 64 ed with errno %d
c070: 22 2c 20 65 72 72 6e 6f 29 3b 0a 20 20 20 20 7d ", errno);. }
c080: 0a 20 20 20 20 69 66 28 20 67 2e 64 62 3d 3d 30 . if( g.db==0
c090: 20 26 26 20 66 69 6c 65 5f 69 73 66 69 6c 65 28 && file_isfile(
c0a0: 7a 52 65 70 6f 29 20 29 7b 0a 20 20 20 20 20 20 zRepo) ){.
c0b0: 64 62 5f 6f 70 65 6e 5f 72 65 70 6f 73 69 74 6f db_open_reposito
c0c0: 72 79 28 7a 52 65 70 6f 29 3b 0a 20 20 20 20 7d ry(zRepo);. }
c0d0: 0a 20 20 7d 0a 23 65 6e 64 69 66 0a 20 20 72 65 . }.#endif. re
c0e0: 74 75 72 6e 20 7a 52 65 70 6f 3b 0a 7d 0a 0a 2f turn zRepo;.}../
c0f0: 2a 0a 2a 2a 20 47 65 6e 65 72 61 74 65 20 61 20 *.** Generate a
c100: 77 65 62 2d 70 61 67 65 20 74 68 61 74 20 6c 69 web-page that li
c110: 73 74 73 20 61 6c 6c 20 72 65 70 6f 73 69 74 6f sts all reposito
c120: 72 69 65 73 20 6c 6f 63 61 74 65 64 20 75 6e 64 ries located und
c130: 65 72 20 74 68 65 0a 2a 2a 20 67 2e 7a 52 65 70 er the.** g.zRep
c140: 6f 73 69 74 6f 72 79 4e 61 6d 65 20 64 69 72 65 ositoryName dire
c150: 63 74 6f 72 79 20 61 6e 64 20 72 65 74 75 72 6e ctory and return
c160: 20 6e 6f 6e 2d 7a 65 72 6f 2e 0a 2a 2a 0a 2a 2a non-zero..**.**
c170: 20 4f 72 2c 20 69 66 20 6e 6f 20 72 65 70 6f 73 Or, if no repos
c180: 69 74 6f 72 69 65 73 20 63 61 6e 20 62 65 20 6c itories can be l
c190: 6f 63 61 74 65 64 20 62 65 6e 65 61 74 68 20 67 ocated beneath g
c1a0: 2e 7a 52 65 70 6f 73 69 74 6f 72 79 4e 61 6d 65 .zRepositoryName
c1b0: 2c 0a 2a 2a 20 72 65 74 75 72 6e 20 30 2e 0a 2a ,.** return 0..*
c1c0: 2f 0a 73 74 61 74 69 63 20 69 6e 74 20 72 65 70 /.static int rep
c1d0: 6f 5f 6c 69 73 74 5f 70 61 67 65 28 76 6f 69 64 o_list_page(void
c1e0: 29 7b 0a 20 20 42 6c 6f 62 20 62 61 73 65 3b 0a ){. Blob base;.
c1f0: 20 20 69 6e 74 20 6e 20 3d 20 30 3b 0a 0a 20 20 int n = 0;..
c200: 61 73 73 65 72 74 28 20 67 2e 64 62 3d 3d 30 20 assert( g.db==0
c210: 29 3b 0a 20 20 62 6c 6f 62 5f 69 6e 69 74 28 26 );. blob_init(&
c220: 62 61 73 65 2c 20 67 2e 7a 52 65 70 6f 73 69 74 base, g.zReposit
c230: 6f 72 79 4e 61 6d 65 2c 20 2d 31 29 3b 0a 20 20 oryName, -1);.
c240: 73 71 6c 69 74 65 33 5f 6f 70 65 6e 28 22 3a 6d sqlite3_open(":m
c250: 65 6d 6f 72 79 3a 22 2c 20 26 67 2e 64 62 29 3b emory:", &g.db);
c260: 0a 20 20 64 62 5f 6d 75 6c 74 69 5f 65 78 65 63 . db_multi_exec
c270: 28 22 43 52 45 41 54 45 20 54 41 42 4c 45 20 73 ("CREATE TABLE s
c280: 66 69 6c 65 28 78 20 54 45 58 54 29 3b 22 29 3b file(x TEXT);");
c290: 0a 20 20 64 62 5f 6d 75 6c 74 69 5f 65 78 65 63 . db_multi_exec
c2a0: 28 22 43 52 45 41 54 45 20 54 41 42 4c 45 20 76 ("CREATE TABLE v
c2b0: 66 69 6c 65 28 70 61 74 68 6e 61 6d 65 29 3b 22 file(pathname);"
c2c0: 29 3b 0a 20 20 76 66 69 6c 65 5f 73 63 61 6e 28 );. vfile_scan(
c2d0: 26 62 61 73 65 2c 20 62 6c 6f 62 5f 73 69 7a 65 &base, blob_size
c2e0: 28 26 62 61 73 65 29 2c 20 30 2c 20 30 2c 20 30 (&base), 0, 0, 0
c2f0: 29 3b 0a 20 20 64 62 5f 6d 75 6c 74 69 5f 65 78 );. db_multi_ex
c300: 65 63 28 22 44 45 4c 45 54 45 20 46 52 4f 4d 20 ec("DELETE FROM
c310: 73 66 69 6c 65 20 57 48 45 52 45 20 78 20 4e 4f sfile WHERE x NO
c320: 54 20 47 4c 4f 42 20 27 2a 5b 5e 2f 5d 2e 66 6f T GLOB '*[^/].fo
c330: 73 73 69 6c 27 22 29 3b 0a 20 20 6e 20 3d 20 64 ssil'");. n = d
c340: 62 5f 69 6e 74 28 30 2c 20 22 53 45 4c 45 43 54 b_int(0, "SELECT
c350: 20 63 6f 75 6e 74 28 2a 29 20 46 52 4f 4d 20 73 count(*) FROM s
c360: 66 69 6c 65 22 29 3b 0a 20 20 69 66 28 20 6e 3e file");. if( n>
c370: 30 20 29 7b 0a 20 20 20 20 53 74 6d 74 20 71 3b 0 ){. Stmt q;
c380: 0a 20 20 20 20 40 20 3c 68 74 6d 6c 3e 0a 20 20 . @ <html>.
c390: 20 20 40 20 3c 68 65 61 64 3e 0a 20 20 20 20 40 @ <head>. @
c3a0: 20 3c 74 69 74 6c 65 3e 52 65 70 6f 73 69 74 6f <title>Reposito
c3b0: 72 79 20 4c 69 73 74 3c 2f 74 69 74 6c 65 3e 0a ry List</title>.
c3c0: 20 20 20 20 40 20 3c 2f 68 65 61 64 3e 0a 20 20 @ </head>.
c3d0: 20 20 40 20 3c 62 6f 64 79 3e 0a 20 20 20 20 40 @ <body>. @
c3e0: 20 3c 68 31 3e 41 76 61 69 6c 61 62 6c 65 20 52 <h1>Available R
c3f0: 65 70 6f 73 69 74 6f 72 69 65 73 3a 3c 2f 68 31 epositories:</h1
c400: 3e 0a 20 20 20 20 40 20 3c 6f 6c 3e 0a 20 20 20 >. @ <ol>.
c410: 20 64 62 5f 70 72 65 70 61 72 65 28 26 71 2c 20 db_prepare(&q,
c420: 22 53 45 4c 45 43 54 20 78 2c 20 73 75 62 73 74 "SELECT x, subst
c430: 72 28 78 2c 2d 37 2c 2d 31 30 30 30 30 30 29 7c r(x,-7,-100000)|
c440: 7c 27 2f 68 6f 6d 65 27 22 0a 20 20 20 20 20 20 |'/home'".
c450: 20 20 20 20 20 20 20 20 20 20 20 20 20 22 20 46 " F
c460: 52 4f 4d 20 73 66 69 6c 65 20 4f 52 44 45 52 20 ROM sfile ORDER
c470: 42 59 20 78 20 43 4f 4c 4c 41 54 45 20 6e 6f 63 BY x COLLATE noc
c480: 61 73 65 3b 22 29 3b 0a 20 20 20 20 77 68 69 6c ase;");. whil
c490: 65 28 20 64 62 5f 73 74 65 70 28 26 71 29 3d 3d e( db_step(&q)==
c4a0: 53 51 4c 49 54 45 5f 52 4f 57 20 29 7b 0a 20 20 SQLITE_ROW ){.
c4b0: 20 20 20 20 63 6f 6e 73 74 20 63 68 61 72 20 2a const char *
c4c0: 7a 4e 61 6d 65 20 3d 20 64 62 5f 63 6f 6c 75 6d zName = db_colum
c4d0: 6e 5f 74 65 78 74 28 26 71 2c 20 30 29 3b 0a 20 n_text(&q, 0);.
c4e0: 20 20 20 20 20 63 6f 6e 73 74 20 63 68 61 72 20 const char
c4f0: 2a 7a 55 72 6c 20 3d 20 64 62 5f 63 6f 6c 75 6d *zUrl = db_colum
c500: 6e 5f 74 65 78 74 28 26 71 2c 20 31 29 3b 0a 20 n_text(&q, 1);.
c510: 20 20 20 20 20 40 20 3c 6c 69 3e 3c 61 20 68 72 @ <li><a hr
c520: 65 66 3d 22 25 68 28 7a 55 72 6c 29 22 20 74 61 ef="%h(zUrl)" ta
c530: 72 67 65 74 3d 22 5f 62 6c 61 6e 6b 22 3e 25 68 rget="_blank">%h
c540: 28 7a 4e 61 6d 65 29 3c 2f 61 3e 3c 2f 6c 69 3e (zName)</a></li>
c550: 0a 20 20 20 20 7d 0a 20 20 20 20 40 20 3c 2f 6f . }. @ </o
c560: 6c 3e 0a 20 20 20 20 40 20 3c 2f 62 6f 64 79 3e l>. @ </body>
c570: 0a 20 20 20 20 40 20 3c 2f 68 74 6d 6c 3e 0a 20 . @ </html>.
c580: 20 20 20 63 67 69 5f 72 65 70 6c 79 28 29 3b 0a cgi_reply();.
c590: 20 20 7d 0a 20 20 73 71 6c 69 74 65 33 5f 63 6c }. sqlite3_cl
c5a0: 6f 73 65 28 67 2e 64 62 29 3b 0a 20 20 67 2e 64 ose(g.db);. g.d
c5b0: 62 20 3d 20 30 3b 0a 20 20 72 65 74 75 72 6e 20 b = 0;. return
c5c0: 6e 3b 0a 7d 0a 0a 2f 2a 0a 2a 2a 20 50 72 65 63 n;.}../*.** Prec
c5d0: 6f 6e 64 69 74 69 6f 6e 73 3a 0a 2a 2a 0a 2a 2a onditions:.**.**
c5e0: 20 20 2a 20 45 6e 76 69 72 6f 6e 6d 65 6e 74 20 * Environment
c5f0: 76 61 72 69 61 62 6c 65 73 20 61 72 65 20 73 65 variables are se
c600: 74 20 75 70 20 61 63 63 6f 72 64 69 6e 67 20 74 t up according t
c610: 6f 20 74 68 65 20 43 47 49 20 73 74 61 6e 64 61 o the CGI standa
c620: 72 64 2e 0a 2a 2a 0a 2a 2a 20 49 66 20 74 68 65 rd..**.** If the
c630: 20 72 65 70 6f 73 69 74 6f 72 79 20 69 73 20 6b repository is k
c640: 6e 6f 77 6e 2c 20 69 74 20 68 61 73 20 61 6c 72 nown, it has alr
c650: 65 61 64 79 20 62 65 65 6e 20 6f 70 65 6e 65 64 eady been opened
c660: 2e 20 20 49 66 20 75 6e 6b 6e 6f 77 6e 2c 0a 2a . If unknown,.*
c670: 2a 20 74 68 65 6e 20 67 2e 7a 52 65 70 6f 73 69 * then g.zReposi
c680: 74 6f 72 79 4e 61 6d 65 20 68 6f 6c 64 73 20 74 toryName holds t
c690: 68 65 20 64 69 72 65 63 74 6f 72 79 20 74 68 61 he directory tha
c6a0: 74 20 63 6f 6e 74 61 69 6e 73 20 74 68 65 20 72 t contains the r
c6b0: 65 70 6f 73 69 74 6f 72 79 0a 2a 2a 20 61 6e 64 epository.** and
c6c0: 20 74 68 65 20 61 63 74 75 61 6c 20 72 65 70 6f the actual repo
c6d0: 73 69 74 6f 72 79 20 69 73 20 74 61 6b 65 6e 20 sitory is taken
c6e0: 66 72 6f 6d 20 74 68 65 20 66 69 72 73 74 20 65 from the first e
c6f0: 6c 65 6d 65 6e 74 20 6f 66 20 50 41 54 48 5f 49 lement of PATH_I
c700: 4e 46 4f 2e 0a 2a 2a 0a 2a 2a 20 50 72 6f 63 65 NFO..**.** Proce
c710: 73 73 20 74 68 65 20 77 65 62 70 61 67 65 20 73 ss the webpage s
c720: 70 65 63 69 66 69 65 64 20 62 79 20 74 68 65 20 pecified by the
c730: 50 41 54 48 5f 49 4e 46 4f 20 6f 72 20 52 45 51 PATH_INFO or REQ
c740: 55 45 53 54 5f 55 52 49 0a 2a 2a 20 65 6e 76 69 UEST_URI.** envi
c750: 72 6f 6e 6d 65 6e 74 20 76 61 72 69 61 62 6c 65 ronment variable
c760: 2e 0a 2a 2a 0a 2a 2a 20 49 66 20 74 68 65 20 72 ..**.** If the r
c770: 65 70 6f 73 69 74 6f 72 79 20 69 73 20 6e 6f 74 epository is not
c780: 20 6b 6e 6f 77 6e 2c 20 74 68 65 6e 20 61 20 73 known, then a s
c790: 65 61 72 63 68 20 69 73 20 64 6f 6e 65 20 74 68 earch is done th
c7a0: 72 6f 75 67 68 20 74 68 65 0a 2a 2a 20 66 69 6c rough the.** fil
c7b0: 65 20 68 69 65 72 61 72 63 68 79 20 72 6f 6f 74 e hierarchy root
c7c0: 65 64 20 61 74 20 67 2e 7a 52 65 70 6f 73 69 74 ed at g.zReposit
c7d0: 6f 72 79 4e 61 6d 65 20 66 6f 72 20 61 20 73 75 oryName for a su
c7e0: 69 74 61 62 6c 65 20 72 65 70 6f 73 69 74 6f 72 itable repositor
c7f0: 79 0a 2a 2a 20 77 69 74 68 20 61 20 6e 61 6d 65 y.** with a name
c800: 20 6f 66 20 24 70 72 65 66 69 78 2e 66 6f 73 73 of $prefix.foss
c810: 69 6c 2c 20 77 68 65 72 65 20 24 70 72 65 66 69 il, where $prefi
c820: 78 20 69 73 20 61 6e 79 20 70 72 65 66 69 78 20 x is any prefix
c830: 6f 66 20 50 41 54 48 5f 49 4e 46 4f 2e 0a 2a 2a of PATH_INFO..**
c840: 20 4f 72 2c 20 69 66 20 61 6e 20 6f 72 64 69 6e Or, if an ordin
c850: 61 72 79 20 66 69 6c 65 20 6e 61 6d 65 64 20 24 ary file named $
c860: 70 72 65 66 69 78 20 69 73 20 66 6f 75 6e 64 2c prefix is found,
c870: 20 61 6e 64 20 24 70 72 65 66 69 78 20 6d 61 74 and $prefix mat
c880: 63 68 65 73 0a 2a 2a 20 70 46 69 6c 65 47 6c 6f ches.** pFileGlo
c890: 62 20 61 6e 64 20 24 70 72 65 66 69 78 20 64 6f b and $prefix do
c8a0: 65 73 20 6e 6f 74 20 6d 61 74 63 68 20 22 2a 2e es not match "*.
c8b0: 66 6f 73 73 69 6c 2a 22 20 61 6e 64 20 74 68 65 fossil*" and the
c8c0: 20 6d 69 6d 65 74 79 70 65 20 6f 66 0a 2a 2a 20 mimetype of.**
c8d0: 24 70 72 65 66 69 78 20 63 61 6e 20 62 65 20 64 $prefix can be d
c8e0: 65 74 65 72 6d 69 6e 65 64 20 66 72 6f 6d 20 69 etermined from i
c8f0: 74 73 20 73 75 66 66 69 78 2c 20 74 68 65 6e 20 ts suffix, then
c900: 74 68 65 20 66 69 6c 65 20 24 70 72 65 66 69 78 the file $prefix
c910: 20 69 73 0a 2a 2a 20 72 65 74 75 72 6e 65 64 20 is.** returned
c920: 61 73 20 73 74 61 74 69 63 20 74 65 78 74 2e 0a as static text..
c930: 2a 2a 0a 2a 2a 20 49 66 20 6e 6f 20 73 75 69 74 **.** If no suit
c940: 61 62 6c 65 20 77 65 62 70 61 67 65 20 69 73 20 able webpage is
c950: 66 6f 75 6e 64 2c 20 74 72 79 20 74 6f 20 72 65 found, try to re
c960: 64 69 72 65 63 74 20 74 6f 20 7a 4e 6f 74 46 6f direct to zNotFo
c970: 75 6e 64 2e 0a 2a 2f 0a 73 74 61 74 69 63 20 76 und..*/.static v
c980: 6f 69 64 20 70 72 6f 63 65 73 73 5f 6f 6e 65 5f oid process_one_
c990: 77 65 62 5f 70 61 67 65 28 0a 20 20 63 6f 6e 73 web_page(. cons
c9a0: 74 20 63 68 61 72 20 2a 7a 4e 6f 74 46 6f 75 6e t char *zNotFoun
c9b0: 64 2c 20 20 20 20 20 20 2f 2a 20 52 65 64 69 72 d, /* Redir
c9c0: 65 63 74 20 68 65 72 65 20 6f 6e 20 61 20 34 30 ect here on a 40
c9d0: 34 20 69 66 20 6e 6f 74 20 4e 55 4c 4c 20 2a 2f 4 if not NULL */
c9e0: 0a 20 20 47 6c 6f 62 20 2a 70 46 69 6c 65 47 6c . Glob *pFileGl
c9f0: 6f 62 2c 20 20 20 20 20 20 20 20 20 20 20 20 2f ob, /
ca00: 2a 20 44 65 6c 69 76 65 72 20 73 74 61 74 69 63 * Deliver static
ca10: 20 66 69 6c 65 73 20 6d 61 74 63 68 69 6e 67 20 files matching
ca20: 2a 2f 0a 20 20 69 6e 74 20 61 6c 6c 6f 77 52 65 */. int allowRe
ca30: 70 6f 4c 69 73 74 20 20 20 20 20 20 20 20 20 20 poList
ca40: 20 2f 2a 20 53 65 6e 64 20 72 65 70 6f 20 6c 69 /* Send repo li
ca50: 73 74 20 66 6f 72 20 22 2f 22 20 55 52 4c 20 2a st for "/" URL *
ca60: 2f 0a 29 7b 0a 20 20 63 6f 6e 73 74 20 63 68 61 /.){. const cha
ca70: 72 20 2a 7a 50 61 74 68 49 6e 66 6f 3b 0a 20 20 r *zPathInfo;.
ca80: 63 68 61 72 20 2a 7a 50 61 74 68 20 3d 20 4e 55 char *zPath = NU
ca90: 4c 4c 3b 0a 20 20 69 6e 74 20 69 64 78 3b 0a 20 LL;. int idx;.
caa0: 20 69 6e 74 20 69 3b 0a 0a 20 20 2f 2a 20 48 61 int i;.. /* Ha
cab0: 6e 64 6c 65 20 75 6e 69 76 65 72 73 61 6c 20 71 ndle universal q
cac0: 75 65 72 79 20 70 61 72 61 6d 65 74 65 72 73 20 uery parameters
cad0: 2a 2f 0a 20 20 69 66 28 20 50 42 28 22 75 74 63 */. if( PB("utc
cae0: 22 29 20 29 7b 0a 20 20 20 20 67 2e 66 54 69 6d ") ){. g.fTim
caf0: 65 46 6f 72 6d 61 74 20 3d 20 31 3b 0a 20 20 7d eFormat = 1;. }
cb00: 65 6c 73 65 20 69 66 28 20 50 42 28 22 6c 6f 63 else if( PB("loc
cb10: 61 6c 74 69 6d 65 22 29 20 29 7b 0a 20 20 20 20 altime") ){.
cb20: 67 2e 66 54 69 6d 65 46 6f 72 6d 61 74 20 3d 20 g.fTimeFormat =
cb30: 32 3b 0a 20 20 7d 0a 0a 20 20 2f 2a 20 49 66 20 2;. }.. /* If
cb40: 74 68 65 20 72 65 70 6f 73 69 74 6f 72 79 20 68 the repository h
cb50: 61 73 20 6e 6f 74 20 62 65 65 6e 20 6f 70 65 6e as not been open
cb60: 65 64 20 61 6c 72 65 61 64 79 2c 20 74 68 65 6e ed already, then
cb70: 20 66 69 6e 64 20 74 68 65 0a 20 20 2a 2a 20 72 find the. ** r
cb80: 65 70 6f 73 69 74 6f 72 79 20 62 61 73 65 64 20 epository based
cb90: 6f 6e 20 74 68 65 20 66 69 72 73 74 20 65 6c 65 on the first ele
cba0: 6d 65 6e 74 20 6f 66 20 50 41 54 48 5f 49 4e 46 ment of PATH_INF
cbb0: 4f 20 61 6e 64 20 6f 70 65 6e 20 69 74 2e 0a 20 O and open it..
cbc0: 20 2a 2f 0a 20 20 7a 50 61 74 68 49 6e 66 6f 20 */. zPathInfo
cbd0: 3d 20 50 44 28 22 50 41 54 48 5f 49 4e 46 4f 22 = PD("PATH_INFO"
cbe0: 2c 22 22 29 3b 0a 20 20 69 66 28 20 21 67 2e 72 ,"");. if( !g.r
cbf0: 65 70 6f 73 69 74 6f 72 79 4f 70 65 6e 20 29 7b epositoryOpen ){
cc00: 0a 20 20 20 20 63 68 61 72 20 2a 7a 52 65 70 6f . char *zRepo
cc10: 2c 20 2a 7a 54 6f 46 72 65 65 3b 0a 20 20 20 20 , *zToFree;.
cc20: 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a 4f 6c 64 const char *zOld
cc30: 53 63 72 69 70 74 20 3d 20 50 44 28 22 53 43 52 Script = PD("SCR
cc40: 49 50 54 5f 4e 41 4d 45 22 2c 20 22 22 29 3b 0a IPT_NAME", "");.
cc50: 20 20 20 20 63 68 61 72 20 2a 7a 4e 65 77 53 63 char *zNewSc
cc60: 72 69 70 74 3b 0a 20 20 20 20 69 6e 74 20 6a 2c ript;. int j,
cc70: 20 6b 3b 0a 20 20 20 20 69 36 34 20 73 7a 46 69 k;. i64 szFi
cc80: 6c 65 3b 0a 0a 20 20 20 20 69 20 3d 20 7a 50 61 le;.. i = zPa
cc90: 74 68 49 6e 66 6f 5b 30 5d 21 3d 30 3b 0a 20 20 thInfo[0]!=0;.
cca0: 20 20 77 68 69 6c 65 28 20 31 20 29 7b 0a 20 20 while( 1 ){.
ccb0: 20 20 20 20 77 68 69 6c 65 28 20 7a 50 61 74 68 while( zPath
ccc0: 49 6e 66 6f 5b 69 5d 20 26 26 20 7a 50 61 74 68 Info[i] && zPath
ccd0: 49 6e 66 6f 5b 69 5d 21 3d 27 2f 27 20 29 7b 20 Info[i]!='/' ){
cce0: 69 2b 2b 3b 20 7d 0a 20 20 20 20 20 20 7a 52 65 i++; }. zRe
ccf0: 70 6f 20 3d 20 7a 54 6f 46 72 65 65 20 3d 20 6d po = zToFree = m
cd00: 70 72 69 6e 74 66 28 22 25 73 25 2e 2a 73 2e 66 printf("%s%.*s.f
cd10: 6f 73 73 69 6c 22 2c 67 2e 7a 52 65 70 6f 73 69 ossil",g.zReposi
cd20: 74 6f 72 79 4e 61 6d 65 2c 69 2c 7a 50 61 74 68 toryName,i,zPath
cd30: 49 6e 66 6f 29 3b 0a 0a 20 20 20 20 20 20 2f 2a Info);.. /*
cd40: 20 54 6f 20 61 76 6f 69 64 20 6d 69 73 63 68 69 To avoid mischi
cd50: 65 66 2c 20 6d 61 6b 65 20 73 75 72 65 20 74 68 ef, make sure th
cd60: 65 20 72 65 70 6f 73 69 74 6f 72 79 20 62 61 73 e repository bas
cd70: 65 6e 61 6d 65 20 63 6f 6e 74 61 69 6e 73 20 6e ename contains n
cd80: 6f 0a 20 20 20 20 20 20 2a 2a 20 63 68 61 72 61 o. ** chara
cd90: 63 74 65 72 73 20 6f 74 68 65 72 20 74 68 61 6e cters other than
cda0: 20 61 6c 70 68 61 6e 75 6d 65 72 69 63 73 2c 20 alphanumerics,
cdb0: 22 2f 22 2c 20 22 5f 22 2c 20 22 2d 22 2c 20 61 "/", "_", "-", a
cdc0: 6e 64 20 22 2e 22 2c 20 61 6e 64 0a 20 20 20 20 nd ".", and.
cdd0: 20 20 2a 2a 20 74 68 61 74 20 22 2d 22 20 6e 65 ** that "-" ne
cde0: 76 65 72 20 6f 63 63 75 72 73 20 69 6d 6d 65 64 ver occurs immed
cdf0: 69 61 74 65 6c 79 20 61 66 74 65 72 20 61 20 22 iately after a "
ce00: 2f 22 20 61 6e 64 20 74 68 61 74 20 22 2e 22 20 /" and that "."
ce10: 69 73 20 61 6c 77 61 79 73 0a 20 20 20 20 20 20 is always.
ce20: 2a 2a 20 73 75 72 72 6f 75 6e 64 65 64 20 62 79 ** surrounded by
ce30: 20 74 77 6f 20 61 6c 70 68 61 6e 75 6d 65 72 69 two alphanumeri
ce40: 63 73 2e 20 20 41 6e 79 20 63 68 61 72 61 63 74 cs. Any charact
ce50: 65 72 20 74 68 61 74 20 64 6f 65 73 20 6e 6f 74 er that does not
ce60: 0a 20 20 20 20 20 20 2a 2a 20 73 61 74 69 73 66 . ** satisf
ce70: 79 20 74 68 65 73 65 20 63 6f 6e 73 74 72 61 69 y these constrai
ce80: 6e 74 73 20 69 73 20 63 6f 6e 76 65 72 74 65 64 nts is converted
ce90: 20 69 6e 74 6f 20 22 5f 22 2e 0a 20 20 20 20 20 into "_"..
cea0: 20 2a 2f 0a 20 20 20 20 20 20 73 7a 46 69 6c 65 */. szFile
ceb0: 20 3d 20 30 3b 0a 20 20 20 20 20 20 66 6f 72 28 = 0;. for(
cec0: 6a 3d 73 74 72 6c 65 6e 28 67 2e 7a 52 65 70 6f j=strlen(g.zRepo
ced0: 73 69 74 6f 72 79 4e 61 6d 65 29 2b 31 2c 20 6b sitoryName)+1, k
cee0: 3d 30 3b 20 7a 52 65 70 6f 5b 6a 5d 20 26 26 20 =0; zRepo[j] &&
cef0: 6b 3c 69 2d 31 3b 20 6a 2b 2b 2c 20 6b 2b 2b 29 k<i-1; j++, k++)
cf00: 7b 0a 20 20 20 20 20 20 20 20 63 68 61 72 20 63 {. char c
cf10: 20 3d 20 7a 52 65 70 6f 5b 6a 5d 3b 0a 20 20 20 = zRepo[j];.
cf20: 20 20 20 20 20 69 66 28 20 66 6f 73 73 69 6c 5f if( fossil_
cf30: 69 73 61 6c 6e 75 6d 28 63 29 20 29 20 63 6f 6e isalnum(c) ) con
cf40: 74 69 6e 75 65 3b 0a 20 20 20 20 20 20 20 20 69 tinue;. i
cf50: 66 28 20 63 3d 3d 27 2f 27 20 29 20 63 6f 6e 74 f( c=='/' ) cont
cf60: 69 6e 75 65 3b 0a 20 20 20 20 20 20 20 20 69 66 inue;. if
cf70: 28 20 63 3d 3d 27 5f 27 20 29 20 63 6f 6e 74 69 ( c=='_' ) conti
cf80: 6e 75 65 3b 0a 20 20 20 20 20 20 20 20 69 66 28 nue;. if(
cf90: 20 63 3d 3d 27 2d 27 20 26 26 20 7a 52 65 70 6f c=='-' && zRepo
cfa0: 5b 6a 2d 31 5d 21 3d 27 2f 27 20 29 20 63 6f 6e [j-1]!='/' ) con
cfb0: 74 69 6e 75 65 3b 0a 20 20 20 20 20 20 20 20 69 tinue;. i
cfc0: 66 28 20 63 3d 3d 27 2e 27 20 26 26 20 66 6f 73 f( c=='.' && fos
cfd0: 73 69 6c 5f 69 73 61 6c 6e 75 6d 28 7a 52 65 70 sil_isalnum(zRep
cfe0: 6f 5b 6a 2d 31 5d 29 20 26 26 20 66 6f 73 73 69 o[j-1]) && fossi
cff0: 6c 5f 69 73 61 6c 6e 75 6d 28 7a 52 65 70 6f 5b l_isalnum(zRepo[
d000: 6a 2b 31 5d 29 29 7b 0a 20 20 20 20 20 20 20 20 j+1])){.
d010: 20 20 63 6f 6e 74 69 6e 75 65 3b 0a 20 20 20 20 continue;.
d020: 20 20 20 20 7d 0a 20 20 20 20 20 20 20 20 73 7a }. sz
d030: 46 69 6c 65 20 3d 20 31 3b 0a 20 20 20 20 20 20 File = 1;.
d040: 20 20 62 72 65 61 6b 3b 0a 20 20 20 20 20 20 7d break;. }
d050: 0a 20 20 20 20 20 20 69 66 28 20 73 7a 46 69 6c . if( szFil
d060: 65 3d 3d 30 20 26 26 20 73 71 6c 69 74 65 33 5f e==0 && sqlite3_
d070: 73 74 72 67 6c 6f 62 28 22 2a 2f 2e 66 6f 73 73 strglob("*/.foss
d080: 69 6c 22 2c 7a 52 65 70 6f 29 21 3d 30 20 29 7b il",zRepo)!=0 ){
d090: 0a 20 20 20 20 20 20 20 20 69 66 28 20 7a 52 65 . if( zRe
d0a0: 70 6f 5b 30 5d 3d 3d 27 2f 27 20 26 26 20 7a 52 po[0]=='/' && zR
d0b0: 65 70 6f 5b 31 5d 3d 3d 27 2f 27 20 29 7b 20 7a epo[1]=='/' ){ z
d0c0: 52 65 70 6f 2b 2b 3b 20 6a 2d 2d 3b 20 7d 0a 20 Repo++; j--; }.
d0d0: 20 20 20 20 20 20 20 73 7a 46 69 6c 65 20 3d 20 szFile =
d0e0: 66 69 6c 65 5f 73 69 7a 65 28 7a 52 65 70 6f 29 file_size(zRepo)
d0f0: 3b 0a 20 20 20 20 20 20 20 20 2f 2a 20 74 68 69 ;. /* thi
d100: 73 20 73 68 6f 75 6c 64 20 6f 6e 6c 79 20 62 65 s should only be
d110: 20 73 65 74 20 66 72 6f 6d 20 74 68 65 20 2d 2d set from the --
d120: 62 61 73 65 75 72 6c 20 6f 70 74 69 6f 6e 2c 20 baseurl option,
d130: 6e 6f 74 20 43 47 49 20 20 2a 2f 0a 20 20 20 20 not CGI */.
d140: 20 20 20 20 69 66 28 20 67 2e 7a 42 61 73 65 55 if( g.zBaseU
d150: 52 4c 20 26 26 20 67 2e 7a 42 61 73 65 55 52 4c RL && g.zBaseURL
d160: 5b 30 5d 21 3d 30 20 26 26 20 67 2e 7a 54 6f 70 [0]!=0 && g.zTop
d170: 20 26 26 20 67 2e 7a 54 6f 70 5b 30 5d 21 3d 30 && g.zTop[0]!=0
d180: 20 26 26 0a 20 20 20 20 20 20 20 20 20 20 20 20 &&.
d190: 66 69 6c 65 5f 69 73 64 69 72 28 67 2e 7a 52 65 file_isdir(g.zRe
d1a0: 70 6f 73 69 74 6f 72 79 4e 61 6d 65 29 3d 3d 31 positoryName)==1
d1b0: 20 29 7b 0a 20 20 20 20 20 20 20 20 20 20 67 2e ){. g.
d1c0: 7a 42 61 73 65 55 52 4c 20 3d 20 6d 70 72 69 6e zBaseURL = mprin
d1d0: 74 66 28 22 25 73 25 2e 2a 73 22 2c 20 67 2e 7a tf("%s%.*s", g.z
d1e0: 42 61 73 65 55 52 4c 2c 20 69 2c 20 7a 50 61 74 BaseURL, i, zPat
d1f0: 68 49 6e 66 6f 29 3b 0a 20 20 20 20 20 20 20 20 hInfo);.
d200: 20 20 67 2e 7a 54 6f 70 20 3d 20 6d 70 72 69 6e g.zTop = mprin
d210: 74 66 28 22 25 73 25 2e 2a 73 22 2c 20 67 2e 7a tf("%s%.*s", g.z
d220: 54 6f 70 2c 20 69 2c 20 7a 50 61 74 68 49 6e 66 Top, i, zPathInf
d230: 6f 29 3b 0a 20 20 20 20 20 20 20 20 7d 0a 20 20 o);. }.
d240: 20 20 20 20 7d 0a 20 20 20 20 20 20 69 66 28 20 }. if(
d250: 73 7a 46 69 6c 65 3c 30 20 26 26 20 69 3e 30 20 szFile<0 && i>0
d260: 29 7b 0a 20 20 20 20 20 20 20 20 63 6f 6e 73 74 ){. const
d270: 20 63 68 61 72 20 2a 7a 4d 69 6d 65 74 79 70 65 char *zMimetype
d280: 3b 0a 20 20 20 20 20 20 20 20 61 73 73 65 72 74 ;. assert
d290: 28 20 66 6f 73 73 69 6c 5f 73 74 72 63 6d 70 28 ( fossil_strcmp(
d2a0: 26 7a 52 65 70 6f 5b 6a 5d 2c 20 22 2e 66 6f 73 &zRepo[j], ".fos
d2b0: 73 69 6c 22 29 3d 3d 30 20 29 3b 0a 20 20 20 20 sil")==0 );.
d2c0: 20 20 20 20 7a 52 65 70 6f 5b 6a 5d 20 3d 20 30 zRepo[j] = 0
d2d0: 3b 0a 20 20 20 20 20 20 20 20 69 66 28 20 7a 50 ;. if( zP
d2e0: 61 74 68 49 6e 66 6f 5b 69 5d 3d 3d 27 2f 27 20 athInfo[i]=='/'
d2f0: 26 26 20 66 69 6c 65 5f 69 73 64 69 72 28 7a 52 && file_isdir(zR
d300: 65 70 6f 29 3d 3d 31 20 29 7b 0a 20 20 20 20 20 epo)==1 ){.
d310: 20 20 20 20 20 66 6f 73 73 69 6c 5f 66 72 65 65 fossil_free
d320: 28 7a 54 6f 46 72 65 65 29 3b 0a 20 20 20 20 20 (zToFree);.
d330: 20 20 20 20 20 69 2b 2b 3b 0a 20 20 20 20 20 20 i++;.
d340: 20 20 20 20 63 6f 6e 74 69 6e 75 65 3b 0a 20 20 continue;.
d350: 20 20 20 20 20 20 7d 0a 20 20 20 20 20 20 20 20 }.
d360: 69 66 28 20 70 46 69 6c 65 47 6c 6f 62 21 3d 30 if( pFileGlob!=0
d370: 0a 20 20 20 20 20 20 20 20 20 26 26 20 66 69 6c . && fil
d380: 65 5f 69 73 66 69 6c 65 28 7a 52 65 70 6f 29 0a e_isfile(zRepo).
d390: 20 20 20 20 20 20 20 20 20 26 26 20 67 6c 6f 62 && glob
d3a0: 5f 6d 61 74 63 68 28 70 46 69 6c 65 47 6c 6f 62 _match(pFileGlob
d3b0: 2c 20 7a 52 65 70 6f 29 0a 20 20 20 20 20 20 20 , zRepo).
d3c0: 20 20 26 26 20 73 71 6c 69 74 65 33 5f 73 74 72 && sqlite3_str
d3d0: 67 6c 6f 62 28 22 2a 2e 66 6f 73 73 69 6c 2a 22 glob("*.fossil*"
d3e0: 2c 7a 52 65 70 6f 29 21 3d 30 0a 20 20 20 20 20 ,zRepo)!=0.
d3f0: 20 20 20 20 26 26 20 28 7a 4d 69 6d 65 74 79 70 && (zMimetyp
d400: 65 20 3d 20 6d 69 6d 65 74 79 70 65 5f 66 72 6f e = mimetype_fro
d410: 6d 5f 6e 61 6d 65 28 7a 52 65 70 6f 29 29 21 3d m_name(zRepo))!=
d420: 30 0a 20 20 20 20 20 20 20 20 20 26 26 20 73 74 0. && st
d430: 72 63 6d 70 28 7a 4d 69 6d 65 74 79 70 65 2c 20 rcmp(zMimetype,
d440: 22 61 70 70 6c 69 63 61 74 69 6f 6e 2f 78 2d 66 "application/x-f
d450: 6f 73 73 69 6c 2d 61 72 74 69 66 61 63 74 22 29 ossil-artifact")
d460: 21 3d 30 0a 20 20 20 20 20 20 20 20 29 7b 0a 20 !=0. ){.
d470: 20 20 20 20 20 20 20 20 20 42 6c 6f 62 20 63 6f Blob co
d480: 6e 74 65 6e 74 3b 0a 20 20 20 20 20 20 20 20 20 ntent;.
d490: 20 62 6c 6f 62 5f 72 65 61 64 5f 66 72 6f 6d 5f blob_read_from_
d4a0: 66 69 6c 65 28 26 63 6f 6e 74 65 6e 74 2c 20 7a file(&content, z
d4b0: 52 65 70 6f 29 3b 0a 20 20 20 20 20 20 20 20 20 Repo);.
d4c0: 20 63 67 69 5f 73 65 74 5f 63 6f 6e 74 65 6e 74 cgi_set_content
d4d0: 5f 74 79 70 65 28 7a 4d 69 6d 65 74 79 70 65 29 _type(zMimetype)
d4e0: 3b 0a 20 20 20 20 20 20 20 20 20 20 63 67 69 5f ;. cgi_
d4f0: 73 65 74 5f 63 6f 6e 74 65 6e 74 28 26 63 6f 6e set_content(&con
d500: 74 65 6e 74 29 3b 0a 20 20 20 20 20 20 20 20 20 tent);.
d510: 20 63 67 69 5f 72 65 70 6c 79 28 29 3b 0a 20 20 cgi_reply();.
d520: 20 20 20 20 20 20 20 20 72 65 74 75 72 6e 3b 0a return;.
d530: 20 20 20 20 20 20 20 20 7d 0a 20 20 20 20 20 20 }.
d540: 20 20 7a 52 65 70 6f 5b 6a 5d 20 3d 20 27 2e 27 zRepo[j] = '.'
d550: 3b 0a 20 20 20 20 20 20 7d 0a 0a 20 20 20 20 20 ;. }..
d560: 20 69 66 28 20 73 7a 46 69 6c 65 3c 31 30 32 34 if( szFile<1024
d570: 20 29 7b 0a 20 20 20 20 20 20 20 20 73 65 74 5f ){. set_
d580: 62 61 73 65 5f 75 72 6c 28 30 29 3b 0a 20 20 20 base_url(0);.
d590: 20 20 20 20 20 69 66 28 20 73 74 72 63 6d 70 28 if( strcmp(
d5a0: 7a 50 61 74 68 49 6e 66 6f 2c 22 2f 22 29 3d 3d zPathInfo,"/")==
d5b0: 30 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 0.
d5c0: 20 20 20 20 26 26 20 61 6c 6c 6f 77 52 65 70 6f && allowRepo
d5d0: 4c 69 73 74 0a 20 20 20 20 20 20 20 20 20 20 20 List.
d5e0: 20 20 20 20 20 20 20 26 26 20 72 65 70 6f 5f 6c && repo_l
d5f0: 69 73 74 5f 70 61 67 65 28 29 20 29 7b 0a 20 20 ist_page() ){.
d600: 20 20 20 20 20 20 20 20 2f 2a 20 57 69 6c 6c 20 /* Will
d610: 72 65 74 75 72 6e 20 61 20 6c 69 73 74 20 6f 66 return a list of
d620: 20 72 65 70 6f 73 69 74 6f 72 69 65 73 20 2a 2f repositories */
d630: 0a 20 20 20 20 20 20 20 20 7d 65 6c 73 65 20 69 . }else i
d640: 66 28 20 7a 4e 6f 74 46 6f 75 6e 64 20 29 7b 0a f( zNotFound ){.
d650: 20 20 20 20 20 20 20 20 20 20 63 67 69 5f 72 65 cgi_re
d660: 64 69 72 65 63 74 28 7a 4e 6f 74 46 6f 75 6e 64 direct(zNotFound
d670: 29 3b 0a 20 20 20 20 20 20 20 20 7d 65 6c 73 65 );. }else
d680: 7b 0a 23 69 66 64 65 66 20 46 4f 53 53 49 4c 5f {.#ifdef FOSSIL_
d690: 45 4e 41 42 4c 45 5f 4a 53 4f 4e 0a 20 20 20 20 ENABLE_JSON.
d6a0: 20 20 20 20 20 20 69 66 28 67 2e 6a 73 6f 6e 2e if(g.json.
d6b0: 69 73 4a 73 6f 6e 4d 6f 64 65 29 7b 0a 20 20 20 isJsonMode){.
d6c0: 20 20 20 20 20 20 20 20 20 6a 73 6f 6e 5f 65 72 json_er
d6d0: 72 28 46 53 4c 5f 4a 53 4f 4e 5f 45 5f 52 45 53 r(FSL_JSON_E_RES
d6e0: 4f 55 52 43 45 5f 4e 4f 54 5f 46 4f 55 4e 44 2c OURCE_NOT_FOUND,
d6f0: 4e 55 4c 4c 2c 31 29 3b 0a 20 20 20 20 20 20 20 NULL,1);.
d700: 20 20 20 20 20 72 65 74 75 72 6e 3b 0a 20 20 20 return;.
d710: 20 20 20 20 20 20 20 7d 0a 23 65 6e 64 69 66 0a }.#endif.
d720: 20 20 20 20 20 20 20 20 20 20 40 20 3c 68 31 3e @ <h1>
d730: 4e 6f 74 20 46 6f 75 6e 64 3c 2f 68 31 3e 0a 20 Not Found</h1>.
d740: 20 20 20 20 20 20 20 20 20 63 67 69 5f 73 65 74 cgi_set
d750: 5f 73 74 61 74 75 73 28 34 30 34 2c 20 22 6e 6f _status(404, "no
d760: 74 20 66 6f 75 6e 64 22 29 3b 0a 20 20 20 20 20 t found");.
d770: 20 20 20 20 20 63 67 69 5f 72 65 70 6c 79 28 29 cgi_reply()
d780: 3b 0a 20 20 20 20 20 20 20 20 7d 0a 20 20 20 20 ;. }.
d790: 20 20 20 20 72 65 74 75 72 6e 3b 0a 20 20 20 20 return;.
d7a0: 20 20 7d 0a 20 20 20 20 20 20 62 72 65 61 6b 3b }. break;
d7b0: 0a 20 20 20 20 7d 0a 20 20 20 20 7a 4e 65 77 53 . }. zNewS
d7c0: 63 72 69 70 74 20 3d 20 6d 70 72 69 6e 74 66 28 cript = mprintf(
d7d0: 22 25 73 25 2e 2a 73 22 2c 20 7a 4f 6c 64 53 63 "%s%.*s", zOldSc
d7e0: 72 69 70 74 2c 20 69 2c 20 7a 50 61 74 68 49 6e ript, i, zPathIn
d7f0: 66 6f 29 3b 0a 20 20 20 20 63 67 69 5f 72 65 70 fo);. cgi_rep
d800: 6c 61 63 65 5f 70 61 72 61 6d 65 74 65 72 28 22 lace_parameter("
d810: 50 41 54 48 5f 49 4e 46 4f 22 2c 20 26 7a 50 61 PATH_INFO", &zPa
d820: 74 68 49 6e 66 6f 5b 69 2b 31 5d 29 3b 0a 20 20 thInfo[i+1]);.
d830: 20 20 7a 50 61 74 68 49 6e 66 6f 20 2b 3d 20 69 zPathInfo += i
d840: 3b 0a 20 20 20 20 63 67 69 5f 72 65 70 6c 61 63 ;. cgi_replac
d850: 65 5f 70 61 72 61 6d 65 74 65 72 28 22 53 43 52 e_parameter("SCR
d860: 49 50 54 5f 4e 41 4d 45 22 2c 20 7a 4e 65 77 53 IPT_NAME", zNewS
d870: 63 72 69 70 74 29 3b 0a 20 20 20 20 64 62 5f 6f cript);. db_o
d880: 70 65 6e 5f 72 65 70 6f 73 69 74 6f 72 79 28 7a pen_repository(z
d890: 52 65 70 6f 29 3b 0a 20 20 20 20 69 66 28 20 67 Repo);. if( g
d8a0: 2e 66 48 74 74 70 54 72 61 63 65 20 29 7b 0a 20 .fHttpTrace ){.
d8b0: 20 20 20 20 20 66 70 72 69 6e 74 66 28 73 74 64 fprintf(std
d8c0: 65 72 72 2c 0a 20 20 20 20 20 20 20 20 20 20 22 err,. "
d8d0: 23 20 72 65 70 6f 73 69 74 6f 72 79 3a 20 5b 25 # repository: [%
d8e0: 73 5d 5c 6e 22 0a 20 20 20 20 20 20 20 20 20 20 s]\n".
d8f0: 22 23 20 6e 65 77 20 50 41 54 48 5f 49 4e 46 4f "# new PATH_INFO
d900: 20 3d 20 5b 25 73 5d 5c 6e 22 0a 20 20 20 20 20 = [%s]\n".
d910: 20 20 20 20 20 22 23 20 6e 65 77 20 53 43 52 49 "# new SCRI
d920: 50 54 5f 4e 41 4d 45 20 3d 20 5b 25 73 5d 5c 6e PT_NAME = [%s]\n
d930: 22 2c 0a 20 20 20 20 20 20 20 20 20 20 7a 52 65 ",. zRe
d940: 70 6f 2c 20 7a 50 61 74 68 49 6e 66 6f 2c 20 7a po, zPathInfo, z
d950: 4e 65 77 53 63 72 69 70 74 29 3b 0a 20 20 20 20 NewScript);.
d960: 7d 0a 20 20 7d 0a 0a 20 20 2f 2a 20 46 69 6e 64 }. }.. /* Find
d970: 20 74 68 65 20 70 61 67 65 20 74 68 61 74 20 74 the page that t
d980: 68 65 20 75 73 65 72 20 68 61 73 20 72 65 71 75 he user has requ
d990: 65 73 74 65 64 2c 20 63 6f 6e 73 74 72 75 63 74 ested, construct
d9a0: 20 61 6e 64 20 64 65 6c 69 76 65 72 20 74 68 61 and deliver tha
d9b0: 74 0a 20 20 2a 2a 20 70 61 67 65 2e 0a 20 20 2a t. ** page.. *
d9c0: 2f 0a 20 20 69 66 28 20 67 2e 7a 43 6f 6e 74 65 /. if( g.zConte
d9d0: 6e 74 54 79 70 65 20 26 26 0a 20 20 20 20 20 20 ntType &&.
d9e0: 73 74 72 6e 63 6d 70 28 67 2e 7a 43 6f 6e 74 65 strncmp(g.zConte
d9f0: 6e 74 54 79 70 65 2c 20 22 61 70 70 6c 69 63 61 ntType, "applica
da00: 74 69 6f 6e 2f 78 2d 66 6f 73 73 69 6c 22 2c 20 tion/x-fossil",
da10: 32 30 29 3d 3d 30 20 29 7b 0a 20 20 20 20 7a 50 20)==0 ){. zP
da20: 61 74 68 49 6e 66 6f 20 3d 20 22 2f 78 66 65 72 athInfo = "/xfer
da30: 22 3b 0a 20 20 7d 0a 20 20 73 65 74 5f 62 61 73 ";. }. set_bas
da40: 65 5f 75 72 6c 28 30 29 3b 0a 20 20 69 66 28 20 e_url(0);. if(
da50: 7a 50 61 74 68 49 6e 66 6f 3d 3d 30 20 7c 7c 20 zPathInfo==0 ||
da60: 7a 50 61 74 68 49 6e 66 6f 5b 30 5d 3d 3d 30 0a zPathInfo[0]==0.
da70: 20 20 20 20 20 20 7c 7c 20 28 7a 50 61 74 68 49 || (zPathI
da80: 6e 66 6f 5b 30 5d 3d 3d 27 2f 27 20 26 26 20 7a nfo[0]=='/' && z
da90: 50 61 74 68 49 6e 66 6f 5b 31 5d 3d 3d 30 29 20 PathInfo[1]==0)
daa0: 29 7b 0a 23 69 66 64 65 66 20 46 4f 53 53 49 4c ){.#ifdef FOSSIL
dab0: 5f 45 4e 41 42 4c 45 5f 4a 53 4f 4e 0a 20 20 20 _ENABLE_JSON.
dac0: 20 69 66 28 67 2e 6a 73 6f 6e 2e 69 73 4a 73 6f if(g.json.isJso
dad0: 6e 4d 6f 64 65 29 7b 0a 20 20 20 20 20 20 6a 73 nMode){. js
dae0: 6f 6e 5f 65 72 72 28 46 53 4c 5f 4a 53 4f 4e 5f on_err(FSL_JSON_
daf0: 45 5f 52 45 53 4f 55 52 43 45 5f 4e 4f 54 5f 46 E_RESOURCE_NOT_F
db00: 4f 55 4e 44 2c 4e 55 4c 4c 2c 31 29 3b 0a 20 20 OUND,NULL,1);.
db10: 20 20 20 20 66 6f 73 73 69 6c 5f 65 78 69 74 28 fossil_exit(
db20: 30 29 3b 0a 20 20 20 20 7d 0a 23 65 6e 64 69 66 0);. }.#endif
db30: 0a 20 20 20 20 66 6f 73 73 69 6c 5f 72 65 64 69 . fossil_redi
db40: 72 65 63 74 5f 68 6f 6d 65 28 29 20 2f 2a 64 6f rect_home() /*do
db50: 65 73 20 6e 6f 74 20 72 65 74 75 72 6e 2a 2f 3b es not return*/;
db60: 0a 20 20 7d 65 6c 73 65 7b 0a 20 20 20 20 7a 50 . }else{. zP
db70: 61 74 68 20 3d 20 6d 70 72 69 6e 74 66 28 22 25 ath = mprintf("%
db80: 73 22 2c 20 7a 50 61 74 68 49 6e 66 6f 29 3b 0a s", zPathInfo);.
db90: 20 20 7d 0a 0a 20 20 2f 2a 20 4d 61 6b 65 20 67 }.. /* Make g
dba0: 2e 7a 50 61 74 68 20 70 6f 69 6e 74 20 74 6f 20 .zPath point to
dbb0: 74 68 65 20 66 69 72 73 74 20 65 6c 65 6d 65 6e the first elemen
dbc0: 74 20 6f 66 20 74 68 65 20 70 61 74 68 2e 20 20 t of the path.
dbd0: 4d 61 6b 65 0a 20 20 2a 2a 20 67 2e 7a 45 78 74 Make. ** g.zExt
dbe0: 72 61 20 70 6f 69 6e 74 20 74 6f 20 65 76 65 72 ra point to ever
dbf0: 79 74 68 69 6e 67 20 70 61 73 74 20 74 68 61 74 ything past that
dc00: 20 70 6f 69 6e 74 2e 0a 20 20 2a 2f 0a 20 20 77 point.. */. w
dc10: 68 69 6c 65 28 31 29 7b 0a 20 20 20 20 63 68 61 hile(1){. cha
dc20: 72 20 2a 7a 41 6c 74 52 65 70 6f 20 3d 20 30 3b r *zAltRepo = 0;
dc30: 0a 20 20 20 20 67 2e 7a 50 61 74 68 20 3d 20 26 . g.zPath = &
dc40: 7a 50 61 74 68 5b 31 5d 3b 0a 20 20 20 20 66 6f zPath[1];. fo
dc50: 72 28 69 3d 31 3b 20 7a 50 61 74 68 5b 69 5d 20 r(i=1; zPath[i]
dc60: 26 26 20 7a 50 61 74 68 5b 69 5d 21 3d 27 2f 27 && zPath[i]!='/'
dc70: 3b 20 69 2b 2b 29 7b 7d 0a 20 20 20 20 69 66 28 ; i++){}. if(
dc80: 20 7a 50 61 74 68 5b 69 5d 3d 3d 27 2f 27 20 29 zPath[i]=='/' )
dc90: 7b 0a 20 20 20 20 20 20 7a 50 61 74 68 5b 69 5d {. zPath[i]
dca0: 20 3d 20 30 3b 0a 20 20 20 20 20 20 67 2e 7a 45 = 0;. g.zE
dcb0: 78 74 72 61 20 3d 20 26 7a 50 61 74 68 5b 69 2b xtra = &zPath[i+
dcc0: 31 5d 3b 0a 0a 20 20 20 20 20 20 2f 2a 20 4c 6f 1];.. /* Lo
dcd0: 6f 6b 20 66 6f 72 20 73 75 62 2d 72 65 70 6f 73 ok for sub-repos
dce0: 69 74 6f 72 69 65 73 2e 20 20 41 20 73 75 62 2d itories. A sub-
dcf0: 72 65 70 6f 73 69 74 6f 72 79 20 69 73 20 61 6e repository is an
dd00: 6f 74 68 65 72 20 72 65 70 6f 73 69 74 6f 72 79 other repository
dd10: 0a 20 20 20 20 20 20 2a 2a 20 74 68 61 74 20 61 . ** that a
dd20: 63 63 65 70 74 73 20 74 68 65 20 6c 6f 67 69 6e ccepts the login
dd30: 20 63 72 65 64 65 6e 74 69 61 6c 73 20 6f 66 20 credentials of
dd40: 74 68 65 20 63 75 72 72 65 6e 74 20 72 65 70 6f the current repo
dd50: 73 69 74 6f 72 79 2e 20 20 41 0a 20 20 20 20 20 sitory. A.
dd60: 20 2a 2a 20 73 75 62 72 65 70 6f 73 69 74 6f 72 ** subrepositor
dd70: 79 20 69 73 20 69 64 65 6e 74 69 66 69 65 64 20 y is identified
dd80: 62 79 20 61 20 43 4f 4e 46 49 47 20 74 61 62 6c by a CONFIG tabl
dd90: 65 20 65 6e 74 72 79 20 22 73 75 62 72 65 70 6f e entry "subrepo
dda0: 3a 4e 41 4d 45 22 0a 20 20 20 20 20 20 2a 2a 20 :NAME". **
ddb0: 77 68 65 72 65 20 4e 41 4d 45 20 69 73 20 74 68 where NAME is th
ddc0: 65 20 66 69 72 73 74 20 63 6f 6d 70 6f 6e 65 6e e first componen
ddd0: 74 20 6f 66 20 74 68 65 20 70 61 74 68 2e 20 20 t of the path.
dde0: 54 68 65 20 76 61 6c 75 65 20 6f 66 20 74 68 65 The value of the
ddf0: 0a 20 20 20 20 20 20 2a 2a 20 74 68 65 20 43 4f . ** the CO
de00: 4e 46 49 47 20 65 6e 74 72 69 65 73 20 69 73 20 NFIG entries is
de10: 74 68 65 20 73 74 72 69 6e 67 20 22 55 53 45 52 the string "USER
de20: 3a 46 49 4c 45 4e 41 4d 45 22 20 77 68 65 72 65 :FILENAME" where
de30: 20 55 53 45 52 20 69 73 20 74 68 65 0a 20 20 20 USER is the.
de40: 20 20 20 2a 2a 20 55 53 45 52 20 6e 61 6d 65 20 ** USER name
de50: 74 6f 20 6c 6f 67 20 69 6e 20 61 73 20 69 6e 20 to log in as in
de60: 74 68 65 20 73 75 62 72 65 70 6f 73 69 74 6f 72 the subrepositor
de70: 79 20 61 6e 64 20 46 49 4c 45 4e 41 4d 45 20 69 y and FILENAME i
de80: 73 20 74 68 65 0a 20 20 20 20 20 20 2a 2a 20 72 s the. ** r
de90: 65 70 6f 73 69 74 6f 72 79 20 66 69 6c 65 6e 61 epository filena
dea0: 6d 65 2e 0a 20 20 20 20 20 20 2a 2f 0a 20 20 20 me.. */.
deb0: 20 20 20 7a 41 6c 74 52 65 70 6f 20 3d 20 64 62 zAltRepo = db
dec0: 5f 74 65 78 74 28 30 2c 20 22 53 45 4c 45 43 54 _text(0, "SELECT
ded0: 20 76 61 6c 75 65 20 46 52 4f 4d 20 63 6f 6e 66 value FROM conf
dee0: 69 67 20 57 48 45 52 45 20 6e 61 6d 65 3d 27 73 ig WHERE name='s
def0: 75 62 72 65 70 6f 3a 25 71 27 22 2c 0a 20 20 20 ubrepo:%q'",.
df00: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
df10: 20 20 20 20 20 20 67 2e 7a 50 61 74 68 29 3b 0a g.zPath);.
df20: 20 20 20 20 20 20 69 66 28 20 7a 41 6c 74 52 65 if( zAltRe
df30: 70 6f 20 29 7b 0a 20 20 20 20 20 20 20 20 69 6e po ){. in
df40: 74 20 6e 48 6f 73 74 3b 0a 20 20 20 20 20 20 20 t nHost;.
df50: 20 69 6e 74 20 6a 6a 3b 0a 20 20 20 20 20 20 20 int jj;.
df60: 20 63 68 61 72 20 2a 7a 55 73 65 72 20 3d 20 7a char *zUser = z
df70: 41 6c 74 52 65 70 6f 3b 0a 20 20 20 20 20 20 20 AltRepo;.
df80: 20 6c 6f 67 69 6e 5f 63 68 65 63 6b 5f 63 72 65 login_check_cre
df90: 64 65 6e 74 69 61 6c 73 28 29 3b 0a 20 20 20 20 dentials();.
dfa0: 20 20 20 20 66 6f 72 28 6a 6a 3d 30 3b 20 7a 41 for(jj=0; zA
dfb0: 6c 74 52 65 70 6f 5b 6a 6a 5d 20 26 26 20 7a 41 ltRepo[jj] && zA
dfc0: 6c 74 52 65 70 6f 5b 6a 6a 5d 21 3d 27 3a 27 3b ltRepo[jj]!=':';
dfd0: 20 6a 6a 2b 2b 29 7b 7d 0a 20 20 20 20 20 20 20 jj++){}.
dfe0: 20 69 66 28 20 7a 41 6c 74 52 65 70 6f 5b 6a 6a if( zAltRepo[jj
dff0: 5d 3d 3d 27 3a 27 20 29 7b 0a 20 20 20 20 20 20 ]==':' ){.
e000: 20 20 20 20 7a 41 6c 74 52 65 70 6f 5b 6a 6a 5d zAltRepo[jj]
e010: 20 3d 20 30 3b 0a 20 20 20 20 20 20 20 20 20 20 = 0;.
e020: 7a 41 6c 74 52 65 70 6f 20 2b 3d 20 6a 6a 2b 31 zAltRepo += jj+1
e030: 3b 0a 20 20 20 20 20 20 20 20 7d 65 6c 73 65 7b ;. }else{
e040: 0a 20 20 20 20 20 20 20 20 20 20 7a 55 73 65 72 . zUser
e050: 20 3d 20 22 6e 6f 62 6f 64 79 22 3b 0a 20 20 20 = "nobody";.
e060: 20 20 20 20 20 7d 0a 20 20 20 20 20 20 20 20 69 }. i
e070: 66 28 20 67 2e 7a 4c 6f 67 69 6e 3d 3d 30 20 7c f( g.zLogin==0 |
e080: 7c 20 67 2e 7a 4c 6f 67 69 6e 5b 30 5d 3d 3d 30 | g.zLogin[0]==0
e090: 20 29 20 7a 55 73 65 72 20 3d 20 22 6e 6f 62 6f ) zUser = "nobo
e0a0: 64 79 22 3b 0a 20 20 20 20 20 20 20 20 69 66 28 dy";. if(
e0b0: 20 7a 41 6c 74 52 65 70 6f 5b 30 5d 21 3d 27 2f zAltRepo[0]!='/
e0c0: 27 20 29 7b 0a 20 20 20 20 20 20 20 20 20 20 7a ' ){. z
e0d0: 41 6c 74 52 65 70 6f 20 3d 20 6d 70 72 69 6e 74 AltRepo = mprint
e0e0: 66 28 22 25 73 2f 2e 2e 2f 25 73 22 2c 20 67 2e f("%s/../%s", g.
e0f0: 7a 52 65 70 6f 73 69 74 6f 72 79 4e 61 6d 65 2c zRepositoryName,
e100: 20 7a 41 6c 74 52 65 70 6f 29 3b 0a 20 20 20 20 zAltRepo);.
e110: 20 20 20 20 20 20 66 69 6c 65 5f 73 69 6d 70 6c file_simpl
e120: 69 66 79 5f 6e 61 6d 65 28 7a 41 6c 74 52 65 70 ify_name(zAltRep
e130: 6f 2c 20 2d 31 2c 20 30 29 3b 0a 20 20 20 20 20 o, -1, 0);.
e140: 20 20 20 7d 0a 20 20 20 20 20 20 20 20 64 62 5f }. db_
e150: 63 6c 6f 73 65 28 31 29 3b 0a 20 20 20 20 20 20 close(1);.
e160: 20 20 64 62 5f 6f 70 65 6e 5f 72 65 70 6f 73 69 db_open_reposi
e170: 74 6f 72 79 28 7a 41 6c 74 52 65 70 6f 29 3b 0a tory(zAltRepo);.
e180: 20 20 20 20 20 20 20 20 6c 6f 67 69 6e 5f 61 73 login_as
e190: 5f 75 73 65 72 28 7a 55 73 65 72 29 3b 0a 20 20 _user(zUser);.
e1a0: 20 20 20 20 20 20 67 2e 70 65 72 6d 2e 50 61 73 g.perm.Pas
e1b0: 73 77 6f 72 64 20 3d 20 30 3b 0a 20 20 20 20 20 sword = 0;.
e1c0: 20 20 20 7a 50 61 74 68 20 2b 3d 20 69 3b 0a 20 zPath += i;.
e1d0: 20 20 20 20 20 20 20 6e 48 6f 73 74 20 3d 20 67 nHost = g
e1e0: 2e 7a 54 6f 70 20 2d 20 67 2e 7a 42 61 73 65 55 .zTop - g.zBaseU
e1f0: 52 4c 3b 0a 20 20 20 20 20 20 20 20 67 2e 7a 42 RL;. g.zB
e200: 61 73 65 55 52 4c 20 3d 20 6d 70 72 69 6e 74 66 aseURL = mprintf
e210: 28 22 25 7a 2f 25 73 22 2c 20 67 2e 7a 42 61 73 ("%z/%s", g.zBas
e220: 65 55 52 4c 2c 20 67 2e 7a 50 61 74 68 29 3b 0a eURL, g.zPath);.
e230: 20 20 20 20 20 20 20 20 67 2e 7a 54 6f 70 20 3d g.zTop =
e240: 20 67 2e 7a 42 61 73 65 55 52 4c 20 2b 20 6e 48 g.zBaseURL + nH
e250: 6f 73 74 3b 0a 20 20 20 20 20 20 20 20 63 6f 6e ost;. con
e260: 74 69 6e 75 65 3b 0a 20 20 20 20 20 20 7d 0a 20 tinue;. }.
e270: 20 20 20 7d 65 6c 73 65 7b 0a 20 20 20 20 20 20 }else{.
e280: 67 2e 7a 45 78 74 72 61 20 3d 20 30 3b 0a 20 20 g.zExtra = 0;.
e290: 20 20 7d 0a 20 20 20 20 62 72 65 61 6b 3b 0a 20 }. break;.
e2a0: 20 7d 0a 23 69 66 64 65 66 20 46 4f 53 53 49 4c }.#ifdef FOSSIL
e2b0: 5f 45 4e 41 42 4c 45 5f 4a 53 4f 4e 0a 20 20 2f _ENABLE_JSON. /
e2c0: 2a 0a 20 20 2a 2a 20 57 6f 72 6b 61 72 6f 75 6e *. ** Workaroun
e2d0: 64 20 74 6f 20 61 6c 6c 6f 77 20 75 73 20 74 6f d to allow us to
e2e0: 20 63 75 73 74 6f 6d 69 7a 65 20 73 6f 6d 65 20 customize some
e2f0: 66 6f 6c 6c 6f 77 69 6e 67 20 62 65 68 61 76 69 following behavi
e300: 6f 75 72 20 66 6f 72 0a 20 20 2a 2a 20 4a 53 4f our for. ** JSO
e310: 4e 20 6d 6f 64 65 2e 20 20 54 68 65 20 70 72 6f N mode. The pro
e320: 62 6c 65 6d 20 69 73 2c 20 77 65 20 64 6f 6e 27 blem is, we don'
e330: 74 20 61 6c 77 61 79 73 20 6b 6e 6f 77 20 69 66 t always know if
e340: 20 77 65 27 72 65 20 69 6e 20 4a 53 4f 4e 0a 20 we're in JSON.
e350: 20 2a 2a 20 6d 6f 64 65 20 61 74 20 74 68 69 73 ** mode at this
e360: 20 70 6f 69 6e 74 20 28 6e 61 6d 65 6c 79 2c 20 point (namely,
e370: 66 6f 72 20 47 45 54 20 6d 6f 64 65 20 77 65 20 for GET mode we
e380: 64 6f 6e 27 74 20 6b 6e 6f 77 20 62 75 74 20 50 don't know but P
e390: 4f 53 54 0a 20 20 2a 2a 20 77 65 20 64 6f 29 2c OST. ** we do),
e3a0: 20 73 6f 20 77 65 20 73 6e 6f 6f 70 20 67 2e 7a so we snoop g.z
e3b0: 50 61 74 68 20 61 6e 64 20 63 68 65 61 74 20 61 Path and cheat a
e3c0: 20 62 69 74 2e 0a 20 20 2a 2f 0a 20 20 69 66 28 bit.. */. if(
e3d0: 20 21 67 2e 6a 73 6f 6e 2e 69 73 4a 73 6f 6e 4d !g.json.isJsonM
e3e0: 6f 64 65 20 26 26 20 67 2e 7a 50 61 74 68 20 26 ode && g.zPath &
e3f0: 26 20 28 30 3d 3d 73 74 72 6e 63 6d 70 28 22 6a & (0==strncmp("j
e400: 73 6f 6e 22 2c 67 2e 7a 50 61 74 68 2c 34 29 29 son",g.zPath,4))
e410: 20 29 7b 0a 20 20 20 20 67 2e 6a 73 6f 6e 2e 69 ){. g.json.i
e420: 73 4a 73 6f 6e 4d 6f 64 65 20 3d 20 31 3b 0a 20 sJsonMode = 1;.
e430: 20 7d 0a 23 65 6e 64 69 66 0a 20 20 69 66 28 20 }.#endif. if(
e440: 67 2e 7a 45 78 74 72 61 20 29 7b 0a 20 20 20 20 g.zExtra ){.
e450: 2f 2a 20 43 47 49 20 70 61 72 61 6d 65 74 65 72 /* CGI parameter
e460: 73 20 67 65 74 20 74 68 69 73 20 74 72 65 61 74 s get this treat
e470: 6d 65 6e 74 20 65 6c 73 65 77 68 65 72 65 2c 20 ment elsewhere,
e480: 62 75 74 20 70 6c 61 63 65 73 20 6c 69 6b 65 20 but places like
e490: 67 65 74 66 69 6c 65 0a 20 20 20 20 2a 2a 20 77 getfile. ** w
e4a0: 69 6c 6c 20 75 73 65 20 67 2e 7a 45 78 74 72 61 ill use g.zExtra
e4b0: 20 64 69 72 65 63 74 6c 79 2e 0a 20 20 20 20 2a directly.. *
e4c0: 2a 20 52 65 6d 69 6e 64 65 72 3a 20 74 68 65 20 * Reminder: the
e4d0: 6c 6f 67 69 6e 20 6d 65 63 68 61 6e 69 73 6d 20 login mechanism
e4e0: 75 73 65 73 20 27 6e 61 6d 65 27 20 64 69 66 66 uses 'name' diff
e4f0: 65 72 65 6e 74 6c 79 2c 20 61 6e 64 20 6d 61 79 erently, and may
e500: 0a 20 20 20 20 2a 2a 20 65 76 65 6e 74 75 61 6c . ** eventual
e510: 6c 79 20 68 61 76 65 20 61 20 70 72 6f 62 6c 65 ly have a proble
e520: 6d 2f 63 6f 6c 6c 69 73 69 6f 6e 20 77 69 74 68 m/collision with
e530: 20 74 68 69 73 2e 0a 20 20 20 20 2a 2a 0a 20 20 this.. **.
e540: 20 20 2a 2a 20 44 69 73 61 62 6c 65 64 20 62 79 ** Disabled by
e550: 20 73 74 65 70 68 61 6e 20 77 68 65 6e 20 72 75 stephan when ru
e560: 6e 6e 69 6e 67 20 69 6e 20 4a 53 4f 4e 20 6d 6f nning in JSON mo
e570: 64 65 20 62 65 63 61 75 73 65 20 74 68 69 73 0a de because this.
e580: 20 20 20 20 2a 2a 20 70 61 72 74 69 63 75 6c 61 ** particula
e590: 72 20 70 61 72 61 6d 65 74 65 72 20 6e 61 6d 65 r parameter name
e5a0: 20 69 73 20 76 65 72 79 20 63 6f 6d 6d 6f 6e 20 is very common
e5b0: 61 6e 64 20 69 20 68 61 76 65 20 68 61 64 20 6e and i have had n
e5c0: 6f 20 65 6e 64 0a 20 20 20 20 2a 2a 20 6f 66 20 o end. ** of
e5d0: 67 72 69 65 66 20 77 69 74 68 20 74 68 69 73 20 grief with this
e5e0: 68 61 6e 64 6c 69 6e 67 2e 20 54 68 65 20 4a 53 handling. The JS
e5f0: 4f 4e 20 41 50 49 20 6e 65 76 65 72 20 72 65 6c ON API never rel
e600: 69 65 73 20 6f 6e 20 74 68 65 0a 20 20 20 20 2a ies on the. *
e610: 2a 20 68 61 6e 64 6c 69 6e 67 20 62 65 6c 6f 77 * handling below
e620: 2c 20 61 6e 64 20 62 79 20 64 69 73 61 62 6c 69 , and by disabli
e630: 6e 67 20 69 74 20 69 6e 20 4a 53 4f 4e 20 6d 6f ng it in JSON mo
e640: 64 65 20 49 20 63 61 6e 20 72 65 6d 6f 76 65 0a de I can remove.
e650: 20 20 20 20 2a 2a 20 6c 6f 74 73 20 6f 66 20 73 ** lots of s
e660: 70 65 63 69 61 6c 2d 63 61 73 65 20 68 61 6e 64 pecial-case hand
e670: 6c 69 6e 67 20 69 6e 20 73 65 76 65 72 61 6c 20 ling in several
e680: 4a 53 4f 4e 20 68 61 6e 64 6c 65 72 73 2e 0a 20 JSON handlers..
e690: 20 20 20 2a 2f 0a 23 69 66 64 65 66 20 46 4f 53 */.#ifdef FOS
e6a0: 53 49 4c 5f 45 4e 41 42 4c 45 5f 4a 53 4f 4e 0a SIL_ENABLE_JSON.
e6b0: 20 20 20 20 69 66 28 21 67 2e 6a 73 6f 6e 2e 69 if(!g.json.i
e6c0: 73 4a 73 6f 6e 4d 6f 64 65 29 7b 0a 23 65 6e 64 sJsonMode){.#end
e6d0: 69 66 0a 20 20 20 20 20 20 64 65 68 74 74 70 69 if. dehttpi
e6e0: 7a 65 28 67 2e 7a 45 78 74 72 61 29 3b 0a 20 20 ze(g.zExtra);.
e6f0: 20 20 20 20 63 67 69 5f 73 65 74 5f 70 61 72 61 cgi_set_para
e700: 6d 65 74 65 72 5f 6e 6f 63 6f 70 79 28 22 6e 61 meter_nocopy("na
e710: 6d 65 22 2c 20 67 2e 7a 45 78 74 72 61 2c 20 31 me", g.zExtra, 1
e720: 29 3b 0a 23 69 66 64 65 66 20 46 4f 53 53 49 4c );.#ifdef FOSSIL
e730: 5f 45 4e 41 42 4c 45 5f 4a 53 4f 4e 0a 20 20 20 _ENABLE_JSON.
e740: 20 7d 0a 23 65 6e 64 69 66 0a 20 20 7d 0a 0a 20 }.#endif. }..
e750: 20 2f 2a 20 4c 6f 63 61 74 65 20 74 68 65 20 6d /* Locate the m
e760: 65 74 68 6f 64 20 73 70 65 63 69 66 69 65 64 20 ethod specified
e770: 62 79 20 74 68 65 20 70 61 74 68 20 61 6e 64 20 by the path and
e780: 65 78 65 63 75 74 65 20 74 68 65 20 66 75 6e 63 execute the func
e790: 74 69 6f 6e 0a 20 20 2a 2a 20 74 68 61 74 20 69 tion. ** that i
e7a0: 6d 70 6c 65 6d 65 6e 74 73 20 74 68 61 74 20 6d mplements that m
e7b0: 65 74 68 6f 64 2e 0a 20 20 2a 2f 0a 20 20 69 66 ethod.. */. if
e7c0: 28 20 6e 61 6d 65 5f 73 65 61 72 63 68 28 67 2e ( name_search(g.
e7d0: 7a 50 61 74 68 2c 20 61 57 65 62 70 61 67 65 2c zPath, aWebpage,
e7e0: 20 63 6f 75 6e 74 28 61 57 65 62 70 61 67 65 29 count(aWebpage)
e7f0: 2c 20 30 2c 20 26 69 64 78 29 20 29 7b 0a 23 69 , 0, &idx) ){.#i
e800: 66 64 65 66 20 46 4f 53 53 49 4c 5f 45 4e 41 42 fdef FOSSIL_ENAB
e810: 4c 45 5f 4a 53 4f 4e 0a 20 20 20 20 69 66 28 67 LE_JSON. if(g
e820: 2e 6a 73 6f 6e 2e 69 73 4a 73 6f 6e 4d 6f 64 65 .json.isJsonMode
e830: 29 7b 0a 20 20 20 20 20 20 6a 73 6f 6e 5f 65 72 ){. json_er
e840: 72 28 46 53 4c 5f 4a 53 4f 4e 5f 45 5f 52 45 53 r(FSL_JSON_E_RES
e850: 4f 55 52 43 45 5f 4e 4f 54 5f 46 4f 55 4e 44 2c OURCE_NOT_FOUND,
e860: 4e 55 4c 4c 2c 30 29 3b 0a 20 20 20 20 7d 65 6c NULL,0);. }el
e870: 73 65 0a 23 65 6e 64 69 66 0a 20 20 20 20 7b 0a se.#endif. {.
e880: 23 69 66 64 65 66 20 46 4f 53 53 49 4c 5f 45 4e #ifdef FOSSIL_EN
e890: 41 42 4c 45 5f 54 48 31 5f 48 4f 4f 4b 53 0a 20 ABLE_TH1_HOOKS.
e8a0: 20 20 20 20 20 69 6e 74 20 72 63 3b 0a 20 20 20 int rc;.
e8b0: 20 20 20 69 66 28 20 21 67 2e 66 4e 6f 54 68 48 if( !g.fNoThH
e8c0: 6f 6f 6b 20 29 7b 0a 20 20 20 20 20 20 20 20 72 ook ){. r
e8d0: 63 20 3d 20 54 68 5f 57 65 62 70 61 67 65 48 6f c = Th_WebpageHo
e8e0: 6f 6b 28 67 2e 7a 50 61 74 68 2c 20 30 29 3b 0a ok(g.zPath, 0);.
e8f0: 20 20 20 20 20 20 7d 65 6c 73 65 7b 0a 20 20 20 }else{.
e900: 20 20 20 20 20 72 63 20 3d 20 54 48 5f 4f 4b 3b rc = TH_OK;
e910: 0a 20 20 20 20 20 20 7d 0a 20 20 20 20 20 20 69 . }. i
e920: 66 28 20 72 63 3d 3d 54 48 5f 4f 4b 20 7c 7c 20 f( rc==TH_OK ||
e930: 72 63 3d 3d 54 48 5f 52 45 54 55 52 4e 20 7c 7c rc==TH_RETURN ||
e940: 20 72 63 3d 3d 54 48 5f 43 4f 4e 54 49 4e 55 45 rc==TH_CONTINUE
e950: 20 29 7b 0a 20 20 20 20 20 20 20 20 69 66 28 20 ){. if(
e960: 72 63 3d 3d 54 48 5f 4f 4b 20 7c 7c 20 72 63 3d rc==TH_OK || rc=
e970: 3d 54 48 5f 52 45 54 55 52 4e 20 29 7b 0a 23 65 =TH_RETURN ){.#e
e980: 6e 64 69 66 0a 20 20 20 20 20 20 20 20 20 20 63 ndif. c
e990: 67 69 5f 73 65 74 5f 73 74 61 74 75 73 28 34 30 gi_set_status(40
e9a0: 34 2c 22 4e 6f 74 20 46 6f 75 6e 64 22 29 3b 0a 4,"Not Found");.
e9b0: 20 20 20 20 20 20 20 20 20 20 40 20 3c 68 31 3e @ <h1>
e9c0: 4e 6f 74 20 46 6f 75 6e 64 3c 2f 68 31 3e 0a 20 Not Found</h1>.
e9d0: 20 20 20 20 20 20 20 20 20 40 20 3c 70 3e 50 61 @ <p>Pa
e9e0: 67 65 20 6e 6f 74 20 66 6f 75 6e 64 3a 20 25 68 ge not found: %h
e9f0: 28 67 2e 7a 50 61 74 68 29 3c 2f 70 3e 0a 23 69 (g.zPath)</p>.#i
ea00: 66 64 65 66 20 46 4f 53 53 49 4c 5f 45 4e 41 42 fdef FOSSIL_ENAB
ea10: 4c 45 5f 54 48 31 5f 48 4f 4f 4b 53 0a 20 20 20 LE_TH1_HOOKS.
ea20: 20 20 20 20 20 7d 0a 20 20 20 20 20 20 20 20 69 }. i
ea30: 66 28 20 21 67 2e 66 4e 6f 54 68 48 6f 6f 6b 20 f( !g.fNoThHook
ea40: 26 26 20 28 72 63 3d 3d 54 48 5f 4f 4b 20 7c 7c && (rc==TH_OK ||
ea50: 20 72 63 3d 3d 54 48 5f 43 4f 4e 54 49 4e 55 45 rc==TH_CONTINUE
ea60: 29 20 29 7b 0a 20 20 20 20 20 20 20 20 20 20 54 ) ){. T
ea70: 68 5f 57 65 62 70 61 67 65 4e 6f 74 69 66 79 28 h_WebpageNotify(
ea80: 67 2e 7a 50 61 74 68 2c 20 30 29 3b 0a 20 20 20 g.zPath, 0);.
ea90: 20 20 20 20 20 7d 0a 20 20 20 20 20 20 7d 0a 23 }. }.#
eaa0: 65 6e 64 69 66 0a 20 20 20 20 7d 0a 20 20 7d 65 endif. }. }e
eab0: 6c 73 65 20 69 66 28 20 61 57 65 62 70 61 67 65 lse if( aWebpage
eac0: 5b 69 64 78 5d 2e 78 46 75 6e 63 21 3d 70 61 67 [idx].xFunc!=pag
ead0: 65 5f 78 66 65 72 20 26 26 20 64 62 5f 73 63 68 e_xfer && db_sch
eae0: 65 6d 61 5f 69 73 5f 6f 75 74 6f 66 64 61 74 65 ema_is_outofdate
eaf0: 28 29 20 29 7b 0a 23 69 66 64 65 66 20 46 4f 53 () ){.#ifdef FOS
eb00: 53 49 4c 5f 45 4e 41 42 4c 45 5f 4a 53 4f 4e 0a SIL_ENABLE_JSON.
eb10: 20 20 20 20 69 66 28 67 2e 6a 73 6f 6e 2e 69 73 if(g.json.is
eb20: 4a 73 6f 6e 4d 6f 64 65 29 7b 0a 20 20 20 20 20 JsonMode){.
eb30: 20 6a 73 6f 6e 5f 65 72 72 28 46 53 4c 5f 4a 53 json_err(FSL_JS
eb40: 4f 4e 5f 45 5f 44 42 5f 4e 45 45 44 53 5f 52 45 ON_E_DB_NEEDS_RE
eb50: 42 55 49 4c 44 2c 4e 55 4c 4c 2c 30 29 3b 0a 20 BUILD,NULL,0);.
eb60: 20 20 20 7d 65 6c 73 65 0a 23 65 6e 64 69 66 0a }else.#endif.
eb70: 20 20 20 20 7b 0a 20 20 20 20 20 20 40 20 3c 68 {. @ <h
eb80: 31 3e 53 65 72 76 65 72 20 43 6f 6e 66 69 67 75 1>Server Configu
eb90: 72 61 74 69 6f 6e 20 45 72 72 6f 72 3c 2f 68 31 ration Error</h1
eba0: 3e 0a 20 20 20 20 20 20 40 20 3c 70 3e 54 68 65 >. @ <p>The
ebb0: 20 64 61 74 61 62 61 73 65 20 73 63 68 65 6d 61 database schema
ebc0: 20 6f 6e 20 74 68 65 20 73 65 72 76 65 72 20 69 on the server i
ebd0: 73 20 6f 75 74 2d 6f 66 2d 64 61 74 65 2e 20 20 s out-of-date.
ebe0: 50 6c 65 61 73 65 20 61 73 6b 0a 20 20 20 20 20 Please ask.
ebf0: 20 40 20 74 68 65 20 61 64 6d 69 6e 69 73 74 72 @ the administr
ec00: 61 74 6f 72 20 74 6f 20 72 75 6e 20 3c 62 3e 66 ator to run <b>f
ec10: 6f 73 73 69 6c 20 72 65 62 75 69 6c 64 3c 2f 62 ossil rebuild</b
ec20: 3e 2e 3c 2f 70 3e 0a 20 20 20 20 7d 0a 20 20 7d >.</p>. }. }
ec30: 65 6c 73 65 7b 0a 23 69 66 64 65 66 20 46 4f 53 else{.#ifdef FOS
ec40: 53 49 4c 5f 45 4e 41 42 4c 45 5f 54 48 31 5f 48 SIL_ENABLE_TH1_H
ec50: 4f 4f 4b 53 0a 20 20 20 20 2f 2a 0a 20 20 20 20 OOKS. /*.
ec60: 2a 2a 20 54 68 65 20 54 48 31 20 72 65 74 75 72 ** The TH1 retur
ec70: 6e 20 63 6f 64 65 73 20 66 72 6f 6d 20 74 68 65 n codes from the
ec80: 20 68 6f 6f 6b 20 77 69 6c 6c 20 62 65 20 68 61 hook will be ha
ec90: 6e 64 6c 65 64 20 61 73 20 66 6f 6c 6c 6f 77 73 ndled as follows
eca0: 3a 0a 20 20 20 20 2a 2a 0a 20 20 20 20 2a 2a 20 :. **. **
ecb0: 54 48 5f 4f 4b 3a 20 54 68 65 20 78 46 75 6e 63 TH_OK: The xFunc
ecc0: 28 29 20 61 6e 64 20 74 68 65 20 54 48 31 20 6e () and the TH1 n
ecd0: 6f 74 69 66 69 63 61 74 69 6f 6e 20 77 69 6c 6c otification will
ece0: 20 62 6f 74 68 20 62 65 20 65 78 65 63 75 74 65 both be execute
ecf0: 64 2e 0a 20 20 20 20 2a 2a 0a 20 20 20 20 2a 2a d.. **. **
ed00: 20 54 48 5f 45 52 52 4f 52 3a 20 54 68 65 20 78 TH_ERROR: The x
ed10: 46 75 6e 63 28 29 20 77 69 6c 6c 20 62 65 20 65 Func() will be e
ed20: 78 65 63 75 74 65 64 2c 20 74 68 65 20 54 48 31 xecuted, the TH1
ed30: 20 6e 6f 74 69 66 69 63 61 74 69 6f 6e 20 77 69 notification wi
ed40: 6c 6c 20 62 65 0a 20 20 20 20 2a 2a 20 20 20 20 ll be. **
ed50: 20 20 20 20 20 20 20 73 6b 69 70 70 65 64 2e 20 skipped.
ed60: 20 49 66 20 74 68 65 20 78 46 75 6e 63 28 29 20 If the xFunc()
ed70: 69 73 20 62 65 69 6e 67 20 68 6f 6f 6b 65 64 2c is being hooked,
ed80: 20 74 68 65 20 65 72 72 6f 72 20 6d 65 73 73 61 the error messa
ed90: 67 65 0a 20 20 20 20 2a 2a 20 20 20 20 20 20 20 ge. **
eda0: 20 20 20 20 77 69 6c 6c 20 62 65 20 65 6d 69 74 will be emit
edb0: 74 65 64 2e 0a 20 20 20 20 2a 2a 0a 20 20 20 20 ted.. **.
edc0: 2a 2a 20 54 48 5f 42 52 45 41 4b 3a 20 54 68 65 ** TH_BREAK: The
edd0: 20 78 46 75 6e 63 28 29 20 61 6e 64 20 74 68 65 xFunc() and the
ede0: 20 54 48 31 20 6e 6f 74 69 66 69 63 61 74 69 6f TH1 notificatio
edf0: 6e 20 77 69 6c 6c 20 62 6f 74 68 20 62 65 20 73 n will both be s
ee00: 6b 69 70 70 65 64 2e 0a 20 20 20 20 2a 2a 0a 20 kipped.. **.
ee10: 20 20 20 2a 2a 20 54 48 5f 52 45 54 55 52 4e 3a ** TH_RETURN:
ee20: 20 54 68 65 20 78 46 75 6e 63 28 29 20 77 69 6c The xFunc() wil
ee30: 6c 20 62 65 20 65 78 65 63 75 74 65 64 2c 20 74 l be executed, t
ee40: 68 65 20 54 48 31 20 6e 6f 74 69 66 69 63 61 74 he TH1 notificat
ee50: 69 6f 6e 20 77 69 6c 6c 20 62 65 0a 20 20 20 20 ion will be.
ee60: 2a 2a 20 20 20 20 20 20 20 20 20 20 20 20 73 6b ** sk
ee70: 69 70 70 65 64 2e 0a 20 20 20 20 2a 2a 0a 20 20 ipped.. **.
ee80: 20 20 2a 2a 20 54 48 5f 43 4f 4e 54 49 4e 55 45 ** TH_CONTINUE
ee90: 3a 20 54 68 65 20 78 46 75 6e 63 28 29 20 77 69 : The xFunc() wi
eea0: 6c 6c 20 62 65 20 73 6b 69 70 70 65 64 2c 20 74 ll be skipped, t
eeb0: 68 65 20 54 48 31 20 6e 6f 74 69 66 69 63 61 74 he TH1 notificat
eec0: 69 6f 6e 20 77 69 6c 6c 20 62 65 0a 20 20 20 20 ion will be.
eed0: 2a 2a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 **
eee0: 65 78 65 63 75 74 65 64 2e 0a 20 20 20 20 2a 2f executed.. */
eef0: 0a 20 20 20 20 69 6e 74 20 72 63 3b 0a 20 20 20 . int rc;.
ef00: 20 69 66 28 20 21 67 2e 66 4e 6f 54 68 48 6f 6f if( !g.fNoThHoo
ef10: 6b 20 29 7b 0a 20 20 20 20 20 20 72 63 20 3d 20 k ){. rc =
ef20: 54 68 5f 57 65 62 70 61 67 65 48 6f 6f 6b 28 61 Th_WebpageHook(a
ef30: 57 65 62 70 61 67 65 5b 69 64 78 5d 2e 7a 4e 61 Webpage[idx].zNa
ef40: 6d 65 2c 20 61 57 65 62 70 61 67 65 5b 69 64 78 me, aWebpage[idx
ef50: 5d 2e 63 6d 64 46 6c 61 67 73 29 3b 0a 20 20 20 ].cmdFlags);.
ef60: 20 7d 65 6c 73 65 7b 0a 20 20 20 20 20 20 72 63 }else{. rc
ef70: 20 3d 20 54 48 5f 4f 4b 3b 0a 20 20 20 20 7d 0a = TH_OK;. }.
ef80: 20 20 20 20 69 66 28 20 72 63 3d 3d 54 48 5f 4f if( rc==TH_O
ef90: 4b 20 7c 7c 20 72 63 3d 3d 54 48 5f 52 45 54 55 K || rc==TH_RETU
efa0: 52 4e 20 7c 7c 20 72 63 3d 3d 54 48 5f 43 4f 4e RN || rc==TH_CON
efb0: 54 49 4e 55 45 20 29 7b 0a 20 20 20 20 20 20 69 TINUE ){. i
efc0: 66 28 20 72 63 3d 3d 54 48 5f 4f 4b 20 7c 7c 20 f( rc==TH_OK ||
efd0: 72 63 3d 3d 54 48 5f 52 45 54 55 52 4e 20 29 7b rc==TH_RETURN ){
efe0: 0a 23 65 6e 64 69 66 0a 20 20 20 20 20 20 20 20 .#endif.
eff0: 61 57 65 62 70 61 67 65 5b 69 64 78 5d 2e 78 46 aWebpage[idx].xF
f000: 75 6e 63 28 29 3b 0a 23 69 66 64 65 66 20 46 4f unc();.#ifdef FO
f010: 53 53 49 4c 5f 45 4e 41 42 4c 45 5f 54 48 31 5f SSIL_ENABLE_TH1_
f020: 48 4f 4f 4b 53 0a 20 20 20 20 20 20 7d 0a 20 20 HOOKS. }.
f030: 20 20 20 20 69 66 28 20 21 67 2e 66 4e 6f 54 68 if( !g.fNoTh
f040: 48 6f 6f 6b 20 26 26 20 28 72 63 3d 3d 54 48 5f Hook && (rc==TH_
f050: 4f 4b 20 7c 7c 20 72 63 3d 3d 54 48 5f 43 4f 4e OK || rc==TH_CON
f060: 54 49 4e 55 45 29 20 29 7b 0a 20 20 20 20 20 20 TINUE) ){.
f070: 20 20 54 68 5f 57 65 62 70 61 67 65 4e 6f 74 69 Th_WebpageNoti
f080: 66 79 28 61 57 65 62 70 61 67 65 5b 69 64 78 5d fy(aWebpage[idx]
f090: 2e 7a 4e 61 6d 65 2c 20 61 57 65 62 70 61 67 65 .zName, aWebpage
f0a0: 5b 69 64 78 5d 2e 63 6d 64 46 6c 61 67 73 29 3b [idx].cmdFlags);
f0b0: 0a 20 20 20 20 20 20 7d 0a 20 20 20 20 7d 0a 23 . }. }.#
f0c0: 65 6e 64 69 66 0a 20 20 7d 0a 0a 20 20 2f 2a 20 endif. }.. /*
f0d0: 52 65 74 75 72 6e 20 74 68 65 20 72 65 73 75 6c Return the resul
f0e0: 74 2e 0a 20 20 2a 2f 0a 20 20 63 67 69 5f 72 65 t.. */. cgi_re
f0f0: 70 6c 79 28 29 3b 0a 7d 0a 0a 2f 2a 20 49 66 20 ply();.}../* If
f100: 74 68 65 20 43 47 49 20 70 72 6f 67 72 61 6d 20 the CGI program
f110: 63 6f 6e 74 61 69 6e 73 20 6f 6e 65 20 6f 72 20 contains one or
f120: 6d 6f 72 65 20 6c 69 6e 65 73 20 6f 66 20 74 68 more lines of th
f130: 65 20 66 6f 72 6d 0a 2a 2a 0a 2a 2a 20 20 20 20 e form.**.**
f140: 72 65 64 69 72 65 63 74 3a 20 20 72 65 70 6f 73 redirect: repos
f150: 69 74 6f 72 79 2d 66 69 6c 65 6e 61 6d 65 20 20 itory-filename
f160: 68 74 74 70 3a 2f 2f 68 6f 73 74 6e 61 6d 65 2f http://hostname/
f170: 70 61 74 68 2f 25 73 0a 2a 2a 0a 2a 2a 20 74 68 path/%s.**.** th
f180: 65 6e 20 63 6f 6e 74 72 6f 6c 20 6a 75 6d 70 73 en control jumps
f190: 20 68 65 72 65 2e 20 20 53 65 61 72 63 68 20 65 here. Search e
f1a0: 61 63 68 20 72 65 70 6f 73 69 74 6f 72 79 20 66 ach repository f
f1b0: 6f 72 20 61 6e 20 61 72 74 69 66 61 63 74 20 49 or an artifact I
f1c0: 44 0a 2a 2a 20 6f 72 20 74 69 63 6b 65 74 20 49 D.** or ticket I
f1d0: 44 20 74 68 61 74 20 6d 61 74 63 68 65 73 20 74 D that matches t
f1e0: 68 65 20 22 6e 61 6d 65 22 20 43 47 49 20 70 61 he "name" CGI pa
f1f0: 72 61 6d 65 74 65 72 20 61 6e 64 20 66 6f 72 20 rameter and for
f200: 74 68 65 0a 2a 2a 20 66 69 72 73 74 20 6d 61 74 the.** first mat
f210: 63 68 2c 20 72 65 64 69 72 65 63 74 20 74 6f 20 ch, redirect to
f220: 74 68 65 20 63 6f 72 72 65 73 70 6f 6e 64 69 6e the correspondin
f230: 67 20 55 52 4c 20 77 69 74 68 20 74 68 65 20 22 g URL with the "
f240: 6e 61 6d 65 22 20 43 47 49 0a 2a 2a 20 70 61 72 name" CGI.** par
f250: 61 6d 65 74 65 72 20 69 6e 73 65 72 74 65 64 2e ameter inserted.
f260: 20 20 50 61 69 6e 74 20 61 6e 20 65 72 72 6f 72 Paint an error
f270: 20 70 61 67 65 20 69 66 20 6e 6f 20 6d 61 74 63 page if no matc
f280: 68 20 69 73 20 66 6f 75 6e 64 2e 0a 2a 2a 0a 2a h is found..**.*
f290: 2a 20 49 66 20 74 68 65 72 65 20 69 73 20 61 20 * If there is a
f2a0: 6c 69 6e 65 20 6f 66 20 74 68 65 20 66 6f 72 6d line of the form
f2b0: 3a 0a 2a 2a 0a 2a 2a 20 20 20 20 72 65 64 69 72 :.**.** redir
f2c0: 65 63 74 3a 20 2a 20 55 52 4c 0a 2a 2a 0a 2a 2a ect: * URL.**.**
f2d0: 20 54 68 65 6e 20 61 20 72 65 64 69 72 65 63 74 Then a redirect
f2e0: 20 69 73 20 6d 61 64 65 20 74 6f 20 55 52 4c 20 is made to URL
f2f0: 69 66 20 6e 6f 20 6d 61 74 63 68 20 69 73 20 66 if no match is f
f300: 6f 75 6e 64 2e 20 20 4f 74 68 65 72 77 69 73 65 ound. Otherwise
f310: 20 61 0a 2a 2a 20 76 65 72 79 20 70 72 69 6d 69 a.** very primi
f320: 74 69 76 65 20 65 72 72 6f 72 20 6d 65 73 73 61 tive error messa
f330: 67 65 20 69 73 20 72 65 74 75 72 6e 65 64 2e 0a ge is returned..
f340: 2a 2f 0a 73 74 61 74 69 63 20 76 6f 69 64 20 72 */.static void r
f350: 65 64 69 72 65 63 74 5f 77 65 62 5f 70 61 67 65 edirect_web_page
f360: 28 69 6e 74 20 6e 52 65 64 69 72 65 63 74 2c 20 (int nRedirect,
f370: 63 68 61 72 20 2a 2a 61 7a 52 65 64 69 72 65 63 char **azRedirec
f380: 74 29 7b 0a 20 20 69 6e 74 20 69 3b 20 20 20 20 t){. int i;
f390: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
f3a0: 20 20 20 20 20 20 20 20 20 2f 2a 20 4c 6f 6f 70 /* Loop
f3b0: 20 63 6f 75 6e 74 65 72 20 2a 2f 0a 20 20 63 6f counter */. co
f3c0: 6e 73 74 20 63 68 61 72 20 2a 7a 4e 6f 74 46 6f nst char *zNotFo
f3d0: 75 6e 64 20 3d 20 30 3b 20 20 20 20 20 20 20 20 und = 0;
f3e0: 20 2f 2a 20 4e 6f 74 20 66 6f 75 6e 64 20 55 52 /* Not found UR
f3f0: 4c 20 2a 2f 0a 20 20 63 6f 6e 73 74 20 63 68 61 L */. const cha
f400: 72 20 2a 7a 4e 61 6d 65 20 3d 20 50 28 22 6e 61 r *zName = P("na
f410: 6d 65 22 29 3b 0a 20 20 73 65 74 5f 62 61 73 65 me");. set_base
f420: 5f 75 72 6c 28 30 29 3b 0a 20 20 69 66 28 20 7a _url(0);. if( z
f430: 4e 61 6d 65 3d 3d 30 20 29 7b 0a 20 20 20 20 7a Name==0 ){. z
f440: 4e 61 6d 65 20 3d 20 50 28 22 53 43 52 49 50 54 Name = P("SCRIPT
f450: 5f 4e 41 4d 45 22 29 3b 0a 20 20 20 20 69 66 28 _NAME");. if(
f460: 20 7a 4e 61 6d 65 20 26 26 20 7a 4e 61 6d 65 5b zName && zName[
f470: 30 5d 3d 3d 27 2f 27 20 29 20 7a 4e 61 6d 65 2b 0]=='/' ) zName+
f480: 2b 3b 0a 20 20 7d 0a 20 20 69 66 28 20 7a 4e 61 +;. }. if( zNa
f490: 6d 65 20 26 26 20 76 61 6c 69 64 61 74 65 31 36 me && validate16
f4a0: 28 7a 4e 61 6d 65 2c 20 73 74 72 6c 65 6e 28 7a (zName, strlen(z
f4b0: 4e 61 6d 65 29 29 20 29 7b 0a 20 20 20 20 66 6f Name)) ){. fo
f4c0: 72 28 69 3d 30 3b 20 69 3c 6e 52 65 64 69 72 65 r(i=0; i<nRedire
f4d0: 63 74 3b 20 69 2b 2b 29 7b 0a 20 20 20 20 20 20 ct; i++){.
f4e0: 69 66 28 20 66 6f 73 73 69 6c 5f 73 74 72 63 6d if( fossil_strcm
f4f0: 70 28 61 7a 52 65 64 69 72 65 63 74 5b 69 2a 32 p(azRedirect[i*2
f500: 5d 2c 22 2a 22 29 3d 3d 30 20 29 7b 0a 20 20 20 ],"*")==0 ){.
f510: 20 20 20 20 20 7a 4e 6f 74 46 6f 75 6e 64 20 3d zNotFound =
f520: 20 61 7a 52 65 64 69 72 65 63 74 5b 69 2a 32 2b azRedirect[i*2+
f530: 31 5d 3b 0a 20 20 20 20 20 20 20 20 63 6f 6e 74 1];. cont
f540: 69 6e 75 65 3b 0a 20 20 20 20 20 20 7d 0a 20 20 inue;. }.
f550: 20 20 20 20 64 62 5f 6f 70 65 6e 5f 72 65 70 6f db_open_repo
f560: 73 69 74 6f 72 79 28 61 7a 52 65 64 69 72 65 63 sitory(azRedirec
f570: 74 5b 69 2a 32 5d 29 3b 0a 20 20 20 20 20 20 69 t[i*2]);. i
f580: 66 28 20 64 62 5f 65 78 69 73 74 73 28 22 53 45 f( db_exists("SE
f590: 4c 45 43 54 20 31 20 46 52 4f 4d 20 62 6c 6f 62 LECT 1 FROM blob
f5a0: 20 57 48 45 52 45 20 75 75 69 64 20 47 4c 4f 42 WHERE uuid GLOB
f5b0: 20 27 25 71 2a 27 22 2c 20 7a 4e 61 6d 65 29 20 '%q*'", zName)
f5c0: 7c 7c 0a 09 20 20 64 62 5f 65 78 69 73 74 73 28 ||.. db_exists(
f5d0: 22 53 45 4c 45 43 54 20 31 20 46 52 4f 4d 20 74 "SELECT 1 FROM t
f5e0: 69 63 6b 65 74 20 57 48 45 52 45 20 74 6b 74 5f icket WHERE tkt_
f5f0: 75 75 69 64 20 47 4c 4f 42 20 27 25 71 2a 27 22 uuid GLOB '%q*'"
f600: 2c 20 7a 4e 61 6d 65 29 20 29 7b 0a 20 20 20 20 , zName) ){.
f610: 20 20 20 20 63 67 69 5f 72 65 64 69 72 65 63 74 cgi_redirect
f620: 66 28 61 7a 52 65 64 69 72 65 63 74 5b 69 2a 32 f(azRedirect[i*2
f630: 2b 31 5d 20 2f 2a 77 6f 72 6b 73 2d 6c 69 6b 65 +1] /*works-like
f640: 3a 22 25 73 22 2a 2f 2c 20 7a 4e 61 6d 65 29 3b :"%s"*/, zName);
f650: 0a 20 20 20 20 20 20 20 20 72 65 74 75 72 6e 3b . return;
f660: 0a 20 20 20 20 20 20 7d 0a 20 20 20 20 20 20 64 . }. d
f670: 62 5f 63 6c 6f 73 65 28 31 29 3b 0a 20 20 20 20 b_close(1);.
f680: 7d 0a 20 20 7d 0a 20 20 69 66 28 20 7a 4e 6f 74 }. }. if( zNot
f690: 46 6f 75 6e 64 20 29 7b 0a 20 20 20 20 63 67 69 Found ){. cgi
f6a0: 5f 72 65 64 69 72 65 63 74 66 28 7a 4e 6f 74 46 _redirectf(zNotF
f6b0: 6f 75 6e 64 20 2f 2a 77 6f 72 6b 73 2d 6c 69 6b ound /*works-lik
f6c0: 65 3a 22 25 73 22 2a 2f 2c 20 7a 4e 61 6d 65 29 e:"%s"*/, zName)
f6d0: 3b 0a 20 20 7d 65 6c 73 65 7b 0a 20 20 20 20 40 ;. }else{. @
f6e0: 20 3c 68 74 6d 6c 3e 0a 20 20 20 20 40 20 3c 68 <html>. @ <h
f6f0: 65 61 64 3e 3c 74 69 74 6c 65 3e 4e 6f 20 53 75 ead><title>No Su
f700: 63 68 20 4f 62 6a 65 63 74 3c 2f 74 69 74 6c 65 ch Object</title
f710: 3e 3c 2f 68 65 61 64 3e 0a 20 20 20 20 40 20 3c ></head>. @ <
f720: 62 6f 64 79 3e 0a 20 20 20 20 40 20 3c 70 3e 4e body>. @ <p>N
f730: 6f 20 73 75 63 68 20 6f 62 6a 65 63 74 3a 20 3c o such object: <
f740: 62 3e 25 68 28 7a 4e 61 6d 65 29 3c 2f 62 3e 3c b>%h(zName)</b><
f750: 2f 70 3e 0a 20 20 20 20 40 20 3c 2f 62 6f 64 79 /p>. @ </body
f760: 3e 0a 20 20 20 20 63 67 69 5f 72 65 70 6c 79 28 >. cgi_reply(
f770: 29 3b 0a 20 20 7d 0a 7d 0a 0a 2f 2a 0a 2a 2a 20 );. }.}../*.**
f780: 43 4f 4d 4d 41 4e 44 3a 20 63 67 69 2a 0a 2a 2a COMMAND: cgi*.**
f790: 0a 2a 2a 20 55 73 61 67 65 3a 20 25 66 6f 73 73 .** Usage: %foss
f7a0: 69 6c 20 3f 63 67 69 3f 20 53 43 52 49 50 54 0a il ?cgi? SCRIPT.
f7b0: 2a 2a 0a 2a 2a 20 54 68 65 20 53 43 52 49 50 54 **.** The SCRIPT
f7c0: 20 61 72 67 75 6d 65 6e 74 20 69 73 20 74 68 65 argument is the
f7d0: 20 6e 61 6d 65 20 6f 66 20 61 20 66 69 6c 65 20 name of a file
f7e0: 74 68 61 74 20 69 73 20 74 68 65 20 43 47 49 20 that is the CGI
f7f0: 73 63 72 69 70 74 0a 2a 2a 20 74 68 61 74 20 69 script.** that i
f800: 73 20 62 65 69 6e 67 20 72 75 6e 2e 20 20 54 68 s being run. Th
f810: 65 20 63 6f 6d 6d 61 6e 64 20 6e 61 6d 65 2c 20 e command name,
f820: 22 63 67 69 22 2c 20 6d 61 79 20 62 65 20 6f 6d "cgi", may be om
f830: 69 74 74 65 64 20 69 66 0a 2a 2a 20 74 68 65 20 itted if.** the
f840: 47 41 54 45 57 41 59 5f 49 4e 54 45 52 46 41 43 GATEWAY_INTERFAC
f850: 45 20 65 6e 76 69 72 6f 6e 6d 65 6e 74 20 76 61 E environment va
f860: 72 69 61 62 6c 65 20 69 73 20 73 65 74 20 74 6f riable is set to
f870: 20 22 43 47 49 22 20 28 77 68 69 63 68 0a 2a 2a "CGI" (which.**
f880: 20 73 68 6f 75 6c 64 20 61 6c 77 61 79 73 20 62 should always b
f890: 65 20 74 68 65 20 63 61 73 65 20 66 6f 72 20 43 e the case for C
f8a0: 47 49 20 73 63 72 69 70 74 73 20 72 75 6e 20 62 GI scripts run b
f8b0: 79 20 61 20 77 65 62 73 65 72 76 65 72 2e 29 20 y a webserver.)
f8c0: 20 54 68 65 0a 2a 2a 20 53 43 52 49 50 54 20 66 The.** SCRIPT f
f8d0: 69 6c 65 20 73 68 6f 75 6c 64 20 6c 6f 6f 6b 20 ile should look
f8e0: 73 6f 6d 65 74 68 69 6e 67 20 6c 69 6b 65 20 74 something like t
f8f0: 68 69 73 3a 0a 2a 2a 0a 2a 2a 20 20 20 20 20 20 his:.**.**
f900: 23 21 2f 75 73 72 2f 62 69 6e 2f 66 6f 73 73 69 #!/usr/bin/fossi
f910: 6c 0a 2a 2a 20 20 20 20 20 20 72 65 70 6f 73 69 l.** reposi
f920: 74 6f 72 79 3a 20 2f 68 6f 6d 65 2f 73 6f 6d 65 tory: /home/some
f930: 62 6f 64 79 2f 70 72 6f 6a 65 63 74 2e 64 62 0a body/project.db.
f940: 2a 2a 0a 2a 2a 20 54 68 65 20 73 65 63 6f 6e 64 **.** The second
f950: 20 6c 69 6e 65 20 64 65 66 69 6e 65 73 20 74 68 line defines th
f960: 65 20 6e 61 6d 65 20 6f 66 20 74 68 65 20 72 65 e name of the re
f970: 70 6f 73 69 74 6f 72 79 2e 20 20 41 66 74 65 72 pository. After
f980: 20 6c 6f 63 61 74 69 6e 67 0a 2a 2a 20 74 68 65 locating.** the
f990: 20 72 65 70 6f 73 69 74 6f 72 79 2c 20 66 6f 73 repository, fos
f9a0: 73 69 6c 20 77 69 6c 6c 20 67 65 6e 65 72 61 74 sil will generat
f9b0: 65 20 61 20 77 65 62 70 61 67 65 20 6f 6e 20 73 e a webpage on s
f9c0: 74 64 6f 75 74 20 62 61 73 65 64 20 6f 6e 0a 2a tdout based on.*
f9d0: 2a 20 74 68 65 20 76 61 6c 75 65 73 20 6f 66 20 * the values of
f9e0: 73 74 61 6e 64 61 72 64 20 43 47 49 20 65 6e 76 standard CGI env
f9f0: 69 72 6f 6e 6d 65 6e 74 20 76 61 72 69 61 62 6c ironment variabl
fa00: 65 73 2e 0a 2a 2a 0a 2a 2a 20 53 65 65 20 61 6c es..**.** See al
fa10: 73 6f 3a 20 68 74 74 70 2c 20 73 65 72 76 65 72 so: http, server
fa20: 2c 20 77 69 6e 73 72 76 0a 2a 2f 0a 76 6f 69 64 , winsrv.*/.void
fa30: 20 63 6d 64 5f 63 67 69 28 76 6f 69 64 29 7b 0a cmd_cgi(void){.
fa40: 20 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a 46 const char *zF
fa50: 69 6c 65 3b 0a 20 20 63 6f 6e 73 74 20 63 68 61 ile;. const cha
fa60: 72 20 2a 7a 4e 6f 74 46 6f 75 6e 64 20 3d 20 30 r *zNotFound = 0
fa70: 3b 0a 20 20 63 68 61 72 20 2a 2a 61 7a 52 65 64 ;. char **azRed
fa80: 69 72 65 63 74 20 3d 20 30 3b 20 20 20 20 20 20 irect = 0;
fa90: 20 20 20 20 20 20 20 2f 2a 20 4c 69 73 74 20 6f /* List o
faa0: 66 20 72 65 70 6f 73 69 74 6f 72 69 65 73 20 74 f repositories t
fab0: 6f 20 72 65 64 69 72 65 63 74 20 74 6f 20 2a 2f o redirect to */
fac0: 0a 20 20 69 6e 74 20 6e 52 65 64 69 72 65 63 74 . int nRedirect
fad0: 20 3d 20 30 3b 20 20 20 20 20 20 20 20 20 20 20 = 0;
fae0: 20 20 20 20 20 20 2f 2a 20 4e 75 6d 62 65 72 20 /* Number
faf0: 6f 66 20 65 6e 74 72 69 65 73 20 69 6e 20 61 7a of entries in az
fb00: 52 65 64 69 72 65 63 74 20 2a 2f 0a 20 20 47 6c Redirect */. Gl
fb10: 6f 62 20 2a 70 46 69 6c 65 47 6c 6f 62 20 3d 20 ob *pFileGlob =
fb20: 30 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 20 0;
fb30: 20 2f 2a 20 50 61 74 74 65 72 6e 20 66 6f 72 20 /* Pattern for
fb40: 66 69 6c 65 73 20 2a 2f 0a 20 20 69 6e 74 20 61 files */. int a
fb50: 6c 6c 6f 77 52 65 70 6f 4c 69 73 74 20 3d 20 30 llowRepoList = 0
fb60: 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a ; /*
fb70: 20 41 6c 6c 6f 77 20 6c 69 73 74 73 20 6f 66 20 Allow lists of
fb80: 72 65 70 6f 73 69 74 6f 72 79 20 66 69 6c 65 73 repository files
fb90: 20 2a 2f 0a 20 20 42 6c 6f 62 20 63 6f 6e 66 69 */. Blob confi
fba0: 67 2c 20 6c 69 6e 65 2c 20 6b 65 79 2c 20 76 61 g, line, key, va
fbb0: 6c 75 65 2c 20 76 61 6c 75 65 32 3b 0a 20 20 69 lue, value2;. i
fbc0: 66 28 20 67 2e 61 72 67 63 3d 3d 33 20 26 26 20 f( g.argc==3 &&
fbd0: 66 6f 73 73 69 6c 5f 73 74 72 63 6d 70 28 67 2e fossil_strcmp(g.
fbe0: 61 72 67 76 5b 31 5d 2c 22 63 67 69 22 29 3d 3d argv[1],"cgi")==
fbf0: 30 20 29 7b 0a 20 20 20 20 7a 46 69 6c 65 20 3d 0 ){. zFile =
fc00: 20 67 2e 61 72 67 76 5b 32 5d 3b 0a 20 20 7d 65 g.argv[2];. }e
fc10: 6c 73 65 7b 0a 20 20 20 20 7a 46 69 6c 65 20 3d lse{. zFile =
fc20: 20 67 2e 61 72 67 76 5b 31 5d 3b 0a 20 20 7d 0a g.argv[1];. }.
fc30: 20 20 67 2e 68 74 74 70 4f 75 74 20 3d 20 73 74 g.httpOut = st
fc40: 64 6f 75 74 3b 0a 20 20 67 2e 68 74 74 70 49 6e dout;. g.httpIn
fc50: 20 3d 20 73 74 64 69 6e 3b 0a 20 20 66 6f 73 73 = stdin;. foss
fc60: 69 6c 5f 62 69 6e 61 72 79 5f 6d 6f 64 65 28 67 il_binary_mode(g
fc70: 2e 68 74 74 70 4f 75 74 29 3b 0a 20 20 66 6f 73 .httpOut);. fos
fc80: 73 69 6c 5f 62 69 6e 61 72 79 5f 6d 6f 64 65 28 sil_binary_mode(
fc90: 67 2e 68 74 74 70 49 6e 29 3b 0a 20 20 67 2e 63 g.httpIn);. g.c
fca0: 67 69 4f 75 74 70 75 74 20 3d 20 31 3b 0a 20 20 giOutput = 1;.
fcb0: 62 6c 6f 62 5f 72 65 61 64 5f 66 72 6f 6d 5f 66 blob_read_from_f
fcc0: 69 6c 65 28 26 63 6f 6e 66 69 67 2c 20 7a 46 69 ile(&config, zFi
fcd0: 6c 65 29 3b 0a 20 20 77 68 69 6c 65 28 20 62 6c le);. while( bl
fce0: 6f 62 5f 6c 69 6e 65 28 26 63 6f 6e 66 69 67 2c ob_line(&config,
fcf0: 20 26 6c 69 6e 65 29 20 29 7b 0a 20 20 20 20 69 &line) ){. i
fd00: 66 28 20 21 62 6c 6f 62 5f 74 6f 6b 65 6e 28 26 f( !blob_token(&
fd10: 6c 69 6e 65 2c 20 26 6b 65 79 29 20 29 20 63 6f line, &key) ) co
fd20: 6e 74 69 6e 75 65 3b 0a 20 20 20 20 69 66 28 20 ntinue;. if(
fd30: 62 6c 6f 62 5f 62 75 66 66 65 72 28 26 6b 65 79 blob_buffer(&key
fd40: 29 5b 30 5d 3d 3d 27 23 27 20 29 20 63 6f 6e 74 )[0]=='#' ) cont
fd50: 69 6e 75 65 3b 0a 20 20 20 20 69 66 28 20 62 6c inue;. if( bl
fd60: 6f 62 5f 65 71 28 26 6b 65 79 2c 20 22 72 65 70 ob_eq(&key, "rep
fd70: 6f 73 69 74 6f 72 79 3a 22 29 20 26 26 20 62 6c ository:") && bl
fd80: 6f 62 5f 74 61 69 6c 28 26 6c 69 6e 65 2c 20 26 ob_tail(&line, &
fd90: 76 61 6c 75 65 29 20 29 7b 0a 20 20 20 20 20 20 value) ){.
fda0: 2f 2a 20 72 65 70 6f 73 69 74 6f 72 79 3a 20 46 /* repository: F
fdb0: 49 4c 45 4e 41 4d 45 0a 20 20 20 20 20 20 2a 2a ILENAME. **
fdc0: 0a 20 20 20 20 20 20 2a 2a 20 54 68 65 20 6e 61 . ** The na
fdd0: 6d 65 20 6f 66 20 74 68 65 20 46 6f 73 73 69 6c me of the Fossil
fde0: 20 72 65 70 6f 73 69 74 6f 72 79 20 74 6f 20 62 repository to b
fdf0: 65 20 73 65 72 76 65 64 20 76 69 61 20 43 47 49 e served via CGI
fe00: 2e 20 20 4d 6f 73 74 0a 20 20 20 20 20 20 2a 2a . Most. **
fe10: 20 66 6f 73 73 69 6c 20 43 47 49 20 73 63 72 69 fossil CGI scri
fe20: 70 74 73 20 68 61 76 65 20 61 20 73 69 6e 67 6c pts have a singl
fe30: 65 20 6e 6f 6e 2d 63 6f 6d 6d 65 6e 74 20 6c 69 e non-comment li
fe40: 6e 65 20 74 68 61 74 20 63 6f 6e 74 61 69 6e 73 ne that contains
fe50: 0a 20 20 20 20 20 20 2a 2a 20 74 68 69 73 20 6f . ** this o
fe60: 6e 65 20 65 6e 74 72 79 2e 0a 20 20 20 20 20 20 ne entry..
fe70: 2a 2f 0a 20 20 20 20 20 20 62 6c 6f 62 5f 74 72 */. blob_tr
fe80: 69 6d 28 26 76 61 6c 75 65 29 3b 0a 20 20 20 20 im(&value);.
fe90: 20 20 64 62 5f 6f 70 65 6e 5f 72 65 70 6f 73 69 db_open_reposi
fea0: 74 6f 72 79 28 62 6c 6f 62 5f 73 74 72 28 26 76 tory(blob_str(&v
feb0: 61 6c 75 65 29 29 3b 0a 20 20 20 20 20 20 62 6c alue));. bl
fec0: 6f 62 5f 72 65 73 65 74 28 26 76 61 6c 75 65 29 ob_reset(&value)
fed0: 3b 0a 20 20 20 20 20 20 63 6f 6e 74 69 6e 75 65 ;. continue
fee0: 3b 0a 20 20 20 20 7d 0a 20 20 20 20 69 66 28 20 ;. }. if(
fef0: 62 6c 6f 62 5f 65 71 28 26 6b 65 79 2c 20 22 64 blob_eq(&key, "d
ff00: 69 72 65 63 74 6f 72 79 3a 22 29 20 26 26 20 62 irectory:") && b
ff10: 6c 6f 62 5f 74 6f 6b 65 6e 28 26 6c 69 6e 65 2c lob_token(&line,
ff20: 20 26 76 61 6c 75 65 29 20 29 7b 0a 20 20 20 20 &value) ){.
ff30: 20 20 2f 2a 20 64 69 72 65 63 74 6f 72 79 3a 20 /* directory:
ff40: 44 49 52 45 43 54 4f 52 59 0a 20 20 20 20 20 20 DIRECTORY.
ff50: 2a 2a 0a 20 20 20 20 20 20 2a 2a 20 49 66 20 72 **. ** If r
ff60: 65 70 6f 73 69 74 6f 72 79 3a 20 69 73 20 6f 6d epository: is om
ff70: 69 74 74 65 64 2c 20 74 68 65 6e 20 74 65 72 6d itted, then term
ff80: 73 20 6f 66 20 74 68 65 20 50 41 54 48 5f 49 4e s of the PATH_IN
ff90: 46 4f 20 63 67 69 20 70 61 72 61 6d 65 74 65 72 FO cgi parameter
ffa0: 0a 20 20 20 20 20 20 2a 2a 20 61 72 65 20 61 70 . ** are ap
ffb0: 70 65 6e 64 65 64 20 74 6f 20 44 49 52 45 43 54 pended to DIRECT
ffc0: 4f 52 59 20 6c 6f 6f 6b 69 6e 67 20 66 6f 72 20 ORY looking for
ffd0: 61 20 72 65 70 6f 73 69 74 6f 72 79 20 28 77 68 a repository (wh
ffe0: 6f 73 65 20 6e 61 6d 65 20 65 6e 64 73 0a 20 20 ose name ends.
fff0: 20 20 20 20 2a 2a 20 69 6e 20 22 2e 66 6f 73 73 ** in ".foss
10000 69 6c 22 29 20 6f 72 20 61 20 66 69 6c 65 20 69 il") or a file i
10010 6e 20 22 66 69 6c 65 73 3a 22 2e 0a 20 20 20 20 n "files:"..
10020 20 20 2a 2f 0a 20 20 20 20 20 20 64 62 5f 63 6c */. db_cl
10030 6f 73 65 28 31 29 3b 0a 20 20 20 20 20 20 67 2e ose(1);. g.
10040 7a 52 65 70 6f 73 69 74 6f 72 79 4e 61 6d 65 20 zRepositoryName
10050 3d 20 6d 70 72 69 6e 74 66 28 22 25 73 22 2c 20 = mprintf("%s",
10060 62 6c 6f 62 5f 73 74 72 28 26 76 61 6c 75 65 29 blob_str(&value)
10070 29 3b 0a 20 20 20 20 20 20 62 6c 6f 62 5f 72 65 );. blob_re
10080 73 65 74 28 26 76 61 6c 75 65 29 3b 0a 20 20 20 set(&value);.
10090 20 20 20 63 6f 6e 74 69 6e 75 65 3b 0a 20 20 20 continue;.
100a0 20 7d 0a 20 20 20 20 69 66 28 20 62 6c 6f 62 5f }. if( blob_
100b0 65 71 28 26 6b 65 79 2c 20 22 6e 6f 74 66 6f 75 eq(&key, "notfou
100c0 6e 64 3a 22 29 20 26 26 20 62 6c 6f 62 5f 74 6f nd:") && blob_to
100d0 6b 65 6e 28 26 6c 69 6e 65 2c 20 26 76 61 6c 75 ken(&line, &valu
100e0 65 29 20 29 7b 0a 20 20 20 20 20 20 2f 2a 20 6e e) ){. /* n
100f0 6f 74 66 6f 75 6e 64 3a 20 55 52 4c 0a 20 20 20 otfound: URL.
10100 20 20 20 2a 2a 0a 20 20 20 20 20 20 2a 2a 20 49 **. ** I
10110 66 20 75 73 69 6e 67 20 64 69 72 65 63 74 6f 72 f using director
10120 79 3a 20 61 6e 64 20 6e 6f 20 73 75 69 74 61 62 y: and no suitab
10130 6c 65 20 72 65 70 6f 73 69 74 6f 72 79 20 6f 72 le repository or
10140 20 66 69 6c 65 20 69 73 20 66 6f 75 6e 64 2c 0a file is found,.
10150 20 20 20 20 20 20 2a 2a 20 74 68 65 6e 20 72 65 ** then re
10160 64 69 72 65 63 74 20 74 6f 20 55 52 4c 2e 0a 20 direct to URL..
10170 20 20 20 20 20 2a 2f 0a 20 20 20 20 20 20 7a 4e */. zN
10180 6f 74 46 6f 75 6e 64 20 3d 20 6d 70 72 69 6e 74 otFound = mprint
10190 66 28 22 25 73 22 2c 20 62 6c 6f 62 5f 73 74 72 f("%s", blob_str
101a0 28 26 76 61 6c 75 65 29 29 3b 0a 20 20 20 20 20 (&value));.
101b0 20 62 6c 6f 62 5f 72 65 73 65 74 28 26 76 61 6c blob_reset(&val
101c0 75 65 29 3b 0a 20 20 20 20 20 20 63 6f 6e 74 69 ue);. conti
101d0 6e 75 65 3b 0a 20 20 20 20 7d 0a 20 20 20 20 69 nue;. }. i
101e0 66 28 20 62 6c 6f 62 5f 65 71 28 26 6b 65 79 2c f( blob_eq(&key,
101f0 20 22 6c 6f 63 61 6c 61 75 74 68 22 29 20 29 7b "localauth") ){
10200 0a 20 20 20 20 20 20 2f 2a 20 6c 6f 63 61 6c 61 . /* locala
10210 75 74 68 0a 20 20 20 20 20 20 2a 2a 0a 20 20 20 uth. **.
10220 20 20 20 2a 2a 20 47 72 61 6e 74 20 22 61 64 6d ** Grant "adm
10230 69 6e 69 73 74 72 61 74 6f 72 22 20 70 72 69 76 inistrator" priv
10240 69 6c 65 67 65 73 20 74 6f 20 75 73 65 72 73 20 ileges to users
10250 63 6f 6e 6e 65 63 74 69 6e 67 20 77 69 74 68 20 connecting with
10260 48 54 54 50 0a 20 20 20 20 20 20 2a 2a 20 66 72 HTTP. ** fr
10270 6f 6d 20 49 50 20 61 64 64 72 65 73 73 20 31 32 om IP address 12
10280 37 2e 30 2e 30 2e 31 2e 20 20 44 6f 20 6e 6f 74 7.0.0.1. Do not
10290 20 62 6f 74 68 65 72 20 63 68 65 63 6b 69 6e 67 bother checking
102a0 20 63 72 65 64 65 6e 74 69 61 6c 73 2e 0a 20 20 credentials..
102b0 20 20 20 20 2a 2f 0a 20 20 20 20 20 20 67 2e 75 */. g.u
102c0 73 65 4c 6f 63 61 6c 61 75 74 68 20 3d 20 31 3b seLocalauth = 1;
102d0 0a 20 20 20 20 20 20 63 6f 6e 74 69 6e 75 65 3b . continue;
102e0 0a 20 20 20 20 7d 0a 20 20 20 20 69 66 28 20 62 . }. if( b
102f0 6c 6f 62 5f 65 71 28 26 6b 65 79 2c 20 22 72 65 lob_eq(&key, "re
10300 70 6f 6c 69 73 74 22 29 20 29 7b 0a 20 20 20 20 polist") ){.
10310 20 20 2f 2a 20 72 65 70 6f 6c 69 73 74 0a 20 20 /* repolist.
10320 20 20 20 20 2a 2a 0a 20 20 20 20 20 20 2a 2a 20 **. **
10330 49 66 20 75 73 69 6e 67 20 22 64 69 72 65 63 74 If using "direct
10340 6f 72 79 3a 22 20 61 6e 64 20 74 68 65 20 55 52 ory:" and the UR
10350 4c 20 69 73 20 22 2f 22 20 74 68 65 6e 20 67 65 L is "/" then ge
10360 6e 65 72 61 74 65 20 61 20 70 61 67 65 0a 20 20 nerate a page.
10370 20 20 20 20 2a 2a 20 73 68 6f 77 69 6e 67 20 61 ** showing a
10380 20 6c 69 73 74 20 6f 66 20 61 76 61 69 6c 61 62 list of availab
10390 6c 65 20 72 65 70 6f 73 69 74 6f 72 69 65 73 2e le repositories.
103a0 0a 20 20 20 20 20 20 2a 2f 0a 20 20 20 20 20 20 . */.
103b0 61 6c 6c 6f 77 52 65 70 6f 4c 69 73 74 20 3d 20 allowRepoList =
103c0 31 3b 0a 20 20 20 20 20 20 63 6f 6e 74 69 6e 75 1;. continu
103d0 65 3b 0a 20 20 20 20 7d 0a 20 20 20 20 69 66 28 e;. }. if(
103e0 20 62 6c 6f 62 5f 65 71 28 26 6b 65 79 2c 20 22 blob_eq(&key, "
103f0 72 65 64 69 72 65 63 74 3a 22 29 20 26 26 20 62 redirect:") && b
10400 6c 6f 62 5f 74 6f 6b 65 6e 28 26 6c 69 6e 65 2c lob_token(&line,
10410 20 26 76 61 6c 75 65 29 0a 20 20 20 20 20 20 20 &value).
10420 20 20 20 20 20 26 26 20 62 6c 6f 62 5f 74 6f 6b && blob_tok
10430 65 6e 28 26 6c 69 6e 65 2c 20 26 76 61 6c 75 65 en(&line, &value
10440 32 29 20 29 7b 0a 20 20 20 20 20 20 2f 2a 20 53 2) ){. /* S
10450 65 65 20 74 68 65 20 68 65 61 64 65 72 20 63 6f ee the header co
10460 6d 6d 65 6e 74 20 6f 6e 20 74 68 65 20 72 65 64 mment on the red
10470 69 72 65 63 74 5f 77 65 62 5f 70 61 67 65 28 29 irect_web_page()
10480 20 66 75 6e 63 74 69 6f 6e 0a 20 20 20 20 20 20 function.
10490 2a 2a 20 61 62 6f 76 65 20 66 6f 72 20 64 65 74 ** above for det
104a0 61 69 6c 73 2e 20 2a 2f 0a 20 20 20 20 20 20 6e ails. */. n
104b0 52 65 64 69 72 65 63 74 2b 2b 3b 0a 20 20 20 20 Redirect++;.
104c0 20 20 61 7a 52 65 64 69 72 65 63 74 20 3d 20 66 azRedirect = f
104d0 6f 73 73 69 6c 5f 72 65 61 6c 6c 6f 63 28 61 7a ossil_realloc(az
104e0 52 65 64 69 72 65 63 74 2c 20 32 2a 6e 52 65 64 Redirect, 2*nRed
104f0 69 72 65 63 74 2a 73 69 7a 65 6f 66 28 63 68 61 irect*sizeof(cha
10500 72 2a 29 29 3b 0a 20 20 20 20 20 20 61 7a 52 65 r*));. azRe
10510 64 69 72 65 63 74 5b 6e 52 65 64 69 72 65 63 74 direct[nRedirect
10520 2a 32 2d 32 5d 20 3d 20 6d 70 72 69 6e 74 66 28 *2-2] = mprintf(
10530 22 25 73 22 2c 20 62 6c 6f 62 5f 73 74 72 28 26 "%s", blob_str(&
10540 76 61 6c 75 65 29 29 3b 0a 20 20 20 20 20 20 61 value));. a
10550 7a 52 65 64 69 72 65 63 74 5b 6e 52 65 64 69 72 zRedirect[nRedir
10560 65 63 74 2a 32 2d 31 5d 20 3d 20 6d 70 72 69 6e ect*2-1] = mprin
10570 74 66 28 22 25 73 22 2c 20 62 6c 6f 62 5f 73 74 tf("%s", blob_st
10580 72 28 26 76 61 6c 75 65 32 29 29 3b 0a 20 20 20 r(&value2));.
10590 20 20 20 62 6c 6f 62 5f 72 65 73 65 74 28 26 76 blob_reset(&v
105a0 61 6c 75 65 29 3b 0a 20 20 20 20 20 20 62 6c 6f alue);. blo
105b0 62 5f 72 65 73 65 74 28 26 76 61 6c 75 65 32 29 b_reset(&value2)
105c0 3b 0a 20 20 20 20 20 20 63 6f 6e 74 69 6e 75 65 ;. continue
105d0 3b 0a 20 20 20 20 7d 0a 20 20 20 20 69 66 28 20 ;. }. if(
105e0 62 6c 6f 62 5f 65 71 28 26 6b 65 79 2c 20 22 66 blob_eq(&key, "f
105f0 69 6c 65 73 3a 22 29 20 26 26 20 62 6c 6f 62 5f iles:") && blob_
10600 74 6f 6b 65 6e 28 26 6c 69 6e 65 2c 20 26 76 61 token(&line, &va
10610 6c 75 65 29 20 29 7b 0a 20 20 20 20 20 20 2f 2a lue) ){. /*
10620 20 66 69 6c 65 73 3a 20 47 4c 4f 42 4c 49 53 54 files: GLOBLIST
10630 0a 20 20 20 20 20 20 2a 2a 0a 20 20 20 20 20 20 . **.
10640 2a 2a 20 47 4c 4f 42 4c 49 53 54 20 69 73 20 61 ** GLOBLIST is a
10650 20 63 6f 6d 6d 61 2d 73 65 70 61 72 61 74 65 64 comma-separated
10660 20 6c 69 73 74 20 6f 66 20 66 69 6c 65 6e 61 6d list of filenam
10670 65 20 67 6c 6f 62 73 2e 20 20 46 6f 72 0a 20 20 e globs. For.
10680 20 20 20 20 2a 2a 20 65 78 61 6d 70 6c 65 3a 20 ** example:
10690 20 2a 2e 68 74 6d 6c 2c 2a 2e 63 73 73 2c 2a 2e *.html,*.css,*.
106a0 6a 73 0a 20 20 20 20 20 20 2a 2a 0a 20 20 20 20 js. **.
106b0 20 20 2a 2a 20 49 66 20 74 68 65 20 72 65 70 6f ** If the repo
106c0 73 69 74 6f 72 79 3a 20 6c 69 6e 65 20 69 73 20 sitory: line is
106d0 6f 6d 69 74 74 65 64 20 61 6e 64 20 74 68 65 6e omitted and then
106e0 20 50 41 54 48 5f 49 4e 46 4f 20 69 73 20 73 65 PATH_INFO is se
106f0 61 72 63 68 65 64 0a 20 20 20 20 20 20 2a 2a 20 arched. **
10700 66 6f 72 20 66 69 6c 65 73 20 74 68 61 74 20 6d for files that m
10710 61 74 63 68 20 61 6e 79 20 6f 66 20 74 68 65 73 atch any of thes
10720 65 20 47 4c 4f 42 73 20 61 6e 64 20 69 66 20 61 e GLOBs and if a
10730 6e 79 20 73 75 63 68 20 66 69 6c 65 20 69 73 0a ny such file is.
10740 20 20 20 20 20 20 2a 2a 20 66 6f 75 6e 64 20 69 ** found i
10750 74 20 69 73 20 72 65 74 75 72 6e 65 64 20 76 65 t is returned ve
10760 72 62 61 74 69 6d 2e 20 20 54 68 69 73 20 66 65 rbatim. This fe
10770 61 74 75 72 65 20 61 6c 6c 6f 77 73 20 22 66 6f ature allows "fo
10780 73 73 69 6c 20 73 65 72 76 65 72 22 0a 20 20 20 ssil server".
10790 20 20 20 2a 2a 20 74 6f 20 66 75 6e 63 74 69 6f ** to functio
107a0 6e 20 61 73 20 61 20 70 72 69 6d 69 74 69 76 65 n as a primitive
107b0 20 77 65 62 2d 73 65 72 76 65 72 20 64 65 6c 69 web-server deli
107c0 76 65 72 69 6e 67 20 61 72 62 69 74 72 61 72 79 vering arbitrary
107d0 20 63 6f 6e 74 65 6e 74 2e 0a 20 20 20 20 20 20 content..
107e0 2a 2f 0a 20 20 20 20 20 20 70 46 69 6c 65 47 6c */. pFileGl
107f0 6f 62 20 3d 20 67 6c 6f 62 5f 63 72 65 61 74 65 ob = glob_create
10800 28 62 6c 6f 62 5f 73 74 72 28 26 76 61 6c 75 65 (blob_str(&value
10810 29 29 3b 0a 20 20 20 20 20 20 62 6c 6f 62 5f 72 ));. blob_r
10820 65 73 65 74 28 26 76 61 6c 75 65 29 3b 0a 20 20 eset(&value);.
10830 20 20 20 20 63 6f 6e 74 69 6e 75 65 3b 0a 20 20 continue;.
10840 20 20 7d 0a 20 20 20 20 69 66 28 20 62 6c 6f 62 }. if( blob
10850 5f 65 71 28 26 6b 65 79 2c 20 22 73 65 74 65 6e _eq(&key, "seten
10860 76 3a 22 29 20 26 26 20 62 6c 6f 62 5f 74 6f 6b v:") && blob_tok
10870 65 6e 28 26 6c 69 6e 65 2c 20 26 76 61 6c 75 65 en(&line, &value
10880 29 0a 20 20 20 20 20 20 20 20 20 20 20 20 26 26 ). &&
10890 20 62 6c 6f 62 5f 74 6f 6b 65 6e 28 26 6c 69 6e blob_token(&lin
108a0 65 2c 20 26 76 61 6c 75 65 32 29 20 29 7b 0a 20 e, &value2) ){.
108b0 20 20 20 20 20 2f 2a 20 73 65 74 65 6e 76 3a 20 /* setenv:
108c0 4e 41 4d 45 20 56 41 4c 55 45 0a 20 20 20 20 20 NAME VALUE.
108d0 20 2a 2a 0a 20 20 20 20 20 20 2a 2a 20 53 65 74 **. ** Set
108e0 73 20 65 6e 76 69 72 6f 6e 6d 65 6e 74 20 76 61 s environment va
108f0 72 69 61 62 6c 65 20 4e 41 4d 45 20 74 6f 20 56 riable NAME to V
10900 41 4c 55 45 0a 20 20 20 20 20 20 2a 2f 0a 20 20 ALUE. */.
10910 20 20 20 20 66 6f 73 73 69 6c 5f 73 65 74 65 6e fossil_seten
10920 76 28 62 6c 6f 62 5f 73 74 72 28 26 76 61 6c 75 v(blob_str(&valu
10930 65 29 2c 20 62 6c 6f 62 5f 73 74 72 28 26 76 61 e), blob_str(&va
10940 6c 75 65 32 29 29 3b 0a 20 20 20 20 20 20 62 6c lue2));. bl
10950 6f 62 5f 72 65 73 65 74 28 26 76 61 6c 75 65 29 ob_reset(&value)
10960 3b 0a 20 20 20 20 20 20 62 6c 6f 62 5f 72 65 73 ;. blob_res
10970 65 74 28 26 76 61 6c 75 65 32 29 3b 0a 20 20 20 et(&value2);.
10980 20 20 20 63 6f 6e 74 69 6e 75 65 3b 0a 20 20 20 continue;.
10990 20 7d 0a 20 20 20 20 69 66 28 20 62 6c 6f 62 5f }. if( blob_
109a0 65 71 28 26 6b 65 79 2c 20 22 64 65 62 75 67 3a eq(&key, "debug:
109b0 22 29 20 26 26 20 62 6c 6f 62 5f 74 6f 6b 65 6e ") && blob_token
109c0 28 26 6c 69 6e 65 2c 20 26 76 61 6c 75 65 29 20 (&line, &value)
109d0 29 7b 0a 20 20 20 20 20 20 2f 2a 20 64 65 62 75 ){. /* debu
109e0 67 3a 20 46 49 4c 45 4e 41 4d 45 0a 20 20 20 20 g: FILENAME.
109f0 20 20 2a 2a 0a 20 20 20 20 20 20 2a 2a 20 43 61 **. ** Ca
10a00 75 73 65 73 20 6f 75 74 70 75 74 20 66 72 6f 6d uses output from
10a10 20 63 67 69 5f 64 65 62 75 67 28 29 20 61 6e 64 cgi_debug() and
10a20 20 43 47 49 44 45 42 55 47 28 28 29 29 20 63 61 CGIDEBUG(()) ca
10a30 6c 6c 73 20 74 6f 20 67 6f 0a 20 20 20 20 20 20 lls to go.
10a40 2a 2a 20 69 6e 74 6f 20 46 49 4c 45 4e 41 4d 45 ** into FILENAME
10a50 2e 0a 20 20 20 20 20 20 2a 2f 0a 20 20 20 20 20 .. */.
10a60 20 67 2e 66 44 65 62 75 67 20 3d 20 66 6f 73 73 g.fDebug = foss
10a70 69 6c 5f 66 6f 70 65 6e 28 62 6c 6f 62 5f 73 74 il_fopen(blob_st
10a80 72 28 26 76 61 6c 75 65 29 2c 20 22 61 62 22 29 r(&value), "ab")
10a90 3b 0a 20 20 20 20 20 20 62 6c 6f 62 5f 72 65 73 ;. blob_res
10aa0 65 74 28 26 76 61 6c 75 65 29 3b 0a 20 20 20 20 et(&value);.
10ab0 20 20 63 6f 6e 74 69 6e 75 65 3b 0a 20 20 20 20 continue;.
10ac0 7d 0a 20 20 20 20 69 66 28 20 62 6c 6f 62 5f 65 }. if( blob_e
10ad0 71 28 26 6b 65 79 2c 20 22 65 72 72 6f 72 6c 6f q(&key, "errorlo
10ae0 67 3a 22 29 20 26 26 20 62 6c 6f 62 5f 74 6f 6b g:") && blob_tok
10af0 65 6e 28 26 6c 69 6e 65 2c 20 26 76 61 6c 75 65 en(&line, &value
10b00 29 20 29 7b 0a 20 20 20 20 20 20 2f 2a 20 65 72 ) ){. /* er
10b10 72 6f 72 6c 6f 67 3a 20 46 49 4c 45 4e 41 4d 45 rorlog: FILENAME
10b20 0a 20 20 20 20 20 20 2a 2a 0a 20 20 20 20 20 20 . **.
10b30 2a 2a 20 43 61 75 73 65 73 20 6d 65 73 73 61 67 ** Causes messag
10b40 65 73 20 66 72 6f 6d 20 77 61 72 6e 69 6e 67 73 es from warnings
10b50 2c 20 65 72 72 6f 72 73 2c 20 61 6e 64 20 70 61 , errors, and pa
10b60 6e 69 63 73 20 74 6f 20 62 65 20 61 70 70 65 6e nics to be appen
10b70 64 65 64 0a 20 20 20 20 20 20 2a 2a 20 74 6f 20 ded. ** to
10b80 46 49 4c 45 4e 41 4d 45 2e 0a 20 20 20 20 20 20 FILENAME..
10b90 2a 2f 0a 20 20 20 20 20 20 67 2e 7a 45 72 72 6c */. g.zErrl
10ba0 6f 67 20 3d 20 6d 70 72 69 6e 74 66 28 22 25 73 og = mprintf("%s
10bb0 22 2c 20 62 6c 6f 62 5f 73 74 72 28 26 76 61 6c ", blob_str(&val
10bc0 75 65 29 29 3b 0a 20 20 20 20 20 20 62 6c 6f 62 ue));. blob
10bd0 5f 72 65 73 65 74 28 26 76 61 6c 75 65 29 3b 0a _reset(&value);.
10be0 20 20 20 20 20 20 63 6f 6e 74 69 6e 75 65 3b 0a continue;.
10bf0 20 20 20 20 7d 0a 20 20 20 20 69 66 28 20 62 6c }. if( bl
10c00 6f 62 5f 65 71 28 26 6b 65 79 2c 20 22 48 4f 4d ob_eq(&key, "HOM
10c10 45 3a 22 29 20 26 26 20 62 6c 6f 62 5f 74 6f 6b E:") && blob_tok
10c20 65 6e 28 26 6c 69 6e 65 2c 20 26 76 61 6c 75 65 en(&line, &value
10c30 29 20 29 7b 0a 20 20 20 20 20 20 2f 2a 20 48 4f ) ){. /* HO
10c40 4d 45 3a 20 56 41 4c 55 45 0a 20 20 20 20 20 20 ME: VALUE.
10c50 2a 2a 0a 20 20 20 20 20 20 2a 2a 20 53 65 74 20 **. ** Set
10c60 43 47 49 20 70 61 72 61 6d 65 74 65 72 20 22 48 CGI parameter "H
10c70 4f 4d 45 22 20 74 6f 20 56 41 4c 55 45 2e 20 20 OME" to VALUE.
10c80 54 68 69 73 20 69 73 20 6c 65 67 61 63 79 2e 20 This is legacy.
10c90 20 55 73 65 0a 20 20 20 20 20 20 2a 2a 20 73 65 Use. ** se
10ca0 74 65 6e 76 3a 20 69 6e 73 74 65 61 64 2e 0a 20 tenv: instead..
10cb0 20 20 20 20 20 2a 2f 0a 20 20 20 20 20 20 63 67 */. cg
10cc0 69 5f 73 65 74 65 6e 76 28 22 48 4f 4d 45 22 2c i_setenv("HOME",
10cd0 20 62 6c 6f 62 5f 73 74 72 28 26 76 61 6c 75 65 blob_str(&value
10ce0 29 29 3b 0a 20 20 20 20 20 20 62 6c 6f 62 5f 72 ));. blob_r
10cf0 65 73 65 74 28 26 76 61 6c 75 65 29 3b 0a 20 20 eset(&value);.
10d00 20 20 20 20 63 6f 6e 74 69 6e 75 65 3b 0a 20 20 continue;.
10d10 20 20 7d 0a 20 20 20 20 69 66 28 20 62 6c 6f 62 }. if( blob
10d20 5f 65 71 28 26 6b 65 79 2c 20 22 73 6b 69 6e 3a _eq(&key, "skin:
10d30 22 29 20 26 26 20 62 6c 6f 62 5f 74 6f 6b 65 6e ") && blob_token
10d40 28 26 6c 69 6e 65 2c 20 26 76 61 6c 75 65 29 20 (&line, &value)
10d50 29 7b 0a 20 20 20 20 20 20 2f 2a 20 73 6b 69 6e ){. /* skin
10d60 3a 20 4c 41 42 45 4c 0a 20 20 20 20 20 20 2a 2a : LABEL. **
10d70 0a 20 20 20 20 20 20 2a 2a 20 55 73 65 20 6f 6e . ** Use on
10d80 65 20 6f 66 20 74 68 65 20 62 75 69 6c 74 2d 69 e of the built-i
10d90 6e 20 73 6b 69 6e 73 20 64 65 66 69 6e 65 64 20 n skins defined
10da0 62 79 20 4c 41 42 45 4c 2e 20 20 4c 41 42 45 4c by LABEL. LABEL
10db0 20 69 73 20 74 68 65 0a 20 20 20 20 20 20 2a 2a is the. **
10dc0 20 6e 61 6d 65 20 6f 66 20 74 68 65 20 73 75 62 name of the sub
10dd0 64 69 72 65 63 74 6f 72 79 20 75 6e 64 65 72 20 directory under
10de0 74 68 65 20 73 6b 69 6e 73 2f 20 64 69 72 65 63 the skins/ direc
10df0 74 6f 72 79 20 74 68 61 74 20 68 6f 6c 64 73 0a tory that holds.
10e00 20 20 20 20 20 20 2a 2a 20 74 68 65 20 65 6c 65 ** the ele
10e10 6d 65 6e 74 73 20 6f 66 20 74 68 65 20 62 75 69 ments of the bui
10e20 6c 74 2d 69 6e 20 73 6b 69 6e 2e 20 20 49 66 20 lt-in skin. If
10e30 4c 41 42 45 4c 20 64 6f 65 73 20 6e 6f 74 20 6d LABEL does not m
10e40 61 74 63 68 2c 0a 20 20 20 20 20 20 2a 2a 20 74 atch,. ** t
10e50 68 69 73 20 64 69 72 65 63 74 69 76 65 20 69 73 his directive is
10e60 20 61 20 73 69 6c 65 6e 74 20 6e 6f 2d 6f 70 2e a silent no-op.
10e70 0a 20 20 20 20 20 20 2a 2f 0a 20 20 20 20 20 20 . */.
10e80 73 6b 69 6e 5f 75 73 65 5f 61 6c 74 65 72 6e 61 skin_use_alterna
10e90 74 69 76 65 28 62 6c 6f 62 5f 73 74 72 28 26 76 tive(blob_str(&v
10ea0 61 6c 75 65 29 29 3b 0a 20 20 20 20 20 20 62 6c alue));. bl
10eb0 6f 62 5f 72 65 73 65 74 28 26 76 61 6c 75 65 29 ob_reset(&value)
10ec0 3b 0a 20 20 20 20 20 20 63 6f 6e 74 69 6e 75 65 ;. continue
10ed0 3b 0a 20 20 20 20 7d 0a 20 20 7d 0a 20 20 62 6c ;. }. }. bl
10ee0 6f 62 5f 72 65 73 65 74 28 26 63 6f 6e 66 69 67 ob_reset(&config
10ef0 29 3b 0a 20 20 69 66 28 20 67 2e 64 62 3d 3d 30 );. if( g.db==0
10f00 20 26 26 20 67 2e 7a 52 65 70 6f 73 69 74 6f 72 && g.zRepositor
10f10 79 4e 61 6d 65 3d 3d 30 20 26 26 20 6e 52 65 64 yName==0 && nRed
10f20 69 72 65 63 74 3d 3d 30 20 29 7b 0a 20 20 20 20 irect==0 ){.
10f30 63 67 69 5f 70 61 6e 69 63 28 22 55 6e 61 62 6c cgi_panic("Unabl
10f40 65 20 74 6f 20 66 69 6e 64 20 6f 72 20 6f 70 65 e to find or ope
10f50 6e 20 74 68 65 20 70 72 6f 6a 65 63 74 20 72 65 n the project re
10f60 70 6f 73 69 74 6f 72 79 22 29 3b 0a 20 20 7d 0a pository");. }.
10f70 20 20 63 67 69 5f 69 6e 69 74 28 29 3b 0a 20 20 cgi_init();.
10f80 69 66 28 20 6e 52 65 64 69 72 65 63 74 20 29 7b if( nRedirect ){
10f90 0a 20 20 20 20 72 65 64 69 72 65 63 74 5f 77 65 . redirect_we
10fa0 62 5f 70 61 67 65 28 6e 52 65 64 69 72 65 63 74 b_page(nRedirect
10fb0 2c 20 61 7a 52 65 64 69 72 65 63 74 29 3b 0a 20 , azRedirect);.
10fc0 20 7d 65 6c 73 65 7b 0a 20 20 20 20 70 72 6f 63 }else{. proc
10fd0 65 73 73 5f 6f 6e 65 5f 77 65 62 5f 70 61 67 65 ess_one_web_page
10fe0 28 7a 4e 6f 74 46 6f 75 6e 64 2c 20 70 46 69 6c (zNotFound, pFil
10ff0 65 47 6c 6f 62 2c 20 61 6c 6c 6f 77 52 65 70 6f eGlob, allowRepo
11000 4c 69 73 74 29 3b 0a 20 20 7d 0a 7d 0a 0a 2f 2a List);. }.}../*
11010 0a 2a 2a 20 49 66 20 67 2e 61 72 67 76 5b 61 72 .** If g.argv[ar
11020 67 5d 20 65 78 69 73 74 73 20 74 68 65 6e 20 69 g] exists then i
11030 74 20 69 73 20 65 69 74 68 65 72 20 74 68 65 20 t is either the
11040 6e 61 6d 65 20 6f 66 20 61 20 72 65 70 6f 73 69 name of a reposi
11050 74 6f 72 79 0a 2a 2a 20 74 68 61 74 20 77 69 6c tory.** that wil
11060 6c 20 62 65 20 75 73 65 64 20 62 79 20 61 20 73 l be used by a s
11070 65 72 76 65 72 2c 20 6f 72 20 65 6c 73 65 20 69 erver, or else i
11080 74 20 69 73 20 61 20 64 69 72 65 63 74 6f 72 79 t is a directory
11090 20 74 68 61 74 0a 2a 2a 20 63 6f 6e 74 61 69 6e that.** contain
110a0 73 20 6d 75 6c 74 69 70 6c 65 20 72 65 70 6f 73 s multiple repos
110b0 69 74 6f 72 69 65 73 20 74 68 61 74 20 63 61 6e itories that can
110c0 20 62 65 20 73 65 72 76 65 64 2e 20 20 49 66 20 be served. If
110d0 67 2e 61 72 67 76 5b 61 72 67 5d 0a 2a 2a 20 69 g.argv[arg].** i
110e0 73 20 61 20 64 69 72 65 63 74 6f 72 79 2c 20 74 s a directory, t
110f0 68 65 20 72 65 70 6f 73 69 74 6f 72 69 65 73 20 he repositories
11100 69 74 20 63 6f 6e 74 61 69 6e 73 20 6d 75 73 74 it contains must
11110 20 62 65 20 6e 61 6d 65 64 0a 2a 2a 20 22 2a 2e be named.** "*.
11120 66 6f 73 73 69 6c 22 2e 20 20 49 66 20 67 2e 61 fossil". If g.a
11130 72 67 76 5b 61 72 67 5d 20 64 6f 65 73 20 6e 6f rgv[arg] does no
11140 74 20 65 78 69 73 74 2c 20 74 68 65 6e 20 77 65 t exist, then we
11150 20 6d 75 73 74 20 62 65 20 77 69 74 68 69 6e 0a must be within.
11160 2a 2a 20 61 6e 20 6f 70 65 6e 20 63 68 65 63 6b ** an open check
11170 2d 6f 75 74 20 61 6e 64 20 74 68 65 20 72 65 70 -out and the rep
11180 6f 73 69 74 6f 72 79 20 73 65 72 76 65 20 69 73 ository serve is
11190 20 74 68 65 20 72 65 70 6f 73 69 74 6f 72 79 20 the repository
111a0 6f 66 0a 2a 2a 20 74 68 61 74 20 63 68 65 63 6b of.** that check
111b0 2d 6f 75 74 2e 0a 2a 2a 0a 2a 2a 20 4f 70 65 6e -out..**.** Open
111c0 20 74 68 65 20 72 65 70 6f 73 69 74 6f 72 79 20 the repository
111d0 74 6f 20 62 65 20 73 65 72 76 65 64 20 69 66 20 to be served if
111e0 69 74 20 69 73 20 6b 6e 6f 77 6e 2e 20 20 49 66 it is known. If
111f0 20 67 2e 61 72 67 76 5b 61 72 67 5d 20 69 73 0a g.argv[arg] is.
11200 2a 2a 20 61 20 64 69 72 65 63 74 6f 72 79 20 66 ** a directory f
11210 75 6c 6c 20 6f 66 20 72 65 70 6f 73 69 74 6f 72 ull of repositor
11220 69 65 73 2c 20 74 68 65 6e 20 73 65 74 20 67 2e ies, then set g.
11230 7a 52 65 70 6f 73 69 74 6f 72 79 4e 61 6d 65 20 zRepositoryName
11240 74 6f 0a 2a 2a 20 74 68 65 20 6e 61 6d 65 20 6f to.** the name o
11250 66 20 74 68 61 74 20 64 69 72 65 63 74 6f 72 79 f that directory
11260 20 61 6e 64 20 74 68 65 20 73 70 65 63 69 66 69 and the specifi
11270 63 20 72 65 70 6f 73 69 74 6f 72 79 20 77 69 6c c repository wil
11280 6c 20 62 65 0a 2a 2a 20 6f 70 65 6e 65 64 20 6c l be.** opened l
11290 61 74 65 72 20 62 79 20 70 72 6f 63 65 73 73 5f ater by process_
112a0 6f 6e 65 5f 77 65 62 5f 70 61 67 65 28 29 20 62 one_web_page() b
112b0 61 73 65 64 20 6f 6e 20 74 68 65 20 63 6f 6e 74 ased on the cont
112c0 65 6e 74 20 6f 66 0a 2a 2a 20 74 68 65 20 50 41 ent of.** the PA
112d0 54 48 5f 49 4e 46 4f 20 76 61 72 69 61 62 6c 65 TH_INFO variable
112e0 2e 0a 2a 2a 0a 2a 2a 20 49 66 20 74 68 65 20 66 ..**.** If the f
112f0 43 72 65 61 74 65 20 66 6c 61 67 20 69 73 20 73 Create flag is s
11300 65 74 2c 20 74 68 65 6e 20 63 72 65 61 74 65 20 et, then create
11310 74 68 65 20 72 65 70 6f 73 69 74 6f 72 79 20 69 the repository i
11320 66 20 69 74 0a 2a 2a 20 64 6f 65 73 20 6e 6f 74 f it.** does not
11330 20 61 6c 72 65 61 64 79 20 65 78 69 73 74 2e 0a already exist..
11340 2a 2f 0a 73 74 61 74 69 63 20 76 6f 69 64 20 66 */.static void f
11350 69 6e 64 5f 73 65 72 76 65 72 5f 72 65 70 6f 73 ind_server_repos
11360 69 74 6f 72 79 28 69 6e 74 20 61 72 67 2c 20 69 itory(int arg, i
11370 6e 74 20 66 43 72 65 61 74 65 29 7b 0a 20 20 69 nt fCreate){. i
11380 66 28 20 67 2e 61 72 67 63 3c 3d 61 72 67 20 29 f( g.argc<=arg )
11390 7b 0a 20 20 20 20 64 62 5f 6d 75 73 74 5f 62 65 {. db_must_be
113a0 5f 77 69 74 68 69 6e 5f 74 72 65 65 28 29 3b 0a _within_tree();.
113b0 20 20 7d 65 6c 73 65 7b 0a 20 20 20 20 63 6f 6e }else{. con
113c0 73 74 20 63 68 61 72 20 2a 7a 52 65 70 6f 20 3d st char *zRepo =
113d0 20 67 2e 61 72 67 76 5b 61 72 67 5d 3b 0a 20 20 g.argv[arg];.
113e0 20 20 69 6e 74 20 69 73 44 69 72 20 3d 20 66 69 int isDir = fi
113f0 6c 65 5f 69 73 64 69 72 28 7a 52 65 70 6f 29 3b le_isdir(zRepo);
11400 0a 20 20 20 20 69 66 28 20 69 73 44 69 72 3d 3d . if( isDir==
11410 31 20 29 7b 0a 20 20 20 20 20 20 67 2e 7a 52 65 1 ){. g.zRe
11420 70 6f 73 69 74 6f 72 79 4e 61 6d 65 20 3d 20 6d positoryName = m
11430 70 72 69 6e 74 66 28 22 25 73 22 2c 20 7a 52 65 printf("%s", zRe
11440 70 6f 29 3b 0a 20 20 20 20 20 20 66 69 6c 65 5f po);. file_
11450 73 69 6d 70 6c 69 66 79 5f 6e 61 6d 65 28 67 2e simplify_name(g.
11460 7a 52 65 70 6f 73 69 74 6f 72 79 4e 61 6d 65 2c zRepositoryName,
11470 20 2d 31 2c 20 30 29 3b 0a 20 20 20 20 7d 65 6c -1, 0);. }el
11480 73 65 7b 0a 20 20 20 20 20 20 69 66 28 20 69 73 se{. if( is
11490 44 69 72 3d 3d 30 20 26 26 20 66 43 72 65 61 74 Dir==0 && fCreat
114a0 65 20 29 7b 0a 20 20 20 20 20 20 20 20 63 6f 6e e ){. con
114b0 73 74 20 63 68 61 72 20 2a 7a 50 61 73 73 77 6f st char *zPasswo
114c0 72 64 3b 0a 20 20 20 20 20 20 20 20 64 62 5f 63 rd;. db_c
114d0 72 65 61 74 65 5f 72 65 70 6f 73 69 74 6f 72 79 reate_repository
114e0 28 7a 52 65 70 6f 29 3b 0a 20 20 20 20 20 20 20 (zRepo);.
114f0 20 64 62 5f 6f 70 65 6e 5f 72 65 70 6f 73 69 74 db_open_reposit
11500 6f 72 79 28 7a 52 65 70 6f 29 3b 0a 20 20 20 20 ory(zRepo);.
11510 20 20 20 20 64 62 5f 62 65 67 69 6e 5f 74 72 61 db_begin_tra
11520 6e 73 61 63 74 69 6f 6e 28 29 3b 0a 20 20 20 20 nsaction();.
11530 20 20 20 20 64 62 5f 69 6e 69 74 69 61 6c 5f 73 db_initial_s
11540 65 74 75 70 28 30 2c 20 22 6e 6f 77 22 2c 20 67 etup(0, "now", g
11550 2e 7a 4c 6f 67 69 6e 29 3b 0a 20 20 20 20 20 20 .zLogin);.
11560 20 20 64 62 5f 65 6e 64 5f 74 72 61 6e 73 61 63 db_end_transac
11570 74 69 6f 6e 28 30 29 3b 0a 20 20 20 20 20 20 20 tion(0);.
11580 20 66 6f 73 73 69 6c 5f 70 72 69 6e 74 28 22 70 fossil_print("p
11590 72 6f 6a 65 63 74 2d 69 64 3a 20 25 73 5c 6e 22 roject-id: %s\n"
115a0 2c 20 64 62 5f 67 65 74 28 22 70 72 6f 6a 65 63 , db_get("projec
115b0 74 2d 63 6f 64 65 22 2c 20 30 29 29 3b 0a 20 20 t-code", 0));.
115c0 20 20 20 20 20 20 66 6f 73 73 69 6c 5f 70 72 69 fossil_pri
115d0 6e 74 28 22 73 65 72 76 65 72 2d 69 64 3a 20 20 nt("server-id:
115e0 25 73 5c 6e 22 2c 20 64 62 5f 67 65 74 28 22 73 %s\n", db_get("s
115f0 65 72 76 65 72 2d 63 6f 64 65 22 2c 20 30 29 29 erver-code", 0))
11600 3b 0a 20 20 20 20 20 20 20 20 7a 50 61 73 73 77 ;. zPassw
11610 6f 72 64 20 3d 20 64 62 5f 74 65 78 74 28 30 2c ord = db_text(0,
11620 20 22 53 45 4c 45 43 54 20 70 77 20 46 52 4f 4d "SELECT pw FROM
11630 20 75 73 65 72 20 57 48 45 52 45 20 6c 6f 67 69 user WHERE logi
11640 6e 3d 25 51 22 2c 20 67 2e 7a 4c 6f 67 69 6e 29 n=%Q", g.zLogin)
11650 3b 0a 20 20 20 20 20 20 20 20 66 6f 73 73 69 6c ;. fossil
11660 5f 70 72 69 6e 74 28 22 61 64 6d 69 6e 2d 75 73 _print("admin-us
11670 65 72 3a 20 25 73 20 28 69 6e 69 74 69 61 6c 20 er: %s (initial
11680 70 61 73 73 77 6f 72 64 20 69 73 20 5c 22 25 73 password is \"%s
11690 5c 22 29 5c 6e 22 2c 0a 20 20 20 20 20 20 20 20 \")\n",.
116a0 20 20 20 20 20 20 20 20 20 20 20 20 20 67 2e 7a g.z
116b0 4c 6f 67 69 6e 2c 20 7a 50 61 73 73 77 6f 72 64 Login, zPassword
116c0 29 3b 0a 20 20 20 20 20 20 20 20 63 61 63 68 65 );. cache
116d0 5f 69 6e 69 74 69 61 6c 69 7a 65 28 29 3b 0a 20 _initialize();.
116e0 20 20 20 20 20 20 20 67 2e 7a 4c 6f 67 69 6e 20 g.zLogin
116f0 3d 20 30 3b 0a 20 20 20 20 20 20 20 20 67 2e 75 = 0;. g.u
11700 73 65 72 55 69 64 20 3d 20 30 3b 0a 20 20 20 20 serUid = 0;.
11710 20 20 7d 65 6c 73 65 7b 0a 20 20 20 20 20 20 20 }else{.
11720 20 64 62 5f 6f 70 65 6e 5f 72 65 70 6f 73 69 74 db_open_reposit
11730 6f 72 79 28 7a 52 65 70 6f 29 3b 0a 20 20 20 20 ory(zRepo);.
11740 20 20 7d 0a 20 20 20 20 7d 0a 20 20 7d 0a 7d 0a }. }. }.}.
11750 0a 2f 2a 0a 2a 2a 20 75 6e 64 6f 63 75 6d 65 6e ./*.** undocumen
11760 74 65 64 20 66 6f 72 6d 61 74 3a 0a 2a 2a 0a 2a ted format:.**.*
11770 2a 20 20 20 20 20 20 20 20 66 6f 73 73 69 6c 20 * fossil
11780 68 74 74 70 20 49 4e 46 49 4c 45 20 4f 55 54 46 http INFILE OUTF
11790 49 4c 45 20 49 50 41 44 44 52 20 3f 52 45 50 4f ILE IPADDR ?REPO
117a0 53 49 54 4f 52 59 3f 0a 2a 2a 0a 2a 2a 20 54 68 SITORY?.**.** Th
117b0 65 20 61 72 67 76 3d 3d 36 20 66 6f 72 6d 20 28 e argv==6 form (
117c0 77 69 74 68 20 6e 6f 20 6f 70 74 69 6f 6e 73 29 with no options)
117d0 20 69 73 20 75 73 65 64 20 62 79 20 74 68 65 20 is used by the
117e0 77 69 6e 33 32 20 73 65 72 76 65 72 20 6f 6e 6c win32 server onl
117f0 79 2e 0a 2a 2a 0a 2a 2a 20 43 4f 4d 4d 41 4e 44 y..**.** COMMAND
11800 3a 20 68 74 74 70 2a 0a 2a 2a 0a 2a 2a 20 55 73 : http*.**.** Us
11810 61 67 65 3a 20 25 66 6f 73 73 69 6c 20 68 74 74 age: %fossil htt
11820 70 20 3f 52 45 50 4f 53 49 54 4f 52 59 3f 20 3f p ?REPOSITORY? ?
11830 4f 50 54 49 4f 4e 53 3f 0a 2a 2a 0a 2a 2a 20 48 OPTIONS?.**.** H
11840 61 6e 64 6c 65 20 61 20 73 69 6e 67 6c 65 20 48 andle a single H
11850 54 54 50 20 72 65 71 75 65 73 74 20 61 70 70 65 TTP request appe
11860 61 72 69 6e 67 20 6f 6e 20 73 74 64 69 6e 2e 20 aring on stdin.
11870 20 54 68 65 20 72 65 73 75 6c 74 69 6e 67 20 77 The resulting w
11880 65 62 70 61 67 65 0a 2a 2a 20 69 73 20 64 65 6c ebpage.** is del
11890 69 76 65 72 65 64 20 6f 6e 20 73 74 64 6f 75 74 ivered on stdout
118a0 2e 20 20 54 68 69 73 20 6d 65 74 68 6f 64 20 69 . This method i
118b0 73 20 75 73 65 64 20 74 6f 20 6c 61 75 6e 63 68 s used to launch
118c0 20 61 6e 20 48 54 54 50 20 72 65 71 75 65 73 74 an HTTP request
118d0 0a 2a 2a 20 68 61 6e 64 6c 65 72 20 66 72 6f 6d .** handler from
118e0 20 69 6e 65 74 64 2c 20 66 6f 72 20 65 78 61 6d inetd, for exam
118f0 70 6c 65 2e 20 20 54 68 65 20 61 72 67 75 6d 65 ple. The argume
11900 6e 74 20 69 73 20 74 68 65 20 6e 61 6d 65 20 6f nt is the name o
11910 66 20 74 68 65 0a 2a 2a 20 72 65 70 6f 73 69 74 f the.** reposit
11920 6f 72 79 2e 0a 2a 2a 0a 2a 2a 20 49 66 20 52 45 ory..**.** If RE
11930 50 4f 53 49 54 4f 52 59 20 69 73 20 61 20 64 69 POSITORY is a di
11940 72 65 63 74 6f 72 79 20 74 68 61 74 20 63 6f 6e rectory that con
11950 74 61 69 6e 73 20 6f 6e 65 20 6f 72 20 6d 6f 72 tains one or mor
11960 65 20 72 65 70 6f 73 69 74 6f 72 69 65 73 2c 0a e repositories,.
11970 2a 2a 20 65 69 74 68 65 72 20 64 69 72 65 63 74 ** either direct
11980 6c 79 20 69 6e 20 52 45 50 4f 53 49 54 4f 52 59 ly in REPOSITORY
11990 20 69 74 73 65 6c 66 20 6f 72 20 69 6e 20 73 75 itself or in su
119a0 62 64 69 72 65 63 74 6f 72 69 65 73 2c 20 61 6e bdirectories, an
119b0 64 0a 2a 2a 20 77 69 74 68 20 6e 61 6d 65 73 20 d.** with names
119c0 6f 66 20 74 68 65 20 66 6f 72 6d 20 22 2a 2e 66 of the form "*.f
119d0 6f 73 73 69 6c 22 20 74 68 65 6e 20 61 20 70 72 ossil" then a pr
119e0 65 66 69 78 20 6f 66 20 74 68 65 20 55 52 4c 20 efix of the URL
119f0 70 61 74 68 6e 61 6d 65 0a 2a 2a 20 73 65 6c 65 pathname.** sele
11a00 63 74 73 20 66 72 6f 6d 20 61 6d 6f 6e 67 20 74 cts from among t
11a10 68 65 20 76 61 72 69 6f 75 73 20 72 65 70 6f 73 he various repos
11a20 69 74 6f 72 69 65 73 2e 20 20 49 66 20 74 68 65 itories. If the
11a30 20 70 61 74 68 6e 61 6d 65 20 64 6f 65 73 0a 2a pathname does.*
11a40 2a 20 6e 6f 74 20 73 65 6c 65 63 74 20 61 20 76 * not select a v
11a50 61 6c 69 64 20 72 65 70 6f 73 69 74 6f 72 79 20 alid repository
11a60 61 6e 64 20 74 68 65 20 2d 2d 6e 6f 74 66 6f 75 and the --notfou
11a70 6e 64 20 6f 70 74 69 6f 6e 20 69 73 20 61 76 61 nd option is ava
11a80 69 6c 61 62 6c 65 2c 0a 2a 2a 20 74 68 65 6e 20 ilable,.** then
11a90 74 68 65 20 73 65 72 76 65 72 20 72 65 64 69 72 the server redir
11aa0 65 63 74 73 20 28 48 54 54 50 20 63 6f 64 65 20 ects (HTTP code
11ab0 33 30 32 29 20 74 6f 20 74 68 65 20 55 52 4c 20 302) to the URL
11ac0 6f 66 20 2d 2d 6e 6f 74 66 6f 75 6e 64 2e 0a 2a of --notfound..*
11ad0 2a 20 57 68 65 6e 20 52 45 50 4f 53 49 54 4f 52 * When REPOSITOR
11ae0 59 20 69 73 20 61 20 64 69 72 65 63 74 6f 72 79 Y is a directory
11af0 2c 20 74 68 65 20 70 61 74 68 6e 61 6d 65 20 6d , the pathname m
11b00 75 73 74 20 63 6f 6e 74 61 69 6e 20 6f 6e 6c 79 ust contain only
11b10 0a 2a 2a 20 61 6c 70 68 61 6e 75 6d 65 72 69 63 .** alphanumeric
11b20 73 2c 20 22 5f 22 2c 20 22 2f 22 2c 20 22 2d 22 s, "_", "/", "-"
11b30 20 61 6e 64 20 22 2e 22 20 61 6e 64 20 6e 6f 20 and "." and no
11b40 22 2d 22 20 6d 61 79 20 6f 63 63 75 72 20 61 66 "-" may occur af
11b50 74 65 72 20 61 20 22 2f 22 0a 2a 2a 20 61 6e 64 ter a "/".** and
11b60 20 65 76 65 72 79 20 22 2e 22 20 6d 75 73 74 20 every "." must
11b70 62 65 20 73 75 72 72 6f 75 6e 64 65 64 20 6f 6e be surrounded on
11b80 20 62 6f 74 68 20 73 69 64 65 73 20 62 79 20 61 both sides by a
11b90 6c 70 68 61 6e 75 6d 65 72 69 63 73 20 6f 72 20 lphanumerics or
11ba0 65 6c 73 65 0a 2a 2a 20 61 20 34 30 34 20 65 72 else.** a 404 er
11bb0 72 6f 72 20 69 73 20 72 65 74 75 72 6e 65 64 2e ror is returned.
11bc0 20 20 53 74 61 74 69 63 20 63 6f 6e 74 65 6e 74 Static content
11bd0 20 66 69 6c 65 73 20 69 6e 20 74 68 65 20 64 69 files in the di
11be0 72 65 63 74 6f 72 79 20 61 72 65 0a 2a 2a 20 72 rectory are.** r
11bf0 65 74 75 72 6e 65 64 20 69 66 20 74 68 65 79 20 eturned if they
11c00 6d 61 74 63 68 20 63 6f 6d 6d 61 2d 73 65 70 61 match comma-sepa
11c10 72 61 74 65 20 47 4c 4f 42 20 70 61 74 74 65 72 rate GLOB patter
11c20 6e 20 73 70 65 63 69 66 69 65 64 20 62 79 20 2d n specified by -
11c30 2d 66 69 6c 65 73 0a 2a 2a 20 61 6e 64 20 64 6f -files.** and do
11c40 20 6e 6f 74 20 6d 61 74 63 68 20 22 2a 2e 66 6f not match "*.fo
11c50 73 73 69 6c 2a 22 20 61 6e 64 20 68 61 76 65 20 ssil*" and have
11c60 61 20 77 65 6c 6c 2d 6b 6e 6f 77 6e 20 73 75 66 a well-known suf
11c70 66 69 78 2e 0a 2a 2a 0a 2a 2a 20 54 68 65 20 2d fix..**.** The -
11c80 2d 68 6f 73 74 20 6f 70 74 69 6f 6e 20 63 61 6e -host option can
11c90 20 62 65 20 75 73 65 64 20 74 6f 20 73 70 65 63 be used to spec
11ca0 69 66 79 20 74 68 65 20 68 6f 73 74 6e 61 6d 65 ify the hostname
11cb0 20 66 6f 72 20 74 68 65 20 73 65 72 76 65 72 2e for the server.
11cc0 0a 2a 2a 20 54 68 65 20 2d 2d 68 74 74 70 73 20 .** The --https
11cd0 6f 70 74 69 6f 6e 20 69 6e 64 69 63 61 74 65 73 option indicates
11ce0 20 74 68 61 74 20 74 68 65 20 72 65 71 75 65 73 that the reques
11cf0 74 20 63 61 6d 65 20 66 72 6f 6d 20 48 54 54 50 t came from HTTP
11d00 53 20 72 61 74 68 65 72 0a 2a 2a 20 74 68 61 6e S rather.** than
11d10 20 48 54 54 50 2e 20 49 66 20 2d 2d 6e 6f 73 73 HTTP. If --noss
11d20 6c 20 69 73 20 67 69 76 65 6e 2c 20 74 68 65 6e l is given, then
11d30 20 53 53 4c 20 63 6f 6e 6e 65 63 74 69 6f 6e 73 SSL connections
11d40 20 77 69 6c 6c 20 6e 6f 74 20 62 65 20 61 76 61 will not be ava
11d50 69 6c 61 62 6c 65 2c 0a 2a 2a 20 74 68 75 73 20 ilable,.** thus
11d60 61 6c 73 6f 20 6e 6f 20 72 65 64 69 72 65 63 74 also no redirect
11d70 69 6e 67 20 66 72 6f 6d 20 68 74 74 70 3a 20 74 ing from http: t
11d80 6f 20 68 74 74 70 73 3a 20 77 69 6c 6c 20 74 61 o https: will ta
11d90 6b 65 20 70 6c 61 63 65 2e 0a 2a 2a 0a 2a 2a 20 ke place..**.**
11da0 49 66 20 74 68 65 20 2d 2d 6c 6f 63 61 6c 61 75 If the --localau
11db0 74 68 20 6f 70 74 69 6f 6e 20 69 73 20 67 69 76 th option is giv
11dc0 65 6e 2c 20 74 68 65 6e 20 61 75 74 6f 6d 61 74 en, then automat
11dd0 69 63 20 6c 6f 67 69 6e 20 69 73 20 70 65 72 66 ic login is perf
11de0 6f 72 6d 65 64 0a 2a 2a 20 66 6f 72 20 72 65 71 ormed.** for req
11df0 75 65 73 74 73 20 63 6f 6d 69 6e 67 20 66 72 6f uests coming fro
11e00 6d 20 6c 6f 63 61 6c 68 6f 73 74 2c 20 69 66 20 m localhost, if
11e10 74 68 65 20 22 6c 6f 63 61 6c 61 75 74 68 22 20 the "localauth"
11e20 73 65 74 74 69 6e 67 20 69 73 20 6e 6f 74 0a 2a setting is not.*
11e30 2a 20 65 6e 61 62 6c 65 64 2e 0a 2a 2a 0a 2a 2a * enabled..**.**
11e40 20 4f 70 74 69 6f 6e 73 3a 0a 2a 2a 20 20 20 2d Options:.** -
11e50 2d 62 61 73 65 75 72 6c 20 55 52 4c 20 20 20 20 -baseurl URL
11e60 62 61 73 65 20 55 52 4c 20 28 75 73 65 66 75 6c base URL (useful
11e70 20 77 69 74 68 20 72 65 76 65 72 73 65 20 70 72 with reverse pr
11e80 6f 78 69 65 73 29 0a 2a 2a 20 20 20 2d 2d 66 69 oxies).** --fi
11e90 6c 65 73 20 47 4c 4f 42 20 20 20 20 20 63 6f 6d les GLOB com
11ea0 6d 61 2d 73 65 70 61 72 61 74 65 20 67 6c 6f 62 ma-separate glob
11eb0 20 70 61 74 74 65 72 6e 73 20 66 6f 72 20 73 74 patterns for st
11ec0 61 74 69 63 20 66 69 6c 65 20 74 6f 20 73 65 72 atic file to ser
11ed0 76 65 0a 2a 2a 20 20 20 2d 2d 6c 6f 63 61 6c 61 ve.** --locala
11ee0 75 74 68 20 20 20 20 20 20 65 6e 61 62 6c 65 20 uth enable
11ef0 61 75 74 6f 6d 61 74 69 63 20 6c 6f 67 69 6e 20 automatic login
11f00 66 6f 72 20 6c 6f 63 61 6c 20 63 6f 6e 6e 65 63 for local connec
11f10 74 69 6f 6e 73 0a 2a 2a 20 20 20 2d 2d 68 6f 73 tions.** --hos
11f20 74 20 4e 41 4d 45 20 20 20 20 20 20 73 70 65 63 t NAME spec
11f30 69 66 79 20 68 6f 73 74 6e 61 6d 65 20 6f 66 20 ify hostname of
11f40 74 68 65 20 73 65 72 76 65 72 0a 2a 2a 20 20 20 the server.**
11f50 2d 2d 68 74 74 70 73 20 20 20 20 20 20 20 20 20 --https
11f60 20 73 69 67 6e 61 6c 20 61 20 72 65 71 75 65 73 signal a reques
11f70 74 20 63 6f 6d 69 6e 67 20 69 6e 20 76 69 61 20 t coming in via
11f80 68 74 74 70 73 0a 2a 2a 20 20 20 2d 2d 6e 6f 6a https.** --noj
11f90 61 69 6c 20 20 20 20 20 20 20 20 20 64 72 6f 70 ail drop
11fa0 20 72 6f 6f 74 20 70 72 69 76 69 6c 65 67 65 20 root privilege
11fb0 62 75 74 20 64 6f 20 6e 6f 74 20 65 6e 74 65 72 but do not enter
11fc0 20 74 68 65 20 63 68 72 6f 6f 74 20 6a 61 69 6c the chroot jail
11fd0 0a 2a 2a 20 20 20 2d 2d 6e 6f 73 73 6c 20 20 20 .** --nossl
11fe0 20 20 20 20 20 20 20 73 69 67 6e 61 6c 20 74 68 signal th
11ff0 61 74 20 6e 6f 20 53 53 4c 20 63 6f 6e 6e 65 63 at no SSL connec
12000 74 69 6f 6e 73 20 61 72 65 20 61 76 61 69 6c 61 tions are availa
12010 62 6c 65 0a 2a 2a 20 20 20 2d 2d 6e 6f 74 66 6f ble.** --notfo
12020 75 6e 64 20 55 52 4c 20 20 20 75 73 65 20 55 52 und URL use UR
12030 4c 20 61 73 20 22 48 54 54 50 20 34 30 34 2c 20 L as "HTTP 404,
12040 6f 62 6a 65 63 74 20 6e 6f 74 20 66 6f 75 6e 64 object not found
12050 22 20 70 61 67 65 2e 0a 2a 2a 20 20 20 2d 2d 72 " page..** --r
12060 65 70 6f 6c 69 73 74 20 20 20 20 20 20 20 49 66 epolist If
12070 20 52 45 50 4f 53 49 54 4f 52 59 20 69 73 20 64 REPOSITORY is d
12080 69 72 65 63 74 6f 72 79 2c 20 55 52 4c 20 22 2f irectory, URL "/
12090 22 20 6c 69 73 74 73 20 61 6c 6c 20 72 65 70 6f " lists all repo
120a0 73 0a 2a 2a 20 20 20 2d 2d 73 63 67 69 20 20 20 s.** --scgi
120b0 20 20 20 20 20 20 20 20 49 6e 74 65 72 70 72 65 Interpre
120c0 74 20 69 6e 70 75 74 20 61 73 20 53 43 47 49 20 t input as SCGI
120d0 72 61 74 68 65 72 20 74 68 61 6e 20 48 54 54 50 rather than HTTP
120e0 0a 2a 2a 20 20 20 2d 2d 73 6b 69 6e 20 4c 41 42 .** --skin LAB
120f0 45 4c 20 20 20 20 20 55 73 65 20 6f 76 65 72 72 EL Use overr
12100 69 64 65 20 73 6b 69 6e 20 4c 41 42 45 4c 0a 2a ide skin LABEL.*
12110 2a 0a 2a 2a 20 53 65 65 20 61 6c 73 6f 3a 20 63 *.** See also: c
12120 67 69 2c 20 73 65 72 76 65 72 2c 20 77 69 6e 73 gi, server, wins
12130 72 76 0a 2a 2f 0a 76 6f 69 64 20 63 6d 64 5f 68 rv.*/.void cmd_h
12140 74 74 70 28 76 6f 69 64 29 7b 0a 20 20 63 6f 6e ttp(void){. con
12150 73 74 20 63 68 61 72 20 2a 7a 49 70 41 64 64 72 st char *zIpAddr
12160 20 3d 20 30 3b 0a 20 20 63 6f 6e 73 74 20 63 68 = 0;. const ch
12170 61 72 20 2a 7a 4e 6f 74 46 6f 75 6e 64 3b 0a 20 ar *zNotFound;.
12180 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a 48 6f const char *zHo
12190 73 74 3b 0a 20 20 63 6f 6e 73 74 20 63 68 61 72 st;. const char
121a0 20 2a 7a 41 6c 74 42 61 73 65 3b 0a 20 20 63 6f *zAltBase;. co
121b0 6e 73 74 20 63 68 61 72 20 2a 7a 46 69 6c 65 47 nst char *zFileG
121c0 6c 6f 62 3b 0a 20 20 69 6e 74 20 75 73 65 53 43 lob;. int useSC
121d0 47 49 3b 0a 20 20 69 6e 74 20 6e 6f 4a 61 69 6c GI;. int noJail
121e0 3b 0a 20 20 69 6e 74 20 61 6c 6c 6f 77 52 65 70 ;. int allowRep
121f0 6f 4c 69 73 74 3b 0a 0a 20 20 2f 2a 20 54 68 65 oList;.. /* The
12200 20 77 69 6e 68 74 74 70 20 6d 6f 64 75 6c 65 20 winhttp module
12210 70 61 73 73 65 73 20 74 68 65 20 2d 2d 66 69 6c passes the --fil
12220 65 73 20 6f 70 74 69 6f 6e 20 61 73 20 2d 2d 66 es option as --f
12230 69 6c 65 73 2d 75 72 6c 65 6e 63 20 77 69 74 68 iles-urlenc with
12240 0a 20 20 2a 2a 20 74 68 65 20 61 72 67 75 6d 65 . ** the argume
12250 6e 74 20 62 65 69 6e 67 20 55 52 4c 20 65 6e 63 nt being URL enc
12260 6f 64 65 64 2c 20 74 6f 20 61 76 6f 69 64 20 77 oded, to avoid w
12270 69 6c 64 63 61 72 64 20 65 78 70 61 6e 73 69 6f ildcard expansio
12280 6e 20 69 6e 20 74 68 65 0a 20 20 2a 2a 20 73 68 n in the. ** sh
12290 65 6c 6c 2e 20 20 54 68 69 73 20 6f 70 74 69 6f ell. This optio
122a0 6e 20 69 73 20 66 6f 72 20 69 6e 74 65 72 6e 61 n is for interna
122b0 6c 20 75 73 65 20 61 6e 64 20 69 73 20 75 6e 64 l use and is und
122c0 6f 63 75 6d 65 6e 74 65 64 2e 0a 20 20 2a 2f 0a ocumented.. */.
122d0 20 20 7a 46 69 6c 65 47 6c 6f 62 20 3d 20 66 69 zFileGlob = fi
122e0 6e 64 5f 6f 70 74 69 6f 6e 28 22 66 69 6c 65 73 nd_option("files
122f0 2d 75 72 6c 65 6e 63 22 2c 30 2c 31 29 3b 0a 20 -urlenc",0,1);.
12300 20 69 66 28 20 7a 46 69 6c 65 47 6c 6f 62 20 29 if( zFileGlob )
12310 7b 0a 20 20 20 20 63 68 61 72 20 2a 7a 20 3d 20 {. char *z =
12320 6d 70 72 69 6e 74 66 28 22 25 73 22 2c 20 7a 46 mprintf("%s", zF
12330 69 6c 65 47 6c 6f 62 29 3b 0a 20 20 20 20 64 65 ileGlob);. de
12340 68 74 74 70 69 7a 65 28 7a 29 3b 0a 20 20 20 20 httpize(z);.
12350 7a 46 69 6c 65 47 6c 6f 62 20 3d 20 7a 3b 0a 20 zFileGlob = z;.
12360 20 7d 65 6c 73 65 7b 0a 20 20 20 20 7a 46 69 6c }else{. zFil
12370 65 47 6c 6f 62 20 3d 20 66 69 6e 64 5f 6f 70 74 eGlob = find_opt
12380 69 6f 6e 28 22 66 69 6c 65 73 22 2c 30 2c 31 29 ion("files",0,1)
12390 3b 0a 20 20 7d 0a 20 20 73 6b 69 6e 5f 6f 76 65 ;. }. skin_ove
123a0 72 72 69 64 65 28 29 3b 0a 20 20 7a 4e 6f 74 46 rride();. zNotF
123b0 6f 75 6e 64 20 3d 20 66 69 6e 64 5f 6f 70 74 69 ound = find_opti
123c0 6f 6e 28 22 6e 6f 74 66 6f 75 6e 64 22 2c 20 30 on("notfound", 0
123d0 2c 20 31 29 3b 0a 20 20 6e 6f 4a 61 69 6c 20 3d , 1);. noJail =
123e0 20 66 69 6e 64 5f 6f 70 74 69 6f 6e 28 22 6e 6f find_option("no
123f0 6a 61 69 6c 22 2c 30 2c 30 29 21 3d 30 3b 0a 20 jail",0,0)!=0;.
12400 20 61 6c 6c 6f 77 52 65 70 6f 4c 69 73 74 20 3d allowRepoList =
12410 20 66 69 6e 64 5f 6f 70 74 69 6f 6e 28 22 72 65 find_option("re
12420 70 6f 6c 69 73 74 22 2c 30 2c 30 29 21 3d 30 3b polist",0,0)!=0;
12430 0a 20 20 67 2e 75 73 65 4c 6f 63 61 6c 61 75 74 . g.useLocalaut
12440 68 20 3d 20 66 69 6e 64 5f 6f 70 74 69 6f 6e 28 h = find_option(
12450 22 6c 6f 63 61 6c 61 75 74 68 22 2c 20 30 2c 20 "localauth", 0,
12460 30 29 21 3d 30 3b 0a 20 20 67 2e 73 73 6c 4e 6f 0)!=0;. g.sslNo
12470 74 41 76 61 69 6c 61 62 6c 65 20 3d 20 66 69 6e tAvailable = fin
12480 64 5f 6f 70 74 69 6f 6e 28 22 6e 6f 73 73 6c 22 d_option("nossl"
12490 2c 20 30 2c 20 30 29 21 3d 30 3b 0a 20 20 75 73 , 0, 0)!=0;. us
124a0 65 53 43 47 49 20 3d 20 66 69 6e 64 5f 6f 70 74 eSCGI = find_opt
124b0 69 6f 6e 28 22 73 63 67 69 22 2c 20 30 2c 20 30 ion("scgi", 0, 0
124c0 29 21 3d 30 3b 0a 20 20 7a 41 6c 74 42 61 73 65 )!=0;. zAltBase
124d0 20 3d 20 66 69 6e 64 5f 6f 70 74 69 6f 6e 28 22 = find_option("
124e0 62 61 73 65 75 72 6c 22 2c 20 30 2c 20 31 29 3b baseurl", 0, 1);
124f0 0a 20 20 69 66 28 20 7a 41 6c 74 42 61 73 65 20 . if( zAltBase
12500 29 20 73 65 74 5f 62 61 73 65 5f 75 72 6c 28 7a ) set_base_url(z
12510 41 6c 74 42 61 73 65 29 3b 0a 20 20 69 66 28 20 AltBase);. if(
12520 66 69 6e 64 5f 6f 70 74 69 6f 6e 28 22 68 74 74 find_option("htt
12530 70 73 22 2c 30 2c 30 29 21 3d 30 20 29 7b 0a 20 ps",0,0)!=0 ){.
12540 20 20 20 7a 49 70 41 64 64 72 20 3d 20 66 6f 73 zIpAddr = fos
12550 73 69 6c 5f 67 65 74 65 6e 76 28 22 52 45 4d 4f sil_getenv("REMO
12560 54 45 5f 48 4f 53 54 22 29 3b 20 2f 2a 20 46 72 TE_HOST"); /* Fr
12570 6f 6d 20 73 74 75 6e 6e 65 6c 20 2a 2f 0a 20 20 om stunnel */.
12580 20 20 63 67 69 5f 72 65 70 6c 61 63 65 5f 70 61 cgi_replace_pa
12590 72 61 6d 65 74 65 72 28 22 48 54 54 50 53 22 2c rameter("HTTPS",
125a0 22 6f 6e 22 29 3b 0a 20 20 7d 0a 20 20 7a 48 6f "on");. }. zHo
125b0 73 74 20 3d 20 66 69 6e 64 5f 6f 70 74 69 6f 6e st = find_option
125c0 28 22 68 6f 73 74 22 2c 20 30 2c 20 31 29 3b 0a ("host", 0, 1);.
125d0 20 20 69 66 28 20 7a 48 6f 73 74 20 29 20 63 67 if( zHost ) cg
125e0 69 5f 72 65 70 6c 61 63 65 5f 70 61 72 61 6d 65 i_replace_parame
125f0 74 65 72 28 22 48 54 54 50 5f 48 4f 53 54 22 2c ter("HTTP_HOST",
12600 7a 48 6f 73 74 29 3b 0a 0a 20 20 2f 2a 20 57 65 zHost);.. /* We
12610 20 73 68 6f 75 6c 64 20 62 65 20 64 6f 6e 65 20 should be done
12620 77 69 74 68 20 6f 70 74 69 6f 6e 73 2e 2e 20 2a with options.. *
12630 2f 0a 20 20 76 65 72 69 66 79 5f 61 6c 6c 5f 6f /. verify_all_o
12640 70 74 69 6f 6e 73 28 29 3b 0a 0a 20 20 69 66 28 ptions();.. if(
12650 20 67 2e 61 72 67 63 21 3d 32 20 26 26 20 67 2e g.argc!=2 && g.
12660 61 72 67 63 21 3d 33 20 26 26 20 67 2e 61 72 67 argc!=3 && g.arg
12670 63 21 3d 35 20 26 26 20 67 2e 61 72 67 63 21 3d c!=5 && g.argc!=
12680 36 20 29 7b 0a 20 20 20 20 66 6f 73 73 69 6c 5f 6 ){. fossil_
12690 66 61 74 61 6c 28 22 6e 6f 20 72 65 70 6f 73 69 fatal("no reposi
126a0 74 6f 72 79 20 73 70 65 63 69 66 69 65 64 22 29 tory specified")
126b0 3b 0a 20 20 7d 0a 20 20 67 2e 63 67 69 4f 75 74 ;. }. g.cgiOut
126c0 70 75 74 20 3d 20 31 3b 0a 20 20 67 2e 66 75 6c put = 1;. g.ful
126d0 6c 48 74 74 70 52 65 70 6c 79 20 3d 20 31 3b 0a lHttpReply = 1;.
126e0 20 20 69 66 28 20 67 2e 61 72 67 63 3e 3d 35 20 if( g.argc>=5
126f0 29 7b 0a 20 20 20 20 67 2e 68 74 74 70 49 6e 20 ){. g.httpIn
12700 3d 20 66 6f 73 73 69 6c 5f 66 6f 70 65 6e 28 67 = fossil_fopen(g
12710 2e 61 72 67 76 5b 32 5d 2c 20 22 72 62 22 29 3b .argv[2], "rb");
12720 0a 20 20 20 20 67 2e 68 74 74 70 4f 75 74 20 3d . g.httpOut =
12730 20 66 6f 73 73 69 6c 5f 66 6f 70 65 6e 28 67 2e fossil_fopen(g.
12740 61 72 67 76 5b 33 5d 2c 20 22 77 62 22 29 3b 0a argv[3], "wb");.
12750 20 20 20 20 7a 49 70 41 64 64 72 20 3d 20 67 2e zIpAddr = g.
12760 61 72 67 76 5b 34 5d 3b 0a 20 20 20 20 66 69 6e argv[4];. fin
12770 64 5f 73 65 72 76 65 72 5f 72 65 70 6f 73 69 74 d_server_reposit
12780 6f 72 79 28 35 2c 20 30 29 3b 0a 20 20 7d 65 6c ory(5, 0);. }el
12790 73 65 7b 0a 20 20 20 20 67 2e 68 74 74 70 49 6e se{. g.httpIn
127a0 20 3d 20 73 74 64 69 6e 3b 0a 20 20 20 20 67 2e = stdin;. g.
127b0 68 74 74 70 4f 75 74 20 3d 20 73 74 64 6f 75 74 httpOut = stdout
127c0 3b 0a 20 20 20 20 66 69 6e 64 5f 73 65 72 76 65 ;. find_serve
127d0 72 5f 72 65 70 6f 73 69 74 6f 72 79 28 32 2c 20 r_repository(2,
127e0 30 29 3b 0a 20 20 7d 0a 20 20 69 66 28 20 7a 49 0);. }. if( zI
127f0 70 41 64 64 72 3d 3d 30 20 29 7b 0a 20 20 20 20 pAddr==0 ){.
12800 7a 49 70 41 64 64 72 20 3d 20 63 67 69 5f 73 73 zIpAddr = cgi_ss
12810 68 5f 72 65 6d 6f 74 65 5f 61 64 64 72 28 30 29 h_remote_addr(0)
12820 3b 0a 20 20 20 20 69 66 28 20 7a 49 70 41 64 64 ;. if( zIpAdd
12830 72 20 26 26 20 7a 49 70 41 64 64 72 5b 30 5d 20 r && zIpAddr[0]
12840 29 7b 0a 20 20 20 20 20 20 67 2e 66 53 73 68 43 ){. g.fSshC
12850 6c 69 65 6e 74 20 7c 3d 20 43 47 49 5f 53 53 48 lient |= CGI_SSH
12860 5f 43 4c 49 45 4e 54 3b 0a 20 20 20 20 7d 0a 20 _CLIENT;. }.
12870 20 7d 0a 20 20 67 2e 7a 52 65 70 6f 73 69 74 6f }. g.zReposito
12880 72 79 4e 61 6d 65 20 3d 20 65 6e 74 65 72 5f 63 ryName = enter_c
12890 68 72 6f 6f 74 5f 6a 61 69 6c 28 67 2e 7a 52 65 hroot_jail(g.zRe
128a0 70 6f 73 69 74 6f 72 79 4e 61 6d 65 2c 20 6e 6f positoryName, no
128b0 4a 61 69 6c 29 3b 0a 20 20 69 66 28 20 75 73 65 Jail);. if( use
128c0 53 43 47 49 20 29 7b 0a 20 20 20 20 63 67 69 5f SCGI ){. cgi_
128d0 68 61 6e 64 6c 65 5f 73 63 67 69 5f 72 65 71 75 handle_scgi_requ
128e0 65 73 74 28 29 3b 0a 20 20 7d 65 6c 73 65 20 69 est();. }else i
128f0 66 28 20 67 2e 66 53 73 68 43 6c 69 65 6e 74 20 f( g.fSshClient
12900 26 20 43 47 49 5f 53 53 48 5f 43 4c 49 45 4e 54 & CGI_SSH_CLIENT
12910 20 29 7b 0a 20 20 20 20 73 73 68 5f 72 65 71 75 ){. ssh_requ
12920 65 73 74 5f 6c 6f 6f 70 28 7a 49 70 41 64 64 72 est_loop(zIpAddr
12930 2c 20 67 6c 6f 62 5f 63 72 65 61 74 65 28 7a 46 , glob_create(zF
12940 69 6c 65 47 6c 6f 62 29 29 3b 0a 20 20 7d 65 6c ileGlob));. }el
12950 73 65 7b 0a 20 20 20 20 63 67 69 5f 68 61 6e 64 se{. cgi_hand
12960 6c 65 5f 68 74 74 70 5f 72 65 71 75 65 73 74 28 le_http_request(
12970 7a 49 70 41 64 64 72 29 3b 0a 20 20 7d 0a 20 20 zIpAddr);. }.
12980 70 72 6f 63 65 73 73 5f 6f 6e 65 5f 77 65 62 5f process_one_web_
12990 70 61 67 65 28 7a 4e 6f 74 46 6f 75 6e 64 2c 20 page(zNotFound,
129a0 67 6c 6f 62 5f 63 72 65 61 74 65 28 7a 46 69 6c glob_create(zFil
129b0 65 47 6c 6f 62 29 2c 20 61 6c 6c 6f 77 52 65 70 eGlob), allowRep
129c0 6f 4c 69 73 74 29 3b 0a 7d 0a 0a 2f 2a 0a 2a 2a oList);.}../*.**
129d0 20 50 72 6f 63 65 73 73 20 61 6c 6c 20 72 65 71 Process all req
129e0 75 65 73 74 73 20 69 6e 20 61 20 73 69 6e 67 6c uests in a singl
129f0 65 20 53 53 48 20 63 6f 6e 6e 65 63 74 69 6f 6e e SSH connection
12a00 20 69 66 20 70 6f 73 73 69 62 6c 65 2e 0a 2a 2f if possible..*/
12a10 0a 76 6f 69 64 20 73 73 68 5f 72 65 71 75 65 73 .void ssh_reques
12a20 74 5f 6c 6f 6f 70 28 63 6f 6e 73 74 20 63 68 61 t_loop(const cha
12a30 72 20 2a 7a 49 70 41 64 64 72 2c 20 47 6c 6f 62 r *zIpAddr, Glob
12a40 20 2a 46 69 6c 65 47 6c 6f 62 29 7b 0a 20 20 62 *FileGlob){. b
12a50 6c 6f 62 5f 7a 65 72 6f 28 26 67 2e 63 67 69 49 lob_zero(&g.cgiI
12a60 6e 29 3b 0a 20 20 64 6f 7b 0a 20 20 20 20 63 67 n);. do{. cg
12a70 69 5f 68 61 6e 64 6c 65 5f 73 73 68 5f 68 74 74 i_handle_ssh_htt
12a80 70 5f 72 65 71 75 65 73 74 28 7a 49 70 41 64 64 p_request(zIpAdd
12a90 72 29 3b 0a 20 20 20 20 70 72 6f 63 65 73 73 5f r);. process_
12aa0 6f 6e 65 5f 77 65 62 5f 70 61 67 65 28 30 2c 20 one_web_page(0,
12ab0 46 69 6c 65 47 6c 6f 62 2c 20 30 29 3b 0a 20 20 FileGlob, 0);.
12ac0 20 20 62 6c 6f 62 5f 72 65 73 65 74 28 26 67 2e blob_reset(&g.
12ad0 63 67 69 49 6e 29 3b 0a 20 20 7d 20 77 68 69 6c cgiIn);. } whil
12ae0 65 20 28 20 67 2e 66 53 73 68 43 6c 69 65 6e 74 e ( g.fSshClient
12af0 20 26 20 43 47 49 5f 53 53 48 5f 46 4f 53 53 49 & CGI_SSH_FOSSI
12b00 4c 20 7c 7c 0a 20 20 20 20 20 20 20 20 20 20 67 L ||. g
12b10 2e 66 53 73 68 43 6c 69 65 6e 74 20 26 20 43 47 .fSshClient & CG
12b20 49 5f 53 53 48 5f 43 4f 4d 50 41 54 20 29 3b 0a I_SSH_COMPAT );.
12b30 7d 0a 0a 2f 2a 0a 2a 2a 20 4e 6f 74 65 20 74 68 }../*.** Note th
12b40 61 74 20 74 68 65 20 66 6f 6c 6c 6f 77 69 6e 67 at the following
12b50 20 63 6f 6d 6d 61 6e 64 20 69 73 20 75 73 65 64 command is used
12b60 20 62 79 20 73 73 68 3a 2f 2f 20 70 72 6f 63 65 by ssh:// proce
12b70 73 73 69 6e 67 2e 0a 2a 2a 0a 2a 2a 20 43 4f 4d ssing..**.** COM
12b80 4d 41 4e 44 3a 20 74 65 73 74 2d 68 74 74 70 0a MAND: test-http.
12b90 2a 2a 0a 2a 2a 20 57 6f 72 6b 73 20 6c 69 6b 65 **.** Works like
12ba0 20 74 68 65 20 68 74 74 70 20 63 6f 6d 6d 61 6e the http comman
12bb0 64 20 62 75 74 20 67 69 76 65 73 20 73 65 74 75 d but gives setu
12bc0 70 20 70 65 72 6d 69 73 73 69 6f 6e 20 74 6f 20 p permission to
12bd0 61 6c 6c 20 75 73 65 72 73 2e 0a 2a 2a 0a 2a 2a all users..**.**
12be0 20 4f 70 74 69 6f 6e 73 3a 0a 2a 2a 20 20 20 2d Options:.** -
12bf0 2d 74 68 2d 74 72 61 63 65 20 20 20 20 20 20 20 -th-trace
12c00 20 20 20 74 72 61 63 65 20 54 48 31 20 65 78 65 trace TH1 exe
12c10 63 75 74 69 6f 6e 20 28 66 6f 72 20 64 65 62 75 cution (for debu
12c20 67 67 69 6e 67 20 70 75 72 70 6f 73 65 73 29 0a gging purposes).
12c30 2a 2a 0a 2a 2f 0a 76 6f 69 64 20 63 6d 64 5f 74 **.*/.void cmd_t
12c40 65 73 74 5f 68 74 74 70 28 76 6f 69 64 29 7b 0a est_http(void){.
12c50 20 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a 49 const char *zI
12c60 70 41 64 64 72 3b 20 20 20 20 2f 2a 20 49 50 20 pAddr; /* IP
12c70 61 64 64 72 65 73 73 20 6f 66 20 72 65 6d 6f 74 address of remot
12c80 65 20 63 6c 69 65 6e 74 20 2a 2f 0a 0a 20 20 54 e client */.. T
12c90 68 5f 49 6e 69 74 54 72 61 63 65 4c 6f 67 28 29 h_InitTraceLog()
12ca0 3b 0a 20 20 6c 6f 67 69 6e 5f 73 65 74 5f 63 61 ;. login_set_ca
12cb0 70 61 62 69 6c 69 74 69 65 73 28 22 73 78 22 2c pabilities("sx",
12cc0 20 30 29 3b 0a 20 20 67 2e 75 73 65 4c 6f 63 61 0);. g.useLoca
12cd0 6c 61 75 74 68 20 3d 20 31 3b 0a 20 20 67 2e 68 lauth = 1;. g.h
12ce0 74 74 70 49 6e 20 3d 20 73 74 64 69 6e 3b 0a 20 ttpIn = stdin;.
12cf0 20 67 2e 68 74 74 70 4f 75 74 20 3d 20 73 74 64 g.httpOut = std
12d00 6f 75 74 3b 0a 20 20 66 69 6e 64 5f 73 65 72 76 out;. find_serv
12d10 65 72 5f 72 65 70 6f 73 69 74 6f 72 79 28 32 2c er_repository(2,
12d20 20 30 29 3b 0a 20 20 67 2e 63 67 69 4f 75 74 70 0);. g.cgiOutp
12d30 75 74 20 3d 20 31 3b 0a 20 20 67 2e 66 75 6c 6c ut = 1;. g.full
12d40 48 74 74 70 52 65 70 6c 79 20 3d 20 31 3b 0a 20 HttpReply = 1;.
12d50 20 7a 49 70 41 64 64 72 20 3d 20 63 67 69 5f 73 zIpAddr = cgi_s
12d60 73 68 5f 72 65 6d 6f 74 65 5f 61 64 64 72 28 30 sh_remote_addr(0
12d70 29 3b 0a 20 20 69 66 28 20 7a 49 70 41 64 64 72 );. if( zIpAddr
12d80 20 26 26 20 7a 49 70 41 64 64 72 5b 30 5d 20 29 && zIpAddr[0] )
12d90 7b 0a 20 20 20 20 67 2e 66 53 73 68 43 6c 69 65 {. g.fSshClie
12da0 6e 74 20 7c 3d 20 43 47 49 5f 53 53 48 5f 43 4c nt |= CGI_SSH_CL
12db0 49 45 4e 54 3b 0a 20 20 20 20 73 73 68 5f 72 65 IENT;. ssh_re
12dc0 71 75 65 73 74 5f 6c 6f 6f 70 28 7a 49 70 41 64 quest_loop(zIpAd
12dd0 64 72 2c 20 30 29 3b 0a 20 20 7d 65 6c 73 65 7b dr, 0);. }else{
12de0 0a 20 20 20 20 63 67 69 5f 73 65 74 5f 70 61 72 . cgi_set_par
12df0 61 6d 65 74 65 72 28 22 52 45 4d 4f 54 45 5f 41 ameter("REMOTE_A
12e00 44 44 52 22 2c 20 22 31 32 37 2e 30 2e 30 2e 31 DDR", "127.0.0.1
12e10 22 29 3b 0a 20 20 20 20 63 67 69 5f 68 61 6e 64 ");. cgi_hand
12e20 6c 65 5f 68 74 74 70 5f 72 65 71 75 65 73 74 28 le_http_request(
12e30 30 29 3b 0a 20 20 20 20 70 72 6f 63 65 73 73 5f 0);. process_
12e40 6f 6e 65 5f 77 65 62 5f 70 61 67 65 28 30 2c 20 one_web_page(0,
12e50 30 2c 20 30 29 3b 0a 20 20 7d 0a 7d 0a 0a 23 69 0, 0);. }.}..#i
12e60 66 20 21 64 65 66 69 6e 65 64 28 5f 57 49 4e 33 f !defined(_WIN3
12e70 32 29 0a 23 69 66 20 21 64 65 66 69 6e 65 64 28 2).#if !defined(
12e80 5f 5f 44 41 52 57 49 4e 5f 5f 29 20 26 26 20 21 __DARWIN__) && !
12e90 64 65 66 69 6e 65 64 28 5f 5f 41 50 50 4c 45 5f defined(__APPLE_
12ea0 5f 29 20 26 26 20 21 64 65 66 69 6e 65 64 28 5f _) && !defined(_
12eb0 5f 48 41 49 4b 55 5f 5f 29 0a 2f 2a 0a 2a 2a 20 _HAIKU__)./*.**
12ec0 53 65 61 72 63 68 20 66 6f 72 20 61 6e 20 65 78 Search for an ex
12ed0 65 63 75 74 61 62 6c 65 20 6f 6e 20 74 68 65 20 ecutable on the
12ee0 50 41 54 48 20 65 6e 76 69 72 6f 6e 6d 65 6e 74 PATH environment
12ef0 20 76 61 72 69 61 62 6c 65 2e 0a 2a 2a 20 52 65 variable..** Re
12f00 74 75 72 6e 20 74 72 75 65 20 28 31 29 20 69 66 turn true (1) if
12f10 20 66 6f 75 6e 64 20 61 6e 64 20 66 61 6c 73 65 found and false
12f20 20 28 30 29 20 69 66 20 6e 6f 74 20 66 6f 75 6e (0) if not foun
12f30 64 2e 0a 2a 2f 0a 73 74 61 74 69 63 20 69 6e 74 d..*/.static int
12f40 20 62 69 6e 61 72 79 4f 6e 50 61 74 68 28 63 6f binaryOnPath(co
12f50 6e 73 74 20 63 68 61 72 20 2a 7a 42 69 6e 61 72 nst char *zBinar
12f60 79 29 7b 0a 20 20 63 6f 6e 73 74 20 63 68 61 72 y){. const char
12f70 20 2a 7a 50 61 74 68 20 3d 20 66 6f 73 73 69 6c *zPath = fossil
12f80 5f 67 65 74 65 6e 76 28 22 50 41 54 48 22 29 3b _getenv("PATH");
12f90 0a 20 20 63 68 61 72 20 2a 7a 46 75 6c 6c 3b 0a . char *zFull;.
12fa0 20 20 69 6e 74 20 69 3b 0a 20 20 69 6e 74 20 62 int i;. int b
12fb0 45 78 69 73 74 73 3b 0a 20 20 77 68 69 6c 65 28 Exists;. while(
12fc0 20 7a 50 61 74 68 20 26 26 20 7a 50 61 74 68 5b zPath && zPath[
12fd0 30 5d 20 29 7b 0a 20 20 20 20 77 68 69 6c 65 28 0] ){. while(
12fe0 20 7a 50 61 74 68 5b 30 5d 3d 3d 27 3a 27 20 29 zPath[0]==':' )
12ff0 20 7a 50 61 74 68 2b 2b 3b 0a 20 20 20 20 66 6f zPath++;. fo
13000 72 28 69 3d 30 3b 20 7a 50 61 74 68 5b 69 5d 20 r(i=0; zPath[i]
13010 26 26 20 7a 50 61 74 68 5b 69 5d 21 3d 27 3a 27 && zPath[i]!=':'
13020 3b 20 69 2b 2b 29 7b 7d 0a 20 20 20 20 7a 46 75 ; i++){}. zFu
13030 6c 6c 20 3d 20 6d 70 72 69 6e 74 66 28 22 25 2e ll = mprintf("%.
13040 2a 73 2f 25 73 22 2c 20 69 2c 20 7a 50 61 74 68 *s/%s", i, zPath
13050 2c 20 7a 42 69 6e 61 72 79 29 3b 0a 20 20 20 20 , zBinary);.
13060 62 45 78 69 73 74 73 20 3d 20 66 69 6c 65 5f 61 bExists = file_a
13070 63 63 65 73 73 28 7a 46 75 6c 6c 2c 20 58 5f 4f ccess(zFull, X_O
13080 4b 29 3b 0a 20 20 20 20 66 6f 73 73 69 6c 5f 66 K);. fossil_f
13090 72 65 65 28 7a 46 75 6c 6c 29 3b 0a 20 20 20 20 ree(zFull);.
130a0 69 66 28 20 62 45 78 69 73 74 73 3d 3d 30 20 29 if( bExists==0 )
130b0 20 72 65 74 75 72 6e 20 31 3b 0a 20 20 20 20 7a return 1;. z
130c0 50 61 74 68 20 2b 3d 20 69 3b 0a 20 20 7d 0a 20 Path += i;. }.
130d0 20 72 65 74 75 72 6e 20 30 3b 0a 7d 0a 23 65 6e return 0;.}.#en
130e0 64 69 66 0a 23 65 6e 64 69 66 0a 0a 2f 2a 0a 2a dif.#endif../*.*
130f0 2a 20 43 4f 4d 4d 41 4e 44 3a 20 73 65 72 76 65 * COMMAND: serve
13100 72 2a 0a 2a 2a 20 43 4f 4d 4d 41 4e 44 3a 20 75 r*.** COMMAND: u
13110 69 0a 2a 2a 0a 2a 2a 20 55 73 61 67 65 3a 20 25 i.**.** Usage: %
13120 66 6f 73 73 69 6c 20 73 65 72 76 65 72 20 3f 4f fossil server ?O
13130 50 54 49 4f 4e 53 3f 20 3f 52 45 50 4f 53 49 54 PTIONS? ?REPOSIT
13140 4f 52 59 3f 0a 2a 2a 20 20 20 20 4f 72 3a 20 25 ORY?.** Or: %
13150 66 6f 73 73 69 6c 20 75 69 20 3f 4f 50 54 49 4f fossil ui ?OPTIO
13160 4e 53 3f 20 3f 52 45 50 4f 53 49 54 4f 52 59 3f NS? ?REPOSITORY?
13170 0a 2a 2a 0a 2a 2a 20 4f 70 65 6e 20 61 20 73 6f .**.** Open a so
13180 63 6b 65 74 20 61 6e 64 20 62 65 67 69 6e 20 6c cket and begin l
13190 69 73 74 65 6e 69 6e 67 20 61 6e 64 20 72 65 73 istening and res
131a0 70 6f 6e 64 69 6e 67 20 74 6f 20 48 54 54 50 20 ponding to HTTP
131b0 72 65 71 75 65 73 74 73 20 6f 6e 0a 2a 2a 20 54 requests on.** T
131c0 43 50 20 70 6f 72 74 20 38 30 38 30 2c 20 6f 72 CP port 8080, or
131d0 20 6f 6e 20 61 6e 79 20 6f 74 68 65 72 20 54 43 on any other TC
131e0 50 20 70 6f 72 74 20 64 65 66 69 6e 65 64 20 62 P port defined b
131f0 79 20 74 68 65 20 2d 50 20 6f 72 0a 2a 2a 20 2d y the -P or.** -
13200 2d 70 6f 72 74 20 6f 70 74 69 6f 6e 2e 20 20 54 -port option. T
13210 68 65 20 6f 70 74 69 6f 6e 61 6c 20 61 72 67 75 he optional argu
13220 6d 65 6e 74 20 69 73 20 74 68 65 20 6e 61 6d 65 ment is the name
13230 20 6f 66 20 74 68 65 20 72 65 70 6f 73 69 74 6f of the reposito
13240 72 79 2e 0a 2a 2a 20 54 68 65 20 72 65 70 6f 73 ry..** The repos
13250 69 74 6f 72 79 20 61 72 67 75 6d 65 6e 74 20 6d itory argument m
13260 61 79 20 62 65 20 6f 6d 69 74 74 65 64 20 69 66 ay be omitted if
13270 20 74 68 65 20 77 6f 72 6b 69 6e 67 20 64 69 72 the working dir
13280 65 63 74 6f 72 79 20 69 73 0a 2a 2a 20 77 69 74 ectory is.** wit
13290 68 69 6e 20 61 6e 20 6f 70 65 6e 20 63 68 65 63 hin an open chec
132a0 6b 6f 75 74 2e 0a 2a 2a 0a 2a 2a 20 54 68 65 20 kout..**.** The
132b0 22 75 69 22 20 63 6f 6d 6d 61 6e 64 20 61 75 74 "ui" command aut
132c0 6f 6d 61 74 69 63 61 6c 6c 79 20 73 74 61 72 74 omatically start
132d0 73 20 61 20 77 65 62 20 62 72 6f 77 73 65 72 20 s a web browser
132e0 61 66 74 65 72 20 69 6e 69 74 69 61 6c 69 7a 69 after initializi
132f0 6e 67 0a 2a 2a 20 74 68 65 20 77 65 62 20 73 65 ng.** the web se
13300 72 76 65 72 2e 20 20 54 68 65 20 22 75 69 22 20 rver. The "ui"
13310 63 6f 6d 6d 61 6e 64 20 61 6c 73 6f 20 62 69 6e command also bin
13320 64 73 20 74 6f 20 31 32 37 2e 30 2e 30 2e 31 20 ds to 127.0.0.1
13330 61 6e 64 20 73 6f 20 77 69 6c 6c 0a 2a 2a 20 6f and so will.** o
13340 6e 6c 79 20 70 72 6f 63 65 73 73 20 48 54 54 50 nly process HTTP
13350 20 74 72 61 66 66 69 63 20 66 72 6f 6d 20 74 68 traffic from th
13360 65 20 6c 6f 63 61 6c 20 6d 61 63 68 69 6e 65 2e e local machine.
13370 0a 2a 2a 0a 2a 2a 20 54 68 65 20 52 45 50 4f 53 .**.** The REPOS
13380 49 54 4f 52 59 20 63 61 6e 20 62 65 20 61 20 64 ITORY can be a d
13390 69 72 65 63 74 6f 72 79 20 28 61 6b 61 20 66 6f irectory (aka fo
133a0 6c 64 65 72 29 20 74 68 61 74 20 63 6f 6e 74 61 lder) that conta
133b0 69 6e 73 20 6f 6e 65 20 6f 72 0a 2a 2a 20 6d 6f ins one or.** mo
133c0 72 65 20 72 65 70 6f 73 69 74 6f 72 69 65 73 20 re repositories
133d0 77 69 74 68 20 6e 61 6d 65 73 20 65 6e 64 69 6e with names endin
133e0 67 20 69 6e 20 22 2e 66 6f 73 73 69 6c 22 2e 20 g in ".fossil".
133f0 20 49 6e 20 74 68 69 73 20 63 61 73 65 2c 20 61 In this case, a
13400 0a 2a 2a 20 70 72 65 66 69 78 20 6f 66 20 74 68 .** prefix of th
13410 65 20 55 52 4c 20 70 61 74 68 6e 61 6d 65 20 69 e URL pathname i
13420 73 20 75 73 65 64 20 74 6f 20 73 65 61 72 63 68 s used to search
13430 20 74 68 65 20 64 69 72 65 63 74 6f 72 79 20 66 the directory f
13440 6f 72 20 61 6e 0a 2a 2a 20 61 70 70 72 6f 70 72 or an.** appropr
13450 69 61 74 65 20 72 65 70 6f 73 69 74 6f 72 79 2e iate repository.
13460 20 20 54 6f 20 74 68 77 61 72 74 20 6d 69 73 63 To thwart misc
13470 68 69 65 66 2c 20 74 68 65 20 70 61 74 68 6e 61 hief, the pathna
13480 6d 65 20 69 6e 20 74 68 65 20 55 52 4c 20 6d 75 me in the URL mu
13490 73 74 0a 2a 2a 20 63 6f 6e 74 61 69 6e 20 6f 6e st.** contain on
134a0 6c 79 20 61 6c 70 68 61 6e 75 6d 65 72 69 63 73 ly alphanumerics
134b0 2c 20 22 5f 22 2c 20 22 2f 22 2c 20 22 2d 22 2c , "_", "/", "-",
134c0 20 61 6e 64 20 22 2e 22 2c 20 61 6e 64 20 6e 6f and ".", and no
134d0 20 22 2d 22 20 6d 61 79 0a 2a 2a 20 6f 63 63 75 "-" may.** occu
134e0 72 20 61 66 74 65 72 20 22 2f 22 2c 20 61 6e 64 r after "/", and
134f0 20 65 76 65 72 79 20 22 2e 22 20 6d 75 73 74 20 every "." must
13500 62 65 20 73 75 72 72 6f 75 6e 64 65 64 20 6f 6e be surrounded on
13510 20 62 6f 74 68 20 73 69 64 65 73 20 62 79 0a 2a both sides by.*
13520 2a 20 61 6c 70 68 61 6e 75 6d 65 72 69 63 73 2e * alphanumerics.
13530 20 20 41 6e 79 20 70 61 74 68 6e 61 6d 65 20 74 Any pathname t
13540 68 61 74 20 64 6f 65 73 20 6e 6f 74 20 73 61 74 hat does not sat
13550 69 73 66 79 20 74 68 65 73 65 20 63 6f 6e 73 74 isfy these const
13560 72 61 69 6e 74 73 0a 2a 2a 20 72 65 73 75 6c 74 raints.** result
13570 73 20 69 6e 20 61 20 34 30 34 20 65 72 72 6f 72 s in a 404 error
13580 2e 20 20 46 69 6c 65 73 20 69 6e 20 52 45 50 4f . Files in REPO
13590 53 49 54 4f 52 59 20 74 68 61 74 20 6d 61 74 63 SITORY that matc
135a0 68 20 74 68 65 20 63 6f 6d 6d 61 2d 73 65 70 61 h the comma-sepa
135b0 72 61 74 65 64 0a 2a 2a 20 6c 69 73 74 20 6f 66 rated.** list of
135c0 20 67 6c 6f 62 20 70 61 74 74 65 72 6e 73 20 67 glob patterns g
135d0 69 76 65 6e 20 62 79 20 2d 2d 66 69 6c 65 73 20 iven by --files
135e0 61 6e 64 20 74 68 61 74 20 68 61 76 65 20 6b 6e and that have kn
135f0 6f 77 6e 20 73 75 66 66 69 78 65 73 0a 2a 2a 20 own suffixes.**
13600 73 75 63 68 20 61 73 20 22 2e 74 78 74 22 20 6f such as ".txt" o
13610 72 20 22 2e 68 74 6d 6c 22 20 6f 72 20 22 2e 6a r ".html" or ".j
13620 70 65 67 22 20 61 6e 64 20 64 6f 20 6e 6f 74 20 peg" and do not
13630 6d 61 74 63 68 20 74 68 65 20 70 61 74 74 65 72 match the patter
13640 6e 0a 2a 2a 20 22 2a 2e 66 6f 73 73 69 6c 2a 22 n.** "*.fossil*"
13650 20 77 69 6c 6c 20 62 65 20 73 65 72 76 65 64 20 will be served
13660 61 73 20 73 74 61 74 69 63 20 63 6f 6e 74 65 6e as static conten
13670 74 2e 20 20 57 69 74 68 20 74 68 65 20 22 75 69 t. With the "ui
13680 22 20 63 6f 6d 6d 61 6e 64 2c 0a 2a 2a 20 74 68 " command,.** th
13690 65 20 52 45 50 4f 53 49 54 4f 52 59 20 63 61 6e e REPOSITORY can
136a0 20 6f 6e 6c 79 20 62 65 20 61 20 64 69 72 65 63 only be a direc
136b0 74 6f 72 79 20 69 66 20 74 68 65 20 2d 2d 6e 6f tory if the --no
136c0 74 66 6f 75 6e 64 20 6f 70 74 69 6f 6e 20 69 73 tfound option is
136d0 0a 2a 2a 20 61 6c 73 6f 20 70 72 65 73 65 6e 74 .** also present
136e0 2e 0a 2a 2a 0a 2a 2a 20 42 79 20 64 65 66 61 75 ..**.** By defau
136f0 6c 74 2c 20 74 68 65 20 22 75 69 22 20 63 6f 6d lt, the "ui" com
13700 6d 61 6e 64 20 70 72 6f 76 69 64 65 73 20 66 75 mand provides fu
13710 6c 6c 20 61 64 6d 69 6e 69 73 74 72 61 74 69 76 ll administrativ
13720 65 20 61 63 63 65 73 73 20 77 69 74 68 6f 75 74 e access without
13730 0a 2a 2a 20 68 61 76 69 6e 67 20 74 6f 20 6c 6f .** having to lo
13740 67 20 69 6e 2e 20 20 54 68 69 73 20 63 61 6e 20 g in. This can
13750 62 65 20 64 69 73 61 62 6c 65 64 20 62 79 20 74 be disabled by t
13760 75 72 6e 69 6e 67 20 6f 66 66 20 74 68 65 20 22 urning off the "
13770 6c 6f 63 61 6c 61 75 74 68 22 0a 2a 2a 20 73 65 localauth".** se
13780 74 74 69 6e 67 2e 20 20 41 75 74 6f 6d 61 74 69 tting. Automati
13790 63 20 6c 6f 67 69 6e 20 66 6f 72 20 74 68 65 20 c login for the
137a0 22 73 65 72 76 65 72 22 20 63 6f 6d 6d 61 6e 64 "server" command
137b0 20 69 73 20 61 76 61 69 6c 61 62 6c 65 20 69 66 is available if
137c0 20 74 68 65 0a 2a 2a 20 2d 2d 6c 6f 63 61 6c 61 the.** --locala
137d0 75 74 68 20 6f 70 74 69 6f 6e 20 69 73 20 70 72 uth option is pr
137e0 65 73 65 6e 74 20 61 6e 64 20 74 68 65 20 22 6c esent and the "l
137f0 6f 63 61 6c 61 75 74 68 22 20 73 65 74 74 69 6e ocalauth" settin
13800 67 20 69 73 20 6f 66 66 20 61 6e 64 20 74 68 65 g is off and the
13810 0a 2a 2a 20 63 6f 6e 6e 65 63 74 69 6f 6e 20 69 .** connection i
13820 73 20 66 72 6f 6d 20 6c 6f 63 61 6c 68 6f 73 74 s from localhost
13830 2e 20 20 54 68 65 20 22 75 69 22 20 63 6f 6d 6d . The "ui" comm
13840 61 6e 64 20 61 6c 73 6f 20 65 6e 61 62 6c 65 73 and also enables
13850 20 2d 2d 72 65 70 6f 6c 69 73 74 0a 2a 2a 20 62 --repolist.** b
13860 79 20 64 65 66 61 75 6c 74 2e 0a 2a 2a 0a 2a 2a y default..**.**
13870 20 4f 70 74 69 6f 6e 73 3a 0a 2a 2a 20 20 20 2d Options:.** -
13880 2d 62 61 73 65 75 72 6c 20 55 52 4c 20 20 20 20 -baseurl URL
13890 20 20 20 55 73 65 20 55 52 4c 20 61 73 20 74 68 Use URL as th
138a0 65 20 62 61 73 65 20 28 75 73 65 66 75 6c 20 66 e base (useful f
138b0 6f 72 20 72 65 76 65 72 73 65 20 70 72 6f 78 69 or reverse proxi
138c0 65 73 29 0a 2a 2a 20 20 20 2d 2d 63 72 65 61 74 es).** --creat
138d0 65 20 20 20 20 20 20 20 20 20 20 20 20 43 72 65 e Cre
138e0 61 74 65 20 61 20 6e 65 77 20 52 45 50 4f 53 49 ate a new REPOSI
138f0 54 4f 52 59 20 69 66 20 69 74 20 64 6f 65 73 20 TORY if it does
13900 6e 6f 74 20 61 6c 72 65 61 64 79 20 65 78 69 73 not already exis
13910 74 0a 2a 2a 20 20 20 2d 2d 70 61 67 65 20 50 41 t.** --page PA
13920 47 45 20 20 20 20 20 20 20 20 20 53 74 61 72 74 GE Start
13930 20 22 75 69 22 20 6f 6e 20 50 41 47 45 2e 20 20 "ui" on PAGE.
13940 65 78 3a 20 2d 2d 70 61 67 65 20 22 74 69 6d 65 ex: --page "time
13950 6c 69 6e 65 3f 79 3d 63 69 22 0a 2a 2a 20 20 20 line?y=ci".**
13960 2d 2d 66 69 6c 65 73 20 47 4c 4f 42 4c 49 53 54 --files GLOBLIST
13970 20 20 20 20 43 6f 6d 6d 61 2d 73 65 70 61 72 61 Comma-separa
13980 74 65 64 20 6c 69 73 74 20 6f 66 20 67 6c 6f 62 ted list of glob
13990 20 70 61 74 74 65 72 6e 73 20 66 6f 72 20 73 74 patterns for st
139a0 61 74 69 63 20 66 69 6c 65 73 0a 2a 2a 20 20 20 atic files.**
139b0 2d 2d 6c 6f 63 61 6c 61 75 74 68 20 20 20 20 20 --localauth
139c0 20 20 20 20 65 6e 61 62 6c 65 20 61 75 74 6f 6d enable autom
139d0 61 74 69 63 20 6c 6f 67 69 6e 20 66 6f 72 20 72 atic login for r
139e0 65 71 75 65 73 74 73 20 66 72 6f 6d 20 6c 6f 63 equests from loc
139f0 61 6c 68 6f 73 74 0a 2a 2a 20 20 20 2d 2d 6c 6f alhost.** --lo
13a00 63 61 6c 68 6f 73 74 20 20 20 20 20 20 20 20 20 calhost
13a10 6c 69 73 74 65 6e 20 6f 6e 20 31 32 37 2e 30 2e listen on 127.0.
13a20 30 2e 31 20 6f 6e 6c 79 20 28 61 6c 77 61 79 73 0.1 only (always
13a30 20 74 72 75 65 20 66 6f 72 20 22 75 69 22 29 0a true for "ui").
13a40 2a 2a 20 20 20 2d 2d 68 74 74 70 73 20 20 20 20 ** --https
13a50 20 20 20 20 20 20 20 20 20 73 69 67 6e 61 6c 20 signal
13a60 61 20 72 65 71 75 65 73 74 20 63 6f 6d 69 6e 67 a request coming
13a70 20 69 6e 20 76 69 61 20 68 74 74 70 73 0a 2a 2a in via https.**
13a80 20 20 20 2d 2d 6e 6f 6a 61 69 6c 20 20 20 20 20 --nojail
13a90 20 20 20 20 20 20 20 44 72 6f 70 20 72 6f 6f 74 Drop root
13aa0 20 70 72 69 76 69 6c 65 67 65 73 20 62 75 74 20 privileges but
13ab0 64 6f 20 6e 6f 74 20 65 6e 74 65 72 20 74 68 65 do not enter the
13ac0 20 63 68 72 6f 6f 74 20 6a 61 69 6c 0a 2a 2a 20 chroot jail.**
13ad0 20 20 2d 2d 6e 6f 73 73 6c 20 20 20 20 20 20 20 --nossl
13ae0 20 20 20 20 20 20 73 69 67 6e 61 6c 20 74 68 61 signal tha
13af0 74 20 6e 6f 20 53 53 4c 20 63 6f 6e 6e 65 63 74 t no SSL connect
13b00 69 6f 6e 73 20 61 72 65 20 61 76 61 69 6c 61 62 ions are availab
13b10 6c 65 0a 2a 2a 20 20 20 2d 2d 6e 6f 74 66 6f 75 le.** --notfou
13b20 6e 64 20 55 52 4c 20 20 20 20 20 20 52 65 64 69 nd URL Redi
13b30 72 65 63 74 0a 2a 2a 20 20 20 2d 50 7c 2d 2d 70 rect.** -P|--p
13b40 6f 72 74 20 54 43 50 50 4f 52 54 20 20 20 6c 69 ort TCPPORT li
13b50 73 74 65 6e 20 74 6f 20 72 65 71 75 65 73 74 20 sten to request
13b60 6f 6e 20 70 6f 72 74 20 54 43 50 50 4f 52 54 0a on port TCPPORT.
13b70 2a 2a 20 20 20 2d 2d 74 68 2d 74 72 61 63 65 20 ** --th-trace
13b80 20 20 20 20 20 20 20 20 20 74 72 61 63 65 20 54 trace T
13b90 48 31 20 65 78 65 63 75 74 69 6f 6e 20 28 66 6f H1 execution (fo
13ba0 72 20 64 65 62 75 67 67 69 6e 67 20 70 75 72 70 r debugging purp
13bb0 6f 73 65 73 29 0a 2a 2a 20 20 20 2d 2d 72 65 70 oses).** --rep
13bc0 6f 6c 69 73 74 20 20 20 20 20 20 20 20 20 20 49 olist I
13bd0 66 20 52 45 50 4f 53 49 54 4f 52 59 20 69 73 20 f REPOSITORY is
13be0 64 69 72 2c 20 55 52 4c 20 22 2f 22 20 6c 69 73 dir, URL "/" lis
13bf0 74 73 20 72 65 70 6f 73 2e 0a 2a 2a 20 20 20 2d ts repos..** -
13c00 2d 73 63 67 69 20 20 20 20 20 20 20 20 20 20 20 -scgi
13c10 20 20 20 41 63 63 65 70 74 20 53 43 47 49 20 72 Accept SCGI r
13c20 61 74 68 65 72 20 74 68 61 6e 20 48 54 54 50 0a ather than HTTP.
13c30 2a 2a 20 20 20 2d 2d 73 6b 69 6e 20 4c 41 42 45 ** --skin LABE
13c40 4c 20 20 20 20 20 20 20 20 55 73 65 20 6f 76 65 L Use ove
13c50 72 72 69 64 65 20 73 6b 69 6e 20 4c 41 42 45 4c rride skin LABEL
13c60 0a 0a 2a 2a 0a 2a 2a 20 53 65 65 20 61 6c 73 6f ..**.** See also
13c70 3a 20 63 67 69 2c 20 68 74 74 70 2c 20 77 69 6e : cgi, http, win
13c80 73 72 76 0a 2a 2f 0a 76 6f 69 64 20 63 6d 64 5f srv.*/.void cmd_
13c90 77 65 62 73 65 72 76 65 72 28 76 6f 69 64 29 7b webserver(void){
13ca0 0a 20 20 69 6e 74 20 69 50 6f 72 74 2c 20 6d 78 . int iPort, mx
13cb0 50 6f 72 74 3b 20 20 20 20 20 20 20 20 2f 2a 20 Port; /*
13cc0 52 61 6e 67 65 20 6f 66 20 54 43 50 20 70 6f 72 Range of TCP por
13cd0 74 73 20 61 6c 6c 6f 77 65 64 20 2a 2f 0a 20 20 ts allowed */.
13ce0 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a 50 6f 72 const char *zPor
13cf0 74 3b 20 20 20 20 20 20 20 20 2f 2a 20 56 61 6c t; /* Val
13d00 75 65 20 6f 66 20 74 68 65 20 2d 2d 70 6f 72 74 ue of the --port
13d10 20 6f 70 74 69 6f 6e 20 2a 2f 0a 20 20 63 6f 6e option */. con
13d20 73 74 20 63 68 61 72 20 2a 7a 42 72 6f 77 73 65 st char *zBrowse
13d30 72 3b 20 20 20 20 20 2f 2a 20 4e 61 6d 65 20 6f r; /* Name o
13d40 66 20 77 65 62 20 62 72 6f 77 73 65 72 20 70 72 f web browser pr
13d50 6f 67 72 61 6d 20 2a 2f 0a 20 20 63 68 61 72 20 ogram */. char
13d60 2a 7a 42 72 6f 77 73 65 72 43 6d 64 20 3d 20 30 *zBrowserCmd = 0
13d70 3b 20 20 20 20 2f 2a 20 43 6f 6d 6d 61 6e 64 20 ; /* Command
13d80 74 6f 20 6c 61 75 6e 63 68 20 74 68 65 20 77 65 to launch the we
13d90 62 20 62 72 6f 77 73 65 72 20 2a 2f 0a 20 20 69 b browser */. i
13da0 6e 74 20 69 73 55 69 43 6d 64 3b 20 20 20 20 20 nt isUiCmd;
13db0 20 20 20 20 20 20 20 20 20 2f 2a 20 54 72 75 65 /* True
13dc0 20 69 66 20 63 6f 6d 6d 61 6e 64 20 69 73 20 22 if command is "
13dd0 75 69 22 2c 20 6e 6f 74 20 22 73 65 72 76 65 72 ui", not "server
13de0 27 20 2a 2f 0a 20 20 63 6f 6e 73 74 20 63 68 61 ' */. const cha
13df0 72 20 2a 7a 4e 6f 74 46 6f 75 6e 64 3b 20 20 20 r *zNotFound;
13e00 20 2f 2a 20 54 68 65 20 2d 2d 6e 6f 74 66 6f 75 /* The --notfou
13e10 6e 64 20 6f 70 74 69 6f 6e 20 6f 72 20 4e 55 4c nd option or NUL
13e20 4c 20 2a 2f 0a 20 20 69 6e 74 20 66 6c 61 67 73 L */. int flags
13e30 20 3d 20 30 3b 20 20 20 20 20 20 20 20 20 20 20 = 0;
13e40 20 2f 2a 20 53 65 72 76 65 72 20 66 6c 61 67 73 /* Server flags
13e50 20 2a 2f 0a 23 69 66 20 21 64 65 66 69 6e 65 64 */.#if !defined
13e60 28 5f 57 49 4e 33 32 29 0a 20 20 69 6e 74 20 6e (_WIN32). int n
13e70 6f 4a 61 69 6c 3b 20 20 20 20 20 20 20 20 20 20 oJail;
13e80 20 20 20 20 20 2f 2a 20 44 6f 20 6e 6f 74 20 65 /* Do not e
13e90 6e 74 65 72 20 74 68 65 20 63 68 72 6f 6f 74 20 nter the chroot
13ea0 6a 61 69 6c 20 2a 2f 0a 23 65 6e 64 69 66 0a 20 jail */.#endif.
13eb0 20 69 6e 74 20 61 6c 6c 6f 77 52 65 70 6f 4c 69 int allowRepoLi
13ec0 73 74 3b 20 20 20 20 20 20 20 20 20 2f 2a 20 4c st; /* L
13ed0 69 73 74 20 72 65 70 6f 73 69 74 6f 72 69 65 73 ist repositories
13ee0 20 6f 6e 20 55 52 4c 20 22 2f 22 20 2a 2f 0a 20 on URL "/" */.
13ef0 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a 41 6c const char *zAl
13f00 74 42 61 73 65 3b 20 20 20 20 20 20 2f 2a 20 41 tBase; /* A
13f10 72 67 75 6d 65 6e 74 20 74 6f 20 74 68 65 20 2d rgument to the -
13f20 2d 62 61 73 65 75 72 6c 20 6f 70 74 69 6f 6e 20 -baseurl option
13f30 2a 2f 0a 20 20 63 6f 6e 73 74 20 63 68 61 72 20 */. const char
13f40 2a 7a 46 69 6c 65 47 6c 6f 62 3b 20 20 20 20 20 *zFileGlob;
13f50 2f 2a 20 53 74 61 74 69 63 20 63 6f 6e 74 65 6e /* Static conten
13f60 74 20 6d 75 73 74 20 6d 61 74 63 68 20 74 68 69 t must match thi
13f70 73 20 2a 2f 0a 20 20 63 68 61 72 20 2a 7a 49 70 s */. char *zIp
13f80 41 64 64 72 20 3d 20 30 3b 20 20 20 20 20 20 20 Addr = 0;
13f90 20 20 2f 2a 20 42 69 6e 64 20 74 6f 20 74 68 69 /* Bind to thi
13fa0 73 20 49 50 20 61 64 64 72 65 73 73 20 2a 2f 0a s IP address */.
13fb0 20 20 69 6e 74 20 66 43 72 65 61 74 65 20 3d 20 int fCreate =
13fc0 30 3b 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 0; /*
13fd0 54 68 65 20 2d 2d 63 72 65 61 74 65 20 66 6c 61 The --create fla
13fe0 67 20 2a 2f 0a 20 20 63 6f 6e 73 74 20 63 68 61 g */. const cha
13ff0 72 20 2a 7a 49 6e 69 74 50 61 67 65 20 3d 20 30 r *zInitPage = 0
14000 3b 20 2f 2a 20 53 74 61 72 74 20 6f 6e 20 74 68 ; /* Start on th
14010 69 73 20 70 61 67 65 2e 20 20 2d 2d 70 61 67 65 is page. --page
14020 20 6f 70 74 69 6f 6e 20 2a 2f 0a 0a 23 69 66 20 option */..#if
14030 64 65 66 69 6e 65 64 28 5f 57 49 4e 33 32 29 0a defined(_WIN32).
14040 20 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a 53 const char *zS
14050 74 6f 70 70 65 72 46 69 6c 65 3b 20 20 20 20 2f topperFile; /
14060 2a 20 4e 61 6d 65 20 6f 66 20 66 69 6c 65 20 75 * Name of file u
14070 73 65 64 20 74 6f 20 74 65 72 6d 69 6e 61 74 65 sed to terminate
14080 20 73 65 72 76 65 72 20 2a 2f 0a 20 20 7a 53 74 server */. zSt
14090 6f 70 70 65 72 46 69 6c 65 20 3d 20 66 69 6e 64 opperFile = find
140a0 5f 6f 70 74 69 6f 6e 28 22 73 74 6f 70 70 65 72 _option("stopper
140b0 22 2c 20 30 2c 20 31 29 3b 0a 23 65 6e 64 69 66 ", 0, 1);.#endif
140c0 0a 0a 20 20 7a 46 69 6c 65 47 6c 6f 62 20 3d 20 .. zFileGlob =
140d0 66 69 6e 64 5f 6f 70 74 69 6f 6e 28 22 66 69 6c find_option("fil
140e0 65 73 2d 75 72 6c 65 6e 63 22 2c 30 2c 31 29 3b es-urlenc",0,1);
140f0 0a 20 20 69 66 28 20 7a 46 69 6c 65 47 6c 6f 62 . if( zFileGlob
14100 20 29 7b 0a 20 20 20 20 63 68 61 72 20 2a 7a 20 ){. char *z
14110 3d 20 6d 70 72 69 6e 74 66 28 22 25 73 22 2c 20 = mprintf("%s",
14120 7a 46 69 6c 65 47 6c 6f 62 29 3b 0a 20 20 20 20 zFileGlob);.
14130 64 65 68 74 74 70 69 7a 65 28 7a 29 3b 0a 20 20 dehttpize(z);.
14140 20 20 7a 46 69 6c 65 47 6c 6f 62 20 3d 20 7a 3b zFileGlob = z;
14150 0a 20 20 7d 65 6c 73 65 7b 0a 20 20 20 20 7a 46 . }else{. zF
14160 69 6c 65 47 6c 6f 62 20 3d 20 66 69 6e 64 5f 6f ileGlob = find_o
14170 70 74 69 6f 6e 28 22 66 69 6c 65 73 22 2c 30 2c ption("files",0,
14180 31 29 3b 0a 20 20 7d 0a 20 20 73 6b 69 6e 5f 6f 1);. }. skin_o
14190 76 65 72 72 69 64 65 28 29 3b 0a 23 69 66 20 21 verride();.#if !
141a0 64 65 66 69 6e 65 64 28 5f 57 49 4e 33 32 29 0a defined(_WIN32).
141b0 20 20 6e 6f 4a 61 69 6c 20 3d 20 66 69 6e 64 5f noJail = find_
141c0 6f 70 74 69 6f 6e 28 22 6e 6f 6a 61 69 6c 22 2c option("nojail",
141d0 30 2c 30 29 21 3d 30 3b 0a 23 65 6e 64 69 66 0a 0,0)!=0;.#endif.
141e0 20 20 67 2e 75 73 65 4c 6f 63 61 6c 61 75 74 68 g.useLocalauth
141f0 20 3d 20 66 69 6e 64 5f 6f 70 74 69 6f 6e 28 22 = find_option("
14200 6c 6f 63 61 6c 61 75 74 68 22 2c 20 30 2c 20 30 localauth", 0, 0
14210 29 21 3d 30 3b 0a 20 20 54 68 5f 49 6e 69 74 54 )!=0;. Th_InitT
14220 72 61 63 65 4c 6f 67 28 29 3b 0a 20 20 7a 50 6f raceLog();. zPo
14230 72 74 20 3d 20 66 69 6e 64 5f 6f 70 74 69 6f 6e rt = find_option
14240 28 22 70 6f 72 74 22 2c 20 22 50 22 2c 20 31 29 ("port", "P", 1)
14250 3b 0a 20 20 69 73 55 69 43 6d 64 20 3d 20 67 2e ;. isUiCmd = g.
14260 61 72 67 76 5b 31 5d 5b 30 5d 3d 3d 27 75 27 3b argv[1][0]=='u';
14270 0a 20 20 69 66 28 20 69 73 55 69 43 6d 64 20 29 . if( isUiCmd )
14280 7b 0a 20 20 20 20 7a 49 6e 69 74 50 61 67 65 20 {. zInitPage
14290 3d 20 66 69 6e 64 5f 6f 70 74 69 6f 6e 28 22 70 = find_option("p
142a0 61 67 65 22 2c 20 30 2c 20 31 29 3b 0a 20 20 7d age", 0, 1);. }
142b0 0a 20 20 69 66 28 20 7a 49 6e 69 74 50 61 67 65 . if( zInitPage
142c0 3d 3d 30 20 29 20 7a 49 6e 69 74 50 61 67 65 20 ==0 ) zInitPage
142d0 3d 20 22 22 3b 0a 20 20 7a 4e 6f 74 46 6f 75 6e = "";. zNotFoun
142e0 64 20 3d 20 66 69 6e 64 5f 6f 70 74 69 6f 6e 28 d = find_option(
142f0 22 6e 6f 74 66 6f 75 6e 64 22 2c 20 30 2c 20 31 "notfound", 0, 1
14300 29 3b 0a 20 20 61 6c 6c 6f 77 52 65 70 6f 4c 69 );. allowRepoLi
14310 73 74 20 3d 20 66 69 6e 64 5f 6f 70 74 69 6f 6e st = find_option
14320 28 22 72 65 70 6f 6c 69 73 74 22 2c 30 2c 30 29 ("repolist",0,0)
14330 21 3d 30 3b 0a 20 20 7a 41 6c 74 42 61 73 65 20 !=0;. zAltBase
14340 3d 20 66 69 6e 64 5f 6f 70 74 69 6f 6e 28 22 62 = find_option("b
14350 61 73 65 75 72 6c 22 2c 20 30 2c 20 31 29 3b 0a aseurl", 0, 1);.
14360 20 20 66 43 72 65 61 74 65 20 3d 20 66 69 6e 64 fCreate = find
14370 5f 6f 70 74 69 6f 6e 28 22 63 72 65 61 74 65 22 _option("create"
14380 2c 30 2c 30 29 21 3d 30 3b 0a 20 20 69 66 28 20 ,0,0)!=0;. if(
14390 66 69 6e 64 5f 6f 70 74 69 6f 6e 28 22 73 63 67 find_option("scg
143a0 69 22 2c 20 30 2c 20 30 29 21 3d 30 20 29 20 66 i", 0, 0)!=0 ) f
143b0 6c 61 67 73 20 7c 3d 20 48 54 54 50 5f 53 45 52 lags |= HTTP_SER
143c0 56 45 52 5f 53 43 47 49 3b 0a 20 20 69 66 28 20 VER_SCGI;. if(
143d0 7a 41 6c 74 42 61 73 65 20 29 7b 0a 20 20 20 20 zAltBase ){.
143e0 73 65 74 5f 62 61 73 65 5f 75 72 6c 28 7a 41 6c set_base_url(zAl
143f0 74 42 61 73 65 29 3b 0a 20 20 7d 0a 20 20 67 2e tBase);. }. g.
14400 73 73 6c 4e 6f 74 41 76 61 69 6c 61 62 6c 65 20 sslNotAvailable
14410 3d 20 66 69 6e 64 5f 6f 70 74 69 6f 6e 28 22 6e = find_option("n
14420 6f 73 73 6c 22 2c 20 30 2c 20 30 29 21 3d 30 3b ossl", 0, 0)!=0;
14430 0a 20 20 69 66 28 20 66 69 6e 64 5f 6f 70 74 69 . if( find_opti
14440 6f 6e 28 22 68 74 74 70 73 22 2c 30 2c 30 29 21 on("https",0,0)!
14450 3d 30 20 29 7b 0a 20 20 20 20 63 67 69 5f 72 65 =0 ){. cgi_re
14460 70 6c 61 63 65 5f 70 61 72 61 6d 65 74 65 72 28 place_parameter(
14470 22 48 54 54 50 53 22 2c 22 6f 6e 22 29 3b 0a 20 "HTTPS","on");.
14480 20 7d 65 6c 73 65 7b 0a 20 20 20 20 2f 2a 20 77 }else{. /* w
14490 69 74 68 6f 75 74 20 2d 2d 68 74 74 70 73 2c 20 ithout --https,
144a0 64 65 66 61 75 6c 74 73 20 74 6f 20 6e 6f 74 20 defaults to not
144b0 61 76 61 69 6c 61 62 6c 65 2e 20 2a 2f 0a 20 20 available. */.
144c0 20 20 67 2e 73 73 6c 4e 6f 74 41 76 61 69 6c 61 g.sslNotAvaila
144d0 62 6c 65 20 3d 20 31 3b 0a 20 20 7d 0a 20 20 69 ble = 1;. }. i
144e0 66 28 20 66 69 6e 64 5f 6f 70 74 69 6f 6e 28 22 f( find_option("
144f0 6c 6f 63 61 6c 68 6f 73 74 22 2c 20 30 2c 20 30 localhost", 0, 0
14500 29 21 3d 30 20 29 7b 0a 20 20 20 20 66 6c 61 67 )!=0 ){. flag
14510 73 20 7c 3d 20 48 54 54 50 5f 53 45 52 56 45 52 s |= HTTP_SERVER
14520 5f 4c 4f 43 41 4c 48 4f 53 54 3b 0a 20 20 7d 0a _LOCALHOST;. }.
14530 0a 20 20 2f 2a 20 57 65 20 73 68 6f 75 6c 64 20 . /* We should
14540 62 65 20 64 6f 6e 65 20 77 69 74 68 20 6f 70 74 be done with opt
14550 69 6f 6e 73 2e 2e 20 2a 2f 0a 20 20 76 65 72 69 ions.. */. veri
14560 66 79 5f 61 6c 6c 5f 6f 70 74 69 6f 6e 73 28 29 fy_all_options()
14570 3b 0a 0a 20 20 69 66 28 20 67 2e 61 72 67 63 21 ;.. if( g.argc!
14580 3d 32 20 26 26 20 67 2e 61 72 67 63 21 3d 33 20 =2 && g.argc!=3
14590 29 20 75 73 61 67 65 28 22 3f 52 45 50 4f 53 49 ) usage("?REPOSI
145a0 54 4f 52 59 3f 22 29 3b 0a 20 20 69 66 28 20 69 TORY?");. if( i
145b0 73 55 69 43 6d 64 20 29 7b 0a 20 20 20 20 66 6c sUiCmd ){. fl
145c0 61 67 73 20 7c 3d 20 48 54 54 50 5f 53 45 52 56 ags |= HTTP_SERV
145d0 45 52 5f 4c 4f 43 41 4c 48 4f 53 54 7c 48 54 54 ER_LOCALHOST|HTT
145e0 50 5f 53 45 52 56 45 52 5f 52 45 50 4f 4c 49 53 P_SERVER_REPOLIS
145f0 54 3b 0a 20 20 20 20 67 2e 75 73 65 4c 6f 63 61 T;. g.useLoca
14600 6c 61 75 74 68 20 3d 20 31 3b 0a 20 20 20 20 61 lauth = 1;. a
14610 6c 6c 6f 77 52 65 70 6f 4c 69 73 74 20 3d 20 31 llowRepoList = 1
14620 3b 0a 20 20 7d 0a 20 20 66 69 6e 64 5f 73 65 72 ;. }. find_ser
14630 76 65 72 5f 72 65 70 6f 73 69 74 6f 72 79 28 32 ver_repository(2
14640 2c 20 66 43 72 65 61 74 65 29 3b 0a 20 20 69 66 , fCreate);. if
14650 28 20 7a 50 6f 72 74 20 29 7b 0a 20 20 20 20 69 ( zPort ){. i
14660 6e 74 20 69 3b 0a 20 20 20 20 66 6f 72 28 69 3d nt i;. for(i=
14670 73 74 72 6c 65 6e 28 7a 50 6f 72 74 29 2d 31 3b strlen(zPort)-1;
14680 20 69 3e 3d 30 20 26 26 20 7a 50 6f 72 74 5b 69 i>=0 && zPort[i
14690 5d 21 3d 27 3a 27 3b 20 69 2d 2d 29 7b 7d 0a 20 ]!=':'; i--){}.
146a0 20 20 20 69 66 28 20 69 3e 30 20 29 7b 0a 20 20 if( i>0 ){.
146b0 20 20 20 20 7a 49 70 41 64 64 72 20 3d 20 6d 70 zIpAddr = mp
146c0 72 69 6e 74 66 28 22 25 2e 2a 73 22 2c 20 69 2c rintf("%.*s", i,
146d0 20 7a 50 6f 72 74 29 3b 0a 20 20 20 20 20 20 7a zPort);. z
146e0 50 6f 72 74 20 2b 3d 20 69 2b 31 3b 0a 20 20 20 Port += i+1;.
146f0 20 7d 0a 20 20 20 20 69 50 6f 72 74 20 3d 20 6d }. iPort = m
14700 78 50 6f 72 74 20 3d 20 61 74 6f 69 28 7a 50 6f xPort = atoi(zPo
14710 72 74 29 3b 0a 20 20 7d 65 6c 73 65 7b 0a 20 20 rt);. }else{.
14720 20 20 69 50 6f 72 74 20 3d 20 64 62 5f 67 65 74 iPort = db_get
14730 5f 69 6e 74 28 22 68 74 74 70 2d 70 6f 72 74 22 _int("http-port"
14740 2c 20 38 30 38 30 29 3b 0a 20 20 20 20 6d 78 50 , 8080);. mxP
14750 6f 72 74 20 3d 20 69 50 6f 72 74 2b 31 30 30 3b ort = iPort+100;
14760 0a 20 20 7d 0a 23 69 66 20 21 64 65 66 69 6e 65 . }.#if !define
14770 64 28 5f 57 49 4e 33 32 29 0a 20 20 2f 2a 20 55 d(_WIN32). /* U
14780 6e 69 78 20 69 6d 70 6c 65 6d 65 6e 74 61 74 69 nix implementati
14790 6f 6e 20 2a 2f 0a 20 20 69 66 28 20 69 73 55 69 on */. if( isUi
147a0 43 6d 64 20 29 7b 0a 23 69 66 20 21 64 65 66 69 Cmd ){.#if !defi
147b0 6e 65 64 28 5f 5f 44 41 52 57 49 4e 5f 5f 29 20 ned(__DARWIN__)
147c0 26 26 20 21 64 65 66 69 6e 65 64 28 5f 5f 41 50 && !defined(__AP
147d0 50 4c 45 5f 5f 29 20 26 26 20 21 64 65 66 69 6e PLE__) && !defin
147e0 65 64 28 5f 5f 48 41 49 4b 55 5f 5f 29 0a 20 20 ed(__HAIKU__).
147f0 20 20 7a 42 72 6f 77 73 65 72 20 3d 20 64 62 5f zBrowser = db_
14800 67 65 74 28 22 77 65 62 2d 62 72 6f 77 73 65 72 get("web-browser
14810 22 2c 20 30 29 3b 0a 20 20 20 20 69 66 28 20 7a ", 0);. if( z
14820 42 72 6f 77 73 65 72 3d 3d 30 20 29 7b 0a 20 20 Browser==0 ){.
14830 20 20 20 20 73 74 61 74 69 63 20 63 6f 6e 73 74 static const
14840 20 63 68 61 72 20 2a 63 6f 6e 73 74 20 61 7a 42 char *const azB
14850 72 6f 77 73 65 72 50 72 6f 67 5b 5d 20 3d 0a 20 rowserProg[] =.
14860 20 20 20 20 20 20 20 20 20 7b 20 22 78 64 67 2d { "xdg-
14870 6f 70 65 6e 22 2c 20 22 67 6e 6f 6d 65 2d 6f 70 open", "gnome-op
14880 65 6e 22 2c 20 22 66 69 72 65 66 6f 78 22 2c 20 en", "firefox",
14890 22 67 6f 6f 67 6c 65 2d 63 68 72 6f 6d 65 22 20 "google-chrome"
148a0 7d 3b 0a 20 20 20 20 20 20 69 6e 74 20 69 3b 0a };. int i;.
148b0 20 20 20 20 20 20 7a 42 72 6f 77 73 65 72 20 3d zBrowser =
148c0 20 22 65 63 68 6f 22 3b 0a 20 20 20 20 20 20 66 "echo";. f
148d0 6f 72 28 69 3d 30 3b 20 69 3c 73 69 7a 65 6f 66 or(i=0; i<sizeof
148e0 28 61 7a 42 72 6f 77 73 65 72 50 72 6f 67 29 2f (azBrowserProg)/
148f0 73 69 7a 65 6f 66 28 61 7a 42 72 6f 77 73 65 72 sizeof(azBrowser
14900 50 72 6f 67 5b 30 5d 29 3b 20 69 2b 2b 29 7b 0a Prog[0]); i++){.
14910 20 20 20 20 20 20 20 20 69 66 28 20 62 69 6e 61 if( bina
14920 72 79 4f 6e 50 61 74 68 28 61 7a 42 72 6f 77 73 ryOnPath(azBrows
14930 65 72 50 72 6f 67 5b 69 5d 29 20 29 7b 0a 20 20 erProg[i]) ){.
14940 20 20 20 20 20 20 20 20 7a 42 72 6f 77 73 65 72 zBrowser
14950 20 3d 20 61 7a 42 72 6f 77 73 65 72 50 72 6f 67 = azBrowserProg
14960 5b 69 5d 3b 0a 20 20 20 20 20 20 20 20 20 20 62 [i];. b
14970 72 65 61 6b 3b 0a 20 20 20 20 20 20 20 20 7d 0a reak;. }.
14980 20 20 20 20 20 20 7d 0a 20 20 20 20 7d 0a 23 65 }. }.#e
14990 6c 73 65 0a 20 20 20 20 7a 42 72 6f 77 73 65 72 lse. zBrowser
149a0 20 3d 20 64 62 5f 67 65 74 28 22 77 65 62 2d 62 = db_get("web-b
149b0 72 6f 77 73 65 72 22 2c 20 22 6f 70 65 6e 22 29 rowser", "open")
149c0 3b 0a 23 65 6e 64 69 66 0a 20 20 20 20 69 66 28 ;.#endif. if(
149d0 20 7a 49 70 41 64 64 72 20 29 7b 0a 20 20 20 20 zIpAddr ){.
149e0 20 20 7a 42 72 6f 77 73 65 72 43 6d 64 20 3d 20 zBrowserCmd =
149f0 6d 70 72 69 6e 74 66 28 22 25 73 20 68 74 74 70 mprintf("%s http
14a00 3a 2f 2f 25 73 3a 25 25 64 2f 25 73 20 26 22 2c ://%s:%%d/%s &",
14a10 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 .
14a20 20 20 20 20 20 20 20 20 20 20 20 20 20 7a 42 72 zBr
14a30 6f 77 73 65 72 2c 20 7a 49 70 41 64 64 72 2c 20 owser, zIpAddr,
14a40 7a 49 6e 69 74 50 61 67 65 29 3b 0a 20 20 20 20 zInitPage);.
14a50 7d 65 6c 73 65 7b 0a 20 20 20 20 20 20 7a 42 72 }else{. zBr
14a60 6f 77 73 65 72 43 6d 64 20 3d 20 6d 70 72 69 6e owserCmd = mprin
14a70 74 66 28 22 25 73 20 68 74 74 70 3a 2f 2f 6c 6f tf("%s http://lo
14a80 63 61 6c 68 6f 73 74 3a 25 25 64 2f 25 73 20 26 calhost:%%d/%s &
14a90 22 2c 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 ",.
14aa0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 7a z
14ab0 42 72 6f 77 73 65 72 2c 20 7a 49 6e 69 74 50 61 Browser, zInitPa
14ac0 67 65 29 3b 0a 20 20 20 20 7d 0a 20 20 7d 0a 20 ge);. }. }.
14ad0 20 69 66 28 20 67 2e 72 65 70 6f 73 69 74 6f 72 if( g.repositor
14ae0 79 4f 70 65 6e 20 29 20 66 6c 61 67 73 20 7c 3d yOpen ) flags |=
14af0 20 48 54 54 50 5f 53 45 52 56 45 52 5f 48 41 44 HTTP_SERVER_HAD
14b00 5f 52 45 50 4f 53 49 54 4f 52 59 3b 0a 20 20 69 _REPOSITORY;. i
14b10 66 28 20 67 2e 6c 6f 63 61 6c 4f 70 65 6e 20 29 f( g.localOpen )
14b20 20 66 6c 61 67 73 20 7c 3d 20 48 54 54 50 5f 53 flags |= HTTP_S
14b30 45 52 56 45 52 5f 48 41 44 5f 43 48 45 43 4b 4f ERVER_HAD_CHECKO
14b40 55 54 3b 0a 20 20 64 62 5f 63 6c 6f 73 65 28 31 UT;. db_close(1
14b50 29 3b 0a 20 20 69 66 28 20 63 67 69 5f 68 74 74 );. if( cgi_htt
14b60 70 5f 73 65 72 76 65 72 28 69 50 6f 72 74 2c 20 p_server(iPort,
14b70 6d 78 50 6f 72 74 2c 20 7a 42 72 6f 77 73 65 72 mxPort, zBrowser
14b80 43 6d 64 2c 20 7a 49 70 41 64 64 72 2c 20 66 6c Cmd, zIpAddr, fl
14b90 61 67 73 29 20 29 7b 0a 20 20 20 20 66 6f 73 73 ags) ){. foss
14ba0 69 6c 5f 66 61 74 61 6c 28 22 75 6e 61 62 6c 65 il_fatal("unable
14bb0 20 74 6f 20 6c 69 73 74 65 6e 20 6f 6e 20 54 43 to listen on TC
14bc0 50 20 73 6f 63 6b 65 74 20 25 64 22 2c 20 69 50 P socket %d", iP
14bd0 6f 72 74 29 3b 0a 20 20 7d 0a 20 20 67 2e 68 74 ort);. }. g.ht
14be0 74 70 49 6e 20 3d 20 73 74 64 69 6e 3b 0a 20 20 tpIn = stdin;.
14bf0 67 2e 68 74 74 70 4f 75 74 20 3d 20 73 74 64 6f g.httpOut = stdo
14c00 75 74 3b 0a 20 20 69 66 28 20 67 2e 66 48 74 74 ut;. if( g.fHtt
14c10 70 54 72 61 63 65 20 7c 7c 20 67 2e 66 53 71 6c pTrace || g.fSql
14c20 54 72 61 63 65 20 29 7b 0a 20 20 20 20 66 70 72 Trace ){. fpr
14c30 69 6e 74 66 28 73 74 64 65 72 72 2c 20 22 3d 3d intf(stderr, "==
14c40 3d 3d 3d 3d 20 53 45 52 56 45 52 20 70 69 64 20 ==== SERVER pid
14c50 25 64 20 3d 3d 3d 3d 3d 3d 3d 5c 6e 22 2c 20 67 %d =======\n", g
14c60 65 74 70 69 64 28 29 29 3b 0a 20 20 7d 0a 20 20 etpid());. }.
14c70 67 2e 63 67 69 4f 75 74 70 75 74 20 3d 20 31 3b g.cgiOutput = 1;
14c80 0a 20 20 66 69 6e 64 5f 73 65 72 76 65 72 5f 72 . find_server_r
14c90 65 70 6f 73 69 74 6f 72 79 28 32 2c 20 30 29 3b epository(2, 0);
14ca0 0a 20 20 67 2e 7a 52 65 70 6f 73 69 74 6f 72 79 . g.zRepository
14cb0 4e 61 6d 65 20 3d 20 65 6e 74 65 72 5f 63 68 72 Name = enter_chr
14cc0 6f 6f 74 5f 6a 61 69 6c 28 67 2e 7a 52 65 70 6f oot_jail(g.zRepo
14cd0 73 69 74 6f 72 79 4e 61 6d 65 2c 20 6e 6f 4a 61 sitoryName, noJa
14ce0 69 6c 29 3b 0a 20 20 69 66 28 20 66 6c 61 67 73 il);. if( flags
14cf0 20 26 20 48 54 54 50 5f 53 45 52 56 45 52 5f 53 & HTTP_SERVER_S
14d00 43 47 49 20 29 7b 0a 20 20 20 20 63 67 69 5f 68 CGI ){. cgi_h
14d10 61 6e 64 6c 65 5f 73 63 67 69 5f 72 65 71 75 65 andle_scgi_reque
14d20 73 74 28 29 3b 0a 20 20 7d 65 6c 73 65 7b 0a 20 st();. }else{.
14d30 20 20 20 63 67 69 5f 68 61 6e 64 6c 65 5f 68 74 cgi_handle_ht
14d40 74 70 5f 72 65 71 75 65 73 74 28 30 29 3b 0a 20 tp_request(0);.
14d50 20 7d 0a 20 20 70 72 6f 63 65 73 73 5f 6f 6e 65 }. process_one
14d60 5f 77 65 62 5f 70 61 67 65 28 7a 4e 6f 74 46 6f _web_page(zNotFo
14d70 75 6e 64 2c 20 67 6c 6f 62 5f 63 72 65 61 74 65 und, glob_create
14d80 28 7a 46 69 6c 65 47 6c 6f 62 29 2c 20 61 6c 6c (zFileGlob), all
14d90 6f 77 52 65 70 6f 4c 69 73 74 29 3b 0a 23 65 6c owRepoList);.#el
14da0 73 65 0a 20 20 2f 2a 20 57 69 6e 33 32 20 69 6d se. /* Win32 im
14db0 70 6c 65 6d 65 6e 74 61 74 69 6f 6e 20 2a 2f 0a plementation */.
14dc0 20 20 69 66 28 20 69 73 55 69 43 6d 64 20 29 7b if( isUiCmd ){
14dd0 0a 20 20 20 20 7a 42 72 6f 77 73 65 72 20 3d 20 . zBrowser =
14de0 64 62 5f 67 65 74 28 22 77 65 62 2d 62 72 6f 77 db_get("web-brow
14df0 73 65 72 22 2c 20 22 73 74 61 72 74 22 29 3b 0a ser", "start");.
14e00 20 20 20 20 69 66 28 20 7a 49 70 41 64 64 72 20 if( zIpAddr
14e10 29 7b 0a 20 20 20 20 20 20 7a 42 72 6f 77 73 65 ){. zBrowse
14e20 72 43 6d 64 20 3d 20 6d 70 72 69 6e 74 66 28 22 rCmd = mprintf("
14e30 25 73 20 68 74 74 70 3a 2f 2f 25 73 3a 25 25 64 %s http://%s:%%d
14e40 2f 25 73 20 26 22 2c 0a 20 20 20 20 20 20 20 20 /%s &",.
14e50 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
14e60 20 20 20 20 7a 42 72 6f 77 73 65 72 2c 20 7a 49 zBrowser, zI
14e70 70 41 64 64 72 2c 20 7a 49 6e 69 74 50 61 67 65 pAddr, zInitPage
14e80 29 3b 0a 20 20 20 20 7d 65 6c 73 65 7b 0a 20 20 );. }else{.
14e90 20 20 20 20 7a 42 72 6f 77 73 65 72 43 6d 64 20 zBrowserCmd
14ea0 3d 20 6d 70 72 69 6e 74 66 28 22 25 73 20 68 74 = mprintf("%s ht
14eb0 74 70 3a 2f 2f 6c 6f 63 61 6c 68 6f 73 74 3a 25 tp://localhost:%
14ec0 25 64 2f 25 73 20 26 22 2c 0a 20 20 20 20 20 20 %d/%s &",.
14ed0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
14ee0 20 20 20 20 20 20 7a 42 72 6f 77 73 65 72 2c 20 zBrowser,
14ef0 7a 49 6e 69 74 50 61 67 65 29 3b 0a 20 20 20 20 zInitPage);.
14f00 7d 0a 20 20 7d 0a 20 20 69 66 28 20 67 2e 72 65 }. }. if( g.re
14f10 70 6f 73 69 74 6f 72 79 4f 70 65 6e 20 29 20 66 positoryOpen ) f
14f20 6c 61 67 73 20 7c 3d 20 48 54 54 50 5f 53 45 52 lags |= HTTP_SER
14f30 56 45 52 5f 48 41 44 5f 52 45 50 4f 53 49 54 4f VER_HAD_REPOSITO
14f40 52 59 3b 0a 20 20 69 66 28 20 67 2e 6c 6f 63 61 RY;. if( g.loca
14f50 6c 4f 70 65 6e 20 29 20 66 6c 61 67 73 20 7c 3d lOpen ) flags |=
14f60 20 48 54 54 50 5f 53 45 52 56 45 52 5f 48 41 44 HTTP_SERVER_HAD
14f70 5f 43 48 45 43 4b 4f 55 54 3b 0a 20 20 64 62 5f _CHECKOUT;. db_
14f80 63 6c 6f 73 65 28 31 29 3b 0a 20 20 69 66 28 20 close(1);. if(
14f90 61 6c 6c 6f 77 52 65 70 6f 4c 69 73 74 20 29 7b allowRepoList ){
14fa0 0a 20 20 20 20 66 6c 61 67 73 20 7c 3d 20 48 54 . flags |= HT
14fb0 54 50 5f 53 45 52 56 45 52 5f 52 45 50 4f 4c 49 TP_SERVER_REPOLI
14fc0 53 54 3b 0a 20 20 7d 0a 20 20 69 66 28 20 77 69 ST;. }. if( wi
14fd0 6e 33 32 5f 68 74 74 70 5f 73 65 72 76 69 63 65 n32_http_service
14fe0 28 69 50 6f 72 74 2c 20 7a 4e 6f 74 46 6f 75 6e (iPort, zNotFoun
14ff0 64 2c 20 7a 46 69 6c 65 47 6c 6f 62 2c 20 66 6c d, zFileGlob, fl
15000 61 67 73 29 20 29 7b 0a 20 20 20 20 77 69 6e 33 ags) ){. win3
15010 32 5f 68 74 74 70 5f 73 65 72 76 65 72 28 69 50 2_http_server(iP
15020 6f 72 74 2c 20 6d 78 50 6f 72 74 2c 20 7a 42 72 ort, mxPort, zBr
15030 6f 77 73 65 72 43 6d 64 2c 0a 20 20 20 20 20 20 owserCmd,.
15040 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
15050 7a 53 74 6f 70 70 65 72 46 69 6c 65 2c 20 7a 4e zStopperFile, zN
15060 6f 74 46 6f 75 6e 64 2c 20 7a 46 69 6c 65 47 6c otFound, zFileGl
15070 6f 62 2c 20 7a 49 70 41 64 64 72 2c 20 66 6c 61 ob, zIpAddr, fla
15080 67 73 29 3b 0a 20 20 7d 0a 23 65 6e 64 69 66 0a gs);. }.#endif.
15090 7d 0a 0a 2f 2a 0a 2a 2a 20 43 4f 4d 4d 41 4e 44 }../*.** COMMAND
150a0 3a 20 20 74 65 73 74 2d 65 63 68 6f 0a 2a 2a 0a : test-echo.**.
150b0 2a 2a 20 55 73 61 67 65 3a 20 20 25 66 6f 73 73 ** Usage: %foss
150c0 69 6c 20 74 65 73 74 2d 65 63 68 6f 20 5b 2d 2d il test-echo [--
150d0 68 65 78 5d 20 41 52 47 53 2e 2e 2e 0a 2a 2a 0a hex] ARGS....**.
150e0 2a 2a 20 45 63 68 6f 20 61 6c 6c 20 63 6f 6d 6d ** Echo all comm
150f0 61 6e 64 2d 6c 69 6e 65 20 61 72 67 75 6d 65 6e and-line argumen
15100 74 73 20 28 65 6e 63 6c 6f 73 65 64 20 69 6e 20 ts (enclosed in
15110 5b 2e 2e 2e 5d 29 20 74 6f 20 74 68 65 20 73 63 [...]) to the sc
15120 72 65 65 6e 20 73 6f 20 74 68 61 74 0a 2a 2a 20 reen so that.**
15130 77 69 6c 64 63 61 72 64 20 65 78 70 61 6e 73 69 wildcard expansi
15140 6f 6e 20 62 65 68 61 76 69 6f 72 20 6f 66 20 74 on behavior of t
15150 68 65 20 68 6f 73 74 20 73 68 65 6c 6c 20 63 61 he host shell ca
15160 6e 20 62 65 20 69 6e 76 65 73 74 69 67 61 74 65 n be investigate
15170 64 2e 0a 2a 2a 0a 2a 2a 20 57 69 74 68 20 74 68 d..**.** With th
15180 65 20 2d 2d 68 65 78 20 6f 70 74 69 6f 6e 2c 20 e --hex option,
15190 73 68 6f 77 20 74 68 65 20 6f 75 74 70 75 74 20 show the output
151a0 61 73 20 68 65 78 61 64 65 63 69 6d 61 6c 2e 20 as hexadecimal.
151b0 20 54 68 69 73 20 63 61 6e 20 62 65 20 75 73 65 This can be use
151c0 64 0a 2a 2a 20 74 6f 20 76 65 72 69 66 79 20 74 d.** to verify t
151d0 68 65 20 66 6f 73 73 69 6c 5f 70 61 74 68 5f 74 he fossil_path_t
151e0 6f 5f 75 74 66 38 28 29 20 72 6f 75 74 69 6e 65 o_utf8() routine
151f0 20 6f 6e 20 57 69 6e 64 6f 77 73 20 61 6e 64 20 on Windows and
15200 4d 61 63 2e 0a 2a 2f 0a 76 6f 69 64 20 74 65 73 Mac..*/.void tes
15210 74 5f 65 63 68 6f 5f 63 6d 64 28 76 6f 69 64 29 t_echo_cmd(void)
15220 7b 0a 20 20 69 6e 74 20 69 2c 20 6a 3b 0a 20 20 {. int i, j;.
15230 69 66 28 20 66 69 6e 64 5f 6f 70 74 69 6f 6e 28 if( find_option(
15240 22 68 65 78 22 2c 30 2c 30 29 3d 3d 30 20 29 7b "hex",0,0)==0 ){
15250 0a 20 20 20 20 66 6f 73 73 69 6c 5f 70 72 69 6e . fossil_prin
15260 74 28 22 67 2e 6e 61 6d 65 4f 66 45 78 65 20 3d t("g.nameOfExe =
15270 20 5b 25 73 5d 5c 6e 22 2c 20 67 2e 6e 61 6d 65 [%s]\n", g.name
15280 4f 66 45 78 65 29 3b 0a 20 20 20 20 66 6f 72 28 OfExe);. for(
15290 69 3d 30 3b 20 69 3c 67 2e 61 72 67 63 3b 20 69 i=0; i<g.argc; i
152a0 2b 2b 29 7b 0a 20 20 20 20 20 20 66 6f 73 73 69 ++){. fossi
152b0 6c 5f 70 72 69 6e 74 28 22 61 72 67 76 5b 25 64 l_print("argv[%d
152c0 5d 20 3d 20 5b 25 73 5d 5c 6e 22 2c 20 69 2c 20 ] = [%s]\n", i,
152d0 67 2e 61 72 67 76 5b 69 5d 29 3b 0a 20 20 20 20 g.argv[i]);.
152e0 7d 0a 20 20 7d 65 6c 73 65 7b 0a 20 20 20 20 75 }. }else{. u
152f0 6e 73 69 67 6e 65 64 20 63 68 61 72 20 2a 7a 2c nsigned char *z,
15300 20 63 3b 0a 20 20 20 20 66 6f 72 28 69 3d 30 3b c;. for(i=0;
15310 20 69 3c 67 2e 61 72 67 63 3b 20 69 2b 2b 29 7b i<g.argc; i++){
15320 0a 20 20 20 20 20 20 66 6f 73 73 69 6c 5f 70 72 . fossil_pr
15330 69 6e 74 28 22 61 72 67 76 5b 25 64 5d 20 3d 20 int("argv[%d] =
15340 5b 22 2c 20 69 29 3b 0a 20 20 20 20 20 20 7a 20 [", i);. z
15350 3d 20 28 75 6e 73 69 67 6e 65 64 20 63 68 61 72 = (unsigned char
15360 2a 29 67 2e 61 72 67 76 5b 69 5d 3b 0a 20 20 20 *)g.argv[i];.
15370 20 20 20 66 6f 72 28 6a 3d 30 3b 20 28 63 20 3d for(j=0; (c =
15380 20 7a 5b 6a 5d 29 21 3d 30 3b 20 6a 2b 2b 29 7b z[j])!=0; j++){
15390 0a 20 20 20 20 20 20 20 20 66 6f 73 73 69 6c 5f . fossil_
153a0 70 72 69 6e 74 28 22 25 30 32 78 22 2c 20 63 29 print("%02x", c)
153b0 3b 0a 20 20 20 20 20 20 7d 0a 20 20 20 20 20 20 ;. }.
153c0 66 6f 73 73 69 6c 5f 70 72 69 6e 74 28 22 5d 5c fossil_print("]\
153d0 6e 22 29 3b 0a 20 20 20 20 7d 0a 20 20 7d 0a 7d n");. }. }.}
153e0 0a .