Fossil

Check-in [3a25b683]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Only request the password one time on a push or pull.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:3a25b683905d9ebab614dd094cd7fd5f045845cf
User & Date: drh 2007-07-30 16:35:16
Context
2007-07-30
17:05
Fix a bug in the logic for finding a pivot during a merge. check-in: 5602bbba user: drh tags: trunk
16:35
Only request the password one time on a push or pull. check-in: 3a25b683 user: drh tags: trunk
14:28
Use POST instead of GET for the /xfer method. Other bug fixes in the URL parser. check-in: e621b6db user: drh tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/content.c.

250
251
252
253
254
255
256

257
258
259

260
261
262
263
264
265
266
...
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
...
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314


315
316
317
318
319
320
321
*/
void content_undelta(int rid){
  if( findSrcid(rid, 0)>0 ){
    Blob x;
    Stmt s;
    content_get(rid, &x);
    db_prepare(&s, "UPDATE blob SET content=:c WHERE rid=%d", rid);

    db_bind_blob(&s, ":c", &x);
    db_exec(&s);
    db_finalize(&s);

    db_multi_exec("DELETE FROM delta WHERE rid=%d", rid);
  }
}

/*
** COMMAND:  test-content-undelta
**
................................................................................
**
** If srcid is a delta that depends on rid, then srcid is
** converted to undeltaed text.
*/
void content_deltify(int rid, int srcid, int force){
  int s;
  Blob data, src, delta;
  static Stmt s1, s2;
  if( srcid==rid ) return;
  if( !force && findSrcid(rid, 0)>0 ) return;
  s = srcid;
  while( (s = findSrcid(s, 0))>0 ){
    if( s==rid ){
      content_undelta(srcid);
      break;
................................................................................
  }
  content_get(srcid, &src);
  content_get(rid, &data);
  blob_delta_create(&src, &data, &delta);
  if( blob_size(&src)>=50 && blob_size(&data)>=50 &&
           blob_size(&delta) < blob_size(&data)*0.75 ){
    blob_compress(&delta, &delta);
    db_static_prepare(&s1, "UPDATE blob SET content=:data WHERE rid=:rid");
    db_static_prepare(&s2, "REPLACE INTO delta(rid,srcid)VALUES(:rid,:sid)");
    db_bind_int(&s1, ":rid", rid);
    db_bind_blob(&s1, ":data", &delta);
    db_bind_int(&s2, ":rid", rid);
    db_bind_int(&s2, ":sid", srcid);
    db_begin_transaction();
    db_exec(&s1);
    db_exec(&s2);
    db_end_transaction(0);


  }
  blob_reset(&src);
  blob_reset(&data);
  blob_reset(&delta);
  verify_before_commit(rid);
}








>



>







 







|







 







|
|
<

<
<




>
>







250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
...
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
...
300
301
302
303
304
305
306
307
308

309


310
311
312
313
314
315
316
317
318
319
320
321
322
*/
void content_undelta(int rid){
  if( findSrcid(rid, 0)>0 ){
    Blob x;
    Stmt s;
    content_get(rid, &x);
    db_prepare(&s, "UPDATE blob SET content=:c WHERE rid=%d", rid);
    blob_compress(&x, &x);
    db_bind_blob(&s, ":c", &x);
    db_exec(&s);
    db_finalize(&s);
    blob_reset(&x);
    db_multi_exec("DELETE FROM delta WHERE rid=%d", rid);
  }
}

/*
** COMMAND:  test-content-undelta
**
................................................................................
**
** If srcid is a delta that depends on rid, then srcid is
** converted to undeltaed text.
*/
void content_deltify(int rid, int srcid, int force){
  int s;
  Blob data, src, delta;
  Stmt s1, s2;
  if( srcid==rid ) return;
  if( !force && findSrcid(rid, 0)>0 ) return;
  s = srcid;
  while( (s = findSrcid(s, 0))>0 ){
    if( s==rid ){
      content_undelta(srcid);
      break;
................................................................................
  }
  content_get(srcid, &src);
  content_get(rid, &data);
  blob_delta_create(&src, &data, &delta);
  if( blob_size(&src)>=50 && blob_size(&data)>=50 &&
           blob_size(&delta) < blob_size(&data)*0.75 ){
    blob_compress(&delta, &delta);
    db_prepare(&s1, "UPDATE blob SET content=:data WHERE rid=%d", rid);
    db_prepare(&s2, "REPLACE INTO delta(rid,srcid)VALUES(%d,%d)", rid, srcid);

    db_bind_blob(&s1, ":data", &delta);


    db_begin_transaction();
    db_exec(&s1);
    db_exec(&s2);
    db_end_transaction(0);
    db_finalize(&s1);
    db_finalize(&s2);
  }
  blob_reset(&src);
  blob_reset(&data);
  blob_reset(&delta);
  verify_before_commit(rid);
}

Changes to src/db.c.

536
537
538
539
540
541
542
543
544
545

546
547
548

549
550
551
552
553
554


555
556
557
558
559
560
561
562
...
771
772
773
774
775
776
777































778
779
780
781
782
783
784
  char zPwd[2000];
  if( g.localOpen) return 1;
  if( getcwd(zPwd, sizeof(zPwd)-20)==0 ){
    db_err("pwd too big: max %d", sizeof(zPwd)-20);
  }
  n = strlen(zPwd);
  while( n>0 ){
    if( access(zPwd, W_OK) ) return 0;
    strcpy(&zPwd[n], "/_FOSSIL_");
    if( isValidLocalDb(zPwd) ){

      zPwd[n] = 0;
      g.zLocalRoot = mprintf("%s/", zPwd);
      break;

    }
    n--;
    while( n>0 && zPwd[n]!='/' ){ n--; }
    while( n>0 && zPwd[n-1]=='/' ){ n--; }
    zPwd[n] = 0;
  }


  return n>0;
}

/*
** Open the repository database given by zDbName.  If zDbName==NULL then
** get the name from the already open local database.
*/
void db_open_repository(const char *zDbName){
................................................................................
}
int db_lget_int(const char *zName, int dflt){
  return db_int(dflt, "SELECT value FROM vvar WHERE name=%Q", zName);
}
void db_lset_int(const char *zName, int value){
  db_multi_exec("REPLACE INTO vvar(name,value) VALUES(%Q,%d)", zName, value);
}
































/*
** COMMAND: open
**
** Create a new local repository.
*/
void cmd_open(void){







|


>


<
>






>
>
|







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







536
537
538
539
540
541
542
543
544
545
546
547
548

549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
...
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
  char zPwd[2000];
  if( g.localOpen) return 1;
  if( getcwd(zPwd, sizeof(zPwd)-20)==0 ){
    db_err("pwd too big: max %d", sizeof(zPwd)-20);
  }
  n = strlen(zPwd);
  while( n>0 ){
    if( access(zPwd, W_OK) ) break;
    strcpy(&zPwd[n], "/_FOSSIL_");
    if( isValidLocalDb(zPwd) ){
      /* Found a valid _FOSSIL_ file */
      zPwd[n] = 0;
      g.zLocalRoot = mprintf("%s/", zPwd);

      return 1;
    }
    n--;
    while( n>0 && zPwd[n]!='/' ){ n--; }
    while( n>0 && zPwd[n-1]=='/' ){ n--; }
    zPwd[n] = 0;
  }

  /* A _FOSSIL_ file could not be found */
  return 0;
}

/*
** Open the repository database given by zDbName.  If zDbName==NULL then
** get the name from the already open local database.
*/
void db_open_repository(const char *zDbName){
................................................................................
}
int db_lget_int(const char *zName, int dflt){
  return db_int(dflt, "SELECT value FROM vvar WHERE name=%Q", zName);
}
void db_lset_int(const char *zName, int value){
  db_multi_exec("REPLACE INTO vvar(name,value) VALUES(%Q,%d)", zName, value);
}

int db_row_to_table(const char *zFormat, ...){
  Stmt q;
  va_list ap;
  int rc;

  va_start(ap, zFormat);
  rc = db_vprepare(&q, zFormat, ap);
  va_end(ap);
  if( rc!=SQLITE_OK ){
    return rc;
  }

  @ <table border="0" cellpadding="0" cellspacing="0">
  if( db_step(&q)==SQLITE_ROW ){
    int ii;
    for(ii=0; ii<sqlite3_column_count(q.pStmt); ii++){
      char *zCol = htmlize(sqlite3_column_name(q.pStmt, ii), -1);
      char *zVal = htmlize(sqlite3_column_text(q.pStmt, ii), -1);

      @ <tr><td align=right>%s(zCol):<td width=10><td>%s(zVal)

      free(zVal);
      free(zCol);
    }
  }
  @ </table>

  return db_finalize(&q);
}


/*
** COMMAND: open
**
** Create a new local repository.
*/
void cmd_open(void){

Changes to src/deltacmd.c.

28
29
30
31
32
33
34
35
36
37
38
39

40
41
42
43
44
45
46
 
/*
** Create a delta that describes the change from pOriginal to pTarget
** and put that delta in pDelta.  The pDelta blob is assumed to be
** uninitialized.
*/
int blob_delta_create(Blob *pOriginal, Blob *pTarget, Blob *pDelta){
  blob_zero(pDelta);
  const char *zOrig, *zTarg;
  int lenOrig, lenTarg;
  int len;
  char *zRes;

  zOrig = blob_buffer(pOriginal);
  lenOrig = blob_size(pOriginal);
  zTarg = blob_buffer(pTarget);
  lenTarg = blob_size(pTarget);
  blob_resize(pDelta, lenTarg+16);
  zRes = blob_buffer(pDelta);
  len = delta_create(zOrig, lenOrig, zTarg, lenTarg, zRes);







<




>







28
29
30
31
32
33
34

35
36
37
38
39
40
41
42
43
44
45
46
 
/*
** Create a delta that describes the change from pOriginal to pTarget
** and put that delta in pDelta.  The pDelta blob is assumed to be
** uninitialized.
*/
int blob_delta_create(Blob *pOriginal, Blob *pTarget, Blob *pDelta){

  const char *zOrig, *zTarg;
  int lenOrig, lenTarg;
  int len;
  char *zRes;
  blob_zero(pDelta);
  zOrig = blob_buffer(pOriginal);
  lenOrig = blob_size(pOriginal);
  zTarg = blob_buffer(pTarget);
  lenTarg = blob_size(pTarget);
  blob_resize(pDelta, lenTarg+16);
  zRes = blob_buffer(pDelta);
  len = delta_create(zOrig, lenOrig, zTarg, lenTarg, zRes);

Changes to src/encode.c.

180
181
182
183
184
185
186




187
188
189
190
191
192
193

/*
** Remove the HTTP encodings from a string.  The conversion is done
** in-place.  Return the length of the string after conversion.
*/
int dehttpize(char *z){
  int i, j;




  i = j = 0;
  while( z[i] ){
    switch( z[i] ){
      case '%':
        if( z[i+1] && z[i+2] ){
          z[j] = AsciiToHex(z[i+1]) << 4;
          z[j] |= AsciiToHex(z[i+2]);







>
>
>
>







180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197

/*
** Remove the HTTP encodings from a string.  The conversion is done
** in-place.  Return the length of the string after conversion.
*/
int dehttpize(char *z){
  int i, j;

  /* Treat a null pointer as a zero-length string. */
  if( !z ) return 0;

  i = j = 0;
  while( z[i] ){
    switch( z[i] ){
      case '%':
        if( z[i+1] && z[i+2] ){
          z[j] = AsciiToHex(z[i+1]) << 4;
          z[j] |= AsciiToHex(z[i+2]);

Changes to src/http.c.

168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
    user_select();
    db_blob(&pw, "SELECT pw FROM user WHERE uid=%d", g.userUid);
    sha1sum_blob(&pw, &sig);
    blob_appendf(&login, "login %s %b %b\n", g.zLogin, &nonce, &sig);
  }else{
    if( g.urlPasswd==0 ){
      if( strcmp(g.urlUser,"anonymous")!=0 ){
        char *zPrompt = mprintf("password for %s", g.urlUser);
        Blob x;
        prompt_for_password(zPrompt, &x, 0);
        free(zPrompt);
        blob_append(&pw, blob_buffer(&x), blob_size(&x));
        blob_reset(&x);
      }
    }
    sha1sum_blob(&pw, &sig);
    blob_appendf(&login, "login %s %b %b\n", g.urlUser, &nonce, &sig);
  }        
  blob_reset(&nonce);
  blob_reset(&pw);







|



|
|







168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
    user_select();
    db_blob(&pw, "SELECT pw FROM user WHERE uid=%d", g.userUid);
    sha1sum_blob(&pw, &sig);
    blob_appendf(&login, "login %s %b %b\n", g.zLogin, &nonce, &sig);
  }else{
    if( g.urlPasswd==0 ){
      if( strcmp(g.urlUser,"anonymous")!=0 ){
        char *zPrompt = mprintf("password for %s: ", g.urlUser);
        Blob x;
        prompt_for_password(zPrompt, &x, 0);
        free(zPrompt);
        g.urlPasswd = blob_str(&x);
        blob_append(&pw, g.urlPasswd, -1);
      }
    }
    sha1sum_blob(&pw, &sig);
    blob_appendf(&login, "login %s %b %b\n", g.urlUser, &nonce, &sig);
  }        
  blob_reset(&nonce);
  blob_reset(&pw);

Changes to src/info.c.

101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
...
121
122
123
124
125
126
127











128



129
130
131
132
133
134
135
136
137
138
...
254
255
256
257
258
259
260

261

262
263
264
265
266
267
268
    if( rid==0 ){
      fossil_panic("no such object: %s\n", g.argv[2]);
    }
    show_common_info(rid, "uuid:", 1);
  }
}

#if 0
/*
** WEB PAGE: vinfo
**
** Return information about a version.  The version number is contained
** in g.zExtra.
*/
void vinfo_page(void){
  Stmt q;
  int rid;
................................................................................
  style_header("Version Information");
  rid = name_to_rid(g.zExtra);
  if( rid==0 ){
    @ No such object: %h(g.argv[2])
    style_footer();
    return;
  }











  db_prepare(&q,



    "SELECT uuid, datetime(mtime,'unixepoch'), datetime(ctime,'unixepoch'),"
    "         uid, size, cksum, branch, comment, type"
    "  FROM record WHERE rid=%d", rid
  );
  if( db_step(&q)==SQLITE_ROW ){
    const char *z;
    const char *zSignedBy = db_text("unknown",
                                     "SELECT login FROM repuser WHERE uid=%d",
                                     db_column_int(&q, 3));
    cType = db_column_text(&q,8)[0];
................................................................................
      hyperlink_to_uuid(zUuid);
      @ </td></tr>
    }
    db_finalize(&q);
  }
  style_footer();
}



/*
** WEB PAGE: diff
**
** Display the difference between two files determined by the v1 and v2
** query parameters.  If only v2 is given compute v1 as the parent of v2.
** If v2 has no parent, then show the complete text of v2.
*/







|

|







 







>
>
>
>
>
>
>
>
>
>
>

>
>
>
|
|
|







 







>

>







101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
...
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
...
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
    if( rid==0 ){
      fossil_panic("no such object: %s\n", g.argv[2]);
    }
    show_common_info(rid, "uuid:", 1);
  }
}

#if 1
/*
** WEBPAGE: vinfo
**
** Return information about a version.  The version number is contained
** in g.zExtra.
*/
void vinfo_page(void){
  Stmt q;
  int rid;
................................................................................
  style_header("Version Information");
  rid = name_to_rid(g.zExtra);
  if( rid==0 ){
    @ No such object: %h(g.argv[2])
    style_footer();
    return;
  }
  db_row_to_table("SELECT "
    "  blob.uuid               AS \"UUID\""
    ", datetime(rcvfrom.mtime) AS \"Created\""
    ", rcvfrom.uid             AS \"User Id\""
    ", blob.size               AS \"Size\""
    "FROM blob, rcvfrom "
    "WHERE rid=%d", rid
  );
  style_footer();
  return;

  db_prepare(&q,
    "SELECT "
      "uuid, "                                         /* 0 */
      "datetime(mtime,'unixepoch'),"                   /* 1 */
      "datetime(ctime,'unixepoch'),"                   /* 2 */
      "uid, size, cksum, branch, comment, type"        /* 3..8 */
    "FROM record WHERE rid=%d", rid
  );
  if( db_step(&q)==SQLITE_ROW ){
    const char *z;
    const char *zSignedBy = db_text("unknown",
                                     "SELECT login FROM repuser WHERE uid=%d",
                                     db_column_int(&q, 3));
    cType = db_column_text(&q,8)[0];
................................................................................
      hyperlink_to_uuid(zUuid);
      @ </td></tr>
    }
    db_finalize(&q);
  }
  style_footer();
}
#endif

#if 0
/*
** WEB PAGE: diff
**
** Display the difference between two files determined by the v1 and v2
** query parameters.  If only v2 is given compute v1 as the parent of v2.
** If v2 has no parent, then show the complete text of v2.
*/

Changes to src/login.c.

201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
    zCap = "s";
    g.noPswd = 1;
    g.isAnon = 0;
  }

  /* Check the login cookie to see if it matches a known valid user.
  */
  if( uid==0 ){
    if( (zCookie = P(login_cookie_name()))!=0 ){
      uid = db_int(0, 
              "SELECT uid FROM user"
              " WHERE uid=%d"
              "   AND cookie=%Q"
              "   AND ipaddr=%Q"
              "   AND cexpire>julianday('now')",
              atoi(zCookie), zCookie, zRemoteAddr
           );
    }else{
      uid = db_int(0, "SELECT uid FROM user WHERE login='anonymous'");
    }
  }

  if( uid==0 ){
    g.isAnon = 1;
    g.zLogin = "";
    zCap = db_get("nologin-cap","onrj");
  }else if( zCap==0 ){







<
|
|
|
|
|
|
|
|
|
<
<
<







201
202
203
204
205
206
207

208
209
210
211
212
213
214
215
216



217
218
219
220
221
222
223
    zCap = "s";
    g.noPswd = 1;
    g.isAnon = 0;
  }

  /* Check the login cookie to see if it matches a known valid user.
  */

  if( uid==0 && (zCookie = P(login_cookie_name()))!=0 ){
    uid = db_int(0, 
            "SELECT 1 FROM user"
            " WHERE uid=%d"
            "   AND cookie=%Q"
            "   AND ipaddr=%Q"
            "   AND cexpire>julianday('now')",
            atoi(zCookie), zCookie, zRemoteAddr
         );



  }

  if( uid==0 ){
    g.isAnon = 1;
    g.zLogin = "";
    zCap = db_get("nologin-cap","onrj");
  }else if( zCap==0 ){

Changes to src/xfer.c.

127
128
129
130
131
132
133

134
135
136
137
138
139
140
...
154
155
156
157
158
159
160
161
162
163
164
165
166

167
168
169
170
171
172
173
...
175
176
177
178
179
180
181







182
183
184
185
186
187
188
}


/*
** Send all pending files.
*/
static int send_all_pending(Blob *pOut){

  int sent = 0;
  int nSent = 0;
  int maxSize = db_get_int("http-msg-size", 1000000);
  Stmt q;
#if 0
  db_multi_exec(
    "CREATE TEMP TABLE priority(rid INTEGER PRIMARY KEY);"
................................................................................
      " SELECT srcid FROM delta WHERE rid=%d"
      " UNION ALL"
      " SELECT rid FROM delta WHERE srcid=%d",
      rid, rid
    );
  }
#endif
  db_prepare(&q, "SELECT rid FROM pending");
  while( db_step(&q)==SQLITE_ROW ){
    int rid = db_column_int(&q, 0);
    if( sent<maxSize ){
      sent += send_file(rid, pOut);
      nSent++;

    }else{
      char *zUuid = db_text(0,
                      "SELECT uuid FROM blob WHERE rid=%d AND size>=0", rid);
      if( zUuid ){
        if( pOut ){
          blob_appendf(pOut, "igot %s\n", zUuid);
        }else{
................................................................................
        }
        free(zUuid);
      }
    }
  }
  db_finalize(&q);
  







#if 0
  db_multi_exec("DROP TABLE priority");
#endif
  return nSent;
}









>







 







|





>







 







>
>
>
>
>
>
>







127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
...
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
...
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
}


/*
** Send all pending files.
*/
static int send_all_pending(Blob *pOut){
  int iRidSent = 0;
  int sent = 0;
  int nSent = 0;
  int maxSize = db_get_int("http-msg-size", 1000000);
  Stmt q;
#if 0
  db_multi_exec(
    "CREATE TEMP TABLE priority(rid INTEGER PRIMARY KEY);"
................................................................................
      " SELECT srcid FROM delta WHERE rid=%d"
      " UNION ALL"
      " SELECT rid FROM delta WHERE srcid=%d",
      rid, rid
    );
  }
#endif
  db_prepare(&q, "SELECT rid FROM pending ORDER BY rid");
  while( db_step(&q)==SQLITE_ROW ){
    int rid = db_column_int(&q, 0);
    if( sent<maxSize ){
      sent += send_file(rid, pOut);
      nSent++;
      iRidSent = rid;
    }else{
      char *zUuid = db_text(0,
                      "SELECT uuid FROM blob WHERE rid=%d AND size>=0", rid);
      if( zUuid ){
        if( pOut ){
          blob_appendf(pOut, "igot %s\n", zUuid);
        }else{
................................................................................
        }
        free(zUuid);
      }
    }
  }
  db_finalize(&q);
  
  /* Delete the 'pending' records for all files just sent. Otherwise,
  ** we can wind up sending some files more than once.
  */
  if( nSent>0 ){
    db_multi_exec("DELETE FROM pending WHERE rid <= %d", iRidSent);
  }

#if 0
  db_multi_exec("DROP TABLE priority");
#endif
  return nSent;
}