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 65 20 61 54 6f 6b ../*.** The aTok
03e0: 65 6e 5b 30 2e 2e 6e 54 6f 6b 65 6e 2d 31 5d 20 en[0..nToken-1]
03f0: 62 6c 6f 62 20 61 72 72 61 79 20 69 73 20 61 20 blob array is a
0400: 70 61 72 73 65 20 6f 66 20 61 20 22 66 69 6c 65 parse of a "file
0410: 22 20 6c 69 6e 65 20 0a 2a 2a 20 6d 65 73 73 61 " line .** messa
0420: 67 65 2e 20 20 54 68 69 73 20 72 6f 75 74 69 6e ge. This routin
0430: 65 20 66 69 6e 69 73 68 65 73 20 70 61 72 73 69 e finishes parsi
0440: 6e 67 20 74 68 61 74 20 6d 65 73 73 61 67 65 20 ng that message
0450: 61 6e 64 20 64 6f 65 73 0a 2a 2a 20 61 20 72 65 and does.** a re
0460: 63 6f 72 64 20 69 6e 73 65 72 74 20 6f 66 20 74 cord insert of t
0470: 68 65 20 66 69 6c 65 2e 0a 2a 2a 0a 2a 2a 20 54 he file..**.** T
0480: 68 65 20 66 69 6c 65 20 6c 69 6e 65 20 69 73 20 he file line is
0490: 69 6e 20 6f 6e 65 20 6f 66 20 74 68 65 20 66 6f in one of the fo
04a0: 6c 6c 6f 77 69 6e 67 20 74 77 6f 20 66 6f 72 6d llowing two form
04b0: 73 3a 0a 2a 2a 0a 2a 2a 20 20 20 20 20 20 66 69 s:.**.** fi
04c0: 6c 65 20 55 55 49 44 20 53 49 5a 45 20 5c 6e 20 le UUID SIZE \n
04d0: 43 4f 4e 54 45 4e 54 0a 2a 2a 20 20 20 20 20 20 CONTENT.**
04e0: 66 69 6c 65 20 55 55 49 44 20 44 45 4c 54 41 53 file UUID DELTAS
04f0: 52 43 20 53 49 5a 45 20 5c 6e 20 43 4f 4e 54 45 RC SIZE \n CONTE
0500: 4e 54 0a 2a 2a 0a 2a 2a 20 54 68 65 20 63 6f 6e NT.**.** The con
0510: 74 65 6e 74 20 69 73 20 53 49 5a 45 20 62 79 74 tent is SIZE byt
0520: 65 73 20 69 6d 6d 65 64 69 61 74 65 6c 79 20 66 es immediately f
0530: 6f 6c 6c 6f 77 69 6e 67 20 74 68 65 20 6e 65 77 ollowing the new
0540: 6c 69 6e 65 2e 0a 2a 2a 20 49 66 20 44 45 4c 54 line..** If DELT
0550: 41 53 52 43 20 65 78 69 73 74 73 2c 20 74 68 65 ASRC exists, the
0560: 6e 20 74 68 65 20 43 4f 4e 54 45 4e 54 20 69 73 n the CONTENT is
0570: 20 61 20 64 65 6c 74 61 20 61 67 61 69 6e 73 74 a delta against
0580: 20 74 68 65 0a 2a 2a 20 63 6f 6e 74 65 6e 74 20 the.** content
0590: 6f 66 20 44 45 4c 54 41 53 52 43 2e 0a 2a 2a 0a of DELTASRC..**.
05a0: 2a 2a 20 49 66 20 61 6e 79 20 65 72 72 6f 72 20 ** If any error
05b0: 6f 63 63 75 72 73 2c 20 77 72 69 74 65 20 61 20 occurs, write a
05c0: 6d 65 73 73 61 67 65 20 69 6e 74 6f 20 70 45 72 message into pEr
05d0: 72 20 77 68 69 63 68 20 68 61 73 20 61 6c 72 65 r which has alre
05e0: 61 64 79 0a 2a 2a 20 62 65 20 69 6e 69 74 69 61 ady.** be initia
05f0: 6c 69 7a 65 64 20 74 6f 20 61 6e 20 65 6d 70 74 lized to an empt
0600: 79 20 73 74 72 69 6e 67 2e 0a 2a 2f 0a 73 74 61 y string..*/.sta
0610: 74 69 63 20 76 6f 69 64 20 78 66 65 72 5f 61 63 tic void xfer_ac
0620: 63 65 70 74 5f 66 69 6c 65 28 42 6c 6f 62 20 2a cept_file(Blob *
0630: 70 49 6e 2c 20 42 6c 6f 62 20 2a 61 54 6f 6b 65 pIn, Blob *aToke
0640: 6e 2c 20 69 6e 74 20 6e 54 6f 6b 65 6e 2c 20 42 n, int nToken, B
0650: 6c 6f 62 20 2a 70 45 72 72 29 7b 0a 20 20 69 6e lob *pErr){. in
0660: 74 20 6e 3b 0a 20 20 69 6e 74 20 72 69 64 3b 0a t n;. int rid;.
0670: 20 20 42 6c 6f 62 20 63 6f 6e 74 65 6e 74 2c 20 Blob content,
0680: 68 61 73 68 3b 0a 20 20 0a 20 20 69 66 28 20 6e hash;. . if( n
0690: 54 6f 6b 65 6e 3c 33 20 7c 7c 20 6e 54 6f 6b 65 Token<3 || nToke
06a0: 6e 3e 34 20 7c 7c 20 21 62 6c 6f 62 5f 69 73 5f n>4 || !blob_is_
06b0: 75 75 69 64 28 26 61 54 6f 6b 65 6e 5b 31 5d 29 uuid(&aToken[1])
06c0: 0a 20 20 20 20 20 20 20 7c 7c 20 21 62 6c 6f 62 . || !blob
06d0: 5f 69 73 5f 69 6e 74 28 26 61 54 6f 6b 65 6e 5b _is_int(&aToken[
06e0: 6e 54 6f 6b 65 6e 2d 31 5d 2c 20 26 6e 29 20 7c nToken-1], &n) |
06f0: 7c 20 6e 3c 3d 30 0a 20 20 20 20 20 20 20 7c 7c | n<=0. ||
0700: 20 28 6e 54 6f 6b 65 6e 3d 3d 34 20 26 26 20 21 (nToken==4 && !
0710: 62 6c 6f 62 5f 69 73 5f 75 75 69 64 28 26 61 54 blob_is_uuid(&aT
0720: 6f 6b 65 6e 5b 32 5d 29 29 20 29 7b 0a 20 20 20 oken[2])) ){.
0730: 20 62 6c 6f 62 5f 61 70 70 65 6e 64 66 28 70 45 blob_appendf(pE
0740: 72 72 2c 20 22 6d 61 6c 66 6f 72 6d 65 64 20 66 rr, "malformed f
0750: 69 6c 65 20 6c 69 6e 65 22 29 3b 0a 20 20 20 20 ile line");.
0760: 72 65 74 75 72 6e 3b 0a 20 20 7d 0a 20 20 62 6c return;. }. bl
0770: 6f 62 5f 7a 65 72 6f 28 26 63 6f 6e 74 65 6e 74 ob_zero(&content
0780: 29 3b 0a 20 20 62 6c 6f 62 5f 7a 65 72 6f 28 26 );. blob_zero(&
0790: 68 61 73 68 29 3b 0a 20 20 62 6c 6f 62 5f 65 78 hash);. blob_ex
07a0: 74 72 61 63 74 28 70 49 6e 2c 20 6e 2c 20 26 63 tract(pIn, n, &c
07b0: 6f 6e 74 65 6e 74 29 3b 0a 20 20 69 66 28 20 6e ontent);. if( n
07c0: 54 6f 6b 65 6e 3d 3d 34 20 29 7b 0a 20 20 20 20 Token==4 ){.
07d0: 42 6c 6f 62 20 73 72 63 3b 0a 20 20 20 20 69 6e Blob src;. in
07e0: 74 20 73 72 63 69 64 20 3d 20 64 62 5f 69 6e 74 t srcid = db_int
07f0: 28 30 2c 20 22 53 45 4c 45 43 54 20 72 69 64 20 (0, "SELECT rid
0800: 46 52 4f 4d 20 62 6c 6f 62 20 57 48 45 52 45 20 FROM blob WHERE
0810: 75 75 69 64 3d 25 42 22 2c 20 26 61 54 6f 6b 65 uuid=%B", &aToke
0820: 6e 5b 32 5d 29 3b 0a 20 20 20 20 69 66 28 20 73 n[2]);. if( s
0830: 72 63 69 64 3d 3d 30 20 29 7b 0a 20 20 20 20 20 rcid==0 ){.
0840: 20 62 6c 6f 62 5f 61 70 70 65 6e 64 66 28 70 45 blob_appendf(pE
0850: 72 72 2c 20 22 75 6e 6b 6e 6f 77 6e 20 64 65 6c rr, "unknown del
0860: 74 61 20 73 6f 75 72 63 65 3a 20 25 62 22 2c 20 ta source: %b",
0870: 26 61 54 6f 6b 65 6e 5b 32 5d 29 3b 0a 20 20 20 &aToken[2]);.
0880: 20 20 20 72 65 74 75 72 6e 3b 0a 20 20 20 20 7d return;. }
0890: 0a 20 20 20 20 63 6f 6e 74 65 6e 74 5f 67 65 74 . content_get
08a0: 28 73 72 63 69 64 2c 20 26 73 72 63 29 3b 0a 20 (srcid, &src);.
08b0: 20 20 20 62 6c 6f 62 5f 64 65 6c 74 61 5f 61 70 blob_delta_ap
08c0: 70 6c 79 28 26 73 72 63 2c 20 26 63 6f 6e 74 65 ply(&src, &conte
08d0: 6e 74 2c 20 26 63 6f 6e 74 65 6e 74 29 3b 0a 20 nt, &content);.
08e0: 20 20 20 62 6c 6f 62 5f 72 65 73 65 74 28 26 73 blob_reset(&s
08f0: 72 63 29 3b 0a 20 20 7d 0a 20 20 73 68 61 31 73 rc);. }. sha1s
0900: 75 6d 5f 62 6c 6f 62 28 26 63 6f 6e 74 65 6e 74 um_blob(&content
0910: 2c 20 26 68 61 73 68 29 3b 0a 20 20 69 66 28 20 , &hash);. if(
0920: 21 62 6c 6f 62 5f 65 71 5f 73 74 72 28 26 61 54 !blob_eq_str(&aT
0930: 6f 6b 65 6e 5b 31 5d 2c 20 62 6c 6f 62 5f 73 74 oken[1], blob_st
0940: 72 28 26 68 61 73 68 29 2c 20 2d 31 29 20 29 7b r(&hash), -1) ){
0950: 0a 20 20 20 20 62 6c 6f 62 5f 61 70 70 65 6e 64 . blob_append
0960: 66 28 70 45 72 72 2c 20 22 63 6f 6e 74 65 6e 74 f(pErr, "content
0970: 20 64 6f 65 73 20 6e 6f 74 20 6d 61 74 63 68 20 does not match
0980: 73 68 61 31 20 68 61 73 68 22 29 3b 0a 20 20 7d sha1 hash");. }
0990: 0a 20 20 62 6c 6f 62 5f 72 65 73 65 74 28 26 68 . blob_reset(&h
09a0: 61 73 68 29 3b 0a 20 20 72 69 64 20 3d 20 63 6f ash);. rid = co
09b0: 6e 74 65 6e 74 5f 70 75 74 28 26 63 6f 6e 74 65 ntent_put(&conte
09c0: 6e 74 2c 20 30 29 3b 0a 20 20 6d 61 6e 69 66 65 nt, 0);. manife
09d0: 73 74 5f 63 72 6f 73 73 6c 69 6e 6b 28 72 69 64 st_crosslink(rid
09e0: 2c 20 26 63 6f 6e 74 65 6e 74 29 3b 0a 20 20 69 , &content);. i
09f0: 66 28 20 72 69 64 3d 3d 30 20 29 7b 0a 20 20 20 f( rid==0 ){.
0a00: 20 62 6c 6f 62 5f 61 70 70 65 6e 64 66 28 70 45 blob_appendf(pE
0a10: 72 72 2c 20 22 25 73 22 2c 20 67 2e 7a 45 72 72 rr, "%s", g.zErr
0a20: 4d 73 67 29 3b 0a 20 20 7d 0a 7d 0a 0a 2f 2a 0a Msg);. }.}../*.
0a30: 2a 2a 20 53 65 6e 64 20 74 68 65 20 66 69 6c 65 ** Send the file
0a40: 20 69 64 65 6e 74 69 66 69 65 64 20 62 79 20 72 identified by r
0a50: 69 64 2e 0a 2a 2a 0a 2a 2a 20 49 66 20 70 4f 75 id..**.** If pOu
0a60: 74 20 69 73 20 6e 6f 74 20 4e 55 4c 4c 2c 20 74 t is not NULL, t
0a70: 68 65 6e 20 61 70 70 65 6e 64 20 74 68 65 20 74 hen append the t
0a80: 65 78 74 20 6f 66 20 74 68 65 20 73 65 6e 64 20 ext of the send
0a90: 6d 65 73 73 61 67 65 0a 2a 2a 20 74 6f 20 70 4f message.** to pO
0aa0: 75 74 2e 20 20 4f 74 68 65 72 77 69 73 65 2c 20 ut. Otherwise,
0ab0: 61 70 70 65 6e 64 20 74 68 65 20 74 65 78 74 20 append the text
0ac0: 74 6f 20 74 68 65 20 43 47 49 20 6f 75 74 70 75 to the CGI outpu
0ad0: 74 2e 0a 2a 2f 0a 73 74 61 74 69 63 20 69 6e 74 t..*/.static int
0ae0: 20 73 65 6e 64 5f 66 69 6c 65 28 69 6e 74 20 72 send_file(int r
0af0: 69 64 2c 20 42 6c 6f 62 20 2a 70 4f 75 74 29 7b id, Blob *pOut){
0b00: 0a 20 20 42 6c 6f 62 20 63 6f 6e 74 65 6e 74 2c . Blob content,
0b10: 20 75 75 69 64 3b 0a 20 20 69 6e 74 20 73 69 7a uuid;. int siz
0b20: 65 3b 0a 0a 23 69 66 20 30 0a 53 45 4c 45 43 54 e;..#if 0.SELECT
0b30: 20 73 72 63 69 64 20 46 52 4f 4d 20 64 65 6c 74 srcid FROM delt
0b40: 61 0a 20 57 48 45 52 45 20 72 69 64 3d 25 64 0a a. WHERE rid=%d.
0b50: 20 20 20 41 4e 44 20 45 58 49 53 54 53 28 53 45 AND EXISTS(SE
0b60: 4c 45 43 54 20 31 20 46 52 4f 4d 20 6f 6e 72 65 LECT 1 FROM onre
0b70: 6d 6f 74 65 20 57 48 45 52 45 20 72 69 64 3d 73 mote WHERE rid=s
0b80: 72 63 69 64 29 0a 55 4e 49 4f 4e 20 41 4c 4c 0a rcid).UNION ALL.
0b90: 53 45 4c 45 43 54 20 69 64 20 46 52 4f 4d 20 64 SELECT id FROM d
0ba0: 65 6c 74 61 0a 20 57 48 45 52 45 20 73 72 63 69 elta. WHERE srci
0bb0: 64 3d 25 64 0a 20 20 20 41 4e 44 20 45 58 49 53 d=%d. AND EXIS
0bc0: 54 53 28 53 45 4c 45 43 54 20 31 20 46 52 4f 4d TS(SELECT 1 FROM
0bd0: 20 6f 6e 72 65 6d 6f 74 65 20 57 48 45 52 45 20 onremote WHERE
0be0: 72 69 64 3d 64 65 6c 74 61 2e 72 69 64 29 0a 4c rid=delta.rid).L
0bf0: 49 4d 49 54 20 31 0a 23 65 6e 64 69 66 0a 0a 20 IMIT 1.#endif..
0c00: 20 2f 2a 20 54 4f 44 4f 3a 0a 20 20 2a 2a 20 43 /* TODO:. ** C
0c10: 68 65 63 6b 20 66 6f 72 20 72 65 6c 61 74 65 64 heck for related
0c20: 20 66 69 6c 65 73 20 69 6e 20 74 68 65 20 6f 6e files in the on
0c30: 72 65 6d 6f 74 65 20 54 45 4d 50 20 74 61 62 6c remote TEMP tabl
0c40: 65 2e 20 20 49 66 20 72 65 6c 61 74 65 64 0a 20 e. If related.
0c50: 20 2a 2a 20 66 69 6c 65 73 20 61 72 65 20 66 6f ** files are fo
0c60: 75 6e 64 2c 20 74 68 65 6e 20 73 65 6e 64 20 61 und, then send a
0c70: 20 64 65 6c 74 61 20 72 61 74 68 65 72 20 74 68 delta rather th
0c80: 61 6e 20 74 68 65 20 77 68 6f 6c 65 20 66 69 6c an the whole fil
0c90: 65 2e 0a 20 20 2a 2f 0a 0a 20 20 62 6c 6f 62 5f e.. */.. blob_
0ca0: 7a 65 72 6f 28 26 75 75 69 64 29 3b 0a 20 20 64 zero(&uuid);. d
0cb0: 62 5f 62 6c 6f 62 28 26 75 75 69 64 2c 20 22 53 b_blob(&uuid, "S
0cc0: 45 4c 45 43 54 20 75 75 69 64 20 46 52 4f 4d 20 ELECT uuid FROM
0cd0: 62 6c 6f 62 20 57 48 45 52 45 20 72 69 64 3d 25 blob WHERE rid=%
0ce0: 64 20 41 4e 44 20 73 69 7a 65 3e 3d 30 22 2c 20 d AND size>=0",
0cf0: 72 69 64 29 3b 0a 20 20 69 66 28 20 62 6c 6f 62 rid);. if( blob
0d00: 5f 73 69 7a 65 28 26 75 75 69 64 29 3d 3d 30 20 _size(&uuid)==0
0d10: 29 7b 0a 20 20 20 20 72 65 74 75 72 6e 20 30 3b ){. return 0;
0d20: 0a 20 20 7d 0a 20 20 63 6f 6e 74 65 6e 74 5f 67 . }. content_g
0d30: 65 74 28 72 69 64 2c 20 26 63 6f 6e 74 65 6e 74 et(rid, &content
0d40: 29 3b 0a 20 20 73 69 7a 65 20 3d 20 62 6c 6f 62 );. size = blob
0d50: 5f 73 69 7a 65 28 26 63 6f 6e 74 65 6e 74 29 3b _size(&content);
0d60: 0a 20 20 69 66 28 20 70 4f 75 74 20 29 7b 0a 20 . if( pOut ){.
0d70: 20 20 20 62 6c 6f 62 5f 61 70 70 65 6e 64 66 28 blob_appendf(
0d80: 70 4f 75 74 2c 20 22 66 69 6c 65 20 25 62 20 25 pOut, "file %b %
0d90: 64 5c 6e 22 2c 20 26 75 75 69 64 2c 20 73 69 7a d\n", &uuid, siz
0da0: 65 29 3b 0a 20 20 20 20 62 6c 6f 62 5f 61 70 70 e);. blob_app
0db0: 65 6e 64 28 70 4f 75 74 2c 20 62 6c 6f 62 5f 62 end(pOut, blob_b
0dc0: 75 66 66 65 72 28 26 63 6f 6e 74 65 6e 74 29 2c uffer(&content),
0dd0: 20 73 69 7a 65 29 3b 0a 20 20 7d 65 6c 73 65 7b size);. }else{
0de0: 0a 20 20 20 20 63 67 69 5f 70 72 69 6e 74 66 28 . cgi_printf(
0df0: 22 66 69 6c 65 20 25 62 20 25 64 5c 6e 22 2c 20 "file %b %d\n",
0e00: 26 75 75 69 64 2c 20 73 69 7a 65 29 3b 0a 20 20 &uuid, size);.
0e10: 20 20 63 67 69 5f 61 70 70 65 6e 64 5f 63 6f 6e cgi_append_con
0e20: 74 65 6e 74 28 62 6c 6f 62 5f 62 75 66 66 65 72 tent(blob_buffer
0e30: 28 26 63 6f 6e 74 65 6e 74 29 2c 20 73 69 7a 65 (&content), size
0e40: 29 3b 0a 20 20 7d 0a 20 20 62 6c 6f 62 5f 72 65 );. }. blob_re
0e50: 73 65 74 28 26 63 6f 6e 74 65 6e 74 29 3b 0a 20 set(&content);.
0e60: 20 62 6c 6f 62 5f 72 65 73 65 74 28 26 75 75 69 blob_reset(&uui
0e70: 64 29 3b 0a 20 20 64 62 5f 6d 75 6c 74 69 5f 65 d);. db_multi_e
0e80: 78 65 63 28 22 49 4e 53 45 52 54 20 4f 52 20 49 xec("INSERT OR I
0e90: 47 4e 4f 52 45 20 49 4e 54 4f 20 6f 6e 72 65 6d GNORE INTO onrem
0ea0: 6f 74 65 20 56 41 4c 55 45 53 28 25 64 29 22 2c ote VALUES(%d)",
0eb0: 20 72 69 64 29 3b 0a 20 20 72 65 74 75 72 6e 20 rid);. return
0ec0: 73 69 7a 65 3b 0a 7d 0a 0a 0a 2f 2a 0a 2a 2a 20 size;.}.../*.**
0ed0: 53 65 6e 64 20 61 6c 6c 20 70 65 6e 64 69 6e 67 Send all pending
0ee0: 20 66 69 6c 65 73 2e 0a 2a 2f 0a 73 74 61 74 69 files..*/.stati
0ef0: 63 20 69 6e 74 20 73 65 6e 64 5f 61 6c 6c 5f 70 c int send_all_p
0f00: 65 6e 64 69 6e 67 28 42 6c 6f 62 20 2a 70 4f 75 ending(Blob *pOu
0f10: 74 29 7b 0a 20 20 69 6e 74 20 69 52 69 64 53 65 t){. int iRidSe
0f20: 6e 74 20 3d 20 30 3b 0a 20 20 69 6e 74 20 73 65 nt = 0;. int se
0f30: 6e 74 20 3d 20 30 3b 0a 20 20 69 6e 74 20 6e 53 nt = 0;. int nS
0f40: 65 6e 74 20 3d 20 30 3b 0a 20 20 69 6e 74 20 6d ent = 0;. int m
0f50: 61 78 53 69 7a 65 20 3d 20 64 62 5f 67 65 74 5f axSize = db_get_
0f60: 69 6e 74 28 22 68 74 74 70 2d 6d 73 67 2d 73 69 int("http-msg-si
0f70: 7a 65 22 2c 20 35 30 30 30 30 30 29 3b 0a 20 20 ze", 500000);.
0f80: 53 74 6d 74 20 71 3b 0a 23 69 66 20 30 0a 20 20 Stmt q;.#if 0.
0f90: 64 62 5f 6d 75 6c 74 69 5f 65 78 65 63 28 0a 20 db_multi_exec(.
0fa0: 20 20 20 22 43 52 45 41 54 45 20 54 45 4d 50 20 "CREATE TEMP
0fb0: 54 41 42 4c 45 20 70 72 69 6f 72 69 74 79 28 72 TABLE priority(r
0fc0: 69 64 20 49 4e 54 45 47 45 52 20 50 52 49 4d 41 id INTEGER PRIMA
0fd0: 52 59 20 4b 45 59 29 3b 22 0a 20 20 20 20 22 49 RY KEY);". "I
0fe0: 4e 53 45 52 54 20 49 4e 54 4f 20 70 72 69 6f 72 NSERT INTO prior
0ff0: 69 74 79 22 0a 20 20 20 20 22 20 53 45 4c 45 43 ity". " SELEC
1000: 54 20 73 72 63 69 64 20 46 52 4f 4d 20 64 65 6c T srcid FROM del
1010: 74 61 22 0a 20 20 20 20 22 20 20 57 48 45 52 45 ta". " WHERE
1020: 20 45 58 49 53 54 53 28 53 45 4c 45 43 54 20 31 EXISTS(SELECT 1
1030: 20 46 52 4f 4d 20 6f 6e 72 65 6d 6f 74 65 20 57 FROM onremote W
1040: 48 45 52 45 20 6f 6e 72 65 6d 6f 74 65 2e 72 69 HERE onremote.ri
1050: 64 3d 64 65 6c 74 61 2e 72 69 64 29 22 0a 20 20 d=delta.rid)".
1060: 20 20 22 20 20 20 20 41 4e 44 20 45 58 49 53 54 " AND EXIST
1070: 53 28 53 45 4c 45 43 54 20 31 20 46 52 4f 4d 20 S(SELECT 1 FROM
1080: 70 65 6e 64 69 6e 67 20 57 48 45 52 45 20 64 65 pending WHERE de
1090: 6c 74 61 2e 73 72 63 69 64 3d 70 65 6e 64 69 6e lta.srcid=pendin
10a0: 67 2e 72 69 64 29 3b 22 0a 20 20 20 20 22 49 4e g.rid);". "IN
10b0: 53 45 52 54 20 4f 52 20 49 47 4e 4f 52 45 20 49 SERT OR IGNORE I
10c0: 4e 54 4f 20 70 72 69 6f 72 69 74 79 22 0a 20 20 NTO priority".
10d0: 20 20 22 20 53 45 4c 45 43 54 20 72 69 64 20 46 " SELECT rid F
10e0: 52 4f 4d 20 64 65 6c 74 61 22 0a 20 20 20 20 22 ROM delta". "
10f0: 20 20 57 48 45 52 45 20 45 58 49 53 54 53 28 53 WHERE EXISTS(S
1100: 45 4c 45 43 54 20 31 20 46 52 4f 4d 20 6f 6e 72 ELECT 1 FROM onr
1110: 65 6d 6f 74 65 20 57 48 45 52 45 20 6f 6e 72 65 emote WHERE onre
1120: 6d 6f 74 65 2e 72 69 64 3d 64 65 6c 74 61 2e 73 mote.rid=delta.s
1130: 72 63 69 64 29 22 0a 20 20 20 20 22 20 20 20 20 rcid)". "
1140: 41 4e 44 20 45 58 49 53 54 53 28 53 45 4c 45 43 AND EXISTS(SELEC
1150: 54 20 31 20 46 52 4f 4d 20 70 65 6e 64 69 6e 67 T 1 FROM pending
1160: 20 57 48 45 52 45 20 64 65 6c 74 61 2e 72 69 64 WHERE delta.rid
1170: 3d 70 65 6e 64 69 6e 67 2e 72 69 64 29 3b 22 0a =pending.rid);".
1180: 20 20 29 3b 0a 20 20 77 68 69 6c 65 28 20 73 65 );. while( se
1190: 6e 74 3c 6d 61 78 53 69 7a 65 20 26 26 20 28 72 nt<maxSize && (r
11a0: 69 64 20 3d 20 64 62 5f 69 6e 74 28 30 2c 20 22 id = db_int(0, "
11b0: 53 45 4c 45 43 54 20 72 69 64 20 46 52 4f 4d 20 SELECT rid FROM
11c0: 70 72 69 6f 72 69 74 79 22 29 29 21 3d 30 20 29 priority"))!=0 )
11d0: 7b 0a 20 20 20 20 73 65 6e 74 20 2b 3d 20 73 65 {. sent += se
11e0: 6e 64 5f 66 69 6c 65 28 72 69 64 2c 20 70 4f 75 nd_file(rid, pOu
11f0: 74 29 3b 0a 20 20 20 20 64 62 5f 6d 75 6c 74 69 t);. db_multi
1200: 5f 65 78 65 63 28 0a 20 20 20 20 20 20 22 49 4e _exec(. "IN
1210: 53 45 52 54 20 4f 52 20 49 47 4e 4f 52 45 20 49 SERT OR IGNORE I
1220: 4e 54 4f 20 70 72 69 6f 72 69 74 79 22 0a 20 20 NTO priority".
1230: 20 20 20 20 22 20 53 45 4c 45 43 54 20 73 72 63 " SELECT src
1240: 69 64 20 46 52 4f 4d 20 64 65 6c 74 61 20 57 48 id FROM delta WH
1250: 45 52 45 20 72 69 64 3d 25 64 22 0a 20 20 20 20 ERE rid=%d".
1260: 20 20 22 20 55 4e 49 4f 4e 20 41 4c 4c 22 0a 20 " UNION ALL".
1270: 20 20 20 20 20 22 20 53 45 4c 45 43 54 20 72 69 " SELECT ri
1280: 64 20 46 52 4f 4d 20 64 65 6c 74 61 20 57 48 45 d FROM delta WHE
1290: 52 45 20 73 72 63 69 64 3d 25 64 22 2c 0a 20 20 RE srcid=%d",.
12a0: 20 20 20 20 72 69 64 2c 20 72 69 64 0a 20 20 20 rid, rid.
12b0: 20 29 3b 0a 20 20 7d 0a 23 65 6e 64 69 66 0a 20 );. }.#endif.
12c0: 20 64 62 5f 70 72 65 70 61 72 65 28 26 71 2c 20 db_prepare(&q,
12d0: 22 53 45 4c 45 43 54 20 72 69 64 20 46 52 4f 4d "SELECT rid FROM
12e0: 20 70 65 6e 64 69 6e 67 20 4f 52 44 45 52 20 42 pending ORDER B
12f0: 59 20 72 69 64 22 29 3b 0a 20 20 77 68 69 6c 65 Y rid");. while
1300: 28 20 64 62 5f 73 74 65 70 28 26 71 29 3d 3d 53 ( db_step(&q)==S
1310: 51 4c 49 54 45 5f 52 4f 57 20 29 7b 0a 20 20 20 QLITE_ROW ){.
1320: 20 69 6e 74 20 72 69 64 20 3d 20 64 62 5f 63 6f int rid = db_co
1330: 6c 75 6d 6e 5f 69 6e 74 28 26 71 2c 20 30 29 3b lumn_int(&q, 0);
1340: 0a 20 20 20 20 69 66 28 20 73 65 6e 74 3c 6d 61 . if( sent<ma
1350: 78 53 69 7a 65 20 29 7b 0a 20 20 20 20 20 20 73 xSize ){. s
1360: 65 6e 74 20 2b 3d 20 73 65 6e 64 5f 66 69 6c 65 ent += send_file
1370: 28 72 69 64 2c 20 70 4f 75 74 29 3b 0a 20 20 20 (rid, pOut);.
1380: 20 20 20 6e 53 65 6e 74 2b 2b 3b 0a 20 20 20 20 nSent++;.
1390: 20 20 69 52 69 64 53 65 6e 74 20 3d 20 72 69 64 iRidSent = rid
13a0: 3b 0a 20 20 20 20 7d 65 6c 73 65 7b 0a 20 20 20 ;. }else{.
13b0: 20 20 20 63 68 61 72 20 2a 7a 55 75 69 64 20 3d char *zUuid =
13c0: 20 64 62 5f 74 65 78 74 28 30 2c 0a 20 20 20 20 db_text(0,.
13d0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
13e0: 20 20 22 53 45 4c 45 43 54 20 75 75 69 64 20 46 "SELECT uuid F
13f0: 52 4f 4d 20 62 6c 6f 62 20 57 48 45 52 45 20 72 ROM blob WHERE r
1400: 69 64 3d 25 64 20 41 4e 44 20 73 69 7a 65 3e 3d id=%d AND size>=
1410: 30 22 2c 20 72 69 64 29 3b 0a 20 20 20 20 20 20 0", rid);.
1420: 69 66 28 20 7a 55 75 69 64 20 29 7b 0a 20 20 20 if( zUuid ){.
1430: 20 20 20 20 20 69 66 28 20 70 4f 75 74 20 29 7b if( pOut ){
1440: 0a 20 20 20 20 20 20 20 20 20 20 62 6c 6f 62 5f . blob_
1450: 61 70 70 65 6e 64 66 28 70 4f 75 74 2c 20 22 69 appendf(pOut, "i
1460: 67 6f 74 20 25 73 5c 6e 22 2c 20 7a 55 75 69 64 got %s\n", zUuid
1470: 29 3b 0a 20 20 20 20 20 20 20 20 7d 65 6c 73 65 );. }else
1480: 7b 0a 20 20 20 20 20 20 20 20 20 20 63 67 69 5f {. cgi_
1490: 70 72 69 6e 74 66 28 22 69 67 6f 74 20 25 73 5c printf("igot %s\
14a0: 6e 22 2c 20 7a 55 75 69 64 29 3b 0a 20 20 20 20 n", zUuid);.
14b0: 20 20 20 20 7d 0a 20 20 20 20 20 20 20 20 66 72 }. fr
14c0: 65 65 28 7a 55 75 69 64 29 3b 0a 20 20 20 20 20 ee(zUuid);.
14d0: 20 7d 0a 20 20 20 20 7d 0a 20 20 7d 0a 20 20 64 }. }. }. d
14e0: 62 5f 66 69 6e 61 6c 69 7a 65 28 26 71 29 3b 0a b_finalize(&q);.
14f0: 20 20 0a 20 20 2f 2a 20 44 65 6c 65 74 65 20 74 . /* Delete t
1500: 68 65 20 27 70 65 6e 64 69 6e 67 27 20 72 65 63 he 'pending' rec
1510: 6f 72 64 73 20 66 6f 72 20 61 6c 6c 20 66 69 6c ords for all fil
1520: 65 73 20 6a 75 73 74 20 73 65 6e 74 2e 20 4f 74 es just sent. Ot
1530: 68 65 72 77 69 73 65 2c 0a 20 20 2a 2a 20 77 65 herwise,. ** we
1540: 20 63 61 6e 20 77 69 6e 64 20 75 70 20 73 65 6e can wind up sen
1550: 64 69 6e 67 20 73 6f 6d 65 20 66 69 6c 65 73 20 ding some files
1560: 6d 6f 72 65 20 74 68 61 6e 20 6f 6e 63 65 2e 0a more than once..
1570: 20 20 2a 2f 0a 20 20 69 66 28 20 6e 53 65 6e 74 */. if( nSent
1580: 3e 30 20 29 7b 0a 20 20 20 20 64 62 5f 6d 75 6c >0 ){. db_mul
1590: 74 69 5f 65 78 65 63 28 22 44 45 4c 45 54 45 20 ti_exec("DELETE
15a0: 46 52 4f 4d 20 70 65 6e 64 69 6e 67 20 57 48 45 FROM pending WHE
15b0: 52 45 20 72 69 64 20 3c 3d 20 25 64 22 2c 20 69 RE rid <= %d", i
15c0: 52 69 64 53 65 6e 74 29 3b 0a 20 20 7d 0a 0a 23 RidSent);. }..#
15d0: 69 66 20 30 0a 20 20 64 62 5f 6d 75 6c 74 69 5f if 0. db_multi_
15e0: 65 78 65 63 28 22 44 52 4f 50 20 54 41 42 4c 45 exec("DROP TABLE
15f0: 20 70 72 69 6f 72 69 74 79 22 29 3b 0a 23 65 6e priority");.#en
1600: 64 69 66 0a 20 20 72 65 74 75 72 6e 20 6e 53 65 dif. return nSe
1610: 6e 74 3b 0a 7d 0a 0a 0a 2f 2a 0a 2a 2a 20 43 68 nt;.}.../*.** Ch
1620: 65 63 6b 20 74 68 65 20 73 69 67 6e 61 74 75 72 eck the signatur
1630: 65 20 6f 6e 20 61 6e 20 61 70 70 6c 69 63 61 74 e on an applicat
1640: 69 6f 6e 2f 78 2d 66 6f 73 73 69 6c 20 70 61 79 ion/x-fossil pay
1650: 6c 6f 61 64 20 72 65 63 65 69 76 65 64 20 62 79 load received by
1660: 0a 2a 2a 20 74 68 65 20 48 54 54 50 20 73 65 72 .** the HTTP ser
1670: 76 65 72 2e 20 20 54 68 65 20 73 69 67 6e 61 74 ver. The signat
1680: 75 72 65 20 69 73 20 61 20 6c 69 6e 65 20 6f 66 ure is a line of
1690: 20 74 68 65 20 66 6f 6c 6c 6f 77 69 6e 67 20 66 the following f
16a0: 6f 72 6d 3a 0a 2a 2a 0a 2a 2a 20 20 20 20 20 20 orm:.**.**
16b0: 20 20 6c 6f 67 69 6e 20 4c 4f 47 49 4e 20 4e 4f login LOGIN NO
16c0: 4e 43 45 20 53 49 47 4e 41 54 55 52 45 0a 2a 2a NCE SIGNATURE.**
16d0: 0a 2a 2a 20 54 68 65 20 4e 4f 4e 43 45 20 69 73 .** The NONCE is
16e0: 20 61 20 72 61 6e 64 6f 6d 20 73 74 72 69 6e 67 a random string
16f0: 2e 20 20 54 68 65 20 73 65 72 76 65 72 20 77 69 . The server wi
1700: 6c 6c 20 6e 65 76 65 72 20 61 63 63 65 70 74 20 ll never accept
1710: 61 0a 2a 2a 20 72 65 70 65 61 74 20 4e 4f 4e 43 a.** repeat NONC
1720: 45 2e 20 20 53 49 47 4e 41 54 55 52 45 20 69 73 E. SIGNATURE is
1730: 20 74 68 65 20 53 48 41 31 20 63 68 65 63 6b 73 the SHA1 checks
1740: 75 6d 20 6f 66 20 74 68 65 20 4e 4f 4e 43 45 20 um of the NONCE
1750: 0a 2a 2a 20 63 6f 6e 63 61 74 65 6e 61 74 65 64 .** concatenated
1760: 20 77 69 74 68 20 74 68 65 20 75 73 65 72 73 20 with the users
1770: 70 61 73 73 77 6f 72 64 2e 0a 2a 2a 0a 2a 2a 20 password..**.**
1780: 54 68 65 20 70 61 72 61 6d 65 74 65 72 73 20 74 The parameters t
1790: 6f 20 74 68 69 73 20 72 6f 75 74 69 6e 65 20 61 o this routine a
17a0: 72 65 20 65 70 68 65 72 6d 65 72 61 6c 20 62 6c re ephermeral bl
17b0: 6f 62 73 20 68 6f 6c 64 69 6e 67 20 74 68 65 0a obs holding the.
17c0: 2a 2a 20 4c 4f 47 49 4e 2c 20 4e 4f 4e 43 45 20 ** LOGIN, NONCE
17d0: 61 6e 64 20 53 49 47 4e 41 54 55 52 45 2e 0a 2a and SIGNATURE..*
17e0: 2a 0a 2a 2a 20 54 68 69 73 20 72 6f 75 74 69 6e *.** This routin
17f0: 65 20 61 74 74 65 6d 70 74 73 20 74 6f 20 6c 6f e attempts to lo
1800: 63 61 74 65 20 74 68 65 20 75 73 65 72 20 61 6e cate the user an
1810: 64 20 76 65 72 69 66 79 20 74 68 65 20 73 69 67 d verify the sig
1820: 6e 61 74 75 72 65 2e 0a 2a 2a 20 49 66 20 65 76 nature..** If ev
1830: 65 72 79 74 68 69 6e 67 20 63 68 65 63 6b 73 20 erything checks
1840: 6f 75 74 2c 20 74 68 65 20 55 53 45 52 2e 43 41 out, the USER.CA
1850: 50 20 63 6f 6c 75 6d 6e 20 66 6f 72 20 74 68 65 P column for the
1860: 20 55 53 45 52 20 74 61 62 6c 65 0a 2a 2a 20 69 USER table.** i
1870: 73 20 63 6f 6e 73 75 6c 74 65 64 20 74 6f 20 73 s consulted to s
1880: 65 74 20 70 72 69 76 69 6c 65 67 65 73 20 69 6e et privileges in
1890: 20 74 68 65 20 67 6c 6f 62 61 6c 20 67 20 76 61 the global g va
18a0: 72 69 61 62 6c 65 2e 0a 2a 2a 0a 2a 2a 20 49 66 riable..**.** If
18b0: 20 61 6e 79 74 68 69 6e 67 20 66 61 69 6c 73 20 anything fails
18c0: 74 6f 20 63 68 65 63 6b 20 6f 75 74 2c 20 6e 6f to check out, no
18d0: 20 63 68 61 6e 67 65 73 20 61 72 65 20 6d 61 64 changes are mad
18e0: 65 20 74 6f 20 70 72 69 76 69 6c 65 67 65 73 2e e to privileges.
18f0: 0a 2a 2a 0a 2a 2a 20 53 69 67 6e 61 74 75 72 65 .**.** Signature
1900: 20 67 65 6e 65 72 61 74 69 6f 6e 20 6f 6e 20 74 generation on t
1910: 68 65 20 63 6c 69 65 6e 74 20 73 69 64 65 20 69 he client side i
1920: 73 20 68 61 6e 64 6c 65 64 20 62 79 20 74 68 65 s handled by the
1930: 20 0a 2a 2a 20 68 74 74 70 5f 65 78 63 68 61 6e .** http_exchan
1940: 67 65 28 29 20 72 6f 75 74 69 6e 65 2e 0a 2a 2f ge() routine..*/
1950: 0a 76 6f 69 64 20 63 68 65 63 6b 5f 6c 6f 67 69 .void check_logi
1960: 6e 28 42 6c 6f 62 20 2a 70 4c 6f 67 69 6e 2c 20 n(Blob *pLogin,
1970: 42 6c 6f 62 20 2a 70 4e 6f 6e 63 65 2c 20 42 6c Blob *pNonce, Bl
1980: 6f 62 20 2a 70 53 69 67 29 7b 0a 20 20 53 74 6d ob *pSig){. Stm
1990: 74 20 71 3b 0a 20 20 69 6e 74 20 72 63 3b 0a 0a t q;. int rc;..
19a0: 20 20 69 66 28 20 64 62 5f 65 78 69 73 74 73 28 if( db_exists(
19b0: 22 53 45 4c 45 43 54 20 31 20 46 52 4f 4d 20 72 "SELECT 1 FROM r
19c0: 63 76 66 72 6f 6d 20 57 48 45 52 45 20 6e 6f 6e cvfrom WHERE non
19d0: 63 65 3d 25 42 22 2c 20 70 4e 6f 6e 63 65 29 20 ce=%B", pNonce)
19e0: 29 7b 0a 20 20 20 20 72 65 74 75 72 6e 3b 20 20 ){. return;
19f0: 2f 2a 20 4e 65 76 65 72 20 61 63 63 65 70 74 20 /* Never accept
1a00: 61 20 72 65 70 65 61 74 65 64 20 6e 6f 6e 63 65 a repeated nonce
1a10: 20 2a 2f 0a 20 20 7d 0a 20 20 64 62 5f 70 72 65 */. }. db_pre
1a20: 70 61 72 65 28 26 71 2c 20 22 53 45 4c 45 43 54 pare(&q, "SELECT
1a30: 20 70 77 2c 20 63 61 70 2c 20 75 69 64 20 46 52 pw, cap, uid FR
1a40: 4f 4d 20 75 73 65 72 20 57 48 45 52 45 20 6c 6f OM user WHERE lo
1a50: 67 69 6e 3d 25 42 22 2c 20 70 4c 6f 67 69 6e 29 gin=%B", pLogin)
1a60: 3b 0a 20 20 69 66 28 20 64 62 5f 73 74 65 70 28 ;. if( db_step(
1a70: 26 71 29 3d 3d 53 51 4c 49 54 45 5f 52 4f 57 20 &q)==SQLITE_ROW
1a80: 29 7b 0a 20 20 20 20 42 6c 6f 62 20 70 77 2c 20 ){. Blob pw,
1a90: 63 6f 6d 62 69 6e 65 64 2c 20 68 61 73 68 3b 0a combined, hash;.
1aa0: 20 20 20 20 62 6c 6f 62 5f 7a 65 72 6f 28 26 70 blob_zero(&p
1ab0: 77 29 3b 0a 20 20 20 20 64 62 5f 65 70 68 65 6d w);. db_ephem
1ac0: 65 72 61 6c 5f 62 6c 6f 62 28 26 71 2c 20 30 2c eral_blob(&q, 0,
1ad0: 20 26 70 77 29 3b 0a 20 20 20 20 62 6c 6f 62 5f &pw);. blob_
1ae0: 7a 65 72 6f 28 26 63 6f 6d 62 69 6e 65 64 29 3b zero(&combined);
1af0: 0a 20 20 20 20 62 6c 6f 62 5f 63 6f 70 79 28 26 . blob_copy(&
1b00: 63 6f 6d 62 69 6e 65 64 2c 20 70 4e 6f 6e 63 65 combined, pNonce
1b10: 29 3b 0a 20 20 20 20 62 6c 6f 62 5f 61 70 70 65 );. blob_appe
1b20: 6e 64 28 26 63 6f 6d 62 69 6e 65 64 2c 20 62 6c nd(&combined, bl
1b30: 6f 62 5f 62 75 66 66 65 72 28 26 70 77 29 2c 20 ob_buffer(&pw),
1b40: 62 6c 6f 62 5f 73 69 7a 65 28 26 70 77 29 29 3b blob_size(&pw));
1b50: 0a 20 20 20 20 2f 2a 20 43 47 49 44 45 42 55 47 . /* CGIDEBUG
1b60: 28 28 22 70 72 65 73 69 67 3d 5b 25 73 5d 5c 6e (("presig=[%s]\n
1b70: 22 2c 20 62 6c 6f 62 5f 73 74 72 28 26 63 6f 6d ", blob_str(&com
1b80: 62 69 6e 65 64 29 29 29 3b 20 2a 2f 0a 20 20 20 bined))); */.
1b90: 20 73 68 61 31 73 75 6d 5f 62 6c 6f 62 28 26 63 sha1sum_blob(&c
1ba0: 6f 6d 62 69 6e 65 64 2c 20 26 68 61 73 68 29 3b ombined, &hash);
1bb0: 0a 20 20 20 20 72 63 20 3d 20 62 6c 6f 62 5f 63 . rc = blob_c
1bc0: 6f 6d 70 61 72 65 28 26 68 61 73 68 2c 20 70 53 ompare(&hash, pS
1bd0: 69 67 29 3b 0a 20 20 20 20 62 6c 6f 62 5f 72 65 ig);. blob_re
1be0: 73 65 74 28 26 68 61 73 68 29 3b 0a 20 20 20 20 set(&hash);.
1bf0: 62 6c 6f 62 5f 72 65 73 65 74 28 26 63 6f 6d 62 blob_reset(&comb
1c00: 69 6e 65 64 29 3b 0a 20 20 20 20 69 66 28 20 72 ined);. if( r
1c10: 63 3d 3d 30 20 29 7b 0a 20 20 20 20 20 20 63 6f c==0 ){. co
1c20: 6e 73 74 20 63 68 61 72 20 2a 7a 43 61 70 3b 0a nst char *zCap;.
1c30: 20 20 20 20 20 20 7a 43 61 70 20 3d 20 64 62 5f zCap = db_
1c40: 63 6f 6c 75 6d 6e 5f 74 65 78 74 28 26 71 2c 20 column_text(&q,
1c50: 31 29 3b 0a 20 20 20 20 20 20 6c 6f 67 69 6e 5f 1);. login_
1c60: 73 65 74 5f 63 61 70 61 62 69 6c 69 74 69 65 73 set_capabilities
1c70: 28 7a 43 61 70 29 3b 0a 20 20 20 20 20 20 67 2e (zCap);. g.
1c80: 75 73 65 72 55 69 64 20 3d 20 64 62 5f 63 6f 6c userUid = db_col
1c90: 75 6d 6e 5f 69 6e 74 28 26 71 2c 20 32 29 3b 0a umn_int(&q, 2);.
1ca0: 20 20 20 20 20 20 67 2e 7a 4c 6f 67 69 6e 20 3d g.zLogin =
1cb0: 20 6d 70 72 69 6e 74 66 28 22 25 62 22 2c 20 70 mprintf("%b", p
1cc0: 4c 6f 67 69 6e 29 3b 0a 20 20 20 20 20 20 67 2e Login);. g.
1cd0: 7a 4e 6f 6e 63 65 20 3d 20 6d 70 72 69 6e 74 66 zNonce = mprintf
1ce0: 28 22 25 62 22 2c 20 70 4e 6f 6e 63 65 29 3b 0a ("%b", pNonce);.
1cf0: 20 20 20 20 7d 0a 20 20 7d 0a 20 20 64 62 5f 72 }. }. db_r
1d00: 65 73 65 74 28 26 71 29 3b 0a 7d 0a 0a 0a 2f 2a eset(&q);.}.../*
1d10: 0a 2a 2a 20 49 66 20 74 68 69 73 20 76 61 72 69 .** If this vari
1d20: 61 62 6c 65 20 69 73 20 73 65 74 2c 20 64 69 73 able is set, dis
1d30: 61 62 6c 65 20 6c 6f 67 69 6e 20 63 68 65 63 6b able login check
1d40: 73 2e 20 20 55 73 65 64 20 66 6f 72 20 64 65 62 s. Used for deb
1d50: 75 67 67 69 6e 67 0a 2a 2a 20 6f 6e 6c 79 2e 0a ugging.** only..
1d60: 2a 2f 0a 73 74 61 74 69 63 20 69 6e 74 20 64 69 */.static int di
1d70: 73 61 62 6c 65 4c 6f 67 69 6e 20 3d 20 30 3b 0a sableLogin = 0;.
1d80: 0a 2f 2a 0a 2a 2a 20 57 45 42 50 41 47 45 3a 20 ./*.** WEBPAGE:
1d90: 78 66 65 72 0a 2a 2a 0a 2a 2a 20 54 68 69 73 20 xfer.**.** This
1da0: 69 73 20 74 68 65 20 74 72 61 6e 73 66 65 72 20 is the transfer
1db0: 68 61 6e 64 6c 65 72 20 6f 6e 20 74 68 65 20 73 handler on the s
1dc0: 65 72 76 65 72 20 73 69 64 65 2e 20 20 54 68 65 erver side. The
1dd0: 20 74 72 61 6e 73 66 65 72 0a 2a 2a 20 6d 65 73 transfer.** mes
1de0: 73 61 67 65 20 68 61 73 20 62 65 65 6e 20 75 6e sage has been un
1df0: 63 6f 6d 70 72 65 73 73 65 64 20 61 6e 64 20 70 compressed and p
1e00: 6c 61 63 65 64 20 69 6e 20 74 68 65 20 67 2e 63 laced in the g.c
1e10: 67 69 49 6e 20 62 6c 6f 62 2e 0a 2a 2a 20 50 72 giIn blob..** Pr
1e20: 6f 63 65 73 73 20 74 68 69 73 20 6d 65 73 73 61 ocess this messa
1e30: 67 65 20 61 6e 64 20 66 6f 72 6d 20 61 6e 20 61 ge and form an a
1e40: 70 70 72 6f 70 72 69 61 74 65 20 72 65 70 6c 79 ppropriate reply
1e50: 2e 0a 2a 2f 0a 76 6f 69 64 20 70 61 67 65 5f 78 ..*/.void page_x
1e60: 66 65 72 28 76 6f 69 64 29 7b 0a 20 20 69 6e 74 fer(void){. int
1e70: 20 6e 54 6f 6b 65 6e 3b 0a 20 20 69 6e 74 20 69 nToken;. int i
1e80: 73 50 75 6c 6c 20 3d 20 30 3b 0a 20 20 69 6e 74 sPull = 0;. int
1e90: 20 69 73 50 75 73 68 20 3d 20 30 3b 0a 20 20 69 isPush = 0;. i
1ea0: 6e 74 20 6e 45 72 72 20 3d 20 30 3b 0a 20 20 42 nt nErr = 0;. B
1eb0: 6c 6f 62 20 6c 69 6e 65 2c 20 65 72 72 6d 73 67 lob line, errmsg
1ec0: 2c 20 61 54 6f 6b 65 6e 5b 35 5d 3b 0a 0a 20 20 , aToken[5];..
1ed0: 64 62 5f 62 65 67 69 6e 5f 74 72 61 6e 73 61 63 db_begin_transac
1ee0: 74 69 6f 6e 28 29 3b 0a 20 20 62 6c 6f 62 61 72 tion();. blobar
1ef0: 72 61 79 5f 7a 65 72 6f 28 61 54 6f 6b 65 6e 2c ray_zero(aToken,
1f00: 20 63 6f 75 6e 74 28 61 54 6f 6b 65 6e 29 29 3b count(aToken));
1f10: 0a 20 20 63 67 69 5f 73 65 74 5f 63 6f 6e 74 65 . cgi_set_conte
1f20: 6e 74 5f 74 79 70 65 28 67 2e 7a 43 6f 6e 74 65 nt_type(g.zConte
1f30: 6e 74 54 79 70 65 29 3b 0a 20 20 62 6c 6f 62 5f ntType);. blob_
1f40: 7a 65 72 6f 28 26 65 72 72 6d 73 67 29 3b 0a 20 zero(&errmsg);.
1f50: 20 64 62 5f 6d 75 6c 74 69 5f 65 78 65 63 28 0a db_multi_exec(.
1f60: 20 20 20 20 20 22 43 52 45 41 54 45 20 54 45 4d "CREATE TEM
1f70: 50 20 54 41 42 4c 45 20 6f 6e 72 65 6d 6f 74 65 P TABLE onremote
1f80: 28 72 69 64 20 49 4e 54 45 47 45 52 20 50 52 49 (rid INTEGER PRI
1f90: 4d 41 52 59 20 4b 45 59 29 3b 22 20 2f 2a 20 43 MARY KEY);" /* C
1fa0: 6c 69 65 6e 74 20 68 61 73 20 2a 2f 0a 20 20 20 lient has */.
1fb0: 20 20 22 43 52 45 41 54 45 20 54 45 4d 50 20 54 "CREATE TEMP T
1fc0: 41 42 4c 45 20 70 65 6e 64 69 6e 67 28 72 69 64 ABLE pending(rid
1fd0: 20 49 4e 54 45 47 45 52 20 50 52 49 4d 41 52 59 INTEGER PRIMARY
1fe0: 20 4b 45 59 29 3b 22 20 20 2f 2a 20 43 6c 69 65 KEY);" /* Clie
1ff0: 6e 74 20 6e 65 65 64 73 20 2a 2f 0a 20 20 29 3b nt needs */. );
2000: 0a 20 20 77 68 69 6c 65 28 20 62 6c 6f 62 5f 6c . while( blob_l
2010: 69 6e 65 28 26 67 2e 63 67 69 49 6e 2c 20 26 6c ine(&g.cgiIn, &l
2020: 69 6e 65 29 20 29 7b 0a 20 20 20 20 6e 54 6f 6b ine) ){. nTok
2030: 65 6e 20 3d 20 62 6c 6f 62 5f 74 6f 6b 65 6e 69 en = blob_tokeni
2040: 7a 65 28 26 6c 69 6e 65 2c 20 61 54 6f 6b 65 6e ze(&line, aToken
2050: 2c 20 63 6f 75 6e 74 28 61 54 6f 6b 65 6e 29 29 , count(aToken))
2060: 3b 0a 0a 20 20 20 20 2f 2a 20 20 20 66 69 6c 65 ;.. /* file
2070: 20 55 55 49 44 20 53 49 5a 45 20 5c 6e 20 43 4f UUID SIZE \n CO
2080: 4e 54 45 4e 54 0a 20 20 20 20 2a 2a 20 20 20 66 NTENT. ** f
2090: 69 6c 65 20 55 55 49 44 20 44 45 4c 54 41 53 52 ile UUID DELTASR
20a0: 43 20 53 49 5a 45 20 5c 6e 20 43 4f 4e 54 45 4e C SIZE \n CONTEN
20b0: 54 0a 20 20 20 20 2a 2a 0a 20 20 20 20 2a 2a 20 T. **. **
20c0: 41 63 63 65 70 74 20 61 20 66 69 6c 65 20 66 72 Accept a file fr
20d0: 6f 6d 20 74 68 65 20 63 6c 69 65 6e 74 2e 0a 20 om the client..
20e0: 20 20 20 2a 2f 0a 20 20 20 20 69 66 28 20 62 6c */. if( bl
20f0: 6f 62 5f 65 71 28 26 61 54 6f 6b 65 6e 5b 30 5d ob_eq(&aToken[0]
2100: 2c 20 22 66 69 6c 65 22 29 20 26 26 20 6e 54 6f , "file") && nTo
2110: 6b 65 6e 3e 3d 32 20 26 26 20 6e 54 6f 6b 65 6e ken>=2 && nToken
2120: 3c 3d 33 20 29 7b 0a 20 20 20 20 20 20 69 66 28 <=3 ){. if(
2130: 20 21 69 73 50 75 73 68 20 29 7b 0a 20 20 20 20 !isPush ){.
2140: 20 20 20 20 63 67 69 5f 72 65 73 65 74 5f 63 6f cgi_reset_co
2150: 6e 74 65 6e 74 28 29 3b 0a 20 20 20 20 20 20 20 ntent();.
2160: 20 40 20 65 72 72 6f 72 20 6e 6f 74 5c 73 61 75 @ error not\sau
2170: 74 68 6f 72 69 7a 65 64 5c 73 74 6f 5c 73 77 72 thorized\sto\swr
2180: 69 74 65 0a 20 20 20 20 20 20 20 20 6e 45 72 72 ite. nErr
2190: 2b 2b 3b 0a 20 20 20 20 20 20 20 20 62 72 65 61 ++;. brea
21a0: 6b 3b 0a 20 20 20 20 20 20 7d 0a 20 20 20 20 20 k;. }.
21b0: 20 78 66 65 72 5f 61 63 63 65 70 74 5f 66 69 6c xfer_accept_fil
21c0: 65 28 26 67 2e 63 67 69 49 6e 2c 20 61 54 6f 6b e(&g.cgiIn, aTok
21d0: 65 6e 2c 20 6e 54 6f 6b 65 6e 2c 20 26 65 72 72 en, nToken, &err
21e0: 6d 73 67 29 3b 0a 20 20 20 20 20 20 69 66 28 20 msg);. if(
21f0: 62 6c 6f 62 5f 73 69 7a 65 28 26 65 72 72 6d 73 blob_size(&errms
2200: 67 29 20 29 7b 0a 20 20 20 20 20 20 20 20 63 67 g) ){. cg
2210: 69 5f 72 65 73 65 74 5f 63 6f 6e 74 65 6e 74 28 i_reset_content(
2220: 29 3b 0a 20 20 20 20 20 20 20 20 40 20 65 72 72 );. @ err
2230: 6f 72 20 25 54 28 62 6c 6f 62 5f 73 74 72 28 26 or %T(blob_str(&
2240: 65 72 72 6d 73 67 29 29 0a 20 20 20 20 20 20 20 errmsg)).
2250: 20 6e 45 72 72 2b 2b 3b 0a 20 20 20 20 20 20 20 nErr++;.
2260: 20 62 72 65 61 6b 3b 0a 20 20 20 20 20 20 7d 0a break;. }.
2270: 20 20 20 20 7d 65 6c 73 65 0a 0a 20 20 20 20 2f }else.. /
2280: 2a 20 20 20 67 69 6d 6d 65 20 55 55 49 44 0a 20 * gimme UUID.
2290: 20 20 20 2a 2a 0a 20 20 20 20 2a 2a 20 43 6c 69 **. ** Cli
22a0: 65 6e 74 20 69 73 20 72 65 71 75 65 73 74 69 6e ent is requestin
22b0: 67 20 61 20 66 69 6c 65 0a 20 20 20 20 2a 2f 0a g a file. */.
22c0: 20 20 20 20 69 66 28 20 62 6c 6f 62 5f 65 71 28 if( blob_eq(
22d0: 26 61 54 6f 6b 65 6e 5b 30 5d 2c 20 22 67 69 6d &aToken[0], "gim
22e0: 6d 65 22 29 20 26 26 20 6e 54 6f 6b 65 6e 3d 3d me") && nToken==
22f0: 32 20 26 26 20 62 6c 6f 62 5f 69 73 5f 75 75 69 2 && blob_is_uui
2300: 64 28 26 61 54 6f 6b 65 6e 5b 31 5d 29 20 29 7b d(&aToken[1]) ){
2310: 0a 20 20 20 20 20 20 69 66 28 20 69 73 50 75 6c . if( isPul
2320: 6c 20 29 7b 0a 20 20 20 20 20 20 20 20 64 62 5f l ){. db_
2330: 6d 75 6c 74 69 5f 65 78 65 63 28 0a 20 20 20 20 multi_exec(.
2340: 20 20 20 20 20 20 22 49 4e 53 45 52 54 20 4f 52 "INSERT OR
2350: 20 49 47 4e 4f 52 45 20 49 4e 54 4f 20 70 65 6e IGNORE INTO pen
2360: 64 69 6e 67 28 72 69 64 29 20 22 0a 20 20 20 20 ding(rid) ".
2370: 20 20 20 20 20 20 22 53 45 4c 45 43 54 20 72 69 "SELECT ri
2380: 64 20 46 52 4f 4d 20 62 6c 6f 62 20 57 48 45 52 d FROM blob WHER
2390: 45 20 75 75 69 64 3d 25 42 20 41 4e 44 20 73 69 E uuid=%B AND si
23a0: 7a 65 3e 3d 30 22 2c 20 26 61 54 6f 6b 65 6e 5b ze>=0", &aToken[
23b0: 31 5d 0a 20 20 20 20 20 20 20 20 29 3b 0a 20 20 1]. );.
23c0: 20 20 20 20 7d 0a 20 20 20 20 7d 65 6c 73 65 0a }. }else.
23d0: 0a 20 20 20 20 2f 2a 20 20 20 69 67 6f 74 20 55 . /* igot U
23e0: 55 49 44 0a 20 20 20 20 2a 2a 20 20 20 6c 65 61 UID. ** lea
23f0: 66 20 55 55 49 44 0a 20 20 20 20 2a 2a 0a 20 20 f UUID. **.
2400: 20 20 2a 2a 20 43 6c 69 65 6e 74 20 61 6e 6e 6f ** Client anno
2410: 75 6e 63 65 73 20 74 68 61 74 20 69 74 20 68 61 unces that it ha
2420: 73 20 61 20 70 61 72 74 69 63 75 6c 61 72 20 66 s a particular f
2430: 69 6c 65 0a 20 20 20 20 2a 2f 0a 20 20 20 20 69 ile. */. i
2440: 66 28 20 6e 54 6f 6b 65 6e 3d 3d 32 0a 20 20 20 f( nToken==2.
2450: 20 20 20 20 20 20 20 26 26 20 28 62 6c 6f 62 5f && (blob_
2460: 65 71 28 26 61 54 6f 6b 65 6e 5b 30 5d 2c 20 22 eq(&aToken[0], "
2470: 69 67 6f 74 22 29 20 7c 7c 20 62 6c 6f 62 5f 65 igot") || blob_e
2480: 71 28 26 61 54 6f 6b 65 6e 5b 30 5d 2c 22 6c 65 q(&aToken[0],"le
2490: 61 66 22 29 29 0a 20 20 20 20 20 20 20 20 20 20 af")).
24a0: 26 26 20 62 6c 6f 62 5f 69 73 5f 75 75 69 64 28 && blob_is_uuid(
24b0: 26 61 54 6f 6b 65 6e 5b 31 5d 29 20 29 7b 0a 20 &aToken[1]) ){.
24c0: 20 20 20 20 20 69 66 28 20 69 73 50 75 6c 6c 20 if( isPull
24d0: 7c 7c 20 69 73 50 75 73 68 20 29 7b 0a 20 20 20 || isPush ){.
24e0: 20 20 20 20 20 69 6e 74 20 72 69 64 20 3d 20 64 int rid = d
24f0: 62 5f 69 6e 74 28 30 2c 20 22 53 45 4c 45 43 54 b_int(0, "SELECT
2500: 20 72 69 64 20 46 52 4f 4d 20 62 6c 6f 62 20 57 rid FROM blob W
2510: 48 45 52 45 20 75 75 69 64 3d 25 42 22 2c 20 26 HERE uuid=%B", &
2520: 61 54 6f 6b 65 6e 5b 31 5d 29 3b 0a 20 20 20 20 aToken[1]);.
2530: 20 20 20 20 69 66 28 20 72 69 64 3e 30 20 29 7b if( rid>0 ){
2540: 0a 20 20 20 20 20 20 20 20 20 20 64 62 5f 6d 75 . db_mu
2550: 6c 74 69 5f 65 78 65 63 28 0a 20 20 20 20 20 20 lti_exec(.
2560: 20 20 20 20 20 20 22 49 4e 53 45 52 54 20 4f 52 "INSERT OR
2570: 20 49 47 4e 4f 52 45 20 49 4e 54 4f 20 6f 6e 72 IGNORE INTO onr
2580: 65 6d 6f 74 65 28 72 69 64 29 20 56 41 4c 55 45 emote(rid) VALUE
2590: 53 28 25 64 29 22 2c 20 72 69 64 0a 20 20 20 20 S(%d)", rid.
25a0: 20 20 20 20 20 20 29 3b 0a 20 20 20 20 20 20 20 );.
25b0: 20 20 20 69 66 28 20 69 73 50 75 6c 6c 20 26 26 if( isPull &&
25c0: 20 62 6c 6f 62 5f 65 71 28 26 61 54 6f 6b 65 6e blob_eq(&aToken
25d0: 5b 30 5d 2c 20 22 6c 65 61 66 22 29 20 29 7b 0a [0], "leaf") ){.
25e0: 20 20 20 20 20 20 20 20 20 20 20 20 64 62 5f 6d db_m
25f0: 75 6c 74 69 5f 65 78 65 63 28 0a 20 20 20 20 20 ulti_exec(.
2600: 20 20 20 20 20 20 20 20 20 22 49 4e 53 45 52 54 "INSERT
2610: 20 4f 52 20 49 47 4e 4f 52 45 20 49 4e 54 4f 20 OR IGNORE INTO
2620: 70 65 6e 64 69 6e 67 28 72 69 64 29 20 22 0a 20 pending(rid) ".
2630: 20 20 20 20 20 20 20 20 20 20 20 20 20 22 53 45 "SE
2640: 4c 45 43 54 20 63 69 64 20 46 52 4f 4d 20 70 6c LECT cid FROM pl
2650: 69 6e 6b 20 57 48 45 52 45 20 70 69 64 3d 25 64 ink WHERE pid=%d
2660: 22 2c 20 72 69 64 0a 20 20 20 20 20 20 20 20 20 ", rid.
2670: 20 20 20 29 3b 0a 20 20 20 20 20 20 20 20 20 20 );.
2680: 7d 0a 20 20 20 20 20 20 20 20 7d 65 6c 73 65 20 }. }else
2690: 69 66 28 20 69 73 50 75 73 68 20 29 7b 0a 20 20 if( isPush ){.
26a0: 20 20 20 20 20 20 20 20 63 6f 6e 74 65 6e 74 5f content_
26b0: 70 75 74 28 30 2c 20 62 6c 6f 62 5f 73 74 72 28 put(0, blob_str(
26c0: 26 61 54 6f 6b 65 6e 5b 31 5d 29 29 3b 0a 20 20 &aToken[1]));.
26d0: 20 20 20 20 20 20 7d 0a 20 20 20 20 20 20 7d 0a }. }.
26e0: 20 20 20 20 7d 65 6c 73 65 0a 0a 20 20 20 20 2f }else.. /
26f0: 2a 20 20 20 20 70 75 6c 6c 20 20 53 45 52 56 45 * pull SERVE
2700: 52 43 4f 44 45 20 20 50 52 4f 4a 45 43 54 43 4f RCODE PROJECTCO
2710: 44 45 0a 20 20 20 20 2a 2a 20 20 20 20 70 75 73 DE. ** pus
2720: 68 20 20 53 45 52 56 45 52 43 4f 44 45 20 20 50 h SERVERCODE P
2730: 52 4f 4a 45 43 54 43 4f 44 45 0a 20 20 20 20 2a ROJECTCODE. *
2740: 2a 0a 20 20 20 20 2a 2a 20 54 68 65 20 63 6c 69 *. ** The cli
2750: 65 6e 74 20 77 61 6e 74 73 20 65 69 74 68 65 72 ent wants either
2760: 20 73 65 6e 64 20 6f 72 20 72 65 63 65 69 76 65 send or receive
2770: 0a 20 20 20 20 2a 2f 0a 20 20 20 20 69 66 28 20 . */. if(
2780: 6e 54 6f 6b 65 6e 3d 3d 33 0a 20 20 20 20 20 20 nToken==3.
2790: 20 20 20 20 20 20 20 20 20 26 26 20 28 62 6c 6f && (blo
27a0: 62 5f 65 71 28 26 61 54 6f 6b 65 6e 5b 30 5d 2c b_eq(&aToken[0],
27b0: 20 22 70 75 6c 6c 22 29 20 7c 7c 20 62 6c 6f 62 "pull") || blob
27c0: 5f 65 71 28 26 61 54 6f 6b 65 6e 5b 30 5d 2c 20 _eq(&aToken[0],
27d0: 22 70 75 73 68 22 29 29 0a 20 20 20 20 20 20 20 "push")).
27e0: 20 20 20 20 20 20 20 20 26 26 20 62 6c 6f 62 5f && blob_
27f0: 69 73 5f 75 75 69 64 28 26 61 54 6f 6b 65 6e 5b is_uuid(&aToken[
2800: 31 5d 29 20 26 26 20 62 6c 6f 62 5f 69 73 5f 75 1]) && blob_is_u
2810: 75 69 64 28 26 61 54 6f 6b 65 6e 5b 32 5d 29 20 uid(&aToken[2])
2820: 29 7b 0a 20 20 20 20 20 20 63 6f 6e 73 74 20 63 ){. const c
2830: 68 61 72 20 2a 7a 53 43 6f 64 65 3b 0a 20 20 20 har *zSCode;.
2840: 20 20 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a const char *z
2850: 50 43 6f 64 65 3b 0a 0a 20 20 20 20 20 20 7a 53 PCode;.. zS
2860: 43 6f 64 65 20 3d 20 64 62 5f 67 65 74 28 22 73 Code = db_get("s
2870: 65 72 76 65 72 2d 63 6f 64 65 22 2c 20 30 29 3b erver-code", 0);
2880: 0a 20 20 20 20 20 20 69 66 28 20 7a 53 43 6f 64 . if( zSCod
2890: 65 3d 3d 30 20 29 7b 0a 20 20 20 20 20 20 20 20 e==0 ){.
28a0: 66 6f 73 73 69 6c 5f 70 61 6e 69 63 28 22 6d 69 fossil_panic("mi
28b0: 73 73 69 6e 67 20 73 65 72 76 65 72 20 63 6f 64 ssing server cod
28c0: 65 22 29 3b 0a 20 20 20 20 20 20 7d 0a 20 20 20 e");. }.
28d0: 20 20 20 69 66 28 20 62 6c 6f 62 5f 65 71 5f 73 if( blob_eq_s
28e0: 74 72 28 26 61 54 6f 6b 65 6e 5b 31 5d 2c 20 7a tr(&aToken[1], z
28f0: 53 43 6f 64 65 2c 20 2d 31 29 20 29 7b 0a 20 20 SCode, -1) ){.
2900: 20 20 20 20 20 20 63 67 69 5f 72 65 73 65 74 5f cgi_reset_
2910: 63 6f 6e 74 65 6e 74 28 29 3b 0a 20 20 20 20 20 content();.
2920: 20 20 20 40 20 65 72 72 6f 72 20 73 65 72 76 65 @ error serve
2930: 72 5c 73 6c 6f 6f 70 0a 20 20 20 20 20 20 20 20 r\sloop.
2940: 6e 45 72 72 2b 2b 3b 0a 20 20 20 20 20 20 20 20 nErr++;.
2950: 62 72 65 61 6b 3b 0a 20 20 20 20 20 20 7d 0a 20 break;. }.
2960: 20 20 20 20 20 7a 50 43 6f 64 65 20 3d 20 64 62 zPCode = db
2970: 5f 67 65 74 28 22 70 72 6f 6a 65 63 74 2d 63 6f _get("project-co
2980: 64 65 22 2c 20 30 29 3b 0a 20 20 20 20 20 20 69 de", 0);. i
2990: 66 28 20 7a 50 43 6f 64 65 3d 3d 30 20 29 7b 0a f( zPCode==0 ){.
29a0: 20 20 20 20 20 20 20 20 66 6f 73 73 69 6c 5f 70 fossil_p
29b0: 61 6e 69 63 28 22 6d 69 73 73 69 6e 67 20 70 72 anic("missing pr
29c0: 6f 6a 65 63 74 20 63 6f 64 65 22 29 3b 0a 20 20 oject code");.
29d0: 20 20 20 20 7d 0a 20 20 20 20 20 20 69 66 28 20 }. if(
29e0: 21 62 6c 6f 62 5f 65 71 5f 73 74 72 28 26 61 54 !blob_eq_str(&aT
29f0: 6f 6b 65 6e 5b 32 5d 2c 20 7a 50 43 6f 64 65 2c oken[2], zPCode,
2a00: 20 2d 31 29 20 29 7b 0a 20 20 20 20 20 20 20 20 -1) ){.
2a10: 63 67 69 5f 72 65 73 65 74 5f 63 6f 6e 74 65 6e cgi_reset_conten
2a20: 74 28 29 3b 0a 20 20 20 20 20 20 20 20 40 20 65 t();. @ e
2a30: 72 72 6f 72 20 77 72 6f 6e 67 5c 73 70 72 6f 6a rror wrong\sproj
2a40: 65 63 74 0a 20 20 20 20 20 20 20 20 6e 45 72 72 ect. nErr
2a50: 2b 2b 3b 0a 20 20 20 20 20 20 20 20 62 72 65 61 ++;. brea
2a60: 6b 3b 0a 20 20 20 20 20 20 7d 0a 20 20 20 20 20 k;. }.
2a70: 20 6c 6f 67 69 6e 5f 63 68 65 63 6b 5f 63 72 65 login_check_cre
2a80: 64 65 6e 74 69 61 6c 73 28 29 3b 0a 20 20 20 20 dentials();.
2a90: 20 20 69 66 28 20 62 6c 6f 62 5f 65 71 28 26 61 if( blob_eq(&a
2aa0: 54 6f 6b 65 6e 5b 30 5d 2c 20 22 70 75 6c 6c 22 Token[0], "pull"
2ab0: 29 20 29 7b 0a 20 20 20 20 20 20 20 20 69 66 28 ) ){. if(
2ac0: 20 21 67 2e 6f 6b 52 65 61 64 20 29 7b 0a 20 20 !g.okRead ){.
2ad0: 20 20 20 20 20 20 20 20 63 67 69 5f 72 65 73 65 cgi_rese
2ae0: 74 5f 63 6f 6e 74 65 6e 74 28 29 3b 0a 20 20 20 t_content();.
2af0: 20 20 20 20 20 20 20 40 20 65 72 72 6f 72 20 6e @ error n
2b00: 6f 74 5c 73 61 75 74 68 6f 72 69 7a 65 64 5c 73 ot\sauthorized\s
2b10: 74 6f 5c 73 72 65 61 64 0a 20 20 20 20 20 20 20 to\sread.
2b20: 20 20 20 6e 45 72 72 2b 2b 3b 0a 20 20 20 20 20 nErr++;.
2b30: 20 20 20 20 20 62 72 65 61 6b 3b 0a 20 20 20 20 break;.
2b40: 20 20 20 20 7d 0a 20 20 20 20 20 20 20 20 69 73 }. is
2b50: 50 75 6c 6c 20 3d 20 31 3b 0a 20 20 20 20 20 20 Pull = 1;.
2b60: 7d 65 6c 73 65 7b 0a 20 20 20 20 20 20 20 20 69 }else{. i
2b70: 66 28 20 21 67 2e 6f 6b 57 72 69 74 65 20 29 7b f( !g.okWrite ){
2b80: 0a 20 20 20 20 20 20 20 20 20 20 63 67 69 5f 72 . cgi_r
2b90: 65 73 65 74 5f 63 6f 6e 74 65 6e 74 28 29 3b 0a eset_content();.
2ba0: 20 20 20 20 20 20 20 20 20 20 40 20 65 72 72 6f @ erro
2bb0: 72 20 6e 6f 74 5c 73 61 75 74 68 6f 72 69 7a 65 r not\sauthorize
2bc0: 64 5c 73 74 6f 5c 73 77 72 69 74 65 0a 20 20 20 d\sto\swrite.
2bd0: 20 20 20 20 20 20 20 6e 45 72 72 2b 2b 3b 0a 20 nErr++;.
2be0: 20 20 20 20 20 20 20 20 20 62 72 65 61 6b 3b 0a break;.
2bf0: 20 20 20 20 20 20 20 20 7d 0a 20 20 20 20 20 20 }.
2c00: 20 20 69 73 50 75 73 68 20 3d 20 31 3b 0a 0a 20 isPush = 1;..
2c10: 20 20 20 20 20 7d 0a 20 20 20 20 7d 65 6c 73 65 }. }else
2c20: 0a 0a 20 20 20 20 2f 2a 20 20 20 20 63 6c 6f 6e .. /* clon
2c30: 65 0a 20 20 20 20 2a 2a 0a 20 20 20 20 2a 2a 20 e. **. **
2c40: 54 68 65 20 63 6c 69 65 6e 74 20 6b 6e 6f 77 73 The client knows
2c50: 20 6e 6f 74 68 69 6e 67 2e 20 20 54 65 6c 6c 20 nothing. Tell
2c60: 61 6c 6c 2e 0a 20 20 20 20 2a 2f 0a 20 20 20 20 all.. */.
2c70: 69 66 28 20 62 6c 6f 62 5f 65 71 28 26 61 54 6f if( blob_eq(&aTo
2c80: 6b 65 6e 5b 30 5d 2c 20 22 63 6c 6f 6e 65 22 29 ken[0], "clone")
2c90: 20 29 7b 0a 20 20 20 20 20 20 6c 6f 67 69 6e 5f ){. login_
2ca0: 63 68 65 63 6b 5f 63 72 65 64 65 6e 74 69 61 6c check_credential
2cb0: 73 28 29 3b 0a 20 20 20 20 20 20 69 66 28 20 21 s();. if( !
2cc0: 67 2e 6f 6b 52 65 61 64 20 29 7b 0a 20 20 20 20 g.okRead ){.
2cd0: 20 20 20 20 63 67 69 5f 72 65 73 65 74 5f 63 6f cgi_reset_co
2ce0: 6e 74 65 6e 74 28 29 3b 0a 20 20 20 20 20 20 20 ntent();.
2cf0: 20 40 20 65 72 72 6f 72 20 6e 6f 74 5c 73 61 75 @ error not\sau
2d00: 74 68 6f 72 69 7a 65 64 5c 73 74 6f 5c 73 72 65 thorized\sto\sre
2d10: 61 64 0a 20 20 20 20 20 20 20 20 6e 45 72 72 2b ad. nErr+
2d20: 2b 3b 0a 20 20 20 20 20 20 20 20 62 72 65 61 6b +;. break
2d30: 3b 0a 20 20 20 20 20 20 7d 0a 20 20 20 20 20 20 ;. }.
2d40: 69 73 50 75 6c 6c 20 3d 20 31 3b 0a 20 20 20 20 isPull = 1;.
2d50: 20 20 40 20 70 75 73 68 20 25 73 28 64 62 5f 67 @ push %s(db_g
2d60: 65 74 28 22 73 65 72 76 65 72 2d 63 6f 64 65 22 et("server-code"
2d70: 2c 20 22 78 22 29 29 20 25 73 28 64 62 5f 67 65 , "x")) %s(db_ge
2d80: 74 28 22 70 72 6f 6a 65 63 74 2d 63 6f 64 65 22 t("project-code"
2d90: 2c 20 22 78 22 29 29 0a 20 20 20 20 20 20 64 62 , "x")). db
2da0: 5f 6d 75 6c 74 69 5f 65 78 65 63 28 0a 20 20 20 _multi_exec(.
2db0: 20 20 20 20 20 22 49 4e 53 45 52 54 20 4f 52 20 "INSERT OR
2dc0: 49 47 4e 4f 52 45 20 49 4e 54 4f 20 70 65 6e 64 IGNORE INTO pend
2dd0: 69 6e 67 28 72 69 64 29 20 22 0a 20 20 20 20 20 ing(rid) ".
2de0: 20 20 20 22 53 45 4c 45 43 54 20 72 69 64 20 46 "SELECT rid F
2df0: 52 4f 4d 20 62 6c 6f 62 20 57 48 45 52 45 20 73 ROM blob WHERE s
2e00: 69 7a 65 3e 3d 30 22 0a 20 20 20 20 20 20 29 3b ize>=0". );
2e10: 0a 20 20 20 20 7d 65 6c 73 65 0a 0a 20 20 20 20 . }else..
2e20: 2f 2a 20 20 20 20 6c 6f 67 69 6e 20 20 55 53 45 /* login USE
2e30: 52 20 20 4e 4f 4e 43 45 20 20 53 49 47 4e 41 54 R NONCE SIGNAT
2e40: 55 52 45 0a 20 20 20 20 2a 2a 0a 20 20 20 20 2a URE. **. *
2e50: 2a 20 43 68 65 63 6b 20 66 6f 72 20 61 20 76 61 * Check for a va
2e60: 6c 69 64 20 6c 6f 67 69 6e 2e 20 20 54 68 69 73 lid login. This
2e70: 20 68 61 73 20 74 6f 20 68 61 70 70 65 6e 20 62 has to happen b
2e80: 65 66 6f 72 65 20 61 6e 79 74 68 69 6e 67 20 65 efore anything e
2e90: 6c 73 65 2e 0a 20 20 20 20 2a 2f 0a 20 20 20 20 lse.. */.
2ea0: 69 66 28 20 62 6c 6f 62 5f 65 71 28 26 61 54 6f if( blob_eq(&aTo
2eb0: 6b 65 6e 5b 30 5d 2c 20 22 6c 6f 67 69 6e 22 29 ken[0], "login")
2ec0: 20 26 26 20 6e 54 6f 6b 65 6e 3d 3d 34 20 29 7b && nToken==4 ){
2ed0: 0a 20 20 20 20 20 20 69 66 28 20 64 69 73 61 62 . if( disab
2ee0: 6c 65 4c 6f 67 69 6e 20 29 7b 0a 20 20 20 20 20 leLogin ){.
2ef0: 20 20 20 67 2e 6f 6b 52 65 61 64 20 3d 20 67 2e g.okRead = g.
2f00: 6f 6b 57 72 69 74 65 20 3d 20 31 3b 0a 20 20 20 okWrite = 1;.
2f10: 20 20 20 7d 65 6c 73 65 7b 0a 20 20 20 20 20 20 }else{.
2f20: 20 20 63 68 65 63 6b 5f 6c 6f 67 69 6e 28 26 61 check_login(&a
2f30: 54 6f 6b 65 6e 5b 31 5d 2c 20 26 61 54 6f 6b 65 Token[1], &aToke
2f40: 6e 5b 32 5d 2c 20 26 61 54 6f 6b 65 6e 5b 33 5d n[2], &aToken[3]
2f50: 29 3b 0a 20 20 20 20 20 20 7d 0a 20 20 20 20 7d );. }. }
2f60: 65 6c 73 65 0a 0a 20 20 20 20 2f 2a 20 55 6e 6b else.. /* Unk
2f70: 6e 6f 77 6e 20 6d 65 73 73 61 67 65 0a 20 20 20 nown message.
2f80: 20 2a 2f 0a 20 20 20 20 7b 0a 20 20 20 20 20 20 */. {.
2f90: 63 67 69 5f 72 65 73 65 74 5f 63 6f 6e 74 65 6e cgi_reset_conten
2fa0: 74 28 29 3b 0a 20 20 20 20 20 20 40 20 65 72 72 t();. @ err
2fb0: 6f 72 20 62 61 64 5c 73 63 6f 6d 6d 61 6e 64 3a or bad\scommand:
2fc0: 5c 73 25 46 28 62 6c 6f 62 5f 73 74 72 28 26 6c \s%F(blob_str(&l
2fd0: 69 6e 65 29 29 0a 20 20 20 20 7d 0a 20 20 20 20 ine)). }.
2fe0: 62 6c 6f 62 61 72 72 61 79 5f 72 65 73 65 74 28 blobarray_reset(
2ff0: 61 54 6f 6b 65 6e 2c 20 6e 54 6f 6b 65 6e 29 3b aToken, nToken);
3000: 0a 20 20 7d 0a 0a 20 20 2f 2a 20 54 68 65 20 69 . }.. /* The i
3010: 6e 70 75 74 20 6d 65 73 73 61 67 65 20 68 61 73 nput message has
3020: 20 6e 6f 77 20 62 65 65 6e 20 70 72 6f 63 65 73 now been proces
3030: 73 65 64 2e 20 20 47 65 6e 65 72 61 74 65 20 61 sed. Generate a
3040: 20 72 65 70 6c 79 2e 20 2a 2f 0a 20 20 69 66 28 reply. */. if(
3050: 20 69 73 50 75 73 68 20 29 7b 0a 20 20 20 20 53 isPush ){. S
3060: 74 6d 74 20 71 3b 0a 20 20 20 20 64 62 5f 70 72 tmt q;. db_pr
3070: 65 70 61 72 65 28 26 71 2c 20 22 53 45 4c 45 43 epare(&q, "SELEC
3080: 54 20 75 75 69 64 20 46 52 4f 4d 20 62 6c 6f 62 T uuid FROM blob
3090: 20 57 48 45 52 45 20 73 69 7a 65 3c 30 22 29 3b WHERE size<0");
30a0: 0a 20 20 20 20 77 68 69 6c 65 28 20 64 62 5f 73 . while( db_s
30b0: 74 65 70 28 26 71 29 3d 3d 53 51 4c 49 54 45 5f tep(&q)==SQLITE_
30c0: 52 4f 57 20 29 7b 0a 20 20 20 20 20 20 63 6f 6e ROW ){. con
30d0: 73 74 20 63 68 61 72 20 2a 7a 55 75 69 64 20 3d st char *zUuid =
30e0: 20 64 62 5f 63 6f 6c 75 6d 6e 5f 74 65 78 74 28 db_column_text(
30f0: 26 71 2c 20 30 29 3b 0a 20 20 20 20 20 20 40 20 &q, 0);. @
3100: 67 69 6d 6d 65 20 25 73 28 7a 55 75 69 64 29 0a gimme %s(zUuid).
3110: 20 20 20 20 7d 0a 20 20 20 20 64 62 5f 66 69 6e }. db_fin
3120: 61 6c 69 7a 65 28 26 71 29 3b 0a 20 20 7d 0a 20 alize(&q);. }.
3130: 20 69 66 28 20 69 73 50 75 6c 6c 20 29 7b 0a 20 if( isPull ){.
3140: 20 20 20 73 65 6e 64 5f 61 6c 6c 5f 70 65 6e 64 send_all_pend
3150: 69 6e 67 28 30 29 3b 0a 20 20 7d 0a 20 20 69 66 ing(0);. }. if
3160: 28 20 69 73 50 75 73 68 20 7c 7c 20 69 73 50 75 ( isPush || isPu
3170: 6c 6c 20 29 7b 0a 20 20 20 20 2f 2a 20 41 6c 77 ll ){. /* Alw
3180: 61 79 73 20 73 65 6e 64 20 6f 75 72 20 6c 65 61 ays send our lea
3190: 76 65 73 20 2a 2f 0a 20 20 20 20 53 74 6d 74 20 ves */. Stmt
31a0: 71 3b 0a 20 20 20 20 64 62 5f 70 72 65 70 61 72 q;. db_prepar
31b0: 65 28 26 71 2c 20 0a 20 20 20 20 20 20 20 22 53 e(&q, . "S
31c0: 45 4c 45 43 54 20 75 75 69 64 20 46 52 4f 4d 20 ELECT uuid FROM
31d0: 62 6c 6f 62 20 57 48 45 52 45 20 72 69 64 20 49 blob WHERE rid I
31e0: 4e 22 0a 20 20 20 20 20 20 20 22 20 20 28 53 45 N". " (SE
31f0: 4c 45 43 54 20 63 69 64 20 46 52 4f 4d 20 70 6c LECT cid FROM pl
3200: 69 6e 6b 20 45 58 43 45 50 54 20 53 45 4c 45 43 ink EXCEPT SELEC
3210: 54 20 70 69 64 20 46 52 4f 4d 20 70 6c 69 6e 6b T pid FROM plink
3220: 29 22 0a 20 20 20 20 29 3b 0a 20 20 20 20 77 68 )". );. wh
3230: 69 6c 65 28 20 64 62 5f 73 74 65 70 28 26 71 29 ile( db_step(&q)
3240: 3d 3d 53 51 4c 49 54 45 5f 52 4f 57 20 29 7b 0a ==SQLITE_ROW ){.
3250: 20 20 20 20 20 20 63 6f 6e 73 74 20 63 68 61 72 const char
3260: 20 2a 7a 55 75 69 64 20 3d 20 64 62 5f 63 6f 6c *zUuid = db_col
3270: 75 6d 6e 5f 74 65 78 74 28 26 71 2c 20 30 29 3b umn_text(&q, 0);
3280: 0a 20 20 20 20 20 20 40 20 6c 65 61 66 20 25 73 . @ leaf %s
3290: 28 7a 55 75 69 64 29 0a 20 20 20 20 7d 0a 20 20 (zUuid). }.
32a0: 20 20 64 62 5f 66 69 6e 61 6c 69 7a 65 28 26 71 db_finalize(&q
32b0: 29 3b 0a 20 20 7d 0a 0a 20 20 64 62 5f 65 6e 64 );. }.. db_end
32c0: 5f 74 72 61 6e 73 61 63 74 69 6f 6e 28 30 29 3b _transaction(0);
32d0: 0a 7d 0a 0a 2f 2a 0a 2a 2a 20 43 4f 4d 4d 41 4e .}../*.** COMMAN
32e0: 44 3a 20 74 65 73 74 2d 78 66 65 72 0a 2a 2a 0a D: test-xfer.**.
32f0: 2a 2a 20 54 68 69 73 20 63 6f 6d 6d 61 6e 64 20 ** This command
3300: 69 73 20 75 73 65 64 20 66 6f 72 20 64 65 62 75 is used for debu
3310: 67 67 69 6e 67 20 74 68 65 20 73 65 72 76 65 72 gging the server
3320: 2e 20 20 54 68 65 72 65 20 69 73 20 61 20 73 69 . There is a si
3330: 6e 67 6c 65 0a 2a 2a 20 61 72 67 75 6d 65 6e 74 ngle.** argument
3340: 20 77 68 69 63 68 20 69 73 20 74 68 65 20 75 6e which is the un
3350: 63 6f 6d 70 72 65 73 73 65 64 20 63 6f 6e 74 65 compressed conte
3360: 6e 74 20 6f 66 20 61 6e 20 22 78 66 65 72 22 20 nt of an "xfer"
3370: 6d 65 73 73 61 67 65 0a 2a 2a 20 66 72 6f 6d 20 message.** from
3380: 63 6c 69 65 6e 74 20 74 6f 20 73 65 72 76 65 72 client to server
3390: 2e 20 20 54 68 69 73 20 63 6f 6d 6d 61 6e 64 20 . This command
33a0: 69 6e 74 65 72 70 72 65 74 73 20 74 68 61 74 20 interprets that
33b0: 6d 65 73 73 61 67 65 20 61 73 0a 2a 2a 20 69 66 message as.** if
33c0: 20 68 61 64 20 62 65 65 6e 20 72 65 63 65 69 76 had been receiv
33d0: 65 64 20 62 79 20 74 68 65 20 73 65 72 76 65 72 ed by the server
33e0: 2e 0a 2a 2a 0a 2a 2a 20 4f 6e 20 74 68 65 20 63 ..**.** On the c
33f0: 6c 69 65 6e 74 20 73 69 64 65 2c 20 72 75 6e 3a lient side, run:
3400: 0a 2a 2a 0a 2a 2a 20 20 20 20 20 20 66 6f 73 73 .**.** foss
3410: 69 6c 20 70 75 73 68 20 68 74 74 70 3a 2f 2f 62 il push http://b
3420: 6f 67 75 73 2f 20 2d 2d 68 74 74 70 74 72 61 63 ogus/ --httptrac
3430: 65 0a 2a 2a 0a 2a 2a 20 4f 72 20 61 20 73 69 6d e.**.** Or a sim
3440: 69 6c 61 72 20 63 6f 6d 6d 61 6e 64 20 74 6f 20 ilar command to
3450: 70 72 6f 76 69 64 65 20 74 68 65 20 6f 75 74 70 provide the outp
3460: 75 74 2e 20 20 54 68 65 20 63 6f 6e 74 65 6e 74 ut. The content
3470: 20 6f 66 20 74 68 65 0a 2a 2a 20 6d 65 73 73 61 of the.** messa
3480: 67 65 20 77 69 6c 6c 20 61 70 70 65 61 72 20 6f ge will appear o
3490: 6e 20 73 74 61 6e 64 61 72 64 20 6f 75 74 70 75 n standard outpu
34a0: 74 2e 20 20 43 61 70 74 75 72 65 20 74 68 69 73 t. Capture this
34b0: 20 6d 65 73 73 61 67 65 0a 2a 2a 20 69 6e 74 6f message.** into
34c0: 20 61 20 66 69 6c 65 20 6e 61 6d 65 64 20 28 66 a file named (f
34d0: 6f 72 20 65 78 61 6d 70 6c 65 29 20 6f 75 74 2e or example) out.
34e0: 74 78 74 2e 20 20 54 68 65 6e 20 72 75 6e 20 74 txt. Then run t
34f0: 68 65 0a 2a 2a 20 73 65 72 76 65 72 20 69 6e 20 he.** server in
3500: 67 64 62 3a 0a 2a 2a 0a 2a 2a 20 20 20 20 20 67 gdb:.**.** g
3510: 64 62 20 66 6f 73 73 69 6c 0a 2a 2a 20 20 20 20 db fossil.**
3520: 20 72 20 74 65 73 74 2d 78 66 65 72 20 6f 75 74 r test-xfer out
3530: 2e 74 78 74 0a 2a 2f 0a 76 6f 69 64 20 63 6d 64 .txt.*/.void cmd
3540: 5f 74 65 73 74 5f 78 66 65 72 28 76 6f 69 64 29 _test_xfer(void)
3550: 7b 0a 20 20 69 6e 74 20 6e 6f 74 55 73 65 64 3b {. int notUsed;
3560: 0a 20 20 69 66 28 20 67 2e 61 72 67 63 21 3d 32 . if( g.argc!=2
3570: 20 26 26 20 67 2e 61 72 67 63 21 3d 33 20 29 7b && g.argc!=3 ){
3580: 0a 20 20 20 20 75 73 61 67 65 28 22 3f 4d 45 53 . usage("?MES
3590: 53 41 47 45 46 49 4c 45 3f 22 29 3b 0a 20 20 7d SAGEFILE?");. }
35a0: 0a 20 20 64 62 5f 6d 75 73 74 5f 62 65 5f 77 69 . db_must_be_wi
35b0: 74 68 69 6e 5f 74 72 65 65 28 29 3b 0a 20 20 62 thin_tree();. b
35c0: 6c 6f 62 5f 7a 65 72 6f 28 26 67 2e 63 67 69 49 lob_zero(&g.cgiI
35d0: 6e 29 3b 0a 20 20 62 6c 6f 62 5f 72 65 61 64 5f n);. blob_read_
35e0: 66 72 6f 6d 5f 66 69 6c 65 28 26 67 2e 63 67 69 from_file(&g.cgi
35f0: 49 6e 2c 20 67 2e 61 72 67 63 3d 3d 32 20 3f 20 In, g.argc==2 ?
3600: 22 2d 22 20 3a 20 67 2e 61 72 67 76 5b 32 5d 29 "-" : g.argv[2])
3610: 3b 0a 20 20 64 69 73 61 62 6c 65 4c 6f 67 69 6e ;. disableLogin
3620: 20 3d 20 31 3b 0a 20 20 70 61 67 65 5f 78 66 65 = 1;. page_xfe
3630: 72 28 29 3b 0a 20 20 70 72 69 6e 74 66 28 22 25 r();. printf("%
3640: 73 5c 6e 22 2c 20 63 67 69 5f 65 78 74 72 61 63 s\n", cgi_extrac
3650: 74 5f 63 6f 6e 74 65 6e 74 28 26 6e 6f 74 55 73 t_content(¬Us
3660: 65 64 29 29 3b 0a 7d 0a 0a 0a 2f 2a 0a 2a 2a 20 ed));.}.../*.**
3670: 53 79 6e 63 20 74 6f 20 74 68 65 20 68 6f 73 74 Sync to the host
3680: 20 69 64 65 6e 74 69 66 69 65 64 20 69 6e 20 67 identified in g
3690: 2e 75 72 6c 4e 61 6d 65 20 61 6e 64 20 67 2e 75 .urlName and g.u
36a0: 72 6c 50 61 74 68 2e 20 20 54 68 69 73 0a 2a 2a rlPath. This.**
36b0: 20 72 6f 75 74 69 6e 65 20 69 73 20 63 61 6c 6c routine is call
36c0: 65 64 20 62 79 20 74 68 65 20 63 6c 69 65 6e 74 ed by the client
36d0: 2e 0a 2a 2a 0a 2a 2a 20 52 65 63 6f 72 64 73 20 ..**.** Records
36e0: 61 72 65 20 70 75 73 68 65 64 20 74 6f 20 74 68 are pushed to th
36f0: 65 20 73 65 72 76 65 72 20 69 66 20 70 75 73 68 e server if push
3700: 46 6c 61 67 20 69 73 20 74 72 75 65 2e 20 20 52 Flag is true. R
3710: 65 63 6f 72 64 73 0a 2a 2a 20 61 72 65 20 70 75 ecords.** are pu
3720: 6c 6c 65 64 20 69 66 20 70 75 6c 6c 46 6c 61 67 lled if pullFlag
3730: 20 69 73 20 74 72 75 65 2e 20 20 41 20 66 75 6c is true. A ful
3740: 6c 20 73 79 6e 63 20 6f 63 63 75 72 73 20 69 66 l sync occurs if
3750: 20 62 6f 74 68 20 61 72 65 0a 2a 2a 20 74 72 75 both are.** tru
3760: 65 2e 0a 2a 2f 0a 76 6f 69 64 20 63 6c 69 65 6e e..*/.void clien
3770: 74 5f 73 79 6e 63 28 69 6e 74 20 70 75 73 68 46 t_sync(int pushF
3780: 6c 61 67 2c 20 69 6e 74 20 70 75 6c 6c 46 6c 61 lag, int pullFla
3790: 67 2c 20 69 6e 74 20 63 6c 6f 6e 65 46 6c 61 67 g, int cloneFlag
37a0: 29 7b 0a 20 20 69 6e 74 20 67 6f 20 3d 20 31 3b ){. int go = 1;
37b0: 20 20 20 20 20 20 20 20 2f 2a 20 4c 6f 6f 70 20 /* Loop
37c0: 75 6e 74 69 6c 20 7a 65 72 6f 20 2a 2f 0a 20 20 until zero */.
37d0: 69 6e 74 20 6e 54 6f 6b 65 6e 3b 0a 20 20 63 6f int nToken;. co
37e0: 6e 73 74 20 63 68 61 72 20 2a 7a 53 43 6f 64 65 nst char *zSCode
37f0: 20 3d 20 64 62 5f 67 65 74 28 22 73 65 72 76 65 = db_get("serve
3800: 72 2d 63 6f 64 65 22 2c 20 22 78 22 29 3b 0a 20 r-code", "x");.
3810: 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a 50 43 const char *zPC
3820: 6f 64 65 20 3d 20 64 62 5f 67 65 74 28 22 70 72 ode = db_get("pr
3830: 6f 6a 65 63 74 2d 63 6f 64 65 22 2c 20 30 29 3b oject-code", 0);
3840: 0a 20 20 69 6e 74 20 6e 46 69 6c 65 20 3d 20 30 . int nFile = 0
3850: 3b 0a 20 20 69 6e 74 20 6e 4d 73 67 20 3d 20 30 ;. int nMsg = 0
3860: 3b 0a 20 20 69 6e 74 20 6e 52 65 71 20 3d 20 30 ;. int nReq = 0
3870: 3b 0a 20 20 69 6e 74 20 6e 46 69 6c 65 53 65 6e ;. int nFileSen
3880: 64 3b 0a 20 20 69 6e 74 20 6e 4e 6f 46 69 6c 65 d;. int nNoFile
3890: 43 79 63 6c 65 20 3d 20 30 3b 0a 20 20 42 6c 6f Cycle = 0;. Blo
38a0: 62 20 73 65 6e 64 3b 20 20 20 20 20 20 20 20 2f b send; /
38b0: 2a 20 54 65 78 74 20 77 65 20 61 72 65 20 73 65 * Text we are se
38c0: 6e 64 69 6e 67 20 74 6f 20 74 68 65 20 73 65 72 nding to the ser
38d0: 76 65 72 20 2a 2f 0a 20 20 42 6c 6f 62 20 72 65 ver */. Blob re
38e0: 63 76 3b 20 20 20 20 20 20 20 20 2f 2a 20 52 65 cv; /* Re
38f0: 70 6c 79 20 77 65 20 67 6f 74 20 62 61 63 6b 20 ply we got back
3900: 66 72 6f 6d 20 74 68 65 20 73 65 72 76 65 72 20 from the server
3910: 2a 2f 0a 20 20 42 6c 6f 62 20 6c 69 6e 65 3b 20 */. Blob line;
3920: 20 20 20 20 20 20 20 2f 2a 20 41 20 73 69 6e 67 /* A sing
3930: 6c 65 20 6c 69 6e 65 20 6f 66 20 74 68 65 20 72 le line of the r
3940: 65 70 6c 79 20 2a 2f 0a 20 20 42 6c 6f 62 20 61 eply */. Blob a
3950: 54 6f 6b 65 6e 5b 35 5d 3b 20 20 20 2f 2a 20 41 Token[5]; /* A
3960: 20 74 6f 6b 65 6e 69 7a 61 74 69 6f 6e 20 6f 66 tokenization of
3970: 20 6c 69 6e 65 20 2a 2f 0a 20 20 42 6c 6f 62 20 line */. Blob
3980: 65 72 72 6d 73 67 3b 20 20 20 20 20 20 2f 2a 20 errmsg; /*
3990: 45 72 72 6f 72 20 6d 65 73 73 61 67 65 20 2a 2f Error message */
39a0: 0a 0a 20 20 61 73 73 65 72 74 28 20 70 75 73 68 .. assert( push
39b0: 46 6c 61 67 20 7c 7c 20 70 75 6c 6c 46 6c 61 67 Flag || pullFlag
39c0: 20 7c 7c 20 63 6c 6f 6e 65 46 6c 61 67 20 29 3b || cloneFlag );
39d0: 0a 20 20 61 73 73 65 72 74 28 20 21 67 2e 75 72 . assert( !g.ur
39e0: 6c 49 73 46 69 6c 65 20 29 3b 20 20 20 20 20 20 lIsFile );
39f0: 20 20 20 20 2f 2a 20 54 68 69 73 20 6f 6e 6c 79 /* This only
3a00: 20 77 6f 72 6b 73 20 66 6f 72 20 6e 65 74 77 6f works for netwo
3a10: 72 6b 69 6e 67 20 2a 2f 0a 0a 20 20 64 62 5f 62 rking */.. db_b
3a20: 65 67 69 6e 5f 74 72 61 6e 73 61 63 74 69 6f 6e egin_transaction
3a30: 28 29 3b 0a 20 20 64 62 5f 6d 75 6c 74 69 5f 65 ();. db_multi_e
3a40: 78 65 63 28 0a 20 20 20 20 2f 2a 20 52 65 63 6f xec(. /* Reco
3a50: 72 64 73 20 77 68 69 63 68 20 77 65 20 6b 6e 6f rds which we kno
3a60: 77 20 74 68 65 20 6f 74 68 65 72 20 73 69 64 65 w the other side
3a70: 20 61 6c 73 6f 20 68 61 73 20 2a 2f 0a 20 20 20 also has */.
3a80: 20 22 43 52 45 41 54 45 20 54 45 4d 50 20 54 41 "CREATE TEMP TA
3a90: 42 4c 45 20 6f 6e 72 65 6d 6f 74 65 28 72 69 64 BLE onremote(rid
3aa0: 20 49 4e 54 45 47 45 52 20 50 52 49 4d 41 52 59 INTEGER PRIMARY
3ab0: 20 4b 45 59 29 3b 22 0a 20 20 20 20 2f 2a 20 52 KEY);". /* R
3ac0: 65 63 6f 72 64 73 20 77 65 20 6b 6e 6f 77 20 74 ecords we know t
3ad0: 68 65 20 6f 74 68 65 72 20 73 69 64 65 20 6e 65 he other side ne
3ae0: 65 64 73 20 2a 2f 0a 20 20 20 20 22 43 52 45 41 eds */. "CREA
3af0: 54 45 20 54 45 4d 50 20 54 41 42 4c 45 20 70 65 TE TEMP TABLE pe
3b00: 6e 64 69 6e 67 28 72 69 64 20 49 4e 54 45 47 45 nding(rid INTEGE
3b10: 52 20 50 52 49 4d 41 52 59 20 4b 45 59 29 3b 22 R PRIMARY KEY);"
3b20: 0a 20 20 29 3b 0a 20 20 62 6c 6f 62 61 72 72 61 . );. blobarra
3b30: 79 5f 7a 65 72 6f 28 61 54 6f 6b 65 6e 2c 20 63 y_zero(aToken, c
3b40: 6f 75 6e 74 28 61 54 6f 6b 65 6e 29 29 3b 0a 20 ount(aToken));.
3b50: 20 62 6c 6f 62 5f 7a 65 72 6f 28 26 73 65 6e 64 blob_zero(&send
3b60: 29 3b 0a 20 20 62 6c 6f 62 5f 7a 65 72 6f 28 26 );. blob_zero(&
3b70: 72 65 63 76 29 3b 0a 20 20 62 6c 6f 62 5f 7a 65 recv);. blob_ze
3b80: 72 6f 28 26 65 72 72 6d 73 67 29 3b 0a 0a 0a 20 ro(&errmsg);...
3b90: 20 77 68 69 6c 65 28 20 67 6f 20 29 7b 0a 20 20 while( go ){.
3ba0: 20 20 67 6f 20 3d 20 30 3b 0a 20 20 20 20 6e 46 go = 0;. nF
3bb0: 69 6c 65 20 3d 20 6e 52 65 71 20 3d 20 6e 4d 73 ile = nReq = nMs
3bc0: 67 20 3d 20 30 3b 0a 0a 20 20 20 20 2f 2a 20 47 g = 0;.. /* G
3bd0: 65 6e 65 72 61 74 65 20 61 20 72 65 71 75 65 73 enerate a reques
3be0: 74 20 74 6f 20 62 65 20 73 65 6e 74 20 74 6f 20 t to be sent to
3bf0: 74 68 65 20 73 65 72 76 65 72 2e 0a 20 20 20 20 the server..
3c00: 2a 2a 20 41 6c 77 61 79 73 20 62 65 67 69 6e 20 ** Always begin
3c10: 77 69 74 68 20 61 20 63 6c 6f 6e 65 2c 20 70 75 with a clone, pu
3c20: 6c 6c 2c 20 6f 72 20 70 75 73 68 20 6d 65 73 73 ll, or push mess
3c30: 61 67 65 0a 20 20 20 20 2a 2f 0a 20 20 20 20 0a age. */. .
3c40: 20 20 20 20 69 66 28 20 63 6c 6f 6e 65 46 6c 61 if( cloneFla
3c50: 67 20 29 7b 0a 20 20 20 20 20 20 62 6c 6f 62 5f g ){. blob_
3c60: 61 70 70 65 6e 64 66 28 26 73 65 6e 64 2c 20 22 appendf(&send, "
3c70: 63 6c 6f 6e 65 5c 6e 22 29 3b 0a 20 20 20 20 20 clone\n");.
3c80: 20 70 75 73 68 46 6c 61 67 20 3d 20 30 3b 0a 20 pushFlag = 0;.
3c90: 20 20 20 20 20 70 75 6c 6c 46 6c 61 67 20 3d 20 pullFlag =
3ca0: 30 3b 0a 20 20 20 20 20 20 6e 4d 73 67 2b 2b 3b 0;. nMsg++;
3cb0: 0a 20 20 20 20 7d 65 6c 73 65 20 69 66 28 20 70 . }else if( p
3cc0: 75 6c 6c 46 6c 61 67 20 29 7b 0a 20 20 20 20 20 ullFlag ){.
3cd0: 20 62 6c 6f 62 5f 61 70 70 65 6e 64 66 28 26 73 blob_appendf(&s
3ce0: 65 6e 64 2c 20 22 70 75 6c 6c 20 25 73 20 25 73 end, "pull %s %s
3cf0: 5c 6e 22 2c 20 7a 53 43 6f 64 65 2c 20 7a 50 43 \n", zSCode, zPC
3d00: 6f 64 65 29 3b 0a 20 20 20 20 20 20 6e 4d 73 67 ode);. nMsg
3d10: 2b 2b 3b 0a 20 20 20 20 7d 0a 20 20 20 20 69 66 ++;. }. if
3d20: 28 20 70 75 73 68 46 6c 61 67 20 29 7b 0a 20 20 ( pushFlag ){.
3d30: 20 20 20 20 62 6c 6f 62 5f 61 70 70 65 6e 64 66 blob_appendf
3d40: 28 26 73 65 6e 64 2c 20 22 70 75 73 68 20 25 73 (&send, "push %s
3d50: 20 25 73 5c 6e 22 2c 20 7a 53 43 6f 64 65 2c 20 %s\n", zSCode,
3d60: 7a 50 43 6f 64 65 29 3b 0a 20 20 20 20 20 20 6e zPCode);. n
3d70: 4d 73 67 2b 2b 3b 0a 20 20 20 20 7d 0a 0a 20 20 Msg++;. }..
3d80: 20 20 69 66 28 20 70 75 6c 6c 46 6c 61 67 20 29 if( pullFlag )
3d90: 7b 0a 20 20 20 20 20 20 2f 2a 20 53 65 6e 64 20 {. /* Send
3da0: 67 69 6d 6d 65 20 6d 65 73 73 61 67 65 20 66 6f gimme message fo
3db0: 72 20 65 76 65 72 79 20 70 68 61 6e 74 6f 6d 20 r every phantom
3dc0: 74 68 61 74 20 77 65 20 68 6f 6c 64 2e 0a 20 20 that we hold..
3dd0: 20 20 20 20 2a 2f 0a 20 20 20 20 20 20 53 74 6d */. Stm
3de0: 74 20 71 3b 0a 20 20 20 20 20 20 64 62 5f 70 72 t q;. db_pr
3df0: 65 70 61 72 65 28 26 71 2c 20 22 53 45 4c 45 43 epare(&q, "SELEC
3e00: 54 20 75 75 69 64 20 46 52 4f 4d 20 62 6c 6f 62 T uuid FROM blob
3e10: 20 57 48 45 52 45 20 73 69 7a 65 3c 30 22 29 3b WHERE size<0");
3e20: 0a 20 20 20 20 20 20 77 68 69 6c 65 28 20 64 62 . while( db
3e30: 5f 73 74 65 70 28 26 71 29 3d 3d 53 51 4c 49 54 _step(&q)==SQLIT
3e40: 45 5f 52 4f 57 20 29 7b 0a 20 20 20 20 20 20 20 E_ROW ){.
3e50: 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a 55 75 const char *zUu
3e60: 69 64 20 3d 20 64 62 5f 63 6f 6c 75 6d 6e 5f 74 id = db_column_t
3e70: 65 78 74 28 26 71 2c 20 30 29 3b 0a 20 20 20 20 ext(&q, 0);.
3e80: 20 20 20 20 62 6c 6f 62 5f 61 70 70 65 6e 64 66 blob_appendf
3e90: 28 26 73 65 6e 64 2c 22 67 69 6d 6d 65 20 25 73 (&send,"gimme %s
3ea0: 5c 6e 22 2c 20 7a 55 75 69 64 29 3b 0a 20 20 20 \n", zUuid);.
3eb0: 20 20 20 20 20 6e 52 65 71 2b 2b 3b 0a 20 20 20 nReq++;.
3ec0: 20 20 20 7d 0a 20 20 20 20 20 20 64 62 5f 66 69 }. db_fi
3ed0: 6e 61 6c 69 7a 65 28 26 71 29 3b 0a 20 20 20 20 nalize(&q);.
3ee0: 7d 0a 0a 20 20 20 20 69 66 28 20 70 75 73 68 46 }.. if( pushF
3ef0: 6c 61 67 20 29 7b 0a 20 20 20 20 20 20 2f 2a 20 lag ){. /*
3f00: 53 65 6e 64 20 74 68 65 20 73 65 72 76 65 72 20 Send the server
3f10: 61 6e 79 20 66 69 6c 65 73 20 74 68 61 74 20 74 any files that t
3f20: 68 65 20 73 65 72 76 65 72 20 68 61 73 20 72 65 he server has re
3f30: 71 75 65 73 74 65 64 20 2a 2f 0a 20 20 20 20 20 quested */.
3f40: 20 6e 46 69 6c 65 20 2b 3d 20 73 65 6e 64 5f 61 nFile += send_a
3f50: 6c 6c 5f 70 65 6e 64 69 6e 67 28 26 73 65 6e 64 ll_pending(&send
3f60: 29 3b 0a 20 20 20 20 7d 0a 0a 20 20 20 20 69 66 );. }.. if
3f70: 28 20 70 75 6c 6c 46 6c 61 67 20 7c 7c 20 70 75 ( pullFlag || pu
3f80: 73 68 46 6c 61 67 20 29 7b 0a 20 20 20 20 20 20 shFlag ){.
3f90: 2f 2a 20 41 6c 77 61 79 73 20 73 65 6e 64 20 6f /* Always send o
3fa0: 75 72 20 6c 65 61 76 65 73 20 2a 2f 0a 20 20 20 ur leaves */.
3fb0: 20 20 20 53 74 6d 74 20 71 3b 0a 20 20 20 20 20 Stmt q;.
3fc0: 20 64 62 5f 70 72 65 70 61 72 65 28 26 71 2c 20 db_prepare(&q,
3fd0: 0a 20 20 20 20 20 20 20 20 20 22 53 45 4c 45 43 . "SELEC
3fe0: 54 20 75 75 69 64 20 46 52 4f 4d 20 62 6c 6f 62 T uuid FROM blob
3ff0: 20 57 48 45 52 45 20 72 69 64 20 49 4e 22 0a 20 WHERE rid IN".
4000: 20 20 20 20 20 20 20 20 22 20 20 28 53 45 4c 45 " (SELE
4010: 43 54 20 63 69 64 20 46 52 4f 4d 20 70 6c 69 6e CT cid FROM plin
4020: 6b 20 45 58 43 45 50 54 20 53 45 4c 45 43 54 20 k EXCEPT SELECT
4030: 70 69 64 20 46 52 4f 4d 20 70 6c 69 6e 6b 29 22 pid FROM plink)"
4040: 0a 20 20 20 20 20 20 29 3b 0a 20 20 20 20 20 20 . );.
4050: 77 68 69 6c 65 28 20 64 62 5f 73 74 65 70 28 26 while( db_step(&
4060: 71 29 3d 3d 53 51 4c 49 54 45 5f 52 4f 57 20 29 q)==SQLITE_ROW )
4070: 7b 0a 20 20 20 20 20 20 20 20 63 6f 6e 73 74 20 {. const
4080: 63 68 61 72 20 2a 7a 55 75 69 64 20 3d 20 64 62 char *zUuid = db
4090: 5f 63 6f 6c 75 6d 6e 5f 74 65 78 74 28 26 71 2c _column_text(&q,
40a0: 20 30 29 3b 0a 20 20 20 20 20 20 20 20 62 6c 6f 0);. blo
40b0: 62 5f 61 70 70 65 6e 64 66 28 26 73 65 6e 64 2c b_appendf(&send,
40c0: 20 22 6c 65 61 66 20 25 73 5c 6e 22 2c 20 7a 55 "leaf %s\n", zU
40d0: 75 69 64 29 3b 0a 20 20 20 20 20 20 20 20 6e 4d uid);. nM
40e0: 73 67 2b 2b 3b 0a 20 20 20 20 20 20 7d 0a 20 20 sg++;. }.
40f0: 20 20 20 20 64 62 5f 66 69 6e 61 6c 69 7a 65 28 db_finalize(
4100: 26 71 29 3b 0a 20 20 20 20 7d 0a 0a 20 20 20 20 &q);. }..
4110: 2f 2a 20 45 78 63 68 61 6e 67 65 20 6d 65 73 73 /* Exchange mess
4120: 61 67 65 73 20 77 69 74 68 20 74 68 65 20 73 65 ages with the se
4130: 72 76 65 72 20 2a 2f 0a 20 20 20 20 70 72 69 6e rver */. prin
4140: 74 66 28 22 53 65 6e 64 3a 20 20 20 20 20 20 25 tf("Send: %
4150: 64 20 66 69 6c 65 73 2c 20 25 64 20 72 65 71 75 d files, %d requ
4160: 65 73 74 73 2c 20 25 64 20 6f 74 68 65 72 20 6d ests, %d other m
4170: 65 73 73 61 67 65 73 5c 6e 22 2c 0a 20 20 20 20 essages\n",.
4180: 20 20 20 20 20 20 20 20 6e 46 69 6c 65 2c 20 6e nFile, n
4190: 52 65 71 2c 20 6e 4d 73 67 29 3b 0a 20 20 20 20 Req, nMsg);.
41a0: 6e 46 69 6c 65 53 65 6e 64 20 3d 20 6e 46 69 6c nFileSend = nFil
41b0: 65 3b 0a 20 20 20 20 6e 46 69 6c 65 20 3d 20 6e e;. nFile = n
41c0: 52 65 71 20 3d 20 6e 4d 73 67 20 3d 20 30 3b 0a Req = nMsg = 0;.
41d0: 20 20 20 20 68 74 74 70 5f 65 78 63 68 61 6e 67 http_exchang
41e0: 65 28 26 73 65 6e 64 2c 20 26 72 65 63 76 29 3b e(&send, &recv);
41f0: 0a 20 20 20 20 62 6c 6f 62 5f 72 65 73 65 74 28 . blob_reset(
4200: 26 73 65 6e 64 29 3b 0a 0a 20 20 20 20 2f 2a 20 &send);.. /*
4210: 50 72 6f 63 65 73 73 20 74 68 65 20 72 65 70 6c Process the repl
4220: 79 20 74 68 61 74 20 63 61 6d 65 20 62 61 63 6b y that came back
4230: 20 66 72 6f 6d 20 74 68 65 20 73 65 72 76 65 72 from the server
4240: 20 2a 2f 0a 20 20 20 20 77 68 69 6c 65 28 20 62 */. while( b
4250: 6c 6f 62 5f 6c 69 6e 65 28 26 72 65 63 76 2c 20 lob_line(&recv,
4260: 26 6c 69 6e 65 29 20 29 7b 0a 20 20 20 20 20 20 &line) ){.
4270: 6e 54 6f 6b 65 6e 20 3d 20 62 6c 6f 62 5f 74 6f nToken = blob_to
4280: 6b 65 6e 69 7a 65 28 26 6c 69 6e 65 2c 20 61 54 kenize(&line, aT
4290: 6f 6b 65 6e 2c 20 63 6f 75 6e 74 28 61 54 6f 6b oken, count(aTok
42a0: 65 6e 29 29 3b 0a 0a 20 20 20 20 20 20 2f 2a 20 en));.. /*
42b0: 20 20 66 69 6c 65 20 55 55 49 44 20 53 49 5a 45 file UUID SIZE
42c0: 20 5c 6e 20 43 4f 4e 54 45 4e 54 0a 20 20 20 20 \n CONTENT.
42d0: 20 20 2a 2a 20 20 20 66 69 6c 65 20 55 55 49 44 ** file UUID
42e0: 20 44 45 4c 54 41 53 52 43 20 53 49 5a 45 20 5c DELTASRC SIZE \
42f0: 6e 20 43 4f 4e 54 45 4e 54 0a 20 20 20 20 20 20 n CONTENT.
4300: 2a 2a 0a 20 20 20 20 20 20 2a 2a 20 52 65 63 65 **. ** Rece
4310: 69 76 65 20 61 20 66 69 6c 65 20 74 72 61 6e 73 ive a file trans
4320: 6d 69 74 74 65 64 20 66 72 6f 6d 20 74 68 65 20 mitted from the
4330: 6f 74 68 65 72 20 73 69 64 65 0a 20 20 20 20 20 other side.
4340: 20 2a 2f 0a 20 20 20 20 20 20 69 66 28 20 62 6c */. if( bl
4350: 6f 62 5f 65 71 28 26 61 54 6f 6b 65 6e 5b 30 5d ob_eq(&aToken[0]
4360: 2c 22 66 69 6c 65 22 29 20 29 7b 0a 20 20 20 20 ,"file") ){.
4370: 20 20 20 20 78 66 65 72 5f 61 63 63 65 70 74 5f xfer_accept_
4380: 66 69 6c 65 28 26 72 65 63 76 2c 20 61 54 6f 6b file(&recv, aTok
4390: 65 6e 2c 20 6e 54 6f 6b 65 6e 2c 20 26 65 72 72 en, nToken, &err
43a0: 6d 73 67 29 3b 0a 20 20 20 20 20 20 20 20 6e 46 msg);. nF
43b0: 69 6c 65 2b 2b 3b 0a 20 20 20 20 20 20 20 20 67 ile++;. g
43c0: 6f 20 3d 20 31 3b 0a 20 20 20 20 20 20 7d 65 6c o = 1;. }el
43d0: 73 65 0a 0a 20 20 20 20 20 20 2f 2a 20 20 20 67 se.. /* g
43e0: 69 6d 6d 65 20 55 55 49 44 0a 20 20 20 20 20 20 imme UUID.
43f0: 2a 2a 0a 20 20 20 20 20 20 2a 2a 20 53 65 72 76 **. ** Serv
4400: 65 72 20 69 73 20 72 65 71 75 65 73 74 69 6e 67 er is requesting
4410: 20 61 20 66 69 6c 65 0a 20 20 20 20 20 20 2a 2f a file. */
4420: 0a 20 20 20 20 20 20 69 66 28 20 62 6c 6f 62 5f . if( blob_
4430: 65 71 28 26 61 54 6f 6b 65 6e 5b 30 5d 2c 20 22 eq(&aToken[0], "
4440: 67 69 6d 6d 65 22 29 20 26 26 20 6e 54 6f 6b 65 gimme") && nToke
4450: 6e 3d 3d 32 0a 20 20 20 20 20 20 20 20 20 20 20 n==2.
4460: 20 20 20 20 26 26 20 62 6c 6f 62 5f 69 73 5f 75 && blob_is_u
4470: 75 69 64 28 26 61 54 6f 6b 65 6e 5b 31 5d 29 20 uid(&aToken[1])
4480: 29 7b 0a 20 20 20 20 20 20 20 20 6e 52 65 71 2b ){. nReq+
4490: 2b 3b 0a 20 20 20 20 20 20 20 20 69 66 28 20 70 +;. if( p
44a0: 75 73 68 46 6c 61 67 20 29 7b 0a 20 20 20 20 20 ushFlag ){.
44b0: 20 20 20 20 20 64 62 5f 6d 75 6c 74 69 5f 65 78 db_multi_ex
44c0: 65 63 28 0a 20 20 20 20 20 20 20 20 20 20 20 20 ec(.
44d0: 22 49 4e 53 45 52 54 20 4f 52 20 49 47 4e 4f 52 "INSERT OR IGNOR
44e0: 45 20 49 4e 54 4f 20 70 65 6e 64 69 6e 67 28 72 E INTO pending(r
44f0: 69 64 29 20 22 0a 20 20 20 20 20 20 20 20 20 20 id) ".
4500: 20 20 22 53 45 4c 45 43 54 20 72 69 64 20 46 52 "SELECT rid FR
4510: 4f 4d 20 62 6c 6f 62 20 57 48 45 52 45 20 75 75 OM blob WHERE uu
4520: 69 64 3d 25 42 20 41 4e 44 20 73 69 7a 65 3e 3d id=%B AND size>=
4530: 30 22 2c 20 26 61 54 6f 6b 65 6e 5b 31 5d 0a 20 0", &aToken[1].
4540: 20 20 20 20 20 20 20 20 20 29 3b 0a 20 20 20 20 );.
4550: 20 20 20 20 20 20 67 6f 20 3d 20 31 3b 0a 20 20 go = 1;.
4560: 20 20 20 20 20 20 7d 0a 20 20 20 20 20 20 7d 65 }. }e
4570: 6c 73 65 0a 20 20 0a 20 20 20 20 20 20 2f 2a 20 lse. . /*
4580: 20 20 69 67 6f 74 20 55 55 49 44 0a 20 20 20 20 igot UUID.
4590: 20 20 2a 2a 20 20 20 6c 65 61 66 20 55 55 49 44 ** leaf UUID
45a0: 0a 20 20 20 20 20 20 2a 2a 0a 20 20 20 20 20 20 . **.
45b0: 2a 2a 20 53 65 72 76 65 72 20 70 72 6f 63 6c 61 ** Server procla
45c0: 69 6d 73 20 74 68 61 74 20 69 74 20 68 61 73 20 ims that it has
45d0: 61 20 70 61 72 74 69 63 75 6c 61 72 20 66 69 6c a particular fil
45e0: 65 2e 20 20 41 20 6c 65 61 66 20 6d 65 73 73 61 e. A leaf messa
45f0: 67 65 0a 20 20 20 20 20 20 2a 2a 20 6d 65 61 6e ge. ** mean
4600: 73 20 74 68 61 74 20 74 68 65 20 66 69 6c 65 20 s that the file
4610: 69 73 20 61 20 6c 65 61 66 20 6d 61 6e 69 66 65 is a leaf manife
4620: 73 74 20 6f 6e 20 74 68 65 20 73 65 72 76 65 72 st on the server
4630: 2e 0a 20 20 20 20 20 20 2a 2f 0a 20 20 20 20 20 .. */.
4640: 20 69 66 28 20 6e 54 6f 6b 65 6e 3d 3d 32 0a 20 if( nToken==2.
4650: 20 20 20 20 20 20 20 20 20 20 20 20 20 26 26 20 &&
4660: 28 62 6c 6f 62 5f 65 71 28 26 61 54 6f 6b 65 6e (blob_eq(&aToken
4670: 5b 30 5d 2c 20 22 69 67 6f 74 22 29 20 7c 7c 20 [0], "igot") ||
4680: 62 6c 6f 62 5f 65 71 28 26 61 54 6f 6b 65 6e 5b blob_eq(&aToken[
4690: 30 5d 2c 20 22 6c 65 61 66 22 29 29 0a 20 20 20 0], "leaf")).
46a0: 20 20 20 20 20 20 20 20 20 20 20 26 26 20 62 6c && bl
46b0: 6f 62 5f 69 73 5f 75 75 69 64 28 26 61 54 6f 6b ob_is_uuid(&aTok
46c0: 65 6e 5b 31 5d 29 20 29 7b 0a 20 20 20 20 20 20 en[1]) ){.
46d0: 20 20 69 6e 74 20 72 69 64 20 3d 20 64 62 5f 69 int rid = db_i
46e0: 6e 74 28 30 2c 20 22 53 45 4c 45 43 54 20 72 69 nt(0, "SELECT ri
46f0: 64 20 46 52 4f 4d 20 62 6c 6f 62 20 57 48 45 52 d FROM blob WHER
4700: 45 20 75 75 69 64 3d 25 42 22 2c 20 26 61 54 6f E uuid=%B", &aTo
4710: 6b 65 6e 5b 31 5d 29 3b 0a 20 20 20 20 20 20 20 ken[1]);.
4720: 20 6e 4d 73 67 2b 2b 3b 0a 20 20 20 20 20 20 20 nMsg++;.
4730: 20 69 66 28 20 72 69 64 3e 30 20 29 7b 0a 20 20 if( rid>0 ){.
4740: 20 20 20 20 20 20 20 20 64 62 5f 6d 75 6c 74 69 db_multi
4750: 5f 65 78 65 63 28 0a 20 20 20 20 20 20 20 20 20 _exec(.
4760: 20 20 20 22 49 4e 53 45 52 54 20 4f 52 20 49 47 "INSERT OR IG
4770: 4e 4f 52 45 20 49 4e 54 4f 20 6f 6e 72 65 6d 6f NORE INTO onremo
4780: 74 65 28 72 69 64 29 20 56 41 4c 55 45 53 28 25 te(rid) VALUES(%
4790: 64 29 22 2c 20 72 69 64 0a 20 20 20 20 20 20 20 d)", rid.
47a0: 20 20 20 29 3b 0a 20 20 20 20 20 20 20 20 20 20 );.
47b0: 2f 2a 20 41 64 64 20 74 6f 20 74 68 65 20 70 65 /* Add to the pe
47c0: 6e 64 69 6e 67 20 73 65 74 20 61 6c 6c 20 63 68 nding set all ch
47d0: 69 6c 64 72 65 6e 20 6f 66 20 74 68 65 20 73 65 ildren of the se
47e0: 72 76 65 72 27 73 20 6c 65 61 76 65 73 20 2a 2f rver's leaves */
47f0: 0a 20 20 20 20 20 20 20 20 20 20 69 66 28 20 70 . if( p
4800: 75 73 68 46 6c 61 67 20 26 26 20 62 6c 6f 62 5f ushFlag && blob_
4810: 65 71 28 26 61 54 6f 6b 65 6e 5b 30 5d 2c 20 22 eq(&aToken[0], "
4820: 6c 65 61 66 22 29 20 29 7b 0a 20 20 20 20 20 20 leaf") ){.
4830: 20 20 20 20 20 20 64 62 5f 6d 75 6c 74 69 5f 65 db_multi_e
4840: 78 65 63 28 0a 20 20 20 20 20 20 20 20 20 20 20 xec(.
4850: 20 20 20 22 49 4e 53 45 52 54 20 4f 52 20 49 47 "INSERT OR IG
4860: 4e 4f 52 45 20 49 4e 54 4f 20 70 65 6e 64 69 6e NORE INTO pendin
4870: 67 28 72 69 64 29 20 22 0a 20 20 20 20 20 20 20 g(rid) ".
4880: 20 20 20 20 20 20 20 22 53 45 4c 45 43 54 20 63 "SELECT c
4890: 69 64 20 46 52 4f 4d 20 70 6c 69 6e 6b 20 57 48 id FROM plink WH
48a0: 45 52 45 20 70 69 64 3d 25 64 22 2c 20 72 69 64 ERE pid=%d", rid
48b0: 0a 20 20 20 20 20 20 20 20 20 20 20 20 29 3b 0a . );.
48c0: 20 20 20 20 20 20 20 20 20 20 20 20 69 66 28 20 if(
48d0: 64 62 5f 63 68 61 6e 67 65 73 28 29 3e 30 20 29 db_changes()>0 )
48e0: 7b 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 {.
48f0: 67 6f 20 3d 20 31 3b 0a 20 20 20 20 20 20 20 20 go = 1;.
4900: 20 20 20 20 7d 0a 20 20 20 20 20 20 20 20 20 20 }.
4910: 7d 0a 20 20 20 20 20 20 20 20 20 20 69 66 28 20 }. if(
4920: 70 75 6c 6c 46 6c 61 67 20 26 26 20 21 67 6f 20 pullFlag && !go
4930: 26 26 20 0a 20 20 20 20 20 20 20 20 20 20 20 20 && .
4940: 20 20 64 62 5f 65 78 69 73 74 73 28 22 53 45 4c db_exists("SEL
4950: 45 43 54 20 31 20 46 52 4f 4d 20 62 6c 6f 62 20 ECT 1 FROM blob
4960: 57 48 45 52 45 20 72 69 64 3d 25 64 20 41 4e 44 WHERE rid=%d AND
4970: 20 73 69 7a 65 3c 30 22 2c 20 72 69 64 29 20 29 size<0", rid) )
4980: 7b 0a 20 20 20 20 20 20 20 20 20 20 20 20 67 6f {. go
4990: 20 3d 20 31 3b 0a 20 20 20 20 20 20 20 20 20 20 = 1;.
49a0: 7d 0a 20 20 20 20 20 20 20 20 7d 65 6c 73 65 20 }. }else
49b0: 69 66 28 20 70 75 6c 6c 46 6c 61 67 20 29 7b 0a if( pullFlag ){.
49c0: 20 20 20 20 20 20 20 20 20 20 67 6f 20 3d 20 31 go = 1
49d0: 3b 0a 20 20 20 20 20 20 20 20 20 20 63 6f 6e 74 ;. cont
49e0: 65 6e 74 5f 70 75 74 28 30 2c 20 62 6c 6f 62 5f ent_put(0, blob_
49f0: 73 74 72 28 26 61 54 6f 6b 65 6e 5b 31 5d 29 29 str(&aToken[1]))
4a00: 3b 0a 20 20 20 20 20 20 20 20 7d 0a 20 20 20 20 ;. }.
4a10: 20 20 7d 65 6c 73 65 0a 20 20 0a 20 20 20 20 20 }else. .
4a20: 20 2f 2a 20 20 20 70 75 73 68 20 20 53 45 52 56 /* push SERV
4a30: 45 52 43 4f 44 45 20 20 50 52 4f 44 55 43 54 43 ERCODE PRODUCTC
4a40: 4f 44 45 0a 20 20 20 20 20 20 2a 2a 0a 20 20 20 ODE. **.
4a50: 20 20 20 2a 2a 20 53 68 6f 75 6c 64 20 6f 6e 6c ** Should onl
4a60: 79 20 68 61 70 70 65 6e 20 69 6e 20 72 65 73 70 y happen in resp
4a70: 6f 6e 73 65 20 74 6f 20 61 20 63 6c 6f 6e 65 2e onse to a clone.
4a80: 0a 20 20 20 20 20 20 2a 2f 0a 20 20 20 20 20 20 . */.
4a90: 69 66 28 20 62 6c 6f 62 5f 65 71 28 26 61 54 6f if( blob_eq(&aTo
4aa0: 6b 65 6e 5b 30 5d 2c 22 70 75 73 68 22 29 20 26 ken[0],"push") &
4ab0: 26 20 6e 54 6f 6b 65 6e 3d 3d 33 20 26 26 20 63 & nToken==3 && c
4ac0: 6c 6f 6e 65 46 6c 61 67 0a 20 20 20 20 20 20 20 loneFlag.
4ad0: 20 20 20 20 20 20 20 26 26 20 62 6c 6f 62 5f 69 && blob_i
4ae0: 73 5f 75 75 69 64 28 26 61 54 6f 6b 65 6e 5b 31 s_uuid(&aToken[1
4af0: 5d 29 20 26 26 20 62 6c 6f 62 5f 69 73 5f 75 75 ]) && blob_is_uu
4b00: 69 64 28 26 61 54 6f 6b 65 6e 5b 32 5d 29 20 29 id(&aToken[2]) )
4b10: 7b 0a 0a 20 20 20 20 20 20 20 20 69 66 28 20 62 {.. if( b
4b20: 6c 6f 62 5f 65 71 5f 73 74 72 28 26 61 54 6f 6b lob_eq_str(&aTok
4b30: 65 6e 5b 31 5d 2c 20 7a 53 43 6f 64 65 2c 20 2d en[1], zSCode, -
4b40: 31 29 20 29 7b 0a 20 20 20 20 20 20 20 20 20 20 1) ){.
4b50: 66 6f 73 73 69 6c 5f 66 61 74 61 6c 28 22 73 65 fossil_fatal("se
4b60: 72 76 65 72 20 6c 6f 6f 70 22 29 3b 0a 20 20 20 rver loop");.
4b70: 20 20 20 20 20 7d 0a 20 20 20 20 20 20 20 20 6e }. n
4b80: 4d 73 67 2b 2b 3b 0a 20 20 20 20 20 20 20 20 69 Msg++;. i
4b90: 66 28 20 7a 50 43 6f 64 65 3d 3d 30 20 29 7b 0a f( zPCode==0 ){.
4ba0: 20 20 20 20 20 20 20 20 20 20 7a 50 43 6f 64 65 zPCode
4bb0: 20 3d 20 6d 70 72 69 6e 74 66 28 22 25 62 22 2c = mprintf("%b",
4bc0: 20 26 61 54 6f 6b 65 6e 5b 32 5d 29 3b 0a 20 20 &aToken[2]);.
4bd0: 20 20 20 20 20 20 20 20 64 62 5f 73 65 74 28 22 db_set("
4be0: 70 72 6f 6a 65 63 74 2d 63 6f 64 65 22 2c 20 7a project-code", z
4bf0: 50 43 6f 64 65 29 3b 0a 20 20 20 20 20 20 20 20 PCode);.
4c00: 7d 0a 20 20 20 20 20 20 20 20 63 6c 6f 6e 65 46 }. cloneF
4c10: 6c 61 67 20 3d 20 30 3b 0a 20 20 20 20 20 20 20 lag = 0;.
4c20: 20 70 75 6c 6c 46 6c 61 67 20 3d 20 31 3b 0a 20 pullFlag = 1;.
4c30: 20 20 20 20 20 7d 65 6c 73 65 0a 0a 20 20 20 20 }else..
4c40: 20 20 2f 2a 20 20 20 65 72 72 6f 72 20 4d 45 53 /* error MES
4c50: 53 41 47 45 0a 20 20 20 20 20 20 2a 2a 0a 20 20 SAGE. **.
4c60: 20 20 20 20 2a 2a 20 52 65 70 6f 72 74 20 61 6e ** Report an
4c70: 20 65 72 72 6f 72 0a 20 20 20 20 20 20 2a 2f 20 error. */
4c80: 20 20 20 20 20 20 20 0a 20 20 20 20 20 20 69 66 . if
4c90: 28 20 62 6c 6f 62 5f 65 71 28 26 61 54 6f 6b 65 ( blob_eq(&aToke
4ca0: 6e 5b 30 5d 2c 22 65 72 72 6f 72 22 29 20 26 26 n[0],"error") &&
4cb0: 20 6e 54 6f 6b 65 6e 3d 3d 32 20 29 7b 0a 20 20 nToken==2 ){.
4cc0: 20 20 20 20 20 20 63 68 61 72 20 2a 7a 4d 73 67 char *zMsg
4cd0: 20 3d 20 62 6c 6f 62 5f 74 65 72 6d 69 6e 61 74 = blob_terminat
4ce0: 65 28 26 61 54 6f 6b 65 6e 5b 31 5d 29 3b 0a 20 e(&aToken[1]);.
4cf0: 20 20 20 20 20 20 20 64 65 66 6f 73 73 69 6c 69 defossili
4d00: 7a 65 28 7a 4d 73 67 29 3b 0a 20 20 20 20 20 20 ze(zMsg);.
4d10: 20 20 62 6c 6f 62 5f 61 70 70 65 6e 64 66 28 26 blob_appendf(&
4d20: 65 72 72 6d 73 67 2c 20 22 73 65 72 76 65 72 20 errmsg, "server
4d30: 73 61 79 73 3a 20 25 73 22 2c 20 7a 4d 73 67 29 says: %s", zMsg)
4d40: 3b 0a 20 20 20 20 20 20 7d 65 6c 73 65 0a 0a 20 ;. }else..
4d50: 20 20 20 20 20 2f 2a 20 55 6e 6b 6e 6f 77 6e 20 /* Unknown
4d60: 6d 65 73 73 61 67 65 20 2a 2f 0a 20 20 20 20 20 message */.
4d70: 20 7b 0a 20 20 20 20 20 20 20 20 62 6c 6f 62 5f {. blob_
4d80: 61 70 70 65 6e 64 66 28 26 65 72 72 6d 73 67 2c appendf(&errmsg,
4d90: 20 22 75 6e 6b 6e 6f 77 6e 20 63 6f 6d 6d 61 6e "unknown comman
4da0: 64 3a 20 25 62 22 2c 20 26 61 54 6f 6b 65 6e 5b d: %b", &aToken[
4db0: 30 5d 29 3b 0a 20 20 20 20 20 20 7d 0a 0a 20 20 0]);. }..
4dc0: 20 20 20 20 69 66 28 20 62 6c 6f 62 5f 73 69 7a if( blob_siz
4dd0: 65 28 26 65 72 72 6d 73 67 29 20 29 7b 0a 20 20 e(&errmsg) ){.
4de0: 20 20 20 20 20 20 66 6f 73 73 69 6c 5f 66 61 74 fossil_fat
4df0: 61 6c 28 22 25 62 22 2c 20 26 65 72 72 6d 73 67 al("%b", &errmsg
4e00: 29 3b 0a 20 20 20 20 20 20 7d 0a 20 20 20 20 20 );. }.
4e10: 20 62 6c 6f 62 61 72 72 61 79 5f 72 65 73 65 74 blobarray_reset
4e20: 28 61 54 6f 6b 65 6e 2c 20 6e 54 6f 6b 65 6e 29 (aToken, nToken)
4e30: 3b 0a 20 20 20 20 7d 0a 20 20 20 20 62 6c 6f 62 ;. }. blob
4e40: 5f 72 65 73 65 74 28 26 72 65 63 76 29 3b 0a 20 _reset(&recv);.
4e50: 20 20 20 70 72 69 6e 74 66 28 22 52 65 63 65 69 printf("Recei
4e60: 76 65 64 3a 20 20 25 64 20 66 69 6c 65 73 2c 20 ved: %d files,
4e70: 25 64 20 72 65 71 75 65 73 74 73 2c 20 25 64 20 %d requests, %d
4e80: 6f 74 68 65 72 20 6d 65 73 73 61 67 65 73 5c 6e other messages\n
4e90: 22 2c 0a 20 20 20 20 20 20 20 20 20 20 20 20 6e ",. n
4ea0: 46 69 6c 65 2c 20 6e 52 65 71 2c 20 6e 4d 73 67 File, nReq, nMsg
4eb0: 29 3b 0a 20 20 20 20 69 66 28 20 6e 46 69 6c 65 );. if( nFile
4ec0: 53 65 6e 64 20 2b 20 6e 46 69 6c 65 3d 3d 30 20 Send + nFile==0
4ed0: 29 7b 0a 20 20 20 20 20 20 6e 4e 6f 46 69 6c 65 ){. nNoFile
4ee0: 43 79 63 6c 65 2b 2b 3b 0a 20 20 20 20 20 20 69 Cycle++;. i
4ef0: 66 28 20 6e 4e 6f 46 69 6c 65 43 79 63 6c 65 3e f( nNoFileCycle>
4f00: 31 20 29 7b 0a 20 20 20 20 20 20 20 20 67 6f 20 1 ){. go
4f10: 3d 20 30 3b 0a 20 20 20 20 20 20 7d 0a 20 20 20 = 0;. }.
4f20: 20 7d 65 6c 73 65 7b 0a 20 20 20 20 20 20 6e 4e }else{. nN
4f30: 6f 46 69 6c 65 43 79 63 6c 65 20 3d 20 30 3b 0a oFileCycle = 0;.
4f40: 20 20 20 20 7d 0a 20 20 20 20 6e 46 69 6c 65 20 }. nFile
4f50: 3d 20 6e 52 65 71 20 3d 20 6e 4d 73 67 20 3d 20 = nReq = nMsg =
4f60: 30 3b 0a 20 20 7d 3b 0a 20 20 68 74 74 70 5f 63 0;. };. http_c
4f70: 6c 6f 73 65 28 29 3b 0a 20 20 64 62 5f 65 6e 64 lose();. db_end
4f80: 5f 74 72 61 6e 73 61 63 74 69 6f 6e 28 30 29 3b _transaction(0);
4f90: 0a 20 20 64 62 5f 6d 75 6c 74 69 5f 65 78 65 63 . db_multi_exec
4fa0: 28 0a 20 20 20 20 22 44 52 4f 50 20 54 41 42 4c (. "DROP TABL
4fb0: 45 20 6f 6e 72 65 6d 6f 74 65 3b 22 0a 20 20 20 E onremote;".
4fc0: 20 22 44 52 4f 50 20 54 41 42 4c 45 20 70 65 6e "DROP TABLE pen
4fd0: 64 69 6e 67 3b 22 0a 20 20 29 3b 0a 7d 0a ding;". );.}.