Fossil SCM

On the /urllist page, hyperlinks to URLs that include a username omit the username.

drh 2021-12-23 13:16 trunk
Commit f0cdbd8b95f5b8eb69ebe21bdd2d30cd47a5827a13c53d1ea5072e6a2bdd2e9e
3 files changed +3 -2 +5 -4 +37
+3 -2
--- src/db.c
+++ src/db.c
@@ -1409,12 +1409,13 @@
14091409
sqlite3_create_function(db, "obscure", 1, SQLITE_UTF8, 0,
14101410
db_obscure, 0, 0);
14111411
sqlite3_create_function(db, "protected_setting", 1, SQLITE_UTF8, 0,
14121412
db_protected_setting_func, 0, 0);
14131413
sqlite3_create_function(db, "win_reserved", 1, SQLITE_UTF8, 0,
1414
- db_win_reserved_func,0,0
1415
- );
1414
+ db_win_reserved_func,0,0);
1415
+ sqlite3_create_function(db, "url_nouser", 1, SQLITE_UTF8, 0,
1416
+ url_nouser_func,0,0);
14161417
}
14171418
14181419
#if USE_SEE
14191420
/*
14201421
** This is a pointer to the saved database encryption key string.
14211422
--- src/db.c
+++ src/db.c
@@ -1409,12 +1409,13 @@
1409 sqlite3_create_function(db, "obscure", 1, SQLITE_UTF8, 0,
1410 db_obscure, 0, 0);
1411 sqlite3_create_function(db, "protected_setting", 1, SQLITE_UTF8, 0,
1412 db_protected_setting_func, 0, 0);
1413 sqlite3_create_function(db, "win_reserved", 1, SQLITE_UTF8, 0,
1414 db_win_reserved_func,0,0
1415 );
 
1416 }
1417
1418 #if USE_SEE
1419 /*
1420 ** This is a pointer to the saved database encryption key string.
1421
--- src/db.c
+++ src/db.c
@@ -1409,12 +1409,13 @@
1409 sqlite3_create_function(db, "obscure", 1, SQLITE_UTF8, 0,
1410 db_obscure, 0, 0);
1411 sqlite3_create_function(db, "protected_setting", 1, SQLITE_UTF8, 0,
1412 db_protected_setting_func, 0, 0);
1413 sqlite3_create_function(db, "win_reserved", 1, SQLITE_UTF8, 0,
1414 db_win_reserved_func,0,0);
1415 sqlite3_create_function(db, "url_nouser", 1, SQLITE_UTF8, 0,
1416 url_nouser_func,0,0);
1417 }
1418
1419 #if USE_SEE
1420 /*
1421 ** This is a pointer to the saved database encryption key string.
1422
+5 -4
--- src/stat.c
+++ src/stat.c
@@ -651,29 +651,30 @@
651651
652652
cnt = 0;
653653
db_prepare(&q,
654654
"SELECT"
655655
" value,"
656
+ " url_nouser(value),"
656657
" substr(name,10),"
657658
" datetime(mtime,'unixepoch')"
658659
"FROM config\n"
659660
"WHERE name GLOB 'sync-url:*'\n"
660661
"ORDER BY 2"
661662
);
662663
while( db_step(&q)==SQLITE_ROW ){
663664
const char *zUrl = db_column_text(&q, 0);
664
- const char *zName = db_column_text(&q, 1);
665
+ const char *zLink = db_column_text(&q, 1);
666
+ const char *zName = db_column_text(&q, 2);
665667
if( cnt++==0 ){
666668
@ <div class="section">Defined sync targets</div>
667669
@ <table border='0' width='100%%'>
668670
}
669671
@ <tr><td>%h(zName)</td><td>&nbsp;&nbsp;</td>
670
- @ <td width='95%%'><a href='%h(zUrl)'>%h(zUrl)</a></td>
671
- @ <td><nobr>%h(db_column_text(&q,2))</nobr></td></tr>
672
+ @ <td width='95%%'><a href='%h(zLink)'>%h(zUrl)</a></td>
673
+ @ <td><nobr>%h(db_column_text(&q,3))</nobr></td></tr>
672674
}
673675
db_finalize(&q);
674
- fossil_free(zPriorRepo);
675676
if( cnt ){
676677
@ </table>
677678
total += cnt;
678679
}
679680
680681
--- src/stat.c
+++ src/stat.c
@@ -651,29 +651,30 @@
651
652 cnt = 0;
653 db_prepare(&q,
654 "SELECT"
655 " value,"
 
656 " substr(name,10),"
657 " datetime(mtime,'unixepoch')"
658 "FROM config\n"
659 "WHERE name GLOB 'sync-url:*'\n"
660 "ORDER BY 2"
661 );
662 while( db_step(&q)==SQLITE_ROW ){
663 const char *zUrl = db_column_text(&q, 0);
664 const char *zName = db_column_text(&q, 1);
 
665 if( cnt++==0 ){
666 @ <div class="section">Defined sync targets</div>
667 @ <table border='0' width='100%%'>
668 }
669 @ <tr><td>%h(zName)</td><td>&nbsp;&nbsp;</td>
670 @ <td width='95%%'><a href='%h(zUrl)'>%h(zUrl)</a></td>
671 @ <td><nobr>%h(db_column_text(&q,2))</nobr></td></tr>
672 }
673 db_finalize(&q);
674 fossil_free(zPriorRepo);
675 if( cnt ){
676 @ </table>
677 total += cnt;
678 }
679
680
--- src/stat.c
+++ src/stat.c
@@ -651,29 +651,30 @@
651
652 cnt = 0;
653 db_prepare(&q,
654 "SELECT"
655 " value,"
656 " url_nouser(value),"
657 " substr(name,10),"
658 " datetime(mtime,'unixepoch')"
659 "FROM config\n"
660 "WHERE name GLOB 'sync-url:*'\n"
661 "ORDER BY 2"
662 );
663 while( db_step(&q)==SQLITE_ROW ){
664 const char *zUrl = db_column_text(&q, 0);
665 const char *zLink = db_column_text(&q, 1);
666 const char *zName = db_column_text(&q, 2);
667 if( cnt++==0 ){
668 @ <div class="section">Defined sync targets</div>
669 @ <table border='0' width='100%%'>
670 }
671 @ <tr><td>%h(zName)</td><td>&nbsp;&nbsp;</td>
672 @ <td width='95%%'><a href='%h(zLink)'>%h(zUrl)</a></td>
673 @ <td><nobr>%h(db_column_text(&q,3))</nobr></td></tr>
674 }
675 db_finalize(&q);
 
676 if( cnt ){
677 @ </table>
678 total += cnt;
679 }
680
681
+37
--- src/url.c
+++ src/url.c
@@ -328,10 +328,47 @@
328328
}
329329
blob_appendf(&x, "%T", p->path);
330330
(void)blob_str(&x);
331331
return x.aData;
332332
}
333
+
334
+/*
335
+** Construct a URL for a UrlData object that omits the
336
+** login name and password, into memory obtained from fossil_malloc()
337
+** and return a pointer to that URL text.
338
+*/
339
+char *url_nouser(const UrlData *p){
340
+ Blob x = BLOB_INITIALIZER;
341
+ if( p->isFile || p->user==0 || p->user[0]==0 ){
342
+ return fossil_strdup(p->canonical);
343
+ }
344
+ blob_appendf(&x, "%s://", p->protocol);
345
+ blob_appendf(&x, "%T", p->name);
346
+ if( p->dfltPort!=p->port ){
347
+ blob_appendf(&x, ":%d", p->port);
348
+ }
349
+ blob_appendf(&x, "%T", p->path);
350
+ (void)blob_str(&x);
351
+ return x.aData;
352
+}
353
+
354
+/*
355
+** SQL function to remove the username/password from a URL
356
+*/
357
+void url_nouser_func(
358
+ sqlite3_context *context,
359
+ int argc,
360
+ sqlite3_value **argv
361
+){
362
+ const char *zOrig = (const char*)sqlite3_value_text(argv[0]);
363
+ UrlData x;
364
+ if( zOrig==0 ) return;
365
+ memset(&x, 0, sizeof(x));
366
+ url_parse_local(zOrig, URL_OMIT_USER, &x);
367
+ sqlite3_result_text(context, x.canonical, -1, SQLITE_TRANSIENT);
368
+ url_unparse(&x);
369
+}
333370
334371
/*
335372
** Reclaim malloced memory from a UrlData object
336373
*/
337374
void url_unparse(UrlData *p){
338375
--- src/url.c
+++ src/url.c
@@ -328,10 +328,47 @@
328 }
329 blob_appendf(&x, "%T", p->path);
330 (void)blob_str(&x);
331 return x.aData;
332 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
333
334 /*
335 ** Reclaim malloced memory from a UrlData object
336 */
337 void url_unparse(UrlData *p){
338
--- src/url.c
+++ src/url.c
@@ -328,10 +328,47 @@
328 }
329 blob_appendf(&x, "%T", p->path);
330 (void)blob_str(&x);
331 return x.aData;
332 }
333
334 /*
335 ** Construct a URL for a UrlData object that omits the
336 ** login name and password, into memory obtained from fossil_malloc()
337 ** and return a pointer to that URL text.
338 */
339 char *url_nouser(const UrlData *p){
340 Blob x = BLOB_INITIALIZER;
341 if( p->isFile || p->user==0 || p->user[0]==0 ){
342 return fossil_strdup(p->canonical);
343 }
344 blob_appendf(&x, "%s://", p->protocol);
345 blob_appendf(&x, "%T", p->name);
346 if( p->dfltPort!=p->port ){
347 blob_appendf(&x, ":%d", p->port);
348 }
349 blob_appendf(&x, "%T", p->path);
350 (void)blob_str(&x);
351 return x.aData;
352 }
353
354 /*
355 ** SQL function to remove the username/password from a URL
356 */
357 void url_nouser_func(
358 sqlite3_context *context,
359 int argc,
360 sqlite3_value **argv
361 ){
362 const char *zOrig = (const char*)sqlite3_value_text(argv[0]);
363 UrlData x;
364 if( zOrig==0 ) return;
365 memset(&x, 0, sizeof(x));
366 url_parse_local(zOrig, URL_OMIT_USER, &x);
367 sqlite3_result_text(context, x.canonical, -1, SQLITE_TRANSIENT);
368 url_unparse(&x);
369 }
370
371 /*
372 ** Reclaim malloced memory from a UrlData object
373 */
374 void url_unparse(UrlData *p){
375

Keyboard Shortcuts

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