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 37 20 44 2e 20 52 69 63 68 (c) 2007 D. Rich
0020: 61 72 64 20 48 69 70 70 0a 2a 2a 0a 2a 2a 20 54 ard Hipp.**.** T
0030: 68 69 73 20 70 72 6f 67 72 61 6d 20 69 73 20 66 his program is f
0040: 72 65 65 20 73 6f 66 74 77 61 72 65 3b 20 79 6f ree software; yo
0050: 75 20 63 61 6e 20 72 65 64 69 73 74 72 69 62 75 u can redistribu
0060: 74 65 20 69 74 20 61 6e 64 2f 6f 72 0a 2a 2a 20 te it and/or.**
0070: 6d 6f 64 69 66 79 20 69 74 20 75 6e 64 65 72 20 modify it under
0080: 74 68 65 20 74 65 72 6d 73 20 6f 66 20 74 68 65 the terms of the
0090: 20 47 4e 55 20 47 65 6e 65 72 61 6c 20 50 75 62 GNU General Pub
00a0: 6c 69 63 0a 2a 2a 20 4c 69 63 65 6e 73 65 20 76 lic.** License v
00b0: 65 72 73 69 6f 6e 20 32 20 61 73 20 70 75 62 6c ersion 2 as publ
00c0: 69 73 68 65 64 20 62 79 20 74 68 65 20 46 72 65 ished by the Fre
00d0: 65 20 53 6f 66 74 77 61 72 65 20 46 6f 75 6e 64 e Software Found
00e0: 61 74 69 6f 6e 2e 0a 2a 2a 0a 2a 2a 20 54 68 69 ation..**.** Thi
00f0: 73 20 70 72 6f 67 72 61 6d 20 69 73 20 64 69 73 s program is dis
0100: 74 72 69 62 75 74 65 64 20 69 6e 20 74 68 65 20 tributed in the
0110: 68 6f 70 65 20 74 68 61 74 20 69 74 20 77 69 6c hope that it wil
0120: 6c 20 62 65 20 75 73 65 66 75 6c 2c 0a 2a 2a 20 l be useful,.**
0130: 62 75 74 20 57 49 54 48 4f 55 54 20 41 4e 59 20 but WITHOUT ANY
0140: 57 41 52 52 41 4e 54 59 3b 20 77 69 74 68 6f 75 WARRANTY; withou
0150: 74 20 65 76 65 6e 20 74 68 65 20 69 6d 70 6c 69 t even the impli
0160: 65 64 20 77 61 72 72 61 6e 74 79 20 6f 66 0a 2a ed warranty of.*
0170: 2a 20 4d 45 52 43 48 41 4e 54 41 42 49 4c 49 54 * MERCHANTABILIT
0180: 59 20 6f 72 20 46 49 54 4e 45 53 53 20 46 4f 52 Y or FITNESS FOR
0190: 20 41 20 50 41 52 54 49 43 55 4c 41 52 20 50 55 A PARTICULAR PU
01a0: 52 50 4f 53 45 2e 20 20 53 65 65 20 74 68 65 20 RPOSE. See the
01b0: 47 4e 55 0a 2a 2a 20 47 65 6e 65 72 61 6c 20 50 GNU.** General P
01c0: 75 62 6c 69 63 20 4c 69 63 65 6e 73 65 20 66 6f ublic License fo
01d0: 72 20 6d 6f 72 65 20 64 65 74 61 69 6c 73 2e 0a r more details..
01e0: 2a 2a 20 0a 2a 2a 20 59 6f 75 20 73 68 6f 75 6c ** .** You shoul
01f0: 64 20 68 61 76 65 20 72 65 63 65 69 76 65 64 20 d have received
0200: 61 20 63 6f 70 79 20 6f 66 20 74 68 65 20 47 4e a copy of the GN
0210: 55 20 47 65 6e 65 72 61 6c 20 50 75 62 6c 69 63 U General Public
0220: 0a 2a 2a 20 4c 69 63 65 6e 73 65 20 61 6c 6f 6e .** License alon
0230: 67 20 77 69 74 68 20 74 68 69 73 20 6c 69 62 72 g with this libr
0240: 61 72 79 3b 20 69 66 20 6e 6f 74 2c 20 77 72 69 ary; if not, wri
0250: 74 65 20 74 6f 20 74 68 65 0a 2a 2a 20 46 72 65 te to the.** Fre
0260: 65 20 53 6f 66 74 77 61 72 65 20 46 6f 75 6e 64 e Software Found
0270: 61 74 69 6f 6e 2c 20 49 6e 63 2e 2c 20 35 39 20 ation, Inc., 59
0280: 54 65 6d 70 6c 65 20 50 6c 61 63 65 20 2d 20 53 Temple Place - S
0290: 75 69 74 65 20 33 33 30 2c 0a 2a 2a 20 42 6f 73 uite 330,.** Bos
02a0: 74 6f 6e 2c 20 4d 41 20 20 30 32 31 31 31 2d 31 ton, MA 02111-1
02b0: 33 30 37 2c 20 55 53 41 2e 0a 2a 2a 0a 2a 2a 20 307, USA..**.**
02c0: 41 75 74 68 6f 72 20 63 6f 6e 74 61 63 74 20 69 Author contact i
02d0: 6e 66 6f 72 6d 61 74 69 6f 6e 3a 0a 2a 2a 20 20 nformation:.**
02e0: 20 64 72 68 40 68 77 61 63 69 2e 63 6f 6d 0a 2a drh@hwaci.com.*
02f0: 2a 20 20 20 68 74 74 70 3a 2f 2f 77 77 77 2e 68 * http://www.h
0300: 77 61 63 69 2e 63 6f 6d 2f 64 72 68 2f 0a 2a 2a waci.com/drh/.**
0310: 0a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a .***************
0320: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
0330: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
0340: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
0350: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
0360: 0a 2a 2a 0a 2a 2a 20 54 68 69 73 20 66 69 6c 65 .**.** This file
0370: 20 63 6f 6e 74 61 69 6e 73 20 63 6f 64 65 20 74 contains code t
0380: 6f 20 69 6d 70 6c 65 6d 65 6e 74 20 74 68 65 20 o implement the
0390: 66 69 6c 65 20 74 72 61 6e 73 66 65 72 20 70 72 file transfer pr
03a0: 6f 74 6f 63 6f 6c 2e 0a 2a 2f 0a 23 69 6e 63 6c otocol..*/.#incl
03b0: 75 64 65 20 22 63 6f 6e 66 69 67 2e 68 22 0a 23 ude "config.h".#
03c0: 69 6e 63 6c 75 64 65 20 22 78 66 65 72 2e 68 22 include "xfer.h"
03d0: 0a 0a 2f 2a 0a 2a 2a 20 54 68 69 73 20 73 74 72 ../*.** This str
03e0: 75 63 74 75 72 65 20 68 6f 6c 64 73 20 69 6e 66 ucture holds inf
03f0: 6f 72 6d 61 74 69 6f 6e 20 61 62 6f 75 74 20 74 ormation about t
0400: 68 65 20 63 75 72 72 65 6e 74 20 73 74 61 74 65 he current state
0410: 20 6f 66 20 65 69 74 68 65 72 0a 2a 2a 20 61 20 of either.** a
0420: 63 6c 69 65 6e 74 20 6f 72 20 61 20 73 65 72 76 client or a serv
0430: 65 72 20 74 68 61 74 20 69 73 20 70 61 72 74 69 er that is parti
0440: 63 69 70 61 74 69 6e 67 20 69 6e 20 78 66 65 72 cipating in xfer
0450: 2e 0a 2a 2f 0a 74 79 70 65 64 65 66 20 73 74 72 ..*/.typedef str
0460: 75 63 74 20 58 66 65 72 20 58 66 65 72 3b 0a 73 uct Xfer Xfer;.s
0470: 74 72 75 63 74 20 58 66 65 72 20 7b 0a 20 20 42 truct Xfer {. B
0480: 6c 6f 62 20 2a 70 49 6e 3b 20 20 20 20 20 20 20 lob *pIn;
0490: 20 20 20 2f 2a 20 49 6e 70 75 74 20 74 65 78 74 /* Input text
04a0: 20 66 72 6f 6d 20 74 68 65 20 6f 74 68 65 72 20 from the other
04b0: 73 69 64 65 20 2a 2f 0a 20 20 42 6c 6f 62 20 2a side */. Blob *
04c0: 70 4f 75 74 3b 20 20 20 20 20 20 20 20 20 2f 2a pOut; /*
04d0: 20 43 6f 6d 70 6f 73 65 20 6f 75 72 20 72 65 70 Compose our rep
04e0: 6c 79 20 68 65 72 65 20 2a 2f 0a 20 20 42 6c 6f ly here */. Blo
04f0: 62 20 6c 69 6e 65 3b 20 20 20 20 20 20 20 20 20 b line;
0500: 20 2f 2a 20 54 68 65 20 63 75 72 72 65 6e 74 20 /* The current
0510: 6c 69 6e 65 20 6f 66 20 69 6e 70 75 74 20 2a 2f line of input */
0520: 0a 20 20 42 6c 6f 62 20 61 54 6f 6b 65 6e 5b 35 . Blob aToken[5
0530: 5d 3b 20 20 20 20 20 2f 2a 20 54 6f 6b 65 6e 69 ]; /* Tokeni
0540: 7a 65 64 20 76 65 72 73 69 6f 6e 20 6f 66 20 6c zed version of l
0550: 69 6e 65 20 2a 2f 0a 20 20 42 6c 6f 62 20 65 72 ine */. Blob er
0560: 72 3b 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 r; /*
0570: 45 72 72 6f 72 20 6d 65 73 73 61 67 65 20 74 65 Error message te
0580: 78 74 20 2a 2f 0a 20 20 69 6e 74 20 6e 54 6f 6b xt */. int nTok
0590: 65 6e 3b 20 20 20 20 20 20 20 20 20 2f 2a 20 4e en; /* N
05a0: 75 6d 62 65 72 20 6f 66 20 74 6f 6b 65 6e 73 20 umber of tokens
05b0: 69 6e 20 6c 69 6e 65 20 2a 2f 0a 20 20 69 6e 74 in line */. int
05c0: 20 6e 49 47 6f 74 53 65 6e 74 3b 20 20 20 20 20 nIGotSent;
05d0: 20 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 20 22 69 /* Number of "i
05e0: 67 6f 74 22 20 63 61 72 64 73 20 73 65 6e 74 20 got" cards sent
05f0: 2a 2f 0a 20 20 69 6e 74 20 6e 47 69 6d 6d 65 53 */. int nGimmeS
0600: 65 6e 74 3b 20 20 20 20 20 2f 2a 20 4e 75 6d 62 ent; /* Numb
0610: 65 72 20 6f 66 20 67 69 6d 6d 65 20 63 61 72 64 er of gimme card
0620: 73 20 73 65 6e 74 20 2a 2f 0a 20 20 69 6e 74 20 s sent */. int
0630: 6e 46 69 6c 65 53 65 6e 74 3b 20 20 20 20 20 20 nFileSent;
0640: 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 20 66 69 6c /* Number of fil
0650: 65 73 20 73 65 6e 74 20 2a 2f 0a 20 20 69 6e 74 es sent */. int
0660: 20 6e 44 65 6c 74 61 53 65 6e 74 3b 20 20 20 20 nDeltaSent;
0670: 20 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 20 64 65 /* Number of de
0680: 6c 74 61 73 20 73 65 6e 74 20 2a 2f 0a 20 20 69 ltas sent */. i
0690: 6e 74 20 6e 46 69 6c 65 52 63 76 64 3b 20 20 20 nt nFileRcvd;
06a0: 20 20 20 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 20 /* Number of
06b0: 66 69 6c 65 73 20 72 65 63 65 69 76 65 64 20 2a files received *
06c0: 2f 0a 20 20 69 6e 74 20 6e 44 65 6c 74 61 52 63 /. int nDeltaRc
06d0: 76 64 3b 20 20 20 20 20 2f 2a 20 4e 75 6d 62 65 vd; /* Numbe
06e0: 72 20 6f 66 20 64 65 6c 74 61 73 20 72 65 63 65 r of deltas rece
06f0: 69 76 65 64 20 2a 2f 0a 20 20 69 6e 74 20 6e 44 ived */. int nD
0700: 61 6e 67 6c 69 6e 67 46 69 6c 65 3b 20 20 2f 2a anglingFile; /*
0710: 20 4e 75 6d 62 65 72 20 6f 66 20 64 61 6e 67 6c Number of dangl
0720: 69 6e 67 20 64 65 6c 74 61 73 20 72 65 63 65 69 ing deltas recei
0730: 76 65 64 20 2a 2f 0a 20 20 69 6e 74 20 6d 78 53 ved */. int mxS
0740: 65 6e 64 3b 20 20 20 20 20 20 20 20 20 2f 2a 20 end; /*
0750: 53 74 6f 70 20 73 65 6e 64 69 6e 67 20 22 66 69 Stop sending "fi
0760: 6c 65 22 20 77 69 74 68 20 70 4f 75 74 20 72 65 le" with pOut re
0770: 61 63 68 65 73 20 74 68 69 73 20 73 69 7a 65 20 aches this size
0780: 2a 2f 0a 7d 3b 0a 0a 0a 2f 2a 0a 2a 2a 20 54 68 */.};.../*.** Th
0790: 65 20 69 6e 70 75 74 20 62 6c 6f 62 20 63 6f 6e e input blob con
07a0: 74 61 69 6e 73 20 61 20 55 55 49 44 2e 20 20 43 tains a UUID. C
07b0: 6f 6e 76 65 72 74 20 69 74 20 69 6e 74 6f 20 61 onvert it into a
07c0: 20 72 65 63 6f 72 64 20 49 44 2e 0a 2a 2a 20 43 record ID..** C
07d0: 72 65 61 74 65 20 61 20 70 68 61 6e 74 6f 6d 20 reate a phantom
07e0: 72 65 63 6f 72 64 20 69 66 20 6e 6f 20 70 72 69 record if no pri
07f0: 6f 72 20 72 65 63 6f 72 64 20 65 78 69 73 74 73 or record exists
0800: 20 61 6e 64 0a 2a 2a 20 70 68 61 6e 74 6f 6d 69 and.** phantomi
0810: 7a 65 20 69 73 20 74 72 75 65 2e 0a 2a 2a 0a 2a ze is true..**.*
0820: 2a 20 43 6f 6d 70 61 72 65 20 74 6f 20 75 75 69 * Compare to uui
0830: 64 5f 74 6f 5f 72 69 64 28 29 2e 20 20 54 68 69 d_to_rid(). Thi
0840: 73 20 72 6f 75 74 69 6e 65 20 74 61 6b 65 73 20 s routine takes
0850: 61 20 62 6c 6f 62 20 61 72 67 75 6d 65 6e 74 0a a blob argument.
0860: 2a 2a 20 61 6e 64 20 64 6f 65 73 20 6c 65 73 73 ** and does less
0870: 20 65 72 72 6f 72 20 63 68 65 63 6b 69 6e 67 2e error checking.
0880: 0a 2a 2f 0a 73 74 61 74 69 63 20 69 6e 74 20 72 .*/.static int r
0890: 69 64 5f 66 72 6f 6d 5f 75 75 69 64 28 42 6c 6f id_from_uuid(Blo
08a0: 62 20 2a 70 55 75 69 64 2c 20 69 6e 74 20 70 68 b *pUuid, int ph
08b0: 61 6e 74 6f 6d 69 7a 65 29 7b 0a 20 20 73 74 61 antomize){. sta
08c0: 74 69 63 20 53 74 6d 74 20 71 3b 0a 20 20 69 6e tic Stmt q;. in
08d0: 74 20 72 69 64 3b 0a 0a 20 20 64 62 5f 73 74 61 t rid;.. db_sta
08e0: 74 69 63 5f 70 72 65 70 61 72 65 28 26 71 2c 20 tic_prepare(&q,
08f0: 22 53 45 4c 45 43 54 20 72 69 64 20 46 52 4f 4d "SELECT rid FROM
0900: 20 62 6c 6f 62 20 57 48 45 52 45 20 75 75 69 64 blob WHERE uuid
0910: 3d 3a 75 75 69 64 22 29 3b 0a 20 20 64 62 5f 62 =:uuid");. db_b
0920: 69 6e 64 5f 73 74 72 28 26 71 2c 20 22 3a 75 75 ind_str(&q, ":uu
0930: 69 64 22 2c 20 70 55 75 69 64 29 3b 0a 20 20 69 id", pUuid);. i
0940: 66 28 20 64 62 5f 73 74 65 70 28 26 71 29 3d 3d f( db_step(&q)==
0950: 53 51 4c 49 54 45 5f 52 4f 57 20 29 7b 0a 20 20 SQLITE_ROW ){.
0960: 20 20 72 69 64 20 3d 20 64 62 5f 63 6f 6c 75 6d rid = db_colum
0970: 6e 5f 69 6e 74 28 26 71 2c 20 30 29 3b 0a 20 20 n_int(&q, 0);.
0980: 7d 65 6c 73 65 7b 0a 20 20 20 20 72 69 64 20 3d }else{. rid =
0990: 20 30 3b 0a 20 20 7d 0a 20 20 64 62 5f 72 65 73 0;. }. db_res
09a0: 65 74 28 26 71 29 3b 0a 20 20 69 66 28 20 72 69 et(&q);. if( ri
09b0: 64 3d 3d 30 20 26 26 20 70 68 61 6e 74 6f 6d 69 d==0 && phantomi
09c0: 7a 65 20 29 7b 0a 20 20 20 20 72 69 64 20 3d 20 ze ){. rid =
09d0: 63 6f 6e 74 65 6e 74 5f 6e 65 77 28 62 6c 6f 62 content_new(blob
09e0: 5f 73 74 72 28 70 55 75 69 64 29 29 3b 0a 20 20 _str(pUuid));.
09f0: 7d 0a 20 20 72 65 74 75 72 6e 20 72 69 64 3b 0a }. return rid;.
0a00: 7d 0a 0a 2f 2a 0a 2a 2a 20 52 65 6d 65 6d 62 65 }../*.** Remembe
0a10: 72 20 74 68 61 74 20 74 68 65 20 6f 74 68 65 72 r that the other
0a20: 20 73 69 64 65 20 6f 66 20 74 68 65 20 63 6f 6e side of the con
0a30: 6e 65 63 74 69 6f 6e 20 61 6c 72 65 61 64 79 20 nection already
0a40: 68 61 73 20 61 20 63 6f 70 79 0a 2a 2a 20 6f 66 has a copy.** of
0a50: 20 74 68 65 20 66 69 6c 65 20 72 69 64 2e 0a 2a the file rid..*
0a60: 2f 0a 73 74 61 74 69 63 20 76 6f 69 64 20 72 65 /.static void re
0a70: 6d 6f 74 65 5f 68 61 73 28 69 6e 74 20 72 69 64 mote_has(int rid
0a80: 29 7b 0a 20 20 69 66 28 20 72 69 64 20 29 20 64 ){. if( rid ) d
0a90: 62 5f 6d 75 6c 74 69 5f 65 78 65 63 28 22 49 4e b_multi_exec("IN
0aa0: 53 45 52 54 20 4f 52 20 49 47 4e 4f 52 45 20 49 SERT OR IGNORE I
0ab0: 4e 54 4f 20 6f 6e 72 65 6d 6f 74 65 20 56 41 4c NTO onremote VAL
0ac0: 55 45 53 28 25 64 29 22 2c 20 72 69 64 29 3b 0a UES(%d)", rid);.
0ad0: 7d 0a 0a 2f 2a 0a 2a 2a 20 54 68 65 20 61 54 6f }../*.** The aTo
0ae0: 6b 65 6e 5b 30 2e 2e 6e 54 6f 6b 65 6e 2d 31 5d ken[0..nToken-1]
0af0: 20 62 6c 6f 62 20 61 72 72 61 79 20 69 73 20 61 blob array is a
0b00: 20 70 61 72 73 65 20 6f 66 20 61 20 22 66 69 6c parse of a "fil
0b10: 65 22 20 6c 69 6e 65 20 0a 2a 2a 20 6d 65 73 73 e" line .** mess
0b20: 61 67 65 2e 20 20 54 68 69 73 20 72 6f 75 74 69 age. This routi
0b30: 6e 65 20 66 69 6e 69 73 68 65 73 20 70 61 72 73 ne finishes pars
0b40: 69 6e 67 20 74 68 61 74 20 6d 65 73 73 61 67 65 ing that message
0b50: 20 61 6e 64 20 64 6f 65 73 0a 2a 2a 20 61 20 72 and does.** a r
0b60: 65 63 6f 72 64 20 69 6e 73 65 72 74 20 6f 66 20 ecord insert of
0b70: 74 68 65 20 66 69 6c 65 2e 0a 2a 2a 0a 2a 2a 20 the file..**.**
0b80: 54 68 65 20 66 69 6c 65 20 6c 69 6e 65 20 69 73 The file line is
0b90: 20 69 6e 20 6f 6e 65 20 6f 66 20 74 68 65 20 66 in one of the f
0ba0: 6f 6c 6c 6f 77 69 6e 67 20 74 77 6f 20 66 6f 72 ollowing two for
0bb0: 6d 73 3a 0a 2a 2a 0a 2a 2a 20 20 20 20 20 20 66 ms:.**.** f
0bc0: 69 6c 65 20 55 55 49 44 20 53 49 5a 45 20 5c 6e ile UUID SIZE \n
0bd0: 20 43 4f 4e 54 45 4e 54 0a 2a 2a 20 20 20 20 20 CONTENT.**
0be0: 20 66 69 6c 65 20 55 55 49 44 20 44 45 4c 54 41 file UUID DELTA
0bf0: 53 52 43 20 53 49 5a 45 20 5c 6e 20 43 4f 4e 54 SRC SIZE \n CONT
0c00: 45 4e 54 0a 2a 2a 0a 2a 2a 20 54 68 65 20 63 6f ENT.**.** The co
0c10: 6e 74 65 6e 74 20 69 73 20 53 49 5a 45 20 62 79 ntent is SIZE by
0c20: 74 65 73 20 69 6d 6d 65 64 69 61 74 65 6c 79 20 tes immediately
0c30: 66 6f 6c 6c 6f 77 69 6e 67 20 74 68 65 20 6e 65 following the ne
0c40: 77 6c 69 6e 65 2e 0a 2a 2a 20 49 66 20 44 45 4c wline..** If DEL
0c50: 54 41 53 52 43 20 65 78 69 73 74 73 2c 20 74 68 TASRC exists, th
0c60: 65 6e 20 74 68 65 20 43 4f 4e 54 45 4e 54 20 69 en the CONTENT i
0c70: 73 20 61 20 64 65 6c 74 61 20 61 67 61 69 6e 73 s a delta agains
0c80: 74 20 74 68 65 0a 2a 2a 20 63 6f 6e 74 65 6e 74 t the.** content
0c90: 20 6f 66 20 44 45 4c 54 41 53 52 43 2e 0a 2a 2a of DELTASRC..**
0ca0: 0a 2a 2a 20 49 66 20 61 6e 79 20 65 72 72 6f 72 .** If any error
0cb0: 20 6f 63 63 75 72 73 2c 20 77 72 69 74 65 20 61 occurs, write a
0cc0: 20 6d 65 73 73 61 67 65 20 69 6e 74 6f 20 70 45 message into pE
0cd0: 72 72 20 77 68 69 63 68 20 68 61 73 20 61 6c 72 rr which has alr
0ce0: 65 61 64 79 0a 2a 2a 20 62 65 20 69 6e 69 74 69 eady.** be initi
0cf0: 61 6c 69 7a 65 64 20 74 6f 20 61 6e 20 65 6d 70 alized to an emp
0d00: 74 79 20 73 74 72 69 6e 67 2e 0a 2a 2a 0a 2a 2a ty string..**.**
0d10: 20 41 6e 79 20 61 72 74 69 66 61 63 74 20 73 75 Any artifact su
0d20: 63 63 65 73 73 66 75 6c 6c 79 20 72 65 63 65 69 ccessfully recei
0d30: 76 65 64 20 62 79 20 74 68 69 73 20 72 6f 75 74 ved by this rout
0d40: 69 6e 65 20 69 73 20 63 6f 6e 73 69 64 65 72 65 ine is considere
0d50: 64 20 74 6f 0a 2a 2a 20 62 65 20 70 75 62 6c 69 d to.** be publi
0d60: 63 20 61 6e 64 20 69 73 20 74 68 65 72 65 66 6f c and is therefo
0d70: 72 65 20 72 65 6d 6f 76 65 64 20 66 72 6f 6d 20 re removed from
0d80: 74 68 65 20 22 70 72 69 76 61 74 65 22 20 74 61 the "private" ta
0d90: 62 6c 65 2e 0a 2a 2f 0a 73 74 61 74 69 63 20 76 ble..*/.static v
0da0: 6f 69 64 20 78 66 65 72 5f 61 63 63 65 70 74 5f oid xfer_accept_
0db0: 66 69 6c 65 28 58 66 65 72 20 2a 70 58 66 65 72 file(Xfer *pXfer
0dc0: 29 7b 0a 20 20 69 6e 74 20 6e 3b 0a 20 20 69 6e ){. int n;. in
0dd0: 74 20 72 69 64 3b 0a 20 20 69 6e 74 20 73 72 63 t rid;. int src
0de0: 69 64 20 3d 20 30 3b 0a 20 20 42 6c 6f 62 20 63 id = 0;. Blob c
0df0: 6f 6e 74 65 6e 74 2c 20 68 61 73 68 3b 0a 20 20 ontent, hash;.
0e00: 0a 20 20 69 66 28 20 70 58 66 65 72 2d 3e 6e 54 . if( pXfer->nT
0e10: 6f 6b 65 6e 3c 33 20 0a 20 20 20 7c 7c 20 70 58 oken<3 . || pX
0e20: 66 65 72 2d 3e 6e 54 6f 6b 65 6e 3e 34 0a 20 20 fer->nToken>4.
0e30: 20 7c 7c 20 21 62 6c 6f 62 5f 69 73 5f 75 75 69 || !blob_is_uui
0e40: 64 28 26 70 58 66 65 72 2d 3e 61 54 6f 6b 65 6e d(&pXfer->aToken
0e50: 5b 31 5d 29 0a 20 20 20 7c 7c 20 21 62 6c 6f 62 [1]). || !blob
0e60: 5f 69 73 5f 69 6e 74 28 26 70 58 66 65 72 2d 3e _is_int(&pXfer->
0e70: 61 54 6f 6b 65 6e 5b 70 58 66 65 72 2d 3e 6e 54 aToken[pXfer->nT
0e80: 6f 6b 65 6e 2d 31 5d 2c 20 26 6e 29 0a 20 20 20 oken-1], &n).
0e90: 7c 7c 20 6e 3c 30 0a 20 20 20 7c 7c 20 28 70 58 || n<0. || (pX
0ea0: 66 65 72 2d 3e 6e 54 6f 6b 65 6e 3d 3d 34 20 26 fer->nToken==4 &
0eb0: 26 20 21 62 6c 6f 62 5f 69 73 5f 75 75 69 64 28 & !blob_is_uuid(
0ec0: 26 70 58 66 65 72 2d 3e 61 54 6f 6b 65 6e 5b 32 &pXfer->aToken[2
0ed0: 5d 29 29 0a 20 20 29 7b 0a 20 20 20 20 62 6c 6f ])). ){. blo
0ee0: 62 5f 61 70 70 65 6e 64 66 28 26 70 58 66 65 72 b_appendf(&pXfer
0ef0: 2d 3e 65 72 72 2c 20 22 6d 61 6c 66 6f 72 6d 65 ->err, "malforme
0f00: 64 20 66 69 6c 65 20 6c 69 6e 65 22 29 3b 0a 20 d file line");.
0f10: 20 20 20 72 65 74 75 72 6e 3b 0a 20 20 7d 0a 20 return;. }.
0f20: 20 62 6c 6f 62 5f 7a 65 72 6f 28 26 63 6f 6e 74 blob_zero(&cont
0f30: 65 6e 74 29 3b 0a 20 20 62 6c 6f 62 5f 7a 65 72 ent);. blob_zer
0f40: 6f 28 26 68 61 73 68 29 3b 0a 20 20 62 6c 6f 62 o(&hash);. blob
0f50: 5f 65 78 74 72 61 63 74 28 70 58 66 65 72 2d 3e _extract(pXfer->
0f60: 70 49 6e 2c 20 6e 2c 20 26 63 6f 6e 74 65 6e 74 pIn, n, &content
0f70: 29 3b 0a 20 20 69 66 28 20 75 75 69 64 5f 69 73 );. if( uuid_is
0f80: 5f 73 68 75 6e 6e 65 64 28 62 6c 6f 62 5f 73 74 _shunned(blob_st
0f90: 72 28 26 70 58 66 65 72 2d 3e 61 54 6f 6b 65 6e r(&pXfer->aToken
0fa0: 5b 31 5d 29 29 20 29 7b 0a 20 20 20 20 2f 2a 20 [1])) ){. /*
0fb0: 49 67 6e 6f 72 65 20 66 69 6c 65 73 20 74 68 61 Ignore files tha
0fc0: 74 20 68 61 76 65 20 62 65 65 6e 20 73 68 75 6e t have been shun
0fd0: 6e 65 64 20 2a 2f 0a 20 20 20 20 72 65 74 75 72 ned */. retur
0fe0: 6e 3b 0a 20 20 7d 0a 20 20 69 66 28 20 70 58 66 n;. }. if( pXf
0ff0: 65 72 2d 3e 6e 54 6f 6b 65 6e 3d 3d 34 20 29 7b er->nToken==4 ){
1000: 0a 20 20 20 20 42 6c 6f 62 20 73 72 63 3b 0a 20 . Blob src;.
1010: 20 20 20 73 72 63 69 64 20 3d 20 72 69 64 5f 66 srcid = rid_f
1020: 72 6f 6d 5f 75 75 69 64 28 26 70 58 66 65 72 2d rom_uuid(&pXfer-
1030: 3e 61 54 6f 6b 65 6e 5b 32 5d 2c 20 31 29 3b 0a >aToken[2], 1);.
1040: 20 20 20 20 69 66 28 20 63 6f 6e 74 65 6e 74 5f if( content_
1050: 67 65 74 28 73 72 63 69 64 2c 20 26 73 72 63 29 get(srcid, &src)
1060: 3d 3d 30 20 29 7b 0a 20 20 20 20 20 20 72 69 64 ==0 ){. rid
1070: 20 3d 20 63 6f 6e 74 65 6e 74 5f 70 75 74 28 26 = content_put(&
1080: 63 6f 6e 74 65 6e 74 2c 20 62 6c 6f 62 5f 73 74 content, blob_st
1090: 72 28 26 70 58 66 65 72 2d 3e 61 54 6f 6b 65 6e r(&pXfer->aToken
10a0: 5b 31 5d 29 2c 20 73 72 63 69 64 29 3b 0a 20 20 [1]), srcid);.
10b0: 20 20 20 20 70 58 66 65 72 2d 3e 6e 44 61 6e 67 pXfer->nDang
10c0: 6c 69 6e 67 46 69 6c 65 2b 2b 3b 0a 20 20 20 20 lingFile++;.
10d0: 20 20 64 62 5f 6d 75 6c 74 69 5f 65 78 65 63 28 db_multi_exec(
10e0: 22 44 45 4c 45 54 45 20 46 52 4f 4d 20 70 68 61 "DELETE FROM pha
10f0: 6e 74 6f 6d 20 57 48 45 52 45 20 72 69 64 3d 25 ntom WHERE rid=%
1100: 64 22 2c 20 72 69 64 29 3b 0a 20 20 20 20 20 20 d", rid);.
1110: 63 6f 6e 74 65 6e 74 5f 6d 61 6b 65 5f 70 75 62 content_make_pub
1120: 6c 69 63 28 72 69 64 29 3b 0a 20 20 20 20 20 20 lic(rid);.
1130: 72 65 74 75 72 6e 3b 0a 20 20 20 20 7d 0a 20 20 return;. }.
1140: 20 20 70 58 66 65 72 2d 3e 6e 44 65 6c 74 61 52 pXfer->nDeltaR
1150: 63 76 64 2b 2b 3b 0a 20 20 20 20 62 6c 6f 62 5f cvd++;. blob_
1160: 64 65 6c 74 61 5f 61 70 70 6c 79 28 26 73 72 63 delta_apply(&src
1170: 2c 20 26 63 6f 6e 74 65 6e 74 2c 20 26 63 6f 6e , &content, &con
1180: 74 65 6e 74 29 3b 0a 20 20 20 20 62 6c 6f 62 5f tent);. blob_
1190: 72 65 73 65 74 28 26 73 72 63 29 3b 0a 20 20 7d reset(&src);. }
11a0: 65 6c 73 65 7b 0a 20 20 20 20 70 58 66 65 72 2d else{. pXfer-
11b0: 3e 6e 46 69 6c 65 52 63 76 64 2b 2b 3b 0a 20 20 >nFileRcvd++;.
11c0: 7d 0a 20 20 73 68 61 31 73 75 6d 5f 62 6c 6f 62 }. sha1sum_blob
11d0: 28 26 63 6f 6e 74 65 6e 74 2c 20 26 68 61 73 68 (&content, &hash
11e0: 29 3b 0a 20 20 69 66 28 20 21 62 6c 6f 62 5f 65 );. if( !blob_e
11f0: 71 5f 73 74 72 28 26 70 58 66 65 72 2d 3e 61 54 q_str(&pXfer->aT
1200: 6f 6b 65 6e 5b 31 5d 2c 20 62 6c 6f 62 5f 73 74 oken[1], blob_st
1210: 72 28 26 68 61 73 68 29 2c 20 2d 31 29 20 29 7b r(&hash), -1) ){
1220: 0a 20 20 20 20 62 6c 6f 62 5f 61 70 70 65 6e 64 . blob_append
1230: 66 28 26 70 58 66 65 72 2d 3e 65 72 72 2c 20 22 f(&pXfer->err, "
1240: 63 6f 6e 74 65 6e 74 20 64 6f 65 73 20 6e 6f 74 content does not
1250: 20 6d 61 74 63 68 20 73 68 61 31 20 68 61 73 68 match sha1 hash
1260: 22 29 3b 0a 20 20 7d 0a 20 20 72 69 64 20 3d 20 ");. }. rid =
1270: 63 6f 6e 74 65 6e 74 5f 70 75 74 28 26 63 6f 6e content_put(&con
1280: 74 65 6e 74 2c 20 62 6c 6f 62 5f 73 74 72 28 26 tent, blob_str(&
1290: 68 61 73 68 29 2c 20 30 29 3b 0a 20 20 62 6c 6f hash), 0);. blo
12a0: 62 5f 72 65 73 65 74 28 26 68 61 73 68 29 3b 0a b_reset(&hash);.
12b0: 20 20 69 66 28 20 72 69 64 3d 3d 30 20 29 7b 0a if( rid==0 ){.
12c0: 20 20 20 20 62 6c 6f 62 5f 61 70 70 65 6e 64 66 blob_appendf
12d0: 28 26 70 58 66 65 72 2d 3e 65 72 72 2c 20 22 25 (&pXfer->err, "%
12e0: 73 22 2c 20 67 2e 7a 45 72 72 4d 73 67 29 3b 0a s", g.zErrMsg);.
12f0: 20 20 7d 65 6c 73 65 7b 0a 20 20 20 20 63 6f 6e }else{. con
1300: 74 65 6e 74 5f 6d 61 6b 65 5f 70 75 62 6c 69 63 tent_make_public
1310: 28 72 69 64 29 3b 0a 20 20 20 20 6d 61 6e 69 66 (rid);. manif
1320: 65 73 74 5f 63 72 6f 73 73 6c 69 6e 6b 28 72 69 est_crosslink(ri
1330: 64 2c 20 26 63 6f 6e 74 65 6e 74 29 3b 0a 20 20 d, &content);.
1340: 7d 0a 20 20 72 65 6d 6f 74 65 5f 68 61 73 28 72 }. remote_has(r
1350: 69 64 29 3b 0a 7d 0a 0a 2f 2a 0a 2a 2a 20 54 72 id);.}../*.** Tr
1360: 79 20 74 6f 20 73 65 6e 64 20 61 20 66 69 6c 65 y to send a file
1370: 20 61 73 20 61 20 64 65 6c 74 61 20 61 67 61 69 as a delta agai
1380: 6e 73 74 20 69 74 73 20 70 61 72 65 6e 74 2e 0a nst its parent..
1390: 2a 2a 20 49 66 20 73 75 63 63 65 73 73 66 75 6c ** If successful
13a0: 2c 20 72 65 74 75 72 6e 20 74 68 65 20 6e 75 6d , return the num
13b0: 62 65 72 20 6f 66 20 62 79 74 65 73 20 69 6e 20 ber of bytes in
13c0: 74 68 65 20 64 65 6c 74 61 2e 0a 2a 2a 20 49 66 the delta..** If
13d0: 20 77 65 20 63 61 6e 6e 6f 74 20 67 65 6e 65 72 we cannot gener
13e0: 61 74 65 20 61 6e 20 61 70 70 72 6f 70 72 69 61 ate an appropria
13f0: 74 65 20 64 65 6c 74 61 2c 20 74 68 65 6e 20 73 te delta, then s
1400: 65 6e 64 0a 2a 2a 20 6e 6f 74 68 69 6e 67 20 61 end.** nothing a
1410: 6e 64 20 72 65 74 75 72 6e 20 7a 65 72 6f 2e 0a nd return zero..
1420: 2a 2a 0a 2a 2a 20 4e 65 76 65 72 20 73 65 6e 64 **.** Never send
1430: 20 61 20 64 65 6c 74 61 20 61 67 61 69 6e 73 74 a delta against
1440: 20 61 20 70 72 69 76 61 74 65 20 61 72 74 69 66 a private artif
1450: 61 63 74 2e 0a 2a 2f 0a 73 74 61 74 69 63 20 69 act..*/.static i
1460: 6e 74 20 73 65 6e 64 5f 64 65 6c 74 61 5f 70 61 nt send_delta_pa
1470: 72 65 6e 74 28 0a 20 20 58 66 65 72 20 2a 70 58 rent(. Xfer *pX
1480: 66 65 72 2c 20 20 20 20 20 20 20 20 20 20 20 20 fer,
1490: 2f 2a 20 54 68 65 20 74 72 61 6e 73 66 65 72 20 /* The transfer
14a0: 63 6f 6e 74 65 78 74 20 2a 2f 0a 20 20 69 6e 74 context */. int
14b0: 20 72 69 64 2c 20 20 20 20 20 20 20 20 20 20 20 rid,
14c0: 20 20 20 20 20 2f 2a 20 72 65 63 6f 72 64 20 69 /* record i
14d0: 64 20 6f 66 20 74 68 65 20 66 69 6c 65 20 74 6f d of the file to
14e0: 20 73 65 6e 64 20 2a 2f 0a 20 20 42 6c 6f 62 20 send */. Blob
14f0: 2a 70 43 6f 6e 74 65 6e 74 2c 20 20 20 20 20 20 *pContent,
1500: 20 20 20 2f 2a 20 54 68 65 20 63 6f 6e 74 65 6e /* The conten
1510: 74 20 6f 66 20 74 68 65 20 66 69 6c 65 20 74 6f t of the file to
1520: 20 73 65 6e 64 20 2a 2f 0a 20 20 42 6c 6f 62 20 send */. Blob
1530: 2a 70 55 75 69 64 20 20 20 20 20 20 20 20 20 20 *pUuid
1540: 20 20 20 2f 2a 20 54 68 65 20 55 55 49 44 20 6f /* The UUID o
1550: 66 20 74 68 65 20 66 69 6c 65 20 74 6f 20 73 65 f the file to se
1560: 6e 64 20 2a 2f 0a 29 7b 0a 20 20 73 74 61 74 69 nd */.){. stati
1570: 63 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 61 7a c const char *az
1580: 51 75 65 72 79 5b 5d 20 3d 20 7b 0a 20 20 20 20 Query[] = {.
1590: 22 53 45 4c 45 43 54 20 70 69 64 20 46 52 4f 4d "SELECT pid FROM
15a0: 20 70 6c 69 6e 6b 20 78 22 0a 20 20 20 20 22 20 plink x". "
15b0: 57 48 45 52 45 20 63 69 64 3d 25 64 22 0a 20 20 WHERE cid=%d".
15c0: 20 20 22 20 20 20 41 4e 44 20 4e 4f 54 20 45 58 " AND NOT EX
15d0: 49 53 54 53 28 53 45 4c 45 43 54 20 31 20 46 52 ISTS(SELECT 1 FR
15e0: 4f 4d 20 70 68 61 6e 74 6f 6d 20 57 48 45 52 45 OM phantom WHERE
15f0: 20 72 69 64 3d 70 69 64 29 22 0a 20 20 20 20 22 rid=pid)". "
1600: 20 20 20 41 4e 44 20 4e 4f 54 20 45 58 49 53 54 AND NOT EXIST
1610: 53 28 53 45 4c 45 43 54 20 31 20 46 52 4f 4d 20 S(SELECT 1 FROM
1620: 70 6c 69 6e 6b 20 79 22 0a 20 20 20 20 20 20 20 plink y".
1630: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 22 "
1640: 20 57 48 45 52 45 20 79 2e 70 69 64 3d 78 2e 63 WHERE y.pid=x.c
1650: 69 64 20 41 4e 44 20 79 2e 63 69 64 3d 78 2e 70 id AND y.cid=x.p
1660: 69 64 29 22 2c 0a 0a 20 20 20 20 22 53 45 4c 45 id)",.. "SELE
1670: 43 54 20 70 69 64 20 46 52 4f 4d 20 6d 6c 69 6e CT pid FROM mlin
1680: 6b 20 78 22 0a 20 20 20 20 22 20 57 48 45 52 45 k x". " WHERE
1690: 20 66 69 64 3d 25 64 22 0a 20 20 20 20 22 20 20 fid=%d". "
16a0: 20 41 4e 44 20 4e 4f 54 20 45 58 49 53 54 53 28 AND NOT EXISTS(
16b0: 53 45 4c 45 43 54 20 31 20 46 52 4f 4d 20 70 68 SELECT 1 FROM ph
16c0: 61 6e 74 6f 6d 20 57 48 45 52 45 20 72 69 64 3d antom WHERE rid=
16d0: 70 69 64 29 22 0a 20 20 20 20 22 20 20 20 41 4e pid)". " AN
16e0: 44 20 4e 4f 54 20 45 58 49 53 54 53 28 53 45 4c D NOT EXISTS(SEL
16f0: 45 43 54 20 31 20 46 52 4f 4d 20 6d 6c 69 6e 6b ECT 1 FROM mlink
1700: 20 79 22 0a 20 20 20 20 20 20 20 20 20 20 20 20 y".
1710: 20 20 20 20 20 20 20 20 20 22 20 20 57 48 45 52 " WHER
1720: 45 20 79 2e 70 69 64 3d 78 2e 66 69 64 20 41 4e E y.pid=x.fid AN
1730: 44 20 79 2e 66 69 64 3d 78 2e 70 69 64 29 22 0a D y.fid=x.pid)".
1740: 20 20 7d 3b 0a 20 20 69 6e 74 20 69 3b 0a 20 20 };. int i;.
1750: 42 6c 6f 62 20 73 72 63 2c 20 64 65 6c 74 61 3b Blob src, delta;
1760: 0a 20 20 69 6e 74 20 73 69 7a 65 20 3d 20 30 3b . int size = 0;
1770: 0a 20 20 69 6e 74 20 73 72 63 49 64 20 3d 20 30 . int srcId = 0
1780: 3b 0a 0a 20 20 66 6f 72 28 69 3d 30 3b 20 73 72 ;.. for(i=0; sr
1790: 63 49 64 3d 3d 30 20 26 26 20 69 3c 63 6f 75 6e cId==0 && i<coun
17a0: 74 28 61 7a 51 75 65 72 79 29 3b 20 69 2b 2b 29 t(azQuery); i++)
17b0: 7b 0a 20 20 20 20 73 72 63 49 64 20 3d 20 64 62 {. srcId = db
17c0: 5f 69 6e 74 28 30 2c 20 61 7a 51 75 65 72 79 5b _int(0, azQuery[
17d0: 69 5d 2c 20 72 69 64 29 3b 0a 20 20 7d 0a 20 20 i], rid);. }.
17e0: 69 66 28 20 73 72 63 49 64 3e 30 20 26 26 20 21 if( srcId>0 && !
17f0: 63 6f 6e 74 65 6e 74 5f 69 73 5f 70 72 69 76 61 content_is_priva
1800: 74 65 28 73 72 63 49 64 29 20 26 26 20 63 6f 6e te(srcId) && con
1810: 74 65 6e 74 5f 67 65 74 28 73 72 63 49 64 2c 20 tent_get(srcId,
1820: 26 73 72 63 29 20 29 7b 0a 20 20 20 20 63 68 61 &src) ){. cha
1830: 72 20 2a 7a 55 75 69 64 20 3d 20 64 62 5f 74 65 r *zUuid = db_te
1840: 78 74 28 30 2c 20 22 53 45 4c 45 43 54 20 75 75 xt(0, "SELECT uu
1850: 69 64 20 46 52 4f 4d 20 62 6c 6f 62 20 57 48 45 id FROM blob WHE
1860: 52 45 20 72 69 64 3d 25 64 22 2c 20 73 72 63 49 RE rid=%d", srcI
1870: 64 29 3b 0a 20 20 20 20 62 6c 6f 62 5f 64 65 6c d);. blob_del
1880: 74 61 5f 63 72 65 61 74 65 28 26 73 72 63 2c 20 ta_create(&src,
1890: 70 43 6f 6e 74 65 6e 74 2c 20 26 64 65 6c 74 61 pContent, &delta
18a0: 29 3b 0a 20 20 20 20 73 69 7a 65 20 3d 20 62 6c );. size = bl
18b0: 6f 62 5f 73 69 7a 65 28 26 64 65 6c 74 61 29 3b ob_size(&delta);
18c0: 0a 20 20 20 20 69 66 28 20 73 69 7a 65 3e 3d 62 . if( size>=b
18d0: 6c 6f 62 5f 73 69 7a 65 28 70 43 6f 6e 74 65 6e lob_size(pConten
18e0: 74 29 2d 35 30 20 29 7b 0a 20 20 20 20 20 20 73 t)-50 ){. s
18f0: 69 7a 65 20 3d 20 30 3b 0a 20 20 20 20 7d 65 6c ize = 0;. }el
1900: 73 65 20 69 66 28 20 75 75 69 64 5f 69 73 5f 73 se if( uuid_is_s
1910: 68 75 6e 6e 65 64 28 7a 55 75 69 64 29 20 29 7b hunned(zUuid) ){
1920: 0a 20 20 20 20 20 20 73 69 7a 65 20 3d 20 30 3b . size = 0;
1930: 0a 20 20 20 20 7d 65 6c 73 65 7b 0a 20 20 20 20 . }else{.
1940: 20 20 62 6c 6f 62 5f 61 70 70 65 6e 64 66 28 70 blob_appendf(p
1950: 58 66 65 72 2d 3e 70 4f 75 74 2c 20 22 66 69 6c Xfer->pOut, "fil
1960: 65 20 25 62 20 25 73 20 25 64 5c 6e 22 2c 20 70 e %b %s %d\n", p
1970: 55 75 69 64 2c 20 7a 55 75 69 64 2c 20 73 69 7a Uuid, zUuid, siz
1980: 65 29 3b 0a 20 20 20 20 20 20 62 6c 6f 62 5f 61 e);. blob_a
1990: 70 70 65 6e 64 28 70 58 66 65 72 2d 3e 70 4f 75 ppend(pXfer->pOu
19a0: 74 2c 20 62 6c 6f 62 5f 62 75 66 66 65 72 28 26 t, blob_buffer(&
19b0: 64 65 6c 74 61 29 2c 20 73 69 7a 65 29 3b 0a 20 delta), size);.
19c0: 20 20 20 20 20 2f 2a 20 62 6c 6f 62 5f 61 70 70 /* blob_app
19d0: 65 6e 64 66 28 70 58 66 65 72 2d 3e 70 4f 75 74 endf(pXfer->pOut
19e0: 2c 20 22 5c 6e 22 2c 20 31 29 3b 20 2a 2f 0a 20 , "\n", 1); */.
19f0: 20 20 20 7d 0a 20 20 20 20 62 6c 6f 62 5f 72 65 }. blob_re
1a00: 73 65 74 28 26 64 65 6c 74 61 29 3b 0a 20 20 20 set(&delta);.
1a10: 20 66 72 65 65 28 7a 55 75 69 64 29 3b 0a 20 20 free(zUuid);.
1a20: 20 20 62 6c 6f 62 5f 72 65 73 65 74 28 26 73 72 blob_reset(&sr
1a30: 63 29 3b 0a 20 20 7d 0a 20 20 72 65 74 75 72 6e c);. }. return
1a40: 20 73 69 7a 65 3b 0a 7d 0a 0a 2f 2a 0a 2a 2a 20 size;.}../*.**
1a50: 54 72 79 20 74 6f 20 73 65 6e 64 20 61 20 66 69 Try to send a fi
1a60: 6c 65 20 61 73 20 61 20 6e 61 74 69 76 65 20 64 le as a native d
1a70: 65 6c 74 61 2e 20 20 0a 2a 2a 20 49 66 20 73 75 elta. .** If su
1a80: 63 63 65 73 73 66 75 6c 2c 20 72 65 74 75 72 6e ccessful, return
1a90: 20 74 68 65 20 6e 75 6d 62 65 72 20 6f 66 20 62 the number of b
1aa0: 79 74 65 73 20 69 6e 20 74 68 65 20 64 65 6c 74 ytes in the delt
1ab0: 61 2e 0a 2a 2a 20 49 66 20 77 65 20 63 61 6e 6e a..** If we cann
1ac0: 6f 74 20 67 65 6e 65 72 61 74 65 20 61 6e 20 61 ot generate an a
1ad0: 70 70 72 6f 70 72 69 61 74 65 20 64 65 6c 74 61 ppropriate delta
1ae0: 2c 20 74 68 65 6e 20 73 65 6e 64 0a 2a 2a 20 6e , then send.** n
1af0: 6f 74 68 69 6e 67 20 61 6e 64 20 72 65 74 75 72 othing and retur
1b00: 6e 20 7a 65 72 6f 2e 0a 2a 2a 0a 2a 2a 20 4e 65 n zero..**.** Ne
1b10: 76 65 72 20 73 65 6e 64 20 61 20 64 65 6c 74 61 ver send a delta
1b20: 20 61 67 61 69 6e 73 74 20 61 20 70 72 69 76 61 against a priva
1b30: 74 65 20 61 72 74 69 66 61 63 74 2e 0a 2a 2f 0a te artifact..*/.
1b40: 73 74 61 74 69 63 20 69 6e 74 20 73 65 6e 64 5f static int send_
1b50: 64 65 6c 74 61 5f 6e 61 74 69 76 65 28 0a 20 20 delta_native(.
1b60: 58 66 65 72 20 2a 70 58 66 65 72 2c 20 20 20 20 Xfer *pXfer,
1b70: 20 20 20 20 20 20 20 20 2f 2a 20 54 68 65 20 74 /* The t
1b80: 72 61 6e 73 66 65 72 20 63 6f 6e 74 65 78 74 20 ransfer context
1b90: 2a 2f 0a 20 20 69 6e 74 20 72 69 64 2c 20 20 20 */. int rid,
1ba0: 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 /*
1bb0: 72 65 63 6f 72 64 20 69 64 20 6f 66 20 74 68 65 record id of the
1bc0: 20 66 69 6c 65 20 74 6f 20 73 65 6e 64 20 2a 2f file to send */
1bd0: 0a 20 20 42 6c 6f 62 20 2a 70 55 75 69 64 20 20 . Blob *pUuid
1be0: 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 54 68 /* Th
1bf0: 65 20 55 55 49 44 20 6f 66 20 74 68 65 20 66 69 e UUID of the fi
1c00: 6c 65 20 74 6f 20 73 65 6e 64 20 2a 2f 0a 29 7b le to send */.){
1c10: 0a 20 20 42 6c 6f 62 20 73 72 63 2c 20 64 65 6c . Blob src, del
1c20: 74 61 3b 0a 20 20 69 6e 74 20 73 69 7a 65 20 3d ta;. int size =
1c30: 20 30 3b 0a 20 20 69 6e 74 20 73 72 63 49 64 3b 0;. int srcId;
1c40: 0a 0a 20 20 73 72 63 49 64 20 3d 20 64 62 5f 69 .. srcId = db_i
1c50: 6e 74 28 30 2c 20 22 53 45 4c 45 43 54 20 73 72 nt(0, "SELECT sr
1c60: 63 69 64 20 46 52 4f 4d 20 64 65 6c 74 61 20 57 cid FROM delta W
1c70: 48 45 52 45 20 72 69 64 3d 25 64 22 2c 20 72 69 HERE rid=%d", ri
1c80: 64 29 3b 0a 20 20 69 66 28 20 73 72 63 49 64 3e d);. if( srcId>
1c90: 30 20 26 26 20 21 63 6f 6e 74 65 6e 74 5f 69 73 0 && !content_is
1ca0: 5f 70 72 69 76 61 74 65 28 73 72 63 49 64 29 20 _private(srcId)
1cb0: 29 7b 0a 20 20 20 20 62 6c 6f 62 5f 7a 65 72 6f ){. blob_zero
1cc0: 28 26 73 72 63 29 3b 0a 20 20 20 20 64 62 5f 62 (&src);. db_b
1cd0: 6c 6f 62 28 26 73 72 63 2c 20 22 53 45 4c 45 43 lob(&src, "SELEC
1ce0: 54 20 75 75 69 64 20 46 52 4f 4d 20 62 6c 6f 62 T uuid FROM blob
1cf0: 20 57 48 45 52 45 20 72 69 64 3d 25 64 22 2c 20 WHERE rid=%d",
1d00: 73 72 63 49 64 29 3b 0a 20 20 20 20 69 66 28 20 srcId);. if(
1d10: 75 75 69 64 5f 69 73 5f 73 68 75 6e 6e 65 64 28 uuid_is_shunned(
1d20: 62 6c 6f 62 5f 73 74 72 28 26 73 72 63 29 29 20 blob_str(&src))
1d30: 29 7b 0a 20 20 20 20 20 20 62 6c 6f 62 5f 72 65 ){. blob_re
1d40: 73 65 74 28 26 73 72 63 29 3b 0a 20 20 20 20 20 set(&src);.
1d50: 20 72 65 74 75 72 6e 20 30 3b 0a 20 20 20 20 7d return 0;. }
1d60: 0a 20 20 20 20 62 6c 6f 62 5f 7a 65 72 6f 28 26 . blob_zero(&
1d70: 64 65 6c 74 61 29 3b 0a 20 20 20 20 64 62 5f 62 delta);. db_b
1d80: 6c 6f 62 28 26 64 65 6c 74 61 2c 20 22 53 45 4c lob(&delta, "SEL
1d90: 45 43 54 20 63 6f 6e 74 65 6e 74 20 46 52 4f 4d ECT content FROM
1da0: 20 62 6c 6f 62 20 57 48 45 52 45 20 72 69 64 3d blob WHERE rid=
1db0: 25 64 22 2c 20 72 69 64 29 3b 0a 20 20 20 20 62 %d", rid);. b
1dc0: 6c 6f 62 5f 75 6e 63 6f 6d 70 72 65 73 73 28 26 lob_uncompress(&
1dd0: 64 65 6c 74 61 2c 20 26 64 65 6c 74 61 29 3b 0a delta, &delta);.
1de0: 20 20 20 20 62 6c 6f 62 5f 61 70 70 65 6e 64 66 blob_appendf
1df0: 28 70 58 66 65 72 2d 3e 70 4f 75 74 2c 20 22 66 (pXfer->pOut, "f
1e00: 69 6c 65 20 25 62 20 25 62 20 25 64 5c 6e 22 2c ile %b %b %d\n",
1e10: 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 .
1e20: 20 70 55 75 69 64 2c 20 26 73 72 63 2c 20 62 6c pUuid, &src, bl
1e30: 6f 62 5f 73 69 7a 65 28 26 64 65 6c 74 61 29 29 ob_size(&delta))
1e40: 3b 0a 20 20 20 20 62 6c 6f 62 5f 61 70 70 65 6e ;. blob_appen
1e50: 64 28 70 58 66 65 72 2d 3e 70 4f 75 74 2c 20 62 d(pXfer->pOut, b
1e60: 6c 6f 62 5f 62 75 66 66 65 72 28 26 64 65 6c 74 lob_buffer(&delt
1e70: 61 29 2c 20 62 6c 6f 62 5f 73 69 7a 65 28 26 64 a), blob_size(&d
1e80: 65 6c 74 61 29 29 3b 0a 20 20 20 20 73 69 7a 65 elta));. size
1e90: 20 3d 20 62 6c 6f 62 5f 73 69 7a 65 28 26 64 65 = blob_size(&de
1ea0: 6c 74 61 29 3b 0a 20 20 20 20 62 6c 6f 62 5f 72 lta);. blob_r
1eb0: 65 73 65 74 28 26 64 65 6c 74 61 29 3b 0a 20 20 eset(&delta);.
1ec0: 20 20 62 6c 6f 62 5f 72 65 73 65 74 28 26 73 72 blob_reset(&sr
1ed0: 63 29 3b 0a 20 20 7d 65 6c 73 65 7b 0a 20 20 20 c);. }else{.
1ee0: 20 73 69 7a 65 20 3d 20 30 3b 0a 20 20 7d 0a 20 size = 0;. }.
1ef0: 20 72 65 74 75 72 6e 20 73 69 7a 65 3b 0a 7d 0a return size;.}.
1f00: 0a 2f 2a 0a 2a 2a 20 53 65 6e 64 20 74 68 65 20 ./*.** Send the
1f10: 66 69 6c 65 20 69 64 65 6e 74 69 66 69 65 64 20 file identified
1f20: 62 79 20 72 69 64 2e 0a 2a 2a 0a 2a 2a 20 54 68 by rid..**.** Th
1f30: 65 20 70 55 75 69 64 20 63 61 6e 20 62 65 20 4e e pUuid can be N
1f40: 55 4c 4c 20 69 6e 20 77 68 69 63 68 20 63 61 73 ULL in which cas
1f50: 65 20 74 68 65 20 63 6f 72 72 65 63 74 20 55 55 e the correct UU
1f60: 49 44 20 69 73 20 63 6f 6d 70 75 74 65 64 0a 2a ID is computed.*
1f70: 2a 20 66 72 6f 6d 20 74 68 65 20 72 69 64 2e 0a * from the rid..
1f80: 2a 2a 0a 2a 2a 20 54 72 79 20 74 6f 20 73 65 6e **.** Try to sen
1f90: 64 20 74 68 65 20 66 69 6c 65 20 61 73 20 61 20 d the file as a
1fa0: 6e 61 74 69 76 65 20 64 65 6c 74 61 20 69 66 20 native delta if
1fb0: 6e 61 74 69 76 65 44 65 6c 74 61 20 69 73 20 74 nativeDelta is t
1fc0: 72 75 65 2c 20 6f 72 0a 2a 2a 20 61 73 20 61 20 rue, or.** as a
1fd0: 70 61 72 65 6e 74 20 64 65 6c 74 61 20 69 66 20 parent delta if
1fe0: 6e 61 74 69 76 65 44 65 6c 74 61 20 69 73 20 66 nativeDelta is f
1ff0: 61 6c 73 65 2e 0a 2a 2a 0a 2a 2a 20 49 74 20 73 alse..**.** It s
2000: 68 6f 75 6c 64 20 6e 65 76 65 72 20 62 65 20 74 hould never be t
2010: 68 65 20 63 61 73 65 20 74 68 61 74 20 72 69 64 he case that rid
2020: 20 69 73 20 61 20 70 72 69 76 61 74 65 20 61 72 is a private ar
2030: 74 69 66 61 63 74 2e 20 20 42 75 74 0a 2a 2a 20 tifact. But.**
2040: 61 73 20 61 20 70 72 65 63 61 75 74 69 6f 6e 2c as a precaution,
2050: 20 74 68 69 73 20 72 6f 75 74 69 6e 65 20 64 6f this routine do
2060: 65 73 20 63 68 65 63 6b 20 6f 6e 20 72 69 64 20 es check on rid
2070: 61 6e 64 20 69 66 20 69 74 20 69 73 20 70 72 69 and if it is pri
2080: 76 61 74 65 0a 2a 2a 20 74 68 69 73 20 72 6f 75 vate.** this rou
2090: 74 69 6e 65 20 62 65 63 6f 6d 65 73 20 61 20 6e tine becomes a n
20a0: 6f 2d 6f 70 2e 0a 2a 2f 0a 73 74 61 74 69 63 20 o-op..*/.static
20b0: 76 6f 69 64 20 73 65 6e 64 5f 66 69 6c 65 28 58 void send_file(X
20c0: 66 65 72 20 2a 70 58 66 65 72 2c 20 69 6e 74 20 fer *pXfer, int
20d0: 72 69 64 2c 20 42 6c 6f 62 20 2a 70 55 75 69 64 rid, Blob *pUuid
20e0: 2c 20 69 6e 74 20 6e 61 74 69 76 65 44 65 6c 74 , int nativeDelt
20f0: 61 29 7b 0a 20 20 42 6c 6f 62 20 63 6f 6e 74 65 a){. Blob conte
2100: 6e 74 2c 20 75 75 69 64 3b 0a 20 20 69 6e 74 20 nt, uuid;. int
2110: 73 69 7a 65 20 3d 20 30 3b 0a 0a 20 20 69 66 28 size = 0;.. if(
2120: 20 63 6f 6e 74 65 6e 74 5f 69 73 5f 70 72 69 76 content_is_priv
2130: 61 74 65 28 72 69 64 29 20 29 20 72 65 74 75 72 ate(rid) ) retur
2140: 6e 3b 0a 20 20 69 66 28 20 64 62 5f 65 78 69 73 n;. if( db_exis
2150: 74 73 28 22 53 45 4c 45 43 54 20 31 20 46 52 4f ts("SELECT 1 FRO
2160: 4d 20 6f 6e 72 65 6d 6f 74 65 20 57 48 45 52 45 M onremote WHERE
2170: 20 72 69 64 3d 25 64 22 2c 20 72 69 64 29 20 29 rid=%d", rid) )
2180: 7b 0a 20 20 20 20 20 72 65 74 75 72 6e 3b 0a 20 {. return;.
2190: 20 7d 0a 20 20 62 6c 6f 62 5f 7a 65 72 6f 28 26 }. blob_zero(&
21a0: 75 75 69 64 29 3b 0a 20 20 64 62 5f 62 6c 6f 62 uuid);. db_blob
21b0: 28 26 75 75 69 64 2c 20 22 53 45 4c 45 43 54 20 (&uuid, "SELECT
21c0: 75 75 69 64 20 46 52 4f 4d 20 62 6c 6f 62 20 57 uuid FROM blob W
21d0: 48 45 52 45 20 72 69 64 3d 25 64 20 41 4e 44 20 HERE rid=%d AND
21e0: 73 69 7a 65 3e 3d 30 22 2c 20 72 69 64 29 3b 0a size>=0", rid);.
21f0: 20 20 69 66 28 20 62 6c 6f 62 5f 73 69 7a 65 28 if( blob_size(
2200: 26 75 75 69 64 29 3d 3d 30 20 29 7b 0a 20 20 20 &uuid)==0 ){.
2210: 20 72 65 74 75 72 6e 3b 0a 20 20 7d 0a 20 20 69 return;. }. i
2220: 66 28 20 70 55 75 69 64 20 29 7b 0a 20 20 20 20 f( pUuid ){.
2230: 69 66 28 20 62 6c 6f 62 5f 63 6f 6d 70 61 72 65 if( blob_compare
2240: 28 70 55 75 69 64 2c 20 26 75 75 69 64 29 21 3d (pUuid, &uuid)!=
2250: 30 20 29 7b 0a 20 20 20 20 20 20 62 6c 6f 62 5f 0 ){. blob_
2260: 72 65 73 65 74 28 26 75 75 69 64 29 3b 0a 20 20 reset(&uuid);.
2270: 20 20 20 20 72 65 74 75 72 6e 3b 0a 20 20 20 20 return;.
2280: 7d 0a 20 20 7d 65 6c 73 65 7b 0a 20 20 20 20 70 }. }else{. p
2290: 55 75 69 64 20 3d 20 26 75 75 69 64 3b 0a 20 20 Uuid = &uuid;.
22a0: 7d 0a 20 20 69 66 28 20 75 75 69 64 5f 69 73 5f }. if( uuid_is_
22b0: 73 68 75 6e 6e 65 64 28 62 6c 6f 62 5f 73 74 72 shunned(blob_str
22c0: 28 70 55 75 69 64 29 29 20 29 7b 0a 20 20 20 20 (pUuid)) ){.
22d0: 62 6c 6f 62 5f 72 65 73 65 74 28 26 75 75 69 64 blob_reset(&uuid
22e0: 29 3b 0a 20 20 20 20 72 65 74 75 72 6e 3b 0a 20 );. return;.
22f0: 20 7d 0a 20 20 69 66 28 20 70 58 66 65 72 2d 3e }. if( pXfer->
2300: 6d 78 53 65 6e 64 3c 3d 62 6c 6f 62 5f 73 69 7a mxSend<=blob_siz
2310: 65 28 70 58 66 65 72 2d 3e 70 4f 75 74 29 20 29 e(pXfer->pOut) )
2320: 7b 0a 20 20 20 20 62 6c 6f 62 5f 61 70 70 65 6e {. blob_appen
2330: 64 66 28 70 58 66 65 72 2d 3e 70 4f 75 74 2c 20 df(pXfer->pOut,
2340: 22 69 67 6f 74 20 25 62 5c 6e 22 2c 20 70 55 75 "igot %b\n", pUu
2350: 69 64 29 3b 0a 20 20 20 20 70 58 66 65 72 2d 3e id);. pXfer->
2360: 6e 49 47 6f 74 53 65 6e 74 2b 2b 3b 0a 20 20 20 nIGotSent++;.
2370: 20 62 6c 6f 62 5f 72 65 73 65 74 28 26 75 75 69 blob_reset(&uui
2380: 64 29 3b 0a 20 20 20 20 72 65 74 75 72 6e 3b 0a d);. return;.
2390: 20 20 7d 0a 20 20 69 66 28 20 6e 61 74 69 76 65 }. if( native
23a0: 44 65 6c 74 61 20 29 7b 0a 20 20 20 20 73 69 7a Delta ){. siz
23b0: 65 20 3d 20 73 65 6e 64 5f 64 65 6c 74 61 5f 6e e = send_delta_n
23c0: 61 74 69 76 65 28 70 58 66 65 72 2c 20 72 69 64 ative(pXfer, rid
23d0: 2c 20 70 55 75 69 64 29 3b 0a 20 20 20 20 69 66 , pUuid);. if
23e0: 28 20 73 69 7a 65 20 29 7b 0a 20 20 20 20 20 20 ( size ){.
23f0: 70 58 66 65 72 2d 3e 6e 44 65 6c 74 61 53 65 6e pXfer->nDeltaSen
2400: 74 2b 2b 3b 0a 20 20 20 20 7d 0a 20 20 7d 0a 20 t++;. }. }.
2410: 20 69 66 28 20 73 69 7a 65 3d 3d 30 20 29 7b 0a if( size==0 ){.
2420: 20 20 20 20 63 6f 6e 74 65 6e 74 5f 67 65 74 28 content_get(
2430: 72 69 64 2c 20 26 63 6f 6e 74 65 6e 74 29 3b 0a rid, &content);.
2440: 0a 20 20 20 20 69 66 28 20 21 6e 61 74 69 76 65 . if( !native
2450: 44 65 6c 74 61 20 26 26 20 62 6c 6f 62 5f 73 69 Delta && blob_si
2460: 7a 65 28 26 63 6f 6e 74 65 6e 74 29 3e 31 30 30 ze(&content)>100
2470: 20 29 7b 0a 20 20 20 20 20 20 73 69 7a 65 20 3d ){. size =
2480: 20 73 65 6e 64 5f 64 65 6c 74 61 5f 70 61 72 65 send_delta_pare
2490: 6e 74 28 70 58 66 65 72 2c 20 72 69 64 2c 20 26 nt(pXfer, rid, &
24a0: 63 6f 6e 74 65 6e 74 2c 20 70 55 75 69 64 29 3b content, pUuid);
24b0: 0a 20 20 20 20 7d 0a 20 20 20 20 69 66 28 20 73 . }. if( s
24c0: 69 7a 65 3d 3d 30 20 29 7b 0a 20 20 20 20 20 20 ize==0 ){.
24d0: 69 6e 74 20 73 69 7a 65 20 3d 20 62 6c 6f 62 5f int size = blob_
24e0: 73 69 7a 65 28 26 63 6f 6e 74 65 6e 74 29 3b 0a size(&content);.
24f0: 20 20 20 20 20 20 62 6c 6f 62 5f 61 70 70 65 6e blob_appen
2500: 64 66 28 70 58 66 65 72 2d 3e 70 4f 75 74 2c 20 df(pXfer->pOut,
2510: 22 66 69 6c 65 20 25 62 20 25 64 5c 6e 22 2c 20 "file %b %d\n",
2520: 70 55 75 69 64 2c 20 73 69 7a 65 29 3b 0a 20 20 pUuid, size);.
2530: 20 20 20 20 62 6c 6f 62 5f 61 70 70 65 6e 64 28 blob_append(
2540: 70 58 66 65 72 2d 3e 70 4f 75 74 2c 20 62 6c 6f pXfer->pOut, blo
2550: 62 5f 62 75 66 66 65 72 28 26 63 6f 6e 74 65 6e b_buffer(&conten
2560: 74 29 2c 20 73 69 7a 65 29 3b 0a 20 20 20 20 20 t), size);.
2570: 20 70 58 66 65 72 2d 3e 6e 46 69 6c 65 53 65 6e pXfer->nFileSen
2580: 74 2b 2b 3b 0a 20 20 20 20 7d 65 6c 73 65 7b 0a t++;. }else{.
2590: 20 20 20 20 20 20 70 58 66 65 72 2d 3e 6e 44 65 pXfer->nDe
25a0: 6c 74 61 53 65 6e 74 2b 2b 3b 0a 20 20 20 20 7d ltaSent++;. }
25b0: 0a 20 20 7d 0a 20 20 72 65 6d 6f 74 65 5f 68 61 . }. remote_ha
25c0: 73 28 72 69 64 29 3b 0a 20 20 62 6c 6f 62 5f 72 s(rid);. blob_r
25d0: 65 73 65 74 28 26 75 75 69 64 29 3b 0a 7d 0a 0a eset(&uuid);.}..
25e0: 2f 2a 0a 2a 2a 20 53 65 6e 64 20 61 20 67 69 6d /*.** Send a gim
25f0: 6d 65 20 6d 65 73 73 61 67 65 20 66 6f 72 20 65 me message for e
2600: 76 65 72 79 20 70 68 61 6e 74 6f 6d 2e 0a 2a 2a very phantom..**
2610: 0a 2a 2a 20 49 74 20 73 68 6f 75 6c 64 20 6e 6f .** It should no
2620: 74 20 62 65 20 70 6f 73 73 69 62 6c 65 20 74 6f t be possible to
2630: 20 68 61 76 65 20 61 20 70 72 69 76 61 74 65 20 have a private
2640: 70 68 61 6e 74 6f 6d 2e 20 20 42 75 74 20 6a 75 phantom. But ju
2650: 73 74 20 74 6f 20 62 65 0a 2a 2a 20 73 75 72 65 st to be.** sure
2660: 2c 20 74 61 6b 65 20 63 61 72 65 20 6e 6f 74 20 , take care not
2670: 74 6f 20 73 65 6e 64 20 61 6e 79 20 22 67 69 6d to send any "gim
2680: 6d 65 22 20 6d 65 73 73 61 67 73 65 20 6f 6e 20 me" messagse on
2690: 70 72 69 76 61 74 65 20 61 72 74 69 66 61 63 74 private artifact
26a0: 73 2e 0a 2a 2f 0a 73 74 61 74 69 63 20 76 6f 69 s..*/.static voi
26b0: 64 20 72 65 71 75 65 73 74 5f 70 68 61 6e 74 6f d request_phanto
26c0: 6d 73 28 58 66 65 72 20 2a 70 58 66 65 72 2c 20 ms(Xfer *pXfer,
26d0: 69 6e 74 20 6d 61 78 52 65 71 29 7b 0a 20 20 53 int maxReq){. S
26e0: 74 6d 74 20 71 3b 0a 20 20 64 62 5f 70 72 65 70 tmt q;. db_prep
26f0: 61 72 65 28 26 71 2c 20 0a 20 20 20 20 22 53 45 are(&q, . "SE
2700: 4c 45 43 54 20 75 75 69 64 20 46 52 4f 4d 20 70 LECT uuid FROM p
2710: 68 61 6e 74 6f 6d 20 4a 4f 49 4e 20 62 6c 6f 62 hantom JOIN blob
2720: 20 55 53 49 4e 47 28 72 69 64 29 22 0a 20 20 20 USING(rid)".
2730: 20 22 20 57 48 45 52 45 20 4e 4f 54 20 45 58 49 " WHERE NOT EXI
2740: 53 54 53 28 53 45 4c 45 43 54 20 31 20 46 52 4f STS(SELECT 1 FRO
2750: 4d 20 73 68 75 6e 20 57 48 45 52 45 20 75 75 69 M shun WHERE uui
2760: 64 3d 62 6c 6f 62 2e 75 75 69 64 29 22 0a 20 20 d=blob.uuid)".
2770: 20 20 22 20 20 20 41 4e 44 20 4e 4f 54 20 45 58 " AND NOT EX
2780: 49 53 54 53 28 53 45 4c 45 43 54 20 31 20 46 52 ISTS(SELECT 1 FR
2790: 4f 4d 20 70 72 69 76 61 74 65 20 57 48 45 52 45 OM private WHERE
27a0: 20 72 69 64 3d 62 6c 6f 62 2e 72 69 64 29 22 0a rid=blob.rid)".
27b0: 20 20 29 3b 0a 20 20 77 68 69 6c 65 28 20 64 62 );. while( db
27c0: 5f 73 74 65 70 28 26 71 29 3d 3d 53 51 4c 49 54 _step(&q)==SQLIT
27d0: 45 5f 52 4f 57 20 26 26 20 6d 61 78 52 65 71 2d E_ROW && maxReq-
27e0: 2d 20 3e 20 30 20 29 7b 0a 20 20 20 20 63 6f 6e - > 0 ){. con
27f0: 73 74 20 63 68 61 72 20 2a 7a 55 75 69 64 20 3d st char *zUuid =
2800: 20 64 62 5f 63 6f 6c 75 6d 6e 5f 74 65 78 74 28 db_column_text(
2810: 26 71 2c 20 30 29 3b 0a 20 20 20 20 62 6c 6f 62 &q, 0);. blob
2820: 5f 61 70 70 65 6e 64 66 28 70 58 66 65 72 2d 3e _appendf(pXfer->
2830: 70 4f 75 74 2c 20 22 67 69 6d 6d 65 20 25 73 5c pOut, "gimme %s\
2840: 6e 22 2c 20 7a 55 75 69 64 29 3b 0a 20 20 20 20 n", zUuid);.
2850: 70 58 66 65 72 2d 3e 6e 47 69 6d 6d 65 53 65 6e pXfer->nGimmeSen
2860: 74 2b 2b 3b 0a 20 20 7d 0a 20 20 64 62 5f 66 69 t++;. }. db_fi
2870: 6e 61 6c 69 7a 65 28 26 71 29 3b 0a 7d 0a 0a 2f nalize(&q);.}../
2880: 2a 0a 2a 2a 20 43 6f 6d 70 75 74 65 20 61 6e 20 *.** Compute an
2890: 53 48 41 31 20 68 61 73 68 20 6f 6e 20 74 68 65 SHA1 hash on the
28a0: 20 74 61 69 6c 20 6f 66 20 70 4d 73 67 2e 20 20 tail of pMsg.
28b0: 56 65 72 69 66 79 20 74 68 61 74 20 69 74 20 6d Verify that it m
28c0: 61 74 63 68 65 73 20 74 68 65 0a 2a 2a 20 74 68 atches the.** th
28d0: 65 20 68 61 73 68 20 67 69 76 65 6e 20 69 6e 20 e hash given in
28e0: 70 48 61 73 68 2e 20 20 52 65 74 75 72 6e 20 31 pHash. Return 1
28f0: 20 6f 6e 20 61 20 73 75 63 63 65 73 73 66 75 6c on a successful
2900: 20 6d 61 74 63 68 2e 20 20 52 65 74 75 72 6e 20 match. Return
2910: 30 0a 2a 2a 20 69 66 20 74 68 65 72 65 20 69 73 0.** if there is
2920: 20 61 20 6d 69 73 6d 61 74 63 68 2e 0a 2a 2f 0a a mismatch..*/.
2930: 73 74 61 74 69 63 20 69 6e 74 20 63 68 65 63 6b static int check
2940: 5f 74 61 69 6c 5f 68 61 73 68 28 42 6c 6f 62 20 _tail_hash(Blob
2950: 2a 70 48 61 73 68 2c 20 42 6c 6f 62 20 2a 70 4d *pHash, Blob *pM
2960: 73 67 29 7b 0a 20 20 42 6c 6f 62 20 74 61 69 6c sg){. Blob tail
2970: 3b 0a 20 20 42 6c 6f 62 20 68 32 3b 0a 20 20 69 ;. Blob h2;. i
2980: 6e 74 20 72 63 3b 0a 20 20 62 6c 6f 62 5f 74 61 nt rc;. blob_ta
2990: 69 6c 28 70 4d 73 67 2c 20 26 74 61 69 6c 29 3b il(pMsg, &tail);
29a0: 0a 20 20 73 68 61 31 73 75 6d 5f 62 6c 6f 62 28 . sha1sum_blob(
29b0: 26 74 61 69 6c 2c 20 26 68 32 29 3b 0a 20 20 72 &tail, &h2);. r
29c0: 63 20 3d 20 62 6c 6f 62 5f 63 6f 6d 70 61 72 65 c = blob_compare
29d0: 28 70 48 61 73 68 2c 20 26 68 32 29 3b 0a 20 20 (pHash, &h2);.
29e0: 62 6c 6f 62 5f 72 65 73 65 74 28 26 68 32 29 3b blob_reset(&h2);
29f0: 0a 20 20 62 6c 6f 62 5f 72 65 73 65 74 28 26 74 . blob_reset(&t
2a00: 61 69 6c 29 3b 0a 20 20 72 65 74 75 72 6e 20 72 ail);. return r
2a10: 63 3d 3d 30 3b 0a 7d 0a 0a 0a 2f 2a 0a 2a 2a 20 c==0;.}.../*.**
2a20: 43 68 65 63 6b 20 74 68 65 20 73 69 67 6e 61 74 Check the signat
2a30: 75 72 65 20 6f 6e 20 61 6e 20 61 70 70 6c 69 63 ure on an applic
2a40: 61 74 69 6f 6e 2f 78 2d 66 6f 73 73 69 6c 20 70 ation/x-fossil p
2a50: 61 79 6c 6f 61 64 20 72 65 63 65 69 76 65 64 20 ayload received
2a60: 62 79 0a 2a 2a 20 74 68 65 20 48 54 54 50 20 73 by.** the HTTP s
2a70: 65 72 76 65 72 2e 20 20 54 68 65 20 73 69 67 6e erver. The sign
2a80: 61 74 75 72 65 20 69 73 20 61 20 6c 69 6e 65 20 ature is a line
2a90: 6f 66 20 74 68 65 20 66 6f 6c 6c 6f 77 69 6e 67 of the following
2aa0: 20 66 6f 72 6d 3a 0a 2a 2a 0a 2a 2a 20 20 20 20 form:.**.**
2ab0: 20 20 20 20 6c 6f 67 69 6e 20 4c 4f 47 49 4e 20 login LOGIN
2ac0: 4e 4f 4e 43 45 20 53 49 47 4e 41 54 55 52 45 0a NONCE SIGNATURE.
2ad0: 2a 2a 0a 2a 2a 20 54 68 65 20 4e 4f 4e 43 45 20 **.** The NONCE
2ae0: 69 73 20 74 68 65 20 53 48 41 31 20 68 61 73 68 is the SHA1 hash
2af0: 20 6f 66 20 74 68 65 20 72 65 6d 61 69 6e 64 65 of the remainde
2b00: 72 20 6f 66 20 74 68 65 20 69 6e 70 75 74 2e 20 r of the input.
2b10: 20 0a 2a 2a 20 53 49 47 4e 41 54 55 52 45 20 69 .** SIGNATURE i
2b20: 73 20 74 68 65 20 53 48 41 31 20 63 68 65 63 6b s the SHA1 check
2b30: 73 75 6d 20 6f 66 20 74 68 65 20 4e 4f 4e 43 45 sum of the NONCE
2b40: 20 63 6f 6e 63 61 74 65 6e 61 74 65 64 20 0a 2a concatenated .*
2b50: 2a 20 77 69 74 68 20 74 68 65 20 75 73 65 72 73 * with the users
2b60: 20 70 61 73 73 77 6f 72 64 2e 0a 2a 2a 0a 2a 2a password..**.**
2b70: 20 54 68 65 20 70 61 72 61 6d 65 74 65 72 73 20 The parameters
2b80: 74 6f 20 74 68 69 73 20 72 6f 75 74 69 6e 65 20 to this routine
2b90: 61 72 65 20 65 70 68 65 72 6d 65 72 61 6c 20 62 are ephermeral b
2ba0: 6c 6f 62 73 20 68 6f 6c 64 69 6e 67 20 74 68 65 lobs holding the
2bb0: 0a 2a 2a 20 4c 4f 47 49 4e 2c 20 4e 4f 4e 43 45 .** LOGIN, NONCE
2bc0: 20 61 6e 64 20 53 49 47 4e 41 54 55 52 45 2e 0a and SIGNATURE..
2bd0: 2a 2a 0a 2a 2a 20 54 68 69 73 20 72 6f 75 74 69 **.** This routi
2be0: 6e 65 20 61 74 74 65 6d 70 74 73 20 74 6f 20 6c ne attempts to l
2bf0: 6f 63 61 74 65 20 74 68 65 20 75 73 65 72 20 61 ocate the user a
2c00: 6e 64 20 76 65 72 69 66 79 20 74 68 65 20 73 69 nd verify the si
2c10: 67 6e 61 74 75 72 65 2e 0a 2a 2a 20 49 66 20 65 gnature..** If e
2c20: 76 65 72 79 74 68 69 6e 67 20 63 68 65 63 6b 73 verything checks
2c30: 20 6f 75 74 2c 20 74 68 65 20 55 53 45 52 2e 43 out, the USER.C
2c40: 41 50 20 63 6f 6c 75 6d 6e 20 66 6f 72 20 74 68 AP column for th
2c50: 65 20 55 53 45 52 20 74 61 62 6c 65 0a 2a 2a 20 e USER table.**
2c60: 69 73 20 63 6f 6e 73 75 6c 74 65 64 20 74 6f 20 is consulted to
2c70: 73 65 74 20 70 72 69 76 69 6c 65 67 65 73 20 69 set privileges i
2c80: 6e 20 74 68 65 20 67 6c 6f 62 61 6c 20 67 20 76 n the global g v
2c90: 61 72 69 61 62 6c 65 2e 0a 2a 2a 0a 2a 2a 20 49 ariable..**.** I
2ca0: 66 20 61 6e 79 74 68 69 6e 67 20 66 61 69 6c 73 f anything fails
2cb0: 20 74 6f 20 63 68 65 63 6b 20 6f 75 74 2c 20 6e to check out, n
2cc0: 6f 20 63 68 61 6e 67 65 73 20 61 72 65 20 6d 61 o changes are ma
2cd0: 64 65 20 74 6f 20 70 72 69 76 69 6c 65 67 65 73 de to privileges
2ce0: 2e 0a 2a 2a 0a 2a 2a 20 53 69 67 6e 61 74 75 72 ..**.** Signatur
2cf0: 65 20 67 65 6e 65 72 61 74 69 6f 6e 20 6f 6e 20 e generation on
2d00: 74 68 65 20 63 6c 69 65 6e 74 20 73 69 64 65 20 the client side
2d10: 69 73 20 68 61 6e 64 6c 65 64 20 62 79 20 74 68 is handled by th
2d20: 65 20 0a 2a 2a 20 68 74 74 70 5f 65 78 63 68 61 e .** http_excha
2d30: 6e 67 65 28 29 20 72 6f 75 74 69 6e 65 2e 0a 2a nge() routine..*
2d40: 2f 0a 76 6f 69 64 20 63 68 65 63 6b 5f 6c 6f 67 /.void check_log
2d50: 69 6e 28 42 6c 6f 62 20 2a 70 4c 6f 67 69 6e 2c in(Blob *pLogin,
2d60: 20 42 6c 6f 62 20 2a 70 4e 6f 6e 63 65 2c 20 42 Blob *pNonce, B
2d70: 6c 6f 62 20 2a 70 53 69 67 29 7b 0a 20 20 53 74 lob *pSig){. St
2d80: 6d 74 20 71 3b 0a 20 20 69 6e 74 20 72 63 3b 0a mt q;. int rc;.
2d90: 0a 20 20 64 62 5f 70 72 65 70 61 72 65 28 26 71 . db_prepare(&q
2da0: 2c 20 22 53 45 4c 45 43 54 20 70 77 2c 20 63 61 , "SELECT pw, ca
2db0: 70 2c 20 75 69 64 20 46 52 4f 4d 20 75 73 65 72 p, uid FROM user
2dc0: 20 57 48 45 52 45 20 6c 6f 67 69 6e 3d 25 42 22 WHERE login=%B"
2dd0: 2c 20 70 4c 6f 67 69 6e 29 3b 0a 20 20 69 66 28 , pLogin);. if(
2de0: 20 64 62 5f 73 74 65 70 28 26 71 29 3d 3d 53 51 db_step(&q)==SQ
2df0: 4c 49 54 45 5f 52 4f 57 20 29 7b 0a 20 20 20 20 LITE_ROW ){.
2e00: 42 6c 6f 62 20 70 77 2c 20 63 6f 6d 62 69 6e 65 Blob pw, combine
2e10: 64 2c 20 68 61 73 68 3b 0a 20 20 20 20 62 6c 6f d, hash;. blo
2e20: 62 5f 7a 65 72 6f 28 26 70 77 29 3b 0a 20 20 20 b_zero(&pw);.
2e30: 20 64 62 5f 65 70 68 65 6d 65 72 61 6c 5f 62 6c db_ephemeral_bl
2e40: 6f 62 28 26 71 2c 20 30 2c 20 26 70 77 29 3b 0a ob(&q, 0, &pw);.
2e50: 20 20 20 20 62 6c 6f 62 5f 7a 65 72 6f 28 26 63 blob_zero(&c
2e60: 6f 6d 62 69 6e 65 64 29 3b 0a 20 20 20 20 62 6c ombined);. bl
2e70: 6f 62 5f 63 6f 70 79 28 26 63 6f 6d 62 69 6e 65 ob_copy(&combine
2e80: 64 2c 20 70 4e 6f 6e 63 65 29 3b 0a 20 20 20 20 d, pNonce);.
2e90: 62 6c 6f 62 5f 61 70 70 65 6e 64 28 26 63 6f 6d blob_append(&com
2ea0: 62 69 6e 65 64 2c 20 62 6c 6f 62 5f 62 75 66 66 bined, blob_buff
2eb0: 65 72 28 26 70 77 29 2c 20 62 6c 6f 62 5f 73 69 er(&pw), blob_si
2ec0: 7a 65 28 26 70 77 29 29 3b 0a 20 20 20 20 2f 2a ze(&pw));. /*
2ed0: 20 43 47 49 44 45 42 55 47 28 28 22 70 72 65 73 CGIDEBUG(("pres
2ee0: 69 67 3d 5b 25 73 5d 5c 6e 22 2c 20 62 6c 6f 62 ig=[%s]\n", blob
2ef0: 5f 73 74 72 28 26 63 6f 6d 62 69 6e 65 64 29 29 _str(&combined))
2f00: 29 3b 20 2a 2f 0a 20 20 20 20 73 68 61 31 73 75 ); */. sha1su
2f10: 6d 5f 62 6c 6f 62 28 26 63 6f 6d 62 69 6e 65 64 m_blob(&combined
2f20: 2c 20 26 68 61 73 68 29 3b 0a 20 20 20 20 72 63 , &hash);. rc
2f30: 20 3d 20 62 6c 6f 62 5f 63 6f 6d 70 61 72 65 28 = blob_compare(
2f40: 26 68 61 73 68 2c 20 70 53 69 67 29 3b 0a 20 20 &hash, pSig);.
2f50: 20 20 62 6c 6f 62 5f 72 65 73 65 74 28 26 68 61 blob_reset(&ha
2f60: 73 68 29 3b 0a 20 20 20 20 62 6c 6f 62 5f 72 65 sh);. blob_re
2f70: 73 65 74 28 26 63 6f 6d 62 69 6e 65 64 29 3b 0a set(&combined);.
2f80: 20 20 20 20 69 66 28 20 72 63 3d 3d 30 20 29 7b if( rc==0 ){
2f90: 0a 20 20 20 20 20 20 63 6f 6e 73 74 20 63 68 61 . const cha
2fa0: 72 20 2a 7a 43 61 70 3b 0a 20 20 20 20 20 20 7a r *zCap;. z
2fb0: 43 61 70 20 3d 20 64 62 5f 63 6f 6c 75 6d 6e 5f Cap = db_column_
2fc0: 74 65 78 74 28 26 71 2c 20 31 29 3b 0a 20 20 20 text(&q, 1);.
2fd0: 20 20 20 6c 6f 67 69 6e 5f 73 65 74 5f 63 61 70 login_set_cap
2fe0: 61 62 69 6c 69 74 69 65 73 28 7a 43 61 70 29 3b abilities(zCap);
2ff0: 0a 20 20 20 20 20 20 67 2e 75 73 65 72 55 69 64 . g.userUid
3000: 20 3d 20 64 62 5f 63 6f 6c 75 6d 6e 5f 69 6e 74 = db_column_int
3010: 28 26 71 2c 20 32 29 3b 0a 20 20 20 20 20 20 67 (&q, 2);. g
3020: 2e 7a 4c 6f 67 69 6e 20 3d 20 6d 70 72 69 6e 74 .zLogin = mprint
3030: 66 28 22 25 62 22 2c 20 70 4c 6f 67 69 6e 29 3b f("%b", pLogin);
3040: 0a 20 20 20 20 20 20 67 2e 7a 4e 6f 6e 63 65 20 . g.zNonce
3050: 3d 20 6d 70 72 69 6e 74 66 28 22 25 62 22 2c 20 = mprintf("%b",
3060: 70 4e 6f 6e 63 65 29 3b 0a 20 20 20 20 7d 0a 20 pNonce);. }.
3070: 20 7d 0a 20 20 64 62 5f 66 69 6e 61 6c 69 7a 65 }. db_finalize
3080: 28 26 71 29 3b 0a 7d 0a 0a 2f 2a 0a 2a 2a 20 53 (&q);.}../*.** S
3090: 65 6e 64 20 74 68 65 20 63 6f 6e 74 65 6e 74 20 end the content
30a0: 6f 66 20 61 6c 6c 20 66 69 6c 65 73 20 69 6e 20 of all files in
30b0: 74 68 65 20 75 6e 73 65 6e 74 20 74 61 62 6c 65 the unsent table
30c0: 2e 0a 2a 2a 0a 2a 2a 20 54 68 69 73 20 69 73 20 ..**.** This is
30d0: 72 65 61 6c 6c 79 20 6a 75 73 74 20 61 6e 20 6f really just an o
30e0: 70 74 69 6d 69 7a 61 74 69 6f 6e 2e 20 20 49 66 ptimization. If
30f0: 20 79 6f 75 20 63 6c 65 61 72 20 74 68 65 0a 2a you clear the.*
3100: 2a 20 75 6e 73 65 6e 74 20 74 61 62 6c 65 2c 20 * unsent table,
3110: 61 6c 6c 20 74 68 65 20 72 69 67 68 74 20 66 69 all the right fi
3120: 6c 65 73 20 77 69 6c 6c 20 73 74 69 6c 6c 20 67 les will still g
3130: 65 74 20 74 72 61 6e 73 66 65 72 72 65 64 2e 0a et transferred..
3140: 2a 2a 20 49 74 20 6a 75 73 74 20 6d 69 67 68 74 ** It just might
3150: 20 72 65 71 75 69 72 65 20 61 6e 20 65 78 74 72 require an extr
3160: 61 20 72 6f 75 6e 64 20 74 72 69 70 20 6f 72 20 a round trip or
3170: 74 77 6f 2e 0a 2a 2f 0a 73 74 61 74 69 63 20 76 two..*/.static v
3180: 6f 69 64 20 73 65 6e 64 5f 75 6e 73 65 6e 74 28 oid send_unsent(
3190: 58 66 65 72 20 2a 70 58 66 65 72 29 7b 0a 20 20 Xfer *pXfer){.
31a0: 53 74 6d 74 20 71 3b 0a 20 20 64 62 5f 70 72 65 Stmt q;. db_pre
31b0: 70 61 72 65 28 26 71 2c 20 22 53 45 4c 45 43 54 pare(&q, "SELECT
31c0: 20 72 69 64 20 46 52 4f 4d 20 75 6e 73 65 6e 74 rid FROM unsent
31d0: 20 45 58 43 45 50 54 20 53 45 4c 45 43 54 20 72 EXCEPT SELECT r
31e0: 69 64 20 46 52 4f 4d 20 70 72 69 76 61 74 65 22 id FROM private"
31f0: 29 3b 0a 20 20 77 68 69 6c 65 28 20 64 62 5f 73 );. while( db_s
3200: 74 65 70 28 26 71 29 3d 3d 53 51 4c 49 54 45 5f tep(&q)==SQLITE_
3210: 52 4f 57 20 29 7b 0a 20 20 20 20 69 6e 74 20 72 ROW ){. int r
3220: 69 64 20 3d 20 64 62 5f 63 6f 6c 75 6d 6e 5f 69 id = db_column_i
3230: 6e 74 28 26 71 2c 20 30 29 3b 0a 20 20 20 20 73 nt(&q, 0);. s
3240: 65 6e 64 5f 66 69 6c 65 28 70 58 66 65 72 2c 20 end_file(pXfer,
3250: 72 69 64 2c 20 30 2c 20 30 29 3b 0a 20 20 7d 0a rid, 0, 0);. }.
3260: 20 20 64 62 5f 66 69 6e 61 6c 69 7a 65 28 26 71 db_finalize(&q
3270: 29 3b 0a 20 20 64 62 5f 6d 75 6c 74 69 5f 65 78 );. db_multi_ex
3280: 65 63 28 22 44 45 4c 45 54 45 20 46 52 4f 4d 20 ec("DELETE FROM
3290: 75 6e 73 65 6e 74 22 29 3b 0a 7d 0a 0a 2f 2a 0a unsent");.}../*.
32a0: 2a 2a 20 43 68 65 63 6b 20 74 6f 20 73 65 65 20 ** Check to see
32b0: 69 66 20 74 68 65 20 6e 75 6d 62 65 72 20 6f 66 if the number of
32c0: 20 75 6e 63 6c 75 73 74 65 72 65 64 20 65 6e 74 unclustered ent
32d0: 72 69 65 73 20 69 73 20 67 72 65 61 74 65 72 20 ries is greater
32e0: 74 68 61 6e 0a 2a 2a 20 31 30 30 20 61 6e 64 20 than.** 100 and
32f0: 69 66 20 69 74 20 69 73 2c 20 66 6f 72 6d 20 61 if it is, form a
3300: 20 6e 65 77 20 63 6c 75 73 74 65 72 2e 20 20 55 new cluster. U
3310: 6e 63 6c 75 73 74 65 72 65 64 20 70 68 61 6e 74 nclustered phant
3320: 6f 6d 73 20 64 6f 20 6e 6f 74 0a 2a 2a 20 63 6f oms do not.** co
3330: 75 6e 74 20 74 6f 77 61 72 64 20 74 68 65 20 31 unt toward the 1
3340: 30 30 20 74 6f 74 61 6c 2e 20 20 41 6e 64 20 70 00 total. And p
3350: 68 61 6e 74 6f 6d 73 20 61 72 65 20 6e 65 76 65 hantoms are neve
3360: 72 20 61 64 64 65 64 20 74 6f 20 61 20 6e 65 77 r added to a new
3370: 0a 2a 2a 20 63 6c 75 73 74 65 72 2e 0a 2a 2f 0a .** cluster..*/.
3380: 73 74 61 74 69 63 20 76 6f 69 64 20 63 72 65 61 static void crea
3390: 74 65 5f 63 6c 75 73 74 65 72 28 76 6f 69 64 29 te_cluster(void)
33a0: 7b 0a 20 20 42 6c 6f 62 20 63 6c 75 73 74 65 72 {. Blob cluster
33b0: 2c 20 63 6b 73 75 6d 3b 0a 20 20 53 74 6d 74 20 , cksum;. Stmt
33c0: 71 3b 0a 20 20 69 6e 74 20 6e 55 6e 63 6c 3b 0a q;. int nUncl;.
33d0: 0a 20 20 2f 2a 20 57 65 20 73 68 6f 75 6c 64 20 . /* We should
33e0: 6e 6f 74 20 65 76 65 72 20 67 65 74 20 61 6e 79 not ever get any
33f0: 20 70 72 69 76 61 74 65 20 61 72 74 69 66 61 63 private artifac
3400: 74 73 20 69 6e 20 74 68 65 20 75 6e 63 6c 75 73 ts in the unclus
3410: 74 65 72 65 64 20 74 61 62 6c 65 2e 0a 20 20 2a tered table.. *
3420: 2a 20 42 75 74 20 69 66 20 77 65 20 64 6f 20 28 * But if we do (
3430: 62 65 63 61 75 73 65 20 6f 66 20 61 20 62 75 67 because of a bug
3440: 29 20 6e 6f 77 20 69 73 20 61 20 67 6f 6f 64 20 ) now is a good
3450: 74 69 6d 65 20 74 6f 20 64 65 6c 65 74 65 20 74 time to delete t
3460: 68 65 6d 2e 20 2a 2f 0a 20 20 64 62 5f 6d 75 6c hem. */. db_mul
3470: 74 69 5f 65 78 65 63 28 0a 20 20 20 20 22 44 45 ti_exec(. "DE
3480: 4c 45 54 45 20 46 52 4f 4d 20 75 6e 63 6c 75 73 LETE FROM unclus
3490: 74 65 72 65 64 20 57 48 45 52 45 20 72 69 64 20 tered WHERE rid
34a0: 49 4e 20 28 53 45 4c 45 43 54 20 72 69 64 20 46 IN (SELECT rid F
34b0: 52 4f 4d 20 70 72 69 76 61 74 65 29 22 0a 20 20 ROM private)".
34c0: 29 3b 0a 0a 20 20 6e 55 6e 63 6c 20 3d 20 64 62 );.. nUncl = db
34d0: 5f 69 6e 74 28 30 2c 20 22 53 45 4c 45 43 54 20 _int(0, "SELECT
34e0: 63 6f 75 6e 74 28 2a 29 20 46 52 4f 4d 20 75 6e count(*) FROM un
34f0: 63 6c 75 73 74 65 72 65 64 22 0a 20 20 20 20 20 clustered".
3500: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 22 "
3510: 20 57 48 45 52 45 20 4e 4f 54 20 45 58 49 53 54 WHERE NOT EXIST
3520: 53 28 53 45 4c 45 43 54 20 31 20 46 52 4f 4d 20 S(SELECT 1 FROM
3530: 70 68 61 6e 74 6f 6d 22 0a 20 20 20 20 20 20 20 phantom".
3540: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
3550: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 22 "
3560: 20 57 48 45 52 45 20 72 69 64 3d 75 6e 63 6c 75 WHERE rid=unclu
3570: 73 74 65 72 65 64 2e 72 69 64 29 22 29 3b 0a 20 stered.rid)");.
3580: 20 69 66 28 20 6e 55 6e 63 6c 3c 31 30 30 20 29 if( nUncl<100 )
3590: 7b 0a 20 20 20 20 72 65 74 75 72 6e 3b 0a 20 20 {. return;.
35a0: 7d 0a 20 20 62 6c 6f 62 5f 7a 65 72 6f 28 26 63 }. blob_zero(&c
35b0: 6c 75 73 74 65 72 29 3b 0a 20 20 64 62 5f 70 72 luster);. db_pr
35c0: 65 70 61 72 65 28 26 71 2c 20 22 53 45 4c 45 43 epare(&q, "SELEC
35d0: 54 20 75 75 69 64 20 46 52 4f 4d 20 75 6e 63 6c T uuid FROM uncl
35e0: 75 73 74 65 72 65 64 2c 20 62 6c 6f 62 22 0a 20 ustered, blob".
35f0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
3600: 22 20 57 48 45 52 45 20 4e 4f 54 20 45 58 49 53 " WHERE NOT EXIS
3610: 54 53 28 53 45 4c 45 43 54 20 31 20 46 52 4f 4d TS(SELECT 1 FROM
3620: 20 70 68 61 6e 74 6f 6d 22 0a 20 20 20 20 20 20 phantom".
3630: 20 20 20 20 20 20 20 20 20 20 20 22 20 20 20 20 "
3640: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 57 W
3650: 48 45 52 45 20 72 69 64 3d 75 6e 63 6c 75 73 74 HERE rid=unclust
3660: 65 72 65 64 2e 72 69 64 29 22 0a 20 20 20 20 20 ered.rid)".
3670: 20 20 20 20 20 20 20 20 20 20 20 20 22 20 20 20 "
3680: 41 4e 44 20 75 6e 63 6c 75 73 74 65 72 65 64 2e AND unclustered.
3690: 72 69 64 3d 62 6c 6f 62 2e 72 69 64 22 0a 20 20 rid=blob.rid".
36a0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 22 "
36b0: 20 20 20 41 4e 44 20 4e 4f 54 20 45 58 49 53 54 AND NOT EXIST
36c0: 53 28 53 45 4c 45 43 54 20 31 20 46 52 4f 4d 20 S(SELECT 1 FROM
36d0: 73 68 75 6e 20 57 48 45 52 45 20 75 75 69 64 3d shun WHERE uuid=
36e0: 62 6c 6f 62 2e 75 75 69 64 29 22 0a 20 20 20 20 blob.uuid)".
36f0: 20 20 20 20 20 20 20 20 20 20 20 20 20 22 20 4f " O
3700: 52 44 45 52 20 42 59 20 31 22 29 3b 0a 20 20 77 RDER BY 1");. w
3710: 68 69 6c 65 28 20 64 62 5f 73 74 65 70 28 26 71 hile( db_step(&q
3720: 29 3d 3d 53 51 4c 49 54 45 5f 52 4f 57 20 29 7b )==SQLITE_ROW ){
3730: 0a 20 20 20 20 62 6c 6f 62 5f 61 70 70 65 6e 64 . blob_append
3740: 66 28 26 63 6c 75 73 74 65 72 2c 20 22 4d 20 25 f(&cluster, "M %
3750: 73 5c 6e 22 2c 20 64 62 5f 63 6f 6c 75 6d 6e 5f s\n", db_column_
3760: 74 65 78 74 28 26 71 2c 20 30 29 29 3b 0a 20 20 text(&q, 0));.
3770: 7d 0a 20 20 64 62 5f 66 69 6e 61 6c 69 7a 65 28 }. db_finalize(
3780: 26 71 29 3b 0a 20 20 6d 64 35 73 75 6d 5f 62 6c &q);. md5sum_bl
3790: 6f 62 28 26 63 6c 75 73 74 65 72 2c 20 26 63 6b ob(&cluster, &ck
37a0: 73 75 6d 29 3b 0a 20 20 62 6c 6f 62 5f 61 70 70 sum);. blob_app
37b0: 65 6e 64 66 28 26 63 6c 75 73 74 65 72 2c 20 22 endf(&cluster, "
37c0: 5a 20 25 62 5c 6e 22 2c 20 26 63 6b 73 75 6d 29 Z %b\n", &cksum)
37d0: 3b 0a 20 20 62 6c 6f 62 5f 72 65 73 65 74 28 26 ;. blob_reset(&
37e0: 63 6b 73 75 6d 29 3b 0a 20 20 64 62 5f 6d 75 6c cksum);. db_mul
37f0: 74 69 5f 65 78 65 63 28 22 44 45 4c 45 54 45 20 ti_exec("DELETE
3800: 46 52 4f 4d 20 75 6e 63 6c 75 73 74 65 72 65 64 FROM unclustered
3810: 22 29 3b 0a 20 20 63 6f 6e 74 65 6e 74 5f 70 75 ");. content_pu
3820: 74 28 26 63 6c 75 73 74 65 72 2c 20 30 2c 20 30 t(&cluster, 0, 0
3830: 29 3b 0a 20 20 62 6c 6f 62 5f 72 65 73 65 74 28 );. blob_reset(
3840: 26 63 6c 75 73 74 65 72 29 3b 0a 7d 0a 0a 2f 2a &cluster);.}../*
3850: 0a 2a 2a 20 53 65 6e 64 20 61 6e 20 69 67 6f 74 .** Send an igot
3860: 20 6d 65 73 73 61 67 65 20 66 6f 72 20 65 76 65 message for eve
3870: 72 79 20 65 6e 74 72 79 20 69 6e 20 75 6e 63 6c ry entry in uncl
3880: 75 73 74 65 72 65 64 20 74 61 62 6c 65 2e 0a 2a ustered table..*
3890: 2a 20 52 65 74 75 72 6e 20 74 68 65 20 6e 75 6d * Return the num
38a0: 62 65 72 20 6f 66 20 63 61 72 64 73 20 73 65 6e ber of cards sen
38b0: 74 2e 0a 2a 2f 0a 73 74 61 74 69 63 20 69 6e 74 t..*/.static int
38c0: 20 73 65 6e 64 5f 75 6e 63 6c 75 73 74 65 72 65 send_unclustere
38d0: 64 28 58 66 65 72 20 2a 70 58 66 65 72 29 7b 0a d(Xfer *pXfer){.
38e0: 20 20 53 74 6d 74 20 71 3b 0a 20 20 69 6e 74 20 Stmt q;. int
38f0: 63 6e 74 20 3d 20 30 3b 0a 20 20 64 62 5f 70 72 cnt = 0;. db_pr
3900: 65 70 61 72 65 28 26 71 2c 20 0a 20 20 20 20 22 epare(&q, . "
3910: 53 45 4c 45 43 54 20 75 75 69 64 20 46 52 4f 4d SELECT uuid FROM
3920: 20 75 6e 63 6c 75 73 74 65 72 65 64 20 4a 4f 49 unclustered JOI
3930: 4e 20 62 6c 6f 62 20 55 53 49 4e 47 28 72 69 64 N blob USING(rid
3940: 29 22 0a 20 20 20 20 22 20 57 48 45 52 45 20 4e )". " WHERE N
3950: 4f 54 20 45 58 49 53 54 53 28 53 45 4c 45 43 54 OT EXISTS(SELECT
3960: 20 31 20 46 52 4f 4d 20 73 68 75 6e 20 57 48 45 1 FROM shun WHE
3970: 52 45 20 75 75 69 64 3d 62 6c 6f 62 2e 75 75 69 RE uuid=blob.uui
3980: 64 29 22 0a 20 20 20 20 22 20 20 20 41 4e 44 20 d)". " AND
3990: 4e 4f 54 20 45 58 49 53 54 53 28 53 45 4c 45 43 NOT EXISTS(SELEC
39a0: 54 20 31 20 46 52 4f 4d 20 70 72 69 76 61 74 65 T 1 FROM private
39b0: 20 57 48 45 52 45 20 72 69 64 3d 62 6c 6f 62 2e WHERE rid=blob.
39c0: 72 69 64 29 22 0a 20 20 29 3b 0a 20 20 77 68 69 rid)". );. whi
39d0: 6c 65 28 20 64 62 5f 73 74 65 70 28 26 71 29 3d le( db_step(&q)=
39e0: 3d 53 51 4c 49 54 45 5f 52 4f 57 20 29 7b 0a 20 =SQLITE_ROW ){.
39f0: 20 20 20 62 6c 6f 62 5f 61 70 70 65 6e 64 66 28 blob_appendf(
3a00: 70 58 66 65 72 2d 3e 70 4f 75 74 2c 20 22 69 67 pXfer->pOut, "ig
3a10: 6f 74 20 25 73 5c 6e 22 2c 20 64 62 5f 63 6f 6c ot %s\n", db_col
3a20: 75 6d 6e 5f 74 65 78 74 28 26 71 2c 20 30 29 29 umn_text(&q, 0))
3a30: 3b 0a 20 20 20 20 63 6e 74 2b 2b 3b 0a 20 20 7d ;. cnt++;. }
3a40: 0a 20 20 64 62 5f 66 69 6e 61 6c 69 7a 65 28 26 . db_finalize(&
3a50: 71 29 3b 0a 20 20 72 65 74 75 72 6e 20 63 6e 74 q);. return cnt
3a60: 3b 0a 7d 0a 0a 2f 2a 0a 2a 2a 20 53 65 6e 64 20 ;.}../*.** Send
3a70: 61 6e 20 69 67 6f 74 20 6d 65 73 73 61 67 65 20 an igot message
3a80: 66 6f 72 20 65 76 65 72 79 20 61 72 74 69 66 61 for every artifa
3a90: 63 74 2e 0a 2a 2f 0a 73 74 61 74 69 63 20 76 6f ct..*/.static vo
3aa0: 69 64 20 73 65 6e 64 5f 61 6c 6c 28 58 66 65 72 id send_all(Xfer
3ab0: 20 2a 70 58 66 65 72 29 7b 0a 20 20 53 74 6d 74 *pXfer){. Stmt
3ac0: 20 71 3b 0a 20 20 64 62 5f 70 72 65 70 61 72 65 q;. db_prepare
3ad0: 28 26 71 2c 20 0a 20 20 20 20 22 53 45 4c 45 43 (&q, . "SELEC
3ae0: 54 20 75 75 69 64 20 46 52 4f 4d 20 62 6c 6f 62 T uuid FROM blob
3af0: 20 22 0a 20 20 20 20 22 20 57 48 45 52 45 20 4e ". " WHERE N
3b00: 4f 54 20 45 58 49 53 54 53 28 53 45 4c 45 43 54 OT EXISTS(SELECT
3b10: 20 31 20 46 52 4f 4d 20 73 68 75 6e 20 57 48 45 1 FROM shun WHE
3b20: 52 45 20 75 75 69 64 3d 62 6c 6f 62 2e 75 75 69 RE uuid=blob.uui
3b30: 64 29 22 0a 20 20 20 20 22 20 20 20 41 4e 44 20 d)". " AND
3b40: 4e 4f 54 20 45 58 49 53 54 53 28 53 45 4c 45 43 NOT EXISTS(SELEC
3b50: 54 20 31 20 46 52 4f 4d 20 70 72 69 76 61 74 65 T 1 FROM private
3b60: 20 57 48 45 52 45 20 72 69 64 3d 62 6c 6f 62 2e WHERE rid=blob.
3b70: 72 69 64 29 22 0a 20 20 29 3b 0a 20 20 77 68 69 rid)". );. whi
3b80: 6c 65 28 20 64 62 5f 73 74 65 70 28 26 71 29 3d le( db_step(&q)=
3b90: 3d 53 51 4c 49 54 45 5f 52 4f 57 20 29 7b 0a 20 =SQLITE_ROW ){.
3ba0: 20 20 20 62 6c 6f 62 5f 61 70 70 65 6e 64 66 28 blob_appendf(
3bb0: 70 58 66 65 72 2d 3e 70 4f 75 74 2c 20 22 69 67 pXfer->pOut, "ig
3bc0: 6f 74 20 25 73 5c 6e 22 2c 20 64 62 5f 63 6f 6c ot %s\n", db_col
3bd0: 75 6d 6e 5f 74 65 78 74 28 26 71 2c 20 30 29 29 umn_text(&q, 0))
3be0: 3b 0a 20 20 7d 0a 20 20 64 62 5f 66 69 6e 61 6c ;. }. db_final
3bf0: 69 7a 65 28 26 71 29 3b 0a 7d 0a 0a 2f 2a 0a 2a ize(&q);.}../*.*
3c00: 2a 20 53 65 6e 64 20 61 20 73 69 6e 67 6c 65 20 * Send a single
3c10: 63 6f 6e 66 69 67 20 63 61 72 64 20 66 6f 72 20 config card for
3c20: 63 6f 6e 66 69 67 75 72 61 74 69 6f 6e 20 69 74 configuration it
3c30: 65 6d 20 7a 4e 61 6d 65 0a 2a 2f 0a 73 74 61 74 em zName.*/.stat
3c40: 69 63 20 76 6f 69 64 20 73 65 6e 64 5f 63 6f 6e ic void send_con
3c50: 66 69 67 5f 63 61 72 64 28 58 66 65 72 20 2a 70 fig_card(Xfer *p
3c60: 58 66 65 72 2c 20 63 6f 6e 73 74 20 63 68 61 72 Xfer, const char
3c70: 20 2a 7a 4e 61 6d 65 29 7b 0a 20 20 69 66 28 20 *zName){. if(
3c80: 7a 4e 61 6d 65 5b 30 5d 21 3d 27 40 27 20 29 7b zName[0]!='@' ){
3c90: 0a 20 20 20 20 63 68 61 72 20 2a 7a 56 61 6c 75 . char *zValu
3ca0: 65 20 3d 20 64 62 5f 67 65 74 28 7a 4e 61 6d 65 e = db_get(zName
3cb0: 2c 20 30 29 3b 0a 20 20 20 20 69 66 28 20 7a 56 , 0);. if( zV
3cc0: 61 6c 75 65 20 29 7b 0a 20 20 20 20 20 20 62 6c alue ){. bl
3cd0: 6f 62 5f 61 70 70 65 6e 64 66 28 70 58 66 65 72 ob_appendf(pXfer
3ce0: 2d 3e 70 4f 75 74 2c 20 22 63 6f 6e 66 69 67 20 ->pOut, "config
3cf0: 25 73 20 25 64 5c 6e 25 73 5c 6e 22 2c 0a 20 20 %s %d\n%s\n",.
3d00: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
3d10: 20 7a 4e 61 6d 65 2c 20 73 74 72 6c 65 6e 28 7a zName, strlen(z
3d20: 56 61 6c 75 65 29 2c 20 7a 56 61 6c 75 65 29 3b Value), zValue);
3d30: 0a 20 20 20 20 20 20 66 72 65 65 28 7a 56 61 6c . free(zVal
3d40: 75 65 29 3b 0a 20 20 20 20 7d 0a 20 20 7d 65 6c ue);. }. }el
3d50: 73 65 7b 0a 20 20 20 20 42 6c 6f 62 20 63 6f 6e se{. Blob con
3d60: 74 65 6e 74 3b 0a 20 20 20 20 62 6c 6f 62 5f 7a tent;. blob_z
3d70: 65 72 6f 28 26 63 6f 6e 74 65 6e 74 29 3b 0a 20 ero(&content);.
3d80: 20 20 20 63 6f 6e 66 69 67 75 72 65 5f 72 65 6e configure_ren
3d90: 64 65 72 5f 73 70 65 63 69 61 6c 5f 6e 61 6d 65 der_special_name
3da0: 28 7a 4e 61 6d 65 2c 20 26 63 6f 6e 74 65 6e 74 (zName, &content
3db0: 29 3b 0a 20 20 20 20 62 6c 6f 62 5f 61 70 70 65 );. blob_appe
3dc0: 6e 64 66 28 70 58 66 65 72 2d 3e 70 4f 75 74 2c ndf(pXfer->pOut,
3dd0: 20 22 63 6f 6e 66 69 67 20 25 73 20 25 64 5c 6e "config %s %d\n
3de0: 25 73 5c 6e 22 2c 20 7a 4e 61 6d 65 2c 0a 20 20 %s\n", zName,.
3df0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 62 b
3e00: 6c 6f 62 5f 73 69 7a 65 28 26 63 6f 6e 74 65 6e lob_size(&conten
3e10: 74 29 2c 20 62 6c 6f 62 5f 73 74 72 28 26 63 6f t), blob_str(&co
3e20: 6e 74 65 6e 74 29 29 3b 0a 20 20 20 20 62 6c 6f ntent));. blo
3e30: 62 5f 72 65 73 65 74 28 26 63 6f 6e 74 65 6e 74 b_reset(&content
3e40: 29 3b 0a 20 20 7d 0a 7d 0a 0a 0a 2f 2a 0a 2a 2a );. }.}.../*.**
3e50: 20 49 66 20 74 68 69 73 20 76 61 72 69 61 62 6c If this variabl
3e60: 65 20 69 73 20 73 65 74 2c 20 64 69 73 61 62 6c e is set, disabl
3e70: 65 20 6c 6f 67 69 6e 20 63 68 65 63 6b 73 2e 20 e login checks.
3e80: 20 55 73 65 64 20 66 6f 72 20 64 65 62 75 67 67 Used for debugg
3e90: 69 6e 67 0a 2a 2a 20 6f 6e 6c 79 2e 0a 2a 2f 0a ing.** only..*/.
3ea0: 73 74 61 74 69 63 20 69 6e 74 20 64 69 73 61 62 static int disab
3eb0: 6c 65 4c 6f 67 69 6e 20 3d 20 30 3b 0a 0a 2f 2a leLogin = 0;../*
3ec0: 0a 2a 2a 20 54 68 65 20 43 47 49 2f 48 54 54 50 .** The CGI/HTTP
3ed0: 20 70 72 65 70 72 6f 63 65 73 73 6f 72 20 61 6c preprocessor al
3ee0: 77 61 79 73 20 72 65 64 69 72 65 63 74 73 20 72 ways redirects r
3ef0: 65 71 75 65 73 74 73 20 77 69 74 68 20 61 20 63 equests with a c
3f00: 6f 6e 74 65 6e 74 2d 74 79 70 65 0a 2a 2a 20 6f ontent-type.** o
3f10: 66 20 61 70 70 6c 69 63 61 74 69 6f 6e 2f 78 2d f application/x-
3f20: 66 6f 73 73 69 6c 20 6f 72 20 61 70 70 6c 69 63 fossil or applic
3f30: 61 74 69 6f 6e 2f 78 2d 66 6f 73 73 69 6c 2d 64 ation/x-fossil-d
3f40: 65 62 75 67 20 74 6f 20 74 68 69 73 20 70 61 67 ebug to this pag
3f50: 65 2c 0a 2a 2a 20 72 65 67 61 72 64 6c 65 73 73 e,.** regardless
3f60: 20 6f 66 20 77 68 61 74 20 70 61 74 68 20 77 61 of what path wa
3f70: 73 20 73 70 65 63 69 66 69 65 64 20 69 6e 20 74 s specified in t
3f80: 68 65 20 48 54 54 50 20 68 65 61 64 65 72 2e 20 he HTTP header.
3f90: 20 54 68 69 73 20 61 6c 6c 6f 77 73 0a 2a 2a 20 This allows.**
3fa0: 63 6c 6f 6e 65 20 63 6c 69 65 6e 74 73 20 74 6f clone clients to
3fb0: 20 73 70 65 63 69 66 79 20 61 20 55 52 4c 20 74 specify a URL t
3fc0: 68 61 74 20 6f 6d 69 74 73 20 64 65 66 61 75 6c hat omits defaul
3fd0: 74 20 70 61 74 68 6e 61 6d 65 73 2c 20 73 75 63 t pathnames, suc
3fe0: 68 0a 2a 2a 20 61 73 20 22 68 74 74 70 3a 2f 2f h.** as "http://
3ff0: 66 6f 73 73 69 6c 2d 73 63 6d 2e 6d 6f 72 67 2f fossil-scm.morg/
4000: 22 20 69 6e 73 74 65 61 64 20 6f 66 20 22 68 74 " instead of "ht
4010: 74 70 3a 2f 2f 66 6f 73 73 69 6c 2d 73 63 6d 2e tp://fossil-scm.
4020: 6f 72 67 2f 69 6e 64 65 78 2e 63 67 69 22 2e 0a org/index.cgi"..
4030: 2a 2a 0a 2a 2a 20 57 45 42 50 41 47 45 3a 20 78 **.** WEBPAGE: x
4040: 66 65 72 0a 2a 2a 0a 2a 2a 20 54 68 69 73 20 69 fer.**.** This i
4050: 73 20 74 68 65 20 74 72 61 6e 73 66 65 72 20 68 s the transfer h
4060: 61 6e 64 6c 65 72 20 6f 6e 20 74 68 65 20 73 65 andler on the se
4070: 72 76 65 72 20 73 69 64 65 2e 20 20 54 68 65 20 rver side. The
4080: 74 72 61 6e 73 66 65 72 0a 2a 2a 20 6d 65 73 73 transfer.** mess
4090: 61 67 65 20 68 61 73 20 62 65 65 6e 20 75 6e 63 age has been unc
40a0: 6f 6d 70 72 65 73 73 65 64 20 61 6e 64 20 70 6c ompressed and pl
40b0: 61 63 65 64 20 69 6e 20 74 68 65 20 67 2e 63 67 aced in the g.cg
40c0: 69 49 6e 20 62 6c 6f 62 2e 0a 2a 2a 20 50 72 6f iIn blob..** Pro
40d0: 63 65 73 73 20 74 68 69 73 20 6d 65 73 73 61 67 cess this messag
40e0: 65 20 61 6e 64 20 66 6f 72 6d 20 61 6e 20 61 70 e and form an ap
40f0: 70 72 6f 70 72 69 61 74 65 20 72 65 70 6c 79 2e propriate reply.
4100: 0a 2a 2f 0a 76 6f 69 64 20 70 61 67 65 5f 78 66 .*/.void page_xf
4110: 65 72 28 76 6f 69 64 29 7b 0a 20 20 69 6e 74 20 er(void){. int
4120: 69 73 50 75 6c 6c 20 3d 20 30 3b 0a 20 20 69 6e isPull = 0;. in
4130: 74 20 69 73 50 75 73 68 20 3d 20 30 3b 0a 20 20 t isPush = 0;.
4140: 69 6e 74 20 6e 45 72 72 20 3d 20 30 3b 0a 20 20 int nErr = 0;.
4150: 58 66 65 72 20 78 66 65 72 3b 0a 20 20 69 6e 74 Xfer xfer;. int
4160: 20 64 65 6c 74 61 46 6c 61 67 20 3d 20 30 3b 0a deltaFlag = 0;.
4170: 20 20 69 6e 74 20 69 73 43 6c 6f 6e 65 20 3d 20 int isClone =
4180: 30 3b 0a 20 20 69 6e 74 20 6e 47 69 6d 6d 65 20 0;. int nGimme
4190: 3d 20 30 3b 0a 20 20 69 6e 74 20 73 69 7a 65 3b = 0;. int size;
41a0: 0a 20 20 69 6e 74 20 72 65 63 76 43 6f 6e 66 69 . int recvConfi
41b0: 67 20 3d 20 30 3b 0a 0a 20 20 6d 65 6d 73 65 74 g = 0;.. memset
41c0: 28 26 78 66 65 72 2c 20 30 2c 20 73 69 7a 65 6f (&xfer, 0, sizeo
41d0: 66 28 78 66 65 72 29 29 3b 0a 20 20 62 6c 6f 62 f(xfer));. blob
41e0: 61 72 72 61 79 5f 7a 65 72 6f 28 78 66 65 72 2e array_zero(xfer.
41f0: 61 54 6f 6b 65 6e 2c 20 63 6f 75 6e 74 28 78 66 aToken, count(xf
4200: 65 72 2e 61 54 6f 6b 65 6e 29 29 3b 0a 20 20 63 er.aToken));. c
4210: 67 69 5f 73 65 74 5f 63 6f 6e 74 65 6e 74 5f 74 gi_set_content_t
4220: 79 70 65 28 67 2e 7a 43 6f 6e 74 65 6e 74 54 79 ype(g.zContentTy
4230: 70 65 29 3b 0a 20 20 62 6c 6f 62 5f 7a 65 72 6f pe);. blob_zero
4240: 28 26 78 66 65 72 2e 65 72 72 29 3b 0a 20 20 78 (&xfer.err);. x
4250: 66 65 72 2e 70 49 6e 20 3d 20 26 67 2e 63 67 69 fer.pIn = &g.cgi
4260: 49 6e 3b 0a 20 20 78 66 65 72 2e 70 4f 75 74 20 In;. xfer.pOut
4270: 3d 20 63 67 69 5f 6f 75 74 70 75 74 5f 62 6c 6f = cgi_output_blo
4280: 62 28 29 3b 0a 20 20 78 66 65 72 2e 6d 78 53 65 b();. xfer.mxSe
4290: 6e 64 20 3d 20 64 62 5f 67 65 74 5f 69 6e 74 28 nd = db_get_int(
42a0: 22 6d 61 78 2d 64 6f 77 6e 6c 6f 61 64 22 2c 20 "max-download",
42b0: 35 30 30 30 30 30 30 29 3b 0a 20 20 67 2e 78 66 5000000);. g.xf
42c0: 65 72 50 61 6e 69 63 20 3d 20 31 3b 0a 0a 20 20 erPanic = 1;..
42d0: 64 62 5f 62 65 67 69 6e 5f 74 72 61 6e 73 61 63 db_begin_transac
42e0: 74 69 6f 6e 28 29 3b 0a 20 20 64 62 5f 6d 75 6c tion();. db_mul
42f0: 74 69 5f 65 78 65 63 28 0a 20 20 20 20 20 22 43 ti_exec(. "C
4300: 52 45 41 54 45 20 54 45 4d 50 20 54 41 42 4c 45 REATE TEMP TABLE
4310: 20 6f 6e 72 65 6d 6f 74 65 28 72 69 64 20 49 4e onremote(rid IN
4320: 54 45 47 45 52 20 50 52 49 4d 41 52 59 20 4b 45 TEGER PRIMARY KE
4330: 59 29 3b 22 0a 20 20 29 3b 0a 20 20 77 68 69 6c Y);". );. whil
4340: 65 28 20 62 6c 6f 62 5f 6c 69 6e 65 28 78 66 65 e( blob_line(xfe
4350: 72 2e 70 49 6e 2c 20 26 78 66 65 72 2e 6c 69 6e r.pIn, &xfer.lin
4360: 65 29 20 29 7b 0a 20 20 20 20 69 66 28 20 62 6c e) ){. if( bl
4370: 6f 62 5f 62 75 66 66 65 72 28 26 78 66 65 72 2e ob_buffer(&xfer.
4380: 6c 69 6e 65 29 5b 30 5d 3d 3d 27 23 27 20 29 20 line)[0]=='#' )
4390: 63 6f 6e 74 69 6e 75 65 3b 0a 20 20 20 20 78 66 continue;. xf
43a0: 65 72 2e 6e 54 6f 6b 65 6e 20 3d 20 62 6c 6f 62 er.nToken = blob
43b0: 5f 74 6f 6b 65 6e 69 7a 65 28 26 78 66 65 72 2e _tokenize(&xfer.
43c0: 6c 69 6e 65 2c 20 78 66 65 72 2e 61 54 6f 6b 65 line, xfer.aToke
43d0: 6e 2c 20 63 6f 75 6e 74 28 78 66 65 72 2e 61 54 n, count(xfer.aT
43e0: 6f 6b 65 6e 29 29 3b 0a 0a 20 20 20 20 2f 2a 20 oken));.. /*
43f0: 20 20 66 69 6c 65 20 55 55 49 44 20 53 49 5a 45 file UUID SIZE
4400: 20 5c 6e 20 43 4f 4e 54 45 4e 54 0a 20 20 20 20 \n CONTENT.
4410: 2a 2a 20 20 20 66 69 6c 65 20 55 55 49 44 20 44 ** file UUID D
4420: 45 4c 54 41 53 52 43 20 53 49 5a 45 20 5c 6e 20 ELTASRC SIZE \n
4430: 43 4f 4e 54 45 4e 54 0a 20 20 20 20 2a 2a 0a 20 CONTENT. **.
4440: 20 20 20 2a 2a 20 41 63 63 65 70 74 20 61 20 66 ** Accept a f
4450: 69 6c 65 20 66 72 6f 6d 20 74 68 65 20 63 6c 69 ile from the cli
4460: 65 6e 74 2e 0a 20 20 20 20 2a 2f 0a 20 20 20 20 ent.. */.
4470: 69 66 28 20 62 6c 6f 62 5f 65 71 28 26 78 66 65 if( blob_eq(&xfe
4480: 72 2e 61 54 6f 6b 65 6e 5b 30 5d 2c 20 22 66 69 r.aToken[0], "fi
4490: 6c 65 22 29 20 29 7b 0a 20 20 20 20 20 20 69 66 le") ){. if
44a0: 28 20 21 69 73 50 75 73 68 20 29 7b 0a 20 20 20 ( !isPush ){.
44b0: 20 20 20 20 20 63 67 69 5f 72 65 73 65 74 5f 63 cgi_reset_c
44c0: 6f 6e 74 65 6e 74 28 29 3b 0a 20 20 20 20 20 20 ontent();.
44d0: 20 20 40 20 65 72 72 6f 72 20 6e 6f 74 5c 73 61 @ error not\sa
44e0: 75 74 68 6f 72 69 7a 65 64 5c 73 74 6f 5c 73 77 uthorized\sto\sw
44f0: 72 69 74 65 0a 20 20 20 20 20 20 20 20 6e 45 72 rite. nEr
4500: 72 2b 2b 3b 0a 20 20 20 20 20 20 20 20 62 72 65 r++;. bre
4510: 61 6b 3b 0a 20 20 20 20 20 20 7d 0a 20 20 20 20 ak;. }.
4520: 20 20 78 66 65 72 5f 61 63 63 65 70 74 5f 66 69 xfer_accept_fi
4530: 6c 65 28 26 78 66 65 72 29 3b 0a 20 20 20 20 20 le(&xfer);.
4540: 20 69 66 28 20 62 6c 6f 62 5f 73 69 7a 65 28 26 if( blob_size(&
4550: 78 66 65 72 2e 65 72 72 29 20 29 7b 0a 20 20 20 xfer.err) ){.
4560: 20 20 20 20 20 63 67 69 5f 72 65 73 65 74 5f 63 cgi_reset_c
4570: 6f 6e 74 65 6e 74 28 29 3b 0a 20 20 20 20 20 20 ontent();.
4580: 20 20 40 20 65 72 72 6f 72 20 25 54 28 62 6c 6f @ error %T(blo
4590: 62 5f 73 74 72 28 26 78 66 65 72 2e 65 72 72 29 b_str(&xfer.err)
45a0: 29 0a 20 20 20 20 20 20 20 20 6e 45 72 72 2b 2b ). nErr++
45b0: 3b 0a 20 20 20 20 20 20 20 20 62 72 65 61 6b 3b ;. break;
45c0: 0a 20 20 20 20 20 20 7d 0a 20 20 20 20 7d 65 6c . }. }el
45d0: 73 65 0a 0a 20 20 20 20 2f 2a 20 20 20 67 69 6d se.. /* gim
45e0: 6d 65 20 55 55 49 44 0a 20 20 20 20 2a 2a 0a 20 me UUID. **.
45f0: 20 20 20 2a 2a 20 43 6c 69 65 6e 74 20 69 73 20 ** Client is
4600: 72 65 71 75 65 73 74 69 6e 67 20 61 20 66 69 6c requesting a fil
4610: 65 2e 20 20 53 65 6e 64 20 69 74 2e 0a 20 20 20 e. Send it..
4620: 20 2a 2f 0a 20 20 20 20 69 66 28 20 62 6c 6f 62 */. if( blob
4630: 5f 65 71 28 26 78 66 65 72 2e 61 54 6f 6b 65 6e _eq(&xfer.aToken
4640: 5b 30 5d 2c 20 22 67 69 6d 6d 65 22 29 0a 20 20 [0], "gimme").
4650: 20 20 20 26 26 20 78 66 65 72 2e 6e 54 6f 6b 65 && xfer.nToke
4660: 6e 3d 3d 32 0a 20 20 20 20 20 26 26 20 62 6c 6f n==2. && blo
4670: 62 5f 69 73 5f 75 75 69 64 28 26 78 66 65 72 2e b_is_uuid(&xfer.
4680: 61 54 6f 6b 65 6e 5b 31 5d 29 0a 20 20 20 20 29 aToken[1]). )
4690: 7b 0a 20 20 20 20 20 20 6e 47 69 6d 6d 65 2b 2b {. nGimme++
46a0: 3b 0a 20 20 20 20 20 20 69 66 28 20 69 73 50 75 ;. if( isPu
46b0: 6c 6c 20 29 7b 0a 20 20 20 20 20 20 20 20 69 6e ll ){. in
46c0: 74 20 72 69 64 20 3d 20 72 69 64 5f 66 72 6f 6d t rid = rid_from
46d0: 5f 75 75 69 64 28 26 78 66 65 72 2e 61 54 6f 6b _uuid(&xfer.aTok
46e0: 65 6e 5b 31 5d 2c 20 30 29 3b 0a 20 20 20 20 20 en[1], 0);.
46f0: 20 20 20 69 66 28 20 72 69 64 20 29 7b 0a 20 20 if( rid ){.
4700: 20 20 20 20 20 20 20 20 73 65 6e 64 5f 66 69 6c send_fil
4710: 65 28 26 78 66 65 72 2c 20 72 69 64 2c 20 26 78 e(&xfer, rid, &x
4720: 66 65 72 2e 61 54 6f 6b 65 6e 5b 31 5d 2c 20 64 fer.aToken[1], d
4730: 65 6c 74 61 46 6c 61 67 29 3b 0a 20 20 20 20 20 eltaFlag);.
4740: 20 20 20 7d 0a 20 20 20 20 20 20 7d 0a 20 20 20 }. }.
4750: 20 7d 65 6c 73 65 0a 0a 20 20 20 20 2f 2a 20 20 }else.. /*
4760: 20 69 67 6f 74 20 55 55 49 44 0a 20 20 20 20 2a igot UUID. *
4770: 2a 0a 20 20 20 20 2a 2a 20 43 6c 69 65 6e 74 20 *. ** Client
4780: 61 6e 6e 6f 75 6e 63 65 73 20 74 68 61 74 20 69 announces that i
4790: 74 20 68 61 73 20 61 20 70 61 72 74 69 63 75 6c t has a particul
47a0: 61 72 20 66 69 6c 65 2e 0a 20 20 20 20 2a 2f 0a ar file.. */.
47b0: 20 20 20 20 69 66 28 20 78 66 65 72 2e 6e 54 6f if( xfer.nTo
47c0: 6b 65 6e 3d 3d 32 0a 20 20 20 20 20 26 26 20 62 ken==2. && b
47d0: 6c 6f 62 5f 65 71 28 26 78 66 65 72 2e 61 54 6f lob_eq(&xfer.aTo
47e0: 6b 65 6e 5b 30 5d 2c 20 22 69 67 6f 74 22 29 0a ken[0], "igot").
47f0: 20 20 20 20 20 26 26 20 62 6c 6f 62 5f 69 73 5f && blob_is_
4800: 75 75 69 64 28 26 78 66 65 72 2e 61 54 6f 6b 65 uuid(&xfer.aToke
4810: 6e 5b 31 5d 29 0a 20 20 20 20 29 7b 0a 20 20 20 n[1]). ){.
4820: 20 20 20 69 66 28 20 69 73 50 75 73 68 20 29 7b if( isPush ){
4830: 0a 20 20 20 20 20 20 20 20 72 69 64 5f 66 72 6f . rid_fro
4840: 6d 5f 75 75 69 64 28 26 78 66 65 72 2e 61 54 6f m_uuid(&xfer.aTo
4850: 6b 65 6e 5b 31 5d 2c 20 31 29 3b 0a 20 20 20 20 ken[1], 1);.
4860: 20 20 7d 0a 20 20 20 20 7d 65 6c 73 65 0a 20 20 }. }else.
4870: 0a 20 20 20 20 0a 20 20 20 20 2f 2a 20 20 20 20 . . /*
4880: 70 75 6c 6c 20 20 53 45 52 56 45 52 43 4f 44 45 pull SERVERCODE
4890: 20 20 50 52 4f 4a 45 43 54 43 4f 44 45 0a 20 20 PROJECTCODE.
48a0: 20 20 2a 2a 20 20 20 20 70 75 73 68 20 20 53 45 ** push SE
48b0: 52 56 45 52 43 4f 44 45 20 20 50 52 4f 4a 45 43 RVERCODE PROJEC
48c0: 54 43 4f 44 45 0a 20 20 20 20 2a 2a 0a 20 20 20 TCODE. **.
48d0: 20 2a 2a 20 54 68 65 20 63 6c 69 65 6e 74 20 77 ** The client w
48e0: 61 6e 74 73 20 65 69 74 68 65 72 20 73 65 6e 64 ants either send
48f0: 20 6f 72 20 72 65 63 65 69 76 65 2e 20 20 54 68 or receive. Th
4900: 65 20 73 65 72 76 65 72 20 73 68 6f 75 6c 64 0a e server should.
4910: 20 20 20 20 2a 2a 20 76 65 72 69 66 79 20 74 68 ** verify th
4920: 61 74 20 74 68 65 20 70 72 6f 6a 65 63 74 20 63 at the project c
4930: 6f 64 65 20 6d 61 74 63 68 65 73 20 61 6e 64 20 ode matches and
4940: 74 68 61 74 20 74 68 65 20 73 65 72 76 65 72 20 that the server
4950: 63 6f 64 65 0a 20 20 20 20 2a 2a 20 64 6f 65 73 code. ** does
4960: 20 6e 6f 74 20 6d 61 74 63 68 2e 0a 20 20 20 20 not match..
4970: 2a 2f 0a 20 20 20 20 69 66 28 20 78 66 65 72 2e */. if( xfer.
4980: 6e 54 6f 6b 65 6e 3d 3d 33 0a 20 20 20 20 20 26 nToken==3. &
4990: 26 20 28 62 6c 6f 62 5f 65 71 28 26 78 66 65 72 & (blob_eq(&xfer
49a0: 2e 61 54 6f 6b 65 6e 5b 30 5d 2c 20 22 70 75 6c .aToken[0], "pul
49b0: 6c 22 29 20 7c 7c 20 62 6c 6f 62 5f 65 71 28 26 l") || blob_eq(&
49c0: 78 66 65 72 2e 61 54 6f 6b 65 6e 5b 30 5d 2c 20 xfer.aToken[0],
49d0: 22 70 75 73 68 22 29 29 0a 20 20 20 20 20 26 26 "push")). &&
49e0: 20 62 6c 6f 62 5f 69 73 5f 75 75 69 64 28 26 78 blob_is_uuid(&x
49f0: 66 65 72 2e 61 54 6f 6b 65 6e 5b 31 5d 29 0a 20 fer.aToken[1]).
4a00: 20 20 20 20 26 26 20 62 6c 6f 62 5f 69 73 5f 75 && blob_is_u
4a10: 75 69 64 28 26 78 66 65 72 2e 61 54 6f 6b 65 6e uid(&xfer.aToken
4a20: 5b 32 5d 29 0a 20 20 20 20 29 7b 0a 20 20 20 20 [2]). ){.
4a30: 20 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a 53 const char *zS
4a40: 43 6f 64 65 3b 0a 20 20 20 20 20 20 63 6f 6e 73 Code;. cons
4a50: 74 20 63 68 61 72 20 2a 7a 50 43 6f 64 65 3b 0a t char *zPCode;.
4a60: 0a 20 20 20 20 20 20 7a 53 43 6f 64 65 20 3d 20 . zSCode =
4a70: 64 62 5f 67 65 74 28 22 73 65 72 76 65 72 2d 63 db_get("server-c
4a80: 6f 64 65 22 2c 20 30 29 3b 0a 20 20 20 20 20 20 ode", 0);.
4a90: 69 66 28 20 7a 53 43 6f 64 65 3d 3d 30 20 29 7b if( zSCode==0 ){
4aa0: 0a 20 20 20 20 20 20 20 20 66 6f 73 73 69 6c 5f . fossil_
4ab0: 70 61 6e 69 63 28 22 6d 69 73 73 69 6e 67 20 73 panic("missing s
4ac0: 65 72 76 65 72 20 63 6f 64 65 22 29 3b 0a 20 20 erver code");.
4ad0: 20 20 20 20 7d 0a 20 20 20 20 20 20 69 66 28 20 }. if(
4ae0: 62 6c 6f 62 5f 65 71 5f 73 74 72 28 26 78 66 65 blob_eq_str(&xfe
4af0: 72 2e 61 54 6f 6b 65 6e 5b 31 5d 2c 20 7a 53 43 r.aToken[1], zSC
4b00: 6f 64 65 2c 20 2d 31 29 20 29 7b 0a 20 20 20 20 ode, -1) ){.
4b10: 20 20 20 20 63 67 69 5f 72 65 73 65 74 5f 63 6f cgi_reset_co
4b20: 6e 74 65 6e 74 28 29 3b 0a 20 20 20 20 20 20 20 ntent();.
4b30: 20 40 20 65 72 72 6f 72 20 73 65 72 76 65 72 5c @ error server\
4b40: 73 6c 6f 6f 70 0a 20 20 20 20 20 20 20 20 6e 45 sloop. nE
4b50: 72 72 2b 2b 3b 0a 20 20 20 20 20 20 20 20 62 72 rr++;. br
4b60: 65 61 6b 3b 0a 20 20 20 20 20 20 7d 0a 20 20 20 eak;. }.
4b70: 20 20 20 7a 50 43 6f 64 65 20 3d 20 64 62 5f 67 zPCode = db_g
4b80: 65 74 28 22 70 72 6f 6a 65 63 74 2d 63 6f 64 65 et("project-code
4b90: 22 2c 20 30 29 3b 0a 20 20 20 20 20 20 69 66 28 ", 0);. if(
4ba0: 20 7a 50 43 6f 64 65 3d 3d 30 20 29 7b 0a 20 20 zPCode==0 ){.
4bb0: 20 20 20 20 20 20 66 6f 73 73 69 6c 5f 70 61 6e fossil_pan
4bc0: 69 63 28 22 6d 69 73 73 69 6e 67 20 70 72 6f 6a ic("missing proj
4bd0: 65 63 74 20 63 6f 64 65 22 29 3b 0a 20 20 20 20 ect code");.
4be0: 20 20 7d 0a 20 20 20 20 20 20 69 66 28 20 21 62 }. if( !b
4bf0: 6c 6f 62 5f 65 71 5f 73 74 72 28 26 78 66 65 72 lob_eq_str(&xfer
4c00: 2e 61 54 6f 6b 65 6e 5b 32 5d 2c 20 7a 50 43 6f .aToken[2], zPCo
4c10: 64 65 2c 20 2d 31 29 20 29 7b 0a 20 20 20 20 20 de, -1) ){.
4c20: 20 20 20 63 67 69 5f 72 65 73 65 74 5f 63 6f 6e cgi_reset_con
4c30: 74 65 6e 74 28 29 3b 0a 20 20 20 20 20 20 20 20 tent();.
4c40: 40 20 65 72 72 6f 72 20 77 72 6f 6e 67 5c 73 70 @ error wrong\sp
4c50: 72 6f 6a 65 63 74 0a 20 20 20 20 20 20 20 20 6e roject. n
4c60: 45 72 72 2b 2b 3b 0a 20 20 20 20 20 20 20 20 62 Err++;. b
4c70: 72 65 61 6b 3b 0a 20 20 20 20 20 20 7d 0a 20 20 reak;. }.
4c80: 20 20 20 20 6c 6f 67 69 6e 5f 63 68 65 63 6b 5f login_check_
4c90: 63 72 65 64 65 6e 74 69 61 6c 73 28 29 3b 0a 20 credentials();.
4ca0: 20 20 20 20 20 69 66 28 20 62 6c 6f 62 5f 65 71 if( blob_eq
4cb0: 28 26 78 66 65 72 2e 61 54 6f 6b 65 6e 5b 30 5d (&xfer.aToken[0]
4cc0: 2c 20 22 70 75 6c 6c 22 29 20 29 7b 0a 20 20 20 , "pull") ){.
4cd0: 20 20 20 20 20 69 66 28 20 21 67 2e 6f 6b 52 65 if( !g.okRe
4ce0: 61 64 20 29 7b 0a 20 20 20 20 20 20 20 20 20 20 ad ){.
4cf0: 63 67 69 5f 72 65 73 65 74 5f 63 6f 6e 74 65 6e cgi_reset_conten
4d00: 74 28 29 3b 0a 20 20 20 20 20 20 20 20 20 20 40 t();. @
4d10: 20 65 72 72 6f 72 20 6e 6f 74 5c 73 61 75 74 68 error not\sauth
4d20: 6f 72 69 7a 65 64 5c 73 74 6f 5c 73 72 65 61 64 orized\sto\sread
4d30: 0a 20 20 20 20 20 20 20 20 20 20 6e 45 72 72 2b . nErr+
4d40: 2b 3b 0a 20 20 20 20 20 20 20 20 20 20 62 72 65 +;. bre
4d50: 61 6b 3b 0a 20 20 20 20 20 20 20 20 7d 0a 20 20 ak;. }.
4d60: 20 20 20 20 20 20 69 73 50 75 6c 6c 20 3d 20 31 isPull = 1
4d70: 3b 0a 20 20 20 20 20 20 7d 65 6c 73 65 7b 0a 20 ;. }else{.
4d80: 20 20 20 20 20 20 20 69 66 28 20 21 67 2e 6f 6b if( !g.ok
4d90: 57 72 69 74 65 20 29 7b 0a 20 20 20 20 20 20 20 Write ){.
4da0: 20 20 20 69 66 28 20 21 69 73 50 75 6c 6c 20 29 if( !isPull )
4db0: 7b 0a 20 20 20 20 20 20 20 20 20 20 20 20 63 67 {. cg
4dc0: 69 5f 72 65 73 65 74 5f 63 6f 6e 74 65 6e 74 28 i_reset_content(
4dd0: 29 3b 0a 20 20 20 20 20 20 20 20 20 20 20 20 40 );. @
4de0: 20 65 72 72 6f 72 20 6e 6f 74 5c 73 61 75 74 68 error not\sauth
4df0: 6f 72 69 7a 65 64 5c 73 74 6f 5c 73 77 72 69 74 orized\sto\swrit
4e00: 65 0a 20 20 20 20 20 20 20 20 20 20 20 20 6e 45 e. nE
4e10: 72 72 2b 2b 3b 0a 20 20 20 20 20 20 20 20 20 20 rr++;.
4e20: 7d 65 6c 73 65 7b 0a 20 20 20 20 20 20 20 20 20 }else{.
4e30: 20 20 20 40 20 6d 65 73 73 61 67 65 20 70 75 6c @ message pul
4e40: 6c 5c 73 6f 6e 6c 79 5c 73 2d 5c 73 6e 6f 74 5c l\sonly\s-\snot\
4e50: 73 61 75 74 68 6f 72 69 7a 65 64 5c 73 74 6f 5c sauthorized\sto\
4e60: 73 70 75 73 68 0a 20 20 20 20 20 20 20 20 20 20 spush.
4e70: 7d 0a 20 20 20 20 20 20 20 20 7d 65 6c 73 65 7b }. }else{
4e80: 0a 20 20 20 20 20 20 20 20 20 20 69 73 50 75 73 . isPus
4e90: 68 20 3d 20 31 3b 0a 20 20 20 20 20 20 20 20 7d h = 1;. }
4ea0: 0a 20 20 20 20 20 20 7d 0a 20 20 20 20 7d 65 6c . }. }el
4eb0: 73 65 0a 0a 20 20 20 20 2f 2a 20 20 20 20 63 6c se.. /* cl
4ec0: 6f 6e 65 0a 20 20 20 20 2a 2a 0a 20 20 20 20 2a one. **. *
4ed0: 2a 20 54 68 65 20 63 6c 69 65 6e 74 20 6b 6e 6f * The client kno
4ee0: 77 73 20 6e 6f 74 68 69 6e 67 2e 20 20 54 65 6c ws nothing. Tel
4ef0: 6c 20 61 6c 6c 2e 0a 20 20 20 20 2a 2f 0a 20 20 l all.. */.
4f00: 20 20 69 66 28 20 62 6c 6f 62 5f 65 71 28 26 78 if( blob_eq(&x
4f10: 66 65 72 2e 61 54 6f 6b 65 6e 5b 30 5d 2c 20 22 fer.aToken[0], "
4f20: 63 6c 6f 6e 65 22 29 20 29 7b 0a 20 20 20 20 20 clone") ){.
4f30: 20 6c 6f 67 69 6e 5f 63 68 65 63 6b 5f 63 72 65 login_check_cre
4f40: 64 65 6e 74 69 61 6c 73 28 29 3b 0a 20 20 20 20 dentials();.
4f50: 20 20 69 66 28 20 21 67 2e 6f 6b 43 6c 6f 6e 65 if( !g.okClone
4f60: 20 29 7b 0a 20 20 20 20 20 20 20 20 63 67 69 5f ){. cgi_
4f70: 72 65 73 65 74 5f 63 6f 6e 74 65 6e 74 28 29 3b reset_content();
4f80: 0a 20 20 20 20 20 20 20 20 40 20 65 72 72 6f 72 . @ error
4f90: 20 6e 6f 74 5c 73 61 75 74 68 6f 72 69 7a 65 64 not\sauthorized
4fa0: 5c 73 74 6f 5c 73 63 6c 6f 6e 65 0a 20 20 20 20 \sto\sclone.
4fb0: 20 20 20 20 6e 45 72 72 2b 2b 3b 0a 20 20 20 20 nErr++;.
4fc0: 20 20 20 20 62 72 65 61 6b 3b 0a 20 20 20 20 20 break;.
4fd0: 20 7d 0a 20 20 20 20 20 20 69 73 43 6c 6f 6e 65 }. isClone
4fe0: 20 3d 20 31 3b 0a 20 20 20 20 20 20 69 73 50 75 = 1;. isPu
4ff0: 6c 6c 20 3d 20 31 3b 0a 20 20 20 20 20 20 64 65 ll = 1;. de
5000: 6c 74 61 46 6c 61 67 20 3d 20 31 3b 0a 20 20 20 ltaFlag = 1;.
5010: 20 20 20 40 20 70 75 73 68 20 25 73 28 64 62 5f @ push %s(db_
5020: 67 65 74 28 22 73 65 72 76 65 72 2d 63 6f 64 65 get("server-code
5030: 22 2c 20 22 78 22 29 29 20 25 73 28 64 62 5f 67 ", "x")) %s(db_g
5040: 65 74 28 22 70 72 6f 6a 65 63 74 2d 63 6f 64 65 et("project-code
5050: 22 2c 20 22 78 22 29 29 0a 20 20 20 20 7d 65 6c ", "x")). }el
5060: 73 65 0a 0a 20 20 20 20 2f 2a 20 20 20 20 6c 6f se.. /* lo
5070: 67 69 6e 20 20 55 53 45 52 20 20 4e 4f 4e 43 45 gin USER NONCE
5080: 20 20 53 49 47 4e 41 54 55 52 45 0a 20 20 20 20 SIGNATURE.
5090: 2a 2a 0a 20 20 20 20 2a 2a 20 43 68 65 63 6b 20 **. ** Check
50a0: 66 6f 72 20 61 20 76 61 6c 69 64 20 6c 6f 67 69 for a valid logi
50b0: 6e 2e 20 20 54 68 69 73 20 68 61 73 20 74 6f 20 n. This has to
50c0: 68 61 70 70 65 6e 20 62 65 66 6f 72 65 20 61 6e happen before an
50d0: 79 74 68 69 6e 67 20 65 6c 73 65 2e 0a 20 20 20 ything else..
50e0: 20 2a 2a 20 54 68 65 20 63 6c 69 65 6e 74 20 63 ** The client c
50f0: 61 6e 20 73 65 6e 64 20 6d 75 6c 74 69 70 6c 65 an send multiple
5100: 20 6c 6f 67 69 6e 73 2e 20 20 50 65 72 6d 69 73 logins. Permis
5110: 73 69 6f 6e 73 20 61 72 65 20 63 75 6d 75 6c 61 sions are cumula
5120: 74 69 76 65 2e 0a 20 20 20 20 2a 2f 0a 20 20 20 tive.. */.
5130: 20 69 66 28 20 62 6c 6f 62 5f 65 71 28 26 78 66 if( blob_eq(&xf
5140: 65 72 2e 61 54 6f 6b 65 6e 5b 30 5d 2c 20 22 6c er.aToken[0], "l
5150: 6f 67 69 6e 22 29 0a 20 20 20 20 20 26 26 20 78 ogin"). && x
5160: 66 65 72 2e 6e 54 6f 6b 65 6e 3d 3d 34 0a 20 20 fer.nToken==4.
5170: 20 20 29 7b 0a 20 20 20 20 20 20 69 66 28 20 64 ){. if( d
5180: 69 73 61 62 6c 65 4c 6f 67 69 6e 20 29 7b 0a 20 isableLogin ){.
5190: 20 20 20 20 20 20 20 67 2e 6f 6b 52 65 61 64 20 g.okRead
51a0: 3d 20 67 2e 6f 6b 57 72 69 74 65 20 3d 20 31 3b = g.okWrite = 1;
51b0: 0a 20 20 20 20 20 20 7d 65 6c 73 65 20 69 66 28 . }else if(
51c0: 20 63 68 65 63 6b 5f 74 61 69 6c 5f 68 61 73 68 check_tail_hash
51d0: 28 26 78 66 65 72 2e 61 54 6f 6b 65 6e 5b 32 5d (&xfer.aToken[2]
51e0: 2c 20 78 66 65 72 2e 70 49 6e 29 20 29 7b 0a 20 , xfer.pIn) ){.
51f0: 20 20 20 20 20 20 20 63 68 65 63 6b 5f 6c 6f 67 check_log
5200: 69 6e 28 26 78 66 65 72 2e 61 54 6f 6b 65 6e 5b in(&xfer.aToken[
5210: 31 5d 2c 20 26 78 66 65 72 2e 61 54 6f 6b 65 6e 1], &xfer.aToken
5220: 5b 32 5d 2c 20 26 78 66 65 72 2e 61 54 6f 6b 65 [2], &xfer.aToke
5230: 6e 5b 33 5d 29 3b 0a 20 20 20 20 20 20 7d 0a 20 n[3]);. }.
5240: 20 20 20 7d 65 6c 73 65 0a 20 20 20 20 0a 20 20 }else. .
5250: 20 20 2f 2a 20 20 20 20 72 65 71 63 6f 6e 66 69 /* reqconfi
5260: 67 20 20 4e 41 4d 45 0a 20 20 20 20 2a 2a 0a 20 g NAME. **.
5270: 20 20 20 2a 2a 20 52 65 71 75 65 73 74 20 61 20 ** Request a
5280: 63 6f 6e 66 69 67 75 72 61 74 69 6f 6e 20 76 61 configuration va
5290: 6c 75 65 0a 20 20 20 20 2a 2f 0a 20 20 20 20 69 lue. */. i
52a0: 66 28 20 62 6c 6f 62 5f 65 71 28 26 78 66 65 72 f( blob_eq(&xfer
52b0: 2e 61 54 6f 6b 65 6e 5b 30 5d 2c 20 22 72 65 71 .aToken[0], "req
52c0: 63 6f 6e 66 69 67 22 29 0a 20 20 20 20 20 26 26 config"). &&
52d0: 20 78 66 65 72 2e 6e 54 6f 6b 65 6e 3d 3d 32 0a xfer.nToken==2.
52e0: 20 20 20 20 29 7b 0a 20 20 20 20 20 20 69 66 28 ){. if(
52f0: 20 67 2e 6f 6b 52 65 61 64 20 29 7b 0a 20 20 20 g.okRead ){.
5300: 20 20 20 20 20 63 68 61 72 20 2a 7a 4e 61 6d 65 char *zName
5310: 20 3d 20 62 6c 6f 62 5f 73 74 72 28 26 78 66 65 = blob_str(&xfe
5320: 72 2e 61 54 6f 6b 65 6e 5b 31 5d 29 3b 0a 20 20 r.aToken[1]);.
5330: 20 20 20 20 20 20 69 66 28 20 63 6f 6e 66 69 67 if( config
5340: 75 72 65 5f 69 73 5f 65 78 70 6f 72 74 61 62 6c ure_is_exportabl
5350: 65 28 7a 4e 61 6d 65 29 20 29 7b 0a 20 20 20 20 e(zName) ){.
5360: 20 20 20 20 20 20 73 65 6e 64 5f 63 6f 6e 66 69 send_confi
5370: 67 5f 63 61 72 64 28 26 78 66 65 72 2c 20 7a 4e g_card(&xfer, zN
5380: 61 6d 65 29 3b 0a 20 20 20 20 20 20 20 20 7d 0a ame);. }.
5390: 20 20 20 20 20 20 7d 0a 20 20 20 20 7d 65 6c 73 }. }els
53a0: 65 0a 20 20 20 20 0a 20 20 20 20 2f 2a 20 20 20 e. . /*
53b0: 63 6f 6e 66 69 67 20 4e 41 4d 45 20 53 49 5a 45 config NAME SIZE
53c0: 20 5c 6e 20 43 4f 4e 54 45 4e 54 0a 20 20 20 20 \n CONTENT.
53d0: 2a 2a 0a 20 20 20 20 2a 2a 20 52 65 63 65 69 76 **. ** Receiv
53e0: 65 20 61 20 63 6f 6e 66 69 67 75 72 61 74 69 6f e a configuratio
53f0: 6e 20 76 61 6c 75 65 20 66 72 6f 6d 20 74 68 65 n value from the
5400: 20 63 6c 69 65 6e 74 2e 20 20 54 68 69 73 20 69 client. This i
5410: 73 20 6f 6e 6c 79 0a 20 20 20 20 2a 2a 20 70 65 s only. ** pe
5420: 72 6d 69 74 74 65 64 20 66 6f 72 20 68 69 67 68 rmitted for high
5430: 2d 70 72 69 76 69 6c 65 67 65 20 75 73 65 72 73 -privilege users
5440: 2e 0a 20 20 20 20 2a 2f 0a 20 20 20 20 69 66 28 .. */. if(
5450: 20 62 6c 6f 62 5f 65 71 28 26 78 66 65 72 2e 61 blob_eq(&xfer.a
5460: 54 6f 6b 65 6e 5b 30 5d 2c 22 63 6f 6e 66 69 67 Token[0],"config
5470: 22 29 20 26 26 20 78 66 65 72 2e 6e 54 6f 6b 65 ") && xfer.nToke
5480: 6e 3d 3d 33 0a 20 20 20 20 20 20 20 20 26 26 20 n==3. &&
5490: 62 6c 6f 62 5f 69 73 5f 69 6e 74 28 26 78 66 65 blob_is_int(&xfe
54a0: 72 2e 61 54 6f 6b 65 6e 5b 32 5d 2c 20 26 73 69 r.aToken[2], &si
54b0: 7a 65 29 20 29 7b 0a 20 20 20 20 20 20 63 6f 6e ze) ){. con
54c0: 73 74 20 63 68 61 72 20 2a 7a 4e 61 6d 65 20 3d st char *zName =
54d0: 20 62 6c 6f 62 5f 73 74 72 28 26 78 66 65 72 2e blob_str(&xfer.
54e0: 61 54 6f 6b 65 6e 5b 31 5d 29 3b 0a 20 20 20 20 aToken[1]);.
54f0: 20 20 42 6c 6f 62 20 63 6f 6e 74 65 6e 74 3b 0a Blob content;.
5500: 20 20 20 20 20 20 62 6c 6f 62 5f 7a 65 72 6f 28 blob_zero(
5510: 26 63 6f 6e 74 65 6e 74 29 3b 0a 20 20 20 20 20 &content);.
5520: 20 62 6c 6f 62 5f 65 78 74 72 61 63 74 28 78 66 blob_extract(xf
5530: 65 72 2e 70 49 6e 2c 20 73 69 7a 65 2c 20 26 63 er.pIn, size, &c
5540: 6f 6e 74 65 6e 74 29 3b 0a 20 20 20 20 20 20 69 ontent);. i
5550: 66 28 20 21 67 2e 6f 6b 41 64 6d 69 6e 20 29 7b f( !g.okAdmin ){
5560: 0a 20 20 20 20 20 20 20 20 63 67 69 5f 72 65 73 . cgi_res
5570: 65 74 5f 63 6f 6e 74 65 6e 74 28 29 3b 0a 20 20 et_content();.
5580: 20 20 20 20 20 20 40 20 65 72 72 6f 72 20 6e 6f @ error no
5590: 74 5c 73 61 75 74 68 6f 72 69 7a 65 64 5c 73 74 t\sauthorized\st
55a0: 6f 5c 73 70 75 73 68 5c 73 63 6f 6e 66 69 67 75 o\spush\sconfigu
55b0: 72 61 74 69 6f 6e 0a 20 20 20 20 20 20 20 20 6e ration. n
55c0: 45 72 72 2b 2b 3b 0a 20 20 20 20 20 20 20 20 62 Err++;. b
55d0: 72 65 61 6b 3b 0a 20 20 20 20 20 20 7d 0a 20 20 reak;. }.
55e0: 20 20 20 20 69 66 28 20 7a 4e 61 6d 65 5b 30 5d if( zName[0]
55f0: 21 3d 27 40 27 20 29 7b 0a 20 20 20 20 20 20 20 !='@' ){.
5600: 20 64 62 5f 6d 75 6c 74 69 5f 65 78 65 63 28 0a db_multi_exec(.
5610: 20 20 20 20 20 20 20 20 20 20 20 20 22 52 45 50 "REP
5620: 4c 41 43 45 20 49 4e 54 4f 20 63 6f 6e 66 69 67 LACE INTO config
5630: 28 6e 61 6d 65 2c 76 61 6c 75 65 29 20 56 41 4c (name,value) VAL
5640: 55 45 53 28 25 51 2c 25 51 29 22 2c 0a 20 20 20 UES(%Q,%Q)",.
5650: 20 20 20 20 20 20 20 20 20 7a 4e 61 6d 65 2c 20 zName,
5660: 62 6c 6f 62 5f 73 74 72 28 26 63 6f 6e 74 65 6e blob_str(&conten
5670: 74 29 0a 20 20 20 20 20 20 20 20 29 3b 0a 20 20 t). );.
5680: 20 20 20 20 7d 65 6c 73 65 7b 0a 20 20 20 20 20 }else{.
5690: 20 20 20 2f 2a 20 4e 6f 74 69 63 65 20 74 68 61 /* Notice tha
56a0: 74 20 77 65 20 61 72 65 20 65 76 61 6c 75 61 74 t we are evaluat
56b0: 69 6e 67 20 61 72 62 69 74 72 61 72 79 20 53 51 ing arbitrary SQ
56c0: 4c 20 72 65 63 65 69 76 65 64 20 66 72 6f 6d 20 L received from
56d0: 74 68 65 0a 20 20 20 20 20 20 20 20 2a 2a 20 63 the. ** c
56e0: 6c 69 65 6e 74 2e 20 20 42 75 74 20 74 68 69 73 lient. But this
56f0: 20 63 61 6e 20 6f 6e 6c 79 20 68 61 70 70 65 6e can only happen
5700: 20 69 66 20 74 68 65 20 63 6c 69 65 6e 74 20 68 if the client h
5710: 61 73 20 61 75 74 68 65 6e 74 69 63 61 74 65 64 as authenticated
5720: 0a 20 20 20 20 20 20 20 20 2a 2a 20 61 73 20 61 . ** as a
5730: 6e 20 61 64 6d 69 6e 69 73 74 72 61 74 6f 72 2c n administrator,
5740: 20 73 6f 20 70 72 65 73 75 6d 61 62 6c 79 20 77 so presumably w
5750: 65 20 74 72 75 73 74 20 74 68 65 20 63 6c 69 65 e trust the clie
5760: 6e 74 20 61 74 20 74 68 69 73 0a 20 20 20 20 20 nt at this.
5770: 20 20 20 2a 2a 20 70 6f 69 6e 74 2e 0a 20 20 20 ** point..
5780: 20 20 20 20 20 2a 2f 0a 20 20 20 20 20 20 20 20 */.
5790: 69 66 28 20 21 72 65 63 76 43 6f 6e 66 69 67 20 if( !recvConfig
57a0: 29 7b 0a 20 20 20 20 20 20 20 20 20 20 63 6f 6e ){. con
57b0: 66 69 67 75 72 65 5f 70 72 65 70 61 72 65 5f 74 figure_prepare_t
57c0: 6f 5f 72 65 63 65 69 76 65 28 30 29 3b 0a 20 20 o_receive(0);.
57d0: 20 20 20 20 20 20 20 20 72 65 63 76 43 6f 6e 66 recvConf
57e0: 69 67 20 3d 20 31 3b 0a 20 20 20 20 20 20 20 20 ig = 1;.
57f0: 7d 0a 20 20 20 20 20 20 20 20 64 62 5f 6d 75 6c }. db_mul
5800: 74 69 5f 65 78 65 63 28 22 25 73 22 2c 20 62 6c ti_exec("%s", bl
5810: 6f 62 5f 73 74 72 28 26 63 6f 6e 74 65 6e 74 29 ob_str(&content)
5820: 29 3b 0a 20 20 20 20 20 20 7d 0a 20 20 20 20 20 );. }.
5830: 20 62 6c 6f 62 5f 72 65 73 65 74 28 26 63 6f 6e blob_reset(&con
5840: 74 65 6e 74 29 3b 0a 20 20 20 20 20 20 62 6c 6f tent);. blo
5850: 62 5f 73 65 65 6b 28 78 66 65 72 2e 70 49 6e 2c b_seek(xfer.pIn,
5860: 20 31 2c 20 42 4c 4f 42 5f 53 45 45 4b 5f 43 55 1, BLOB_SEEK_CU
5870: 52 29 3b 0a 20 20 20 20 7d 65 6c 73 65 0a 0a 20 R);. }else..
5880: 20 20 20 20 20 0a 0a 20 20 20 20 2f 2a 20 20 20 .. /*
5890: 20 63 6f 6f 6b 69 65 20 54 45 58 54 0a 20 20 20 cookie TEXT.
58a0: 20 2a 2a 0a 20 20 20 20 2a 2a 20 41 20 63 6f 6f **. ** A coo
58b0: 6b 69 65 20 63 6f 6e 74 61 69 6e 73 20 61 20 61 kie contains a a
58c0: 72 62 69 74 72 61 72 79 2d 6c 65 6e 67 74 68 20 rbitrary-length
58d0: 61 72 67 75 6d 65 6e 74 20 74 68 61 74 20 69 73 argument that is
58e0: 20 73 65 72 76 65 72 2d 64 65 66 69 6e 65 64 2e server-defined.
58f0: 0a 20 20 20 20 2a 2a 20 54 68 65 20 61 72 67 75 . ** The argu
5900: 6d 65 6e 74 20 6d 75 73 74 20 62 65 20 65 6e 63 ment must be enc
5910: 6f 64 65 64 20 73 6f 20 61 73 20 6e 6f 74 20 74 oded so as not t
5920: 6f 20 63 6f 6e 74 61 69 6e 20 61 6e 79 20 77 68 o contain any wh
5930: 69 74 65 73 70 61 63 65 2e 0a 20 20 20 20 2a 2a itespace.. **
5940: 20 54 68 65 20 73 65 72 76 65 72 20 63 61 6e 20 The server can
5950: 6f 70 74 69 6f 6e 61 6c 6c 79 20 73 65 6e 64 20 optionally send
5960: 61 20 63 6f 6f 6b 69 65 20 74 6f 20 74 68 65 20 a cookie to the
5970: 63 6c 69 65 6e 74 2e 20 20 54 68 65 20 63 6c 69 client. The cli
5980: 65 6e 74 0a 20 20 20 20 2a 2a 20 6d 69 67 68 74 ent. ** might
5990: 20 74 68 65 6e 20 72 65 74 75 72 6e 20 74 68 65 then return the
59a0: 20 73 61 6d 65 20 63 6f 6f 6b 69 65 20 62 61 63 same cookie bac
59b0: 6b 20 74 6f 20 74 68 65 20 73 65 72 76 65 72 20 k to the server
59c0: 6f 6e 20 69 74 73 20 6e 65 78 74 0a 20 20 20 20 on its next.
59d0: 2a 2a 20 63 6f 6d 6d 75 6e 69 63 61 74 69 6f 6e ** communication
59e0: 2e 20 20 54 68 65 20 63 6f 6f 6b 69 65 20 6d 69 . The cookie mi
59f0: 67 68 74 20 72 65 63 6f 72 64 20 69 6e 66 6f 72 ght record infor
5a00: 6d 61 74 69 6f 6e 20 74 68 61 74 20 68 65 6c 70 mation that help
5a10: 73 0a 20 20 20 20 2a 2a 20 74 68 65 20 73 65 72 s. ** the ser
5a20: 76 65 72 20 6f 70 74 69 6d 69 7a 65 20 61 20 70 ver optimize a p
5a30: 75 73 68 20 6f 72 20 70 75 6c 6c 2e 0a 20 20 20 ush or pull..
5a40: 20 2a 2a 0a 20 20 20 20 2a 2a 20 54 68 65 20 63 **. ** The c
5a50: 6c 69 65 6e 74 20 69 73 20 6e 6f 74 20 72 65 71 lient is not req
5a60: 75 69 72 65 64 20 74 6f 20 72 65 74 75 72 6e 20 uired to return
5a70: 61 20 63 6f 6f 6b 69 65 2e 20 20 53 6f 20 74 68 a cookie. So th
5a80: 65 20 73 65 72 76 65 72 0a 20 20 20 20 2a 2a 20 e server. **
5a90: 6d 75 73 74 20 6e 6f 74 20 64 65 70 65 6e 64 20 must not depend
5aa0: 6f 6e 20 74 68 65 20 63 6f 6f 6b 69 65 2e 20 20 on the cookie.
5ab0: 54 68 65 20 63 6f 6f 6b 69 65 20 73 68 6f 75 6c The cookie shoul
5ac0: 64 20 62 65 20 61 6e 20 6f 70 74 69 6d 69 7a 61 d be an optimiza
5ad0: 74 69 6f 6e 0a 20 20 20 20 2a 2a 20 6f 6e 6c 79 tion. ** only
5ae0: 2e 20 20 54 68 65 20 63 6c 69 65 6e 74 20 6d 69 . The client mi
5af0: 67 68 74 20 61 6c 73 6f 20 73 65 6e 64 20 61 20 ght also send a
5b00: 63 6f 6f 6b 69 65 20 74 68 61 74 20 63 61 6d 65 cookie that came
5b10: 20 66 72 6f 6d 20 61 20 64 69 66 66 65 72 65 6e from a differen
5b20: 74 0a 20 20 20 20 2a 2a 20 73 65 72 76 65 72 2e t. ** server.
5b30: 20 20 53 6f 20 74 68 65 20 73 65 72 76 65 72 20 So the server
5b40: 6d 75 73 74 20 62 65 20 70 72 65 70 61 72 65 64 must be prepared
5b50: 20 74 6f 20 64 69 73 74 69 6e 67 75 69 73 68 20 to distinguish
5b60: 69 74 73 20 6f 77 6e 20 63 6f 6f 6b 69 65 0a 20 its own cookie.
5b70: 20 20 20 2a 2a 20 66 72 6f 6d 20 63 6f 6f 6b 69 ** from cooki
5b80: 65 73 20 6f 72 69 67 69 6e 61 74 69 6e 67 20 66 es originating f
5b90: 72 6f 6d 20 6f 74 68 65 72 20 73 65 72 76 65 72 rom other server
5ba0: 73 2e 20 20 54 68 65 20 63 6c 69 65 6e 74 20 6d s. The client m
5bb0: 69 67 68 74 20 73 65 6e 64 0a 20 20 20 20 2a 2a ight send. **
5bc0: 20 62 61 63 6b 20 73 65 76 65 72 61 6c 20 64 69 back several di
5bd0: 66 66 65 72 65 6e 74 20 63 6f 6f 6b 69 65 73 20 fferent cookies
5be0: 74 6f 20 74 68 65 20 73 65 72 76 65 72 2e 20 20 to the server.
5bf0: 54 68 65 20 73 65 72 76 65 72 20 73 68 6f 75 6c The server shoul
5c00: 64 20 62 65 0a 20 20 20 20 2a 2a 20 70 72 65 70 d be. ** prep
5c10: 61 72 65 64 20 74 6f 20 73 69 66 74 20 74 68 72 ared to sift thr
5c20: 6f 75 67 68 20 74 68 65 20 63 6f 6f 6b 69 65 73 ough the cookies
5c30: 20 61 6e 64 20 70 69 63 6b 20 74 68 65 20 6f 6e and pick the on
5c40: 65 20 74 68 61 74 20 69 74 20 77 61 6e 74 73 2e e that it wants.
5c50: 0a 20 20 20 20 2a 2f 0a 20 20 20 20 69 66 28 20 . */. if(
5c60: 62 6c 6f 62 5f 65 71 28 26 78 66 65 72 2e 61 54 blob_eq(&xfer.aT
5c70: 6f 6b 65 6e 5b 30 5d 2c 20 22 63 6f 6f 6b 69 65 oken[0], "cookie
5c80: 22 29 20 26 26 20 78 66 65 72 2e 6e 54 6f 6b 65 ") && xfer.nToke
5c90: 6e 3d 3d 32 20 29 7b 0a 20 20 20 20 20 20 2f 2a n==2 ){. /*
5ca0: 20 50 72 6f 63 65 73 73 20 74 68 65 20 63 6f 6f Process the coo
5cb0: 6b 69 65 20 2a 2f 0a 20 20 20 20 7d 65 6c 73 65 kie */. }else
5cc0: 0a 0a 20 20 20 20 2f 2a 20 55 6e 6b 6e 6f 77 6e .. /* Unknown
5cd0: 20 6d 65 73 73 61 67 65 0a 20 20 20 20 2a 2f 0a message. */.
5ce0: 20 20 20 20 7b 0a 20 20 20 20 20 20 63 67 69 5f {. cgi_
5cf0: 72 65 73 65 74 5f 63 6f 6e 74 65 6e 74 28 29 3b reset_content();
5d00: 0a 20 20 20 20 20 20 40 20 65 72 72 6f 72 20 62 . @ error b
5d10: 61 64 5c 73 63 6f 6d 6d 61 6e 64 3a 5c 73 25 46 ad\scommand:\s%F
5d20: 28 62 6c 6f 62 5f 73 74 72 28 26 78 66 65 72 2e (blob_str(&xfer.
5d30: 6c 69 6e 65 29 29 0a 20 20 20 20 7d 0a 20 20 20 line)). }.
5d40: 20 62 6c 6f 62 61 72 72 61 79 5f 72 65 73 65 74 blobarray_reset
5d50: 28 78 66 65 72 2e 61 54 6f 6b 65 6e 2c 20 78 66 (xfer.aToken, xf
5d60: 65 72 2e 6e 54 6f 6b 65 6e 29 3b 0a 20 20 7d 0a er.nToken);. }.
5d70: 20 20 69 66 28 20 69 73 50 75 73 68 20 29 7b 0a if( isPush ){.
5d80: 20 20 20 20 72 65 71 75 65 73 74 5f 70 68 61 6e request_phan
5d90: 74 6f 6d 73 28 26 78 66 65 72 2c 20 35 30 30 29 toms(&xfer, 500)
5da0: 3b 0a 20 20 7d 0a 20 20 69 66 28 20 69 73 43 6c ;. }. if( isCl
5db0: 6f 6e 65 20 26 26 20 6e 47 69 6d 6d 65 3d 3d 30 one && nGimme==0
5dc0: 20 29 7b 0a 20 20 20 20 2f 2a 20 54 68 65 20 69 ){. /* The i
5dd0: 6e 69 74 69 61 6c 20 22 63 6c 6f 6e 65 22 20 6d nitial "clone" m
5de0: 65 73 73 61 67 65 20 66 72 6f 6d 20 63 6c 69 65 essage from clie
5df0: 6e 74 20 74 6f 20 73 65 72 76 65 72 20 63 6f 6e nt to server con
5e00: 74 61 69 6e 73 20 6e 6f 0a 20 20 20 20 2a 2a 20 tains no. **
5e10: 22 67 69 6d 6d 65 22 20 63 61 72 64 73 2e 20 4f "gimme" cards. O
5e20: 6e 20 74 68 61 74 20 69 6e 69 74 69 61 6c 20 6d n that initial m
5e30: 65 73 73 61 67 65 2c 20 73 65 6e 64 20 74 68 65 essage, send the
5e40: 20 63 6c 69 65 6e 74 20 61 6e 20 22 69 67 6f 74 client an "igot
5e50: 22 0a 20 20 20 20 2a 2a 20 63 61 72 64 20 66 6f ". ** card fo
5e60: 72 20 65 76 65 72 79 20 61 72 74 69 66 61 63 74 r every artifact
5e70: 20 63 75 72 72 65 6e 74 6c 79 20 69 6e 20 74 68 currently in th
5e80: 65 20 72 65 73 70 6f 73 69 74 6f 72 79 2e 20 20 e respository.
5e90: 54 68 69 73 20 77 69 6c 6c 0a 20 20 20 20 2a 2a This will. **
5ea0: 20 63 61 75 73 65 20 74 68 65 20 63 6c 69 65 6e cause the clien
5eb0: 74 20 74 6f 20 63 72 65 61 74 65 20 70 68 61 6e t to create phan
5ec0: 74 6f 6d 73 20 66 6f 72 20 61 6c 6c 20 61 72 74 toms for all art
5ed0: 69 66 61 63 74 73 2c 20 77 68 69 63 68 20 77 69 ifacts, which wi
5ee0: 6c 6c 0a 20 20 20 20 2a 2a 20 69 6e 20 74 75 72 ll. ** in tur
5ef0: 6e 20 6d 61 6b 65 20 73 75 72 65 20 74 68 61 74 n make sure that
5f00: 20 74 68 65 20 65 6e 74 69 72 65 20 72 65 70 6f the entire repo
5f10: 73 69 74 6f 72 79 20 69 73 20 73 65 6e 74 20 65 sitory is sent e
5f20: 66 66 69 63 69 65 6e 74 6c 79 0a 20 20 20 20 2a fficiently. *
5f30: 2a 20 61 6e 64 20 65 78 70 65 64 69 74 69 6f 75 * and expeditiou
5f40: 73 6c 79 2e 0a 20 20 20 20 2a 2f 0a 20 20 20 20 sly.. */.
5f50: 73 65 6e 64 5f 61 6c 6c 28 26 78 66 65 72 29 3b send_all(&xfer);
5f60: 0a 20 20 7d 65 6c 73 65 20 69 66 28 20 69 73 50 . }else if( isP
5f70: 75 6c 6c 20 29 7b 0a 20 20 20 20 63 72 65 61 74 ull ){. creat
5f80: 65 5f 63 6c 75 73 74 65 72 28 29 3b 0a 20 20 20 e_cluster();.
5f90: 20 73 65 6e 64 5f 75 6e 63 6c 75 73 74 65 72 65 send_unclustere
5fa0: 64 28 26 78 66 65 72 29 3b 0a 20 20 7d 0a 20 20 d(&xfer);. }.
5fb0: 69 66 28 20 72 65 63 76 43 6f 6e 66 69 67 20 29 if( recvConfig )
5fc0: 7b 0a 20 20 20 20 63 6f 6e 66 69 67 75 72 65 5f {. configure_
5fd0: 66 69 6e 61 6c 69 7a 65 5f 72 65 63 65 69 76 65 finalize_receive
5fe0: 28 29 3b 0a 20 20 7d 0a 20 20 64 62 5f 65 6e 64 ();. }. db_end
5ff0: 5f 74 72 61 6e 73 61 63 74 69 6f 6e 28 30 29 3b _transaction(0);
6000: 0a 7d 0a 0a 2f 2a 0a 2a 2a 20 43 4f 4d 4d 41 4e .}../*.** COMMAN
6010: 44 3a 20 74 65 73 74 2d 78 66 65 72 0a 2a 2a 0a D: test-xfer.**.
6020: 2a 2a 20 54 68 69 73 20 63 6f 6d 6d 61 6e 64 20 ** This command
6030: 69 73 20 75 73 65 64 20 66 6f 72 20 64 65 62 75 is used for debu
6040: 67 67 69 6e 67 20 74 68 65 20 73 65 72 76 65 72 gging the server
6050: 2e 20 20 54 68 65 72 65 20 69 73 20 61 20 73 69 . There is a si
6060: 6e 67 6c 65 0a 2a 2a 20 61 72 67 75 6d 65 6e 74 ngle.** argument
6070: 20 77 68 69 63 68 20 69 73 20 74 68 65 20 75 6e which is the un
6080: 63 6f 6d 70 72 65 73 73 65 64 20 63 6f 6e 74 65 compressed conte
6090: 6e 74 20 6f 66 20 61 6e 20 22 78 66 65 72 22 20 nt of an "xfer"
60a0: 6d 65 73 73 61 67 65 0a 2a 2a 20 66 72 6f 6d 20 message.** from
60b0: 63 6c 69 65 6e 74 20 74 6f 20 73 65 72 76 65 72 client to server
60c0: 2e 20 20 54 68 69 73 20 63 6f 6d 6d 61 6e 64 20 . This command
60d0: 69 6e 74 65 72 70 72 65 74 73 20 74 68 61 74 20 interprets that
60e0: 6d 65 73 73 61 67 65 20 61 73 0a 2a 2a 20 69 66 message as.** if
60f0: 20 68 61 64 20 62 65 65 6e 20 72 65 63 65 69 76 had been receiv
6100: 65 64 20 62 79 20 74 68 65 20 73 65 72 76 65 72 ed by the server
6110: 2e 0a 2a 2a 0a 2a 2a 20 4f 6e 20 74 68 65 20 63 ..**.** On the c
6120: 6c 69 65 6e 74 20 73 69 64 65 2c 20 72 75 6e 3a lient side, run:
6130: 0a 2a 2a 0a 2a 2a 20 20 20 20 20 20 66 6f 73 73 .**.** foss
6140: 69 6c 20 70 75 73 68 20 68 74 74 70 3a 2f 2f 62 il push http://b
6150: 6f 67 75 73 2f 20 2d 2d 68 74 74 70 74 72 61 63 ogus/ --httptrac
6160: 65 0a 2a 2a 0a 2a 2a 20 4f 72 20 61 20 73 69 6d e.**.** Or a sim
6170: 69 6c 61 72 20 63 6f 6d 6d 61 6e 64 20 74 6f 20 ilar command to
6180: 70 72 6f 76 69 64 65 20 74 68 65 20 6f 75 74 70 provide the outp
6190: 75 74 2e 20 20 54 68 65 20 63 6f 6e 74 65 6e 74 ut. The content
61a0: 20 6f 66 20 74 68 65 0a 2a 2a 20 6d 65 73 73 61 of the.** messa
61b0: 67 65 20 77 69 6c 6c 20 61 70 70 65 61 72 20 6f ge will appear o
61c0: 6e 20 73 74 61 6e 64 61 72 64 20 6f 75 74 70 75 n standard outpu
61d0: 74 2e 20 20 43 61 70 74 75 72 65 20 74 68 69 73 t. Capture this
61e0: 20 6d 65 73 73 61 67 65 0a 2a 2a 20 69 6e 74 6f message.** into
61f0: 20 61 20 66 69 6c 65 20 6e 61 6d 65 64 20 28 66 a file named (f
6200: 6f 72 20 65 78 61 6d 70 6c 65 29 20 6f 75 74 2e or example) out.
6210: 74 78 74 2e 20 20 54 68 65 6e 20 72 75 6e 20 74 txt. Then run t
6220: 68 65 0a 2a 2a 20 73 65 72 76 65 72 20 69 6e 20 he.** server in
6230: 67 64 62 3a 0a 2a 2a 0a 2a 2a 20 20 20 20 20 67 gdb:.**.** g
6240: 64 62 20 66 6f 73 73 69 6c 0a 2a 2a 20 20 20 20 db fossil.**
6250: 20 72 20 74 65 73 74 2d 78 66 65 72 20 6f 75 74 r test-xfer out
6260: 2e 74 78 74 0a 2a 2f 0a 76 6f 69 64 20 63 6d 64 .txt.*/.void cmd
6270: 5f 74 65 73 74 5f 78 66 65 72 28 76 6f 69 64 29 _test_xfer(void)
6280: 7b 0a 20 20 69 6e 74 20 6e 6f 74 55 73 65 64 3b {. int notUsed;
6290: 0a 20 20 69 66 28 20 67 2e 61 72 67 63 21 3d 32 . if( g.argc!=2
62a0: 20 26 26 20 67 2e 61 72 67 63 21 3d 33 20 29 7b && g.argc!=3 ){
62b0: 0a 20 20 20 20 75 73 61 67 65 28 22 3f 4d 45 53 . usage("?MES
62c0: 53 41 47 45 46 49 4c 45 3f 22 29 3b 0a 20 20 7d SAGEFILE?");. }
62d0: 0a 20 20 64 62 5f 6d 75 73 74 5f 62 65 5f 77 69 . db_must_be_wi
62e0: 74 68 69 6e 5f 74 72 65 65 28 29 3b 0a 20 20 62 thin_tree();. b
62f0: 6c 6f 62 5f 7a 65 72 6f 28 26 67 2e 63 67 69 49 lob_zero(&g.cgiI
6300: 6e 29 3b 0a 20 20 62 6c 6f 62 5f 72 65 61 64 5f n);. blob_read_
6310: 66 72 6f 6d 5f 66 69 6c 65 28 26 67 2e 63 67 69 from_file(&g.cgi
6320: 49 6e 2c 20 67 2e 61 72 67 63 3d 3d 32 20 3f 20 In, g.argc==2 ?
6330: 22 2d 22 20 3a 20 67 2e 61 72 67 76 5b 32 5d 29 "-" : g.argv[2])
6340: 3b 0a 20 20 64 69 73 61 62 6c 65 4c 6f 67 69 6e ;. disableLogin
6350: 20 3d 20 31 3b 0a 20 20 70 61 67 65 5f 78 66 65 = 1;. page_xfe
6360: 72 28 29 3b 0a 20 20 70 72 69 6e 74 66 28 22 25 r();. printf("%
6370: 73 5c 6e 22 2c 20 63 67 69 5f 65 78 74 72 61 63 s\n", cgi_extrac
6380: 74 5f 63 6f 6e 74 65 6e 74 28 26 6e 6f 74 55 73 t_content(¬Us
6390: 65 64 29 29 3b 0a 7d 0a 0a 2f 2a 0a 2a 2a 20 46 ed));.}../*.** F
63a0: 6f 72 6d 61 74 20 73 74 72 69 6e 67 73 20 66 6f ormat strings fo
63b0: 72 20 70 72 6f 67 72 65 73 73 20 72 65 70 6f 72 r progress repor
63c0: 74 69 6e 67 2e 0a 2a 2f 0a 73 74 61 74 69 63 20 ting..*/.static
63d0: 63 6f 6e 73 74 20 63 68 61 72 20 7a 4c 61 62 65 const char zLabe
63e0: 6c 46 6f 72 6d 61 74 5b 5d 20 3d 20 22 25 2d 31 lFormat[] = "%-1
63f0: 30 73 20 25 31 30 73 20 25 31 30 73 20 25 31 30 0s %10s %10s %10
6400: 73 20 25 31 30 73 5c 6e 22 3b 0a 73 74 61 74 69 s %10s\n";.stati
6410: 63 20 63 6f 6e 73 74 20 63 68 61 72 20 7a 56 61 c const char zVa
6420: 6c 75 65 46 6f 72 6d 61 74 5b 5d 20 3d 20 22 5c lueFormat[] = "\
6430: 72 25 2d 31 30 73 20 25 31 30 64 20 25 31 30 64 r%-10s %10d %10d
6440: 20 25 31 30 64 20 25 31 30 64 5c 6e 22 3b 0a 0a %10d %10d\n";..
6450: 0a 2f 2a 0a 2a 2a 20 53 79 6e 63 20 74 6f 20 74 ./*.** Sync to t
6460: 68 65 20 68 6f 73 74 20 69 64 65 6e 74 69 66 69 he host identifi
6470: 65 64 20 69 6e 20 67 2e 75 72 6c 4e 61 6d 65 20 ed in g.urlName
6480: 61 6e 64 20 67 2e 75 72 6c 50 61 74 68 2e 20 20 and g.urlPath.
6490: 54 68 69 73 0a 2a 2a 20 72 6f 75 74 69 6e 65 20 This.** routine
64a0: 69 73 20 63 61 6c 6c 65 64 20 62 79 20 74 68 65 is called by the
64b0: 20 63 6c 69 65 6e 74 2e 0a 2a 2a 0a 2a 2a 20 52 client..**.** R
64c0: 65 63 6f 72 64 73 20 61 72 65 20 70 75 73 68 65 ecords are pushe
64d0: 64 20 74 6f 20 74 68 65 20 73 65 72 76 65 72 20 d to the server
64e0: 69 66 20 70 75 73 68 46 6c 61 67 20 69 73 20 74 if pushFlag is t
64f0: 72 75 65 2e 20 20 52 65 63 6f 72 64 73 0a 2a 2a rue. Records.**
6500: 20 61 72 65 20 70 75 6c 6c 65 64 20 69 66 20 70 are pulled if p
6510: 75 6c 6c 46 6c 61 67 20 69 73 20 74 72 75 65 2e ullFlag is true.
6520: 20 20 41 20 66 75 6c 6c 20 73 79 6e 63 20 6f 63 A full sync oc
6530: 63 75 72 73 20 69 66 20 62 6f 74 68 20 61 72 65 curs if both are
6540: 0a 2a 2a 20 74 72 75 65 2e 0a 2a 2f 0a 76 6f 69 .** true..*/.voi
6550: 64 20 63 6c 69 65 6e 74 5f 73 79 6e 63 28 0a 20 d client_sync(.
6560: 20 69 6e 74 20 70 75 73 68 46 6c 61 67 2c 20 20 int pushFlag,
6570: 20 20 20 20 20 20 20 20 20 2f 2a 20 54 72 75 65 /* True
6580: 20 74 6f 20 64 6f 20 61 20 70 75 73 68 20 28 6f to do a push (o
6590: 72 20 61 20 73 79 6e 63 29 20 2a 2f 0a 20 20 69 r a sync) */. i
65a0: 6e 74 20 70 75 6c 6c 46 6c 61 67 2c 20 20 20 20 nt pullFlag,
65b0: 20 20 20 20 20 20 20 2f 2a 20 54 72 75 65 20 74 /* True t
65c0: 6f 20 64 6f 20 61 20 70 75 6c 6c 20 28 6f 72 20 o do a pull (or
65d0: 61 20 73 79 6e 63 29 20 2a 2f 0a 20 20 69 6e 74 a sync) */. int
65e0: 20 63 6c 6f 6e 65 46 6c 61 67 2c 20 20 20 20 20 cloneFlag,
65f0: 20 20 20 20 20 2f 2a 20 54 72 75 65 20 69 66 20 /* True if
6600: 74 68 69 73 20 69 73 20 61 20 63 6c 6f 6e 65 20 this is a clone
6610: 2a 2f 0a 20 20 69 6e 74 20 63 6f 6e 66 69 67 52 */. int configR
6620: 63 76 4d 61 73 6b 2c 20 20 20 20 20 20 2f 2a 20 cvMask, /*
6630: 52 65 63 65 69 76 65 20 74 68 65 73 65 20 63 6f Receive these co
6640: 6e 66 69 67 75 72 61 74 69 6f 6e 20 69 74 65 6d nfiguration item
6650: 73 20 2a 2f 0a 20 20 69 6e 74 20 63 6f 6e 66 69 s */. int confi
6660: 67 53 65 6e 64 4d 61 73 6b 20 20 20 20 20 20 2f gSendMask /
6670: 2a 20 53 65 6e 64 20 74 68 65 73 65 20 63 6f 6e * Send these con
6680: 66 69 67 75 72 61 74 69 6f 6e 20 69 74 65 6d 73 figuration items
6690: 20 2a 2f 0a 29 7b 0a 20 20 69 6e 74 20 67 6f 20 */.){. int go
66a0: 3d 20 31 3b 20 20 20 20 20 20 20 20 20 20 20 20 = 1;
66b0: 20 2f 2a 20 4c 6f 6f 70 20 75 6e 74 69 6c 20 7a /* Loop until z
66c0: 65 72 6f 20 2a 2f 0a 20 20 69 6e 74 20 6e 43 61 ero */. int nCa
66d0: 72 64 20 3d 20 30 3b 20 20 20 20 20 20 20 20 20 rd = 0;
66e0: 20 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 20 63 61 /* Number of ca
66f0: 72 64 73 20 73 65 6e 74 20 6f 72 20 72 65 63 65 rds sent or rece
6700: 69 76 65 64 20 2a 2f 0a 20 20 69 6e 74 20 6e 43 ived */. int nC
6710: 79 63 6c 65 20 3d 20 30 3b 20 20 20 20 20 20 20 ycle = 0;
6720: 20 20 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 20 72 /* Number of r
6730: 6f 75 6e 64 20 74 72 69 70 73 20 74 6f 20 74 68 ound trips to th
6740: 65 20 73 65 72 76 65 72 20 2a 2f 0a 20 20 69 6e e server */. in
6750: 74 20 73 69 7a 65 3b 20 20 20 20 20 20 20 20 20 t size;
6760: 20 20 20 20 20 20 2f 2a 20 53 69 7a 65 20 6f 66 /* Size of
6770: 20 61 20 63 6f 6e 66 69 67 20 76 61 6c 75 65 20 a config value
6780: 2a 2f 0a 20 20 69 6e 74 20 6e 46 69 6c 65 53 65 */. int nFileSe
6790: 6e 64 20 3d 20 30 3b 0a 20 20 69 6e 74 20 6f 72 nd = 0;. int or
67a0: 69 67 43 6f 6e 66 69 67 52 63 76 4d 61 73 6b 3b igConfigRcvMask;
67b0: 20 20 2f 2a 20 4f 72 69 67 69 6e 61 6c 20 76 61 /* Original va
67c0: 6c 75 65 20 6f 66 20 63 6f 6e 66 69 67 52 63 76 lue of configRcv
67d0: 4d 61 73 6b 20 2a 2f 0a 20 20 69 6e 74 20 6e 46 Mask */. int nF
67e0: 69 6c 65 52 65 63 76 3b 20 20 20 20 20 20 20 20 ileRecv;
67f0: 20 20 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 20 66 /* Number of f
6800: 69 6c 65 73 20 72 65 63 65 69 76 65 64 20 2a 2f iles received */
6810: 0a 20 20 69 6e 74 20 6d 78 50 68 61 6e 74 6f 6d . int mxPhantom
6820: 52 65 71 20 3d 20 32 30 30 3b 20 2f 2a 20 4d 61 Req = 200; /* Ma
6830: 78 20 6e 75 6d 62 65 72 20 6f 66 20 70 68 61 6e x number of phan
6840: 74 6f 6d 73 20 74 6f 20 72 65 71 75 65 73 74 20 toms to request
6850: 70 65 72 20 63 6f 6d 6d 20 2a 2f 0a 20 20 63 6f per comm */. co
6860: 6e 73 74 20 63 68 61 72 20 2a 7a 43 6f 6f 6b 69 nst char *zCooki
6870: 65 3b 20 20 20 20 2f 2a 20 53 65 72 76 65 72 20 e; /* Server
6880: 63 6f 6f 6b 69 65 20 2a 2f 0a 20 20 69 6e 74 20 cookie */. int
6890: 6e 53 65 6e 74 2c 20 6e 52 63 76 64 3b 20 20 20 nSent, nRcvd;
68a0: 20 20 20 20 2f 2a 20 42 79 74 65 73 20 73 65 6e /* Bytes sen
68b0: 74 20 61 6e 64 20 72 65 63 65 69 76 65 64 20 28 t and received (
68c0: 61 66 74 65 72 20 63 6f 6d 70 72 65 73 73 69 6f after compressio
68d0: 6e 29 20 2a 2f 0a 20 20 42 6c 6f 62 20 73 65 6e n) */. Blob sen
68e0: 64 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 20 d;
68f0: 2f 2a 20 54 65 78 74 20 77 65 20 61 72 65 20 73 /* Text we are s
6900: 65 6e 64 69 6e 67 20 74 6f 20 74 68 65 20 73 65 ending to the se
6910: 72 76 65 72 20 2a 2f 0a 20 20 42 6c 6f 62 20 72 rver */. Blob r
6920: 65 63 76 3b 20 20 20 20 20 20 20 20 20 20 20 20 ecv;
6930: 20 20 2f 2a 20 52 65 70 6c 79 20 77 65 20 67 6f /* Reply we go
6940: 74 20 62 61 63 6b 20 66 72 6f 6d 20 74 68 65 20 t back from the
6950: 73 65 72 76 65 72 20 2a 2f 0a 20 20 58 66 65 72 server */. Xfer
6960: 20 78 66 65 72 3b 20 20 20 20 20 20 20 20 20 20 xfer;
6970: 20 20 20 20 2f 2a 20 54 72 61 6e 73 66 65 72 20 /* Transfer
6980: 64 61 74 61 20 2a 2f 0a 20 20 63 6f 6e 73 74 20 data */. const
6990: 63 68 61 72 20 2a 7a 53 43 6f 64 65 20 3d 20 64 char *zSCode = d
69a0: 62 5f 67 65 74 28 22 73 65 72 76 65 72 2d 63 6f b_get("server-co
69b0: 64 65 22 2c 20 22 78 22 29 3b 0a 20 20 63 6f 6e de", "x");. con
69c0: 73 74 20 63 68 61 72 20 2a 7a 50 43 6f 64 65 20 st char *zPCode
69d0: 3d 20 64 62 5f 67 65 74 28 22 70 72 6f 6a 65 63 = db_get("projec
69e0: 74 2d 63 6f 64 65 22 2c 20 30 29 3b 0a 0a 20 20 t-code", 0);..
69f0: 69 66 28 20 64 62 5f 67 65 74 5f 62 6f 6f 6c 65 if( db_get_boole
6a00: 61 6e 28 22 64 6f 6e 74 2d 70 75 73 68 22 2c 20 an("dont-push",
6a10: 30 29 20 29 20 70 75 73 68 46 6c 61 67 20 3d 20 0) ) pushFlag =
6a20: 30 3b 0a 20 20 69 66 28 20 70 75 73 68 46 6c 61 0;. if( pushFla
6a30: 67 20 2b 20 70 75 6c 6c 46 6c 61 67 20 2b 20 63 g + pullFlag + c
6a40: 6c 6f 6e 65 46 6c 61 67 20 3d 3d 20 30 20 29 20 loneFlag == 0 )
6a50: 72 65 74 75 72 6e 3b 0a 0a 20 20 74 72 61 6e 73 return;.. trans
6a60: 70 6f 72 74 5f 73 74 61 74 73 28 30 2c 20 30 2c port_stats(0, 0,
6a70: 20 31 29 3b 0a 20 20 73 6f 63 6b 65 74 5f 67 6c 1);. socket_gl
6a80: 6f 62 61 6c 5f 69 6e 69 74 28 29 3b 0a 20 20 6d obal_init();. m
6a90: 65 6d 73 65 74 28 26 78 66 65 72 2c 20 30 2c 20 emset(&xfer, 0,
6aa0: 73 69 7a 65 6f 66 28 78 66 65 72 29 29 3b 0a 20 sizeof(xfer));.
6ab0: 20 78 66 65 72 2e 70 49 6e 20 3d 20 26 72 65 63 xfer.pIn = &rec
6ac0: 76 3b 0a 20 20 78 66 65 72 2e 70 4f 75 74 20 3d v;. xfer.pOut =
6ad0: 20 26 73 65 6e 64 3b 0a 20 20 78 66 65 72 2e 6d &send;. xfer.m
6ae0: 78 53 65 6e 64 20 3d 20 64 62 5f 67 65 74 5f 69 xSend = db_get_i
6af0: 6e 74 28 22 6d 61 78 2d 75 70 6c 6f 61 64 22 2c nt("max-upload",
6b00: 20 32 35 30 30 30 30 29 3b 0a 0a 20 20 61 73 73 250000);.. ass
6b10: 65 72 74 28 20 70 75 73 68 46 6c 61 67 20 7c 20 ert( pushFlag |
6b20: 70 75 6c 6c 46 6c 61 67 20 7c 20 63 6c 6f 6e 65 pullFlag | clone
6b30: 46 6c 61 67 20 7c 20 63 6f 6e 66 69 67 52 63 76 Flag | configRcv
6b40: 4d 61 73 6b 20 7c 20 63 6f 6e 66 69 67 53 65 6e Mask | configSen
6b50: 64 4d 61 73 6b 20 29 3b 0a 20 20 64 62 5f 62 65 dMask );. db_be
6b60: 67 69 6e 5f 74 72 61 6e 73 61 63 74 69 6f 6e 28 gin_transaction(
6b70: 29 3b 0a 20 20 64 62 5f 72 65 63 6f 72 64 5f 72 );. db_record_r
6b80: 65 70 6f 73 69 74 6f 72 79 5f 66 69 6c 65 6e 61 epository_filena
6b90: 6d 65 28 30 29 3b 0a 20 20 64 62 5f 6d 75 6c 74 me(0);. db_mult
6ba0: 69 5f 65 78 65 63 28 0a 20 20 20 20 22 43 52 45 i_exec(. "CRE
6bb0: 41 54 45 20 54 45 4d 50 20 54 41 42 4c 45 20 6f ATE TEMP TABLE o
6bc0: 6e 72 65 6d 6f 74 65 28 72 69 64 20 49 4e 54 45 nremote(rid INTE
6bd0: 47 45 52 20 50 52 49 4d 41 52 59 20 4b 45 59 29 GER PRIMARY KEY)
6be0: 3b 22 0a 20 20 29 3b 0a 20 20 62 6c 6f 62 61 72 ;". );. blobar
6bf0: 72 61 79 5f 7a 65 72 6f 28 78 66 65 72 2e 61 54 ray_zero(xfer.aT
6c00: 6f 6b 65 6e 2c 20 63 6f 75 6e 74 28 78 66 65 72 oken, count(xfer
6c10: 2e 61 54 6f 6b 65 6e 29 29 3b 0a 20 20 62 6c 6f .aToken));. blo
6c20: 62 5f 7a 65 72 6f 28 26 73 65 6e 64 29 3b 0a 20 b_zero(&send);.
6c30: 20 62 6c 6f 62 5f 7a 65 72 6f 28 26 72 65 63 76 blob_zero(&recv
6c40: 29 3b 0a 20 20 62 6c 6f 62 5f 7a 65 72 6f 28 26 );. blob_zero(&
6c50: 78 66 65 72 2e 65 72 72 29 3b 0a 20 20 62 6c 6f xfer.err);. blo
6c60: 62 5f 7a 65 72 6f 28 26 78 66 65 72 2e 6c 69 6e b_zero(&xfer.lin
6c70: 65 29 3b 0a 20 20 6f 72 69 67 43 6f 6e 66 69 67 e);. origConfig
6c80: 52 63 76 4d 61 73 6b 20 3d 20 63 6f 6e 66 69 67 RcvMask = config
6c90: 52 63 76 4d 61 73 6b 3b 0a 0a 20 20 2f 2a 0a 20 RcvMask;.. /*.
6ca0: 20 2a 2a 20 41 6c 77 61 79 73 20 62 65 67 69 6e ** Always begin
6cb0: 20 77 69 74 68 20 61 20 63 6c 6f 6e 65 2c 20 70 with a clone, p
6cc0: 75 6c 6c 2c 20 6f 72 20 70 75 73 68 20 6d 65 73 ull, or push mes
6cd0: 73 61 67 65 0a 20 20 2a 2f 0a 20 20 69 66 28 20 sage. */. if(
6ce0: 63 6c 6f 6e 65 46 6c 61 67 20 29 7b 0a 20 20 20 cloneFlag ){.
6cf0: 20 62 6c 6f 62 5f 61 70 70 65 6e 64 66 28 26 73 blob_appendf(&s
6d00: 65 6e 64 2c 20 22 63 6c 6f 6e 65 5c 6e 22 29 3b end, "clone\n");
6d10: 0a 20 20 20 20 70 75 73 68 46 6c 61 67 20 3d 20 . pushFlag =
6d20: 30 3b 0a 20 20 20 20 70 75 6c 6c 46 6c 61 67 20 0;. pullFlag
6d30: 3d 20 30 3b 0a 20 20 20 20 6e 43 61 72 64 2b 2b = 0;. nCard++
6d40: 3b 0a 20 20 20 20 2f 2a 20 54 42 44 3a 20 52 65 ;. /* TBD: Re
6d50: 71 75 65 73 74 20 61 6c 6c 20 74 72 61 6e 73 66 quest all transf
6d60: 65 72 61 62 6c 65 20 63 6f 6e 66 69 67 75 72 61 erable configura
6d70: 74 69 6f 6e 20 76 61 6c 75 65 73 20 2a 2f 0a 20 tion values */.
6d80: 20 7d 65 6c 73 65 20 69 66 28 20 70 75 6c 6c 46 }else if( pullF
6d90: 6c 61 67 20 29 7b 0a 20 20 20 20 62 6c 6f 62 5f lag ){. blob_
6da0: 61 70 70 65 6e 64 66 28 26 73 65 6e 64 2c 20 22 appendf(&send, "
6db0: 70 75 6c 6c 20 25 73 20 25 73 5c 6e 22 2c 20 7a pull %s %s\n", z
6dc0: 53 43 6f 64 65 2c 20 7a 50 43 6f 64 65 29 3b 0a SCode, zPCode);.
6dd0: 20 20 20 20 6e 43 61 72 64 2b 2b 3b 0a 20 20 7d nCard++;. }
6de0: 0a 20 20 69 66 28 20 70 75 73 68 46 6c 61 67 20 . if( pushFlag
6df0: 29 7b 0a 20 20 20 20 62 6c 6f 62 5f 61 70 70 65 ){. blob_appe
6e00: 6e 64 66 28 26 73 65 6e 64 2c 20 22 70 75 73 68 ndf(&send, "push
6e10: 20 25 73 20 25 73 5c 6e 22 2c 20 7a 53 43 6f 64 %s %s\n", zSCod
6e20: 65 2c 20 7a 50 43 6f 64 65 29 3b 0a 20 20 20 20 e, zPCode);.
6e30: 6e 43 61 72 64 2b 2b 3b 0a 20 20 7d 0a 20 20 70 nCard++;. }. p
6e40: 72 69 6e 74 66 28 7a 4c 61 62 65 6c 46 6f 72 6d rintf(zLabelForm
6e50: 61 74 2c 20 22 22 2c 20 22 42 79 74 65 73 22 2c at, "", "Bytes",
6e60: 20 22 43 61 72 64 73 22 2c 20 22 41 72 74 69 66 "Cards", "Artif
6e70: 61 63 74 73 22 2c 20 22 44 65 6c 74 61 73 22 29 acts", "Deltas")
6e80: 3b 0a 0a 20 20 77 68 69 6c 65 28 20 67 6f 20 29 ;.. while( go )
6e90: 7b 0a 20 20 20 20 69 6e 74 20 6e 65 77 50 68 61 {. int newPha
6ea0: 6e 74 6f 6d 20 3d 20 30 3b 0a 20 20 20 20 63 68 ntom = 0;. ch
6eb0: 61 72 20 2a 7a 52 61 6e 64 6f 6d 6e 65 73 73 3b ar *zRandomness;
6ec0: 0a 0a 20 20 20 20 2f 2a 20 53 65 6e 64 20 6d 61 .. /* Send ma
6ed0: 6b 65 20 74 68 65 20 6d 6f 73 74 20 72 65 63 65 ke the most rece
6ee0: 6e 74 6c 79 20 72 65 63 65 69 76 65 64 20 63 6f ntly received co
6ef0: 6f 6b 69 65 2e 20 20 4c 65 74 20 74 68 65 20 73 okie. Let the s
6f00: 65 72 76 65 72 0a 20 20 20 20 2a 2a 20 66 69 67 erver. ** fig
6f10: 75 72 65 20 6f 75 74 20 69 66 20 74 68 69 73 20 ure out if this
6f20: 69 73 20 61 20 63 6f 6f 6b 69 65 20 74 68 61 74 is a cookie that
6f30: 20 69 74 20 63 61 72 65 73 20 61 62 6f 75 74 2e it cares about.
6f40: 0a 20 20 20 20 2a 2f 0a 20 20 20 20 7a 43 6f 6f . */. zCoo
6f50: 6b 69 65 20 3d 20 64 62 5f 67 65 74 28 22 63 6f kie = db_get("co
6f60: 6f 6b 69 65 22 2c 20 30 29 3b 0a 20 20 20 20 69 okie", 0);. i
6f70: 66 28 20 7a 43 6f 6f 6b 69 65 20 29 7b 0a 20 20 f( zCookie ){.
6f80: 20 20 20 20 62 6c 6f 62 5f 61 70 70 65 6e 64 66 blob_appendf
6f90: 28 26 73 65 6e 64 2c 20 22 63 6f 6f 6b 69 65 20 (&send, "cookie
6fa0: 25 73 5c 6e 22 2c 20 7a 43 6f 6f 6b 69 65 29 3b %s\n", zCookie);
6fb0: 0a 20 20 20 20 7d 0a 20 20 20 20 0a 20 20 20 20 . }. .
6fc0: 2f 2a 20 47 65 6e 65 72 61 74 65 20 67 69 6d 6d /* Generate gimm
6fd0: 65 20 63 61 72 64 73 20 66 6f 72 20 70 68 61 6e e cards for phan
6fe0: 74 6f 6d 73 20 61 6e 64 20 6c 65 61 66 20 63 61 toms and leaf ca
6ff0: 72 64 73 0a 20 20 20 20 2a 2a 20 66 6f 72 20 61 rds. ** for a
7000: 6c 6c 20 6c 65 61 76 65 73 2e 0a 20 20 20 20 2a ll leaves.. *
7010: 2f 0a 20 20 20 20 69 66 28 20 70 75 6c 6c 46 6c /. if( pullFl
7020: 61 67 20 7c 7c 20 63 6c 6f 6e 65 46 6c 61 67 20 ag || cloneFlag
7030: 29 7b 0a 20 20 20 20 20 20 72 65 71 75 65 73 74 ){. request
7040: 5f 70 68 61 6e 74 6f 6d 73 28 26 78 66 65 72 2c _phantoms(&xfer,
7050: 20 6d 78 50 68 61 6e 74 6f 6d 52 65 71 29 3b 0a mxPhantomReq);.
7060: 20 20 20 20 7d 0a 20 20 20 20 69 66 28 20 70 75 }. if( pu
7070: 73 68 46 6c 61 67 20 29 7b 0a 20 20 20 20 20 20 shFlag ){.
7080: 73 65 6e 64 5f 75 6e 73 65 6e 74 28 26 78 66 65 send_unsent(&xfe
7090: 72 29 3b 0a 20 20 20 20 20 20 6e 43 61 72 64 20 r);. nCard
70a0: 2b 3d 20 73 65 6e 64 5f 75 6e 63 6c 75 73 74 65 += send_uncluste
70b0: 72 65 64 28 26 78 66 65 72 29 3b 0a 20 20 20 20 red(&xfer);.
70c0: 7d 0a 0a 20 20 20 20 2f 2a 20 53 65 6e 64 20 63 }.. /* Send c
70d0: 6f 6e 66 69 67 75 72 61 74 69 6f 6e 20 70 61 72 onfiguration par
70e0: 61 6d 65 74 65 72 20 72 65 71 75 65 73 74 73 20 ameter requests
70f0: 2a 2f 0a 20 20 20 20 69 66 28 20 63 6f 6e 66 69 */. if( confi
7100: 67 52 63 76 4d 61 73 6b 20 29 7b 0a 20 20 20 20 gRcvMask ){.
7110: 20 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a 4e const char *zN
7120: 61 6d 65 3b 0a 20 20 20 20 20 20 7a 4e 61 6d 65 ame;. zName
7130: 20 3d 20 63 6f 6e 66 69 67 75 72 65 5f 66 69 72 = configure_fir
7140: 73 74 5f 6e 61 6d 65 28 63 6f 6e 66 69 67 52 63 st_name(configRc
7150: 76 4d 61 73 6b 29 3b 0a 20 20 20 20 20 20 77 68 vMask);. wh
7160: 69 6c 65 28 20 7a 4e 61 6d 65 20 29 7b 0a 20 20 ile( zName ){.
7170: 20 20 20 20 20 20 62 6c 6f 62 5f 61 70 70 65 6e blob_appen
7180: 64 66 28 26 73 65 6e 64 2c 20 22 72 65 71 63 6f df(&send, "reqco
7190: 6e 66 69 67 20 25 73 5c 6e 22 2c 20 7a 4e 61 6d nfig %s\n", zNam
71a0: 65 29 3b 0a 20 20 20 20 20 20 20 20 7a 4e 61 6d e);. zNam
71b0: 65 20 3d 20 63 6f 6e 66 69 67 75 72 65 5f 6e 65 e = configure_ne
71c0: 78 74 5f 6e 61 6d 65 28 63 6f 6e 66 69 67 52 63 xt_name(configRc
71d0: 76 4d 61 73 6b 29 3b 0a 20 20 20 20 20 20 20 20 vMask);.
71e0: 6e 43 61 72 64 2b 2b 3b 0a 20 20 20 20 20 20 7d nCard++;. }
71f0: 0a 20 20 20 20 20 20 69 66 28 20 63 6f 6e 66 69 . if( confi
7200: 67 52 63 76 4d 61 73 6b 20 26 20 28 43 4f 4e 46 gRcvMask & (CONF
7210: 49 47 53 45 54 5f 55 53 45 52 7c 43 4f 4e 46 49 IGSET_USER|CONFI
7220: 47 53 45 54 5f 54 4b 54 29 20 29 7b 0a 20 20 20 GSET_TKT) ){.
7230: 20 20 20 20 20 63 6f 6e 66 69 67 75 72 65 5f 70 configure_p
7240: 72 65 70 61 72 65 5f 74 6f 5f 72 65 63 65 69 76 repare_to_receiv
7250: 65 28 30 29 3b 0a 20 20 20 20 20 20 7d 0a 20 20 e(0);. }.
7260: 20 20 20 20 63 6f 6e 66 69 67 52 63 76 4d 61 73 configRcvMas
7270: 6b 20 3d 20 30 3b 0a 20 20 20 20 7d 0a 0a 20 20 k = 0;. }..
7280: 20 20 2f 2a 20 53 65 6e 64 20 63 6f 6e 66 69 67 /* Send config
7290: 75 72 61 74 69 6f 6e 20 70 61 72 61 6d 65 74 65 uration paramete
72a0: 72 73 20 62 65 69 6e 67 20 70 75 73 68 65 64 20 rs being pushed
72b0: 2a 2f 0a 20 20 20 20 69 66 28 20 63 6f 6e 66 69 */. if( confi
72c0: 67 53 65 6e 64 4d 61 73 6b 20 29 7b 0a 20 20 20 gSendMask ){.
72d0: 20 20 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a const char *z
72e0: 4e 61 6d 65 3b 0a 20 20 20 20 20 20 7a 4e 61 6d Name;. zNam
72f0: 65 20 3d 20 63 6f 6e 66 69 67 75 72 65 5f 66 69 e = configure_fi
7300: 72 73 74 5f 6e 61 6d 65 28 63 6f 6e 66 69 67 53 rst_name(configS
7310: 65 6e 64 4d 61 73 6b 29 3b 0a 20 20 20 20 20 20 endMask);.
7320: 77 68 69 6c 65 28 20 7a 4e 61 6d 65 20 29 7b 0a while( zName ){.
7330: 20 20 20 20 20 20 20 20 73 65 6e 64 5f 63 6f 6e send_con
7340: 66 69 67 5f 63 61 72 64 28 26 78 66 65 72 2c 20 fig_card(&xfer,
7350: 7a 4e 61 6d 65 29 3b 0a 20 20 20 20 20 20 20 20 zName);.
7360: 7a 4e 61 6d 65 20 3d 20 63 6f 6e 66 69 67 75 72 zName = configur
7370: 65 5f 6e 65 78 74 5f 6e 61 6d 65 28 63 6f 6e 66 e_next_name(conf
7380: 69 67 53 65 6e 64 4d 61 73 6b 29 3b 0a 20 20 20 igSendMask);.
7390: 20 20 20 20 20 6e 43 61 72 64 2b 2b 3b 0a 20 20 nCard++;.
73a0: 20 20 20 20 7d 0a 20 20 20 20 20 20 63 6f 6e 66 }. conf
73b0: 69 67 53 65 6e 64 4d 61 73 6b 20 3d 20 30 3b 0a igSendMask = 0;.
73c0: 20 20 20 20 7d 0a 0a 20 20 20 20 2f 2a 20 41 70 }.. /* Ap
73d0: 70 65 6e 64 20 72 61 6e 64 6f 6d 6e 65 73 73 20 pend randomness
73e0: 74 6f 20 74 68 65 20 65 6e 64 20 6f 66 20 74 68 to the end of th
73f0: 65 20 6d 65 73 73 61 67 65 20 2a 2f 0a 20 20 20 e message */.
7400: 20 7a 52 61 6e 64 6f 6d 6e 65 73 73 20 3d 20 64 zRandomness = d
7410: 62 5f 74 65 78 74 28 30 2c 20 22 53 45 4c 45 43 b_text(0, "SELEC
7420: 54 20 68 65 78 28 72 61 6e 64 6f 6d 62 6c 6f 62 T hex(randomblob
7430: 28 32 30 29 29 22 29 3b 0a 20 20 20 20 62 6c 6f (20))");. blo
7440: 62 5f 61 70 70 65 6e 64 66 28 26 73 65 6e 64 2c b_appendf(&send,
7450: 20 22 23 20 25 73 5c 6e 22 2c 20 7a 52 61 6e 64 "# %s\n", zRand
7460: 6f 6d 6e 65 73 73 29 3b 0a 20 20 20 20 66 72 65 omness);. fre
7470: 65 28 7a 52 61 6e 64 6f 6d 6e 65 73 73 29 3b 0a e(zRandomness);.
7480: 0a 20 20 20 20 2f 2a 20 45 78 63 68 61 6e 67 65 . /* Exchange
7490: 20 6d 65 73 73 61 67 65 73 20 77 69 74 68 20 74 messages with t
74a0: 68 65 20 73 65 72 76 65 72 20 2a 2f 0a 20 20 20 he server */.
74b0: 20 6e 46 69 6c 65 53 65 6e 64 20 3d 20 78 66 65 nFileSend = xfe
74c0: 72 2e 6e 46 69 6c 65 53 65 6e 74 20 2b 20 78 66 r.nFileSent + xf
74d0: 65 72 2e 6e 44 65 6c 74 61 53 65 6e 74 3b 0a 20 er.nDeltaSent;.
74e0: 20 20 20 70 72 69 6e 74 66 28 7a 56 61 6c 75 65 printf(zValue
74f0: 46 6f 72 6d 61 74 2c 20 22 53 65 6e 64 3a 22 2c Format, "Send:",
7500: 0a 20 20 20 20 20 20 20 20 20 20 20 20 62 6c 6f . blo
7510: 62 5f 73 69 7a 65 28 26 73 65 6e 64 29 2c 20 6e b_size(&send), n
7520: 43 61 72 64 2b 78 66 65 72 2e 6e 47 69 6d 6d 65 Card+xfer.nGimme
7530: 53 65 6e 74 2b 78 66 65 72 2e 6e 49 47 6f 74 53 Sent+xfer.nIGotS
7540: 65 6e 74 2c 0a 20 20 20 20 20 20 20 20 20 20 20 ent,.
7550: 20 78 66 65 72 2e 6e 46 69 6c 65 53 65 6e 74 2c xfer.nFileSent,
7560: 20 78 66 65 72 2e 6e 44 65 6c 74 61 53 65 6e 74 xfer.nDeltaSent
7570: 29 3b 0a 20 20 20 20 6e 43 61 72 64 20 3d 20 30 );. nCard = 0
7580: 3b 0a 20 20 20 20 78 66 65 72 2e 6e 46 69 6c 65 ;. xfer.nFile
7590: 53 65 6e 74 20 3d 20 30 3b 0a 20 20 20 20 78 66 Sent = 0;. xf
75a0: 65 72 2e 6e 44 65 6c 74 61 53 65 6e 74 20 3d 20 er.nDeltaSent =
75b0: 30 3b 0a 20 20 20 20 78 66 65 72 2e 6e 47 69 6d 0;. xfer.nGim
75c0: 6d 65 53 65 6e 74 20 3d 20 30 3b 0a 20 20 20 20 meSent = 0;.
75d0: 66 66 6c 75 73 68 28 73 74 64 6f 75 74 29 3b 0a fflush(stdout);.
75e0: 20 20 20 20 68 74 74 70 5f 65 78 63 68 61 6e 67 http_exchang
75f0: 65 28 26 73 65 6e 64 2c 20 26 72 65 63 76 29 3b e(&send, &recv);
7600: 0a 20 20 20 20 62 6c 6f 62 5f 72 65 73 65 74 28 . blob_reset(
7610: 26 73 65 6e 64 29 3b 0a 0a 20 20 20 20 2f 2a 20 &send);.. /*
7620: 42 65 67 69 6e 20 63 6f 6e 73 74 72 75 63 74 69 Begin constructi
7630: 6e 67 20 74 68 65 20 6e 65 78 74 20 6d 65 73 73 ng the next mess
7640: 61 67 65 20 28 77 68 69 63 68 20 6d 69 67 68 74 age (which might
7650: 20 6e 65 76 65 72 20 62 65 0a 20 20 20 20 2a 2a never be. **
7660: 20 73 65 6e 74 29 20 62 79 20 62 65 67 69 6e 6e sent) by beginn
7670: 69 6e 67 20 77 69 74 68 20 74 68 65 20 70 75 6c ing with the pul
7680: 6c 20 6f 72 20 70 75 73 68 20 63 61 72 64 73 0a l or push cards.
7690: 20 20 20 20 2a 2f 0a 20 20 20 20 69 66 28 20 70 */. if( p
76a0: 75 6c 6c 46 6c 61 67 20 29 7b 0a 20 20 20 20 20 ullFlag ){.
76b0: 20 62 6c 6f 62 5f 61 70 70 65 6e 64 66 28 26 73 blob_appendf(&s
76c0: 65 6e 64 2c 20 22 70 75 6c 6c 20 25 73 20 25 73 end, "pull %s %s
76d0: 5c 6e 22 2c 20 7a 53 43 6f 64 65 2c 20 7a 50 43 \n", zSCode, zPC
76e0: 6f 64 65 29 3b 0a 20 20 20 20 20 20 6e 43 61 72 ode);. nCar
76f0: 64 2b 2b 3b 0a 20 20 20 20 7d 0a 20 20 20 20 69 d++;. }. i
7700: 66 28 20 70 75 73 68 46 6c 61 67 20 29 7b 0a 20 f( pushFlag ){.
7710: 20 20 20 20 20 62 6c 6f 62 5f 61 70 70 65 6e 64 blob_append
7720: 66 28 26 73 65 6e 64 2c 20 22 70 75 73 68 20 25 f(&send, "push %
7730: 73 20 25 73 5c 6e 22 2c 20 7a 53 43 6f 64 65 2c s %s\n", zSCode,
7740: 20 7a 50 43 6f 64 65 29 3b 0a 20 20 20 20 20 20 zPCode);.
7750: 6e 43 61 72 64 2b 2b 3b 0a 20 20 20 20 7d 0a 0a nCard++;. }..
7760: 20 20 20 20 2f 2a 20 50 72 6f 63 65 73 73 20 74 /* Process t
7770: 68 65 20 72 65 70 6c 79 20 74 68 61 74 20 63 61 he reply that ca
7780: 6d 65 20 62 61 63 6b 20 66 72 6f 6d 20 74 68 65 me back from the
7790: 20 73 65 72 76 65 72 20 2a 2f 0a 20 20 20 20 77 server */. w
77a0: 68 69 6c 65 28 20 62 6c 6f 62 5f 6c 69 6e 65 28 hile( blob_line(
77b0: 26 72 65 63 76 2c 20 26 78 66 65 72 2e 6c 69 6e &recv, &xfer.lin
77c0: 65 29 20 29 7b 0a 20 20 20 20 20 20 69 66 28 20 e) ){. if(
77d0: 62 6c 6f 62 5f 62 75 66 66 65 72 28 26 78 66 65 blob_buffer(&xfe
77e0: 72 2e 6c 69 6e 65 29 5b 30 5d 3d 3d 27 23 27 20 r.line)[0]=='#'
77f0: 29 7b 0a 20 20 20 20 20 20 20 20 63 6f 6e 74 69 ){. conti
7800: 6e 75 65 3b 0a 20 20 20 20 20 20 7d 0a 20 20 20 nue;. }.
7810: 20 20 20 78 66 65 72 2e 6e 54 6f 6b 65 6e 20 3d xfer.nToken =
7820: 20 62 6c 6f 62 5f 74 6f 6b 65 6e 69 7a 65 28 26 blob_tokenize(&
7830: 78 66 65 72 2e 6c 69 6e 65 2c 20 78 66 65 72 2e xfer.line, xfer.
7840: 61 54 6f 6b 65 6e 2c 20 63 6f 75 6e 74 28 78 66 aToken, count(xf
7850: 65 72 2e 61 54 6f 6b 65 6e 29 29 3b 0a 20 20 20 er.aToken));.
7860: 20 20 20 6e 43 61 72 64 2b 2b 3b 0a 20 20 20 20 nCard++;.
7870: 20 20 70 72 69 6e 74 66 28 22 5c 72 25 64 22 2c printf("\r%d",
7880: 20 6e 43 61 72 64 29 3b 0a 20 20 20 20 20 20 66 nCard);. f
7890: 66 6c 75 73 68 28 73 74 64 6f 75 74 29 3b 0a 0a flush(stdout);..
78a0: 20 20 20 20 20 20 2f 2a 20 20 20 66 69 6c 65 20 /* file
78b0: 55 55 49 44 20 53 49 5a 45 20 5c 6e 20 43 4f 4e UUID SIZE \n CON
78c0: 54 45 4e 54 0a 20 20 20 20 20 20 2a 2a 20 20 20 TENT. **
78d0: 66 69 6c 65 20 55 55 49 44 20 44 45 4c 54 41 53 file UUID DELTAS
78e0: 52 43 20 53 49 5a 45 20 5c 6e 20 43 4f 4e 54 45 RC SIZE \n CONTE
78f0: 4e 54 0a 20 20 20 20 20 20 2a 2a 0a 20 20 20 20 NT. **.
7900: 20 20 2a 2a 20 52 65 63 65 69 76 65 20 61 20 66 ** Receive a f
7910: 69 6c 65 20 74 72 61 6e 73 6d 69 74 74 65 64 20 ile transmitted
7920: 66 72 6f 6d 20 74 68 65 20 73 65 72 76 65 72 2e from the server.
7930: 0a 20 20 20 20 20 20 2a 2f 0a 20 20 20 20 20 20 . */.
7940: 69 66 28 20 62 6c 6f 62 5f 65 71 28 26 78 66 65 if( blob_eq(&xfe
7950: 72 2e 61 54 6f 6b 65 6e 5b 30 5d 2c 22 66 69 6c r.aToken[0],"fil
7960: 65 22 29 20 29 7b 0a 20 20 20 20 20 20 20 20 78 e") ){. x
7970: 66 65 72 5f 61 63 63 65 70 74 5f 66 69 6c 65 28 fer_accept_file(
7980: 26 78 66 65 72 29 3b 0a 20 20 20 20 20 20 7d 65 &xfer);. }e
7990: 6c 73 65 0a 0a 20 20 20 20 20 20 2f 2a 20 20 20 lse.. /*
79a0: 67 69 6d 6d 65 20 55 55 49 44 0a 20 20 20 20 20 gimme UUID.
79b0: 20 2a 2a 0a 20 20 20 20 20 20 2a 2a 20 53 65 72 **. ** Ser
79c0: 76 65 72 20 69 73 20 72 65 71 75 65 73 74 69 6e ver is requestin
79d0: 67 20 61 20 66 69 6c 65 2e 20 20 49 66 20 74 68 g a file. If th
79e0: 65 20 66 69 6c 65 20 69 73 20 61 20 6d 61 6e 69 e file is a mani
79f0: 66 65 73 74 2c 20 61 73 73 75 6d 65 0a 20 20 20 fest, assume.
7a00: 20 20 20 2a 2a 20 74 68 61 74 20 74 68 65 20 73 ** that the s
7a10: 65 72 76 65 72 20 77 69 6c 6c 20 61 6c 73 6f 20 erver will also
7a20: 77 61 6e 74 20 74 6f 20 6b 6e 6f 77 20 61 6c 6c want to know all
7a30: 20 6f 66 20 74 68 65 20 63 6f 6e 74 65 6e 74 20 of the content
7a40: 66 69 6c 65 73 0a 20 20 20 20 20 20 2a 2a 20 61 files. ** a
7a50: 73 73 6f 63 69 61 74 65 64 20 77 69 74 68 20 74 ssociated with t
7a60: 68 65 20 6d 61 6e 69 66 65 73 74 20 61 6e 64 20 he manifest and
7a70: 73 65 6e 64 20 74 68 6f 73 65 20 74 6f 6f 2e 0a send those too..
7a80: 20 20 20 20 20 20 2a 2f 0a 20 20 20 20 20 20 69 */. i
7a90: 66 28 20 62 6c 6f 62 5f 65 71 28 26 78 66 65 72 f( blob_eq(&xfer
7aa0: 2e 61 54 6f 6b 65 6e 5b 30 5d 2c 20 22 67 69 6d .aToken[0], "gim
7ab0: 6d 65 22 29 0a 20 20 20 20 20 20 20 26 26 20 78 me"). && x
7ac0: 66 65 72 2e 6e 54 6f 6b 65 6e 3d 3d 32 0a 20 20 fer.nToken==2.
7ad0: 20 20 20 20 20 26 26 20 62 6c 6f 62 5f 69 73 5f && blob_is_
7ae0: 75 75 69 64 28 26 78 66 65 72 2e 61 54 6f 6b 65 uuid(&xfer.aToke
7af0: 6e 5b 31 5d 29 0a 20 20 20 20 20 20 29 7b 0a 20 n[1]). ){.
7b00: 20 20 20 20 20 20 20 69 66 28 20 70 75 73 68 46 if( pushF
7b10: 6c 61 67 20 29 7b 0a 20 20 20 20 20 20 20 20 20 lag ){.
7b20: 20 69 6e 74 20 72 69 64 20 3d 20 72 69 64 5f 66 int rid = rid_f
7b30: 72 6f 6d 5f 75 75 69 64 28 26 78 66 65 72 2e 61 rom_uuid(&xfer.a
7b40: 54 6f 6b 65 6e 5b 31 5d 2c 20 30 29 3b 0a 20 20 Token[1], 0);.
7b50: 20 20 20 20 20 20 20 20 69 66 28 20 72 69 64 20 if( rid
7b60: 29 20 73 65 6e 64 5f 66 69 6c 65 28 26 78 66 65 ) send_file(&xfe
7b70: 72 2c 20 72 69 64 2c 20 26 78 66 65 72 2e 61 54 r, rid, &xfer.aT
7b80: 6f 6b 65 6e 5b 31 5d 2c 20 30 29 3b 0a 20 20 20 oken[1], 0);.
7b90: 20 20 20 20 20 7d 0a 20 20 20 20 20 20 7d 65 6c }. }el
7ba0: 73 65 0a 20 20 0a 20 20 20 20 20 20 2f 2a 20 20 se. . /*
7bb0: 20 69 67 6f 74 20 55 55 49 44 0a 20 20 20 20 20 igot UUID.
7bc0: 20 2a 2a 0a 20 20 20 20 20 20 2a 2a 20 53 65 72 **. ** Ser
7bd0: 76 65 72 20 61 6e 6e 6f 75 6e 63 65 73 20 74 68 ver announces th
7be0: 61 74 20 69 74 20 68 61 73 20 61 20 70 61 72 74 at it has a part
7bf0: 69 63 75 6c 61 72 20 66 69 6c 65 2e 20 20 49 66 icular file. If
7c00: 20 74 68 69 73 20 69 73 0a 20 20 20 20 20 20 2a this is. *
7c10: 2a 20 6e 6f 74 20 61 20 66 69 6c 65 20 74 68 61 * not a file tha
7c20: 74 20 77 65 20 68 61 76 65 20 61 6e 64 20 77 65 t we have and we
7c30: 20 61 72 65 20 70 75 6c 6c 69 6e 67 2c 20 74 68 are pulling, th
7c40: 65 6e 20 63 72 65 61 74 65 20 61 0a 20 20 20 20 en create a.
7c50: 20 20 2a 2a 20 70 68 61 6e 74 6f 6d 20 74 6f 20 ** phantom to
7c60: 63 61 75 73 65 20 74 68 69 73 20 66 69 6c 65 20 cause this file
7c70: 74 6f 20 62 65 20 72 65 71 75 65 73 74 65 64 20 to be requested
7c80: 6f 6e 20 74 68 65 20 6e 65 78 74 20 63 79 63 6c on the next cycl
7c90: 65 2e 0a 20 20 20 20 20 20 2a 2a 20 41 6c 77 61 e.. ** Alwa
7ca0: 79 73 20 72 65 6d 65 6d 62 65 72 20 74 68 61 74 ys remember that
7cb0: 20 74 68 65 20 73 65 72 76 65 72 20 68 61 73 20 the server has
7cc0: 74 68 69 73 20 66 69 6c 65 20 73 6f 20 74 68 61 this file so tha
7cd0: 74 20 77 65 20 64 6f 0a 20 20 20 20 20 20 2a 2a t we do. **
7ce0: 20 6e 6f 74 20 74 72 61 6e 73 6d 69 74 20 69 74 not transmit it
7cf0: 20 62 79 20 61 63 63 69 64 65 6e 74 2e 0a 20 20 by accident..
7d00: 20 20 20 20 2a 2f 0a 20 20 20 20 20 20 69 66 28 */. if(
7d10: 20 78 66 65 72 2e 6e 54 6f 6b 65 6e 3d 3d 32 0a xfer.nToken==2.
7d20: 20 20 20 20 20 20 20 26 26 20 62 6c 6f 62 5f 65 && blob_e
7d30: 71 28 26 78 66 65 72 2e 61 54 6f 6b 65 6e 5b 30 q(&xfer.aToken[0
7d40: 5d 2c 20 22 69 67 6f 74 22 29 0a 20 20 20 20 20 ], "igot").
7d50: 20 20 26 26 20 62 6c 6f 62 5f 69 73 5f 75 75 69 && blob_is_uui
7d60: 64 28 26 78 66 65 72 2e 61 54 6f 6b 65 6e 5b 31 d(&xfer.aToken[1
7d70: 5d 29 0a 20 20 20 20 20 20 29 7b 0a 20 20 20 20 ]). ){.
7d80: 20 20 20 20 69 6e 74 20 72 69 64 20 3d 20 72 69 int rid = ri
7d90: 64 5f 66 72 6f 6d 5f 75 75 69 64 28 26 78 66 65 d_from_uuid(&xfe
7da0: 72 2e 61 54 6f 6b 65 6e 5b 31 5d 2c 20 30 29 3b r.aToken[1], 0);
7db0: 0a 20 20 20 20 20 20 20 20 69 66 28 20 72 69 64 . if( rid
7dc0: 3e 30 20 29 7b 0a 20 20 20 20 20 20 20 20 20 20 >0 ){.
7dd0: 63 6f 6e 74 65 6e 74 5f 6d 61 6b 65 5f 70 75 62 content_make_pub
7de0: 6c 69 63 28 72 69 64 29 3b 0a 20 20 20 20 20 20 lic(rid);.
7df0: 20 20 7d 65 6c 73 65 20 69 66 28 20 70 75 6c 6c }else if( pull
7e00: 46 6c 61 67 20 7c 7c 20 63 6c 6f 6e 65 46 6c 61 Flag || cloneFla
7e10: 67 20 29 7b 0a 20 20 20 20 20 20 20 20 20 20 72 g ){. r
7e20: 69 64 20 3d 20 63 6f 6e 74 65 6e 74 5f 6e 65 77 id = content_new
7e30: 28 62 6c 6f 62 5f 73 74 72 28 26 78 66 65 72 2e (blob_str(&xfer.
7e40: 61 54 6f 6b 65 6e 5b 31 5d 29 29 3b 0a 20 20 20 aToken[1]));.
7e50: 20 20 20 20 20 20 20 69 66 28 20 72 69 64 20 29 if( rid )
7e60: 20 6e 65 77 50 68 61 6e 74 6f 6d 20 3d 20 31 3b newPhantom = 1;
7e70: 0a 20 20 20 20 20 20 20 20 7d 0a 20 20 20 20 20 . }.
7e80: 20 20 20 72 65 6d 6f 74 65 5f 68 61 73 28 72 69 remote_has(ri
7e90: 64 29 3b 0a 20 20 20 20 20 20 7d 65 6c 73 65 0a d);. }else.
7ea0: 20 20 20 20 0a 20 20 20 20 20 20 0a 20 20 20 20 . .
7eb0: 20 20 2f 2a 20 20 20 70 75 73 68 20 20 53 45 52 /* push SER
7ec0: 56 45 52 43 4f 44 45 20 20 50 52 4f 44 55 43 54 VERCODE PRODUCT
7ed0: 43 4f 44 45 0a 20 20 20 20 20 20 2a 2a 0a 20 20 CODE. **.
7ee0: 20 20 20 20 2a 2a 20 53 68 6f 75 6c 64 20 6f 6e ** Should on
7ef0: 6c 79 20 68 61 70 70 65 6e 20 69 6e 20 72 65 73 ly happen in res
7f00: 70 6f 6e 73 65 20 74 6f 20 61 20 63 6c 6f 6e 65 ponse to a clone
7f10: 2e 20 20 54 68 69 73 20 6d 65 73 73 61 67 65 20 . This message
7f20: 74 65 6c 6c 73 0a 20 20 20 20 20 20 2a 2a 20 74 tells. ** t
7f30: 68 65 20 63 6c 69 65 6e 74 20 77 68 61 74 20 70 he client what p
7f40: 72 6f 64 75 63 74 20 74 6f 20 75 73 65 20 66 6f roduct to use fo
7f50: 72 20 74 68 65 20 6e 65 77 20 64 61 74 61 62 61 r the new databa
7f60: 73 65 2e 0a 20 20 20 20 20 20 2a 2f 0a 20 20 20 se.. */.
7f70: 20 20 20 69 66 28 20 62 6c 6f 62 5f 65 71 28 26 if( blob_eq(&
7f80: 78 66 65 72 2e 61 54 6f 6b 65 6e 5b 30 5d 2c 22 xfer.aToken[0],"
7f90: 70 75 73 68 22 29 0a 20 20 20 20 20 20 20 26 26 push"). &&
7fa0: 20 78 66 65 72 2e 6e 54 6f 6b 65 6e 3d 3d 33 0a xfer.nToken==3.
7fb0: 20 20 20 20 20 20 20 26 26 20 63 6c 6f 6e 65 46 && cloneF
7fc0: 6c 61 67 0a 20 20 20 20 20 20 20 26 26 20 62 6c lag. && bl
7fd0: 6f 62 5f 69 73 5f 75 75 69 64 28 26 78 66 65 72 ob_is_uuid(&xfer
7fe0: 2e 61 54 6f 6b 65 6e 5b 31 5d 29 0a 20 20 20 20 .aToken[1]).
7ff0: 20 20 20 26 26 20 62 6c 6f 62 5f 69 73 5f 75 75 && blob_is_uu
8000: 69 64 28 26 78 66 65 72 2e 61 54 6f 6b 65 6e 5b id(&xfer.aToken[
8010: 32 5d 29 0a 20 20 20 20 20 20 29 7b 0a 20 20 20 2]). ){.
8020: 20 20 20 20 20 69 66 28 20 62 6c 6f 62 5f 65 71 if( blob_eq
8030: 5f 73 74 72 28 26 78 66 65 72 2e 61 54 6f 6b 65 _str(&xfer.aToke
8040: 6e 5b 31 5d 2c 20 7a 53 43 6f 64 65 2c 20 2d 31 n[1], zSCode, -1
8050: 29 20 29 7b 0a 20 20 20 20 20 20 20 20 20 20 66 ) ){. f
8060: 6f 73 73 69 6c 5f 66 61 74 61 6c 28 22 73 65 72 ossil_fatal("ser
8070: 76 65 72 20 6c 6f 6f 70 22 29 3b 0a 20 20 20 20 ver loop");.
8080: 20 20 20 20 7d 0a 20 20 20 20 20 20 20 20 69 66 }. if
8090: 28 20 7a 50 43 6f 64 65 3d 3d 30 20 29 7b 0a 20 ( zPCode==0 ){.
80a0: 20 20 20 20 20 20 20 20 20 7a 50 43 6f 64 65 20 zPCode
80b0: 3d 20 6d 70 72 69 6e 74 66 28 22 25 62 22 2c 20 = mprintf("%b",
80c0: 26 78 66 65 72 2e 61 54 6f 6b 65 6e 5b 32 5d 29 &xfer.aToken[2])
80d0: 3b 0a 20 20 20 20 20 20 20 20 20 20 64 62 5f 73 ;. db_s
80e0: 65 74 28 22 70 72 6f 6a 65 63 74 2d 63 6f 64 65 et("project-code
80f0: 22 2c 20 7a 50 43 6f 64 65 2c 20 30 29 3b 0a 20 ", zPCode, 0);.
8100: 20 20 20 20 20 20 20 7d 0a 20 20 20 20 20 20 20 }.
8110: 20 62 6c 6f 62 5f 61 70 70 65 6e 64 66 28 26 73 blob_appendf(&s
8120: 65 6e 64 2c 20 22 63 6c 6f 6e 65 5c 6e 22 29 3b end, "clone\n");
8130: 0a 20 20 20 20 20 20 20 20 6e 43 61 72 64 2b 2b . nCard++
8140: 3b 0a 20 20 20 20 20 20 7d 65 6c 73 65 0a 20 20 ;. }else.
8150: 20 20 20 20 0a 20 20 20 20 20 20 2f 2a 20 20 20 . /*
8160: 63 6f 6e 66 69 67 20 4e 41 4d 45 20 53 49 5a 45 config NAME SIZE
8170: 20 5c 6e 20 43 4f 4e 54 45 4e 54 0a 20 20 20 20 \n CONTENT.
8180: 20 20 2a 2a 0a 20 20 20 20 20 20 2a 2a 20 52 65 **. ** Re
8190: 63 65 69 76 65 20 61 20 63 6f 6e 66 69 67 75 72 ceive a configur
81a0: 61 74 69 6f 6e 20 76 61 6c 75 65 20 66 72 6f 6d ation value from
81b0: 20 74 68 65 20 73 65 72 76 65 72 2e 0a 20 20 20 the server..
81c0: 20 20 20 2a 2f 0a 20 20 20 20 20 20 69 66 28 20 */. if(
81d0: 62 6c 6f 62 5f 65 71 28 26 78 66 65 72 2e 61 54 blob_eq(&xfer.aT
81e0: 6f 6b 65 6e 5b 30 5d 2c 22 63 6f 6e 66 69 67 22 oken[0],"config"
81f0: 29 20 26 26 20 78 66 65 72 2e 6e 54 6f 6b 65 6e ) && xfer.nToken
8200: 3d 3d 33 0a 20 20 20 20 20 20 20 20 20 20 26 26 ==3. &&
8210: 20 62 6c 6f 62 5f 69 73 5f 69 6e 74 28 26 78 66 blob_is_int(&xf
8220: 65 72 2e 61 54 6f 6b 65 6e 5b 32 5d 2c 20 26 73 er.aToken[2], &s
8230: 69 7a 65 29 20 29 7b 0a 20 20 20 20 20 20 20 20 ize) ){.
8240: 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a 4e 61 6d const char *zNam
8250: 65 20 3d 20 62 6c 6f 62 5f 73 74 72 28 26 78 66 e = blob_str(&xf
8260: 65 72 2e 61 54 6f 6b 65 6e 5b 31 5d 29 3b 0a 20 er.aToken[1]);.
8270: 20 20 20 20 20 20 20 42 6c 6f 62 20 63 6f 6e 74 Blob cont
8280: 65 6e 74 3b 0a 20 20 20 20 20 20 20 20 62 6c 6f ent;. blo
8290: 62 5f 7a 65 72 6f 28 26 63 6f 6e 74 65 6e 74 29 b_zero(&content)
82a0: 3b 0a 20 20 20 20 20 20 20 20 62 6c 6f 62 5f 65 ;. blob_e
82b0: 78 74 72 61 63 74 28 78 66 65 72 2e 70 49 6e 2c xtract(xfer.pIn,
82c0: 20 73 69 7a 65 2c 20 26 63 6f 6e 74 65 6e 74 29 size, &content)
82d0: 3b 0a 20 20 20 20 20 20 20 20 67 2e 6f 6b 41 64 ;. g.okAd
82e0: 6d 69 6e 20 3d 20 67 2e 6f 6b 52 64 41 64 64 72 min = g.okRdAddr
82f0: 20 3d 20 31 3b 0a 20 20 20 20 20 20 20 20 69 66 = 1;. if
8300: 28 20 63 6f 6e 66 69 67 75 72 65 5f 69 73 5f 65 ( configure_is_e
8310: 78 70 6f 72 74 61 62 6c 65 28 7a 4e 61 6d 65 29 xportable(zName)
8320: 20 26 20 6f 72 69 67 43 6f 6e 66 69 67 52 63 76 & origConfigRcv
8330: 4d 61 73 6b 20 29 7b 0a 20 20 20 20 20 20 20 20 Mask ){.
8340: 20 20 69 66 28 20 7a 4e 61 6d 65 5b 30 5d 21 3d if( zName[0]!=
8350: 27 40 27 20 29 7b 0a 20 20 20 20 20 20 20 20 20 '@' ){.
8360: 20 20 20 64 62 5f 6d 75 6c 74 69 5f 65 78 65 63 db_multi_exec
8370: 28 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 (.
8380: 20 20 22 52 45 50 4c 41 43 45 20 49 4e 54 4f 20 "REPLACE INTO
8390: 63 6f 6e 66 69 67 28 6e 61 6d 65 2c 76 61 6c 75 config(name,valu
83a0: 65 29 20 56 41 4c 55 45 53 28 25 51 2c 25 51 29 e) VALUES(%Q,%Q)
83b0: 22 2c 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 ",.
83c0: 20 20 20 7a 4e 61 6d 65 2c 20 62 6c 6f 62 5f 73 zName, blob_s
83d0: 74 72 28 26 63 6f 6e 74 65 6e 74 29 0a 20 20 20 tr(&content).
83e0: 20 20 20 20 20 20 20 20 20 29 3b 0a 20 20 20 20 );.
83f0: 20 20 20 20 20 20 7d 65 6c 73 65 7b 0a 20 20 20 }else{.
8400: 20 20 20 20 20 20 20 20 20 2f 2a 20 4e 6f 74 69 /* Noti
8410: 63 65 20 74 68 61 74 20 77 65 20 61 72 65 20 65 ce that we are e
8420: 76 61 6c 75 61 74 69 6e 67 20 61 72 62 69 74 72 valuating arbitr
8430: 61 72 79 20 53 51 4c 20 72 65 63 65 69 76 65 64 ary SQL received
8440: 20 66 72 6f 6d 20 74 68 65 0a 20 20 20 20 20 20 from the.
8450: 20 20 20 20 20 20 2a 2a 20 73 65 72 76 65 72 2e ** server.
8460: 20 20 42 75 74 20 74 68 69 73 20 63 61 6e 20 6f But this can o
8470: 6e 6c 79 20 68 61 70 70 65 6e 20 69 66 20 77 65 nly happen if we
8480: 20 68 61 76 65 20 73 70 65 63 69 66 69 63 61 6c have specifical
8490: 6c 79 0a 20 20 20 20 20 20 20 20 20 20 20 20 2a ly. *
84a0: 2a 20 72 65 71 75 65 73 74 65 64 20 63 6f 6e 66 * requested conf
84b0: 69 67 75 72 61 74 69 6f 6e 20 69 6e 66 6f 72 6d iguration inform
84c0: 61 74 69 6f 6e 20 66 72 6f 6d 20 74 68 65 20 73 ation from the s
84d0: 65 72 76 65 72 2c 20 73 6f 0a 20 20 20 20 20 20 erver, so.
84e0: 20 20 20 20 20 20 2a 2a 20 70 72 65 73 75 6d 61 ** presuma
84f0: 62 6c 79 20 74 68 65 20 6f 70 65 72 61 74 6f 72 bly the operator
8500: 20 74 72 75 73 74 73 20 74 68 65 20 73 65 72 76 trusts the serv
8510: 65 72 2e 0a 20 20 20 20 20 20 20 20 20 20 20 20 er..
8520: 2a 2f 0a 20 20 20 20 20 20 20 20 20 20 20 20 64 */. d
8530: 62 5f 6d 75 6c 74 69 5f 65 78 65 63 28 22 25 73 b_multi_exec("%s
8540: 22 2c 20 62 6c 6f 62 5f 73 74 72 28 26 63 6f 6e ", blob_str(&con
8550: 74 65 6e 74 29 29 3b 0a 20 20 20 20 20 20 20 20 tent));.
8560: 20 20 7d 0a 20 20 20 20 20 20 20 20 7d 0a 20 20 }. }.
8570: 20 20 20 20 20 20 6e 43 61 72 64 2b 2b 3b 0a 20 nCard++;.
8580: 20 20 20 20 20 20 20 62 6c 6f 62 5f 72 65 73 65 blob_rese
8590: 74 28 26 63 6f 6e 74 65 6e 74 29 3b 0a 20 20 20 t(&content);.
85a0: 20 20 20 20 20 62 6c 6f 62 5f 73 65 65 6b 28 78 blob_seek(x
85b0: 66 65 72 2e 70 49 6e 2c 20 31 2c 20 42 4c 4f 42 fer.pIn, 1, BLOB
85c0: 5f 53 45 45 4b 5f 43 55 52 29 3b 0a 20 20 20 20 _SEEK_CUR);.
85d0: 20 20 7d 65 6c 73 65 0a 0a 20 20 20 20 20 20 0a }else.. .
85e0: 20 20 20 20 20 20 2f 2a 20 20 20 20 63 6f 6f 6b /* cook
85f0: 69 65 20 54 45 58 54 0a 20 20 20 20 20 20 2a 2a ie TEXT. **
8600: 0a 20 20 20 20 20 20 2a 2a 20 54 68 65 20 73 65 . ** The se
8610: 72 76 65 72 20 6d 69 67 68 74 20 69 6e 63 6c 75 rver might inclu
8620: 64 65 20 61 20 63 6f 6f 6b 69 65 20 69 6e 20 69 de a cookie in i
8630: 74 73 20 72 65 70 6c 79 2e 20 20 54 68 65 20 63 ts reply. The c
8640: 6c 69 65 6e 74 0a 20 20 20 20 20 20 2a 2a 20 73 lient. ** s
8650: 68 6f 75 6c 64 20 72 65 6d 65 6d 62 65 72 20 74 hould remember t
8660: 68 69 73 20 63 6f 6f 6b 69 65 20 61 6e 64 20 73 his cookie and s
8670: 65 6e 64 20 69 74 20 62 61 63 6b 20 74 6f 20 74 end it back to t
8680: 68 65 20 73 65 72 76 65 72 0a 20 20 20 20 20 20 he server.
8690: 2a 2a 20 69 6e 20 69 74 73 20 6e 65 78 74 20 71 ** in its next q
86a0: 75 65 72 79 2e 0a 20 20 20 20 20 20 2a 2a 0a 20 uery.. **.
86b0: 20 20 20 20 20 2a 2a 20 45 61 63 68 20 63 6f 6f ** Each coo
86c0: 6b 69 65 20 72 65 63 65 69 76 65 64 20 6f 76 65 kie received ove
86d0: 72 77 72 69 74 65 73 20 74 68 65 20 70 72 69 6f rwrites the prio
86e0: 72 20 63 6f 6f 6b 69 65 20 66 72 6f 6d 20 74 68 r cookie from th
86f0: 65 0a 20 20 20 20 20 20 2a 2a 20 73 61 6d 65 20 e. ** same
8700: 73 65 72 76 65 72 2e 0a 20 20 20 20 20 20 2a 2f server.. */
8710: 0a 20 20 20 20 20 20 69 66 28 20 62 6c 6f 62 5f . if( blob_
8720: 65 71 28 26 78 66 65 72 2e 61 54 6f 6b 65 6e 5b eq(&xfer.aToken[
8730: 30 5d 2c 20 22 63 6f 6f 6b 69 65 22 29 20 26 26 0], "cookie") &&
8740: 20 78 66 65 72 2e 6e 54 6f 6b 65 6e 3d 3d 32 20 xfer.nToken==2
8750: 29 7b 0a 20 20 20 20 20 20 20 20 64 62 5f 73 65 ){. db_se
8760: 74 28 22 63 6f 6f 6b 69 65 22 2c 20 62 6c 6f 62 t("cookie", blob
8770: 5f 73 74 72 28 26 78 66 65 72 2e 61 54 6f 6b 65 _str(&xfer.aToke
8780: 6e 5b 31 5d 29 2c 20 30 29 3b 0a 20 20 20 20 20 n[1]), 0);.
8790: 20 7d 65 6c 73 65 0a 0a 20 20 20 20 20 20 2f 2a }else.. /*
87a0: 20 20 20 6d 65 73 73 61 67 65 20 4d 45 53 53 41 message MESSA
87b0: 47 45 0a 20 20 20 20 20 20 2a 2a 0a 20 20 20 20 GE. **.
87c0: 20 20 2a 2a 20 50 72 69 6e 74 20 61 20 6d 65 73 ** Print a mes
87d0: 73 61 67 65 2e 20 20 53 69 6d 69 6c 61 72 20 74 sage. Similar t
87e0: 6f 20 22 65 72 72 6f 72 22 20 62 75 74 20 64 6f o "error" but do
87f0: 65 73 20 6e 6f 74 20 73 74 6f 70 20 70 72 6f 63 es not stop proc
8800: 65 73 73 69 6e 67 0a 20 20 20 20 20 20 2a 2f 20 essing. */
8810: 20 20 20 20 20 20 20 0a 20 20 20 20 20 20 69 66 . if
8820: 28 20 62 6c 6f 62 5f 65 71 28 26 78 66 65 72 2e ( blob_eq(&xfer.
8830: 61 54 6f 6b 65 6e 5b 30 5d 2c 22 6d 65 73 73 61 aToken[0],"messa
8840: 67 65 22 29 20 26 26 20 78 66 65 72 2e 6e 54 6f ge") && xfer.nTo
8850: 6b 65 6e 3d 3d 32 20 29 7b 0a 20 20 20 20 20 20 ken==2 ){.
8860: 20 20 63 68 61 72 20 2a 7a 4d 73 67 20 3d 20 62 char *zMsg = b
8870: 6c 6f 62 5f 74 65 72 6d 69 6e 61 74 65 28 26 78 lob_terminate(&x
8880: 66 65 72 2e 61 54 6f 6b 65 6e 5b 31 5d 29 3b 0a fer.aToken[1]);.
8890: 20 20 20 20 20 20 20 20 64 65 66 6f 73 73 69 6c defossil
88a0: 69 7a 65 28 7a 4d 73 67 29 3b 0a 20 20 20 20 20 ize(zMsg);.
88b0: 20 20 20 70 72 69 6e 74 66 28 22 53 65 72 76 65 printf("Serve
88c0: 72 20 73 61 79 73 3a 20 25 73 5c 6e 22 2c 20 7a r says: %s\n", z
88d0: 4d 73 67 29 3b 0a 20 20 20 20 20 20 7d 65 6c 73 Msg);. }els
88e0: 65 0a 0a 20 20 20 20 20 20 2f 2a 20 20 20 65 72 e.. /* er
88f0: 72 6f 72 20 4d 45 53 53 41 47 45 0a 20 20 20 20 ror MESSAGE.
8900: 20 20 2a 2a 0a 20 20 20 20 20 20 2a 2a 20 52 65 **. ** Re
8910: 70 6f 72 74 20 61 6e 20 65 72 72 6f 72 20 61 6e port an error an
8920: 64 20 61 62 61 6e 64 6f 6e 20 74 68 65 20 73 79 d abandon the sy
8930: 6e 63 20 73 65 73 73 69 6f 6e 0a 20 20 20 20 20 nc session.
8940: 20 2a 2f 20 20 20 20 20 20 20 20 0a 20 20 20 20 */ .
8950: 20 20 69 66 28 20 62 6c 6f 62 5f 65 71 28 26 78 if( blob_eq(&x
8960: 66 65 72 2e 61 54 6f 6b 65 6e 5b 30 5d 2c 22 65 fer.aToken[0],"e
8970: 72 72 6f 72 22 29 20 26 26 20 78 66 65 72 2e 6e rror") && xfer.n
8980: 54 6f 6b 65 6e 3d 3d 32 20 29 7b 0a 20 20 20 20 Token==2 ){.
8990: 20 20 20 20 63 68 61 72 20 2a 7a 4d 73 67 20 3d char *zMsg =
89a0: 20 62 6c 6f 62 5f 74 65 72 6d 69 6e 61 74 65 28 blob_terminate(
89b0: 26 78 66 65 72 2e 61 54 6f 6b 65 6e 5b 31 5d 29 &xfer.aToken[1])
89c0: 3b 0a 20 20 20 20 20 20 20 20 64 65 66 6f 73 73 ;. defoss
89d0: 69 6c 69 7a 65 28 7a 4d 73 67 29 3b 0a 20 20 20 ilize(zMsg);.
89e0: 20 20 20 20 20 62 6c 6f 62 5f 61 70 70 65 6e 64 blob_append
89f0: 66 28 26 78 66 65 72 2e 65 72 72 2c 20 22 73 65 f(&xfer.err, "se
8a00: 72 76 65 72 20 73 61 79 73 3a 20 25 73 22 2c 20 rver says: %s",
8a10: 7a 4d 73 67 29 3b 0a 20 20 20 20 20 20 7d 65 6c zMsg);. }el
8a20: 73 65 0a 0a 20 20 20 20 20 20 2f 2a 20 55 6e 6b se.. /* Unk
8a30: 6e 6f 77 6e 20 6d 65 73 73 61 67 65 20 2a 2f 0a nown message */.
8a40: 20 20 20 20 20 20 7b 0a 20 20 20 20 20 20 20 20 {.
8a50: 69 66 28 20 62 6c 6f 62 5f 73 74 72 28 26 78 66 if( blob_str(&xf
8a60: 65 72 2e 61 54 6f 6b 65 6e 5b 30 5d 29 5b 30 5d er.aToken[0])[0]
8a70: 3d 3d 27 3c 27 20 29 7b 0a 20 20 20 20 20 20 20 =='<' ){.
8a80: 20 20 20 66 6f 73 73 69 6c 5f 66 61 74 61 6c 28 fossil_fatal(
8a90: 0a 20 20 20 20 20 20 20 20 20 20 20 20 22 73 65 . "se
8aa0: 72 76 65 72 20 72 65 70 6c 69 65 73 20 77 69 74 rver replies wit
8ab0: 68 20 48 54 4d 4c 20 69 6e 73 74 65 61 64 20 6f h HTML instead o
8ac0: 66 20 66 6f 73 73 69 6c 20 73 79 6e 63 20 70 72 f fossil sync pr
8ad0: 6f 74 6f 63 6f 6c 3a 5c 6e 25 62 22 2c 0a 20 20 otocol:\n%b",.
8ae0: 20 20 20 20 20 20 20 20 20 20 26 72 65 63 76 0a &recv.
8af0: 20 20 20 20 20 20 20 20 20 20 29 3b 0a 20 20 20 );.
8b00: 20 20 20 20 20 7d 0a 20 20 20 20 20 20 20 20 62 }. b
8b10: 6c 6f 62 5f 61 70 70 65 6e 64 66 28 26 78 66 65 lob_appendf(&xfe
8b20: 72 2e 65 72 72 2c 20 22 75 6e 6b 6e 6f 77 6e 20 r.err, "unknown
8b30: 63 6f 6d 6d 61 6e 64 3a 20 25 62 22 2c 20 26 78 command: %b", &x
8b40: 66 65 72 2e 61 54 6f 6b 65 6e 5b 30 5d 29 3b 0a fer.aToken[0]);.
8b50: 20 20 20 20 20 20 7d 0a 0a 20 20 20 20 20 20 69 }.. i
8b60: 66 28 20 62 6c 6f 62 5f 73 69 7a 65 28 26 78 66 f( blob_size(&xf
8b70: 65 72 2e 65 72 72 29 20 29 7b 0a 20 20 20 20 20 er.err) ){.
8b80: 20 20 20 66 6f 73 73 69 6c 5f 66 61 74 61 6c 28 fossil_fatal(
8b90: 22 25 62 22 2c 20 26 78 66 65 72 2e 65 72 72 29 "%b", &xfer.err)
8ba0: 3b 0a 20 20 20 20 20 20 7d 0a 20 20 20 20 20 20 ;. }.
8bb0: 62 6c 6f 62 61 72 72 61 79 5f 72 65 73 65 74 28 blobarray_reset(
8bc0: 78 66 65 72 2e 61 54 6f 6b 65 6e 2c 20 78 66 65 xfer.aToken, xfe
8bd0: 72 2e 6e 54 6f 6b 65 6e 29 3b 0a 20 20 20 20 20 r.nToken);.
8be0: 20 62 6c 6f 62 5f 72 65 73 65 74 28 26 78 66 65 blob_reset(&xfe
8bf0: 72 2e 6c 69 6e 65 29 3b 0a 20 20 20 20 7d 0a 20 r.line);. }.
8c00: 20 20 20 69 66 28 20 6f 72 69 67 43 6f 6e 66 69 if( origConfi
8c10: 67 52 63 76 4d 61 73 6b 20 26 20 28 43 4f 4e 46 gRcvMask & (CONF
8c20: 49 47 53 45 54 5f 54 4b 54 7c 43 4f 4e 46 49 47 IGSET_TKT|CONFIG
8c30: 53 45 54 5f 55 53 45 52 29 20 29 7b 0a 20 20 20 SET_USER) ){.
8c40: 20 20 20 63 6f 6e 66 69 67 75 72 65 5f 66 69 6e configure_fin
8c50: 61 6c 69 7a 65 5f 72 65 63 65 69 76 65 28 29 3b alize_receive();
8c60: 0a 20 20 20 20 7d 0a 20 20 20 20 6f 72 69 67 43 . }. origC
8c70: 6f 6e 66 69 67 52 63 76 4d 61 73 6b 20 3d 20 30 onfigRcvMask = 0
8c80: 3b 0a 20 20 20 20 70 72 69 6e 74 66 28 7a 56 61 ;. printf(zVa
8c90: 6c 75 65 46 6f 72 6d 61 74 2c 20 22 52 65 63 65 lueFormat, "Rece
8ca0: 69 76 65 64 3a 22 2c 0a 20 20 20 20 20 20 20 20 ived:",.
8cb0: 20 20 20 20 62 6c 6f 62 5f 73 69 7a 65 28 26 72 blob_size(&r
8cc0: 65 63 76 29 2c 20 6e 43 61 72 64 2c 0a 20 20 20 ecv), nCard,.
8cd0: 20 20 20 20 20 20 20 20 20 78 66 65 72 2e 6e 46 xfer.nF
8ce0: 69 6c 65 52 63 76 64 2c 20 78 66 65 72 2e 6e 44 ileRcvd, xfer.nD
8cf0: 65 6c 74 61 52 63 76 64 20 2b 20 78 66 65 72 2e eltaRcvd + xfer.
8d00: 6e 44 61 6e 67 6c 69 6e 67 46 69 6c 65 29 3b 0a nDanglingFile);.
8d10: 20 20 20 20 62 6c 6f 62 5f 72 65 73 65 74 28 26 blob_reset(&
8d20: 72 65 63 76 29 3b 0a 20 20 20 20 6e 43 79 63 6c recv);. nCycl
8d30: 65 2b 2b 3b 0a 20 20 20 20 67 6f 20 3d 20 30 3b e++;. go = 0;
8d40: 0a 0a 20 20 20 20 2f 2a 20 49 66 20 77 65 20 72 .. /* If we r
8d50: 65 63 65 69 76 65 64 20 6f 6e 65 20 6f 72 20 6d eceived one or m
8d60: 6f 72 65 20 66 69 6c 65 73 20 6f 6e 20 74 68 65 ore files on the
8d70: 20 70 72 65 76 69 6f 75 73 20 65 78 63 68 61 6e previous exchan
8d80: 67 65 20 62 75 74 0a 20 20 20 20 2a 2a 20 74 68 ge but. ** th
8d90: 65 72 65 20 61 72 65 20 73 74 69 6c 6c 20 70 68 ere are still ph
8da0: 61 6e 74 6f 6d 73 2c 20 74 68 65 6e 20 67 6f 20 antoms, then go
8db0: 61 6e 6f 74 68 65 72 20 72 6f 75 6e 64 2e 0a 20 another round..
8dc0: 20 20 20 2a 2f 0a 20 20 20 20 6e 46 69 6c 65 52 */. nFileR
8dd0: 65 63 76 20 3d 20 78 66 65 72 2e 6e 46 69 6c 65 ecv = xfer.nFile
8de0: 52 63 76 64 20 2b 20 78 66 65 72 2e 6e 44 65 6c Rcvd + xfer.nDel
8df0: 74 61 52 63 76 64 20 2b 20 78 66 65 72 2e 6e 44 taRcvd + xfer.nD
8e00: 61 6e 67 6c 69 6e 67 46 69 6c 65 3b 0a 20 20 20 anglingFile;.
8e10: 20 69 66 28 20 28 6e 46 69 6c 65 52 65 63 76 3e if( (nFileRecv>
8e20: 30 20 7c 7c 20 6e 65 77 50 68 61 6e 74 6f 6d 29 0 || newPhantom)
8e30: 20 26 26 20 64 62 5f 65 78 69 73 74 73 28 22 53 && db_exists("S
8e40: 45 4c 45 43 54 20 31 20 46 52 4f 4d 20 70 68 61 ELECT 1 FROM pha
8e50: 6e 74 6f 6d 22 29 20 29 7b 0a 20 20 20 20 20 20 ntom") ){.
8e60: 67 6f 20 3d 20 31 3b 0a 20 20 20 20 20 20 6d 78 go = 1;. mx
8e70: 50 68 61 6e 74 6f 6d 52 65 71 20 3d 20 6e 46 69 PhantomReq = nFi
8e80: 6c 65 52 65 63 76 2a 32 3b 0a 20 20 20 20 20 20 leRecv*2;.
8e90: 69 66 28 20 6d 78 50 68 61 6e 74 6f 6d 52 65 71 if( mxPhantomReq
8ea0: 3c 32 30 30 20 29 20 6d 78 50 68 61 6e 74 6f 6d <200 ) mxPhantom
8eb0: 52 65 71 20 3d 20 32 30 30 3b 0a 20 20 20 20 7d Req = 200;. }
8ec0: 0a 20 20 20 20 6e 43 61 72 64 20 3d 20 30 3b 0a . nCard = 0;.
8ed0: 20 20 20 20 78 66 65 72 2e 6e 46 69 6c 65 52 63 xfer.nFileRc
8ee0: 76 64 20 3d 20 30 3b 0a 20 20 20 20 78 66 65 72 vd = 0;. xfer
8ef0: 2e 6e 44 65 6c 74 61 52 63 76 64 20 3d 20 30 3b .nDeltaRcvd = 0;
8f00: 0a 20 20 20 20 78 66 65 72 2e 6e 44 61 6e 67 6c . xfer.nDangl
8f10: 69 6e 67 46 69 6c 65 20 3d 20 30 3b 0a 0a 20 20 ingFile = 0;..
8f20: 20 20 2f 2a 20 49 66 20 77 65 20 68 61 76 65 20 /* If we have
8f30: 6f 6e 65 20 6f 72 20 6d 6f 72 65 20 66 69 6c 65 one or more file
8f40: 73 20 71 75 65 75 65 64 20 74 6f 20 73 65 6e 64 s queued to send
8f50: 2c 20 74 68 65 6e 20 67 6f 0a 20 20 20 20 2a 2a , then go. **
8f60: 20 61 6e 6f 74 68 65 72 20 72 6f 75 6e 64 20 0a another round .
8f70: 20 20 20 20 2a 2f 0a 20 20 20 20 69 66 28 20 78 */. if( x
8f80: 66 65 72 2e 6e 46 69 6c 65 53 65 6e 74 2b 78 66 fer.nFileSent+xf
8f90: 65 72 2e 6e 44 65 6c 74 61 53 65 6e 74 3e 30 20 er.nDeltaSent>0
8fa0: 29 7b 0a 20 20 20 20 20 20 67 6f 20 3d 20 31 3b ){. go = 1;
8fb0: 0a 20 20 20 20 7d 0a 20 20 7d 3b 0a 20 20 74 72 . }. };. tr
8fc0: 61 6e 73 70 6f 72 74 5f 73 74 61 74 73 28 26 6e ansport_stats(&n
8fd0: 53 65 6e 74 2c 20 26 6e 52 63 76 64 2c 20 31 29 Sent, &nRcvd, 1)
8fe0: 3b 0a 20 20 70 72 69 6e 74 66 28 22 54 6f 74 61 ;. printf("Tota
8ff0: 6c 20 6e 65 74 77 6f 72 6b 20 74 72 61 66 66 69 l network traffi
9000: 63 3a 20 25 64 20 62 79 74 65 73 20 73 65 6e 74 c: %d bytes sent
9010: 2c 20 25 64 20 62 79 74 65 73 20 72 65 63 65 69 , %d bytes recei
9020: 76 65 64 5c 6e 22 2c 0a 20 20 20 20 20 20 20 20 ved\n",.
9030: 20 6e 53 65 6e 74 2c 20 6e 52 63 76 64 29 3b 0a nSent, nRcvd);.
9040: 20 20 74 72 61 6e 73 70 6f 72 74 5f 63 6c 6f 73 transport_clos
9050: 65 28 29 3b 0a 20 20 73 6f 63 6b 65 74 5f 67 6c e();. socket_gl
9060: 6f 62 61 6c 5f 73 68 75 74 64 6f 77 6e 28 29 3b obal_shutdown();
9070: 0a 20 20 64 62 5f 6d 75 6c 74 69 5f 65 78 65 63 . db_multi_exec
9080: 28 22 44 52 4f 50 20 54 41 42 4c 45 20 6f 6e 72 ("DROP TABLE onr
9090: 65 6d 6f 74 65 22 29 3b 0a 20 20 64 62 5f 65 6e emote");. db_en
90a0: 64 5f 74 72 61 6e 73 61 63 74 69 6f 6e 28 30 29 d_transaction(0)
90b0: 3b 0a 7d 0a ;.}.