0000: 2f 2a 0a 2a 2a 20 43 6f 70 79 72 69 67 68 74 20 /*.** Copyright
0010: 28 63 29 20 32 30 30 36 20 44 2e 20 52 69 63 68 (c) 2006 D. Rich
0020: 61 72 64 20 48 69 70 70 0a 2a 2a 0a 2a 2a 20 54 ard Hipp.**.** T
0030: 68 69 73 20 70 72 6f 67 72 61 6d 20 69 73 20 66 his program is f
0040: 72 65 65 20 73 6f 66 74 77 61 72 65 3b 20 79 6f ree software; yo
0050: 75 20 63 61 6e 20 72 65 64 69 73 74 72 69 62 75 u can redistribu
0060: 74 65 20 69 74 20 61 6e 64 2f 6f 72 0a 2a 2a 20 te it and/or.**
0070: 6d 6f 64 69 66 79 20 69 74 20 75 6e 64 65 72 20 modify it under
0080: 74 68 65 20 74 65 72 6d 73 20 6f 66 20 74 68 65 the terms of the
0090: 20 53 69 6d 70 6c 69 66 69 65 64 20 42 53 44 20 Simplified BSD
00a0: 4c 69 63 65 6e 73 65 20 28 61 6c 73 6f 0a 2a 2a License (also.**
00b0: 20 6b 6e 6f 77 6e 20 61 73 20 74 68 65 20 22 32 known as the "2
00c0: 2d 43 6c 61 75 73 65 20 4c 69 63 65 6e 73 65 22 -Clause License"
00d0: 20 6f 72 20 22 46 72 65 65 42 53 44 20 4c 69 63 or "FreeBSD Lic
00e0: 65 6e 73 65 22 2e 29 0a 2a 2a 0a 2a 2a 20 54 68 ense".).**.** Th
00f0: 69 73 20 70 72 6f 67 72 61 6d 20 69 73 20 64 69 is program is di
0100: 73 74 72 69 62 75 74 65 64 20 69 6e 20 74 68 65 stributed in the
0110: 20 68 6f 70 65 20 74 68 61 74 20 69 74 20 77 69 hope that it wi
0120: 6c 6c 20 62 65 20 75 73 65 66 75 6c 2c 0a 2a 2a ll be useful,.**
0130: 20 62 75 74 20 77 69 74 68 6f 75 74 20 61 6e 79 but without any
0140: 20 77 61 72 72 61 6e 74 79 3b 20 77 69 74 68 6f warranty; witho
0150: 75 74 20 65 76 65 6e 20 74 68 65 20 69 6d 70 6c ut even the impl
0160: 69 65 64 20 77 61 72 72 61 6e 74 79 20 6f 66 0a ied warranty of.
0170: 2a 2a 20 6d 65 72 63 68 61 6e 74 61 62 69 6c 69 ** merchantabili
0180: 74 79 20 6f 72 20 66 69 74 6e 65 73 73 20 66 6f ty or fitness fo
0190: 72 20 61 20 70 61 72 74 69 63 75 6c 61 72 20 70 r a particular p
01a0: 75 72 70 6f 73 65 2e 0a 2a 2a 0a 2a 2a 20 41 75 urpose..**.** Au
01b0: 74 68 6f 72 20 63 6f 6e 74 61 63 74 20 69 6e 66 thor contact inf
01c0: 6f 72 6d 61 74 69 6f 6e 3a 0a 2a 2a 20 20 20 64 ormation:.** d
01d0: 72 68 40 68 77 61 63 69 2e 63 6f 6d 0a 2a 2a 20 rh@hwaci.com.**
01e0: 20 20 68 74 74 70 3a 2f 2f 77 77 77 2e 68 77 61 http://www.hwa
01f0: 63 69 2e 63 6f 6d 2f 64 72 68 2f 0a 2a 2a 0a 2a ci.com/drh/.**.*
0200: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
0210: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
0220: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
0230: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
0240: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 0a 2a **************.*
0250: 2a 0a 2a 2a 20 54 68 69 73 20 6d 6f 64 75 6c 65 *.** This module
0260: 20 63 6f 64 65 73 20 74 68 65 20 6d 61 69 6e 28 codes the main(
0270: 29 20 70 72 6f 63 65 64 75 72 65 20 74 68 61 74 ) procedure that
0280: 20 72 75 6e 73 20 66 69 72 73 74 20 77 68 65 6e runs first when
0290: 20 74 68 65 0a 2a 2a 20 70 72 6f 67 72 61 6d 20 the.** program
02a0: 69 73 20 69 6e 76 6f 6b 65 64 2e 0a 2a 2f 0a 23 is invoked..*/.#
02b0: 69 6e 63 6c 75 64 65 20 22 56 45 52 53 49 4f 4e include "VERSION
02c0: 2e 68 22 0a 23 69 6e 63 6c 75 64 65 20 22 63 6f .h".#include "co
02d0: 6e 66 69 67 2e 68 22 0a 23 69 66 20 64 65 66 69 nfig.h".#if defi
02e0: 6e 65 64 28 5f 57 49 4e 33 32 29 0a 23 20 20 69 ned(_WIN32).# i
02f0: 6e 63 6c 75 64 65 20 3c 77 69 6e 64 6f 77 73 2e nclude <windows.
0300: 68 3e 0a 23 65 6e 64 69 66 0a 23 69 6e 63 6c 75 h>.#endif.#inclu
0310: 64 65 20 22 6d 61 69 6e 2e 68 22 0a 23 69 6e 63 de "main.h".#inc
0320: 6c 75 64 65 20 3c 73 74 72 69 6e 67 2e 68 3e 0a lude <string.h>.
0330: 23 69 6e 63 6c 75 64 65 20 3c 74 69 6d 65 2e 68 #include <time.h
0340: 3e 0a 23 69 6e 63 6c 75 64 65 20 3c 66 63 6e 74 >.#include <fcnt
0350: 6c 2e 68 3e 0a 23 69 6e 63 6c 75 64 65 20 3c 73 l.h>.#include <s
0360: 79 73 2f 74 79 70 65 73 2e 68 3e 0a 23 69 6e 63 ys/types.h>.#inc
0370: 6c 75 64 65 20 3c 73 79 73 2f 73 74 61 74 2e 68 lude <sys/stat.h
0380: 3e 0a 23 69 6e 63 6c 75 64 65 20 3c 73 74 64 6c >.#include <stdl
0390: 69 62 2e 68 3e 20 2f 2a 20 61 74 65 78 69 74 28 ib.h> /* atexit(
03a0: 29 20 2a 2f 0a 23 69 66 20 21 64 65 66 69 6e 65 ) */.#if !define
03b0: 64 28 5f 57 49 4e 33 32 29 0a 23 20 20 69 6e 63 d(_WIN32).# inc
03c0: 6c 75 64 65 20 3c 65 72 72 6e 6f 2e 68 3e 20 2f lude <errno.h> /
03d0: 2a 20 65 72 72 6e 6f 20 67 6c 6f 62 61 6c 20 2a * errno global *
03e0: 2f 0a 23 65 6e 64 69 66 0a 23 69 66 64 65 66 20 /.#endif.#ifdef
03f0: 46 4f 53 53 49 4c 5f 45 4e 41 42 4c 45 5f 53 53 FOSSIL_ENABLE_SS
0400: 4c 0a 23 20 20 69 6e 63 6c 75 64 65 20 22 6f 70 L.# include "op
0410: 65 6e 73 73 6c 2f 63 72 79 70 74 6f 2e 68 22 0a enssl/crypto.h".
0420: 23 65 6e 64 69 66 0a 23 69 66 20 64 65 66 69 6e #endif.#if defin
0430: 65 64 28 46 4f 53 53 49 4c 5f 45 4e 41 42 4c 45 ed(FOSSIL_ENABLE
0440: 5f 4d 49 4e 49 5a 29 0a 23 20 20 64 65 66 69 6e _MINIZ).# defin
0450: 65 20 4d 49 4e 49 5a 5f 48 45 41 44 45 52 5f 46 e MINIZ_HEADER_F
0460: 49 4c 45 5f 4f 4e 4c 59 0a 23 20 20 69 6e 63 6c ILE_ONLY.# incl
0470: 75 64 65 20 22 6d 69 6e 69 7a 2e 63 22 0a 23 65 ude "miniz.c".#e
0480: 6c 73 65 0a 23 20 20 69 6e 63 6c 75 64 65 20 3c lse.# include <
0490: 7a 6c 69 62 2e 68 3e 0a 23 65 6e 64 69 66 0a 23 zlib.h>.#endif.#
04a0: 69 66 20 49 4e 54 45 52 46 41 43 45 0a 23 69 66 if INTERFACE.#if
04b0: 64 65 66 20 46 4f 53 53 49 4c 5f 45 4e 41 42 4c def FOSSIL_ENABL
04c0: 45 5f 54 43 4c 0a 23 20 20 69 6e 63 6c 75 64 65 E_TCL.# include
04d0: 20 22 74 63 6c 2e 68 22 0a 23 65 6e 64 69 66 0a "tcl.h".#endif.
04e0: 23 69 66 64 65 66 20 46 4f 53 53 49 4c 5f 45 4e #ifdef FOSSIL_EN
04f0: 41 42 4c 45 5f 4a 53 4f 4e 0a 23 20 20 69 6e 63 ABLE_JSON.# inc
0500: 6c 75 64 65 20 22 63 73 6f 6e 5f 61 6d 61 6c 67 lude "cson_amalg
0510: 61 6d 61 74 69 6f 6e 2e 68 22 20 2f 2a 20 4a 53 amation.h" /* JS
0520: 4f 4e 20 41 50 49 2e 20 2a 2f 0a 23 20 20 69 6e ON API. */.# in
0530: 63 6c 75 64 65 20 22 6a 73 6f 6e 5f 64 65 74 61 clude "json_deta
0540: 69 6c 2e 68 22 0a 23 65 6e 64 69 66 0a 0a 2f 2a il.h".#endif../*
0550: 0a 2a 2a 20 53 69 7a 65 20 6f 66 20 61 20 55 55 .** Size of a UU
0560: 49 44 20 69 6e 20 63 68 61 72 61 63 74 65 72 73 ID in characters
0570: 2e 20 20 20 41 20 55 55 49 44 20 69 73 20 61 20 . A UUID is a
0580: 72 61 6e 64 6f 6d 6c 79 20 67 65 6e 65 72 61 74 randomly generat
0590: 65 64 0a 2a 2a 20 6c 6f 77 65 72 2d 63 61 73 65 ed.** lower-case
05a0: 20 68 65 78 61 64 65 63 69 6d 61 6c 20 6e 75 6d hexadecimal num
05b0: 62 65 72 20 75 73 65 64 20 74 6f 20 69 64 65 6e ber used to iden
05c0: 74 69 66 79 20 74 69 63 6b 65 74 73 2e 0a 2a 2a tify tickets..**
05d0: 0a 2a 2a 20 49 6e 20 46 6f 73 73 69 6c 20 31 2e .** In Fossil 1.
05e0: 78 2c 20 55 55 49 44 20 61 6c 73 6f 20 72 65 66 x, UUID also ref
05f0: 65 72 72 65 64 20 74 6f 20 61 20 53 48 41 31 20 erred to a SHA1
0600: 61 72 74 69 66 61 63 74 20 68 61 73 68 2e 20 20 artifact hash.
0610: 42 75 74 20 74 68 61 74 0a 2a 2a 20 75 73 61 67 But that.** usag
0620: 65 20 69 73 20 6e 6f 77 20 6f 62 73 6f 6c 65 74 e is now obsolet
0630: 65 2e 20 20 54 68 65 20 74 65 72 6d 20 55 55 49 e. The term UUI
0640: 44 20 73 68 6f 75 6c 64 20 6e 6f 77 20 6d 65 61 D should now mea
0650: 6e 20 6f 6e 6c 79 20 61 20 76 65 72 79 20 6c 61 n only a very la
0660: 72 67 65 0a 2a 2a 20 72 61 6e 64 6f 6d 20 6e 75 rge.** random nu
0670: 6d 62 65 72 20 75 73 65 64 20 61 73 20 61 20 75 mber used as a u
0680: 6e 69 71 75 65 20 69 64 65 6e 74 69 66 69 65 72 nique identifier
0690: 20 66 6f 72 20 74 69 63 6b 65 74 73 20 6f 72 20 for tickets or
06a0: 6f 74 68 65 72 20 6f 62 6a 65 63 74 73 2e 0a 2a other objects..*
06b0: 2f 0a 23 64 65 66 69 6e 65 20 55 55 49 44 5f 53 /.#define UUID_S
06c0: 49 5a 45 20 34 30 0a 0a 2f 2a 0a 2a 2a 20 4d 61 IZE 40../*.** Ma
06d0: 78 69 6d 75 6d 20 6e 75 6d 62 65 72 20 6f 66 20 ximum number of
06e0: 61 75 78 69 6c 69 61 72 79 20 70 61 72 61 6d 65 auxiliary parame
06f0: 74 65 72 73 20 6f 6e 20 72 65 70 6f 72 74 73 0a ters on reports.
0700: 2a 2f 0a 23 64 65 66 69 6e 65 20 4d 58 5f 41 55 */.#define MX_AU
0710: 58 20 20 35 0a 0a 2f 2a 0a 2a 2a 20 48 6f 6c 64 X 5../*.** Hold
0720: 73 20 66 6c 61 67 73 20 66 6f 72 20 66 6f 73 73 s flags for foss
0730: 69 6c 20 75 73 65 72 20 70 65 72 6d 69 73 73 69 il user permissi
0740: 6f 6e 73 2e 0a 2a 2f 0a 73 74 72 75 63 74 20 46 ons..*/.struct F
0750: 6f 73 73 69 6c 55 73 65 72 50 65 72 6d 73 20 7b ossilUserPerms {
0760: 0a 20 20 63 68 61 72 20 53 65 74 75 70 3b 20 20 . char Setup;
0770: 20 20 20 20 20 20 20 20 20 20 2f 2a 20 73 3a 20 /* s:
0780: 75 73 65 20 53 65 74 75 70 20 73 63 72 65 65 6e use Setup screen
0790: 73 20 6f 6e 20 77 65 62 20 69 6e 74 65 72 66 61 s on web interfa
07a0: 63 65 20 2a 2f 0a 20 20 63 68 61 72 20 41 64 6d ce */. char Adm
07b0: 69 6e 3b 20 20 20 20 20 20 20 20 20 20 20 20 2f in; /
07c0: 2a 20 61 3a 20 61 64 6d 69 6e 69 73 74 72 61 74 * a: administrat
07d0: 69 76 65 20 70 65 72 6d 69 73 73 69 6f 6e 20 2a ive permission *
07e0: 2f 0a 20 20 63 68 61 72 20 44 65 6c 65 74 65 3b /. char Delete;
07f0: 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 64 3a /* d:
0800: 20 64 65 6c 65 74 65 20 77 69 6b 69 20 6f 72 20 delete wiki or
0810: 74 69 63 6b 65 74 73 20 2a 2f 0a 20 20 63 68 61 tickets */. cha
0820: 72 20 50 61 73 73 77 6f 72 64 3b 20 20 20 20 20 r Password;
0830: 20 20 20 20 2f 2a 20 70 3a 20 63 68 61 6e 67 65 /* p: change
0840: 20 70 61 73 73 77 6f 72 64 20 2a 2f 0a 20 20 63 password */. c
0850: 68 61 72 20 51 75 65 72 79 3b 20 20 20 20 20 20 har Query;
0860: 20 20 20 20 20 20 2f 2a 20 71 3a 20 63 72 65 61 /* q: crea
0870: 74 65 20 6e 65 77 20 72 65 70 6f 72 74 73 20 2a te new reports *
0880: 2f 0a 20 20 63 68 61 72 20 57 72 69 74 65 3b 20 /. char Write;
0890: 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 69 3a /* i:
08a0: 20 78 66 65 72 20 69 6e 62 6f 75 6e 64 2e 20 63 xfer inbound. c
08b0: 68 65 63 6b 2d 69 6e 20 2a 2f 0a 20 20 63 68 61 heck-in */. cha
08c0: 72 20 52 65 61 64 3b 20 20 20 20 20 20 20 20 20 r Read;
08d0: 20 20 20 20 2f 2a 20 6f 3a 20 78 66 65 72 20 6f /* o: xfer o
08e0: 75 74 62 6f 75 6e 64 2e 20 63 68 65 63 6b 2d 6f utbound. check-o
08f0: 75 74 20 2a 2f 0a 20 20 63 68 61 72 20 48 79 70 ut */. char Hyp
0900: 65 72 6c 69 6e 6b 3b 20 20 20 20 20 20 20 20 2f erlink; /
0910: 2a 20 68 3a 20 65 6e 61 62 6c 65 20 74 68 65 20 * h: enable the
0920: 64 69 73 70 6c 61 79 20 6f 66 20 68 79 70 65 72 display of hyper
0930: 6c 69 6e 6b 73 20 2a 2f 0a 20 20 63 68 61 72 20 links */. char
0940: 43 6c 6f 6e 65 3b 20 20 20 20 20 20 20 20 20 20 Clone;
0950: 20 20 2f 2a 20 67 3a 20 63 6c 6f 6e 65 20 2a 2f /* g: clone */
0960: 0a 20 20 63 68 61 72 20 52 64 57 69 6b 69 3b 20 . char RdWiki;
0970: 20 20 20 20 20 20 20 20 20 20 2f 2a 20 6a 3a 20 /* j:
0980: 76 69 65 77 20 77 69 6b 69 20 76 69 61 20 77 65 view wiki via we
0990: 62 20 2a 2f 0a 20 20 63 68 61 72 20 4e 65 77 57 b */. char NewW
09a0: 69 6b 69 3b 20 20 20 20 20 20 20 20 20 20 2f 2a iki; /*
09b0: 20 66 3a 20 63 72 65 61 74 65 20 6e 65 77 20 77 f: create new w
09c0: 69 6b 69 20 76 69 61 20 77 65 62 20 2a 2f 0a 20 iki via web */.
09d0: 20 63 68 61 72 20 41 70 6e 64 57 69 6b 69 3b 20 char ApndWiki;
09e0: 20 20 20 20 20 20 20 20 2f 2a 20 6d 3a 20 61 70 /* m: ap
09f0: 70 65 6e 64 20 74 6f 20 77 69 6b 69 20 76 69 61 pend to wiki via
0a00: 20 77 65 62 20 2a 2f 0a 20 20 63 68 61 72 20 57 web */. char W
0a10: 72 57 69 6b 69 3b 20 20 20 20 20 20 20 20 20 20 rWiki;
0a20: 20 2f 2a 20 6b 3a 20 65 64 69 74 20 77 69 6b 69 /* k: edit wiki
0a30: 20 76 69 61 20 77 65 62 20 2a 2f 0a 20 20 63 68 via web */. ch
0a40: 61 72 20 4d 6f 64 57 69 6b 69 3b 20 20 20 20 20 ar ModWiki;
0a50: 20 20 20 20 20 2f 2a 20 6c 3a 20 61 70 70 72 6f /* l: appro
0a60: 76 65 20 61 6e 64 20 70 75 62 6c 69 73 68 20 77 ve and publish w
0a70: 69 6b 69 20 63 6f 6e 74 65 6e 74 20 28 4d 6f 64 iki content (Mod
0a80: 65 72 61 74 6f 72 29 20 2a 2f 0a 20 20 63 68 61 erator) */. cha
0a90: 72 20 52 64 54 6b 74 3b 20 20 20 20 20 20 20 20 r RdTkt;
0aa0: 20 20 20 20 2f 2a 20 72 3a 20 76 69 65 77 20 74 /* r: view t
0ab0: 69 63 6b 65 74 73 20 76 69 61 20 77 65 62 20 2a ickets via web *
0ac0: 2f 0a 20 20 63 68 61 72 20 4e 65 77 54 6b 74 3b /. char NewTkt;
0ad0: 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 6e 3a /* n:
0ae0: 20 63 72 65 61 74 65 20 6e 65 77 20 74 69 63 6b create new tick
0af0: 65 74 73 20 2a 2f 0a 20 20 63 68 61 72 20 41 70 ets */. char Ap
0b00: 6e 64 54 6b 74 3b 20 20 20 20 20 20 20 20 20 20 ndTkt;
0b10: 2f 2a 20 63 3a 20 61 70 70 65 6e 64 20 74 6f 20 /* c: append to
0b20: 74 69 63 6b 65 74 73 20 76 69 61 20 74 68 65 20 tickets via the
0b30: 77 65 62 20 2a 2f 0a 20 20 63 68 61 72 20 57 72 web */. char Wr
0b40: 54 6b 74 3b 20 20 20 20 20 20 20 20 20 20 20 20 Tkt;
0b50: 2f 2a 20 77 3a 20 6d 61 6b 65 20 63 68 61 6e 67 /* w: make chang
0b60: 65 73 20 74 6f 20 74 69 63 6b 65 74 73 20 76 69 es to tickets vi
0b70: 61 20 77 65 62 20 2a 2f 0a 20 20 63 68 61 72 20 a web */. char
0b80: 4d 6f 64 54 6b 74 3b 20 20 20 20 20 20 20 20 20 ModTkt;
0b90: 20 20 2f 2a 20 71 3a 20 61 70 70 72 6f 76 65 20 /* q: approve
0ba0: 61 6e 64 20 70 75 62 6c 69 73 68 20 74 69 63 6b and publish tick
0bb0: 65 74 20 63 68 61 6e 67 65 73 20 28 4d 6f 64 65 et changes (Mode
0bc0: 72 61 74 6f 72 29 20 2a 2f 0a 20 20 63 68 61 72 rator) */. char
0bd0: 20 41 74 74 61 63 68 3b 20 20 20 20 20 20 20 20 Attach;
0be0: 20 20 20 2f 2a 20 62 3a 20 61 64 64 20 61 74 74 /* b: add att
0bf0: 61 63 68 6d 65 6e 74 73 20 2a 2f 0a 20 20 63 68 achments */. ch
0c00: 61 72 20 54 6b 74 46 6d 74 3b 20 20 20 20 20 20 ar TktFmt;
0c10: 20 20 20 20 20 2f 2a 20 74 3a 20 63 72 65 61 74 /* t: creat
0c20: 65 20 6e 65 77 20 74 69 63 6b 65 74 20 72 65 70 e new ticket rep
0c30: 6f 72 74 20 66 6f 72 6d 61 74 73 20 2a 2f 0a 20 ort formats */.
0c40: 20 63 68 61 72 20 52 64 41 64 64 72 3b 20 20 20 char RdAddr;
0c50: 20 20 20 20 20 20 20 20 2f 2a 20 65 3a 20 72 65 /* e: re
0c60: 61 64 20 65 6d 61 69 6c 20 61 64 64 72 65 73 73 ad email address
0c70: 65 73 20 6f 72 20 6f 74 68 65 72 20 70 72 69 76 es or other priv
0c80: 61 74 65 20 64 61 74 61 20 2a 2f 0a 20 20 63 68 ate data */. ch
0c90: 61 72 20 5a 69 70 3b 20 20 20 20 20 20 20 20 20 ar Zip;
0ca0: 20 20 20 20 20 2f 2a 20 7a 3a 20 64 6f 77 6e 6c /* z: downl
0cb0: 6f 61 64 20 7a 69 70 70 65 64 20 61 72 74 69 66 oad zipped artif
0cc0: 61 63 74 20 76 69 61 20 2f 7a 69 70 20 55 52 4c act via /zip URL
0cd0: 20 2a 2f 0a 20 20 63 68 61 72 20 50 72 69 76 61 */. char Priva
0ce0: 74 65 3b 20 20 20 20 20 20 20 20 20 20 2f 2a 20 te; /*
0cf0: 78 3a 20 63 61 6e 20 73 65 6e 64 20 61 6e 64 20 x: can send and
0d00: 72 65 63 65 69 76 65 20 70 72 69 76 61 74 65 20 receive private
0d10: 63 6f 6e 74 65 6e 74 20 2a 2f 0a 20 20 63 68 61 content */. cha
0d20: 72 20 57 72 55 6e 76 65 72 3b 20 20 20 20 20 20 r WrUnver;
0d30: 20 20 20 20 2f 2a 20 79 3a 20 63 61 6e 20 70 75 /* y: can pu
0d40: 73 68 20 75 6e 76 65 72 73 69 6f 6e 65 64 20 63 sh unversioned c
0d50: 6f 6e 74 65 6e 74 20 2a 2f 0a 7d 3b 0a 0a 23 69 ontent */.};..#i
0d60: 66 64 65 66 20 46 4f 53 53 49 4c 5f 45 4e 41 42 fdef FOSSIL_ENAB
0d70: 4c 45 5f 54 43 4c 0a 2f 2a 0a 2a 2a 20 41 6c 6c LE_TCL./*.** All
0d80: 20 54 63 6c 20 72 65 6c 61 74 65 64 20 63 6f 6e Tcl related con
0d90: 74 65 78 74 20 69 6e 66 6f 72 6d 61 74 69 6f 6e text information
0da0: 20 69 73 20 69 6e 20 74 68 69 73 20 73 74 72 75 is in this stru
0db0: 63 74 75 72 65 2e 20 20 54 68 69 73 20 73 74 72 cture. This str
0dc0: 75 63 74 75 72 65 0a 2a 2a 20 64 65 66 69 6e 69 ucture.** defini
0dd0: 74 69 6f 6e 20 68 61 73 20 62 65 65 6e 20 63 6f tion has been co
0de0: 70 69 65 64 20 66 72 6f 6d 20 61 6e 64 20 73 68 pied from and sh
0df0: 6f 75 6c 64 20 62 65 20 6b 65 70 74 20 69 6e 20 ould be kept in
0e00: 73 79 6e 63 20 77 69 74 68 20 74 68 65 20 6f 6e sync with the on
0e10: 65 20 69 6e 0a 2a 2a 20 22 74 68 5f 74 63 6c 2e e in.** "th_tcl.
0e20: 63 22 2e 0a 2a 2f 0a 73 74 72 75 63 74 20 54 63 c"..*/.struct Tc
0e30: 6c 43 6f 6e 74 65 78 74 20 7b 0a 20 20 69 6e 74 lContext {. int
0e40: 20 61 72 67 63 3b 20 20 20 20 20 20 20 20 20 20 argc;
0e50: 20 20 20 20 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 /* Number of
0e60: 20 6f 72 69 67 69 6e 61 6c 20 28 65 78 70 61 6e original (expan
0e70: 64 65 64 29 20 61 72 67 75 6d 65 6e 74 73 2e 20 ded) arguments.
0e80: 2a 2f 0a 20 20 63 68 61 72 20 2a 2a 61 72 67 76 */. char **argv
0e90: 3b 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 46 ; /* F
0ea0: 75 6c 6c 20 63 6f 70 79 20 6f 66 20 74 68 65 20 ull copy of the
0eb0: 6f 72 69 67 69 6e 61 6c 20 28 65 78 70 61 6e 64 original (expand
0ec0: 65 64 29 20 61 72 67 75 6d 65 6e 74 73 2e 20 2a ed) arguments. *
0ed0: 2f 0a 20 20 76 6f 69 64 20 2a 68 4c 69 62 72 61 /. void *hLibra
0ee0: 72 79 3b 20 20 20 20 20 20 20 20 2f 2a 20 54 68 ry; /* Th
0ef0: 65 20 54 63 6c 20 6c 69 62 72 61 72 79 20 6d 6f e Tcl library mo
0f00: 64 75 6c 65 20 68 61 6e 64 6c 65 2e 20 2a 2f 0a dule handle. */.
0f10: 20 20 76 6f 69 64 20 2a 78 46 69 6e 64 45 78 65 void *xFindExe
0f20: 63 75 74 61 62 6c 65 3b 20 2f 2a 20 53 65 65 20 cutable; /* See
0f30: 74 63 6c 5f 46 69 6e 64 45 78 65 63 75 74 61 62 tcl_FindExecutab
0f40: 6c 65 50 72 6f 63 20 69 6e 20 74 68 5f 74 63 6c leProc in th_tcl
0f50: 2e 63 2e 20 2a 2f 0a 20 20 76 6f 69 64 20 2a 78 .c. */. void *x
0f60: 43 72 65 61 74 65 49 6e 74 65 72 70 3b 20 20 20 CreateInterp;
0f70: 2f 2a 20 53 65 65 20 74 63 6c 5f 43 72 65 61 74 /* See tcl_Creat
0f80: 65 49 6e 74 65 72 70 50 72 6f 63 20 69 6e 20 74 eInterpProc in t
0f90: 68 5f 74 63 6c 2e 63 2e 20 2a 2f 0a 20 20 76 6f h_tcl.c. */. vo
0fa0: 69 64 20 2a 78 44 65 6c 65 74 65 49 6e 74 65 72 id *xDeleteInter
0fb0: 70 3b 20 20 20 2f 2a 20 53 65 65 20 74 63 6c 5f p; /* See tcl_
0fc0: 44 65 6c 65 74 65 49 6e 74 65 72 70 50 72 6f 63 DeleteInterpProc
0fd0: 20 69 6e 20 74 68 5f 74 63 6c 2e 63 2e 20 2a 2f in th_tcl.c. */
0fe0: 0a 20 20 76 6f 69 64 20 2a 78 46 69 6e 61 6c 69 . void *xFinali
0ff0: 7a 65 3b 20 20 20 20 20 20 20 2f 2a 20 53 65 65 ze; /* See
1000: 20 74 63 6c 5f 46 69 6e 61 6c 69 7a 65 50 72 6f tcl_FinalizePro
1010: 63 20 69 6e 20 74 68 5f 74 63 6c 2e 63 2e 20 2a c in th_tcl.c. *
1020: 2f 0a 20 20 54 63 6c 5f 49 6e 74 65 72 70 20 2a /. Tcl_Interp *
1030: 69 6e 74 65 72 70 3b 20 20 20 20 2f 2a 20 54 68 interp; /* Th
1040: 65 20 6f 6e 2d 64 65 6d 61 6e 64 20 63 72 65 61 e on-demand crea
1050: 74 65 64 20 54 63 6c 20 69 6e 74 65 72 70 72 65 ted Tcl interpre
1060: 74 65 72 2e 20 2a 2f 0a 20 20 69 6e 74 20 75 73 ter. */. int us
1070: 65 4f 62 6a 50 72 6f 63 3b 20 20 20 20 20 20 20 eObjProc;
1080: 20 2f 2a 20 4e 6f 6e 2d 7a 65 72 6f 20 69 66 20 /* Non-zero if
1090: 61 6e 20 6f 62 6a 50 72 6f 63 20 63 61 6e 20 62 an objProc can b
10a0: 65 20 63 61 6c 6c 65 64 20 64 69 72 65 63 74 6c e called directl
10b0: 79 2e 20 2a 2f 0a 20 20 69 6e 74 20 75 73 65 54 y. */. int useT
10c0: 69 70 32 38 35 3b 20 20 20 20 20 20 20 20 20 2f ip285; /
10d0: 2a 20 4e 6f 6e 2d 7a 65 72 6f 20 69 66 20 54 49 * Non-zero if TI
10e0: 50 20 23 32 38 35 20 69 73 20 61 76 61 69 6c 61 P #285 is availa
10f0: 62 6c 65 2e 20 2a 2f 0a 20 20 63 68 61 72 20 2a ble. */. char *
1100: 73 65 74 75 70 3b 20 20 20 20 20 20 20 20 20 20 setup;
1110: 20 2f 2a 20 54 68 65 20 6f 70 74 69 6f 6e 61 6c /* The optional
1120: 20 54 63 6c 20 73 65 74 75 70 20 73 63 72 69 70 Tcl setup scrip
1130: 74 2e 20 2a 2f 0a 20 20 76 6f 69 64 20 2a 78 50 t. */. void *xP
1140: 72 65 45 76 61 6c 3b 20 20 20 20 20 20 20 20 2f reEval; /
1150: 2a 20 4f 70 74 69 6f 6e 61 6c 2c 20 63 61 6c 6c * Optional, call
1160: 65 64 20 62 65 66 6f 72 65 20 54 63 6c 5f 45 76 ed before Tcl_Ev
1170: 61 6c 2a 28 29 2e 20 2a 2f 0a 20 20 76 6f 69 64 al*(). */. void
1180: 20 2a 70 50 72 65 43 6f 6e 74 65 78 74 3b 20 20 *pPreContext;
1190: 20 20 20 2f 2a 20 4f 70 74 69 6f 6e 61 6c 2c 20 /* Optional,
11a0: 70 72 6f 76 69 64 65 64 20 74 6f 20 78 50 72 65 provided to xPre
11b0: 45 76 61 6c 28 29 2e 20 2a 2f 0a 20 20 76 6f 69 Eval(). */. voi
11c0: 64 20 2a 78 50 6f 73 74 45 76 61 6c 3b 20 20 20 d *xPostEval;
11d0: 20 20 20 20 2f 2a 20 4f 70 74 69 6f 6e 61 6c 2c /* Optional,
11e0: 20 63 61 6c 6c 65 64 20 61 66 74 65 72 20 54 63 called after Tc
11f0: 6c 5f 45 76 61 6c 2a 28 29 2e 20 2a 2f 0a 20 20 l_Eval*(). */.
1200: 76 6f 69 64 20 2a 70 50 6f 73 74 43 6f 6e 74 65 void *pPostConte
1210: 78 74 3b 20 20 20 20 2f 2a 20 4f 70 74 69 6f 6e xt; /* Option
1220: 61 6c 2c 20 70 72 6f 76 69 64 65 64 20 74 6f 20 al, provided to
1230: 78 50 6f 73 74 45 76 61 6c 28 29 2e 20 2a 2f 0a xPostEval(). */.
1240: 7d 3b 0a 23 65 6e 64 69 66 0a 0a 73 74 72 75 63 };.#endif..struc
1250: 74 20 47 6c 6f 62 61 6c 20 7b 0a 20 20 69 6e 74 t Global {. int
1260: 20 61 72 67 63 3b 20 63 68 61 72 20 2a 2a 61 72 argc; char **ar
1270: 67 76 3b 20 20 2f 2a 20 43 6f 6d 6d 61 6e 64 2d gv; /* Command-
1280: 6c 69 6e 65 20 61 72 67 75 6d 65 6e 74 73 20 74 line arguments t
1290: 6f 20 74 68 65 20 70 72 6f 67 72 61 6d 20 2a 2f o the program */
12a0: 0a 20 20 63 68 61 72 20 2a 6e 61 6d 65 4f 66 45 . char *nameOfE
12b0: 78 65 3b 20 20 20 20 20 20 20 20 2f 2a 20 46 75 xe; /* Fu
12c0: 6c 6c 20 70 61 74 68 20 6f 66 20 65 78 65 63 75 ll path of execu
12d0: 74 61 62 6c 65 2e 20 2a 2f 0a 20 20 63 6f 6e 73 table. */. cons
12e0: 74 20 63 68 61 72 20 2a 7a 45 72 72 6c 6f 67 3b t char *zErrlog;
12f0: 20 20 20 20 2f 2a 20 4c 6f 67 20 65 72 72 6f 72 /* Log error
1300: 73 20 74 6f 20 74 68 69 73 20 66 69 6c 65 2c 20 s to this file,
1310: 69 66 20 6e 6f 74 20 4e 55 4c 4c 20 2a 2f 0a 20 if not NULL */.
1320: 20 69 6e 74 20 69 73 43 6f 6e 73 74 3b 20 20 20 int isConst;
1330: 20 20 20 20 20 20 20 20 20 2f 2a 20 54 72 75 65 /* True
1340: 20 69 66 20 74 68 65 20 6f 75 74 70 75 74 20 69 if the output i
1350: 73 20 75 6e 63 68 61 6e 67 69 6e 67 20 26 20 63 s unchanging & c
1360: 61 63 68 65 61 62 6c 65 20 2a 2f 0a 20 20 63 6f acheable */. co
1370: 6e 73 74 20 63 68 61 72 20 2a 7a 56 66 73 4e 61 nst char *zVfsNa
1380: 6d 65 3b 20 20 20 2f 2a 20 54 68 65 20 56 46 53 me; /* The VFS
1390: 20 74 6f 20 75 73 65 20 66 6f 72 20 64 61 74 61 to use for data
13a0: 62 61 73 65 20 63 6f 6e 6e 65 63 74 69 6f 6e 73 base connections
13b0: 20 2a 2f 0a 20 20 73 71 6c 69 74 65 33 20 2a 64 */. sqlite3 *d
13c0: 62 3b 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a b; /*
13d0: 20 54 68 65 20 63 6f 6e 6e 65 63 74 69 6f 6e 20 The connection
13e0: 74 6f 20 74 68 65 20 64 61 74 61 62 61 73 65 73 to the databases
13f0: 20 2a 2f 0a 20 20 73 71 6c 69 74 65 33 20 2a 64 */. sqlite3 *d
1400: 62 43 6f 6e 66 69 67 3b 20 20 20 20 20 20 2f 2a bConfig; /*
1410: 20 53 65 70 61 72 61 74 65 20 63 6f 6e 6e 65 63 Separate connec
1420: 74 69 6f 6e 20 66 6f 72 20 67 6c 6f 62 61 6c 5f tion for global_
1430: 63 6f 6e 66 69 67 20 74 61 62 6c 65 20 2a 2f 0a config table */.
1440: 20 20 63 68 61 72 20 2a 7a 41 75 78 53 63 68 65 char *zAuxSche
1450: 6d 61 3b 20 20 20 20 20 20 20 2f 2a 20 4d 61 69 ma; /* Mai
1460: 6e 20 72 65 70 6f 73 69 74 6f 72 79 20 61 75 78 n repository aux
1470: 2d 73 63 68 65 6d 61 20 2a 2f 0a 20 20 69 6e 74 -schema */. int
1480: 20 64 62 49 67 6e 6f 72 65 45 72 72 6f 72 73 3b dbIgnoreErrors;
1490: 20 20 20 20 20 2f 2a 20 49 67 6e 6f 72 65 20 64 /* Ignore d
14a0: 61 74 61 62 61 73 65 20 65 72 72 6f 72 73 20 69 atabase errors i
14b0: 66 20 74 72 75 65 20 2a 2f 0a 20 20 63 6f 6e 73 f true */. cons
14c0: 74 20 63 68 61 72 20 2a 7a 43 6f 6e 66 69 67 44 t char *zConfigD
14d0: 62 4e 61 6d 65 3b 2f 2a 20 50 61 74 68 20 6f 66 bName;/* Path of
14e0: 20 74 68 65 20 63 6f 6e 66 69 67 20 64 61 74 61 the config data
14f0: 62 61 73 65 2e 20 4e 55 4c 4c 20 69 66 20 6e 6f base. NULL if no
1500: 74 20 6f 70 65 6e 20 2a 2f 0a 20 20 73 71 6c 69 t open */. sqli
1510: 74 65 33 5f 69 6e 74 36 34 20 6e 6f 77 3b 20 20 te3_int64 now;
1520: 20 20 20 20 2f 2a 20 53 65 63 6f 6e 64 73 20 73 /* Seconds s
1530: 69 6e 63 65 20 31 39 37 30 20 2a 2f 0a 20 20 69 ince 1970 */. i
1540: 6e 74 20 72 65 70 6f 73 69 74 6f 72 79 4f 70 65 nt repositoryOpe
1550: 6e 3b 20 20 20 20 20 2f 2a 20 54 72 75 65 20 69 n; /* True i
1560: 66 20 74 68 65 20 6d 61 69 6e 20 72 65 70 6f 73 f the main repos
1570: 69 74 6f 72 79 20 64 61 74 61 62 61 73 65 20 69 itory database i
1580: 73 20 6f 70 65 6e 20 2a 2f 0a 20 20 63 68 61 72 s open */. char
1590: 20 2a 7a 52 65 70 6f 73 69 74 6f 72 79 4f 70 74 *zRepositoryOpt
15a0: 69 6f 6e 3b 20 2f 2a 20 4d 6f 73 74 20 72 65 63 ion; /* Most rec
15b0: 65 6e 74 20 63 61 63 68 65 64 20 72 65 70 6f 73 ent cached repos
15c0: 69 74 6f 72 79 20 6f 70 74 69 6f 6e 20 76 61 6c itory option val
15d0: 75 65 20 2a 2f 0a 20 20 63 68 61 72 20 2a 7a 52 ue */. char *zR
15e0: 65 70 6f 73 69 74 6f 72 79 4e 61 6d 65 3b 20 20 epositoryName;
15f0: 2f 2a 20 4e 61 6d 65 20 6f 66 20 74 68 65 20 72 /* Name of the r
1600: 65 70 6f 73 69 74 6f 72 79 20 64 61 74 61 62 61 epository databa
1610: 73 65 20 66 69 6c 65 20 2a 2f 0a 20 20 63 68 61 se file */. cha
1620: 72 20 2a 7a 4c 6f 63 61 6c 44 62 4e 61 6d 65 3b r *zLocalDbName;
1630: 20 20 20 20 20 2f 2a 20 4e 61 6d 65 20 6f 66 20 /* Name of
1640: 74 68 65 20 6c 6f 63 61 6c 20 64 61 74 61 62 61 the local databa
1650: 73 65 20 66 69 6c 65 20 2a 2f 0a 20 20 63 68 61 se file */. cha
1660: 72 20 2a 7a 4f 70 65 6e 52 65 76 69 73 69 6f 6e r *zOpenRevision
1670: 3b 20 20 20 20 2f 2a 20 43 68 65 63 6b 2d 69 6e ; /* Check-in
1680: 20 76 65 72 73 69 6f 6e 20 74 6f 20 75 73 65 20 version to use
1690: 64 75 72 69 6e 67 20 64 61 74 61 62 61 73 65 20 during database
16a0: 6f 70 65 6e 20 2a 2f 0a 20 20 69 6e 74 20 6c 6f open */. int lo
16b0: 63 61 6c 4f 70 65 6e 3b 20 20 20 20 20 20 20 20 calOpen;
16c0: 20 20 2f 2a 20 54 72 75 65 20 69 66 20 74 68 65 /* True if the
16d0: 20 6c 6f 63 61 6c 20 64 61 74 61 62 61 73 65 20 local database
16e0: 69 73 20 6f 70 65 6e 20 2a 2f 0a 20 20 63 68 61 is open */. cha
16f0: 72 20 2a 7a 4c 6f 63 61 6c 52 6f 6f 74 3b 20 20 r *zLocalRoot;
1700: 20 20 20 20 20 2f 2a 20 54 68 65 20 64 69 72 65 /* The dire
1710: 63 74 6f 72 79 20 68 6f 6c 64 69 6e 67 20 74 68 ctory holding th
1720: 65 20 20 6c 6f 63 61 6c 20 64 61 74 61 62 61 73 e local databas
1730: 65 20 2a 2f 0a 20 20 69 6e 74 20 6d 69 6e 50 72 e */. int minPr
1740: 65 66 69 78 3b 20 20 20 20 20 20 20 20 20 20 2f efix; /
1750: 2a 20 4e 75 6d 62 65 72 20 6f 66 20 64 69 67 69 * Number of digi
1760: 74 73 20 6e 65 65 64 65 64 20 66 6f 72 20 61 20 ts needed for a
1770: 64 69 73 74 69 6e 63 74 20 55 55 49 44 20 2a 2f distinct UUID */
1780: 0a 20 20 69 6e 74 20 65 48 61 73 68 50 6f 6c 69 . int eHashPoli
1790: 63 79 3b 20 20 20 20 20 20 20 20 2f 2a 20 43 75 cy; /* Cu
17a0: 72 72 65 6e 74 20 68 61 73 68 20 70 6f 6c 69 63 rrent hash polic
17b0: 79 2e 20 20 4f 6e 65 20 6f 66 20 48 50 4f 4c 49 y. One of HPOLI
17c0: 43 59 5f 2a 20 2a 2f 0a 20 20 69 6e 74 20 66 4e CY_* */. int fN
17d0: 6f 44 69 72 53 79 6d 6c 69 6e 6b 73 3b 20 20 20 oDirSymlinks;
17e0: 20 20 2f 2a 20 54 72 75 65 20 69 66 20 2d 2d 6e /* True if --n
17f0: 6f 2d 64 69 72 2d 73 79 6d 6c 69 6e 6b 73 20 66 o-dir-symlinks f
1800: 6c 61 67 20 69 73 20 70 72 65 73 65 6e 74 20 2a lag is present *
1810: 2f 0a 20 20 69 6e 74 20 66 53 71 6c 54 72 61 63 /. int fSqlTrac
1820: 65 3b 20 20 20 20 20 20 20 20 20 20 2f 2a 20 54 e; /* T
1830: 72 75 65 20 69 66 20 2d 2d 73 71 6c 74 72 61 63 rue if --sqltrac
1840: 65 20 66 6c 61 67 20 69 73 20 70 72 65 73 65 6e e flag is presen
1850: 74 20 2a 2f 0a 20 20 69 6e 74 20 66 53 71 6c 53 t */. int fSqlS
1860: 74 61 74 73 3b 20 20 20 20 20 20 20 20 20 20 2f tats; /
1870: 2a 20 54 72 75 65 20 69 66 20 2d 2d 73 71 6c 74 * True if --sqlt
1880: 72 61 63 65 20 6f 72 20 2d 2d 73 71 6c 73 74 61 race or --sqlsta
1890: 74 73 20 61 72 65 20 70 72 65 73 65 6e 74 20 2a ts are present *
18a0: 2f 0a 20 20 69 6e 74 20 66 53 71 6c 50 72 69 6e /. int fSqlPrin
18b0: 74 3b 20 20 20 20 20 20 20 20 20 20 2f 2a 20 54 t; /* T
18c0: 72 75 65 20 69 66 20 2d 73 71 6c 70 72 69 6e 74 rue if -sqlprint
18d0: 20 66 6c 61 67 20 69 73 20 70 72 65 73 65 6e 74 flag is present
18e0: 20 2a 2f 0a 20 20 69 6e 74 20 66 51 75 69 65 74 */. int fQuiet
18f0: 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a ; /*
1900: 20 54 72 75 65 20 69 66 20 2d 71 75 69 65 74 20 True if -quiet
1910: 66 6c 61 67 20 69 73 20 70 72 65 73 65 6e 74 20 flag is present
1920: 2a 2f 0a 20 20 69 6e 74 20 66 4a 61 69 6c 3b 20 */. int fJail;
1930: 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 /*
1940: 54 72 75 65 20 69 66 20 72 75 6e 6e 69 6e 67 20 True if running
1950: 77 69 74 68 20 61 20 63 68 72 6f 6f 74 20 6a 61 with a chroot ja
1960: 69 6c 20 2a 2f 0a 20 20 69 6e 74 20 66 48 74 74 il */. int fHtt
1970: 70 54 72 61 63 65 3b 20 20 20 20 20 20 20 20 20 pTrace;
1980: 2f 2a 20 54 72 61 63 65 20 6f 75 74 62 6f 75 6e /* Trace outboun
1990: 64 20 48 54 54 50 20 72 65 71 75 65 73 74 73 20 d HTTP requests
19a0: 2a 2f 0a 20 20 69 6e 74 20 66 41 6e 79 54 72 61 */. int fAnyTra
19b0: 63 65 3b 20 20 20 20 20 20 20 20 20 20 2f 2a 20 ce; /*
19c0: 41 6e 79 20 6b 69 6e 64 20 6f 66 20 74 72 61 63 Any kind of trac
19d0: 69 6e 67 20 2a 2f 0a 20 20 63 68 61 72 20 2a 7a ing */. char *z
19e0: 48 74 74 70 41 75 74 68 3b 20 20 20 20 20 20 20 HttpAuth;
19f0: 20 2f 2a 20 48 54 54 50 20 41 75 74 68 6f 72 69 /* HTTP Authori
1a00: 7a 61 74 69 6f 6e 20 75 73 65 72 3a 70 61 73 73 zation user:pass
1a10: 20 69 6e 66 6f 72 6d 61 74 69 6f 6e 20 2a 2f 0a information */.
1a20: 20 20 69 6e 74 20 66 53 79 73 74 65 6d 54 72 61 int fSystemTra
1a30: 63 65 3b 20 20 20 20 20 20 20 2f 2a 20 54 72 61 ce; /* Tra
1a40: 63 65 20 63 61 6c 6c 73 20 74 6f 20 66 6f 73 73 ce calls to foss
1a50: 69 6c 5f 73 79 73 74 65 6d 28 29 2c 20 2d 2d 73 il_system(), --s
1a60: 79 73 74 65 6d 74 72 61 63 65 20 2a 2f 0a 20 20 ystemtrace */.
1a70: 69 6e 74 20 66 53 73 68 54 72 61 63 65 3b 20 20 int fSshTrace;
1a80: 20 20 20 20 20 20 20 20 2f 2a 20 54 72 61 63 65 /* Trace
1a90: 20 74 68 65 20 53 53 48 20 73 65 74 75 70 20 74 the SSH setup t
1aa0: 72 61 66 66 69 63 20 2a 2f 0a 20 20 69 6e 74 20 raffic */. int
1ab0: 66 53 73 68 43 6c 69 65 6e 74 3b 20 20 20 20 20 fSshClient;
1ac0: 20 20 20 20 2f 2a 20 48 54 54 50 20 63 6c 69 65 /* HTTP clie
1ad0: 6e 74 20 66 6c 61 67 73 20 66 6f 72 20 53 53 48 nt flags for SSH
1ae0: 20 63 6c 69 65 6e 74 20 2a 2f 0a 20 20 63 68 61 client */. cha
1af0: 72 20 2a 7a 53 73 68 43 6d 64 3b 20 20 20 20 20 r *zSshCmd;
1b00: 20 20 20 20 20 2f 2a 20 53 53 48 20 63 6f 6d 6d /* SSH comm
1b10: 61 6e 64 20 73 74 72 69 6e 67 20 2a 2f 0a 20 20 and string */.
1b20: 69 6e 74 20 66 4e 6f 53 79 6e 63 3b 20 20 20 20 int fNoSync;
1b30: 20 20 20 20 20 20 20 20 2f 2a 20 44 6f 20 6e 6f /* Do no
1b40: 74 20 64 6f 20 61 6e 20 61 75 74 6f 73 79 6e 63 t do an autosync
1b50: 20 65 76 65 72 2e 20 20 2d 2d 6e 6f 73 79 6e 63 ever. --nosync
1b60: 20 2a 2f 0a 20 20 69 6e 74 20 66 49 50 76 34 3b */. int fIPv4;
1b70: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a /*
1b80: 20 55 73 65 20 6f 6e 6c 79 20 49 50 76 34 2c 20 Use only IPv4,
1b90: 6e 6f 74 20 49 50 76 36 2e 20 2d 2d 69 70 76 34 not IPv6. --ipv4
1ba0: 20 2a 2f 0a 20 20 63 68 61 72 20 2a 7a 50 61 74 */. char *zPat
1bb0: 68 3b 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a h; /*
1bc0: 20 4e 61 6d 65 20 6f 66 20 77 65 62 70 61 67 65 Name of webpage
1bd0: 20 62 65 69 6e 67 20 73 65 72 76 65 64 20 2a 2f being served */
1be0: 0a 20 20 63 68 61 72 20 2a 7a 45 78 74 72 61 3b . char *zExtra;
1bf0: 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 45 78 /* Ex
1c00: 74 72 61 20 70 61 74 68 20 69 6e 66 6f 72 6d 61 tra path informa
1c10: 74 69 6f 6e 20 70 61 73 74 20 74 68 65 20 77 65 tion past the we
1c20: 62 70 61 67 65 20 6e 61 6d 65 20 2a 2f 0a 20 20 bpage name */.
1c30: 63 68 61 72 20 2a 7a 42 61 73 65 55 52 4c 3b 20 char *zBaseURL;
1c40: 20 20 20 20 20 20 20 20 2f 2a 20 46 75 6c 6c 20 /* Full
1c50: 74 65 78 74 20 6f 66 20 74 68 65 20 55 52 4c 20 text of the URL
1c60: 62 65 69 6e 67 20 73 65 72 76 65 64 20 2a 2f 0a being served */.
1c70: 20 20 63 68 61 72 20 2a 7a 48 74 74 70 73 55 52 char *zHttpsUR
1c80: 4c 3b 20 20 20 20 20 20 20 20 2f 2a 20 7a 42 61 L; /* zBa
1c90: 73 65 55 52 4c 20 74 72 61 6e 73 6c 61 74 65 64 seURL translated
1ca0: 20 74 6f 20 68 74 74 70 73 3a 20 2a 2f 0a 20 20 to https: */.
1cb0: 63 68 61 72 20 2a 7a 54 6f 70 3b 20 20 20 20 20 char *zTop;
1cc0: 20 20 20 20 20 20 20 20 2f 2a 20 50 61 72 65 6e /* Paren
1cd0: 74 20 64 69 72 65 63 74 6f 72 79 20 6f 66 20 7a t directory of z
1ce0: 50 61 74 68 20 2a 2f 0a 20 20 63 6f 6e 73 74 20 Path */. const
1cf0: 63 68 61 72 20 2a 7a 43 6f 6e 74 65 6e 74 54 79 char *zContentTy
1d00: 70 65 3b 20 20 2f 2a 20 54 68 65 20 63 6f 6e 74 pe; /* The cont
1d10: 65 6e 74 20 74 79 70 65 20 6f 66 20 74 68 65 20 ent type of the
1d20: 69 6e 70 75 74 20 48 54 54 50 20 72 65 71 75 65 input HTTP reque
1d30: 73 74 20 2a 2f 0a 20 20 69 6e 74 20 69 45 72 72 st */. int iErr
1d40: 50 72 69 6f 72 69 74 79 3b 20 20 20 20 20 20 20 Priority;
1d50: 2f 2a 20 50 72 69 6f 72 69 74 79 20 6f 66 20 63 /* Priority of c
1d60: 75 72 72 65 6e 74 20 65 72 72 6f 72 20 6d 65 73 urrent error mes
1d70: 73 61 67 65 20 2a 2f 0a 20 20 63 68 61 72 20 2a sage */. char *
1d80: 7a 45 72 72 4d 73 67 3b 20 20 20 20 20 20 20 20 zErrMsg;
1d90: 20 20 2f 2a 20 54 65 78 74 20 6f 66 20 61 6e 20 /* Text of an
1da0: 65 72 72 6f 72 20 6d 65 73 73 61 67 65 20 2a 2f error message */
1db0: 0a 20 20 69 6e 74 20 73 73 6c 4e 6f 74 41 76 61 . int sslNotAva
1dc0: 69 6c 61 62 6c 65 3b 20 20 20 20 2f 2a 20 53 53 ilable; /* SS
1dd0: 4c 20 69 73 20 6e 6f 74 20 61 76 61 69 6c 61 62 L is not availab
1de0: 6c 65 2e 20 20 44 6f 20 6e 6f 74 20 72 65 64 69 le. Do not redi
1df0: 72 65 63 74 20 74 6f 20 68 74 74 70 73 3a 20 2a rect to https: *
1e00: 2f 0a 20 20 42 6c 6f 62 20 63 67 69 49 6e 3b 20 /. Blob cgiIn;
1e10: 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 49 /* I
1e20: 6e 70 75 74 20 74 6f 20 61 6e 20 78 66 65 72 20 nput to an xfer
1e30: 77 77 77 20 6d 65 74 68 6f 64 20 2a 2f 0a 20 20 www method */.
1e40: 69 6e 74 20 63 67 69 4f 75 74 70 75 74 3b 20 20 int cgiOutput;
1e50: 20 20 20 20 20 20 20 20 2f 2a 20 57 72 69 74 65 /* Write
1e60: 20 65 72 72 6f 72 20 61 6e 64 20 73 74 61 74 75 error and statu
1e70: 73 20 6d 65 73 73 61 67 65 73 20 74 6f 20 43 47 s messages to CG
1e80: 49 20 2a 2f 0a 20 20 69 6e 74 20 78 66 65 72 50 I */. int xferP
1e90: 61 6e 69 63 3b 20 20 20 20 20 20 20 20 20 20 2f anic; /
1ea0: 2a 20 57 72 69 74 65 20 65 72 72 6f 72 20 6d 65 * Write error me
1eb0: 73 73 61 67 65 73 20 69 6e 20 58 46 45 52 20 70 ssages in XFER p
1ec0: 72 6f 74 6f 63 6f 6c 20 2a 2f 0a 20 20 69 6e 74 rotocol */. int
1ed0: 20 66 75 6c 6c 48 74 74 70 52 65 70 6c 79 3b 20 fullHttpReply;
1ee0: 20 20 20 20 20 2f 2a 20 54 72 75 65 20 66 6f 72 /* True for
1ef0: 20 66 75 6c 6c 20 48 54 54 50 20 72 65 70 6c 79 full HTTP reply
1f00: 2e 20 20 46 61 6c 73 65 20 66 6f 72 20 43 47 49 . False for CGI
1f10: 20 72 65 70 6c 79 20 2a 2f 0a 20 20 54 68 5f 49 reply */. Th_I
1f20: 6e 74 65 72 70 20 2a 69 6e 74 65 72 70 3b 20 20 nterp *interp;
1f30: 20 20 20 20 2f 2a 20 54 68 65 20 54 48 31 20 69 /* The TH1 i
1f40: 6e 74 65 72 70 72 65 74 65 72 20 2a 2f 0a 20 20 nterpreter */.
1f50: 63 68 61 72 20 2a 74 68 31 53 65 74 75 70 3b 20 char *th1Setup;
1f60: 20 20 20 20 20 20 20 20 2f 2a 20 54 68 65 20 54 /* The T
1f70: 48 31 20 70 6f 73 74 2d 63 72 65 61 74 69 6f 6e H1 post-creation
1f80: 20 73 65 74 75 70 20 73 63 72 69 70 74 2c 20 69 setup script, i
1f90: 66 20 61 6e 79 20 2a 2f 0a 20 20 69 6e 74 20 74 f any */. int t
1fa0: 68 31 46 6c 61 67 73 3b 20 20 20 20 20 20 20 20 h1Flags;
1fb0: 20 20 20 2f 2a 20 54 68 65 20 54 48 31 20 69 6e /* The TH1 in
1fc0: 74 65 67 72 61 74 69 6f 6e 20 73 74 61 74 65 20 tegration state
1fd0: 66 6c 61 67 73 20 2a 2f 0a 20 20 46 49 4c 45 20 flags */. FILE
1fe0: 2a 68 74 74 70 49 6e 3b 20 20 20 20 20 20 20 20 *httpIn;
1ff0: 20 20 20 2f 2a 20 41 63 63 65 70 74 20 48 54 54 /* Accept HTT
2000: 50 20 69 6e 70 75 74 20 66 72 6f 6d 20 68 65 72 P input from her
2010: 65 20 2a 2f 0a 20 20 46 49 4c 45 20 2a 68 74 74 e */. FILE *htt
2020: 70 4f 75 74 3b 20 20 20 20 20 20 20 20 20 20 2f pOut; /
2030: 2a 20 53 65 6e 64 20 48 54 54 50 20 6f 75 74 70 * Send HTTP outp
2040: 75 74 20 68 65 72 65 20 2a 2f 0a 20 20 69 6e 74 ut here */. int
2050: 20 78 6c 69 6e 6b 43 6c 75 73 74 65 72 4f 6e 6c xlinkClusterOnl
2060: 79 3b 20 20 20 2f 2a 20 53 65 74 20 77 68 65 6e y; /* Set when
2070: 20 63 6c 6f 6e 69 6e 67 2e 20 20 4f 6e 6c 79 20 cloning. Only
2080: 70 72 6f 63 65 73 73 20 63 6c 75 73 74 65 72 73 process clusters
2090: 20 2a 2f 0a 20 20 69 6e 74 20 66 54 69 6d 65 46 */. int fTimeF
20a0: 6f 72 6d 61 74 3b 20 20 20 20 20 20 20 20 2f 2a ormat; /*
20b0: 20 31 20 66 6f 72 20 55 54 43 2e 20 20 32 20 66 1 for UTC. 2 f
20c0: 6f 72 20 6c 6f 63 61 6c 74 69 6d 65 2e 20 20 30 or localtime. 0
20d0: 20 6e 6f 74 20 79 65 74 20 73 65 6c 65 63 74 65 not yet selecte
20e0: 64 20 2a 2f 0a 20 20 69 6e 74 20 2a 61 43 6f 6d d */. int *aCom
20f0: 6d 69 74 46 69 6c 65 3b 20 20 20 20 20 20 20 2f mitFile; /
2100: 2a 20 41 72 72 61 79 20 6f 66 20 66 69 6c 65 73 * Array of files
2110: 20 74 6f 20 62 65 20 63 6f 6d 6d 69 74 74 65 64 to be committed
2120: 20 2a 2f 0a 20 20 69 6e 74 20 6d 61 72 6b 50 72 */. int markPr
2130: 69 76 61 74 65 3b 20 20 20 20 20 20 20 20 2f 2a ivate; /*
2140: 20 41 6c 6c 20 6e 65 77 20 61 72 74 69 66 61 63 All new artifac
2150: 74 73 20 61 72 65 20 70 72 69 76 61 74 65 20 69 ts are private i
2160: 66 20 74 72 75 65 20 2a 2f 0a 20 20 69 6e 74 20 f true */. int
2170: 63 6c 6f 63 6b 53 6b 65 77 53 65 65 6e 3b 20 20 clockSkewSeen;
2180: 20 20 20 20 2f 2a 20 54 72 75 65 20 69 66 20 63 /* True if c
2190: 6c 6f 63 6b 73 20 6f 6e 20 63 6c 69 65 6e 74 20 locks on client
21a0: 61 6e 64 20 73 65 72 76 65 72 20 6f 75 74 20 6f and server out o
21b0: 66 20 73 79 6e 63 20 2a 2f 0a 20 20 69 6e 74 20 f sync */. int
21c0: 77 69 6b 69 46 6c 61 67 73 3b 20 20 20 20 20 20 wikiFlags;
21d0: 20 20 20 20 2f 2a 20 57 69 6b 69 20 63 6f 6e 76 /* Wiki conv
21e0: 65 72 73 69 6f 6e 20 66 6c 61 67 73 20 61 70 70 ersion flags app
21f0: 6c 69 65 64 20 74 6f 20 25 57 20 2a 2f 0a 20 20 lied to %W */.
2200: 63 68 61 72 20 69 73 48 54 54 50 3b 20 20 20 20 char isHTTP;
2210: 20 20 20 20 20 20 20 20 2f 2a 20 54 72 75 65 20 /* True
2220: 69 66 20 73 65 72 76 65 72 2f 43 47 49 20 6d 6f if server/CGI mo
2230: 64 65 73 2c 20 65 6c 73 65 20 61 73 73 75 6d 65 des, else assume
2240: 20 43 4c 49 2e 20 2a 2f 0a 20 20 63 68 61 72 20 CLI. */. char
2250: 6a 61 76 61 73 63 72 69 70 74 48 79 70 65 72 6c javascriptHyperl
2260: 69 6e 6b 3b 20 2f 2a 20 49 66 20 74 72 75 65 2c ink; /* If true,
2270: 20 73 65 74 20 68 72 65 66 3d 20 75 73 69 6e 67 set href= using
2280: 20 73 63 72 69 70 74 2c 20 6e 6f 74 20 48 54 4d script, not HTM
2290: 4c 20 2a 2f 0a 20 20 42 6c 6f 62 20 68 74 74 70 L */. Blob http
22a0: 48 65 61 64 65 72 3b 20 20 20 20 20 20 20 20 2f Header; /
22b0: 2a 20 43 6f 6d 70 6c 65 74 65 20 74 65 78 74 20 * Complete text
22c0: 6f 66 20 74 68 65 20 48 54 54 50 20 72 65 71 75 of the HTTP requ
22d0: 65 73 74 20 68 65 61 64 65 72 20 2a 2f 0a 20 20 est header */.
22e0: 55 72 6c 44 61 74 61 20 75 72 6c 3b 20 20 20 20 UrlData url;
22f0: 20 20 20 20 20 20 20 20 2f 2a 20 49 6e 66 6f 72 /* Infor
2300: 6d 61 74 69 6f 6e 20 61 62 6f 75 74 20 63 75 72 mation about cur
2310: 72 65 6e 74 20 55 52 4c 20 2a 2f 0a 20 20 63 6f rent URL */. co
2320: 6e 73 74 20 63 68 61 72 20 2a 7a 4c 6f 67 69 6e nst char *zLogin
2330: 3b 20 20 20 20 20 2f 2a 20 4c 6f 67 69 6e 20 6e ; /* Login n
2340: 61 6d 65 2e 20 20 4e 55 4c 4c 20 6f 72 20 22 22 ame. NULL or ""
2350: 20 69 66 20 6e 6f 74 20 6c 6f 67 67 65 64 20 69 if not logged i
2360: 6e 2e 20 2a 2f 0a 20 20 63 6f 6e 73 74 20 63 68 n. */. const ch
2370: 61 72 20 2a 7a 53 53 4c 49 64 65 6e 74 69 74 79 ar *zSSLIdentity
2380: 3b 20 20 2f 2a 20 56 61 6c 75 65 20 6f 66 20 2d ; /* Value of -
2390: 2d 73 73 6c 2d 69 64 65 6e 74 69 74 79 20 6f 70 -ssl-identity op
23a0: 74 69 6f 6e 2c 20 66 69 6c 65 6e 61 6d 65 20 6f tion, filename o
23b0: 66 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 f.
23c0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2a *
23d0: 2a 20 53 53 4c 20 63 6c 69 65 6e 74 20 69 64 65 * SSL client ide
23e0: 6e 74 69 74 79 20 2a 2f 0a 20 20 69 6e 74 20 75 ntity */. int u
23f0: 73 65 4c 6f 63 61 6c 61 75 74 68 3b 20 20 20 20 seLocalauth;
2400: 20 20 20 2f 2a 20 4e 6f 20 6c 6f 67 69 6e 20 72 /* No login r
2410: 65 71 75 69 72 65 64 20 69 66 20 66 72 6f 6d 20 equired if from
2420: 31 32 37 2e 30 2e 30 2e 31 20 2a 2f 0a 20 20 69 127.0.0.1 */. i
2430: 6e 74 20 6e 6f 50 73 77 64 3b 20 20 20 20 20 20 nt noPswd;
2440: 20 20 20 20 20 20 20 2f 2a 20 4c 6f 67 67 65 64 /* Logged
2450: 20 69 6e 20 77 69 74 68 6f 75 74 20 70 61 73 73 in without pass
2460: 77 6f 72 64 20 28 6f 6e 20 31 32 37 2e 30 2e 30 word (on 127.0.0
2470: 2e 31 29 20 2a 2f 0a 20 20 69 6e 74 20 75 73 65 .1) */. int use
2480: 72 55 69 64 3b 20 20 20 20 20 20 20 20 20 20 20 rUid;
2490: 20 2f 2a 20 49 6e 74 65 67 65 72 20 75 73 65 72 /* Integer user
24a0: 20 69 64 20 2a 2f 0a 20 20 69 6e 74 20 69 73 48 id */. int isH
24b0: 75 6d 61 6e 3b 20 20 20 20 20 20 20 20 20 20 20 uman;
24c0: 20 2f 2a 20 54 72 75 65 20 69 66 20 61 63 63 65 /* True if acce
24d0: 73 73 20 62 79 20 61 20 68 75 6d 61 6e 2c 20 6e ss by a human, n
24e0: 6f 74 20 61 20 73 70 69 64 65 72 20 6f 72 20 62 ot a spider or b
24f0: 6f 74 20 2a 2f 0a 20 20 69 6e 74 20 63 6f 6d 46 ot */. int comF
2500: 6d 74 46 6c 61 67 73 3b 20 20 20 20 20 20 20 20 mtFlags;
2510: 2f 2a 20 5a 65 72 6f 20 6f 72 20 6d 6f 72 65 20 /* Zero or more
2520: 22 43 4f 4d 4d 45 4e 54 5f 50 52 49 4e 54 5f 2a "COMMENT_PRINT_*
2530: 22 20 62 69 74 20 66 6c 61 67 73 20 2a 2f 0a 0a " bit flags */..
2540: 20 20 2f 2a 20 49 6e 66 6f 72 6d 61 74 69 6f 6e /* Information
2550: 20 75 73 65 64 20 74 6f 20 70 6f 70 75 6c 61 74 used to populat
2560: 65 20 74 68 65 20 52 43 56 46 52 4f 4d 20 74 61 e the RCVFROM ta
2570: 62 6c 65 20 2a 2f 0a 20 20 69 6e 74 20 72 63 76 ble */. int rcv
2580: 69 64 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 id;
2590: 20 2f 2a 20 54 68 65 20 72 63 76 69 64 2e 20 20 /* The rcvid.
25a0: 30 20 69 66 20 6e 6f 74 20 79 65 74 20 64 65 66 0 if not yet def
25b0: 69 6e 65 64 2e 20 2a 2f 0a 20 20 63 68 61 72 20 ined. */. char
25c0: 2a 7a 49 70 41 64 64 72 3b 20 20 20 20 20 20 20 *zIpAddr;
25d0: 20 20 20 2f 2a 20 54 68 65 20 72 65 6d 6f 74 65 /* The remote
25e0: 20 49 50 20 61 64 64 72 65 73 73 20 2a 2f 0a 20 IP address */.
25f0: 20 63 68 61 72 20 2a 7a 4e 6f 6e 63 65 3b 20 20 char *zNonce;
2600: 20 20 20 20 20 20 20 20 20 2f 2a 20 54 68 65 20 /* The
2610: 6e 6f 6e 63 65 20 75 73 65 64 20 66 6f 72 20 6c nonce used for l
2620: 6f 67 69 6e 20 2a 2f 0a 0a 20 20 2f 2a 20 70 65 ogin */.. /* pe
2630: 72 6d 69 73 73 69 6f 6e 73 20 61 76 61 69 6c 61 rmissions availa
2640: 62 6c 65 20 74 6f 20 63 75 72 72 65 6e 74 20 75 ble to current u
2650: 73 65 72 20 2a 2f 0a 20 20 73 74 72 75 63 74 20 ser */. struct
2660: 46 6f 73 73 69 6c 55 73 65 72 50 65 72 6d 73 20 FossilUserPerms
2670: 70 65 72 6d 3b 0a 0a 20 20 2f 2a 20 70 65 72 6d perm;.. /* perm
2680: 69 73 73 69 6f 6e 73 20 61 76 61 69 6c 61 62 6c issions availabl
2690: 65 20 74 6f 20 63 75 72 72 65 6e 74 20 75 73 65 e to current use
26a0: 72 20 6f 72 20 74 6f 20 22 61 6e 6f 6e 79 6d 6f r or to "anonymo
26b0: 75 73 22 2e 0a 20 20 2a 2a 20 54 68 69 73 20 69 us".. ** This i
26c0: 73 20 74 68 65 20 6c 6f 67 69 63 61 6c 20 75 6e s the logical un
26d0: 69 6f 6e 20 6f 66 20 70 65 72 6d 20 70 65 72 6d ion of perm perm
26e0: 69 73 73 69 6f 6e 73 20 61 62 6f 76 65 20 77 69 issions above wi
26f0: 74 68 0a 20 20 2a 2a 20 74 68 65 20 76 61 6c 75 th. ** the valu
2700: 65 20 74 68 61 74 20 70 65 72 6d 20 77 6f 75 6c e that perm woul
2710: 64 20 74 61 6b 65 20 69 66 20 67 2e 7a 4c 6f 67 d take if g.zLog
2720: 69 6e 20 77 65 72 65 20 22 61 6e 6f 6e 79 6d 6f in were "anonymo
2730: 75 73 22 2e 20 2a 2f 0a 20 20 73 74 72 75 63 74 us". */. struct
2740: 20 46 6f 73 73 69 6c 55 73 65 72 50 65 72 6d 73 FossilUserPerms
2750: 20 61 6e 6f 6e 3b 0a 0a 23 69 66 64 65 66 20 46 anon;..#ifdef F
2760: 4f 53 53 49 4c 5f 45 4e 41 42 4c 45 5f 54 43 4c OSSIL_ENABLE_TCL
2770: 0a 20 20 2f 2a 20 61 6c 6c 20 54 63 6c 20 72 65 . /* all Tcl re
2780: 6c 61 74 65 64 20 63 6f 6e 74 65 78 74 20 6e 65 lated context ne
2790: 63 65 73 73 61 72 79 20 66 6f 72 20 69 6e 74 65 cessary for inte
27a0: 67 72 61 74 69 6f 6e 20 2a 2f 0a 20 20 73 74 72 gration */. str
27b0: 75 63 74 20 54 63 6c 43 6f 6e 74 65 78 74 20 74 uct TclContext t
27c0: 63 6c 3b 0a 23 65 6e 64 69 66 0a 0a 20 20 2f 2a cl;.#endif.. /*
27d0: 20 46 6f 72 20 64 65 66 65 6e 73 65 20 61 67 61 For defense aga
27e0: 69 6e 73 74 20 43 72 6f 73 73 2d 73 69 74 65 20 inst Cross-site
27f0: 52 65 71 75 65 73 74 20 46 6f 72 67 65 72 79 20 Request Forgery
2800: 61 74 74 61 63 6b 73 20 2a 2f 0a 20 20 63 68 61 attacks */. cha
2810: 72 20 7a 43 73 72 66 54 6f 6b 65 6e 5b 31 32 5d r zCsrfToken[12]
2820: 3b 20 20 20 20 2f 2a 20 56 61 6c 75 65 20 6f 66 ; /* Value of
2830: 20 74 68 65 20 61 6e 74 69 2d 43 53 52 46 20 74 the anti-CSRF t
2840: 6f 6b 65 6e 20 2a 2f 0a 20 20 69 6e 74 20 6f 6b oken */. int ok
2850: 43 73 72 66 3b 20 20 20 20 20 20 20 20 20 20 20 Csrf;
2860: 20 20 2f 2a 20 41 6e 74 69 2d 43 53 52 46 20 74 /* Anti-CSRF t
2870: 6f 6b 65 6e 20 69 73 20 70 72 65 73 65 6e 74 20 oken is present
2880: 61 6e 64 20 76 61 6c 69 64 20 2a 2f 0a 0a 20 20 and valid */..
2890: 69 6e 74 20 70 61 72 73 65 43 6e 74 5b 31 30 5d int parseCnt[10]
28a0: 3b 20 20 20 20 20 20 20 2f 2a 20 43 6f 75 6e 74 ; /* Count
28b0: 73 20 6f 66 20 61 72 74 69 66 61 63 74 73 20 70 s of artifacts p
28c0: 61 72 73 65 64 20 2a 2f 0a 20 20 46 49 4c 45 20 arsed */. FILE
28d0: 2a 66 44 65 62 75 67 3b 20 20 20 20 20 20 20 20 *fDebug;
28e0: 20 20 20 2f 2a 20 57 72 69 74 65 20 64 65 62 75 /* Write debu
28f0: 67 20 69 6e 66 6f 72 6d 61 74 69 6f 6e 20 68 65 g information he
2900: 72 65 2c 20 69 66 20 74 68 65 20 66 69 6c 65 20 re, if the file
2910: 65 78 69 73 74 73 20 2a 2f 0a 23 69 66 64 65 66 exists */.#ifdef
2920: 20 46 4f 53 53 49 4c 5f 45 4e 41 42 4c 45 5f 54 FOSSIL_ENABLE_T
2930: 48 31 5f 48 4f 4f 4b 53 0a 20 20 69 6e 74 20 66 H1_HOOKS. int f
2940: 4e 6f 54 68 48 6f 6f 6b 3b 20 20 20 20 20 20 20 NoThHook;
2950: 20 20 20 2f 2a 20 44 69 73 61 62 6c 65 20 61 6c /* Disable al
2960: 6c 20 54 48 31 20 63 6f 6d 6d 61 6e 64 2f 77 65 l TH1 command/we
2970: 62 70 61 67 65 20 68 6f 6f 6b 73 20 2a 2f 0a 23 bpage hooks */.#
2980: 65 6e 64 69 66 0a 20 20 69 6e 74 20 74 68 54 72 endif. int thTr
2990: 61 63 65 3b 20 20 20 20 20 20 20 20 20 20 20 20 ace;
29a0: 2f 2a 20 54 72 75 65 20 74 6f 20 65 6e 61 62 6c /* True to enabl
29b0: 65 20 54 48 31 20 64 65 62 75 67 67 69 6e 67 20 e TH1 debugging
29c0: 6f 75 74 70 75 74 20 2a 2f 0a 20 20 42 6c 6f 62 output */. Blob
29d0: 20 74 68 4c 6f 67 3b 20 20 20 20 20 20 20 20 20 thLog;
29e0: 20 20 20 20 2f 2a 20 54 65 78 74 20 6f 66 20 74 /* Text of t
29f0: 68 65 20 54 48 31 20 64 65 62 75 67 67 69 6e 67 he TH1 debugging
2a00: 20 6f 75 74 70 75 74 20 2a 2f 0a 0a 20 20 69 6e output */.. in
2a10: 74 20 69 73 48 6f 6d 65 3b 20 20 20 20 20 20 20 t isHome;
2a20: 20 20 20 20 20 20 2f 2a 20 54 72 75 65 20 69 66 /* True if
2a30: 20 72 65 6e 64 65 72 69 6e 67 20 74 68 65 20 22 rendering the "
2a40: 68 6f 6d 65 22 20 70 61 67 65 20 2a 2f 0a 0a 20 home" page */..
2a50: 20 2f 2a 20 53 74 6f 72 61 67 65 20 66 6f 72 20 /* Storage for
2a60: 74 68 65 20 61 75 78 28 29 20 61 6e 64 2f 6f 72 the aux() and/or
2a70: 20 6f 70 74 69 6f 6e 28 29 20 53 51 4c 20 66 75 option() SQL fu
2a80: 6e 63 74 69 6f 6e 20 61 72 67 75 6d 65 6e 74 73 nction arguments
2a90: 20 2a 2f 0a 20 20 69 6e 74 20 6e 41 75 78 3b 20 */. int nAux;
2aa0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
2ab0: 20 20 20 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 20 /* Number of
2ac0: 64 69 73 74 69 6e 63 74 20 61 75 78 28 29 20 6f distinct aux() o
2ad0: 72 20 6f 70 74 69 6f 6e 28 29 20 76 61 6c 75 65 r option() value
2ae0: 73 20 2a 2f 0a 20 20 63 6f 6e 73 74 20 63 68 61 s */. const cha
2af0: 72 20 2a 61 7a 41 75 78 4e 61 6d 65 5b 4d 58 5f r *azAuxName[MX_
2b00: 41 55 58 5d 3b 20 2f 2a 20 4e 61 6d 65 20 6f 66 AUX]; /* Name of
2b10: 20 65 61 63 68 20 61 75 78 28 29 20 6f 72 20 6f each aux() or o
2b20: 70 74 69 6f 6e 28 29 20 76 61 6c 75 65 20 2a 2f ption() value */
2b30: 0a 20 20 63 68 61 72 20 2a 61 7a 41 75 78 50 61 . char *azAuxPa
2b40: 72 61 6d 5b 4d 58 5f 41 55 58 5d 3b 20 20 20 20 ram[MX_AUX];
2b50: 20 20 2f 2a 20 50 61 72 61 6d 20 6f 66 20 65 61 /* Param of ea
2b60: 63 68 20 61 75 78 28 29 20 6f 72 20 6f 70 74 69 ch aux() or opti
2b70: 6f 6e 28 29 20 76 61 6c 75 65 20 2a 2f 0a 20 20 on() value */.
2b80: 63 6f 6e 73 74 20 63 68 61 72 20 2a 61 7a 41 75 const char *azAu
2b90: 78 56 61 6c 5b 4d 58 5f 41 55 58 5d 3b 20 20 2f xVal[MX_AUX]; /
2ba0: 2a 20 56 61 6c 75 65 20 6f 66 20 65 61 63 68 20 * Value of each
2bb0: 61 75 78 28 29 20 6f 72 20 6f 70 74 69 6f 6e 28 aux() or option(
2bc0: 29 20 76 61 6c 75 65 20 2a 2f 0a 20 20 63 6f 6e ) value */. con
2bd0: 73 74 20 63 68 61 72 20 2a 2a 61 7a 41 75 78 4f st char **azAuxO
2be0: 70 74 5b 4d 58 5f 41 55 58 5d 3b 20 2f 2a 20 4f pt[MX_AUX]; /* O
2bf0: 70 74 69 6f 6e 73 20 6f 66 20 65 61 63 68 20 6f ptions of each o
2c00: 70 74 69 6f 6e 28 29 20 76 61 6c 75 65 20 2a 2f ption() value */
2c10: 0a 20 20 69 6e 74 20 61 6e 41 75 78 43 6f 6c 73 . int anAuxCols
2c20: 5b 4d 58 5f 41 55 58 5d 3b 20 20 20 20 20 20 20 [MX_AUX];
2c30: 20 20 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 20 63 /* Number of c
2c40: 6f 6c 75 6d 6e 73 20 66 6f 72 20 6f 70 74 69 6f olumns for optio
2c50: 6e 28 29 20 76 61 6c 75 65 73 20 2a 2f 0a 0a 20 n() values */..
2c60: 20 69 6e 74 20 61 6c 6c 6f 77 53 79 6d 6c 69 6e int allowSymlin
2c70: 6b 73 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 ks;
2c80: 2f 2a 20 43 61 63 68 65 64 20 22 61 6c 6c 6f 77 /* Cached "allow
2c90: 2d 73 79 6d 6c 69 6e 6b 73 22 20 6f 70 74 69 6f -symlinks" optio
2ca0: 6e 20 2a 2f 0a 0a 20 20 69 6e 74 20 6d 61 69 6e n */.. int main
2cb0: 54 69 6d 65 72 49 64 3b 20 20 20 20 20 20 20 20 TimerId;
2cc0: 20 20 20 20 20 20 20 2f 2a 20 53 65 74 20 74 6f /* Set to
2cd0: 20 66 6f 73 73 69 6c 5f 74 69 6d 65 72 5f 73 74 fossil_timer_st
2ce0: 61 72 74 28 29 20 2a 2f 0a 23 69 66 64 65 66 20 art() */.#ifdef
2cf0: 46 4f 53 53 49 4c 5f 45 4e 41 42 4c 45 5f 4a 53 FOSSIL_ENABLE_JS
2d00: 4f 4e 0a 20 20 73 74 72 75 63 74 20 46 6f 73 73 ON. struct Foss
2d10: 69 6c 4a 73 6f 6e 42 69 74 73 20 7b 0a 20 20 20 ilJsonBits {.
2d20: 20 69 6e 74 20 69 73 4a 73 6f 6e 4d 6f 64 65 3b int isJsonMode;
2d30: 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 54 /* T
2d40: 72 75 65 20 69 66 20 72 75 6e 6e 69 6e 67 20 69 rue if running i
2d50: 6e 20 4a 53 4f 4e 20 6d 6f 64 65 2c 20 65 6c 73 n JSON mode, els
2d60: 65 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 e.
2d70: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
2d80: 20 20 20 20 66 61 6c 73 65 2e 20 54 68 69 73 20 false. This
2d90: 63 68 61 6e 67 65 73 20 68 6f 77 20 65 72 72 6f changes how erro
2da0: 72 73 20 61 72 65 0a 20 20 20 20 20 20 20 20 20 rs are.
2db0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
2dc0: 20 20 20 20 20 20 20 20 20 72 65 70 6f 72 74 65 reporte
2dd0: 64 2e 20 49 6e 20 4a 53 4f 4e 20 6d 6f 64 65 20 d. In JSON mode
2de0: 77 65 20 74 72 79 20 74 6f 0a 20 20 20 20 20 20 we try to.
2df0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
2e00: 20 20 20 20 20 20 20 20 20 20 20 20 61 6c 77 61 alwa
2e10: 79 73 20 6f 75 74 70 75 74 20 4a 53 4f 4e 2d 66 ys output JSON-f
2e20: 6f 72 6d 20 65 72 72 6f 72 0a 20 20 20 20 20 20 orm error.
2e30: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
2e40: 20 20 20 20 20 20 20 20 20 20 20 20 72 65 73 70 resp
2e50: 6f 6e 73 65 73 20 61 6e 64 20 61 6c 77 61 79 73 onses and always
2e60: 20 65 78 69 74 28 29 20 77 69 74 68 0a 20 20 20 exit() with.
2e70: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
2e80: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 63 c
2e90: 6f 64 65 20 30 20 74 6f 20 61 76 6f 69 64 20 61 ode 0 to avoid a
2ea0: 6e 20 48 54 54 50 20 35 30 30 20 65 72 72 6f 72 n HTTP 500 error
2eb0: 2e 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 ..
2ec0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
2ed0: 20 2a 2f 0a 20 20 20 20 69 6e 74 20 72 65 73 75 */. int resu
2ee0: 6c 74 43 6f 64 65 3b 20 20 20 20 20 20 20 20 20 ltCode;
2ef0: 20 20 20 2f 2a 20 75 73 65 64 20 66 6f 72 20 70 /* used for p
2f00: 61 73 73 69 6e 67 20 62 61 63 6b 20 73 70 65 63 assing back spec
2f10: 69 66 69 63 20 63 6f 64 65 73 0a 20 20 20 20 20 ific codes.
2f20: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
2f30: 20 20 20 20 20 20 20 20 20 20 2a 2a 20 66 72 6f ** fro
2f40: 6d 20 2f 6a 73 6f 6e 20 63 61 6c 6c 62 61 63 6b m /json callback
2f50: 73 2e 20 2a 2f 0a 20 20 20 20 69 6e 74 20 65 72 s. */. int er
2f60: 72 6f 72 44 65 74 61 69 6c 50 61 72 61 6e 6f 69 rorDetailParanoi
2f70: 61 3b 20 20 20 2f 2a 20 30 3d 66 75 6c 6c 20 65 a; /* 0=full e
2f80: 72 72 6f 72 20 63 6f 64 65 73 2c 20 31 3d 25 31 rror codes, 1=%1
2f90: 30 2c 20 32 3d 25 31 30 30 2c 20 33 3d 25 31 30 0, 2=%100, 3=%10
2fa0: 30 30 20 2a 2f 0a 20 20 20 20 63 73 6f 6e 5f 6f 00 */. cson_o
2fb0: 75 74 70 75 74 5f 6f 70 74 20 6f 75 74 4f 70 74 utput_opt outOpt
2fc0: 3b 20 20 20 20 2f 2a 20 66 6f 72 6d 61 74 74 69 ; /* formatti
2fd0: 6e 67 20 6f 70 74 69 6f 6e 73 20 66 6f 72 20 4a ng options for J
2fe0: 53 4f 4e 20 6d 6f 64 65 2e 20 2a 2f 0a 20 20 20 SON mode. */.
2ff0: 20 63 73 6f 6e 5f 76 61 6c 75 65 20 2a 61 75 74 cson_value *aut
3000: 68 54 6f 6b 65 6e 3b 20 20 20 20 20 2f 2a 20 61 hToken; /* a
3010: 75 74 68 65 6e 74 69 63 61 74 69 6f 6e 20 74 6f uthentication to
3020: 6b 65 6e 20 2a 2f 0a 20 20 20 20 63 6f 6e 73 74 ken */. const
3030: 20 63 68 61 72 20 2a 6a 73 6f 6e 70 3b 20 20 20 char *jsonp;
3040: 20 20 20 20 20 20 2f 2a 20 4e 61 6d 65 20 6f 66 /* Name of
3050: 20 4a 53 4f 4e 50 20 66 75 6e 63 74 69 6f 6e 20 JSONP function
3060: 77 72 61 70 70 65 72 2e 20 2a 2f 0a 20 20 20 20 wrapper. */.
3070: 75 6e 73 69 67 6e 65 64 20 63 68 61 72 20 64 69 unsigned char di
3080: 73 70 61 74 63 68 44 65 70 74 68 20 2f 2a 20 54 spatchDepth /* T
3090: 65 6c 6c 73 20 4a 53 4f 4e 20 63 6f 6d 6d 61 6e ells JSON comman
30a0: 64 20 64 69 73 70 61 74 63 68 69 6e 67 0a 20 20 d dispatching.
30b0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
30c0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
30d0: 20 77 68 69 63 68 20 61 72 67 75 6d 65 6e 74 20 which argument
30e0: 77 65 20 61 72 65 20 63 75 72 72 65 6e 74 6c 79 we are currently
30f0: 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 .
3100: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
3110: 20 20 20 20 77 6f 72 6b 69 6e 67 20 6f 6e 2e 20 working on.
3120: 46 6f 72 20 74 68 69 73 20 70 75 72 70 6f 73 65 For this purpose
3130: 2c 20 61 72 67 23 30 0a 20 20 20 20 20 20 20 20 , arg#0.
3140: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
3150: 20 20 20 20 20 20 20 20 20 20 20 69 73 20 74 68 is th
3160: 65 20 22 6a 73 6f 6e 22 20 70 61 74 68 2f 43 4c e "json" path/CL
3170: 49 20 61 72 67 2e 0a 20 20 20 20 20 20 20 20 20 I arg..
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 2a 2f 3b 0a 20 20 20 20 73 */;. s
31a0: 74 72 75 63 74 20 7b 20 20 20 20 20 20 20 20 20 truct {
31b0: 20 20 20 20 20 20 20 20 20 20 2f 2a 20 22 67 61 /* "ga
31c0: 72 62 61 67 65 20 63 6f 6c 6c 65 63 74 6f 72 22 rbage collector"
31d0: 20 2a 2f 0a 20 20 20 20 20 20 63 73 6f 6e 5f 76 */. cson_v
31e0: 61 6c 75 65 20 2a 76 3b 0a 20 20 20 20 20 20 63 alue *v;. c
31f0: 73 6f 6e 5f 61 72 72 61 79 20 2a 61 3b 0a 20 20 son_array *a;.
3200: 20 20 7d 20 67 63 3b 0a 20 20 20 20 73 74 72 75 } gc;. stru
3210: 63 74 20 7b 20 20 20 20 20 20 20 20 20 20 20 20 ct {
3220: 20 20 20 20 20 20 20 2f 2a 20 4a 53 4f 4e 20 50 /* JSON P
3230: 4f 53 54 20 64 61 74 61 2e 20 2a 2f 0a 20 20 20 OST data. */.
3240: 20 20 20 63 73 6f 6e 5f 76 61 6c 75 65 20 2a 76 cson_value *v
3250: 3b 0a 20 20 20 20 20 20 63 73 6f 6e 5f 61 72 72 ;. cson_arr
3260: 61 79 20 2a 61 3b 0a 20 20 20 20 20 20 69 6e 74 ay *a;. int
3270: 20 6f 66 66 73 65 74 3b 20 20 20 20 20 20 20 20 offset;
3280: 20 20 20 20 20 20 2f 2a 20 54 65 6c 6c 73 20 75 /* Tells u
3290: 73 20 77 68 69 63 68 20 50 41 54 48 5f 49 4e 46 s which PATH_INF
32a0: 4f 2f 43 4c 49 20 61 72 67 73 0a 20 20 20 20 20 O/CLI args.
32b0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
32c0: 20 20 20 20 20 20 20 20 20 20 20 20 20 70 61 72 par
32d0: 74 20 68 6f 6c 64 73 20 74 68 65 20 22 6a 73 6f t holds the "jso
32e0: 6e 22 20 63 6f 6d 6d 61 6e 64 2c 20 73 6f 0a 20 n" command, so.
32f0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
3300: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
3310: 20 74 68 61 74 20 77 65 20 63 61 6e 20 61 63 63 that we can acc
3320: 6f 75 6e 74 20 66 6f 72 20 73 75 62 2d 72 65 70 ount for sub-rep
3330: 6f 73 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 os.
3340: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
3350: 20 20 20 20 20 61 6e 64 20 70 61 74 68 20 70 72 and path pr
3360: 65 66 69 78 65 73 2e 20 20 54 68 69 73 20 69 73 efixes. This is
3370: 20 68 61 6e 64 6c 65 64 0a 20 20 20 20 20 20 20 handled.
3380: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
3390: 20 20 20 20 20 20 20 20 20 20 20 64 69 66 66 65 diffe
33a0: 72 65 6e 74 6c 79 20 66 6f 72 20 43 4c 49 20 61 rently for CLI a
33b0: 6e 64 20 43 47 49 20 6d 6f 64 65 73 2e 0a 20 20 nd CGI modes..
33c0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
33d0: 20 20 20 20 20 20 20 20 20 20 20 20 20 2a 2f 0a */.
33e0: 20 20 20 20 20 20 63 6f 6e 73 74 20 63 68 61 72 const char
33f0: 20 2a 63 6f 6d 6d 61 6e 64 53 74 72 20 20 20 2f *commandStr /
3400: 2a 22 63 6f 6d 6d 61 6e 64 22 20 72 65 71 75 65 *"command" reque
3410: 73 74 20 70 61 72 61 6d 2e 2a 2f 3b 0a 20 20 20 st param.*/;.
3420: 20 7d 20 63 6d 64 3b 0a 20 20 20 20 73 74 72 75 } cmd;. stru
3430: 63 74 20 7b 20 20 20 20 20 20 20 20 20 20 20 20 ct {
3440: 20 20 20 20 20 20 20 2f 2a 20 4a 53 4f 4e 20 50 /* JSON P
3450: 4f 53 54 20 64 61 74 61 2e 20 2a 2f 0a 20 20 20 OST data. */.
3460: 20 20 20 63 73 6f 6e 5f 76 61 6c 75 65 20 2a 76 cson_value *v
3470: 3b 0a 20 20 20 20 20 20 63 73 6f 6e 5f 6f 62 6a ;. cson_obj
3480: 65 63 74 20 2a 6f 3b 0a 20 20 20 20 7d 20 70 6f ect *o;. } po
3490: 73 74 3b 0a 20 20 20 20 73 74 72 75 63 74 20 7b st;. struct {
34a0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
34b0: 20 20 20 2f 2a 20 47 45 54 2f 43 4f 4f 4b 49 45 /* GET/COOKIE
34c0: 20 70 61 72 61 6d 73 20 69 6e 20 4a 53 4f 4e 20 params in JSON
34d0: 6d 6f 64 65 2e 20 2a 2f 0a 20 20 20 20 20 20 63 mode. */. c
34e0: 73 6f 6e 5f 76 61 6c 75 65 20 2a 76 3b 0a 20 20 son_value *v;.
34f0: 20 20 20 20 63 73 6f 6e 5f 6f 62 6a 65 63 74 20 cson_object
3500: 2a 6f 3b 0a 20 20 20 20 7d 20 70 61 72 61 6d 3b *o;. } param;
3510: 0a 20 20 20 20 73 74 72 75 63 74 20 7b 0a 20 20 . struct {.
3520: 20 20 20 20 63 73 6f 6e 5f 76 61 6c 75 65 20 2a cson_value *
3530: 76 3b 0a 20 20 20 20 20 20 63 73 6f 6e 5f 6f 62 v;. cson_ob
3540: 6a 65 63 74 20 2a 6f 3b 0a 20 20 20 20 7d 20 72 ject *o;. } r
3550: 65 71 50 61 79 6c 6f 61 64 3b 20 20 20 20 20 20 eqPayload;
3560: 20 20 20 20 20 20 20 20 2f 2a 20 72 65 71 75 65 /* reque
3570: 73 74 20 70 61 79 6c 6f 61 64 20 6f 62 6a 65 63 st payload objec
3580: 74 20 28 69 66 20 61 6e 79 29 20 2a 2f 0a 20 20 t (if any) */.
3590: 20 20 63 73 6f 6e 5f 61 72 72 61 79 20 2a 77 61 cson_array *wa
35a0: 72 6e 69 6e 67 73 3b 20 20 20 20 20 20 2f 2a 20 rnings; /*
35b0: 72 65 73 70 6f 6e 73 65 20 77 61 72 6e 69 6e 67 response warning
35c0: 73 20 2a 2f 0a 20 20 20 20 69 6e 74 20 74 69 6d s */. int tim
35d0: 65 72 49 64 3b 20 20 20 20 20 20 20 20 20 20 20 erId;
35e0: 20 20 20 20 2f 2a 20 66 65 74 63 68 65 64 20 66 /* fetched f
35f0: 72 6f 6d 20 66 6f 73 73 69 6c 5f 74 69 6d 65 72 rom fossil_timer
3600: 5f 73 74 61 72 74 28 29 20 2a 2f 0a 20 20 7d 20 _start() */. }
3610: 6a 73 6f 6e 3b 0a 23 65 6e 64 69 66 20 2f 2a 20 json;.#endif /*
3620: 46 4f 53 53 49 4c 5f 45 4e 41 42 4c 45 5f 4a 53 FOSSIL_ENABLE_JS
3630: 4f 4e 20 2a 2f 0a 7d 3b 0a 0a 2f 2a 0a 2a 2a 20 ON */.};../*.**
3640: 4d 61 63 72 6f 20 66 6f 72 20 64 65 62 75 67 67 Macro for debugg
3650: 69 6e 67 3a 0a 2a 2f 0a 23 64 65 66 69 6e 65 20 ing:.*/.#define
3660: 43 47 49 44 45 42 55 47 28 58 29 20 20 69 66 28 CGIDEBUG(X) if(
3670: 20 67 2e 66 44 65 62 75 67 20 29 20 63 67 69 5f g.fDebug ) cgi_
3680: 64 65 62 75 67 20 58 0a 0a 23 65 6e 64 69 66 0a debug X..#endif.
3690: 0a 47 6c 6f 62 61 6c 20 67 3b 0a 0a 2f 2a 0a 2a .Global g;../*.*
36a0: 2a 20 61 74 65 78 69 74 28 29 20 68 61 6e 64 6c * atexit() handl
36b0: 65 72 20 77 68 69 63 68 20 66 72 65 65 73 20 75 er which frees u
36c0: 70 20 22 73 6f 6d 65 22 20 6f 66 20 74 68 65 20 p "some" of the
36d0: 72 65 73 6f 75 72 63 65 73 0a 2a 2a 20 75 73 65 resources.** use
36e0: 64 20 62 79 20 66 6f 73 73 69 6c 2e 0a 2a 2f 0a d by fossil..*/.
36f0: 73 74 61 74 69 63 20 76 6f 69 64 20 66 6f 73 73 static void foss
3700: 69 6c 5f 61 74 65 78 69 74 28 76 6f 69 64 29 20 il_atexit(void)
3710: 7b 0a 23 69 66 20 55 53 45 5f 53 45 45 0a 20 20 {.#if USE_SEE.
3720: 2f 2a 0a 20 20 2a 2a 20 5a 65 72 6f 2c 20 75 6e /*. ** Zero, un
3730: 6c 6f 63 6b 2c 20 61 6e 64 20 66 72 65 65 20 74 lock, and free t
3740: 68 65 20 73 61 76 65 64 20 64 61 74 61 62 61 73 he saved databas
3750: 65 20 65 6e 63 72 79 70 74 69 6f 6e 20 6b 65 79 e encryption key
3760: 20 6e 6f 77 2e 0a 20 20 2a 2f 0a 20 20 64 62 5f now.. */. db_
3770: 75 6e 73 61 76 65 5f 65 6e 63 72 79 70 74 69 6f unsave_encryptio
3780: 6e 5f 6b 65 79 28 29 3b 0a 23 65 6e 64 69 66 0a n_key();.#endif.
3790: 23 69 66 20 64 65 66 69 6e 65 64 28 5f 57 49 4e #if defined(_WIN
37a0: 33 32 29 20 7c 7c 20 64 65 66 69 6e 65 64 28 5f 32) || defined(_
37b0: 5f 42 49 4f 4e 49 43 5f 5f 29 0a 20 20 2f 2a 0a _BIONIC__). /*.
37c0: 20 20 2a 2a 20 46 72 65 65 20 74 68 65 20 73 65 ** Free the se
37d0: 63 75 72 65 20 67 65 74 70 61 73 73 28 29 20 62 cure getpass() b
37e0: 75 66 66 65 72 20 6e 6f 77 2e 0a 20 20 2a 2f 0a uffer now.. */.
37f0: 20 20 66 72 65 65 70 61 73 73 28 29 3b 0a 23 65 freepass();.#e
3800: 6e 64 69 66 0a 23 69 66 20 64 65 66 69 6e 65 64 ndif.#if defined
3810: 28 5f 57 49 4e 33 32 29 20 26 26 20 21 64 65 66 (_WIN32) && !def
3820: 69 6e 65 64 28 5f 57 49 4e 36 34 29 20 26 26 20 ined(_WIN64) &&
3830: 64 65 66 69 6e 65 64 28 46 4f 53 53 49 4c 5f 45 defined(FOSSIL_E
3840: 4e 41 42 4c 45 5f 54 43 4c 29 20 26 26 20 5c 0a NABLE_TCL) && \.
3850: 20 20 20 20 64 65 66 69 6e 65 64 28 55 53 45 5f defined(USE_
3860: 54 43 4c 5f 53 54 55 42 53 29 0a 20 20 2f 2a 0a TCL_STUBS). /*.
3870: 20 20 2a 2a 20 49 66 20 54 63 6c 20 69 73 20 63 ** If Tcl is c
3880: 6f 6d 70 69 6c 65 64 20 6f 6e 20 57 69 6e 64 6f ompiled on Windo
3890: 77 73 20 75 73 69 6e 67 20 74 68 65 20 6c 61 74 ws using the lat
38a0: 65 73 74 20 4d 69 6e 47 57 2c 20 46 6f 73 73 69 est MinGW, Fossi
38b0: 6c 20 63 61 6e 20 63 72 61 73 68 0a 20 20 2a 2a l can crash. **
38c0: 20 77 68 65 6e 20 65 78 69 74 69 6e 67 20 77 68 when exiting wh
38d0: 69 6c 65 20 61 20 73 74 75 62 73 2d 65 6e 61 62 ile a stubs-enab
38e0: 6c 65 64 20 54 63 6c 20 69 73 20 73 74 69 6c 6c led Tcl is still
38f0: 20 6c 6f 61 64 65 64 2e 20 20 54 68 69 73 20 69 loaded. This i
3900: 73 20 64 75 65 20 74 6f 0a 20 20 2a 2a 20 61 20 s due to. ** a
3910: 62 75 67 20 69 6e 20 4d 69 6e 47 57 2c 20 73 65 bug in MinGW, se
3920: 65 3a 0a 20 20 2a 2a 0a 20 20 2a 2a 20 20 20 20 e:. **. **
3930: 20 68 74 74 70 3a 2f 2f 63 6f 6d 6d 65 6e 74 73 http://comments
3940: 2e 67 6d 61 6e 65 2e 6f 72 67 2f 67 6d 61 6e 65 .gmane.org/gmane
3950: 2e 63 6f 6d 70 2e 67 6e 75 2e 6d 69 6e 67 77 2e .comp.gnu.mingw.
3960: 75 73 65 72 2f 34 31 37 32 34 0a 20 20 2a 2a 0a user/41724. **.
3970: 20 20 2a 2a 20 54 68 65 20 77 6f 72 6b 61 72 6f ** The workaro
3980: 75 6e 64 20 69 73 20 74 6f 20 6d 61 6e 75 61 6c und is to manual
3990: 6c 79 20 75 6e 6c 6f 61 64 20 74 68 65 20 6c 6f ly unload the lo
39a0: 61 64 65 64 20 54 63 6c 20 6c 69 62 72 61 72 79 aded Tcl library
39b0: 20 70 72 69 6f 72 20 74 6f 0a 20 20 2a 2a 20 65 prior to. ** e
39c0: 78 69 74 69 6e 67 20 74 68 65 20 70 72 6f 63 65 xiting the proce
39d0: 73 73 2e 20 20 54 68 69 73 20 69 73 73 75 65 20 ss. This issue
39e0: 64 6f 65 73 20 6e 6f 74 20 69 6d 70 61 63 74 20 does not impact
39f0: 36 34 2d 62 69 74 20 57 69 6e 64 6f 77 73 2e 0a 64-bit Windows..
3a00: 20 20 2a 2f 0a 20 20 75 6e 6c 6f 61 64 54 63 6c */. unloadTcl
3a10: 28 67 2e 69 6e 74 65 72 70 2c 20 26 67 2e 74 63 (g.interp, &g.tc
3a20: 6c 29 3b 0a 23 65 6e 64 69 66 0a 23 69 66 64 65 l);.#endif.#ifde
3a30: 66 20 46 4f 53 53 49 4c 5f 45 4e 41 42 4c 45 5f f FOSSIL_ENABLE_
3a40: 4a 53 4f 4e 0a 20 20 63 73 6f 6e 5f 76 61 6c 75 JSON. cson_valu
3a50: 65 5f 66 72 65 65 28 67 2e 6a 73 6f 6e 2e 67 63 e_free(g.json.gc
3a60: 2e 76 29 3b 0a 20 20 6d 65 6d 73 65 74 28 26 67 .v);. memset(&g
3a70: 2e 6a 73 6f 6e 2c 20 30 2c 20 73 69 7a 65 6f 66 .json, 0, sizeof
3a80: 28 67 2e 6a 73 6f 6e 29 29 3b 0a 23 65 6e 64 69 (g.json));.#endi
3a90: 66 0a 20 20 66 72 65 65 28 67 2e 7a 45 72 72 4d f. free(g.zErrM
3aa0: 73 67 29 3b 0a 20 20 69 66 28 67 2e 64 62 29 7b sg);. if(g.db){
3ab0: 0a 20 20 20 20 64 62 5f 63 6c 6f 73 65 28 30 29 . db_close(0)
3ac0: 3b 0a 20 20 7d 0a 20 20 2f 2a 0a 20 20 2a 2a 20 ;. }. /*. **
3ad0: 46 49 58 4d 45 3a 20 54 68 65 20 6e 65 78 74 20 FIXME: The next
3ae0: 74 77 6f 20 6c 69 6e 65 73 20 63 61 6e 6e 6f 74 two lines cannot
3af0: 20 61 6c 77 61 79 73 20 62 65 20 65 6e 61 62 6c always be enabl
3b00: 65 64 3b 20 68 6f 77 65 76 65 72 2c 20 74 68 65 ed; however, the
3b10: 79 0a 20 20 2a 2a 20 20 20 20 20 20 20 20 61 72 y. ** ar
3b20: 65 20 76 65 72 79 20 75 73 65 66 75 6c 20 66 6f e very useful fo
3b30: 72 20 74 72 61 63 6b 69 6e 67 20 64 6f 77 6e 20 r tracking down
3b40: 54 48 31 20 6d 65 6d 6f 72 79 20 6c 65 61 6b 73 TH1 memory leaks
3b50: 2e 0a 20 20 2a 2f 0a 20 20 69 66 28 20 66 6f 73 .. */. if( fos
3b60: 73 69 6c 5f 67 65 74 65 6e 76 28 22 54 48 31 5f sil_getenv("TH1_
3b70: 44 45 4c 45 54 45 5f 49 4e 54 45 52 50 22 29 21 DELETE_INTERP")!
3b80: 3d 30 20 29 7b 0a 20 20 20 20 69 66 28 20 67 2e =0 ){. if( g.
3b90: 69 6e 74 65 72 70 20 29 7b 0a 20 20 20 20 20 20 interp ){.
3ba0: 54 68 5f 44 65 6c 65 74 65 49 6e 74 65 72 70 28 Th_DeleteInterp(
3bb0: 67 2e 69 6e 74 65 72 70 29 3b 20 67 2e 69 6e 74 g.interp); g.int
3bc0: 65 72 70 20 3d 20 30 3b 0a 20 20 20 20 7d 0a 20 erp = 0;. }.
3bd0: 20 20 20 61 73 73 65 72 74 28 20 54 68 5f 47 65 assert( Th_Ge
3be0: 74 4f 75 74 73 74 61 6e 64 69 6e 67 4d 61 6c 6c tOutstandingMall
3bf0: 6f 63 28 29 3d 3d 30 20 29 3b 0a 20 20 7d 0a 7d oc()==0 );. }.}
3c00: 0a 0a 2f 2a 0a 2a 2a 20 43 6f 6e 76 65 72 74 20 ../*.** Convert
3c10: 61 6c 6c 20 61 72 67 75 6d 65 6e 74 73 20 66 72 all arguments fr
3c20: 6f 6d 20 6d 62 63 73 20 28 6f 72 20 75 6e 69 63 om mbcs (or unic
3c30: 6f 64 65 29 20 74 6f 20 55 54 46 2d 38 2e 20 54 ode) to UTF-8. T
3c40: 68 65 6e 0a 2a 2a 20 73 65 61 72 63 68 20 67 2e hen.** search g.
3c50: 61 72 67 76 20 66 6f 72 20 61 72 67 75 6d 65 6e argv for argumen
3c60: 74 73 20 22 2d 2d 61 72 67 73 20 46 49 4c 45 4e ts "--args FILEN
3c70: 41 4d 45 22 2e 20 49 66 20 66 6f 75 6e 64 2c 20 AME". If found,
3c80: 74 68 65 6e 0a 2a 2a 20 28 31 29 20 72 65 6d 6f then.** (1) remo
3c90: 76 65 20 74 68 65 20 74 77 6f 20 61 72 67 75 6d ve the two argum
3ca0: 65 6e 74 73 20 66 72 6f 6d 20 67 2e 61 72 67 76 ents from g.argv
3cb0: 0a 2a 2a 20 28 32 29 20 52 65 61 64 20 74 68 65 .** (2) Read the
3cc0: 20 66 69 6c 65 20 46 49 4c 45 4e 41 4d 45 0a 2a file FILENAME.*
3cd0: 2a 20 28 33 29 20 55 73 65 20 74 68 65 20 63 6f * (3) Use the co
3ce0: 6e 74 65 6e 74 73 20 6f 66 20 46 49 4c 45 20 74 ntents of FILE t
3cf0: 6f 20 72 65 70 6c 61 63 65 20 74 68 65 20 74 77 o replace the tw
3d00: 6f 20 72 65 6d 6f 76 65 64 20 61 72 67 75 6d 65 o removed argume
3d10: 6e 74 73 3a 0a 2a 2a 20 20 20 20 20 28 61 29 20 nts:.** (a)
3d20: 49 67 6e 6f 72 65 20 62 6c 61 6e 6b 20 6c 69 6e Ignore blank lin
3d30: 65 73 20 69 6e 20 74 68 65 20 66 69 6c 65 0a 2a es in the file.*
3d40: 2a 20 20 20 20 20 28 62 29 20 45 61 63 68 20 6e * (b) Each n
3d50: 6f 6e 2d 65 6d 70 74 79 20 6c 69 6e 65 20 6f 66 on-empty line of
3d60: 20 74 68 65 20 66 69 6c 65 20 69 73 20 61 6e 20 the file is an
3d70: 61 72 67 75 6d 65 6e 74 2c 20 65 78 63 65 70 74 argument, except
3d80: 0a 2a 2a 20 20 20 20 20 28 63 29 20 49 66 20 74 .** (c) If t
3d90: 68 65 20 6c 69 6e 65 20 62 65 67 69 6e 73 20 77 he line begins w
3da0: 69 74 68 20 22 2d 22 20 61 6e 64 20 63 6f 6e 74 ith "-" and cont
3db0: 61 69 6e 73 20 61 20 73 70 61 63 65 2c 20 69 74 ains a space, it
3dc0: 20 69 73 20 62 72 6f 6b 65 6e 0a 2a 2a 20 20 20 is broken.**
3dd0: 20 20 20 20 20 20 69 6e 74 6f 20 74 77 6f 20 61 into two a
3de0: 72 67 75 6d 65 6e 74 73 20 61 74 20 74 68 65 20 rguments at the
3df0: 73 70 61 63 65 2e 0a 2a 2f 0a 73 74 61 74 69 63 space..*/.static
3e00: 20 76 6f 69 64 20 65 78 70 61 6e 64 5f 61 72 67 void expand_arg
3e10: 73 5f 6f 70 74 69 6f 6e 28 69 6e 74 20 61 72 67 s_option(int arg
3e20: 63 2c 20 76 6f 69 64 20 2a 61 72 67 76 29 7b 0a c, void *argv){.
3e30: 20 20 42 6c 6f 62 20 66 69 6c 65 20 3d 20 65 6d Blob file = em
3e40: 70 74 79 5f 62 6c 6f 62 3b 20 20 20 2f 2a 20 43 pty_blob; /* C
3e50: 6f 6e 74 65 6e 74 20 6f 66 20 74 68 65 20 66 69 ontent of the fi
3e60: 6c 65 20 2a 2f 0a 20 20 42 6c 6f 62 20 6c 69 6e le */. Blob lin
3e70: 65 20 3d 20 65 6d 70 74 79 5f 62 6c 6f 62 3b 20 e = empty_blob;
3e80: 20 20 2f 2a 20 4f 6e 65 20 6c 69 6e 65 20 6f 66 /* One line of
3e90: 20 74 68 65 20 66 69 6c 65 20 2a 2f 0a 20 20 75 the file */. u
3ea0: 6e 73 69 67 6e 65 64 20 69 6e 74 20 6e 4c 69 6e nsigned int nLin
3eb0: 65 3b 20 20 20 20 20 20 20 2f 2a 20 4e 75 6d 62 e; /* Numb
3ec0: 65 72 20 6f 66 20 6c 69 6e 65 73 20 69 6e 20 74 er of lines in t
3ed0: 68 65 20 66 69 6c 65 2a 2f 0a 20 20 75 6e 73 69 he file*/. unsi
3ee0: 67 6e 65 64 20 69 6e 74 20 69 2c 20 6a 2c 20 6b gned int i, j, k
3ef0: 3b 20 20 20 20 20 2f 2a 20 4c 6f 6f 70 20 63 6f ; /* Loop co
3f00: 75 6e 74 65 72 73 20 2a 2f 0a 20 20 69 6e 74 20 unters */. int
3f10: 6e 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 20 n;
3f20: 20 20 20 20 20 20 2f 2a 20 4e 75 6d 62 65 72 20 /* Number
3f30: 6f 66 20 62 79 74 65 73 20 69 6e 20 6f 6e 65 20 of bytes in one
3f40: 6c 69 6e 65 20 2a 2f 0a 20 20 63 68 61 72 20 2a line */. char *
3f50: 7a 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 20 z;
3f60: 20 20 20 20 2f 2a 20 47 65 6e 65 72 61 6c 20 75 /* General u
3f70: 73 65 20 73 74 72 69 6e 67 20 70 6f 69 6e 74 65 se string pointe
3f80: 72 20 2a 2f 0a 20 20 63 68 61 72 20 2a 2a 6e 65 r */. char **ne
3f90: 77 41 72 67 76 3b 20 20 20 20 20 20 20 20 20 20 wArgv;
3fa0: 20 2f 2a 20 4e 65 77 20 65 78 70 61 6e 64 65 64 /* New expanded
3fb0: 20 67 2e 61 72 67 76 20 75 6e 64 65 72 20 63 6f g.argv under co
3fc0: 6e 73 74 72 75 63 74 69 6f 6e 20 2a 2f 0a 20 20 nstruction */.
3fd0: 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a 46 69 6c const char *zFil
3fe0: 65 4e 61 6d 65 3b 20 20 20 20 2f 2a 20 69 6e 70 eName; /* inp
3ff0: 75 74 20 66 69 6c 65 20 6e 61 6d 65 20 2a 2f 0a ut file name */.
4000: 20 20 46 49 4c 45 20 2a 69 6e 46 69 6c 65 3b 20 FILE *inFile;
4010: 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 69 /* i
4020: 6e 70 75 74 20 46 49 4c 45 20 2a 2f 0a 23 69 66 nput FILE */.#if
4030: 20 64 65 66 69 6e 65 64 28 5f 57 49 4e 33 32 29 defined(_WIN32)
4040: 0a 20 20 77 63 68 61 72 5f 74 20 62 75 66 5b 4d . wchar_t buf[M
4050: 41 58 5f 50 41 54 48 5d 3b 0a 23 65 6e 64 69 66 AX_PATH];.#endif
4060: 0a 0a 20 20 67 2e 61 72 67 63 20 3d 20 61 72 67 .. g.argc = arg
4070: 63 3b 0a 20 20 67 2e 61 72 67 76 20 3d 20 61 72 c;. g.argv = ar
4080: 67 76 3b 0a 20 20 73 71 6c 69 74 65 33 5f 69 6e gv;. sqlite3_in
4090: 69 74 69 61 6c 69 7a 65 28 29 3b 0a 23 69 66 20 itialize();.#if
40a0: 64 65 66 69 6e 65 64 28 5f 57 49 4e 33 32 29 20 defined(_WIN32)
40b0: 26 26 20 64 65 66 69 6e 65 64 28 42 52 4f 4b 45 && defined(BROKE
40c0: 4e 5f 4d 49 4e 47 57 5f 43 4d 44 4c 49 4e 45 29 N_MINGW_CMDLINE)
40d0: 0a 20 20 66 6f 72 28 69 3d 30 3b 20 69 3c 67 2e . for(i=0; i<g.
40e0: 61 72 67 63 3b 20 69 2b 2b 29 20 67 2e 61 72 67 argc; i++) g.arg
40f0: 76 5b 69 5d 20 3d 20 66 6f 73 73 69 6c 5f 6d 62 v[i] = fossil_mb
4100: 63 73 5f 74 6f 5f 75 74 66 38 28 67 2e 61 72 67 cs_to_utf8(g.arg
4110: 76 5b 69 5d 29 3b 0a 23 65 6c 73 65 0a 20 20 66 v[i]);.#else. f
4120: 6f 72 28 69 3d 30 3b 20 69 3c 67 2e 61 72 67 63 or(i=0; i<g.argc
4130: 3b 20 69 2b 2b 29 20 67 2e 61 72 67 76 5b 69 5d ; i++) g.argv[i]
4140: 20 3d 20 66 6f 73 73 69 6c 5f 70 61 74 68 5f 74 = fossil_path_t
4150: 6f 5f 75 74 66 38 28 67 2e 61 72 67 76 5b 69 5d o_utf8(g.argv[i]
4160: 29 3b 0a 23 65 6e 64 69 66 0a 23 69 66 20 64 65 );.#endif.#if de
4170: 66 69 6e 65 64 28 5f 57 49 4e 33 32 29 0a 20 20 fined(_WIN32).
4180: 47 65 74 4d 6f 64 75 6c 65 46 69 6c 65 4e 61 6d GetModuleFileNam
4190: 65 57 28 4e 55 4c 4c 2c 20 62 75 66 2c 20 4d 41 eW(NULL, buf, MA
41a0: 58 5f 50 41 54 48 29 3b 0a 20 20 67 2e 6e 61 6d X_PATH);. g.nam
41b0: 65 4f 66 45 78 65 20 3d 20 66 6f 73 73 69 6c 5f eOfExe = fossil_
41c0: 70 61 74 68 5f 74 6f 5f 75 74 66 38 28 62 75 66 path_to_utf8(buf
41d0: 29 3b 0a 23 65 6c 73 65 0a 20 20 67 2e 6e 61 6d );.#else. g.nam
41e0: 65 4f 66 45 78 65 20 3d 20 67 2e 61 72 67 76 5b eOfExe = g.argv[
41f0: 30 5d 3b 0a 23 65 6e 64 69 66 0a 20 20 66 6f 72 0];.#endif. for
4200: 28 69 3d 31 3b 20 69 3c 67 2e 61 72 67 63 2d 31 (i=1; i<g.argc-1
4210: 3b 20 69 2b 2b 29 7b 0a 20 20 20 20 7a 20 3d 20 ; i++){. z =
4220: 67 2e 61 72 67 76 5b 69 5d 3b 0a 20 20 20 20 69 g.argv[i];. i
4230: 66 28 20 7a 5b 30 5d 21 3d 27 2d 27 20 29 20 63 f( z[0]!='-' ) c
4240: 6f 6e 74 69 6e 75 65 3b 0a 20 20 20 20 7a 2b 2b ontinue;. z++
4250: 3b 0a 20 20 20 20 69 66 28 20 7a 5b 30 5d 3d 3d ;. if( z[0]==
4260: 27 2d 27 20 29 20 7a 2b 2b 3b 0a 20 20 20 20 69 '-' ) z++;. i
4270: 66 28 20 7a 5b 30 5d 3d 3d 30 20 29 20 72 65 74 f( z[0]==0 ) ret
4280: 75 72 6e 3b 20 20 20 2f 2a 20 53 74 6f 70 20 73 urn; /* Stop s
4290: 65 61 72 63 68 69 6e 67 20 61 74 20 22 2d 2d 22 earching at "--"
42a0: 20 2a 2f 0a 20 20 20 20 69 66 28 20 66 6f 73 73 */. if( foss
42b0: 69 6c 5f 73 74 72 63 6d 70 28 7a 2c 20 22 61 72 il_strcmp(z, "ar
42c0: 67 73 22 29 3d 3d 30 20 29 20 62 72 65 61 6b 3b gs")==0 ) break;
42d0: 0a 20 20 7d 0a 20 20 69 66 28 20 69 3e 3d 67 2e . }. if( i>=g.
42e0: 61 72 67 63 2d 31 20 29 20 72 65 74 75 72 6e 3b argc-1 ) return;
42f0: 0a 0a 20 20 7a 46 69 6c 65 4e 61 6d 65 20 3d 20 .. zFileName =
4300: 67 2e 61 72 67 76 5b 69 2b 31 5d 3b 0a 20 20 69 g.argv[i+1];. i
4310: 6e 46 69 6c 65 20 3d 20 28 30 3d 3d 73 74 72 63 nFile = (0==strc
4320: 6d 70 28 22 2d 22 2c 7a 46 69 6c 65 4e 61 6d 65 mp("-",zFileName
4330: 29 29 0a 20 20 20 20 3f 20 73 74 64 69 6e 0a 20 )). ? stdin.
4340: 20 20 20 3a 20 66 6f 73 73 69 6c 5f 66 6f 70 65 : fossil_fope
4350: 6e 28 7a 46 69 6c 65 4e 61 6d 65 2c 22 72 62 22 n(zFileName,"rb"
4360: 29 3b 0a 20 20 69 66 28 21 69 6e 46 69 6c 65 29 );. if(!inFile)
4370: 7b 0a 20 20 20 20 66 6f 73 73 69 6c 5f 66 61 74 {. fossil_fat
4380: 61 6c 28 22 43 61 6e 6e 6f 74 20 6f 70 65 6e 20 al("Cannot open
4390: 2d 61 72 67 73 20 66 69 6c 65 20 5b 25 73 5d 22 -args file [%s]"
43a0: 2c 20 7a 46 69 6c 65 4e 61 6d 65 29 3b 0a 20 20 , zFileName);.
43b0: 7d 65 6c 73 65 7b 0a 20 20 20 20 62 6c 6f 62 5f }else{. blob_
43c0: 72 65 61 64 5f 66 72 6f 6d 5f 63 68 61 6e 6e 65 read_from_channe
43d0: 6c 28 26 66 69 6c 65 2c 20 69 6e 46 69 6c 65 2c l(&file, inFile,
43e0: 20 2d 31 29 3b 0a 20 20 20 20 69 66 28 73 74 64 -1);. if(std
43f0: 69 6e 20 21 3d 20 69 6e 46 69 6c 65 29 7b 0a 20 in != inFile){.
4400: 20 20 20 20 20 66 63 6c 6f 73 65 28 69 6e 46 69 fclose(inFi
4410: 6c 65 29 3b 0a 20 20 20 20 7d 0a 20 20 20 20 69 le);. }. i
4420: 6e 46 69 6c 65 20 3d 20 4e 55 4c 4c 3b 0a 20 20 nFile = NULL;.
4430: 7d 0a 20 20 62 6c 6f 62 5f 74 6f 5f 75 74 66 38 }. blob_to_utf8
4440: 5f 6e 6f 5f 62 6f 6d 28 26 66 69 6c 65 2c 20 31 _no_bom(&file, 1
4450: 29 3b 0a 20 20 7a 20 3d 20 62 6c 6f 62 5f 73 74 );. z = blob_st
4460: 72 28 26 66 69 6c 65 29 3b 0a 20 20 66 6f 72 28 r(&file);. for(
4470: 6b 3d 30 2c 20 6e 4c 69 6e 65 3d 31 3b 20 7a 5b k=0, nLine=1; z[
4480: 6b 5d 3b 20 6b 2b 2b 29 20 69 66 28 20 7a 5b 6b k]; k++) if( z[k
4490: 5d 3d 3d 27 5c 6e 27 20 29 20 6e 4c 69 6e 65 2b ]=='\n' ) nLine+
44a0: 2b 3b 0a 20 20 6e 65 77 41 72 67 76 20 3d 20 66 +;. newArgv = f
44b0: 6f 73 73 69 6c 5f 6d 61 6c 6c 6f 63 28 20 73 69 ossil_malloc( si
44c0: 7a 65 6f 66 28 63 68 61 72 2a 29 2a 28 67 2e 61 zeof(char*)*(g.a
44d0: 72 67 63 20 2b 20 6e 4c 69 6e 65 2a 32 29 20 29 rgc + nLine*2) )
44e0: 3b 0a 20 20 66 6f 72 28 6a 3d 30 3b 20 6a 3c 69 ;. for(j=0; j<i
44f0: 3b 20 6a 2b 2b 29 20 6e 65 77 41 72 67 76 5b 6a ; j++) newArgv[j
4500: 5d 20 3d 20 67 2e 61 72 67 76 5b 6a 5d 3b 0a 0a ] = g.argv[j];..
4510: 20 20 62 6c 6f 62 5f 72 65 77 69 6e 64 28 26 66 blob_rewind(&f
4520: 69 6c 65 29 3b 0a 20 20 77 68 69 6c 65 28 20 28 ile);. while( (
4530: 6e 20 3d 20 62 6c 6f 62 5f 6c 69 6e 65 28 26 66 n = blob_line(&f
4540: 69 6c 65 2c 20 26 6c 69 6e 65 29 29 3e 30 20 29 ile, &line))>0 )
4550: 7b 0a 20 20 20 20 69 66 28 20 6e 3c 31 20 29 20 {. if( n<1 )
4560: 63 6f 6e 74 69 6e 75 65 0a 20 20 20 20 20 20 2f continue. /
4570: 2a 2a 0a 20 20 20 20 20 20 20 2a 2a 20 52 65 6d **. ** Rem
4580: 69 6e 64 65 72 3a 20 63 6f 72 6e 65 72 2d 63 61 inder: corner-ca
4590: 73 65 3a 20 61 20 6c 69 6e 65 20 77 69 74 68 20 se: a line with
45a0: 31 20 62 79 74 65 20 61 6e 64 20 6e 6f 20 6e 65 1 byte and no ne
45b0: 77 6c 69 6e 65 2e 0a 20 20 20 20 20 20 20 2a 2f wline.. */
45c0: 3b 0a 20 20 20 20 7a 20 3d 20 62 6c 6f 62 5f 62 ;. z = blob_b
45d0: 75 66 66 65 72 28 26 6c 69 6e 65 29 3b 0a 20 20 uffer(&line);.
45e0: 20 20 69 66 28 27 5c 6e 27 3d 3d 7a 5b 6e 2d 31 if('\n'==z[n-1
45f0: 5d 29 7b 0a 20 20 20 20 20 20 7a 5b 6e 2d 31 5d ]){. z[n-1]
4600: 20 3d 20 30 3b 0a 20 20 20 20 7d 0a 0a 20 20 20 = 0;. }..
4610: 20 69 66 28 28 6e 3e 31 29 20 26 26 20 28 27 5c if((n>1) && ('\
4620: 72 27 3d 3d 7a 5b 6e 2d 32 5d 29 29 7b 0a 20 20 r'==z[n-2])){.
4630: 20 20 20 20 69 66 28 6e 3d 3d 32 29 20 63 6f 6e if(n==2) con
4640: 74 69 6e 75 65 20 2f 2a 65 6d 70 74 79 20 6c 69 tinue /*empty li
4650: 6e 65 2a 2f 3b 0a 20 20 20 20 20 20 7a 5b 6e 2d ne*/;. z[n-
4660: 32 5d 20 3d 20 30 3b 0a 20 20 20 20 7d 0a 20 20 2] = 0;. }.
4670: 20 20 69 66 28 21 7a 5b 30 5d 29 20 63 6f 6e 74 if(!z[0]) cont
4680: 69 6e 75 65 3b 0a 20 20 20 20 6e 65 77 41 72 67 inue;. newArg
4690: 76 5b 6a 2b 2b 5d 20 3d 20 7a 3b 0a 20 20 20 20 v[j++] = z;.
46a0: 69 66 28 20 7a 5b 30 5d 3d 3d 27 2d 27 20 29 7b if( z[0]=='-' ){
46b0: 0a 20 20 20 20 20 20 66 6f 72 28 6b 3d 31 3b 20 . for(k=1;
46c0: 7a 5b 6b 5d 20 26 26 20 21 66 6f 73 73 69 6c 5f z[k] && !fossil_
46d0: 69 73 73 70 61 63 65 28 7a 5b 6b 5d 29 3b 20 6b isspace(z[k]); k
46e0: 2b 2b 29 7b 7d 0a 20 20 20 20 20 20 69 66 28 20 ++){}. if(
46f0: 7a 5b 6b 5d 20 29 7b 0a 20 20 20 20 20 20 20 20 z[k] ){.
4700: 7a 5b 6b 5d 20 3d 20 30 3b 0a 20 20 20 20 20 20 z[k] = 0;.
4710: 20 20 6b 2b 2b 3b 0a 20 20 20 20 20 20 20 20 69 k++;. i
4720: 66 28 20 7a 5b 6b 5d 20 29 20 6e 65 77 41 72 67 f( z[k] ) newArg
4730: 76 5b 6a 2b 2b 5d 20 3d 20 26 7a 5b 6b 5d 3b 0a v[j++] = &z[k];.
4740: 20 20 20 20 20 20 7d 0a 20 20 20 20 7d 0a 20 20 }. }.
4750: 7d 0a 20 20 69 20 2b 3d 20 32 3b 0a 20 20 77 68 }. i += 2;. wh
4760: 69 6c 65 28 20 69 3c 67 2e 61 72 67 63 20 29 20 ile( i<g.argc )
4770: 6e 65 77 41 72 67 76 5b 6a 2b 2b 5d 20 3d 20 67 newArgv[j++] = g
4780: 2e 61 72 67 76 5b 69 2b 2b 5d 3b 0a 20 20 6e 65 .argv[i++];. ne
4790: 77 41 72 67 76 5b 6a 5d 20 3d 20 30 3b 0a 20 20 wArgv[j] = 0;.
47a0: 67 2e 61 72 67 63 20 3d 20 6a 3b 0a 20 20 67 2e g.argc = j;. g.
47b0: 61 72 67 76 20 3d 20 6e 65 77 41 72 67 76 3b 0a argv = newArgv;.
47c0: 7d 0a 0a 23 69 66 64 65 66 20 46 4f 53 53 49 4c }..#ifdef FOSSIL
47d0: 5f 45 4e 41 42 4c 45 5f 54 43 4c 0a 2f 2a 0a 2a _ENABLE_TCL./*.*
47e0: 2a 20 4d 61 6b 65 20 61 20 64 65 65 70 20 63 6f * Make a deep co
47f0: 70 79 20 6f 66 20 74 68 65 20 70 72 6f 76 69 64 py of the provid
4800: 65 64 20 61 72 67 75 6d 65 6e 74 20 61 72 72 61 ed argument arra
4810: 79 20 61 6e 64 20 72 65 74 75 72 6e 20 69 74 2e y and return it.
4820: 0a 2a 2f 0a 73 74 61 74 69 63 20 63 68 61 72 20 .*/.static char
4830: 2a 2a 63 6f 70 79 5f 61 72 67 73 28 69 6e 74 20 **copy_args(int
4840: 61 72 67 63 2c 20 63 68 61 72 20 2a 2a 61 72 67 argc, char **arg
4850: 76 29 7b 0a 20 20 63 68 61 72 20 2a 2a 7a 4e 65 v){. char **zNe
4860: 77 41 72 67 76 3b 0a 20 20 69 6e 74 20 69 3b 0a wArgv;. int i;.
4870: 20 20 7a 4e 65 77 41 72 67 76 20 3d 20 66 6f 73 zNewArgv = fos
4880: 73 69 6c 5f 6d 61 6c 6c 6f 63 28 20 73 69 7a 65 sil_malloc( size
4890: 6f 66 28 63 68 61 72 2a 29 2a 28 61 72 67 63 2b of(char*)*(argc+
48a0: 31 29 20 29 3b 0a 20 20 6d 65 6d 73 65 74 28 7a 1) );. memset(z
48b0: 4e 65 77 41 72 67 76 2c 20 30 2c 20 73 69 7a 65 NewArgv, 0, size
48c0: 6f 66 28 63 68 61 72 2a 29 2a 28 61 72 67 63 2b of(char*)*(argc+
48d0: 31 29 29 3b 0a 20 20 66 6f 72 28 69 3d 30 3b 20 1));. for(i=0;
48e0: 69 3c 61 72 67 63 3b 20 69 2b 2b 29 7b 0a 20 20 i<argc; i++){.
48f0: 20 20 7a 4e 65 77 41 72 67 76 5b 69 5d 20 3d 20 zNewArgv[i] =
4900: 66 6f 73 73 69 6c 5f 73 74 72 64 75 70 28 61 72 fossil_strdup(ar
4910: 67 76 5b 69 5d 29 3b 0a 20 20 7d 0a 20 20 72 65 gv[i]);. }. re
4920: 74 75 72 6e 20 7a 4e 65 77 41 72 67 76 3b 0a 7d turn zNewArgv;.}
4930: 0a 23 65 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 52 .#endif../*.** R
4940: 65 74 75 72 6e 73 20 61 20 6e 61 6d 65 20 66 6f eturns a name fo
4950: 72 20 61 20 53 51 4c 69 74 65 20 72 65 74 75 72 r a SQLite retur
4960: 6e 20 63 6f 64 65 2e 0a 2a 2f 0a 73 74 61 74 69 n code..*/.stati
4970: 63 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 66 6f c const char *fo
4980: 73 73 69 6c 5f 73 71 6c 69 74 65 5f 72 65 74 75 ssil_sqlite_retu
4990: 72 6e 5f 63 6f 64 65 5f 6e 61 6d 65 28 69 6e 74 rn_code_name(int
49a0: 20 72 63 29 7b 0a 20 20 73 74 61 74 69 63 20 63 rc){. static c
49b0: 68 61 72 20 7a 43 6f 64 65 5b 33 30 5d 3b 0a 20 har zCode[30];.
49c0: 20 73 77 69 74 63 68 28 20 72 63 20 26 20 30 78 switch( rc & 0x
49d0: 66 66 20 29 7b 0a 20 20 20 20 63 61 73 65 20 53 ff ){. case S
49e0: 51 4c 49 54 45 5f 4f 4b 3a 20 20 20 20 20 20 20 QLITE_OK:
49f0: 20 20 72 65 74 75 72 6e 20 22 53 51 4c 49 54 45 return "SQLITE
4a00: 5f 4f 4b 22 3b 0a 20 20 20 20 63 61 73 65 20 53 _OK";. case S
4a10: 51 4c 49 54 45 5f 45 52 52 4f 52 3a 20 20 20 20 QLITE_ERROR:
4a20: 20 20 72 65 74 75 72 6e 20 22 53 51 4c 49 54 45 return "SQLITE
4a30: 5f 45 52 52 4f 52 22 3b 0a 20 20 20 20 63 61 73 _ERROR";. cas
4a40: 65 20 53 51 4c 49 54 45 5f 49 4e 54 45 52 4e 41 e SQLITE_INTERNA
4a50: 4c 3a 20 20 20 72 65 74 75 72 6e 20 22 53 51 4c L: return "SQL
4a60: 49 54 45 5f 49 4e 54 45 52 4e 41 4c 22 3b 0a 20 ITE_INTERNAL";.
4a70: 20 20 20 63 61 73 65 20 53 51 4c 49 54 45 5f 50 case SQLITE_P
4a80: 45 52 4d 3a 20 20 20 20 20 20 20 72 65 74 75 72 ERM: retur
4a90: 6e 20 22 53 51 4c 49 54 45 5f 50 45 52 4d 22 3b n "SQLITE_PERM";
4aa0: 0a 20 20 20 20 63 61 73 65 20 53 51 4c 49 54 45 . case SQLITE
4ab0: 5f 41 42 4f 52 54 3a 20 20 20 20 20 20 72 65 74 _ABORT: ret
4ac0: 75 72 6e 20 22 53 51 4c 49 54 45 5f 41 42 4f 52 urn "SQLITE_ABOR
4ad0: 54 22 3b 0a 20 20 20 20 63 61 73 65 20 53 51 4c T";. case SQL
4ae0: 49 54 45 5f 42 55 53 59 3a 20 20 20 20 20 20 20 ITE_BUSY:
4af0: 72 65 74 75 72 6e 20 22 53 51 4c 49 54 45 5f 42 return "SQLITE_B
4b00: 55 53 59 22 3b 0a 20 20 20 20 63 61 73 65 20 53 USY";. case S
4b10: 51 4c 49 54 45 5f 4c 4f 43 4b 45 44 3a 20 20 20 QLITE_LOCKED:
4b20: 20 20 72 65 74 75 72 6e 20 22 53 51 4c 49 54 45 return "SQLITE
4b30: 5f 4c 4f 43 4b 45 44 22 3b 0a 20 20 20 20 63 61 _LOCKED";. ca
4b40: 73 65 20 53 51 4c 49 54 45 5f 4e 4f 4d 45 4d 3a se SQLITE_NOMEM:
4b50: 20 20 20 20 20 20 72 65 74 75 72 6e 20 22 53 51 return "SQ
4b60: 4c 49 54 45 5f 4e 4f 4d 45 4d 22 3b 0a 20 20 20 LITE_NOMEM";.
4b70: 20 63 61 73 65 20 53 51 4c 49 54 45 5f 52 45 41 case SQLITE_REA
4b80: 44 4f 4e 4c 59 3a 20 20 20 72 65 74 75 72 6e 20 DONLY: return
4b90: 22 53 51 4c 49 54 45 5f 52 45 41 44 4f 4e 4c 59 "SQLITE_READONLY
4ba0: 22 3b 0a 20 20 20 20 63 61 73 65 20 53 51 4c 49 ";. case SQLI
4bb0: 54 45 5f 49 4e 54 45 52 52 55 50 54 3a 20 20 72 TE_INTERRUPT: r
4bc0: 65 74 75 72 6e 20 22 53 51 4c 49 54 45 5f 49 4e eturn "SQLITE_IN
4bd0: 54 45 52 52 55 50 54 22 3b 0a 20 20 20 20 63 61 TERRUPT";. ca
4be0: 73 65 20 53 51 4c 49 54 45 5f 49 4f 45 52 52 3a se SQLITE_IOERR:
4bf0: 20 20 20 20 20 20 72 65 74 75 72 6e 20 22 53 51 return "SQ
4c00: 4c 49 54 45 5f 49 4f 45 52 52 22 3b 0a 20 20 20 LITE_IOERR";.
4c10: 20 63 61 73 65 20 53 51 4c 49 54 45 5f 43 4f 52 case SQLITE_COR
4c20: 52 55 50 54 3a 20 20 20 20 72 65 74 75 72 6e 20 RUPT: return
4c30: 22 53 51 4c 49 54 45 5f 43 4f 52 52 55 50 54 22 "SQLITE_CORRUPT"
4c40: 3b 0a 20 20 20 20 63 61 73 65 20 53 51 4c 49 54 ;. case SQLIT
4c50: 45 5f 4e 4f 54 46 4f 55 4e 44 3a 20 20 20 72 65 E_NOTFOUND: re
4c60: 74 75 72 6e 20 22 53 51 4c 49 54 45 5f 4e 4f 54 turn "SQLITE_NOT
4c70: 46 4f 55 4e 44 22 3b 0a 20 20 20 20 63 61 73 65 FOUND";. case
4c80: 20 53 51 4c 49 54 45 5f 46 55 4c 4c 3a 20 20 20 SQLITE_FULL:
4c90: 20 20 20 20 72 65 74 75 72 6e 20 22 53 51 4c 49 return "SQLI
4ca0: 54 45 5f 46 55 4c 4c 22 3b 0a 20 20 20 20 63 61 TE_FULL";. ca
4cb0: 73 65 20 53 51 4c 49 54 45 5f 43 41 4e 54 4f 50 se SQLITE_CANTOP
4cc0: 45 4e 3a 20 20 20 72 65 74 75 72 6e 20 22 53 51 EN: return "SQ
4cd0: 4c 49 54 45 5f 43 41 4e 54 4f 50 45 4e 22 3b 0a LITE_CANTOPEN";.
4ce0: 20 20 20 20 63 61 73 65 20 53 51 4c 49 54 45 5f case SQLITE_
4cf0: 50 52 4f 54 4f 43 4f 4c 3a 20 20 20 72 65 74 75 PROTOCOL: retu
4d00: 72 6e 20 22 53 51 4c 49 54 45 5f 50 52 4f 54 4f rn "SQLITE_PROTO
4d10: 43 4f 4c 22 3b 0a 20 20 20 20 63 61 73 65 20 53 COL";. case S
4d20: 51 4c 49 54 45 5f 45 4d 50 54 59 3a 20 20 20 20 QLITE_EMPTY:
4d30: 20 20 72 65 74 75 72 6e 20 22 53 51 4c 49 54 45 return "SQLITE
4d40: 5f 45 4d 50 54 59 22 3b 0a 20 20 20 20 63 61 73 _EMPTY";. cas
4d50: 65 20 53 51 4c 49 54 45 5f 53 43 48 45 4d 41 3a e SQLITE_SCHEMA:
4d60: 20 20 20 20 20 72 65 74 75 72 6e 20 22 53 51 4c return "SQL
4d70: 49 54 45 5f 53 43 48 45 4d 41 22 3b 0a 20 20 20 ITE_SCHEMA";.
4d80: 20 63 61 73 65 20 53 51 4c 49 54 45 5f 54 4f 4f case SQLITE_TOO
4d90: 42 49 47 3a 20 20 20 20 20 72 65 74 75 72 6e 20 BIG: return
4da0: 22 53 51 4c 49 54 45 5f 54 4f 4f 42 49 47 22 3b "SQLITE_TOOBIG";
4db0: 0a 20 20 20 20 63 61 73 65 20 53 51 4c 49 54 45 . case SQLITE
4dc0: 5f 43 4f 4e 53 54 52 41 49 4e 54 3a 20 72 65 74 _CONSTRAINT: ret
4dd0: 75 72 6e 20 22 53 51 4c 49 54 45 5f 43 4f 4e 53 urn "SQLITE_CONS
4de0: 54 52 41 49 4e 54 22 3b 0a 20 20 20 20 63 61 73 TRAINT";. cas
4df0: 65 20 53 51 4c 49 54 45 5f 4d 49 53 4d 41 54 43 e SQLITE_MISMATC
4e00: 48 3a 20 20 20 72 65 74 75 72 6e 20 22 53 51 4c H: return "SQL
4e10: 49 54 45 5f 4d 49 53 4d 41 54 43 48 22 3b 0a 20 ITE_MISMATCH";.
4e20: 20 20 20 63 61 73 65 20 53 51 4c 49 54 45 5f 4d case SQLITE_M
4e30: 49 53 55 53 45 3a 20 20 20 20 20 72 65 74 75 72 ISUSE: retur
4e40: 6e 20 22 53 51 4c 49 54 45 5f 4d 49 53 55 53 45 n "SQLITE_MISUSE
4e50: 22 3b 0a 20 20 20 20 63 61 73 65 20 53 51 4c 49 ";. case SQLI
4e60: 54 45 5f 4e 4f 4c 46 53 3a 20 20 20 20 20 20 72 TE_NOLFS: r
4e70: 65 74 75 72 6e 20 22 53 51 4c 49 54 45 5f 4e 4f eturn "SQLITE_NO
4e80: 4c 46 53 22 3b 0a 20 20 20 20 63 61 73 65 20 53 LFS";. case S
4e90: 51 4c 49 54 45 5f 41 55 54 48 3a 20 20 20 20 20 QLITE_AUTH:
4ea0: 20 20 72 65 74 75 72 6e 20 22 53 51 4c 49 54 45 return "SQLITE
4eb0: 5f 41 55 54 48 22 3b 0a 20 20 20 20 63 61 73 65 _AUTH";. case
4ec0: 20 53 51 4c 49 54 45 5f 46 4f 52 4d 41 54 3a 20 SQLITE_FORMAT:
4ed0: 20 20 20 20 72 65 74 75 72 6e 20 22 53 51 4c 49 return "SQLI
4ee0: 54 45 5f 46 4f 52 4d 41 54 22 3b 0a 20 20 20 20 TE_FORMAT";.
4ef0: 63 61 73 65 20 53 51 4c 49 54 45 5f 52 41 4e 47 case SQLITE_RANG
4f00: 45 3a 20 20 20 20 20 20 72 65 74 75 72 6e 20 22 E: return "
4f10: 53 51 4c 49 54 45 5f 52 41 4e 47 45 22 3b 0a 20 SQLITE_RANGE";.
4f20: 20 20 20 63 61 73 65 20 53 51 4c 49 54 45 5f 4e case SQLITE_N
4f30: 4f 54 41 44 42 3a 20 20 20 20 20 72 65 74 75 72 OTADB: retur
4f40: 6e 20 22 53 51 4c 49 54 45 5f 4e 4f 54 41 44 42 n "SQLITE_NOTADB
4f50: 22 3b 0a 20 20 20 20 63 61 73 65 20 53 51 4c 49 ";. case SQLI
4f60: 54 45 5f 4e 4f 54 49 43 45 3a 20 20 20 20 20 72 TE_NOTICE: r
4f70: 65 74 75 72 6e 20 22 53 51 4c 49 54 45 5f 4e 4f eturn "SQLITE_NO
4f80: 54 49 43 45 22 3b 0a 20 20 20 20 63 61 73 65 20 TICE";. case
4f90: 53 51 4c 49 54 45 5f 57 41 52 4e 49 4e 47 3a 20 SQLITE_WARNING:
4fa0: 20 20 20 72 65 74 75 72 6e 20 22 53 51 4c 49 54 return "SQLIT
4fb0: 45 5f 57 41 52 4e 49 4e 47 22 3b 0a 20 20 20 20 E_WARNING";.
4fc0: 63 61 73 65 20 53 51 4c 49 54 45 5f 52 4f 57 3a case SQLITE_ROW:
4fd0: 20 20 20 20 20 20 20 20 72 65 74 75 72 6e 20 22 return "
4fe0: 53 51 4c 49 54 45 5f 52 4f 57 22 3b 0a 20 20 20 SQLITE_ROW";.
4ff0: 20 63 61 73 65 20 53 51 4c 49 54 45 5f 44 4f 4e case SQLITE_DON
5000: 45 3a 20 20 20 20 20 20 20 72 65 74 75 72 6e 20 E: return
5010: 22 53 51 4c 49 54 45 5f 44 4f 4e 45 22 3b 0a 20 "SQLITE_DONE";.
5020: 20 20 20 64 65 66 61 75 6c 74 3a 20 7b 0a 20 20 default: {.
5030: 20 20 20 20 73 71 6c 69 74 65 33 5f 73 6e 70 72 sqlite3_snpr
5040: 69 6e 74 66 28 73 69 7a 65 6f 66 28 7a 43 6f 64 intf(sizeof(zCod
5050: 65 29 2c 20 7a 43 6f 64 65 2c 20 22 53 51 4c 69 e), zCode, "SQLi
5060: 74 65 20 72 65 74 75 72 6e 20 63 6f 64 65 20 25 te return code %
5070: 64 22 2c 20 72 63 29 3b 0a 20 20 20 20 7d 0a 20 d", rc);. }.
5080: 20 7d 0a 20 20 72 65 74 75 72 6e 20 7a 43 6f 64 }. return zCod
5090: 65 3b 0a 7d 0a 0a 2f 2a 20 45 72 72 6f 72 20 6c e;.}../* Error l
50a0: 6f 67 73 20 66 72 6f 6d 20 53 51 4c 69 74 65 20 ogs from SQLite
50b0: 2a 2f 0a 73 74 61 74 69 63 20 76 6f 69 64 20 66 */.static void f
50c0: 6f 73 73 69 6c 5f 73 71 6c 69 74 65 5f 6c 6f 67 ossil_sqlite_log
50d0: 28 76 6f 69 64 20 2a 6e 6f 74 55 73 65 64 2c 20 (void *notUsed,
50e0: 69 6e 74 20 69 43 6f 64 65 2c 20 63 6f 6e 73 74 int iCode, const
50f0: 20 63 68 61 72 20 2a 7a 45 72 72 6d 73 67 29 7b char *zErrmsg){
5100: 0a 23 69 66 64 65 66 20 5f 5f 41 50 50 4c 45 5f .#ifdef __APPLE_
5110: 5f 0a 20 20 2f 2a 20 44 69 73 61 62 6c 65 20 74 _. /* Disable t
5120: 68 65 20 66 69 6c 65 20 61 6c 69 61 73 20 77 61 he file alias wa
5130: 72 6e 69 6e 67 20 6f 6e 20 61 70 70 6c 65 20 70 rning on apple p
5140: 72 6f 64 75 63 74 73 20 62 65 63 61 75 73 65 20 roducts because
5150: 54 69 6d 65 20 4d 61 63 68 69 6e 65 0a 20 20 2a Time Machine. *
5160: 2a 20 63 72 65 61 74 65 73 20 6c 6f 74 73 20 6f * creates lots o
5170: 66 20 61 6c 69 61 73 65 73 20 61 6e 64 20 74 68 f aliases and th
5180: 65 20 77 61 72 6e 69 6e 67 20 61 6c 61 72 6d 73 e warning alarms
5190: 20 70 65 6f 70 6c 65 2e 20 2a 2f 0a 20 20 69 66 people. */. if
51a0: 28 20 69 43 6f 64 65 3d 3d 53 51 4c 49 54 45 5f ( iCode==SQLITE_
51b0: 57 41 52 4e 49 4e 47 20 29 20 72 65 74 75 72 6e WARNING ) return
51c0: 3b 0a 23 65 6e 64 69 66 0a 20 20 69 66 28 20 69 ;.#endif. if( i
51d0: 43 6f 64 65 3d 3d 53 51 4c 49 54 45 5f 53 43 48 Code==SQLITE_SCH
51e0: 45 4d 41 20 29 20 72 65 74 75 72 6e 3b 0a 20 20 EMA ) return;.
51f0: 69 66 28 20 67 2e 64 62 49 67 6e 6f 72 65 45 72 if( g.dbIgnoreEr
5200: 72 6f 72 73 20 29 20 72 65 74 75 72 6e 3b 0a 20 rors ) return;.
5210: 20 66 6f 73 73 69 6c 5f 77 61 72 6e 69 6e 67 28 fossil_warning(
5220: 22 25 73 3a 20 25 73 22 2c 20 66 6f 73 73 69 6c "%s: %s", fossil
5230: 5f 73 71 6c 69 74 65 5f 72 65 74 75 72 6e 5f 63 _sqlite_return_c
5240: 6f 64 65 5f 6e 61 6d 65 28 69 43 6f 64 65 29 2c ode_name(iCode),
5250: 20 7a 45 72 72 6d 73 67 29 3b 0a 7d 0a 0a 2f 2a zErrmsg);.}../*
5260: 0a 2a 2a 20 54 68 69 73 20 66 75 6e 63 74 69 6f .** This functio
5270: 6e 20 61 74 74 65 6d 70 74 73 20 74 6f 20 66 69 n attempts to fi
5280: 6e 64 20 63 6f 6d 6d 61 6e 64 20 6c 69 6e 65 20 nd command line
5290: 6f 70 74 69 6f 6e 73 20 6b 6e 6f 77 6e 20 74 6f options known to
52a0: 20 63 6f 6e 74 61 69 6e 0a 2a 2a 20 62 69 74 77 contain.** bitw
52b0: 69 73 65 20 66 6c 61 67 73 20 61 6e 64 20 69 6e ise flags and in
52c0: 69 74 69 61 6c 69 7a 65 73 20 74 68 65 20 61 73 itializes the as
52d0: 73 6f 63 69 61 74 65 64 20 67 6c 6f 62 61 6c 20 sociated global
52e0: 76 61 72 69 61 62 6c 65 73 2e 20 20 41 66 74 65 variables. Afte
52f0: 72 0a 2a 2a 20 74 68 69 73 20 66 75 6e 63 74 69 r.** this functi
5300: 6f 6e 20 65 78 65 63 75 74 65 73 2c 20 61 6c 6c on executes, all
5310: 20 67 6c 6f 62 61 6c 20 76 61 72 69 61 62 6c 65 global variable
5320: 73 20 28 69 2e 65 2e 20 69 6e 20 74 68 65 20 22 s (i.e. in the "
5330: 67 22 20 73 74 72 75 63 74 29 0a 2a 2a 20 63 6f g" struct).** co
5340: 6e 74 61 69 6e 69 6e 67 20 6f 70 74 69 6f 6e 2d ntaining option-
5350: 73 65 74 74 61 62 6c 65 20 62 69 74 77 69 73 65 settable bitwise
5360: 20 66 6c 61 67 20 66 69 65 6c 64 73 20 6d 75 73 flag fields mus
5370: 74 20 62 65 20 69 6e 69 74 69 61 6c 69 7a 65 64 t be initialized
5380: 2e 0a 2a 2f 0a 73 74 61 74 69 63 20 76 6f 69 64 ..*/.static void
5390: 20 66 6f 73 73 69 6c 5f 69 6e 69 74 5f 66 6c 61 fossil_init_fla
53a0: 67 73 5f 66 72 6f 6d 5f 6f 70 74 69 6f 6e 73 28 gs_from_options(
53b0: 76 6f 69 64 29 7b 0a 20 20 63 6f 6e 73 74 20 63 void){. const c
53c0: 68 61 72 20 2a 7a 56 61 6c 75 65 20 3d 20 66 69 har *zValue = fi
53d0: 6e 64 5f 6f 70 74 69 6f 6e 28 22 63 6f 6d 66 6d nd_option("comfm
53e0: 74 66 6c 61 67 73 22 2c 20 30 2c 20 31 29 3b 0a tflags", 0, 1);.
53f0: 20 20 69 66 28 20 7a 56 61 6c 75 65 20 29 7b 0a if( zValue ){.
5400: 20 20 20 20 67 2e 63 6f 6d 46 6d 74 46 6c 61 67 g.comFmtFlag
5410: 73 20 3d 20 61 74 6f 69 28 7a 56 61 6c 75 65 29 s = atoi(zValue)
5420: 3b 0a 20 20 7d 65 6c 73 65 7b 0a 20 20 20 20 67 ;. }else{. g
5430: 2e 63 6f 6d 46 6d 74 46 6c 61 67 73 20 3d 20 43 .comFmtFlags = C
5440: 4f 4d 4d 45 4e 54 5f 50 52 49 4e 54 5f 44 45 46 OMMENT_PRINT_DEF
5450: 41 55 4c 54 3b 0a 20 20 7d 0a 7d 0a 0a 2f 2a 0a AULT;. }.}../*.
5460: 2a 2a 20 54 68 69 73 20 70 72 6f 63 65 64 75 72 ** This procedur
5470: 65 20 72 75 6e 73 20 66 69 72 73 74 2e 0a 2a 2f e runs first..*/
5480: 0a 23 69 66 20 64 65 66 69 6e 65 64 28 5f 57 49 .#if defined(_WI
5490: 4e 33 32 29 20 26 26 20 21 64 65 66 69 6e 65 64 N32) && !defined
54a0: 28 42 52 4f 4b 45 4e 5f 4d 49 4e 47 57 5f 43 4d (BROKEN_MINGW_CM
54b0: 44 4c 49 4e 45 29 0a 69 6e 74 20 5f 64 6f 77 69 DLINE).int _dowi
54c0: 6c 64 63 61 72 64 20 3d 20 2d 31 3b 20 2f 2a 20 ldcard = -1; /*
54d0: 54 68 69 73 20 74 75 72 6e 73 20 6f 6e 20 63 6f This turns on co
54e0: 6d 6d 61 6e 64 2d 6c 69 6e 65 20 67 6c 6f 62 62 mmand-line globb
54f0: 69 6e 67 20 69 6e 20 4d 69 6e 47 57 2d 77 36 34 ing in MinGW-w64
5500: 20 2a 2f 0a 69 6e 74 20 77 6d 61 69 6e 28 69 6e */.int wmain(in
5510: 74 20 61 72 67 63 2c 20 77 63 68 61 72 5f 74 20 t argc, wchar_t
5520: 2a 2a 61 72 67 76 29 0a 23 65 6c 73 65 0a 23 69 **argv).#else.#i
5530: 66 20 64 65 66 69 6e 65 64 28 5f 57 49 4e 33 32 f defined(_WIN32
5540: 29 0a 69 6e 74 20 5f 43 52 54 5f 67 6c 6f 62 20 ).int _CRT_glob
5550: 3d 20 30 78 30 30 30 31 3b 20 2f 2a 20 53 65 65 = 0x0001; /* See
5560: 20 4d 69 6e 47 57 20 62 75 67 20 23 32 30 36 32 MinGW bug #2062
5570: 20 2a 2f 0a 23 65 6e 64 69 66 0a 69 6e 74 20 6d */.#endif.int m
5580: 61 69 6e 28 69 6e 74 20 61 72 67 63 2c 20 63 68 ain(int argc, ch
5590: 61 72 20 2a 2a 61 72 67 76 29 0a 23 65 6e 64 69 ar **argv).#endi
55a0: 66 0a 7b 0a 20 20 63 6f 6e 73 74 20 63 68 61 72 f.{. const char
55b0: 20 2a 7a 43 6d 64 4e 61 6d 65 20 3d 20 22 75 6e *zCmdName = "un
55c0: 6b 6e 6f 77 6e 22 3b 0a 20 20 63 6f 6e 73 74 20 known";. const
55d0: 43 6d 64 4f 72 50 61 67 65 20 2a 70 43 6d 64 20 CmdOrPage *pCmd
55e0: 3d 20 30 3b 0a 20 20 69 6e 74 20 72 63 3b 0a 0a = 0;. int rc;..
55f0: 20 20 66 6f 73 73 69 6c 5f 6c 69 6d 69 74 5f 6d fossil_limit_m
5600: 65 6d 6f 72 79 28 31 29 3b 0a 20 20 69 66 28 20 emory(1);. if(
5610: 73 71 6c 69 74 65 33 5f 6c 69 62 76 65 72 73 69 sqlite3_libversi
5620: 6f 6e 5f 6e 75 6d 62 65 72 28 29 3c 33 30 31 34 on_number()<3014
5630: 30 30 30 20 29 7b 0a 20 20 20 20 66 6f 73 73 69 000 ){. fossi
5640: 6c 5f 66 61 74 61 6c 28 22 55 6e 73 75 69 74 61 l_fatal("Unsuita
5650: 62 6c 65 20 53 51 4c 69 74 65 20 76 65 72 73 69 ble SQLite versi
5660: 6f 6e 20 25 73 2c 20 6d 75 73 74 20 62 65 20 61 on %s, must be a
5670: 74 20 6c 65 61 73 74 20 33 2e 31 34 2e 30 22 2c t least 3.14.0",
5680: 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 .
5690: 20 20 73 71 6c 69 74 65 33 5f 6c 69 62 76 65 72 sqlite3_libver
56a0: 73 69 6f 6e 28 29 29 3b 0a 20 20 7d 0a 20 20 73 sion());. }. s
56b0: 71 6c 69 74 65 33 5f 63 6f 6e 66 69 67 28 53 51 qlite3_config(SQ
56c0: 4c 49 54 45 5f 43 4f 4e 46 49 47 5f 4d 55 4c 54 LITE_CONFIG_MULT
56d0: 49 54 48 52 45 41 44 29 3b 0a 20 20 73 71 6c 69 ITHREAD);. sqli
56e0: 74 65 33 5f 63 6f 6e 66 69 67 28 53 51 4c 49 54 te3_config(SQLIT
56f0: 45 5f 43 4f 4e 46 49 47 5f 4c 4f 47 2c 20 66 6f E_CONFIG_LOG, fo
5700: 73 73 69 6c 5f 73 71 6c 69 74 65 5f 6c 6f 67 2c ssil_sqlite_log,
5710: 20 30 29 3b 0a 20 20 6d 65 6d 73 65 74 28 26 67 0);. memset(&g
5720: 2c 20 30 2c 20 73 69 7a 65 6f 66 28 67 29 29 3b , 0, sizeof(g));
5730: 0a 20 20 67 2e 6e 6f 77 20 3d 20 74 69 6d 65 28 . g.now = time(
5740: 30 29 3b 0a 20 20 67 2e 68 74 74 70 48 65 61 64 0);. g.httpHead
5750: 65 72 20 3d 20 65 6d 70 74 79 5f 62 6c 6f 62 3b er = empty_blob;
5760: 0a 23 69 66 64 65 66 20 46 4f 53 53 49 4c 5f 45 .#ifdef FOSSIL_E
5770: 4e 41 42 4c 45 5f 4a 53 4f 4e 0a 23 69 66 20 64 NABLE_JSON.#if d
5780: 65 66 69 6e 65 64 28 4e 44 45 42 55 47 29 0a 20 efined(NDEBUG).
5790: 20 67 2e 6a 73 6f 6e 2e 65 72 72 6f 72 44 65 74 g.json.errorDet
57a0: 61 69 6c 50 61 72 61 6e 6f 69 61 20 3d 20 32 20 ailParanoia = 2
57b0: 2f 2a 20 46 49 58 4d 45 3a 20 6d 61 6b 65 20 63 /* FIXME: make c
57c0: 6f 6e 66 69 67 75 72 61 62 6c 65 0a 20 20 20 20 onfigurable.
57d0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
57e0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
57f0: 4f 6e 65 20 70 72 6f 62 6c 65 6d 20 77 65 20 68 One problem we h
5800: 61 76 65 20 68 65 72 65 20 69 73 20 74 68 61 74 ave here is that
5810: 20 74 68 69 73 0a 20 20 20 20 20 20 20 20 20 20 this.
5820: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
5830: 20 20 20 20 20 20 20 20 20 20 63 6f 64 65 20 69 code i
5840: 73 20 6e 65 65 64 65 64 20 62 65 66 6f 72 65 20 s needed before
5850: 74 68 65 20 64 62 20 69 73 20 6f 70 65 6e 65 64 the db is opened
5860: 2c 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 ,.
5870: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
5880: 20 20 20 20 20 20 73 6f 20 77 65 20 63 61 6e 27 so we can'
5890: 74 20 73 71 6c 20 66 6f 72 20 69 74 2e 2a 2f 3b t sql for it.*/;
58a0: 0a 23 65 6c 73 65 0a 20 20 67 2e 6a 73 6f 6e 2e .#else. g.json.
58b0: 65 72 72 6f 72 44 65 74 61 69 6c 50 61 72 61 6e errorDetailParan
58c0: 6f 69 61 20 3d 20 30 3b 0a 23 65 6e 64 69 66 0a oia = 0;.#endif.
58d0: 20 20 67 2e 6a 73 6f 6e 2e 6f 75 74 4f 70 74 20 g.json.outOpt
58e0: 3d 20 63 73 6f 6e 5f 6f 75 74 70 75 74 5f 6f 70 = cson_output_op
58f0: 74 5f 65 6d 70 74 79 3b 0a 20 20 67 2e 6a 73 6f t_empty;. g.jso
5900: 6e 2e 6f 75 74 4f 70 74 2e 61 64 64 4e 65 77 6c n.outOpt.addNewl
5910: 69 6e 65 20 3d 20 31 3b 0a 20 20 67 2e 6a 73 6f ine = 1;. g.jso
5920: 6e 2e 6f 75 74 4f 70 74 2e 69 6e 64 65 6e 74 61 n.outOpt.indenta
5930: 74 69 6f 6e 20 3d 20 31 20 2f 2a 20 69 6e 20 43 tion = 1 /* in C
5940: 47 49 2f 73 65 72 76 65 72 20 6d 6f 64 65 20 74 GI/server mode t
5950: 68 69 73 20 63 61 6e 20 62 65 20 63 6f 6e 66 69 his can be confi
5960: 67 75 72 65 64 20 2a 2f 3b 0a 23 65 6e 64 69 66 gured */;.#endif
5970: 20 2f 2a 20 46 4f 53 53 49 4c 5f 45 4e 41 42 4c /* FOSSIL_ENABL
5980: 45 5f 4a 53 4f 4e 20 2a 2f 0a 20 20 65 78 70 61 E_JSON */. expa
5990: 6e 64 5f 61 72 67 73 5f 6f 70 74 69 6f 6e 28 61 nd_args_option(a
59a0: 72 67 63 2c 20 61 72 67 76 29 3b 0a 23 69 66 64 rgc, argv);.#ifd
59b0: 65 66 20 46 4f 53 53 49 4c 5f 45 4e 41 42 4c 45 ef FOSSIL_ENABLE
59c0: 5f 54 43 4c 0a 20 20 6d 65 6d 73 65 74 28 26 67 _TCL. memset(&g
59d0: 2e 74 63 6c 2c 20 30 2c 20 73 69 7a 65 6f 66 28 .tcl, 0, sizeof(
59e0: 54 63 6c 43 6f 6e 74 65 78 74 29 29 3b 0a 20 20 TclContext));.
59f0: 67 2e 74 63 6c 2e 61 72 67 63 20 3d 20 67 2e 61 g.tcl.argc = g.a
5a00: 72 67 63 3b 0a 20 20 67 2e 74 63 6c 2e 61 72 67 rgc;. g.tcl.arg
5a10: 76 20 3d 20 63 6f 70 79 5f 61 72 67 73 28 67 2e v = copy_args(g.
5a20: 61 72 67 63 2c 20 67 2e 61 72 67 76 29 3b 20 2f argc, g.argv); /
5a30: 2a 20 73 61 76 65 20 66 75 6c 6c 20 61 72 67 75 * save full argu
5a40: 6d 65 6e 74 73 20 2a 2f 0a 23 65 6e 64 69 66 0a ments */.#endif.
5a50: 20 20 67 2e 6d 61 69 6e 54 69 6d 65 72 49 64 20 g.mainTimerId
5a60: 3d 20 66 6f 73 73 69 6c 5f 74 69 6d 65 72 5f 73 = fossil_timer_s
5a70: 74 61 72 74 28 29 3b 0a 20 20 63 61 70 74 75 72 tart();. captur
5a80: 65 5f 63 61 73 65 5f 73 65 6e 73 69 74 69 76 65 e_case_sensitive
5a90: 5f 6f 70 74 69 6f 6e 28 29 3b 0a 20 20 67 2e 7a _option();. g.z
5aa0: 56 66 73 4e 61 6d 65 20 3d 20 66 69 6e 64 5f 6f VfsName = find_o
5ab0: 70 74 69 6f 6e 28 22 76 66 73 22 2c 30 2c 31 29 ption("vfs",0,1)
5ac0: 3b 0a 20 20 69 66 28 20 67 2e 7a 56 66 73 4e 61 ;. if( g.zVfsNa
5ad0: 6d 65 3d 3d 30 20 29 7b 0a 20 20 20 20 67 2e 7a me==0 ){. g.z
5ae0: 56 66 73 4e 61 6d 65 20 3d 20 66 6f 73 73 69 6c VfsName = fossil
5af0: 5f 67 65 74 65 6e 76 28 22 46 4f 53 53 49 4c 5f _getenv("FOSSIL_
5b00: 56 46 53 22 29 3b 0a 20 20 7d 0a 20 20 69 66 28 VFS");. }. if(
5b10: 20 67 2e 7a 56 66 73 4e 61 6d 65 20 29 7b 0a 20 g.zVfsName ){.
5b20: 20 20 20 73 71 6c 69 74 65 33 5f 76 66 73 20 2a sqlite3_vfs *
5b30: 70 56 66 73 20 3d 20 73 71 6c 69 74 65 33 5f 76 pVfs = sqlite3_v
5b40: 66 73 5f 66 69 6e 64 28 67 2e 7a 56 66 73 4e 61 fs_find(g.zVfsNa
5b50: 6d 65 29 3b 0a 20 20 20 20 69 66 28 20 70 56 66 me);. if( pVf
5b60: 73 20 29 7b 0a 20 20 20 20 20 20 73 71 6c 69 74 s ){. sqlit
5b70: 65 33 5f 76 66 73 5f 72 65 67 69 73 74 65 72 28 e3_vfs_register(
5b80: 70 56 66 73 2c 20 31 29 3b 0a 20 20 20 20 7d 65 pVfs, 1);. }e
5b90: 6c 73 65 7b 0a 20 20 20 20 20 20 66 6f 73 73 69 lse{. fossi
5ba0: 6c 5f 66 61 74 61 6c 28 22 6e 6f 20 73 75 63 68 l_fatal("no such
5bb0: 20 56 46 53 3a 20 5c 22 25 73 5c 22 22 2c 20 67 VFS: \"%s\"", g
5bc0: 2e 7a 56 66 73 4e 61 6d 65 29 3b 0a 20 20 20 20 .zVfsName);.
5bd0: 7d 0a 20 20 7d 0a 20 20 69 66 28 20 66 6f 73 73 }. }. if( foss
5be0: 69 6c 5f 67 65 74 65 6e 76 28 22 47 41 54 45 57 il_getenv("GATEW
5bf0: 41 59 5f 49 4e 54 45 52 46 41 43 45 22 29 21 3d AY_INTERFACE")!=
5c00: 30 20 26 26 20 21 66 69 6e 64 5f 6f 70 74 69 6f 0 && !find_optio
5c10: 6e 28 22 6e 6f 63 67 69 22 2c 20 30 2c 20 30 29 n("nocgi", 0, 0)
5c20: 29 7b 0a 20 20 20 20 7a 43 6d 64 4e 61 6d 65 20 ){. zCmdName
5c30: 3d 20 22 63 67 69 22 3b 0a 20 20 20 20 67 2e 69 = "cgi";. g.i
5c40: 73 48 54 54 50 20 3d 20 31 3b 0a 20 20 7d 65 6c sHTTP = 1;. }el
5c50: 73 65 20 69 66 28 20 67 2e 61 72 67 63 3c 32 20 se if( g.argc<2
5c60: 29 7b 0a 20 20 20 20 66 6f 73 73 69 6c 5f 70 72 ){. fossil_pr
5c70: 69 6e 74 28 0a 20 20 20 20 20 20 20 22 55 73 61 int(. "Usa
5c80: 67 65 3a 20 25 73 20 43 4f 4d 4d 41 4e 44 20 2e ge: %s COMMAND .
5c90: 2e 2e 5c 6e 22 0a 20 20 20 20 20 20 20 22 20 20 ..\n". "
5ca0: 20 6f 72 3a 20 25 73 20 68 65 6c 70 20 20 20 20 or: %s help
5cb0: 20 20 20 20 20 20 20 2d 2d 20 66 6f 72 20 61 20 -- for a
5cc0: 6c 69 73 74 20 6f 66 20 63 6f 6d 6d 6f 6e 20 63 list of common c
5cd0: 6f 6d 6d 61 6e 64 73 5c 6e 22 0a 20 20 20 20 20 ommands\n".
5ce0: 20 20 22 20 20 20 6f 72 3a 20 25 73 20 68 65 6c " or: %s hel
5cf0: 70 20 43 4f 4d 4d 41 4e 44 20 20 20 2d 2d 20 66 p COMMAND -- f
5d00: 6f 72 20 68 65 6c 70 20 77 69 74 68 20 74 68 65 or help with the
5d10: 20 6e 61 6d 65 64 20 63 6f 6d 6d 61 6e 64 5c 6e named command\n
5d20: 22 2c 0a 20 20 20 20 20 20 20 67 2e 61 72 67 76 ",. g.argv
5d30: 5b 30 5d 2c 20 67 2e 61 72 67 76 5b 30 5d 2c 20 [0], g.argv[0],
5d40: 67 2e 61 72 67 76 5b 30 5d 29 3b 0a 20 20 20 20 g.argv[0]);.
5d50: 66 6f 73 73 69 6c 5f 70 72 69 6e 74 28 0a 20 20 fossil_print(.
5d60: 20 20 20 20 22 5c 6e 43 6f 6d 6d 61 6e 64 73 20 "\nCommands
5d70: 61 6e 64 20 66 69 6c 65 6e 61 6d 65 73 20 6d 61 and filenames ma
5d80: 79 20 62 65 20 70 61 73 73 65 64 20 6f 6e 20 74 y be passed on t
5d90: 6f 20 66 6f 73 73 69 6c 20 66 72 6f 6d 20 61 20 o fossil from a
5da0: 66 69 6c 65 5c 6e 22 0a 20 20 20 20 20 20 22 62 file\n". "b
5db0: 79 20 75 73 69 6e 67 3a 5c 6e 22 0a 20 20 20 20 y using:\n".
5dc0: 20 20 22 5c 6e 20 20 20 20 25 73 20 2d 2d 61 72 "\n %s --ar
5dd0: 67 73 20 46 49 4c 45 4e 41 4d 45 20 2e 2e 2e 5c gs FILENAME ...\
5de0: 6e 22 2c 0a 20 20 20 20 20 20 67 2e 61 72 67 76 n",. g.argv
5df0: 5b 30 5d 0a 20 20 20 20 29 3b 0a 20 20 20 20 66 [0]. );. f
5e00: 6f 73 73 69 6c 5f 70 72 69 6e 74 28 0a 20 20 20 ossil_print(.
5e10: 20 20 20 22 5c 6e 45 61 63 68 20 6c 69 6e 65 20 "\nEach line
5e20: 6f 66 20 74 68 65 20 66 69 6c 65 20 69 73 20 61 of the file is a
5e30: 73 73 75 6d 65 64 20 74 6f 20 62 65 20 61 20 66 ssumed to be a f
5e40: 69 6c 65 6e 61 6d 65 20 75 6e 6c 65 73 73 20 69 ilename unless i
5e50: 74 20 73 74 61 72 74 73 5c 6e 22 0a 20 20 20 20 t starts\n".
5e60: 20 20 22 77 69 74 68 20 27 2d 27 20 61 6e 64 20 "with '-' and
5e70: 63 6f 6e 74 61 69 6e 73 20 61 20 73 70 61 63 65 contains a space
5e80: 2c 20 69 6e 20 77 68 69 63 68 20 63 61 73 65 20 , in which case
5e90: 69 74 20 69 73 20 61 73 73 75 6d 65 64 20 74 6f it is assumed to
5ea0: 20 62 65 5c 6e 22 0a 20 20 20 20 20 20 22 61 6e be\n". "an
5eb0: 6f 74 68 65 72 20 66 6c 61 67 20 61 6e 64 20 69 other flag and i
5ec0: 73 20 74 72 65 61 74 65 64 20 61 73 20 73 75 63 s treated as suc
5ed0: 68 2e 20 2d 2d 61 72 67 73 20 46 49 4c 45 4e 41 h. --args FILENA
5ee0: 4d 45 20 6d 61 79 20 62 65 20 75 73 65 64 5c 6e ME may be used\n
5ef0: 22 0a 20 20 20 20 20 20 22 69 6e 20 63 6f 6e 6a ". "in conj
5f00: 75 6e 63 74 69 6f 6e 20 77 69 74 68 20 61 6e 79 unction with any
5f10: 20 6f 74 68 65 72 20 66 6c 61 67 73 2e 5c 6e 22 other flags.\n"
5f20: 29 3b 0a 20 20 20 20 66 6f 73 73 69 6c 5f 65 78 );. fossil_ex
5f30: 69 74 28 31 29 3b 0a 20 20 7d 65 6c 73 65 7b 0a it(1);. }else{.
5f40: 20 20 20 20 63 6f 6e 73 74 20 63 68 61 72 20 2a const char *
5f50: 7a 43 68 64 69 72 20 3d 20 66 69 6e 64 5f 6f 70 zChdir = find_op
5f60: 74 69 6f 6e 28 22 63 68 64 69 72 22 2c 30 2c 31 tion("chdir",0,1
5f70: 29 3b 0a 20 20 20 20 67 2e 69 73 48 54 54 50 20 );. g.isHTTP
5f80: 3d 20 30 3b 0a 20 20 20 20 67 2e 72 63 76 69 64 = 0;. g.rcvid
5f90: 20 3d 20 30 3b 0a 20 20 20 20 67 2e 66 4e 6f 44 = 0;. g.fNoD
5fa0: 69 72 53 79 6d 6c 69 6e 6b 73 20 3d 20 66 69 6e irSymlinks = fin
5fb0: 64 5f 6f 70 74 69 6f 6e 28 22 6e 6f 2d 64 69 72 d_option("no-dir
5fc0: 2d 73 79 6d 6c 69 6e 6b 73 22 2c 20 30 2c 20 30 -symlinks", 0, 0
5fd0: 29 21 3d 30 3b 0a 20 20 20 20 67 2e 66 51 75 69 )!=0;. g.fQui
5fe0: 65 74 20 3d 20 66 69 6e 64 5f 6f 70 74 69 6f 6e et = find_option
5ff0: 28 22 71 75 69 65 74 22 2c 20 30 2c 20 30 29 21 ("quiet", 0, 0)!
6000: 3d 30 3b 0a 20 20 20 20 67 2e 66 53 71 6c 54 72 =0;. g.fSqlTr
6010: 61 63 65 20 3d 20 66 69 6e 64 5f 6f 70 74 69 6f ace = find_optio
6020: 6e 28 22 73 71 6c 74 72 61 63 65 22 2c 20 30 2c n("sqltrace", 0,
6030: 20 30 29 21 3d 30 3b 0a 20 20 20 20 67 2e 66 53 0)!=0;. g.fS
6040: 71 6c 53 74 61 74 73 20 3d 20 66 69 6e 64 5f 6f qlStats = find_o
6050: 70 74 69 6f 6e 28 22 73 71 6c 73 74 61 74 73 22 ption("sqlstats"
6060: 2c 20 30 2c 20 30 29 21 3d 30 3b 0a 20 20 20 20 , 0, 0)!=0;.
6070: 67 2e 66 53 79 73 74 65 6d 54 72 61 63 65 20 3d g.fSystemTrace =
6080: 20 66 69 6e 64 5f 6f 70 74 69 6f 6e 28 22 73 79 find_option("sy
6090: 73 74 65 6d 74 72 61 63 65 22 2c 20 30 2c 20 30 stemtrace", 0, 0
60a0: 29 21 3d 30 3b 0a 20 20 20 20 67 2e 66 53 73 68 )!=0;. g.fSsh
60b0: 54 72 61 63 65 20 3d 20 66 69 6e 64 5f 6f 70 74 Trace = find_opt
60c0: 69 6f 6e 28 22 73 73 68 74 72 61 63 65 22 2c 20 ion("sshtrace",
60d0: 30 2c 20 30 29 21 3d 30 3b 0a 20 20 20 20 67 2e 0, 0)!=0;. g.
60e0: 66 53 73 68 43 6c 69 65 6e 74 20 3d 20 30 3b 0a fSshClient = 0;.
60f0: 20 20 20 20 67 2e 7a 53 73 68 43 6d 64 20 3d 20 g.zSshCmd =
6100: 30 3b 0a 20 20 20 20 69 66 28 20 67 2e 66 53 71 0;. if( g.fSq
6110: 6c 54 72 61 63 65 20 29 20 67 2e 66 53 71 6c 53 lTrace ) g.fSqlS
6120: 74 61 74 73 20 3d 20 31 3b 0a 20 20 20 20 67 2e tats = 1;. g.
6130: 66 48 74 74 70 54 72 61 63 65 20 3d 20 66 69 6e fHttpTrace = fin
6140: 64 5f 6f 70 74 69 6f 6e 28 22 68 74 74 70 74 72 d_option("httptr
6150: 61 63 65 22 2c 20 30 2c 20 30 29 21 3d 30 3b 0a ace", 0, 0)!=0;.
6160: 23 69 66 64 65 66 20 46 4f 53 53 49 4c 5f 45 4e #ifdef FOSSIL_EN
6170: 41 42 4c 45 5f 54 48 31 5f 48 4f 4f 4b 53 0a 20 ABLE_TH1_HOOKS.
6180: 20 20 20 67 2e 66 4e 6f 54 68 48 6f 6f 6b 20 3d g.fNoThHook =
6190: 20 66 69 6e 64 5f 6f 70 74 69 6f 6e 28 22 6e 6f find_option("no
61a0: 2d 74 68 2d 68 6f 6f 6b 22 2c 20 30 2c 20 30 29 -th-hook", 0, 0)
61b0: 21 3d 30 3b 0a 23 65 6e 64 69 66 0a 20 20 20 20 !=0;.#endif.
61c0: 67 2e 66 41 6e 79 54 72 61 63 65 20 3d 20 67 2e g.fAnyTrace = g.
61d0: 66 53 71 6c 54 72 61 63 65 7c 67 2e 66 53 79 73 fSqlTrace|g.fSys
61e0: 74 65 6d 54 72 61 63 65 7c 67 2e 66 53 73 68 54 temTrace|g.fSshT
61f0: 72 61 63 65 7c 67 2e 66 48 74 74 70 54 72 61 63 race|g.fHttpTrac
6200: 65 3b 0a 20 20 20 20 67 2e 7a 48 74 74 70 41 75 e;. g.zHttpAu
6210: 74 68 20 3d 20 30 3b 0a 20 20 20 20 67 2e 7a 4c th = 0;. g.zL
6220: 6f 67 69 6e 20 3d 20 66 69 6e 64 5f 6f 70 74 69 ogin = find_opti
6230: 6f 6e 28 22 75 73 65 72 22 2c 20 22 55 22 2c 20 on("user", "U",
6240: 31 29 3b 0a 20 20 20 20 67 2e 7a 53 53 4c 49 64 1);. g.zSSLId
6250: 65 6e 74 69 74 79 20 3d 20 66 69 6e 64 5f 6f 70 entity = find_op
6260: 74 69 6f 6e 28 22 73 73 6c 2d 69 64 65 6e 74 69 tion("ssl-identi
6270: 74 79 22 2c 20 30 2c 20 31 29 3b 0a 20 20 20 20 ty", 0, 1);.
6280: 67 2e 7a 45 72 72 6c 6f 67 20 3d 20 66 69 6e 64 g.zErrlog = find
6290: 5f 6f 70 74 69 6f 6e 28 22 65 72 72 6f 72 6c 6f _option("errorlo
62a0: 67 22 2c 20 30 2c 20 31 29 3b 0a 20 20 20 20 66 g", 0, 1);. f
62b0: 6f 73 73 69 6c 5f 69 6e 69 74 5f 66 6c 61 67 73 ossil_init_flags
62c0: 5f 66 72 6f 6d 5f 6f 70 74 69 6f 6e 73 28 29 3b _from_options();
62d0: 0a 20 20 20 20 69 66 28 20 66 69 6e 64 5f 6f 70 . if( find_op
62e0: 74 69 6f 6e 28 22 75 74 63 22 2c 30 2c 30 29 20 tion("utc",0,0)
62f0: 29 20 67 2e 66 54 69 6d 65 46 6f 72 6d 61 74 20 ) g.fTimeFormat
6300: 3d 20 31 3b 0a 20 20 20 20 69 66 28 20 66 69 6e = 1;. if( fin
6310: 64 5f 6f 70 74 69 6f 6e 28 22 6c 6f 63 61 6c 74 d_option("localt
6320: 69 6d 65 22 2c 30 2c 30 29 20 29 20 67 2e 66 54 ime",0,0) ) g.fT
6330: 69 6d 65 46 6f 72 6d 61 74 20 3d 20 32 3b 0a 20 imeFormat = 2;.
6340: 20 20 20 69 66 28 20 7a 43 68 64 69 72 20 26 26 if( zChdir &&
6350: 20 66 69 6c 65 5f 63 68 64 69 72 28 7a 43 68 64 file_chdir(zChd
6360: 69 72 2c 20 30 29 20 29 7b 0a 20 20 20 20 20 20 ir, 0) ){.
6370: 66 6f 73 73 69 6c 5f 66 61 74 61 6c 28 22 75 6e fossil_fatal("un
6380: 61 62 6c 65 20 74 6f 20 63 68 61 6e 67 65 20 64 able to change d
6390: 69 72 65 63 74 6f 72 69 65 73 20 74 6f 20 25 73 irectories to %s
63a0: 22 2c 20 7a 43 68 64 69 72 29 3b 0a 20 20 20 20 ", zChdir);.
63b0: 7d 0a 20 20 20 20 69 66 28 20 66 69 6e 64 5f 6f }. if( find_o
63c0: 70 74 69 6f 6e 28 22 68 65 6c 70 22 2c 30 2c 30 ption("help",0,0
63d0: 29 21 3d 30 20 29 7b 0a 20 20 20 20 20 20 2f 2a )!=0 ){. /*
63e0: 20 49 66 20 2d 2d 68 65 6c 70 20 69 73 20 66 6f If --help is fo
63f0: 75 6e 64 20 61 6e 79 77 68 65 72 65 20 6f 6e 20 und anywhere on
6400: 74 68 65 20 63 6f 6d 6d 61 6e 64 20 6c 69 6e 65 the command line
6410: 2c 20 74 72 61 6e 73 6c 61 74 65 20 74 68 65 20 , translate the
6420: 63 6f 6d 6d 61 6e 64 0a 20 20 20 20 20 20 20 2a command. *
6430: 20 74 6f 20 22 66 6f 73 73 69 6c 20 68 65 6c 70 to "fossil help
6440: 20 63 6d 64 6e 61 6d 65 22 20 77 68 65 72 65 20 cmdname" where
6450: 22 63 6d 64 6e 61 6d 65 22 20 69 73 20 74 68 65 "cmdname" is the
6460: 20 66 69 72 73 74 20 61 72 67 75 6d 65 6e 74 20 first argument
6470: 74 68 61 74 0a 20 20 20 20 20 20 20 2a 20 64 6f that. * do
6480: 65 73 20 6e 6f 74 20 62 65 67 69 6e 20 77 69 74 es not begin wit
6490: 68 20 61 20 22 2d 22 20 63 68 61 72 61 63 74 65 h a "-" characte
64a0: 72 2e 20 20 49 66 20 61 6c 6c 20 61 72 67 75 6d r. If all argum
64b0: 65 6e 74 73 20 73 74 61 72 74 20 77 69 74 68 20 ents start with
64c0: 22 2d 22 2c 0a 20 20 20 20 20 20 20 2a 20 74 72 "-",. * tr
64d0: 61 6e 73 6c 61 74 65 20 74 6f 20 22 66 6f 73 73 anslate to "foss
64e0: 69 6c 20 68 65 6c 70 20 61 72 67 76 5b 31 5d 20 il help argv[1]
64f0: 61 72 67 76 5b 32 5d 2e 2e 2e 22 2e 20 2a 2f 0a argv[2]...". */.
6500: 20 20 20 20 20 20 69 6e 74 20 69 2c 20 6e 4e 65 int i, nNe
6510: 77 41 72 67 63 3b 0a 20 20 20 20 20 20 63 68 61 wArgc;. cha
6520: 72 20 2a 2a 7a 4e 65 77 41 72 67 76 20 3d 20 66 r **zNewArgv = f
6530: 6f 73 73 69 6c 5f 6d 61 6c 6c 6f 63 28 20 73 69 ossil_malloc( si
6540: 7a 65 6f 66 28 63 68 61 72 2a 29 2a 28 67 2e 61 zeof(char*)*(g.a
6550: 72 67 63 2b 32 29 20 29 3b 0a 20 20 20 20 20 20 rgc+2) );.
6560: 7a 4e 65 77 41 72 67 76 5b 30 5d 20 3d 20 67 2e zNewArgv[0] = g.
6570: 61 72 67 76 5b 30 5d 3b 0a 20 20 20 20 20 20 7a argv[0];. z
6580: 4e 65 77 41 72 67 76 5b 31 5d 20 3d 20 22 68 65 NewArgv[1] = "he
6590: 6c 70 22 3b 0a 20 20 20 20 20 20 66 6f 72 28 69 lp";. for(i
65a0: 3d 31 3b 20 69 3c 67 2e 61 72 67 63 3b 20 69 2b =1; i<g.argc; i+
65b0: 2b 29 7b 0a 20 20 20 20 20 20 20 20 69 66 28 20 +){. if(
65c0: 67 2e 61 72 67 76 5b 69 5d 5b 30 5d 21 3d 27 2d g.argv[i][0]!='-
65d0: 27 20 29 7b 0a 20 20 20 20 20 20 20 20 20 20 6e ' ){. n
65e0: 4e 65 77 41 72 67 63 20 3d 20 33 3b 0a 20 20 20 NewArgc = 3;.
65f0: 20 20 20 20 20 20 20 7a 4e 65 77 41 72 67 76 5b zNewArgv[
6600: 32 5d 20 3d 20 67 2e 61 72 67 76 5b 69 5d 3b 0a 2] = g.argv[i];.
6610: 20 20 20 20 20 20 20 20 20 20 7a 4e 65 77 41 72 zNewAr
6620: 67 76 5b 33 5d 20 3d 20 30 3b 0a 20 20 20 20 20 gv[3] = 0;.
6630: 20 20 20 20 20 62 72 65 61 6b 3b 0a 20 20 20 20 break;.
6640: 20 20 20 20 7d 0a 20 20 20 20 20 20 7d 0a 20 20 }. }.
6650: 20 20 20 20 69 66 28 20 69 3d 3d 67 2e 61 72 67 if( i==g.arg
6660: 63 20 29 7b 0a 20 20 20 20 20 20 20 20 66 6f 72 c ){. for
6670: 28 69 3d 31 3b 20 69 3c 67 2e 61 72 67 63 3b 20 (i=1; i<g.argc;
6680: 69 2b 2b 29 20 7a 4e 65 77 41 72 67 76 5b 69 2b i++) zNewArgv[i+
6690: 31 5d 20 3d 20 67 2e 61 72 67 76 5b 69 5d 3b 0a 1] = g.argv[i];.
66a0: 20 20 20 20 20 20 20 20 6e 4e 65 77 41 72 67 63 nNewArgc
66b0: 20 3d 20 67 2e 61 72 67 63 2b 31 3b 0a 20 20 20 = g.argc+1;.
66c0: 20 20 20 20 20 7a 4e 65 77 41 72 67 76 5b 69 2b zNewArgv[i+
66d0: 31 5d 20 3d 20 30 3b 0a 20 20 20 20 20 20 7d 0a 1] = 0;. }.
66e0: 20 20 20 20 20 20 67 2e 61 72 67 63 20 3d 20 6e g.argc = n
66f0: 4e 65 77 41 72 67 63 3b 0a 20 20 20 20 20 20 67 NewArgc;. g
6700: 2e 61 72 67 76 20 3d 20 7a 4e 65 77 41 72 67 76 .argv = zNewArgv
6710: 3b 0a 20 20 20 20 7d 0a 20 20 20 20 7a 43 6d 64 ;. }. zCmd
6720: 4e 61 6d 65 20 3d 20 67 2e 61 72 67 76 5b 31 5d Name = g.argv[1]
6730: 3b 0a 20 20 7d 0a 23 69 66 6e 64 65 66 20 5f 57 ;. }.#ifndef _W
6740: 49 4e 33 32 0a 20 20 2f 2a 20 54 68 65 72 65 20 IN32. /* There
6750: 69 73 20 61 20 62 75 67 20 69 6e 20 73 74 75 6e is a bug in stun
6760: 6e 65 6c 34 20 69 6e 20 77 68 69 63 68 20 69 74 nel4 in which it
6770: 20 73 6f 6d 65 74 69 6d 65 73 20 73 74 61 72 74 sometimes start
6780: 73 20 75 70 20 63 6c 69 65 6e 74 0a 20 20 2a 2a s up client. **
6790: 20 70 72 6f 63 65 73 73 65 73 20 77 69 74 68 6f processes witho
67a0: 75 74 20 66 69 72 73 74 20 6f 70 65 6e 69 6e 67 ut first opening
67b0: 20 66 69 6c 65 20 64 65 73 63 72 69 70 74 6f 72 file descriptor
67c0: 20 32 20 28 73 74 61 6e 64 61 72 64 20 65 72 72 2 (standard err
67d0: 6f 72 29 2e 0a 20 20 2a 2a 20 49 66 20 74 68 69 or).. ** If thi
67e0: 73 20 68 61 70 70 65 6e 73 2c 20 61 6e 64 20 61 s happens, and a
67f0: 20 73 75 62 73 65 71 75 65 6e 74 20 6f 70 65 6e subsequent open
6800: 28 29 20 6f 66 20 61 20 64 61 74 61 62 61 73 65 () of a database
6810: 20 72 65 74 75 72 6e 73 20 66 69 6c 65 0a 20 20 returns file.
6820: 2a 2a 20 64 65 73 63 72 69 70 74 6f 72 20 32 2c ** descriptor 2,
6830: 20 61 6e 64 20 74 68 65 6e 20 61 6e 20 61 73 73 and then an ass
6840: 65 72 74 28 29 20 66 69 72 65 73 20 61 6e 64 20 ert() fires and
6850: 77 72 69 74 65 73 20 6f 6e 20 66 64 20 32 2c 20 writes on fd 2,
6860: 74 68 61 74 0a 20 20 2a 2a 20 63 61 6e 20 63 6f that. ** can co
6870: 72 72 75 70 74 20 74 68 65 20 64 61 74 61 20 66 rrupt the data f
6880: 69 6c 65 2e 20 20 54 6f 20 61 76 6f 69 64 20 74 ile. To avoid t
6890: 68 69 73 20 70 72 6f 62 6c 65 6d 2c 20 6d 61 6b his problem, mak
68a0: 65 20 73 75 72 65 20 6f 70 65 6e 28 29 0a 20 20 e sure open().
68b0: 2a 2a 20 77 69 6c 6c 20 6e 65 76 65 72 20 72 65 ** will never re
68c0: 74 75 72 6e 20 66 69 6c 65 20 64 65 73 63 72 69 turn file descri
68d0: 70 74 6f 72 20 32 20 6f 72 20 6c 65 73 73 2e 20 ptor 2 or less.
68e0: 2a 2f 0a 20 20 69 66 28 20 21 69 73 5f 76 61 6c */. if( !is_val
68f0: 69 64 5f 66 64 28 32 29 20 29 7b 0a 20 20 20 20 id_fd(2) ){.
6900: 69 6e 74 20 6e 54 72 79 20 3d 20 30 3b 0a 20 20 int nTry = 0;.
6910: 20 20 69 6e 74 20 66 64 20 3d 20 30 3b 0a 20 20 int fd = 0;.
6920: 20 20 69 6e 74 20 78 20 3d 20 30 3b 0a 20 20 20 int x = 0;.
6930: 20 64 6f 7b 0a 20 20 20 20 20 20 66 64 20 3d 20 do{. fd =
6940: 6f 70 65 6e 28 22 2f 64 65 76 2f 6e 75 6c 6c 22 open("/dev/null"
6950: 2c 4f 5f 57 52 4f 4e 4c 59 29 3b 0a 20 20 20 20 ,O_WRONLY);.
6960: 20 20 69 66 28 20 66 64 3e 3d 32 20 29 20 62 72 if( fd>=2 ) br
6970: 65 61 6b 3b 0a 20 20 20 20 20 20 69 66 28 20 66 eak;. if( f
6980: 64 3c 30 20 29 20 78 20 3d 20 65 72 72 6e 6f 3b d<0 ) x = errno;
6990: 0a 20 20 20 20 7d 77 68 69 6c 65 28 20 6e 54 72 . }while( nTr
69a0: 79 2b 2b 20 3c 20 32 20 29 3b 0a 20 20 20 20 69 y++ < 2 );. i
69b0: 66 28 20 66 64 3c 32 20 29 7b 0a 20 20 20 20 20 f( fd<2 ){.
69c0: 20 67 2e 63 67 69 4f 75 74 70 75 74 20 3d 20 31 g.cgiOutput = 1
69d0: 3b 0a 20 20 20 20 20 20 67 2e 68 74 74 70 4f 75 ;. g.httpOu
69e0: 74 20 3d 20 73 74 64 6f 75 74 3b 0a 20 20 20 20 t = stdout;.
69f0: 20 20 67 2e 66 75 6c 6c 48 74 74 70 52 65 70 6c g.fullHttpRepl
6a00: 79 20 3d 20 21 67 2e 69 73 48 54 54 50 3b 0a 20 y = !g.isHTTP;.
6a10: 20 20 20 20 20 66 6f 73 73 69 6c 5f 66 61 74 61 fossil_fata
6a20: 6c 28 22 66 69 6c 65 20 64 65 73 63 72 69 70 74 l("file descript
6a30: 6f 72 20 32 20 69 73 20 6e 6f 74 20 6f 70 65 6e or 2 is not open
6a40: 2e 20 28 66 64 3d 25 64 2c 20 65 72 72 6e 6f 3d . (fd=%d, errno=
6a50: 25 64 29 22 2c 0a 20 20 20 20 20 20 20 20 20 20 %d)",.
6a60: 20 20 20 20 20 20 20 20 20 66 64 2c 20 78 29 3b fd, x);
6a70: 0a 20 20 20 20 7d 0a 20 20 7d 0a 23 65 6e 64 69 . }. }.#endi
6a80: 66 0a 20 20 72 63 20 3d 20 64 69 73 70 61 74 63 f. rc = dispatc
6a90: 68 5f 6e 61 6d 65 5f 73 65 61 72 63 68 28 7a 43 h_name_search(zC
6aa0: 6d 64 4e 61 6d 65 2c 20 43 4d 44 46 4c 41 47 5f mdName, CMDFLAG_
6ab0: 43 4f 4d 4d 41 4e 44 7c 43 4d 44 46 4c 41 47 5f COMMAND|CMDFLAG_
6ac0: 50 52 45 46 49 58 2c 20 26 70 43 6d 64 29 3b 0a PREFIX, &pCmd);.
6ad0: 20 20 69 66 28 20 72 63 3d 3d 31 20 29 7b 0a 23 if( rc==1 ){.#
6ae0: 69 66 64 65 66 20 46 4f 53 53 49 4c 5f 45 4e 41 ifdef FOSSIL_ENA
6af0: 42 4c 45 5f 54 48 31 5f 48 4f 4f 4b 53 0a 20 20 BLE_TH1_HOOKS.
6b00: 20 20 69 66 28 20 21 67 2e 69 73 48 54 54 50 20 if( !g.isHTTP
6b10: 26 26 20 21 67 2e 66 4e 6f 54 68 48 6f 6f 6b 20 && !g.fNoThHook
6b20: 29 7b 0a 20 20 20 20 20 20 72 63 20 3d 20 54 68 ){. rc = Th
6b30: 5f 43 6f 6d 6d 61 6e 64 48 6f 6f 6b 28 7a 43 6d _CommandHook(zCm
6b40: 64 4e 61 6d 65 2c 20 30 29 3b 0a 20 20 20 20 7d dName, 0);. }
6b50: 65 6c 73 65 7b 0a 20 20 20 20 20 20 72 63 20 3d else{. rc =
6b60: 20 54 48 5f 4f 4b 3b 0a 20 20 20 20 7d 0a 20 20 TH_OK;. }.
6b70: 20 20 69 66 28 20 72 63 3d 3d 54 48 5f 4f 4b 20 if( rc==TH_OK
6b80: 7c 7c 20 72 63 3d 3d 54 48 5f 52 45 54 55 52 4e || rc==TH_RETURN
6b90: 20 7c 7c 20 72 63 3d 3d 54 48 5f 43 4f 4e 54 49 || rc==TH_CONTI
6ba0: 4e 55 45 20 29 7b 0a 20 20 20 20 20 20 69 66 28 NUE ){. if(
6bb0: 20 72 63 3d 3d 54 48 5f 4f 4b 20 7c 7c 20 72 63 rc==TH_OK || rc
6bc0: 3d 3d 54 48 5f 52 45 54 55 52 4e 20 29 7b 0a 23 ==TH_RETURN ){.#
6bd0: 65 6e 64 69 66 0a 20 20 20 20 20 20 20 20 66 6f endif. fo
6be0: 73 73 69 6c 5f 66 61 74 61 6c 28 22 25 73 3a 20 ssil_fatal("%s:
6bf0: 75 6e 6b 6e 6f 77 6e 20 63 6f 6d 6d 61 6e 64 3a unknown command:
6c00: 20 25 73 5c 6e 22 0a 20 20 20 20 20 20 20 20 20 %s\n".
6c10: 20 20 20 20 20 20 20 20 20 20 20 20 22 25 73 3a "%s:
6c20: 20 75 73 65 20 5c 22 68 65 6c 70 5c 22 20 66 6f use \"help\" fo
6c30: 72 20 6d 6f 72 65 20 69 6e 66 6f 72 6d 61 74 69 r more informati
6c40: 6f 6e 22 2c 0a 20 20 20 20 20 20 20 20 20 20 20 on",.
6c50: 20 20 20 20 20 20 20 20 20 20 67 2e 61 72 67 76 g.argv
6c60: 5b 30 5d 2c 20 7a 43 6d 64 4e 61 6d 65 2c 20 67 [0], zCmdName, g
6c70: 2e 61 72 67 76 5b 30 5d 29 3b 0a 23 69 66 64 65 .argv[0]);.#ifde
6c80: 66 20 46 4f 53 53 49 4c 5f 45 4e 41 42 4c 45 5f f FOSSIL_ENABLE_
6c90: 54 48 31 5f 48 4f 4f 4b 53 0a 20 20 20 20 20 20 TH1_HOOKS.
6ca0: 7d 0a 20 20 20 20 20 20 69 66 28 20 21 67 2e 69 }. if( !g.i
6cb0: 73 48 54 54 50 20 26 26 20 21 67 2e 66 4e 6f 54 sHTTP && !g.fNoT
6cc0: 68 48 6f 6f 6b 20 26 26 20 28 72 63 3d 3d 54 48 hHook && (rc==TH
6cd0: 5f 4f 4b 20 7c 7c 20 72 63 3d 3d 54 48 5f 43 4f _OK || rc==TH_CO
6ce0: 4e 54 49 4e 55 45 29 20 29 7b 0a 20 20 20 20 20 NTINUE) ){.
6cf0: 20 20 20 54 68 5f 43 6f 6d 6d 61 6e 64 4e 6f 74 Th_CommandNot
6d00: 69 66 79 28 7a 43 6d 64 4e 61 6d 65 2c 20 30 29 ify(zCmdName, 0)
6d10: 3b 0a 20 20 20 20 20 20 7d 0a 20 20 20 20 7d 0a ;. }. }.
6d20: 20 20 20 20 66 6f 73 73 69 6c 5f 65 78 69 74 28 fossil_exit(
6d30: 30 29 3b 0a 23 65 6e 64 69 66 0a 20 20 7d 65 6c 0);.#endif. }el
6d40: 73 65 20 69 66 28 20 72 63 3d 3d 32 20 29 7b 0a se if( rc==2 ){.
6d50: 20 20 20 20 42 6c 6f 62 20 63 6f 75 6c 64 62 65 Blob couldbe
6d60: 3b 0a 20 20 20 20 62 6c 6f 62 5f 69 6e 69 74 28 ;. blob_init(
6d70: 26 63 6f 75 6c 64 62 65 2c 30 2c 30 29 3b 0a 20 &couldbe,0,0);.
6d80: 20 20 20 64 69 73 70 61 74 63 68 5f 6d 61 74 63 dispatch_matc
6d90: 68 69 6e 67 5f 6e 61 6d 65 73 28 7a 43 6d 64 4e hing_names(zCmdN
6da0: 61 6d 65 2c 20 26 63 6f 75 6c 64 62 65 29 3b 0a ame, &couldbe);.
6db0: 20 20 20 20 66 6f 73 73 69 6c 5f 70 72 69 6e 74 fossil_print
6dc0: 28 22 25 73 3a 20 61 6d 62 69 67 75 6f 75 73 20 ("%s: ambiguous
6dd0: 63 6f 6d 6d 61 6e 64 20 70 72 65 66 69 78 3a 20 command prefix:
6de0: 25 73 5c 6e 22 0a 20 20 20 20 20 20 20 20 20 20 %s\n".
6df0: 20 20 20 20 20 20 20 22 25 73 3a 20 63 6f 75 6c "%s: coul
6e00: 64 20 62 65 20 61 6e 79 20 6f 66 3a 25 73 5c 6e d be any of:%s\n
6e10: 22 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 ".
6e20: 20 20 20 22 25 73 3a 20 75 73 65 20 5c 22 68 65 "%s: use \"he
6e30: 6c 70 5c 22 20 66 6f 72 20 6d 6f 72 65 20 69 6e lp\" for more in
6e40: 66 6f 72 6d 61 74 69 6f 6e 5c 6e 22 2c 0a 20 20 formation\n",.
6e50: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 67 g
6e60: 2e 61 72 67 76 5b 30 5d 2c 20 7a 43 6d 64 4e 61 .argv[0], zCmdNa
6e70: 6d 65 2c 20 67 2e 61 72 67 76 5b 30 5d 2c 20 62 me, g.argv[0], b
6e80: 6c 6f 62 5f 73 74 72 28 26 63 6f 75 6c 64 62 65 lob_str(&couldbe
6e90: 29 2c 20 67 2e 61 72 67 76 5b 30 5d 29 3b 0a 20 ), g.argv[0]);.
6ea0: 20 20 20 66 6f 73 73 69 6c 5f 65 78 69 74 28 31 fossil_exit(1
6eb0: 29 3b 0a 20 20 7d 0a 20 20 61 74 65 78 69 74 28 );. }. atexit(
6ec0: 20 66 6f 73 73 69 6c 5f 61 74 65 78 69 74 20 29 fossil_atexit )
6ed0: 3b 0a 23 69 66 64 65 66 20 46 4f 53 53 49 4c 5f ;.#ifdef FOSSIL_
6ee0: 45 4e 41 42 4c 45 5f 54 48 31 5f 48 4f 4f 4b 53 ENABLE_TH1_HOOKS
6ef0: 0a 20 20 2f 2a 0a 20 20 2a 2a 20 54 68 65 20 54 . /*. ** The T
6f00: 48 31 20 72 65 74 75 72 6e 20 63 6f 64 65 73 20 H1 return codes
6f10: 66 72 6f 6d 20 74 68 65 20 68 6f 6f 6b 20 77 69 from the hook wi
6f20: 6c 6c 20 62 65 20 68 61 6e 64 6c 65 64 20 61 73 ll be handled as
6f30: 20 66 6f 6c 6c 6f 77 73 3a 0a 20 20 2a 2a 0a 20 follows:. **.
6f40: 20 2a 2a 20 54 48 5f 4f 4b 3a 20 54 68 65 20 78 ** TH_OK: The x
6f50: 46 75 6e 63 28 29 20 61 6e 64 20 74 68 65 20 54 Func() and the T
6f60: 48 31 20 6e 6f 74 69 66 69 63 61 74 69 6f 6e 20 H1 notification
6f70: 77 69 6c 6c 20 62 6f 74 68 20 62 65 20 65 78 65 will both be exe
6f80: 63 75 74 65 64 2e 0a 20 20 2a 2a 0a 20 20 2a 2a cuted.. **. **
6f90: 20 54 48 5f 45 52 52 4f 52 3a 20 54 68 65 20 78 TH_ERROR: The x
6fa0: 46 75 6e 63 28 29 20 77 69 6c 6c 20 62 65 20 65 Func() will be e
6fb0: 78 65 63 75 74 65 64 2c 20 74 68 65 20 54 48 31 xecuted, the TH1
6fc0: 20 6e 6f 74 69 66 69 63 61 74 69 6f 6e 20 77 69 notification wi
6fd0: 6c 6c 20 62 65 0a 20 20 2a 2a 20 20 20 20 20 20 ll be. **
6fe0: 20 20 20 20 20 73 6b 69 70 70 65 64 2e 20 20 49 skipped. I
6ff0: 66 20 74 68 65 20 78 46 75 6e 63 28 29 20 69 73 f the xFunc() is
7000: 20 62 65 69 6e 67 20 68 6f 6f 6b 65 64 2c 20 74 being hooked, t
7010: 68 65 20 65 72 72 6f 72 20 6d 65 73 73 61 67 65 he error message
7020: 0a 20 20 2a 2a 20 20 20 20 20 20 20 20 20 20 20 . **
7030: 77 69 6c 6c 20 62 65 20 65 6d 69 74 74 65 64 2e will be emitted.
7040: 0a 20 20 2a 2a 0a 20 20 2a 2a 20 54 48 5f 42 52 . **. ** TH_BR
7050: 45 41 4b 3a 20 54 68 65 20 78 46 75 6e 63 28 29 EAK: The xFunc()
7060: 20 61 6e 64 20 74 68 65 20 54 48 31 20 6e 6f 74 and the TH1 not
7070: 69 66 69 63 61 74 69 6f 6e 20 77 69 6c 6c 20 62 ification will b
7080: 6f 74 68 20 62 65 20 73 6b 69 70 70 65 64 2e 0a oth be skipped..
7090: 20 20 2a 2a 0a 20 20 2a 2a 20 54 48 5f 52 45 54 **. ** TH_RET
70a0: 55 52 4e 3a 20 54 68 65 20 78 46 75 6e 63 28 29 URN: The xFunc()
70b0: 20 77 69 6c 6c 20 62 65 20 65 78 65 63 75 74 65 will be execute
70c0: 64 2c 20 74 68 65 20 54 48 31 20 6e 6f 74 69 66 d, the TH1 notif
70d0: 69 63 61 74 69 6f 6e 20 77 69 6c 6c 20 62 65 0a ication will be.
70e0: 20 20 2a 2a 20 20 20 20 20 20 20 20 20 20 20 20 **
70f0: 73 6b 69 70 70 65 64 2e 0a 20 20 2a 2a 0a 20 20 skipped.. **.
7100: 2a 2a 20 54 48 5f 43 4f 4e 54 49 4e 55 45 3a 20 ** TH_CONTINUE:
7110: 54 68 65 20 78 46 75 6e 63 28 29 20 77 69 6c 6c The xFunc() will
7120: 20 62 65 20 73 6b 69 70 70 65 64 2c 20 74 68 65 be skipped, the
7130: 20 54 48 31 20 6e 6f 74 69 66 69 63 61 74 69 6f TH1 notificatio
7140: 6e 20 77 69 6c 6c 20 62 65 0a 20 20 2a 2a 20 20 n will be. **
7150: 20 20 20 20 20 20 20 20 20 20 20 20 65 78 65 63 exec
7160: 75 74 65 64 2e 0a 20 20 2a 2f 0a 20 20 69 66 28 uted.. */. if(
7170: 20 21 67 2e 69 73 48 54 54 50 20 26 26 20 21 67 !g.isHTTP && !g
7180: 2e 66 4e 6f 54 68 48 6f 6f 6b 20 29 7b 0a 20 20 .fNoThHook ){.
7190: 20 20 72 63 20 3d 20 54 68 5f 43 6f 6d 6d 61 6e rc = Th_Comman
71a0: 64 48 6f 6f 6b 28 70 43 6d 64 2d 3e 7a 4e 61 6d dHook(pCmd->zNam
71b0: 65 2c 20 70 43 6d 64 2d 3e 65 43 6d 64 46 6c 61 e, pCmd->eCmdFla
71c0: 67 73 29 3b 0a 20 20 7d 65 6c 73 65 7b 0a 20 20 gs);. }else{.
71d0: 20 20 72 63 20 3d 20 54 48 5f 4f 4b 3b 0a 20 20 rc = TH_OK;.
71e0: 7d 0a 20 20 69 66 28 20 72 63 3d 3d 54 48 5f 4f }. if( rc==TH_O
71f0: 4b 20 7c 7c 20 72 63 3d 3d 54 48 5f 52 45 54 55 K || rc==TH_RETU
7200: 52 4e 20 7c 7c 20 72 63 3d 3d 54 48 5f 43 4f 4e RN || rc==TH_CON
7210: 54 49 4e 55 45 20 29 7b 0a 20 20 20 20 69 66 28 TINUE ){. if(
7220: 20 72 63 3d 3d 54 48 5f 4f 4b 20 7c 7c 20 72 63 rc==TH_OK || rc
7230: 3d 3d 54 48 5f 52 45 54 55 52 4e 20 29 7b 0a 23 ==TH_RETURN ){.#
7240: 65 6e 64 69 66 0a 20 20 20 20 20 20 70 43 6d 64 endif. pCmd
7250: 2d 3e 78 46 75 6e 63 28 29 3b 0a 23 69 66 64 65 ->xFunc();.#ifde
7260: 66 20 46 4f 53 53 49 4c 5f 45 4e 41 42 4c 45 5f f FOSSIL_ENABLE_
7270: 54 48 31 5f 48 4f 4f 4b 53 0a 20 20 20 20 7d 0a TH1_HOOKS. }.
7280: 20 20 20 20 69 66 28 20 21 67 2e 69 73 48 54 54 if( !g.isHTT
7290: 50 20 26 26 20 21 67 2e 66 4e 6f 54 68 48 6f 6f P && !g.fNoThHoo
72a0: 6b 20 26 26 20 28 72 63 3d 3d 54 48 5f 4f 4b 20 k && (rc==TH_OK
72b0: 7c 7c 20 72 63 3d 3d 54 48 5f 43 4f 4e 54 49 4e || rc==TH_CONTIN
72c0: 55 45 29 20 29 7b 0a 20 20 20 20 20 20 54 68 5f UE) ){. Th_
72d0: 43 6f 6d 6d 61 6e 64 4e 6f 74 69 66 79 28 70 43 CommandNotify(pC
72e0: 6d 64 2d 3e 7a 4e 61 6d 65 2c 20 70 43 6d 64 2d md->zName, pCmd-
72f0: 3e 65 43 6d 64 46 6c 61 67 73 29 3b 0a 20 20 20 >eCmdFlags);.
7300: 20 7d 0a 20 20 7d 0a 23 65 6e 64 69 66 0a 20 20 }. }.#endif.
7310: 66 6f 73 73 69 6c 5f 65 78 69 74 28 30 29 3b 0a fossil_exit(0);.
7320: 20 20 2f 2a 4e 4f 54 5f 52 45 41 43 48 45 44 2a /*NOT_REACHED*
7330: 2f 0a 20 20 72 65 74 75 72 6e 20 30 3b 0a 7d 0a /. return 0;.}.
7340: 0a 2f 2a 0a 2a 2a 20 50 72 69 6e 74 20 61 20 75 ./*.** Print a u
7350: 73 61 67 65 20 63 6f 6d 6d 65 6e 74 20 61 6e 64 sage comment and
7360: 20 71 75 69 74 0a 2a 2f 0a 76 6f 69 64 20 75 73 quit.*/.void us
7370: 61 67 65 28 63 6f 6e 73 74 20 63 68 61 72 20 2a age(const char *
7380: 7a 46 6f 72 6d 61 74 29 7b 0a 20 20 66 6f 73 73 zFormat){. foss
7390: 69 6c 5f 66 61 74 61 6c 28 22 55 73 61 67 65 3a il_fatal("Usage:
73a0: 20 25 73 20 25 73 20 25 73 22 2c 20 67 2e 61 72 %s %s %s", g.ar
73b0: 67 76 5b 30 5d 2c 20 67 2e 61 72 67 76 5b 31 5d gv[0], g.argv[1]
73c0: 2c 20 7a 46 6f 72 6d 61 74 29 3b 0a 7d 0a 0a 2f , zFormat);.}../
73d0: 2a 0a 2a 2a 20 52 65 6d 6f 76 65 20 6e 20 65 6c *.** Remove n el
73e0: 65 6d 65 6e 74 73 20 66 72 6f 6d 20 67 2e 61 72 ements from g.ar
73f0: 67 76 20 62 65 67 69 6e 6e 69 6e 67 20 77 69 74 gv beginning wit
7400: 68 20 74 68 65 20 69 2d 74 68 20 65 6c 65 6d 65 h the i-th eleme
7410: 6e 74 2e 0a 2a 2f 0a 73 74 61 74 69 63 20 76 6f nt..*/.static vo
7420: 69 64 20 72 65 6d 6f 76 65 5f 66 72 6f 6d 5f 61 id remove_from_a
7430: 72 67 76 28 69 6e 74 20 69 2c 20 69 6e 74 20 6e rgv(int i, int n
7440: 29 7b 0a 20 20 69 6e 74 20 6a 3b 0a 20 20 66 6f ){. int j;. fo
7450: 72 28 6a 3d 69 2b 6e 3b 20 6a 3c 67 2e 61 72 67 r(j=i+n; j<g.arg
7460: 63 3b 20 69 2b 2b 2c 20 6a 2b 2b 29 7b 0a 20 20 c; i++, j++){.
7470: 20 20 67 2e 61 72 67 76 5b 69 5d 20 3d 20 67 2e g.argv[i] = g.
7480: 61 72 67 76 5b 6a 5d 3b 0a 20 20 7d 0a 20 20 67 argv[j];. }. g
7490: 2e 61 72 67 63 20 3d 20 69 3b 0a 7d 0a 0a 0a 2f .argc = i;.}.../
74a0: 2a 0a 2a 2a 20 4c 6f 6f 6b 20 66 6f 72 20 61 20 *.** Look for a
74b0: 63 6f 6d 6d 61 6e 64 2d 6c 69 6e 65 20 6f 70 74 command-line opt
74c0: 69 6f 6e 2e 20 20 49 66 20 70 72 65 73 65 6e 74 ion. If present
74d0: 2c 20 72 65 74 75 72 6e 20 61 20 70 6f 69 6e 74 , return a point
74e0: 65 72 2e 0a 2a 2a 20 52 65 74 75 72 6e 20 4e 55 er..** Return NU
74f0: 4c 4c 20 69 66 20 6d 69 73 73 69 6e 67 2e 0a 2a LL if missing..*
7500: 2a 0a 2a 2a 20 68 61 73 41 72 67 3d 3d 30 20 6d *.** hasArg==0 m
7510: 65 61 6e 73 20 74 68 65 20 6f 70 74 69 6f 6e 20 eans the option
7520: 69 73 20 61 20 66 6c 61 67 2e 20 20 49 74 20 69 is a flag. It i
7530: 73 20 65 69 74 68 65 72 20 70 72 65 73 65 6e 74 s either present
7540: 20 6f 72 20 6e 6f 74 2e 0a 2a 2a 20 68 61 73 41 or not..** hasA
7550: 72 67 3d 3d 31 20 6d 65 61 6e 73 20 74 68 65 20 rg==1 means the
7560: 6f 70 74 69 6f 6e 20 68 61 73 20 61 6e 20 61 72 option has an ar
7570: 67 75 6d 65 6e 74 2e 20 20 52 65 74 75 72 6e 20 gument. Return
7580: 61 20 70 6f 69 6e 74 65 72 20 74 6f 20 74 68 65 a pointer to the
7590: 0a 2a 2a 20 61 72 67 75 6d 65 6e 74 2e 0a 2a 2f .** argument..*/
75a0: 0a 63 6f 6e 73 74 20 63 68 61 72 20 2a 66 69 6e .const char *fin
75b0: 64 5f 6f 70 74 69 6f 6e 28 63 6f 6e 73 74 20 63 d_option(const c
75c0: 68 61 72 20 2a 7a 4c 6f 6e 67 2c 20 63 6f 6e 73 har *zLong, cons
75d0: 74 20 63 68 61 72 20 2a 7a 53 68 6f 72 74 2c 20 t char *zShort,
75e0: 69 6e 74 20 68 61 73 41 72 67 29 7b 0a 20 20 69 int hasArg){. i
75f0: 6e 74 20 69 3b 0a 20 20 69 6e 74 20 6e 4c 6f 6e nt i;. int nLon
7600: 67 3b 0a 20 20 63 6f 6e 73 74 20 63 68 61 72 20 g;. const char
7610: 2a 7a 52 65 74 75 72 6e 20 3d 20 30 3b 0a 20 20 *zReturn = 0;.
7620: 61 73 73 65 72 74 28 20 68 61 73 41 72 67 3d 3d assert( hasArg==
7630: 30 20 7c 7c 20 68 61 73 41 72 67 3d 3d 31 20 29 0 || hasArg==1 )
7640: 3b 0a 20 20 6e 4c 6f 6e 67 20 3d 20 73 74 72 6c ;. nLong = strl
7650: 65 6e 28 7a 4c 6f 6e 67 29 3b 0a 20 20 66 6f 72 en(zLong);. for
7660: 28 69 3d 31 3b 20 69 3c 67 2e 61 72 67 63 3b 20 (i=1; i<g.argc;
7670: 69 2b 2b 29 7b 0a 20 20 20 20 63 68 61 72 20 2a i++){. char *
7680: 7a 3b 0a 20 20 20 20 69 66 28 20 69 2b 68 61 73 z;. if( i+has
7690: 41 72 67 20 3e 3d 20 67 2e 61 72 67 63 20 29 20 Arg >= g.argc )
76a0: 62 72 65 61 6b 3b 0a 20 20 20 20 7a 20 3d 20 67 break;. z = g
76b0: 2e 61 72 67 76 5b 69 5d 3b 0a 20 20 20 20 69 66 .argv[i];. if
76c0: 28 20 7a 5b 30 5d 21 3d 27 2d 27 20 29 20 63 6f ( z[0]!='-' ) co
76d0: 6e 74 69 6e 75 65 3b 0a 20 20 20 20 7a 2b 2b 3b ntinue;. z++;
76e0: 0a 20 20 20 20 69 66 28 20 7a 5b 30 5d 3d 3d 27 . if( z[0]=='
76f0: 2d 27 20 29 7b 0a 20 20 20 20 20 20 69 66 28 20 -' ){. if(
7700: 7a 5b 31 5d 3d 3d 30 20 29 7b 0a 20 20 20 20 20 z[1]==0 ){.
7710: 20 20 20 72 65 6d 6f 76 65 5f 66 72 6f 6d 5f 61 remove_from_a
7720: 72 67 76 28 69 2c 20 31 29 3b 0a 20 20 20 20 20 rgv(i, 1);.
7730: 20 20 20 62 72 65 61 6b 3b 0a 20 20 20 20 20 20 break;.
7740: 7d 0a 20 20 20 20 20 20 7a 2b 2b 3b 0a 20 20 20 }. z++;.
7750: 20 7d 0a 20 20 20 20 69 66 28 20 73 74 72 6e 63 }. if( strnc
7760: 6d 70 28 7a 2c 7a 4c 6f 6e 67 2c 6e 4c 6f 6e 67 mp(z,zLong,nLong
7770: 29 3d 3d 30 20 29 7b 0a 20 20 20 20 20 20 69 66 )==0 ){. if
7780: 28 20 68 61 73 41 72 67 20 26 26 20 7a 5b 6e 4c ( hasArg && z[nL
7790: 6f 6e 67 5d 3d 3d 27 3d 27 20 29 7b 0a 20 20 20 ong]=='=' ){.
77a0: 20 20 20 20 20 7a 52 65 74 75 72 6e 20 3d 20 26 zReturn = &
77b0: 7a 5b 6e 4c 6f 6e 67 2b 31 5d 3b 0a 20 20 20 20 z[nLong+1];.
77c0: 20 20 20 20 72 65 6d 6f 76 65 5f 66 72 6f 6d 5f remove_from_
77d0: 61 72 67 76 28 69 2c 20 31 29 3b 0a 20 20 20 20 argv(i, 1);.
77e0: 20 20 20 20 62 72 65 61 6b 3b 0a 20 20 20 20 20 break;.
77f0: 20 7d 65 6c 73 65 20 69 66 28 20 7a 5b 6e 4c 6f }else if( z[nLo
7800: 6e 67 5d 3d 3d 30 20 29 7b 0a 20 20 20 20 20 20 ng]==0 ){.
7810: 20 20 7a 52 65 74 75 72 6e 20 3d 20 67 2e 61 72 zReturn = g.ar
7820: 67 76 5b 69 2b 68 61 73 41 72 67 5d 3b 0a 20 20 gv[i+hasArg];.
7830: 20 20 20 20 20 20 72 65 6d 6f 76 65 5f 66 72 6f remove_fro
7840: 6d 5f 61 72 67 76 28 69 2c 20 31 2b 68 61 73 41 m_argv(i, 1+hasA
7850: 72 67 29 3b 0a 20 20 20 20 20 20 20 20 62 72 65 rg);. bre
7860: 61 6b 3b 0a 20 20 20 20 20 20 7d 0a 20 20 20 20 ak;. }.
7870: 7d 65 6c 73 65 20 69 66 28 20 66 6f 73 73 69 6c }else if( fossil
7880: 5f 73 74 72 63 6d 70 28 7a 2c 7a 53 68 6f 72 74 _strcmp(z,zShort
7890: 29 3d 3d 30 20 29 7b 0a 20 20 20 20 20 20 7a 52 )==0 ){. zR
78a0: 65 74 75 72 6e 20 3d 20 67 2e 61 72 67 76 5b 69 eturn = g.argv[i
78b0: 2b 68 61 73 41 72 67 5d 3b 0a 20 20 20 20 20 20 +hasArg];.
78c0: 72 65 6d 6f 76 65 5f 66 72 6f 6d 5f 61 72 67 76 remove_from_argv
78d0: 28 69 2c 20 31 2b 68 61 73 41 72 67 29 3b 0a 20 (i, 1+hasArg);.
78e0: 20 20 20 20 20 62 72 65 61 6b 3b 0a 20 20 20 20 break;.
78f0: 7d 0a 20 20 7d 0a 20 20 72 65 74 75 72 6e 20 7a }. }. return z
7900: 52 65 74 75 72 6e 3b 0a 7d 0a 0a 2f 2a 0a 2a 2a Return;.}../*.**
7910: 20 4c 6f 6f 6b 20 66 6f 72 20 6d 75 6c 74 69 70 Look for multip
7920: 6c 65 20 6f 63 63 75 72 72 65 6e 63 65 73 20 6f le occurrences o
7930: 66 20 61 20 63 6f 6d 6d 61 6e 64 2d 6c 69 6e 65 f a command-line
7940: 20 6f 70 74 69 6f 6e 20 77 69 74 68 20 74 68 65 option with the
7950: 0a 2a 2a 20 63 6f 72 72 65 73 70 6f 6e 64 69 6e .** correspondin
7960: 67 20 61 72 67 75 6d 65 6e 74 2e 0a 2a 2a 0a 2a g argument..**.*
7970: 2a 20 52 65 74 75 72 6e 20 61 20 6d 61 6c 6c 6f * Return a mallo
7980: 63 20 61 6c 6c 6f 63 61 74 65 64 20 61 72 72 61 c allocated arra
7990: 79 20 6f 66 20 70 6f 69 6e 74 65 72 73 20 74 6f y of pointers to
79a0: 20 74 68 65 20 61 72 67 75 6d 65 6e 74 73 2e 0a the arguments..
79b0: 2a 2a 0a 2a 2a 20 70 6e 55 73 65 64 41 72 67 73 **.** pnUsedArgs
79c0: 20 69 73 20 75 73 65 64 20 74 6f 20 73 74 6f 72 is used to stor
79d0: 65 20 74 68 65 20 6e 75 6d 62 65 72 20 6f 66 20 e the number of
79e0: 6d 61 74 63 68 65 64 20 61 72 67 75 6d 65 6e 74 matched argument
79f0: 73 2e 0a 2a 2a 0a 2a 2a 20 43 61 6c 6c 65 72 20 s..**.** Caller
7a00: 69 73 20 72 65 73 70 6f 6e 73 69 62 6c 65 20 74 is responsible t
7a10: 6f 20 66 72 65 65 20 61 6c 6c 6f 63 61 74 65 64 o free allocated
7a20: 20 6d 65 6d 6f 72 79 2e 0a 2a 2f 0a 63 6f 6e 73 memory..*/.cons
7a30: 74 20 63 68 61 72 20 2a 2a 66 69 6e 64 5f 72 65 t char **find_re
7a40: 70 65 61 74 61 62 6c 65 5f 6f 70 74 69 6f 6e 28 peatable_option(
7a50: 0a 20 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a . const char *z
7a60: 4c 6f 6e 67 2c 0a 20 20 63 6f 6e 73 74 20 63 68 Long,. const ch
7a70: 61 72 20 2a 7a 53 68 6f 72 74 2c 0a 20 20 69 6e ar *zShort,. in
7a80: 74 20 2a 70 6e 55 73 65 64 41 72 67 73 0a 29 7b t *pnUsedArgs.){
7a90: 0a 20 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a . const char *z
7aa0: 4f 70 74 69 6f 6e 3b 0a 20 20 63 6f 6e 73 74 20 Option;. const
7ab0: 63 68 61 72 20 2a 2a 70 7a 41 72 67 73 20 3d 20 char **pzArgs =
7ac0: 30 3b 0a 20 20 69 6e 74 20 6e 41 6c 6c 6f 63 41 0;. int nAllocA
7ad0: 72 67 73 20 3d 20 30 3b 0a 20 20 69 6e 74 20 6e rgs = 0;. int n
7ae0: 55 73 65 64 41 72 67 73 20 3d 20 30 3b 0a 0a 20 UsedArgs = 0;..
7af0: 20 77 68 69 6c 65 28 20 28 7a 4f 70 74 69 6f 6e while( (zOption
7b00: 20 3d 20 66 69 6e 64 5f 6f 70 74 69 6f 6e 28 7a = find_option(z
7b10: 4c 6f 6e 67 2c 20 7a 53 68 6f 72 74 2c 20 31 29 Long, zShort, 1)
7b20: 29 21 3d 30 20 29 7b 0a 20 20 20 20 69 66 28 20 )!=0 ){. if(
7b30: 70 7a 41 72 67 73 3d 3d 30 20 26 26 20 6e 41 6c pzArgs==0 && nAl
7b40: 6c 6f 63 41 72 67 73 3d 3d 30 20 29 7b 0a 20 20 locArgs==0 ){.
7b50: 20 20 20 20 6e 41 6c 6c 6f 63 41 72 67 73 20 3d nAllocArgs =
7b60: 20 31 3b 0a 20 20 20 20 20 20 70 7a 41 72 67 73 1;. pzArgs
7b70: 20 3d 20 66 6f 73 73 69 6c 5f 6d 61 6c 6c 6f 63 = fossil_malloc
7b80: 28 20 6e 41 6c 6c 6f 63 41 72 67 73 2a 73 69 7a ( nAllocArgs*siz
7b90: 65 6f 66 28 70 7a 41 72 67 73 5b 30 5d 29 20 29 eof(pzArgs[0]) )
7ba0: 3b 0a 20 20 20 20 7d 65 6c 73 65 20 69 66 28 20 ;. }else if(
7bb0: 6e 41 6c 6c 6f 63 41 72 67 73 3c 3d 6e 55 73 65 nAllocArgs<=nUse
7bc0: 64 41 72 67 73 20 29 7b 0a 20 20 20 20 20 20 6e dArgs ){. n
7bd0: 41 6c 6c 6f 63 41 72 67 73 20 3d 20 6e 41 6c 6c AllocArgs = nAll
7be0: 6f 63 41 72 67 73 2a 32 3b 0a 20 20 20 20 20 20 ocArgs*2;.
7bf0: 70 7a 41 72 67 73 20 3d 20 66 6f 73 73 69 6c 5f pzArgs = fossil_
7c00: 72 65 61 6c 6c 6f 63 28 20 28 76 6f 69 64 20 2a realloc( (void *
7c10: 29 70 7a 41 72 67 73 2c 20 6e 41 6c 6c 6f 63 41 )pzArgs, nAllocA
7c20: 72 67 73 2a 73 69 7a 65 6f 66 28 70 7a 41 72 67 rgs*sizeof(pzArg
7c30: 73 5b 30 5d 29 20 29 3b 0a 20 20 20 20 7d 0a 20 s[0]) );. }.
7c40: 20 20 20 70 7a 41 72 67 73 5b 6e 55 73 65 64 41 pzArgs[nUsedA
7c50: 72 67 73 2b 2b 5d 20 3d 20 7a 4f 70 74 69 6f 6e rgs++] = zOption
7c60: 3b 0a 20 20 7d 0a 20 20 2a 70 6e 55 73 65 64 41 ;. }. *pnUsedA
7c70: 72 67 73 20 3d 20 6e 55 73 65 64 41 72 67 73 3b rgs = nUsedArgs;
7c80: 0a 20 20 72 65 74 75 72 6e 20 70 7a 41 72 67 73 . return pzArgs
7c90: 3b 0a 7d 0a 0a 2f 2a 0a 2a 2a 20 4c 6f 6f 6b 20 ;.}../*.** Look
7ca0: 66 6f 72 20 61 20 72 65 70 6f 73 69 74 6f 72 79 for a repository
7cb0: 20 63 6f 6d 6d 61 6e 64 2d 6c 69 6e 65 20 6f 70 command-line op
7cc0: 74 69 6f 6e 2e 20 20 49 66 20 70 72 65 73 65 6e tion. If presen
7cd0: 74 2c 20 5b 72 65 2d 5d 63 61 63 68 65 20 69 74 t, [re-]cache it
7ce0: 20 69 6e 0a 2a 2a 20 74 68 65 20 67 6c 6f 62 61 in.** the globa
7cf0: 6c 20 73 74 61 74 65 20 61 6e 64 20 72 65 74 75 l state and retu
7d00: 72 6e 20 74 68 65 20 6e 65 77 20 70 6f 69 6e 74 rn the new point
7d10: 65 72 2c 20 66 72 65 65 69 6e 67 20 61 6e 79 20 er, freeing any
7d20: 70 72 65 76 69 6f 75 73 20 76 61 6c 75 65 2e 0a previous value..
7d30: 2a 2a 20 49 66 20 61 62 73 65 6e 74 20 61 6e 64 ** If absent and
7d40: 20 74 68 65 72 65 20 69 73 20 6e 6f 20 63 61 63 there is no cac
7d50: 68 65 64 20 76 61 6c 75 65 2c 20 72 65 74 75 72 hed value, retur
7d60: 6e 20 4e 55 4c 4c 2e 0a 2a 2f 0a 63 6f 6e 73 74 n NULL..*/.const
7d70: 20 63 68 61 72 20 2a 66 69 6e 64 5f 72 65 70 6f char *find_repo
7d80: 73 69 74 6f 72 79 5f 6f 70 74 69 6f 6e 28 29 7b sitory_option(){
7d90: 0a 20 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a . const char *z
7da0: 52 65 70 6f 73 69 74 6f 72 79 20 3d 20 66 69 6e Repository = fin
7db0: 64 5f 6f 70 74 69 6f 6e 28 22 72 65 70 6f 73 69 d_option("reposi
7dc0: 74 6f 72 79 22 2c 20 22 52 22 2c 20 31 29 3b 0a tory", "R", 1);.
7dd0: 20 20 69 66 28 20 7a 52 65 70 6f 73 69 74 6f 72 if( zRepositor
7de0: 79 20 29 7b 0a 20 20 20 20 69 66 28 20 67 2e 7a y ){. if( g.z
7df0: 52 65 70 6f 73 69 74 6f 72 79 4f 70 74 69 6f 6e RepositoryOption
7e00: 20 29 20 66 6f 73 73 69 6c 5f 66 72 65 65 28 67 ) fossil_free(g
7e10: 2e 7a 52 65 70 6f 73 69 74 6f 72 79 4f 70 74 69 .zRepositoryOpti
7e20: 6f 6e 29 3b 0a 20 20 20 20 67 2e 7a 52 65 70 6f on);. g.zRepo
7e30: 73 69 74 6f 72 79 4f 70 74 69 6f 6e 20 3d 20 6d sitoryOption = m
7e40: 70 72 69 6e 74 66 28 22 25 73 22 2c 20 7a 52 65 printf("%s", zRe
7e50: 70 6f 73 69 74 6f 72 79 29 3b 0a 20 20 7d 0a 20 pository);. }.
7e60: 20 72 65 74 75 72 6e 20 67 2e 7a 52 65 70 6f 73 return g.zRepos
7e70: 69 74 6f 72 79 4f 70 74 69 6f 6e 3b 0a 7d 0a 0a itoryOption;.}..
7e80: 2f 2a 0a 2a 2a 20 56 65 72 69 66 79 20 74 68 61 /*.** Verify tha
7e90: 74 20 74 68 65 72 65 20 61 72 65 20 6e 6f 20 75 t there are no u
7ea0: 6e 70 72 6f 63 65 73 73 65 64 20 63 6f 6d 6d 61 nprocessed comma
7eb0: 6e 64 2d 6c 69 6e 65 20 6f 70 74 69 6f 6e 73 2e nd-line options.
7ec0: 20 20 49 66 0a 2a 2a 20 41 6e 79 20 72 65 6d 61 If.** Any rema
7ed0: 69 6e 69 6e 67 20 63 6f 6d 6d 61 6e 64 2d 6c 69 ining command-li
7ee0: 6e 65 20 61 72 67 75 6d 65 6e 74 20 62 65 67 69 ne argument begi
7ef0: 6e 73 20 77 69 74 68 20 22 2d 22 20 70 72 69 6e ns with "-" prin
7f00: 74 0a 2a 2a 20 61 6e 20 65 72 72 6f 72 20 6d 65 t.** an error me
7f10: 73 73 61 67 65 20 61 6e 64 20 71 75 69 74 2e 0a ssage and quit..
7f20: 2a 2f 0a 76 6f 69 64 20 76 65 72 69 66 79 5f 61 */.void verify_a
7f30: 6c 6c 5f 6f 70 74 69 6f 6e 73 28 76 6f 69 64 29 ll_options(void)
7f40: 7b 0a 20 20 69 6e 74 20 69 3b 0a 20 20 66 6f 72 {. int i;. for
7f50: 28 69 3d 31 3b 20 69 3c 67 2e 61 72 67 63 3b 20 (i=1; i<g.argc;
7f60: 69 2b 2b 29 7b 0a 20 20 20 20 69 66 28 20 67 2e i++){. if( g.
7f70: 61 72 67 76 5b 69 5d 5b 30 5d 3d 3d 27 2d 27 20 argv[i][0]=='-'
7f80: 26 26 20 67 2e 61 72 67 76 5b 69 5d 5b 31 5d 21 && g.argv[i][1]!
7f90: 3d 30 20 29 7b 0a 20 20 20 20 20 20 66 6f 73 73 =0 ){. foss
7fa0: 69 6c 5f 66 61 74 61 6c 28 0a 20 20 20 20 20 20 il_fatal(.
7fb0: 20 20 22 75 6e 72 65 63 6f 67 6e 69 7a 65 64 20 "unrecognized
7fc0: 63 6f 6d 6d 61 6e 64 2d 6c 69 6e 65 20 6f 70 74 command-line opt
7fd0: 69 6f 6e 2c 20 6f 72 20 6d 69 73 73 69 6e 67 20 ion, or missing
7fe0: 61 72 67 75 6d 65 6e 74 3a 20 25 73 22 2c 0a 20 argument: %s",.
7ff0: 20 20 20 20 20 20 20 67 2e 61 72 67 76 5b 69 5d g.argv[i]
8000: 29 3b 0a 20 20 20 20 7d 0a 20 20 7d 0a 7d 0a 0a );. }. }.}..
8010: 2f 2a 0a 2a 2a 20 50 72 69 6e 74 20 61 20 6c 69 /*.** Print a li
8020: 73 74 20 6f 66 20 77 6f 72 64 73 20 69 6e 20 6d st of words in m
8030: 75 6c 74 69 70 6c 65 20 63 6f 6c 75 6d 6e 73 2e ultiple columns.
8040: 0a 2a 2f 0a 0a 0a 2f 2a 0a 2a 2a 20 54 68 69 73 .*/.../*.** This
8050: 20 66 75 6e 63 74 69 6f 6e 20 72 65 74 75 72 6e function return
8060: 73 20 61 20 68 75 6d 61 6e 20 72 65 61 64 61 62 s a human readab
8070: 6c 65 20 76 65 72 73 69 6f 6e 20 73 74 72 69 6e le version strin
8080: 67 2e 0a 2a 2f 0a 63 6f 6e 73 74 20 63 68 61 72 g..*/.const char
8090: 20 2a 67 65 74 5f 76 65 72 73 69 6f 6e 28 29 7b *get_version(){
80a0: 0a 20 20 73 74 61 74 69 63 20 63 6f 6e 73 74 20 . static const
80b0: 63 68 61 72 20 76 65 72 73 69 6f 6e 5b 5d 20 3d char version[] =
80c0: 20 52 45 4c 45 41 53 45 5f 56 45 52 53 49 4f 4e RELEASE_VERSION
80d0: 20 22 20 22 20 4d 41 4e 49 46 45 53 54 5f 56 45 " " MANIFEST_VE
80e0: 52 53 49 4f 4e 20 22 20 22 0a 20 20 20 20 20 20 RSION " ".
80f0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
8100: 20 20 20 20 20 20 20 20 20 20 4d 41 4e 49 46 45 MANIFE
8110: 53 54 5f 44 41 54 45 20 22 20 55 54 43 22 3b 0a ST_DATE " UTC";.
8120: 20 20 72 65 74 75 72 6e 20 76 65 72 73 69 6f 6e return version
8130: 3b 0a 7d 0a 0a 2f 2a 0a 2a 2a 20 54 68 69 73 20 ;.}../*.** This
8140: 66 75 6e 63 74 69 6f 6e 20 70 6f 70 75 6c 61 74 function populat
8150: 65 73 20 61 20 62 6c 6f 62 20 77 69 74 68 20 76 es a blob with v
8160: 65 72 73 69 6f 6e 20 69 6e 66 6f 72 6d 61 74 69 ersion informati
8170: 6f 6e 2e 20 20 49 74 20 69 73 20 75 73 65 64 20 on. It is used
8180: 62 79 0a 2a 2a 20 74 68 65 20 22 76 65 72 73 69 by.** the "versi
8190: 6f 6e 22 20 63 6f 6d 6d 61 6e 64 20 61 6e 64 20 on" command and
81a0: 22 74 65 73 74 2d 76 65 72 73 69 6f 6e 22 20 77 "test-version" w
81b0: 65 62 20 70 61 67 65 2e 20 20 49 74 20 61 73 73 eb page. It ass
81c0: 75 6d 65 73 20 74 68 65 20 62 6c 6f 62 0a 2a 2a umes the blob.**
81d0: 20 70 61 73 73 65 64 20 74 6f 20 69 74 20 69 73 passed to it is
81e0: 20 75 6e 69 6e 69 74 69 61 6c 69 7a 65 64 3b 20 uninitialized;
81f0: 6f 74 68 65 72 77 69 73 65 2c 20 69 74 20 77 69 otherwise, it wi
8200: 6c 6c 20 6c 65 61 6b 20 6d 65 6d 6f 72 79 2e 0a ll leak memory..
8210: 2a 2f 0a 73 74 61 74 69 63 20 76 6f 69 64 20 67 */.static void g
8220: 65 74 5f 76 65 72 73 69 6f 6e 5f 62 6c 6f 62 28 et_version_blob(
8230: 0a 20 20 42 6c 6f 62 20 2a 70 4f 75 74 2c 20 20 . Blob *pOut,
8240: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f /
8250: 2a 20 57 72 69 74 65 20 74 68 65 20 6d 61 6e 69 * Write the mani
8260: 66 65 73 74 20 68 65 72 65 20 2a 2f 0a 20 20 69 fest here */. i
8270: 6e 74 20 62 56 65 72 62 6f 73 65 20 20 20 20 20 nt bVerbose
8280: 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 4e 6f /* No
8290: 6e 2d 7a 65 72 6f 20 66 6f 72 20 66 75 6c 6c 20 n-zero for full
82a0: 69 6e 66 6f 72 6d 61 74 69 6f 6e 2e 20 2a 2f 0a information. */.
82b0: 29 7b 0a 23 69 66 20 64 65 66 69 6e 65 64 28 46 ){.#if defined(F
82c0: 4f 53 53 49 4c 5f 45 4e 41 42 4c 45 5f 54 43 4c OSSIL_ENABLE_TCL
82d0: 29 0a 20 20 69 6e 74 20 72 63 3b 0a 20 20 63 6f ). int rc;. co
82e0: 6e 73 74 20 63 68 61 72 20 2a 7a 52 63 3b 0a 23 nst char *zRc;.#
82f0: 65 6e 64 69 66 0a 20 20 53 74 6d 74 20 71 3b 0a endif. Stmt q;.
8300: 20 20 62 6c 6f 62 5f 7a 65 72 6f 28 70 4f 75 74 blob_zero(pOut
8310: 29 3b 0a 20 20 62 6c 6f 62 5f 61 70 70 65 6e 64 );. blob_append
8320: 66 28 70 4f 75 74 2c 20 22 54 68 69 73 20 69 73 f(pOut, "This is
8330: 20 66 6f 73 73 69 6c 20 76 65 72 73 69 6f 6e 20 fossil version
8340: 25 73 5c 6e 22 2c 20 67 65 74 5f 76 65 72 73 69 %s\n", get_versi
8350: 6f 6e 28 29 29 3b 0a 20 20 69 66 28 20 21 62 56 on());. if( !bV
8360: 65 72 62 6f 73 65 20 29 20 72 65 74 75 72 6e 3b erbose ) return;
8370: 0a 20 20 62 6c 6f 62 5f 61 70 70 65 6e 64 66 28 . blob_appendf(
8380: 70 4f 75 74 2c 20 22 43 6f 6d 70 69 6c 65 64 20 pOut, "Compiled
8390: 6f 6e 20 25 73 20 25 73 20 75 73 69 6e 67 20 25 on %s %s using %
83a0: 73 20 28 25 64 2d 62 69 74 29 5c 6e 22 2c 0a 20 s (%d-bit)\n",.
83b0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 5f 5f __
83c0: 44 41 54 45 5f 5f 2c 20 5f 5f 54 49 4d 45 5f 5f DATE__, __TIME__
83d0: 2c 20 43 4f 4d 50 49 4c 45 52 5f 4e 41 4d 45 2c , COMPILER_NAME,
83e0: 20 73 69 7a 65 6f 66 28 76 6f 69 64 2a 29 2a 38 sizeof(void*)*8
83f0: 29 3b 0a 20 20 62 6c 6f 62 5f 61 70 70 65 6e 64 );. blob_append
8400: 66 28 70 4f 75 74 2c 20 22 53 63 68 65 6d 61 20 f(pOut, "Schema
8410: 76 65 72 73 69 6f 6e 20 25 73 5c 6e 22 2c 20 41 version %s\n", A
8420: 55 58 5f 53 43 48 45 4d 41 5f 4d 41 58 29 3b 0a UX_SCHEMA_MAX);.
8430: 23 69 66 20 64 65 66 69 6e 65 64 28 46 4f 53 53 #if defined(FOSS
8440: 49 4c 5f 45 4e 41 42 4c 45 5f 4d 49 4e 49 5a 29 IL_ENABLE_MINIZ)
8450: 0a 20 20 62 6c 6f 62 5f 61 70 70 65 6e 64 66 28 . blob_appendf(
8460: 70 4f 75 74 2c 20 22 6d 69 6e 69 7a 20 25 73 2c pOut, "miniz %s,
8470: 20 6c 6f 61 64 65 64 20 25 73 5c 6e 22 2c 20 4d loaded %s\n", M
8480: 5a 5f 56 45 52 53 49 4f 4e 2c 20 6d 7a 5f 76 65 Z_VERSION, mz_ve
8490: 72 73 69 6f 6e 28 29 29 3b 0a 23 65 6c 73 65 0a rsion());.#else.
84a0: 20 20 62 6c 6f 62 5f 61 70 70 65 6e 64 66 28 70 blob_appendf(p
84b0: 4f 75 74 2c 20 22 7a 6c 69 62 20 25 73 2c 20 6c Out, "zlib %s, l
84c0: 6f 61 64 65 64 20 25 73 5c 6e 22 2c 20 5a 4c 49 oaded %s\n", ZLI
84d0: 42 5f 56 45 52 53 49 4f 4e 2c 20 7a 6c 69 62 56 B_VERSION, zlibV
84e0: 65 72 73 69 6f 6e 28 29 29 3b 0a 23 65 6e 64 69 ersion());.#endi
84f0: 66 0a 23 69 66 20 46 4f 53 53 49 4c 5f 48 41 52 f.#if FOSSIL_HAR
8500: 44 45 4e 45 44 5f 53 48 41 31 0a 20 20 62 6c 6f DENED_SHA1. blo
8510: 62 5f 61 70 70 65 6e 64 66 28 70 4f 75 74 2c 20 b_appendf(pOut,
8520: 22 68 61 72 64 65 6e 65 64 2d 53 48 41 31 20 62 "hardened-SHA1 b
8530: 79 20 4d 61 72 63 20 53 74 65 76 65 6e 73 20 61 y Marc Stevens a
8540: 6e 64 20 44 61 6e 20 53 68 75 6d 6f 77 5c 6e 22 nd Dan Shumow\n"
8550: 29 3b 0a 23 65 6e 64 69 66 0a 23 69 66 20 64 65 );.#endif.#if de
8560: 66 69 6e 65 64 28 46 4f 53 53 49 4c 5f 45 4e 41 fined(FOSSIL_ENA
8570: 42 4c 45 5f 53 53 4c 29 0a 20 20 62 6c 6f 62 5f BLE_SSL). blob_
8580: 61 70 70 65 6e 64 66 28 70 4f 75 74 2c 20 22 53 appendf(pOut, "S
8590: 53 4c 20 28 25 73 29 5c 6e 22 2c 20 53 53 4c 65 SL (%s)\n", SSLe
85a0: 61 79 5f 76 65 72 73 69 6f 6e 28 53 53 4c 45 41 ay_version(SSLEA
85b0: 59 5f 56 45 52 53 49 4f 4e 29 29 3b 0a 23 65 6e Y_VERSION));.#en
85c0: 64 69 66 0a 23 69 66 20 64 65 66 69 6e 65 64 28 dif.#if defined(
85d0: 46 4f 53 53 49 4c 5f 48 41 56 45 5f 46 55 53 45 FOSSIL_HAVE_FUSE
85e0: 46 53 29 0a 20 20 62 6c 6f 62 5f 61 70 70 65 6e FS). blob_appen
85f0: 64 66 28 70 4f 75 74 2c 20 22 6c 69 62 66 75 73 df(pOut, "libfus
8600: 65 20 25 73 2c 20 6c 6f 61 64 65 64 20 25 73 5c e %s, loaded %s\
8610: 6e 22 2c 20 66 75 73 65 66 73 5f 69 6e 63 5f 76 n", fusefs_inc_v
8620: 65 72 73 69 6f 6e 28 29 2c 0a 20 20 20 20 20 20 ersion(),.
8630: 20 20 20 20 20 20 20 20 20 66 75 73 65 66 73 5f fusefs_
8640: 6c 69 62 5f 76 65 72 73 69 6f 6e 28 29 29 3b 0a lib_version());.
8650: 23 65 6e 64 69 66 0a 23 69 66 20 64 65 66 69 6e #endif.#if defin
8660: 65 64 28 46 4f 53 53 49 4c 5f 44 45 42 55 47 29 ed(FOSSIL_DEBUG)
8670: 0a 20 20 62 6c 6f 62 5f 61 70 70 65 6e 64 28 70 . blob_append(p
8680: 4f 75 74 2c 20 22 46 4f 53 53 49 4c 5f 44 45 42 Out, "FOSSIL_DEB
8690: 55 47 5c 6e 22 2c 20 2d 31 29 3b 0a 23 65 6e 64 UG\n", -1);.#end
86a0: 69 66 0a 23 69 66 20 64 65 66 69 6e 65 64 28 46 if.#if defined(F
86b0: 4f 53 53 49 4c 5f 4f 4d 49 54 5f 44 45 4c 54 41 OSSIL_OMIT_DELTA
86c0: 5f 43 4b 53 55 4d 5f 54 45 53 54 29 0a 20 20 62 _CKSUM_TEST). b
86d0: 6c 6f 62 5f 61 70 70 65 6e 64 28 70 4f 75 74 2c lob_append(pOut,
86e0: 20 22 46 4f 53 53 49 4c 5f 4f 4d 49 54 5f 44 45 "FOSSIL_OMIT_DE
86f0: 4c 54 41 5f 43 4b 53 55 4d 5f 54 45 53 54 5c 6e LTA_CKSUM_TEST\n
8700: 22 2c 20 2d 31 29 3b 0a 23 65 6e 64 69 66 0a 23 ", -1);.#endif.#
8710: 69 66 20 64 65 66 69 6e 65 64 28 46 4f 53 53 49 if defined(FOSSI
8720: 4c 5f 45 4e 41 42 4c 45 5f 4c 45 47 41 43 59 5f L_ENABLE_LEGACY_
8730: 4d 56 5f 52 4d 29 0a 20 20 62 6c 6f 62 5f 61 70 MV_RM). blob_ap
8740: 70 65 6e 64 28 70 4f 75 74 2c 20 22 46 4f 53 53 pend(pOut, "FOSS
8750: 49 4c 5f 45 4e 41 42 4c 45 5f 4c 45 47 41 43 59 IL_ENABLE_LEGACY
8760: 5f 4d 56 5f 52 4d 5c 6e 22 2c 20 2d 31 29 3b 0a _MV_RM\n", -1);.
8770: 23 65 6e 64 69 66 0a 23 69 66 20 64 65 66 69 6e #endif.#if defin
8780: 65 64 28 46 4f 53 53 49 4c 5f 45 4e 41 42 4c 45 ed(FOSSIL_ENABLE
8790: 5f 45 58 45 43 5f 52 45 4c 5f 50 41 54 48 53 29 _EXEC_REL_PATHS)
87a0: 0a 20 20 62 6c 6f 62 5f 61 70 70 65 6e 64 28 70 . blob_append(p
87b0: 4f 75 74 2c 20 22 46 4f 53 53 49 4c 5f 45 4e 41 Out, "FOSSIL_ENA
87c0: 42 4c 45 5f 45 58 45 43 5f 52 45 4c 5f 50 41 54 BLE_EXEC_REL_PAT
87d0: 48 53 5c 6e 22 2c 20 2d 31 29 3b 0a 23 65 6e 64 HS\n", -1);.#end
87e0: 69 66 0a 23 69 66 20 64 65 66 69 6e 65 64 28 46 if.#if defined(F
87f0: 4f 53 53 49 4c 5f 45 4e 41 42 4c 45 5f 54 48 31 OSSIL_ENABLE_TH1
8800: 5f 44 4f 43 53 29 0a 20 20 62 6c 6f 62 5f 61 70 _DOCS). blob_ap
8810: 70 65 6e 64 28 70 4f 75 74 2c 20 22 46 4f 53 53 pend(pOut, "FOSS
8820: 49 4c 5f 45 4e 41 42 4c 45 5f 54 48 31 5f 44 4f IL_ENABLE_TH1_DO
8830: 43 53 5c 6e 22 2c 20 2d 31 29 3b 0a 23 65 6e 64 CS\n", -1);.#end
8840: 69 66 0a 23 69 66 20 64 65 66 69 6e 65 64 28 46 if.#if defined(F
8850: 4f 53 53 49 4c 5f 45 4e 41 42 4c 45 5f 54 48 31 OSSIL_ENABLE_TH1
8860: 5f 48 4f 4f 4b 53 29 0a 20 20 62 6c 6f 62 5f 61 _HOOKS). blob_a
8870: 70 70 65 6e 64 28 70 4f 75 74 2c 20 22 46 4f 53 ppend(pOut, "FOS
8880: 53 49 4c 5f 45 4e 41 42 4c 45 5f 54 48 31 5f 48 SIL_ENABLE_TH1_H
8890: 4f 4f 4b 53 5c 6e 22 2c 20 2d 31 29 3b 0a 23 65 OOKS\n", -1);.#e
88a0: 6e 64 69 66 0a 23 69 66 20 64 65 66 69 6e 65 64 ndif.#if defined
88b0: 28 46 4f 53 53 49 4c 5f 45 4e 41 42 4c 45 5f 54 (FOSSIL_ENABLE_T
88c0: 43 4c 29 0a 20 20 54 68 5f 46 6f 73 73 69 6c 49 CL). Th_FossilI
88d0: 6e 69 74 28 54 48 5f 49 4e 49 54 5f 44 45 46 41 nit(TH_INIT_DEFA
88e0: 55 4c 54 20 7c 20 54 48 5f 49 4e 49 54 5f 46 4f ULT | TH_INIT_FO
88f0: 52 43 45 5f 54 43 4c 29 3b 0a 20 20 72 63 20 3d RCE_TCL);. rc =
8900: 20 54 68 5f 45 76 61 6c 28 67 2e 69 6e 74 65 72 Th_Eval(g.inter
8910: 70 2c 20 30 2c 20 22 74 63 6c 49 6e 76 6f 6b 65 p, 0, "tclInvoke
8920: 20 69 6e 66 6f 20 70 61 74 63 68 6c 65 76 65 6c info patchlevel
8930: 22 2c 20 2d 31 29 3b 0a 20 20 7a 52 63 20 3d 20 ", -1);. zRc =
8940: 54 68 5f 52 65 74 75 72 6e 43 6f 64 65 4e 61 6d Th_ReturnCodeNam
8950: 65 28 72 63 2c 20 30 29 3b 0a 20 20 62 6c 6f 62 e(rc, 0);. blob
8960: 5f 61 70 70 65 6e 64 66 28 70 4f 75 74 2c 20 22 _appendf(pOut, "
8970: 54 43 4c 20 28 54 63 6c 20 25 73 2c 20 6c 6f 61 TCL (Tcl %s, loa
8980: 64 65 64 20 25 73 3a 20 25 73 29 5c 6e 22 2c 0a ded %s: %s)\n",.
8990: 20 20 20 20 54 43 4c 5f 50 41 54 43 48 5f 4c 45 TCL_PATCH_LE
89a0: 56 45 4c 2c 20 7a 52 63 2c 20 54 68 5f 47 65 74 VEL, zRc, Th_Get
89b0: 52 65 73 75 6c 74 28 67 2e 69 6e 74 65 72 70 2c Result(g.interp,
89c0: 20 30 29 0a 20 20 29 3b 0a 23 65 6e 64 69 66 0a 0). );.#endif.
89d0: 23 69 66 20 64 65 66 69 6e 65 64 28 55 53 45 5f #if defined(USE_
89e0: 54 43 4c 5f 53 54 55 42 53 29 0a 20 20 62 6c 6f TCL_STUBS). blo
89f0: 62 5f 61 70 70 65 6e 64 28 70 4f 75 74 2c 20 22 b_append(pOut, "
8a00: 55 53 45 5f 54 43 4c 5f 53 54 55 42 53 5c 6e 22 USE_TCL_STUBS\n"
8a10: 2c 20 2d 31 29 3b 0a 23 65 6e 64 69 66 0a 23 69 , -1);.#endif.#i
8a20: 66 20 64 65 66 69 6e 65 64 28 46 4f 53 53 49 4c f defined(FOSSIL
8a30: 5f 45 4e 41 42 4c 45 5f 54 43 4c 5f 53 54 55 42 _ENABLE_TCL_STUB
8a40: 53 29 0a 20 20 62 6c 6f 62 5f 61 70 70 65 6e 64 S). blob_append
8a50: 28 70 4f 75 74 2c 20 22 46 4f 53 53 49 4c 5f 54 (pOut, "FOSSIL_T
8a60: 43 4c 5f 53 54 55 42 53 5c 6e 22 2c 20 2d 31 29 CL_STUBS\n", -1)
8a70: 3b 0a 23 65 6e 64 69 66 0a 23 69 66 20 64 65 66 ;.#endif.#if def
8a80: 69 6e 65 64 28 46 4f 53 53 49 4c 5f 45 4e 41 42 ined(FOSSIL_ENAB
8a90: 4c 45 5f 54 43 4c 5f 50 52 49 56 41 54 45 5f 53 LE_TCL_PRIVATE_S
8aa0: 54 55 42 53 29 0a 20 20 62 6c 6f 62 5f 61 70 70 TUBS). blob_app
8ab0: 65 6e 64 28 70 4f 75 74 2c 20 22 46 4f 53 53 49 end(pOut, "FOSSI
8ac0: 4c 5f 45 4e 41 42 4c 45 5f 54 43 4c 5f 50 52 49 L_ENABLE_TCL_PRI
8ad0: 56 41 54 45 5f 53 54 55 42 53 5c 6e 22 2c 20 2d VATE_STUBS\n", -
8ae0: 31 29 3b 0a 23 65 6e 64 69 66 0a 23 69 66 20 64 1);.#endif.#if d
8af0: 65 66 69 6e 65 64 28 46 4f 53 53 49 4c 5f 45 4e efined(FOSSIL_EN
8b00: 41 42 4c 45 5f 4a 53 4f 4e 29 0a 20 20 62 6c 6f ABLE_JSON). blo
8b10: 62 5f 61 70 70 65 6e 64 66 28 70 4f 75 74 2c 20 b_appendf(pOut,
8b20: 22 4a 53 4f 4e 20 28 41 50 49 20 25 73 29 5c 6e "JSON (API %s)\n
8b30: 22 2c 20 46 4f 53 53 49 4c 5f 4a 53 4f 4e 5f 41 ", FOSSIL_JSON_A
8b40: 50 49 5f 56 45 52 53 49 4f 4e 29 3b 0a 23 65 6e PI_VERSION);.#en
8b50: 64 69 66 0a 23 69 66 20 64 65 66 69 6e 65 64 28 dif.#if defined(
8b60: 42 52 4f 4b 45 4e 5f 4d 49 4e 47 57 5f 43 4d 44 BROKEN_MINGW_CMD
8b70: 4c 49 4e 45 29 0a 20 20 62 6c 6f 62 5f 61 70 70 LINE). blob_app
8b80: 65 6e 64 28 70 4f 75 74 2c 20 22 4d 42 43 53 5f end(pOut, "MBCS_
8b90: 43 4f 4d 4d 41 4e 44 5f 4c 49 4e 45 5c 6e 22 2c COMMAND_LINE\n",
8ba0: 20 2d 31 29 3b 0a 23 65 6c 73 65 0a 20 20 62 6c -1);.#else. bl
8bb0: 6f 62 5f 61 70 70 65 6e 64 28 70 4f 75 74 2c 20 ob_append(pOut,
8bc0: 22 55 4e 49 43 4f 44 45 5f 43 4f 4d 4d 41 4e 44 "UNICODE_COMMAND
8bd0: 5f 4c 49 4e 45 5c 6e 22 2c 20 2d 31 29 3b 0a 23 _LINE\n", -1);.#
8be0: 65 6e 64 69 66 0a 23 69 66 20 64 65 66 69 6e 65 endif.#if define
8bf0: 64 28 46 4f 53 53 49 4c 5f 44 59 4e 41 4d 49 43 d(FOSSIL_DYNAMIC
8c00: 5f 42 55 49 4c 44 29 0a 20 20 62 6c 6f 62 5f 61 _BUILD). blob_a
8c10: 70 70 65 6e 64 28 70 4f 75 74 2c 20 22 46 4f 53 ppend(pOut, "FOS
8c20: 53 49 4c 5f 44 59 4e 41 4d 49 43 5f 42 55 49 4c SIL_DYNAMIC_BUIL
8c30: 44 5c 6e 22 2c 20 2d 31 29 3b 0a 23 65 6c 73 65 D\n", -1);.#else
8c40: 0a 20 20 62 6c 6f 62 5f 61 70 70 65 6e 64 28 70 . blob_append(p
8c50: 4f 75 74 2c 20 22 46 4f 53 53 49 4c 5f 53 54 41 Out, "FOSSIL_STA
8c60: 54 49 43 5f 42 55 49 4c 44 5c 6e 22 2c 20 2d 31 TIC_BUILD\n", -1
8c70: 29 3b 0a 23 65 6e 64 69 66 0a 23 69 66 20 64 65 );.#endif.#if de
8c80: 66 69 6e 65 64 28 55 53 45 5f 53 45 45 29 0a 20 fined(USE_SEE).
8c90: 20 62 6c 6f 62 5f 61 70 70 65 6e 64 28 70 4f 75 blob_append(pOu
8ca0: 74 2c 20 22 55 53 45 5f 53 45 45 5c 6e 22 2c 20 t, "USE_SEE\n",
8cb0: 2d 31 29 3b 0a 23 65 6e 64 69 66 0a 23 69 66 20 -1);.#endif.#if
8cc0: 64 65 66 69 6e 65 64 28 46 4f 53 53 49 4c 5f 41 defined(FOSSIL_A
8cd0: 4c 4c 4f 57 5f 4f 55 54 5f 4f 46 5f 4f 52 44 45 LLOW_OUT_OF_ORDE
8ce0: 52 5f 44 41 54 45 53 29 0a 20 20 62 6c 6f 62 5f R_DATES). blob_
8cf0: 61 70 70 65 6e 64 28 70 4f 75 74 2c 20 22 46 4f append(pOut, "FO
8d00: 53 53 49 4c 5f 41 4c 4c 4f 57 5f 4f 55 54 5f 4f SSIL_ALLOW_OUT_O
8d10: 46 5f 4f 52 44 45 52 5f 44 41 54 45 53 5c 6e 22 F_ORDER_DATES\n"
8d20: 29 3b 0a 23 65 6e 64 69 66 0a 20 20 62 6c 6f 62 );.#endif. blob
8d30: 5f 61 70 70 65 6e 64 66 28 70 4f 75 74 2c 20 22 _appendf(pOut, "
8d40: 53 51 4c 69 74 65 20 25 73 20 25 2e 33 30 73 5c SQLite %s %.30s\
8d50: 6e 22 2c 20 73 71 6c 69 74 65 33 5f 6c 69 62 76 n", sqlite3_libv
8d60: 65 72 73 69 6f 6e 28 29 2c 0a 20 20 20 20 20 20 ersion(),.
8d70: 20 20 20 20 20 20 20 20 20 73 71 6c 69 74 65 33 sqlite3
8d80: 5f 73 6f 75 72 63 65 69 64 28 29 29 3b 0a 20 20 _sourceid());.
8d90: 69 66 28 20 67 2e 64 62 3d 3d 30 20 29 20 73 71 if( g.db==0 ) sq
8da0: 6c 69 74 65 33 5f 6f 70 65 6e 28 22 3a 6d 65 6d lite3_open(":mem
8db0: 6f 72 79 3a 22 2c 20 26 67 2e 64 62 29 3b 0a 20 ory:", &g.db);.
8dc0: 20 64 62 5f 70 72 65 70 61 72 65 28 26 71 2c 0a db_prepare(&q,.
8dd0: 20 20 20 20 20 22 70 72 61 67 6d 61 20 63 6f 6d "pragma com
8de0: 70 69 6c 65 5f 6f 70 74 69 6f 6e 73 22 29 3b 0a pile_options");.
8df0: 20 20 77 68 69 6c 65 28 20 64 62 5f 73 74 65 70 while( db_step
8e00: 28 26 71 29 3d 3d 53 51 4c 49 54 45 5f 52 4f 57 (&q)==SQLITE_ROW
8e10: 20 29 7b 0a 20 20 20 20 63 6f 6e 73 74 20 63 68 ){. const ch
8e20: 61 72 20 2a 74 65 78 74 20 3d 20 64 62 5f 63 6f ar *text = db_co
8e30: 6c 75 6d 6e 5f 74 65 78 74 28 26 71 2c 20 30 29 lumn_text(&q, 0)
8e40: 3b 0a 20 20 20 20 69 66 28 20 73 74 72 6e 63 6d ;. if( strncm
8e50: 70 28 74 65 78 74 2c 20 22 43 4f 4d 50 49 4c 45 p(text, "COMPILE
8e60: 52 22 2c 20 38 29 20 29 7b 0a 20 20 20 20 20 20 R", 8) ){.
8e70: 62 6c 6f 62 5f 61 70 70 65 6e 64 66 28 70 4f 75 blob_appendf(pOu
8e80: 74 2c 20 22 53 51 4c 49 54 45 5f 25 73 5c 6e 22 t, "SQLITE_%s\n"
8e90: 2c 20 74 65 78 74 29 3b 0a 20 20 20 20 7d 0a 20 , text);. }.
8ea0: 20 7d 0a 20 20 64 62 5f 66 69 6e 61 6c 69 7a 65 }. db_finalize
8eb0: 28 26 71 29 3b 0a 7d 0a 0a 2f 2a 0a 2a 2a 20 54 (&q);.}../*.** T
8ec0: 68 69 73 20 66 75 6e 63 74 69 6f 6e 20 72 65 74 his function ret
8ed0: 75 72 6e 73 20 74 68 65 20 75 73 65 72 2d 61 67 urns the user-ag
8ee0: 65 6e 74 20 73 74 72 69 6e 67 20 66 6f 72 20 46 ent string for F
8ef0: 6f 73 73 69 6c 2c 20 66 6f 72 0a 2a 2a 20 75 73 ossil, for.** us
8f00: 65 20 69 6e 20 48 54 54 50 28 53 29 20 72 65 71 e in HTTP(S) req
8f10: 75 65 73 74 73 2e 0a 2a 2f 0a 63 6f 6e 73 74 20 uests..*/.const
8f20: 63 68 61 72 20 2a 67 65 74 5f 75 73 65 72 5f 61 char *get_user_a
8f30: 67 65 6e 74 28 29 7b 0a 20 20 73 74 61 74 69 63 gent(){. static
8f40: 20 63 6f 6e 73 74 20 63 68 61 72 20 76 65 72 73 const char vers
8f50: 69 6f 6e 5b 5d 20 3d 20 22 46 6f 73 73 69 6c 2f ion[] = "Fossil/
8f60: 22 20 52 45 4c 45 41 53 45 5f 56 45 52 53 49 4f " RELEASE_VERSIO
8f70: 4e 20 22 20 28 22 20 4d 41 4e 49 46 45 53 54 5f N " (" MANIFEST_
8f80: 44 41 54 45 0a 20 20 20 20 20 20 20 20 20 20 20 DATE.
8f90: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
8fa0: 20 20 20 20 20 22 20 22 20 4d 41 4e 49 46 45 53 " " MANIFES
8fb0: 54 5f 56 45 52 53 49 4f 4e 20 22 29 22 3b 0a 20 T_VERSION ")";.
8fc0: 20 72 65 74 75 72 6e 20 76 65 72 73 69 6f 6e 3b return version;
8fd0: 0a 7d 0a 0a 0a 2f 2a 0a 2a 2a 20 43 4f 4d 4d 41 .}.../*.** COMMA
8fe0: 4e 44 3a 20 76 65 72 73 69 6f 6e 0a 2a 2a 0a 2a ND: version.**.*
8ff0: 2a 20 55 73 61 67 65 3a 20 25 66 6f 73 73 69 6c * Usage: %fossil
9000: 20 76 65 72 73 69 6f 6e 20 3f 2d 76 65 72 62 6f version ?-verbo
9010: 73 65 7c 2d 76 3f 0a 2a 2a 0a 2a 2a 20 50 72 69 se|-v?.**.** Pri
9020: 6e 74 20 74 68 65 20 73 6f 75 72 63 65 20 63 6f nt the source co
9030: 64 65 20 76 65 72 73 69 6f 6e 20 6e 75 6d 62 65 de version numbe
9040: 72 20 66 6f 72 20 74 68 65 20 66 6f 73 73 69 6c r for the fossil
9050: 20 65 78 65 63 75 74 61 62 6c 65 2e 0a 2a 2a 20 executable..**
9060: 49 66 20 74 68 65 20 76 65 72 62 6f 73 65 20 6f If the verbose o
9070: 70 74 69 6f 6e 20 69 73 20 73 70 65 63 69 66 69 ption is specifi
9080: 65 64 2c 20 61 64 64 69 74 69 6f 6e 61 6c 20 64 ed, additional d
9090: 65 74 61 69 6c 73 20 77 69 6c 6c 0a 2a 2a 20 62 etails will.** b
90a0: 65 20 6f 75 74 70 75 74 20 61 62 6f 75 74 20 77 e output about w
90b0: 68 61 74 20 6f 70 74 69 6f 6e 61 6c 20 66 65 61 hat optional fea
90c0: 74 75 72 65 73 20 74 68 69 73 20 62 69 6e 61 72 tures this binar
90d0: 79 20 77 61 73 20 63 6f 6d 70 69 6c 65 64 0a 2a y was compiled.*
90e0: 2a 20 77 69 74 68 0a 2a 2f 0a 76 6f 69 64 20 76 * with.*/.void v
90f0: 65 72 73 69 6f 6e 5f 63 6d 64 28 76 6f 69 64 29 ersion_cmd(void)
9100: 7b 0a 20 20 42 6c 6f 62 20 76 65 72 73 69 6f 6e {. Blob version
9110: 49 6e 66 6f 3b 0a 20 20 69 6e 74 20 76 65 72 62 Info;. int verb
9120: 6f 73 65 46 6c 61 67 20 3d 20 66 69 6e 64 5f 6f oseFlag = find_o
9130: 70 74 69 6f 6e 28 22 76 65 72 62 6f 73 65 22 2c ption("verbose",
9140: 22 76 22 2c 30 29 21 3d 30 3b 0a 0a 20 20 2f 2a "v",0)!=0;.. /*
9150: 20 57 65 20 73 68 6f 75 6c 64 20 62 65 20 64 6f We should be do
9160: 6e 65 20 77 69 74 68 20 6f 70 74 69 6f 6e 73 2e ne with options.
9170: 2e 20 2a 2f 0a 20 20 76 65 72 69 66 79 5f 61 6c . */. verify_al
9180: 6c 5f 6f 70 74 69 6f 6e 73 28 29 3b 0a 20 20 67 l_options();. g
9190: 65 74 5f 76 65 72 73 69 6f 6e 5f 62 6c 6f 62 28 et_version_blob(
91a0: 26 76 65 72 73 69 6f 6e 49 6e 66 6f 2c 20 76 65 &versionInfo, ve
91b0: 72 62 6f 73 65 46 6c 61 67 29 3b 0a 20 20 66 6f rboseFlag);. fo
91c0: 73 73 69 6c 5f 70 72 69 6e 74 28 22 25 73 22 2c ssil_print("%s",
91d0: 20 62 6c 6f 62 5f 73 74 72 28 26 76 65 72 73 69 blob_str(&versi
91e0: 6f 6e 49 6e 66 6f 29 29 3b 0a 7d 0a 0a 0a 2f 2a onInfo));.}.../*
91f0: 0a 2a 2a 20 57 45 42 50 41 47 45 3a 20 76 65 72 .** WEBPAGE: ver
9200: 73 69 6f 6e 0a 2a 2a 0a 2a 2a 20 53 68 6f 77 20 sion.**.** Show
9210: 74 68 65 20 76 65 72 73 69 6f 6e 20 69 6e 66 6f the version info
9220: 72 6d 61 74 69 6f 6e 20 66 6f 72 20 46 6f 73 73 rmation for Foss
9230: 69 6c 2e 0a 2a 2a 0a 2a 2a 20 51 75 65 72 79 20 il..**.** Query
9240: 70 61 72 61 6d 65 74 65 72 73 3a 0a 2a 2a 0a 2a parameters:.**.*
9250: 2a 20 20 20 20 76 65 72 62 6f 73 65 20 20 20 20 * verbose
9260: 20 20 20 53 68 6f 77 20 64 65 74 61 69 6c 73 0a Show details.
9270: 2a 2f 0a 76 6f 69 64 20 74 65 73 74 5f 76 65 72 */.void test_ver
9280: 73 69 6f 6e 5f 70 61 67 65 28 76 6f 69 64 29 7b sion_page(void){
9290: 0a 20 20 42 6c 6f 62 20 76 65 72 73 69 6f 6e 49 . Blob versionI
92a0: 6e 66 6f 3b 0a 20 20 69 6e 74 20 76 65 72 62 6f nfo;. int verbo
92b0: 73 65 46 6c 61 67 3b 0a 0a 20 20 6c 6f 67 69 6e seFlag;.. login
92c0: 5f 63 68 65 63 6b 5f 63 72 65 64 65 6e 74 69 61 _check_credentia
92d0: 6c 73 28 29 3b 0a 20 20 69 66 28 20 21 67 2e 70 ls();. if( !g.p
92e0: 65 72 6d 2e 52 65 61 64 20 29 7b 20 6c 6f 67 69 erm.Read ){ logi
92f0: 6e 5f 6e 65 65 64 65 64 28 67 2e 61 6e 6f 6e 2e n_needed(g.anon.
9300: 52 65 61 64 29 3b 20 72 65 74 75 72 6e 3b 20 7d Read); return; }
9310: 0a 20 20 76 65 72 62 6f 73 65 46 6c 61 67 20 3d . verboseFlag =
9320: 20 50 44 28 22 76 65 72 62 6f 73 65 22 2c 20 30 PD("verbose", 0
9330: 29 20 21 3d 20 30 3b 0a 20 20 73 74 79 6c 65 5f ) != 0;. style_
9340: 68 65 61 64 65 72 28 22 56 65 72 73 69 6f 6e 20 header("Version
9350: 49 6e 66 6f 72 6d 61 74 69 6f 6e 22 29 3b 0a 20 Information");.
9360: 20 73 74 79 6c 65 5f 73 75 62 6d 65 6e 75 5f 65 style_submenu_e
9370: 6c 65 6d 65 6e 74 28 22 53 74 61 74 22 2c 20 22 lement("Stat", "
9380: 73 74 61 74 22 29 3b 0a 20 20 67 65 74 5f 76 65 stat");. get_ve
9390: 72 73 69 6f 6e 5f 62 6c 6f 62 28 26 76 65 72 73 rsion_blob(&vers
93a0: 69 6f 6e 49 6e 66 6f 2c 20 76 65 72 62 6f 73 65 ionInfo, verbose
93b0: 46 6c 61 67 29 3b 0a 20 20 40 20 3c 70 72 65 3e Flag);. @ <pre>
93c0: 0a 20 20 40 20 25 68 28 62 6c 6f 62 5f 73 74 72 . @ %h(blob_str
93d0: 28 26 76 65 72 73 69 6f 6e 49 6e 66 6f 29 29 0a (&versionInfo)).
93e0: 20 20 40 20 3c 2f 70 72 65 3e 0a 20 20 73 74 79 @ </pre>. sty
93f0: 6c 65 5f 66 6f 6f 74 65 72 28 29 3b 0a 7d 0a 0a le_footer();.}..
9400: 0a 2f 2a 0a 2a 2a 20 53 65 74 20 74 68 65 20 67 ./*.** Set the g
9410: 2e 7a 42 61 73 65 55 52 4c 20 76 61 6c 75 65 20 .zBaseURL value
9420: 74 6f 20 74 68 65 20 66 75 6c 6c 20 55 52 4c 20 to the full URL
9430: 66 6f 72 20 74 68 65 20 74 6f 70 6c 65 76 65 6c for the toplevel
9440: 20 6f 66 0a 2a 2a 20 74 68 65 20 66 6f 73 73 69 of.** the fossi
9450: 6c 20 74 72 65 65 2e 20 20 53 65 74 20 67 2e 7a l tree. Set g.z
9460: 54 6f 70 20 74 6f 20 67 2e 7a 42 61 73 65 55 52 Top to g.zBaseUR
9470: 4c 20 77 69 74 68 6f 75 74 20 74 68 65 0a 2a 2a L without the.**
9480: 20 6c 65 61 64 69 6e 67 20 22 68 74 74 70 3a 2f leading "http:/
9490: 2f 22 20 61 6e 64 20 74 68 65 20 68 6f 73 74 20 /" and the host
94a0: 61 6e 64 20 70 6f 72 74 2e 0a 2a 2a 0a 2a 2a 20 and port..**.**
94b0: 54 68 65 20 67 2e 7a 42 61 73 65 55 52 4c 20 69 The g.zBaseURL i
94c0: 73 20 6e 6f 72 6d 61 6c 6c 79 20 73 65 74 20 62 s normally set b
94d0: 61 73 65 64 20 6f 6e 20 48 54 54 50 5f 48 4f 53 ased on HTTP_HOS
94e0: 54 20 61 6e 64 20 53 43 52 49 50 54 5f 4e 41 4d T and SCRIPT_NAM
94f0: 45 0a 2a 2a 20 65 6e 76 69 72 6f 6e 6d 65 6e 74 E.** environment
9500: 20 76 61 72 69 61 62 6c 65 73 2e 20 20 48 6f 77 variables. How
9510: 65 76 65 72 2c 20 69 66 20 7a 41 6c 74 42 61 73 ever, if zAltBas
9520: 65 20 69 73 20 6e 6f 74 20 4e 55 4c 4c 20 74 68 e is not NULL th
9530: 65 6e 20 69 74 0a 2a 2a 20 69 73 20 74 68 65 20 en it.** is the
9540: 61 72 67 75 6d 65 6e 74 20 74 6f 20 74 68 65 20 argument to the
9550: 2d 2d 62 61 73 65 75 72 6c 20 6f 70 74 69 6f 6e --baseurl option
9560: 20 63 6f 6d 6d 61 6e 64 2d 6c 69 6e 65 20 6f 70 command-line op
9570: 74 69 6f 6e 20 61 6e 64 0a 2a 2a 20 67 2e 7a 42 tion and.** g.zB
9580: 61 73 65 55 52 4c 20 61 6e 64 20 67 2e 7a 54 6f aseURL and g.zTo
9590: 70 20 69 73 20 73 65 74 20 66 72 6f 6d 20 74 68 p is set from th
95a0: 61 74 20 69 6e 73 74 65 61 64 2e 0a 2a 2f 0a 73 at instead..*/.s
95b0: 74 61 74 69 63 20 76 6f 69 64 20 73 65 74 5f 62 tatic void set_b
95c0: 61 73 65 5f 75 72 6c 28 63 6f 6e 73 74 20 63 68 ase_url(const ch
95d0: 61 72 20 2a 7a 41 6c 74 42 61 73 65 29 7b 0a 20 ar *zAltBase){.
95e0: 20 69 6e 74 20 69 3b 0a 20 20 63 6f 6e 73 74 20 int i;. const
95f0: 63 68 61 72 20 2a 7a 48 6f 73 74 3b 0a 20 20 63 char *zHost;. c
9600: 6f 6e 73 74 20 63 68 61 72 20 2a 7a 4d 6f 64 65 onst char *zMode
9610: 3b 0a 20 20 63 6f 6e 73 74 20 63 68 61 72 20 2a ;. const char *
9620: 7a 43 75 72 3b 0a 0a 20 20 69 66 28 20 67 2e 7a zCur;.. if( g.z
9630: 42 61 73 65 55 52 4c 21 3d 30 20 29 20 72 65 74 BaseURL!=0 ) ret
9640: 75 72 6e 3b 0a 20 20 69 66 28 20 7a 41 6c 74 42 urn;. if( zAltB
9650: 61 73 65 20 29 7b 0a 20 20 20 20 69 6e 74 20 69 ase ){. int i
9660: 2c 20 6e 2c 20 63 3b 0a 20 20 20 20 67 2e 7a 54 , n, c;. g.zT
9670: 6f 70 20 3d 20 67 2e 7a 42 61 73 65 55 52 4c 20 op = g.zBaseURL
9680: 3d 20 6d 70 72 69 6e 74 66 28 22 25 73 22 2c 20 = mprintf("%s",
9690: 7a 41 6c 74 42 61 73 65 29 3b 0a 20 20 20 20 69 zAltBase);. i
96a0: 66 28 20 73 74 72 6e 63 6d 70 28 67 2e 7a 54 6f f( strncmp(g.zTo
96b0: 70 2c 20 22 68 74 74 70 3a 2f 2f 22 2c 20 37 29 p, "http://", 7)
96c0: 3d 3d 30 20 29 7b 0a 20 20 20 20 20 20 2f 2a 20 ==0 ){. /*
96d0: 69 74 20 69 73 20 48 54 54 50 2c 20 72 65 70 6c it is HTTP, repl
96e0: 61 63 65 20 70 72 65 66 69 78 20 77 69 74 68 20 ace prefix with
96f0: 48 54 54 50 53 2e 20 2a 2f 0a 20 20 20 20 20 20 HTTPS. */.
9700: 67 2e 7a 48 74 74 70 73 55 52 4c 20 3d 20 6d 70 g.zHttpsURL = mp
9710: 72 69 6e 74 66 28 22 68 74 74 70 73 3a 2f 2f 25 rintf("https://%
9720: 73 22 2c 20 26 67 2e 7a 54 6f 70 5b 37 5d 29 3b s", &g.zTop[7]);
9730: 0a 20 20 20 20 7d 65 6c 73 65 20 69 66 28 20 73 . }else if( s
9740: 74 72 6e 63 6d 70 28 67 2e 7a 54 6f 70 2c 20 22 trncmp(g.zTop, "
9750: 68 74 74 70 73 3a 2f 2f 22 2c 20 38 29 3d 3d 30 https://", 8)==0
9760: 20 29 7b 0a 20 20 20 20 20 20 2f 2a 20 69 74 20 ){. /* it
9770: 69 73 20 61 6c 72 65 61 64 79 20 48 54 54 50 53 is already HTTPS
9780: 2c 20 75 73 65 20 69 74 2e 20 2a 2f 0a 20 20 20 , use it. */.
9790: 20 20 20 67 2e 7a 48 74 74 70 73 55 52 4c 20 3d g.zHttpsURL =
97a0: 20 6d 70 72 69 6e 74 66 28 22 25 73 22 2c 20 67 mprintf("%s", g
97b0: 2e 7a 54 6f 70 29 3b 0a 20 20 20 20 7d 65 6c 73 .zTop);. }els
97c0: 65 7b 0a 20 20 20 20 20 20 66 6f 73 73 69 6c 5f e{. fossil_
97d0: 66 61 74 61 6c 28 22 61 72 67 75 6d 65 6e 74 20 fatal("argument
97e0: 74 6f 20 2d 2d 62 61 73 65 75 72 6c 20 73 68 6f to --baseurl sho
97f0: 75 6c 64 20 62 65 20 27 68 74 74 70 3a 2f 2f 68 uld be 'http://h
9800: 6f 73 74 2f 70 61 74 68 27 22 0a 20 20 20 20 20 ost/path'".
9810: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 22 20 "
9820: 6f 72 20 27 68 74 74 70 73 3a 2f 2f 68 6f 73 74 or 'https://host
9830: 2f 70 61 74 68 27 22 29 3b 0a 20 20 20 20 7d 0a /path'");. }.
9840: 20 20 20 20 66 6f 72 28 69 3d 6e 3d 30 3b 20 28 for(i=n=0; (
9850: 63 20 3d 20 67 2e 7a 54 6f 70 5b 69 5d 29 21 3d c = g.zTop[i])!=
9860: 30 3b 20 69 2b 2b 29 7b 0a 20 20 20 20 20 20 69 0; i++){. i
9870: 66 28 20 63 3d 3d 27 2f 27 20 29 7b 0a 20 20 20 f( c=='/' ){.
9880: 20 20 20 20 20 6e 2b 2b 3b 0a 20 20 20 20 20 20 n++;.
9890: 20 20 69 66 28 20 6e 3d 3d 33 20 29 7b 0a 20 20 if( n==3 ){.
98a0: 20 20 20 20 20 20 20 20 67 2e 7a 54 6f 70 20 2b g.zTop +
98b0: 3d 20 69 3b 0a 20 20 20 20 20 20 20 20 20 20 62 = i;. b
98c0: 72 65 61 6b 3b 0a 20 20 20 20 20 20 20 20 7d 0a reak;. }.
98d0: 20 20 20 20 20 20 7d 0a 20 20 20 20 7d 0a 20 20 }. }.
98e0: 20 20 69 66 28 20 67 2e 7a 54 6f 70 3d 3d 67 2e if( g.zTop==g.
98f0: 7a 42 61 73 65 55 52 4c 20 29 7b 0a 20 20 20 20 zBaseURL ){.
9900: 20 20 66 6f 73 73 69 6c 5f 66 61 74 61 6c 28 22 fossil_fatal("
9910: 61 72 67 75 6d 65 6e 74 20 74 6f 20 2d 2d 62 61 argument to --ba
9920: 73 65 75 72 6c 20 73 68 6f 75 6c 64 20 62 65 20 seurl should be
9930: 27 68 74 74 70 3a 2f 2f 68 6f 73 74 2f 70 61 74 'http://host/pat
9940: 68 27 22 0a 20 20 20 20 20 20 20 20 20 20 20 20 h'".
9950: 20 20 20 20 20 20 20 22 20 6f 72 20 27 68 74 74 " or 'htt
9960: 70 73 3a 2f 2f 68 6f 73 74 2f 70 61 74 68 27 22 ps://host/path'"
9970: 29 3b 0a 20 20 20 20 7d 0a 20 20 20 20 69 66 28 );. }. if(
9980: 20 67 2e 7a 54 6f 70 5b 31 5d 3d 3d 30 20 29 20 g.zTop[1]==0 )
9990: 67 2e 7a 54 6f 70 2b 2b 3b 0a 20 20 7d 65 6c 73 g.zTop++;. }els
99a0: 65 7b 0a 20 20 20 20 7a 48 6f 73 74 20 3d 20 50 e{. zHost = P
99b0: 44 28 22 48 54 54 50 5f 48 4f 53 54 22 2c 22 22 D("HTTP_HOST",""
99c0: 29 3b 0a 20 20 20 20 7a 4d 6f 64 65 20 3d 20 50 );. zMode = P
99d0: 44 28 22 48 54 54 50 53 22 2c 22 6f 66 66 22 29 D("HTTPS","off")
99e0: 3b 0a 20 20 20 20 7a 43 75 72 20 3d 20 50 44 28 ;. zCur = PD(
99f0: 22 53 43 52 49 50 54 5f 4e 41 4d 45 22 2c 22 2f "SCRIPT_NAME","/
9a00: 22 29 3b 0a 20 20 20 20 69 20 3d 20 73 74 72 6c ");. i = strl
9a10: 65 6e 28 7a 43 75 72 29 3b 0a 20 20 20 20 77 68 en(zCur);. wh
9a20: 69 6c 65 28 20 69 3e 30 20 26 26 20 7a 43 75 72 ile( i>0 && zCur
9a30: 5b 69 2d 31 5d 3d 3d 27 2f 27 20 29 20 69 2d 2d [i-1]=='/' ) i--
9a40: 3b 0a 20 20 20 20 69 66 28 20 66 6f 73 73 69 6c ;. if( fossil
9a50: 5f 73 74 72 69 63 6d 70 28 7a 4d 6f 64 65 2c 22 _stricmp(zMode,"
9a60: 6f 6e 22 29 3d 3d 30 20 29 7b 0a 20 20 20 20 20 on")==0 ){.
9a70: 20 67 2e 7a 42 61 73 65 55 52 4c 20 3d 20 6d 70 g.zBaseURL = mp
9a80: 72 69 6e 74 66 28 22 68 74 74 70 73 3a 2f 2f 25 rintf("https://%
9a90: 73 25 2e 2a 73 22 2c 20 7a 48 6f 73 74 2c 20 69 s%.*s", zHost, i
9aa0: 2c 20 7a 43 75 72 29 3b 0a 20 20 20 20 20 20 67 , zCur);. g
9ab0: 2e 7a 54 6f 70 20 3d 20 26 67 2e 7a 42 61 73 65 .zTop = &g.zBase
9ac0: 55 52 4c 5b 38 2b 73 74 72 6c 65 6e 28 7a 48 6f URL[8+strlen(zHo
9ad0: 73 74 29 5d 3b 0a 20 20 20 20 20 20 67 2e 7a 48 st)];. g.zH
9ae0: 74 74 70 73 55 52 4c 20 3d 20 67 2e 7a 42 61 73 ttpsURL = g.zBas
9af0: 65 55 52 4c 3b 0a 20 20 20 20 7d 65 6c 73 65 7b eURL;. }else{
9b00: 0a 20 20 20 20 20 20 67 2e 7a 42 61 73 65 55 52 . g.zBaseUR
9b10: 4c 20 3d 20 6d 70 72 69 6e 74 66 28 22 68 74 74 L = mprintf("htt
9b20: 70 3a 2f 2f 25 73 25 2e 2a 73 22 2c 20 7a 48 6f p://%s%.*s", zHo
9b30: 73 74 2c 20 69 2c 20 7a 43 75 72 29 3b 0a 20 20 st, i, zCur);.
9b40: 20 20 20 20 67 2e 7a 54 6f 70 20 3d 20 26 67 2e g.zTop = &g.
9b50: 7a 42 61 73 65 55 52 4c 5b 37 2b 73 74 72 6c 65 zBaseURL[7+strle
9b60: 6e 28 7a 48 6f 73 74 29 5d 3b 0a 20 20 20 20 20 n(zHost)];.
9b70: 20 67 2e 7a 48 74 74 70 73 55 52 4c 20 3d 20 6d g.zHttpsURL = m
9b80: 70 72 69 6e 74 66 28 22 68 74 74 70 73 3a 2f 2f printf("https://
9b90: 25 73 25 2e 2a 73 22 2c 20 7a 48 6f 73 74 2c 20 %s%.*s", zHost,
9ba0: 69 2c 20 7a 43 75 72 29 3b 0a 20 20 20 20 7d 0a i, zCur);. }.
9bb0: 20 20 7d 0a 20 20 69 66 28 20 64 62 5f 69 73 5f }. if( db_is_
9bc0: 77 72 69 74 65 61 62 6c 65 28 22 72 65 70 6f 73 writeable("repos
9bd0: 69 74 6f 72 79 22 29 20 29 7b 0a 20 20 20 20 69 itory") ){. i
9be0: 66 28 20 21 64 62 5f 65 78 69 73 74 73 28 22 53 f( !db_exists("S
9bf0: 45 4c 45 43 54 20 31 20 46 52 4f 4d 20 63 6f 6e ELECT 1 FROM con
9c00: 66 69 67 20 57 48 45 52 45 20 6e 61 6d 65 3d 27 fig WHERE name='
9c10: 62 61 73 65 75 72 6c 3a 25 71 27 22 2c 20 67 2e baseurl:%q'", g.
9c20: 7a 42 61 73 65 55 52 4c 29 29 7b 0a 20 20 20 20 zBaseURL)){.
9c30: 20 20 64 62 5f 6d 75 6c 74 69 5f 65 78 65 63 28 db_multi_exec(
9c40: 22 49 4e 53 45 52 54 20 49 4e 54 4f 20 63 6f 6e "INSERT INTO con
9c50: 66 69 67 28 6e 61 6d 65 2c 76 61 6c 75 65 2c 6d fig(name,value,m
9c60: 74 69 6d 65 29 22 0a 20 20 20 20 20 20 20 20 20 time)".
9c70: 20 20 20 20 20 20 20 20 20 20 20 22 56 41 4c 55 "VALU
9c80: 45 53 28 27 62 61 73 65 75 72 6c 3a 25 71 27 2c ES('baseurl:%q',
9c90: 31 2c 6e 6f 77 28 29 29 22 2c 20 67 2e 7a 42 61 1,now())", g.zBa
9ca0: 73 65 55 52 4c 29 3b 0a 20 20 20 20 7d 65 6c 73 seURL);. }els
9cb0: 65 7b 0a 20 20 20 20 20 20 64 62 5f 6f 70 74 69 e{. db_opti
9cc0: 6f 6e 61 6c 5f 73 71 6c 28 22 72 65 70 6f 73 69 onal_sql("reposi
9cd0: 74 6f 72 79 22 2c 0a 20 20 20 20 20 20 20 20 20 tory",.
9ce0: 20 20 22 52 45 50 4c 41 43 45 20 49 4e 54 4f 20 "REPLACE INTO
9cf0: 63 6f 6e 66 69 67 28 6e 61 6d 65 2c 76 61 6c 75 config(name,valu
9d00: 65 2c 6d 74 69 6d 65 29 22 0a 20 20 20 20 20 20 e,mtime)".
9d10: 20 20 20 20 20 22 56 41 4c 55 45 53 28 27 62 61 "VALUES('ba
9d20: 73 65 75 72 6c 3a 25 71 27 2c 31 2c 6e 6f 77 28 seurl:%q',1,now(
9d30: 29 29 22 2c 20 67 2e 7a 42 61 73 65 55 52 4c 0a ))", g.zBaseURL.
9d40: 20 20 20 20 20 20 29 3b 0a 20 20 20 20 7d 0a 20 );. }.
9d50: 20 7d 0a 7d 0a 0a 2f 2a 0a 2a 2a 20 53 65 6e 64 }.}../*.** Send
9d60: 20 61 6e 20 48 54 54 50 20 72 65 64 69 72 65 63 an HTTP redirec
9d70: 74 20 62 61 63 6b 20 74 6f 20 74 68 65 20 64 65 t back to the de
9d80: 73 69 67 6e 61 74 65 64 20 49 6e 64 65 78 20 50 signated Index P
9d90: 61 67 65 2e 0a 2a 2f 0a 4e 4f 52 45 54 55 52 4e age..*/.NORETURN
9da0: 20 76 6f 69 64 20 66 6f 73 73 69 6c 5f 72 65 64 void fossil_red
9db0: 69 72 65 63 74 5f 68 6f 6d 65 28 76 6f 69 64 29 irect_home(void)
9dc0: 7b 0a 20 20 63 67 69 5f 72 65 64 69 72 65 63 74 {. cgi_redirect
9dd0: 66 28 22 25 73 25 73 22 2c 20 67 2e 7a 54 6f 70 f("%s%s", g.zTop
9de0: 2c 20 64 62 5f 67 65 74 28 22 69 6e 64 65 78 2d , db_get("index-
9df0: 70 61 67 65 22 2c 20 22 2f 69 6e 64 65 78 22 29 page", "/index")
9e00: 29 3b 0a 7d 0a 0a 2f 2a 0a 2a 2a 20 49 66 20 72 );.}../*.** If r
9e10: 75 6e 6e 69 6e 67 20 61 73 20 72 6f 6f 74 2c 20 unning as root,
9e20: 63 68 72 6f 6f 74 20 74 6f 20 74 68 65 20 64 69 chroot to the di
9e30: 72 65 63 74 6f 72 79 20 63 6f 6e 74 61 69 6e 69 rectory containi
9e40: 6e 67 20 74 68 65 0a 2a 2a 20 72 65 70 6f 73 69 ng the.** reposi
9e50: 74 6f 72 79 20 7a 52 65 70 6f 20 61 6e 64 20 74 tory zRepo and t
9e60: 68 65 6e 20 64 72 6f 70 20 72 6f 6f 74 20 70 72 hen drop root pr
9e70: 69 76 69 6c 65 67 65 73 2e 20 20 52 65 74 75 72 ivileges. Retur
9e80: 6e 20 74 68 65 0a 2a 2a 20 6e 65 77 20 72 65 70 n the.** new rep
9e90: 6f 73 69 74 6f 72 79 20 6e 61 6d 65 2e 0a 2a 2a ository name..**
9ea0: 0a 2a 2a 20 7a 52 65 70 6f 20 6d 69 67 68 74 20 .** zRepo might
9eb0: 62 65 20 61 20 64 69 72 65 63 74 6f 72 79 20 69 be a directory i
9ec0: 74 73 65 6c 66 2e 20 20 49 6e 20 74 68 61 74 20 tself. In that
9ed0: 63 61 73 65 20 63 68 72 6f 6f 74 20 69 6e 74 6f case chroot into
9ee0: 0a 2a 2a 20 74 68 65 20 64 69 72 65 63 74 6f 72 .** the director
9ef0: 79 20 7a 52 65 70 6f 2e 0a 2a 2a 0a 2a 2a 20 41 y zRepo..**.** A
9f00: 73 73 75 6d 65 20 74 68 65 20 75 73 65 72 2d 69 ssume the user-i
9f10: 64 20 61 6e 64 20 67 72 6f 75 70 2d 69 64 20 6f d and group-id o
9f20: 66 20 74 68 65 20 72 65 70 6f 73 69 74 6f 72 79 f the repository
9f30: 2c 20 6f 72 20 69 66 20 7a 52 65 70 6f 0a 2a 2a , or if zRepo.**
9f40: 20 69 73 20 61 20 64 69 72 65 63 74 6f 72 79 2c is a directory,
9f50: 20 6f 66 20 74 68 61 74 20 64 69 72 65 63 74 6f of that directo
9f60: 72 79 2e 0a 2a 2a 0a 2a 2a 20 54 68 65 20 6e 6f ry..**.** The no
9f70: 4a 61 69 6c 20 66 6c 61 67 20 6d 65 61 6e 73 20 Jail flag means
9f80: 74 68 61 74 20 74 68 65 20 63 68 72 6f 6f 74 20 that the chroot
9f90: 6a 61 69 6c 20 69 73 20 6e 6f 74 20 65 6e 74 65 jail is not ente
9fa0: 72 65 64 2e 20 20 42 75 74 0a 2a 2a 20 70 72 69 red. But.** pri
9fb0: 76 69 6c 65 67 65 73 20 61 72 65 20 73 74 69 6c vileges are stil
9fc0: 6c 20 6c 6f 77 65 72 65 64 20 74 6f 20 74 68 61 l lowered to tha
9fd0: 74 20 6f 66 20 74 68 65 20 75 73 65 72 2d 69 64 t of the user-id
9fe0: 20 61 6e 64 20 67 72 6f 75 70 2d 69 64 0a 2a 2a and group-id.**
9ff0: 20 6f 66 20 74 68 65 20 72 65 70 6f 73 69 74 6f of the reposito
a000: 72 79 20 66 69 6c 65 2e 0a 2a 2f 0a 73 74 61 74 ry file..*/.stat
a010: 69 63 20 63 68 61 72 20 2a 65 6e 74 65 72 5f 63 ic char *enter_c
a020: 68 72 6f 6f 74 5f 6a 61 69 6c 28 63 68 61 72 20 hroot_jail(char
a030: 2a 7a 52 65 70 6f 2c 20 69 6e 74 20 6e 6f 4a 61 *zRepo, int noJa
a040: 69 6c 29 7b 0a 23 69 66 20 21 64 65 66 69 6e 65 il){.#if !define
a050: 64 28 5f 57 49 4e 33 32 29 0a 20 20 69 66 28 20 d(_WIN32). if(
a060: 67 65 74 75 69 64 28 29 3d 3d 30 20 29 7b 0a 20 getuid()==0 ){.
a070: 20 20 20 69 6e 74 20 69 3b 0a 20 20 20 20 73 74 int i;. st
a080: 72 75 63 74 20 73 74 61 74 20 73 53 74 61 74 3b ruct stat sStat;
a090: 0a 20 20 20 20 42 6c 6f 62 20 64 69 72 3b 0a 20 . Blob dir;.
a0a0: 20 20 20 63 68 61 72 20 2a 7a 44 69 72 3b 0a 20 char *zDir;.
a0b0: 20 20 20 69 66 28 20 67 2e 64 62 21 3d 30 20 29 if( g.db!=0 )
a0c0: 7b 0a 20 20 20 20 20 20 64 62 5f 63 6c 6f 73 65 {. db_close
a0d0: 28 31 29 3b 0a 20 20 20 20 7d 0a 0a 20 20 20 20 (1);. }..
a0e0: 66 69 6c 65 5f 63 61 6e 6f 6e 69 63 61 6c 5f 6e file_canonical_n
a0f0: 61 6d 65 28 7a 52 65 70 6f 2c 20 26 64 69 72 2c ame(zRepo, &dir,
a100: 20 30 29 3b 0a 20 20 20 20 7a 44 69 72 20 3d 20 0);. zDir =
a110: 62 6c 6f 62 5f 73 74 72 28 26 64 69 72 29 3b 0a blob_str(&dir);.
a120: 20 20 20 20 69 66 28 20 21 6e 6f 4a 61 69 6c 20 if( !noJail
a130: 29 7b 0a 20 20 20 20 20 20 69 66 28 20 66 69 6c ){. if( fil
a140: 65 5f 69 73 64 69 72 28 7a 44 69 72 29 3d 3d 31 e_isdir(zDir)==1
a150: 20 29 7b 0a 20 20 20 20 20 20 20 20 69 66 28 20 ){. if(
a160: 66 69 6c 65 5f 63 68 64 69 72 28 7a 44 69 72 2c file_chdir(zDir,
a170: 20 31 29 20 29 7b 0a 20 20 20 20 20 20 20 20 20 1) ){.
a180: 20 66 6f 73 73 69 6c 5f 66 61 74 61 6c 28 22 75 fossil_fatal("u
a190: 6e 61 62 6c 65 20 74 6f 20 63 68 72 6f 6f 74 20 nable to chroot
a1a0: 69 6e 74 6f 20 25 73 22 2c 20 7a 44 69 72 29 3b into %s", zDir);
a1b0: 0a 20 20 20 20 20 20 20 20 7d 0a 20 20 20 20 20 . }.
a1c0: 20 20 20 67 2e 66 4a 61 69 6c 20 3d 20 31 3b 0a g.fJail = 1;.
a1d0: 20 20 20 20 20 20 20 20 7a 52 65 70 6f 20 3d 20 zRepo =
a1e0: 22 2f 22 3b 0a 20 20 20 20 20 20 7d 65 6c 73 65 "/";. }else
a1f0: 7b 0a 20 20 20 20 20 20 20 20 66 6f 72 28 69 3d {. for(i=
a200: 73 74 72 6c 65 6e 28 7a 44 69 72 29 2d 31 3b 20 strlen(zDir)-1;
a210: 69 3e 30 20 26 26 20 7a 44 69 72 5b 69 5d 21 3d i>0 && zDir[i]!=
a220: 27 2f 27 3b 20 69 2d 2d 29 7b 7d 0a 20 20 20 20 '/'; i--){}.
a230: 20 20 20 20 69 66 28 20 7a 44 69 72 5b 69 5d 21 if( zDir[i]!
a240: 3d 27 2f 27 20 29 20 66 6f 73 73 69 6c 5f 66 61 ='/' ) fossil_fa
a250: 74 61 6c 28 22 62 61 64 20 72 65 70 6f 73 69 74 tal("bad reposit
a260: 6f 72 79 20 6e 61 6d 65 3a 20 25 73 22 2c 20 7a ory name: %s", z
a270: 52 65 70 6f 29 3b 0a 20 20 20 20 20 20 20 20 69 Repo);. i
a280: 66 28 20 69 3e 30 20 29 7b 0a 20 20 20 20 20 20 f( i>0 ){.
a290: 20 20 20 20 7a 44 69 72 5b 69 5d 20 3d 20 30 3b zDir[i] = 0;
a2a0: 0a 20 20 20 20 20 20 20 20 20 20 69 66 28 20 66 . if( f
a2b0: 69 6c 65 5f 63 68 64 69 72 28 7a 44 69 72 2c 20 ile_chdir(zDir,
a2c0: 31 29 20 29 7b 0a 20 20 20 20 20 20 20 20 20 20 1) ){.
a2d0: 20 20 66 6f 73 73 69 6c 5f 66 61 74 61 6c 28 22 fossil_fatal("
a2e0: 75 6e 61 62 6c 65 20 74 6f 20 63 68 72 6f 6f 74 unable to chroot
a2f0: 20 69 6e 74 6f 20 25 73 22 2c 20 7a 44 69 72 29 into %s", zDir)
a300: 3b 0a 20 20 20 20 20 20 20 20 20 20 7d 0a 20 20 ;. }.
a310: 20 20 20 20 20 20 20 20 7a 44 69 72 5b 69 5d 20 zDir[i]
a320: 3d 20 27 2f 27 3b 0a 20 20 20 20 20 20 20 20 7d = '/';. }
a330: 0a 20 20 20 20 20 20 20 20 7a 52 65 70 6f 20 3d . zRepo =
a340: 20 26 7a 44 69 72 5b 69 5d 3b 0a 20 20 20 20 20 &zDir[i];.
a350: 20 7d 0a 20 20 20 20 7d 0a 20 20 20 20 69 66 28 }. }. if(
a360: 20 73 74 61 74 28 7a 52 65 70 6f 2c 20 26 73 53 stat(zRepo, &sS
a370: 74 61 74 29 21 3d 30 20 29 7b 0a 20 20 20 20 20 tat)!=0 ){.
a380: 20 66 6f 73 73 69 6c 5f 66 61 74 61 6c 28 22 63 fossil_fatal("c
a390: 61 6e 6e 6f 74 20 73 74 61 74 28 29 20 72 65 70 annot stat() rep
a3a0: 6f 73 69 74 6f 72 79 3a 20 25 73 22 2c 20 7a 52 ository: %s", zR
a3b0: 65 70 6f 29 3b 0a 20 20 20 20 7d 0a 20 20 20 20 epo);. }.
a3c0: 69 20 3d 20 73 65 74 67 69 64 28 73 53 74 61 74 i = setgid(sStat
a3d0: 2e 73 74 5f 67 69 64 29 3b 0a 20 20 20 20 69 20 .st_gid);. i
a3e0: 3d 20 69 20 7c 7c 20 73 65 74 75 69 64 28 73 53 = i || setuid(sS
a3f0: 74 61 74 2e 73 74 5f 75 69 64 29 3b 0a 20 20 20 tat.st_uid);.
a400: 20 69 66 28 69 29 7b 0a 20 20 20 20 20 20 66 6f if(i){. fo
a410: 73 73 69 6c 5f 66 61 74 61 6c 28 22 73 65 74 67 ssil_fatal("setg
a420: 69 64 2f 75 69 64 28 29 20 66 61 69 6c 65 64 20 id/uid() failed
a430: 77 69 74 68 20 65 72 72 6e 6f 20 25 64 22 2c 20 with errno %d",
a440: 65 72 72 6e 6f 29 3b 0a 20 20 20 20 7d 0a 20 20 errno);. }.
a450: 20 20 69 66 28 20 67 2e 64 62 3d 3d 30 20 26 26 if( g.db==0 &&
a460: 20 66 69 6c 65 5f 69 73 66 69 6c 65 28 7a 52 65 file_isfile(zRe
a470: 70 6f 29 20 29 7b 0a 20 20 20 20 20 20 64 62 5f po) ){. db_
a480: 6f 70 65 6e 5f 72 65 70 6f 73 69 74 6f 72 79 28 open_repository(
a490: 7a 52 65 70 6f 29 3b 0a 20 20 20 20 7d 0a 20 20 zRepo);. }.
a4a0: 7d 0a 23 65 6e 64 69 66 0a 20 20 72 65 74 75 72 }.#endif. retur
a4b0: 6e 20 7a 52 65 70 6f 3b 0a 7d 0a 0a 2f 2a 0a 2a n zRepo;.}../*.*
a4c0: 2a 20 47 65 6e 65 72 61 74 65 20 61 20 77 65 62 * Generate a web
a4d0: 2d 70 61 67 65 20 74 68 61 74 20 6c 69 73 74 73 -page that lists
a4e0: 20 61 6c 6c 20 72 65 70 6f 73 69 74 6f 72 69 65 all repositorie
a4f0: 73 20 6c 6f 63 61 74 65 64 20 75 6e 64 65 72 20 s located under
a500: 74 68 65 0a 2a 2a 20 67 2e 7a 52 65 70 6f 73 69 the.** g.zReposi
a510: 74 6f 72 79 4e 61 6d 65 20 64 69 72 65 63 74 6f toryName directo
a520: 72 79 20 61 6e 64 20 72 65 74 75 72 6e 20 6e 6f ry and return no
a530: 6e 2d 7a 65 72 6f 2e 0a 2a 2a 0a 2a 2a 20 46 6f n-zero..**.** Fo
a540: 72 20 74 68 65 20 73 70 65 63 69 61 6c 20 63 61 r the special ca
a550: 73 65 20 77 68 65 6e 20 67 2e 7a 52 65 70 6f 73 se when g.zRepos
a560: 69 74 6f 72 79 4e 61 6d 65 20 61 20 6e 6f 6e 2d itoryName a non-
a570: 63 68 72 6f 6f 74 2d 6a 61 69 6c 20 22 2f 22 2c chroot-jail "/",
a580: 0a 2a 2a 20 63 6f 6d 70 6f 73 65 20 74 68 65 20 .** compose the
a590: 6c 69 73 74 20 75 73 69 6e 67 20 74 68 65 20 22 list using the "
a5a0: 72 65 70 6f 3a 22 20 65 6e 74 72 69 65 73 20 69 repo:" entries i
a5b0: 6e 20 74 68 65 20 67 6c 6f 62 61 6c 5f 63 6f 6e n the global_con
a5c0: 66 69 67 0a 2a 2a 20 74 61 62 6c 65 20 6f 66 20 fig.** table of
a5d0: 74 68 65 20 63 6f 6e 66 69 67 75 72 61 74 69 6f the configuratio
a5e0: 6e 20 64 61 74 61 62 61 73 65 2e 20 20 54 68 65 n database. The
a5f0: 73 65 20 65 6e 74 72 69 65 73 20 63 6f 6d 70 72 se entries compr
a600: 69 73 65 20 61 6c 6c 0a 2a 2a 20 6f 66 20 74 68 ise all.** of th
a610: 65 20 72 65 70 6f 73 69 74 6f 72 69 65 73 20 6b e repositories k
a620: 6e 6f 77 6e 20 74 6f 20 74 68 65 20 22 61 6c 6c nown to the "all
a630: 22 20 63 6f 6d 6d 61 6e 64 2e 20 20 54 68 65 20 " command. The
a640: 73 70 65 63 69 61 6c 20 63 61 73 65 0a 2a 2a 20 special case.**
a650: 70 72 6f 63 65 73 73 69 6e 67 20 69 73 20 64 69 processing is di
a660: 73 61 6c 6c 6f 77 65 64 20 66 6f 72 20 63 68 72 sallowed for chr
a670: 6f 6f 74 20 6a 61 69 6c 73 20 62 65 63 61 75 73 oot jails becaus
a680: 65 20 67 2e 7a 52 65 70 6f 73 69 74 6f 72 79 4e e g.zRepositoryN
a690: 61 6d 65 0a 2a 2a 20 69 73 20 61 6c 77 61 79 73 ame.** is always
a6a0: 20 22 2f 22 20 69 6e 73 69 64 65 20 61 20 63 68 "/" inside a ch
a6b0: 72 6f 6f 74 20 6a 61 69 6c 20 61 6e 64 20 73 6f root jail and so
a6c0: 20 69 74 20 63 61 6e 6e 6f 74 20 62 65 20 75 73 it cannot be us
a6d0: 65 64 20 61 73 20 61 20 66 6c 61 67 0a 2a 2a 20 ed as a flag.**
a6e0: 74 6f 20 73 69 67 6e 61 6c 20 74 68 65 20 73 70 to signal the sp
a6f0: 65 63 69 61 6c 20 70 72 6f 63 65 73 73 69 6e 67 ecial processing
a700: 20 69 6e 20 74 68 61 74 20 63 61 73 65 2e 20 20 in that case.
a710: 54 68 65 20 73 70 65 63 69 61 6c 20 63 61 73 65 The special case
a720: 0a 2a 2a 20 70 72 6f 63 65 73 73 69 6e 67 20 69 .** processing i
a730: 73 20 69 6e 74 65 6e 64 65 64 20 66 6f 72 20 74 s intended for t
a740: 68 65 20 22 66 6f 73 73 69 6c 20 61 6c 6c 20 75 he "fossil all u
a750: 69 22 20 63 6f 6d 6d 61 6e 64 20 77 68 69 63 68 i" command which
a760: 20 6e 65 76 65 72 0a 2a 2a 20 72 75 6e 73 20 69 never.** runs i
a770: 6e 20 61 20 63 68 72 6f 6f 74 20 6a 61 69 6c 20 n a chroot jail
a780: 61 6e 79 68 6f 77 2e 0a 2a 2a 0a 2a 2a 20 4f 72 anyhow..**.** Or
a790: 2c 20 69 66 20 6e 6f 20 72 65 70 6f 73 69 74 6f , if no reposito
a7a0: 72 69 65 73 20 63 61 6e 20 62 65 20 6c 6f 63 61 ries can be loca
a7b0: 74 65 64 20 62 65 6e 65 61 74 68 20 67 2e 7a 52 ted beneath g.zR
a7c0: 65 70 6f 73 69 74 6f 72 79 4e 61 6d 65 2c 0a 2a epositoryName,.*
a7d0: 2a 20 72 65 74 75 72 6e 20 30 2e 0a 2a 2f 0a 73 * return 0..*/.s
a7e0: 74 61 74 69 63 20 69 6e 74 20 72 65 70 6f 5f 6c tatic int repo_l
a7f0: 69 73 74 5f 70 61 67 65 28 76 6f 69 64 29 7b 0a ist_page(void){.
a800: 20 20 42 6c 6f 62 20 62 61 73 65 3b 0a 20 20 69 Blob base;. i
a810: 6e 74 20 6e 20 3d 20 30 3b 0a 20 20 69 6e 74 20 nt n = 0;. int
a820: 61 6c 6c 52 65 70 6f 3b 0a 0a 20 20 61 73 73 65 allRepo;.. asse
a830: 72 74 28 20 67 2e 64 62 3d 3d 30 20 29 3b 0a 20 rt( g.db==0 );.
a840: 20 69 66 28 20 66 6f 73 73 69 6c 5f 73 74 72 63 if( fossil_strc
a850: 6d 70 28 67 2e 7a 52 65 70 6f 73 69 74 6f 72 79 mp(g.zRepository
a860: 4e 61 6d 65 2c 22 2f 22 29 3d 3d 30 20 26 26 20 Name,"/")==0 &&
a870: 21 67 2e 66 4a 61 69 6c 20 29 7b 0a 20 20 20 20 !g.fJail ){.
a880: 2f 2a 20 46 6f 72 20 74 68 65 20 73 70 65 63 69 /* For the speci
a890: 61 6c 20 63 61 73 65 20 6f 66 20 74 68 65 20 22 al case of the "
a8a0: 72 65 70 6f 73 69 74 6f 72 79 20 64 69 72 65 63 repository direc
a8b0: 74 6f 72 79 22 20 62 65 69 6e 67 20 22 2f 22 2c tory" being "/",
a8c0: 0a 20 20 20 20 2a 2a 20 73 68 6f 77 20 61 6c 6c . ** show all
a8d0: 20 6f 66 20 74 68 65 20 72 65 70 6f 73 69 74 6f of the reposito
a8e0: 72 69 65 73 20 6e 61 6d 65 64 20 69 6e 20 74 68 ries named in th
a8f0: 65 20 7e 2f 2e 66 6f 73 73 69 6c 20 64 61 74 61 e ~/.fossil data
a900: 62 61 73 65 2e 0a 20 20 20 20 2a 2a 0a 20 20 20 base.. **.
a910: 20 2a 2a 20 4f 6e 20 75 6e 69 78 20 73 79 73 74 ** On unix syst
a920: 65 6d 73 2c 20 74 68 65 6e 20 65 6e 74 72 69 65 ems, then entrie
a930: 73 20 61 72 65 20 6f 66 20 74 68 65 20 66 6f 72 s are of the for
a940: 6d 20 22 72 65 70 6f 3a 2f 68 6f 6d 65 2f 2e 2e m "repo:/home/..
a950: 2e 22 0a 20 20 20 20 2a 2a 20 61 6e 64 20 6f 6e .". ** and on
a960: 20 57 69 6e 64 6f 77 73 20 73 79 73 74 65 6d 73 Windows systems
a970: 20 74 68 65 79 20 61 72 65 20 6c 69 6b 65 20 6f they are like o
a980: 6e 20 75 6e 69 78 2c 20 73 74 61 72 74 69 6e 67 n unix, starting
a990: 20 77 69 74 68 20 61 20 22 2f 22 0a 20 20 20 20 with a "/".
a9a0: 2a 2a 20 6f 72 20 74 68 65 79 20 63 61 6e 20 62 ** or they can b
a9b0: 65 67 69 6e 20 77 69 74 68 20 61 20 64 72 69 76 egin with a driv
a9c0: 65 20 6c 65 74 74 65 72 3a 20 22 72 65 70 6f 3a e letter: "repo:
a9d0: 43 3a 2f 55 73 65 72 73 2f 2e 2e 2e 22 2e 20 20 C:/Users/...".
a9e0: 49 6e 20 65 69 74 68 65 72 0a 20 20 20 20 2a 2a In either. **
a9f0: 20 63 61 73 65 2c 20 77 65 20 77 61 6e 74 20 72 case, we want r
aa00: 65 74 75 72 6e 65 64 20 70 61 74 68 20 74 6f 20 eturned path to
aa10: 6f 6d 69 74 20 61 6e 79 20 69 6e 69 74 69 61 6c omit any initial
aa20: 20 22 2f 22 2e 0a 20 20 20 20 2a 2f 0a 20 20 20 "/".. */.
aa30: 20 64 62 5f 6f 70 65 6e 5f 63 6f 6e 66 69 67 28 db_open_config(
aa40: 31 2c 20 30 29 3b 0a 20 20 20 20 64 62 5f 6d 75 1, 0);. db_mu
aa50: 6c 74 69 5f 65 78 65 63 28 0a 20 20 20 20 20 20 lti_exec(.
aa60: 20 22 43 52 45 41 54 45 20 54 45 4d 50 20 56 49 "CREATE TEMP VI
aa70: 45 57 20 73 66 69 6c 65 20 41 53 22 0a 20 20 20 EW sfile AS".
aa80: 20 20 20 20 22 20 20 53 45 4c 45 43 54 20 6c 74 " SELECT lt
aa90: 72 69 6d 28 73 75 62 73 74 72 28 6e 61 6d 65 2c rim(substr(name,
aaa0: 36 29 2c 27 2f 27 29 20 41 53 20 27 70 61 74 68 6),'/') AS 'path
aab0: 6e 61 6d 65 27 20 46 52 4f 4d 20 67 6c 6f 62 61 name' FROM globa
aac0: 6c 5f 63 6f 6e 66 69 67 22 0a 20 20 20 20 20 20 l_config".
aad0: 20 22 20 20 20 57 48 45 52 45 20 6e 61 6d 65 20 " WHERE name
aae0: 47 4c 4f 42 20 27 72 65 70 6f 3a 2a 27 22 0a 20 GLOB 'repo:*'".
aaf0: 20 20 20 29 3b 0a 20 20 20 20 61 6c 6c 52 65 70 );. allRep
ab00: 6f 20 3d 20 31 3b 0a 20 20 7d 65 6c 73 65 7b 0a o = 1;. }else{.
ab10: 20 20 20 20 2f 2a 20 54 68 65 20 64 65 66 61 75 /* The defau
ab20: 6c 74 20 63 61 73 65 3a 20 20 41 6c 6c 20 72 65 lt case: All re
ab30: 70 6f 73 69 74 6f 72 69 65 73 20 75 6e 64 65 72 positories under
ab40: 20 74 68 65 20 67 2e 7a 52 65 70 6f 73 69 74 6f the g.zReposito
ab50: 72 79 4e 61 6d 65 0a 20 20 20 20 2a 2a 20 64 69 ryName. ** di
ab60: 72 65 63 74 6f 72 79 2e 0a 20 20 20 20 2a 2f 0a rectory.. */.
ab70: 20 20 20 20 62 6c 6f 62 5f 69 6e 69 74 28 26 62 blob_init(&b
ab80: 61 73 65 2c 20 67 2e 7a 52 65 70 6f 73 69 74 6f ase, g.zReposito
ab90: 72 79 4e 61 6d 65 2c 20 2d 31 29 3b 0a 20 20 20 ryName, -1);.
aba0: 20 73 71 6c 69 74 65 33 5f 6f 70 65 6e 28 22 3a sqlite3_open(":
abb0: 6d 65 6d 6f 72 79 3a 22 2c 20 26 67 2e 64 62 29 memory:", &g.db)
abc0: 3b 0a 20 20 20 20 64 62 5f 6d 75 6c 74 69 5f 65 ;. db_multi_e
abd0: 78 65 63 28 22 43 52 45 41 54 45 20 54 41 42 4c xec("CREATE TABL
abe0: 45 20 73 66 69 6c 65 28 70 61 74 68 6e 61 6d 65 E sfile(pathname
abf0: 20 54 45 58 54 29 3b 22 29 3b 0a 20 20 20 20 64 TEXT);");. d
ac00: 62 5f 6d 75 6c 74 69 5f 65 78 65 63 28 22 43 52 b_multi_exec("CR
ac10: 45 41 54 45 20 54 41 42 4c 45 20 76 66 69 6c 65 EATE TABLE vfile
ac20: 28 70 61 74 68 6e 61 6d 65 29 3b 22 29 3b 0a 20 (pathname);");.
ac30: 20 20 20 76 66 69 6c 65 5f 73 63 61 6e 28 26 62 vfile_scan(&b
ac40: 61 73 65 2c 20 62 6c 6f 62 5f 73 69 7a 65 28 26 ase, blob_size(&
ac50: 62 61 73 65 29 2c 20 30 2c 20 30 2c 20 30 29 3b base), 0, 0, 0);
ac60: 0a 20 20 20 20 64 62 5f 6d 75 6c 74 69 5f 65 78 . db_multi_ex
ac70: 65 63 28 22 44 45 4c 45 54 45 20 46 52 4f 4d 20 ec("DELETE FROM
ac80: 73 66 69 6c 65 20 57 48 45 52 45 20 70 61 74 68 sfile WHERE path
ac90: 6e 61 6d 65 20 4e 4f 54 20 47 4c 4f 42 20 27 2a name NOT GLOB '*
aca0: 5b 5e 2f 5d 2e 66 6f 73 73 69 6c 27 22 29 3b 0a [^/].fossil'");.
acb0: 20 20 20 20 61 6c 6c 52 65 70 6f 20 3d 20 30 3b allRepo = 0;
acc0: 0a 20 20 7d 0a 20 20 40 20 3c 68 74 6d 6c 3e 0a . }. @ <html>.
acd0: 20 20 40 20 3c 68 65 61 64 3e 0a 20 20 40 20 3c @ <head>. @ <
ace0: 62 61 73 65 20 68 72 65 66 3d 22 25 73 28 67 2e base href="%s(g.
acf0: 7a 42 61 73 65 55 52 4c 29 2f 22 20 2f 3e 0a 20 zBaseURL)/" />.
ad00: 20 40 20 3c 74 69 74 6c 65 3e 52 65 70 6f 73 69 @ <title>Reposi
ad10: 74 6f 72 79 20 4c 69 73 74 3c 2f 74 69 74 6c 65 tory List</title
ad20: 3e 0a 20 20 40 20 3c 2f 68 65 61 64 3e 0a 20 20 >. @ </head>.
ad30: 40 20 3c 62 6f 64 79 3e 0a 20 20 6e 20 3d 20 64 @ <body>. n = d
ad40: 62 5f 69 6e 74 28 30 2c 20 22 53 45 4c 45 43 54 b_int(0, "SELECT
ad50: 20 63 6f 75 6e 74 28 2a 29 20 46 52 4f 4d 20 73 count(*) FROM s
ad60: 66 69 6c 65 22 29 3b 0a 20 20 69 66 28 20 6e 3e file");. if( n>
ad70: 30 20 29 7b 0a 20 20 20 20 53 74 6d 74 20 71 3b 0 ){. Stmt q;
ad80: 0a 20 20 20 20 40 20 3c 68 31 3e 41 76 61 69 6c . @ <h1>Avail
ad90: 61 62 6c 65 20 52 65 70 6f 73 69 74 6f 72 69 65 able Repositorie
ada0: 73 3a 3c 2f 68 31 3e 0a 20 20 20 20 40 20 3c 6f s:</h1>. @ <o
adb0: 6c 3e 0a 20 20 20 20 64 62 5f 70 72 65 70 61 72 l>. db_prepar
adc0: 65 28 26 71 2c 20 22 53 45 4c 45 43 54 20 70 61 e(&q, "SELECT pa
add0: 74 68 6e 61 6d 65 22 0a 20 20 20 20 20 20 20 20 thname".
ade0: 20 20 20 20 20 20 20 20 20 20 20 22 20 46 52 4f " FRO
adf0: 4d 20 73 66 69 6c 65 20 4f 52 44 45 52 20 42 59 M sfile ORDER BY
ae00: 20 70 61 74 68 6e 61 6d 65 20 43 4f 4c 4c 41 54 pathname COLLAT
ae10: 45 20 6e 6f 63 61 73 65 3b 22 29 3b 0a 20 20 20 E nocase;");.
ae20: 20 77 68 69 6c 65 28 20 64 62 5f 73 74 65 70 28 while( db_step(
ae30: 26 71 29 3d 3d 53 51 4c 49 54 45 5f 52 4f 57 20 &q)==SQLITE_ROW
ae40: 29 7b 0a 20 20 20 20 20 20 63 6f 6e 73 74 20 63 ){. const c
ae50: 68 61 72 20 2a 7a 4e 61 6d 65 20 3d 20 64 62 5f har *zName = db_
ae60: 63 6f 6c 75 6d 6e 5f 74 65 78 74 28 26 71 2c 20 column_text(&q,
ae70: 30 29 3b 0a 20 20 20 20 20 20 69 6e 74 20 6e 4e 0);. int nN
ae80: 61 6d 65 20 3d 20 28 69 6e 74 29 73 74 72 6c 65 ame = (int)strle
ae90: 6e 28 7a 4e 61 6d 65 29 3b 0a 20 20 20 20 20 20 n(zName);.
aea0: 63 68 61 72 20 2a 7a 55 72 6c 3b 0a 20 20 20 20 char *zUrl;.
aeb0: 20 20 69 66 28 20 6e 4e 61 6d 65 3c 37 20 29 20 if( nName<7 )
aec0: 63 6f 6e 74 69 6e 75 65 3b 0a 20 20 20 20 20 20 continue;.
aed0: 7a 55 72 6c 20 3d 20 73 71 6c 69 74 65 33 5f 6d zUrl = sqlite3_m
aee0: 70 72 69 6e 74 66 28 22 25 2e 2a 73 22 2c 20 6e printf("%.*s", n
aef0: 4e 61 6d 65 2d 37 2c 20 7a 4e 61 6d 65 29 3b 0a Name-7, zName);.
af00: 20 20 20 20 20 20 69 66 28 20 73 71 6c 69 74 65 if( sqlite
af10: 33 5f 73 74 72 67 6c 6f 62 28 22 2a 2e 66 6f 73 3_strglob("*.fos
af20: 73 69 6c 22 2c 20 7a 4e 61 6d 65 29 21 3d 30 20 sil", zName)!=0
af30: 29 7b 0a 20 20 20 20 20 20 20 20 2f 2a 20 54 68 ){. /* Th
af40: 65 20 22 66 6f 73 73 69 6c 20 73 65 72 76 65 72 e "fossil server
af50: 20 44 49 52 45 43 54 4f 52 59 22 20 61 6e 64 20 DIRECTORY" and
af60: 22 66 6f 73 73 69 6c 20 75 69 20 44 49 52 45 43 "fossil ui DIREC
af70: 54 4f 52 59 22 20 63 6f 6d 6d 61 6e 64 73 0a 20 TORY" commands.
af80: 20 20 20 20 20 20 20 2a 2a 20 64 6f 20 6e 6f 74 ** do not
af90: 20 77 6f 72 6b 20 66 6f 72 20 72 65 70 6f 73 69 work for reposi
afa0: 74 6f 72 69 65 73 20 77 68 6f 73 65 20 6e 61 6d tories whose nam
afb0: 65 73 20 64 6f 20 6e 6f 74 20 65 6e 64 20 69 6e es do not end in
afc0: 20 22 2e 66 6f 73 73 69 6c 22 2e 0a 20 20 20 20 ".fossil"..
afd0: 20 20 20 20 2a 2a 20 53 6f 20 64 6f 20 6e 6f 74 ** So do not
afe0: 20 68 79 70 65 72 6c 69 6e 6b 20 74 68 6f 73 65 hyperlink those
aff0: 20 63 61 73 65 73 2e 20 2a 2f 0a 20 20 20 20 20 cases. */.
b000: 20 20 20 40 20 3c 6c 69 3e 25 68 28 7a 4e 61 6d @ <li>%h(zNam
b010: 65 29 3c 2f 6c 69 3e 0a 20 20 20 20 20 20 7d 20 e)</li>. }
b020: 65 6c 73 65 20 69 66 28 20 61 6c 6c 52 65 70 6f else if( allRepo
b030: 20 26 26 20 73 71 6c 69 74 65 33 5f 73 74 72 67 && sqlite3_strg
b040: 6c 6f 62 28 22 5b 61 2d 7a 41 2d 5a 5d 3a 2f 3f lob("[a-zA-Z]:/?
b050: 2a 22 2c 20 7a 4e 61 6d 65 29 21 3d 30 20 29 7b *", zName)!=0 ){
b060: 0a 20 20 20 20 20 20 20 20 40 20 3c 6c 69 3e 3c . @ <li><
b070: 61 20 68 72 65 66 3d 22 25 52 2f 25 54 28 7a 55 a href="%R/%T(zU
b080: 72 6c 29 2f 68 6f 6d 65 22 20 74 61 72 67 65 74 rl)/home" target
b090: 3d 22 5f 62 6c 61 6e 6b 22 3e 2f 25 68 28 7a 4e ="_blank">/%h(zN
b0a0: 61 6d 65 29 3c 2f 61 3e 3c 2f 6c 69 3e 0a 20 20 ame)</a></li>.
b0b0: 20 20 20 20 7d 65 6c 73 65 7b 0a 20 20 20 20 20 }else{.
b0c0: 20 20 20 40 20 3c 6c 69 3e 3c 61 20 68 72 65 66 @ <li><a href
b0d0: 3d 22 25 52 2f 25 54 28 7a 55 72 6c 29 2f 68 6f ="%R/%T(zUrl)/ho
b0e0: 6d 65 22 20 74 61 72 67 65 74 3d 22 5f 62 6c 61 me" target="_bla
b0f0: 6e 6b 22 3e 25 68 28 7a 4e 61 6d 65 29 3c 2f 61 nk">%h(zName)</a
b100: 3e 3c 2f 6c 69 3e 0a 20 20 20 20 20 20 7d 0a 20 ></li>. }.
b110: 20 20 20 20 20 73 71 6c 69 74 65 33 5f 66 72 65 sqlite3_fre
b120: 65 28 7a 55 72 6c 29 3b 0a 20 20 20 20 7d 0a 20 e(zUrl);. }.
b130: 20 20 20 40 20 3c 2f 6f 6c 3e 0a 20 20 7d 65 6c @ </ol>. }el
b140: 73 65 7b 0a 20 20 20 20 40 20 3c 68 31 3e 4e 6f se{. @ <h1>No
b150: 20 52 65 70 6f 73 69 74 6f 72 69 65 73 20 46 6f Repositories Fo
b160: 75 6e 64 3c 2f 68 31 3e 0a 20 20 7d 0a 20 20 40 und</h1>. }. @
b170: 20 3c 2f 62 6f 64 79 3e 0a 20 20 40 20 3c 2f 68 </body>. @ </h
b180: 74 6d 6c 3e 0a 20 20 63 67 69 5f 72 65 70 6c 79 tml>. cgi_reply
b190: 28 29 3b 0a 20 20 73 71 6c 69 74 65 33 5f 63 6c ();. sqlite3_cl
b1a0: 6f 73 65 28 67 2e 64 62 29 3b 0a 20 20 67 2e 64 ose(g.db);. g.d
b1b0: 62 20 3d 20 30 3b 0a 20 20 72 65 74 75 72 6e 20 b = 0;. return
b1c0: 6e 3b 0a 7d 0a 0a 2f 2a 0a 2a 2a 20 50 72 65 63 n;.}../*.** Prec
b1d0: 6f 6e 64 69 74 69 6f 6e 73 3a 0a 2a 2a 0a 2a 2a onditions:.**.**
b1e0: 20 20 2a 20 45 6e 76 69 72 6f 6e 6d 65 6e 74 20 * Environment
b1f0: 76 61 72 69 61 62 6c 65 73 20 61 72 65 20 73 65 variables are se
b200: 74 20 75 70 20 61 63 63 6f 72 64 69 6e 67 20 74 t up according t
b210: 6f 20 74 68 65 20 43 47 49 20 73 74 61 6e 64 61 o the CGI standa
b220: 72 64 2e 0a 2a 2a 0a 2a 2a 20 49 66 20 74 68 65 rd..**.** If the
b230: 20 72 65 70 6f 73 69 74 6f 72 79 20 69 73 20 6b repository is k
b240: 6e 6f 77 6e 2c 20 69 74 20 68 61 73 20 61 6c 72 nown, it has alr
b250: 65 61 64 79 20 62 65 65 6e 20 6f 70 65 6e 65 64 eady been opened
b260: 2e 20 20 49 66 20 75 6e 6b 6e 6f 77 6e 2c 0a 2a . If unknown,.*
b270: 2a 20 74 68 65 6e 20 67 2e 7a 52 65 70 6f 73 69 * then g.zReposi
b280: 74 6f 72 79 4e 61 6d 65 20 68 6f 6c 64 73 20 74 toryName holds t
b290: 68 65 20 64 69 72 65 63 74 6f 72 79 20 74 68 61 he directory tha
b2a0: 74 20 63 6f 6e 74 61 69 6e 73 20 74 68 65 20 72 t contains the r
b2b0: 65 70 6f 73 69 74 6f 72 79 0a 2a 2a 20 61 6e 64 epository.** and
b2c0: 20 74 68 65 20 61 63 74 75 61 6c 20 72 65 70 6f the actual repo
b2d0: 73 69 74 6f 72 79 20 69 73 20 74 61 6b 65 6e 20 sitory is taken
b2e0: 66 72 6f 6d 20 74 68 65 20 66 69 72 73 74 20 65 from the first e
b2f0: 6c 65 6d 65 6e 74 20 6f 66 20 50 41 54 48 5f 49 lement of PATH_I
b300: 4e 46 4f 2e 0a 2a 2a 0a 2a 2a 20 50 72 6f 63 65 NFO..**.** Proce
b310: 73 73 20 74 68 65 20 77 65 62 70 61 67 65 20 73 ss the webpage s
b320: 70 65 63 69 66 69 65 64 20 62 79 20 74 68 65 20 pecified by the
b330: 50 41 54 48 5f 49 4e 46 4f 20 6f 72 20 52 45 51 PATH_INFO or REQ
b340: 55 45 53 54 5f 55 52 49 0a 2a 2a 20 65 6e 76 69 UEST_URI.** envi
b350: 72 6f 6e 6d 65 6e 74 20 76 61 72 69 61 62 6c 65 ronment variable
b360: 2e 0a 2a 2a 0a 2a 2a 20 49 66 20 74 68 65 20 72 ..**.** If the r
b370: 65 70 6f 73 69 74 6f 72 79 20 69 73 20 6e 6f 74 epository is not
b380: 20 6b 6e 6f 77 6e 2c 20 74 68 65 6e 20 61 20 73 known, then a s
b390: 65 61 72 63 68 20 69 73 20 64 6f 6e 65 20 74 68 earch is done th
b3a0: 72 6f 75 67 68 20 74 68 65 0a 2a 2a 20 66 69 6c rough the.** fil
b3b0: 65 20 68 69 65 72 61 72 63 68 79 20 72 6f 6f 74 e hierarchy root
b3c0: 65 64 20 61 74 20 67 2e 7a 52 65 70 6f 73 69 74 ed at g.zReposit
b3d0: 6f 72 79 4e 61 6d 65 20 66 6f 72 20 61 20 73 75 oryName for a su
b3e0: 69 74 61 62 6c 65 20 72 65 70 6f 73 69 74 6f 72 itable repositor
b3f0: 79 0a 2a 2a 20 77 69 74 68 20 61 20 6e 61 6d 65 y.** with a name
b400: 20 6f 66 20 24 70 72 65 66 69 78 2e 66 6f 73 73 of $prefix.foss
b410: 69 6c 2c 20 77 68 65 72 65 20 24 70 72 65 66 69 il, where $prefi
b420: 78 20 69 73 20 61 6e 79 20 70 72 65 66 69 78 20 x is any prefix
b430: 6f 66 20 50 41 54 48 5f 49 4e 46 4f 2e 0a 2a 2a of PATH_INFO..**
b440: 20 4f 72 2c 20 69 66 20 61 6e 20 6f 72 64 69 6e Or, if an ordin
b450: 61 72 79 20 66 69 6c 65 20 6e 61 6d 65 64 20 24 ary file named $
b460: 70 72 65 66 69 78 20 69 73 20 66 6f 75 6e 64 2c prefix is found,
b470: 20 61 6e 64 20 24 70 72 65 66 69 78 20 6d 61 74 and $prefix mat
b480: 63 68 65 73 0a 2a 2a 20 70 46 69 6c 65 47 6c 6f ches.** pFileGlo
b490: 62 20 61 6e 64 20 24 70 72 65 66 69 78 20 64 6f b and $prefix do
b4a0: 65 73 20 6e 6f 74 20 6d 61 74 63 68 20 22 2a 2e es not match "*.
b4b0: 66 6f 73 73 69 6c 2a 22 20 61 6e 64 20 74 68 65 fossil*" and the
b4c0: 20 6d 69 6d 65 74 79 70 65 20 6f 66 0a 2a 2a 20 mimetype of.**
b4d0: 24 70 72 65 66 69 78 20 63 61 6e 20 62 65 20 64 $prefix can be d
b4e0: 65 74 65 72 6d 69 6e 65 64 20 66 72 6f 6d 20 69 etermined from i
b4f0: 74 73 20 73 75 66 66 69 78 2c 20 74 68 65 6e 20 ts suffix, then
b500: 74 68 65 20 66 69 6c 65 20 24 70 72 65 66 69 78 the file $prefix
b510: 20 69 73 0a 2a 2a 20 72 65 74 75 72 6e 65 64 20 is.** returned
b520: 61 73 20 73 74 61 74 69 63 20 74 65 78 74 2e 0a as static text..
b530: 2a 2a 0a 2a 2a 20 49 66 20 6e 6f 20 73 75 69 74 **.** If no suit
b540: 61 62 6c 65 20 77 65 62 70 61 67 65 20 69 73 20 able webpage is
b550: 66 6f 75 6e 64 2c 20 74 72 79 20 74 6f 20 72 65 found, try to re
b560: 64 69 72 65 63 74 20 74 6f 20 7a 4e 6f 74 46 6f direct to zNotFo
b570: 75 6e 64 2e 0a 2a 2f 0a 73 74 61 74 69 63 20 76 und..*/.static v
b580: 6f 69 64 20 70 72 6f 63 65 73 73 5f 6f 6e 65 5f oid process_one_
b590: 77 65 62 5f 70 61 67 65 28 0a 20 20 63 6f 6e 73 web_page(. cons
b5a0: 74 20 63 68 61 72 20 2a 7a 4e 6f 74 46 6f 75 6e t char *zNotFoun
b5b0: 64 2c 20 20 20 20 20 20 2f 2a 20 52 65 64 69 72 d, /* Redir
b5c0: 65 63 74 20 68 65 72 65 20 6f 6e 20 61 20 34 30 ect here on a 40
b5d0: 34 20 69 66 20 6e 6f 74 20 4e 55 4c 4c 20 2a 2f 4 if not NULL */
b5e0: 0a 20 20 47 6c 6f 62 20 2a 70 46 69 6c 65 47 6c . Glob *pFileGl
b5f0: 6f 62 2c 20 20 20 20 20 20 20 20 20 20 20 20 2f ob, /
b600: 2a 20 44 65 6c 69 76 65 72 20 73 74 61 74 69 63 * Deliver static
b610: 20 66 69 6c 65 73 20 6d 61 74 63 68 69 6e 67 20 files matching
b620: 2a 2f 0a 20 20 69 6e 74 20 61 6c 6c 6f 77 52 65 */. int allowRe
b630: 70 6f 4c 69 73 74 20 20 20 20 20 20 20 20 20 20 poList
b640: 20 2f 2a 20 53 65 6e 64 20 72 65 70 6f 20 6c 69 /* Send repo li
b650: 73 74 20 66 6f 72 20 22 2f 22 20 55 52 4c 20 2a st for "/" URL *
b660: 2f 0a 29 7b 0a 20 20 63 6f 6e 73 74 20 63 68 61 /.){. const cha
b670: 72 20 2a 7a 50 61 74 68 49 6e 66 6f 20 3d 20 50 r *zPathInfo = P
b680: 44 28 22 50 41 54 48 5f 49 4e 46 4f 22 2c 20 22 D("PATH_INFO", "
b690: 22 29 3b 0a 20 20 63 68 61 72 20 2a 7a 50 61 74 ");. char *zPat
b6a0: 68 20 3d 20 4e 55 4c 4c 3b 0a 20 20 69 6e 74 20 h = NULL;. int
b6b0: 69 3b 0a 20 20 63 6f 6e 73 74 20 43 6d 64 4f 72 i;. const CmdOr
b6c0: 50 61 67 65 20 2a 70 43 6d 64 20 3d 20 30 3b 0a Page *pCmd = 0;.
b6d0: 20 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a 42 const char *zB
b6e0: 61 73 65 20 3d 20 67 2e 7a 52 65 70 6f 73 69 74 ase = g.zReposit
b6f0: 6f 72 79 4e 61 6d 65 3b 0a 0a 20 20 2f 2a 20 48 oryName;.. /* H
b700: 61 6e 64 6c 65 20 75 6e 69 76 65 72 73 61 6c 20 andle universal
b710: 71 75 65 72 79 20 70 61 72 61 6d 65 74 65 72 73 query parameters
b720: 20 2a 2f 0a 20 20 69 66 28 20 50 42 28 22 75 74 */. if( PB("ut
b730: 63 22 29 20 29 7b 0a 20 20 20 20 67 2e 66 54 69 c") ){. g.fTi
b740: 6d 65 46 6f 72 6d 61 74 20 3d 20 31 3b 0a 20 20 meFormat = 1;.
b750: 7d 65 6c 73 65 20 69 66 28 20 50 42 28 22 6c 6f }else if( PB("lo
b760: 63 61 6c 74 69 6d 65 22 29 20 29 7b 0a 20 20 20 caltime") ){.
b770: 20 67 2e 66 54 69 6d 65 46 6f 72 6d 61 74 20 3d g.fTimeFormat =
b780: 20 32 3b 0a 20 20 7d 0a 0a 20 20 2f 2a 20 49 66 2;. }.. /* If
b790: 20 74 68 65 20 72 65 70 6f 73 69 74 6f 72 79 20 the repository
b7a0: 68 61 73 20 6e 6f 74 20 62 65 65 6e 20 6f 70 65 has not been ope
b7b0: 6e 65 64 20 61 6c 72 65 61 64 79 2c 20 74 68 65 ned already, the
b7c0: 6e 20 66 69 6e 64 20 74 68 65 0a 20 20 2a 2a 20 n find the. **
b7d0: 72 65 70 6f 73 69 74 6f 72 79 20 62 61 73 65 64 repository based
b7e0: 20 6f 6e 20 74 68 65 20 66 69 72 73 74 20 65 6c on the first el
b7f0: 65 6d 65 6e 74 20 6f 66 20 50 41 54 48 5f 49 4e ement of PATH_IN
b800: 46 4f 20 61 6e 64 20 6f 70 65 6e 20 69 74 2e 0a FO and open it..
b810: 20 20 2a 2f 0a 20 20 69 66 28 20 21 67 2e 72 65 */. if( !g.re
b820: 70 6f 73 69 74 6f 72 79 4f 70 65 6e 20 29 7b 0a positoryOpen ){.
b830: 20 20 20 20 63 68 61 72 20 2a 7a 52 65 70 6f 3b char *zRepo;
b840: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f /
b850: 2a 20 43 61 6e 64 69 64 61 74 65 20 72 65 70 6f * Candidate repo
b860: 73 69 74 6f 72 79 20 6e 61 6d 65 20 2a 2f 0a 20 sitory name */.
b870: 20 20 20 63 68 61 72 20 2a 7a 54 6f 46 72 65 65 char *zToFree
b880: 20 3d 20 30 3b 20 20 20 20 20 20 20 20 20 2f 2a = 0; /*
b890: 20 4d 61 6c 6c 6f 63 65 64 20 6d 65 6d 6f 72 79 Malloced memory
b8a0: 20 74 68 61 74 20 6e 65 65 64 73 20 74 6f 20 62 that needs to b
b8b0: 65 20 66 72 65 65 64 20 2a 2f 0a 20 20 20 20 63 e freed */. c
b8c0: 6f 6e 73 74 20 63 68 61 72 20 2a 7a 43 6c 65 61 onst char *zClea
b8d0: 6e 52 65 70 6f 3b 20 20 20 20 2f 2a 20 7a 52 65 nRepo; /* zRe
b8e0: 70 6f 20 77 69 74 68 20 73 75 72 70 6c 75 73 20 po with surplus
b8f0: 6c 65 61 64 69 6e 67 20 22 2f 22 20 72 65 6d 6f leading "/" remo
b900: 76 65 64 20 2a 2f 0a 20 20 20 20 63 6f 6e 73 74 ved */. const
b910: 20 63 68 61 72 20 2a 7a 4f 6c 64 53 63 72 69 70 char *zOldScrip
b920: 74 20 3d 20 50 44 28 22 53 43 52 49 50 54 5f 4e t = PD("SCRIPT_N
b930: 41 4d 45 22 2c 20 22 22 29 3b 20 20 2f 2a 20 4f AME", ""); /* O
b940: 72 69 67 69 6e 61 6c 20 53 43 52 49 50 54 5f 4e riginal SCRIPT_N
b950: 41 4d 45 20 2a 2f 0a 20 20 20 20 63 68 61 72 20 AME */. char
b960: 2a 7a 4e 65 77 53 63 72 69 70 74 3b 20 20 20 20 *zNewScript;
b970: 20 20 20 20 20 20 2f 2a 20 52 65 76 69 73 65 64 /* Revised
b980: 20 53 43 52 49 50 54 5f 4e 41 4d 45 20 61 66 74 SCRIPT_NAME aft
b990: 65 72 20 70 72 6f 63 65 73 73 69 6e 67 20 2a 2f er processing */
b9a0: 0a 20 20 20 20 69 6e 74 20 6a 2c 20 6b 3b 20 20 . int j, k;
b9b0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
b9c0: 2f 2a 20 4c 6f 6f 70 20 76 61 72 69 61 62 6c 65 /* Loop variable
b9d0: 73 20 2a 2f 0a 20 20 20 20 69 36 34 20 73 7a 46 s */. i64 szF
b9e0: 69 6c 65 3b 20 20 20 20 20 20 20 20 20 20 20 20 ile;
b9f0: 20 20 20 20 2f 2a 20 46 69 6c 65 20 73 69 7a 65 /* File size
ba00: 20 6f 66 20 74 68 65 20 63 61 6e 64 69 64 61 74 of the candidat
ba10: 65 20 72 65 70 6f 73 69 74 6f 72 79 20 2a 2f 0a e repository */.
ba20: 0a 20 20 20 20 69 20 3d 20 7a 50 61 74 68 49 6e . i = zPathIn
ba30: 66 6f 5b 30 5d 21 3d 30 3b 0a 20 20 20 20 69 66 fo[0]!=0;. if
ba40: 28 20 66 6f 73 73 69 6c 5f 73 74 72 63 6d 70 28 ( fossil_strcmp(
ba50: 67 2e 7a 52 65 70 6f 73 69 74 6f 72 79 4e 61 6d g.zRepositoryNam
ba60: 65 2c 20 22 2f 22 29 3d 3d 30 20 29 7b 0a 20 20 e, "/")==0 ){.
ba70: 20 20 20 20 7a 42 61 73 65 2b 2b 3b 0a 23 69 66 zBase++;.#if
ba80: 20 64 65 66 69 6e 65 64 28 5f 57 49 4e 33 32 29 defined(_WIN32)
ba90: 20 7c 7c 20 64 65 66 69 6e 65 64 28 5f 5f 43 59 || defined(__CY
baa0: 47 57 49 4e 5f 5f 29 0a 20 20 20 20 20 20 69 66 GWIN__). if
bab0: 28 20 73 71 6c 69 74 65 33 5f 73 74 72 67 6c 6f ( sqlite3_strglo
bac0: 62 28 22 2f 5b 61 2d 7a 41 2d 5a 5d 3a 2f 2a 22 b("/[a-zA-Z]:/*"
bad0: 2c 20 7a 50 61 74 68 49 6e 66 6f 29 3d 3d 30 20 , zPathInfo)==0
bae0: 29 20 69 20 3d 20 34 3b 0a 23 65 6e 64 69 66 0a ) i = 4;.#endif.
baf0: 20 20 20 20 7d 0a 20 20 20 20 77 68 69 6c 65 28 }. while(
bb00: 20 31 20 29 7b 0a 20 20 20 20 20 20 77 68 69 6c 1 ){. whil
bb10: 65 28 20 7a 50 61 74 68 49 6e 66 6f 5b 69 5d 20 e( zPathInfo[i]
bb20: 26 26 20 7a 50 61 74 68 49 6e 66 6f 5b 69 5d 21 && zPathInfo[i]!
bb30: 3d 27 2f 27 20 29 7b 20 69 2b 2b 3b 20 7d 0a 0a ='/' ){ i++; }..
bb40: 20 20 20 20 20 20 2f 2a 20 54 68 65 20 63 61 6e /* The can
bb50: 64 69 64 61 74 65 20 72 65 70 6f 73 69 74 6f 72 didate repositor
bb60: 79 20 6e 61 6d 65 20 69 73 20 73 6f 6d 65 20 70 y name is some p
bb70: 72 65 66 69 78 20 6f 66 20 74 68 65 20 50 41 54 refix of the PAT
bb80: 48 5f 49 4e 46 4f 0a 20 20 20 20 20 20 2a 2a 20 H_INFO. **
bb90: 77 69 74 68 20 22 2e 66 6f 73 73 69 6c 22 20 61 with ".fossil" a
bba0: 70 70 65 6e 64 65 64 20 2a 2f 0a 20 20 20 20 20 ppended */.
bbb0: 20 7a 52 65 70 6f 20 3d 20 7a 54 6f 46 72 65 65 zRepo = zToFree
bbc0: 20 3d 20 6d 70 72 69 6e 74 66 28 22 25 73 25 2e = mprintf("%s%.
bbd0: 2a 73 2e 66 6f 73 73 69 6c 22 2c 7a 42 61 73 65 *s.fossil",zBase
bbe0: 2c 69 2c 7a 50 61 74 68 49 6e 66 6f 29 3b 0a 20 ,i,zPathInfo);.
bbf0: 20 20 20 20 20 69 66 28 20 67 2e 66 48 74 74 70 if( g.fHttp
bc00: 54 72 61 63 65 20 29 7b 0a 20 20 20 20 20 20 20 Trace ){.
bc10: 20 40 20 3c 21 2d 2d 20 4c 6f 6f 6b 69 6e 67 20 @ <!-- Looking
bc20: 66 6f 72 20 72 65 70 6f 73 69 74 6f 72 79 20 6e for repository n
bc30: 61 6d 65 64 20 22 25 68 28 7a 52 65 70 6f 29 22 amed "%h(zRepo)"
bc40: 20 2d 2d 3e 0a 20 20 20 20 20 20 20 20 66 70 72 -->. fpr
bc50: 69 6e 74 66 28 73 74 64 65 72 72 2c 20 22 23 20 intf(stderr, "#
bc60: 6c 6f 6f 6b 69 6e 67 20 66 6f 72 20 72 65 70 6f looking for repo
bc70: 73 69 74 6f 72 79 20 6e 61 6d 65 64 20 5c 22 25 sitory named \"%
bc80: 73 5c 22 5c 6e 22 2c 20 7a 52 65 70 6f 29 3b 0a s\"\n", zRepo);.
bc90: 20 20 20 20 20 20 7d 0a 0a 0a 20 20 20 20 20 20 }...
bca0: 2f 2a 20 46 6f 72 20 73 61 66 65 74 79 20 2d 2d /* For safety --
bcb0: 20 74 6f 20 70 72 65 76 65 6e 74 20 61 6e 20 61 to prevent an a
bcc0: 74 74 61 63 6b 65 72 20 66 72 6f 6d 20 61 63 63 ttacker from acc
bcd0: 65 73 73 69 6e 67 20 61 72 62 69 74 72 61 72 79 essing arbitrary
bce0: 20 64 69 73 6b 0a 20 20 20 20 20 20 2a 2a 20 66 disk. ** f
bcf0: 69 6c 65 73 20 62 79 20 73 65 6e 64 69 6e 67 20 iles by sending
bd00: 61 20 6d 61 6c 69 63 69 6f 75 73 6c 79 20 63 72 a maliciously cr
bd10: 61 66 74 65 64 20 72 65 71 75 65 73 74 20 55 52 afted request UR
bd20: 49 20 74 6f 20 61 20 70 75 62 6c 69 63 0a 20 20 I to a public.
bd30: 20 20 20 20 2a 2a 20 73 65 72 76 65 72 20 2d 2d ** server --
bd40: 20 6d 61 6b 65 20 73 75 72 65 20 74 68 65 20 72 make sure the r
bd50: 65 70 6f 73 69 74 6f 72 79 20 62 61 73 65 6e 61 epository basena
bd60: 6d 65 20 63 6f 6e 74 61 69 6e 73 20 6e 6f 0a 20 me contains no.
bd70: 20 20 20 20 20 2a 2a 20 63 68 61 72 61 63 74 65 ** characte
bd80: 72 73 20 6f 74 68 65 72 20 74 68 61 6e 20 61 6c rs other than al
bd90: 70 68 61 6e 75 6d 65 72 69 63 73 2c 20 22 2f 22 phanumerics, "/"
bda0: 2c 20 22 5f 22 2c 20 22 2d 22 2c 20 61 6e 64 20 , "_", "-", and
bdb0: 22 2e 22 2c 20 61 6e 64 0a 20 20 20 20 20 20 2a ".", and. *
bdc0: 2a 20 74 68 61 74 20 22 2d 22 20 6e 65 76 65 72 * that "-" never
bdd0: 20 6f 63 63 75 72 73 20 69 6d 6d 65 64 69 61 74 occurs immediat
bde0: 65 6c 79 20 61 66 74 65 72 20 61 20 22 2f 22 20 ely after a "/"
bdf0: 61 6e 64 20 74 68 61 74 20 22 2e 22 20 69 73 20 and that "." is
be00: 61 6c 77 61 79 73 0a 20 20 20 20 20 20 2a 2a 20 always. **
be10: 73 75 72 72 6f 75 6e 64 65 64 20 62 79 20 74 77 surrounded by tw
be20: 6f 20 61 6c 70 68 61 6e 75 6d 65 72 69 63 73 2e o alphanumerics.
be30: 20 20 41 6e 79 20 63 68 61 72 61 63 74 65 72 20 Any character
be40: 74 68 61 74 20 64 6f 65 73 20 6e 6f 74 0a 20 20 that does not.
be50: 20 20 20 20 2a 2a 20 73 61 74 69 73 66 79 20 74 ** satisfy t
be60: 68 65 73 65 20 63 6f 6e 73 74 72 61 69 6e 74 73 hese constraints
be70: 20 69 73 20 63 6f 6e 76 65 72 74 65 64 20 69 6e is converted in
be80: 74 6f 20 22 5f 22 2e 0a 20 20 20 20 20 20 2a 2f to "_".. */
be90: 0a 20 20 20 20 20 20 73 7a 46 69 6c 65 20 3d 20 . szFile =
bea0: 30 3b 0a 20 20 20 20 20 20 66 6f 72 28 6a 3d 73 0;. for(j=s
beb0: 74 72 6c 65 6e 28 7a 42 61 73 65 29 2b 31 2c 20 trlen(zBase)+1,
bec0: 6b 3d 30 3b 20 7a 52 65 70 6f 5b 6a 5d 20 26 26 k=0; zRepo[j] &&
bed0: 20 6b 3c 69 2d 31 3b 20 6a 2b 2b 2c 20 6b 2b 2b k<i-1; j++, k++
bee0: 29 7b 0a 20 20 20 20 20 20 20 20 63 68 61 72 20 ){. char
bef0: 63 20 3d 20 7a 52 65 70 6f 5b 6a 5d 3b 0a 20 20 c = zRepo[j];.
bf00: 20 20 20 20 20 20 69 66 28 20 66 6f 73 73 69 6c if( fossil
bf10: 5f 69 73 61 6c 6e 75 6d 28 63 29 20 29 20 63 6f _isalnum(c) ) co
bf20: 6e 74 69 6e 75 65 3b 0a 23 69 66 20 64 65 66 69 ntinue;.#if defi
bf30: 6e 65 64 28 5f 57 49 4e 33 32 29 20 7c 7c 20 64 ned(_WIN32) || d
bf40: 65 66 69 6e 65 64 28 5f 5f 43 59 47 57 49 4e 5f efined(__CYGWIN_
bf50: 5f 29 0a 20 20 20 20 20 20 20 20 2f 2a 20 41 6c _). /* Al
bf60: 6c 6f 77 20 6e 61 6d 65 73 20 74 6f 20 62 65 67 low names to beg
bf70: 69 6e 20 77 69 74 68 20 22 2f 58 3a 2f 22 20 6f in with "/X:/" o
bf80: 6e 20 77 69 6e 64 6f 77 73 20 2a 2f 0a 20 20 20 n windows */.
bf90: 20 20 20 20 20 69 66 28 20 63 3d 3d 27 3a 27 20 if( c==':'
bfa0: 26 26 20 6a 3d 3d 32 20 26 26 20 73 71 6c 69 74 && j==2 && sqlit
bfb0: 65 33 5f 73 74 72 67 6c 6f 62 28 22 2f 5b 61 2d e3_strglob("/[a-
bfc0: 7a 41 2d 5a 5d 3a 2f 2a 22 2c 20 7a 52 65 70 6f zA-Z]:/*", zRepo
bfd0: 29 3d 3d 30 20 29 7b 0a 20 20 20 20 20 20 20 20 )==0 ){.
bfe0: 20 20 63 6f 6e 74 69 6e 75 65 3b 0a 20 20 20 20 continue;.
bff0: 20 20 20 20 7d 0a 23 65 6e 64 69 66 0a 20 20 20 }.#endif.
c000: 20 20 20 20 20 69 66 28 20 63 3d 3d 27 2f 27 20 if( c=='/'
c010: 29 20 63 6f 6e 74 69 6e 75 65 3b 0a 20 20 20 20 ) continue;.
c020: 20 20 20 20 69 66 28 20 63 3d 3d 27 5f 27 20 29 if( c=='_' )
c030: 20 63 6f 6e 74 69 6e 75 65 3b 0a 20 20 20 20 20 continue;.
c040: 20 20 20 69 66 28 20 63 3d 3d 27 2d 27 20 26 26 if( c=='-' &&
c050: 20 7a 52 65 70 6f 5b 6a 2d 31 5d 21 3d 27 2f 27 zRepo[j-1]!='/'
c060: 20 29 20 63 6f 6e 74 69 6e 75 65 3b 0a 20 20 20 ) continue;.
c070: 20 20 20 20 20 69 66 28 20 63 3d 3d 27 2e 27 20 if( c=='.'
c080: 26 26 20 66 6f 73 73 69 6c 5f 69 73 61 6c 6e 75 && fossil_isalnu
c090: 6d 28 7a 52 65 70 6f 5b 6a 2d 31 5d 29 20 26 26 m(zRepo[j-1]) &&
c0a0: 20 66 6f 73 73 69 6c 5f 69 73 61 6c 6e 75 6d 28 fossil_isalnum(
c0b0: 7a 52 65 70 6f 5b 6a 2b 31 5d 29 29 7b 0a 20 20 zRepo[j+1])){.
c0c0: 20 20 20 20 20 20 20 20 63 6f 6e 74 69 6e 75 65 continue
c0d0: 3b 0a 20 20 20 20 20 20 20 20 7d 0a 20 20 20 20 ;. }.
c0e0: 20 20 20 20 2f 2a 20 49 66 20 77 65 20 72 65 61 /* If we rea
c0f0: 63 68 20 74 68 69 73 20 70 6f 69 6e 74 2c 20 69 ch this point, i
c100: 74 20 6d 65 61 6e 73 20 74 68 61 74 20 74 68 65 t means that the
c110: 20 72 65 71 75 65 73 74 20 55 52 49 20 63 6f 6e request URI con
c120: 74 61 69 6e 73 0a 20 20 20 20 20 20 20 20 2a 2a tains. **
c130: 20 61 6e 20 69 6c 6c 65 67 61 6c 20 63 68 61 72 an illegal char
c140: 61 63 74 65 72 20 6f 72 20 63 68 61 72 61 63 74 acter or charact
c150: 65 72 20 63 6f 6d 62 69 6e 61 74 69 6f 6e 2e 20 er combination.
c160: 20 50 72 6f 76 6f 6b 65 20 61 0a 20 20 20 20 20 Provoke a.
c170: 20 20 20 2a 2a 20 22 4e 6f 74 20 46 6f 75 6e 64 ** "Not Found
c180: 22 20 65 72 72 6f 72 2e 20 2a 2f 0a 20 20 20 20 " error. */.
c190: 20 20 20 20 73 7a 46 69 6c 65 20 3d 20 31 3b 0a szFile = 1;.
c1a0: 20 20 20 20 20 20 20 20 69 66 28 20 67 2e 66 48 if( g.fH
c1b0: 74 74 70 54 72 61 63 65 20 29 7b 0a 20 20 20 20 ttpTrace ){.
c1c0: 20 20 20 20 20 20 40 20 3c 21 2d 2d 20 55 6e 73 @ <!-- Uns
c1d0: 61 66 65 20 70 61 74 68 6e 61 6d 65 20 72 65 6a afe pathname rej
c1e0: 65 63 74 65 64 3a 20 22 25 68 28 7a 52 65 70 6f ected: "%h(zRepo
c1f0: 29 22 20 2d 2d 3e 0a 20 20 20 20 20 20 20 20 20 )" -->.
c200: 20 66 70 72 69 6e 74 66 28 73 74 64 65 72 72 2c fprintf(stderr,
c210: 20 22 23 20 75 6e 73 61 66 65 20 70 61 74 68 6e "# unsafe pathn
c220: 61 6d 65 20 72 65 6a 65 63 74 65 64 3a 20 25 73 ame rejected: %s
c230: 5c 6e 22 2c 20 7a 52 65 70 6f 29 3b 0a 20 20 20 \n", zRepo);.
c240: 20 20 20 20 20 7d 0a 20 20 20 20 20 20 20 20 62 }. b
c250: 72 65 61 6b 3b 0a 20 20 20 20 20 20 7d 0a 0a 20 reak;. }..
c260: 20 20 20 20 20 2f 2a 20 43 68 65 63 6b 20 74 6f /* Check to
c270: 20 73 65 65 20 69 66 20 61 20 66 69 6c 65 20 6e see if a file n
c280: 61 6d 65 20 7a 52 65 70 6f 20 65 78 69 73 74 73 ame zRepo exists
c290: 2e 20 20 49 66 20 61 20 66 69 6c 65 20 6e 61 6d . If a file nam
c2a0: 65 64 20 7a 52 65 70 6f 0a 20 20 20 20 20 20 2a ed zRepo. *
c2b0: 2a 20 64 6f 65 73 20 6e 6f 74 20 65 78 69 73 74 * does not exist
c2c0: 2c 20 73 7a 46 69 6c 65 20 77 69 6c 6c 20 62 65 , szFile will be
c2d0: 63 6f 6d 65 20 2d 31 2e 20 20 49 66 20 74 68 65 come -1. If the
c2e0: 20 66 69 6c 65 20 64 6f 65 73 20 65 78 69 73 74 file does exist
c2f0: 2c 0a 20 20 20 20 20 20 2a 2a 20 74 68 65 6e 20 ,. ** then
c300: 73 7a 46 69 6c 65 20 77 69 6c 6c 20 62 65 63 6f szFile will beco
c310: 6d 65 20 7a 65 72 6f 20 28 66 6f 72 20 61 6e 20 me zero (for an
c320: 65 6d 70 74 79 20 66 69 6c 65 29 20 6f 72 20 70 empty file) or p
c330: 6f 73 69 74 69 76 65 2e 0a 20 20 20 20 20 20 2a ositive.. *
c340: 2a 20 53 70 65 63 69 61 6c 20 63 61 73 65 3a 20 * Special case:
c350: 20 41 73 73 75 6d 65 20 61 6e 79 20 66 69 6c 65 Assume any file
c360: 20 77 69 74 68 20 61 20 62 61 73 65 6e 61 6d 65 with a basename
c370: 20 6f 66 20 22 2e 66 6f 73 73 69 6c 22 20 64 6f of ".fossil" do
c380: 65 73 0a 20 20 20 20 20 20 2a 2a 20 6e 6f 74 20 es. ** not
c390: 65 78 69 73 74 2e 0a 20 20 20 20 20 20 2a 2f 0a exist.. */.
c3a0: 20 20 20 20 20 20 7a 43 6c 65 61 6e 52 65 70 6f zCleanRepo
c3b0: 20 3d 20 66 69 6c 65 5f 63 6c 65 61 6e 75 70 5f = file_cleanup_
c3c0: 66 75 6c 6c 70 61 74 68 28 7a 52 65 70 6f 29 3b fullpath(zRepo);
c3d0: 0a 20 20 20 20 20 20 69 66 28 20 73 7a 46 69 6c . if( szFil
c3e0: 65 3d 3d 30 20 26 26 20 73 71 6c 69 74 65 33 5f e==0 && sqlite3_
c3f0: 73 74 72 67 6c 6f 62 28 22 2a 2f 2e 66 6f 73 73 strglob("*/.foss
c400: 69 6c 22 2c 7a 52 65 70 6f 29 21 3d 30 20 29 7b il",zRepo)!=0 ){
c410: 0a 20 20 20 20 20 20 20 20 73 7a 46 69 6c 65 20 . szFile
c420: 3d 20 66 69 6c 65 5f 73 69 7a 65 28 7a 43 6c 65 = file_size(zCle
c430: 61 6e 52 65 70 6f 29 3b 0a 20 20 20 20 20 20 20 anRepo);.
c440: 20 69 66 28 20 67 2e 66 48 74 74 70 54 72 61 63 if( g.fHttpTrac
c450: 65 20 29 7b 0a 20 20 20 20 20 20 20 20 20 20 63 e ){. c
c460: 68 61 72 20 7a 42 75 66 5b 32 34 5d 3b 0a 20 20 har zBuf[24];.
c470: 20 20 20 20 20 20 20 20 73 71 6c 69 74 65 33 5f sqlite3_
c480: 73 6e 70 72 69 6e 74 66 28 73 69 7a 65 6f 66 28 snprintf(sizeof(
c490: 7a 42 75 66 29 2c 20 7a 42 75 66 2c 20 22 25 6c zBuf), zBuf, "%l
c4a0: 6c 64 22 2c 20 73 7a 46 69 6c 65 29 3b 0a 20 20 ld", szFile);.
c4b0: 20 20 20 20 20 20 20 20 40 20 3c 21 2d 2d 20 66 @ <!-- f
c4c0: 69 6c 65 5f 73 69 7a 65 28 25 68 28 7a 43 6c 65 ile_size(%h(zCle
c4d0: 61 6e 52 65 70 6f 29 29 20 69 73 20 25 73 28 7a anRepo)) is %s(z
c4e0: 42 75 66 29 20 2d 2d 3e 0a 20 20 20 20 20 20 20 Buf) -->.
c4f0: 20 20 20 66 70 72 69 6e 74 66 28 73 74 64 65 72 fprintf(stder
c500: 72 2c 20 22 23 20 66 69 6c 65 5f 73 69 7a 65 28 r, "# file_size(
c510: 25 73 29 20 3d 20 25 73 5c 6e 22 2c 20 7a 43 6c %s) = %s\n", zCl
c520: 65 61 6e 52 65 70 6f 2c 20 7a 42 75 66 29 3b 0a eanRepo, zBuf);.
c530: 20 20 20 20 20 20 20 20 7d 0a 20 20 20 20 20 20 }.
c540: 7d 0a 0a 20 20 20 20 20 20 2f 2a 20 49 66 20 6e }.. /* If n
c550: 6f 20 66 69 6c 65 20 6e 61 6d 65 64 20 62 79 20 o file named by
c560: 7a 52 65 70 6f 20 65 78 69 73 74 73 2c 20 72 65 zRepo exists, re
c570: 6d 6f 76 65 20 74 68 65 20 61 64 64 65 64 20 22 move the added "
c580: 2e 66 6f 73 73 69 6c 22 20 73 75 66 66 69 78 0a .fossil" suffix.
c590: 20 20 20 20 20 20 2a 2a 20 61 6e 64 20 63 68 65 ** and che
c5a0: 63 6b 20 74 6f 20 73 65 65 20 69 66 20 74 68 65 ck to see if the
c5b0: 72 65 20 69 73 20 61 20 66 69 6c 65 20 6f 72 20 re is a file or
c5c0: 64 69 72 65 63 74 6f 72 79 20 77 69 74 68 20 74 directory with t
c5d0: 68 65 20 73 61 6d 65 0a 20 20 20 20 20 20 2a 2a he same. **
c5e0: 20 6e 61 6d 65 20 61 73 20 74 68 65 20 72 61 77 name as the raw
c5f0: 20 50 41 54 48 5f 49 4e 46 4f 20 74 65 78 74 2e PATH_INFO text.
c600: 0a 20 20 20 20 20 20 2a 2f 0a 20 20 20 20 20 20 . */.
c610: 69 66 28 20 73 7a 46 69 6c 65 3c 30 20 26 26 20 if( szFile<0 &&
c620: 69 3e 30 20 29 7b 0a 20 20 20 20 20 20 20 20 63 i>0 ){. c
c630: 6f 6e 73 74 20 63 68 61 72 20 2a 7a 4d 69 6d 65 onst char *zMime
c640: 74 79 70 65 3b 0a 20 20 20 20 20 20 20 20 61 73 type;. as
c650: 73 65 72 74 28 20 66 6f 73 73 69 6c 5f 73 74 72 sert( fossil_str
c660: 63 6d 70 28 26 7a 52 65 70 6f 5b 6a 5d 2c 20 22 cmp(&zRepo[j], "
c670: 2e 66 6f 73 73 69 6c 22 29 3d 3d 30 20 29 3b 0a .fossil")==0 );.
c680: 20 20 20 20 20 20 20 20 7a 52 65 70 6f 5b 6a 5d zRepo[j]
c690: 20 3d 20 30 3b 20 20 2f 2a 20 52 65 6d 6f 76 65 = 0; /* Remove
c6a0: 20 74 68 65 20 22 2e 66 6f 73 73 69 6c 22 20 73 the ".fossil" s
c6b0: 75 66 66 69 78 20 2a 2f 0a 0a 20 20 20 20 20 20 uffix */..
c6c0: 20 20 2f 2a 20 54 68 65 20 50 41 54 48 5f 49 4e /* The PATH_IN
c6d0: 46 4f 20 70 72 65 66 69 78 20 73 65 65 6e 20 73 FO prefix seen s
c6e0: 6f 20 66 61 72 20 69 73 20 61 20 76 61 6c 69 64 o far is a valid
c6f0: 20 64 69 72 65 63 74 6f 72 79 2e 0a 20 20 20 20 directory..
c700: 20 20 20 20 2a 2a 20 43 6f 6e 74 69 6e 75 65 20 ** Continue
c710: 74 68 65 20 6c 6f 6f 70 20 77 69 74 68 20 74 68 the loop with th
c720: 65 20 6e 65 78 74 20 65 6c 65 6d 65 6e 74 20 6f e next element o
c730: 66 20 74 68 65 20 50 41 54 48 5f 49 4e 46 4f 20 f the PATH_INFO
c740: 2a 2f 0a 20 20 20 20 20 20 20 20 69 66 28 20 7a */. if( z
c750: 50 61 74 68 49 6e 66 6f 5b 69 5d 3d 3d 27 2f 27 PathInfo[i]=='/'
c760: 20 26 26 20 66 69 6c 65 5f 69 73 64 69 72 28 7a && file_isdir(z
c770: 43 6c 65 61 6e 52 65 70 6f 29 3d 3d 31 20 29 7b CleanRepo)==1 ){
c780: 0a 20 20 20 20 20 20 20 20 20 20 66 6f 73 73 69 . fossi
c790: 6c 5f 66 72 65 65 28 7a 54 6f 46 72 65 65 29 3b l_free(zToFree);
c7a0: 0a 20 20 20 20 20 20 20 20 20 20 69 2b 2b 3b 0a . i++;.
c7b0: 20 20 20 20 20 20 20 20 20 20 63 6f 6e 74 69 6e contin
c7c0: 75 65 3b 0a 20 20 20 20 20 20 20 20 7d 0a 0a 20 ue;. }..
c7d0: 20 20 20 20 20 20 20 2f 2a 20 49 66 20 7a 52 65 /* If zRe
c7e0: 70 6f 20 69 73 20 74 68 65 20 6e 61 6d 65 20 6f po is the name o
c7f0: 66 20 61 6e 20 6f 72 64 69 6e 61 72 79 20 66 69 f an ordinary fi
c800: 6c 65 20 74 68 61 74 20 6d 61 74 63 68 65 73 20 le that matches
c810: 74 68 65 0a 20 20 20 20 20 20 20 20 2a 2a 20 22 the. ** "
c820: 2d 2d 66 69 6c 65 20 47 4c 4f 42 22 20 70 61 74 --file GLOB" pat
c830: 74 65 72 6e 2c 20 74 68 65 6e 20 74 68 65 20 43 tern, then the C
c840: 47 49 20 72 65 70 6c 79 20 69 73 20 74 68 65 20 GI reply is the
c850: 74 65 78 74 20 6f 66 0a 20 20 20 20 20 20 20 20 text of.
c860: 2a 2a 20 6f 66 20 74 68 65 20 66 69 6c 65 2e 0a ** of the file..
c870: 20 20 20 20 20 20 20 20 2a 2a 0a 20 20 20 20 20 **.
c880: 20 20 20 2a 2a 20 46 6f 72 20 73 61 66 65 74 79 ** For safety
c890: 2c 20 64 6f 20 6e 6f 74 20 61 6c 6c 6f 77 20 61 , do not allow a
c8a0: 6e 79 20 66 69 6c 65 20 77 68 6f 73 65 20 6e 61 ny file whose na
c8b0: 6d 65 20 63 6f 6e 74 61 69 6e 73 20 22 2e 66 6f me contains ".fo
c8c0: 73 73 69 6c 22 0a 20 20 20 20 20 20 20 20 2a 2a ssil". **
c8d0: 20 74 6f 20 62 65 20 72 65 74 75 72 6e 65 64 20 to be returned
c8e0: 74 68 69 73 20 77 61 79 2c 20 74 6f 20 70 72 65 this way, to pre
c8f0: 76 65 6e 74 20 63 6f 6d 70 6c 65 74 65 20 72 65 vent complete re
c900: 70 6f 73 69 74 6f 72 69 65 73 20 66 72 6f 6d 0a positories from.
c910: 20 20 20 20 20 20 20 20 2a 2a 20 62 65 69 6e 67 ** being
c920: 20 64 65 6c 69 76 65 72 65 64 20 61 63 63 69 64 delivered accid
c930: 65 6e 74 6c 79 2e 20 20 54 68 69 73 20 69 73 20 ently. This is
c940: 6e 6f 74 20 69 6e 74 65 6e 64 65 64 20 74 6f 20 not intended to
c950: 62 65 20 61 0a 20 20 20 20 20 20 20 20 2a 2a 20 be a. **
c960: 67 65 6e 65 72 61 6c 2d 70 75 72 70 6f 73 65 20 general-purpose
c970: 77 65 62 20 73 65 72 76 65 72 2e 20 20 54 68 65 web server. The
c980: 20 22 2d 2d 66 69 6c 65 20 47 4c 4f 42 22 20 6d "--file GLOB" m
c990: 65 63 68 61 6e 69 73 6d 20 69 73 0a 20 20 20 20 echanism is.
c9a0: 20 20 20 20 2a 2a 20 64 65 73 69 67 6e 65 64 20 ** designed
c9b0: 74 6f 20 61 6c 6c 6f 77 20 74 68 65 20 64 65 6c to allow the del
c9c0: 69 76 65 72 79 20 6f 66 20 61 20 66 65 77 20 73 ivery of a few s
c9d0: 74 61 74 69 63 20 69 6d 61 67 65 73 20 6f 72 20 tatic images or
c9e0: 48 54 4d 4c 0a 20 20 20 20 20 20 20 20 2a 2a 20 HTML. **
c9f0: 70 61 67 65 73 2e 0a 20 20 20 20 20 20 20 20 2a pages.. *
ca00: 2f 0a 20 20 20 20 20 20 20 20 69 66 28 20 70 46 /. if( pF
ca10: 69 6c 65 47 6c 6f 62 21 3d 30 0a 20 20 20 20 20 ileGlob!=0.
ca20: 20 20 20 20 26 26 20 66 69 6c 65 5f 69 73 66 69 && file_isfi
ca30: 6c 65 28 7a 43 6c 65 61 6e 52 65 70 6f 29 0a 20 le(zCleanRepo).
ca40: 20 20 20 20 20 20 20 20 26 26 20 67 6c 6f 62 5f && glob_
ca50: 6d 61 74 63 68 28 70 46 69 6c 65 47 6c 6f 62 2c match(pFileGlob,
ca60: 20 66 69 6c 65 5f 63 6c 65 61 6e 75 70 5f 66 75 file_cleanup_fu
ca70: 6c 6c 70 61 74 68 28 7a 52 65 70 6f 29 29 0a 20 llpath(zRepo)).
ca80: 20 20 20 20 20 20 20 20 26 26 20 73 71 6c 69 74 && sqlit
ca90: 65 33 5f 73 74 72 67 6c 6f 62 28 22 2a 2e 66 6f e3_strglob("*.fo
caa0: 73 73 69 6c 2a 22 2c 7a 52 65 70 6f 29 21 3d 30 ssil*",zRepo)!=0
cab0: 0a 20 20 20 20 20 20 20 20 20 26 26 20 28 7a 4d . && (zM
cac0: 69 6d 65 74 79 70 65 20 3d 20 6d 69 6d 65 74 79 imetype = mimety
cad0: 70 65 5f 66 72 6f 6d 5f 6e 61 6d 65 28 7a 52 65 pe_from_name(zRe
cae0: 70 6f 29 29 21 3d 30 0a 20 20 20 20 20 20 20 20 po))!=0.
caf0: 20 26 26 20 73 74 72 63 6d 70 28 7a 4d 69 6d 65 && strcmp(zMime
cb00: 74 79 70 65 2c 20 22 61 70 70 6c 69 63 61 74 69 type, "applicati
cb10: 6f 6e 2f 78 2d 66 6f 73 73 69 6c 2d 61 72 74 69 on/x-fossil-arti
cb20: 66 61 63 74 22 29 21 3d 30 0a 20 20 20 20 20 20 fact")!=0.
cb30: 20 20 29 7b 0a 20 20 20 20 20 20 20 20 20 20 42 ){. B
cb40: 6c 6f 62 20 63 6f 6e 74 65 6e 74 3b 0a 20 20 20 lob content;.
cb50: 20 20 20 20 20 20 20 62 6c 6f 62 5f 72 65 61 64 blob_read
cb60: 5f 66 72 6f 6d 5f 66 69 6c 65 28 26 63 6f 6e 74 _from_file(&cont
cb70: 65 6e 74 2c 20 66 69 6c 65 5f 63 6c 65 61 6e 75 ent, file_cleanu
cb80: 70 5f 66 75 6c 6c 70 61 74 68 28 7a 52 65 70 6f p_fullpath(zRepo
cb90: 29 29 3b 0a 20 20 20 20 20 20 20 20 20 20 63 67 ));. cg
cba0: 69 5f 73 65 74 5f 63 6f 6e 74 65 6e 74 5f 74 79 i_set_content_ty
cbb0: 70 65 28 7a 4d 69 6d 65 74 79 70 65 29 3b 0a 20 pe(zMimetype);.
cbc0: 20 20 20 20 20 20 20 20 20 63 67 69 5f 73 65 74 cgi_set
cbd0: 5f 63 6f 6e 74 65 6e 74 28 26 63 6f 6e 74 65 6e _content(&conten
cbe0: 74 29 3b 0a 20 20 20 20 20 20 20 20 20 20 63 67 t);. cg
cbf0: 69 5f 72 65 70 6c 79 28 29 3b 0a 20 20 20 20 20 i_reply();.
cc00: 20 20 20 20 20 72 65 74 75 72 6e 3b 0a 20 20 20 return;.
cc10: 20 20 20 20 20 7d 0a 20 20 20 20 20 20 20 20 7a }. z
cc20: 52 65 70 6f 5b 6a 5d 20 3d 20 27 2e 27 3b 0a 20 Repo[j] = '.';.
cc30: 20 20 20 20 20 7d 0a 0a 20 20 20 20 20 20 2f 2a }.. /*
cc40: 20 49 66 20 77 65 20 72 65 61 63 68 20 74 68 69 If we reach thi
cc50: 73 20 70 6f 69 6e 74 2c 20 69 74 20 6d 65 61 6e s point, it mean
cc60: 73 20 74 68 61 74 20 74 68 65 20 73 65 61 72 63 s that the searc
cc70: 68 20 6f 66 20 74 68 65 20 50 41 54 48 5f 49 4e h of the PATH_IN
cc80: 46 4f 0a 20 20 20 20 20 20 2a 2a 20 73 74 72 69 FO. ** stri
cc90: 6e 67 20 69 73 20 66 69 6e 69 73 68 65 64 2e 20 ng is finished.
cca0: 20 45 69 74 68 65 72 20 7a 52 65 70 6f 20 63 6f Either zRepo co
ccb0: 6e 74 61 69 6e 73 20 74 68 65 20 6e 61 6d 65 20 ntains the name
ccc0: 6f 66 20 74 68 65 0a 20 20 20 20 20 20 2a 2a 20 of the. **
ccd0: 72 65 70 6f 73 69 74 6f 72 79 20 74 6f 20 62 65 repository to be
cce0: 20 75 73 65 64 2c 20 6f 72 20 65 6c 73 65 20 6e used, or else n
ccf0: 6f 20 72 65 70 6f 73 69 74 6f 72 79 20 63 6f 75 o repository cou
cd00: 6c 64 20 62 65 20 66 6f 75 6e 64 20 61 6e 0a 20 ld be found an.
cd10: 20 20 20 20 20 2a 2a 20 73 6f 6d 65 20 6b 69 6e ** some kin
cd20: 64 20 6f 66 20 65 72 72 6f 72 20 72 65 73 70 6f d of error respo
cd30: 6e 73 65 20 69 73 20 72 65 71 75 69 72 65 64 2e nse is required.
cd40: 0a 20 20 20 20 20 20 2a 2f 0a 20 20 20 20 20 20 . */.
cd50: 69 66 28 20 73 7a 46 69 6c 65 3c 31 30 32 34 20 if( szFile<1024
cd60: 29 7b 0a 20 20 20 20 20 20 20 20 73 65 74 5f 62 ){. set_b
cd70: 61 73 65 5f 75 72 6c 28 30 29 3b 0a 20 20 20 20 ase_url(0);.
cd80: 20 20 20 20 69 66 28 20 73 74 72 63 6d 70 28 7a if( strcmp(z
cd90: 50 61 74 68 49 6e 66 6f 2c 22 2f 22 29 3d 3d 30 PathInfo,"/")==0
cda0: 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 .
cdb0: 20 20 20 26 26 20 61 6c 6c 6f 77 52 65 70 6f 4c && allowRepoL
cdc0: 69 73 74 0a 20 20 20 20 20 20 20 20 20 20 20 20 ist.
cdd0: 20 20 20 20 20 20 26 26 20 72 65 70 6f 5f 6c 69 && repo_li
cde0: 73 74 5f 70 61 67 65 28 29 20 29 7b 0a 20 20 20 st_page() ){.
cdf0: 20 20 20 20 20 20 20 2f 2a 20 57 69 6c 6c 20 72 /* Will r
ce00: 65 74 75 72 6e 20 61 20 6c 69 73 74 20 6f 66 20 eturn a list of
ce10: 72 65 70 6f 73 69 74 6f 72 69 65 73 20 2a 2f 0a repositories */.
ce20: 20 20 20 20 20 20 20 20 7d 65 6c 73 65 20 69 66 }else if
ce30: 28 20 7a 4e 6f 74 46 6f 75 6e 64 20 29 7b 0a 20 ( zNotFound ){.
ce40: 20 20 20 20 20 20 20 20 20 63 67 69 5f 72 65 64 cgi_red
ce50: 69 72 65 63 74 28 7a 4e 6f 74 46 6f 75 6e 64 29 irect(zNotFound)
ce60: 3b 0a 20 20 20 20 20 20 20 20 7d 65 6c 73 65 7b ;. }else{
ce70: 0a 23 69 66 64 65 66 20 46 4f 53 53 49 4c 5f 45 .#ifdef FOSSIL_E
ce80: 4e 41 42 4c 45 5f 4a 53 4f 4e 0a 20 20 20 20 20 NABLE_JSON.
ce90: 20 20 20 20 20 69 66 28 67 2e 6a 73 6f 6e 2e 69 if(g.json.i
cea0: 73 4a 73 6f 6e 4d 6f 64 65 29 7b 0a 20 20 20 20 sJsonMode){.
ceb0: 20 20 20 20 20 20 20 20 6a 73 6f 6e 5f 65 72 72 json_err
cec0: 28 46 53 4c 5f 4a 53 4f 4e 5f 45 5f 52 45 53 4f (FSL_JSON_E_RESO
ced0: 55 52 43 45 5f 4e 4f 54 5f 46 4f 55 4e 44 2c 4e URCE_NOT_FOUND,N
cee0: 55 4c 4c 2c 31 29 3b 0a 20 20 20 20 20 20 20 20 ULL,1);.
cef0: 20 20 20 20 72 65 74 75 72 6e 3b 0a 20 20 20 20 return;.
cf00: 20 20 20 20 20 20 7d 0a 23 65 6e 64 69 66 0a 20 }.#endif.
cf10: 20 20 20 20 20 20 20 20 20 40 20 3c 68 31 3e 4e @ <h1>N
cf20: 6f 74 20 46 6f 75 6e 64 3c 2f 68 31 3e 0a 20 20 ot Found</h1>.
cf30: 20 20 20 20 20 20 20 20 63 67 69 5f 73 65 74 5f cgi_set_
cf40: 73 74 61 74 75 73 28 34 30 34 2c 20 22 6e 6f 74 status(404, "not
cf50: 20 66 6f 75 6e 64 22 29 3b 0a 20 20 20 20 20 20 found");.
cf60: 20 20 20 20 63 67 69 5f 72 65 70 6c 79 28 29 3b cgi_reply();
cf70: 0a 20 20 20 20 20 20 20 20 7d 0a 20 20 20 20 20 . }.
cf80: 20 20 20 72 65 74 75 72 6e 3b 0a 20 20 20 20 20 return;.
cf90: 20 7d 0a 20 20 20 20 20 20 62 72 65 61 6b 3b 0a }. break;.
cfa0: 20 20 20 20 7d 0a 0a 20 20 20 20 2f 2a 20 41 64 }.. /* Ad
cfb0: 64 20 74 68 65 20 72 65 70 6f 73 69 74 6f 72 79 d the repository
cfc0: 20 6e 61 6d 65 20 28 77 69 74 68 6f 75 74 20 74 name (without t
cfd0: 68 65 20 22 2e 66 6f 73 73 69 6c 22 20 73 75 66 he ".fossil" suf
cfe0: 66 69 78 29 20 74 6f 20 74 68 65 20 65 6e 64 0a fix) to the end.
cff0: 20 20 20 20 2a 2a 20 6f 66 20 53 43 52 49 50 54 ** of SCRIPT
d000: 5f 4e 41 4d 45 20 61 6e 64 20 67 2e 7a 54 6f 70 _NAME and g.zTop
d010: 20 61 6e 64 20 67 2e 7a 42 61 73 65 55 52 4c 20 and g.zBaseURL
d020: 61 6e 64 20 72 65 6d 6f 76 65 20 74 68 65 20 72 and remove the r
d030: 65 70 6f 73 69 74 6f 72 79 0a 20 20 20 20 2a 2a epository. **
d040: 20 6e 61 6d 65 20 66 72 6f 6d 20 74 68 65 20 62 name from the b
d050: 65 67 69 6e 6e 69 6e 67 20 6f 66 20 50 41 54 48 eginning of PATH
d060: 5f 49 4e 46 4f 2e 0a 20 20 20 20 2a 2f 0a 20 20 _INFO.. */.
d070: 20 20 7a 4e 65 77 53 63 72 69 70 74 20 3d 20 6d zNewScript = m
d080: 70 72 69 6e 74 66 28 22 25 73 25 2e 2a 73 22 2c printf("%s%.*s",
d090: 20 7a 4f 6c 64 53 63 72 69 70 74 2c 20 69 2c 20 zOldScript, i,
d0a0: 7a 50 61 74 68 49 6e 66 6f 29 3b 0a 20 20 20 20 zPathInfo);.
d0b0: 69 66 28 20 67 2e 7a 54 6f 70 20 29 20 67 2e 7a if( g.zTop ) g.z
d0c0: 54 6f 70 20 3d 20 6d 70 72 69 6e 74 66 28 22 25 Top = mprintf("%
d0d0: 73 25 2e 2a 73 22 2c 20 67 2e 7a 54 6f 70 2c 20 s%.*s", g.zTop,
d0e0: 69 2c 20 7a 50 61 74 68 49 6e 66 6f 29 3b 0a 20 i, zPathInfo);.
d0f0: 20 20 20 69 66 28 20 67 2e 7a 42 61 73 65 55 52 if( g.zBaseUR
d100: 4c 20 29 20 67 2e 7a 42 61 73 65 55 52 4c 20 3d L ) g.zBaseURL =
d110: 20 6d 70 72 69 6e 74 66 28 22 25 73 25 2e 2a 73 mprintf("%s%.*s
d120: 22 2c 20 67 2e 7a 42 61 73 65 55 52 4c 2c 20 69 ", g.zBaseURL, i
d130: 2c 20 7a 50 61 74 68 49 6e 66 6f 29 3b 0a 20 20 , zPathInfo);.
d140: 20 20 63 67 69 5f 72 65 70 6c 61 63 65 5f 70 61 cgi_replace_pa
d150: 72 61 6d 65 74 65 72 28 22 50 41 54 48 5f 49 4e rameter("PATH_IN
d160: 46 4f 22 2c 20 26 7a 50 61 74 68 49 6e 66 6f 5b FO", &zPathInfo[
d170: 69 2b 31 5d 29 3b 0a 20 20 20 20 7a 50 61 74 68 i+1]);. zPath
d180: 49 6e 66 6f 20 2b 3d 20 69 3b 0a 20 20 20 20 63 Info += i;. c
d190: 67 69 5f 72 65 70 6c 61 63 65 5f 70 61 72 61 6d gi_replace_param
d1a0: 65 74 65 72 28 22 53 43 52 49 50 54 5f 4e 41 4d eter("SCRIPT_NAM
d1b0: 45 22 2c 20 7a 4e 65 77 53 63 72 69 70 74 29 3b E", zNewScript);
d1c0: 0a 20 20 20 20 64 62 5f 6f 70 65 6e 5f 72 65 70 . db_open_rep
d1d0: 6f 73 69 74 6f 72 79 28 66 69 6c 65 5f 63 6c 65 ository(file_cle
d1e0: 61 6e 75 70 5f 66 75 6c 6c 70 61 74 68 28 7a 52 anup_fullpath(zR
d1f0: 65 70 6f 29 29 3b 0a 20 20 20 20 69 66 28 20 67 epo));. if( g
d200: 2e 66 48 74 74 70 54 72 61 63 65 20 29 7b 0a 20 .fHttpTrace ){.
d210: 20 20 20 20 20 40 20 3c 21 2d 2d 20 72 65 70 6f @ <!-- repo
d220: 73 69 74 6f 72 79 3a 20 22 25 68 28 7a 52 65 70 sitory: "%h(zRep
d230: 6f 29 22 20 2d 2d 3e 0a 20 20 20 20 20 20 40 20 o)" -->. @
d240: 3c 21 2d 2d 20 74 72 61 6e 73 6c 61 74 65 64 20 <!-- translated
d250: 50 41 54 48 5f 49 4e 46 4f 3a 20 22 25 68 28 7a PATH_INFO: "%h(z
d260: 50 61 74 68 49 6e 66 6f 29 22 20 2d 2d 3e 0a 20 PathInfo)" -->.
d270: 20 20 20 20 20 40 20 3c 21 2d 2d 20 74 72 61 6e @ <!-- tran
d280: 73 6c 61 74 65 64 20 53 43 52 49 50 54 5f 4e 41 slated SCRIPT_NA
d290: 4d 45 3a 20 22 25 68 28 7a 4e 65 77 53 63 72 69 ME: "%h(zNewScri
d2a0: 70 74 29 22 20 2d 2d 3e 0a 20 20 20 20 20 20 66 pt)" -->. f
d2b0: 70 72 69 6e 74 66 28 73 74 64 65 72 72 2c 0a 20 printf(stderr,.
d2c0: 20 20 20 20 20 20 20 20 20 22 23 20 72 65 70 6f "# repo
d2d0: 73 69 74 6f 72 79 3a 20 5b 25 73 5d 5c 6e 22 0a sitory: [%s]\n".
d2e0: 20 20 20 20 20 20 20 20 20 20 22 23 20 74 72 61 "# tra
d2f0: 6e 73 6c 61 74 65 64 20 50 41 54 48 5f 49 4e 46 nslated PATH_INF
d300: 4f 20 3d 20 5b 25 73 5d 5c 6e 22 0a 20 20 20 20 O = [%s]\n".
d310: 20 20 20 20 20 20 22 23 20 74 72 61 6e 73 6c 61 "# transla
d320: 74 65 64 20 53 43 52 49 50 54 5f 4e 41 4d 45 20 ted SCRIPT_NAME
d330: 3d 20 5b 25 73 5d 5c 6e 22 2c 0a 20 20 20 20 20 = [%s]\n",.
d340: 20 20 20 20 20 7a 52 65 70 6f 2c 20 7a 50 61 74 zRepo, zPat
d350: 68 49 6e 66 6f 2c 20 7a 4e 65 77 53 63 72 69 70 hInfo, zNewScrip
d360: 74 29 3b 0a 20 20 20 20 20 20 69 66 28 20 67 2e t);. if( g.
d370: 7a 54 6f 70 20 29 7b 0a 20 20 20 20 20 20 20 20 zTop ){.
d380: 40 20 3c 21 2d 2d 20 74 72 61 6e 73 6c 61 74 65 @ <!-- translate
d390: 64 20 67 2e 7a 54 6f 70 3a 20 22 25 68 28 67 2e d g.zTop: "%h(g.
d3a0: 7a 54 6f 70 29 22 20 2d 2d 3e 0a 20 20 20 20 20 zTop)" -->.
d3b0: 20 20 20 66 70 72 69 6e 74 66 28 73 74 64 65 72 fprintf(stder
d3c0: 72 2c 20 22 23 20 74 72 61 6e 73 6c 61 74 65 64 r, "# translated
d3d0: 20 67 2e 7a 54 6f 70 20 3d 20 5b 25 73 5d 5c 6e g.zTop = [%s]\n
d3e0: 22 2c 20 67 2e 7a 54 6f 70 29 3b 0a 20 20 20 20 ", g.zTop);.
d3f0: 20 20 7d 0a 20 20 20 20 20 20 69 66 28 20 67 2e }. if( g.
d400: 7a 42 61 73 65 55 52 4c 20 29 7b 0a 20 20 20 20 zBaseURL ){.
d410: 20 20 20 20 40 20 3c 21 2d 2d 20 74 72 61 6e 73 @ <!-- trans
d420: 6c 61 74 65 64 20 67 2e 7a 42 61 73 65 55 52 4c lated g.zBaseURL
d430: 3a 20 22 25 68 28 67 2e 7a 42 61 73 65 55 52 4c : "%h(g.zBaseURL
d440: 29 22 20 2d 2d 3e 0a 20 20 20 20 20 20 20 20 66 )" -->. f
d450: 70 72 69 6e 74 66 28 73 74 64 65 72 72 2c 20 22 printf(stderr, "
d460: 23 20 74 72 61 6e 73 6c 61 74 65 64 20 67 2e 7a # translated g.z
d470: 42 61 73 65 55 52 4c 20 3d 20 5b 25 73 5d 5c 6e BaseURL = [%s]\n
d480: 22 2c 20 67 2e 7a 42 61 73 65 55 52 4c 29 3b 0a ", g.zBaseURL);.
d490: 20 20 20 20 20 20 7d 0a 20 20 20 20 7d 0a 20 20 }. }.
d4a0: 7d 0a 0a 20 20 2f 2a 20 41 74 20 74 68 69 73 20 }.. /* At this
d4b0: 70 6f 69 6e 74 2c 20 74 68 65 20 61 70 70 72 6f point, the appro
d4c0: 70 72 69 61 74 65 20 72 65 70 6f 73 69 74 6f 72 priate repositor
d4d0: 79 20 64 61 74 61 62 61 73 65 20 66 69 6c 65 20 y database file
d4e0: 77 69 6c 6c 20 68 61 76 65 0a 20 20 2a 2a 20 62 will have. ** b
d4f0: 65 65 6e 20 6f 70 65 6e 65 64 2e 20 20 55 73 65 een opened. Use
d500: 20 74 68 65 20 66 69 72 73 74 20 65 6c 65 6d 65 the first eleme
d510: 6e 74 20 6f 66 20 50 41 54 48 5f 49 4e 46 4f 20 nt of PATH_INFO
d520: 61 73 20 74 68 65 20 70 61 67 65 20 6e 61 6d 65 as the page name
d530: 0a 20 20 2a 2a 20 61 6e 64 20 64 65 6c 69 76 65 . ** and delive
d540: 72 20 74 68 65 20 61 70 70 72 6f 70 72 69 61 74 r the appropriat
d550: 65 20 70 61 67 65 20 62 61 63 6b 20 74 6f 20 74 e page back to t
d560: 68 65 20 75 73 65 72 2e 0a 20 20 2a 2f 0a 20 20 he user.. */.
d570: 69 66 28 20 67 2e 7a 43 6f 6e 74 65 6e 74 54 79 if( g.zContentTy
d580: 70 65 20 26 26 0a 20 20 20 20 20 20 73 74 72 6e pe &&. strn
d590: 63 6d 70 28 67 2e 7a 43 6f 6e 74 65 6e 74 54 79 cmp(g.zContentTy
d5a0: 70 65 2c 20 22 61 70 70 6c 69 63 61 74 69 6f 6e pe, "application
d5b0: 2f 78 2d 66 6f 73 73 69 6c 22 2c 20 32 30 29 3d /x-fossil", 20)=
d5c0: 3d 30 20 29 7b 0a 20 20 20 20 2f 2a 20 53 70 65 =0 ){. /* Spe
d5d0: 63 69 61 6c 20 63 61 73 65 3a 20 20 49 66 20 74 cial case: If t
d5e0: 68 65 20 63 6f 6e 74 65 6e 74 20 6d 69 6d 65 74 he content mimet
d5f0: 79 70 65 20 73 68 6f 77 73 20 74 68 61 74 20 69 ype shows that i
d600: 74 20 69 73 20 22 66 6f 73 73 69 6c 20 73 79 6e t is "fossil syn
d610: 63 22 0a 20 20 20 20 2a 2a 20 70 61 79 6c 6f 61 c". ** payloa
d620: 64 2c 20 74 68 65 6e 20 70 72 65 74 65 6e 64 20 d, then pretend
d630: 74 68 61 74 20 74 68 65 20 50 41 54 48 5f 49 4e that the PATH_IN
d640: 46 4f 20 69 73 20 2f 78 66 65 72 20 73 6f 20 74 FO is /xfer so t
d650: 68 61 74 20 77 65 20 61 6c 77 61 79 73 0a 20 20 hat we always.
d660: 20 20 2a 2a 20 69 6e 76 6f 6b 65 20 74 68 65 20 ** invoke the
d670: 73 79 6e 63 20 70 61 67 65 2e 20 2a 2f 0a 20 20 sync page. */.
d680: 20 20 7a 50 61 74 68 49 6e 66 6f 20 3d 20 22 2f zPathInfo = "/
d690: 78 66 65 72 22 3b 0a 20 20 7d 0a 20 20 73 65 74 xfer";. }. set
d6a0: 5f 62 61 73 65 5f 75 72 6c 28 30 29 3b 0a 20 20 _base_url(0);.
d6b0: 69 66 28 20 7a 50 61 74 68 49 6e 66 6f 3d 3d 30 if( zPathInfo==0
d6c0: 20 7c 7c 20 7a 50 61 74 68 49 6e 66 6f 5b 30 5d || zPathInfo[0]
d6d0: 3d 3d 30 0a 20 20 20 20 20 20 7c 7c 20 28 7a 50 ==0. || (zP
d6e0: 61 74 68 49 6e 66 6f 5b 30 5d 3d 3d 27 2f 27 20 athInfo[0]=='/'
d6f0: 26 26 20 7a 50 61 74 68 49 6e 66 6f 5b 31 5d 3d && zPathInfo[1]=
d700: 3d 30 29 20 29 7b 0a 20 20 20 20 2f 2a 20 53 65 =0) ){. /* Se
d710: 63 6f 6e 64 20 73 70 65 63 69 61 6c 20 63 61 73 cond special cas
d720: 65 3a 20 49 66 20 74 68 65 20 50 41 54 48 5f 49 e: If the PATH_I
d730: 4e 46 4f 20 69 73 20 62 6c 61 6e 6b 2c 20 69 73 NFO is blank, is
d740: 73 75 65 20 61 20 72 65 64 69 72 65 63 74 20 74 sue a redirect t
d750: 6f 0a 20 20 20 20 2a 2a 20 74 68 65 20 68 6f 6d o. ** the hom
d760: 65 20 70 61 67 65 20 69 64 65 6e 74 69 66 69 65 e page identifie
d770: 64 20 62 79 20 74 68 65 20 22 69 6e 64 65 78 2d d by the "index-
d780: 70 61 67 65 22 20 73 65 74 74 69 6e 67 20 69 6e page" setting in
d790: 20 74 68 65 20 72 65 70 6f 73 69 74 6f 72 79 0a the repository.
d7a0: 20 20 20 20 2a 2a 20 43 4f 4e 46 49 47 20 74 61 ** CONFIG ta
d7b0: 62 6c 65 2c 20 74 6f 20 22 2f 69 6e 64 65 78 22 ble, to "/index"
d7c0: 20 69 66 20 74 68 65 72 65 20 6e 6f 20 22 69 6e if there no "in
d7d0: 64 65 78 2d 70 61 67 65 22 20 73 65 74 74 69 6e dex-page" settin
d7e0: 67 2e 20 2a 2f 0a 23 69 66 64 65 66 20 46 4f 53 g. */.#ifdef FOS
d7f0: 53 49 4c 5f 45 4e 41 42 4c 45 5f 4a 53 4f 4e 0a SIL_ENABLE_JSON.
d800: 20 20 20 20 69 66 28 67 2e 6a 73 6f 6e 2e 69 73 if(g.json.is
d810: 4a 73 6f 6e 4d 6f 64 65 29 7b 0a 20 20 20 20 20 JsonMode){.
d820: 20 6a 73 6f 6e 5f 65 72 72 28 46 53 4c 5f 4a 53 json_err(FSL_JS
d830: 4f 4e 5f 45 5f 52 45 53 4f 55 52 43 45 5f 4e 4f ON_E_RESOURCE_NO
d840: 54 5f 46 4f 55 4e 44 2c 4e 55 4c 4c 2c 31 29 3b T_FOUND,NULL,1);
d850: 0a 20 20 20 20 20 20 66 6f 73 73 69 6c 5f 65 78 . fossil_ex
d860: 69 74 28 30 29 3b 0a 20 20 20 20 7d 0a 23 65 6e it(0);. }.#en
d870: 64 69 66 0a 20 20 20 20 66 6f 73 73 69 6c 5f 72 dif. fossil_r
d880: 65 64 69 72 65 63 74 5f 68 6f 6d 65 28 29 20 2f edirect_home() /
d890: 2a 64 6f 65 73 20 6e 6f 74 20 72 65 74 75 72 6e *does not return
d8a0: 2a 2f 3b 0a 20 20 7d 65 6c 73 65 7b 0a 20 20 20 */;. }else{.
d8b0: 20 7a 50 61 74 68 20 3d 20 6d 70 72 69 6e 74 66 zPath = mprintf
d8c0: 28 22 25 73 22 2c 20 7a 50 61 74 68 49 6e 66 6f ("%s", zPathInfo
d8d0: 29 3b 0a 20 20 7d 0a 0a 20 20 2f 2a 20 4d 61 6b );. }.. /* Mak
d8e0: 65 20 67 2e 7a 50 61 74 68 20 70 6f 69 6e 74 20 e g.zPath point
d8f0: 74 6f 20 74 68 65 20 66 69 72 73 74 20 65 6c 65 to the first ele
d900: 6d 65 6e 74 20 6f 66 20 74 68 65 20 70 61 74 68 ment of the path
d910: 2e 20 20 4d 61 6b 65 0a 20 20 2a 2a 20 67 2e 7a . Make. ** g.z
d920: 45 78 74 72 61 20 70 6f 69 6e 74 20 74 6f 20 65 Extra point to e
d930: 76 65 72 79 74 68 69 6e 67 20 70 61 73 74 20 74 verything past t
d940: 68 61 74 20 70 6f 69 6e 74 2e 0a 20 20 2a 2f 0a hat point.. */.
d950: 20 20 77 68 69 6c 65 28 31 29 7b 0a 20 20 20 20 while(1){.
d960: 67 2e 7a 50 61 74 68 20 3d 20 26 7a 50 61 74 68 g.zPath = &zPath
d970: 5b 31 5d 3b 0a 20 20 20 20 66 6f 72 28 69 3d 31 [1];. for(i=1
d980: 3b 20 7a 50 61 74 68 5b 69 5d 20 26 26 20 7a 50 ; zPath[i] && zP
d990: 61 74 68 5b 69 5d 21 3d 27 2f 27 3b 20 69 2b 2b ath[i]!='/'; i++
d9a0: 29 7b 7d 0a 20 20 20 20 69 66 28 20 7a 50 61 74 ){}. if( zPat
d9b0: 68 5b 69 5d 3d 3d 27 2f 27 20 29 7b 0a 20 20 20 h[i]=='/' ){.
d9c0: 20 20 20 7a 50 61 74 68 5b 69 5d 20 3d 20 30 3b zPath[i] = 0;
d9d0: 0a 20 20 20 20 20 20 67 2e 7a 45 78 74 72 61 20 . g.zExtra
d9e0: 3d 20 26 7a 50 61 74 68 5b 69 2b 31 5d 3b 0a 20 = &zPath[i+1];.
d9f0: 20 20 20 7d 65 6c 73 65 7b 0a 20 20 20 20 20 20 }else{.
da00: 67 2e 7a 45 78 74 72 61 20 3d 20 30 3b 0a 20 20 g.zExtra = 0;.
da10: 20 20 7d 0a 20 20 20 20 62 72 65 61 6b 3b 0a 20 }. break;.
da20: 20 7d 0a 23 69 66 64 65 66 20 46 4f 53 53 49 4c }.#ifdef FOSSIL
da30: 5f 45 4e 41 42 4c 45 5f 4a 53 4f 4e 0a 20 20 2f _ENABLE_JSON. /
da40: 2a 0a 20 20 2a 2a 20 57 6f 72 6b 61 72 6f 75 6e *. ** Workaroun
da50: 64 20 74 6f 20 61 6c 6c 6f 77 20 75 73 20 74 6f d to allow us to
da60: 20 63 75 73 74 6f 6d 69 7a 65 20 73 6f 6d 65 20 customize some
da70: 66 6f 6c 6c 6f 77 69 6e 67 20 62 65 68 61 76 69 following behavi
da80: 6f 75 72 20 66 6f 72 0a 20 20 2a 2a 20 4a 53 4f our for. ** JSO
da90: 4e 20 6d 6f 64 65 2e 20 20 54 68 65 20 70 72 6f N mode. The pro
daa0: 62 6c 65 6d 20 69 73 2c 20 77 65 20 64 6f 6e 27 blem is, we don'
dab0: 74 20 61 6c 77 61 79 73 20 6b 6e 6f 77 20 69 66 t always know if
dac0: 20 77 65 27 72 65 20 69 6e 20 4a 53 4f 4e 0a 20 we're in JSON.
dad0: 20 2a 2a 20 6d 6f 64 65 20 61 74 20 74 68 69 73 ** mode at this
dae0: 20 70 6f 69 6e 74 20 28 6e 61 6d 65 6c 79 2c 20 point (namely,
daf0: 66 6f 72 20 47 45 54 20 6d 6f 64 65 20 77 65 20 for GET mode we
db00: 64 6f 6e 27 74 20 6b 6e 6f 77 20 62 75 74 20 50 don't know but P
db10: 4f 53 54 0a 20 20 2a 2a 20 77 65 20 64 6f 29 2c OST. ** we do),
db20: 20 73 6f 20 77 65 20 73 6e 6f 6f 70 20 67 2e 7a so we snoop g.z
db30: 50 61 74 68 20 61 6e 64 20 63 68 65 61 74 20 61 Path and cheat a
db40: 20 62 69 74 2e 0a 20 20 2a 2f 0a 20 20 69 66 28 bit.. */. if(
db50: 20 21 67 2e 6a 73 6f 6e 2e 69 73 4a 73 6f 6e 4d !g.json.isJsonM
db60: 6f 64 65 20 26 26 20 67 2e 7a 50 61 74 68 20 26 ode && g.zPath &
db70: 26 20 28 30 3d 3d 73 74 72 6e 63 6d 70 28 22 6a & (0==strncmp("j
db80: 73 6f 6e 22 2c 67 2e 7a 50 61 74 68 2c 34 29 29 son",g.zPath,4))
db90: 20 29 7b 0a 20 20 20 20 67 2e 6a 73 6f 6e 2e 69 ){. g.json.i
dba0: 73 4a 73 6f 6e 4d 6f 64 65 20 3d 20 31 3b 0a 20 sJsonMode = 1;.
dbb0: 20 7d 0a 23 65 6e 64 69 66 0a 20 20 69 66 28 20 }.#endif. if(
dbc0: 67 2e 7a 45 78 74 72 61 20 29 7b 0a 20 20 20 20 g.zExtra ){.
dbd0: 2f 2a 20 43 47 49 20 70 61 72 61 6d 65 74 65 72 /* CGI parameter
dbe0: 73 20 67 65 74 20 74 68 69 73 20 74 72 65 61 74 s get this treat
dbf0: 6d 65 6e 74 20 65 6c 73 65 77 68 65 72 65 2c 20 ment elsewhere,
dc00: 62 75 74 20 70 6c 61 63 65 73 20 6c 69 6b 65 20 but places like
dc10: 67 65 74 66 69 6c 65 0a 20 20 20 20 2a 2a 20 77 getfile. ** w
dc20: 69 6c 6c 20 75 73 65 20 67 2e 7a 45 78 74 72 61 ill use g.zExtra
dc30: 20 64 69 72 65 63 74 6c 79 2e 0a 20 20 20 20 2a directly.. *
dc40: 2a 20 52 65 6d 69 6e 64 65 72 3a 20 74 68 65 20 * Reminder: the
dc50: 6c 6f 67 69 6e 20 6d 65 63 68 61 6e 69 73 6d 20 login mechanism
dc60: 75 73 65 73 20 27 6e 61 6d 65 27 20 64 69 66 66 uses 'name' diff
dc70: 65 72 65 6e 74 6c 79 2c 20 61 6e 64 20 6d 61 79 erently, and may
dc80: 0a 20 20 20 20 2a 2a 20 65 76 65 6e 74 75 61 6c . ** eventual
dc90: 6c 79 20 68 61 76 65 20 61 20 70 72 6f 62 6c 65 ly have a proble
dca0: 6d 2f 63 6f 6c 6c 69 73 69 6f 6e 20 77 69 74 68 m/collision with
dcb0: 20 74 68 69 73 2e 0a 20 20 20 20 2a 2a 0a 20 20 this.. **.
dcc0: 20 20 2a 2a 20 44 69 73 61 62 6c 65 64 20 62 79 ** Disabled by
dcd0: 20 73 74 65 70 68 61 6e 20 77 68 65 6e 20 72 75 stephan when ru
dce0: 6e 6e 69 6e 67 20 69 6e 20 4a 53 4f 4e 20 6d 6f nning in JSON mo
dcf0: 64 65 20 62 65 63 61 75 73 65 20 74 68 69 73 0a de because this.
dd00: 20 20 20 20 2a 2a 20 70 61 72 74 69 63 75 6c 61 ** particula
dd10: 72 20 70 61 72 61 6d 65 74 65 72 20 6e 61 6d 65 r parameter name
dd20: 20 69 73 20 76 65 72 79 20 63 6f 6d 6d 6f 6e 20 is very common
dd30: 61 6e 64 20 69 20 68 61 76 65 20 68 61 64 20 6e and i have had n
dd40: 6f 20 65 6e 64 0a 20 20 20 20 2a 2a 20 6f 66 20 o end. ** of
dd50: 67 72 69 65 66 20 77 69 74 68 20 74 68 69 73 20 grief with this
dd60: 68 61 6e 64 6c 69 6e 67 2e 20 54 68 65 20 4a 53 handling. The JS
dd70: 4f 4e 20 41 50 49 20 6e 65 76 65 72 20 72 65 6c ON API never rel
dd80: 69 65 73 20 6f 6e 20 74 68 65 0a 20 20 20 20 2a ies on the. *
dd90: 2a 20 68 61 6e 64 6c 69 6e 67 20 62 65 6c 6f 77 * handling below
dda0: 2c 20 61 6e 64 20 62 79 20 64 69 73 61 62 6c 69 , and by disabli
ddb0: 6e 67 20 69 74 20 69 6e 20 4a 53 4f 4e 20 6d 6f ng it in JSON mo
ddc0: 64 65 20 49 20 63 61 6e 20 72 65 6d 6f 76 65 0a de I can remove.
ddd0: 20 20 20 20 2a 2a 20 6c 6f 74 73 20 6f 66 20 73 ** lots of s
dde0: 70 65 63 69 61 6c 2d 63 61 73 65 20 68 61 6e 64 pecial-case hand
ddf0: 6c 69 6e 67 20 69 6e 20 73 65 76 65 72 61 6c 20 ling in several
de00: 4a 53 4f 4e 20 68 61 6e 64 6c 65 72 73 2e 0a 20 JSON handlers..
de10: 20 20 20 2a 2f 0a 23 69 66 64 65 66 20 46 4f 53 */.#ifdef FOS
de20: 53 49 4c 5f 45 4e 41 42 4c 45 5f 4a 53 4f 4e 0a SIL_ENABLE_JSON.
de30: 20 20 20 20 69 66 28 21 67 2e 6a 73 6f 6e 2e 69 if(!g.json.i
de40: 73 4a 73 6f 6e 4d 6f 64 65 29 7b 0a 23 65 6e 64 sJsonMode){.#end
de50: 69 66 0a 20 20 20 20 20 20 64 65 68 74 74 70 69 if. dehttpi
de60: 7a 65 28 67 2e 7a 45 78 74 72 61 29 3b 0a 20 20 ze(g.zExtra);.
de70: 20 20 20 20 63 67 69 5f 73 65 74 5f 70 61 72 61 cgi_set_para
de80: 6d 65 74 65 72 5f 6e 6f 63 6f 70 79 28 22 6e 61 meter_nocopy("na
de90: 6d 65 22 2c 20 67 2e 7a 45 78 74 72 61 2c 20 31 me", g.zExtra, 1
dea0: 29 3b 0a 23 69 66 64 65 66 20 46 4f 53 53 49 4c );.#ifdef FOSSIL
deb0: 5f 45 4e 41 42 4c 45 5f 4a 53 4f 4e 0a 20 20 20 _ENABLE_JSON.
dec0: 20 7d 0a 23 65 6e 64 69 66 0a 20 20 7d 0a 0a 20 }.#endif. }..
ded0: 20 2f 2a 20 4c 6f 63 61 74 65 20 74 68 65 20 6d /* Locate the m
dee0: 65 74 68 6f 64 20 73 70 65 63 69 66 69 65 64 20 ethod specified
def0: 62 79 20 74 68 65 20 70 61 74 68 20 61 6e 64 20 by the path and
df00: 65 78 65 63 75 74 65 20 74 68 65 20 66 75 6e 63 execute the func
df10: 74 69 6f 6e 0a 20 20 2a 2a 20 74 68 61 74 20 69 tion. ** that i
df20: 6d 70 6c 65 6d 65 6e 74 73 20 74 68 61 74 20 6d mplements that m
df30: 65 74 68 6f 64 2e 0a 20 20 2a 2f 0a 20 20 69 66 ethod.. */. if
df40: 28 20 64 69 73 70 61 74 63 68 5f 6e 61 6d 65 5f ( dispatch_name_
df50: 73 65 61 72 63 68 28 67 2e 7a 50 61 74 68 2d 31 search(g.zPath-1
df60: 2c 20 43 4d 44 46 4c 41 47 5f 57 45 42 50 41 47 , CMDFLAG_WEBPAG
df70: 45 2c 20 26 70 43 6d 64 29 20 29 7b 0a 23 69 66 E, &pCmd) ){.#if
df80: 64 65 66 20 46 4f 53 53 49 4c 5f 45 4e 41 42 4c def FOSSIL_ENABL
df90: 45 5f 4a 53 4f 4e 0a 20 20 20 20 69 66 28 67 2e E_JSON. if(g.
dfa0: 6a 73 6f 6e 2e 69 73 4a 73 6f 6e 4d 6f 64 65 29 json.isJsonMode)
dfb0: 7b 0a 20 20 20 20 20 20 6a 73 6f 6e 5f 65 72 72 {. json_err
dfc0: 28 46 53 4c 5f 4a 53 4f 4e 5f 45 5f 52 45 53 4f (FSL_JSON_E_RESO
dfd0: 55 52 43 45 5f 4e 4f 54 5f 46 4f 55 4e 44 2c 4e URCE_NOT_FOUND,N
dfe0: 55 4c 4c 2c 30 29 3b 0a 20 20 20 20 7d 65 6c 73 ULL,0);. }els
dff0: 65 0a 23 65 6e 64 69 66 0a 20 20 20 20 7b 0a 23 e.#endif. {.#
e000: 69 66 64 65 66 20 46 4f 53 53 49 4c 5f 45 4e 41 ifdef FOSSIL_ENA
e010: 42 4c 45 5f 54 48 31 5f 48 4f 4f 4b 53 0a 20 20 BLE_TH1_HOOKS.
e020: 20 20 20 20 69 6e 74 20 72 63 3b 0a 20 20 20 20 int rc;.
e030: 20 20 69 66 28 20 21 67 2e 66 4e 6f 54 68 48 6f if( !g.fNoThHo
e040: 6f 6b 20 29 7b 0a 20 20 20 20 20 20 20 20 72 63 ok ){. rc
e050: 20 3d 20 54 68 5f 57 65 62 70 61 67 65 48 6f 6f = Th_WebpageHoo
e060: 6b 28 67 2e 7a 50 61 74 68 2c 20 30 29 3b 0a 20 k(g.zPath, 0);.
e070: 20 20 20 20 20 7d 65 6c 73 65 7b 0a 20 20 20 20 }else{.
e080: 20 20 20 20 72 63 20 3d 20 54 48 5f 4f 4b 3b 0a rc = TH_OK;.
e090: 20 20 20 20 20 20 7d 0a 20 20 20 20 20 20 69 66 }. if
e0a0: 28 20 72 63 3d 3d 54 48 5f 4f 4b 20 7c 7c 20 72 ( rc==TH_OK || r
e0b0: 63 3d 3d 54 48 5f 52 45 54 55 52 4e 20 7c 7c 20 c==TH_RETURN ||
e0c0: 72 63 3d 3d 54 48 5f 43 4f 4e 54 49 4e 55 45 20 rc==TH_CONTINUE
e0d0: 29 7b 0a 20 20 20 20 20 20 20 20 69 66 28 20 72 ){. if( r
e0e0: 63 3d 3d 54 48 5f 4f 4b 20 7c 7c 20 72 63 3d 3d c==TH_OK || rc==
e0f0: 54 48 5f 52 45 54 55 52 4e 20 29 7b 0a 23 65 6e TH_RETURN ){.#en
e100: 64 69 66 0a 20 20 20 20 20 20 20 20 20 20 63 67 dif. cg
e110: 69 5f 73 65 74 5f 73 74 61 74 75 73 28 34 30 34 i_set_status(404
e120: 2c 22 4e 6f 74 20 46 6f 75 6e 64 22 29 3b 0a 20 ,"Not Found");.
e130: 20 20 20 20 20 20 20 20 20 40 20 3c 68 31 3e 4e @ <h1>N
e140: 6f 74 20 46 6f 75 6e 64 3c 2f 68 31 3e 0a 20 20 ot Found</h1>.
e150: 20 20 20 20 20 20 20 20 40 20 3c 70 3e 50 61 67 @ <p>Pag
e160: 65 20 6e 6f 74 20 66 6f 75 6e 64 3a 20 25 68 28 e not found: %h(
e170: 67 2e 7a 50 61 74 68 29 3c 2f 70 3e 0a 23 69 66 g.zPath)</p>.#if
e180: 64 65 66 20 46 4f 53 53 49 4c 5f 45 4e 41 42 4c def FOSSIL_ENABL
e190: 45 5f 54 48 31 5f 48 4f 4f 4b 53 0a 20 20 20 20 E_TH1_HOOKS.
e1a0: 20 20 20 20 7d 0a 20 20 20 20 20 20 20 20 69 66 }. if
e1b0: 28 20 21 67 2e 66 4e 6f 54 68 48 6f 6f 6b 20 26 ( !g.fNoThHook &
e1c0: 26 20 28 72 63 3d 3d 54 48 5f 4f 4b 20 7c 7c 20 & (rc==TH_OK ||
e1d0: 72 63 3d 3d 54 48 5f 43 4f 4e 54 49 4e 55 45 29 rc==TH_CONTINUE)
e1e0: 20 29 7b 0a 20 20 20 20 20 20 20 20 20 20 54 68 ){. Th
e1f0: 5f 57 65 62 70 61 67 65 4e 6f 74 69 66 79 28 67 _WebpageNotify(g
e200: 2e 7a 50 61 74 68 2c 20 30 29 3b 0a 20 20 20 20 .zPath, 0);.
e210: 20 20 20 20 7d 0a 20 20 20 20 20 20 7d 0a 23 65 }. }.#e
e220: 6e 64 69 66 0a 20 20 20 20 7d 0a 20 20 7d 65 6c ndif. }. }el
e230: 73 65 20 69 66 28 20 70 43 6d 64 2d 3e 78 46 75 se if( pCmd->xFu
e240: 6e 63 21 3d 70 61 67 65 5f 78 66 65 72 20 26 26 nc!=page_xfer &&
e250: 20 64 62 5f 73 63 68 65 6d 61 5f 69 73 5f 6f 75 db_schema_is_ou
e260: 74 6f 66 64 61 74 65 28 29 20 29 7b 0a 23 69 66 tofdate() ){.#if
e270: 64 65 66 20 46 4f 53 53 49 4c 5f 45 4e 41 42 4c def FOSSIL_ENABL
e280: 45 5f 4a 53 4f 4e 0a 20 20 20 20 69 66 28 67 2e E_JSON. if(g.
e290: 6a 73 6f 6e 2e 69 73 4a 73 6f 6e 4d 6f 64 65 29 json.isJsonMode)
e2a0: 7b 0a 20 20 20 20 20 20 6a 73 6f 6e 5f 65 72 72 {. json_err
e2b0: 28 46 53 4c 5f 4a 53 4f 4e 5f 45 5f 44 42 5f 4e (FSL_JSON_E_DB_N
e2c0: 45 45 44 53 5f 52 45 42 55 49 4c 44 2c 4e 55 4c EEDS_REBUILD,NUL
e2d0: 4c 2c 30 29 3b 0a 20 20 20 20 7d 65 6c 73 65 0a L,0);. }else.
e2e0: 23 65 6e 64 69 66 0a 20 20 20 20 7b 0a 20 20 20 #endif. {.
e2f0: 20 20 20 40 20 3c 68 31 3e 53 65 72 76 65 72 20 @ <h1>Server
e300: 43 6f 6e 66 69 67 75 72 61 74 69 6f 6e 20 45 72 Configuration Er
e310: 72 6f 72 3c 2f 68 31 3e 0a 20 20 20 20 20 20 40 ror</h1>. @
e320: 20 3c 70 3e 54 68 65 20 64 61 74 61 62 61 73 65 <p>The database
e330: 20 73 63 68 65 6d 61 20 6f 6e 20 74 68 65 20 73 schema on the s
e340: 65 72 76 65 72 20 69 73 20 6f 75 74 2d 6f 66 2d erver is out-of-
e350: 64 61 74 65 2e 20 20 50 6c 65 61 73 65 20 61 73 date. Please as
e360: 6b 0a 20 20 20 20 20 20 40 20 74 68 65 20 61 64 k. @ the ad
e370: 6d 69 6e 69 73 74 72 61 74 6f 72 20 74 6f 20 72 ministrator to r
e380: 75 6e 20 3c 62 3e 66 6f 73 73 69 6c 20 72 65 62 un <b>fossil reb
e390: 75 69 6c 64 3c 2f 62 3e 2e 3c 2f 70 3e 0a 20 20 uild</b>.</p>.
e3a0: 20 20 7d 0a 20 20 7d 65 6c 73 65 7b 0a 23 69 66 }. }else{.#if
e3b0: 64 65 66 20 46 4f 53 53 49 4c 5f 45 4e 41 42 4c def FOSSIL_ENABL
e3c0: 45 5f 54 48 31 5f 48 4f 4f 4b 53 0a 20 20 20 20 E_TH1_HOOKS.
e3d0: 2f 2a 0a 20 20 20 20 2a 2a 20 54 68 65 20 54 48 /*. ** The TH
e3e0: 31 20 72 65 74 75 72 6e 20 63 6f 64 65 73 20 66 1 return codes f
e3f0: 72 6f 6d 20 74 68 65 20 68 6f 6f 6b 20 77 69 6c rom the hook wil
e400: 6c 20 62 65 20 68 61 6e 64 6c 65 64 20 61 73 20 l be handled as
e410: 66 6f 6c 6c 6f 77 73 3a 0a 20 20 20 20 2a 2a 0a follows:. **.
e420: 20 20 20 20 2a 2a 20 54 48 5f 4f 4b 3a 20 54 68 ** TH_OK: Th
e430: 65 20 78 46 75 6e 63 28 29 20 61 6e 64 20 74 68 e xFunc() and th
e440: 65 20 54 48 31 20 6e 6f 74 69 66 69 63 61 74 69 e TH1 notificati
e450: 6f 6e 20 77 69 6c 6c 20 62 6f 74 68 20 62 65 20 on will both be
e460: 65 78 65 63 75 74 65 64 2e 0a 20 20 20 20 2a 2a executed.. **
e470: 0a 20 20 20 20 2a 2a 20 54 48 5f 45 52 52 4f 52 . ** TH_ERROR
e480: 3a 20 54 68 65 20 78 46 75 6e 63 28 29 20 77 69 : The xFunc() wi
e490: 6c 6c 20 62 65 20 65 78 65 63 75 74 65 64 2c 20 ll be executed,
e4a0: 74 68 65 20 54 48 31 20 6e 6f 74 69 66 69 63 61 the TH1 notifica
e4b0: 74 69 6f 6e 20 77 69 6c 6c 20 62 65 0a 20 20 20 tion will be.
e4c0: 20 2a 2a 20 20 20 20 20 20 20 20 20 20 20 73 6b ** sk
e4d0: 69 70 70 65 64 2e 20 20 49 66 20 74 68 65 20 78 ipped. If the x
e4e0: 46 75 6e 63 28 29 20 69 73 20 62 65 69 6e 67 20 Func() is being
e4f0: 68 6f 6f 6b 65 64 2c 20 74 68 65 20 65 72 72 6f hooked, the erro
e500: 72 20 6d 65 73 73 61 67 65 0a 20 20 20 20 2a 2a r message. **
e510: 20 20 20 20 20 20 20 20 20 20 20 77 69 6c 6c 20 will
e520: 62 65 20 65 6d 69 74 74 65 64 2e 0a 20 20 20 20 be emitted..
e530: 2a 2a 0a 20 20 20 20 2a 2a 20 54 48 5f 42 52 45 **. ** TH_BRE
e540: 41 4b 3a 20 54 68 65 20 78 46 75 6e 63 28 29 20 AK: The xFunc()
e550: 61 6e 64 20 74 68 65 20 54 48 31 20 6e 6f 74 69 and the TH1 noti
e560: 66 69 63 61 74 69 6f 6e 20 77 69 6c 6c 20 62 6f fication will bo
e570: 74 68 20 62 65 20 73 6b 69 70 70 65 64 2e 0a 20 th be skipped..
e580: 20 20 20 2a 2a 0a 20 20 20 20 2a 2a 20 54 48 5f **. ** TH_
e590: 52 45 54 55 52 4e 3a 20 54 68 65 20 78 46 75 6e RETURN: The xFun
e5a0: 63 28 29 20 77 69 6c 6c 20 62 65 20 65 78 65 63 c() will be exec
e5b0: 75 74 65 64 2c 20 74 68 65 20 54 48 31 20 6e 6f uted, the TH1 no
e5c0: 74 69 66 69 63 61 74 69 6f 6e 20 77 69 6c 6c 20 tification will
e5d0: 62 65 0a 20 20 20 20 2a 2a 20 20 20 20 20 20 20 be. **
e5e0: 20 20 20 20 20 73 6b 69 70 70 65 64 2e 0a 20 20 skipped..
e5f0: 20 20 2a 2a 0a 20 20 20 20 2a 2a 20 54 48 5f 43 **. ** TH_C
e600: 4f 4e 54 49 4e 55 45 3a 20 54 68 65 20 78 46 75 ONTINUE: The xFu
e610: 6e 63 28 29 20 77 69 6c 6c 20 62 65 20 73 6b 69 nc() will be ski
e620: 70 70 65 64 2c 20 74 68 65 20 54 48 31 20 6e 6f pped, the TH1 no
e630: 74 69 66 69 63 61 74 69 6f 6e 20 77 69 6c 6c 20 tification will
e640: 62 65 0a 20 20 20 20 2a 2a 20 20 20 20 20 20 20 be. **
e650: 20 20 20 20 20 20 20 65 78 65 63 75 74 65 64 2e executed.
e660: 0a 20 20 20 20 2a 2f 0a 20 20 20 20 69 6e 74 20 . */. int
e670: 72 63 3b 0a 20 20 20 20 69 66 28 20 21 67 2e 66 rc;. if( !g.f
e680: 4e 6f 54 68 48 6f 6f 6b 20 29 7b 0a 20 20 20 20 NoThHook ){.
e690: 20 20 72 63 20 3d 20 54 68 5f 57 65 62 70 61 67 rc = Th_Webpag
e6a0: 65 48 6f 6f 6b 28 70 43 6d 64 2d 3e 7a 4e 61 6d eHook(pCmd->zNam
e6b0: 65 2b 31 2c 20 70 43 6d 64 2d 3e 65 43 6d 64 46 e+1, pCmd->eCmdF
e6c0: 6c 61 67 73 29 3b 0a 20 20 20 20 7d 65 6c 73 65 lags);. }else
e6d0: 7b 0a 20 20 20 20 20 20 72 63 20 3d 20 54 48 5f {. rc = TH_
e6e0: 4f 4b 3b 0a 20 20 20 20 7d 0a 20 20 20 20 69 66 OK;. }. if
e6f0: 28 20 72 63 3d 3d 54 48 5f 4f 4b 20 7c 7c 20 72 ( rc==TH_OK || r
e700: 63 3d 3d 54 48 5f 52 45 54 55 52 4e 20 7c 7c 20 c==TH_RETURN ||
e710: 72 63 3d 3d 54 48 5f 43 4f 4e 54 49 4e 55 45 20 rc==TH_CONTINUE
e720: 29 7b 0a 20 20 20 20 20 20 69 66 28 20 72 63 3d ){. if( rc=
e730: 3d 54 48 5f 4f 4b 20 7c 7c 20 72 63 3d 3d 54 48 =TH_OK || rc==TH
e740: 5f 52 45 54 55 52 4e 20 29 7b 0a 23 65 6e 64 69 _RETURN ){.#endi
e750: 66 0a 20 20 20 20 20 20 20 20 70 43 6d 64 2d 3e f. pCmd->
e760: 78 46 75 6e 63 28 29 3b 0a 23 69 66 64 65 66 20 xFunc();.#ifdef
e770: 46 4f 53 53 49 4c 5f 45 4e 41 42 4c 45 5f 54 48 FOSSIL_ENABLE_TH
e780: 31 5f 48 4f 4f 4b 53 0a 20 20 20 20 20 20 7d 0a 1_HOOKS. }.
e790: 20 20 20 20 20 20 69 66 28 20 21 67 2e 66 4e 6f if( !g.fNo
e7a0: 54 68 48 6f 6f 6b 20 26 26 20 28 72 63 3d 3d 54 ThHook && (rc==T
e7b0: 48 5f 4f 4b 20 7c 7c 20 72 63 3d 3d 54 48 5f 43 H_OK || rc==TH_C
e7c0: 4f 4e 54 49 4e 55 45 29 20 29 7b 0a 20 20 20 20 ONTINUE) ){.
e7d0: 20 20 20 20 54 68 5f 57 65 62 70 61 67 65 4e 6f Th_WebpageNo
e7e0: 74 69 66 79 28 70 43 6d 64 2d 3e 7a 4e 61 6d 65 tify(pCmd->zName
e7f0: 2b 31 2c 20 70 43 6d 64 2d 3e 65 43 6d 64 46 6c +1, pCmd->eCmdFl
e800: 61 67 73 29 3b 0a 20 20 20 20 20 20 7d 0a 20 20 ags);. }.
e810: 20 20 7d 0a 23 65 6e 64 69 66 0a 20 20 7d 0a 0a }.#endif. }..
e820: 20 20 2f 2a 20 52 65 74 75 72 6e 20 74 68 65 20 /* Return the
e830: 72 65 73 75 6c 74 2e 0a 20 20 2a 2f 0a 20 20 63 result.. */. c
e840: 67 69 5f 72 65 70 6c 79 28 29 3b 0a 7d 0a 0a 2f gi_reply();.}../
e850: 2a 20 49 66 20 74 68 65 20 43 47 49 20 70 72 6f * If the CGI pro
e860: 67 72 61 6d 20 63 6f 6e 74 61 69 6e 73 20 6f 6e gram contains on
e870: 65 20 6f 72 20 6d 6f 72 65 20 6c 69 6e 65 73 20 e or more lines
e880: 6f 66 20 74 68 65 20 66 6f 72 6d 0a 2a 2a 0a 2a of the form.**.*
e890: 2a 20 20 20 20 72 65 64 69 72 65 63 74 3a 20 20 * redirect:
e8a0: 72 65 70 6f 73 69 74 6f 72 79 2d 66 69 6c 65 6e repository-filen
e8b0: 61 6d 65 20 20 68 74 74 70 3a 2f 2f 68 6f 73 74 ame http://host
e8c0: 6e 61 6d 65 2f 70 61 74 68 2f 25 73 0a 2a 2a 0a name/path/%s.**.
e8d0: 2a 2a 20 74 68 65 6e 20 63 6f 6e 74 72 6f 6c 20 ** then control
e8e0: 6a 75 6d 70 73 20 68 65 72 65 2e 20 20 53 65 61 jumps here. Sea
e8f0: 72 63 68 20 65 61 63 68 20 72 65 70 6f 73 69 74 rch each reposit
e900: 6f 72 79 20 66 6f 72 20 61 6e 20 61 72 74 69 66 ory for an artif
e910: 61 63 74 20 49 44 0a 2a 2a 20 6f 72 20 74 69 63 act ID.** or tic
e920: 6b 65 74 20 49 44 20 74 68 61 74 20 6d 61 74 63 ket ID that matc
e930: 68 65 73 20 74 68 65 20 22 6e 61 6d 65 22 20 43 hes the "name" C
e940: 47 49 20 70 61 72 61 6d 65 74 65 72 20 61 6e 64 GI parameter and
e950: 20 66 6f 72 20 74 68 65 0a 2a 2a 20 66 69 72 73 for the.** firs
e960: 74 20 6d 61 74 63 68 2c 20 72 65 64 69 72 65 63 t match, redirec
e970: 74 20 74 6f 20 74 68 65 20 63 6f 72 72 65 73 70 t to the corresp
e980: 6f 6e 64 69 6e 67 20 55 52 4c 20 77 69 74 68 20 onding URL with
e990: 74 68 65 20 22 6e 61 6d 65 22 20 43 47 49 0a 2a the "name" CGI.*
e9a0: 2a 20 70 61 72 61 6d 65 74 65 72 20 69 6e 73 65 * parameter inse
e9b0: 72 74 65 64 2e 20 20 50 61 69 6e 74 20 61 6e 20 rted. Paint an
e9c0: 65 72 72 6f 72 20 70 61 67 65 20 69 66 20 6e 6f error page if no
e9d0: 20 6d 61 74 63 68 20 69 73 20 66 6f 75 6e 64 2e match is found.
e9e0: 0a 2a 2a 0a 2a 2a 20 49 66 20 74 68 65 72 65 20 .**.** If there
e9f0: 69 73 20 61 20 6c 69 6e 65 20 6f 66 20 74 68 65 is a line of the
ea00: 20 66 6f 72 6d 3a 0a 2a 2a 0a 2a 2a 20 20 20 20 form:.**.**
ea10: 72 65 64 69 72 65 63 74 3a 20 2a 20 55 52 4c 0a redirect: * URL.
ea20: 2a 2a 0a 2a 2a 20 54 68 65 6e 20 61 20 72 65 64 **.** Then a red
ea30: 69 72 65 63 74 20 69 73 20 6d 61 64 65 20 74 6f irect is made to
ea40: 20 55 52 4c 20 69 66 20 6e 6f 20 6d 61 74 63 68 URL if no match
ea50: 20 69 73 20 66 6f 75 6e 64 2e 20 20 4f 74 68 65 is found. Othe
ea60: 72 77 69 73 65 20 61 0a 2a 2a 20 76 65 72 79 20 rwise a.** very
ea70: 70 72 69 6d 69 74 69 76 65 20 65 72 72 6f 72 20 primitive error
ea80: 6d 65 73 73 61 67 65 20 69 73 20 72 65 74 75 72 message is retur
ea90: 6e 65 64 2e 0a 2a 2f 0a 73 74 61 74 69 63 20 76 ned..*/.static v
eaa0: 6f 69 64 20 72 65 64 69 72 65 63 74 5f 77 65 62 oid redirect_web
eab0: 5f 70 61 67 65 28 69 6e 74 20 6e 52 65 64 69 72 _page(int nRedir
eac0: 65 63 74 2c 20 63 68 61 72 20 2a 2a 61 7a 52 65 ect, char **azRe
ead0: 64 69 72 65 63 74 29 7b 0a 20 20 69 6e 74 20 69 direct){. int i
eae0: 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 ;
eaf0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a /*
eb00: 20 4c 6f 6f 70 20 63 6f 75 6e 74 65 72 20 2a 2f Loop counter */
eb10: 0a 20 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a . const char *z
eb20: 4e 6f 74 46 6f 75 6e 64 20 3d 20 30 3b 20 20 20 NotFound = 0;
eb30: 20 20 20 20 20 20 2f 2a 20 4e 6f 74 20 66 6f 75 /* Not fou
eb40: 6e 64 20 55 52 4c 20 2a 2f 0a 20 20 63 6f 6e 73 nd URL */. cons
eb50: 74 20 63 68 61 72 20 2a 7a 4e 61 6d 65 20 3d 20 t char *zName =
eb60: 50 28 22 6e 61 6d 65 22 29 3b 0a 20 20 73 65 74 P("name");. set
eb70: 5f 62 61 73 65 5f 75 72 6c 28 30 29 3b 0a 20 20 _base_url(0);.
eb80: 69 66 28 20 7a 4e 61 6d 65 3d 3d 30 20 29 7b 0a if( zName==0 ){.
eb90: 20 20 20 20 7a 4e 61 6d 65 20 3d 20 50 28 22 53 zName = P("S
eba0: 43 52 49 50 54 5f 4e 41 4d 45 22 29 3b 0a 20 20 CRIPT_NAME");.
ebb0: 20 20 69 66 28 20 7a 4e 61 6d 65 20 26 26 20 7a if( zName && z
ebc0: 4e 61 6d 65 5b 30 5d 3d 3d 27 2f 27 20 29 20 7a Name[0]=='/' ) z
ebd0: 4e 61 6d 65 2b 2b 3b 0a 20 20 7d 0a 20 20 69 66 Name++;. }. if
ebe0: 28 20 7a 4e 61 6d 65 20 26 26 20 76 61 6c 69 64 ( zName && valid
ebf0: 61 74 65 31 36 28 7a 4e 61 6d 65 2c 20 73 74 72 ate16(zName, str
ec00: 6c 65 6e 28 7a 4e 61 6d 65 29 29 20 29 7b 0a 20 len(zName)) ){.
ec10: 20 20 20 66 6f 72 28 69 3d 30 3b 20 69 3c 6e 52 for(i=0; i<nR
ec20: 65 64 69 72 65 63 74 3b 20 69 2b 2b 29 7b 0a 20 edirect; i++){.
ec30: 20 20 20 20 20 69 66 28 20 66 6f 73 73 69 6c 5f if( fossil_
ec40: 73 74 72 63 6d 70 28 61 7a 52 65 64 69 72 65 63 strcmp(azRedirec
ec50: 74 5b 69 2a 32 5d 2c 22 2a 22 29 3d 3d 30 20 29 t[i*2],"*")==0 )
ec60: 7b 0a 20 20 20 20 20 20 20 20 7a 4e 6f 74 46 6f {. zNotFo
ec70: 75 6e 64 20 3d 20 61 7a 52 65 64 69 72 65 63 74 und = azRedirect
ec80: 5b 69 2a 32 2b 31 5d 3b 0a 20 20 20 20 20 20 20 [i*2+1];.
ec90: 20 63 6f 6e 74 69 6e 75 65 3b 0a 20 20 20 20 20 continue;.
eca0: 20 7d 0a 20 20 20 20 20 20 64 62 5f 6f 70 65 6e }. db_open
ecb0: 5f 72 65 70 6f 73 69 74 6f 72 79 28 61 7a 52 65 _repository(azRe
ecc0: 64 69 72 65 63 74 5b 69 2a 32 5d 29 3b 0a 20 20 direct[i*2]);.
ecd0: 20 20 20 20 69 66 28 20 64 62 5f 65 78 69 73 74 if( db_exist
ece0: 73 28 22 53 45 4c 45 43 54 20 31 20 46 52 4f 4d s("SELECT 1 FROM
ecf0: 20 62 6c 6f 62 20 57 48 45 52 45 20 75 75 69 64 blob WHERE uuid
ed00: 20 47 4c 4f 42 20 27 25 71 2a 27 22 2c 20 7a 4e GLOB '%q*'", zN
ed10: 61 6d 65 29 20 7c 7c 0a 20 20 20 20 20 20 20 20 ame) ||.
ed20: 20 20 64 62 5f 65 78 69 73 74 73 28 22 53 45 4c db_exists("SEL
ed30: 45 43 54 20 31 20 46 52 4f 4d 20 74 69 63 6b 65 ECT 1 FROM ticke
ed40: 74 20 57 48 45 52 45 20 74 6b 74 5f 75 75 69 64 t WHERE tkt_uuid
ed50: 20 47 4c 4f 42 20 27 25 71 2a 27 22 2c 20 7a 4e GLOB '%q*'", zN
ed60: 61 6d 65 29 20 29 7b 0a 20 20 20 20 20 20 20 20 ame) ){.
ed70: 63 67 69 5f 72 65 64 69 72 65 63 74 66 28 61 7a cgi_redirectf(az
ed80: 52 65 64 69 72 65 63 74 5b 69 2a 32 2b 31 5d 20 Redirect[i*2+1]
ed90: 2f 2a 77 6f 72 6b 73 2d 6c 69 6b 65 3a 22 25 73 /*works-like:"%s
eda0: 22 2a 2f 2c 20 7a 4e 61 6d 65 29 3b 0a 20 20 20 "*/, zName);.
edb0: 20 20 20 20 20 72 65 74 75 72 6e 3b 0a 20 20 20 return;.
edc0: 20 20 20 7d 0a 20 20 20 20 20 20 64 62 5f 63 6c }. db_cl
edd0: 6f 73 65 28 31 29 3b 0a 20 20 20 20 7d 0a 20 20 ose(1);. }.
ede0: 7d 0a 20 20 69 66 28 20 7a 4e 6f 74 46 6f 75 6e }. if( zNotFoun
edf0: 64 20 29 7b 0a 20 20 20 20 63 67 69 5f 72 65 64 d ){. cgi_red
ee00: 69 72 65 63 74 66 28 7a 4e 6f 74 46 6f 75 6e 64 irectf(zNotFound
ee10: 20 2f 2a 77 6f 72 6b 73 2d 6c 69 6b 65 3a 22 25 /*works-like:"%
ee20: 73 22 2a 2f 2c 20 7a 4e 61 6d 65 29 3b 0a 20 20 s"*/, zName);.
ee30: 7d 65 6c 73 65 7b 0a 20 20 20 20 40 20 3c 68 74 }else{. @ <ht
ee40: 6d 6c 3e 0a 20 20 20 20 40 20 3c 68 65 61 64 3e ml>. @ <head>
ee50: 3c 74 69 74 6c 65 3e 4e 6f 20 53 75 63 68 20 4f <title>No Such O
ee60: 62 6a 65 63 74 3c 2f 74 69 74 6c 65 3e 3c 2f 68 bject</title></h
ee70: 65 61 64 3e 0a 20 20 20 20 40 20 3c 62 6f 64 79 ead>. @ <body
ee80: 3e 0a 20 20 20 20 40 20 3c 70 3e 4e 6f 20 73 75 >. @ <p>No su
ee90: 63 68 20 6f 62 6a 65 63 74 3a 20 3c 62 3e 25 68 ch object: <b>%h
eea0: 28 7a 4e 61 6d 65 29 3c 2f 62 3e 3c 2f 70 3e 0a (zName)</b></p>.
eeb0: 20 20 20 20 40 20 3c 2f 62 6f 64 79 3e 0a 20 20 @ </body>.
eec0: 20 20 63 67 69 5f 72 65 70 6c 79 28 29 3b 0a 20 cgi_reply();.
eed0: 20 7d 0a 7d 0a 0a 2f 2a 0a 2a 2a 20 43 4f 4d 4d }.}../*.** COMM
eee0: 41 4e 44 3a 20 63 67 69 2a 0a 2a 2a 0a 2a 2a 20 AND: cgi*.**.**
eef0: 55 73 61 67 65 3a 20 25 66 6f 73 73 69 6c 20 3f Usage: %fossil ?
ef00: 63 67 69 3f 20 46 49 4c 45 0a 2a 2a 0a 2a 2a 20 cgi? FILE.**.**
ef10: 54 68 69 73 20 63 6f 6d 6d 61 6e 64 20 63 61 75 This command cau
ef20: 73 65 73 20 46 6f 73 73 69 6c 20 74 6f 20 67 65 ses Fossil to ge
ef30: 6e 65 72 61 74 65 20 72 65 70 6c 79 20 74 6f 20 nerate reply to
ef40: 61 20 43 47 49 20 72 65 71 75 65 73 74 2e 0a 2a a CGI request..*
ef50: 2a 0a 2a 2a 20 54 68 65 20 46 49 4c 45 20 61 72 *.** The FILE ar
ef60: 67 75 6d 65 6e 74 20 69 73 20 74 68 65 20 6e 61 gument is the na
ef70: 6d 65 20 6f 66 20 61 20 63 6f 6e 74 72 6f 6c 20 me of a control
ef80: 66 69 6c 65 20 74 68 61 74 20 70 72 6f 76 69 64 file that provid
ef90: 65 73 20 46 6f 73 73 69 6c 0a 2a 2a 20 77 69 74 es Fossil.** wit
efa0: 68 20 69 6d 70 6f 72 74 61 6e 74 20 69 6e 66 6f h important info
efb0: 72 6d 61 74 69 6f 6e 20 73 75 63 68 20 61 73 20 rmation such as
efc0: 77 68 65 72 65 20 74 6f 20 66 69 6e 64 20 69 74 where to find it
efd0: 73 20 72 65 70 6f 73 69 74 6f 72 79 2e 20 20 49 s repository. I
efe0: 6e 0a 2a 2a 20 61 20 74 79 70 69 63 61 6c 20 43 n.** a typical C
eff0: 47 49 20 64 65 70 6c 6f 79 6d 65 6e 74 2c 20 46 GI deployment, F
f000: 49 4c 45 20 69 73 20 74 68 65 20 6e 61 6d 65 20 ILE is the name
f010: 6f 66 20 74 68 65 20 43 47 49 20 73 63 72 69 70 of the CGI scrip
f020: 74 20 61 6e 64 20 77 69 6c 6c 0a 2a 2a 20 74 79 t and will.** ty
f030: 70 69 63 61 6c 6c 79 20 6c 6f 6f 6b 20 73 6f 6d pically look som
f040: 65 74 68 69 6e 67 20 6c 69 6b 65 20 74 68 69 73 ething like this
f050: 3a 0a 2a 2a 0a 2a 2a 20 20 20 20 20 20 23 21 2f :.**.** #!/
f060: 75 73 72 2f 62 69 6e 2f 66 6f 73 73 69 6c 0a 2a usr/bin/fossil.*
f070: 2a 20 20 20 20 20 20 72 65 70 6f 73 69 74 6f 72 * repositor
f080: 79 3a 20 2f 68 6f 6d 65 2f 73 6f 6d 65 62 6f 64 y: /home/somebod
f090: 79 2f 70 72 6f 6a 65 63 74 2e 64 62 0a 2a 2a 0a y/project.db.**.
f0a0: 2a 2a 20 54 68 65 20 63 6f 6d 6d 61 6e 64 20 6e ** The command n
f0b0: 61 6d 65 2c 20 22 63 67 69 22 2c 20 6d 61 79 20 ame, "cgi", may
f0c0: 62 65 20 6f 6d 69 74 74 65 64 20 69 66 20 74 68 be omitted if th
f0d0: 65 20 47 41 54 45 57 41 59 5f 49 4e 54 45 52 46 e GATEWAY_INTERF
f0e0: 41 43 45 0a 2a 2a 20 65 6e 76 69 72 6f 6e 6d 65 ACE.** environme
f0f0: 6e 74 20 76 61 72 69 61 62 6c 65 20 69 73 20 73 nt variable is s
f100: 65 74 20 74 6f 20 22 43 47 49 22 2c 20 77 68 69 et to "CGI", whi
f110: 63 68 20 73 68 6f 75 6c 64 20 61 6c 77 61 79 73 ch should always
f120: 20 62 65 20 74 68 65 0a 2a 2a 20 63 61 73 65 20 be the.** case
f130: 66 6f 72 20 43 47 49 20 73 63 72 69 70 74 73 20 for CGI scripts
f140: 72 75 6e 20 62 79 20 61 20 77 65 62 73 65 72 76 run by a webserv
f150: 65 72 2e 20 20 46 6f 73 73 69 6c 20 69 67 6e 6f er. Fossil igno
f160: 72 65 73 20 61 6e 79 20 6c 69 6e 65 73 0a 2a 2a res any lines.**
f170: 20 74 68 61 74 20 62 65 67 69 6e 20 77 69 74 68 that begin with
f180: 20 22 23 22 2e 0a 2a 2a 0a 2a 2a 20 54 68 65 20 "#"..**.** The
f190: 66 6f 6c 6c 6f 77 69 6e 67 20 63 6f 6e 74 72 6f following contro
f1a0: 6c 20 6c 69 6e 65 73 20 61 72 65 20 72 65 63 6f l lines are reco
f1b0: 67 6e 69 7a 65 64 3a 0a 2a 2a 0a 2a 2a 20 20 20 gnized:.**.**
f1c0: 20 72 65 70 6f 73 69 74 6f 72 79 3a 20 50 41 54 repository: PAT
f1d0: 48 20 20 20 20 20 20 20 20 20 4e 61 6d 65 20 6f H Name o
f1e0: 66 20 74 68 65 20 46 6f 73 73 69 6c 20 72 65 70 f the Fossil rep
f1f0: 6f 73 69 74 6f 72 79 0a 2a 2a 0a 2a 2a 20 20 20 ository.**.**
f200: 20 64 69 72 65 63 74 6f 72 79 3a 20 20 50 41 54 directory: PAT
f210: 48 20 20 20 20 20 20 20 20 20 4e 61 6d 65 20 6f H Name o
f220: 66 20 61 20 64 69 72 65 63 74 6f 72 79 20 63 6f f a directory co
f230: 6e 74 61 69 6e 69 6e 67 20 6d 61 6e 79 20 46 6f ntaining many Fo
f240: 73 73 69 6c 0a 2a 2a 20 20 20 20 20 20 20 20 20 ssil.**
f250: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
f260: 20 20 20 20 72 65 70 6f 73 69 74 6f 72 69 65 73 repositories
f270: 20 77 68 6f 73 65 20 6e 61 6d 65 73 20 61 6c 6c whose names all
f280: 20 65 6e 64 20 77 69 74 68 20 22 2e 66 6f 73 73 end with ".foss
f290: 69 6c 22 2e 0a 2a 2a 20 20 20 20 20 20 20 20 20 il"..**
f2a0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
f2b0: 20 20 20 20 54 68 65 72 65 20 73 68 6f 75 6c 64 There should
f2c0: 20 6f 6e 6c 79 20 62 65 20 6f 6e 65 20 6f 66 20 only be one of
f2d0: 22 72 65 70 6f 73 69 74 6f 72 79 3a 22 0a 2a 2a "repository:".**
f2e0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
f2f0: 20 20 20 20 20 20 20 20 20 20 20 20 20 6f 72 20 or
f300: 22 64 69 72 65 63 74 6f 72 79 3a 22 0a 2a 2a 0a "directory:".**.
f310: 2a 2a 20 20 20 20 6e 6f 74 66 6f 75 6e 64 3a 20 ** notfound:
f320: 55 52 4c 20 20 20 20 20 20 20 20 20 20 20 20 57 URL W
f330: 68 65 6e 20 69 6e 20 22 64 69 72 65 63 74 6f 72 hen in "director
f340: 79 3a 22 20 6d 6f 64 65 2c 20 72 65 64 69 72 65 y:" mode, redire
f350: 63 74 20 74 6f 0a 2a 2a 20 20 20 20 20 20 20 20 ct to.**
f360: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
f370: 20 20 20 20 20 55 52 4c 20 69 66 20 6e 6f 20 73 URL if no s
f380: 75 69 74 61 62 6c 65 20 72 65 70 6f 73 69 74 6f uitable reposito
f390: 72 79 20 69 73 20 66 6f 75 6e 64 2e 0a 2a 2a 0a ry is found..**.
f3a0: 2a 2a 20 20 20 20 72 65 70 6f 6c 69 73 74 20 20 ** repolist
f3b0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 57 W
f3c0: 68 65 6e 20 69 6e 20 22 64 69 72 65 63 74 6f 72 hen in "director
f3d0: 79 3a 22 20 6d 6f 64 65 2c 20 64 69 73 70 6c 61 y:" mode, displa
f3e0: 79 20 61 20 70 61 67 65 0a 2a 2a 20 20 20 20 20 y a page.**
f3f0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
f400: 20 20 20 20 20 20 20 20 73 68 6f 77 69 6e 67 20 showing
f410: 61 20 6c 69 73 74 20 6f 66 20 61 76 61 69 6c 61 a list of availa
f420: 62 6c 65 20 72 65 70 6f 73 69 74 6f 72 69 65 73 ble repositories
f430: 20 69 66 0a 2a 2a 20 20 20 20 20 20 20 20 20 20 if.**
f440: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
f450: 20 20 20 74 68 65 20 55 52 4c 20 69 73 20 22 2f the URL is "/
f460: 22 2e 0a 2a 2a 0a 2a 2a 20 20 20 20 6c 6f 63 61 "..**.** loca
f470: 6c 61 75 74 68 20 20 20 20 20 20 20 20 20 20 20 lauth
f480: 20 20 20 20 20 47 72 61 6e 74 20 61 64 6d 69 6e Grant admin
f490: 69 73 74 72 61 74 6f 72 20 70 72 69 76 69 6c 65 istrator privile
f4a0: 67 65 73 20 74 6f 20 63 6f 6e 6e 65 63 74 69 6f ges to connectio
f4b0: 6e 73 0a 2a 2a 20 20 20 20 20 20 20 20 20 20 20 ns.**
f4c0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
f4d0: 20 20 66 72 6f 6d 20 31 32 37 2e 30 2e 30 2e 31 from 127.0.0.1
f4e0: 20 6f 72 20 3a 3a 31 2e 0a 2a 2a 0a 2a 2a 20 20 or ::1..**.**
f4f0: 20 20 73 6b 69 6e 3a 20 4c 41 42 45 4c 20 20 20 skin: LABEL
f500: 20 20 20 20 20 20 20 20 20 20 20 55 73 65 20 74 Use t
f510: 68 65 20 62 75 69 6c 74 2d 69 6e 20 73 6b 69 6e he built-in skin
f520: 20 63 61 6c 6c 65 64 20 4c 41 42 45 4c 20 72 61 called LABEL ra
f530: 74 68 65 72 20 74 68 61 6e 0a 2a 2a 20 20 20 20 ther than.**
f540: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
f550: 20 20 20 20 20 20 20 20 20 74 68 65 20 64 65 66 the def
f560: 61 75 6c 74 2e 20 20 49 66 20 74 68 65 72 65 20 ault. If there
f570: 61 72 65 20 6e 6f 20 73 6b 69 6e 73 20 63 61 6c are no skins cal
f580: 6c 65 64 20 4c 41 42 45 4c 0a 2a 2a 20 20 20 20 led LABEL.**
f590: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
f5a0: 20 20 20 20 20 20 20 20 20 74 68 65 6e 20 74 68 then th
f5b0: 69 73 20 6c 69 6e 65 20 69 73 20 61 20 6e 6f 2d is line is a no-
f5c0: 6f 70 2e 0a 2a 2a 0a 2a 2a 20 20 20 20 66 69 6c op..**.** fil
f5d0: 65 73 3a 20 47 4c 4f 42 4c 49 53 54 20 20 20 20 es: GLOBLIST
f5e0: 20 20 20 20 20 20 47 4c 4f 42 4c 49 53 54 20 69 GLOBLIST i
f5f0: 73 20 61 20 63 6f 6d 6d 61 2d 73 65 70 61 72 61 s a comma-separa
f600: 74 65 64 20 6c 69 73 74 20 6f 66 20 47 4c 4f 42 ted list of GLOB
f610: 0a 2a 2a 20 20 20 20 20 20 20 20 20 20 20 20 20 .**
f620: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
f630: 70 61 74 74 65 72 6e 73 20 74 68 61 74 20 73 70 patterns that sp
f640: 65 63 69 66 79 20 66 69 6c 65 73 20 74 68 61 74 ecify files that
f650: 20 63 61 6e 20 62 65 0a 2a 2a 20 20 20 20 20 20 can be.**
f660: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
f670: 20 20 20 20 20 20 20 72 65 74 75 72 6e 65 64 20 returned
f680: 76 65 72 62 61 74 69 6d 2e 20 20 54 68 69 73 20 verbatim. This
f690: 66 65 61 74 75 72 65 20 61 6c 6c 6f 77 73 20 46 feature allows F
f6a0: 6f 73 73 69 6c 0a 2a 2a 20 20 20 20 20 20 20 20 ossil.**
f6b0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
f6c0: 20 20 20 20 20 74 6f 20 61 63 74 20 61 73 20 61 to act as a
f6d0: 20 77 65 62 20 73 65 72 76 65 72 20 72 65 74 75 web server retu
f6e0: 72 6e 69 6e 67 20 73 74 61 74 69 63 0a 2a 2a 20 rning static.**
f6f0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
f700: 20 20 20 20 20 20 20 20 20 20 20 20 63 6f 6e 74 cont
f710: 65 6e 74 2e 0a 2a 2a 0a 2a 2a 20 20 20 20 73 65 ent..**.** se
f720: 74 65 6e 76 3a 20 4e 41 4d 45 20 56 41 4c 55 45 tenv: NAME VALUE
f730: 20 20 20 20 20 20 20 53 65 74 20 65 6e 76 69 72 Set envir
f740: 6f 6e 6d 65 6e 74 20 76 61 72 69 61 62 6c 65 20 onment variable
f750: 4e 41 4d 45 20 74 6f 20 56 41 4c 55 45 2e 20 20 NAME to VALUE.
f760: 4f 72 0a 2a 2a 20 20 20 20 20 20 20 20 20 20 20 Or.**
f770: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
f780: 20 20 69 66 20 56 41 4c 55 45 20 69 73 20 6f 6d if VALUE is om
f790: 69 74 74 65 64 2c 20 75 6e 73 65 74 20 4e 41 4d itted, unset NAM
f7a0: 45 2e 0a 2a 2a 0a 2a 2a 20 20 20 20 48 4f 4d 45 E..**.** HOME
f7b0: 3a 20 50 41 54 48 20 20 20 20 20 20 20 20 20 20 : PATH
f7c0: 20 20 20 20 20 53 68 6f 72 74 68 61 6e 64 20 66 Shorthand f
f7d0: 6f 72 20 22 73 65 74 65 6e 76 3a 20 48 4f 4d 45 or "setenv: HOME
f7e0: 20 50 41 54 48 22 0a 2a 2a 0a 2a 2a 20 20 20 20 PATH".**.**
f7f0: 64 65 62 75 67 3a 20 46 49 4c 45 20 20 20 20 20 debug: FILE
f800: 20 20 20 20 20 20 20 20 20 43 61 75 73 69 6e 67 Causing
f810: 20 64 65 62 75 67 67 69 6e 67 20 69 6e 66 6f 72 debugging infor
f820: 6d 61 74 69 6f 6e 20 74 6f 20 62 65 20 77 72 69 mation to be wri
f830: 74 74 65 6e 0a 2a 2a 20 20 20 20 20 20 20 20 20 tten.**
f840: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
f850: 20 20 20 20 69 6e 74 6f 20 46 49 4c 45 2e 0a 2a into FILE..*
f860: 2a 0a 2a 2a 20 20 20 20 65 72 72 6f 72 6c 6f 67 *.** errorlog
f870: 3a 20 46 49 4c 45 20 20 20 20 20 20 20 20 20 20 : FILE
f880: 20 57 61 72 6e 69 6e 67 73 2c 20 65 72 72 6f 72 Warnings, error
f890: 73 2c 20 61 6e 64 20 70 61 6e 69 63 73 20 77 72 s, and panics wr
f8a0: 69 74 74 65 6e 20 74 6f 20 46 49 4c 45 2e 0a 2a itten to FILE..*
f8b0: 2a 0a 2a 2a 20 20 20 20 72 65 64 69 72 65 63 74 *.** redirect
f8c0: 3a 20 52 45 50 4f 20 55 52 4c 20 20 20 20 20 20 : REPO URL
f8d0: 20 45 78 74 72 61 63 74 20 74 68 65 20 22 6e 61 Extract the "na
f8e0: 6d 65 22 20 71 75 65 72 79 20 70 61 72 61 6d 65 me" query parame
f8f0: 74 65 72 20 61 6e 64 20 73 65 61 72 63 68 0a 2a ter and search.*
f900: 2a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 *
f910: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 52 45 RE
f920: 50 4f 20 66 6f 72 20 61 20 63 68 65 63 6b 2d 69 PO for a check-i
f930: 6e 20 6f 72 20 74 69 63 6b 65 74 20 74 68 61 74 n or ticket that
f940: 20 6d 61 74 63 68 65 73 20 74 68 65 0a 2a 2a 20 matches the.**
f950: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
f960: 20 20 20 20 20 20 20 20 20 20 20 20 76 61 6c 75 valu
f970: 65 20 6f 66 20 22 6e 61 6d 65 22 2c 20 74 68 65 e of "name", the
f980: 6e 20 72 65 64 69 72 65 63 74 20 74 6f 20 55 52 n redirect to UR
f990: 4c 2e 20 20 54 68 65 72 65 0a 2a 2a 20 20 20 20 L. There.**
f9a0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
f9b0: 20 20 20 20 20 20 20 20 20 63 61 6e 20 62 65 20 can be
f9c0: 6d 75 6c 74 69 70 6c 65 20 22 72 65 64 69 72 65 multiple "redire
f9d0: 63 74 3a 22 20 6c 69 6e 65 73 20 74 68 61 74 20 ct:" lines that
f9e0: 61 72 65 0a 2a 2a 20 20 20 20 20 20 20 20 20 20 are.**
f9f0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
fa00: 20 20 20 70 72 6f 63 65 73 73 65 64 20 69 6e 20 processed in
fa10: 6f 72 64 65 72 2e 20 20 49 66 20 74 68 65 20 52 order. If the R
fa20: 45 50 4f 20 69 73 20 22 2a 22 2c 20 74 68 65 6e EPO is "*", then
fa30: 0a 2a 2a 20 20 20 20 20 20 20 20 20 20 20 20 20 .**
fa40: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
fa50: 61 6e 20 75 6e 63 6f 6e 64 69 74 69 6f 6e 61 6c an unconditional
fa60: 20 72 65 64 69 72 65 63 74 20 74 6f 20 55 52 4c redirect to URL
fa70: 20 69 73 20 74 61 6b 65 6e 2e 0a 2a 2a 0a 2a 2a is taken..**.**
fa80: 20 4d 6f 73 74 20 43 47 49 20 66 69 6c 65 73 20 Most CGI files
fa90: 63 6f 6e 74 61 69 6e 20 6f 6e 6c 79 20 61 20 22 contain only a "
faa0: 72 65 70 6f 73 69 74 6f 72 79 3a 22 20 6c 69 6e repository:" lin
fab0: 65 2e 20 20 49 74 20 69 73 20 75 6e 63 6f 6d 6d e. It is uncomm
fac0: 6f 6e 20 74 6f 0a 2a 2a 20 75 73 65 20 61 6e 79 on to.** use any
fad0: 20 6f 74 68 65 72 20 6f 70 74 69 6f 6e 2e 0a 2a other option..*
fae0: 2a 0a 2a 2a 20 53 65 65 20 61 6c 73 6f 3a 20 68 *.** See also: h
faf0: 74 74 70 2c 20 73 65 72 76 65 72 2c 20 77 69 6e ttp, server, win
fb00: 73 72 76 0a 2a 2f 0a 76 6f 69 64 20 63 6d 64 5f srv.*/.void cmd_
fb10: 63 67 69 28 76 6f 69 64 29 7b 0a 20 20 63 6f 6e cgi(void){. con
fb20: 73 74 20 63 68 61 72 20 2a 7a 46 69 6c 65 3b 0a st char *zFile;.
fb30: 20 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a 4e const char *zN
fb40: 6f 74 46 6f 75 6e 64 20 3d 20 30 3b 0a 20 20 63 otFound = 0;. c
fb50: 68 61 72 20 2a 2a 61 7a 52 65 64 69 72 65 63 74 har **azRedirect
fb60: 20 3d 20 30 3b 20 20 20 20 20 20 20 20 20 20 20 = 0;
fb70: 20 20 2f 2a 20 4c 69 73 74 20 6f 66 20 72 65 70 /* List of rep
fb80: 6f 73 69 74 6f 72 69 65 73 20 74 6f 20 72 65 64 ositories to red
fb90: 69 72 65 63 74 20 74 6f 20 2a 2f 0a 20 20 69 6e irect to */. in
fba0: 74 20 6e 52 65 64 69 72 65 63 74 20 3d 20 30 3b t nRedirect = 0;
fbb0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
fbc0: 20 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 20 65 6e /* Number of en
fbd0: 74 72 69 65 73 20 69 6e 20 61 7a 52 65 64 69 72 tries in azRedir
fbe0: 65 63 74 20 2a 2f 0a 20 20 47 6c 6f 62 20 2a 70 ect */. Glob *p
fbf0: 46 69 6c 65 47 6c 6f 62 20 3d 20 30 3b 20 20 20 FileGlob = 0;
fc00: 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 50 /* P
fc10: 61 74 74 65 72 6e 20 66 6f 72 20 66 69 6c 65 73 attern for files
fc20: 20 2a 2f 0a 20 20 69 6e 74 20 61 6c 6c 6f 77 52 */. int allowR
fc30: 65 70 6f 4c 69 73 74 20 3d 20 30 3b 20 20 20 20 epoList = 0;
fc40: 20 20 20 20 20 20 20 20 20 2f 2a 20 41 6c 6c 6f /* Allo
fc50: 77 20 6c 69 73 74 73 20 6f 66 20 72 65 70 6f 73 w lists of repos
fc60: 69 74 6f 72 79 20 66 69 6c 65 73 20 2a 2f 0a 20 itory files */.
fc70: 20 42 6c 6f 62 20 63 6f 6e 66 69 67 2c 20 6c 69 Blob config, li
fc80: 6e 65 2c 20 6b 65 79 2c 20 76 61 6c 75 65 2c 20 ne, key, value,
fc90: 76 61 6c 75 65 32 3b 0a 20 20 69 66 28 20 67 2e value2;. if( g.
fca0: 61 72 67 63 3d 3d 33 20 26 26 20 66 6f 73 73 69 argc==3 && fossi
fcb0: 6c 5f 73 74 72 63 6d 70 28 67 2e 61 72 67 76 5b l_strcmp(g.argv[
fcc0: 31 5d 2c 22 63 67 69 22 29 3d 3d 30 20 29 7b 0a 1],"cgi")==0 ){.
fcd0: 20 20 20 20 7a 46 69 6c 65 20 3d 20 67 2e 61 72 zFile = g.ar
fce0: 67 76 5b 32 5d 3b 0a 20 20 7d 65 6c 73 65 7b 0a gv[2];. }else{.
fcf0: 20 20 20 20 7a 46 69 6c 65 20 3d 20 67 2e 61 72 zFile = g.ar
fd00: 67 76 5b 31 5d 3b 0a 20 20 7d 0a 20 20 67 2e 68 gv[1];. }. g.h
fd10: 74 74 70 4f 75 74 20 3d 20 73 74 64 6f 75 74 3b ttpOut = stdout;
fd20: 0a 20 20 67 2e 68 74 74 70 49 6e 20 3d 20 73 74 . g.httpIn = st
fd30: 64 69 6e 3b 0a 20 20 66 6f 73 73 69 6c 5f 62 69 din;. fossil_bi
fd40: 6e 61 72 79 5f 6d 6f 64 65 28 67 2e 68 74 74 70 nary_mode(g.http
fd50: 4f 75 74 29 3b 0a 20 20 66 6f 73 73 69 6c 5f 62 Out);. fossil_b
fd60: 69 6e 61 72 79 5f 6d 6f 64 65 28 67 2e 68 74 74 inary_mode(g.htt
fd70: 70 49 6e 29 3b 0a 20 20 67 2e 63 67 69 4f 75 74 pIn);. g.cgiOut
fd80: 70 75 74 20 3d 20 31 3b 0a 20 20 62 6c 6f 62 5f put = 1;. blob_
fd90: 72 65 61 64 5f 66 72 6f 6d 5f 66 69 6c 65 28 26 read_from_file(&
fda0: 63 6f 6e 66 69 67 2c 20 7a 46 69 6c 65 29 3b 0a config, zFile);.
fdb0: 20 20 77 68 69 6c 65 28 20 62 6c 6f 62 5f 6c 69 while( blob_li
fdc0: 6e 65 28 26 63 6f 6e 66 69 67 2c 20 26 6c 69 6e ne(&config, &lin
fdd0: 65 29 20 29 7b 0a 20 20 20 20 69 66 28 20 21 62 e) ){. if( !b
fde0: 6c 6f 62 5f 74 6f 6b 65 6e 28 26 6c 69 6e 65 2c lob_token(&line,
fdf0: 20 26 6b 65 79 29 20 29 20 63 6f 6e 74 69 6e 75 &key) ) continu
fe00: 65 3b 0a 20 20 20 20 69 66 28 20 62 6c 6f 62 5f e;. if( blob_
fe10: 62 75 66 66 65 72 28 26 6b 65 79 29 5b 30 5d 3d buffer(&key)[0]=
fe20: 3d 27 23 27 20 29 20 63 6f 6e 74 69 6e 75 65 3b ='#' ) continue;
fe30: 0a 20 20 20 20 69 66 28 20 62 6c 6f 62 5f 65 71 . if( blob_eq
fe40: 28 26 6b 65 79 2c 20 22 72 65 70 6f 73 69 74 6f (&key, "reposito
fe50: 72 79 3a 22 29 20 26 26 20 62 6c 6f 62 5f 74 61 ry:") && blob_ta
fe60: 69 6c 28 26 6c 69 6e 65 2c 20 26 76 61 6c 75 65 il(&line, &value
fe70: 29 20 29 7b 0a 20 20 20 20 20 20 2f 2a 20 72 65 ) ){. /* re
fe80: 70 6f 73 69 74 6f 72 79 3a 20 46 49 4c 45 4e 41 pository: FILENA
fe90: 4d 45 0a 20 20 20 20 20 20 2a 2a 0a 20 20 20 20 ME. **.
fea0: 20 20 2a 2a 20 54 68 65 20 6e 61 6d 65 20 6f 66 ** The name of
feb0: 20 74 68 65 20 46 6f 73 73 69 6c 20 72 65 70 6f the Fossil repo
fec0: 73 69 74 6f 72 79 20 74 6f 20 62 65 20 73 65 72 sitory to be ser
fed0: 76 65 64 20 76 69 61 20 43 47 49 2e 20 20 4d 6f ved via CGI. Mo
fee0: 73 74 0a 20 20 20 20 20 20 2a 2a 20 66 6f 73 73 st. ** foss
fef0: 69 6c 20 43 47 49 20 73 63 72 69 70 74 73 20 68 il CGI scripts h
ff00: 61 76 65 20 61 20 73 69 6e 67 6c 65 20 6e 6f 6e ave a single non
ff10: 2d 63 6f 6d 6d 65 6e 74 20 6c 69 6e 65 20 74 68 -comment line th
ff20: 61 74 20 63 6f 6e 74 61 69 6e 73 0a 20 20 20 20 at contains.
ff30: 20 20 2a 2a 20 74 68 69 73 20 6f 6e 65 20 65 6e ** this one en
ff40: 74 72 79 2e 0a 20 20 20 20 20 20 2a 2f 0a 20 20 try.. */.
ff50: 20 20 20 20 62 6c 6f 62 5f 74 72 69 6d 28 26 76 blob_trim(&v
ff60: 61 6c 75 65 29 3b 0a 20 20 20 20 20 20 64 62 5f alue);. db_
ff70: 6f 70 65 6e 5f 72 65 70 6f 73 69 74 6f 72 79 28 open_repository(
ff80: 62 6c 6f 62 5f 73 74 72 28 26 76 61 6c 75 65 29 blob_str(&value)
ff90: 29 3b 0a 20 20 20 20 20 20 62 6c 6f 62 5f 72 65 );. blob_re
ffa0: 73 65 74 28 26 76 61 6c 75 65 29 3b 0a 20 20 20 set(&value);.
ffb0: 20 20 20 63 6f 6e 74 69 6e 75 65 3b 0a 20 20 20 continue;.
ffc0: 20 7d 0a 20 20 20 20 69 66 28 20 62 6c 6f 62 5f }. if( blob_
ffd0: 65 71 28 26 6b 65 79 2c 20 22 64 69 72 65 63 74 eq(&key, "direct
ffe0: 6f 72 79 3a 22 29 20 26 26 20 62 6c 6f 62 5f 74 ory:") && blob_t
fff0: 6f 6b 65 6e 28 26 6c 69 6e 65 2c 20 26 76 61 6c oken(&line, &val
10000 75 65 29 20 29 7b 0a 20 20 20 20 20 20 2f 2a 20 ue) ){. /*
10010 64 69 72 65 63 74 6f 72 79 3a 20 44 49 52 45 43 directory: DIREC
10020 54 4f 52 59 0a 20 20 20 20 20 20 2a 2a 0a 20 20 TORY. **.
10030 20 20 20 20 2a 2a 20 49 66 20 72 65 70 6f 73 69 ** If reposi
10040 74 6f 72 79 3a 20 69 73 20 6f 6d 69 74 74 65 64 tory: is omitted
10050 2c 20 74 68 65 6e 20 74 65 72 6d 73 20 6f 66 20 , then terms of
10060 74 68 65 20 50 41 54 48 5f 49 4e 46 4f 20 63 67 the PATH_INFO cg
10070 69 20 70 61 72 61 6d 65 74 65 72 0a 20 20 20 20 i parameter.
10080 20 20 2a 2a 20 61 72 65 20 61 70 70 65 6e 64 65 ** are appende
10090 64 20 74 6f 20 44 49 52 45 43 54 4f 52 59 20 6c d to DIRECTORY l
100a0 6f 6f 6b 69 6e 67 20 66 6f 72 20 61 20 72 65 70 ooking for a rep
100b0 6f 73 69 74 6f 72 79 20 28 77 68 6f 73 65 20 6e ository (whose n
100c0 61 6d 65 20 65 6e 64 73 0a 20 20 20 20 20 20 2a ame ends. *
100d0 2a 20 69 6e 20 22 2e 66 6f 73 73 69 6c 22 29 20 * in ".fossil")
100e0 6f 72 20 61 20 66 69 6c 65 20 69 6e 20 22 66 69 or a file in "fi
100f0 6c 65 73 3a 22 2e 0a 20 20 20 20 20 20 2a 2f 0a les:".. */.
10100 20 20 20 20 20 20 64 62 5f 63 6c 6f 73 65 28 31 db_close(1
10110 29 3b 0a 20 20 20 20 20 20 67 2e 7a 52 65 70 6f );. g.zRepo
10120 73 69 74 6f 72 79 4e 61 6d 65 20 3d 20 6d 70 72 sitoryName = mpr
10130 69 6e 74 66 28 22 25 73 22 2c 20 62 6c 6f 62 5f intf("%s", blob_
10140 73 74 72 28 26 76 61 6c 75 65 29 29 3b 0a 20 20 str(&value));.
10150 20 20 20 20 62 6c 6f 62 5f 72 65 73 65 74 28 26 blob_reset(&
10160 76 61 6c 75 65 29 3b 0a 20 20 20 20 20 20 63 6f value);. co
10170 6e 74 69 6e 75 65 3b 0a 20 20 20 20 7d 0a 20 20 ntinue;. }.
10180 20 20 69 66 28 20 62 6c 6f 62 5f 65 71 28 26 6b if( blob_eq(&k
10190 65 79 2c 20 22 6e 6f 74 66 6f 75 6e 64 3a 22 29 ey, "notfound:")
101a0 20 26 26 20 62 6c 6f 62 5f 74 6f 6b 65 6e 28 26 && blob_token(&
101b0 6c 69 6e 65 2c 20 26 76 61 6c 75 65 29 20 29 7b line, &value) ){
101c0 0a 20 20 20 20 20 20 2f 2a 20 6e 6f 74 66 6f 75 . /* notfou
101d0 6e 64 3a 20 55 52 4c 0a 20 20 20 20 20 20 2a 2a nd: URL. **
101e0 0a 20 20 20 20 20 20 2a 2a 20 49 66 20 75 73 69 . ** If usi
101f0 6e 67 20 64 69 72 65 63 74 6f 72 79 3a 20 61 6e ng directory: an
10200 64 20 6e 6f 20 73 75 69 74 61 62 6c 65 20 72 65 d no suitable re
10210 70 6f 73 69 74 6f 72 79 20 6f 72 20 66 69 6c 65 pository or file
10220 20 69 73 20 66 6f 75 6e 64 2c 0a 20 20 20 20 20 is found,.
10230 20 2a 2a 20 74 68 65 6e 20 72 65 64 69 72 65 63 ** then redirec
10240 74 20 74 6f 20 55 52 4c 2e 0a 20 20 20 20 20 20 t to URL..
10250 2a 2f 0a 20 20 20 20 20 20 7a 4e 6f 74 46 6f 75 */. zNotFou
10260 6e 64 20 3d 20 6d 70 72 69 6e 74 66 28 22 25 73 nd = mprintf("%s
10270 22 2c 20 62 6c 6f 62 5f 73 74 72 28 26 76 61 6c ", blob_str(&val
10280 75 65 29 29 3b 0a 20 20 20 20 20 20 62 6c 6f 62 ue));. blob
10290 5f 72 65 73 65 74 28 26 76 61 6c 75 65 29 3b 0a _reset(&value);.
102a0 20 20 20 20 20 20 63 6f 6e 74 69 6e 75 65 3b 0a continue;.
102b0 20 20 20 20 7d 0a 20 20 20 20 69 66 28 20 62 6c }. if( bl
102c0 6f 62 5f 65 71 28 26 6b 65 79 2c 20 22 6c 6f 63 ob_eq(&key, "loc
102d0 61 6c 61 75 74 68 22 29 20 29 7b 0a 20 20 20 20 alauth") ){.
102e0 20 20 2f 2a 20 6c 6f 63 61 6c 61 75 74 68 0a 20 /* localauth.
102f0 20 20 20 20 20 2a 2a 0a 20 20 20 20 20 20 2a 2a **. **
10300 20 47 72 61 6e 74 20 22 61 64 6d 69 6e 69 73 74 Grant "administ
10310 72 61 74 6f 72 22 20 70 72 69 76 69 6c 65 67 65 rator" privilege
10320 73 20 74 6f 20 75 73 65 72 73 20 63 6f 6e 6e 65 s to users conne
10330 63 74 69 6e 67 20 77 69 74 68 20 48 54 54 50 0a cting with HTTP.
10340 20 20 20 20 20 20 2a 2a 20 66 72 6f 6d 20 49 50 ** from IP
10350 20 61 64 64 72 65 73 73 20 31 32 37 2e 30 2e 30 address 127.0.0
10360 2e 31 2e 20 20 44 6f 20 6e 6f 74 20 62 6f 74 68 .1. Do not both
10370 65 72 20 63 68 65 63 6b 69 6e 67 20 63 72 65 64 er checking cred
10380 65 6e 74 69 61 6c 73 2e 0a 20 20 20 20 20 20 2a entials.. *
10390 2f 0a 20 20 20 20 20 20 67 2e 75 73 65 4c 6f 63 /. g.useLoc
103a0 61 6c 61 75 74 68 20 3d 20 31 3b 0a 20 20 20 20 alauth = 1;.
103b0 20 20 63 6f 6e 74 69 6e 75 65 3b 0a 20 20 20 20 continue;.
103c0 7d 0a 20 20 20 20 69 66 28 20 62 6c 6f 62 5f 65 }. if( blob_e
103d0 71 28 26 6b 65 79 2c 20 22 72 65 70 6f 6c 69 73 q(&key, "repolis
103e0 74 22 29 20 29 7b 0a 20 20 20 20 20 20 2f 2a 20 t") ){. /*
103f0 72 65 70 6f 6c 69 73 74 0a 20 20 20 20 20 20 2a repolist. *
10400 2a 0a 20 20 20 20 20 20 2a 2a 20 49 66 20 75 73 *. ** If us
10410 69 6e 67 20 22 64 69 72 65 63 74 6f 72 79 3a 22 ing "directory:"
10420 20 61 6e 64 20 74 68 65 20 55 52 4c 20 69 73 20 and the URL is
10430 22 2f 22 20 74 68 65 6e 20 67 65 6e 65 72 61 74 "/" then generat
10440 65 20 61 20 70 61 67 65 0a 20 20 20 20 20 20 2a e a page. *
10450 2a 20 73 68 6f 77 69 6e 67 20 61 20 6c 69 73 74 * showing a list
10460 20 6f 66 20 61 76 61 69 6c 61 62 6c 65 20 72 65 of available re
10470 70 6f 73 69 74 6f 72 69 65 73 2e 0a 20 20 20 20 positories..
10480 20 20 2a 2f 0a 20 20 20 20 20 20 61 6c 6c 6f 77 */. allow
10490 52 65 70 6f 4c 69 73 74 20 3d 20 31 3b 0a 20 20 RepoList = 1;.
104a0 20 20 20 20 63 6f 6e 74 69 6e 75 65 3b 0a 20 20 continue;.
104b0 20 20 7d 0a 20 20 20 20 69 66 28 20 62 6c 6f 62 }. if( blob
104c0 5f 65 71 28 26 6b 65 79 2c 20 22 72 65 64 69 72 _eq(&key, "redir
104d0 65 63 74 3a 22 29 20 26 26 20 62 6c 6f 62 5f 74 ect:") && blob_t
104e0 6f 6b 65 6e 28 26 6c 69 6e 65 2c 20 26 76 61 6c oken(&line, &val
104f0 75 65 29 0a 20 20 20 20 20 20 20 20 20 20 20 20 ue).
10500 26 26 20 62 6c 6f 62 5f 74 6f 6b 65 6e 28 26 6c && blob_token(&l
10510 69 6e 65 2c 20 26 76 61 6c 75 65 32 29 20 29 7b ine, &value2) ){
10520 0a 20 20 20 20 20 20 2f 2a 20 53 65 65 20 74 68 . /* See th
10530 65 20 68 65 61 64 65 72 20 63 6f 6d 6d 65 6e 74 e header comment
10540 20 6f 6e 20 74 68 65 20 72 65 64 69 72 65 63 74 on the redirect
10550 5f 77 65 62 5f 70 61 67 65 28 29 20 66 75 6e 63 _web_page() func
10560 74 69 6f 6e 0a 20 20 20 20 20 20 2a 2a 20 61 62 tion. ** ab
10570 6f 76 65 20 66 6f 72 20 64 65 74 61 69 6c 73 2e ove for details.
10580 20 2a 2f 0a 20 20 20 20 20 20 6e 52 65 64 69 72 */. nRedir
10590 65 63 74 2b 2b 3b 0a 20 20 20 20 20 20 61 7a 52 ect++;. azR
105a0 65 64 69 72 65 63 74 20 3d 20 66 6f 73 73 69 6c edirect = fossil
105b0 5f 72 65 61 6c 6c 6f 63 28 61 7a 52 65 64 69 72 _realloc(azRedir
105c0 65 63 74 2c 20 32 2a 6e 52 65 64 69 72 65 63 74 ect, 2*nRedirect
105d0 2a 73 69 7a 65 6f 66 28 63 68 61 72 2a 29 29 3b *sizeof(char*));
105e0 0a 20 20 20 20 20 20 61 7a 52 65 64 69 72 65 63 . azRedirec
105f0 74 5b 6e 52 65 64 69 72 65 63 74 2a 32 2d 32 5d t[nRedirect*2-2]
10600 20 3d 20 6d 70 72 69 6e 74 66 28 22 25 73 22 2c = mprintf("%s",
10610 20 62 6c 6f 62 5f 73 74 72 28 26 76 61 6c 75 65 blob_str(&value
10620 29 29 3b 0a 20 20 20 20 20 20 61 7a 52 65 64 69 ));. azRedi
10630 72 65 63 74 5b 6e 52 65 64 69 72 65 63 74 2a 32 rect[nRedirect*2
10640 2d 31 5d 20 3d 20 6d 70 72 69 6e 74 66 28 22 25 -1] = mprintf("%
10650 73 22 2c 20 62 6c 6f 62 5f 73 74 72 28 26 76 61 s", blob_str(&va
10660 6c 75 65 32 29 29 3b 0a 20 20 20 20 20 20 62 6c lue2));. bl
10670 6f 62 5f 72 65 73 65 74 28 26 76 61 6c 75 65 29 ob_reset(&value)
10680 3b 0a 20 20 20 20 20 20 62 6c 6f 62 5f 72 65 73 ;. blob_res
10690 65 74 28 26 76 61 6c 75 65 32 29 3b 0a 20 20 20 et(&value2);.
106a0 20 20 20 63 6f 6e 74 69 6e 75 65 3b 0a 20 20 20 continue;.
106b0 20 7d 0a 20 20 20 20 69 66 28 20 62 6c 6f 62 5f }. if( blob_
106c0 65 71 28 26 6b 65 79 2c 20 22 66 69 6c 65 73 3a eq(&key, "files:
106d0 22 29 20 26 26 20 62 6c 6f 62 5f 74 6f 6b 65 6e ") && blob_token
106e0 28 26 6c 69 6e 65 2c 20 26 76 61 6c 75 65 29 20 (&line, &value)
106f0 29 7b 0a 20 20 20 20 20 20 2f 2a 20 66 69 6c 65 ){. /* file
10700 73 3a 20 47 4c 4f 42 4c 49 53 54 0a 20 20 20 20 s: GLOBLIST.
10710 20 20 2a 2a 0a 20 20 20 20 20 20 2a 2a 20 47 4c **. ** GL
10720 4f 42 4c 49 53 54 20 69 73 20 61 20 63 6f 6d 6d OBLIST is a comm
10730 61 2d 73 65 70 61 72 61 74 65 64 20 6c 69 73 74 a-separated list
10740 20 6f 66 20 66 69 6c 65 6e 61 6d 65 20 67 6c 6f of filename glo
10750 62 73 2e 20 20 46 6f 72 0a 20 20 20 20 20 20 2a bs. For. *
10760 2a 20 65 78 61 6d 70 6c 65 3a 20 20 2a 2e 68 74 * example: *.ht
10770 6d 6c 2c 2a 2e 63 73 73 2c 2a 2e 6a 73 0a 20 20 ml,*.css,*.js.
10780 20 20 20 20 2a 2a 0a 20 20 20 20 20 20 2a 2a 20 **. **
10790 49 66 20 74 68 65 20 72 65 70 6f 73 69 74 6f 72 If the repositor
107a0 79 3a 20 6c 69 6e 65 20 69 73 20 6f 6d 69 74 74 y: line is omitt
107b0 65 64 20 61 6e 64 20 74 68 65 6e 20 50 41 54 48 ed and then PATH
107c0 5f 49 4e 46 4f 20 69 73 20 73 65 61 72 63 68 65 _INFO is searche
107d0 64 0a 20 20 20 20 20 20 2a 2a 20 66 6f 72 20 66 d. ** for f
107e0 69 6c 65 73 20 74 68 61 74 20 6d 61 74 63 68 20 iles that match
107f0 61 6e 79 20 6f 66 20 74 68 65 73 65 20 47 4c 4f any of these GLO
10800 42 73 20 61 6e 64 20 69 66 20 61 6e 79 20 73 75 Bs and if any su
10810 63 68 20 66 69 6c 65 20 69 73 0a 20 20 20 20 20 ch file is.
10820 20 2a 2a 20 66 6f 75 6e 64 20 69 74 20 69 73 20 ** found it is
10830 72 65 74 75 72 6e 65 64 20 76 65 72 62 61 74 69 returned verbati
10840 6d 2e 20 20 54 68 69 73 20 66 65 61 74 75 72 65 m. This feature
10850 20 61 6c 6c 6f 77 73 20 22 66 6f 73 73 69 6c 20 allows "fossil
10860 73 65 72 76 65 72 22 0a 20 20 20 20 20 20 2a 2a server". **
10870 20 74 6f 20 66 75 6e 63 74 69 6f 6e 20 61 73 20 to function as
10880 61 20 70 72 69 6d 69 74 69 76 65 20 77 65 62 2d a primitive web-
10890 73 65 72 76 65 72 20 64 65 6c 69 76 65 72 69 6e server deliverin
108a0 67 20 61 72 62 69 74 72 61 72 79 20 63 6f 6e 74 g arbitrary cont
108b0 65 6e 74 2e 0a 20 20 20 20 20 20 2a 2f 0a 20 20 ent.. */.
108c0 20 20 20 20 70 46 69 6c 65 47 6c 6f 62 20 3d 20 pFileGlob =
108d0 67 6c 6f 62 5f 63 72 65 61 74 65 28 62 6c 6f 62 glob_create(blob
108e0 5f 73 74 72 28 26 76 61 6c 75 65 29 29 3b 0a 20 _str(&value));.
108f0 20 20 20 20 20 62 6c 6f 62 5f 72 65 73 65 74 28 blob_reset(
10900 26 76 61 6c 75 65 29 3b 0a 20 20 20 20 20 20 63 &value);. c
10910 6f 6e 74 69 6e 75 65 3b 0a 20 20 20 20 7d 0a 20 ontinue;. }.
10920 20 20 20 69 66 28 20 62 6c 6f 62 5f 65 71 28 26 if( blob_eq(&
10930 6b 65 79 2c 20 22 73 65 74 65 6e 76 3a 22 29 20 key, "setenv:")
10940 26 26 20 62 6c 6f 62 5f 74 6f 6b 65 6e 28 26 6c && blob_token(&l
10950 69 6e 65 2c 20 26 76 61 6c 75 65 29 20 29 7b 0a ine, &value) ){.
10960 20 20 20 20 20 20 2f 2a 20 73 65 74 65 6e 76 3a /* setenv:
10970 20 4e 41 4d 45 20 56 41 4c 55 45 0a 20 20 20 20 NAME VALUE.
10980 20 20 2a 2a 20 73 65 74 65 6e 76 3a 20 4e 41 4d ** setenv: NAM
10990 45 0a 20 20 20 20 20 20 2a 2a 0a 20 20 20 20 20 E. **.
109a0 20 2a 2a 20 53 65 74 73 20 65 6e 76 69 72 6f 6e ** Sets environ
109b0 6d 65 6e 74 20 76 61 72 69 61 62 6c 65 20 4e 41 ment variable NA
109c0 4d 45 20 74 6f 20 56 41 4c 55 45 2e 20 20 49 66 ME to VALUE. If
109d0 20 56 41 4c 55 45 20 69 73 20 6f 6d 69 74 74 65 VALUE is omitte
109e0 64 2c 20 74 68 65 6e 0a 20 20 20 20 20 20 2a 2a d, then. **
109f0 20 74 68 65 20 65 6e 76 69 72 6f 6e 6d 65 6e 74 the environment
10a00 20 76 61 72 69 61 62 6c 65 20 69 73 20 75 6e 73 variable is uns
10a10 65 74 2e 0a 20 20 20 20 20 20 2a 2f 0a 20 20 20 et.. */.
10a20 20 20 20 62 6c 6f 62 5f 74 6f 6b 65 6e 28 26 6c blob_token(&l
10a30 69 6e 65 2c 26 76 61 6c 75 65 32 29 3b 0a 20 20 ine,&value2);.
10a40 20 20 20 20 66 6f 73 73 69 6c 5f 73 65 74 65 6e fossil_seten
10a50 76 28 62 6c 6f 62 5f 73 74 72 28 26 76 61 6c 75 v(blob_str(&valu
10a60 65 29 2c 20 62 6c 6f 62 5f 73 74 72 28 26 76 61 e), blob_str(&va
10a70 6c 75 65 32 29 29 3b 0a 20 20 20 20 20 20 62 6c lue2));. bl
10a80 6f 62 5f 72 65 73 65 74 28 26 76 61 6c 75 65 29 ob_reset(&value)
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 32 29 3b 0a 20 20 20 et(&value2);.
10ab0 20 20 20 63 6f 6e 74 69 6e 75 65 3b 0a 20 20 20 continue;.
10ac0 20 7d 0a 20 20 20 20 69 66 28 20 62 6c 6f 62 5f }. if( blob_
10ad0 65 71 28 26 6b 65 79 2c 20 22 64 65 62 75 67 3a eq(&key, "debug:
10ae0 22 29 20 26 26 20 62 6c 6f 62 5f 74 6f 6b 65 6e ") && blob_token
10af0 28 26 6c 69 6e 65 2c 20 26 76 61 6c 75 65 29 20 (&line, &value)
10b00 29 7b 0a 20 20 20 20 20 20 2f 2a 20 64 65 62 75 ){. /* debu
10b10 67 3a 20 46 49 4c 45 4e 41 4d 45 0a 20 20 20 20 g: FILENAME.
10b20 20 20 2a 2a 0a 20 20 20 20 20 20 2a 2a 20 43 61 **. ** Ca
10b30 75 73 65 73 20 6f 75 74 70 75 74 20 66 72 6f 6d uses output from
10b40 20 63 67 69 5f 64 65 62 75 67 28 29 20 61 6e 64 cgi_debug() and
10b50 20 43 47 49 44 45 42 55 47 28 28 29 29 20 63 61 CGIDEBUG(()) ca
10b60 6c 6c 73 20 74 6f 20 67 6f 0a 20 20 20 20 20 20 lls to go.
10b70 2a 2a 20 69 6e 74 6f 20 46 49 4c 45 4e 41 4d 45 ** into FILENAME
10b80 2e 0a 20 20 20 20 20 20 2a 2f 0a 20 20 20 20 20 .. */.
10b90 20 67 2e 66 44 65 62 75 67 20 3d 20 66 6f 73 73 g.fDebug = foss
10ba0 69 6c 5f 66 6f 70 65 6e 28 62 6c 6f 62 5f 73 74 il_fopen(blob_st
10bb0 72 28 26 76 61 6c 75 65 29 2c 20 22 61 62 22 29 r(&value), "ab")
10bc0 3b 0a 20 20 20 20 20 20 62 6c 6f 62 5f 72 65 73 ;. blob_res
10bd0 65 74 28 26 76 61 6c 75 65 29 3b 0a 20 20 20 20 et(&value);.
10be0 20 20 63 6f 6e 74 69 6e 75 65 3b 0a 20 20 20 20 continue;.
10bf0 7d 0a 20 20 20 20 69 66 28 20 62 6c 6f 62 5f 65 }. if( blob_e
10c00 71 28 26 6b 65 79 2c 20 22 65 72 72 6f 72 6c 6f q(&key, "errorlo
10c10 67 3a 22 29 20 26 26 20 62 6c 6f 62 5f 74 6f 6b g:") && 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 65 72 ) ){. /* er
10c40 72 6f 72 6c 6f 67 3a 20 46 49 4c 45 4e 41 4d 45 rorlog: FILENAME
10c50 0a 20 20 20 20 20 20 2a 2a 0a 20 20 20 20 20 20 . **.
10c60 2a 2a 20 43 61 75 73 65 73 20 6d 65 73 73 61 67 ** Causes messag
10c70 65 73 20 66 72 6f 6d 20 77 61 72 6e 69 6e 67 73 es from warnings
10c80 2c 20 65 72 72 6f 72 73 2c 20 61 6e 64 20 70 61 , errors, and pa
10c90 6e 69 63 73 20 74 6f 20 62 65 20 61 70 70 65 6e nics to be appen
10ca0 64 65 64 0a 20 20 20 20 20 20 2a 2a 20 74 6f 20 ded. ** to
10cb0 46 49 4c 45 4e 41 4d 45 2e 0a 20 20 20 20 20 20 FILENAME..
10cc0 2a 2f 0a 20 20 20 20 20 20 67 2e 7a 45 72 72 6c */. g.zErrl
10cd0 6f 67 20 3d 20 6d 70 72 69 6e 74 66 28 22 25 73 og = mprintf("%s
10ce0 22 2c 20 62 6c 6f 62 5f 73 74 72 28 26 76 61 6c ", blob_str(&val
10cf0 75 65 29 29 3b 0a 20 20 20 20 20 20 62 6c 6f 62 ue));. blob
10d00 5f 72 65 73 65 74 28 26 76 61 6c 75 65 29 3b 0a _reset(&value);.
10d10 20 20 20 20 20 20 63 6f 6e 74 69 6e 75 65 3b 0a continue;.
10d20 20 20 20 20 7d 0a 20 20 20 20 69 66 28 20 62 6c }. if( bl
10d30 6f 62 5f 65 71 28 26 6b 65 79 2c 20 22 48 4f 4d ob_eq(&key, "HOM
10d40 45 3a 22 29 20 26 26 20 62 6c 6f 62 5f 74 6f 6b E:") && blob_tok
10d50 65 6e 28 26 6c 69 6e 65 2c 20 26 76 61 6c 75 65 en(&line, &value
10d60 29 20 29 7b 0a 20 20 20 20 20 20 2f 2a 20 48 4f ) ){. /* HO
10d70 4d 45 3a 20 56 41 4c 55 45 0a 20 20 20 20 20 20 ME: VALUE.
10d80 2a 2a 0a 20 20 20 20 20 20 2a 2a 20 53 65 74 20 **. ** Set
10d90 43 47 49 20 70 61 72 61 6d 65 74 65 72 20 22 48 CGI parameter "H
10da0 4f 4d 45 22 20 74 6f 20 56 41 4c 55 45 2e 20 20 OME" to VALUE.
10db0 54 68 69 73 20 69 73 20 6c 65 67 61 63 79 2e 20 This is legacy.
10dc0 20 55 73 65 0a 20 20 20 20 20 20 2a 2a 20 73 65 Use. ** se
10dd0 74 65 6e 76 3a 20 69 6e 73 74 65 61 64 2e 0a 20 tenv: instead..
10de0 20 20 20 20 20 2a 2f 0a 20 20 20 20 20 20 63 67 */. cg
10df0 69 5f 73 65 74 65 6e 76 28 22 48 4f 4d 45 22 2c i_setenv("HOME",
10e00 20 62 6c 6f 62 5f 73 74 72 28 26 76 61 6c 75 65 blob_str(&value
10e10 29 29 3b 0a 20 20 20 20 20 20 62 6c 6f 62 5f 72 ));. blob_r
10e20 65 73 65 74 28 26 76 61 6c 75 65 29 3b 0a 20 20 eset(&value);.
10e30 20 20 20 20 63 6f 6e 74 69 6e 75 65 3b 0a 20 20 continue;.
10e40 20 20 7d 0a 20 20 20 20 69 66 28 20 62 6c 6f 62 }. if( blob
10e50 5f 65 71 28 26 6b 65 79 2c 20 22 73 6b 69 6e 3a _eq(&key, "skin:
10e60 22 29 20 26 26 20 62 6c 6f 62 5f 74 6f 6b 65 6e ") && blob_token
10e70 28 26 6c 69 6e 65 2c 20 26 76 61 6c 75 65 29 20 (&line, &value)
10e80 29 7b 0a 20 20 20 20 20 20 2f 2a 20 73 6b 69 6e ){. /* skin
10e90 3a 20 4c 41 42 45 4c 0a 20 20 20 20 20 20 2a 2a : LABEL. **
10ea0 0a 20 20 20 20 20 20 2a 2a 20 55 73 65 20 6f 6e . ** Use on
10eb0 65 20 6f 66 20 74 68 65 20 62 75 69 6c 74 2d 69 e of the built-i
10ec0 6e 20 73 6b 69 6e 73 20 64 65 66 69 6e 65 64 20 n skins defined
10ed0 62 79 20 4c 41 42 45 4c 2e 20 20 4c 41 42 45 4c by LABEL. LABEL
10ee0 20 69 73 20 74 68 65 0a 20 20 20 20 20 20 2a 2a is the. **
10ef0 20 6e 61 6d 65 20 6f 66 20 74 68 65 20 73 75 62 name of the sub
10f00 64 69 72 65 63 74 6f 72 79 20 75 6e 64 65 72 20 directory under
10f10 74 68 65 20 73 6b 69 6e 73 2f 20 64 69 72 65 63 the skins/ direc
10f20 74 6f 72 79 20 74 68 61 74 20 68 6f 6c 64 73 0a tory that holds.
10f30 20 20 20 20 20 20 2a 2a 20 74 68 65 20 65 6c 65 ** the ele
10f40 6d 65 6e 74 73 20 6f 66 20 74 68 65 20 62 75 69 ments of the bui
10f50 6c 74 2d 69 6e 20 73 6b 69 6e 2e 20 20 49 66 20 lt-in skin. If
10f60 4c 41 42 45 4c 20 64 6f 65 73 20 6e 6f 74 20 6d LABEL does not m
10f70 61 74 63 68 2c 0a 20 20 20 20 20 20 2a 2a 20 74 atch,. ** t
10f80 68 69 73 20 64 69 72 65 63 74 69 76 65 20 69 73 his directive is
10f90 20 61 20 73 69 6c 65 6e 74 20 6e 6f 2d 6f 70 2e a silent no-op.
10fa0 0a 20 20 20 20 20 20 2a 2f 0a 20 20 20 20 20 20 . */.
10fb0 73 6b 69 6e 5f 75 73 65 5f 61 6c 74 65 72 6e 61 skin_use_alterna
10fc0 74 69 76 65 28 62 6c 6f 62 5f 73 74 72 28 26 76 tive(blob_str(&v
10fd0 61 6c 75 65 29 29 3b 0a 20 20 20 20 20 20 62 6c alue));. bl
10fe0 6f 62 5f 72 65 73 65 74 28 26 76 61 6c 75 65 29 ob_reset(&value)
10ff0 3b 0a 20 20 20 20 20 20 63 6f 6e 74 69 6e 75 65 ;. continue
11000 3b 0a 20 20 20 20 7d 0a 20 20 7d 0a 20 20 62 6c ;. }. }. bl
11010 6f 62 5f 72 65 73 65 74 28 26 63 6f 6e 66 69 67 ob_reset(&config
11020 29 3b 0a 20 20 69 66 28 20 67 2e 64 62 3d 3d 30 );. if( g.db==0
11030 20 26 26 20 67 2e 7a 52 65 70 6f 73 69 74 6f 72 && g.zRepositor
11040 79 4e 61 6d 65 3d 3d 30 20 26 26 20 6e 52 65 64 yName==0 && nRed
11050 69 72 65 63 74 3d 3d 30 20 29 7b 0a 20 20 20 20 irect==0 ){.
11060 63 67 69 5f 70 61 6e 69 63 28 22 55 6e 61 62 6c cgi_panic("Unabl
11070 65 20 74 6f 20 66 69 6e 64 20 6f 72 20 6f 70 65 e to find or ope
11080 6e 20 74 68 65 20 70 72 6f 6a 65 63 74 20 72 65 n the project re
11090 70 6f 73 69 74 6f 72 79 22 29 3b 0a 20 20 7d 0a pository");. }.
110a0 20 20 63 67 69 5f 69 6e 69 74 28 29 3b 0a 20 20 cgi_init();.
110b0 69 66 28 20 6e 52 65 64 69 72 65 63 74 20 29 7b if( nRedirect ){
110c0 0a 20 20 20 20 72 65 64 69 72 65 63 74 5f 77 65 . redirect_we
110d0 62 5f 70 61 67 65 28 6e 52 65 64 69 72 65 63 74 b_page(nRedirect
110e0 2c 20 61 7a 52 65 64 69 72 65 63 74 29 3b 0a 20 , azRedirect);.
110f0 20 7d 65 6c 73 65 7b 0a 20 20 20 20 70 72 6f 63 }else{. proc
11100 65 73 73 5f 6f 6e 65 5f 77 65 62 5f 70 61 67 65 ess_one_web_page
11110 28 7a 4e 6f 74 46 6f 75 6e 64 2c 20 70 46 69 6c (zNotFound, pFil
11120 65 47 6c 6f 62 2c 20 61 6c 6c 6f 77 52 65 70 6f eGlob, allowRepo
11130 4c 69 73 74 29 3b 0a 20 20 7d 0a 7d 0a 0a 2f 2a List);. }.}../*
11140 0a 2a 2a 20 49 66 20 67 2e 61 72 67 76 5b 61 72 .** If g.argv[ar
11150 67 5d 20 65 78 69 73 74 73 20 74 68 65 6e 20 69 g] exists then i
11160 74 20 69 73 20 65 69 74 68 65 72 20 74 68 65 20 t is either the
11170 6e 61 6d 65 20 6f 66 20 61 20 72 65 70 6f 73 69 name of a reposi
11180 74 6f 72 79 0a 2a 2a 20 74 68 61 74 20 77 69 6c tory.** that wil
11190 6c 20 62 65 20 75 73 65 64 20 62 79 20 61 20 73 l be used by a s
111a0 65 72 76 65 72 2c 20 6f 72 20 65 6c 73 65 20 69 erver, or else i
111b0 74 20 69 73 20 61 20 64 69 72 65 63 74 6f 72 79 t is a directory
111c0 20 74 68 61 74 0a 2a 2a 20 63 6f 6e 74 61 69 6e that.** contain
111d0 73 20 6d 75 6c 74 69 70 6c 65 20 72 65 70 6f 73 s multiple repos
111e0 69 74 6f 72 69 65 73 20 74 68 61 74 20 63 61 6e itories that can
111f0 20 62 65 20 73 65 72 76 65 64 2e 20 20 49 66 20 be served. If
11200 67 2e 61 72 67 76 5b 61 72 67 5d 0a 2a 2a 20 69 g.argv[arg].** i
11210 73 20 61 20 64 69 72 65 63 74 6f 72 79 2c 20 74 s a directory, t
11220 68 65 20 72 65 70 6f 73 69 74 6f 72 69 65 73 20 he repositories
11230 69 74 20 63 6f 6e 74 61 69 6e 73 20 6d 75 73 74 it contains must
11240 20 62 65 20 6e 61 6d 65 64 0a 2a 2a 20 22 2a 2e be named.** "*.
11250 66 6f 73 73 69 6c 22 2e 20 20 49 66 20 67 2e 61 fossil". If g.a
11260 72 67 76 5b 61 72 67 5d 20 64 6f 65 73 20 6e 6f rgv[arg] does no
11270 74 20 65 78 69 73 74 2c 20 74 68 65 6e 20 77 65 t exist, then we
11280 20 6d 75 73 74 20 62 65 20 77 69 74 68 69 6e 0a must be within.
11290 2a 2a 20 61 6e 20 6f 70 65 6e 20 63 68 65 63 6b ** an open check
112a0 2d 6f 75 74 20 61 6e 64 20 74 68 65 20 72 65 70 -out and the rep
112b0 6f 73 69 74 6f 72 79 20 73 65 72 76 65 20 69 73 ository serve is
112c0 20 74 68 65 20 72 65 70 6f 73 69 74 6f 72 79 20 the repository
112d0 6f 66 0a 2a 2a 20 74 68 61 74 20 63 68 65 63 6b of.** that check
112e0 2d 6f 75 74 2e 0a 2a 2a 0a 2a 2a 20 4f 70 65 6e -out..**.** Open
112f0 20 74 68 65 20 72 65 70 6f 73 69 74 6f 72 79 20 the repository
11300 74 6f 20 62 65 20 73 65 72 76 65 64 20 69 66 20 to be served if
11310 69 74 20 69 73 20 6b 6e 6f 77 6e 2e 20 20 49 66 it is known. If
11320 20 67 2e 61 72 67 76 5b 61 72 67 5d 20 69 73 0a g.argv[arg] is.
11330 2a 2a 20 61 20 64 69 72 65 63 74 6f 72 79 20 66 ** a directory f
11340 75 6c 6c 20 6f 66 20 72 65 70 6f 73 69 74 6f 72 ull of repositor
11350 69 65 73 2c 20 74 68 65 6e 20 73 65 74 20 67 2e ies, then set g.
11360 7a 52 65 70 6f 73 69 74 6f 72 79 4e 61 6d 65 20 zRepositoryName
11370 74 6f 0a 2a 2a 20 74 68 65 20 6e 61 6d 65 20 6f to.** the name o
11380 66 20 74 68 61 74 20 64 69 72 65 63 74 6f 72 79 f that directory
11390 20 61 6e 64 20 74 68 65 20 73 70 65 63 69 66 69 and the specifi
113a0 63 20 72 65 70 6f 73 69 74 6f 72 79 20 77 69 6c c repository wil
113b0 6c 20 62 65 0a 2a 2a 20 6f 70 65 6e 65 64 20 6c l be.** opened l
113c0 61 74 65 72 20 62 79 20 70 72 6f 63 65 73 73 5f ater by process_
113d0 6f 6e 65 5f 77 65 62 5f 70 61 67 65 28 29 20 62 one_web_page() b
113e0 61 73 65 64 20 6f 6e 20 74 68 65 20 63 6f 6e 74 ased on the cont
113f0 65 6e 74 20 6f 66 0a 2a 2a 20 74 68 65 20 50 41 ent of.** the PA
11400 54 48 5f 49 4e 46 4f 20 76 61 72 69 61 62 6c 65 TH_INFO variable
11410 2e 0a 2a 2a 0a 2a 2a 20 49 66 20 74 68 65 20 66 ..**.** If the f
11420 43 72 65 61 74 65 20 66 6c 61 67 20 69 73 20 73 Create flag is s
11430 65 74 2c 20 74 68 65 6e 20 63 72 65 61 74 65 20 et, then create
11440 74 68 65 20 72 65 70 6f 73 69 74 6f 72 79 20 69 the repository i
11450 66 20 69 74 0a 2a 2a 20 64 6f 65 73 20 6e 6f 74 f it.** does not
11460 20 61 6c 72 65 61 64 79 20 65 78 69 73 74 2e 20 already exist.
11470 41 6c 77 61 79 73 20 75 73 65 20 22 61 75 74 6f Always use "auto
11480 22 20 68 61 73 68 2d 70 6f 6c 69 63 79 20 69 6e " hash-policy in
11490 20 74 68 69 73 20 63 61 73 65 2e 0a 2a 2f 0a 73 this case..*/.s
114a0 74 61 74 69 63 20 76 6f 69 64 20 66 69 6e 64 5f tatic void find_
114b0 73 65 72 76 65 72 5f 72 65 70 6f 73 69 74 6f 72 server_repositor
114c0 79 28 69 6e 74 20 61 72 67 2c 20 69 6e 74 20 66 y(int arg, int f
114d0 43 72 65 61 74 65 29 7b 0a 20 20 69 66 28 20 67 Create){. if( g
114e0 2e 61 72 67 63 3c 3d 61 72 67 20 29 7b 0a 20 20 .argc<=arg ){.
114f0 20 20 64 62 5f 6d 75 73 74 5f 62 65 5f 77 69 74 db_must_be_wit
11500 68 69 6e 5f 74 72 65 65 28 29 3b 0a 20 20 7d 65 hin_tree();. }e
11510 6c 73 65 7b 0a 20 20 20 20 63 6f 6e 73 74 20 63 lse{. const c
11520 68 61 72 20 2a 7a 52 65 70 6f 20 3d 20 67 2e 61 har *zRepo = g.a
11530 72 67 76 5b 61 72 67 5d 3b 0a 20 20 20 20 69 6e rgv[arg];. in
11540 74 20 69 73 44 69 72 20 3d 20 66 69 6c 65 5f 69 t isDir = file_i
11550 73 64 69 72 28 7a 52 65 70 6f 29 3b 0a 20 20 20 sdir(zRepo);.
11560 20 69 66 28 20 69 73 44 69 72 3d 3d 31 20 29 7b if( isDir==1 ){
11570 0a 20 20 20 20 20 20 67 2e 7a 52 65 70 6f 73 69 . g.zReposi
11580 74 6f 72 79 4e 61 6d 65 20 3d 20 6d 70 72 69 6e toryName = mprin
11590 74 66 28 22 25 73 22 2c 20 7a 52 65 70 6f 29 3b tf("%s", zRepo);
115a0 0a 20 20 20 20 20 20 66 69 6c 65 5f 73 69 6d 70 . file_simp
115b0 6c 69 66 79 5f 6e 61 6d 65 28 67 2e 7a 52 65 70 lify_name(g.zRep
115c0 6f 73 69 74 6f 72 79 4e 61 6d 65 2c 20 2d 31 2c ositoryName, -1,
115d0 20 30 29 3b 0a 20 20 20 20 7d 65 6c 73 65 7b 0a 0);. }else{.
115e0 20 20 20 20 20 20 69 66 28 20 69 73 44 69 72 3d if( isDir=
115f0 3d 30 20 26 26 20 66 43 72 65 61 74 65 20 29 7b =0 && fCreate ){
11600 0a 20 20 20 20 20 20 20 20 63 6f 6e 73 74 20 63 . const c
11610 68 61 72 20 2a 7a 50 61 73 73 77 6f 72 64 3b 0a har *zPassword;.
11620 20 20 20 20 20 20 20 20 64 62 5f 63 72 65 61 74 db_creat
11630 65 5f 72 65 70 6f 73 69 74 6f 72 79 28 7a 52 65 e_repository(zRe
11640 70 6f 29 3b 0a 20 20 20 20 20 20 20 20 64 62 5f po);. db_
11650 6f 70 65 6e 5f 72 65 70 6f 73 69 74 6f 72 79 28 open_repository(
11660 7a 52 65 70 6f 29 3b 0a 20 20 20 20 20 20 20 20 zRepo);.
11670 64 62 5f 62 65 67 69 6e 5f 74 72 61 6e 73 61 63 db_begin_transac
11680 74 69 6f 6e 28 29 3b 0a 20 20 20 20 20 20 20 20 tion();.
11690 67 2e 65 48 61 73 68 50 6f 6c 69 63 79 20 3d 20 g.eHashPolicy =
116a0 48 50 4f 4c 49 43 59 5f 41 55 54 4f 3b 0a 20 20 HPOLICY_AUTO;.
116b0 20 20 20 20 20 20 64 62 5f 73 65 74 5f 69 6e 74 db_set_int
116c0 28 22 68 61 73 68 2d 70 6f 6c 69 63 79 22 2c 20 ("hash-policy",
116d0 48 50 4f 4c 49 43 59 5f 41 55 54 4f 2c 20 30 29 HPOLICY_AUTO, 0)
116e0 3b 0a 20 20 20 20 20 20 20 20 64 62 5f 69 6e 69 ;. db_ini
116f0 74 69 61 6c 5f 73 65 74 75 70 28 30 2c 20 22 6e tial_setup(0, "n
11700 6f 77 22 2c 20 67 2e 7a 4c 6f 67 69 6e 29 3b 0a ow", g.zLogin);.
11710 20 20 20 20 20 20 20 20 64 62 5f 65 6e 64 5f 74 db_end_t
11720 72 61 6e 73 61 63 74 69 6f 6e 28 30 29 3b 0a 20 ransaction(0);.
11730 20 20 20 20 20 20 20 66 6f 73 73 69 6c 5f 70 72 fossil_pr
11740 69 6e 74 28 22 70 72 6f 6a 65 63 74 2d 69 64 3a int("project-id:
11750 20 25 73 5c 6e 22 2c 20 64 62 5f 67 65 74 28 22 %s\n", db_get("
11760 70 72 6f 6a 65 63 74 2d 63 6f 64 65 22 2c 20 30 project-code", 0
11770 29 29 3b 0a 20 20 20 20 20 20 20 20 66 6f 73 73 ));. foss
11780 69 6c 5f 70 72 69 6e 74 28 22 73 65 72 76 65 72 il_print("server
11790 2d 69 64 3a 20 20 25 73 5c 6e 22 2c 20 64 62 5f -id: %s\n", db_
117a0 67 65 74 28 22 73 65 72 76 65 72 2d 63 6f 64 65 get("server-code
117b0 22 2c 20 30 29 29 3b 0a 20 20 20 20 20 20 20 20 ", 0));.
117c0 7a 50 61 73 73 77 6f 72 64 20 3d 20 64 62 5f 74 zPassword = db_t
117d0 65 78 74 28 30 2c 20 22 53 45 4c 45 43 54 20 70 ext(0, "SELECT p
117e0 77 20 46 52 4f 4d 20 75 73 65 72 20 57 48 45 52 w FROM user WHER
117f0 45 20 6c 6f 67 69 6e 3d 25 51 22 2c 20 67 2e 7a E login=%Q", g.z
11800 4c 6f 67 69 6e 29 3b 0a 20 20 20 20 20 20 20 20 Login);.
11810 66 6f 73 73 69 6c 5f 70 72 69 6e 74 28 22 61 64 fossil_print("ad
11820 6d 69 6e 2d 75 73 65 72 3a 20 25 73 20 28 69 6e min-user: %s (in
11830 69 74 69 61 6c 20 70 61 73 73 77 6f 72 64 20 69 itial password i
11840 73 20 5c 22 25 73 5c 22 29 5c 6e 22 2c 0a 20 20 s \"%s\")\n",.
11850 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
11860 20 20 20 67 2e 7a 4c 6f 67 69 6e 2c 20 7a 50 61 g.zLogin, zPa
11870 73 73 77 6f 72 64 29 3b 0a 20 20 20 20 20 20 20 ssword);.
11880 20 63 61 63 68 65 5f 69 6e 69 74 69 61 6c 69 7a cache_initializ
11890 65 28 29 3b 0a 20 20 20 20 20 20 20 20 67 2e 7a e();. g.z
118a0 4c 6f 67 69 6e 20 3d 20 30 3b 0a 20 20 20 20 20 Login = 0;.
118b0 20 20 20 67 2e 75 73 65 72 55 69 64 20 3d 20 30 g.userUid = 0
118c0 3b 0a 20 20 20 20 20 20 7d 65 6c 73 65 7b 0a 20 ;. }else{.
118d0 20 20 20 20 20 20 20 64 62 5f 6f 70 65 6e 5f 72 db_open_r
118e0 65 70 6f 73 69 74 6f 72 79 28 7a 52 65 70 6f 29 epository(zRepo)
118f0 3b 0a 20 20 20 20 20 20 7d 0a 20 20 20 20 7d 0a ;. }. }.
11900 20 20 7d 0a 7d 0a 0a 23 69 66 20 64 65 66 69 6e }.}..#if defin
11910 65 64 28 5f 57 49 4e 33 32 29 20 26 26 20 55 53 ed(_WIN32) && US
11920 45 5f 53 45 45 0a 2f 2a 0a 2a 2a 20 54 68 69 73 E_SEE./*.** This
11930 20 66 75 6e 63 74 69 6f 6e 20 61 74 74 65 6d 70 function attemp
11940 74 73 20 74 6f 20 70 61 72 73 65 20 61 20 73 74 ts to parse a st
11950 72 69 6e 67 20 76 61 6c 75 65 20 69 6e 20 74 68 ring value in th
11960 65 20 66 6f 6c 6c 6f 77 69 6e 67 0a 2a 2a 20 66 e following.** f
11970 6f 72 6d 61 74 3a 0a 2a 2a 0a 2a 2a 20 20 20 20 ormat:.**.**
11980 20 22 25 6c 75 3a 25 70 3a 25 75 22 0a 2a 2a 0a "%lu:%p:%u".**.
11990 2a 2a 20 54 68 65 72 65 20 61 72 65 20 74 68 72 ** There are thr
119a0 65 65 20 70 61 72 74 73 2c 20 77 68 69 63 68 20 ee parts, which
119b0 6d 75 73 74 20 62 65 20 64 65 6c 69 6d 69 74 65 must be delimite
119c0 64 20 62 79 20 63 6f 6c 6f 6e 73 2e 20 20 54 68 d by colons. Th
119d0 65 0a 2a 2a 20 66 69 72 73 74 20 70 61 72 74 20 e.** first part
119e0 69 73 20 61 6e 20 75 6e 73 69 67 6e 65 64 20 6c is an unsigned l
119f0 6f 6e 67 20 69 6e 74 65 67 65 72 20 69 6e 20 62 ong integer in b
11a00 61 73 65 2d 31 30 20 28 64 65 63 69 6d 61 6c 29 ase-10 (decimal)
11a10 20 66 6f 72 6d 61 74 2e 0a 2a 2a 20 54 68 65 20 format..** The
11a20 73 65 63 6f 6e 64 20 70 61 72 74 20 69 73 20 61 second part is a
11a30 20 6e 75 6d 65 72 69 63 61 6c 20 72 65 70 72 65 numerical repre
11a40 73 65 6e 74 61 74 69 6f 6e 20 6f 66 20 61 20 6e sentation of a n
11a50 61 74 69 76 65 20 70 6f 69 6e 74 65 72 2c 0a 2a ative pointer,.*
11a60 2a 20 69 6e 20 74 68 65 20 61 70 70 72 6f 70 72 * in the appropr
11a70 69 61 74 65 20 69 6d 70 6c 65 6d 65 6e 74 61 74 iate implementat
11a80 69 6f 6e 20 64 65 66 69 6e 65 64 20 66 6f 72 6d ion defined form
11a90 61 74 2e 20 20 54 68 65 20 74 68 69 72 64 20 70 at. The third p
11aa0 61 72 74 0a 2a 2a 20 69 73 20 61 6e 20 75 6e 73 art.** is an uns
11ab0 69 67 6e 65 64 20 69 6e 74 65 67 65 72 20 69 6e igned integer in
11ac0 20 62 61 73 65 2d 31 30 20 28 64 65 63 69 6d 61 base-10 (decima
11ad0 6c 29 20 66 6f 72 6d 61 74 2e 0a 2a 2a 0a 2a 2a l) format..**.**
11ae0 20 49 66 20 74 68 65 20 73 70 65 63 69 66 69 65 If the specifie
11af0 64 20 76 61 6c 75 65 20 63 61 6e 6e 6f 74 20 62 d value cannot b
11b00 65 20 70 61 72 73 65 64 2c 20 66 6f 72 20 61 6e e parsed, for an
11b10 79 20 72 65 61 73 6f 6e 2c 20 61 20 66 61 74 61 y reason, a fata
11b20 6c 0a 2a 2a 20 65 72 72 6f 72 20 77 69 6c 6c 20 l.** error will
11b30 62 65 20 72 61 69 73 65 64 20 61 6e 64 20 74 68 be raised and th
11b40 65 20 70 72 6f 63 65 73 73 20 77 69 6c 6c 20 62 e process will b
11b50 65 20 74 65 72 6d 69 6e 61 74 65 64 2e 0a 2a 2f e terminated..*/
11b60 0a 76 6f 69 64 20 70 61 72 73 65 5f 70 69 64 5f .void parse_pid_
11b70 6b 65 79 5f 76 61 6c 75 65 28 0a 20 20 63 6f 6e key_value(. con
11b80 73 74 20 63 68 61 72 20 2a 7a 50 69 64 4b 65 79 st char *zPidKey
11b90 2c 20 2f 2a 20 54 68 65 20 76 61 6c 75 65 20 74 , /* The value t
11ba0 6f 20 62 65 20 70 61 72 73 65 64 2e 20 2a 2f 0a o be parsed. */.
11bb0 20 20 44 57 4f 52 44 20 2a 70 50 72 6f 63 65 73 DWORD *pProces
11bc0 73 49 64 2c 20 20 20 2f 2a 20 54 68 65 20 65 78 sId, /* The ex
11bd0 74 72 61 63 74 65 64 20 70 72 6f 63 65 73 73 20 tracted process
11be0 69 64 65 6e 74 69 66 69 65 72 2e 20 2a 2f 0a 20 identifier. */.
11bf0 20 4c 50 56 4f 49 44 20 2a 70 70 41 64 64 72 65 LPVOID *ppAddre
11c00 73 73 2c 20 20 20 2f 2a 20 54 68 65 20 65 78 74 ss, /* The ext
11c10 72 61 63 74 65 64 20 70 6f 69 6e 74 65 72 20 76 racted pointer v
11c20 61 6c 75 65 2e 20 2a 2f 0a 20 20 53 49 5a 45 5f alue. */. SIZE_
11c30 54 20 2a 70 6e 53 69 7a 65 20 20 20 20 20 20 20 T *pnSize
11c40 2f 2a 20 54 68 65 20 65 78 74 72 61 63 74 65 64 /* The extracted
11c50 20 73 69 7a 65 20 76 61 6c 75 65 2e 20 2a 2f 0a size value. */.
11c60 29 7b 0a 20 20 75 6e 73 69 67 6e 65 64 20 69 6e ){. unsigned in
11c70 74 20 6e 53 69 7a 65 20 3d 20 30 3b 0a 20 20 69 t nSize = 0;. i
11c80 66 28 20 73 73 63 61 6e 66 28 7a 50 69 64 4b 65 f( sscanf(zPidKe
11c90 79 2c 20 22 25 6c 75 3a 25 70 3a 25 75 22 2c 20 y, "%lu:%p:%u",
11ca0 70 50 72 6f 63 65 73 73 49 64 2c 20 70 70 41 64 pProcessId, ppAd
11cb0 64 72 65 73 73 2c 20 26 6e 53 69 7a 65 29 3d 3d dress, &nSize)==
11cc0 33 20 29 7b 0a 20 20 20 20 2a 70 6e 53 69 7a 65 3 ){. *pnSize
11cd0 20 3d 20 28 53 49 5a 45 5f 54 29 6e 53 69 7a 65 = (SIZE_T)nSize
11ce0 3b 0a 20 20 7d 65 6c 73 65 7b 0a 20 20 20 20 66 ;. }else{. f
11cf0 6f 73 73 69 6c 5f 66 61 74 61 6c 28 22 66 61 69 ossil_fatal("fai
11d00 6c 65 64 20 74 6f 20 70 61 72 73 65 20 70 69 64 led to parse pid
11d10 20 6b 65 79 22 29 3b 0a 20 20 7d 0a 7d 0a 23 65 key");. }.}.#e
11d20 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 75 6e 64 6f ndif../*.** undo
11d30 63 75 6d 65 6e 74 65 64 20 66 6f 72 6d 61 74 3a cumented format:
11d40 0a 2a 2a 0a 2a 2a 20 20 20 20 20 20 20 20 66 6f .**.** fo
11d50 73 73 69 6c 20 68 74 74 70 20 49 4e 46 49 4c 45 ssil http INFILE
11d60 20 4f 55 54 46 49 4c 45 20 49 50 41 44 44 52 20 OUTFILE IPADDR
11d70 3f 52 45 50 4f 53 49 54 4f 52 59 3f 0a 2a 2a 0a ?REPOSITORY?.**.
11d80 2a 2a 20 54 68 65 20 61 72 67 76 3d 3d 36 20 66 ** The argv==6 f
11d90 6f 72 6d 20 28 77 69 74 68 20 6e 6f 20 6f 70 74 orm (with no opt
11da0 69 6f 6e 73 29 20 69 73 20 75 73 65 64 20 62 79 ions) is used by
11db0 20 74 68 65 20 77 69 6e 33 32 20 73 65 72 76 65 the win32 serve
11dc0 72 20 6f 6e 6c 79 2e 0a 2a 2a 0a 2a 2a 20 43 4f r only..**.** CO
11dd0 4d 4d 41 4e 44 3a 20 68 74 74 70 2a 0a 2a 2a 0a MMAND: http*.**.
11de0 2a 2a 20 55 73 61 67 65 3a 20 25 66 6f 73 73 69 ** Usage: %fossi
11df0 6c 20 68 74 74 70 20 3f 52 45 50 4f 53 49 54 4f l http ?REPOSITO
11e00 52 59 3f 20 3f 4f 50 54 49 4f 4e 53 3f 0a 2a 2a RY? ?OPTIONS?.**
11e10 0a 2a 2a 20 48 61 6e 64 6c 65 20 61 20 73 69 6e .** Handle a sin
11e20 67 6c 65 20 48 54 54 50 20 72 65 71 75 65 73 74 gle HTTP request
11e30 20 61 70 70 65 61 72 69 6e 67 20 6f 6e 20 73 74 appearing on st
11e40 64 69 6e 2e 20 20 54 68 65 20 72 65 73 75 6c 74 din. The result
11e50 69 6e 67 20 77 65 62 70 61 67 65 0a 2a 2a 20 69 ing webpage.** i
11e60 73 20 64 65 6c 69 76 65 72 65 64 20 6f 6e 20 73 s delivered on s
11e70 74 64 6f 75 74 2e 20 20 54 68 69 73 20 6d 65 74 tdout. This met
11e80 68 6f 64 20 69 73 20 75 73 65 64 20 74 6f 20 6c hod is used to l
11e90 61 75 6e 63 68 20 61 6e 20 48 54 54 50 20 72 65 aunch an HTTP re
11ea0 71 75 65 73 74 0a 2a 2a 20 68 61 6e 64 6c 65 72 quest.** handler
11eb0 20 66 72 6f 6d 20 69 6e 65 74 64 2c 20 66 6f 72 from inetd, for
11ec0 20 65 78 61 6d 70 6c 65 2e 20 20 54 68 65 20 61 example. The a
11ed0 72 67 75 6d 65 6e 74 20 69 73 20 74 68 65 20 6e rgument is the n
11ee0 61 6d 65 20 6f 66 20 74 68 65 0a 2a 2a 20 72 65 ame of the.** re
11ef0 70 6f 73 69 74 6f 72 79 2e 0a 2a 2a 0a 2a 2a 20 pository..**.**
11f00 49 66 20 52 45 50 4f 53 49 54 4f 52 59 20 69 73 If REPOSITORY is
11f10 20 61 20 64 69 72 65 63 74 6f 72 79 20 74 68 61 a directory tha
11f20 74 20 63 6f 6e 74 61 69 6e 73 20 6f 6e 65 20 6f t contains one o
11f30 72 20 6d 6f 72 65 20 72 65 70 6f 73 69 74 6f 72 r more repositor
11f40 69 65 73 2c 0a 2a 2a 20 65 69 74 68 65 72 20 64 ies,.** either d
11f50 69 72 65 63 74 6c 79 20 69 6e 20 52 45 50 4f 53 irectly in REPOS
11f60 49 54 4f 52 59 20 69 74 73 65 6c 66 20 6f 72 20 ITORY itself or
11f70 69 6e 20 73 75 62 64 69 72 65 63 74 6f 72 69 65 in subdirectorie
11f80 73 2c 20 61 6e 64 0a 2a 2a 20 77 69 74 68 20 6e s, and.** with n
11f90 61 6d 65 73 20 6f 66 20 74 68 65 20 66 6f 72 6d ames of the form
11fa0 20 22 2a 2e 66 6f 73 73 69 6c 22 20 74 68 65 6e "*.fossil" then
11fb0 20 61 20 70 72 65 66 69 78 20 6f 66 20 74 68 65 a prefix of the
11fc0 20 55 52 4c 20 70 61 74 68 6e 61 6d 65 0a 2a 2a URL pathname.**
11fd0 20 73 65 6c 65 63 74 73 20 66 72 6f 6d 20 61 6d selects from am
11fe0 6f 6e 67 20 74 68 65 20 76 61 72 69 6f 75 73 20 ong the various
11ff0 72 65 70 6f 73 69 74 6f 72 69 65 73 2e 20 20 49 repositories. I
12000 66 20 74 68 65 20 70 61 74 68 6e 61 6d 65 20 64 f the pathname d
12010 6f 65 73 0a 2a 2a 20 6e 6f 74 20 73 65 6c 65 63 oes.** not selec
12020 74 20 61 20 76 61 6c 69 64 20 72 65 70 6f 73 69 t a valid reposi
12030 74 6f 72 79 20 61 6e 64 20 74 68 65 20 2d 2d 6e tory and the --n
12040 6f 74 66 6f 75 6e 64 20 6f 70 74 69 6f 6e 20 69 otfound option i
12050 73 20 61 76 61 69 6c 61 62 6c 65 2c 0a 2a 2a 20 s available,.**
12060 74 68 65 6e 20 74 68 65 20 73 65 72 76 65 72 20 then the server
12070 72 65 64 69 72 65 63 74 73 20 28 48 54 54 50 20 redirects (HTTP
12080 63 6f 64 65 20 33 30 32 29 20 74 6f 20 74 68 65 code 302) to the
12090 20 55 52 4c 20 6f 66 20 2d 2d 6e 6f 74 66 6f 75 URL of --notfou
120a0 6e 64 2e 0a 2a 2a 20 57 68 65 6e 20 52 45 50 4f nd..** When REPO
120b0 53 49 54 4f 52 59 20 69 73 20 61 20 64 69 72 65 SITORY is a dire
120c0 63 74 6f 72 79 2c 20 74 68 65 20 70 61 74 68 6e ctory, the pathn
120d0 61 6d 65 20 6d 75 73 74 20 63 6f 6e 74 61 69 6e ame must contain
120e0 20 6f 6e 6c 79 0a 2a 2a 20 61 6c 70 68 61 6e 75 only.** alphanu
120f0 6d 65 72 69 63 73 2c 20 22 5f 22 2c 20 22 2f 22 merics, "_", "/"
12100 2c 20 22 2d 22 20 61 6e 64 20 22 2e 22 20 61 6e , "-" and "." an
12110 64 20 6e 6f 20 22 2d 22 20 6d 61 79 20 6f 63 63 d no "-" may occ
12120 75 72 20 61 66 74 65 72 20 61 20 22 2f 22 0a 2a ur after a "/".*
12130 2a 20 61 6e 64 20 65 76 65 72 79 20 22 2e 22 20 * and every "."
12140 6d 75 73 74 20 62 65 20 73 75 72 72 6f 75 6e 64 must be surround
12150 65 64 20 6f 6e 20 62 6f 74 68 20 73 69 64 65 73 ed on both sides
12160 20 62 79 20 61 6c 70 68 61 6e 75 6d 65 72 69 63 by alphanumeric
12170 73 20 6f 72 20 65 6c 73 65 0a 2a 2a 20 61 20 34 s or else.** a 4
12180 30 34 20 65 72 72 6f 72 20 69 73 20 72 65 74 75 04 error is retu
12190 72 6e 65 64 2e 20 20 53 74 61 74 69 63 20 63 6f rned. Static co
121a0 6e 74 65 6e 74 20 66 69 6c 65 73 20 69 6e 20 74 ntent files in t
121b0 68 65 20 64 69 72 65 63 74 6f 72 79 20 61 72 65 he directory are
121c0 0a 2a 2a 20 72 65 74 75 72 6e 65 64 20 69 66 20 .** returned if
121d0 74 68 65 79 20 6d 61 74 63 68 20 63 6f 6d 6d 61 they match comma
121e0 2d 73 65 70 61 72 61 74 65 20 47 4c 4f 42 20 70 -separate GLOB p
121f0 61 74 74 65 72 6e 20 73 70 65 63 69 66 69 65 64 attern specified
12200 20 62 79 20 2d 2d 66 69 6c 65 73 0a 2a 2a 20 61 by --files.** a
12210 6e 64 20 64 6f 20 6e 6f 74 20 6d 61 74 63 68 20 nd do not match
12220 22 2a 2e 66 6f 73 73 69 6c 2a 22 20 61 6e 64 20 "*.fossil*" and
12230 68 61 76 65 20 61 20 77 65 6c 6c 2d 6b 6e 6f 77 have a well-know
12240 6e 20 73 75 66 66 69 78 2e 0a 2a 2a 0a 2a 2a 20 n suffix..**.**
12250 54 68 65 20 2d 2d 68 6f 73 74 20 6f 70 74 69 6f The --host optio
12260 6e 20 63 61 6e 20 62 65 20 75 73 65 64 20 74 6f n can be used to
12270 20 73 70 65 63 69 66 79 20 74 68 65 20 68 6f 73 specify the hos
12280 74 6e 61 6d 65 20 66 6f 72 20 74 68 65 20 73 65 tname for the se
12290 72 76 65 72 2e 0a 2a 2a 20 54 68 65 20 2d 2d 68 rver..** The --h
122a0 74 74 70 73 20 6f 70 74 69 6f 6e 20 69 6e 64 69 ttps option indi
122b0 63 61 74 65 73 20 74 68 61 74 20 74 68 65 20 72 cates that the r
122c0 65 71 75 65 73 74 20 63 61 6d 65 20 66 72 6f 6d equest came from
122d0 20 48 54 54 50 53 20 72 61 74 68 65 72 0a 2a 2a HTTPS rather.**
122e0 20 74 68 61 6e 20 48 54 54 50 2e 20 49 66 20 2d than HTTP. If -
122f0 2d 6e 6f 73 73 6c 20 69 73 20 67 69 76 65 6e 2c -nossl is given,
12300 20 74 68 65 6e 20 53 53 4c 20 63 6f 6e 6e 65 63 then SSL connec
12310 74 69 6f 6e 73 20 77 69 6c 6c 20 6e 6f 74 20 62 tions will not b
12320 65 20 61 76 61 69 6c 61 62 6c 65 2c 0a 2a 2a 20 e available,.**
12330 74 68 75 73 20 61 6c 73 6f 20 6e 6f 20 72 65 64 thus also no red
12340 69 72 65 63 74 69 6e 67 20 66 72 6f 6d 20 68 74 irecting from ht
12350 74 70 3a 20 74 6f 20 68 74 74 70 73 3a 20 77 69 tp: to https: wi
12360 6c 6c 20 74 61 6b 65 20 70 6c 61 63 65 2e 0a 2a ll take place..*
12370 2a 0a 2a 2a 20 49 66 20 74 68 65 20 2d 2d 6c 6f *.** If the --lo
12380 63 61 6c 61 75 74 68 20 6f 70 74 69 6f 6e 20 69 calauth option i
12390 73 20 67 69 76 65 6e 2c 20 74 68 65 6e 20 61 75 s given, then au
123a0 74 6f 6d 61 74 69 63 20 6c 6f 67 69 6e 20 69 73 tomatic login is
123b0 20 70 65 72 66 6f 72 6d 65 64 0a 2a 2a 20 66 6f performed.** fo
123c0 72 20 72 65 71 75 65 73 74 73 20 63 6f 6d 69 6e r requests comin
123d0 67 20 66 72 6f 6d 20 6c 6f 63 61 6c 68 6f 73 74 g from localhost
123e0 2c 20 69 66 20 74 68 65 20 22 6c 6f 63 61 6c 61 , if the "locala
123f0 75 74 68 22 20 73 65 74 74 69 6e 67 20 69 73 20 uth" setting is
12400 6e 6f 74 0a 2a 2a 20 65 6e 61 62 6c 65 64 2e 0a not.** enabled..
12410 2a 2a 0a 2a 2a 20 4f 70 74 69 6f 6e 73 3a 0a 2a **.** Options:.*
12420 2a 20 20 20 2d 2d 62 61 73 65 75 72 6c 20 55 52 * --baseurl UR
12430 4c 20 20 20 20 62 61 73 65 20 55 52 4c 20 28 75 L base URL (u
12440 73 65 66 75 6c 20 77 69 74 68 20 72 65 76 65 72 seful with rever
12450 73 65 20 70 72 6f 78 69 65 73 29 0a 2a 2a 20 20 se proxies).**
12460 20 2d 2d 66 69 6c 65 73 20 47 4c 4f 42 20 20 20 --files GLOB
12470 20 20 63 6f 6d 6d 61 2d 73 65 70 61 72 61 74 65 comma-separate
12480 20 67 6c 6f 62 20 70 61 74 74 65 72 6e 73 20 66 glob patterns f
12490 6f 72 20 73 74 61 74 69 63 20 66 69 6c 65 20 74 or static file t
124a0 6f 20 73 65 72 76 65 0a 2a 2a 20 20 20 2d 2d 6c o serve.** --l
124b0 6f 63 61 6c 61 75 74 68 20 20 20 20 20 20 65 6e ocalauth en
124c0 61 62 6c 65 20 61 75 74 6f 6d 61 74 69 63 20 6c able automatic l
124d0 6f 67 69 6e 20 66 6f 72 20 6c 6f 63 61 6c 20 63 ogin for local c
124e0 6f 6e 6e 65 63 74 69 6f 6e 73 0a 2a 2a 20 20 20 onnections.**
124f0 2d 2d 68 6f 73 74 20 4e 41 4d 45 20 20 20 20 20 --host NAME
12500 20 73 70 65 63 69 66 79 20 68 6f 73 74 6e 61 6d specify hostnam
12510 65 20 6f 66 20 74 68 65 20 73 65 72 76 65 72 0a e of the server.
12520 2a 2a 20 20 20 2d 2d 68 74 74 70 73 20 20 20 20 ** --https
12530 20 20 20 20 20 20 73 69 67 6e 61 6c 20 61 20 72 signal a r
12540 65 71 75 65 73 74 20 63 6f 6d 69 6e 67 20 69 6e equest coming in
12550 20 76 69 61 20 68 74 74 70 73 0a 2a 2a 20 20 20 via https.**
12560 2d 2d 6e 6f 6a 61 69 6c 20 20 20 20 20 20 20 20 --nojail
12570 20 64 72 6f 70 20 72 6f 6f 74 20 70 72 69 76 69 drop root privi
12580 6c 65 67 65 20 62 75 74 20 64 6f 20 6e 6f 74 20 lege but do not
12590 65 6e 74 65 72 20 74 68 65 20 63 68 72 6f 6f 74 enter the chroot
125a0 20 6a 61 69 6c 0a 2a 2a 20 20 20 2d 2d 6e 6f 73 jail.** --nos
125b0 73 6c 20 20 20 20 20 20 20 20 20 20 73 69 67 6e sl sign
125c0 61 6c 20 74 68 61 74 20 6e 6f 20 53 53 4c 20 63 al that no SSL c
125d0 6f 6e 6e 65 63 74 69 6f 6e 73 20 61 72 65 20 61 onnections are a
125e0 76 61 69 6c 61 62 6c 65 0a 2a 2a 20 20 20 2d 2d vailable.** --
125f0 6e 6f 74 66 6f 75 6e 64 20 55 52 4c 20 20 20 75 notfound URL u
12600 73 65 20 55 52 4c 20 61 73 20 22 48 54 54 50 20 se URL as "HTTP
12610 34 30 34 2c 20 6f 62 6a 65 63 74 20 6e 6f 74 20 404, object not
12620 66 6f 75 6e 64 22 20 70 61 67 65 2e 0a 2a 2a 20 found" page..**
12630 20 20 2d 2d 72 65 70 6f 6c 69 73 74 20 20 20 20 --repolist
12640 20 20 20 49 66 20 52 45 50 4f 53 49 54 4f 52 59 If REPOSITORY
12650 20 69 73 20 64 69 72 65 63 74 6f 72 79 2c 20 55 is directory, U
12660 52 4c 20 22 2f 22 20 6c 69 73 74 73 20 61 6c 6c RL "/" lists all
12670 20 72 65 70 6f 73 0a 2a 2a 20 20 20 2d 2d 73 63 repos.** --sc
12680 67 69 20 20 20 20 20 20 20 20 20 20 20 49 6e 74 gi Int
12690 65 72 70 72 65 74 20 69 6e 70 75 74 20 61 73 20 erpret input as
126a0 53 43 47 49 20 72 61 74 68 65 72 20 74 68 61 6e SCGI rather than
126b0 20 48 54 54 50 0a 2a 2a 20 20 20 2d 2d 73 6b 69 HTTP.** --ski
126c0 6e 20 4c 41 42 45 4c 20 20 20 20 20 55 73 65 20 n LABEL Use
126d0 6f 76 65 72 72 69 64 65 20 73 6b 69 6e 20 4c 41 override skin LA
126e0 42 45 4c 0a 2a 2a 20 20 20 2d 2d 74 68 2d 74 72 BEL.** --th-tr
126f0 61 63 65 20 20 20 20 20 20 20 74 72 61 63 65 20 ace trace
12700 54 48 31 20 65 78 65 63 75 74 69 6f 6e 20 28 66 TH1 execution (f
12710 6f 72 20 64 65 62 75 67 67 69 6e 67 20 70 75 72 or debugging pur
12720 70 6f 73 65 73 29 0a 2a 2a 20 20 20 2d 2d 75 73 poses).** --us
12730 65 70 69 64 6b 65 79 20 20 20 20 20 20 55 73 65 epidkey Use
12740 20 73 61 76 65 64 20 65 6e 63 72 79 70 74 69 6f saved encryptio
12750 6e 20 6b 65 79 20 66 72 6f 6d 20 70 61 72 65 6e n key from paren
12760 74 20 70 72 6f 63 65 73 73 2e 20 20 54 68 69 73 t process. This
12770 20 69 73 0a 2a 2a 20 20 20 20 20 20 20 20 20 20 is.**
12780 20 20 20 20 20 20 20 20 20 20 6f 6e 6c 79 20 6e only n
12790 65 63 65 73 73 61 72 79 20 77 68 65 6e 20 75 73 ecessary when us
127a0 69 6e 67 20 53 45 45 20 6f 6e 20 57 69 6e 64 6f ing SEE on Windo
127b0 77 73 2e 0a 2a 2a 0a 2a 2a 20 53 65 65 20 61 6c ws..**.** See al
127c0 73 6f 3a 20 63 67 69 2c 20 73 65 72 76 65 72 2c so: cgi, server,
127d0 20 77 69 6e 73 72 76 0a 2a 2f 0a 76 6f 69 64 20 winsrv.*/.void
127e0 63 6d 64 5f 68 74 74 70 28 76 6f 69 64 29 7b 0a cmd_http(void){.
127f0 20 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a 49 const char *zI
12800 70 41 64 64 72 20 3d 20 30 3b 0a 20 20 63 6f 6e pAddr = 0;. con
12810 73 74 20 63 68 61 72 20 2a 7a 4e 6f 74 46 6f 75 st char *zNotFou
12820 6e 64 3b 0a 20 20 63 6f 6e 73 74 20 63 68 61 72 nd;. const char
12830 20 2a 7a 48 6f 73 74 3b 0a 20 20 63 6f 6e 73 74 *zHost;. const
12840 20 63 68 61 72 20 2a 7a 41 6c 74 42 61 73 65 3b char *zAltBase;
12850 0a 20 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a . const char *z
12860 46 69 6c 65 47 6c 6f 62 3b 0a 20 20 69 6e 74 20 FileGlob;. int
12870 75 73 65 53 43 47 49 3b 0a 20 20 69 6e 74 20 6e useSCGI;. int n
12880 6f 4a 61 69 6c 3b 0a 20 20 69 6e 74 20 61 6c 6c oJail;. int all
12890 6f 77 52 65 70 6f 4c 69 73 74 3b 0a 23 69 66 20 owRepoList;.#if
128a0 64 65 66 69 6e 65 64 28 5f 57 49 4e 33 32 29 20 defined(_WIN32)
128b0 26 26 20 55 53 45 5f 53 45 45 0a 20 20 63 6f 6e && USE_SEE. con
128c0 73 74 20 63 68 61 72 20 2a 7a 50 69 64 4b 65 79 st char *zPidKey
128d0 3b 0a 23 65 6e 64 69 66 0a 0a 20 20 54 68 5f 49 ;.#endif.. Th_I
128e0 6e 69 74 54 72 61 63 65 4c 6f 67 28 29 3b 0a 0a nitTraceLog();..
128f0 20 20 2f 2a 20 54 68 65 20 77 69 6e 68 74 74 70 /* The winhttp
12900 20 6d 6f 64 75 6c 65 20 70 61 73 73 65 73 20 74 module passes t
12910 68 65 20 2d 2d 66 69 6c 65 73 20 6f 70 74 69 6f he --files optio
12920 6e 20 61 73 20 2d 2d 66 69 6c 65 73 2d 75 72 6c n as --files-url
12930 65 6e 63 20 77 69 74 68 0a 20 20 2a 2a 20 74 68 enc with. ** th
12940 65 20 61 72 67 75 6d 65 6e 74 20 62 65 69 6e 67 e argument being
12950 20 55 52 4c 20 65 6e 63 6f 64 65 64 2c 20 74 6f URL encoded, to
12960 20 61 76 6f 69 64 20 77 69 6c 64 63 61 72 64 20 avoid wildcard
12970 65 78 70 61 6e 73 69 6f 6e 20 69 6e 20 74 68 65 expansion in the
12980 0a 20 20 2a 2a 20 73 68 65 6c 6c 2e 20 20 54 68 . ** shell. Th
12990 69 73 20 6f 70 74 69 6f 6e 20 69 73 20 66 6f 72 is option is for
129a0 20 69 6e 74 65 72 6e 61 6c 20 75 73 65 20 61 6e internal use an
129b0 64 20 69 73 20 75 6e 64 6f 63 75 6d 65 6e 74 65 d is undocumente
129c0 64 2e 0a 20 20 2a 2f 0a 20 20 7a 46 69 6c 65 47 d.. */. zFileG
129d0 6c 6f 62 20 3d 20 66 69 6e 64 5f 6f 70 74 69 6f lob = find_optio
129e0 6e 28 22 66 69 6c 65 73 2d 75 72 6c 65 6e 63 22 n("files-urlenc"
129f0 2c 30 2c 31 29 3b 0a 20 20 69 66 28 20 7a 46 69 ,0,1);. if( zFi
12a00 6c 65 47 6c 6f 62 20 29 7b 0a 20 20 20 20 63 68 leGlob ){. ch
12a10 61 72 20 2a 7a 20 3d 20 6d 70 72 69 6e 74 66 28 ar *z = mprintf(
12a20 22 25 73 22 2c 20 7a 46 69 6c 65 47 6c 6f 62 29 "%s", zFileGlob)
12a30 3b 0a 20 20 20 20 64 65 68 74 74 70 69 7a 65 28 ;. dehttpize(
12a40 7a 29 3b 0a 20 20 20 20 7a 46 69 6c 65 47 6c 6f z);. zFileGlo
12a50 62 20 3d 20 7a 3b 0a 20 20 7d 65 6c 73 65 7b 0a b = z;. }else{.
12a60 20 20 20 20 7a 46 69 6c 65 47 6c 6f 62 20 3d 20 zFileGlob =
12a70 66 69 6e 64 5f 6f 70 74 69 6f 6e 28 22 66 69 6c find_option("fil
12a80 65 73 22 2c 30 2c 31 29 3b 0a 20 20 7d 0a 20 20 es",0,1);. }.
12a90 73 6b 69 6e 5f 6f 76 65 72 72 69 64 65 28 29 3b skin_override();
12aa0 0a 20 20 7a 4e 6f 74 46 6f 75 6e 64 20 3d 20 66 . zNotFound = f
12ab0 69 6e 64 5f 6f 70 74 69 6f 6e 28 22 6e 6f 74 66 ind_option("notf
12ac0 6f 75 6e 64 22 2c 20 30 2c 20 31 29 3b 0a 20 20 ound", 0, 1);.
12ad0 6e 6f 4a 61 69 6c 20 3d 20 66 69 6e 64 5f 6f 70 noJail = find_op
12ae0 74 69 6f 6e 28 22 6e 6f 6a 61 69 6c 22 2c 30 2c tion("nojail",0,
12af0 30 29 21 3d 30 3b 0a 20 20 61 6c 6c 6f 77 52 65 0)!=0;. allowRe
12b00 70 6f 4c 69 73 74 20 3d 20 66 69 6e 64 5f 6f 70 poList = find_op
12b10 74 69 6f 6e 28 22 72 65 70 6f 6c 69 73 74 22 2c tion("repolist",
12b20 30 2c 30 29 21 3d 30 3b 0a 20 20 67 2e 75 73 65 0,0)!=0;. g.use
12b30 4c 6f 63 61 6c 61 75 74 68 20 3d 20 66 69 6e 64 Localauth = find
12b40 5f 6f 70 74 69 6f 6e 28 22 6c 6f 63 61 6c 61 75 _option("localau
12b50 74 68 22 2c 20 30 2c 20 30 29 21 3d 30 3b 0a 20 th", 0, 0)!=0;.
12b60 20 67 2e 73 73 6c 4e 6f 74 41 76 61 69 6c 61 62 g.sslNotAvailab
12b70 6c 65 20 3d 20 66 69 6e 64 5f 6f 70 74 69 6f 6e le = find_option
12b80 28 22 6e 6f 73 73 6c 22 2c 20 30 2c 20 30 29 21 ("nossl", 0, 0)!
12b90 3d 30 3b 0a 20 20 75 73 65 53 43 47 49 20 3d 20 =0;. useSCGI =
12ba0 66 69 6e 64 5f 6f 70 74 69 6f 6e 28 22 73 63 67 find_option("scg
12bb0 69 22 2c 20 30 2c 20 30 29 21 3d 30 3b 0a 20 20 i", 0, 0)!=0;.
12bc0 7a 41 6c 74 42 61 73 65 20 3d 20 66 69 6e 64 5f zAltBase = find_
12bd0 6f 70 74 69 6f 6e 28 22 62 61 73 65 75 72 6c 22 option("baseurl"
12be0 2c 20 30 2c 20 31 29 3b 0a 20 20 69 66 28 20 7a , 0, 1);. if( z
12bf0 41 6c 74 42 61 73 65 20 29 20 73 65 74 5f 62 61 AltBase ) set_ba
12c00 73 65 5f 75 72 6c 28 7a 41 6c 74 42 61 73 65 29 se_url(zAltBase)
12c10 3b 0a 20 20 69 66 28 20 66 69 6e 64 5f 6f 70 74 ;. if( find_opt
12c20 69 6f 6e 28 22 68 74 74 70 73 22 2c 30 2c 30 29 ion("https",0,0)
12c30 21 3d 30 20 29 7b 0a 20 20 20 20 7a 49 70 41 64 !=0 ){. zIpAd
12c40 64 72 20 3d 20 66 6f 73 73 69 6c 5f 67 65 74 65 dr = fossil_gete
12c50 6e 76 28 22 52 45 4d 4f 54 45 5f 48 4f 53 54 22 nv("REMOTE_HOST"
12c60 29 3b 20 2f 2a 20 46 72 6f 6d 20 73 74 75 6e 6e ); /* From stunn
12c70 65 6c 20 2a 2f 0a 20 20 20 20 63 67 69 5f 72 65 el */. cgi_re
12c80 70 6c 61 63 65 5f 70 61 72 61 6d 65 74 65 72 28 place_parameter(
12c90 22 48 54 54 50 53 22 2c 22 6f 6e 22 29 3b 0a 20 "HTTPS","on");.
12ca0 20 7d 0a 20 20 7a 48 6f 73 74 20 3d 20 66 69 6e }. zHost = fin
12cb0 64 5f 6f 70 74 69 6f 6e 28 22 68 6f 73 74 22 2c d_option("host",
12cc0 20 30 2c 20 31 29 3b 0a 20 20 69 66 28 20 7a 48 0, 1);. if( zH
12cd0 6f 73 74 20 29 20 63 67 69 5f 72 65 70 6c 61 63 ost ) cgi_replac
12ce0 65 5f 70 61 72 61 6d 65 74 65 72 28 22 48 54 54 e_parameter("HTT
12cf0 50 5f 48 4f 53 54 22 2c 7a 48 6f 73 74 29 3b 0a P_HOST",zHost);.
12d00 0a 23 69 66 20 64 65 66 69 6e 65 64 28 5f 57 49 .#if defined(_WI
12d10 4e 33 32 29 20 26 26 20 55 53 45 5f 53 45 45 0a N32) && USE_SEE.
12d20 20 20 7a 50 69 64 4b 65 79 20 3d 20 66 69 6e 64 zPidKey = find
12d30 5f 6f 70 74 69 6f 6e 28 22 75 73 65 70 69 64 6b _option("usepidk
12d40 65 79 22 2c 20 30 2c 20 31 29 3b 0a 20 20 69 66 ey", 0, 1);. if
12d50 28 20 7a 50 69 64 4b 65 79 20 29 7b 0a 20 20 20 ( zPidKey ){.
12d60 20 44 57 4f 52 44 20 70 72 6f 63 65 73 73 49 64 DWORD processId
12d70 20 3d 20 30 3b 0a 20 20 20 20 4c 50 56 4f 49 44 = 0;. LPVOID
12d80 20 70 41 64 64 72 65 73 73 20 3d 20 4e 55 4c 4c pAddress = NULL
12d90 3b 0a 20 20 20 20 53 49 5a 45 5f 54 20 6e 53 69 ;. SIZE_T nSi
12da0 7a 65 20 3d 20 30 3b 0a 20 20 20 20 70 61 72 73 ze = 0;. pars
12db0 65 5f 70 69 64 5f 6b 65 79 5f 76 61 6c 75 65 28 e_pid_key_value(
12dc0 7a 50 69 64 4b 65 79 2c 20 26 70 72 6f 63 65 73 zPidKey, &proces
12dd0 73 49 64 2c 20 26 70 41 64 64 72 65 73 73 2c 20 sId, &pAddress,
12de0 26 6e 53 69 7a 65 29 3b 0a 20 20 20 20 64 62 5f &nSize);. db_
12df0 72 65 61 64 5f 73 61 76 65 64 5f 65 6e 63 72 79 read_saved_encry
12e00 70 74 69 6f 6e 5f 6b 65 79 5f 66 72 6f 6d 5f 70 ption_key_from_p
12e10 72 6f 63 65 73 73 28 70 72 6f 63 65 73 73 49 64 rocess(processId
12e20 2c 20 70 41 64 64 72 65 73 73 2c 20 6e 53 69 7a , pAddress, nSiz
12e30 65 29 3b 0a 20 20 7d 0a 23 65 6e 64 69 66 0a 0a e);. }.#endif..
12e40 20 20 2f 2a 20 57 65 20 73 68 6f 75 6c 64 20 62 /* We should b
12e50 65 20 64 6f 6e 65 20 77 69 74 68 20 6f 70 74 69 e done with opti
12e60 6f 6e 73 2e 2e 20 2a 2f 0a 20 20 76 65 72 69 66 ons.. */. verif
12e70 79 5f 61 6c 6c 5f 6f 70 74 69 6f 6e 73 28 29 3b y_all_options();
12e80 0a 0a 20 20 69 66 28 20 67 2e 61 72 67 63 21 3d .. if( g.argc!=
12e90 32 20 26 26 20 67 2e 61 72 67 63 21 3d 33 20 26 2 && g.argc!=3 &
12ea0 26 20 67 2e 61 72 67 63 21 3d 35 20 26 26 20 67 & g.argc!=5 && g
12eb0 2e 61 72 67 63 21 3d 36 20 29 7b 0a 20 20 20 20 .argc!=6 ){.
12ec0 66 6f 73 73 69 6c 5f 66 61 74 61 6c 28 22 6e 6f fossil_fatal("no
12ed0 20 72 65 70 6f 73 69 74 6f 72 79 20 73 70 65 63 repository spec
12ee0 69 66 69 65 64 22 29 3b 0a 20 20 7d 0a 20 20 67 ified");. }. g
12ef0 2e 63 67 69 4f 75 74 70 75 74 20 3d 20 31 3b 0a .cgiOutput = 1;.
12f00 20 20 67 2e 66 75 6c 6c 48 74 74 70 52 65 70 6c g.fullHttpRepl
12f10 79 20 3d 20 31 3b 0a 20 20 69 66 28 20 67 2e 61 y = 1;. if( g.a
12f20 72 67 63 3e 3d 35 20 29 7b 0a 20 20 20 20 67 2e rgc>=5 ){. g.
12f30 68 74 74 70 49 6e 20 3d 20 66 6f 73 73 69 6c 5f httpIn = fossil_
12f40 66 6f 70 65 6e 28 67 2e 61 72 67 76 5b 32 5d 2c fopen(g.argv[2],
12f50 20 22 72 62 22 29 3b 0a 20 20 20 20 67 2e 68 74 "rb");. g.ht
12f60 74 70 4f 75 74 20 3d 20 66 6f 73 73 69 6c 5f 66 tpOut = fossil_f
12f70 6f 70 65 6e 28 67 2e 61 72 67 76 5b 33 5d 2c 20 open(g.argv[3],
12f80 22 77 62 22 29 3b 0a 20 20 20 20 7a 49 70 41 64 "wb");. zIpAd
12f90 64 72 20 3d 20 67 2e 61 72 67 76 5b 34 5d 3b 0a dr = g.argv[4];.
12fa0 20 20 20 20 66 69 6e 64 5f 73 65 72 76 65 72 5f find_server_
12fb0 72 65 70 6f 73 69 74 6f 72 79 28 35 2c 20 30 29 repository(5, 0)
12fc0 3b 0a 20 20 7d 65 6c 73 65 7b 0a 20 20 20 20 67 ;. }else{. g
12fd0 2e 68 74 74 70 49 6e 20 3d 20 73 74 64 69 6e 3b .httpIn = stdin;
12fe0 0a 20 20 20 20 67 2e 68 74 74 70 4f 75 74 20 3d . g.httpOut =
12ff0 20 73 74 64 6f 75 74 3b 0a 20 20 20 20 66 69 6e stdout;. fin
13000 64 5f 73 65 72 76 65 72 5f 72 65 70 6f 73 69 74 d_server_reposit
13010 6f 72 79 28 32 2c 20 30 29 3b 0a 20 20 7d 0a 20 ory(2, 0);. }.
13020 20 69 66 28 20 7a 49 70 41 64 64 72 3d 3d 30 20 if( zIpAddr==0
13030 29 7b 0a 20 20 20 20 7a 49 70 41 64 64 72 20 3d ){. zIpAddr =
13040 20 63 67 69 5f 73 73 68 5f 72 65 6d 6f 74 65 5f cgi_ssh_remote_
13050 61 64 64 72 28 30 29 3b 0a 20 20 20 20 69 66 28 addr(0);. if(
13060 20 7a 49 70 41 64 64 72 20 26 26 20 7a 49 70 41 zIpAddr && zIpA
13070 64 64 72 5b 30 5d 20 29 7b 0a 20 20 20 20 20 20 ddr[0] ){.
13080 67 2e 66 53 73 68 43 6c 69 65 6e 74 20 7c 3d 20 g.fSshClient |=
13090 43 47 49 5f 53 53 48 5f 43 4c 49 45 4e 54 3b 0a CGI_SSH_CLIENT;.
130a0 20 20 20 20 7d 0a 20 20 7d 0a 20 20 67 2e 7a 52 }. }. g.zR
130b0 65 70 6f 73 69 74 6f 72 79 4e 61 6d 65 20 3d 20 epositoryName =
130c0 65 6e 74 65 72 5f 63 68 72 6f 6f 74 5f 6a 61 69 enter_chroot_jai
130d0 6c 28 67 2e 7a 52 65 70 6f 73 69 74 6f 72 79 4e l(g.zRepositoryN
130e0 61 6d 65 2c 20 6e 6f 4a 61 69 6c 29 3b 0a 20 20 ame, noJail);.
130f0 69 66 28 20 75 73 65 53 43 47 49 20 29 7b 0a 20 if( useSCGI ){.
13100 20 20 20 63 67 69 5f 68 61 6e 64 6c 65 5f 73 63 cgi_handle_sc
13110 67 69 5f 72 65 71 75 65 73 74 28 29 3b 0a 20 20 gi_request();.
13120 7d 65 6c 73 65 20 69 66 28 20 67 2e 66 53 73 68 }else if( g.fSsh
13130 43 6c 69 65 6e 74 20 26 20 43 47 49 5f 53 53 48 Client & CGI_SSH
13140 5f 43 4c 49 45 4e 54 20 29 7b 0a 20 20 20 20 73 _CLIENT ){. s
13150 73 68 5f 72 65 71 75 65 73 74 5f 6c 6f 6f 70 28 sh_request_loop(
13160 7a 49 70 41 64 64 72 2c 20 67 6c 6f 62 5f 63 72 zIpAddr, glob_cr
13170 65 61 74 65 28 7a 46 69 6c 65 47 6c 6f 62 29 29 eate(zFileGlob))
13180 3b 0a 20 20 7d 65 6c 73 65 7b 0a 20 20 20 20 63 ;. }else{. c
13190 67 69 5f 68 61 6e 64 6c 65 5f 68 74 74 70 5f 72 gi_handle_http_r
131a0 65 71 75 65 73 74 28 7a 49 70 41 64 64 72 29 3b equest(zIpAddr);
131b0 0a 20 20 7d 0a 20 20 70 72 6f 63 65 73 73 5f 6f . }. process_o
131c0 6e 65 5f 77 65 62 5f 70 61 67 65 28 7a 4e 6f 74 ne_web_page(zNot
131d0 46 6f 75 6e 64 2c 20 67 6c 6f 62 5f 63 72 65 61 Found, glob_crea
131e0 74 65 28 7a 46 69 6c 65 47 6c 6f 62 29 2c 20 61 te(zFileGlob), a
131f0 6c 6c 6f 77 52 65 70 6f 4c 69 73 74 29 3b 0a 7d llowRepoList);.}
13200 0a 0a 2f 2a 0a 2a 2a 20 50 72 6f 63 65 73 73 20 ../*.** Process
13210 61 6c 6c 20 72 65 71 75 65 73 74 73 20 69 6e 20 all requests in
13220 61 20 73 69 6e 67 6c 65 20 53 53 48 20 63 6f 6e a single SSH con
13230 6e 65 63 74 69 6f 6e 20 69 66 20 70 6f 73 73 69 nection if possi
13240 62 6c 65 2e 0a 2a 2f 0a 76 6f 69 64 20 73 73 68 ble..*/.void ssh
13250 5f 72 65 71 75 65 73 74 5f 6c 6f 6f 70 28 63 6f _request_loop(co
13260 6e 73 74 20 63 68 61 72 20 2a 7a 49 70 41 64 64 nst char *zIpAdd
13270 72 2c 20 47 6c 6f 62 20 2a 46 69 6c 65 47 6c 6f r, Glob *FileGlo
13280 62 29 7b 0a 20 20 62 6c 6f 62 5f 7a 65 72 6f 28 b){. blob_zero(
13290 26 67 2e 63 67 69 49 6e 29 3b 0a 20 20 64 6f 7b &g.cgiIn);. do{
132a0 0a 20 20 20 20 63 67 69 5f 68 61 6e 64 6c 65 5f . cgi_handle_
132b0 73 73 68 5f 68 74 74 70 5f 72 65 71 75 65 73 74 ssh_http_request
132c0 28 7a 49 70 41 64 64 72 29 3b 0a 20 20 20 20 70 (zIpAddr);. p
132d0 72 6f 63 65 73 73 5f 6f 6e 65 5f 77 65 62 5f 70 rocess_one_web_p
132e0 61 67 65 28 30 2c 20 46 69 6c 65 47 6c 6f 62 2c age(0, FileGlob,
132f0 20 30 29 3b 0a 20 20 20 20 62 6c 6f 62 5f 72 65 0);. blob_re
13300 73 65 74 28 26 67 2e 63 67 69 49 6e 29 3b 0a 20 set(&g.cgiIn);.
13310 20 7d 20 77 68 69 6c 65 20 28 20 67 2e 66 53 73 } while ( g.fSs
13320 68 43 6c 69 65 6e 74 20 26 20 43 47 49 5f 53 53 hClient & CGI_SS
13330 48 5f 46 4f 53 53 49 4c 20 7c 7c 0a 20 20 20 20 H_FOSSIL ||.
13340 20 20 20 20 20 20 67 2e 66 53 73 68 43 6c 69 65 g.fSshClie
13350 6e 74 20 26 20 43 47 49 5f 53 53 48 5f 43 4f 4d nt & CGI_SSH_COM
13360 50 41 54 20 29 3b 0a 7d 0a 0a 2f 2a 0a 2a 2a 20 PAT );.}../*.**
13370 4e 6f 74 65 20 74 68 61 74 20 74 68 65 20 66 6f Note that the fo
13380 6c 6c 6f 77 69 6e 67 20 63 6f 6d 6d 61 6e 64 20 llowing command
13390 69 73 20 75 73 65 64 20 62 79 20 73 73 68 3a 2f is used by ssh:/
133a0 2f 20 70 72 6f 63 65 73 73 69 6e 67 2e 0a 2a 2a / processing..**
133b0 0a 2a 2a 20 43 4f 4d 4d 41 4e 44 3a 20 74 65 73 .** COMMAND: tes
133c0 74 2d 68 74 74 70 0a 2a 2a 0a 2a 2a 20 57 6f 72 t-http.**.** Wor
133d0 6b 73 20 6c 69 6b 65 20 74 68 65 20 68 74 74 70 ks like the http
133e0 20 63 6f 6d 6d 61 6e 64 20 62 75 74 20 67 69 76 command but giv
133f0 65 73 20 73 65 74 75 70 20 70 65 72 6d 69 73 73 es setup permiss
13400 69 6f 6e 20 74 6f 20 61 6c 6c 20 75 73 65 72 73 ion to all users
13410 2e 0a 2a 2a 0a 2a 2a 20 4f 70 74 69 6f 6e 73 3a ..**.** Options:
13420 0a 2a 2a 20 20 20 2d 2d 74 68 2d 74 72 61 63 65 .** --th-trace
13430 20 20 20 20 20 20 20 20 20 20 74 72 61 63 65 20 trace
13440 54 48 31 20 65 78 65 63 75 74 69 6f 6e 20 28 66 TH1 execution (f
13450 6f 72 20 64 65 62 75 67 67 69 6e 67 20 70 75 72 or debugging pur
13460 70 6f 73 65 73 29 0a 2a 2a 0a 2a 2f 0a 76 6f 69 poses).**.*/.voi
13470 64 20 63 6d 64 5f 74 65 73 74 5f 68 74 74 70 28 d cmd_test_http(
13480 76 6f 69 64 29 7b 0a 20 20 63 6f 6e 73 74 20 63 void){. const c
13490 68 61 72 20 2a 7a 49 70 41 64 64 72 3b 20 20 20 har *zIpAddr;
134a0 20 2f 2a 20 49 50 20 61 64 64 72 65 73 73 20 6f /* IP address o
134b0 66 20 72 65 6d 6f 74 65 20 63 6c 69 65 6e 74 20 f remote client
134c0 2a 2f 0a 0a 20 20 54 68 5f 49 6e 69 74 54 72 61 */.. Th_InitTra
134d0 63 65 4c 6f 67 28 29 3b 0a 20 20 6c 6f 67 69 6e ceLog();. login
134e0 5f 73 65 74 5f 63 61 70 61 62 69 6c 69 74 69 65 _set_capabilitie
134f0 73 28 22 73 78 22 2c 20 30 29 3b 0a 20 20 67 2e s("sx", 0);. g.
13500 75 73 65 4c 6f 63 61 6c 61 75 74 68 20 3d 20 31 useLocalauth = 1
13510 3b 0a 20 20 67 2e 68 74 74 70 49 6e 20 3d 20 73 ;. g.httpIn = s
13520 74 64 69 6e 3b 0a 20 20 67 2e 68 74 74 70 4f 75 tdin;. g.httpOu
13530 74 20 3d 20 73 74 64 6f 75 74 3b 0a 20 20 66 69 t = stdout;. fi
13540 6e 64 5f 73 65 72 76 65 72 5f 72 65 70 6f 73 69 nd_server_reposi
13550 74 6f 72 79 28 32 2c 20 30 29 3b 0a 20 20 67 2e tory(2, 0);. g.
13560 63 67 69 4f 75 74 70 75 74 20 3d 20 31 3b 0a 20 cgiOutput = 1;.
13570 20 67 2e 66 75 6c 6c 48 74 74 70 52 65 70 6c 79 g.fullHttpReply
13580 20 3d 20 31 3b 0a 20 20 7a 49 70 41 64 64 72 20 = 1;. zIpAddr
13590 3d 20 63 67 69 5f 73 73 68 5f 72 65 6d 6f 74 65 = cgi_ssh_remote
135a0 5f 61 64 64 72 28 30 29 3b 0a 20 20 69 66 28 20 _addr(0);. if(
135b0 7a 49 70 41 64 64 72 20 26 26 20 7a 49 70 41 64 zIpAddr && zIpAd
135c0 64 72 5b 30 5d 20 29 7b 0a 20 20 20 20 67 2e 66 dr[0] ){. g.f
135d0 53 73 68 43 6c 69 65 6e 74 20 7c 3d 20 43 47 49 SshClient |= CGI
135e0 5f 53 53 48 5f 43 4c 49 45 4e 54 3b 0a 20 20 20 _SSH_CLIENT;.
135f0 20 73 73 68 5f 72 65 71 75 65 73 74 5f 6c 6f 6f ssh_request_loo
13600 70 28 7a 49 70 41 64 64 72 2c 20 30 29 3b 0a 20 p(zIpAddr, 0);.
13610 20 7d 65 6c 73 65 7b 0a 20 20 20 20 63 67 69 5f }else{. cgi_
13620 73 65 74 5f 70 61 72 61 6d 65 74 65 72 28 22 52 set_parameter("R
13630 45 4d 4f 54 45 5f 41 44 44 52 22 2c 20 22 31 32 EMOTE_ADDR", "12
13640 37 2e 30 2e 30 2e 31 22 29 3b 0a 20 20 20 20 63 7.0.0.1");. c
13650 67 69 5f 68 61 6e 64 6c 65 5f 68 74 74 70 5f 72 gi_handle_http_r
13660 65 71 75 65 73 74 28 30 29 3b 0a 20 20 20 20 70 equest(0);. p
13670 72 6f 63 65 73 73 5f 6f 6e 65 5f 77 65 62 5f 70 rocess_one_web_p
13680 61 67 65 28 30 2c 20 30 2c 20 30 29 3b 0a 20 20 age(0, 0, 0);.
13690 7d 0a 7d 0a 0a 23 69 66 20 21 64 65 66 69 6e 65 }.}..#if !define
136a0 64 28 5f 57 49 4e 33 32 29 0a 23 69 66 20 21 64 d(_WIN32).#if !d
136b0 65 66 69 6e 65 64 28 5f 5f 44 41 52 57 49 4e 5f efined(__DARWIN_
136c0 5f 29 20 26 26 20 21 64 65 66 69 6e 65 64 28 5f _) && !defined(_
136d0 5f 41 50 50 4c 45 5f 5f 29 20 26 26 20 21 64 65 _APPLE__) && !de
136e0 66 69 6e 65 64 28 5f 5f 48 41 49 4b 55 5f 5f 29 fined(__HAIKU__)
136f0 0a 2f 2a 0a 2a 2a 20 53 65 61 72 63 68 20 66 6f ./*.** Search fo
13700 72 20 61 6e 20 65 78 65 63 75 74 61 62 6c 65 20 r an executable
13710 6f 6e 20 74 68 65 20 50 41 54 48 20 65 6e 76 69 on the PATH envi
13720 72 6f 6e 6d 65 6e 74 20 76 61 72 69 61 62 6c 65 ronment variable
13730 2e 0a 2a 2a 20 52 65 74 75 72 6e 20 74 72 75 65 ..** Return true
13740 20 28 31 29 20 69 66 20 66 6f 75 6e 64 20 61 6e (1) if found an
13750 64 20 66 61 6c 73 65 20 28 30 29 20 69 66 20 6e d false (0) if n
13760 6f 74 20 66 6f 75 6e 64 2e 0a 2a 2f 0a 73 74 61 ot found..*/.sta
13770 74 69 63 20 69 6e 74 20 62 69 6e 61 72 79 4f 6e tic int binaryOn
13780 50 61 74 68 28 63 6f 6e 73 74 20 63 68 61 72 20 Path(const char
13790 2a 7a 42 69 6e 61 72 79 29 7b 0a 20 20 63 6f 6e *zBinary){. con
137a0 73 74 20 63 68 61 72 20 2a 7a 50 61 74 68 20 3d st char *zPath =
137b0 20 66 6f 73 73 69 6c 5f 67 65 74 65 6e 76 28 22 fossil_getenv("
137c0 50 41 54 48 22 29 3b 0a 20 20 63 68 61 72 20 2a PATH");. char *
137d0 7a 46 75 6c 6c 3b 0a 20 20 69 6e 74 20 69 3b 0a zFull;. int i;.
137e0 20 20 69 6e 74 20 62 45 78 69 73 74 73 3b 0a 20 int bExists;.
137f0 20 77 68 69 6c 65 28 20 7a 50 61 74 68 20 26 26 while( zPath &&
13800 20 7a 50 61 74 68 5b 30 5d 20 29 7b 0a 20 20 20 zPath[0] ){.
13810 20 77 68 69 6c 65 28 20 7a 50 61 74 68 5b 30 5d while( zPath[0]
13820 3d 3d 27 3a 27 20 29 20 7a 50 61 74 68 2b 2b 3b ==':' ) zPath++;
13830 0a 20 20 20 20 66 6f 72 28 69 3d 30 3b 20 7a 50 . for(i=0; zP
13840 61 74 68 5b 69 5d 20 26 26 20 7a 50 61 74 68 5b ath[i] && zPath[
13850 69 5d 21 3d 27 3a 27 3b 20 69 2b 2b 29 7b 7d 0a i]!=':'; i++){}.
13860 20 20 20 20 7a 46 75 6c 6c 20 3d 20 6d 70 72 69 zFull = mpri
13870 6e 74 66 28 22 25 2e 2a 73 2f 25 73 22 2c 20 69 ntf("%.*s/%s", i
13880 2c 20 7a 50 61 74 68 2c 20 7a 42 69 6e 61 72 79 , zPath, zBinary
13890 29 3b 0a 20 20 20 20 62 45 78 69 73 74 73 20 3d );. bExists =
138a0 20 66 69 6c 65 5f 61 63 63 65 73 73 28 7a 46 75 file_access(zFu
138b0 6c 6c 2c 20 58 5f 4f 4b 29 3b 0a 20 20 20 20 66 ll, X_OK);. f
138c0 6f 73 73 69 6c 5f 66 72 65 65 28 7a 46 75 6c 6c ossil_free(zFull
138d0 29 3b 0a 20 20 20 20 69 66 28 20 62 45 78 69 73 );. if( bExis
138e0 74 73 3d 3d 30 20 29 20 72 65 74 75 72 6e 20 31 ts==0 ) return 1
138f0 3b 0a 20 20 20 20 7a 50 61 74 68 20 2b 3d 20 69 ;. zPath += i
13900 3b 0a 20 20 7d 0a 20 20 72 65 74 75 72 6e 20 30 ;. }. return 0
13910 3b 0a 7d 0a 23 65 6e 64 69 66 0a 23 65 6e 64 69 ;.}.#endif.#endi
13920 66 0a 0a 2f 2a 0a 2a 2a 20 43 4f 4d 4d 41 4e 44 f../*.** COMMAND
13930 3a 20 73 65 72 76 65 72 2a 0a 2a 2a 20 43 4f 4d : server*.** COM
13940 4d 41 4e 44 3a 20 75 69 0a 2a 2a 0a 2a 2a 20 55 MAND: ui.**.** U
13950 73 61 67 65 3a 20 25 66 6f 73 73 69 6c 20 73 65 sage: %fossil se
13960 72 76 65 72 20 3f 4f 50 54 49 4f 4e 53 3f 20 3f rver ?OPTIONS? ?
13970 52 45 50 4f 53 49 54 4f 52 59 3f 0a 2a 2a 20 20 REPOSITORY?.**
13980 20 20 6f 72 3a 20 25 66 6f 73 73 69 6c 20 75 69 or: %fossil ui
13990 20 3f 4f 50 54 49 4f 4e 53 3f 20 3f 52 45 50 4f ?OPTIONS? ?REPO
139a0 53 49 54 4f 52 59 3f 0a 2a 2a 0a 2a 2a 20 4f 70 SITORY?.**.** Op
139b0 65 6e 20 61 20 73 6f 63 6b 65 74 20 61 6e 64 20 en a socket and
139c0 62 65 67 69 6e 20 6c 69 73 74 65 6e 69 6e 67 20 begin listening
139d0 61 6e 64 20 72 65 73 70 6f 6e 64 69 6e 67 20 74 and responding t
139e0 6f 20 48 54 54 50 20 72 65 71 75 65 73 74 73 20 o HTTP requests
139f0 6f 6e 0a 2a 2a 20 54 43 50 20 70 6f 72 74 20 38 on.** TCP port 8
13a00 30 38 30 2c 20 6f 72 20 6f 6e 20 61 6e 79 20 6f 080, or on any o
13a10 74 68 65 72 20 54 43 50 20 70 6f 72 74 20 64 65 ther TCP port de
13a20 66 69 6e 65 64 20 62 79 20 74 68 65 20 2d 50 20 fined by the -P
13a30 6f 72 0a 2a 2a 20 2d 2d 70 6f 72 74 20 6f 70 74 or.** --port opt
13a40 69 6f 6e 2e 20 20 54 68 65 20 6f 70 74 69 6f 6e ion. The option
13a50 61 6c 20 61 72 67 75 6d 65 6e 74 20 69 73 20 74 al argument is t
13a60 68 65 20 6e 61 6d 65 20 6f 66 20 74 68 65 20 72 he name of the r
13a70 65 70 6f 73 69 74 6f 72 79 2e 0a 2a 2a 20 54 68 epository..** Th
13a80 65 20 72 65 70 6f 73 69 74 6f 72 79 20 61 72 67 e repository arg
13a90 75 6d 65 6e 74 20 6d 61 79 20 62 65 20 6f 6d 69 ument may be omi
13aa0 74 74 65 64 20 69 66 20 74 68 65 20 77 6f 72 6b tted if the work
13ab0 69 6e 67 20 64 69 72 65 63 74 6f 72 79 20 69 73 ing directory is
13ac0 0a 2a 2a 20 77 69 74 68 69 6e 20 61 6e 20 6f 70 .** within an op
13ad0 65 6e 20 63 68 65 63 6b 6f 75 74 2e 0a 2a 2a 0a en checkout..**.
13ae0 2a 2a 20 54 68 65 20 22 75 69 22 20 63 6f 6d 6d ** The "ui" comm
13af0 61 6e 64 20 61 75 74 6f 6d 61 74 69 63 61 6c 6c and automaticall
13b00 79 20 73 74 61 72 74 73 20 61 20 77 65 62 20 62 y starts a web b
13b10 72 6f 77 73 65 72 20 61 66 74 65 72 20 69 6e 69 rowser after ini
13b20 74 69 61 6c 69 7a 69 6e 67 0a 2a 2a 20 74 68 65 tializing.** the
13b30 20 77 65 62 20 73 65 72 76 65 72 2e 20 20 54 68 web server. Th
13b40 65 20 22 75 69 22 20 63 6f 6d 6d 61 6e 64 20 61 e "ui" command a
13b50 6c 73 6f 20 62 69 6e 64 73 20 74 6f 20 31 32 37 lso binds to 127
13b60 2e 30 2e 30 2e 31 20 61 6e 64 20 73 6f 20 77 69 .0.0.1 and so wi
13b70 6c 6c 0a 2a 2a 20 6f 6e 6c 79 20 70 72 6f 63 65 ll.** only proce
13b80 73 73 20 48 54 54 50 20 74 72 61 66 66 69 63 20 ss HTTP traffic
13b90 66 72 6f 6d 20 74 68 65 20 6c 6f 63 61 6c 20 6d from the local m
13ba0 61 63 68 69 6e 65 2e 0a 2a 2a 0a 2a 2a 20 54 68 achine..**.** Th
13bb0 65 20 52 45 50 4f 53 49 54 4f 52 59 20 63 61 6e e REPOSITORY can
13bc0 20 62 65 20 61 20 64 69 72 65 63 74 6f 72 79 20 be a directory
13bd0 28 61 6b 61 20 66 6f 6c 64 65 72 29 20 74 68 61 (aka folder) tha
13be0 74 20 63 6f 6e 74 61 69 6e 73 20 6f 6e 65 20 6f t contains one o
13bf0 72 0a 2a 2a 20 6d 6f 72 65 20 72 65 70 6f 73 69 r.** more reposi
13c00 74 6f 72 69 65 73 20 77 69 74 68 20 6e 61 6d 65 tories with name
13c10 73 20 65 6e 64 69 6e 67 20 69 6e 20 22 2e 66 6f s ending in ".fo
13c20 73 73 69 6c 22 2e 20 20 49 6e 20 74 68 69 73 20 ssil". In this
13c30 63 61 73 65 2c 20 61 0a 2a 2a 20 70 72 65 66 69 case, a.** prefi
13c40 78 20 6f 66 20 74 68 65 20 55 52 4c 20 70 61 74 x of the URL pat
13c50 68 6e 61 6d 65 20 69 73 20 75 73 65 64 20 74 6f hname is used to
13c60 20 73 65 61 72 63 68 20 74 68 65 20 64 69 72 65 search the dire
13c70 63 74 6f 72 79 20 66 6f 72 20 61 6e 0a 2a 2a 20 ctory for an.**
13c80 61 70 70 72 6f 70 72 69 61 74 65 20 72 65 70 6f appropriate repo
13c90 73 69 74 6f 72 79 2e 20 20 54 6f 20 74 68 77 61 sitory. To thwa
13ca0 72 74 20 6d 69 73 63 68 69 65 66 2c 20 74 68 65 rt mischief, the
13cb0 20 70 61 74 68 6e 61 6d 65 20 69 6e 20 74 68 65 pathname in the
13cc0 20 55 52 4c 20 6d 75 73 74 0a 2a 2a 20 63 6f 6e URL must.** con
13cd0 74 61 69 6e 20 6f 6e 6c 79 20 61 6c 70 68 61 6e tain only alphan
13ce0 75 6d 65 72 69 63 73 2c 20 22 5f 22 2c 20 22 2f umerics, "_", "/
13cf0 22 2c 20 22 2d 22 2c 20 61 6e 64 20 22 2e 22 2c ", "-", and ".",
13d00 20 61 6e 64 20 6e 6f 20 22 2d 22 20 6d 61 79 0a and no "-" may.
13d10 2a 2a 20 6f 63 63 75 72 20 61 66 74 65 72 20 22 ** occur after "
13d20 2f 22 2c 20 61 6e 64 20 65 76 65 72 79 20 22 2e /", and every ".
13d30 22 20 6d 75 73 74 20 62 65 20 73 75 72 72 6f 75 " must be surrou
13d40 6e 64 65 64 20 6f 6e 20 62 6f 74 68 20 73 69 64 nded on both sid
13d50 65 73 20 62 79 0a 2a 2a 20 61 6c 70 68 61 6e 75 es by.** alphanu
13d60 6d 65 72 69 63 73 2e 20 20 41 6e 79 20 70 61 74 merics. Any pat
13d70 68 6e 61 6d 65 20 74 68 61 74 20 64 6f 65 73 20 hname that does
13d80 6e 6f 74 20 73 61 74 69 73 66 79 20 74 68 65 73 not satisfy thes
13d90 65 20 63 6f 6e 73 74 72 61 69 6e 74 73 0a 2a 2a e constraints.**
13da0 20 72 65 73 75 6c 74 73 20 69 6e 20 61 20 34 30 results in a 40
13db0 34 20 65 72 72 6f 72 2e 20 20 46 69 6c 65 73 20 4 error. Files
13dc0 69 6e 20 52 45 50 4f 53 49 54 4f 52 59 20 74 68 in REPOSITORY th
13dd0 61 74 20 6d 61 74 63 68 20 74 68 65 20 63 6f 6d at match the com
13de0 6d 61 2d 73 65 70 61 72 61 74 65 64 0a 2a 2a 20 ma-separated.**
13df0 6c 69 73 74 20 6f 66 20 67 6c 6f 62 20 70 61 74 list of glob pat
13e00 74 65 72 6e 73 20 67 69 76 65 6e 20 62 79 20 2d terns given by -
13e10 2d 66 69 6c 65 73 20 61 6e 64 20 74 68 61 74 20 -files and that
13e20 68 61 76 65 20 6b 6e 6f 77 6e 20 73 75 66 66 69 have known suffi
13e30 78 65 73 0a 2a 2a 20 73 75 63 68 20 61 73 20 22 xes.** such as "
13e40 2e 74 78 74 22 20 6f 72 20 22 2e 68 74 6d 6c 22 .txt" or ".html"
13e50 20 6f 72 20 22 2e 6a 70 65 67 22 20 61 6e 64 20 or ".jpeg" and
13e60 64 6f 20 6e 6f 74 20 6d 61 74 63 68 20 74 68 65 do not match the
13e70 20 70 61 74 74 65 72 6e 0a 2a 2a 20 22 2a 2e 66 pattern.** "*.f
13e80 6f 73 73 69 6c 2a 22 20 77 69 6c 6c 20 62 65 20 ossil*" will be
13e90 73 65 72 76 65 64 20 61 73 20 73 74 61 74 69 63 served as static
13ea0 20 63 6f 6e 74 65 6e 74 2e 20 20 57 69 74 68 20 content. With
13eb0 74 68 65 20 22 75 69 22 20 63 6f 6d 6d 61 6e 64 the "ui" command
13ec0 2c 0a 2a 2a 20 74 68 65 20 52 45 50 4f 53 49 54 ,.** the REPOSIT
13ed0 4f 52 59 20 63 61 6e 20 6f 6e 6c 79 20 62 65 20 ORY can only be
13ee0 61 20 64 69 72 65 63 74 6f 72 79 20 69 66 20 74 a directory if t
13ef0 68 65 20 2d 2d 6e 6f 74 66 6f 75 6e 64 20 6f 70 he --notfound op
13f00 74 69 6f 6e 20 69 73 0a 2a 2a 20 61 6c 73 6f 20 tion is.** also
13f10 70 72 65 73 65 6e 74 2e 0a 2a 2a 0a 2a 2a 20 46 present..**.** F
13f20 6f 72 20 74 68 65 20 73 70 65 63 69 61 6c 20 63 or the special c
13f30 61 73 65 20 52 45 50 4f 53 49 54 4f 52 59 20 6e ase REPOSITORY n
13f40 61 6d 65 20 6f 66 20 22 2f 22 2c 20 74 68 65 20 ame of "/", the
13f50 6c 69 73 74 20 67 6c 6f 62 61 6c 20 63 6f 6e 66 list global conf
13f60 69 67 75 72 61 74 69 6f 6e 0a 2a 2a 20 64 61 74 iguration.** dat
13f70 61 62 61 73 65 20 69 73 20 63 6f 6e 73 75 6c 74 abase is consult
13f80 65 64 20 66 6f 72 20 61 20 6c 69 73 74 20 6f 66 ed for a list of
13f90 20 61 6c 6c 20 6b 6e 6f 77 6e 20 72 65 70 6f 73 all known repos
13fa0 69 74 6f 72 69 65 73 2e 20 20 54 68 65 20 2d 2d itories. The --
13fb0 72 65 70 6f 6c 69 73 74 0a 2a 2a 20 6f 70 74 69 repolist.** opti
13fc0 6f 6e 20 69 73 20 69 6d 70 6c 69 65 64 20 62 79 on is implied by
13fd0 20 74 68 69 73 20 73 70 65 63 69 61 6c 20 63 61 this special ca
13fe0 73 65 2e 20 20 53 65 65 20 61 6c 73 6f 20 74 68 se. See also th
13ff0 65 20 22 66 6f 73 73 69 6c 20 61 6c 6c 20 75 69 e "fossil all ui
14000 22 0a 2a 2a 20 63 6f 6d 6d 61 6e 64 2e 0a 2a 2a ".** command..**
14010 0a 2a 2a 20 42 79 20 64 65 66 61 75 6c 74 2c 20 .** By default,
14020 74 68 65 20 22 75 69 22 20 63 6f 6d 6d 61 6e 64 the "ui" command
14030 20 70 72 6f 76 69 64 65 73 20 66 75 6c 6c 20 61 provides full a
14040 64 6d 69 6e 69 73 74 72 61 74 69 76 65 20 61 63 dministrative ac
14050 63 65 73 73 20 77 69 74 68 6f 75 74 0a 2a 2a 20 cess without.**
14060 68 61 76 69 6e 67 20 74 6f 20 6c 6f 67 20 69 6e having to log in
14070 2e 20 20 54 68 69 73 20 63 61 6e 20 62 65 20 64 . This can be d
14080 69 73 61 62 6c 65 64 20 62 79 20 74 75 72 6e 69 isabled by turni
14090 6e 67 20 6f 66 66 20 74 68 65 20 22 6c 6f 63 61 ng off the "loca
140a0 6c 61 75 74 68 22 0a 2a 2a 20 73 65 74 74 69 6e lauth".** settin
140b0 67 2e 20 20 41 75 74 6f 6d 61 74 69 63 20 6c 6f g. Automatic lo
140c0 67 69 6e 20 66 6f 72 20 74 68 65 20 22 73 65 72 gin for the "ser
140d0 76 65 72 22 20 63 6f 6d 6d 61 6e 64 20 69 73 20 ver" command is
140e0 61 76 61 69 6c 61 62 6c 65 20 69 66 20 74 68 65 available if the
140f0 0a 2a 2a 20 2d 2d 6c 6f 63 61 6c 61 75 74 68 20 .** --localauth
14100 6f 70 74 69 6f 6e 20 69 73 20 70 72 65 73 65 6e option is presen
14110 74 20 61 6e 64 20 74 68 65 20 22 6c 6f 63 61 6c t and the "local
14120 61 75 74 68 22 20 73 65 74 74 69 6e 67 20 69 73 auth" setting is
14130 20 6f 66 66 20 61 6e 64 20 74 68 65 0a 2a 2a 20 off and the.**
14140 63 6f 6e 6e 65 63 74 69 6f 6e 20 69 73 20 66 72 connection is fr
14150 6f 6d 20 6c 6f 63 61 6c 68 6f 73 74 2e 20 20 54 om localhost. T
14160 68 65 20 22 75 69 22 20 63 6f 6d 6d 61 6e 64 20 he "ui" command
14170 61 6c 73 6f 20 65 6e 61 62 6c 65 73 20 2d 2d 72 also enables --r
14180 65 70 6f 6c 69 73 74 0a 2a 2a 20 62 79 20 64 65 epolist.** by de
14190 66 61 75 6c 74 2e 0a 2a 2a 0a 2a 2a 20 4f 70 74 fault..**.** Opt
141a0 69 6f 6e 73 3a 0a 2a 2a 20 20 20 2d 2d 62 61 73 ions:.** --bas
141b0 65 75 72 6c 20 55 52 4c 20 20 20 20 20 20 20 55 eurl URL U
141c0 73 65 20 55 52 4c 20 61 73 20 74 68 65 20 62 61 se URL as the ba
141d0 73 65 20 28 75 73 65 66 75 6c 20 66 6f 72 20 72 se (useful for r
141e0 65 76 65 72 73 65 20 70 72 6f 78 69 65 73 29 0a everse proxies).
141f0 2a 2a 20 20 20 2d 2d 63 72 65 61 74 65 20 20 20 ** --create
14200 20 20 20 20 20 20 20 20 20 43 72 65 61 74 65 20 Create
14210 61 20 6e 65 77 20 52 45 50 4f 53 49 54 4f 52 59 a new REPOSITORY
14220 20 69 66 20 69 74 20 64 6f 65 73 20 6e 6f 74 20 if it does not
14230 61 6c 72 65 61 64 79 20 65 78 69 73 74 0a 2a 2a already exist.**
14240 20 20 20 2d 2d 70 61 67 65 20 50 41 47 45 20 20 --page PAGE
14250 20 20 20 20 20 20 20 53 74 61 72 74 20 22 75 69 Start "ui
14260 22 20 6f 6e 20 50 41 47 45 2e 20 20 65 78 3a 20 " on PAGE. ex:
14270 2d 2d 70 61 67 65 20 22 74 69 6d 65 6c 69 6e 65 --page "timeline
14280 3f 79 3d 63 69 22 0a 2a 2a 20 20 20 2d 2d 66 69 ?y=ci".** --fi
14290 6c 65 73 20 47 4c 4f 42 4c 49 53 54 20 20 20 20 les GLOBLIST
142a0 43 6f 6d 6d 61 2d 73 65 70 61 72 61 74 65 64 20 Comma-separated
142b0 6c 69 73 74 20 6f 66 20 67 6c 6f 62 20 70 61 74 list of glob pat
142c0 74 65 72 6e 73 20 66 6f 72 20 73 74 61 74 69 63 terns for static
142d0 20 66 69 6c 65 73 0a 2a 2a 20 20 20 2d 2d 6c 6f files.** --lo
142e0 63 61 6c 61 75 74 68 20 20 20 20 20 20 20 20 20 calauth
142f0 65 6e 61 62 6c 65 20 61 75 74 6f 6d 61 74 69 63 enable automatic
14300 20 6c 6f 67 69 6e 20 66 6f 72 20 72 65 71 75 65 login for reque
14310 73 74 73 20 66 72 6f 6d 20 6c 6f 63 61 6c 68 6f sts from localho
14320 73 74 0a 2a 2a 20 20 20 2d 2d 6c 6f 63 61 6c 68 st.** --localh
14330 6f 73 74 20 20 20 20 20 20 20 20 20 6c 69 73 74 ost list
14340 65 6e 20 6f 6e 20 31 32 37 2e 30 2e 30 2e 31 20 en on 127.0.0.1
14350 6f 6e 6c 79 20 28 61 6c 77 61 79 73 20 74 72 75 only (always tru
14360 65 20 66 6f 72 20 22 75 69 22 29 0a 2a 2a 20 20 e for "ui").**
14370 20 2d 2d 68 74 74 70 73 20 20 20 20 20 20 20 20 --https
14380 20 20 20 20 20 73 69 67 6e 61 6c 20 61 20 72 65 signal a re
14390 71 75 65 73 74 20 63 6f 6d 69 6e 67 20 69 6e 20 quest coming in
143a0 76 69 61 20 68 74 74 70 73 0a 2a 2a 20 20 20 2d via https.** -
143b0 2d 6e 6f 6a 61 69 6c 20 20 20 20 20 20 20 20 20 -nojail
143c0 20 20 20 44 72 6f 70 20 72 6f 6f 74 20 70 72 69 Drop root pri
143d0 76 69 6c 65 67 65 73 20 62 75 74 20 64 6f 20 6e vileges but do n
143e0 6f 74 20 65 6e 74 65 72 20 74 68 65 20 63 68 72 ot enter the chr
143f0 6f 6f 74 20 6a 61 69 6c 0a 2a 2a 20 20 20 2d 2d oot jail.** --
14400 6e 6f 73 73 6c 20 20 20 20 20 20 20 20 20 20 20 nossl
14410 20 20 73 69 67 6e 61 6c 20 74 68 61 74 20 6e 6f signal that no
14420 20 53 53 4c 20 63 6f 6e 6e 65 63 74 69 6f 6e 73 SSL connections
14430 20 61 72 65 20 61 76 61 69 6c 61 62 6c 65 0a 2a are available.*
14440 2a 20 20 20 2d 2d 6e 6f 74 66 6f 75 6e 64 20 55 * --notfound U
14450 52 4c 20 20 20 20 20 20 52 65 64 69 72 65 63 74 RL Redirect
14460 0a 2a 2a 20 20 20 2d 50 7c 2d 2d 70 6f 72 74 20 .** -P|--port
14470 54 43 50 50 4f 52 54 20 20 20 6c 69 73 74 65 6e TCPPORT listen
14480 20 74 6f 20 72 65 71 75 65 73 74 20 6f 6e 20 70 to request on p
14490 6f 72 74 20 54 43 50 50 4f 52 54 0a 2a 2a 20 20 ort TCPPORT.**
144a0 20 2d 2d 74 68 2d 74 72 61 63 65 20 20 20 20 20 --th-trace
144b0 20 20 20 20 20 74 72 61 63 65 20 54 48 31 20 65 trace TH1 e
144c0 78 65 63 75 74 69 6f 6e 20 28 66 6f 72 20 64 65 xecution (for de
144d0 62 75 67 67 69 6e 67 20 70 75 72 70 6f 73 65 73 bugging purposes
144e0 29 0a 2a 2a 20 20 20 2d 2d 72 65 70 6f 6c 69 73 ).** --repolis
144f0 74 20 20 20 20 20 20 20 20 20 20 49 66 20 52 45 t If RE
14500 50 4f 53 49 54 4f 52 59 20 69 73 20 64 69 72 2c POSITORY is dir,
14510 20 55 52 4c 20 22 2f 22 20 6c 69 73 74 73 20 72 URL "/" lists r
14520 65 70 6f 73 2e 0a 2a 2a 20 20 20 2d 2d 73 63 67 epos..** --scg
14530 69 20 20 20 20 20 20 20 20 20 20 20 20 20 20 41 i A
14540 63 63 65 70 74 20 53 43 47 49 20 72 61 74 68 65 ccept SCGI rathe
14550 72 20 74 68 61 6e 20 48 54 54 50 0a 2a 2a 20 20 r than HTTP.**
14560 20 2d 2d 73 6b 69 6e 20 4c 41 42 45 4c 20 20 20 --skin LABEL
14570 20 20 20 20 20 55 73 65 20 6f 76 65 72 72 69 64 Use overrid
14580 65 20 73 6b 69 6e 20 4c 41 42 45 4c 0a 2a 2a 20 e skin LABEL.**
14590 20 20 2d 2d 75 73 65 70 69 64 6b 65 79 20 20 20 --usepidkey
145a0 20 20 20 20 20 20 55 73 65 20 73 61 76 65 64 20 Use saved
145b0 65 6e 63 72 79 70 74 69 6f 6e 20 6b 65 79 20 66 encryption key f
145c0 72 6f 6d 20 70 61 72 65 6e 74 20 70 72 6f 63 65 rom parent proce
145d0 73 73 2e 20 20 54 68 69 73 20 69 73 0a 2a 2a 20 ss. This is.**
145e0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
145f0 20 20 20 20 20 20 6f 6e 6c 79 20 6e 65 63 65 73 only neces
14600 73 61 72 79 20 77 68 65 6e 20 75 73 69 6e 67 20 sary when using
14610 53 45 45 20 6f 6e 20 57 69 6e 64 6f 77 73 2e 0a SEE on Windows..
14620 2a 2a 0a 2a 2a 20 53 65 65 20 61 6c 73 6f 3a 20 **.** See also:
14630 63 67 69 2c 20 68 74 74 70 2c 20 77 69 6e 73 72 cgi, http, winsr
14640 76 0a 2a 2f 0a 76 6f 69 64 20 63 6d 64 5f 77 65 v.*/.void cmd_we
14650 62 73 65 72 76 65 72 28 76 6f 69 64 29 7b 0a 20 bserver(void){.
14660 20 69 6e 74 20 69 50 6f 72 74 2c 20 6d 78 50 6f int iPort, mxPo
14670 72 74 3b 20 20 20 20 20 20 20 20 2f 2a 20 52 61 rt; /* Ra
14680 6e 67 65 20 6f 66 20 54 43 50 20 70 6f 72 74 73 nge of TCP ports
14690 20 61 6c 6c 6f 77 65 64 20 2a 2f 0a 20 20 63 6f allowed */. co
146a0 6e 73 74 20 63 68 61 72 20 2a 7a 50 6f 72 74 3b nst char *zPort;
146b0 20 20 20 20 20 20 20 20 2f 2a 20 56 61 6c 75 65 /* Value
146c0 20 6f 66 20 74 68 65 20 2d 2d 70 6f 72 74 20 6f of the --port o
146d0 70 74 69 6f 6e 20 2a 2f 0a 20 20 63 6f 6e 73 74 ption */. const
146e0 20 63 68 61 72 20 2a 7a 42 72 6f 77 73 65 72 3b char *zBrowser;
146f0 20 20 20 20 20 2f 2a 20 4e 61 6d 65 20 6f 66 20 /* Name of
14700 77 65 62 20 62 72 6f 77 73 65 72 20 70 72 6f 67 web browser prog
14710 72 61 6d 20 2a 2f 0a 20 20 63 68 61 72 20 2a 7a ram */. char *z
14720 42 72 6f 77 73 65 72 43 6d 64 20 3d 20 30 3b 20 BrowserCmd = 0;
14730 20 20 20 2f 2a 20 43 6f 6d 6d 61 6e 64 20 74 6f /* Command to
14740 20 6c 61 75 6e 63 68 20 74 68 65 20 77 65 62 20 launch the web
14750 62 72 6f 77 73 65 72 20 2a 2f 0a 20 20 69 6e 74 browser */. int
14760 20 69 73 55 69 43 6d 64 3b 20 20 20 20 20 20 20 isUiCmd;
14770 20 20 20 20 20 20 20 2f 2a 20 54 72 75 65 20 69 /* True i
14780 66 20 63 6f 6d 6d 61 6e 64 20 69 73 20 22 75 69 f command is "ui
14790 22 2c 20 6e 6f 74 20 22 73 65 72 76 65 72 27 20 ", not "server'
147a0 2a 2f 0a 20 20 63 6f 6e 73 74 20 63 68 61 72 20 */. const char
147b0 2a 7a 4e 6f 74 46 6f 75 6e 64 3b 20 20 20 20 2f *zNotFound; /
147c0 2a 20 54 68 65 20 2d 2d 6e 6f 74 66 6f 75 6e 64 * The --notfound
147d0 20 6f 70 74 69 6f 6e 20 6f 72 20 4e 55 4c 4c 20 option or NULL
147e0 2a 2f 0a 20 20 69 6e 74 20 66 6c 61 67 73 20 3d */. int flags =
147f0 20 30 3b 20 20 20 20 20 20 20 20 20 20 20 20 2f 0; /
14800 2a 20 53 65 72 76 65 72 20 66 6c 61 67 73 20 2a * Server flags *
14810 2f 0a 23 69 66 20 21 64 65 66 69 6e 65 64 28 5f /.#if !defined(_
14820 57 49 4e 33 32 29 0a 20 20 69 6e 74 20 6e 6f 4a WIN32). int noJ
14830 61 69 6c 3b 20 20 20 20 20 20 20 20 20 20 20 20 ail;
14840 20 20 20 2f 2a 20 44 6f 20 6e 6f 74 20 65 6e 74 /* Do not ent
14850 65 72 20 74 68 65 20 63 68 72 6f 6f 74 20 6a 61 er the chroot ja
14860 69 6c 20 2a 2f 0a 23 65 6e 64 69 66 0a 20 20 69 il */.#endif. i
14870 6e 74 20 61 6c 6c 6f 77 52 65 70 6f 4c 69 73 74 nt allowRepoList
14880 3b 20 20 20 20 20 20 20 20 20 2f 2a 20 4c 69 73 ; /* Lis
14890 74 20 72 65 70 6f 73 69 74 6f 72 69 65 73 20 6f t repositories o
148a0 6e 20 55 52 4c 20 22 2f 22 20 2a 2f 0a 20 20 63 n URL "/" */. c
148b0 6f 6e 73 74 20 63 68 61 72 20 2a 7a 41 6c 74 42 onst char *zAltB
148c0 61 73 65 3b 20 20 20 20 20 20 2f 2a 20 41 72 67 ase; /* Arg
148d0 75 6d 65 6e 74 20 74 6f 20 74 68 65 20 2d 2d 62 ument to the --b
148e0 61 73 65 75 72 6c 20 6f 70 74 69 6f 6e 20 2a 2f aseurl option */
148f0 0a 20 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a . const char *z
14900 46 69 6c 65 47 6c 6f 62 3b 20 20 20 20 20 2f 2a FileGlob; /*
14910 20 53 74 61 74 69 63 20 63 6f 6e 74 65 6e 74 20 Static content
14920 6d 75 73 74 20 6d 61 74 63 68 20 74 68 69 73 20 must match this
14930 2a 2f 0a 20 20 63 68 61 72 20 2a 7a 49 70 41 64 */. char *zIpAd
14940 64 72 20 3d 20 30 3b 20 20 20 20 20 20 20 20 20 dr = 0;
14950 2f 2a 20 42 69 6e 64 20 74 6f 20 74 68 69 73 20 /* Bind to this
14960 49 50 20 61 64 64 72 65 73 73 20 2a 2f 0a 20 20 IP address */.
14970 69 6e 74 20 66 43 72 65 61 74 65 20 3d 20 30 3b int fCreate = 0;
14980 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 54 68 /* Th
14990 65 20 2d 2d 63 72 65 61 74 65 20 66 6c 61 67 20 e --create flag
149a0 2a 2f 0a 20 20 63 6f 6e 73 74 20 63 68 61 72 20 */. const char
149b0 2a 7a 49 6e 69 74 50 61 67 65 20 3d 20 30 3b 20 *zInitPage = 0;
149c0 2f 2a 20 53 74 61 72 74 20 6f 6e 20 74 68 69 73 /* Start on this
149d0 20 70 61 67 65 2e 20 20 2d 2d 70 61 67 65 20 6f page. --page o
149e0 70 74 69 6f 6e 20 2a 2f 0a 23 69 66 20 64 65 66 ption */.#if def
149f0 69 6e 65 64 28 5f 57 49 4e 33 32 29 20 26 26 20 ined(_WIN32) &&
14a00 55 53 45 5f 53 45 45 0a 20 20 63 6f 6e 73 74 20 USE_SEE. const
14a10 63 68 61 72 20 2a 7a 50 69 64 4b 65 79 3b 0a 23 char *zPidKey;.#
14a20 65 6e 64 69 66 0a 0a 23 69 66 20 64 65 66 69 6e endif..#if defin
14a30 65 64 28 5f 57 49 4e 33 32 29 0a 20 20 63 6f 6e ed(_WIN32). con
14a40 73 74 20 63 68 61 72 20 2a 7a 53 74 6f 70 70 65 st char *zStoppe
14a50 72 46 69 6c 65 3b 20 20 20 20 2f 2a 20 4e 61 6d rFile; /* Nam
14a60 65 20 6f 66 20 66 69 6c 65 20 75 73 65 64 20 74 e of file used t
14a70 6f 20 74 65 72 6d 69 6e 61 74 65 20 73 65 72 76 o terminate serv
14a80 65 72 20 2a 2f 0a 20 20 7a 53 74 6f 70 70 65 72 er */. zStopper
14a90 46 69 6c 65 20 3d 20 66 69 6e 64 5f 6f 70 74 69 File = find_opti
14aa0 6f 6e 28 22 73 74 6f 70 70 65 72 22 2c 20 30 2c on("stopper", 0,
14ab0 20 31 29 3b 0a 23 65 6e 64 69 66 0a 0a 20 20 7a 1);.#endif.. z
14ac0 46 69 6c 65 47 6c 6f 62 20 3d 20 66 69 6e 64 5f FileGlob = find_
14ad0 6f 70 74 69 6f 6e 28 22 66 69 6c 65 73 2d 75 72 option("files-ur
14ae0 6c 65 6e 63 22 2c 30 2c 31 29 3b 0a 20 20 69 66 lenc",0,1);. if
14af0 28 20 7a 46 69 6c 65 47 6c 6f 62 20 29 7b 0a 20 ( zFileGlob ){.
14b00 20 20 20 63 68 61 72 20 2a 7a 20 3d 20 6d 70 72 char *z = mpr
14b10 69 6e 74 66 28 22 25 73 22 2c 20 7a 46 69 6c 65 intf("%s", zFile
14b20 47 6c 6f 62 29 3b 0a 20 20 20 20 64 65 68 74 74 Glob);. dehtt
14b30 70 69 7a 65 28 7a 29 3b 0a 20 20 20 20 7a 46 69 pize(z);. zFi
14b40 6c 65 47 6c 6f 62 20 3d 20 7a 3b 0a 20 20 7d 65 leGlob = z;. }e
14b50 6c 73 65 7b 0a 20 20 20 20 7a 46 69 6c 65 47 6c lse{. zFileGl
14b60 6f 62 20 3d 20 66 69 6e 64 5f 6f 70 74 69 6f 6e ob = find_option
14b70 28 22 66 69 6c 65 73 22 2c 30 2c 31 29 3b 0a 20 ("files",0,1);.
14b80 20 7d 0a 20 20 73 6b 69 6e 5f 6f 76 65 72 72 69 }. skin_overri
14b90 64 65 28 29 3b 0a 23 69 66 20 21 64 65 66 69 6e de();.#if !defin
14ba0 65 64 28 5f 57 49 4e 33 32 29 0a 20 20 6e 6f 4a ed(_WIN32). noJ
14bb0 61 69 6c 20 3d 20 66 69 6e 64 5f 6f 70 74 69 6f ail = find_optio
14bc0 6e 28 22 6e 6f 6a 61 69 6c 22 2c 30 2c 30 29 21 n("nojail",0,0)!
14bd0 3d 30 3b 0a 23 65 6e 64 69 66 0a 20 20 67 2e 75 =0;.#endif. g.u
14be0 73 65 4c 6f 63 61 6c 61 75 74 68 20 3d 20 66 69 seLocalauth = fi
14bf0 6e 64 5f 6f 70 74 69 6f 6e 28 22 6c 6f 63 61 6c nd_option("local
14c00 61 75 74 68 22 2c 20 30 2c 20 30 29 21 3d 30 3b auth", 0, 0)!=0;
14c10 0a 20 20 54 68 5f 49 6e 69 74 54 72 61 63 65 4c . Th_InitTraceL
14c20 6f 67 28 29 3b 0a 20 20 7a 50 6f 72 74 20 3d 20 og();. zPort =
14c30 66 69 6e 64 5f 6f 70 74 69 6f 6e 28 22 70 6f 72 find_option("por
14c40 74 22 2c 20 22 50 22 2c 20 31 29 3b 0a 20 20 69 t", "P", 1);. i
14c50 73 55 69 43 6d 64 20 3d 20 67 2e 61 72 67 76 5b sUiCmd = g.argv[
14c60 31 5d 5b 30 5d 3d 3d 27 75 27 3b 0a 20 20 69 66 1][0]=='u';. if
14c70 28 20 69 73 55 69 43 6d 64 20 29 7b 0a 20 20 20 ( isUiCmd ){.
14c80 20 7a 49 6e 69 74 50 61 67 65 20 3d 20 66 69 6e zInitPage = fin
14c90 64 5f 6f 70 74 69 6f 6e 28 22 70 61 67 65 22 2c d_option("page",
14ca0 20 30 2c 20 31 29 3b 0a 20 20 7d 0a 20 20 7a 4e 0, 1);. }. zN
14cb0 6f 74 46 6f 75 6e 64 20 3d 20 66 69 6e 64 5f 6f otFound = find_o
14cc0 70 74 69 6f 6e 28 22 6e 6f 74 66 6f 75 6e 64 22 ption("notfound"
14cd0 2c 20 30 2c 20 31 29 3b 0a 20 20 61 6c 6c 6f 77 , 0, 1);. allow
14ce0 52 65 70 6f 4c 69 73 74 20 3d 20 66 69 6e 64 5f RepoList = find_
14cf0 6f 70 74 69 6f 6e 28 22 72 65 70 6f 6c 69 73 74 option("repolist
14d00 22 2c 30 2c 30 29 21 3d 30 3b 0a 20 20 7a 41 6c ",0,0)!=0;. zAl
14d10 74 42 61 73 65 20 3d 20 66 69 6e 64 5f 6f 70 74 tBase = find_opt
14d20 69 6f 6e 28 22 62 61 73 65 75 72 6c 22 2c 20 30 ion("baseurl", 0
14d30 2c 20 31 29 3b 0a 20 20 66 43 72 65 61 74 65 20 , 1);. fCreate
14d40 3d 20 66 69 6e 64 5f 6f 70 74 69 6f 6e 28 22 63 = find_option("c
14d50 72 65 61 74 65 22 2c 30 2c 30 29 21 3d 30 3b 0a reate",0,0)!=0;.
14d60 20 20 69 66 28 20 66 69 6e 64 5f 6f 70 74 69 6f if( find_optio
14d70 6e 28 22 73 63 67 69 22 2c 20 30 2c 20 30 29 21 n("scgi", 0, 0)!
14d80 3d 30 20 29 20 66 6c 61 67 73 20 7c 3d 20 48 54 =0 ) flags |= HT
14d90 54 50 5f 53 45 52 56 45 52 5f 53 43 47 49 3b 0a TP_SERVER_SCGI;.
14da0 20 20 69 66 28 20 7a 41 6c 74 42 61 73 65 20 29 if( zAltBase )
14db0 7b 0a 20 20 20 20 73 65 74 5f 62 61 73 65 5f 75 {. set_base_u
14dc0 72 6c 28 7a 41 6c 74 42 61 73 65 29 3b 0a 20 20 rl(zAltBase);.
14dd0 7d 0a 20 20 67 2e 73 73 6c 4e 6f 74 41 76 61 69 }. g.sslNotAvai
14de0 6c 61 62 6c 65 20 3d 20 66 69 6e 64 5f 6f 70 74 lable = find_opt
14df0 69 6f 6e 28 22 6e 6f 73 73 6c 22 2c 20 30 2c 20 ion("nossl", 0,
14e00 30 29 21 3d 30 3b 0a 20 20 69 66 28 20 66 69 6e 0)!=0;. if( fin
14e10 64 5f 6f 70 74 69 6f 6e 28 22 68 74 74 70 73 22 d_option("https"
14e20 2c 30 2c 30 29 21 3d 30 20 29 7b 0a 20 20 20 20 ,0,0)!=0 ){.
14e30 63 67 69 5f 72 65 70 6c 61 63 65 5f 70 61 72 61 cgi_replace_para
14e40 6d 65 74 65 72 28 22 48 54 54 50 53 22 2c 22 6f meter("HTTPS","o
14e50 6e 22 29 3b 0a 20 20 7d 65 6c 73 65 7b 0a 20 20 n");. }else{.
14e60 20 20 2f 2a 20 77 69 74 68 6f 75 74 20 2d 2d 68 /* without --h
14e70 74 74 70 73 2c 20 64 65 66 61 75 6c 74 73 20 74 ttps, defaults t
14e80 6f 20 6e 6f 74 20 61 76 61 69 6c 61 62 6c 65 2e o not available.
14e90 20 2a 2f 0a 20 20 20 20 67 2e 73 73 6c 4e 6f 74 */. g.sslNot
14ea0 41 76 61 69 6c 61 62 6c 65 20 3d 20 31 3b 0a 20 Available = 1;.
14eb0 20 7d 0a 20 20 69 66 28 20 66 69 6e 64 5f 6f 70 }. if( find_op
14ec0 74 69 6f 6e 28 22 6c 6f 63 61 6c 68 6f 73 74 22 tion("localhost"
14ed0 2c 20 30 2c 20 30 29 21 3d 30 20 29 7b 0a 20 20 , 0, 0)!=0 ){.
14ee0 20 20 66 6c 61 67 73 20 7c 3d 20 48 54 54 50 5f flags |= HTTP_
14ef0 53 45 52 56 45 52 5f 4c 4f 43 41 4c 48 4f 53 54 SERVER_LOCALHOST
14f00 3b 0a 20 20 7d 0a 0a 23 69 66 20 64 65 66 69 6e ;. }..#if defin
14f10 65 64 28 5f 57 49 4e 33 32 29 20 26 26 20 55 53 ed(_WIN32) && US
14f20 45 5f 53 45 45 0a 20 20 7a 50 69 64 4b 65 79 20 E_SEE. zPidKey
14f30 3d 20 66 69 6e 64 5f 6f 70 74 69 6f 6e 28 22 75 = find_option("u
14f40 73 65 70 69 64 6b 65 79 22 2c 20 30 2c 20 31 29 sepidkey", 0, 1)
14f50 3b 0a 20 20 69 66 28 20 7a 50 69 64 4b 65 79 20 ;. if( zPidKey
14f60 29 7b 0a 20 20 20 20 44 57 4f 52 44 20 70 72 6f ){. DWORD pro
14f70 63 65 73 73 49 64 20 3d 20 30 3b 0a 20 20 20 20 cessId = 0;.
14f80 4c 50 56 4f 49 44 20 70 41 64 64 72 65 73 73 20 LPVOID pAddress
14f90 3d 20 4e 55 4c 4c 3b 0a 20 20 20 20 53 49 5a 45 = NULL;. SIZE
14fa0 5f 54 20 6e 53 69 7a 65 20 3d 20 30 3b 0a 20 20 _T nSize = 0;.
14fb0 20 20 70 61 72 73 65 5f 70 69 64 5f 6b 65 79 5f parse_pid_key_
14fc0 76 61 6c 75 65 28 7a 50 69 64 4b 65 79 2c 20 26 value(zPidKey, &
14fd0 70 72 6f 63 65 73 73 49 64 2c 20 26 70 41 64 64 processId, &pAdd
14fe0 72 65 73 73 2c 20 26 6e 53 69 7a 65 29 3b 0a 20 ress, &nSize);.
14ff0 20 20 20 64 62 5f 72 65 61 64 5f 73 61 76 65 64 db_read_saved
15000 5f 65 6e 63 72 79 70 74 69 6f 6e 5f 6b 65 79 5f _encryption_key_
15010 66 72 6f 6d 5f 70 72 6f 63 65 73 73 28 70 72 6f from_process(pro
15020 63 65 73 73 49 64 2c 20 70 41 64 64 72 65 73 73 cessId, pAddress
15030 2c 20 6e 53 69 7a 65 29 3b 0a 20 20 7d 0a 23 65 , nSize);. }.#e
15040 6e 64 69 66 0a 0a 20 20 2f 2a 20 57 65 20 73 68 ndif.. /* We sh
15050 6f 75 6c 64 20 62 65 20 64 6f 6e 65 20 77 69 74 ould be done wit
15060 68 20 6f 70 74 69 6f 6e 73 2e 2e 20 2a 2f 0a 20 h options.. */.
15070 20 76 65 72 69 66 79 5f 61 6c 6c 5f 6f 70 74 69 verify_all_opti
15080 6f 6e 73 28 29 3b 0a 0a 20 20 69 66 28 20 67 2e ons();.. if( g.
15090 61 72 67 63 21 3d 32 20 26 26 20 67 2e 61 72 67 argc!=2 && g.arg
150a0 63 21 3d 33 20 29 20 75 73 61 67 65 28 22 3f 52 c!=3 ) usage("?R
150b0 45 50 4f 53 49 54 4f 52 59 3f 22 29 3b 0a 20 20 EPOSITORY?");.
150c0 69 66 28 20 69 73 55 69 43 6d 64 20 29 7b 0a 20 if( isUiCmd ){.
150d0 20 20 20 66 6c 61 67 73 20 7c 3d 20 48 54 54 50 flags |= HTTP
150e0 5f 53 45 52 56 45 52 5f 4c 4f 43 41 4c 48 4f 53 _SERVER_LOCALHOS
150f0 54 7c 48 54 54 50 5f 53 45 52 56 45 52 5f 52 45 T|HTTP_SERVER_RE
15100 50 4f 4c 49 53 54 3b 0a 20 20 20 20 67 2e 75 73 POLIST;. g.us
15110 65 4c 6f 63 61 6c 61 75 74 68 20 3d 20 31 3b 0a eLocalauth = 1;.
15120 20 20 20 20 61 6c 6c 6f 77 52 65 70 6f 4c 69 73 allowRepoLis
15130 74 20 3d 20 31 3b 0a 20 20 7d 0a 20 20 66 69 6e t = 1;. }. fin
15140 64 5f 73 65 72 76 65 72 5f 72 65 70 6f 73 69 74 d_server_reposit
15150 6f 72 79 28 32 2c 20 66 43 72 65 61 74 65 29 3b ory(2, fCreate);
15160 0a 20 20 69 66 28 20 7a 49 6e 69 74 50 61 67 65 . if( zInitPage
15170 3d 3d 30 20 29 7b 0a 20 20 20 20 69 66 28 20 69 ==0 ){. if( i
15180 73 55 69 43 6d 64 20 26 26 20 67 2e 6c 6f 63 61 sUiCmd && g.loca
15190 6c 4f 70 65 6e 20 29 7b 0a 20 20 20 20 20 20 7a lOpen ){. z
151a0 49 6e 69 74 50 61 67 65 20 3d 20 22 74 69 6d 65 InitPage = "time
151b0 6c 69 6e 65 3f 63 3d 63 75 72 72 65 6e 74 22 3b line?c=current";
151c0 0a 20 20 20 20 7d 65 6c 73 65 7b 0a 20 20 20 20 . }else{.
151d0 20 20 7a 49 6e 69 74 50 61 67 65 20 3d 20 22 22 zInitPage = ""
151e0 3b 0a 20 20 20 20 7d 0a 20 20 7d 0a 20 20 69 66 ;. }. }. if
151f0 28 20 7a 50 6f 72 74 20 29 7b 0a 20 20 20 20 69 ( zPort ){. i
15200 6e 74 20 69 3b 0a 20 20 20 20 66 6f 72 28 69 3d nt i;. for(i=
15210 73 74 72 6c 65 6e 28 7a 50 6f 72 74 29 2d 31 3b strlen(zPort)-1;
15220 20 69 3e 3d 30 20 26 26 20 7a 50 6f 72 74 5b 69 i>=0 && zPort[i
15230 5d 21 3d 27 3a 27 3b 20 69 2d 2d 29 7b 7d 0a 20 ]!=':'; i--){}.
15240 20 20 20 69 66 28 20 69 3e 30 20 29 7b 0a 20 20 if( i>0 ){.
15250 20 20 20 20 7a 49 70 41 64 64 72 20 3d 20 6d 70 zIpAddr = mp
15260 72 69 6e 74 66 28 22 25 2e 2a 73 22 2c 20 69 2c rintf("%.*s", i,
15270 20 7a 50 6f 72 74 29 3b 0a 20 20 20 20 20 20 7a zPort);. z
15280 50 6f 72 74 20 2b 3d 20 69 2b 31 3b 0a 20 20 20 Port += i+1;.
15290 20 7d 0a 20 20 20 20 69 50 6f 72 74 20 3d 20 6d }. iPort = m
152a0 78 50 6f 72 74 20 3d 20 61 74 6f 69 28 7a 50 6f xPort = atoi(zPo
152b0 72 74 29 3b 0a 20 20 7d 65 6c 73 65 7b 0a 20 20 rt);. }else{.
152c0 20 20 69 50 6f 72 74 20 3d 20 64 62 5f 67 65 74 iPort = db_get
152d0 5f 69 6e 74 28 22 68 74 74 70 2d 70 6f 72 74 22 _int("http-port"
152e0 2c 20 38 30 38 30 29 3b 0a 20 20 20 20 6d 78 50 , 8080);. mxP
152f0 6f 72 74 20 3d 20 69 50 6f 72 74 2b 31 30 30 3b ort = iPort+100;
15300 0a 20 20 7d 0a 23 69 66 20 21 64 65 66 69 6e 65 . }.#if !define
15310 64 28 5f 57 49 4e 33 32 29 0a 20 20 2f 2a 20 55 d(_WIN32). /* U
15320 6e 69 78 20 69 6d 70 6c 65 6d 65 6e 74 61 74 69 nix implementati
15330 6f 6e 20 2a 2f 0a 20 20 69 66 28 20 69 73 55 69 on */. if( isUi
15340 43 6d 64 20 29 7b 0a 23 69 66 20 21 64 65 66 69 Cmd ){.#if !defi
15350 6e 65 64 28 5f 5f 44 41 52 57 49 4e 5f 5f 29 20 ned(__DARWIN__)
15360 26 26 20 21 64 65 66 69 6e 65 64 28 5f 5f 41 50 && !defined(__AP
15370 50 4c 45 5f 5f 29 20 26 26 20 21 64 65 66 69 6e PLE__) && !defin
15380 65 64 28 5f 5f 48 41 49 4b 55 5f 5f 29 0a 20 20 ed(__HAIKU__).
15390 20 20 7a 42 72 6f 77 73 65 72 20 3d 20 64 62 5f zBrowser = db_
153a0 67 65 74 28 22 77 65 62 2d 62 72 6f 77 73 65 72 get("web-browser
153b0 22 2c 20 30 29 3b 0a 20 20 20 20 69 66 28 20 7a ", 0);. if( z
153c0 42 72 6f 77 73 65 72 3d 3d 30 20 29 7b 0a 20 20 Browser==0 ){.
153d0 20 20 20 20 73 74 61 74 69 63 20 63 6f 6e 73 74 static const
153e0 20 63 68 61 72 20 2a 63 6f 6e 73 74 20 61 7a 42 char *const azB
153f0 72 6f 77 73 65 72 50 72 6f 67 5b 5d 20 3d 0a 20 rowserProg[] =.
15400 20 20 20 20 20 20 20 20 20 7b 20 22 78 64 67 2d { "xdg-
15410 6f 70 65 6e 22 2c 20 22 67 6e 6f 6d 65 2d 6f 70 open", "gnome-op
15420 65 6e 22 2c 20 22 66 69 72 65 66 6f 78 22 2c 20 en", "firefox",
15430 22 67 6f 6f 67 6c 65 2d 63 68 72 6f 6d 65 22 20 "google-chrome"
15440 7d 3b 0a 20 20 20 20 20 20 69 6e 74 20 69 3b 0a };. int i;.
15450 20 20 20 20 20 20 7a 42 72 6f 77 73 65 72 20 3d zBrowser =
15460 20 22 65 63 68 6f 22 3b 0a 20 20 20 20 20 20 66 "echo";. f
15470 6f 72 28 69 3d 30 3b 20 69 3c 63 6f 75 6e 74 28 or(i=0; i<count(
15480 61 7a 42 72 6f 77 73 65 72 50 72 6f 67 29 3b 20 azBrowserProg);
15490 69 2b 2b 29 7b 0a 20 20 20 20 20 20 20 20 69 66 i++){. if
154a0 28 20 62 69 6e 61 72 79 4f 6e 50 61 74 68 28 61 ( binaryOnPath(a
154b0 7a 42 72 6f 77 73 65 72 50 72 6f 67 5b 69 5d 29 zBrowserProg[i])
154c0 20 29 7b 0a 20 20 20 20 20 20 20 20 20 20 7a 42 ){. zB
154d0 72 6f 77 73 65 72 20 3d 20 61 7a 42 72 6f 77 73 rowser = azBrows
154e0 65 72 50 72 6f 67 5b 69 5d 3b 0a 20 20 20 20 20 erProg[i];.
154f0 20 20 20 20 20 62 72 65 61 6b 3b 0a 20 20 20 20 break;.
15500 20 20 20 20 7d 0a 20 20 20 20 20 20 7d 0a 20 20 }. }.
15510 20 20 7d 0a 23 65 6c 73 65 0a 20 20 20 20 7a 42 }.#else. zB
15520 72 6f 77 73 65 72 20 3d 20 64 62 5f 67 65 74 28 rowser = db_get(
15530 22 77 65 62 2d 62 72 6f 77 73 65 72 22 2c 20 22 "web-browser", "
15540 6f 70 65 6e 22 29 3b 0a 23 65 6e 64 69 66 0a 20 open");.#endif.
15550 20 20 20 69 66 28 20 7a 49 70 41 64 64 72 20 29 if( zIpAddr )
15560 7b 0a 20 20 20 20 20 20 7a 42 72 6f 77 73 65 72 {. zBrowser
15570 43 6d 64 20 3d 20 6d 70 72 69 6e 74 66 28 22 25 Cmd = mprintf("%
15580 73 20 68 74 74 70 3a 2f 2f 25 73 3a 25 25 64 2f s http://%s:%%d/
15590 25 73 20 26 22 2c 0a 20 20 20 20 20 20 20 20 20 %s &",.
155a0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
155b0 20 20 20 7a 42 72 6f 77 73 65 72 2c 20 7a 49 70 zBrowser, zIp
155c0 41 64 64 72 2c 20 7a 49 6e 69 74 50 61 67 65 29 Addr, zInitPage)
155d0 3b 0a 20 20 20 20 7d 65 6c 73 65 7b 0a 20 20 20 ;. }else{.
155e0 20 20 20 7a 42 72 6f 77 73 65 72 43 6d 64 20 3d zBrowserCmd =
155f0 20 6d 70 72 69 6e 74 66 28 22 25 73 20 68 74 74 mprintf("%s htt
15600 70 3a 2f 2f 6c 6f 63 61 6c 68 6f 73 74 3a 25 25 p://localhost:%%
15610 64 2f 25 73 20 26 22 2c 0a 20 20 20 20 20 20 20 d/%s &",.
15620 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
15630 20 20 20 20 20 7a 42 72 6f 77 73 65 72 2c 20 7a zBrowser, z
15640 49 6e 69 74 50 61 67 65 29 3b 0a 20 20 20 20 7d InitPage);. }
15650 0a 20 20 7d 0a 20 20 69 66 28 20 67 2e 72 65 70 . }. if( g.rep
15660 6f 73 69 74 6f 72 79 4f 70 65 6e 20 29 20 66 6c ositoryOpen ) fl
15670 61 67 73 20 7c 3d 20 48 54 54 50 5f 53 45 52 56 ags |= HTTP_SERV
15680 45 52 5f 48 41 44 5f 52 45 50 4f 53 49 54 4f 52 ER_HAD_REPOSITOR
15690 59 3b 0a 20 20 69 66 28 20 67 2e 6c 6f 63 61 6c Y;. if( g.local
156a0 4f 70 65 6e 20 29 20 66 6c 61 67 73 20 7c 3d 20 Open ) flags |=
156b0 48 54 54 50 5f 53 45 52 56 45 52 5f 48 41 44 5f HTTP_SERVER_HAD_
156c0 43 48 45 43 4b 4f 55 54 3b 0a 20 20 64 62 5f 63 CHECKOUT;. db_c
156d0 6c 6f 73 65 28 31 29 3b 0a 20 20 69 66 28 20 63 lose(1);. if( c
156e0 67 69 5f 68 74 74 70 5f 73 65 72 76 65 72 28 69 gi_http_server(i
156f0 50 6f 72 74 2c 20 6d 78 50 6f 72 74 2c 20 7a 42 Port, mxPort, zB
15700 72 6f 77 73 65 72 43 6d 64 2c 20 7a 49 70 41 64 rowserCmd, zIpAd
15710 64 72 2c 20 66 6c 61 67 73 29 20 29 7b 0a 20 20 dr, flags) ){.
15720 20 20 66 6f 73 73 69 6c 5f 66 61 74 61 6c 28 22 fossil_fatal("
15730 75 6e 61 62 6c 65 20 74 6f 20 6c 69 73 74 65 6e unable to listen
15740 20 6f 6e 20 54 43 50 20 73 6f 63 6b 65 74 20 25 on TCP socket %
15750 64 22 2c 20 69 50 6f 72 74 29 3b 0a 20 20 7d 0a d", iPort);. }.
15760 20 20 67 2e 68 74 74 70 49 6e 20 3d 20 73 74 64 g.httpIn = std
15770 69 6e 3b 0a 20 20 67 2e 68 74 74 70 4f 75 74 20 in;. g.httpOut
15780 3d 20 73 74 64 6f 75 74 3b 0a 20 20 69 66 28 20 = stdout;. if(
15790 67 2e 66 48 74 74 70 54 72 61 63 65 20 7c 7c 20 g.fHttpTrace ||
157a0 67 2e 66 53 71 6c 54 72 61 63 65 20 29 7b 0a 20 g.fSqlTrace ){.
157b0 20 20 20 66 70 72 69 6e 74 66 28 73 74 64 65 72 fprintf(stder
157c0 72 2c 20 22 3d 3d 3d 3d 3d 3d 20 53 45 52 56 45 r, "====== SERVE
157d0 52 20 70 69 64 20 25 64 20 3d 3d 3d 3d 3d 3d 3d R pid %d =======
157e0 5c 6e 22 2c 20 67 65 74 70 69 64 28 29 29 3b 0a \n", getpid());.
157f0 20 20 7d 0a 20 20 67 2e 63 67 69 4f 75 74 70 75 }. g.cgiOutpu
15800 74 20 3d 20 31 3b 0a 20 20 66 69 6e 64 5f 73 65 t = 1;. find_se
15810 72 76 65 72 5f 72 65 70 6f 73 69 74 6f 72 79 28 rver_repository(
15820 32 2c 20 30 29 3b 0a 20 20 69 66 28 20 66 6f 73 2, 0);. if( fos
15830 73 69 6c 5f 73 74 72 63 6d 70 28 67 2e 7a 52 65 sil_strcmp(g.zRe
15840 70 6f 73 69 74 6f 72 79 4e 61 6d 65 2c 22 2f 22 positoryName,"/"
15850 29 3d 3d 30 20 29 7b 0a 20 20 20 20 61 6c 6c 6f )==0 ){. allo
15860 77 52 65 70 6f 4c 69 73 74 20 3d 20 31 3b 0a 20 wRepoList = 1;.
15870 20 7d 65 6c 73 65 7b 0a 20 20 20 20 67 2e 7a 52 }else{. g.zR
15880 65 70 6f 73 69 74 6f 72 79 4e 61 6d 65 20 3d 20 epositoryName =
15890 65 6e 74 65 72 5f 63 68 72 6f 6f 74 5f 6a 61 69 enter_chroot_jai
158a0 6c 28 67 2e 7a 52 65 70 6f 73 69 74 6f 72 79 4e l(g.zRepositoryN
158b0 61 6d 65 2c 20 6e 6f 4a 61 69 6c 29 3b 0a 20 20 ame, noJail);.
158c0 7d 0a 20 20 69 66 28 20 66 6c 61 67 73 20 26 20 }. if( flags &
158d0 48 54 54 50 5f 53 45 52 56 45 52 5f 53 43 47 49 HTTP_SERVER_SCGI
158e0 20 29 7b 0a 20 20 20 20 63 67 69 5f 68 61 6e 64 ){. cgi_hand
158f0 6c 65 5f 73 63 67 69 5f 72 65 71 75 65 73 74 28 le_scgi_request(
15900 29 3b 0a 20 20 7d 65 6c 73 65 7b 0a 20 20 20 20 );. }else{.
15910 63 67 69 5f 68 61 6e 64 6c 65 5f 68 74 74 70 5f cgi_handle_http_
15920 72 65 71 75 65 73 74 28 30 29 3b 0a 20 20 7d 0a request(0);. }.
15930 20 20 70 72 6f 63 65 73 73 5f 6f 6e 65 5f 77 65 process_one_we
15940 62 5f 70 61 67 65 28 7a 4e 6f 74 46 6f 75 6e 64 b_page(zNotFound
15950 2c 20 67 6c 6f 62 5f 63 72 65 61 74 65 28 7a 46 , glob_create(zF
15960 69 6c 65 47 6c 6f 62 29 2c 20 61 6c 6c 6f 77 52 ileGlob), allowR
15970 65 70 6f 4c 69 73 74 29 3b 0a 23 65 6c 73 65 0a epoList);.#else.
15980 20 20 2f 2a 20 57 69 6e 33 32 20 69 6d 70 6c 65 /* Win32 imple
15990 6d 65 6e 74 61 74 69 6f 6e 20 2a 2f 0a 20 20 69 mentation */. i
159a0 66 28 20 69 73 55 69 43 6d 64 20 29 7b 0a 20 20 f( isUiCmd ){.
159b0 20 20 7a 42 72 6f 77 73 65 72 20 3d 20 64 62 5f zBrowser = db_
159c0 67 65 74 28 22 77 65 62 2d 62 72 6f 77 73 65 72 get("web-browser
159d0 22 2c 20 22 73 74 61 72 74 22 29 3b 0a 20 20 20 ", "start");.
159e0 20 69 66 28 20 7a 49 70 41 64 64 72 20 29 7b 0a if( zIpAddr ){.
159f0 20 20 20 20 20 20 7a 42 72 6f 77 73 65 72 43 6d zBrowserCm
15a00 64 20 3d 20 6d 70 72 69 6e 74 66 28 22 25 73 20 d = mprintf("%s
15a10 68 74 74 70 3a 2f 2f 25 73 3a 25 25 64 2f 25 73 http://%s:%%d/%s
15a20 20 26 22 2c 0a 20 20 20 20 20 20 20 20 20 20 20 &",.
15a30 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
15a40 20 7a 42 72 6f 77 73 65 72 2c 20 7a 49 70 41 64 zBrowser, zIpAd
15a50 64 72 2c 20 7a 49 6e 69 74 50 61 67 65 29 3b 0a dr, zInitPage);.
15a60 20 20 20 20 7d 65 6c 73 65 7b 0a 20 20 20 20 20 }else{.
15a70 20 7a 42 72 6f 77 73 65 72 43 6d 64 20 3d 20 6d zBrowserCmd = m
15a80 70 72 69 6e 74 66 28 22 25 73 20 68 74 74 70 3a printf("%s http:
15a90 2f 2f 6c 6f 63 61 6c 68 6f 73 74 3a 25 25 64 2f //localhost:%%d/
15aa0 25 73 20 26 22 2c 0a 20 20 20 20 20 20 20 20 20 %s &",.
15ab0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
15ac0 20 20 20 7a 42 72 6f 77 73 65 72 2c 20 7a 49 6e zBrowser, zIn
15ad0 69 74 50 61 67 65 29 3b 0a 20 20 20 20 7d 0a 20 itPage);. }.
15ae0 20 7d 0a 20 20 69 66 28 20 67 2e 72 65 70 6f 73 }. if( g.repos
15af0 69 74 6f 72 79 4f 70 65 6e 20 29 20 66 6c 61 67 itoryOpen ) flag
15b00 73 20 7c 3d 20 48 54 54 50 5f 53 45 52 56 45 52 s |= HTTP_SERVER
15b10 5f 48 41 44 5f 52 45 50 4f 53 49 54 4f 52 59 3b _HAD_REPOSITORY;
15b20 0a 20 20 69 66 28 20 67 2e 6c 6f 63 61 6c 4f 70 . if( g.localOp
15b30 65 6e 20 29 20 66 6c 61 67 73 20 7c 3d 20 48 54 en ) flags |= HT
15b40 54 50 5f 53 45 52 56 45 52 5f 48 41 44 5f 43 48 TP_SERVER_HAD_CH
15b50 45 43 4b 4f 55 54 3b 0a 20 20 64 62 5f 63 6c 6f ECKOUT;. db_clo
15b60 73 65 28 31 29 3b 0a 20 20 69 66 28 20 61 6c 6c se(1);. if( all
15b70 6f 77 52 65 70 6f 4c 69 73 74 20 29 7b 0a 20 20 owRepoList ){.
15b80 20 20 66 6c 61 67 73 20 7c 3d 20 48 54 54 50 5f flags |= HTTP_
15b90 53 45 52 56 45 52 5f 52 45 50 4f 4c 49 53 54 3b SERVER_REPOLIST;
15ba0 0a 20 20 7d 0a 20 20 69 66 28 20 77 69 6e 33 32 . }. if( win32
15bb0 5f 68 74 74 70 5f 73 65 72 76 69 63 65 28 69 50 _http_service(iP
15bc0 6f 72 74 2c 20 7a 41 6c 74 42 61 73 65 2c 20 7a ort, zAltBase, z
15bd0 4e 6f 74 46 6f 75 6e 64 2c 20 7a 46 69 6c 65 47 NotFound, zFileG
15be0 6c 6f 62 2c 20 66 6c 61 67 73 29 20 29 7b 0a 20 lob, flags) ){.
15bf0 20 20 20 77 69 6e 33 32 5f 68 74 74 70 5f 73 65 win32_http_se
15c00 72 76 65 72 28 69 50 6f 72 74 2c 20 6d 78 50 6f rver(iPort, mxPo
15c10 72 74 2c 20 7a 42 72 6f 77 73 65 72 43 6d 64 2c rt, zBrowserCmd,
15c20 20 7a 53 74 6f 70 70 65 72 46 69 6c 65 2c 0a 20 zStopperFile,.
15c30 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
15c40 20 20 20 20 20 7a 41 6c 74 42 61 73 65 2c 20 7a zAltBase, z
15c50 4e 6f 74 46 6f 75 6e 64 2c 20 7a 46 69 6c 65 47 NotFound, zFileG
15c60 6c 6f 62 2c 20 7a 49 70 41 64 64 72 2c 20 66 6c lob, zIpAddr, fl
15c70 61 67 73 29 3b 0a 20 20 7d 0a 23 65 6e 64 69 66 ags);. }.#endif
15c80 0a 7d 0a 0a 2f 2a 0a 2a 2a 20 43 4f 4d 4d 41 4e .}../*.** COMMAN
15c90 44 3a 20 74 65 73 74 2d 65 63 68 6f 0a 2a 2a 0a D: test-echo.**.
15ca0 2a 2a 20 55 73 61 67 65 3a 20 20 25 66 6f 73 73 ** Usage: %foss
15cb0 69 6c 20 74 65 73 74 2d 65 63 68 6f 20 5b 2d 2d il test-echo [--
15cc0 68 65 78 5d 20 41 52 47 53 2e 2e 2e 0a 2a 2a 0a hex] ARGS....**.
15cd0 2a 2a 20 45 63 68 6f 20 61 6c 6c 20 63 6f 6d 6d ** Echo all comm
15ce0 61 6e 64 2d 6c 69 6e 65 20 61 72 67 75 6d 65 6e and-line argumen
15cf0 74 73 20 28 65 6e 63 6c 6f 73 65 64 20 69 6e 20 ts (enclosed in
15d00 5b 2e 2e 2e 5d 29 20 74 6f 20 74 68 65 20 73 63 [...]) to the sc
15d10 72 65 65 6e 20 73 6f 20 74 68 61 74 0a 2a 2a 20 reen so that.**
15d20 77 69 6c 64 63 61 72 64 20 65 78 70 61 6e 73 69 wildcard expansi
15d30 6f 6e 20 62 65 68 61 76 69 6f 72 20 6f 66 20 74 on behavior of t
15d40 68 65 20 68 6f 73 74 20 73 68 65 6c 6c 20 63 61 he host shell ca
15d50 6e 20 62 65 20 69 6e 76 65 73 74 69 67 61 74 65 n be investigate
15d60 64 2e 0a 2a 2a 0a 2a 2a 20 57 69 74 68 20 74 68 d..**.** With th
15d70 65 20 2d 2d 68 65 78 20 6f 70 74 69 6f 6e 2c 20 e --hex option,
15d80 73 68 6f 77 20 74 68 65 20 6f 75 74 70 75 74 20 show the output
15d90 61 73 20 68 65 78 61 64 65 63 69 6d 61 6c 2e 20 as hexadecimal.
15da0 20 54 68 69 73 20 63 61 6e 20 62 65 20 75 73 65 This can be use
15db0 64 0a 2a 2a 20 74 6f 20 76 65 72 69 66 79 20 74 d.** to verify t
15dc0 68 65 20 66 6f 73 73 69 6c 5f 70 61 74 68 5f 74 he fossil_path_t
15dd0 6f 5f 75 74 66 38 28 29 20 72 6f 75 74 69 6e 65 o_utf8() routine
15de0 20 6f 6e 20 57 69 6e 64 6f 77 73 20 61 6e 64 20 on Windows and
15df0 4d 61 63 2e 0a 2a 2f 0a 76 6f 69 64 20 74 65 73 Mac..*/.void tes
15e00 74 5f 65 63 68 6f 5f 63 6d 64 28 76 6f 69 64 29 t_echo_cmd(void)
15e10 7b 0a 20 20 69 6e 74 20 69 2c 20 6a 3b 0a 20 20 {. int i, j;.
15e20 69 66 28 20 66 69 6e 64 5f 6f 70 74 69 6f 6e 28 if( find_option(
15e30 22 68 65 78 22 2c 30 2c 30 29 3d 3d 30 20 29 7b "hex",0,0)==0 ){
15e40 0a 20 20 20 20 66 6f 73 73 69 6c 5f 70 72 69 6e . fossil_prin
15e50 74 28 22 67 2e 6e 61 6d 65 4f 66 45 78 65 20 3d t("g.nameOfExe =
15e60 20 5b 25 73 5d 5c 6e 22 2c 20 67 2e 6e 61 6d 65 [%s]\n", g.name
15e70 4f 66 45 78 65 29 3b 0a 20 20 20 20 66 6f 72 28 OfExe);. for(
15e80 69 3d 30 3b 20 69 3c 67 2e 61 72 67 63 3b 20 69 i=0; i<g.argc; i
15e90 2b 2b 29 7b 0a 20 20 20 20 20 20 66 6f 73 73 69 ++){. fossi
15ea0 6c 5f 70 72 69 6e 74 28 22 61 72 67 76 5b 25 64 l_print("argv[%d
15eb0 5d 20 3d 20 5b 25 73 5d 5c 6e 22 2c 20 69 2c 20 ] = [%s]\n", i,
15ec0 67 2e 61 72 67 76 5b 69 5d 29 3b 0a 20 20 20 20 g.argv[i]);.
15ed0 7d 0a 20 20 7d 65 6c 73 65 7b 0a 20 20 20 20 75 }. }else{. u
15ee0 6e 73 69 67 6e 65 64 20 63 68 61 72 20 2a 7a 2c nsigned char *z,
15ef0 20 63 3b 0a 20 20 20 20 66 6f 72 28 69 3d 30 3b c;. for(i=0;
15f00 20 69 3c 67 2e 61 72 67 63 3b 20 69 2b 2b 29 7b i<g.argc; i++){
15f10 0a 20 20 20 20 20 20 66 6f 73 73 69 6c 5f 70 72 . fossil_pr
15f20 69 6e 74 28 22 61 72 67 76 5b 25 64 5d 20 3d 20 int("argv[%d] =
15f30 5b 22 2c 20 69 29 3b 0a 20 20 20 20 20 20 7a 20 [", i);. z
15f40 3d 20 28 75 6e 73 69 67 6e 65 64 20 63 68 61 72 = (unsigned char
15f50 2a 29 67 2e 61 72 67 76 5b 69 5d 3b 0a 20 20 20 *)g.argv[i];.
15f60 20 20 20 66 6f 72 28 6a 3d 30 3b 20 28 63 20 3d for(j=0; (c =
15f70 20 7a 5b 6a 5d 29 21 3d 30 3b 20 6a 2b 2b 29 7b z[j])!=0; j++){
15f80 0a 20 20 20 20 20 20 20 20 66 6f 73 73 69 6c 5f . fossil_
15f90 70 72 69 6e 74 28 22 25 30 32 78 22 2c 20 63 29 print("%02x", c)
15fa0 3b 0a 20 20 20 20 20 20 7d 0a 20 20 20 20 20 20 ;. }.
15fb0 66 6f 73 73 69 6c 5f 70 72 69 6e 74 28 22 5d 5c fossil_print("]\
15fc0 6e 22 29 3b 0a 20 20 20 20 7d 0a 20 20 7d 0a 7d n");. }. }.}
15fd0 0a .