Fossil SCM

Only request the password one time on a push or pull.

drh 2007-07-30 16:35 trunk
Commit 3a25b683905d9ebab614dd094cd7fd5f045845cf
+7 -6
--- src/content.c
+++ src/content.c
@@ -252,13 +252,15 @@
252252
if( findSrcid(rid, 0)>0 ){
253253
Blob x;
254254
Stmt s;
255255
content_get(rid, &x);
256256
db_prepare(&s, "UPDATE blob SET content=:c WHERE rid=%d", rid);
257
+ blob_compress(&x, &x);
257258
db_bind_blob(&s, ":c", &x);
258259
db_exec(&s);
259260
db_finalize(&s);
261
+ blob_reset(&x);
260262
db_multi_exec("DELETE FROM delta WHERE rid=%d", rid);
261263
}
262264
}
263265
264266
/*
@@ -284,11 +286,11 @@
284286
** converted to undeltaed text.
285287
*/
286288
void content_deltify(int rid, int srcid, int force){
287289
int s;
288290
Blob data, src, delta;
289
- static Stmt s1, s2;
291
+ Stmt s1, s2;
290292
if( srcid==rid ) return;
291293
if( !force && findSrcid(rid, 0)>0 ) return;
292294
s = srcid;
293295
while( (s = findSrcid(s, 0))>0 ){
294296
if( s==rid ){
@@ -300,20 +302,19 @@
300302
content_get(rid, &data);
301303
blob_delta_create(&src, &data, &delta);
302304
if( blob_size(&src)>=50 && blob_size(&data)>=50 &&
303305
blob_size(&delta) < blob_size(&data)*0.75 ){
304306
blob_compress(&delta, &delta);
305
- db_static_prepare(&s1, "UPDATE blob SET content=:data WHERE rid=:rid");
306
- db_static_prepare(&s2, "REPLACE INTO delta(rid,srcid)VALUES(:rid,:sid)");
307
- db_bind_int(&s1, ":rid", rid);
307
+ db_prepare(&s1, "UPDATE blob SET content=:data WHERE rid=%d", rid);
308
+ db_prepare(&s2, "REPLACE INTO delta(rid,srcid)VALUES(%d,%d)", rid, srcid);
308309
db_bind_blob(&s1, ":data", &delta);
309
- db_bind_int(&s2, ":rid", rid);
310
- db_bind_int(&s2, ":sid", srcid);
311310
db_begin_transaction();
312311
db_exec(&s1);
313312
db_exec(&s2);
314313
db_end_transaction(0);
314
+ db_finalize(&s1);
315
+ db_finalize(&s2);
315316
}
316317
blob_reset(&src);
317318
blob_reset(&data);
318319
blob_reset(&delta);
319320
verify_before_commit(rid);
320321
--- src/content.c
+++ src/content.c
@@ -252,13 +252,15 @@
252 if( findSrcid(rid, 0)>0 ){
253 Blob x;
254 Stmt s;
255 content_get(rid, &x);
256 db_prepare(&s, "UPDATE blob SET content=:c WHERE rid=%d", rid);
 
257 db_bind_blob(&s, ":c", &x);
258 db_exec(&s);
259 db_finalize(&s);
 
260 db_multi_exec("DELETE FROM delta WHERE rid=%d", rid);
261 }
262 }
263
264 /*
@@ -284,11 +286,11 @@
284 ** converted to undeltaed text.
285 */
286 void content_deltify(int rid, int srcid, int force){
287 int s;
288 Blob data, src, delta;
289 static Stmt s1, s2;
290 if( srcid==rid ) return;
291 if( !force && findSrcid(rid, 0)>0 ) return;
292 s = srcid;
293 while( (s = findSrcid(s, 0))>0 ){
294 if( s==rid ){
@@ -300,20 +302,19 @@
300 content_get(rid, &data);
301 blob_delta_create(&src, &data, &delta);
302 if( blob_size(&src)>=50 && blob_size(&data)>=50 &&
303 blob_size(&delta) < blob_size(&data)*0.75 ){
304 blob_compress(&delta, &delta);
305 db_static_prepare(&s1, "UPDATE blob SET content=:data WHERE rid=:rid");
306 db_static_prepare(&s2, "REPLACE INTO delta(rid,srcid)VALUES(:rid,:sid)");
307 db_bind_int(&s1, ":rid", rid);
308 db_bind_blob(&s1, ":data", &delta);
309 db_bind_int(&s2, ":rid", rid);
310 db_bind_int(&s2, ":sid", srcid);
311 db_begin_transaction();
312 db_exec(&s1);
313 db_exec(&s2);
314 db_end_transaction(0);
 
 
315 }
316 blob_reset(&src);
317 blob_reset(&data);
318 blob_reset(&delta);
319 verify_before_commit(rid);
320
--- src/content.c
+++ src/content.c
@@ -252,13 +252,15 @@
252 if( findSrcid(rid, 0)>0 ){
253 Blob x;
254 Stmt s;
255 content_get(rid, &x);
256 db_prepare(&s, "UPDATE blob SET content=:c WHERE rid=%d", rid);
257 blob_compress(&x, &x);
258 db_bind_blob(&s, ":c", &x);
259 db_exec(&s);
260 db_finalize(&s);
261 blob_reset(&x);
262 db_multi_exec("DELETE FROM delta WHERE rid=%d", rid);
263 }
264 }
265
266 /*
@@ -284,11 +286,11 @@
286 ** converted to undeltaed text.
287 */
288 void content_deltify(int rid, int srcid, int force){
289 int s;
290 Blob data, src, delta;
291 Stmt s1, s2;
292 if( srcid==rid ) return;
293 if( !force && findSrcid(rid, 0)>0 ) return;
294 s = srcid;
295 while( (s = findSrcid(s, 0))>0 ){
296 if( s==rid ){
@@ -300,20 +302,19 @@
302 content_get(rid, &data);
303 blob_delta_create(&src, &data, &delta);
304 if( blob_size(&src)>=50 && blob_size(&data)>=50 &&
305 blob_size(&delta) < blob_size(&data)*0.75 ){
306 blob_compress(&delta, &delta);
307 db_prepare(&s1, "UPDATE blob SET content=:data WHERE rid=%d", rid);
308 db_prepare(&s2, "REPLACE INTO delta(rid,srcid)VALUES(%d,%d)", rid, srcid);
 
309 db_bind_blob(&s1, ":data", &delta);
 
 
310 db_begin_transaction();
311 db_exec(&s1);
312 db_exec(&s2);
313 db_end_transaction(0);
314 db_finalize(&s1);
315 db_finalize(&s2);
316 }
317 blob_reset(&src);
318 blob_reset(&data);
319 blob_reset(&delta);
320 verify_before_commit(rid);
321
+37 -3
--- src/db.c
+++ src/db.c
@@ -538,23 +538,26 @@
538538
if( getcwd(zPwd, sizeof(zPwd)-20)==0 ){
539539
db_err("pwd too big: max %d", sizeof(zPwd)-20);
540540
}
541541
n = strlen(zPwd);
542542
while( n>0 ){
543
- if( access(zPwd, W_OK) ) return 0;
543
+ if( access(zPwd, W_OK) ) break;
544544
strcpy(&zPwd[n], "/_FOSSIL_");
545545
if( isValidLocalDb(zPwd) ){
546
+ /* Found a valid _FOSSIL_ file */
546547
zPwd[n] = 0;
547548
g.zLocalRoot = mprintf("%s/", zPwd);
548
- break;
549
+ return 1;
549550
}
550551
n--;
551552
while( n>0 && zPwd[n]!='/' ){ n--; }
552553
while( n>0 && zPwd[n-1]=='/' ){ n--; }
553554
zPwd[n] = 0;
554555
}
555
- return n>0;
556
+
557
+ /* A _FOSSIL_ file could not be found */
558
+ return 0;
556559
}
557560
558561
/*
559562
** Open the repository database given by zDbName. If zDbName==NULL then
560563
** get the name from the already open local database.
@@ -773,10 +776,41 @@
773776
return db_int(dflt, "SELECT value FROM vvar WHERE name=%Q", zName);
774777
}
775778
void db_lset_int(const char *zName, int value){
776779
db_multi_exec("REPLACE INTO vvar(name,value) VALUES(%Q,%d)", zName, value);
777780
}
781
+
782
+int db_row_to_table(const char *zFormat, ...){
783
+ Stmt q;
784
+ va_list ap;
785
+ int rc;
786
+
787
+ va_start(ap, zFormat);
788
+ rc = db_vprepare(&q, zFormat, ap);
789
+ va_end(ap);
790
+ if( rc!=SQLITE_OK ){
791
+ return rc;
792
+ }
793
+
794
+ @ <table border="0" cellpadding="0" cellspacing="0">
795
+ if( db_step(&q)==SQLITE_ROW ){
796
+ int ii;
797
+ for(ii=0; ii<sqlite3_column_count(q.pStmt); ii++){
798
+ char *zCol = htmlize(sqlite3_column_name(q.pStmt, ii), -1);
799
+ char *zVal = htmlize(sqlite3_column_text(q.pStmt, ii), -1);
800
+
801
+ @ <tr><td align=right>%s(zCol):<td width=10><td>%s(zVal)
802
+
803
+ free(zVal);
804
+ free(zCol);
805
+ }
806
+ }
807
+ @ </table>
808
+
809
+ return db_finalize(&q);
810
+}
811
+
778812
779813
/*
780814
** COMMAND: open
781815
**
782816
** Create a new local repository.
783817
--- src/db.c
+++ src/db.c
@@ -538,23 +538,26 @@
538 if( getcwd(zPwd, sizeof(zPwd)-20)==0 ){
539 db_err("pwd too big: max %d", sizeof(zPwd)-20);
540 }
541 n = strlen(zPwd);
542 while( n>0 ){
543 if( access(zPwd, W_OK) ) return 0;
544 strcpy(&zPwd[n], "/_FOSSIL_");
545 if( isValidLocalDb(zPwd) ){
 
546 zPwd[n] = 0;
547 g.zLocalRoot = mprintf("%s/", zPwd);
548 break;
549 }
550 n--;
551 while( n>0 && zPwd[n]!='/' ){ n--; }
552 while( n>0 && zPwd[n-1]=='/' ){ n--; }
553 zPwd[n] = 0;
554 }
555 return n>0;
 
 
556 }
557
558 /*
559 ** Open the repository database given by zDbName. If zDbName==NULL then
560 ** get the name from the already open local database.
@@ -773,10 +776,41 @@
773 return db_int(dflt, "SELECT value FROM vvar WHERE name=%Q", zName);
774 }
775 void db_lset_int(const char *zName, int value){
776 db_multi_exec("REPLACE INTO vvar(name,value) VALUES(%Q,%d)", zName, value);
777 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
778
779 /*
780 ** COMMAND: open
781 **
782 ** Create a new local repository.
783
--- src/db.c
+++ src/db.c
@@ -538,23 +538,26 @@
538 if( getcwd(zPwd, sizeof(zPwd)-20)==0 ){
539 db_err("pwd too big: max %d", sizeof(zPwd)-20);
540 }
541 n = strlen(zPwd);
542 while( n>0 ){
543 if( access(zPwd, W_OK) ) break;
544 strcpy(&zPwd[n], "/_FOSSIL_");
545 if( isValidLocalDb(zPwd) ){
546 /* Found a valid _FOSSIL_ file */
547 zPwd[n] = 0;
548 g.zLocalRoot = mprintf("%s/", zPwd);
549 return 1;
550 }
551 n--;
552 while( n>0 && zPwd[n]!='/' ){ n--; }
553 while( n>0 && zPwd[n-1]=='/' ){ n--; }
554 zPwd[n] = 0;
555 }
556
557 /* A _FOSSIL_ file could not be found */
558 return 0;
559 }
560
561 /*
562 ** Open the repository database given by zDbName. If zDbName==NULL then
563 ** get the name from the already open local database.
@@ -773,10 +776,41 @@
776 return db_int(dflt, "SELECT value FROM vvar WHERE name=%Q", zName);
777 }
778 void db_lset_int(const char *zName, int value){
779 db_multi_exec("REPLACE INTO vvar(name,value) VALUES(%Q,%d)", zName, value);
780 }
781
782 int db_row_to_table(const char *zFormat, ...){
783 Stmt q;
784 va_list ap;
785 int rc;
786
787 va_start(ap, zFormat);
788 rc = db_vprepare(&q, zFormat, ap);
789 va_end(ap);
790 if( rc!=SQLITE_OK ){
791 return rc;
792 }
793
794 @ <table border="0" cellpadding="0" cellspacing="0">
795 if( db_step(&q)==SQLITE_ROW ){
796 int ii;
797 for(ii=0; ii<sqlite3_column_count(q.pStmt); ii++){
798 char *zCol = htmlize(sqlite3_column_name(q.pStmt, ii), -1);
799 char *zVal = htmlize(sqlite3_column_text(q.pStmt, ii), -1);
800
801 @ <tr><td align=right>%s(zCol):<td width=10><td>%s(zVal)
802
803 free(zVal);
804 free(zCol);
805 }
806 }
807 @ </table>
808
809 return db_finalize(&q);
810 }
811
812
813 /*
814 ** COMMAND: open
815 **
816 ** Create a new local repository.
817
+1 -1
--- src/deltacmd.c
+++ src/deltacmd.c
@@ -30,15 +30,15 @@
3030
** Create a delta that describes the change from pOriginal to pTarget
3131
** and put that delta in pDelta. The pDelta blob is assumed to be
3232
** uninitialized.
3333
*/
3434
int blob_delta_create(Blob *pOriginal, Blob *pTarget, Blob *pDelta){
35
- blob_zero(pDelta);
3635
const char *zOrig, *zTarg;
3736
int lenOrig, lenTarg;
3837
int len;
3938
char *zRes;
39
+ blob_zero(pDelta);
4040
zOrig = blob_buffer(pOriginal);
4141
lenOrig = blob_size(pOriginal);
4242
zTarg = blob_buffer(pTarget);
4343
lenTarg = blob_size(pTarget);
4444
blob_resize(pDelta, lenTarg+16);
4545
--- src/deltacmd.c
+++ src/deltacmd.c
@@ -30,15 +30,15 @@
30 ** Create a delta that describes the change from pOriginal to pTarget
31 ** and put that delta in pDelta. The pDelta blob is assumed to be
32 ** uninitialized.
33 */
34 int blob_delta_create(Blob *pOriginal, Blob *pTarget, Blob *pDelta){
35 blob_zero(pDelta);
36 const char *zOrig, *zTarg;
37 int lenOrig, lenTarg;
38 int len;
39 char *zRes;
 
40 zOrig = blob_buffer(pOriginal);
41 lenOrig = blob_size(pOriginal);
42 zTarg = blob_buffer(pTarget);
43 lenTarg = blob_size(pTarget);
44 blob_resize(pDelta, lenTarg+16);
45
--- src/deltacmd.c
+++ src/deltacmd.c
@@ -30,15 +30,15 @@
30 ** Create a delta that describes the change from pOriginal to pTarget
31 ** and put that delta in pDelta. The pDelta blob is assumed to be
32 ** uninitialized.
33 */
34 int blob_delta_create(Blob *pOriginal, Blob *pTarget, Blob *pDelta){
 
35 const char *zOrig, *zTarg;
36 int lenOrig, lenTarg;
37 int len;
38 char *zRes;
39 blob_zero(pDelta);
40 zOrig = blob_buffer(pOriginal);
41 lenOrig = blob_size(pOriginal);
42 zTarg = blob_buffer(pTarget);
43 lenTarg = blob_size(pTarget);
44 blob_resize(pDelta, lenTarg+16);
45
--- src/encode.c
+++ src/encode.c
@@ -182,10 +182,14 @@
182182
** Remove the HTTP encodings from a string. The conversion is done
183183
** in-place. Return the length of the string after conversion.
184184
*/
185185
int dehttpize(char *z){
186186
int i, j;
187
+
188
+ /* Treat a null pointer as a zero-length string. */
189
+ if( !z ) return 0;
190
+
187191
i = j = 0;
188192
while( z[i] ){
189193
switch( z[i] ){
190194
case '%':
191195
if( z[i+1] && z[i+2] ){
192196
--- src/encode.c
+++ src/encode.c
@@ -182,10 +182,14 @@
182 ** Remove the HTTP encodings from a string. The conversion is done
183 ** in-place. Return the length of the string after conversion.
184 */
185 int dehttpize(char *z){
186 int i, j;
 
 
 
 
187 i = j = 0;
188 while( z[i] ){
189 switch( z[i] ){
190 case '%':
191 if( z[i+1] && z[i+2] ){
192
--- src/encode.c
+++ src/encode.c
@@ -182,10 +182,14 @@
182 ** Remove the HTTP encodings from a string. The conversion is done
183 ** in-place. Return the length of the string after conversion.
184 */
185 int dehttpize(char *z){
186 int i, j;
187
188 /* Treat a null pointer as a zero-length string. */
189 if( !z ) return 0;
190
191 i = j = 0;
192 while( z[i] ){
193 switch( z[i] ){
194 case '%':
195 if( z[i+1] && z[i+2] ){
196
+3 -3
--- src/http.c
+++ src/http.c
@@ -170,16 +170,16 @@
170170
sha1sum_blob(&pw, &sig);
171171
blob_appendf(&login, "login %s %b %b\n", g.zLogin, &nonce, &sig);
172172
}else{
173173
if( g.urlPasswd==0 ){
174174
if( strcmp(g.urlUser,"anonymous")!=0 ){
175
- char *zPrompt = mprintf("password for %s", g.urlUser);
175
+ char *zPrompt = mprintf("password for %s: ", g.urlUser);
176176
Blob x;
177177
prompt_for_password(zPrompt, &x, 0);
178178
free(zPrompt);
179
- blob_append(&pw, blob_buffer(&x), blob_size(&x));
180
- blob_reset(&x);
179
+ g.urlPasswd = blob_str(&x);
180
+ blob_append(&pw, g.urlPasswd, -1);
181181
}
182182
}
183183
sha1sum_blob(&pw, &sig);
184184
blob_appendf(&login, "login %s %b %b\n", g.urlUser, &nonce, &sig);
185185
}
186186
--- src/http.c
+++ src/http.c
@@ -170,16 +170,16 @@
170 sha1sum_blob(&pw, &sig);
171 blob_appendf(&login, "login %s %b %b\n", g.zLogin, &nonce, &sig);
172 }else{
173 if( g.urlPasswd==0 ){
174 if( strcmp(g.urlUser,"anonymous")!=0 ){
175 char *zPrompt = mprintf("password for %s", g.urlUser);
176 Blob x;
177 prompt_for_password(zPrompt, &x, 0);
178 free(zPrompt);
179 blob_append(&pw, blob_buffer(&x), blob_size(&x));
180 blob_reset(&x);
181 }
182 }
183 sha1sum_blob(&pw, &sig);
184 blob_appendf(&login, "login %s %b %b\n", g.urlUser, &nonce, &sig);
185 }
186
--- src/http.c
+++ src/http.c
@@ -170,16 +170,16 @@
170 sha1sum_blob(&pw, &sig);
171 blob_appendf(&login, "login %s %b %b\n", g.zLogin, &nonce, &sig);
172 }else{
173 if( g.urlPasswd==0 ){
174 if( strcmp(g.urlUser,"anonymous")!=0 ){
175 char *zPrompt = mprintf("password for %s: ", g.urlUser);
176 Blob x;
177 prompt_for_password(zPrompt, &x, 0);
178 free(zPrompt);
179 g.urlPasswd = blob_str(&x);
180 blob_append(&pw, g.urlPasswd, -1);
181 }
182 }
183 sha1sum_blob(&pw, &sig);
184 blob_appendf(&login, "login %s %b %b\n", g.urlUser, &nonce, &sig);
185 }
186
+21 -5
--- src/info.c
+++ src/info.c
@@ -103,13 +103,13 @@
103103
}
104104
show_common_info(rid, "uuid:", 1);
105105
}
106106
}
107107
108
-#if 0
108
+#if 1
109109
/*
110
-** WEB PAGE: vinfo
110
+** WEBPAGE: vinfo
111111
**
112112
** Return information about a version. The version number is contained
113113
** in g.zExtra.
114114
*/
115115
void vinfo_page(void){
@@ -123,14 +123,28 @@
123123
if( rid==0 ){
124124
@ No such object: %h(g.argv[2])
125125
style_footer();
126126
return;
127127
}
128
+ db_row_to_table("SELECT "
129
+ " blob.uuid AS \"UUID\""
130
+ ", datetime(rcvfrom.mtime) AS \"Created\""
131
+ ", rcvfrom.uid AS \"User Id\""
132
+ ", blob.size AS \"Size\""
133
+ "FROM blob, rcvfrom "
134
+ "WHERE rid=%d", rid
135
+ );
136
+ style_footer();
137
+ return;
138
+
128139
db_prepare(&q,
129
- "SELECT uuid, datetime(mtime,'unixepoch'), datetime(ctime,'unixepoch'),"
130
- " uid, size, cksum, branch, comment, type"
131
- " FROM record WHERE rid=%d", rid
140
+ "SELECT "
141
+ "uuid, " /* 0 */
142
+ "datetime(mtime,'unixepoch')," /* 1 */
143
+ "datetime(ctime,'unixepoch')," /* 2 */
144
+ "uid, size, cksum, branch, comment, type" /* 3..8 */
145
+ "FROM record WHERE rid=%d", rid
132146
);
133147
if( db_step(&q)==SQLITE_ROW ){
134148
const char *z;
135149
const char *zSignedBy = db_text("unknown",
136150
"SELECT login FROM repuser WHERE uid=%d",
@@ -256,11 +270,13 @@
256270
}
257271
db_finalize(&q);
258272
}
259273
style_footer();
260274
}
275
+#endif
261276
277
+#if 0
262278
/*
263279
** WEB PAGE: diff
264280
**
265281
** Display the difference between two files determined by the v1 and v2
266282
** query parameters. If only v2 is given compute v1 as the parent of v2.
267283
--- src/info.c
+++ src/info.c
@@ -103,13 +103,13 @@
103 }
104 show_common_info(rid, "uuid:", 1);
105 }
106 }
107
108 #if 0
109 /*
110 ** WEB PAGE: vinfo
111 **
112 ** Return information about a version. The version number is contained
113 ** in g.zExtra.
114 */
115 void vinfo_page(void){
@@ -123,14 +123,28 @@
123 if( rid==0 ){
124 @ No such object: %h(g.argv[2])
125 style_footer();
126 return;
127 }
 
 
 
 
 
 
 
 
 
 
 
128 db_prepare(&q,
129 "SELECT uuid, datetime(mtime,'unixepoch'), datetime(ctime,'unixepoch'),"
130 " uid, size, cksum, branch, comment, type"
131 " FROM record WHERE rid=%d", rid
 
 
 
132 );
133 if( db_step(&q)==SQLITE_ROW ){
134 const char *z;
135 const char *zSignedBy = db_text("unknown",
136 "SELECT login FROM repuser WHERE uid=%d",
@@ -256,11 +270,13 @@
256 }
257 db_finalize(&q);
258 }
259 style_footer();
260 }
 
261
 
262 /*
263 ** WEB PAGE: diff
264 **
265 ** Display the difference between two files determined by the v1 and v2
266 ** query parameters. If only v2 is given compute v1 as the parent of v2.
267
--- src/info.c
+++ src/info.c
@@ -103,13 +103,13 @@
103 }
104 show_common_info(rid, "uuid:", 1);
105 }
106 }
107
108 #if 1
109 /*
110 ** WEBPAGE: vinfo
111 **
112 ** Return information about a version. The version number is contained
113 ** in g.zExtra.
114 */
115 void vinfo_page(void){
@@ -123,14 +123,28 @@
123 if( rid==0 ){
124 @ No such object: %h(g.argv[2])
125 style_footer();
126 return;
127 }
128 db_row_to_table("SELECT "
129 " blob.uuid AS \"UUID\""
130 ", datetime(rcvfrom.mtime) AS \"Created\""
131 ", rcvfrom.uid AS \"User Id\""
132 ", blob.size AS \"Size\""
133 "FROM blob, rcvfrom "
134 "WHERE rid=%d", rid
135 );
136 style_footer();
137 return;
138
139 db_prepare(&q,
140 "SELECT "
141 "uuid, " /* 0 */
142 "datetime(mtime,'unixepoch')," /* 1 */
143 "datetime(ctime,'unixepoch')," /* 2 */
144 "uid, size, cksum, branch, comment, type" /* 3..8 */
145 "FROM record WHERE rid=%d", rid
146 );
147 if( db_step(&q)==SQLITE_ROW ){
148 const char *z;
149 const char *zSignedBy = db_text("unknown",
150 "SELECT login FROM repuser WHERE uid=%d",
@@ -256,11 +270,13 @@
270 }
271 db_finalize(&q);
272 }
273 style_footer();
274 }
275 #endif
276
277 #if 0
278 /*
279 ** WEB PAGE: diff
280 **
281 ** Display the difference between two files determined by the v1 and v2
282 ** query parameters. If only v2 is given compute v1 as the parent of v2.
283
+9 -13
--- src/login.c
+++ src/login.c
@@ -203,23 +203,19 @@
203203
g.isAnon = 0;
204204
}
205205
206206
/* Check the login cookie to see if it matches a known valid user.
207207
*/
208
- if( uid==0 ){
209
- if( (zCookie = P(login_cookie_name()))!=0 ){
210
- uid = db_int(0,
211
- "SELECT uid FROM user"
212
- " WHERE uid=%d"
213
- " AND cookie=%Q"
214
- " AND ipaddr=%Q"
215
- " AND cexpire>julianday('now')",
216
- atoi(zCookie), zCookie, zRemoteAddr
217
- );
218
- }else{
219
- uid = db_int(0, "SELECT uid FROM user WHERE login='anonymous'");
220
- }
208
+ if( uid==0 && (zCookie = P(login_cookie_name()))!=0 ){
209
+ uid = db_int(0,
210
+ "SELECT 1 FROM user"
211
+ " WHERE uid=%d"
212
+ " AND cookie=%Q"
213
+ " AND ipaddr=%Q"
214
+ " AND cexpire>julianday('now')",
215
+ atoi(zCookie), zCookie, zRemoteAddr
216
+ );
221217
}
222218
223219
if( uid==0 ){
224220
g.isAnon = 1;
225221
g.zLogin = "";
226222
--- src/login.c
+++ src/login.c
@@ -203,23 +203,19 @@
203 g.isAnon = 0;
204 }
205
206 /* Check the login cookie to see if it matches a known valid user.
207 */
208 if( uid==0 ){
209 if( (zCookie = P(login_cookie_name()))!=0 ){
210 uid = db_int(0,
211 "SELECT uid FROM user"
212 " WHERE uid=%d"
213 " AND cookie=%Q"
214 " AND ipaddr=%Q"
215 " AND cexpire>julianday('now')",
216 atoi(zCookie), zCookie, zRemoteAddr
217 );
218 }else{
219 uid = db_int(0, "SELECT uid FROM user WHERE login='anonymous'");
220 }
221 }
222
223 if( uid==0 ){
224 g.isAnon = 1;
225 g.zLogin = "";
226
--- src/login.c
+++ src/login.c
@@ -203,23 +203,19 @@
203 g.isAnon = 0;
204 }
205
206 /* Check the login cookie to see if it matches a known valid user.
207 */
208 if( uid==0 && (zCookie = P(login_cookie_name()))!=0 ){
209 uid = db_int(0,
210 "SELECT 1 FROM user"
211 " WHERE uid=%d"
212 " AND cookie=%Q"
213 " AND ipaddr=%Q"
214 " AND cexpire>julianday('now')",
215 atoi(zCookie), zCookie, zRemoteAddr
216 );
 
 
 
 
217 }
218
219 if( uid==0 ){
220 g.isAnon = 1;
221 g.zLogin = "";
222
+10 -1
--- src/xfer.c
+++ src/xfer.c
@@ -129,10 +129,11 @@
129129
130130
/*
131131
** Send all pending files.
132132
*/
133133
static int send_all_pending(Blob *pOut){
134
+ int iRidSent = 0;
134135
int sent = 0;
135136
int nSent = 0;
136137
int maxSize = db_get_int("http-msg-size", 1000000);
137138
Stmt q;
138139
#if 0
@@ -156,16 +157,17 @@
156157
" SELECT rid FROM delta WHERE srcid=%d",
157158
rid, rid
158159
);
159160
}
160161
#endif
161
- db_prepare(&q, "SELECT rid FROM pending");
162
+ db_prepare(&q, "SELECT rid FROM pending ORDER BY rid");
162163
while( db_step(&q)==SQLITE_ROW ){
163164
int rid = db_column_int(&q, 0);
164165
if( sent<maxSize ){
165166
sent += send_file(rid, pOut);
166167
nSent++;
168
+ iRidSent = rid;
167169
}else{
168170
char *zUuid = db_text(0,
169171
"SELECT uuid FROM blob WHERE rid=%d AND size>=0", rid);
170172
if( zUuid ){
171173
if( pOut ){
@@ -177,10 +179,17 @@
177179
}
178180
}
179181
}
180182
db_finalize(&q);
181183
184
+ /* Delete the 'pending' records for all files just sent. Otherwise,
185
+ ** we can wind up sending some files more than once.
186
+ */
187
+ if( nSent>0 ){
188
+ db_multi_exec("DELETE FROM pending WHERE rid <= %d", iRidSent);
189
+ }
190
+
182191
#if 0
183192
db_multi_exec("DROP TABLE priority");
184193
#endif
185194
return nSent;
186195
}
187196
--- src/xfer.c
+++ src/xfer.c
@@ -129,10 +129,11 @@
129
130 /*
131 ** Send all pending files.
132 */
133 static int send_all_pending(Blob *pOut){
 
134 int sent = 0;
135 int nSent = 0;
136 int maxSize = db_get_int("http-msg-size", 1000000);
137 Stmt q;
138 #if 0
@@ -156,16 +157,17 @@
156 " SELECT rid FROM delta WHERE srcid=%d",
157 rid, rid
158 );
159 }
160 #endif
161 db_prepare(&q, "SELECT rid FROM pending");
162 while( db_step(&q)==SQLITE_ROW ){
163 int rid = db_column_int(&q, 0);
164 if( sent<maxSize ){
165 sent += send_file(rid, pOut);
166 nSent++;
 
167 }else{
168 char *zUuid = db_text(0,
169 "SELECT uuid FROM blob WHERE rid=%d AND size>=0", rid);
170 if( zUuid ){
171 if( pOut ){
@@ -177,10 +179,17 @@
177 }
178 }
179 }
180 db_finalize(&q);
181
 
 
 
 
 
 
 
182 #if 0
183 db_multi_exec("DROP TABLE priority");
184 #endif
185 return nSent;
186 }
187
--- src/xfer.c
+++ src/xfer.c
@@ -129,10 +129,11 @@
129
130 /*
131 ** Send all pending files.
132 */
133 static int send_all_pending(Blob *pOut){
134 int iRidSent = 0;
135 int sent = 0;
136 int nSent = 0;
137 int maxSize = db_get_int("http-msg-size", 1000000);
138 Stmt q;
139 #if 0
@@ -156,16 +157,17 @@
157 " SELECT rid FROM delta WHERE srcid=%d",
158 rid, rid
159 );
160 }
161 #endif
162 db_prepare(&q, "SELECT rid FROM pending ORDER BY rid");
163 while( db_step(&q)==SQLITE_ROW ){
164 int rid = db_column_int(&q, 0);
165 if( sent<maxSize ){
166 sent += send_file(rid, pOut);
167 nSent++;
168 iRidSent = rid;
169 }else{
170 char *zUuid = db_text(0,
171 "SELECT uuid FROM blob WHERE rid=%d AND size>=0", rid);
172 if( zUuid ){
173 if( pOut ){
@@ -177,10 +179,17 @@
179 }
180 }
181 }
182 db_finalize(&q);
183
184 /* Delete the 'pending' records for all files just sent. Otherwise,
185 ** we can wind up sending some files more than once.
186 */
187 if( nSent>0 ){
188 db_multi_exec("DELETE FROM pending WHERE rid <= %d", iRidSent);
189 }
190
191 #if 0
192 db_multi_exec("DROP TABLE priority");
193 #endif
194 return nSent;
195 }
196

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button