Fossil SCM
Merge trunk into rss-content.
Commit
f118634c5caefd1fcae765b2298eb86e9a8378046e3e9db8e7c83c90d34c005b
Parent
d7d3fdab9e3b1a1…
74 files changed
+1
-2
+440
-282
+1551
-532
+32
-8
+17
-41
+43
-73
+30
-37
+72
-10
+1
-1
+1199
-181
+20
-1
+1
-1
+2
+3
-2
+4
+2
+1
+37
-8
+2
-1
+177
-1
+26
-14
+12
-11
+16
-4
+1
-1
+14
-7
+1
-1
+1301
-214
+1301
-214
+661
+8
-5
+4
+1295
-35
+5
-6
+10
-10
+62
-7
+3
-2
+101
-38
+3
-1
+2
-1
+6
-1
+98
-53
+39
-3
+61
-21
+128
-1
+251
-58
+2
-2
+1
-1
+4
+4
+13
-3
+34
+17
-2
+22
-3
+33
+107
-27
+18
+11
-6
+2
-2
+11
-39
+11
-39
+16
-15
+115
-43
+4
-1
+2
+4
+45
-36
+26
+2
-2
+28
-10
+193
-1
+142
-119
+6
-6
+3
-1
+3
-3
~
extsrc/qrf.h
~
extsrc/shell.c
~
extsrc/sqlite3.c
~
extsrc/sqlite3.h
~
skins/ardoise/css.txt
~
skins/blitz/css.txt
~
skins/darkmode/css.txt
~
src/ajax.c
~
src/alerts.c
~
src/attach.c
~
src/builtin.c
~
src/bundle.c
~
src/capabilities.c
~
src/cgi.c
~
src/checkin.c
~
src/comformat.c
~
src/configure.c
~
src/content.c
~
src/db.c
~
src/default.css
~
src/delta.c
~
src/deltafunc.c
~
src/diff.tcl
~
src/diffcmd.c
~
src/event.c
~
src/finfo.c
~
src/forum.c
~
src/forum.c
~
src/fossil.attach.js
~
src/fossil.bootstrap.js
~
src/fossil.dom.js
~
src/fossil.page.forumpost.js
~
src/fossil.page.wikiedit.js
~
src/fossil.popupwidget.js
~
src/fossil.storage.js
~
src/fossil.tabs.js
~
src/info.c
~
src/login.c
~
src/main.c
~
src/main.mk
~
src/manifest.c
~
src/markdown.md
~
src/merge.c
~
src/moderate.c
~
src/name.c
~
src/schema.c
~
src/setup.c
~
src/setupuser.c
~
src/sqlcmd.c
~
src/stash.c
~
src/stat.c
~
src/statrep.c
~
src/style.c
~
src/style.forum.css
~
src/tag.c
~
src/timeline.c
~
src/tkt.c
~
src/util.c
~
src/wiki.c
~
src/wiki.c
~
src/wiki.wiki
~
src/wikiformat.c
~
tools/makemake.tcl
~
win/Makefile.mingw
~
win/Makefile.msc
~
www/caps/ref.html
~
www/changes.wiki
~
www/customskin.md
~
www/fileformat.wiki
~
www/forum.wiki
~
www/fossil-v-git.wiki
~
www/javascript.md
~
www/server/any/cgi.md
~
www/sync.wiki
+1
-2
| --- extsrc/qrf.h | ||
| +++ extsrc/qrf.h | ||
| @@ -68,12 +68,11 @@ | ||
| 68 | 68 | const sqlite3_qrf_spec *pSpec, /* Result format specification */ |
| 69 | 69 | char **pzErr /* OUT: Write error message here */ |
| 70 | 70 | ); |
| 71 | 71 | |
| 72 | 72 | /* |
| 73 | -** Range of values for sqlite3_qrf_spec.aWidth[] entries and for | |
| 74 | -** sqlite3_qrf_spec.mxColWidth and .nScreenWidth | |
| 73 | +** Range of values for sqlite3_qrf_spec.aWidth[] entries. | |
| 75 | 74 | */ |
| 76 | 75 | #define QRF_MAX_WIDTH 10000 |
| 77 | 76 | #define QRF_MIN_WIDTH 0 |
| 78 | 77 | |
| 79 | 78 | /* |
| 80 | 79 |
| --- extsrc/qrf.h | |
| +++ extsrc/qrf.h | |
| @@ -68,12 +68,11 @@ | |
| 68 | const sqlite3_qrf_spec *pSpec, /* Result format specification */ |
| 69 | char **pzErr /* OUT: Write error message here */ |
| 70 | ); |
| 71 | |
| 72 | /* |
| 73 | ** Range of values for sqlite3_qrf_spec.aWidth[] entries and for |
| 74 | ** sqlite3_qrf_spec.mxColWidth and .nScreenWidth |
| 75 | */ |
| 76 | #define QRF_MAX_WIDTH 10000 |
| 77 | #define QRF_MIN_WIDTH 0 |
| 78 | |
| 79 | /* |
| 80 |
| --- extsrc/qrf.h | |
| +++ extsrc/qrf.h | |
| @@ -68,12 +68,11 @@ | |
| 68 | const sqlite3_qrf_spec *pSpec, /* Result format specification */ |
| 69 | char **pzErr /* OUT: Write error message here */ |
| 70 | ); |
| 71 | |
| 72 | /* |
| 73 | ** Range of values for sqlite3_qrf_spec.aWidth[] entries. |
| 74 | */ |
| 75 | #define QRF_MAX_WIDTH 10000 |
| 76 | #define QRF_MIN_WIDTH 0 |
| 77 | |
| 78 | /* |
| 79 |
+440
-282
| --- extsrc/shell.c | ||
| +++ extsrc/shell.c | ||
| @@ -5,16 +5,16 @@ | ||
| 5 | 5 | ** |
| 6 | 6 | ** ext/expert/sqlite3expert.c |
| 7 | 7 | ** ext/expert/sqlite3expert.h |
| 8 | 8 | ** ext/intck/sqlite3intck.c |
| 9 | 9 | ** ext/intck/sqlite3intck.h |
| 10 | -** ext/misc/analyze.c | |
| 11 | 10 | ** ext/misc/appendvfs.c |
| 12 | 11 | ** ext/misc/base64.c |
| 13 | 12 | ** ext/misc/base85.c |
| 14 | 13 | ** ext/misc/completion.c |
| 15 | 14 | ** ext/misc/decimal.c |
| 15 | +** ext/misc/diskused.c | |
| 16 | 16 | ** ext/misc/fileio.c |
| 17 | 17 | ** ext/misc/ieee754.c |
| 18 | 18 | ** ext/misc/memtrace.c |
| 19 | 19 | ** ext/misc/pcachetrace.c |
| 20 | 20 | ** ext/misc/regexp.c |
| @@ -154,10 +154,11 @@ | ||
| 154 | 154 | #include <string.h> |
| 155 | 155 | #include <stdio.h> |
| 156 | 156 | #include <assert.h> |
| 157 | 157 | #include <math.h> |
| 158 | 158 | #include <stdint.h> |
| 159 | +#include <time.h> | |
| 159 | 160 | #include "sqlite3.h" |
| 160 | 161 | typedef sqlite3_int64 i64; |
| 161 | 162 | typedef sqlite3_uint64 u64; |
| 162 | 163 | typedef unsigned char u8; |
| 163 | 164 | #include <ctype.h> |
| @@ -190,13 +191,14 @@ | ||
| 190 | 191 | #include <sys/stat.h> |
| 191 | 192 | |
| 192 | 193 | #if HAVE_READLINE |
| 193 | 194 | # include <readline/readline.h> |
| 194 | 195 | # include <readline/history.h> |
| 195 | -#endif | |
| 196 | - | |
| 197 | -#if HAVE_EDITLINE | |
| 196 | +#elif HAVE_EDITLINE | |
| 197 | +/* If both HAVE_READLINE and HAVE_EDITLINE are true, assume that this | |
| 198 | +** libedit installation does not have its own headers, instead using | |
| 199 | +** those from libreadline. */ | |
| 198 | 200 | # include <editline/readline.h> |
| 199 | 201 | #endif |
| 200 | 202 | |
| 201 | 203 | #if HAVE_EDITLINE || HAVE_READLINE |
| 202 | 204 | |
| @@ -744,12 +746,11 @@ | ||
| 744 | 746 | const sqlite3_qrf_spec *pSpec, /* Result format specification */ |
| 745 | 747 | char **pzErr /* OUT: Write error message here */ |
| 746 | 748 | ); |
| 747 | 749 | |
| 748 | 750 | /* |
| 749 | -** Range of values for sqlite3_qrf_spec.aWidth[] entries and for | |
| 750 | -** sqlite3_qrf_spec.mxColWidth and .nScreenWidth | |
| 751 | +** Range of values for sqlite3_qrf_spec.aWidth[] entries. | |
| 751 | 752 | */ |
| 752 | 753 | #define QRF_MAX_WIDTH 10000 |
| 753 | 754 | #define QRF_MIN_WIDTH 0 |
| 754 | 755 | |
| 755 | 756 | /* |
| @@ -1129,10 +1130,14 @@ | ||
| 1129 | 1130 | sqlite3_str_append(pOut, "-", 1); |
| 1130 | 1131 | } |
| 1131 | 1132 | if( N<10000 ){ |
| 1132 | 1133 | sqlite3_str_appendf(pOut, "%4lld ", N); |
| 1133 | 1134 | return; |
| 1135 | + } | |
| 1136 | + if( N>=9223372036854775800LL ){ | |
| 1137 | + sqlite3_str_appendf(pOut, "%.2fE", 1e-18*(double)N); | |
| 1138 | + return; | |
| 1134 | 1139 | } |
| 1135 | 1140 | for(i=1; i<=18; i++){ |
| 1136 | 1141 | N = (N+5)/10; |
| 1137 | 1142 | if( N<10000 ){ |
| 1138 | 1143 | int n = (int)N; |
| @@ -1289,12 +1294,12 @@ | ||
| 1289 | 1294 | if( nCycle>=0 || nLoop>=0 || nRow>=0 ){ |
| 1290 | 1295 | int nSp = 0; |
| 1291 | 1296 | sqlite3_str_reset(pStats); |
| 1292 | 1297 | if( nCycle>=0 && nTotal>0 ){ |
| 1293 | 1298 | qrfApproxInt64(pStats, nCycle); |
| 1294 | - sqlite3_str_appendf(pStats, " %3d%%", | |
| 1295 | - ((nCycle*100)+nTotal/2) / nTotal | |
| 1299 | + sqlite3_str_appendf(pStats, " %3.0f%%", | |
| 1300 | + ((100.0*(double)nCycle)+nTotal/2.0) / (double)nTotal | |
| 1296 | 1301 | ); |
| 1297 | 1302 | nSp = 2; |
| 1298 | 1303 | } |
| 1299 | 1304 | if( nLoop>=0 ){ |
| 1300 | 1305 | if( nSp ) sqlite3_str_appendchar(pStats, nSp, ' '); |
| @@ -1787,11 +1792,11 @@ | ||
| 1787 | 1792 | } |
| 1788 | 1793 | if( i>0 ){ |
| 1789 | 1794 | sqlite3_str_append(pOut, (const char*)z, i); |
| 1790 | 1795 | } |
| 1791 | 1796 | switch( z[i] ){ |
| 1792 | - case '>': sqlite3_str_append(pOut, "<", 4); break; | |
| 1797 | + case '>': sqlite3_str_append(pOut, ">", 4); break; | |
| 1793 | 1798 | case '&': sqlite3_str_append(pOut, "&", 5); break; |
| 1794 | 1799 | case '<': sqlite3_str_append(pOut, "<", 4); break; |
| 1795 | 1800 | case '"': sqlite3_str_append(pOut, """, 6); break; |
| 1796 | 1801 | case '\'': sqlite3_str_append(pOut, "'", 5); break; |
| 1797 | 1802 | default: i--; |
| @@ -2281,11 +2286,11 @@ | ||
| 2281 | 2286 | if( bWrap && z[i]!=0 && !qrfSpace(z[i]) && qrfAlnum(c)==qrfAlnum(z[i]) ){ |
| 2282 | 2287 | /* Perhaps try to back up to a better place to break the line */ |
| 2283 | 2288 | for(k=i-1; k>=i/2; k--){ |
| 2284 | 2289 | if( qrfSpace(z[k]) ) break; |
| 2285 | 2290 | } |
| 2286 | - if( k<i/2 ){ | |
| 2291 | + if( k<i/2 && i/2>0 ){ | |
| 2287 | 2292 | for(k=i; k>=i/2; k--){ |
| 2288 | 2293 | if( qrfAlnum(z[k-1])!=qrfAlnum(z[k]) && (z[k]&0xc0)!=0x80 ) break; |
| 2289 | 2294 | } |
| 2290 | 2295 | } |
| 2291 | 2296 | if( k>=i/2 ){ |
| @@ -2532,16 +2537,16 @@ | ||
| 2532 | 2537 | const char *azDash[2] = { |
| 2533 | 2538 | BOX_24 BOX_24 BOX_24 BOX_24 BOX_24 BOX_24 BOX_24 BOX_24 BOX_24 BOX_24, |
| 2534 | 2539 | DBL_24 DBL_24 DBL_24 DBL_24 DBL_24 DBL_24 DBL_24 DBL_24 DBL_24 DBL_24 |
| 2535 | 2540 | };/* 0 1 2 3 4 5 6 7 8 9 */ |
| 2536 | 2541 | const int nDash = 30; |
| 2537 | - N *= 3; | |
| 2538 | - while( N>nDash ){ | |
| 2542 | + i64 nn = 3*(i64)N; | |
| 2543 | + while( nn>nDash ){ | |
| 2539 | 2544 | sqlite3_str_append(pOut, azDash[bDbl], nDash); |
| 2540 | - N -= nDash; | |
| 2545 | + nn -= nDash; | |
| 2541 | 2546 | } |
| 2542 | - sqlite3_str_append(pOut, azDash[bDbl], N); | |
| 2547 | + sqlite3_str_append(pOut, azDash[bDbl], (int)nn); | |
| 2543 | 2548 | } |
| 2544 | 2549 | |
| 2545 | 2550 | /* |
| 2546 | 2551 | ** Draw a horizontal separator for a QRF_STYLE_Box table. |
| 2547 | 2552 | */ |
| @@ -2610,11 +2615,11 @@ | ||
| 2610 | 2615 | int nSW /* Screen width */ |
| 2611 | 2616 | ){ |
| 2612 | 2617 | int i; /* Loop counter */ |
| 2613 | 2618 | int nr; /* Number of rows */ |
| 2614 | 2619 | int w = 0; /* Width of the current column */ |
| 2615 | - int t; /* Total width of all columns */ | |
| 2620 | + i64 t; /* Total width of all columns */ | |
| 2616 | 2621 | int *aw; /* Array of individual column widths */ |
| 2617 | 2622 | |
| 2618 | 2623 | aw = sqlite3_malloc64( sizeof(int)*nCol ); |
| 2619 | 2624 | if( aw==0 ){ |
| 2620 | 2625 | qrfOom(p); |
| @@ -2748,12 +2753,15 @@ | ||
| 2748 | 2753 | }else{ |
| 2749 | 2754 | sepW = pData->nCol*3 + 1; |
| 2750 | 2755 | if( p->spec.bBorder==QRF_No ) sepW -= 2; |
| 2751 | 2756 | } |
| 2752 | 2757 | nCol = pData->nCol; |
| 2753 | - for(i=sumW=0; i<nCol; i++) sumW += pData->a[i].w; | |
| 2754 | - if( p->spec.nScreenWidth >= sumW+sepW ) return; | |
| 2758 | + for(i=0, sumW=0; i<nCol; i++){ | |
| 2759 | + if( sumW > 2147483647 - pData->a[i].w ) return; | |
| 2760 | + sumW += pData->a[i].w; | |
| 2761 | + } | |
| 2762 | + if( p->spec.nScreenWidth >= (i64)sumW + sepW ) return; | |
| 2755 | 2763 | |
| 2756 | 2764 | /* First thing to do is reduce the separation between columns */ |
| 2757 | 2765 | pData->nMargin = 0; |
| 2758 | 2766 | if( p->spec.eStyle==QRF_STYLE_Column ){ |
| 2759 | 2767 | sepW = pData->nCol - 1; |
| @@ -3624,11 +3632,11 @@ | ||
| 3624 | 3632 | p->nRow = 0; |
| 3625 | 3633 | sz = sizeof(sqlite3_qrf_spec); |
| 3626 | 3634 | memcpy(&p->spec, pSpec, sz); |
| 3627 | 3635 | if( p->spec.zNull==0 ) p->spec.zNull = ""; |
| 3628 | 3636 | p->mxWidth = p->spec.nScreenWidth; |
| 3629 | - if( p->mxWidth<=0 ) p->mxWidth = QRF_MAX_WIDTH; | |
| 3637 | + if( p->mxWidth<=0 ) p->mxWidth = 2147483647; | |
| 3630 | 3638 | p->mxHeight = p->spec.nLineLimit; |
| 3631 | 3639 | if( p->mxHeight<=0 ) p->mxHeight = 2147483647; |
| 3632 | 3640 | if( p->spec.eStyle>QRF_STYLE_Table ) p->spec.eStyle = QRF_Auto; |
| 3633 | 3641 | if( p->spec.eEsc>QRF_ESC_Symbol ) p->spec.eEsc = QRF_Auto; |
| 3634 | 3642 | if( p->spec.eText>QRF_TEXT_Relaxed ) p->spec.eText = QRF_Auto; |
| @@ -5272,10 +5280,14 @@ | ||
| 5272 | 5280 | #include <stdarg.h> |
| 5273 | 5281 | |
| 5274 | 5282 | /****************************************************************************** |
| 5275 | 5283 | ** The Hash Engine |
| 5276 | 5284 | */ |
| 5285 | +#if defined(__GNUC__) && __GNUC__>=11 | |
| 5286 | +# pragma GCC diagnostic push | |
| 5287 | +# pragma GCC diagnostic ignored "-Wstringop-overread" | |
| 5288 | +#endif | |
| 5277 | 5289 | /* Context for the SHA1 hash */ |
| 5278 | 5290 | typedef struct SHA1Context SHA1Context; |
| 5279 | 5291 | struct SHA1Context { |
| 5280 | 5292 | unsigned int state[5]; |
| 5281 | 5293 | unsigned int count[2]; |
| @@ -5412,11 +5424,11 @@ | ||
| 5412 | 5424 | } |
| 5413 | 5425 | j = 0; |
| 5414 | 5426 | }else{ |
| 5415 | 5427 | i = 0; |
| 5416 | 5428 | } |
| 5417 | - (void)memcpy(&p->buffer[j], &data[i], len - i); | |
| 5429 | + if( len-i>0 ) (void)memcpy(&p->buffer[j], &data[i], len - i); | |
| 5418 | 5430 | } |
| 5419 | 5431 | |
| 5420 | 5432 | /* Compute a string using sqlite3_vsnprintf() and hash it */ |
| 5421 | 5433 | static void hash_step_vformat( |
| 5422 | 5434 | SHA1Context *p, /* Add content to this context */ |
| @@ -5467,10 +5479,13 @@ | ||
| 5467 | 5479 | zOut[i*2+1] = zEncode[digest[i] & 0xf]; |
| 5468 | 5480 | } |
| 5469 | 5481 | zOut[i*2]= 0; |
| 5470 | 5482 | } |
| 5471 | 5483 | } |
| 5484 | +#if defined(__GNUC__) && __GNUC__>=11 | |
| 5485 | +# pragma GCC diagnostic pop | |
| 5486 | +#endif | |
| 5472 | 5487 | /* End of the hashing logic |
| 5473 | 5488 | *****************************************************************************/ |
| 5474 | 5489 | |
| 5475 | 5490 | /* |
| 5476 | 5491 | ** Two SQL functions: sha1(X) and sha1b(X). |
| @@ -6056,32 +6071,41 @@ | ||
| 6056 | 6071 | } |
| 6057 | 6072 | z[i] = 0; |
| 6058 | 6073 | sqlite3_result_text(pCtx, z, i, sqlite3_free); |
| 6059 | 6074 | } |
| 6060 | 6075 | |
| 6076 | +/* Forward declaration */ | |
| 6077 | +static void decimal_expand(Decimal *p, int nDigit, int nFrac); | |
| 6078 | + | |
| 6061 | 6079 | /* |
| 6062 | 6080 | ** Round a decimal value to N significant digits. N must be positive. |
| 6063 | 6081 | */ |
| 6064 | 6082 | static void decimal_round(Decimal *p, int N){ |
| 6065 | 6083 | int i; |
| 6066 | - int nZero; | |
| 6084 | + int nZero; /* Number of leading zeros */ | |
| 6067 | 6085 | if( N<1 ) return; |
| 6068 | 6086 | if( p==0 ) return; |
| 6069 | 6087 | if( p->nDigit<=N ) return; |
| 6070 | 6088 | for(nZero=0; nZero<p->nDigit && p->a[nZero]==0; nZero++){} |
| 6071 | 6089 | N += nZero; |
| 6072 | 6090 | if( p->nDigit<=N ) return; |
| 6073 | - if( p->a[N]>4 ){ | |
| 6091 | + if( p->a[N]>=5 ){ | |
| 6092 | + /* If all leading digits are 9, increase the number of digits | |
| 6093 | + ** by adding a new 0 to the front */ | |
| 6094 | + for(i=0; i<N && p->a[i]==9; i++){} | |
| 6095 | + if( i==N ){ | |
| 6096 | + decimal_expand(p, p->nDigit+1, 0); | |
| 6097 | + if( p->oom ) return; | |
| 6098 | + } | |
| 6099 | + | |
| 6100 | + /* Do the rounding */ | |
| 6074 | 6101 | p->a[N-1]++; |
| 6075 | 6102 | for(i=N-1; i>0 && p->a[i]>9; i--){ |
| 6076 | 6103 | p->a[i] = 0; |
| 6077 | 6104 | p->a[i-1]++; |
| 6078 | 6105 | } |
| 6079 | - if( p->a[0]>9 ){ | |
| 6080 | - p->a[0] = 1; | |
| 6081 | - p->nFrac--; | |
| 6082 | - } | |
| 6106 | + assert( p->a[0]<=9 ); | |
| 6083 | 6107 | } |
| 6084 | 6108 | memset(&p->a[N], 0, p->nDigit - N); |
| 6085 | 6109 | } |
| 6086 | 6110 | |
| 6087 | 6111 | /* |
| @@ -8363,19 +8387,26 @@ | ||
| 8363 | 8387 | } |
| 8364 | 8388 | }else{ |
| 8365 | 8389 | iMin = iMax = sqlite3_value_int64(argv[iArg++]); |
| 8366 | 8390 | } |
| 8367 | 8391 | }else{ |
| 8368 | - if( idxNum & 0x0300 ){ /* value>X or value>=X */ | |
| 8392 | + if( idxNum & 0x0300 ){ /* value>X (0x200) or value>=X (0x100) */ | |
| 8369 | 8393 | if( sqlite3_value_numeric_type(argv[iArg])==SQLITE_FLOAT ){ |
| 8370 | 8394 | double r = sqlite3_value_double(argv[iArg++]); |
| 8371 | - if( r<(double)SMALLEST_INT64 ){ | |
| 8395 | + if( r<=(double)SMALLEST_INT64 ){ | |
| 8372 | 8396 | iMin = SMALLEST_INT64; |
| 8373 | - }else if( (idxNum & 0x0200)!=0 && r==seriesCeil(r) ){ | |
| 8374 | - iMin = (sqlite3_int64)seriesCeil(r+1.0); | |
| 8397 | + }else if( r>(double)LARGEST_INT64 ){ | |
| 8398 | + goto series_no_rows; | |
| 8375 | 8399 | }else{ |
| 8376 | 8400 | iMin = (sqlite3_int64)seriesCeil(r); |
| 8401 | + if( iMin<0 && r>0.0 ){ | |
| 8402 | + iMin = LARGEST_INT64; | |
| 8403 | + } | |
| 8404 | + if( (idxNum & 0x0200)!=0 && r==seriesCeil(r) ){ | |
| 8405 | + if( iMin==LARGEST_INT64 ) goto series_no_rows; | |
| 8406 | + iMin++; | |
| 8407 | + } | |
| 8377 | 8408 | } |
| 8378 | 8409 | }else{ |
| 8379 | 8410 | iMin = sqlite3_value_int64(argv[iArg++]); |
| 8380 | 8411 | if( (idxNum & 0x0200)!=0 ){ |
| 8381 | 8412 | if( iMin==LARGEST_INT64 ){ |
| @@ -8384,19 +8415,25 @@ | ||
| 8384 | 8415 | iMin++; |
| 8385 | 8416 | } |
| 8386 | 8417 | } |
| 8387 | 8418 | } |
| 8388 | 8419 | } |
| 8389 | - if( idxNum & 0x3000 ){ /* value<X or value<=X */ | |
| 8420 | + if( idxNum & 0x3000 ){ /* value<X (0x2000) or value<=X (0x1000) */ | |
| 8390 | 8421 | if( sqlite3_value_numeric_type(argv[iArg])==SQLITE_FLOAT ){ |
| 8391 | 8422 | double r = sqlite3_value_double(argv[iArg++]); |
| 8392 | - if( r>(double)LARGEST_INT64 ){ | |
| 8423 | + if( r>=(double)LARGEST_INT64 ){ | |
| 8393 | 8424 | iMax = LARGEST_INT64; |
| 8394 | - }else if( (idxNum & 0x2000)!=0 && r==seriesFloor(r) ){ | |
| 8395 | - iMax = (sqlite3_int64)(r-1.0); | |
| 8425 | + }else if( r<=(double)SMALLEST_INT64 ){ | |
| 8426 | + goto series_no_rows; | |
| 8396 | 8427 | }else{ |
| 8397 | 8428 | iMax = (sqlite3_int64)seriesFloor(r); |
| 8429 | + if( iMax<0 && r>0.0 ){ | |
| 8430 | + iMax = LARGEST_INT64; | |
| 8431 | + }else if( (idxNum & 0x2000)!=0 && r==seriesFloor(r) ){ | |
| 8432 | + if( iMax==SMALLEST_INT64 ) goto series_no_rows; | |
| 8433 | + iMax--; | |
| 8434 | + } | |
| 8398 | 8435 | } |
| 8399 | 8436 | }else{ |
| 8400 | 8437 | iMax = sqlite3_value_int64(argv[iArg++]); |
| 8401 | 8438 | if( idxNum & 0x2000 ){ |
| 8402 | 8439 | if( iMax==SMALLEST_INT64 ){ |
| @@ -9638,11 +9675,10 @@ | ||
| 9638 | 9675 | if( pRe==0 ){ |
| 9639 | 9676 | sqlite3_result_error_nomem(context); |
| 9640 | 9677 | return; |
| 9641 | 9678 | } |
| 9642 | 9679 | pStr = sqlite3_str_new(0); |
| 9643 | - if( pStr==0 ) goto re_bytecode_func_err; | |
| 9644 | 9680 | if( pRe->nInit>0 ){ |
| 9645 | 9681 | sqlite3_str_appendf(pStr, "INIT "); |
| 9646 | 9682 | for(i=0; i<pRe->nInit; i++){ |
| 9647 | 9683 | sqlite3_str_appendf(pStr, "%02x", pRe->zInit[i]); |
| 9648 | 9684 | } |
| @@ -9649,20 +9685,20 @@ | ||
| 9649 | 9685 | sqlite3_str_appendf(pStr, "\n"); |
| 9650 | 9686 | } |
| 9651 | 9687 | for(i=0; (unsigned)i<pRe->nState; i++){ |
| 9652 | 9688 | sqlite3_str_appendf(pStr, "%-8s %4d\n", |
| 9653 | 9689 | ReOpName[(unsigned char)pRe->aOp[i]], pRe->aArg[i]); |
| 9690 | + } | |
| 9691 | + if( sqlite3_str_errcode(pStr)==SQLITE_NOMEM ){ | |
| 9692 | + sqlite3_str_finish(pStr); | |
| 9693 | + re_free(pRe); | |
| 9694 | + sqlite3_result_error_nomem(context); | |
| 9695 | + return; | |
| 9654 | 9696 | } |
| 9655 | 9697 | n = sqlite3_str_length(pStr); |
| 9656 | 9698 | z = sqlite3_str_finish(pStr); |
| 9657 | - if( n==0 ){ | |
| 9658 | - sqlite3_free(z); | |
| 9659 | - }else{ | |
| 9660 | - sqlite3_result_text(context, z, n-1, sqlite3_free); | |
| 9661 | - } | |
| 9662 | - | |
| 9663 | -re_bytecode_func_err: | |
| 9699 | + sqlite3_result_text(context, z, n-1, sqlite3_free); | |
| 9664 | 9700 | re_free(pRe); |
| 9665 | 9701 | } |
| 9666 | 9702 | |
| 9667 | 9703 | #endif /* SQLITE_DEBUG */ |
| 9668 | 9704 | |
| @@ -10870,10 +10906,13 @@ | ||
| 10870 | 10906 | ** Return NULL if unable. |
| 10871 | 10907 | ** |
| 10872 | 10908 | ** The file or directory X is not required to exist. The answer is formed |
| 10873 | 10909 | ** by calling system realpath() on the prefix of X that does exist and |
| 10874 | 10910 | ** appending the tail of X that does not (yet) exist. |
| 10911 | +** | |
| 10912 | +** FIXME: This routine sometimes returns NULL rather than raising | |
| 10913 | +** an SQLITE_NOMEM error if an OOM is encountered. | |
| 10875 | 10914 | */ |
| 10876 | 10915 | static void realpathFunc( |
| 10877 | 10916 | sqlite3_context *context, |
| 10878 | 10917 | int argc, |
| 10879 | 10918 | sqlite3_value **argv |
| @@ -10892,10 +10931,11 @@ | ||
| 10892 | 10931 | (void)argc; |
| 10893 | 10932 | zPath = (const char*)sqlite3_value_text(argv[0]); |
| 10894 | 10933 | if( zPath==0 ) return; |
| 10895 | 10934 | if( zPath[0]==0 ) zPath = "."; |
| 10896 | 10935 | zCopy = sqlite3_mprintf("%s",zPath); |
| 10936 | + if( zCopy==0 ) return; | |
| 10897 | 10937 | len = strlen(zCopy); |
| 10898 | 10938 | while( len>1 && (zCopy[len-1]=='/' || (isWin && zCopy[len-1]=='\\')) ){ |
| 10899 | 10939 | len--; |
| 10900 | 10940 | } |
| 10901 | 10941 | zCopy[len] = 0; |
| @@ -12685,10 +12725,11 @@ | ||
| 12685 | 12725 | |
| 12686 | 12726 | for(p=pCsr->pFreeEntry; p; p=pNext){ |
| 12687 | 12727 | pNext = p->pNext; |
| 12688 | 12728 | zipfileEntryFree(p); |
| 12689 | 12729 | } |
| 12730 | + pCsr->pFreeEntry = 0; | |
| 12690 | 12731 | } |
| 12691 | 12732 | |
| 12692 | 12733 | /* |
| 12693 | 12734 | ** Destructor for an ZipfileCsr. |
| 12694 | 12735 | */ |
| @@ -13087,11 +13128,17 @@ | ||
| 13087 | 13128 | } |
| 13088 | 13129 | } |
| 13089 | 13130 | |
| 13090 | 13131 | if( rc==SQLITE_OK ){ |
| 13091 | 13132 | u32 *pt = &pNew->mUnixTime; |
| 13092 | - pNew->cds.zFile = sqlite3_mprintf("%.*s", nFile, aRead); | |
| 13133 | + /* aRead[0..nFile-1] might contain embedded \000 characters | |
| 13134 | + ** See Bug 2026-05-31T11:43:05Z */ | |
| 13135 | + pNew->cds.zFile = sqlite3_malloc64(nFile+1); | |
| 13136 | + if( pNew->cds.zFile!=0 ){ | |
| 13137 | + memcpy(pNew->cds.zFile, aRead, nFile); | |
| 13138 | + pNew->cds.zFile[nFile] = 0; | |
| 13139 | + } | |
| 13093 | 13140 | pNew->aExtra = (u8*)&pNew[1]; |
| 13094 | 13141 | memcpy(pNew->aExtra, &aRead[nFile], nExtra); |
| 13095 | 13142 | if( pNew->cds.zFile==0 ){ |
| 13096 | 13143 | rc = SQLITE_NOMEM; |
| 13097 | 13144 | }else if( 0==zipfileScanExtra(&aRead[nFile], pNew->cds.nExtra, pt) ){ |
| @@ -14191,14 +14238,14 @@ | ||
| 14191 | 14238 | ZipfileBuffer body; |
| 14192 | 14239 | ZipfileBuffer cds; |
| 14193 | 14240 | }; |
| 14194 | 14241 | |
| 14195 | 14242 | static int zipfileBufferGrow(ZipfileBuffer *pBuf, i64 nByte){ |
| 14196 | - if( pBuf->n+nByte>pBuf->nAlloc ){ | |
| 14243 | + if( (pBuf->nAlloc-pBuf->n)<nByte ){ | |
| 14197 | 14244 | u8 *aNew; |
| 14198 | - sqlite3_int64 nNew = pBuf->n ? pBuf->n*2 : 512; | |
| 14199 | - int nReq = pBuf->n + nByte; | |
| 14245 | + i64 nNew = pBuf->n ? (i64)pBuf->n*2 : 512; | |
| 14246 | + i64 nReq = pBuf->n + nByte; | |
| 14200 | 14247 | |
| 14201 | 14248 | while( nNew<nReq ) nNew = nNew*2; |
| 14202 | 14249 | aNew = sqlite3_realloc64(pBuf->a, nNew); |
| 14203 | 14250 | if( aNew==0 ) return SQLITE_NOMEM; |
| 14204 | 14251 | pBuf->a = aNew; |
| @@ -16296,11 +16343,11 @@ | ||
| 16296 | 16343 | p->pTable = pTab; |
| 16297 | 16344 | |
| 16298 | 16345 | /* The statement the vtab will pass to sqlite3_declare_vtab() */ |
| 16299 | 16346 | zInner = idxAppendText(&rc, 0, "CREATE TABLE x("); |
| 16300 | 16347 | for(i=0; i<pTab->nCol; i++){ |
| 16301 | - zInner = idxAppendText(&rc, zInner, "%s%Q COLLATE %s", | |
| 16348 | + zInner = idxAppendText(&rc, zInner, "%s%Q COLLATE %Q", | |
| 16302 | 16349 | (i==0 ? "" : ", "), pTab->aCol[i].zName, pTab->aCol[i].zColl |
| 16303 | 16350 | ); |
| 16304 | 16351 | } |
| 16305 | 16352 | zInner = idxAppendText(&rc, zInner, ")"); |
| 16306 | 16353 | |
| @@ -16496,11 +16543,11 @@ | ||
| 16496 | 16543 | sqlite3_free(zCols); |
| 16497 | 16544 | sqlite3_free(zOrder); |
| 16498 | 16545 | return sqlite3_reset(pIndexXInfo); |
| 16499 | 16546 | } |
| 16500 | 16547 | zCols = idxAppendText(&rc, zCols, |
| 16501 | - "%sx.%Q IS sqlite_expert_rem(%d, x.%Q) COLLATE %s", | |
| 16548 | + "%sx.%Q IS sqlite_expert_rem(%d, x.%Q) COLLATE %Q", | |
| 16502 | 16549 | zComma, zName, nCol, zName, zColl |
| 16503 | 16550 | ); |
| 16504 | 16551 | zOrder = idxAppendText(&rc, zOrder, "%s%d", zComma, ++nCol); |
| 16505 | 16552 | } |
| 16506 | 16553 | sqlite3_reset(pIndexXInfo); |
| @@ -19464,11 +19511,11 @@ | ||
| 19464 | 19511 | sqlite3_vfs_unregister(pVfs); |
| 19465 | 19512 | sqlite3_free(pVfs); |
| 19466 | 19513 | } |
| 19467 | 19514 | |
| 19468 | 19515 | /************************* End ext/misc/vfstrace.c ********************/ |
| 19469 | -/************************* Begin ext/misc/analyze.c ******************/ | |
| 19516 | +/************************* Begin ext/misc/diskused.c ******************/ | |
| 19470 | 19517 | /* |
| 19471 | 19518 | ** 2026-04-13 |
| 19472 | 19519 | ** |
| 19473 | 19520 | ** The author disclaims copyright to this source code. In place of |
| 19474 | 19521 | ** a legal notice, here is a blessing: |
| @@ -19477,12 +19524,21 @@ | ||
| 19477 | 19524 | ** May you find forgiveness for yourself and forgive others. |
| 19478 | 19525 | ** May you share freely, never taking more than you give. |
| 19479 | 19526 | ** |
| 19480 | 19527 | ****************************************************************************** |
| 19481 | 19528 | ** |
| 19482 | -** Partial reimplement of the sqlite3_analyzer utility program as | |
| 19483 | -** loadable SQL function. | |
| 19529 | +** This extension implements an SQL function: | |
| 19530 | +** | |
| 19531 | +** diskused(X) | |
| 19532 | +** | |
| 19533 | +** Where X is the schema name (typically 'main'). The output is text | |
| 19534 | +** that describes how much filesystem space the various tables and indexes | |
| 19535 | +** of the database consume. | |
| 19536 | +** | |
| 19537 | +** This function is a replacement for the (now deprecated) | |
| 19538 | +** "sqlite3_analyzer" utility program. This function is built | |
| 19539 | +** into the CLI and is used to implement the ".diskused" command there. | |
| 19484 | 19540 | */ |
| 19485 | 19541 | /* #include "sqlite3ext.h" */ |
| 19486 | 19542 | SQLITE_EXTENSION_INIT1 |
| 19487 | 19543 | #include <assert.h> |
| 19488 | 19544 | #include <string.h> |
| @@ -19490,28 +19546,28 @@ | ||
| 19490 | 19546 | #include <math.h> |
| 19491 | 19547 | |
| 19492 | 19548 | /* |
| 19493 | 19549 | ** State information for the analysis |
| 19494 | 19550 | */ |
| 19495 | -typedef struct Analysis Analysis; | |
| 19496 | -struct Analysis { | |
| 19551 | +typedef struct DiskUsed DiskUsed; | |
| 19552 | +struct DiskUsed { | |
| 19497 | 19553 | sqlite3 *db; /* Database connection */ |
| 19498 | 19554 | sqlite3_context *context; /* SQL function context */ |
| 19499 | 19555 | sqlite3_str *pOut; /* Write output here */ |
| 19500 | 19556 | char *zSU; /* Name of the temp.space_used table */ |
| 19501 | 19557 | const char *zSchema; /* Schema to be analyzed */ |
| 19502 | 19558 | }; |
| 19503 | 19559 | |
| 19504 | 19560 | /* |
| 19505 | -** Free all resources that the Analysis object references and | |
| 19506 | -** reset the Analysis object. | |
| 19561 | +** Free all resources that the DiskUsed object references and | |
| 19562 | +** reset the DiskUsed object. | |
| 19507 | 19563 | ** |
| 19508 | -** Call this routine multiple times on the same Analysis object | |
| 19564 | +** Call this routine multiple times on the same DiskUsed object | |
| 19509 | 19565 | ** is a harmless no-op, as long as the memory for the object itself |
| 19510 | 19566 | ** has not been freed. |
| 19511 | 19567 | */ |
| 19512 | -static void analysisReset(Analysis *p){ | |
| 19568 | +static void diskusedReset(DiskUsed *p){ | |
| 19513 | 19569 | if( p->zSU ){ |
| 19514 | 19570 | char *zSql = sqlite3_mprintf("DROP TABLE temp.%s;", p->zSU); |
| 19515 | 19571 | if( zSql ){ |
| 19516 | 19572 | sqlite3_exec(p->db, zSql, 0, 0, 0); |
| 19517 | 19573 | sqlite3_free(zSql); |
| @@ -19524,11 +19580,11 @@ | ||
| 19524 | 19580 | |
| 19525 | 19581 | /* |
| 19526 | 19582 | ** Report an error using formatted text. If zFormat==NULL then report |
| 19527 | 19583 | ** an OOM error. |
| 19528 | 19584 | */ |
| 19529 | -static void analysisError(Analysis *p, const char *zFormat, ...){ | |
| 19585 | +static void diskusedError(DiskUsed *p, const char *zFormat, ...){ | |
| 19530 | 19586 | char *zErr; |
| 19531 | 19587 | if( zFormat ){ |
| 19532 | 19588 | va_list ap; |
| 19533 | 19589 | va_start(ap, zFormat); |
| 19534 | 19590 | zErr = sqlite3_vmprintf(zFormat, ap); |
| @@ -19540,38 +19596,38 @@ | ||
| 19540 | 19596 | sqlite3_result_error_nomem(p->context); |
| 19541 | 19597 | }else{ |
| 19542 | 19598 | sqlite3_result_error(p->context, zErr, -1); |
| 19543 | 19599 | sqlite3_free(zErr); |
| 19544 | 19600 | } |
| 19545 | - analysisReset(p); | |
| 19601 | + diskusedReset(p); | |
| 19546 | 19602 | } |
| 19547 | 19603 | |
| 19548 | 19604 | /* |
| 19549 | 19605 | ** Prepare and return an SQL statement. |
| 19550 | 19606 | */ |
| 19551 | -static sqlite3_stmt *analysisVPrep(Analysis *p, const char *zFmt, va_list ap){ | |
| 19607 | +static sqlite3_stmt *diskusedVPrep(DiskUsed *p, const char *zFmt, va_list ap){ | |
| 19552 | 19608 | char *zSql; |
| 19553 | 19609 | int rc; |
| 19554 | 19610 | sqlite3_stmt *pStmt = 0; |
| 19555 | 19611 | zSql = sqlite3_vmprintf(zFmt, ap); |
| 19556 | - if( zSql==0 ){ analysisError(p,0); return 0; } | |
| 19612 | + if( zSql==0 ){ diskusedError(p,0); return 0; } | |
| 19557 | 19613 | rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0); |
| 19558 | 19614 | if( rc ){ |
| 19559 | - analysisError(p, "SQL parse error: %s\nOriginal SQL: %s", | |
| 19615 | + diskusedError(p, "SQL parse error: %s\nOriginal SQL: %s", | |
| 19560 | 19616 | sqlite3_errmsg(p->db), zSql); |
| 19561 | 19617 | sqlite3_finalize(pStmt); |
| 19562 | - analysisReset(p); | |
| 19618 | + diskusedReset(p); | |
| 19563 | 19619 | pStmt = 0; |
| 19564 | 19620 | } |
| 19565 | 19621 | sqlite3_free(zSql); |
| 19566 | 19622 | return pStmt; |
| 19567 | 19623 | } |
| 19568 | -static sqlite3_stmt *analysisPrepare(Analysis *p, const char *zFormat, ...){ | |
| 19624 | +static sqlite3_stmt *diskusedPrepare(DiskUsed *p, const char *zFormat, ...){ | |
| 19569 | 19625 | va_list ap; |
| 19570 | 19626 | sqlite3_stmt *pStmt = 0; |
| 19571 | 19627 | va_start(ap, zFormat); |
| 19572 | - pStmt = analysisVPrep(p,zFormat,ap); | |
| 19628 | + pStmt = diskusedVPrep(p,zFormat,ap); | |
| 19573 | 19629 | va_end(ap); |
| 19574 | 19630 | return pStmt; |
| 19575 | 19631 | } |
| 19576 | 19632 | |
| 19577 | 19633 | /* |
| @@ -19580,60 +19636,60 @@ | ||
| 19580 | 19636 | ** |
| 19581 | 19637 | ** If rc is SQLITE_DONE or SQLITE_OK, then return false. |
| 19582 | 19638 | ** |
| 19583 | 19639 | ** The prepared statement is closed in either case. |
| 19584 | 19640 | */ |
| 19585 | -static int analysisStmtFinish(Analysis *p, int rc, sqlite3_stmt *pStmt){ | |
| 19641 | +static int diskusedStmtFinish(DiskUsed *p, int rc, sqlite3_stmt *pStmt){ | |
| 19586 | 19642 | if( rc==SQLITE_DONE ){ |
| 19587 | 19643 | rc = SQLITE_OK; |
| 19588 | 19644 | } |
| 19589 | 19645 | if( rc!=SQLITE_OK || (rc = sqlite3_reset(pStmt))!=SQLITE_OK ){ |
| 19590 | - analysisError(p, "SQL run-time error: %s\nOriginal SQL: %s", | |
| 19646 | + diskusedError(p, "SQL run-time error: %s\nOriginal SQL: %s", | |
| 19591 | 19647 | sqlite3_errmsg(p->db), sqlite3_sql(pStmt)); |
| 19592 | - analysisReset(p); | |
| 19648 | + diskusedReset(p); | |
| 19593 | 19649 | } |
| 19594 | 19650 | sqlite3_finalize(pStmt); |
| 19595 | 19651 | return rc; |
| 19596 | 19652 | } |
| 19597 | 19653 | |
| 19598 | 19654 | /* |
| 19599 | 19655 | ** Run SQL. Return the number of errors. |
| 19600 | 19656 | */ |
| 19601 | -static int analysisSql(Analysis *p, const char *zFormat, ...){ | |
| 19657 | +static int diskusedSql(DiskUsed *p, const char *zFormat, ...){ | |
| 19602 | 19658 | va_list ap; |
| 19603 | 19659 | int rc; |
| 19604 | 19660 | sqlite3_stmt *pStmt = 0; |
| 19605 | 19661 | va_start(ap, zFormat); |
| 19606 | - pStmt = analysisVPrep(p,zFormat,ap); | |
| 19662 | + pStmt = diskusedVPrep(p,zFormat,ap); | |
| 19607 | 19663 | va_end(ap); |
| 19608 | 19664 | if( pStmt==0 ) return 1; |
| 19609 | 19665 | while( (rc = sqlite3_step(pStmt))==SQLITE_ROW ){} |
| 19610 | 19666 | if( rc==SQLITE_DONE ){ |
| 19611 | 19667 | rc = SQLITE_OK; |
| 19612 | 19668 | }else{ |
| 19613 | - analysisError(p, "SQL run-time error: %s\nOriginal SQL: %s", | |
| 19669 | + diskusedError(p, "SQL run-time error: %s\nOriginal SQL: %s", | |
| 19614 | 19670 | sqlite3_errmsg(p->db), sqlite3_sql(pStmt)); |
| 19615 | - analysisReset(p); | |
| 19671 | + diskusedReset(p); | |
| 19616 | 19672 | } |
| 19617 | 19673 | sqlite3_finalize(pStmt); |
| 19618 | 19674 | return rc; |
| 19619 | 19675 | } |
| 19620 | 19676 | |
| 19621 | 19677 | /* |
| 19622 | 19678 | ** Run an SQL query that returns an integer. Write that integer |
| 19623 | 19679 | ** into *piRes. Return the number of errors. |
| 19624 | 19680 | */ |
| 19625 | -static int analysisSqlInt( | |
| 19626 | - Analysis *p, | |
| 19681 | +static int diskusedSqlInt( | |
| 19682 | + DiskUsed *p, | |
| 19627 | 19683 | sqlite3_int64 *piRes, |
| 19628 | 19684 | const char *zFormat, ... |
| 19629 | 19685 | ){ |
| 19630 | 19686 | va_list ap; |
| 19631 | 19687 | int rc; |
| 19632 | 19688 | sqlite3_stmt *pStmt = 0; |
| 19633 | 19689 | va_start(ap, zFormat); |
| 19634 | - pStmt = analysisVPrep(p,zFormat,ap); | |
| 19690 | + pStmt = diskusedVPrep(p,zFormat,ap); | |
| 19635 | 19691 | va_end(ap); |
| 19636 | 19692 | if( pStmt==0 ) return 1; |
| 19637 | 19693 | rc = sqlite3_step(pStmt); |
| 19638 | 19694 | if( rc==SQLITE_ROW ){ |
| 19639 | 19695 | *piRes = sqlite3_column_int64(pStmt, 0); |
| @@ -19641,14 +19697,14 @@ | ||
| 19641 | 19697 | }else if( rc==SQLITE_DONE ){ |
| 19642 | 19698 | rc = SQLITE_OK; |
| 19643 | 19699 | }else{ |
| 19644 | 19700 | if( p->db ){ |
| 19645 | 19701 | /* p->db is NULL if there was some prior error */ |
| 19646 | - analysisError(p, "SQL run-time error: %s\nOriginal SQL: %s", | |
| 19702 | + diskusedError(p, "SQL run-time error: %s\nOriginal SQL: %s", | |
| 19647 | 19703 | sqlite3_errmsg(p->db), sqlite3_sql(pStmt)); |
| 19648 | 19704 | } |
| 19649 | - analysisReset(p); | |
| 19705 | + diskusedReset(p); | |
| 19650 | 19706 | } |
| 19651 | 19707 | sqlite3_finalize(pStmt); |
| 19652 | 19708 | return rc; |
| 19653 | 19709 | } |
| 19654 | 19710 | |
| @@ -19657,20 +19713,20 @@ | ||
| 19657 | 19713 | ** by the format string. If the output is initially empty, begin |
| 19658 | 19714 | ** the title line with "/" so that it forms the beginning of a C-style |
| 19659 | 19715 | ** comment. Otherwise begin with a new-line. Always finish with a |
| 19660 | 19716 | ** newline. |
| 19661 | 19717 | */ |
| 19662 | -static void analysisTitle(Analysis *p, const char *zFormat, ...){ | |
| 19718 | +static void diskusedTitle(DiskUsed *p, const char *zFormat, ...){ | |
| 19663 | 19719 | char *zFirst; |
| 19664 | 19720 | char *zTitle; |
| 19665 | 19721 | size_t nTitle; |
| 19666 | 19722 | va_list ap; |
| 19667 | 19723 | va_start(ap, zFormat); |
| 19668 | 19724 | zTitle = sqlite3_vmprintf(zFormat, ap); |
| 19669 | 19725 | va_end(ap); |
| 19670 | 19726 | if( zTitle==0 ){ |
| 19671 | - analysisError(p, 0); | |
| 19727 | + diskusedError(p, 0); | |
| 19672 | 19728 | return; |
| 19673 | 19729 | } |
| 19674 | 19730 | zFirst = sqlite3_str_length(p->pOut)==0 ? "/" : "\n*"; |
| 19675 | 19731 | nTitle = strlen(zTitle); |
| 19676 | 19732 | if( nTitle>=75 ){ |
| @@ -19685,12 +19741,12 @@ | ||
| 19685 | 19741 | /* |
| 19686 | 19742 | ** Add an output line that begins with the zDesc text extended out to |
| 19687 | 19743 | ** 50 columns with "." characters, and followed by whatever text is |
| 19688 | 19744 | ** described by zFormat. |
| 19689 | 19745 | */ |
| 19690 | -static void analysisLine( | |
| 19691 | - Analysis *p, /* Analysis context */ | |
| 19746 | +static void diskusedLine( | |
| 19747 | + DiskUsed *p, /* DiskUsed context */ | |
| 19692 | 19748 | const char *zDesc, /* Description */ |
| 19693 | 19749 | const char *zFormat, /* Argument to the description */ |
| 19694 | 19750 | ... |
| 19695 | 19751 | ){ |
| 19696 | 19752 | char *zTxt; |
| @@ -19698,14 +19754,14 @@ | ||
| 19698 | 19754 | va_list ap; |
| 19699 | 19755 | va_start(ap, zFormat); |
| 19700 | 19756 | zTxt = sqlite3_vmprintf(zFormat, ap); |
| 19701 | 19757 | va_end(ap); |
| 19702 | 19758 | if( zTxt==0 ){ |
| 19703 | - analysisError(p, 0); | |
| 19759 | + diskusedError(p, 0); | |
| 19704 | 19760 | return; |
| 19705 | 19761 | } |
| 19706 | - nDesc = strlen(zDesc); | |
| 19762 | + nDesc = zDesc ? strlen(zDesc) : 0; | |
| 19707 | 19763 | if( nDesc>=50 ){ |
| 19708 | 19764 | sqlite3_str_appendf(p->pOut, "%s %z", zDesc, zTxt); |
| 19709 | 19765 | }else{ |
| 19710 | 19766 | int nExtra = 50 - (int)nDesc; |
| 19711 | 19767 | sqlite3_str_appendf(p->pOut, "%s%.*c %z", zDesc, nExtra, '.', zTxt); |
| @@ -19715,11 +19771,11 @@ | ||
| 19715 | 19771 | /* |
| 19716 | 19772 | ** Write a percentage into the output. The number written should show |
| 19717 | 19773 | ** two or three significant digits, with the decimal point being the fourth |
| 19718 | 19774 | ** character. |
| 19719 | 19775 | */ |
| 19720 | -static void analysisPercent(Analysis *p, double r){ | |
| 19776 | +static void diskusedPercent(DiskUsed *p, double r){ | |
| 19721 | 19777 | char zNum[100]; |
| 19722 | 19778 | char *zDP; |
| 19723 | 19779 | int nLeadingDigit; |
| 19724 | 19780 | int sz; |
| 19725 | 19781 | sqlite3_snprintf(sizeof(zNum)-5, zNum, r>=10.0 ? "%.3g" :"%.2g", r); |
| @@ -19744,12 +19800,12 @@ | ||
| 19744 | 19800 | ** |
| 19745 | 19801 | ** The title if the subreport is given by zTitle. zWhere is |
| 19746 | 19802 | ** a boolean expression that can go in the WHERE clause to select |
| 19747 | 19803 | ** the relevant rows of the s.zSU table. |
| 19748 | 19804 | */ |
| 19749 | -static int analysisSubreport( | |
| 19750 | - Analysis *p, /* Analysis context */ | |
| 19805 | +static int diskusedSubreport( | |
| 19806 | + DiskUsed *p, /* DiskUsed context */ | |
| 19751 | 19807 | char *zTitle, /* Title for this subreport */ |
| 19752 | 19808 | char *zWhere, /* WHERE clause for this subreport */ |
| 19753 | 19809 | sqlite3_int64 pgsz, /* Database page size */ |
| 19754 | 19810 | sqlite3_int64 nPage /* Number of pages in entire database */ |
| 19755 | 19811 | ){ |
| @@ -19773,14 +19829,14 @@ | ||
| 19773 | 19829 | sqlite3_int64 total_unused; /* Total unused bytes */ |
| 19774 | 19830 | sqlite3_int64 total_meta; /* Total metadata */ |
| 19775 | 19831 | int rc; |
| 19776 | 19832 | |
| 19777 | 19833 | if( zTitle==0 || zWhere==0 ){ |
| 19778 | - analysisError(p, 0); | |
| 19834 | + diskusedError(p, 0); | |
| 19779 | 19835 | return SQLITE_NOMEM; |
| 19780 | 19836 | } |
| 19781 | - pStmt = analysisPrepare(p, | |
| 19837 | + pStmt = diskusedPrepare(p, | |
| 19782 | 19838 | "SELECT\n" |
| 19783 | 19839 | " sum(if(is_without_rowid OR is_index,nentry,leaf_entries)),\n" /* 0 */ |
| 19784 | 19840 | " sum(payload),\n" /* 1 */ |
| 19785 | 19841 | " sum(ovfl_payload),\n" /* 2 */ |
| 19786 | 19842 | " max(mx_payload),\n" /* 3 */ |
| @@ -19797,11 +19853,11 @@ | ||
| 19797 | 19853 | " FROM temp.%s WHERE %s", |
| 19798 | 19854 | p->zSU, zWhere); |
| 19799 | 19855 | if( pStmt==0 ) return 1; |
| 19800 | 19856 | rc = sqlite3_step(pStmt); |
| 19801 | 19857 | if( rc==SQLITE_ROW ){ |
| 19802 | - analysisTitle(p, zTitle); | |
| 19858 | + diskusedTitle(p, "%s", zTitle); | |
| 19803 | 19859 | |
| 19804 | 19860 | nentry = sqlite3_column_int64(pStmt, 0); |
| 19805 | 19861 | payload = sqlite3_column_int64(pStmt, 1); |
| 19806 | 19862 | ovfl_payload = sqlite3_column_int64(pStmt, 2); |
| 19807 | 19863 | mx_payload = sqlite3_column_int64(pStmt, 3); |
| @@ -19816,73 +19872,73 @@ | ||
| 19816 | 19872 | cnt = sqlite3_column_int64(pStmt, 12); |
| 19817 | 19873 | int_cell = sqlite3_column_int64(pStmt, 13); |
| 19818 | 19874 | rc = SQLITE_DONE; |
| 19819 | 19875 | |
| 19820 | 19876 | total_pages = leaf_pages + int_pages + ovfl_pages; |
| 19821 | - analysisLine(p, "Percentage of total database", "%.3g%%\n", | |
| 19877 | + diskusedLine(p, "Percentage of total database", "%.3g%%\n", | |
| 19822 | 19878 | (total_pages*100.0)/(double)nPage); |
| 19823 | - analysisLine(p, "Number of entries", "%lld\n", nentry); | |
| 19879 | + diskusedLine(p, "Number of entries", "%lld\n", nentry); | |
| 19824 | 19880 | storage = total_pages*pgsz; |
| 19825 | - analysisLine(p, "Bytes of storage consumed", "%lld\n", storage); | |
| 19826 | - analysisLine(p, "Bytes of payload", "%-11lld ", payload); | |
| 19827 | - analysisPercent(p, payload*100.0/(double)storage); | |
| 19881 | + diskusedLine(p, "Bytes of storage consumed", "%lld\n", storage); | |
| 19882 | + diskusedLine(p, "Bytes of payload", "%-11lld ", payload); | |
| 19883 | + diskusedPercent(p, payload*100.0/(double)storage); | |
| 19828 | 19884 | if( ovfl_cnt>0 ){ |
| 19829 | - analysisLine(p, "Bytes of payload in overflow","%-11lld ",ovfl_payload); | |
| 19830 | - analysisPercent(p, ovfl_payload*100.0/(double)payload); | |
| 19885 | + diskusedLine(p, "Bytes of payload in overflow","%-11lld ",ovfl_payload); | |
| 19886 | + diskusedPercent(p, ovfl_payload*100.0/(double)payload); | |
| 19831 | 19887 | } |
| 19832 | 19888 | total_unused = leaf_unused + int_unused + ovfl_unused; |
| 19833 | 19889 | total_meta = storage - payload - total_unused; |
| 19834 | - analysisLine(p, "Bytes of metadata","%-11lld ", total_meta); | |
| 19835 | - analysisPercent(p, total_meta*100.0/(double)storage); | |
| 19890 | + diskusedLine(p, "Bytes of metadata","%-11lld ", total_meta); | |
| 19891 | + diskusedPercent(p, total_meta*100.0/(double)storage); | |
| 19836 | 19892 | if( cnt==1 ){ |
| 19837 | - analysisLine(p, "B-tree depth", "%lld\n", depth); | |
| 19893 | + diskusedLine(p, "B-tree depth", "%lld\n", depth); | |
| 19838 | 19894 | if( int_cell>1 ){ |
| 19839 | - analysisLine(p, "Average fanout", "%.1f\n", | |
| 19895 | + diskusedLine(p, "Average fanout", "%.1f\n", | |
| 19840 | 19896 | (double)(int_cell+int_pages)/(double)int_pages); |
| 19841 | 19897 | } |
| 19842 | 19898 | } |
| 19843 | 19899 | if( nentry>0 ){ |
| 19844 | - analysisLine(p, "Average payload per entry", "%.1f\n", | |
| 19900 | + diskusedLine(p, "Average payload per entry", "%.1f\n", | |
| 19845 | 19901 | (double)payload/(double)nentry); |
| 19846 | - analysisLine(p, "Average unused bytes per entry", "%.1f\n", | |
| 19902 | + diskusedLine(p, "Average unused bytes per entry", "%.1f\n", | |
| 19847 | 19903 | (double)total_unused/(double)nentry); |
| 19848 | - analysisLine(p, "Average metadata per entry", "%.1f\n", | |
| 19904 | + diskusedLine(p, "Average metadata per entry", "%.1f\n", | |
| 19849 | 19905 | (double)total_meta/(double)nentry); |
| 19850 | 19906 | } |
| 19851 | - analysisLine(p, "Maximum single-entry payload", "%lld\n", mx_payload); | |
| 19852 | - if( nentry>0 ){ | |
| 19853 | - analysisLine(p, "Entries that use overflow", "%-11lld ", ovfl_cnt); | |
| 19854 | - analysisPercent(p, ovfl_cnt*100.0/(double)nentry); | |
| 19855 | - } | |
| 19856 | - if( int_pages>0 ){ | |
| 19857 | - analysisLine(p, "Index pages used", "%lld\n", int_pages); | |
| 19858 | - } | |
| 19859 | - analysisLine(p, "Primary pages used", "%lld\n", leaf_pages); | |
| 19860 | - if( ovfl_cnt ){ | |
| 19861 | - analysisLine(p, "Overflow pages used", "%lld\n", ovfl_pages); | |
| 19862 | - } | |
| 19863 | - analysisLine(p, "Total pages used", "%lld\n", total_pages); | |
| 19864 | - if( int_pages>0 ){ | |
| 19865 | - analysisLine(p, "Unused bytes on index pages", "%lld\n", int_unused); | |
| 19866 | - } | |
| 19867 | - analysisLine(p, "Unused bytes on primary pages", "%lld\n", leaf_unused); | |
| 19868 | - if( ovfl_cnt ){ | |
| 19869 | - analysisLine(p, "Unused bytes on overflow pages", "%lld\n", ovfl_unused); | |
| 19870 | - } | |
| 19871 | - analysisLine(p, "Unused bytes on all pages", "%-11lld ", total_unused); | |
| 19872 | - analysisPercent(p, total_unused*100.0/(double)storage); | |
| 19873 | - } | |
| 19874 | - return analysisStmtFinish(p, rc, pStmt); | |
| 19875 | -} | |
| 19876 | - | |
| 19877 | -/* | |
| 19878 | -** SQL Function: analyze(SCHEMA) | |
| 19907 | + diskusedLine(p, "Maximum single-entry payload", "%lld\n", mx_payload); | |
| 19908 | + if( nentry>0 ){ | |
| 19909 | + diskusedLine(p, "Entries that use overflow", "%-11lld ", ovfl_cnt); | |
| 19910 | + diskusedPercent(p, ovfl_cnt*100.0/(double)nentry); | |
| 19911 | + } | |
| 19912 | + if( int_pages>0 ){ | |
| 19913 | + diskusedLine(p, "Index pages used", "%lld\n", int_pages); | |
| 19914 | + } | |
| 19915 | + diskusedLine(p, "Primary pages used", "%lld\n", leaf_pages); | |
| 19916 | + if( ovfl_cnt ){ | |
| 19917 | + diskusedLine(p, "Overflow pages used", "%lld\n", ovfl_pages); | |
| 19918 | + } | |
| 19919 | + diskusedLine(p, "Total pages used", "%lld\n", total_pages); | |
| 19920 | + if( int_pages>0 ){ | |
| 19921 | + diskusedLine(p, "Unused bytes on index pages", "%lld\n", int_unused); | |
| 19922 | + } | |
| 19923 | + diskusedLine(p, "Unused bytes on primary pages", "%lld\n", leaf_unused); | |
| 19924 | + if( ovfl_cnt ){ | |
| 19925 | + diskusedLine(p, "Unused bytes on overflow pages", "%lld\n", ovfl_unused); | |
| 19926 | + } | |
| 19927 | + diskusedLine(p, "Unused bytes on all pages", "%-11lld ", total_unused); | |
| 19928 | + diskusedPercent(p, total_unused*100.0/(double)storage); | |
| 19929 | + } | |
| 19930 | + return diskusedStmtFinish(p, rc, pStmt); | |
| 19931 | +} | |
| 19932 | + | |
| 19933 | +/* | |
| 19934 | +** SQL Function: diskused(SCHEMA) | |
| 19879 | 19935 | ** |
| 19880 | 19936 | ** Analyze the database schema named in the argument. Return text |
| 19881 | -** containing the analysis. | |
| 19937 | +** containing the space utilization stats. | |
| 19882 | 19938 | */ |
| 19883 | -static void analyzeFunc( | |
| 19939 | +static void diskusedFunc( | |
| 19884 | 19940 | sqlite3_context *context, |
| 19885 | 19941 | int argc, |
| 19886 | 19942 | sqlite3_value **argv |
| 19887 | 19943 | ){ |
| 19888 | 19944 | int rc; |
| @@ -19893,47 +19949,47 @@ | ||
| 19893 | 19949 | sqlite3_int64 nPage; |
| 19894 | 19950 | sqlite3_int64 nPageInUse; |
| 19895 | 19951 | sqlite3_int64 nFreeList; |
| 19896 | 19952 | sqlite3_int64 nIndex; |
| 19897 | 19953 | sqlite3_int64 nWORowid; |
| 19898 | - Analysis s; | |
| 19954 | + DiskUsed s; | |
| 19899 | 19955 | sqlite3_uint64 r[2]; |
| 19900 | 19956 | |
| 19901 | 19957 | (void)argc; |
| 19902 | 19958 | memset(&s, 0, sizeof(s)); |
| 19903 | 19959 | s.db = sqlite3_context_db_handle(context); |
| 19904 | 19960 | s.context = context; |
| 19905 | 19961 | s.pOut = sqlite3_str_new(0); |
| 19906 | 19962 | if( sqlite3_str_errcode(s.pOut) ){ |
| 19907 | - analysisError(&s, 0); | |
| 19963 | + diskusedError(&s, 0); | |
| 19908 | 19964 | return; |
| 19909 | 19965 | } |
| 19910 | 19966 | s.zSchema = (const char*)sqlite3_value_text(argv[0]); |
| 19911 | 19967 | if( s.zSchema==0 ){ |
| 19912 | 19968 | s.zSchema = "main"; |
| 19913 | 19969 | }else if( sqlite3_strlike("temp",s.zSchema,0)==0 ){ |
| 19914 | - analysisReset(&s); | |
| 19970 | + diskusedReset(&s); | |
| 19915 | 19971 | sqlite3_result_text(context, "cannot analyze \"temp\"",-1,SQLITE_STATIC); |
| 19916 | 19972 | return; |
| 19917 | 19973 | } |
| 19918 | 19974 | ii = 0; |
| 19919 | - rc = analysisSqlInt(&s,&ii,"SELECT 1 FROM pragma_database_list" | |
| 19975 | + rc = diskusedSqlInt(&s,&ii,"SELECT 1 FROM pragma_database_list" | |
| 19920 | 19976 | " WHERE name=%Q COLLATE nocase",s.zSchema); |
| 19921 | 19977 | if( rc || ii==0 ){ |
| 19922 | - analysisReset(&s); | |
| 19978 | + diskusedReset(&s); | |
| 19923 | 19979 | sqlite3_result_text(context,"no such database",-1,SQLITE_STATIC); |
| 19924 | 19980 | return; |
| 19925 | 19981 | } |
| 19926 | 19982 | sqlite3_randomness(sizeof(r), &r); |
| 19927 | - s.zSU = sqlite3_mprintf("analysis%016llx%016llx", r[0], r[1]); | |
| 19928 | - if( s.zSU==0 ){ analysisError(&s, 0); return; } | |
| 19983 | + s.zSU = sqlite3_mprintf("diskused%016llx%016llx", r[0], r[1]); | |
| 19984 | + if( s.zSU==0 ){ diskusedError(&s, 0); return; } | |
| 19929 | 19985 | |
| 19930 | 19986 | /* The s.zSU table contains the data used for the analysis. |
| 19931 | 19987 | ** The table name contains 128-bits of randomness to avoid |
| 19932 | 19988 | ** collisions with preexisting tables in temp. |
| 19933 | 19989 | */ |
| 19934 | - rc = analysisSql(&s, | |
| 19990 | + rc = diskusedSql(&s, | |
| 19935 | 19991 | "CREATE TABLE temp.%s(\n" |
| 19936 | 19992 | " name text, -- A table or index\n" |
| 19937 | 19993 | " tblname text, -- Table that owns name\n" |
| 19938 | 19994 | " is_index boolean, -- TRUE if it is an index\n" |
| 19939 | 19995 | " is_without_rowid boolean, -- TRUE if WITHOUT ROWID table\n" |
| @@ -19956,11 +20012,11 @@ | ||
| 19956 | 20012 | ); |
| 19957 | 20013 | if( rc ) return; |
| 19958 | 20014 | |
| 19959 | 20015 | /* Populate the s.zSU table |
| 19960 | 20016 | */ |
| 19961 | - rc = analysisSql(&s, | |
| 20017 | + rc = diskusedSql(&s, | |
| 19962 | 20018 | "WITH\n" |
| 19963 | 20019 | " allidx(idxname) AS (\n" |
| 19964 | 20020 | " SELECT name FROM \"%w\".sqlite_schema WHERE type='index'\n" |
| 19965 | 20021 | " ),\n" |
| 19966 | 20022 | " allobj(allname,tblname,isidx,isworowid) AS (\n" |
| @@ -20008,141 +20064,143 @@ | ||
| 20008 | 20064 | s.zSchema /* JOIN dbstat(%Q) */ |
| 20009 | 20065 | ); |
| 20010 | 20066 | if( rc ) return; |
| 20011 | 20067 | |
| 20012 | 20068 | nPage = 0; |
| 20013 | - rc = analysisSqlInt(&s, &nPage, "PRAGMA \"%w\".page_count", s.zSchema); | |
| 20069 | + rc = diskusedSqlInt(&s, &nPage, "PRAGMA \"%w\".page_count", s.zSchema); | |
| 20014 | 20070 | if( rc ) return; |
| 20015 | 20071 | if( nPage<=0 ){ |
| 20016 | 20072 | /* Very brief reply for an empty database */ |
| 20017 | - analysisReset(&s); | |
| 20073 | + diskusedReset(&s); | |
| 20018 | 20074 | sqlite3_result_text(context, "empty database", -1, SQLITE_STATIC); |
| 20019 | 20075 | return; |
| 20020 | 20076 | } |
| 20021 | 20077 | |
| 20022 | 20078 | /* Begin generating the report */ |
| 20023 | - analysisTitle(&s, "Database storage utilization report"); | |
| 20079 | + diskusedTitle(&s, "Database storage utilization report"); | |
| 20024 | 20080 | pgsz = 0; |
| 20025 | - rc = analysisSqlInt(&s, &pgsz, "PRAGMA \"%w\".page_size", s.zSchema); | |
| 20081 | + rc = diskusedSqlInt(&s, &pgsz, "PRAGMA \"%w\".page_size", s.zSchema); | |
| 20026 | 20082 | if( rc ) return; |
| 20027 | - analysisLine(&s, "Page size in bytes","%lld\n",pgsz); | |
| 20028 | - analysisLine(&s, "Pages in the database", "%lld\n", nPage); | |
| 20083 | + diskusedLine(&s, "Page size in bytes","%lld\n",pgsz); | |
| 20084 | + diskusedLine(&s, "Pages in the database", "%lld\n", nPage); | |
| 20029 | 20085 | |
| 20030 | 20086 | nPageInUse = 0; |
| 20031 | - rc = analysisSqlInt(&s, &nPageInUse, | |
| 20087 | + rc = diskusedSqlInt(&s, &nPageInUse, | |
| 20032 | 20088 | "SELECT sum(leaf_pages+int_pages+ovfl_pages) FROM temp.%s", s.zSU); |
| 20033 | 20089 | if( rc ) return; |
| 20034 | - analysisLine(&s, "Pages that store data", "%-11lld ", nPageInUse); | |
| 20035 | - analysisPercent(&s, (nPageInUse*100.0)/(double)nPage); | |
| 20090 | + diskusedLine(&s, "Pages that store data", "%-11lld ", nPageInUse); | |
| 20091 | + diskusedPercent(&s, (nPageInUse*100.0)/(double)nPage); | |
| 20036 | 20092 | |
| 20037 | 20093 | nFreeList = 0; |
| 20038 | - rc = analysisSqlInt(&s, &nFreeList, "PRAGMA \"%w\".freelist_count",s.zSchema); | |
| 20094 | + rc = diskusedSqlInt(&s, &nFreeList, "PRAGMA \"%w\".freelist_count",s.zSchema); | |
| 20039 | 20095 | if( rc ) return; |
| 20040 | - analysisLine(&s, "Pages on the freelist", "%-11lld ", nFreeList); | |
| 20041 | - analysisPercent(&s, (nFreeList*100.0)/(double)nPage); | |
| 20096 | + diskusedLine(&s, "Pages on the freelist", "%-11lld ", nFreeList); | |
| 20097 | + diskusedPercent(&s, (nFreeList*100.0)/(double)nPage); | |
| 20042 | 20098 | |
| 20043 | 20099 | ii = 0; |
| 20044 | - rc = analysisSqlInt(&s, &ii, "PRAGMA \"%w\".auto_vacuum", s.zSchema); | |
| 20100 | + rc = diskusedSqlInt(&s, &ii, "PRAGMA \"%w\".auto_vacuum", s.zSchema); | |
| 20045 | 20101 | if( rc ) return; |
| 20046 | 20102 | if( ii==0 || nPage<=1 ){ |
| 20047 | 20103 | ii = 0; |
| 20048 | 20104 | }else{ |
| 20049 | 20105 | double rPtrsPerPage = pgsz/5; |
| 20050 | 20106 | double rAvPage = (nPage-1.0)/(rPtrsPerPage+1.0); |
| 20051 | 20107 | ii = (sqlite3_int64)ceil(rAvPage); |
| 20052 | 20108 | } |
| 20053 | - analysisLine(&s, "Pages of auto-vacuum overhead", "%-11lld ", ii); | |
| 20054 | - analysisPercent(&s, (ii*100.0)/(double)nPage); | |
| 20109 | + diskusedLine(&s, "Pages of auto-vacuum overhead", "%-11lld ", ii); | |
| 20110 | + diskusedPercent(&s, (ii*100.0)/(double)nPage); | |
| 20055 | 20111 | |
| 20056 | 20112 | ii = 0; |
| 20057 | - rc = analysisSqlInt(&s, &ii, | |
| 20113 | + rc = diskusedSqlInt(&s, &ii, | |
| 20058 | 20114 | "SELECT count(*)+1 FROM \"%w\".sqlite_schema WHERE type='table'", |
| 20059 | 20115 | s.zSchema); |
| 20060 | 20116 | if( rc ) return; |
| 20061 | - analysisLine(&s, "Number of tables", "%lld\n", ii); | |
| 20117 | + diskusedLine(&s, "Number of tables", "%lld\n", ii); | |
| 20062 | 20118 | nWORowid = 0; |
| 20063 | - rc = analysisSqlInt(&s, &nWORowid, | |
| 20119 | + rc = diskusedSqlInt(&s, &nWORowid, | |
| 20064 | 20120 | "SELECT count(*) FROM \"%w\".pragma_table_list WHERE wr", |
| 20065 | 20121 | s.zSchema); |
| 20066 | 20122 | if( rc ) return; |
| 20067 | 20123 | if( nWORowid>0 ){ |
| 20068 | - analysisLine(&s, "Number of WITHOUT ROWID tables", "%lld\n", nWORowid); | |
| 20069 | - analysisLine(&s, "Number of rowid tables", "%lld\n", ii - nWORowid); | |
| 20124 | + diskusedLine(&s, "Number of WITHOUT ROWID tables", "%lld\n", nWORowid); | |
| 20125 | + diskusedLine(&s, "Number of rowid tables", "%lld\n", ii - nWORowid); | |
| 20070 | 20126 | } |
| 20071 | 20127 | nIndex = 0; |
| 20072 | - rc = analysisSqlInt(&s, &nIndex, | |
| 20128 | + rc = diskusedSqlInt(&s, &nIndex, | |
| 20073 | 20129 | "SELECT count(*) FROM \"%w\".sqlite_schema WHERE type='index'", |
| 20074 | 20130 | s.zSchema); |
| 20075 | 20131 | if( rc ) return; |
| 20076 | - analysisLine(&s, "Number of indexes", "%lld\n", nIndex); | |
| 20132 | + diskusedLine(&s, "Number of indexes", "%lld\n", nIndex); | |
| 20077 | 20133 | ii = 0; |
| 20078 | - rc = analysisSqlInt(&s, &ii, | |
| 20134 | + rc = diskusedSqlInt(&s, &ii, | |
| 20079 | 20135 | "SELECT count(*) FROM \"%w\".sqlite_schema" |
| 20080 | 20136 | " WHERE name GLOB 'sqlite_autoindex_*' AND type='index'", |
| 20081 | 20137 | s.zSchema); |
| 20082 | 20138 | if( rc ) return; |
| 20083 | - analysisLine(&s, "Number of defined indexes", "%lld\n", nIndex - ii); | |
| 20084 | - analysisLine(&s, "Number of implied indexes", "%lld\n", ii); | |
| 20085 | - analysisLine(&s, "Size of the database in bytes", "%lld\n", pgsz*nPage); | |
| 20139 | + diskusedLine(&s, "Number of defined indexes", "%lld\n", nIndex - ii); | |
| 20140 | + diskusedLine(&s, "Number of implied indexes", "%lld\n", ii); | |
| 20141 | + diskusedLine(&s, "Size of the database in bytes", "%lld\n", pgsz*nPage); | |
| 20086 | 20142 | ii = 0; |
| 20087 | - rc = analysisSqlInt(&s, &ii, | |
| 20143 | + rc = diskusedSqlInt(&s, &ii, | |
| 20088 | 20144 | "SELECT sum(payload) FROM temp.%s" |
| 20089 | 20145 | " WHERE NOT is_index AND name NOT LIKE 'sqlite_schema'", |
| 20090 | 20146 | s.zSU); |
| 20091 | 20147 | if( rc ) return; |
| 20092 | - analysisLine(&s, "Bytes of payload", "%-11lld ", ii); | |
| 20093 | - analysisPercent(&s, ii*100.0/(double)(pgsz*nPage)); | |
| 20148 | + diskusedLine(&s, "Bytes of payload", "%-11lld ", ii); | |
| 20149 | + diskusedPercent(&s, ii*100.0/(double)(pgsz*nPage)); | |
| 20094 | 20150 | |
| 20095 | - analysisTitle(&s, "Page counts for all tables with their indexes"); | |
| 20096 | - pStmt = analysisPrepare(&s, | |
| 20151 | + diskusedTitle(&s, "Page counts for all tables with their indexes"); | |
| 20152 | + pStmt = diskusedPrepare(&s, | |
| 20097 | 20153 | "SELECT upper(tblname),\n" |
| 20098 | 20154 | " sum(int_pages+leaf_pages+ovfl_pages)\n" |
| 20099 | 20155 | " FROM temp.%s\n" |
| 20156 | + " WHERE tblname IS NOT NULL\n" | |
| 20157 | + " GROUP BY 1\n" | |
| 20158 | + " ORDER BY 2 DESC, 1;", | |
| 20159 | + s.zSU); | |
| 20160 | + if( pStmt==0 ) return; | |
| 20161 | + while( (rc = sqlite3_step(pStmt))==SQLITE_ROW ){ | |
| 20162 | + sqlite3_int64 nn = sqlite3_column_int64(pStmt,1); | |
| 20163 | + diskusedLine(&s, (const char*)sqlite3_column_text(pStmt,0), "%-11lld ", nn); | |
| 20164 | + diskusedPercent(&s, (nn*100.0)/(double)nPage); | |
| 20165 | + } | |
| 20166 | + if( diskusedStmtFinish(&s, rc, pStmt) ) return; | |
| 20167 | + | |
| 20168 | + diskusedTitle(&s, "Page counts for all tables and indexes separately"); | |
| 20169 | + pStmt = diskusedPrepare(&s, | |
| 20170 | + "SELECT upper(name),\n" | |
| 20171 | + " sum(int_pages+leaf_pages+ovfl_pages)\n" | |
| 20172 | + " FROM temp.%s\n" | |
| 20173 | + " WHERE name IS NOT NULL\n" | |
| 20100 | 20174 | " GROUP BY 1\n" |
| 20101 | 20175 | " ORDER BY 2 DESC, 1;", |
| 20102 | 20176 | s.zSU); |
| 20103 | 20177 | if( pStmt==0 ) return; |
| 20104 | 20178 | while( (rc = sqlite3_step(pStmt))==SQLITE_ROW ){ |
| 20105 | 20179 | sqlite3_int64 nn = sqlite3_column_int64(pStmt,1); |
| 20106 | - analysisLine(&s, (const char*)sqlite3_column_text(pStmt,0), "%-11lld ", nn); | |
| 20107 | - analysisPercent(&s, (nn*100.0)/(double)nPage); | |
| 20108 | - } | |
| 20109 | - if( analysisStmtFinish(&s, rc, pStmt) ) return; | |
| 20110 | - | |
| 20111 | - analysisTitle(&s, "Page counts for all tables and indexes separately"); | |
| 20112 | - pStmt = analysisPrepare(&s, | |
| 20113 | - "SELECT upper(name),\n" | |
| 20114 | - " sum(int_pages+leaf_pages+ovfl_pages)\n" | |
| 20115 | - " FROM temp.%s\n" | |
| 20116 | - " GROUP BY 1\n" | |
| 20117 | - " ORDER BY 2 DESC, 1;", | |
| 20118 | - s.zSU); | |
| 20119 | - if( pStmt==0 ) return; | |
| 20120 | - while( (rc = sqlite3_step(pStmt))==SQLITE_ROW ){ | |
| 20121 | - sqlite3_int64 nn = sqlite3_column_int64(pStmt,1); | |
| 20122 | - analysisLine(&s, (const char*)sqlite3_column_text(pStmt,0), "%-11lld ", nn); | |
| 20123 | - analysisPercent(&s, (nn*100.0)/(double)nPage); | |
| 20124 | - } | |
| 20125 | - if( analysisStmtFinish(&s, rc, pStmt) ) return; | |
| 20126 | - | |
| 20127 | - rc = analysisSubreport(&s, "All tables and indexes", "1", pgsz, nPage); | |
| 20180 | + diskusedLine(&s, (const char*)sqlite3_column_text(pStmt,0), "%-11lld ", nn); | |
| 20181 | + diskusedPercent(&s, (nn*100.0)/(double)nPage); | |
| 20182 | + } | |
| 20183 | + if( diskusedStmtFinish(&s, rc, pStmt) ) return; | |
| 20184 | + | |
| 20185 | + rc = diskusedSubreport(&s, "All tables and indexes", "1", pgsz, nPage); | |
| 20128 | 20186 | if( rc ) return; |
| 20129 | - rc = analysisSubreport(&s, "All tables", "NOT is_index", pgsz, nPage); | |
| 20187 | + rc = diskusedSubreport(&s, "All tables", "NOT is_index", pgsz, nPage); | |
| 20130 | 20188 | if( rc ) return; |
| 20131 | 20189 | if( nWORowid>0 ){ |
| 20132 | - rc = analysisSubreport(&s, "All WITHOUT ROWID tables", "is_without_rowid", | |
| 20190 | + rc = diskusedSubreport(&s, "All WITHOUT ROWID tables", "is_without_rowid", | |
| 20133 | 20191 | pgsz, nPage); |
| 20134 | 20192 | if( rc ) return; |
| 20135 | - rc = analysisSubreport(&s, "All rowid tables", | |
| 20193 | + rc = diskusedSubreport(&s, "All rowid tables", | |
| 20136 | 20194 | "NOT is_without_rowid AND NOT is_index", |
| 20137 | 20195 | pgsz, nPage); |
| 20138 | 20196 | if( rc ) return; |
| 20139 | 20197 | } |
| 20140 | - rc = analysisSubreport(&s, "All indexes", "is_index", pgsz, nPage); | |
| 20198 | + rc = diskusedSubreport(&s, "All indexes", "is_index", pgsz, nPage); | |
| 20141 | 20199 | if( rc ) return; |
| 20142 | 20200 | |
| 20143 | - pStmt = analysisPrepare(&s, | |
| 20201 | + pStmt = diskusedPrepare(&s, | |
| 20144 | 20202 | "SELECT upper(tblname), tblname, sum(is_index) FROM temp.%s" |
| 20145 | 20203 | " GROUP BY 1 ORDER BY 1", |
| 20146 | 20204 | s.zSU); |
| 20147 | 20205 | if( pStmt==0 ) return; |
| 20148 | 20206 | while( (rc = sqlite3_step(pStmt))==SQLITE_ROW ){ |
| @@ -20150,37 +20208,37 @@ | ||
| 20150 | 20208 | const char *zName = (const char*)sqlite3_column_text(pStmt, 1); |
| 20151 | 20209 | int nSubIndex = sqlite3_column_int(pStmt, 2); |
| 20152 | 20210 | if( nSubIndex==0 ){ |
| 20153 | 20211 | char *zTitle = sqlite3_mprintf("Table %s", zUpper); |
| 20154 | 20212 | char *zWhere = sqlite3_mprintf("name=%Q", zName); |
| 20155 | - rc = analysisSubreport(&s, zTitle, zWhere, pgsz, nPage); | |
| 20213 | + rc = diskusedSubreport(&s, zTitle, zWhere, pgsz, nPage); | |
| 20156 | 20214 | sqlite3_free(zTitle); |
| 20157 | 20215 | sqlite3_free(zWhere); |
| 20158 | 20216 | if( rc ) break; |
| 20159 | 20217 | }else{ |
| 20160 | 20218 | sqlite3_stmt *pS2; |
| 20161 | 20219 | char *zTitle = sqlite3_mprintf("Table %s and all its indexes", zUpper); |
| 20162 | 20220 | char *zWhere = sqlite3_mprintf("tblname=%Q", zName); |
| 20163 | - rc = analysisSubreport(&s, zTitle, zWhere, pgsz, nPage); | |
| 20221 | + rc = diskusedSubreport(&s, zTitle, zWhere, pgsz, nPage); | |
| 20164 | 20222 | sqlite3_free(zTitle); |
| 20165 | 20223 | sqlite3_free(zWhere); |
| 20166 | 20224 | if( rc ) break; |
| 20167 | 20225 | zTitle = sqlite3_mprintf("Table %s w/o any indexes", zUpper); |
| 20168 | 20226 | zWhere = sqlite3_mprintf("name=%Q", zName); |
| 20169 | - rc = analysisSubreport(&s, zTitle, zWhere, pgsz, nPage); | |
| 20227 | + rc = diskusedSubreport(&s, zTitle, zWhere, pgsz, nPage); | |
| 20170 | 20228 | sqlite3_free(zTitle); |
| 20171 | 20229 | sqlite3_free(zWhere); |
| 20172 | 20230 | if( rc ) break; |
| 20173 | 20231 | if( nSubIndex>1 ){ |
| 20174 | 20232 | zTitle = sqlite3_mprintf("All indexes of table %s", zUpper); |
| 20175 | 20233 | zWhere = sqlite3_mprintf("tblname=%Q AND is_index", zName); |
| 20176 | - rc = analysisSubreport(&s, zTitle, zWhere, pgsz, nPage); | |
| 20234 | + rc = diskusedSubreport(&s, zTitle, zWhere, pgsz, nPage); | |
| 20177 | 20235 | sqlite3_free(zTitle); |
| 20178 | 20236 | sqlite3_free(zWhere); |
| 20179 | 20237 | if( rc ) break; |
| 20180 | 20238 | } |
| 20181 | - pS2 = analysisPrepare(&s, | |
| 20239 | + pS2 = diskusedPrepare(&s, | |
| 20182 | 20240 | "SELECT name, upper(name) FROM temp.%s" |
| 20183 | 20241 | " WHERE is_index AND tblname=%Q", |
| 20184 | 20242 | s.zSU, zName); |
| 20185 | 20243 | if( pS2==0 ){ |
| 20186 | 20244 | rc = SQLITE_NOMEM; |
| @@ -20189,25 +20247,25 @@ | ||
| 20189 | 20247 | while( (rc = sqlite3_step(pS2))==SQLITE_ROW ){ |
| 20190 | 20248 | const char *zU = (const char*)sqlite3_column_text(pS2, 1); |
| 20191 | 20249 | const char *zN = (const char*)sqlite3_column_text(pS2, 0); |
| 20192 | 20250 | zTitle = sqlite3_mprintf("Index %s", zU); |
| 20193 | 20251 | zWhere = sqlite3_mprintf("name=%Q", zN); |
| 20194 | - rc = analysisSubreport(&s, zTitle, zWhere, pgsz, nPage); | |
| 20252 | + rc = diskusedSubreport(&s, zTitle, zWhere, pgsz, nPage); | |
| 20195 | 20253 | sqlite3_free(zTitle); |
| 20196 | 20254 | sqlite3_free(zWhere); |
| 20197 | 20255 | if( rc ) break; |
| 20198 | 20256 | } |
| 20199 | - rc = analysisStmtFinish(&s, rc, pS2); | |
| 20257 | + rc = diskusedStmtFinish(&s, rc, pS2); | |
| 20200 | 20258 | if( rc ) break; |
| 20201 | 20259 | } |
| 20202 | 20260 | } |
| 20203 | - if( analysisStmtFinish(&s, rc, pStmt) ) return; | |
| 20261 | + if( diskusedStmtFinish(&s, rc, pStmt) ) return; | |
| 20204 | 20262 | |
| 20205 | 20263 | /* Append SQL statements that will recreate the raw data used for |
| 20206 | 20264 | ** the analysis. |
| 20207 | 20265 | */ |
| 20208 | - analysisTitle(&s, "Raw data used to generate this report"); | |
| 20266 | + diskusedTitle(&s, "Raw data used to generate this report"); | |
| 20209 | 20267 | sqlite3_str_appendf(s.pOut, |
| 20210 | 20268 | "The following SQL will create a table named \"space_used\" which\n" |
| 20211 | 20269 | "contains most of the information used to generate the report above.\n" |
| 20212 | 20270 | "*/\n" |
| 20213 | 20271 | ); |
| @@ -20233,11 +20291,11 @@ | ||
| 20233 | 20291 | " ovfl_unused int, -- Unused bytes on overflow pages\n" /* 16 */ |
| 20234 | 20292 | " int_entries int -- B-tree entries on internal pages\n"/* 17 */ |
| 20235 | 20293 | ");\n" |
| 20236 | 20294 | "INSERT INTO space_used VALUES\n" |
| 20237 | 20295 | ); |
| 20238 | - pStmt = analysisPrepare(&s, | |
| 20296 | + pStmt = diskusedPrepare(&s, | |
| 20239 | 20297 | "SELECT quote(name), quote(tblname),\n" /* 0..1 */ |
| 20240 | 20298 | " is_index, is_without_rowid, nentry, leaf_entries,\n" /* 2..5 */ |
| 20241 | 20299 | " depth, payload, ovfl_payload, ovfl_cnt, mx_payload,\n" /* 6..10 */ |
| 20242 | 20300 | " int_pages, leaf_pages, ovfl_pages, int_unused,\n" /* 11..14 */ |
| 20243 | 20301 | " leaf_unused, ovfl_unused, int_entries\n" /* 15..17 */ |
| @@ -20268,11 +20326,11 @@ | ||
| 20268 | 20326 | sqlite3_column_int64(pStmt, 15), |
| 20269 | 20327 | sqlite3_column_int64(pStmt, 16), |
| 20270 | 20328 | sqlite3_column_int64(pStmt, 17)); |
| 20271 | 20329 | } |
| 20272 | 20330 | if( rc!=SQLITE_DONE ){ |
| 20273 | - analysisError(&s, "SQL run-time error: %s\nSQL: %s", | |
| 20331 | + diskusedError(&s, "SQL run-time error: %s\nSQL: %s", | |
| 20274 | 20332 | sqlite3_errmsg(s.db), sqlite3_sql(pStmt)); |
| 20275 | 20333 | sqlite3_finalize(pStmt); |
| 20276 | 20334 | return; |
| 20277 | 20335 | } |
| 20278 | 20336 | sqlite3_str_appendf(s.pOut,";\nCOMMIT;"); |
| @@ -20281,32 +20339,32 @@ | ||
| 20281 | 20339 | if( sqlite3_str_length(s.pOut) ){ |
| 20282 | 20340 | sqlite3_result_text(context, sqlite3_str_finish(s.pOut), -1, |
| 20283 | 20341 | sqlite3_free); |
| 20284 | 20342 | s.pOut = 0; |
| 20285 | 20343 | } |
| 20286 | - analysisReset(&s); | |
| 20344 | + diskusedReset(&s); | |
| 20287 | 20345 | } |
| 20288 | 20346 | |
| 20289 | 20347 | |
| 20290 | 20348 | #ifdef _WIN32 |
| 20291 | 20349 | |
| 20292 | 20350 | #endif |
| 20293 | -int sqlite3_analyze_init( | |
| 20351 | +int sqlite3_diskused_init( | |
| 20294 | 20352 | sqlite3 *db, |
| 20295 | 20353 | char **pzErrMsg, |
| 20296 | 20354 | const sqlite3_api_routines *pApi |
| 20297 | 20355 | ){ |
| 20298 | 20356 | int rc = SQLITE_OK; |
| 20299 | 20357 | SQLITE_EXTENSION_INIT2(pApi); |
| 20300 | 20358 | (void)pzErrMsg; /* Unused parameter */ |
| 20301 | - rc = sqlite3_create_function(db, "analyze", 1, | |
| 20359 | + rc = sqlite3_create_function(db, "diskused", 1, | |
| 20302 | 20360 | SQLITE_UTF8|SQLITE_INNOCUOUS, |
| 20303 | - 0, analyzeFunc, 0, 0); | |
| 20361 | + 0, diskusedFunc, 0, 0); | |
| 20304 | 20362 | return rc; |
| 20305 | 20363 | } |
| 20306 | 20364 | |
| 20307 | -/************************* End ext/misc/analyze.c ********************/ | |
| 20365 | +/************************* End ext/misc/diskused.c ********************/ | |
| 20308 | 20366 | |
| 20309 | 20367 | #if !defined(SQLITE_OMIT_VIRTUALTABLE) && defined(SQLITE_ENABLE_DBPAGE_VTAB) |
| 20310 | 20368 | #define SQLITE_SHELL_HAVE_RECOVER 1 |
| 20311 | 20369 | #else |
| 20312 | 20370 | #define SQLITE_SHELL_HAVE_RECOVER 0 |
| @@ -25138,11 +25196,11 @@ | ||
| 25138 | 25196 | /* |
| 25139 | 25197 | ** Return true if either the SQLITE_NO_COLOR compile-time option is used |
| 25140 | 25198 | ** or if the NO_COLOR environment variable exists |
| 25141 | 25199 | */ |
| 25142 | 25200 | static int shellNoColor(void){ |
| 25143 | -#ifdef SQLITE_NO_COLOR | |
| 25201 | +#if defined(SQLITE_NO_COLOR) || defined(SQLITE_SHELL_FIDDLE) | |
| 25144 | 25202 | return 1; |
| 25145 | 25203 | #else |
| 25146 | 25204 | return getenv("NO_COLOR")!=0; |
| 25147 | 25205 | #endif |
| 25148 | 25206 | } |
| @@ -25172,11 +25230,11 @@ | ||
| 25172 | 25230 | case 1: |
| 25173 | 25231 | #if defined(SQLITE_PS1) |
| 25174 | 25232 | return SQLITE_PS1; |
| 25175 | 25233 | #else |
| 25176 | 25234 | if( shellNoColor() ){ |
| 25177 | - return "/A-/v /~> "; | |
| 25235 | + return "/A-/v /f-> "; | |
| 25178 | 25236 | }else{ |
| 25179 | 25237 | return "/e[1;32m/A-/v /e[1;/x33/:36/;m/m/e[3m/;/f/;/e[0m-> "; |
| 25180 | 25238 | } |
| 25181 | 25239 | #endif |
| 25182 | 25240 | |
| @@ -25184,11 +25242,11 @@ | ||
| 25184 | 25242 | case 2: |
| 25185 | 25243 | #if defined(SQLITE_PS2) |
| 25186 | 25244 | return SQLITE_PS2; |
| 25187 | 25245 | #else |
| 25188 | 25246 | if( shellNoColor() ){ |
| 25189 | - return "/B/C> "; | |
| 25247 | + return "/B/C-> "; | |
| 25190 | 25248 | }else{ |
| 25191 | 25249 | return "/B/e[1;/x33/:36/;m/C/e[0m-> "; |
| 25192 | 25250 | } |
| 25193 | 25251 | #endif |
| 25194 | 25252 | |
| @@ -25196,11 +25254,15 @@ | ||
| 25196 | 25254 | ** of cases 1 and 2 */ |
| 25197 | 25255 | case 3: return "SQLITE_PS1"; |
| 25198 | 25256 | case 4: return "SQLITE_PS2"; |
| 25199 | 25257 | |
| 25200 | 25258 | /* Name of the application */ |
| 25259 | +#ifndef SQLITE_CLI_APPNAME | |
| 25201 | 25260 | case 'A': return "SQLite"; |
| 25261 | +#else | |
| 25262 | + case 'A': return SHELL_STRINGIFY(SQLITE_CLI_APPNAME); | |
| 25263 | +#endif | |
| 25202 | 25264 | |
| 25203 | 25265 | /* Full version number of the application, including patch level */ |
| 25204 | 25266 | case 'V': return sqlite3_libversion(); |
| 25205 | 25267 | |
| 25206 | 25268 | /* Version number without the patch level */ |
| @@ -26303,10 +26365,47 @@ | ||
| 26303 | 26365 | if( *az ){ |
| 26304 | 26366 | memcpy(*az, zNew, n+1 ); |
| 26305 | 26367 | } |
| 26306 | 26368 | } |
| 26307 | 26369 | } |
| 26370 | + | |
| 26371 | +/* Forward reference */ | |
| 26372 | +static int pickStr(const char *zArg, char **pzErr, ...); | |
| 26373 | + | |
| 26374 | +/* | |
| 26375 | +** Change the limits on the display mode. Return 0 on | |
| 26376 | +** success. Return non-zero if zArg is mis-formatted. | |
| 26377 | +** | |
| 26378 | +** Valid arguments: | |
| 26379 | +** | |
| 26380 | +** "on" Default limits | |
| 26381 | +** "off" All limits turned off | |
| 26382 | +** L,C Line and Characters limits set | |
| 26383 | +** L,C,T Line, Character, and Title limits set | |
| 26384 | +** | |
| 26385 | +** Anything else returns non-zero | |
| 26386 | +*/ | |
| 26387 | +static int modeSetLimit(ShellState *p, const char *zArg){ | |
| 26388 | + int k = zArg==0 ? 1 : pickStr(zArg,0,"on","off",""); | |
| 26389 | + if( k==0 ){ | |
| 26390 | + p->mode.spec.nLineLimit = DFLT_LINE_LIMIT; | |
| 26391 | + p->mode.spec.nCharLimit = DFLT_CHAR_LIMIT; | |
| 26392 | + p->mode.spec.nTitleLimit = DFLT_TITLE_LIMIT; | |
| 26393 | + }else if( k==1 ){ | |
| 26394 | + p->mode.spec.nLineLimit = 0; | |
| 26395 | + p->mode.spec.nCharLimit = 0; | |
| 26396 | + p->mode.spec.nTitleLimit = 0; | |
| 26397 | + }else{ | |
| 26398 | + int L, C, T = 0; | |
| 26399 | + int nNum = sscanf(zArg, "%d,%d,%d", &L, &C, &T); | |
| 26400 | + if( nNum<2 || L<0 || C<0 || T<0) return 1; | |
| 26401 | + p->mode.spec.nLineLimit = L; | |
| 26402 | + p->mode.spec.nCharLimit = C; | |
| 26403 | + if( nNum==3 ) p->mode.spec.nTitleLimit = T; | |
| 26404 | + } | |
| 26405 | + return 0; | |
| 26406 | +} | |
| 26308 | 26407 | |
| 26309 | 26408 | /* |
| 26310 | 26409 | ** Change the mode to eMode |
| 26311 | 26410 | */ |
| 26312 | 26411 | static void modeChange(ShellState *p, unsigned char eMode){ |
| @@ -26340,10 +26439,11 @@ | ||
| 26340 | 26439 | modeDup(&p->mode, &p->aSavedModes[eMode-MODE_USER].mode); |
| 26341 | 26440 | }else if( eMode==MODE_BATCH ){ |
| 26342 | 26441 | u8 mFlags = p->mode.mFlags; |
| 26343 | 26442 | modeFree(&p->mode); |
| 26344 | 26443 | modeChange(p, MODE_List); |
| 26444 | + modeSetLimit(p, "off"); | |
| 26345 | 26445 | p->mode.mFlags = mFlags; |
| 26346 | 26446 | }else if( eMode==MODE_TTY ){ |
| 26347 | 26447 | u8 mFlags = p->mode.mFlags; |
| 26348 | 26448 | modeFree(&p->mode); |
| 26349 | 26449 | modeChange(p, MODE_QBox); |
| @@ -26976,11 +27076,11 @@ | ||
| 26976 | 27076 | return SQLITE_OK; |
| 26977 | 27077 | } |
| 26978 | 27078 | #endif |
| 26979 | 27079 | |
| 26980 | 27080 | /* |
| 26981 | -** Print a schema statement. This is helper routine to dump_callbac(). | |
| 27081 | +** Print a schema statement. This is a helper routine to dump_callback(). | |
| 26982 | 27082 | ** |
| 26983 | 27083 | ** This routine converts some CREATE TABLE statements for shadow tables |
| 26984 | 27084 | ** in FTS3/4/5 into CREATE TABLE IF NOT EXISTS statements. |
| 26985 | 27085 | ** |
| 26986 | 27086 | ** If the schema statement in z[] contains a start-of-comment and if |
| @@ -28428,12 +28528,12 @@ | ||
| 28428 | 28528 | ".databases List names and files of attached databases", |
| 28429 | 28529 | ".dbconfig ?op? ?val? List or change sqlite3_db_config() options", |
| 28430 | 28530 | #if SQLITE_SHELL_HAVE_RECOVER |
| 28431 | 28531 | ".dbinfo ?DB? Show status information about the database", |
| 28432 | 28532 | #endif |
| 28433 | - ".dbstat ?SCHEMA? Report database space and size stats", | |
| 28434 | 28533 | ".dbtotxt Hex dump of the database file", |
| 28534 | + ".diskused ?SCHEMA? Report database space and size stats", | |
| 28435 | 28535 | ".dump ?OBJECTS? Render database content as SQL", |
| 28436 | 28536 | " Options:", |
| 28437 | 28537 | " --data-only Output only INSERT statements", |
| 28438 | 28538 | " --newlines Allow unescaped newline characters in output", |
| 28439 | 28539 | " --nosys Omit system tables (ex: \"sqlite_stat1\")", |
| @@ -28540,10 +28640,13 @@ | ||
| 28540 | 28640 | " --reset Reset the count for each input and interrupt", |
| 28541 | 28641 | " --timeout S Halt after running for S seconds", |
| 28542 | 28642 | #endif |
| 28543 | 28643 | ".prompt MAIN CONTINUE Replace the standard prompts", |
| 28544 | 28644 | " --hard-reset Unset SQLITE_PS1/2 and then --reset", |
| 28645 | +#ifndef SQLITE_NO_COLOR | |
| 28646 | + " --no-color Disable color prompts. Use --color to re-enable", | |
| 28647 | +#endif | |
| 28545 | 28648 | " --reset Revert to default prompts", |
| 28546 | 28649 | " --show Show the current prompt strings", |
| 28547 | 28650 | " -- No more options. Subsequent args are prompts", |
| 28548 | 28651 | #ifndef SQLITE_SHELL_FIDDLE |
| 28549 | 28652 | ".quit Stop interpreting input stream, exit if primary.", |
| @@ -29440,11 +29543,11 @@ | ||
| 29440 | 29543 | sqlite3_base64_init(p->db, 0, 0); |
| 29441 | 29544 | sqlite3_base85_init(p->db, 0, 0); |
| 29442 | 29545 | sqlite3_regexp_init(p->db, 0, 0); |
| 29443 | 29546 | sqlite3_ieee_init(p->db, 0, 0); |
| 29444 | 29547 | sqlite3_series_init(p->db, 0, 0); |
| 29445 | - sqlite3_analyze_init(p->db, 0, 0); | |
| 29548 | + sqlite3_diskused_init(p->db, 0, 0); | |
| 29446 | 29549 | #ifndef SQLITE_SHELL_FIDDLE |
| 29447 | 29550 | sqlite3_fileio_init(p->db, 0, 0); |
| 29448 | 29551 | sqlite3_completion_init(p->db, 0, 0); |
| 29449 | 29552 | #endif |
| 29450 | 29553 | #ifdef SQLITE_HAVE_ZLIB |
| @@ -31246,11 +31349,11 @@ | ||
| 31246 | 31349 | typedef struct ArCommand ArCommand; |
| 31247 | 31350 | struct ArCommand { |
| 31248 | 31351 | u8 eCmd; /* An AR_CMD_* value */ |
| 31249 | 31352 | u8 bVerbose; /* True if --verbose */ |
| 31250 | 31353 | u8 bZip; /* True if the archive is a ZIP */ |
| 31251 | - u8 bDryRun; /* True if --dry-run */ | |
| 31354 | + u8 bDryRun; /* 1 for --dry-run, 2 for --debug */ | |
| 31252 | 31355 | u8 bAppend; /* True if --append */ |
| 31253 | 31356 | u8 bGlob; /* True if --glob */ |
| 31254 | 31357 | u8 fromCmdLine; /* Run from -A instead of .archive */ |
| 31255 | 31358 | int nArg; /* Number of command arguments */ |
| 31256 | 31359 | char *zSrcTable; /* "sqlar", "zipfile($file)" or "zip" */ |
| @@ -31308,10 +31411,11 @@ | ||
| 31308 | 31411 | #define AR_SWITCH_FILE 9 |
| 31309 | 31412 | #define AR_SWITCH_DIRECTORY 10 |
| 31310 | 31413 | #define AR_SWITCH_APPEND 11 |
| 31311 | 31414 | #define AR_SWITCH_DRYRUN 12 |
| 31312 | 31415 | #define AR_SWITCH_GLOB 13 |
| 31416 | +#define AR_SWITCH_DEBUG 14 | |
| 31313 | 31417 | |
| 31314 | 31418 | static int arProcessSwitch(ArCommand *pAr, int eSwitch, const char *zArg){ |
| 31315 | 31419 | switch( eSwitch ){ |
| 31316 | 31420 | case AR_CMD_CREATE: |
| 31317 | 31421 | case AR_CMD_EXTRACT: |
| @@ -31325,11 +31429,14 @@ | ||
| 31325 | 31429 | } |
| 31326 | 31430 | pAr->eCmd = eSwitch; |
| 31327 | 31431 | break; |
| 31328 | 31432 | |
| 31329 | 31433 | case AR_SWITCH_DRYRUN: |
| 31330 | - pAr->bDryRun = 1; | |
| 31434 | + if( pAr->bDryRun<2 ) pAr->bDryRun = 1; | |
| 31435 | + break; | |
| 31436 | + case AR_SWITCH_DEBUG: | |
| 31437 | + pAr->bDryRun = 2; | |
| 31331 | 31438 | break; |
| 31332 | 31439 | case AR_SWITCH_GLOB: |
| 31333 | 31440 | pAr->bGlob = 1; |
| 31334 | 31441 | break; |
| 31335 | 31442 | case AR_SWITCH_VERBOSE: |
| @@ -31376,10 +31483,11 @@ | ||
| 31376 | 31483 | { "verbose", 'v', AR_SWITCH_VERBOSE, 0 }, |
| 31377 | 31484 | { "file", 'f', AR_SWITCH_FILE, 1 }, |
| 31378 | 31485 | { "append", 'a', AR_SWITCH_APPEND, 1 }, |
| 31379 | 31486 | { "directory", 'C', AR_SWITCH_DIRECTORY, 1 }, |
| 31380 | 31487 | { "dryrun", 'n', AR_SWITCH_DRYRUN, 0 }, |
| 31488 | + { "debug", 0, AR_SWITCH_DEBUG, 0 }, | |
| 31381 | 31489 | { "glob", 'g', AR_SWITCH_GLOB, 0 }, |
| 31382 | 31490 | }; |
| 31383 | 31491 | int nSwitch = sizeof(aSwitch) / sizeof(struct ArSwitch); |
| 31384 | 31492 | struct ArSwitch *pEnd = &aSwitch[nSwitch]; |
| 31385 | 31493 | |
| @@ -31676,18 +31784,41 @@ | ||
| 31676 | 31784 | |
| 31677 | 31785 | /* |
| 31678 | 31786 | ** Implementation of .ar "eXtract" command. |
| 31679 | 31787 | */ |
| 31680 | 31788 | static int arExtractCommand(ArCommand *pAr){ |
| 31789 | + /* The zSql1[] string is a template for the query that does the | |
| 31790 | + ** extraction. Notes: | |
| 31791 | + ** | |
| 31792 | + ** * $dir is the directory into which the archive is to be extracted | |
| 31793 | + ** * $pass is the integer pass number: 0, 1, or 2 | |
| 31794 | + ** * The dest CTE is created so that realpath($dir) only needs | |
| 31795 | + ** to be called once. | |
| 31796 | + */ | |
| 31681 | 31797 | const char *zSql1 = |
| 31682 | - "WITH dest(dpath,dlen) AS (SELECT realpath($dir),length(realpath($dir)))\n" | |
| 31683 | - "SELECT ($dir || name),\n" | |
| 31684 | - " CASE WHEN $dryrun THEN 0\n" | |
| 31685 | - " ELSE writefile($dir||name, %s, mode, mtime) END\n" | |
| 31798 | + "WITH dest(dpath,dlen) AS (\n" | |
| 31799 | +#ifdef _WIN32 | |
| 31800 | + " SELECT realpath($dir) || '\\',\n" | |
| 31801 | +#else | |
| 31802 | + " SELECT realpath($dir) || '/',\n" | |
| 31803 | +#endif | |
| 31804 | + " 1+length(realpath($dir))\n" | |
| 31805 | + ")\n" | |
| 31806 | + "SELECT\n" | |
| 31807 | + " ($dir || name),\n" | |
| 31808 | + " CASE $dryrun\n" /* vv--- azExtraArg */ | |
| 31809 | + " WHEN 0 THEN writefile($dir||name, %s, mode, mtime)\n" | |
| 31810 | + " WHEN 1 THEN 0\n" | |
| 31811 | + " ELSE shell_putsnl(format('writefile(%%Q,%%s,%%0o,%%d)'," | |
| 31812 | + "$dir||name,quote(%s),mode,mtime)) IS NULL\n" | |
| 31813 | + " END\n" /* ^^--- azExtraArg */ | |
| 31686 | 31814 | " FROM dest CROSS JOIN %s\n" |
| 31687 | - " WHERE (%s)\n" | |
| 31688 | - " AND (data IS NULL OR $pass==0)\n" /* Dirs both passes */ | |
| 31815 | + " WHERE (%s)\n" /* ^^-- pAr->zSrcTable */ | |
| 31816 | + /* ^^--- zWhere */ | |
| 31817 | + " AND (CASE $pass WHEN 0 THEN (mode&0xf000)<>0xa000\n" | |
| 31818 | + " WHEN 1 THEN (mode&0xf000)=0xa000\n" | |
| 31819 | + " ELSE data IS NULL END)\n" | |
| 31689 | 31820 | " AND dpath=substr(realpath($dir||name),1,dlen)\n" /* No escapes */ |
| 31690 | 31821 | " AND name NOT GLOB '*..[/\\]*'\n"; /* No /../ in paths */ |
| 31691 | 31822 | |
| 31692 | 31823 | const char *azExtraArg[] = { |
| 31693 | 31824 | "sqlar_uncompress(data, sz)", |
| @@ -31714,39 +31845,48 @@ | ||
| 31714 | 31845 | } |
| 31715 | 31846 | if( zDir==0 ) rc = SQLITE_NOMEM; |
| 31716 | 31847 | } |
| 31717 | 31848 | |
| 31718 | 31849 | shellPreparePrintf(pAr->db, &rc, &pSql, zSql1, |
| 31719 | - azExtraArg[pAr->bZip], pAr->zSrcTable, zWhere | |
| 31850 | + azExtraArg[pAr->bZip], | |
| 31851 | + azExtraArg[pAr->bZip], | |
| 31852 | + pAr->zSrcTable, | |
| 31853 | + zWhere | |
| 31720 | 31854 | ); |
| 31721 | 31855 | |
| 31722 | 31856 | if( rc==SQLITE_OK ){ |
| 31723 | 31857 | j = sqlite3_bind_parameter_index(pSql, "$dir"); |
| 31724 | 31858 | sqlite3_bind_text(pSql, j, zDir, -1, SQLITE_STATIC); |
| 31725 | 31859 | j = sqlite3_bind_parameter_index(pSql, "$dryrun"); |
| 31726 | 31860 | sqlite3_bind_int(pSql, j, pAr->bDryRun); |
| 31727 | 31861 | |
| 31728 | 31862 | /* Run the SELECT statement twice |
| 31729 | - ** (0) writefile() all files and directories | |
| 31730 | - ** (1) writefile() for directory again | |
| 31731 | - ** The second pass is so that the timestamps for extracted directories | |
| 31863 | + ** (0) writefile() files and directories | |
| 31864 | + ** (1) writefile() symlinks | |
| 31865 | + ** (2) writefile() for directory again | |
| 31866 | + ** The third pass is so that the timestamps for extracted directories | |
| 31732 | 31867 | ** will be reset to the value in the archive, since populating them |
| 31733 | 31868 | ** in the first pass will have changed the timestamp. */ |
| 31734 | - for(i=0; i<2; i++){ | |
| 31869 | + for(i=0; i<3; i++){ | |
| 31870 | + if( pAr->bDryRun>=2 ){ | |
| 31871 | + cli_printf(pAr->out, "*** BEGIN PASS %d ***\n", i+1); | |
| 31872 | + } | |
| 31735 | 31873 | j = sqlite3_bind_parameter_index(pSql, "$pass"); |
| 31736 | 31874 | sqlite3_bind_int(pSql, j, i); |
| 31737 | - if( pAr->bDryRun ){ | |
| 31875 | + if( pAr->bDryRun && i==0 ){ | |
| 31738 | 31876 | cli_printf(pAr->out, "%s\n", sqlite3_sql(pSql)); |
| 31739 | - if( pAr->bVerbose==0 ) break; | |
| 31740 | 31877 | } |
| 31741 | 31878 | while( rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pSql) ){ |
| 31742 | 31879 | if( i==0 && pAr->bVerbose ){ |
| 31743 | 31880 | cli_printf(pAr->out, "%s\n", sqlite3_column_text(pSql, 0)); |
| 31744 | 31881 | } |
| 31745 | 31882 | } |
| 31746 | - if( pAr->bDryRun ) break; | |
| 31883 | + if( pAr->bDryRun==1 ) break; | |
| 31747 | 31884 | shellReset(&rc, pSql); |
| 31885 | + if( pAr->bDryRun>=2 ){ | |
| 31886 | + cli_printf(pAr->out, "*** END PASS %d ***\n", i+1); | |
| 31887 | + } | |
| 31748 | 31888 | } |
| 31749 | 31889 | shellFinalize(&rc, pSql); |
| 31750 | 31890 | } |
| 31751 | 31891 | |
| 31752 | 31892 | sqlite3_free(zDir); |
| @@ -32257,11 +32397,11 @@ | ||
| 32257 | 32397 | ; |
| 32258 | 32398 | static const char * const zCollectVar = "\ |
| 32259 | 32399 | SELECT\ |
| 32260 | 32400 | '('||x'0a'\ |
| 32261 | 32401 | || group_concat(\ |
| 32262 | - cname||' ANY',\ | |
| 32402 | + cname,\ | |
| 32263 | 32403 | ','||iif((cpos-1)%4>0, ' ', x'0a'||' '))\ |
| 32264 | 32404 | ||')' AS ColsSpec \ |
| 32265 | 32405 | FROM (\ |
| 32266 | 32406 | SELECT cpos, printf('\"%w\"',printf('%!.*s%s', nlen-chop,name,suff)) AS cname \ |
| 32267 | 32407 | FROM ColNames ORDER BY cpos\ |
| @@ -33102,30 +33242,14 @@ | ||
| 33102 | 33242 | }else if( optionMatch(z,"limits") ){ |
| 33103 | 33243 | if( (++i)>=nArg ){ |
| 33104 | 33244 | dotCmdError(p, i-1, "missing argument", 0); |
| 33105 | 33245 | return 1; |
| 33106 | 33246 | } |
| 33107 | - k = pickStr(azArg[i],0,"on","off",""); | |
| 33108 | - if( k==0 ){ | |
| 33109 | - p->mode.spec.nLineLimit = DFLT_LINE_LIMIT; | |
| 33110 | - p->mode.spec.nCharLimit = DFLT_CHAR_LIMIT; | |
| 33111 | - p->mode.spec.nTitleLimit = DFLT_TITLE_LIMIT; | |
| 33112 | - }else if( k==1 ){ | |
| 33113 | - p->mode.spec.nLineLimit = 0; | |
| 33114 | - p->mode.spec.nCharLimit = 0; | |
| 33115 | - p->mode.spec.nTitleLimit = 0; | |
| 33116 | - }else{ | |
| 33117 | - int L, C, T = 0; | |
| 33118 | - int nNum = sscanf(azArg[i], "%d,%d,%d", &L, &C, &T); | |
| 33119 | - if( nNum<2 || L<0 || C<0 || T<0){ | |
| 33120 | - dotCmdError(p, i, "bad argument", "Should be \"L,C,T\" where L, C" | |
| 33121 | - " and T are unsigned integers"); | |
| 33122 | - return 1; | |
| 33123 | - } | |
| 33124 | - p->mode.spec.nLineLimit = L; | |
| 33125 | - p->mode.spec.nCharLimit = C; | |
| 33126 | - if( nNum==3 ) p->mode.spec.nTitleLimit = T; | |
| 33247 | + if( modeSetLimit(p, azArg[i]) ){ | |
| 33248 | + dotCmdError(p, i, "bad argument", "Should be \"on\" or \"off\" or " | |
| 33249 | + "\"L,C,T\" where L, C, and T are unsigned integers"); | |
| 33250 | + return 1; | |
| 33127 | 33251 | } |
| 33128 | 33252 | chng = 1; |
| 33129 | 33253 | }else if( optionMatch(z,"list") ){ |
| 33130 | 33254 | int ii; |
| 33131 | 33255 | cli_puts("available modes:", p->out); |
| @@ -34339,11 +34463,16 @@ | ||
| 34339 | 34463 | if( c=='d' && n>=3 && cli_strncmp(azArg[0], "dbinfo", n)==0 ){ |
| 34340 | 34464 | rc = shell_dbinfo_command(p, nArg, azArg); |
| 34341 | 34465 | }else |
| 34342 | 34466 | #endif /* SQLITE_SHELL_HAVE_RECOVER */ |
| 34343 | 34467 | |
| 34344 | - if( c=='d' && n==6 && cli_strncmp(azArg[0], "dbstat", n)==0 ){ | |
| 34468 | + if( c=='d' && n>=3 && cli_strncmp(azArg[0], "dbtotxt", n)==0 ){ | |
| 34469 | + open_db(p, 0); | |
| 34470 | + rc = shell_dbtotxt_command(p, nArg, azArg); | |
| 34471 | + }else | |
| 34472 | + | |
| 34473 | + if( c=='d' && n==8 && cli_strncmp(azArg[0], "diskused", n)==0 ){ | |
| 34345 | 34474 | const char *zSchema = 0; |
| 34346 | 34475 | int ii; |
| 34347 | 34476 | char *zSql; |
| 34348 | 34477 | open_db(p, 0); |
| 34349 | 34478 | for(ii=1; ii<nArg; ii++){ |
| @@ -34358,27 +34487,19 @@ | ||
| 34358 | 34487 | rc = 1; |
| 34359 | 34488 | goto meta_command_exit; |
| 34360 | 34489 | } |
| 34361 | 34490 | zSchema = z; |
| 34362 | 34491 | } |
| 34363 | - zSql = sqlite3_mprintf("SELECT analyze(%Q)", zSchema); | |
| 34492 | + zSql = sqlite3_mprintf("SELECT diskused(%Q)", zSchema); | |
| 34364 | 34493 | shell_check_oom(zSql); |
| 34365 | 34494 | modePush(p); |
| 34366 | 34495 | modeChange(p, MODE_BATCH); |
| 34367 | - p->mode.spec.nLineLimit = 0; | |
| 34368 | - p->mode.spec.nCharLimit = 0; | |
| 34369 | - p->mode.spec.nTitleLimit = 0; | |
| 34370 | 34496 | shell_exec(p, zSql, 0); |
| 34371 | 34497 | modePop(p); |
| 34372 | 34498 | sqlite3_free(zSql); |
| 34373 | 34499 | }else |
| 34374 | 34500 | |
| 34375 | - if( c=='d' && n>=3 && cli_strncmp(azArg[0], "dbtotxt", n)==0 ){ | |
| 34376 | - open_db(p, 0); | |
| 34377 | - rc = shell_dbtotxt_command(p, nArg, azArg); | |
| 34378 | - }else | |
| 34379 | - | |
| 34380 | 34501 | if( c=='d' && cli_strncmp(azArg[0], "dump", n)==0 ){ |
| 34381 | 34502 | char *zLike = 0; |
| 34382 | 34503 | char *zSql; |
| 34383 | 34504 | int i; |
| 34384 | 34505 | int savedShellFlags = p->shellFlgs; |
| @@ -35491,10 +35612,26 @@ | ||
| 35491 | 35612 | }else |
| 35492 | 35613 | if( strcmp(z,"-show")==0 ){ |
| 35493 | 35614 | cli_printf(stdout,"Main prompt: '%s'\n", prompt_string(p, 0)); |
| 35494 | 35615 | cli_printf(stdout,"Continuation: '%s'\n", prompt_string(p, 1)); |
| 35495 | 35616 | }else |
| 35617 | +#ifndef SQLITE_NO_COLOR | |
| 35618 | + if( strcmp(z,"-color")==0 ){ | |
| 35619 | +#ifdef _WIN32 | |
| 35620 | + _putenv("NO_COLOR="); | |
| 35621 | +#else | |
| 35622 | + unsetenv("NO_COLOR"); | |
| 35623 | +#endif | |
| 35624 | + }else | |
| 35625 | + if( strcmp(z,"-no-color")==0 ){ | |
| 35626 | +#ifdef _WIN32 | |
| 35627 | + _putenv("NO_COLOR=1"); | |
| 35628 | +#else | |
| 35629 | + setenv("NO_COLOR","1",1); | |
| 35630 | +#endif | |
| 35631 | + }else | |
| 35632 | +#endif | |
| 35496 | 35633 | if( strcmp(z,"-")==0 ){ |
| 35497 | 35634 | noOpt = 1; |
| 35498 | 35635 | }else |
| 35499 | 35636 | { |
| 35500 | 35637 | dotCmdError(p, i, "unknown option", 0); |
| @@ -35505,10 +35642,11 @@ | ||
| 35505 | 35642 | dotCmdError(p, i, "extra argument", 0); |
| 35506 | 35643 | rc = 1; |
| 35507 | 35644 | goto meta_command_exit; |
| 35508 | 35645 | }else if( !p->dot.abQuot[i] && sqlite3_strglob("*[^a-z]*",z)!=0 ){ |
| 35509 | 35646 | dotCmdError(p, i, "use quotes around the prompt string", 0); |
| 35647 | + rc = 1; | |
| 35510 | 35648 | }else{ |
| 35511 | 35649 | free(p->azPrompt[cnt]); |
| 35512 | 35650 | p->azPrompt[cnt] = strdup(z); |
| 35513 | 35651 | cnt++; |
| 35514 | 35652 | } |
| @@ -37717,17 +37855,17 @@ | ||
| 37717 | 37855 | " -- treat no subsequent arguments as options\n" |
| 37718 | 37856 | #if defined(SQLITE_HAVE_ZLIB) && !defined(SQLITE_OMIT_VIRTUALTABLE) |
| 37719 | 37857 | " -A ARGS... run \".archive ARGS\" and exit\n" |
| 37720 | 37858 | #endif |
| 37721 | 37859 | " -append append the database to the end of the file\n" |
| 37722 | - " -ascii set output mode to 'ascii'\n" | |
| 37860 | + " -ascii set '.mode ascii'\n" | |
| 37723 | 37861 | " -bail stop after hitting an error\n" |
| 37724 | 37862 | " -batch force batch I/O\n" |
| 37725 | - " -box set output mode to 'box'\n" | |
| 37863 | + " -box set '.mode box'\n" | |
| 37726 | 37864 | " -cmd COMMAND run \"COMMAND\" before reading stdin\n" |
| 37727 | - " -column set output mode to 'column'\n" | |
| 37728 | - " -csv set output mode to 'csv'\n" | |
| 37865 | + " -column set '.mode column'\n" | |
| 37866 | + " -csv set '.mode csv -limits off'\n" | |
| 37729 | 37867 | #if !defined(SQLITE_OMIT_DESERIALIZE) |
| 37730 | 37868 | " -deserialize open the database using sqlite3_deserialize()\n" |
| 37731 | 37869 | #endif |
| 37732 | 37870 | " -echo print inputs before execution\n" |
| 37733 | 37871 | " -escape T ctrl-char escape; T is one of: symbol, ascii, off\n" |
| @@ -37735,18 +37873,18 @@ | ||
| 37735 | 37873 | " -[no]header turn headers on or off\n" |
| 37736 | 37874 | #if defined(SQLITE_ENABLE_MEMSYS3) || defined(SQLITE_ENABLE_MEMSYS5) |
| 37737 | 37875 | " -heap SIZE Size of heap for memsys3 or memsys5\n" |
| 37738 | 37876 | #endif |
| 37739 | 37877 | " -help show this message\n" |
| 37740 | - " -html set output mode to HTML\n" | |
| 37878 | + " -html set '.mode html'\n" | |
| 37741 | 37879 | " -ifexists only open if database already exists\n" |
| 37742 | 37880 | " -interactive force interactive I/O\n" |
| 37743 | - " -json set output mode to 'json'\n" | |
| 37744 | - " -line set output mode to 'line'\n" | |
| 37745 | - " -list set output mode to 'list'\n" | |
| 37881 | + " -json set '.mode json'\n" | |
| 37882 | + " -line set '.mode line'\n" | |
| 37883 | + " -list set '.mode list'\n" | |
| 37746 | 37884 | " -lookaside SIZE N use N entries of SZ bytes for lookaside memory\n" |
| 37747 | - " -markdown set output mode to 'markdown'\n" | |
| 37885 | + " -markdown set '.mode markdown'\n" | |
| 37748 | 37886 | #if !defined(SQLITE_OMIT_DESERIALIZE) |
| 37749 | 37887 | " -maxsize N maximum size for a --deserialize database\n" |
| 37750 | 37888 | #endif |
| 37751 | 37889 | " -memtrace trace all memory allocations and deallocations\n" |
| 37752 | 37890 | " -mmap N default mmap size set to N\n" |
| @@ -37759,21 +37897,21 @@ | ||
| 37759 | 37897 | " -nonce STRING set the safe-mode escape nonce\n" |
| 37760 | 37898 | " -no-rowid-in-view Disable rowid-in-view using sqlite3_config()\n" |
| 37761 | 37899 | " -nullvalue TEXT set text string for NULL values. Default ''\n" |
| 37762 | 37900 | " -pagecache SIZE N use N slots of SZ bytes each for page cache memory\n" |
| 37763 | 37901 | " -pcachetrace trace all page cache operations\n" |
| 37764 | - " -quote set output mode to 'quote'\n" | |
| 37902 | + " -quote set '.mode quote'\n" | |
| 37765 | 37903 | " -readonly open the database read-only\n" |
| 37766 | 37904 | " -safe enable safe-mode\n" |
| 37767 | 37905 | " -screenwidth N use N as the default screenwidth \n" |
| 37768 | 37906 | " -separator SEP set output column separator. Default: '|'\n" |
| 37769 | 37907 | #ifdef SQLITE_ENABLE_SORTER_REFERENCES |
| 37770 | 37908 | " -sorterref SIZE sorter references threshold size\n" |
| 37771 | 37909 | #endif |
| 37772 | 37910 | " -stats print memory stats before each finalize\n" |
| 37773 | - " -table set output mode to 'table'\n" | |
| 37774 | - " -tabs set output mode to 'tabs'\n" | |
| 37911 | + " -table set '.mode table'\n" | |
| 37912 | + " -tabs set '.mode tabs'\n" | |
| 37775 | 37913 | " -unsafe-testing allow unsafe commands and modes for testing\n" |
| 37776 | 37914 | " -version show SQLite version\n" |
| 37777 | 37915 | " -vfs NAME use NAME as the default VFS\n" |
| 37778 | 37916 | " -vfstrace enable tracing of all VFS calls\n" |
| 37779 | 37917 | #ifdef SQLITE_HAVE_ZLIB |
| @@ -37801,10 +37939,23 @@ | ||
| 37801 | 37939 | sputz(stdout, "WARNING: attempt to configure SQLite after" |
| 37802 | 37940 | " initialization.\n"); |
| 37803 | 37941 | } |
| 37804 | 37942 | } |
| 37805 | 37943 | |
| 37944 | +#if HAVE_EDITLINE | |
| 37945 | +/* | |
| 37946 | +** https://sqlite.org/forum/forumpost/aad7a634916ff050: | |
| 37947 | +** | |
| 37948 | +** Calling setlocale(LC_...,"") is required to get libedit to accept | |
| 37949 | +** non-ASCII input. | |
| 37950 | +*/ | |
| 37951 | +#define DO_SET_LOCALE 1 | |
| 37952 | +#include <locale.h> | |
| 37953 | +#else | |
| 37954 | +#define DO_SET_LOCALE 0 | |
| 37955 | +#endif | |
| 37956 | + | |
| 37806 | 37957 | /* |
| 37807 | 37958 | ** Initialize the state information in data |
| 37808 | 37959 | */ |
| 37809 | 37960 | static void main_init(ShellState *p) { |
| 37810 | 37961 | memset(p, 0, sizeof(*p)); |
| @@ -37825,10 +37976,14 @@ | ||
| 37825 | 37976 | #else |
| 37826 | 37977 | /* No \001...\002 escapes required for linenoise or when not using a |
| 37827 | 37978 | ** command-line editing library */ |
| 37828 | 37979 | p->bDelimitNonprint = 0; |
| 37829 | 37980 | #endif |
| 37981 | +#if DO_SET_LOCALE | |
| 37982 | + setlocale(LC_CTYPE,""); | |
| 37983 | +#endif | |
| 37984 | +#undef DO_SET_LOCALE | |
| 37830 | 37985 | } |
| 37831 | 37986 | |
| 37832 | 37987 | /* |
| 37833 | 37988 | ** Output text to the console in a font that attracts extra attention. |
| 37834 | 37989 | */ |
| @@ -37854,11 +38009,11 @@ | ||
| 37854 | 38009 | } |
| 37855 | 38010 | |
| 37856 | 38011 | /* |
| 37857 | 38012 | ** The callback from atexit(). |
| 37858 | 38013 | */ |
| 37859 | -static void abnormalExit(void){ | |
| 38014 | +static void SQLITE_CDECL abnormalExit(void){ | |
| 37860 | 38015 | if( seenInterrupt ) eputz("Program interrupted.\n"); |
| 37861 | 38016 | if( globalShellState ){ |
| 37862 | 38017 | clearTempFile(globalShellState, 1, 1); |
| 37863 | 38018 | } |
| 37864 | 38019 | } |
| @@ -38065,11 +38220,11 @@ | ||
| 38065 | 38220 | stdin_is_interactive = 0; |
| 38066 | 38221 | nCmd++; |
| 38067 | 38222 | azCmd = realloc(azCmd, sizeof(azCmd[0])*nCmd); |
| 38068 | 38223 | shell_check_oom(azCmd); |
| 38069 | 38224 | aiCmd = realloc(aiCmd, sizeof(aiCmd[0])*nCmd); |
| 38070 | - shell_check_oom(azCmd); | |
| 38225 | + shell_check_oom(aiCmd); | |
| 38071 | 38226 | azCmd[nCmd-1] = z; |
| 38072 | 38227 | aiCmd[nCmd-1] = i; |
| 38073 | 38228 | } |
| 38074 | 38229 | continue; |
| 38075 | 38230 | } |
| @@ -38354,10 +38509,11 @@ | ||
| 38354 | 38509 | modeChange(&data, MODE_Psql); |
| 38355 | 38510 | }else if( cli_strcmp(z,"-box")==0 ){ |
| 38356 | 38511 | modeChange(&data, MODE_Box); |
| 38357 | 38512 | }else if( cli_strcmp(z,"-csv")==0 ){ |
| 38358 | 38513 | modeChange(&data, MODE_Csv); |
| 38514 | + modeSetLimit(&data, "off"); | |
| 38359 | 38515 | }else if( cli_strcmp(z,"-escape")==0 && i+1<argc ){ |
| 38360 | 38516 | /* See similar code at tag-20250224-1 */ |
| 38361 | 38517 | const char *zEsc = argv[++i]; |
| 38362 | 38518 | int k; |
| 38363 | 38519 | for(k=0; k<ArraySize(qrfEscNames); k++){ |
| @@ -38412,12 +38568,14 @@ | ||
| 38412 | 38568 | }else if( cli_strcmp(z,"-nullvalue")==0 ){ |
| 38413 | 38569 | modeSetStr(&data.mode.spec.zNull, |
| 38414 | 38570 | cmdline_option_value(argc,argv,++i)); |
| 38415 | 38571 | }else if( cli_strcmp(z,"-header")==0 ){ |
| 38416 | 38572 | data.mode.spec.bTitles = QRF_Yes; |
| 38573 | + data.mode.mFlags |= MFLG_HDR; | |
| 38417 | 38574 | }else if( cli_strcmp(z,"-noheader")==0 ){ |
| 38418 | 38575 | data.mode.spec.bTitles = QRF_No; |
| 38576 | + data.mode.mFlags |= MFLG_HDR; | |
| 38419 | 38577 | }else if( cli_strcmp(z,"-echo")==0 ){ |
| 38420 | 38578 | data.mode.mFlags |= MFLG_ECHO; |
| 38421 | 38579 | }else if( cli_strcmp(z,"-eqp")==0 ){ |
| 38422 | 38580 | data.mode.autoEQP = AUTOEQP_on; |
| 38423 | 38581 | }else if( cli_strcmp(z,"-eqpfull")==0 ){ |
| 38424 | 38582 |
| --- extsrc/shell.c | |
| +++ extsrc/shell.c | |
| @@ -5,16 +5,16 @@ | |
| 5 | ** |
| 6 | ** ext/expert/sqlite3expert.c |
| 7 | ** ext/expert/sqlite3expert.h |
| 8 | ** ext/intck/sqlite3intck.c |
| 9 | ** ext/intck/sqlite3intck.h |
| 10 | ** ext/misc/analyze.c |
| 11 | ** ext/misc/appendvfs.c |
| 12 | ** ext/misc/base64.c |
| 13 | ** ext/misc/base85.c |
| 14 | ** ext/misc/completion.c |
| 15 | ** ext/misc/decimal.c |
| 16 | ** ext/misc/fileio.c |
| 17 | ** ext/misc/ieee754.c |
| 18 | ** ext/misc/memtrace.c |
| 19 | ** ext/misc/pcachetrace.c |
| 20 | ** ext/misc/regexp.c |
| @@ -154,10 +154,11 @@ | |
| 154 | #include <string.h> |
| 155 | #include <stdio.h> |
| 156 | #include <assert.h> |
| 157 | #include <math.h> |
| 158 | #include <stdint.h> |
| 159 | #include "sqlite3.h" |
| 160 | typedef sqlite3_int64 i64; |
| 161 | typedef sqlite3_uint64 u64; |
| 162 | typedef unsigned char u8; |
| 163 | #include <ctype.h> |
| @@ -190,13 +191,14 @@ | |
| 190 | #include <sys/stat.h> |
| 191 | |
| 192 | #if HAVE_READLINE |
| 193 | # include <readline/readline.h> |
| 194 | # include <readline/history.h> |
| 195 | #endif |
| 196 | |
| 197 | #if HAVE_EDITLINE |
| 198 | # include <editline/readline.h> |
| 199 | #endif |
| 200 | |
| 201 | #if HAVE_EDITLINE || HAVE_READLINE |
| 202 | |
| @@ -744,12 +746,11 @@ | |
| 744 | const sqlite3_qrf_spec *pSpec, /* Result format specification */ |
| 745 | char **pzErr /* OUT: Write error message here */ |
| 746 | ); |
| 747 | |
| 748 | /* |
| 749 | ** Range of values for sqlite3_qrf_spec.aWidth[] entries and for |
| 750 | ** sqlite3_qrf_spec.mxColWidth and .nScreenWidth |
| 751 | */ |
| 752 | #define QRF_MAX_WIDTH 10000 |
| 753 | #define QRF_MIN_WIDTH 0 |
| 754 | |
| 755 | /* |
| @@ -1129,10 +1130,14 @@ | |
| 1129 | sqlite3_str_append(pOut, "-", 1); |
| 1130 | } |
| 1131 | if( N<10000 ){ |
| 1132 | sqlite3_str_appendf(pOut, "%4lld ", N); |
| 1133 | return; |
| 1134 | } |
| 1135 | for(i=1; i<=18; i++){ |
| 1136 | N = (N+5)/10; |
| 1137 | if( N<10000 ){ |
| 1138 | int n = (int)N; |
| @@ -1289,12 +1294,12 @@ | |
| 1289 | if( nCycle>=0 || nLoop>=0 || nRow>=0 ){ |
| 1290 | int nSp = 0; |
| 1291 | sqlite3_str_reset(pStats); |
| 1292 | if( nCycle>=0 && nTotal>0 ){ |
| 1293 | qrfApproxInt64(pStats, nCycle); |
| 1294 | sqlite3_str_appendf(pStats, " %3d%%", |
| 1295 | ((nCycle*100)+nTotal/2) / nTotal |
| 1296 | ); |
| 1297 | nSp = 2; |
| 1298 | } |
| 1299 | if( nLoop>=0 ){ |
| 1300 | if( nSp ) sqlite3_str_appendchar(pStats, nSp, ' '); |
| @@ -1787,11 +1792,11 @@ | |
| 1787 | } |
| 1788 | if( i>0 ){ |
| 1789 | sqlite3_str_append(pOut, (const char*)z, i); |
| 1790 | } |
| 1791 | switch( z[i] ){ |
| 1792 | case '>': sqlite3_str_append(pOut, "<", 4); break; |
| 1793 | case '&': sqlite3_str_append(pOut, "&", 5); break; |
| 1794 | case '<': sqlite3_str_append(pOut, "<", 4); break; |
| 1795 | case '"': sqlite3_str_append(pOut, """, 6); break; |
| 1796 | case '\'': sqlite3_str_append(pOut, "'", 5); break; |
| 1797 | default: i--; |
| @@ -2281,11 +2286,11 @@ | |
| 2281 | if( bWrap && z[i]!=0 && !qrfSpace(z[i]) && qrfAlnum(c)==qrfAlnum(z[i]) ){ |
| 2282 | /* Perhaps try to back up to a better place to break the line */ |
| 2283 | for(k=i-1; k>=i/2; k--){ |
| 2284 | if( qrfSpace(z[k]) ) break; |
| 2285 | } |
| 2286 | if( k<i/2 ){ |
| 2287 | for(k=i; k>=i/2; k--){ |
| 2288 | if( qrfAlnum(z[k-1])!=qrfAlnum(z[k]) && (z[k]&0xc0)!=0x80 ) break; |
| 2289 | } |
| 2290 | } |
| 2291 | if( k>=i/2 ){ |
| @@ -2532,16 +2537,16 @@ | |
| 2532 | const char *azDash[2] = { |
| 2533 | BOX_24 BOX_24 BOX_24 BOX_24 BOX_24 BOX_24 BOX_24 BOX_24 BOX_24 BOX_24, |
| 2534 | DBL_24 DBL_24 DBL_24 DBL_24 DBL_24 DBL_24 DBL_24 DBL_24 DBL_24 DBL_24 |
| 2535 | };/* 0 1 2 3 4 5 6 7 8 9 */ |
| 2536 | const int nDash = 30; |
| 2537 | N *= 3; |
| 2538 | while( N>nDash ){ |
| 2539 | sqlite3_str_append(pOut, azDash[bDbl], nDash); |
| 2540 | N -= nDash; |
| 2541 | } |
| 2542 | sqlite3_str_append(pOut, azDash[bDbl], N); |
| 2543 | } |
| 2544 | |
| 2545 | /* |
| 2546 | ** Draw a horizontal separator for a QRF_STYLE_Box table. |
| 2547 | */ |
| @@ -2610,11 +2615,11 @@ | |
| 2610 | int nSW /* Screen width */ |
| 2611 | ){ |
| 2612 | int i; /* Loop counter */ |
| 2613 | int nr; /* Number of rows */ |
| 2614 | int w = 0; /* Width of the current column */ |
| 2615 | int t; /* Total width of all columns */ |
| 2616 | int *aw; /* Array of individual column widths */ |
| 2617 | |
| 2618 | aw = sqlite3_malloc64( sizeof(int)*nCol ); |
| 2619 | if( aw==0 ){ |
| 2620 | qrfOom(p); |
| @@ -2748,12 +2753,15 @@ | |
| 2748 | }else{ |
| 2749 | sepW = pData->nCol*3 + 1; |
| 2750 | if( p->spec.bBorder==QRF_No ) sepW -= 2; |
| 2751 | } |
| 2752 | nCol = pData->nCol; |
| 2753 | for(i=sumW=0; i<nCol; i++) sumW += pData->a[i].w; |
| 2754 | if( p->spec.nScreenWidth >= sumW+sepW ) return; |
| 2755 | |
| 2756 | /* First thing to do is reduce the separation between columns */ |
| 2757 | pData->nMargin = 0; |
| 2758 | if( p->spec.eStyle==QRF_STYLE_Column ){ |
| 2759 | sepW = pData->nCol - 1; |
| @@ -3624,11 +3632,11 @@ | |
| 3624 | p->nRow = 0; |
| 3625 | sz = sizeof(sqlite3_qrf_spec); |
| 3626 | memcpy(&p->spec, pSpec, sz); |
| 3627 | if( p->spec.zNull==0 ) p->spec.zNull = ""; |
| 3628 | p->mxWidth = p->spec.nScreenWidth; |
| 3629 | if( p->mxWidth<=0 ) p->mxWidth = QRF_MAX_WIDTH; |
| 3630 | p->mxHeight = p->spec.nLineLimit; |
| 3631 | if( p->mxHeight<=0 ) p->mxHeight = 2147483647; |
| 3632 | if( p->spec.eStyle>QRF_STYLE_Table ) p->spec.eStyle = QRF_Auto; |
| 3633 | if( p->spec.eEsc>QRF_ESC_Symbol ) p->spec.eEsc = QRF_Auto; |
| 3634 | if( p->spec.eText>QRF_TEXT_Relaxed ) p->spec.eText = QRF_Auto; |
| @@ -5272,10 +5280,14 @@ | |
| 5272 | #include <stdarg.h> |
| 5273 | |
| 5274 | /****************************************************************************** |
| 5275 | ** The Hash Engine |
| 5276 | */ |
| 5277 | /* Context for the SHA1 hash */ |
| 5278 | typedef struct SHA1Context SHA1Context; |
| 5279 | struct SHA1Context { |
| 5280 | unsigned int state[5]; |
| 5281 | unsigned int count[2]; |
| @@ -5412,11 +5424,11 @@ | |
| 5412 | } |
| 5413 | j = 0; |
| 5414 | }else{ |
| 5415 | i = 0; |
| 5416 | } |
| 5417 | (void)memcpy(&p->buffer[j], &data[i], len - i); |
| 5418 | } |
| 5419 | |
| 5420 | /* Compute a string using sqlite3_vsnprintf() and hash it */ |
| 5421 | static void hash_step_vformat( |
| 5422 | SHA1Context *p, /* Add content to this context */ |
| @@ -5467,10 +5479,13 @@ | |
| 5467 | zOut[i*2+1] = zEncode[digest[i] & 0xf]; |
| 5468 | } |
| 5469 | zOut[i*2]= 0; |
| 5470 | } |
| 5471 | } |
| 5472 | /* End of the hashing logic |
| 5473 | *****************************************************************************/ |
| 5474 | |
| 5475 | /* |
| 5476 | ** Two SQL functions: sha1(X) and sha1b(X). |
| @@ -6056,32 +6071,41 @@ | |
| 6056 | } |
| 6057 | z[i] = 0; |
| 6058 | sqlite3_result_text(pCtx, z, i, sqlite3_free); |
| 6059 | } |
| 6060 | |
| 6061 | /* |
| 6062 | ** Round a decimal value to N significant digits. N must be positive. |
| 6063 | */ |
| 6064 | static void decimal_round(Decimal *p, int N){ |
| 6065 | int i; |
| 6066 | int nZero; |
| 6067 | if( N<1 ) return; |
| 6068 | if( p==0 ) return; |
| 6069 | if( p->nDigit<=N ) return; |
| 6070 | for(nZero=0; nZero<p->nDigit && p->a[nZero]==0; nZero++){} |
| 6071 | N += nZero; |
| 6072 | if( p->nDigit<=N ) return; |
| 6073 | if( p->a[N]>4 ){ |
| 6074 | p->a[N-1]++; |
| 6075 | for(i=N-1; i>0 && p->a[i]>9; i--){ |
| 6076 | p->a[i] = 0; |
| 6077 | p->a[i-1]++; |
| 6078 | } |
| 6079 | if( p->a[0]>9 ){ |
| 6080 | p->a[0] = 1; |
| 6081 | p->nFrac--; |
| 6082 | } |
| 6083 | } |
| 6084 | memset(&p->a[N], 0, p->nDigit - N); |
| 6085 | } |
| 6086 | |
| 6087 | /* |
| @@ -8363,19 +8387,26 @@ | |
| 8363 | } |
| 8364 | }else{ |
| 8365 | iMin = iMax = sqlite3_value_int64(argv[iArg++]); |
| 8366 | } |
| 8367 | }else{ |
| 8368 | if( idxNum & 0x0300 ){ /* value>X or value>=X */ |
| 8369 | if( sqlite3_value_numeric_type(argv[iArg])==SQLITE_FLOAT ){ |
| 8370 | double r = sqlite3_value_double(argv[iArg++]); |
| 8371 | if( r<(double)SMALLEST_INT64 ){ |
| 8372 | iMin = SMALLEST_INT64; |
| 8373 | }else if( (idxNum & 0x0200)!=0 && r==seriesCeil(r) ){ |
| 8374 | iMin = (sqlite3_int64)seriesCeil(r+1.0); |
| 8375 | }else{ |
| 8376 | iMin = (sqlite3_int64)seriesCeil(r); |
| 8377 | } |
| 8378 | }else{ |
| 8379 | iMin = sqlite3_value_int64(argv[iArg++]); |
| 8380 | if( (idxNum & 0x0200)!=0 ){ |
| 8381 | if( iMin==LARGEST_INT64 ){ |
| @@ -8384,19 +8415,25 @@ | |
| 8384 | iMin++; |
| 8385 | } |
| 8386 | } |
| 8387 | } |
| 8388 | } |
| 8389 | if( idxNum & 0x3000 ){ /* value<X or value<=X */ |
| 8390 | if( sqlite3_value_numeric_type(argv[iArg])==SQLITE_FLOAT ){ |
| 8391 | double r = sqlite3_value_double(argv[iArg++]); |
| 8392 | if( r>(double)LARGEST_INT64 ){ |
| 8393 | iMax = LARGEST_INT64; |
| 8394 | }else if( (idxNum & 0x2000)!=0 && r==seriesFloor(r) ){ |
| 8395 | iMax = (sqlite3_int64)(r-1.0); |
| 8396 | }else{ |
| 8397 | iMax = (sqlite3_int64)seriesFloor(r); |
| 8398 | } |
| 8399 | }else{ |
| 8400 | iMax = sqlite3_value_int64(argv[iArg++]); |
| 8401 | if( idxNum & 0x2000 ){ |
| 8402 | if( iMax==SMALLEST_INT64 ){ |
| @@ -9638,11 +9675,10 @@ | |
| 9638 | if( pRe==0 ){ |
| 9639 | sqlite3_result_error_nomem(context); |
| 9640 | return; |
| 9641 | } |
| 9642 | pStr = sqlite3_str_new(0); |
| 9643 | if( pStr==0 ) goto re_bytecode_func_err; |
| 9644 | if( pRe->nInit>0 ){ |
| 9645 | sqlite3_str_appendf(pStr, "INIT "); |
| 9646 | for(i=0; i<pRe->nInit; i++){ |
| 9647 | sqlite3_str_appendf(pStr, "%02x", pRe->zInit[i]); |
| 9648 | } |
| @@ -9649,20 +9685,20 @@ | |
| 9649 | sqlite3_str_appendf(pStr, "\n"); |
| 9650 | } |
| 9651 | for(i=0; (unsigned)i<pRe->nState; i++){ |
| 9652 | sqlite3_str_appendf(pStr, "%-8s %4d\n", |
| 9653 | ReOpName[(unsigned char)pRe->aOp[i]], pRe->aArg[i]); |
| 9654 | } |
| 9655 | n = sqlite3_str_length(pStr); |
| 9656 | z = sqlite3_str_finish(pStr); |
| 9657 | if( n==0 ){ |
| 9658 | sqlite3_free(z); |
| 9659 | }else{ |
| 9660 | sqlite3_result_text(context, z, n-1, sqlite3_free); |
| 9661 | } |
| 9662 | |
| 9663 | re_bytecode_func_err: |
| 9664 | re_free(pRe); |
| 9665 | } |
| 9666 | |
| 9667 | #endif /* SQLITE_DEBUG */ |
| 9668 | |
| @@ -10870,10 +10906,13 @@ | |
| 10870 | ** Return NULL if unable. |
| 10871 | ** |
| 10872 | ** The file or directory X is not required to exist. The answer is formed |
| 10873 | ** by calling system realpath() on the prefix of X that does exist and |
| 10874 | ** appending the tail of X that does not (yet) exist. |
| 10875 | */ |
| 10876 | static void realpathFunc( |
| 10877 | sqlite3_context *context, |
| 10878 | int argc, |
| 10879 | sqlite3_value **argv |
| @@ -10892,10 +10931,11 @@ | |
| 10892 | (void)argc; |
| 10893 | zPath = (const char*)sqlite3_value_text(argv[0]); |
| 10894 | if( zPath==0 ) return; |
| 10895 | if( zPath[0]==0 ) zPath = "."; |
| 10896 | zCopy = sqlite3_mprintf("%s",zPath); |
| 10897 | len = strlen(zCopy); |
| 10898 | while( len>1 && (zCopy[len-1]=='/' || (isWin && zCopy[len-1]=='\\')) ){ |
| 10899 | len--; |
| 10900 | } |
| 10901 | zCopy[len] = 0; |
| @@ -12685,10 +12725,11 @@ | |
| 12685 | |
| 12686 | for(p=pCsr->pFreeEntry; p; p=pNext){ |
| 12687 | pNext = p->pNext; |
| 12688 | zipfileEntryFree(p); |
| 12689 | } |
| 12690 | } |
| 12691 | |
| 12692 | /* |
| 12693 | ** Destructor for an ZipfileCsr. |
| 12694 | */ |
| @@ -13087,11 +13128,17 @@ | |
| 13087 | } |
| 13088 | } |
| 13089 | |
| 13090 | if( rc==SQLITE_OK ){ |
| 13091 | u32 *pt = &pNew->mUnixTime; |
| 13092 | pNew->cds.zFile = sqlite3_mprintf("%.*s", nFile, aRead); |
| 13093 | pNew->aExtra = (u8*)&pNew[1]; |
| 13094 | memcpy(pNew->aExtra, &aRead[nFile], nExtra); |
| 13095 | if( pNew->cds.zFile==0 ){ |
| 13096 | rc = SQLITE_NOMEM; |
| 13097 | }else if( 0==zipfileScanExtra(&aRead[nFile], pNew->cds.nExtra, pt) ){ |
| @@ -14191,14 +14238,14 @@ | |
| 14191 | ZipfileBuffer body; |
| 14192 | ZipfileBuffer cds; |
| 14193 | }; |
| 14194 | |
| 14195 | static int zipfileBufferGrow(ZipfileBuffer *pBuf, i64 nByte){ |
| 14196 | if( pBuf->n+nByte>pBuf->nAlloc ){ |
| 14197 | u8 *aNew; |
| 14198 | sqlite3_int64 nNew = pBuf->n ? pBuf->n*2 : 512; |
| 14199 | int nReq = pBuf->n + nByte; |
| 14200 | |
| 14201 | while( nNew<nReq ) nNew = nNew*2; |
| 14202 | aNew = sqlite3_realloc64(pBuf->a, nNew); |
| 14203 | if( aNew==0 ) return SQLITE_NOMEM; |
| 14204 | pBuf->a = aNew; |
| @@ -16296,11 +16343,11 @@ | |
| 16296 | p->pTable = pTab; |
| 16297 | |
| 16298 | /* The statement the vtab will pass to sqlite3_declare_vtab() */ |
| 16299 | zInner = idxAppendText(&rc, 0, "CREATE TABLE x("); |
| 16300 | for(i=0; i<pTab->nCol; i++){ |
| 16301 | zInner = idxAppendText(&rc, zInner, "%s%Q COLLATE %s", |
| 16302 | (i==0 ? "" : ", "), pTab->aCol[i].zName, pTab->aCol[i].zColl |
| 16303 | ); |
| 16304 | } |
| 16305 | zInner = idxAppendText(&rc, zInner, ")"); |
| 16306 | |
| @@ -16496,11 +16543,11 @@ | |
| 16496 | sqlite3_free(zCols); |
| 16497 | sqlite3_free(zOrder); |
| 16498 | return sqlite3_reset(pIndexXInfo); |
| 16499 | } |
| 16500 | zCols = idxAppendText(&rc, zCols, |
| 16501 | "%sx.%Q IS sqlite_expert_rem(%d, x.%Q) COLLATE %s", |
| 16502 | zComma, zName, nCol, zName, zColl |
| 16503 | ); |
| 16504 | zOrder = idxAppendText(&rc, zOrder, "%s%d", zComma, ++nCol); |
| 16505 | } |
| 16506 | sqlite3_reset(pIndexXInfo); |
| @@ -19464,11 +19511,11 @@ | |
| 19464 | sqlite3_vfs_unregister(pVfs); |
| 19465 | sqlite3_free(pVfs); |
| 19466 | } |
| 19467 | |
| 19468 | /************************* End ext/misc/vfstrace.c ********************/ |
| 19469 | /************************* Begin ext/misc/analyze.c ******************/ |
| 19470 | /* |
| 19471 | ** 2026-04-13 |
| 19472 | ** |
| 19473 | ** The author disclaims copyright to this source code. In place of |
| 19474 | ** a legal notice, here is a blessing: |
| @@ -19477,12 +19524,21 @@ | |
| 19477 | ** May you find forgiveness for yourself and forgive others. |
| 19478 | ** May you share freely, never taking more than you give. |
| 19479 | ** |
| 19480 | ****************************************************************************** |
| 19481 | ** |
| 19482 | ** Partial reimplement of the sqlite3_analyzer utility program as |
| 19483 | ** loadable SQL function. |
| 19484 | */ |
| 19485 | /* #include "sqlite3ext.h" */ |
| 19486 | SQLITE_EXTENSION_INIT1 |
| 19487 | #include <assert.h> |
| 19488 | #include <string.h> |
| @@ -19490,28 +19546,28 @@ | |
| 19490 | #include <math.h> |
| 19491 | |
| 19492 | /* |
| 19493 | ** State information for the analysis |
| 19494 | */ |
| 19495 | typedef struct Analysis Analysis; |
| 19496 | struct Analysis { |
| 19497 | sqlite3 *db; /* Database connection */ |
| 19498 | sqlite3_context *context; /* SQL function context */ |
| 19499 | sqlite3_str *pOut; /* Write output here */ |
| 19500 | char *zSU; /* Name of the temp.space_used table */ |
| 19501 | const char *zSchema; /* Schema to be analyzed */ |
| 19502 | }; |
| 19503 | |
| 19504 | /* |
| 19505 | ** Free all resources that the Analysis object references and |
| 19506 | ** reset the Analysis object. |
| 19507 | ** |
| 19508 | ** Call this routine multiple times on the same Analysis object |
| 19509 | ** is a harmless no-op, as long as the memory for the object itself |
| 19510 | ** has not been freed. |
| 19511 | */ |
| 19512 | static void analysisReset(Analysis *p){ |
| 19513 | if( p->zSU ){ |
| 19514 | char *zSql = sqlite3_mprintf("DROP TABLE temp.%s;", p->zSU); |
| 19515 | if( zSql ){ |
| 19516 | sqlite3_exec(p->db, zSql, 0, 0, 0); |
| 19517 | sqlite3_free(zSql); |
| @@ -19524,11 +19580,11 @@ | |
| 19524 | |
| 19525 | /* |
| 19526 | ** Report an error using formatted text. If zFormat==NULL then report |
| 19527 | ** an OOM error. |
| 19528 | */ |
| 19529 | static void analysisError(Analysis *p, const char *zFormat, ...){ |
| 19530 | char *zErr; |
| 19531 | if( zFormat ){ |
| 19532 | va_list ap; |
| 19533 | va_start(ap, zFormat); |
| 19534 | zErr = sqlite3_vmprintf(zFormat, ap); |
| @@ -19540,38 +19596,38 @@ | |
| 19540 | sqlite3_result_error_nomem(p->context); |
| 19541 | }else{ |
| 19542 | sqlite3_result_error(p->context, zErr, -1); |
| 19543 | sqlite3_free(zErr); |
| 19544 | } |
| 19545 | analysisReset(p); |
| 19546 | } |
| 19547 | |
| 19548 | /* |
| 19549 | ** Prepare and return an SQL statement. |
| 19550 | */ |
| 19551 | static sqlite3_stmt *analysisVPrep(Analysis *p, const char *zFmt, va_list ap){ |
| 19552 | char *zSql; |
| 19553 | int rc; |
| 19554 | sqlite3_stmt *pStmt = 0; |
| 19555 | zSql = sqlite3_vmprintf(zFmt, ap); |
| 19556 | if( zSql==0 ){ analysisError(p,0); return 0; } |
| 19557 | rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0); |
| 19558 | if( rc ){ |
| 19559 | analysisError(p, "SQL parse error: %s\nOriginal SQL: %s", |
| 19560 | sqlite3_errmsg(p->db), zSql); |
| 19561 | sqlite3_finalize(pStmt); |
| 19562 | analysisReset(p); |
| 19563 | pStmt = 0; |
| 19564 | } |
| 19565 | sqlite3_free(zSql); |
| 19566 | return pStmt; |
| 19567 | } |
| 19568 | static sqlite3_stmt *analysisPrepare(Analysis *p, const char *zFormat, ...){ |
| 19569 | va_list ap; |
| 19570 | sqlite3_stmt *pStmt = 0; |
| 19571 | va_start(ap, zFormat); |
| 19572 | pStmt = analysisVPrep(p,zFormat,ap); |
| 19573 | va_end(ap); |
| 19574 | return pStmt; |
| 19575 | } |
| 19576 | |
| 19577 | /* |
| @@ -19580,60 +19636,60 @@ | |
| 19580 | ** |
| 19581 | ** If rc is SQLITE_DONE or SQLITE_OK, then return false. |
| 19582 | ** |
| 19583 | ** The prepared statement is closed in either case. |
| 19584 | */ |
| 19585 | static int analysisStmtFinish(Analysis *p, int rc, sqlite3_stmt *pStmt){ |
| 19586 | if( rc==SQLITE_DONE ){ |
| 19587 | rc = SQLITE_OK; |
| 19588 | } |
| 19589 | if( rc!=SQLITE_OK || (rc = sqlite3_reset(pStmt))!=SQLITE_OK ){ |
| 19590 | analysisError(p, "SQL run-time error: %s\nOriginal SQL: %s", |
| 19591 | sqlite3_errmsg(p->db), sqlite3_sql(pStmt)); |
| 19592 | analysisReset(p); |
| 19593 | } |
| 19594 | sqlite3_finalize(pStmt); |
| 19595 | return rc; |
| 19596 | } |
| 19597 | |
| 19598 | /* |
| 19599 | ** Run SQL. Return the number of errors. |
| 19600 | */ |
| 19601 | static int analysisSql(Analysis *p, const char *zFormat, ...){ |
| 19602 | va_list ap; |
| 19603 | int rc; |
| 19604 | sqlite3_stmt *pStmt = 0; |
| 19605 | va_start(ap, zFormat); |
| 19606 | pStmt = analysisVPrep(p,zFormat,ap); |
| 19607 | va_end(ap); |
| 19608 | if( pStmt==0 ) return 1; |
| 19609 | while( (rc = sqlite3_step(pStmt))==SQLITE_ROW ){} |
| 19610 | if( rc==SQLITE_DONE ){ |
| 19611 | rc = SQLITE_OK; |
| 19612 | }else{ |
| 19613 | analysisError(p, "SQL run-time error: %s\nOriginal SQL: %s", |
| 19614 | sqlite3_errmsg(p->db), sqlite3_sql(pStmt)); |
| 19615 | analysisReset(p); |
| 19616 | } |
| 19617 | sqlite3_finalize(pStmt); |
| 19618 | return rc; |
| 19619 | } |
| 19620 | |
| 19621 | /* |
| 19622 | ** Run an SQL query that returns an integer. Write that integer |
| 19623 | ** into *piRes. Return the number of errors. |
| 19624 | */ |
| 19625 | static int analysisSqlInt( |
| 19626 | Analysis *p, |
| 19627 | sqlite3_int64 *piRes, |
| 19628 | const char *zFormat, ... |
| 19629 | ){ |
| 19630 | va_list ap; |
| 19631 | int rc; |
| 19632 | sqlite3_stmt *pStmt = 0; |
| 19633 | va_start(ap, zFormat); |
| 19634 | pStmt = analysisVPrep(p,zFormat,ap); |
| 19635 | va_end(ap); |
| 19636 | if( pStmt==0 ) return 1; |
| 19637 | rc = sqlite3_step(pStmt); |
| 19638 | if( rc==SQLITE_ROW ){ |
| 19639 | *piRes = sqlite3_column_int64(pStmt, 0); |
| @@ -19641,14 +19697,14 @@ | |
| 19641 | }else if( rc==SQLITE_DONE ){ |
| 19642 | rc = SQLITE_OK; |
| 19643 | }else{ |
| 19644 | if( p->db ){ |
| 19645 | /* p->db is NULL if there was some prior error */ |
| 19646 | analysisError(p, "SQL run-time error: %s\nOriginal SQL: %s", |
| 19647 | sqlite3_errmsg(p->db), sqlite3_sql(pStmt)); |
| 19648 | } |
| 19649 | analysisReset(p); |
| 19650 | } |
| 19651 | sqlite3_finalize(pStmt); |
| 19652 | return rc; |
| 19653 | } |
| 19654 | |
| @@ -19657,20 +19713,20 @@ | |
| 19657 | ** by the format string. If the output is initially empty, begin |
| 19658 | ** the title line with "/" so that it forms the beginning of a C-style |
| 19659 | ** comment. Otherwise begin with a new-line. Always finish with a |
| 19660 | ** newline. |
| 19661 | */ |
| 19662 | static void analysisTitle(Analysis *p, const char *zFormat, ...){ |
| 19663 | char *zFirst; |
| 19664 | char *zTitle; |
| 19665 | size_t nTitle; |
| 19666 | va_list ap; |
| 19667 | va_start(ap, zFormat); |
| 19668 | zTitle = sqlite3_vmprintf(zFormat, ap); |
| 19669 | va_end(ap); |
| 19670 | if( zTitle==0 ){ |
| 19671 | analysisError(p, 0); |
| 19672 | return; |
| 19673 | } |
| 19674 | zFirst = sqlite3_str_length(p->pOut)==0 ? "/" : "\n*"; |
| 19675 | nTitle = strlen(zTitle); |
| 19676 | if( nTitle>=75 ){ |
| @@ -19685,12 +19741,12 @@ | |
| 19685 | /* |
| 19686 | ** Add an output line that begins with the zDesc text extended out to |
| 19687 | ** 50 columns with "." characters, and followed by whatever text is |
| 19688 | ** described by zFormat. |
| 19689 | */ |
| 19690 | static void analysisLine( |
| 19691 | Analysis *p, /* Analysis context */ |
| 19692 | const char *zDesc, /* Description */ |
| 19693 | const char *zFormat, /* Argument to the description */ |
| 19694 | ... |
| 19695 | ){ |
| 19696 | char *zTxt; |
| @@ -19698,14 +19754,14 @@ | |
| 19698 | va_list ap; |
| 19699 | va_start(ap, zFormat); |
| 19700 | zTxt = sqlite3_vmprintf(zFormat, ap); |
| 19701 | va_end(ap); |
| 19702 | if( zTxt==0 ){ |
| 19703 | analysisError(p, 0); |
| 19704 | return; |
| 19705 | } |
| 19706 | nDesc = strlen(zDesc); |
| 19707 | if( nDesc>=50 ){ |
| 19708 | sqlite3_str_appendf(p->pOut, "%s %z", zDesc, zTxt); |
| 19709 | }else{ |
| 19710 | int nExtra = 50 - (int)nDesc; |
| 19711 | sqlite3_str_appendf(p->pOut, "%s%.*c %z", zDesc, nExtra, '.', zTxt); |
| @@ -19715,11 +19771,11 @@ | |
| 19715 | /* |
| 19716 | ** Write a percentage into the output. The number written should show |
| 19717 | ** two or three significant digits, with the decimal point being the fourth |
| 19718 | ** character. |
| 19719 | */ |
| 19720 | static void analysisPercent(Analysis *p, double r){ |
| 19721 | char zNum[100]; |
| 19722 | char *zDP; |
| 19723 | int nLeadingDigit; |
| 19724 | int sz; |
| 19725 | sqlite3_snprintf(sizeof(zNum)-5, zNum, r>=10.0 ? "%.3g" :"%.2g", r); |
| @@ -19744,12 +19800,12 @@ | |
| 19744 | ** |
| 19745 | ** The title if the subreport is given by zTitle. zWhere is |
| 19746 | ** a boolean expression that can go in the WHERE clause to select |
| 19747 | ** the relevant rows of the s.zSU table. |
| 19748 | */ |
| 19749 | static int analysisSubreport( |
| 19750 | Analysis *p, /* Analysis context */ |
| 19751 | char *zTitle, /* Title for this subreport */ |
| 19752 | char *zWhere, /* WHERE clause for this subreport */ |
| 19753 | sqlite3_int64 pgsz, /* Database page size */ |
| 19754 | sqlite3_int64 nPage /* Number of pages in entire database */ |
| 19755 | ){ |
| @@ -19773,14 +19829,14 @@ | |
| 19773 | sqlite3_int64 total_unused; /* Total unused bytes */ |
| 19774 | sqlite3_int64 total_meta; /* Total metadata */ |
| 19775 | int rc; |
| 19776 | |
| 19777 | if( zTitle==0 || zWhere==0 ){ |
| 19778 | analysisError(p, 0); |
| 19779 | return SQLITE_NOMEM; |
| 19780 | } |
| 19781 | pStmt = analysisPrepare(p, |
| 19782 | "SELECT\n" |
| 19783 | " sum(if(is_without_rowid OR is_index,nentry,leaf_entries)),\n" /* 0 */ |
| 19784 | " sum(payload),\n" /* 1 */ |
| 19785 | " sum(ovfl_payload),\n" /* 2 */ |
| 19786 | " max(mx_payload),\n" /* 3 */ |
| @@ -19797,11 +19853,11 @@ | |
| 19797 | " FROM temp.%s WHERE %s", |
| 19798 | p->zSU, zWhere); |
| 19799 | if( pStmt==0 ) return 1; |
| 19800 | rc = sqlite3_step(pStmt); |
| 19801 | if( rc==SQLITE_ROW ){ |
| 19802 | analysisTitle(p, zTitle); |
| 19803 | |
| 19804 | nentry = sqlite3_column_int64(pStmt, 0); |
| 19805 | payload = sqlite3_column_int64(pStmt, 1); |
| 19806 | ovfl_payload = sqlite3_column_int64(pStmt, 2); |
| 19807 | mx_payload = sqlite3_column_int64(pStmt, 3); |
| @@ -19816,73 +19872,73 @@ | |
| 19816 | cnt = sqlite3_column_int64(pStmt, 12); |
| 19817 | int_cell = sqlite3_column_int64(pStmt, 13); |
| 19818 | rc = SQLITE_DONE; |
| 19819 | |
| 19820 | total_pages = leaf_pages + int_pages + ovfl_pages; |
| 19821 | analysisLine(p, "Percentage of total database", "%.3g%%\n", |
| 19822 | (total_pages*100.0)/(double)nPage); |
| 19823 | analysisLine(p, "Number of entries", "%lld\n", nentry); |
| 19824 | storage = total_pages*pgsz; |
| 19825 | analysisLine(p, "Bytes of storage consumed", "%lld\n", storage); |
| 19826 | analysisLine(p, "Bytes of payload", "%-11lld ", payload); |
| 19827 | analysisPercent(p, payload*100.0/(double)storage); |
| 19828 | if( ovfl_cnt>0 ){ |
| 19829 | analysisLine(p, "Bytes of payload in overflow","%-11lld ",ovfl_payload); |
| 19830 | analysisPercent(p, ovfl_payload*100.0/(double)payload); |
| 19831 | } |
| 19832 | total_unused = leaf_unused + int_unused + ovfl_unused; |
| 19833 | total_meta = storage - payload - total_unused; |
| 19834 | analysisLine(p, "Bytes of metadata","%-11lld ", total_meta); |
| 19835 | analysisPercent(p, total_meta*100.0/(double)storage); |
| 19836 | if( cnt==1 ){ |
| 19837 | analysisLine(p, "B-tree depth", "%lld\n", depth); |
| 19838 | if( int_cell>1 ){ |
| 19839 | analysisLine(p, "Average fanout", "%.1f\n", |
| 19840 | (double)(int_cell+int_pages)/(double)int_pages); |
| 19841 | } |
| 19842 | } |
| 19843 | if( nentry>0 ){ |
| 19844 | analysisLine(p, "Average payload per entry", "%.1f\n", |
| 19845 | (double)payload/(double)nentry); |
| 19846 | analysisLine(p, "Average unused bytes per entry", "%.1f\n", |
| 19847 | (double)total_unused/(double)nentry); |
| 19848 | analysisLine(p, "Average metadata per entry", "%.1f\n", |
| 19849 | (double)total_meta/(double)nentry); |
| 19850 | } |
| 19851 | analysisLine(p, "Maximum single-entry payload", "%lld\n", mx_payload); |
| 19852 | if( nentry>0 ){ |
| 19853 | analysisLine(p, "Entries that use overflow", "%-11lld ", ovfl_cnt); |
| 19854 | analysisPercent(p, ovfl_cnt*100.0/(double)nentry); |
| 19855 | } |
| 19856 | if( int_pages>0 ){ |
| 19857 | analysisLine(p, "Index pages used", "%lld\n", int_pages); |
| 19858 | } |
| 19859 | analysisLine(p, "Primary pages used", "%lld\n", leaf_pages); |
| 19860 | if( ovfl_cnt ){ |
| 19861 | analysisLine(p, "Overflow pages used", "%lld\n", ovfl_pages); |
| 19862 | } |
| 19863 | analysisLine(p, "Total pages used", "%lld\n", total_pages); |
| 19864 | if( int_pages>0 ){ |
| 19865 | analysisLine(p, "Unused bytes on index pages", "%lld\n", int_unused); |
| 19866 | } |
| 19867 | analysisLine(p, "Unused bytes on primary pages", "%lld\n", leaf_unused); |
| 19868 | if( ovfl_cnt ){ |
| 19869 | analysisLine(p, "Unused bytes on overflow pages", "%lld\n", ovfl_unused); |
| 19870 | } |
| 19871 | analysisLine(p, "Unused bytes on all pages", "%-11lld ", total_unused); |
| 19872 | analysisPercent(p, total_unused*100.0/(double)storage); |
| 19873 | } |
| 19874 | return analysisStmtFinish(p, rc, pStmt); |
| 19875 | } |
| 19876 | |
| 19877 | /* |
| 19878 | ** SQL Function: analyze(SCHEMA) |
| 19879 | ** |
| 19880 | ** Analyze the database schema named in the argument. Return text |
| 19881 | ** containing the analysis. |
| 19882 | */ |
| 19883 | static void analyzeFunc( |
| 19884 | sqlite3_context *context, |
| 19885 | int argc, |
| 19886 | sqlite3_value **argv |
| 19887 | ){ |
| 19888 | int rc; |
| @@ -19893,47 +19949,47 @@ | |
| 19893 | sqlite3_int64 nPage; |
| 19894 | sqlite3_int64 nPageInUse; |
| 19895 | sqlite3_int64 nFreeList; |
| 19896 | sqlite3_int64 nIndex; |
| 19897 | sqlite3_int64 nWORowid; |
| 19898 | Analysis s; |
| 19899 | sqlite3_uint64 r[2]; |
| 19900 | |
| 19901 | (void)argc; |
| 19902 | memset(&s, 0, sizeof(s)); |
| 19903 | s.db = sqlite3_context_db_handle(context); |
| 19904 | s.context = context; |
| 19905 | s.pOut = sqlite3_str_new(0); |
| 19906 | if( sqlite3_str_errcode(s.pOut) ){ |
| 19907 | analysisError(&s, 0); |
| 19908 | return; |
| 19909 | } |
| 19910 | s.zSchema = (const char*)sqlite3_value_text(argv[0]); |
| 19911 | if( s.zSchema==0 ){ |
| 19912 | s.zSchema = "main"; |
| 19913 | }else if( sqlite3_strlike("temp",s.zSchema,0)==0 ){ |
| 19914 | analysisReset(&s); |
| 19915 | sqlite3_result_text(context, "cannot analyze \"temp\"",-1,SQLITE_STATIC); |
| 19916 | return; |
| 19917 | } |
| 19918 | ii = 0; |
| 19919 | rc = analysisSqlInt(&s,&ii,"SELECT 1 FROM pragma_database_list" |
| 19920 | " WHERE name=%Q COLLATE nocase",s.zSchema); |
| 19921 | if( rc || ii==0 ){ |
| 19922 | analysisReset(&s); |
| 19923 | sqlite3_result_text(context,"no such database",-1,SQLITE_STATIC); |
| 19924 | return; |
| 19925 | } |
| 19926 | sqlite3_randomness(sizeof(r), &r); |
| 19927 | s.zSU = sqlite3_mprintf("analysis%016llx%016llx", r[0], r[1]); |
| 19928 | if( s.zSU==0 ){ analysisError(&s, 0); return; } |
| 19929 | |
| 19930 | /* The s.zSU table contains the data used for the analysis. |
| 19931 | ** The table name contains 128-bits of randomness to avoid |
| 19932 | ** collisions with preexisting tables in temp. |
| 19933 | */ |
| 19934 | rc = analysisSql(&s, |
| 19935 | "CREATE TABLE temp.%s(\n" |
| 19936 | " name text, -- A table or index\n" |
| 19937 | " tblname text, -- Table that owns name\n" |
| 19938 | " is_index boolean, -- TRUE if it is an index\n" |
| 19939 | " is_without_rowid boolean, -- TRUE if WITHOUT ROWID table\n" |
| @@ -19956,11 +20012,11 @@ | |
| 19956 | ); |
| 19957 | if( rc ) return; |
| 19958 | |
| 19959 | /* Populate the s.zSU table |
| 19960 | */ |
| 19961 | rc = analysisSql(&s, |
| 19962 | "WITH\n" |
| 19963 | " allidx(idxname) AS (\n" |
| 19964 | " SELECT name FROM \"%w\".sqlite_schema WHERE type='index'\n" |
| 19965 | " ),\n" |
| 19966 | " allobj(allname,tblname,isidx,isworowid) AS (\n" |
| @@ -20008,141 +20064,143 @@ | |
| 20008 | s.zSchema /* JOIN dbstat(%Q) */ |
| 20009 | ); |
| 20010 | if( rc ) return; |
| 20011 | |
| 20012 | nPage = 0; |
| 20013 | rc = analysisSqlInt(&s, &nPage, "PRAGMA \"%w\".page_count", s.zSchema); |
| 20014 | if( rc ) return; |
| 20015 | if( nPage<=0 ){ |
| 20016 | /* Very brief reply for an empty database */ |
| 20017 | analysisReset(&s); |
| 20018 | sqlite3_result_text(context, "empty database", -1, SQLITE_STATIC); |
| 20019 | return; |
| 20020 | } |
| 20021 | |
| 20022 | /* Begin generating the report */ |
| 20023 | analysisTitle(&s, "Database storage utilization report"); |
| 20024 | pgsz = 0; |
| 20025 | rc = analysisSqlInt(&s, &pgsz, "PRAGMA \"%w\".page_size", s.zSchema); |
| 20026 | if( rc ) return; |
| 20027 | analysisLine(&s, "Page size in bytes","%lld\n",pgsz); |
| 20028 | analysisLine(&s, "Pages in the database", "%lld\n", nPage); |
| 20029 | |
| 20030 | nPageInUse = 0; |
| 20031 | rc = analysisSqlInt(&s, &nPageInUse, |
| 20032 | "SELECT sum(leaf_pages+int_pages+ovfl_pages) FROM temp.%s", s.zSU); |
| 20033 | if( rc ) return; |
| 20034 | analysisLine(&s, "Pages that store data", "%-11lld ", nPageInUse); |
| 20035 | analysisPercent(&s, (nPageInUse*100.0)/(double)nPage); |
| 20036 | |
| 20037 | nFreeList = 0; |
| 20038 | rc = analysisSqlInt(&s, &nFreeList, "PRAGMA \"%w\".freelist_count",s.zSchema); |
| 20039 | if( rc ) return; |
| 20040 | analysisLine(&s, "Pages on the freelist", "%-11lld ", nFreeList); |
| 20041 | analysisPercent(&s, (nFreeList*100.0)/(double)nPage); |
| 20042 | |
| 20043 | ii = 0; |
| 20044 | rc = analysisSqlInt(&s, &ii, "PRAGMA \"%w\".auto_vacuum", s.zSchema); |
| 20045 | if( rc ) return; |
| 20046 | if( ii==0 || nPage<=1 ){ |
| 20047 | ii = 0; |
| 20048 | }else{ |
| 20049 | double rPtrsPerPage = pgsz/5; |
| 20050 | double rAvPage = (nPage-1.0)/(rPtrsPerPage+1.0); |
| 20051 | ii = (sqlite3_int64)ceil(rAvPage); |
| 20052 | } |
| 20053 | analysisLine(&s, "Pages of auto-vacuum overhead", "%-11lld ", ii); |
| 20054 | analysisPercent(&s, (ii*100.0)/(double)nPage); |
| 20055 | |
| 20056 | ii = 0; |
| 20057 | rc = analysisSqlInt(&s, &ii, |
| 20058 | "SELECT count(*)+1 FROM \"%w\".sqlite_schema WHERE type='table'", |
| 20059 | s.zSchema); |
| 20060 | if( rc ) return; |
| 20061 | analysisLine(&s, "Number of tables", "%lld\n", ii); |
| 20062 | nWORowid = 0; |
| 20063 | rc = analysisSqlInt(&s, &nWORowid, |
| 20064 | "SELECT count(*) FROM \"%w\".pragma_table_list WHERE wr", |
| 20065 | s.zSchema); |
| 20066 | if( rc ) return; |
| 20067 | if( nWORowid>0 ){ |
| 20068 | analysisLine(&s, "Number of WITHOUT ROWID tables", "%lld\n", nWORowid); |
| 20069 | analysisLine(&s, "Number of rowid tables", "%lld\n", ii - nWORowid); |
| 20070 | } |
| 20071 | nIndex = 0; |
| 20072 | rc = analysisSqlInt(&s, &nIndex, |
| 20073 | "SELECT count(*) FROM \"%w\".sqlite_schema WHERE type='index'", |
| 20074 | s.zSchema); |
| 20075 | if( rc ) return; |
| 20076 | analysisLine(&s, "Number of indexes", "%lld\n", nIndex); |
| 20077 | ii = 0; |
| 20078 | rc = analysisSqlInt(&s, &ii, |
| 20079 | "SELECT count(*) FROM \"%w\".sqlite_schema" |
| 20080 | " WHERE name GLOB 'sqlite_autoindex_*' AND type='index'", |
| 20081 | s.zSchema); |
| 20082 | if( rc ) return; |
| 20083 | analysisLine(&s, "Number of defined indexes", "%lld\n", nIndex - ii); |
| 20084 | analysisLine(&s, "Number of implied indexes", "%lld\n", ii); |
| 20085 | analysisLine(&s, "Size of the database in bytes", "%lld\n", pgsz*nPage); |
| 20086 | ii = 0; |
| 20087 | rc = analysisSqlInt(&s, &ii, |
| 20088 | "SELECT sum(payload) FROM temp.%s" |
| 20089 | " WHERE NOT is_index AND name NOT LIKE 'sqlite_schema'", |
| 20090 | s.zSU); |
| 20091 | if( rc ) return; |
| 20092 | analysisLine(&s, "Bytes of payload", "%-11lld ", ii); |
| 20093 | analysisPercent(&s, ii*100.0/(double)(pgsz*nPage)); |
| 20094 | |
| 20095 | analysisTitle(&s, "Page counts for all tables with their indexes"); |
| 20096 | pStmt = analysisPrepare(&s, |
| 20097 | "SELECT upper(tblname),\n" |
| 20098 | " sum(int_pages+leaf_pages+ovfl_pages)\n" |
| 20099 | " FROM temp.%s\n" |
| 20100 | " GROUP BY 1\n" |
| 20101 | " ORDER BY 2 DESC, 1;", |
| 20102 | s.zSU); |
| 20103 | if( pStmt==0 ) return; |
| 20104 | while( (rc = sqlite3_step(pStmt))==SQLITE_ROW ){ |
| 20105 | sqlite3_int64 nn = sqlite3_column_int64(pStmt,1); |
| 20106 | analysisLine(&s, (const char*)sqlite3_column_text(pStmt,0), "%-11lld ", nn); |
| 20107 | analysisPercent(&s, (nn*100.0)/(double)nPage); |
| 20108 | } |
| 20109 | if( analysisStmtFinish(&s, rc, pStmt) ) return; |
| 20110 | |
| 20111 | analysisTitle(&s, "Page counts for all tables and indexes separately"); |
| 20112 | pStmt = analysisPrepare(&s, |
| 20113 | "SELECT upper(name),\n" |
| 20114 | " sum(int_pages+leaf_pages+ovfl_pages)\n" |
| 20115 | " FROM temp.%s\n" |
| 20116 | " GROUP BY 1\n" |
| 20117 | " ORDER BY 2 DESC, 1;", |
| 20118 | s.zSU); |
| 20119 | if( pStmt==0 ) return; |
| 20120 | while( (rc = sqlite3_step(pStmt))==SQLITE_ROW ){ |
| 20121 | sqlite3_int64 nn = sqlite3_column_int64(pStmt,1); |
| 20122 | analysisLine(&s, (const char*)sqlite3_column_text(pStmt,0), "%-11lld ", nn); |
| 20123 | analysisPercent(&s, (nn*100.0)/(double)nPage); |
| 20124 | } |
| 20125 | if( analysisStmtFinish(&s, rc, pStmt) ) return; |
| 20126 | |
| 20127 | rc = analysisSubreport(&s, "All tables and indexes", "1", pgsz, nPage); |
| 20128 | if( rc ) return; |
| 20129 | rc = analysisSubreport(&s, "All tables", "NOT is_index", pgsz, nPage); |
| 20130 | if( rc ) return; |
| 20131 | if( nWORowid>0 ){ |
| 20132 | rc = analysisSubreport(&s, "All WITHOUT ROWID tables", "is_without_rowid", |
| 20133 | pgsz, nPage); |
| 20134 | if( rc ) return; |
| 20135 | rc = analysisSubreport(&s, "All rowid tables", |
| 20136 | "NOT is_without_rowid AND NOT is_index", |
| 20137 | pgsz, nPage); |
| 20138 | if( rc ) return; |
| 20139 | } |
| 20140 | rc = analysisSubreport(&s, "All indexes", "is_index", pgsz, nPage); |
| 20141 | if( rc ) return; |
| 20142 | |
| 20143 | pStmt = analysisPrepare(&s, |
| 20144 | "SELECT upper(tblname), tblname, sum(is_index) FROM temp.%s" |
| 20145 | " GROUP BY 1 ORDER BY 1", |
| 20146 | s.zSU); |
| 20147 | if( pStmt==0 ) return; |
| 20148 | while( (rc = sqlite3_step(pStmt))==SQLITE_ROW ){ |
| @@ -20150,37 +20208,37 @@ | |
| 20150 | const char *zName = (const char*)sqlite3_column_text(pStmt, 1); |
| 20151 | int nSubIndex = sqlite3_column_int(pStmt, 2); |
| 20152 | if( nSubIndex==0 ){ |
| 20153 | char *zTitle = sqlite3_mprintf("Table %s", zUpper); |
| 20154 | char *zWhere = sqlite3_mprintf("name=%Q", zName); |
| 20155 | rc = analysisSubreport(&s, zTitle, zWhere, pgsz, nPage); |
| 20156 | sqlite3_free(zTitle); |
| 20157 | sqlite3_free(zWhere); |
| 20158 | if( rc ) break; |
| 20159 | }else{ |
| 20160 | sqlite3_stmt *pS2; |
| 20161 | char *zTitle = sqlite3_mprintf("Table %s and all its indexes", zUpper); |
| 20162 | char *zWhere = sqlite3_mprintf("tblname=%Q", zName); |
| 20163 | rc = analysisSubreport(&s, zTitle, zWhere, pgsz, nPage); |
| 20164 | sqlite3_free(zTitle); |
| 20165 | sqlite3_free(zWhere); |
| 20166 | if( rc ) break; |
| 20167 | zTitle = sqlite3_mprintf("Table %s w/o any indexes", zUpper); |
| 20168 | zWhere = sqlite3_mprintf("name=%Q", zName); |
| 20169 | rc = analysisSubreport(&s, zTitle, zWhere, pgsz, nPage); |
| 20170 | sqlite3_free(zTitle); |
| 20171 | sqlite3_free(zWhere); |
| 20172 | if( rc ) break; |
| 20173 | if( nSubIndex>1 ){ |
| 20174 | zTitle = sqlite3_mprintf("All indexes of table %s", zUpper); |
| 20175 | zWhere = sqlite3_mprintf("tblname=%Q AND is_index", zName); |
| 20176 | rc = analysisSubreport(&s, zTitle, zWhere, pgsz, nPage); |
| 20177 | sqlite3_free(zTitle); |
| 20178 | sqlite3_free(zWhere); |
| 20179 | if( rc ) break; |
| 20180 | } |
| 20181 | pS2 = analysisPrepare(&s, |
| 20182 | "SELECT name, upper(name) FROM temp.%s" |
| 20183 | " WHERE is_index AND tblname=%Q", |
| 20184 | s.zSU, zName); |
| 20185 | if( pS2==0 ){ |
| 20186 | rc = SQLITE_NOMEM; |
| @@ -20189,25 +20247,25 @@ | |
| 20189 | while( (rc = sqlite3_step(pS2))==SQLITE_ROW ){ |
| 20190 | const char *zU = (const char*)sqlite3_column_text(pS2, 1); |
| 20191 | const char *zN = (const char*)sqlite3_column_text(pS2, 0); |
| 20192 | zTitle = sqlite3_mprintf("Index %s", zU); |
| 20193 | zWhere = sqlite3_mprintf("name=%Q", zN); |
| 20194 | rc = analysisSubreport(&s, zTitle, zWhere, pgsz, nPage); |
| 20195 | sqlite3_free(zTitle); |
| 20196 | sqlite3_free(zWhere); |
| 20197 | if( rc ) break; |
| 20198 | } |
| 20199 | rc = analysisStmtFinish(&s, rc, pS2); |
| 20200 | if( rc ) break; |
| 20201 | } |
| 20202 | } |
| 20203 | if( analysisStmtFinish(&s, rc, pStmt) ) return; |
| 20204 | |
| 20205 | /* Append SQL statements that will recreate the raw data used for |
| 20206 | ** the analysis. |
| 20207 | */ |
| 20208 | analysisTitle(&s, "Raw data used to generate this report"); |
| 20209 | sqlite3_str_appendf(s.pOut, |
| 20210 | "The following SQL will create a table named \"space_used\" which\n" |
| 20211 | "contains most of the information used to generate the report above.\n" |
| 20212 | "*/\n" |
| 20213 | ); |
| @@ -20233,11 +20291,11 @@ | |
| 20233 | " ovfl_unused int, -- Unused bytes on overflow pages\n" /* 16 */ |
| 20234 | " int_entries int -- B-tree entries on internal pages\n"/* 17 */ |
| 20235 | ");\n" |
| 20236 | "INSERT INTO space_used VALUES\n" |
| 20237 | ); |
| 20238 | pStmt = analysisPrepare(&s, |
| 20239 | "SELECT quote(name), quote(tblname),\n" /* 0..1 */ |
| 20240 | " is_index, is_without_rowid, nentry, leaf_entries,\n" /* 2..5 */ |
| 20241 | " depth, payload, ovfl_payload, ovfl_cnt, mx_payload,\n" /* 6..10 */ |
| 20242 | " int_pages, leaf_pages, ovfl_pages, int_unused,\n" /* 11..14 */ |
| 20243 | " leaf_unused, ovfl_unused, int_entries\n" /* 15..17 */ |
| @@ -20268,11 +20326,11 @@ | |
| 20268 | sqlite3_column_int64(pStmt, 15), |
| 20269 | sqlite3_column_int64(pStmt, 16), |
| 20270 | sqlite3_column_int64(pStmt, 17)); |
| 20271 | } |
| 20272 | if( rc!=SQLITE_DONE ){ |
| 20273 | analysisError(&s, "SQL run-time error: %s\nSQL: %s", |
| 20274 | sqlite3_errmsg(s.db), sqlite3_sql(pStmt)); |
| 20275 | sqlite3_finalize(pStmt); |
| 20276 | return; |
| 20277 | } |
| 20278 | sqlite3_str_appendf(s.pOut,";\nCOMMIT;"); |
| @@ -20281,32 +20339,32 @@ | |
| 20281 | if( sqlite3_str_length(s.pOut) ){ |
| 20282 | sqlite3_result_text(context, sqlite3_str_finish(s.pOut), -1, |
| 20283 | sqlite3_free); |
| 20284 | s.pOut = 0; |
| 20285 | } |
| 20286 | analysisReset(&s); |
| 20287 | } |
| 20288 | |
| 20289 | |
| 20290 | #ifdef _WIN32 |
| 20291 | |
| 20292 | #endif |
| 20293 | int sqlite3_analyze_init( |
| 20294 | sqlite3 *db, |
| 20295 | char **pzErrMsg, |
| 20296 | const sqlite3_api_routines *pApi |
| 20297 | ){ |
| 20298 | int rc = SQLITE_OK; |
| 20299 | SQLITE_EXTENSION_INIT2(pApi); |
| 20300 | (void)pzErrMsg; /* Unused parameter */ |
| 20301 | rc = sqlite3_create_function(db, "analyze", 1, |
| 20302 | SQLITE_UTF8|SQLITE_INNOCUOUS, |
| 20303 | 0, analyzeFunc, 0, 0); |
| 20304 | return rc; |
| 20305 | } |
| 20306 | |
| 20307 | /************************* End ext/misc/analyze.c ********************/ |
| 20308 | |
| 20309 | #if !defined(SQLITE_OMIT_VIRTUALTABLE) && defined(SQLITE_ENABLE_DBPAGE_VTAB) |
| 20310 | #define SQLITE_SHELL_HAVE_RECOVER 1 |
| 20311 | #else |
| 20312 | #define SQLITE_SHELL_HAVE_RECOVER 0 |
| @@ -25138,11 +25196,11 @@ | |
| 25138 | /* |
| 25139 | ** Return true if either the SQLITE_NO_COLOR compile-time option is used |
| 25140 | ** or if the NO_COLOR environment variable exists |
| 25141 | */ |
| 25142 | static int shellNoColor(void){ |
| 25143 | #ifdef SQLITE_NO_COLOR |
| 25144 | return 1; |
| 25145 | #else |
| 25146 | return getenv("NO_COLOR")!=0; |
| 25147 | #endif |
| 25148 | } |
| @@ -25172,11 +25230,11 @@ | |
| 25172 | case 1: |
| 25173 | #if defined(SQLITE_PS1) |
| 25174 | return SQLITE_PS1; |
| 25175 | #else |
| 25176 | if( shellNoColor() ){ |
| 25177 | return "/A-/v /~> "; |
| 25178 | }else{ |
| 25179 | return "/e[1;32m/A-/v /e[1;/x33/:36/;m/m/e[3m/;/f/;/e[0m-> "; |
| 25180 | } |
| 25181 | #endif |
| 25182 | |
| @@ -25184,11 +25242,11 @@ | |
| 25184 | case 2: |
| 25185 | #if defined(SQLITE_PS2) |
| 25186 | return SQLITE_PS2; |
| 25187 | #else |
| 25188 | if( shellNoColor() ){ |
| 25189 | return "/B/C> "; |
| 25190 | }else{ |
| 25191 | return "/B/e[1;/x33/:36/;m/C/e[0m-> "; |
| 25192 | } |
| 25193 | #endif |
| 25194 | |
| @@ -25196,11 +25254,15 @@ | |
| 25196 | ** of cases 1 and 2 */ |
| 25197 | case 3: return "SQLITE_PS1"; |
| 25198 | case 4: return "SQLITE_PS2"; |
| 25199 | |
| 25200 | /* Name of the application */ |
| 25201 | case 'A': return "SQLite"; |
| 25202 | |
| 25203 | /* Full version number of the application, including patch level */ |
| 25204 | case 'V': return sqlite3_libversion(); |
| 25205 | |
| 25206 | /* Version number without the patch level */ |
| @@ -26303,10 +26365,47 @@ | |
| 26303 | if( *az ){ |
| 26304 | memcpy(*az, zNew, n+1 ); |
| 26305 | } |
| 26306 | } |
| 26307 | } |
| 26308 | |
| 26309 | /* |
| 26310 | ** Change the mode to eMode |
| 26311 | */ |
| 26312 | static void modeChange(ShellState *p, unsigned char eMode){ |
| @@ -26340,10 +26439,11 @@ | |
| 26340 | modeDup(&p->mode, &p->aSavedModes[eMode-MODE_USER].mode); |
| 26341 | }else if( eMode==MODE_BATCH ){ |
| 26342 | u8 mFlags = p->mode.mFlags; |
| 26343 | modeFree(&p->mode); |
| 26344 | modeChange(p, MODE_List); |
| 26345 | p->mode.mFlags = mFlags; |
| 26346 | }else if( eMode==MODE_TTY ){ |
| 26347 | u8 mFlags = p->mode.mFlags; |
| 26348 | modeFree(&p->mode); |
| 26349 | modeChange(p, MODE_QBox); |
| @@ -26976,11 +27076,11 @@ | |
| 26976 | return SQLITE_OK; |
| 26977 | } |
| 26978 | #endif |
| 26979 | |
| 26980 | /* |
| 26981 | ** Print a schema statement. This is helper routine to dump_callbac(). |
| 26982 | ** |
| 26983 | ** This routine converts some CREATE TABLE statements for shadow tables |
| 26984 | ** in FTS3/4/5 into CREATE TABLE IF NOT EXISTS statements. |
| 26985 | ** |
| 26986 | ** If the schema statement in z[] contains a start-of-comment and if |
| @@ -28428,12 +28528,12 @@ | |
| 28428 | ".databases List names and files of attached databases", |
| 28429 | ".dbconfig ?op? ?val? List or change sqlite3_db_config() options", |
| 28430 | #if SQLITE_SHELL_HAVE_RECOVER |
| 28431 | ".dbinfo ?DB? Show status information about the database", |
| 28432 | #endif |
| 28433 | ".dbstat ?SCHEMA? Report database space and size stats", |
| 28434 | ".dbtotxt Hex dump of the database file", |
| 28435 | ".dump ?OBJECTS? Render database content as SQL", |
| 28436 | " Options:", |
| 28437 | " --data-only Output only INSERT statements", |
| 28438 | " --newlines Allow unescaped newline characters in output", |
| 28439 | " --nosys Omit system tables (ex: \"sqlite_stat1\")", |
| @@ -28540,10 +28640,13 @@ | |
| 28540 | " --reset Reset the count for each input and interrupt", |
| 28541 | " --timeout S Halt after running for S seconds", |
| 28542 | #endif |
| 28543 | ".prompt MAIN CONTINUE Replace the standard prompts", |
| 28544 | " --hard-reset Unset SQLITE_PS1/2 and then --reset", |
| 28545 | " --reset Revert to default prompts", |
| 28546 | " --show Show the current prompt strings", |
| 28547 | " -- No more options. Subsequent args are prompts", |
| 28548 | #ifndef SQLITE_SHELL_FIDDLE |
| 28549 | ".quit Stop interpreting input stream, exit if primary.", |
| @@ -29440,11 +29543,11 @@ | |
| 29440 | sqlite3_base64_init(p->db, 0, 0); |
| 29441 | sqlite3_base85_init(p->db, 0, 0); |
| 29442 | sqlite3_regexp_init(p->db, 0, 0); |
| 29443 | sqlite3_ieee_init(p->db, 0, 0); |
| 29444 | sqlite3_series_init(p->db, 0, 0); |
| 29445 | sqlite3_analyze_init(p->db, 0, 0); |
| 29446 | #ifndef SQLITE_SHELL_FIDDLE |
| 29447 | sqlite3_fileio_init(p->db, 0, 0); |
| 29448 | sqlite3_completion_init(p->db, 0, 0); |
| 29449 | #endif |
| 29450 | #ifdef SQLITE_HAVE_ZLIB |
| @@ -31246,11 +31349,11 @@ | |
| 31246 | typedef struct ArCommand ArCommand; |
| 31247 | struct ArCommand { |
| 31248 | u8 eCmd; /* An AR_CMD_* value */ |
| 31249 | u8 bVerbose; /* True if --verbose */ |
| 31250 | u8 bZip; /* True if the archive is a ZIP */ |
| 31251 | u8 bDryRun; /* True if --dry-run */ |
| 31252 | u8 bAppend; /* True if --append */ |
| 31253 | u8 bGlob; /* True if --glob */ |
| 31254 | u8 fromCmdLine; /* Run from -A instead of .archive */ |
| 31255 | int nArg; /* Number of command arguments */ |
| 31256 | char *zSrcTable; /* "sqlar", "zipfile($file)" or "zip" */ |
| @@ -31308,10 +31411,11 @@ | |
| 31308 | #define AR_SWITCH_FILE 9 |
| 31309 | #define AR_SWITCH_DIRECTORY 10 |
| 31310 | #define AR_SWITCH_APPEND 11 |
| 31311 | #define AR_SWITCH_DRYRUN 12 |
| 31312 | #define AR_SWITCH_GLOB 13 |
| 31313 | |
| 31314 | static int arProcessSwitch(ArCommand *pAr, int eSwitch, const char *zArg){ |
| 31315 | switch( eSwitch ){ |
| 31316 | case AR_CMD_CREATE: |
| 31317 | case AR_CMD_EXTRACT: |
| @@ -31325,11 +31429,14 @@ | |
| 31325 | } |
| 31326 | pAr->eCmd = eSwitch; |
| 31327 | break; |
| 31328 | |
| 31329 | case AR_SWITCH_DRYRUN: |
| 31330 | pAr->bDryRun = 1; |
| 31331 | break; |
| 31332 | case AR_SWITCH_GLOB: |
| 31333 | pAr->bGlob = 1; |
| 31334 | break; |
| 31335 | case AR_SWITCH_VERBOSE: |
| @@ -31376,10 +31483,11 @@ | |
| 31376 | { "verbose", 'v', AR_SWITCH_VERBOSE, 0 }, |
| 31377 | { "file", 'f', AR_SWITCH_FILE, 1 }, |
| 31378 | { "append", 'a', AR_SWITCH_APPEND, 1 }, |
| 31379 | { "directory", 'C', AR_SWITCH_DIRECTORY, 1 }, |
| 31380 | { "dryrun", 'n', AR_SWITCH_DRYRUN, 0 }, |
| 31381 | { "glob", 'g', AR_SWITCH_GLOB, 0 }, |
| 31382 | }; |
| 31383 | int nSwitch = sizeof(aSwitch) / sizeof(struct ArSwitch); |
| 31384 | struct ArSwitch *pEnd = &aSwitch[nSwitch]; |
| 31385 | |
| @@ -31676,18 +31784,41 @@ | |
| 31676 | |
| 31677 | /* |
| 31678 | ** Implementation of .ar "eXtract" command. |
| 31679 | */ |
| 31680 | static int arExtractCommand(ArCommand *pAr){ |
| 31681 | const char *zSql1 = |
| 31682 | "WITH dest(dpath,dlen) AS (SELECT realpath($dir),length(realpath($dir)))\n" |
| 31683 | "SELECT ($dir || name),\n" |
| 31684 | " CASE WHEN $dryrun THEN 0\n" |
| 31685 | " ELSE writefile($dir||name, %s, mode, mtime) END\n" |
| 31686 | " FROM dest CROSS JOIN %s\n" |
| 31687 | " WHERE (%s)\n" |
| 31688 | " AND (data IS NULL OR $pass==0)\n" /* Dirs both passes */ |
| 31689 | " AND dpath=substr(realpath($dir||name),1,dlen)\n" /* No escapes */ |
| 31690 | " AND name NOT GLOB '*..[/\\]*'\n"; /* No /../ in paths */ |
| 31691 | |
| 31692 | const char *azExtraArg[] = { |
| 31693 | "sqlar_uncompress(data, sz)", |
| @@ -31714,39 +31845,48 @@ | |
| 31714 | } |
| 31715 | if( zDir==0 ) rc = SQLITE_NOMEM; |
| 31716 | } |
| 31717 | |
| 31718 | shellPreparePrintf(pAr->db, &rc, &pSql, zSql1, |
| 31719 | azExtraArg[pAr->bZip], pAr->zSrcTable, zWhere |
| 31720 | ); |
| 31721 | |
| 31722 | if( rc==SQLITE_OK ){ |
| 31723 | j = sqlite3_bind_parameter_index(pSql, "$dir"); |
| 31724 | sqlite3_bind_text(pSql, j, zDir, -1, SQLITE_STATIC); |
| 31725 | j = sqlite3_bind_parameter_index(pSql, "$dryrun"); |
| 31726 | sqlite3_bind_int(pSql, j, pAr->bDryRun); |
| 31727 | |
| 31728 | /* Run the SELECT statement twice |
| 31729 | ** (0) writefile() all files and directories |
| 31730 | ** (1) writefile() for directory again |
| 31731 | ** The second pass is so that the timestamps for extracted directories |
| 31732 | ** will be reset to the value in the archive, since populating them |
| 31733 | ** in the first pass will have changed the timestamp. */ |
| 31734 | for(i=0; i<2; i++){ |
| 31735 | j = sqlite3_bind_parameter_index(pSql, "$pass"); |
| 31736 | sqlite3_bind_int(pSql, j, i); |
| 31737 | if( pAr->bDryRun ){ |
| 31738 | cli_printf(pAr->out, "%s\n", sqlite3_sql(pSql)); |
| 31739 | if( pAr->bVerbose==0 ) break; |
| 31740 | } |
| 31741 | while( rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pSql) ){ |
| 31742 | if( i==0 && pAr->bVerbose ){ |
| 31743 | cli_printf(pAr->out, "%s\n", sqlite3_column_text(pSql, 0)); |
| 31744 | } |
| 31745 | } |
| 31746 | if( pAr->bDryRun ) break; |
| 31747 | shellReset(&rc, pSql); |
| 31748 | } |
| 31749 | shellFinalize(&rc, pSql); |
| 31750 | } |
| 31751 | |
| 31752 | sqlite3_free(zDir); |
| @@ -32257,11 +32397,11 @@ | |
| 32257 | ; |
| 32258 | static const char * const zCollectVar = "\ |
| 32259 | SELECT\ |
| 32260 | '('||x'0a'\ |
| 32261 | || group_concat(\ |
| 32262 | cname||' ANY',\ |
| 32263 | ','||iif((cpos-1)%4>0, ' ', x'0a'||' '))\ |
| 32264 | ||')' AS ColsSpec \ |
| 32265 | FROM (\ |
| 32266 | SELECT cpos, printf('\"%w\"',printf('%!.*s%s', nlen-chop,name,suff)) AS cname \ |
| 32267 | FROM ColNames ORDER BY cpos\ |
| @@ -33102,30 +33242,14 @@ | |
| 33102 | }else if( optionMatch(z,"limits") ){ |
| 33103 | if( (++i)>=nArg ){ |
| 33104 | dotCmdError(p, i-1, "missing argument", 0); |
| 33105 | return 1; |
| 33106 | } |
| 33107 | k = pickStr(azArg[i],0,"on","off",""); |
| 33108 | if( k==0 ){ |
| 33109 | p->mode.spec.nLineLimit = DFLT_LINE_LIMIT; |
| 33110 | p->mode.spec.nCharLimit = DFLT_CHAR_LIMIT; |
| 33111 | p->mode.spec.nTitleLimit = DFLT_TITLE_LIMIT; |
| 33112 | }else if( k==1 ){ |
| 33113 | p->mode.spec.nLineLimit = 0; |
| 33114 | p->mode.spec.nCharLimit = 0; |
| 33115 | p->mode.spec.nTitleLimit = 0; |
| 33116 | }else{ |
| 33117 | int L, C, T = 0; |
| 33118 | int nNum = sscanf(azArg[i], "%d,%d,%d", &L, &C, &T); |
| 33119 | if( nNum<2 || L<0 || C<0 || T<0){ |
| 33120 | dotCmdError(p, i, "bad argument", "Should be \"L,C,T\" where L, C" |
| 33121 | " and T are unsigned integers"); |
| 33122 | return 1; |
| 33123 | } |
| 33124 | p->mode.spec.nLineLimit = L; |
| 33125 | p->mode.spec.nCharLimit = C; |
| 33126 | if( nNum==3 ) p->mode.spec.nTitleLimit = T; |
| 33127 | } |
| 33128 | chng = 1; |
| 33129 | }else if( optionMatch(z,"list") ){ |
| 33130 | int ii; |
| 33131 | cli_puts("available modes:", p->out); |
| @@ -34339,11 +34463,16 @@ | |
| 34339 | if( c=='d' && n>=3 && cli_strncmp(azArg[0], "dbinfo", n)==0 ){ |
| 34340 | rc = shell_dbinfo_command(p, nArg, azArg); |
| 34341 | }else |
| 34342 | #endif /* SQLITE_SHELL_HAVE_RECOVER */ |
| 34343 | |
| 34344 | if( c=='d' && n==6 && cli_strncmp(azArg[0], "dbstat", n)==0 ){ |
| 34345 | const char *zSchema = 0; |
| 34346 | int ii; |
| 34347 | char *zSql; |
| 34348 | open_db(p, 0); |
| 34349 | for(ii=1; ii<nArg; ii++){ |
| @@ -34358,27 +34487,19 @@ | |
| 34358 | rc = 1; |
| 34359 | goto meta_command_exit; |
| 34360 | } |
| 34361 | zSchema = z; |
| 34362 | } |
| 34363 | zSql = sqlite3_mprintf("SELECT analyze(%Q)", zSchema); |
| 34364 | shell_check_oom(zSql); |
| 34365 | modePush(p); |
| 34366 | modeChange(p, MODE_BATCH); |
| 34367 | p->mode.spec.nLineLimit = 0; |
| 34368 | p->mode.spec.nCharLimit = 0; |
| 34369 | p->mode.spec.nTitleLimit = 0; |
| 34370 | shell_exec(p, zSql, 0); |
| 34371 | modePop(p); |
| 34372 | sqlite3_free(zSql); |
| 34373 | }else |
| 34374 | |
| 34375 | if( c=='d' && n>=3 && cli_strncmp(azArg[0], "dbtotxt", n)==0 ){ |
| 34376 | open_db(p, 0); |
| 34377 | rc = shell_dbtotxt_command(p, nArg, azArg); |
| 34378 | }else |
| 34379 | |
| 34380 | if( c=='d' && cli_strncmp(azArg[0], "dump", n)==0 ){ |
| 34381 | char *zLike = 0; |
| 34382 | char *zSql; |
| 34383 | int i; |
| 34384 | int savedShellFlags = p->shellFlgs; |
| @@ -35491,10 +35612,26 @@ | |
| 35491 | }else |
| 35492 | if( strcmp(z,"-show")==0 ){ |
| 35493 | cli_printf(stdout,"Main prompt: '%s'\n", prompt_string(p, 0)); |
| 35494 | cli_printf(stdout,"Continuation: '%s'\n", prompt_string(p, 1)); |
| 35495 | }else |
| 35496 | if( strcmp(z,"-")==0 ){ |
| 35497 | noOpt = 1; |
| 35498 | }else |
| 35499 | { |
| 35500 | dotCmdError(p, i, "unknown option", 0); |
| @@ -35505,10 +35642,11 @@ | |
| 35505 | dotCmdError(p, i, "extra argument", 0); |
| 35506 | rc = 1; |
| 35507 | goto meta_command_exit; |
| 35508 | }else if( !p->dot.abQuot[i] && sqlite3_strglob("*[^a-z]*",z)!=0 ){ |
| 35509 | dotCmdError(p, i, "use quotes around the prompt string", 0); |
| 35510 | }else{ |
| 35511 | free(p->azPrompt[cnt]); |
| 35512 | p->azPrompt[cnt] = strdup(z); |
| 35513 | cnt++; |
| 35514 | } |
| @@ -37717,17 +37855,17 @@ | |
| 37717 | " -- treat no subsequent arguments as options\n" |
| 37718 | #if defined(SQLITE_HAVE_ZLIB) && !defined(SQLITE_OMIT_VIRTUALTABLE) |
| 37719 | " -A ARGS... run \".archive ARGS\" and exit\n" |
| 37720 | #endif |
| 37721 | " -append append the database to the end of the file\n" |
| 37722 | " -ascii set output mode to 'ascii'\n" |
| 37723 | " -bail stop after hitting an error\n" |
| 37724 | " -batch force batch I/O\n" |
| 37725 | " -box set output mode to 'box'\n" |
| 37726 | " -cmd COMMAND run \"COMMAND\" before reading stdin\n" |
| 37727 | " -column set output mode to 'column'\n" |
| 37728 | " -csv set output mode to 'csv'\n" |
| 37729 | #if !defined(SQLITE_OMIT_DESERIALIZE) |
| 37730 | " -deserialize open the database using sqlite3_deserialize()\n" |
| 37731 | #endif |
| 37732 | " -echo print inputs before execution\n" |
| 37733 | " -escape T ctrl-char escape; T is one of: symbol, ascii, off\n" |
| @@ -37735,18 +37873,18 @@ | |
| 37735 | " -[no]header turn headers on or off\n" |
| 37736 | #if defined(SQLITE_ENABLE_MEMSYS3) || defined(SQLITE_ENABLE_MEMSYS5) |
| 37737 | " -heap SIZE Size of heap for memsys3 or memsys5\n" |
| 37738 | #endif |
| 37739 | " -help show this message\n" |
| 37740 | " -html set output mode to HTML\n" |
| 37741 | " -ifexists only open if database already exists\n" |
| 37742 | " -interactive force interactive I/O\n" |
| 37743 | " -json set output mode to 'json'\n" |
| 37744 | " -line set output mode to 'line'\n" |
| 37745 | " -list set output mode to 'list'\n" |
| 37746 | " -lookaside SIZE N use N entries of SZ bytes for lookaside memory\n" |
| 37747 | " -markdown set output mode to 'markdown'\n" |
| 37748 | #if !defined(SQLITE_OMIT_DESERIALIZE) |
| 37749 | " -maxsize N maximum size for a --deserialize database\n" |
| 37750 | #endif |
| 37751 | " -memtrace trace all memory allocations and deallocations\n" |
| 37752 | " -mmap N default mmap size set to N\n" |
| @@ -37759,21 +37897,21 @@ | |
| 37759 | " -nonce STRING set the safe-mode escape nonce\n" |
| 37760 | " -no-rowid-in-view Disable rowid-in-view using sqlite3_config()\n" |
| 37761 | " -nullvalue TEXT set text string for NULL values. Default ''\n" |
| 37762 | " -pagecache SIZE N use N slots of SZ bytes each for page cache memory\n" |
| 37763 | " -pcachetrace trace all page cache operations\n" |
| 37764 | " -quote set output mode to 'quote'\n" |
| 37765 | " -readonly open the database read-only\n" |
| 37766 | " -safe enable safe-mode\n" |
| 37767 | " -screenwidth N use N as the default screenwidth \n" |
| 37768 | " -separator SEP set output column separator. Default: '|'\n" |
| 37769 | #ifdef SQLITE_ENABLE_SORTER_REFERENCES |
| 37770 | " -sorterref SIZE sorter references threshold size\n" |
| 37771 | #endif |
| 37772 | " -stats print memory stats before each finalize\n" |
| 37773 | " -table set output mode to 'table'\n" |
| 37774 | " -tabs set output mode to 'tabs'\n" |
| 37775 | " -unsafe-testing allow unsafe commands and modes for testing\n" |
| 37776 | " -version show SQLite version\n" |
| 37777 | " -vfs NAME use NAME as the default VFS\n" |
| 37778 | " -vfstrace enable tracing of all VFS calls\n" |
| 37779 | #ifdef SQLITE_HAVE_ZLIB |
| @@ -37801,10 +37939,23 @@ | |
| 37801 | sputz(stdout, "WARNING: attempt to configure SQLite after" |
| 37802 | " initialization.\n"); |
| 37803 | } |
| 37804 | } |
| 37805 | |
| 37806 | /* |
| 37807 | ** Initialize the state information in data |
| 37808 | */ |
| 37809 | static void main_init(ShellState *p) { |
| 37810 | memset(p, 0, sizeof(*p)); |
| @@ -37825,10 +37976,14 @@ | |
| 37825 | #else |
| 37826 | /* No \001...\002 escapes required for linenoise or when not using a |
| 37827 | ** command-line editing library */ |
| 37828 | p->bDelimitNonprint = 0; |
| 37829 | #endif |
| 37830 | } |
| 37831 | |
| 37832 | /* |
| 37833 | ** Output text to the console in a font that attracts extra attention. |
| 37834 | */ |
| @@ -37854,11 +38009,11 @@ | |
| 37854 | } |
| 37855 | |
| 37856 | /* |
| 37857 | ** The callback from atexit(). |
| 37858 | */ |
| 37859 | static void abnormalExit(void){ |
| 37860 | if( seenInterrupt ) eputz("Program interrupted.\n"); |
| 37861 | if( globalShellState ){ |
| 37862 | clearTempFile(globalShellState, 1, 1); |
| 37863 | } |
| 37864 | } |
| @@ -38065,11 +38220,11 @@ | |
| 38065 | stdin_is_interactive = 0; |
| 38066 | nCmd++; |
| 38067 | azCmd = realloc(azCmd, sizeof(azCmd[0])*nCmd); |
| 38068 | shell_check_oom(azCmd); |
| 38069 | aiCmd = realloc(aiCmd, sizeof(aiCmd[0])*nCmd); |
| 38070 | shell_check_oom(azCmd); |
| 38071 | azCmd[nCmd-1] = z; |
| 38072 | aiCmd[nCmd-1] = i; |
| 38073 | } |
| 38074 | continue; |
| 38075 | } |
| @@ -38354,10 +38509,11 @@ | |
| 38354 | modeChange(&data, MODE_Psql); |
| 38355 | }else if( cli_strcmp(z,"-box")==0 ){ |
| 38356 | modeChange(&data, MODE_Box); |
| 38357 | }else if( cli_strcmp(z,"-csv")==0 ){ |
| 38358 | modeChange(&data, MODE_Csv); |
| 38359 | }else if( cli_strcmp(z,"-escape")==0 && i+1<argc ){ |
| 38360 | /* See similar code at tag-20250224-1 */ |
| 38361 | const char *zEsc = argv[++i]; |
| 38362 | int k; |
| 38363 | for(k=0; k<ArraySize(qrfEscNames); k++){ |
| @@ -38412,12 +38568,14 @@ | |
| 38412 | }else if( cli_strcmp(z,"-nullvalue")==0 ){ |
| 38413 | modeSetStr(&data.mode.spec.zNull, |
| 38414 | cmdline_option_value(argc,argv,++i)); |
| 38415 | }else if( cli_strcmp(z,"-header")==0 ){ |
| 38416 | data.mode.spec.bTitles = QRF_Yes; |
| 38417 | }else if( cli_strcmp(z,"-noheader")==0 ){ |
| 38418 | data.mode.spec.bTitles = QRF_No; |
| 38419 | }else if( cli_strcmp(z,"-echo")==0 ){ |
| 38420 | data.mode.mFlags |= MFLG_ECHO; |
| 38421 | }else if( cli_strcmp(z,"-eqp")==0 ){ |
| 38422 | data.mode.autoEQP = AUTOEQP_on; |
| 38423 | }else if( cli_strcmp(z,"-eqpfull")==0 ){ |
| 38424 |
| --- extsrc/shell.c | |
| +++ extsrc/shell.c | |
| @@ -5,16 +5,16 @@ | |
| 5 | ** |
| 6 | ** ext/expert/sqlite3expert.c |
| 7 | ** ext/expert/sqlite3expert.h |
| 8 | ** ext/intck/sqlite3intck.c |
| 9 | ** ext/intck/sqlite3intck.h |
| 10 | ** ext/misc/appendvfs.c |
| 11 | ** ext/misc/base64.c |
| 12 | ** ext/misc/base85.c |
| 13 | ** ext/misc/completion.c |
| 14 | ** ext/misc/decimal.c |
| 15 | ** ext/misc/diskused.c |
| 16 | ** ext/misc/fileio.c |
| 17 | ** ext/misc/ieee754.c |
| 18 | ** ext/misc/memtrace.c |
| 19 | ** ext/misc/pcachetrace.c |
| 20 | ** ext/misc/regexp.c |
| @@ -154,10 +154,11 @@ | |
| 154 | #include <string.h> |
| 155 | #include <stdio.h> |
| 156 | #include <assert.h> |
| 157 | #include <math.h> |
| 158 | #include <stdint.h> |
| 159 | #include <time.h> |
| 160 | #include "sqlite3.h" |
| 161 | typedef sqlite3_int64 i64; |
| 162 | typedef sqlite3_uint64 u64; |
| 163 | typedef unsigned char u8; |
| 164 | #include <ctype.h> |
| @@ -190,13 +191,14 @@ | |
| 191 | #include <sys/stat.h> |
| 192 | |
| 193 | #if HAVE_READLINE |
| 194 | # include <readline/readline.h> |
| 195 | # include <readline/history.h> |
| 196 | #elif HAVE_EDITLINE |
| 197 | /* If both HAVE_READLINE and HAVE_EDITLINE are true, assume that this |
| 198 | ** libedit installation does not have its own headers, instead using |
| 199 | ** those from libreadline. */ |
| 200 | # include <editline/readline.h> |
| 201 | #endif |
| 202 | |
| 203 | #if HAVE_EDITLINE || HAVE_READLINE |
| 204 | |
| @@ -744,12 +746,11 @@ | |
| 746 | const sqlite3_qrf_spec *pSpec, /* Result format specification */ |
| 747 | char **pzErr /* OUT: Write error message here */ |
| 748 | ); |
| 749 | |
| 750 | /* |
| 751 | ** Range of values for sqlite3_qrf_spec.aWidth[] entries. |
| 752 | */ |
| 753 | #define QRF_MAX_WIDTH 10000 |
| 754 | #define QRF_MIN_WIDTH 0 |
| 755 | |
| 756 | /* |
| @@ -1129,10 +1130,14 @@ | |
| 1130 | sqlite3_str_append(pOut, "-", 1); |
| 1131 | } |
| 1132 | if( N<10000 ){ |
| 1133 | sqlite3_str_appendf(pOut, "%4lld ", N); |
| 1134 | return; |
| 1135 | } |
| 1136 | if( N>=9223372036854775800LL ){ |
| 1137 | sqlite3_str_appendf(pOut, "%.2fE", 1e-18*(double)N); |
| 1138 | return; |
| 1139 | } |
| 1140 | for(i=1; i<=18; i++){ |
| 1141 | N = (N+5)/10; |
| 1142 | if( N<10000 ){ |
| 1143 | int n = (int)N; |
| @@ -1289,12 +1294,12 @@ | |
| 1294 | if( nCycle>=0 || nLoop>=0 || nRow>=0 ){ |
| 1295 | int nSp = 0; |
| 1296 | sqlite3_str_reset(pStats); |
| 1297 | if( nCycle>=0 && nTotal>0 ){ |
| 1298 | qrfApproxInt64(pStats, nCycle); |
| 1299 | sqlite3_str_appendf(pStats, " %3.0f%%", |
| 1300 | ((100.0*(double)nCycle)+nTotal/2.0) / (double)nTotal |
| 1301 | ); |
| 1302 | nSp = 2; |
| 1303 | } |
| 1304 | if( nLoop>=0 ){ |
| 1305 | if( nSp ) sqlite3_str_appendchar(pStats, nSp, ' '); |
| @@ -1787,11 +1792,11 @@ | |
| 1792 | } |
| 1793 | if( i>0 ){ |
| 1794 | sqlite3_str_append(pOut, (const char*)z, i); |
| 1795 | } |
| 1796 | switch( z[i] ){ |
| 1797 | case '>': sqlite3_str_append(pOut, ">", 4); break; |
| 1798 | case '&': sqlite3_str_append(pOut, "&", 5); break; |
| 1799 | case '<': sqlite3_str_append(pOut, "<", 4); break; |
| 1800 | case '"': sqlite3_str_append(pOut, """, 6); break; |
| 1801 | case '\'': sqlite3_str_append(pOut, "'", 5); break; |
| 1802 | default: i--; |
| @@ -2281,11 +2286,11 @@ | |
| 2286 | if( bWrap && z[i]!=0 && !qrfSpace(z[i]) && qrfAlnum(c)==qrfAlnum(z[i]) ){ |
| 2287 | /* Perhaps try to back up to a better place to break the line */ |
| 2288 | for(k=i-1; k>=i/2; k--){ |
| 2289 | if( qrfSpace(z[k]) ) break; |
| 2290 | } |
| 2291 | if( k<i/2 && i/2>0 ){ |
| 2292 | for(k=i; k>=i/2; k--){ |
| 2293 | if( qrfAlnum(z[k-1])!=qrfAlnum(z[k]) && (z[k]&0xc0)!=0x80 ) break; |
| 2294 | } |
| 2295 | } |
| 2296 | if( k>=i/2 ){ |
| @@ -2532,16 +2537,16 @@ | |
| 2537 | const char *azDash[2] = { |
| 2538 | BOX_24 BOX_24 BOX_24 BOX_24 BOX_24 BOX_24 BOX_24 BOX_24 BOX_24 BOX_24, |
| 2539 | DBL_24 DBL_24 DBL_24 DBL_24 DBL_24 DBL_24 DBL_24 DBL_24 DBL_24 DBL_24 |
| 2540 | };/* 0 1 2 3 4 5 6 7 8 9 */ |
| 2541 | const int nDash = 30; |
| 2542 | i64 nn = 3*(i64)N; |
| 2543 | while( nn>nDash ){ |
| 2544 | sqlite3_str_append(pOut, azDash[bDbl], nDash); |
| 2545 | nn -= nDash; |
| 2546 | } |
| 2547 | sqlite3_str_append(pOut, azDash[bDbl], (int)nn); |
| 2548 | } |
| 2549 | |
| 2550 | /* |
| 2551 | ** Draw a horizontal separator for a QRF_STYLE_Box table. |
| 2552 | */ |
| @@ -2610,11 +2615,11 @@ | |
| 2615 | int nSW /* Screen width */ |
| 2616 | ){ |
| 2617 | int i; /* Loop counter */ |
| 2618 | int nr; /* Number of rows */ |
| 2619 | int w = 0; /* Width of the current column */ |
| 2620 | i64 t; /* Total width of all columns */ |
| 2621 | int *aw; /* Array of individual column widths */ |
| 2622 | |
| 2623 | aw = sqlite3_malloc64( sizeof(int)*nCol ); |
| 2624 | if( aw==0 ){ |
| 2625 | qrfOom(p); |
| @@ -2748,12 +2753,15 @@ | |
| 2753 | }else{ |
| 2754 | sepW = pData->nCol*3 + 1; |
| 2755 | if( p->spec.bBorder==QRF_No ) sepW -= 2; |
| 2756 | } |
| 2757 | nCol = pData->nCol; |
| 2758 | for(i=0, sumW=0; i<nCol; i++){ |
| 2759 | if( sumW > 2147483647 - pData->a[i].w ) return; |
| 2760 | sumW += pData->a[i].w; |
| 2761 | } |
| 2762 | if( p->spec.nScreenWidth >= (i64)sumW + sepW ) return; |
| 2763 | |
| 2764 | /* First thing to do is reduce the separation between columns */ |
| 2765 | pData->nMargin = 0; |
| 2766 | if( p->spec.eStyle==QRF_STYLE_Column ){ |
| 2767 | sepW = pData->nCol - 1; |
| @@ -3624,11 +3632,11 @@ | |
| 3632 | p->nRow = 0; |
| 3633 | sz = sizeof(sqlite3_qrf_spec); |
| 3634 | memcpy(&p->spec, pSpec, sz); |
| 3635 | if( p->spec.zNull==0 ) p->spec.zNull = ""; |
| 3636 | p->mxWidth = p->spec.nScreenWidth; |
| 3637 | if( p->mxWidth<=0 ) p->mxWidth = 2147483647; |
| 3638 | p->mxHeight = p->spec.nLineLimit; |
| 3639 | if( p->mxHeight<=0 ) p->mxHeight = 2147483647; |
| 3640 | if( p->spec.eStyle>QRF_STYLE_Table ) p->spec.eStyle = QRF_Auto; |
| 3641 | if( p->spec.eEsc>QRF_ESC_Symbol ) p->spec.eEsc = QRF_Auto; |
| 3642 | if( p->spec.eText>QRF_TEXT_Relaxed ) p->spec.eText = QRF_Auto; |
| @@ -5272,10 +5280,14 @@ | |
| 5280 | #include <stdarg.h> |
| 5281 | |
| 5282 | /****************************************************************************** |
| 5283 | ** The Hash Engine |
| 5284 | */ |
| 5285 | #if defined(__GNUC__) && __GNUC__>=11 |
| 5286 | # pragma GCC diagnostic push |
| 5287 | # pragma GCC diagnostic ignored "-Wstringop-overread" |
| 5288 | #endif |
| 5289 | /* Context for the SHA1 hash */ |
| 5290 | typedef struct SHA1Context SHA1Context; |
| 5291 | struct SHA1Context { |
| 5292 | unsigned int state[5]; |
| 5293 | unsigned int count[2]; |
| @@ -5412,11 +5424,11 @@ | |
| 5424 | } |
| 5425 | j = 0; |
| 5426 | }else{ |
| 5427 | i = 0; |
| 5428 | } |
| 5429 | if( len-i>0 ) (void)memcpy(&p->buffer[j], &data[i], len - i); |
| 5430 | } |
| 5431 | |
| 5432 | /* Compute a string using sqlite3_vsnprintf() and hash it */ |
| 5433 | static void hash_step_vformat( |
| 5434 | SHA1Context *p, /* Add content to this context */ |
| @@ -5467,10 +5479,13 @@ | |
| 5479 | zOut[i*2+1] = zEncode[digest[i] & 0xf]; |
| 5480 | } |
| 5481 | zOut[i*2]= 0; |
| 5482 | } |
| 5483 | } |
| 5484 | #if defined(__GNUC__) && __GNUC__>=11 |
| 5485 | # pragma GCC diagnostic pop |
| 5486 | #endif |
| 5487 | /* End of the hashing logic |
| 5488 | *****************************************************************************/ |
| 5489 | |
| 5490 | /* |
| 5491 | ** Two SQL functions: sha1(X) and sha1b(X). |
| @@ -6056,32 +6071,41 @@ | |
| 6071 | } |
| 6072 | z[i] = 0; |
| 6073 | sqlite3_result_text(pCtx, z, i, sqlite3_free); |
| 6074 | } |
| 6075 | |
| 6076 | /* Forward declaration */ |
| 6077 | static void decimal_expand(Decimal *p, int nDigit, int nFrac); |
| 6078 | |
| 6079 | /* |
| 6080 | ** Round a decimal value to N significant digits. N must be positive. |
| 6081 | */ |
| 6082 | static void decimal_round(Decimal *p, int N){ |
| 6083 | int i; |
| 6084 | int nZero; /* Number of leading zeros */ |
| 6085 | if( N<1 ) return; |
| 6086 | if( p==0 ) return; |
| 6087 | if( p->nDigit<=N ) return; |
| 6088 | for(nZero=0; nZero<p->nDigit && p->a[nZero]==0; nZero++){} |
| 6089 | N += nZero; |
| 6090 | if( p->nDigit<=N ) return; |
| 6091 | if( p->a[N]>=5 ){ |
| 6092 | /* If all leading digits are 9, increase the number of digits |
| 6093 | ** by adding a new 0 to the front */ |
| 6094 | for(i=0; i<N && p->a[i]==9; i++){} |
| 6095 | if( i==N ){ |
| 6096 | decimal_expand(p, p->nDigit+1, 0); |
| 6097 | if( p->oom ) return; |
| 6098 | } |
| 6099 | |
| 6100 | /* Do the rounding */ |
| 6101 | p->a[N-1]++; |
| 6102 | for(i=N-1; i>0 && p->a[i]>9; i--){ |
| 6103 | p->a[i] = 0; |
| 6104 | p->a[i-1]++; |
| 6105 | } |
| 6106 | assert( p->a[0]<=9 ); |
| 6107 | } |
| 6108 | memset(&p->a[N], 0, p->nDigit - N); |
| 6109 | } |
| 6110 | |
| 6111 | /* |
| @@ -8363,19 +8387,26 @@ | |
| 8387 | } |
| 8388 | }else{ |
| 8389 | iMin = iMax = sqlite3_value_int64(argv[iArg++]); |
| 8390 | } |
| 8391 | }else{ |
| 8392 | if( idxNum & 0x0300 ){ /* value>X (0x200) or value>=X (0x100) */ |
| 8393 | if( sqlite3_value_numeric_type(argv[iArg])==SQLITE_FLOAT ){ |
| 8394 | double r = sqlite3_value_double(argv[iArg++]); |
| 8395 | if( r<=(double)SMALLEST_INT64 ){ |
| 8396 | iMin = SMALLEST_INT64; |
| 8397 | }else if( r>(double)LARGEST_INT64 ){ |
| 8398 | goto series_no_rows; |
| 8399 | }else{ |
| 8400 | iMin = (sqlite3_int64)seriesCeil(r); |
| 8401 | if( iMin<0 && r>0.0 ){ |
| 8402 | iMin = LARGEST_INT64; |
| 8403 | } |
| 8404 | if( (idxNum & 0x0200)!=0 && r==seriesCeil(r) ){ |
| 8405 | if( iMin==LARGEST_INT64 ) goto series_no_rows; |
| 8406 | iMin++; |
| 8407 | } |
| 8408 | } |
| 8409 | }else{ |
| 8410 | iMin = sqlite3_value_int64(argv[iArg++]); |
| 8411 | if( (idxNum & 0x0200)!=0 ){ |
| 8412 | if( iMin==LARGEST_INT64 ){ |
| @@ -8384,19 +8415,25 @@ | |
| 8415 | iMin++; |
| 8416 | } |
| 8417 | } |
| 8418 | } |
| 8419 | } |
| 8420 | if( idxNum & 0x3000 ){ /* value<X (0x2000) or value<=X (0x1000) */ |
| 8421 | if( sqlite3_value_numeric_type(argv[iArg])==SQLITE_FLOAT ){ |
| 8422 | double r = sqlite3_value_double(argv[iArg++]); |
| 8423 | if( r>=(double)LARGEST_INT64 ){ |
| 8424 | iMax = LARGEST_INT64; |
| 8425 | }else if( r<=(double)SMALLEST_INT64 ){ |
| 8426 | goto series_no_rows; |
| 8427 | }else{ |
| 8428 | iMax = (sqlite3_int64)seriesFloor(r); |
| 8429 | if( iMax<0 && r>0.0 ){ |
| 8430 | iMax = LARGEST_INT64; |
| 8431 | }else if( (idxNum & 0x2000)!=0 && r==seriesFloor(r) ){ |
| 8432 | if( iMax==SMALLEST_INT64 ) goto series_no_rows; |
| 8433 | iMax--; |
| 8434 | } |
| 8435 | } |
| 8436 | }else{ |
| 8437 | iMax = sqlite3_value_int64(argv[iArg++]); |
| 8438 | if( idxNum & 0x2000 ){ |
| 8439 | if( iMax==SMALLEST_INT64 ){ |
| @@ -9638,11 +9675,10 @@ | |
| 9675 | if( pRe==0 ){ |
| 9676 | sqlite3_result_error_nomem(context); |
| 9677 | return; |
| 9678 | } |
| 9679 | pStr = sqlite3_str_new(0); |
| 9680 | if( pRe->nInit>0 ){ |
| 9681 | sqlite3_str_appendf(pStr, "INIT "); |
| 9682 | for(i=0; i<pRe->nInit; i++){ |
| 9683 | sqlite3_str_appendf(pStr, "%02x", pRe->zInit[i]); |
| 9684 | } |
| @@ -9649,20 +9685,20 @@ | |
| 9685 | sqlite3_str_appendf(pStr, "\n"); |
| 9686 | } |
| 9687 | for(i=0; (unsigned)i<pRe->nState; i++){ |
| 9688 | sqlite3_str_appendf(pStr, "%-8s %4d\n", |
| 9689 | ReOpName[(unsigned char)pRe->aOp[i]], pRe->aArg[i]); |
| 9690 | } |
| 9691 | if( sqlite3_str_errcode(pStr)==SQLITE_NOMEM ){ |
| 9692 | sqlite3_str_finish(pStr); |
| 9693 | re_free(pRe); |
| 9694 | sqlite3_result_error_nomem(context); |
| 9695 | return; |
| 9696 | } |
| 9697 | n = sqlite3_str_length(pStr); |
| 9698 | z = sqlite3_str_finish(pStr); |
| 9699 | sqlite3_result_text(context, z, n-1, sqlite3_free); |
| 9700 | re_free(pRe); |
| 9701 | } |
| 9702 | |
| 9703 | #endif /* SQLITE_DEBUG */ |
| 9704 | |
| @@ -10870,10 +10906,13 @@ | |
| 10906 | ** Return NULL if unable. |
| 10907 | ** |
| 10908 | ** The file or directory X is not required to exist. The answer is formed |
| 10909 | ** by calling system realpath() on the prefix of X that does exist and |
| 10910 | ** appending the tail of X that does not (yet) exist. |
| 10911 | ** |
| 10912 | ** FIXME: This routine sometimes returns NULL rather than raising |
| 10913 | ** an SQLITE_NOMEM error if an OOM is encountered. |
| 10914 | */ |
| 10915 | static void realpathFunc( |
| 10916 | sqlite3_context *context, |
| 10917 | int argc, |
| 10918 | sqlite3_value **argv |
| @@ -10892,10 +10931,11 @@ | |
| 10931 | (void)argc; |
| 10932 | zPath = (const char*)sqlite3_value_text(argv[0]); |
| 10933 | if( zPath==0 ) return; |
| 10934 | if( zPath[0]==0 ) zPath = "."; |
| 10935 | zCopy = sqlite3_mprintf("%s",zPath); |
| 10936 | if( zCopy==0 ) return; |
| 10937 | len = strlen(zCopy); |
| 10938 | while( len>1 && (zCopy[len-1]=='/' || (isWin && zCopy[len-1]=='\\')) ){ |
| 10939 | len--; |
| 10940 | } |
| 10941 | zCopy[len] = 0; |
| @@ -12685,10 +12725,11 @@ | |
| 12725 | |
| 12726 | for(p=pCsr->pFreeEntry; p; p=pNext){ |
| 12727 | pNext = p->pNext; |
| 12728 | zipfileEntryFree(p); |
| 12729 | } |
| 12730 | pCsr->pFreeEntry = 0; |
| 12731 | } |
| 12732 | |
| 12733 | /* |
| 12734 | ** Destructor for an ZipfileCsr. |
| 12735 | */ |
| @@ -13087,11 +13128,17 @@ | |
| 13128 | } |
| 13129 | } |
| 13130 | |
| 13131 | if( rc==SQLITE_OK ){ |
| 13132 | u32 *pt = &pNew->mUnixTime; |
| 13133 | /* aRead[0..nFile-1] might contain embedded \000 characters |
| 13134 | ** See Bug 2026-05-31T11:43:05Z */ |
| 13135 | pNew->cds.zFile = sqlite3_malloc64(nFile+1); |
| 13136 | if( pNew->cds.zFile!=0 ){ |
| 13137 | memcpy(pNew->cds.zFile, aRead, nFile); |
| 13138 | pNew->cds.zFile[nFile] = 0; |
| 13139 | } |
| 13140 | pNew->aExtra = (u8*)&pNew[1]; |
| 13141 | memcpy(pNew->aExtra, &aRead[nFile], nExtra); |
| 13142 | if( pNew->cds.zFile==0 ){ |
| 13143 | rc = SQLITE_NOMEM; |
| 13144 | }else if( 0==zipfileScanExtra(&aRead[nFile], pNew->cds.nExtra, pt) ){ |
| @@ -14191,14 +14238,14 @@ | |
| 14238 | ZipfileBuffer body; |
| 14239 | ZipfileBuffer cds; |
| 14240 | }; |
| 14241 | |
| 14242 | static int zipfileBufferGrow(ZipfileBuffer *pBuf, i64 nByte){ |
| 14243 | if( (pBuf->nAlloc-pBuf->n)<nByte ){ |
| 14244 | u8 *aNew; |
| 14245 | i64 nNew = pBuf->n ? (i64)pBuf->n*2 : 512; |
| 14246 | i64 nReq = pBuf->n + nByte; |
| 14247 | |
| 14248 | while( nNew<nReq ) nNew = nNew*2; |
| 14249 | aNew = sqlite3_realloc64(pBuf->a, nNew); |
| 14250 | if( aNew==0 ) return SQLITE_NOMEM; |
| 14251 | pBuf->a = aNew; |
| @@ -16296,11 +16343,11 @@ | |
| 16343 | p->pTable = pTab; |
| 16344 | |
| 16345 | /* The statement the vtab will pass to sqlite3_declare_vtab() */ |
| 16346 | zInner = idxAppendText(&rc, 0, "CREATE TABLE x("); |
| 16347 | for(i=0; i<pTab->nCol; i++){ |
| 16348 | zInner = idxAppendText(&rc, zInner, "%s%Q COLLATE %Q", |
| 16349 | (i==0 ? "" : ", "), pTab->aCol[i].zName, pTab->aCol[i].zColl |
| 16350 | ); |
| 16351 | } |
| 16352 | zInner = idxAppendText(&rc, zInner, ")"); |
| 16353 | |
| @@ -16496,11 +16543,11 @@ | |
| 16543 | sqlite3_free(zCols); |
| 16544 | sqlite3_free(zOrder); |
| 16545 | return sqlite3_reset(pIndexXInfo); |
| 16546 | } |
| 16547 | zCols = idxAppendText(&rc, zCols, |
| 16548 | "%sx.%Q IS sqlite_expert_rem(%d, x.%Q) COLLATE %Q", |
| 16549 | zComma, zName, nCol, zName, zColl |
| 16550 | ); |
| 16551 | zOrder = idxAppendText(&rc, zOrder, "%s%d", zComma, ++nCol); |
| 16552 | } |
| 16553 | sqlite3_reset(pIndexXInfo); |
| @@ -19464,11 +19511,11 @@ | |
| 19511 | sqlite3_vfs_unregister(pVfs); |
| 19512 | sqlite3_free(pVfs); |
| 19513 | } |
| 19514 | |
| 19515 | /************************* End ext/misc/vfstrace.c ********************/ |
| 19516 | /************************* Begin ext/misc/diskused.c ******************/ |
| 19517 | /* |
| 19518 | ** 2026-04-13 |
| 19519 | ** |
| 19520 | ** The author disclaims copyright to this source code. In place of |
| 19521 | ** a legal notice, here is a blessing: |
| @@ -19477,12 +19524,21 @@ | |
| 19524 | ** May you find forgiveness for yourself and forgive others. |
| 19525 | ** May you share freely, never taking more than you give. |
| 19526 | ** |
| 19527 | ****************************************************************************** |
| 19528 | ** |
| 19529 | ** This extension implements an SQL function: |
| 19530 | ** |
| 19531 | ** diskused(X) |
| 19532 | ** |
| 19533 | ** Where X is the schema name (typically 'main'). The output is text |
| 19534 | ** that describes how much filesystem space the various tables and indexes |
| 19535 | ** of the database consume. |
| 19536 | ** |
| 19537 | ** This function is a replacement for the (now deprecated) |
| 19538 | ** "sqlite3_analyzer" utility program. This function is built |
| 19539 | ** into the CLI and is used to implement the ".diskused" command there. |
| 19540 | */ |
| 19541 | /* #include "sqlite3ext.h" */ |
| 19542 | SQLITE_EXTENSION_INIT1 |
| 19543 | #include <assert.h> |
| 19544 | #include <string.h> |
| @@ -19490,28 +19546,28 @@ | |
| 19546 | #include <math.h> |
| 19547 | |
| 19548 | /* |
| 19549 | ** State information for the analysis |
| 19550 | */ |
| 19551 | typedef struct DiskUsed DiskUsed; |
| 19552 | struct DiskUsed { |
| 19553 | sqlite3 *db; /* Database connection */ |
| 19554 | sqlite3_context *context; /* SQL function context */ |
| 19555 | sqlite3_str *pOut; /* Write output here */ |
| 19556 | char *zSU; /* Name of the temp.space_used table */ |
| 19557 | const char *zSchema; /* Schema to be analyzed */ |
| 19558 | }; |
| 19559 | |
| 19560 | /* |
| 19561 | ** Free all resources that the DiskUsed object references and |
| 19562 | ** reset the DiskUsed object. |
| 19563 | ** |
| 19564 | ** Call this routine multiple times on the same DiskUsed object |
| 19565 | ** is a harmless no-op, as long as the memory for the object itself |
| 19566 | ** has not been freed. |
| 19567 | */ |
| 19568 | static void diskusedReset(DiskUsed *p){ |
| 19569 | if( p->zSU ){ |
| 19570 | char *zSql = sqlite3_mprintf("DROP TABLE temp.%s;", p->zSU); |
| 19571 | if( zSql ){ |
| 19572 | sqlite3_exec(p->db, zSql, 0, 0, 0); |
| 19573 | sqlite3_free(zSql); |
| @@ -19524,11 +19580,11 @@ | |
| 19580 | |
| 19581 | /* |
| 19582 | ** Report an error using formatted text. If zFormat==NULL then report |
| 19583 | ** an OOM error. |
| 19584 | */ |
| 19585 | static void diskusedError(DiskUsed *p, const char *zFormat, ...){ |
| 19586 | char *zErr; |
| 19587 | if( zFormat ){ |
| 19588 | va_list ap; |
| 19589 | va_start(ap, zFormat); |
| 19590 | zErr = sqlite3_vmprintf(zFormat, ap); |
| @@ -19540,38 +19596,38 @@ | |
| 19596 | sqlite3_result_error_nomem(p->context); |
| 19597 | }else{ |
| 19598 | sqlite3_result_error(p->context, zErr, -1); |
| 19599 | sqlite3_free(zErr); |
| 19600 | } |
| 19601 | diskusedReset(p); |
| 19602 | } |
| 19603 | |
| 19604 | /* |
| 19605 | ** Prepare and return an SQL statement. |
| 19606 | */ |
| 19607 | static sqlite3_stmt *diskusedVPrep(DiskUsed *p, const char *zFmt, va_list ap){ |
| 19608 | char *zSql; |
| 19609 | int rc; |
| 19610 | sqlite3_stmt *pStmt = 0; |
| 19611 | zSql = sqlite3_vmprintf(zFmt, ap); |
| 19612 | if( zSql==0 ){ diskusedError(p,0); return 0; } |
| 19613 | rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0); |
| 19614 | if( rc ){ |
| 19615 | diskusedError(p, "SQL parse error: %s\nOriginal SQL: %s", |
| 19616 | sqlite3_errmsg(p->db), zSql); |
| 19617 | sqlite3_finalize(pStmt); |
| 19618 | diskusedReset(p); |
| 19619 | pStmt = 0; |
| 19620 | } |
| 19621 | sqlite3_free(zSql); |
| 19622 | return pStmt; |
| 19623 | } |
| 19624 | static sqlite3_stmt *diskusedPrepare(DiskUsed *p, const char *zFormat, ...){ |
| 19625 | va_list ap; |
| 19626 | sqlite3_stmt *pStmt = 0; |
| 19627 | va_start(ap, zFormat); |
| 19628 | pStmt = diskusedVPrep(p,zFormat,ap); |
| 19629 | va_end(ap); |
| 19630 | return pStmt; |
| 19631 | } |
| 19632 | |
| 19633 | /* |
| @@ -19580,60 +19636,60 @@ | |
| 19636 | ** |
| 19637 | ** If rc is SQLITE_DONE or SQLITE_OK, then return false. |
| 19638 | ** |
| 19639 | ** The prepared statement is closed in either case. |
| 19640 | */ |
| 19641 | static int diskusedStmtFinish(DiskUsed *p, int rc, sqlite3_stmt *pStmt){ |
| 19642 | if( rc==SQLITE_DONE ){ |
| 19643 | rc = SQLITE_OK; |
| 19644 | } |
| 19645 | if( rc!=SQLITE_OK || (rc = sqlite3_reset(pStmt))!=SQLITE_OK ){ |
| 19646 | diskusedError(p, "SQL run-time error: %s\nOriginal SQL: %s", |
| 19647 | sqlite3_errmsg(p->db), sqlite3_sql(pStmt)); |
| 19648 | diskusedReset(p); |
| 19649 | } |
| 19650 | sqlite3_finalize(pStmt); |
| 19651 | return rc; |
| 19652 | } |
| 19653 | |
| 19654 | /* |
| 19655 | ** Run SQL. Return the number of errors. |
| 19656 | */ |
| 19657 | static int diskusedSql(DiskUsed *p, const char *zFormat, ...){ |
| 19658 | va_list ap; |
| 19659 | int rc; |
| 19660 | sqlite3_stmt *pStmt = 0; |
| 19661 | va_start(ap, zFormat); |
| 19662 | pStmt = diskusedVPrep(p,zFormat,ap); |
| 19663 | va_end(ap); |
| 19664 | if( pStmt==0 ) return 1; |
| 19665 | while( (rc = sqlite3_step(pStmt))==SQLITE_ROW ){} |
| 19666 | if( rc==SQLITE_DONE ){ |
| 19667 | rc = SQLITE_OK; |
| 19668 | }else{ |
| 19669 | diskusedError(p, "SQL run-time error: %s\nOriginal SQL: %s", |
| 19670 | sqlite3_errmsg(p->db), sqlite3_sql(pStmt)); |
| 19671 | diskusedReset(p); |
| 19672 | } |
| 19673 | sqlite3_finalize(pStmt); |
| 19674 | return rc; |
| 19675 | } |
| 19676 | |
| 19677 | /* |
| 19678 | ** Run an SQL query that returns an integer. Write that integer |
| 19679 | ** into *piRes. Return the number of errors. |
| 19680 | */ |
| 19681 | static int diskusedSqlInt( |
| 19682 | DiskUsed *p, |
| 19683 | sqlite3_int64 *piRes, |
| 19684 | const char *zFormat, ... |
| 19685 | ){ |
| 19686 | va_list ap; |
| 19687 | int rc; |
| 19688 | sqlite3_stmt *pStmt = 0; |
| 19689 | va_start(ap, zFormat); |
| 19690 | pStmt = diskusedVPrep(p,zFormat,ap); |
| 19691 | va_end(ap); |
| 19692 | if( pStmt==0 ) return 1; |
| 19693 | rc = sqlite3_step(pStmt); |
| 19694 | if( rc==SQLITE_ROW ){ |
| 19695 | *piRes = sqlite3_column_int64(pStmt, 0); |
| @@ -19641,14 +19697,14 @@ | |
| 19697 | }else if( rc==SQLITE_DONE ){ |
| 19698 | rc = SQLITE_OK; |
| 19699 | }else{ |
| 19700 | if( p->db ){ |
| 19701 | /* p->db is NULL if there was some prior error */ |
| 19702 | diskusedError(p, "SQL run-time error: %s\nOriginal SQL: %s", |
| 19703 | sqlite3_errmsg(p->db), sqlite3_sql(pStmt)); |
| 19704 | } |
| 19705 | diskusedReset(p); |
| 19706 | } |
| 19707 | sqlite3_finalize(pStmt); |
| 19708 | return rc; |
| 19709 | } |
| 19710 | |
| @@ -19657,20 +19713,20 @@ | |
| 19713 | ** by the format string. If the output is initially empty, begin |
| 19714 | ** the title line with "/" so that it forms the beginning of a C-style |
| 19715 | ** comment. Otherwise begin with a new-line. Always finish with a |
| 19716 | ** newline. |
| 19717 | */ |
| 19718 | static void diskusedTitle(DiskUsed *p, const char *zFormat, ...){ |
| 19719 | char *zFirst; |
| 19720 | char *zTitle; |
| 19721 | size_t nTitle; |
| 19722 | va_list ap; |
| 19723 | va_start(ap, zFormat); |
| 19724 | zTitle = sqlite3_vmprintf(zFormat, ap); |
| 19725 | va_end(ap); |
| 19726 | if( zTitle==0 ){ |
| 19727 | diskusedError(p, 0); |
| 19728 | return; |
| 19729 | } |
| 19730 | zFirst = sqlite3_str_length(p->pOut)==0 ? "/" : "\n*"; |
| 19731 | nTitle = strlen(zTitle); |
| 19732 | if( nTitle>=75 ){ |
| @@ -19685,12 +19741,12 @@ | |
| 19741 | /* |
| 19742 | ** Add an output line that begins with the zDesc text extended out to |
| 19743 | ** 50 columns with "." characters, and followed by whatever text is |
| 19744 | ** described by zFormat. |
| 19745 | */ |
| 19746 | static void diskusedLine( |
| 19747 | DiskUsed *p, /* DiskUsed context */ |
| 19748 | const char *zDesc, /* Description */ |
| 19749 | const char *zFormat, /* Argument to the description */ |
| 19750 | ... |
| 19751 | ){ |
| 19752 | char *zTxt; |
| @@ -19698,14 +19754,14 @@ | |
| 19754 | va_list ap; |
| 19755 | va_start(ap, zFormat); |
| 19756 | zTxt = sqlite3_vmprintf(zFormat, ap); |
| 19757 | va_end(ap); |
| 19758 | if( zTxt==0 ){ |
| 19759 | diskusedError(p, 0); |
| 19760 | return; |
| 19761 | } |
| 19762 | nDesc = zDesc ? strlen(zDesc) : 0; |
| 19763 | if( nDesc>=50 ){ |
| 19764 | sqlite3_str_appendf(p->pOut, "%s %z", zDesc, zTxt); |
| 19765 | }else{ |
| 19766 | int nExtra = 50 - (int)nDesc; |
| 19767 | sqlite3_str_appendf(p->pOut, "%s%.*c %z", zDesc, nExtra, '.', zTxt); |
| @@ -19715,11 +19771,11 @@ | |
| 19771 | /* |
| 19772 | ** Write a percentage into the output. The number written should show |
| 19773 | ** two or three significant digits, with the decimal point being the fourth |
| 19774 | ** character. |
| 19775 | */ |
| 19776 | static void diskusedPercent(DiskUsed *p, double r){ |
| 19777 | char zNum[100]; |
| 19778 | char *zDP; |
| 19779 | int nLeadingDigit; |
| 19780 | int sz; |
| 19781 | sqlite3_snprintf(sizeof(zNum)-5, zNum, r>=10.0 ? "%.3g" :"%.2g", r); |
| @@ -19744,12 +19800,12 @@ | |
| 19800 | ** |
| 19801 | ** The title if the subreport is given by zTitle. zWhere is |
| 19802 | ** a boolean expression that can go in the WHERE clause to select |
| 19803 | ** the relevant rows of the s.zSU table. |
| 19804 | */ |
| 19805 | static int diskusedSubreport( |
| 19806 | DiskUsed *p, /* DiskUsed context */ |
| 19807 | char *zTitle, /* Title for this subreport */ |
| 19808 | char *zWhere, /* WHERE clause for this subreport */ |
| 19809 | sqlite3_int64 pgsz, /* Database page size */ |
| 19810 | sqlite3_int64 nPage /* Number of pages in entire database */ |
| 19811 | ){ |
| @@ -19773,14 +19829,14 @@ | |
| 19829 | sqlite3_int64 total_unused; /* Total unused bytes */ |
| 19830 | sqlite3_int64 total_meta; /* Total metadata */ |
| 19831 | int rc; |
| 19832 | |
| 19833 | if( zTitle==0 || zWhere==0 ){ |
| 19834 | diskusedError(p, 0); |
| 19835 | return SQLITE_NOMEM; |
| 19836 | } |
| 19837 | pStmt = diskusedPrepare(p, |
| 19838 | "SELECT\n" |
| 19839 | " sum(if(is_without_rowid OR is_index,nentry,leaf_entries)),\n" /* 0 */ |
| 19840 | " sum(payload),\n" /* 1 */ |
| 19841 | " sum(ovfl_payload),\n" /* 2 */ |
| 19842 | " max(mx_payload),\n" /* 3 */ |
| @@ -19797,11 +19853,11 @@ | |
| 19853 | " FROM temp.%s WHERE %s", |
| 19854 | p->zSU, zWhere); |
| 19855 | if( pStmt==0 ) return 1; |
| 19856 | rc = sqlite3_step(pStmt); |
| 19857 | if( rc==SQLITE_ROW ){ |
| 19858 | diskusedTitle(p, "%s", zTitle); |
| 19859 | |
| 19860 | nentry = sqlite3_column_int64(pStmt, 0); |
| 19861 | payload = sqlite3_column_int64(pStmt, 1); |
| 19862 | ovfl_payload = sqlite3_column_int64(pStmt, 2); |
| 19863 | mx_payload = sqlite3_column_int64(pStmt, 3); |
| @@ -19816,73 +19872,73 @@ | |
| 19872 | cnt = sqlite3_column_int64(pStmt, 12); |
| 19873 | int_cell = sqlite3_column_int64(pStmt, 13); |
| 19874 | rc = SQLITE_DONE; |
| 19875 | |
| 19876 | total_pages = leaf_pages + int_pages + ovfl_pages; |
| 19877 | diskusedLine(p, "Percentage of total database", "%.3g%%\n", |
| 19878 | (total_pages*100.0)/(double)nPage); |
| 19879 | diskusedLine(p, "Number of entries", "%lld\n", nentry); |
| 19880 | storage = total_pages*pgsz; |
| 19881 | diskusedLine(p, "Bytes of storage consumed", "%lld\n", storage); |
| 19882 | diskusedLine(p, "Bytes of payload", "%-11lld ", payload); |
| 19883 | diskusedPercent(p, payload*100.0/(double)storage); |
| 19884 | if( ovfl_cnt>0 ){ |
| 19885 | diskusedLine(p, "Bytes of payload in overflow","%-11lld ",ovfl_payload); |
| 19886 | diskusedPercent(p, ovfl_payload*100.0/(double)payload); |
| 19887 | } |
| 19888 | total_unused = leaf_unused + int_unused + ovfl_unused; |
| 19889 | total_meta = storage - payload - total_unused; |
| 19890 | diskusedLine(p, "Bytes of metadata","%-11lld ", total_meta); |
| 19891 | diskusedPercent(p, total_meta*100.0/(double)storage); |
| 19892 | if( cnt==1 ){ |
| 19893 | diskusedLine(p, "B-tree depth", "%lld\n", depth); |
| 19894 | if( int_cell>1 ){ |
| 19895 | diskusedLine(p, "Average fanout", "%.1f\n", |
| 19896 | (double)(int_cell+int_pages)/(double)int_pages); |
| 19897 | } |
| 19898 | } |
| 19899 | if( nentry>0 ){ |
| 19900 | diskusedLine(p, "Average payload per entry", "%.1f\n", |
| 19901 | (double)payload/(double)nentry); |
| 19902 | diskusedLine(p, "Average unused bytes per entry", "%.1f\n", |
| 19903 | (double)total_unused/(double)nentry); |
| 19904 | diskusedLine(p, "Average metadata per entry", "%.1f\n", |
| 19905 | (double)total_meta/(double)nentry); |
| 19906 | } |
| 19907 | diskusedLine(p, "Maximum single-entry payload", "%lld\n", mx_payload); |
| 19908 | if( nentry>0 ){ |
| 19909 | diskusedLine(p, "Entries that use overflow", "%-11lld ", ovfl_cnt); |
| 19910 | diskusedPercent(p, ovfl_cnt*100.0/(double)nentry); |
| 19911 | } |
| 19912 | if( int_pages>0 ){ |
| 19913 | diskusedLine(p, "Index pages used", "%lld\n", int_pages); |
| 19914 | } |
| 19915 | diskusedLine(p, "Primary pages used", "%lld\n", leaf_pages); |
| 19916 | if( ovfl_cnt ){ |
| 19917 | diskusedLine(p, "Overflow pages used", "%lld\n", ovfl_pages); |
| 19918 | } |
| 19919 | diskusedLine(p, "Total pages used", "%lld\n", total_pages); |
| 19920 | if( int_pages>0 ){ |
| 19921 | diskusedLine(p, "Unused bytes on index pages", "%lld\n", int_unused); |
| 19922 | } |
| 19923 | diskusedLine(p, "Unused bytes on primary pages", "%lld\n", leaf_unused); |
| 19924 | if( ovfl_cnt ){ |
| 19925 | diskusedLine(p, "Unused bytes on overflow pages", "%lld\n", ovfl_unused); |
| 19926 | } |
| 19927 | diskusedLine(p, "Unused bytes on all pages", "%-11lld ", total_unused); |
| 19928 | diskusedPercent(p, total_unused*100.0/(double)storage); |
| 19929 | } |
| 19930 | return diskusedStmtFinish(p, rc, pStmt); |
| 19931 | } |
| 19932 | |
| 19933 | /* |
| 19934 | ** SQL Function: diskused(SCHEMA) |
| 19935 | ** |
| 19936 | ** Analyze the database schema named in the argument. Return text |
| 19937 | ** containing the space utilization stats. |
| 19938 | */ |
| 19939 | static void diskusedFunc( |
| 19940 | sqlite3_context *context, |
| 19941 | int argc, |
| 19942 | sqlite3_value **argv |
| 19943 | ){ |
| 19944 | int rc; |
| @@ -19893,47 +19949,47 @@ | |
| 19949 | sqlite3_int64 nPage; |
| 19950 | sqlite3_int64 nPageInUse; |
| 19951 | sqlite3_int64 nFreeList; |
| 19952 | sqlite3_int64 nIndex; |
| 19953 | sqlite3_int64 nWORowid; |
| 19954 | DiskUsed s; |
| 19955 | sqlite3_uint64 r[2]; |
| 19956 | |
| 19957 | (void)argc; |
| 19958 | memset(&s, 0, sizeof(s)); |
| 19959 | s.db = sqlite3_context_db_handle(context); |
| 19960 | s.context = context; |
| 19961 | s.pOut = sqlite3_str_new(0); |
| 19962 | if( sqlite3_str_errcode(s.pOut) ){ |
| 19963 | diskusedError(&s, 0); |
| 19964 | return; |
| 19965 | } |
| 19966 | s.zSchema = (const char*)sqlite3_value_text(argv[0]); |
| 19967 | if( s.zSchema==0 ){ |
| 19968 | s.zSchema = "main"; |
| 19969 | }else if( sqlite3_strlike("temp",s.zSchema,0)==0 ){ |
| 19970 | diskusedReset(&s); |
| 19971 | sqlite3_result_text(context, "cannot analyze \"temp\"",-1,SQLITE_STATIC); |
| 19972 | return; |
| 19973 | } |
| 19974 | ii = 0; |
| 19975 | rc = diskusedSqlInt(&s,&ii,"SELECT 1 FROM pragma_database_list" |
| 19976 | " WHERE name=%Q COLLATE nocase",s.zSchema); |
| 19977 | if( rc || ii==0 ){ |
| 19978 | diskusedReset(&s); |
| 19979 | sqlite3_result_text(context,"no such database",-1,SQLITE_STATIC); |
| 19980 | return; |
| 19981 | } |
| 19982 | sqlite3_randomness(sizeof(r), &r); |
| 19983 | s.zSU = sqlite3_mprintf("diskused%016llx%016llx", r[0], r[1]); |
| 19984 | if( s.zSU==0 ){ diskusedError(&s, 0); return; } |
| 19985 | |
| 19986 | /* The s.zSU table contains the data used for the analysis. |
| 19987 | ** The table name contains 128-bits of randomness to avoid |
| 19988 | ** collisions with preexisting tables in temp. |
| 19989 | */ |
| 19990 | rc = diskusedSql(&s, |
| 19991 | "CREATE TABLE temp.%s(\n" |
| 19992 | " name text, -- A table or index\n" |
| 19993 | " tblname text, -- Table that owns name\n" |
| 19994 | " is_index boolean, -- TRUE if it is an index\n" |
| 19995 | " is_without_rowid boolean, -- TRUE if WITHOUT ROWID table\n" |
| @@ -19956,11 +20012,11 @@ | |
| 20012 | ); |
| 20013 | if( rc ) return; |
| 20014 | |
| 20015 | /* Populate the s.zSU table |
| 20016 | */ |
| 20017 | rc = diskusedSql(&s, |
| 20018 | "WITH\n" |
| 20019 | " allidx(idxname) AS (\n" |
| 20020 | " SELECT name FROM \"%w\".sqlite_schema WHERE type='index'\n" |
| 20021 | " ),\n" |
| 20022 | " allobj(allname,tblname,isidx,isworowid) AS (\n" |
| @@ -20008,141 +20064,143 @@ | |
| 20064 | s.zSchema /* JOIN dbstat(%Q) */ |
| 20065 | ); |
| 20066 | if( rc ) return; |
| 20067 | |
| 20068 | nPage = 0; |
| 20069 | rc = diskusedSqlInt(&s, &nPage, "PRAGMA \"%w\".page_count", s.zSchema); |
| 20070 | if( rc ) return; |
| 20071 | if( nPage<=0 ){ |
| 20072 | /* Very brief reply for an empty database */ |
| 20073 | diskusedReset(&s); |
| 20074 | sqlite3_result_text(context, "empty database", -1, SQLITE_STATIC); |
| 20075 | return; |
| 20076 | } |
| 20077 | |
| 20078 | /* Begin generating the report */ |
| 20079 | diskusedTitle(&s, "Database storage utilization report"); |
| 20080 | pgsz = 0; |
| 20081 | rc = diskusedSqlInt(&s, &pgsz, "PRAGMA \"%w\".page_size", s.zSchema); |
| 20082 | if( rc ) return; |
| 20083 | diskusedLine(&s, "Page size in bytes","%lld\n",pgsz); |
| 20084 | diskusedLine(&s, "Pages in the database", "%lld\n", nPage); |
| 20085 | |
| 20086 | nPageInUse = 0; |
| 20087 | rc = diskusedSqlInt(&s, &nPageInUse, |
| 20088 | "SELECT sum(leaf_pages+int_pages+ovfl_pages) FROM temp.%s", s.zSU); |
| 20089 | if( rc ) return; |
| 20090 | diskusedLine(&s, "Pages that store data", "%-11lld ", nPageInUse); |
| 20091 | diskusedPercent(&s, (nPageInUse*100.0)/(double)nPage); |
| 20092 | |
| 20093 | nFreeList = 0; |
| 20094 | rc = diskusedSqlInt(&s, &nFreeList, "PRAGMA \"%w\".freelist_count",s.zSchema); |
| 20095 | if( rc ) return; |
| 20096 | diskusedLine(&s, "Pages on the freelist", "%-11lld ", nFreeList); |
| 20097 | diskusedPercent(&s, (nFreeList*100.0)/(double)nPage); |
| 20098 | |
| 20099 | ii = 0; |
| 20100 | rc = diskusedSqlInt(&s, &ii, "PRAGMA \"%w\".auto_vacuum", s.zSchema); |
| 20101 | if( rc ) return; |
| 20102 | if( ii==0 || nPage<=1 ){ |
| 20103 | ii = 0; |
| 20104 | }else{ |
| 20105 | double rPtrsPerPage = pgsz/5; |
| 20106 | double rAvPage = (nPage-1.0)/(rPtrsPerPage+1.0); |
| 20107 | ii = (sqlite3_int64)ceil(rAvPage); |
| 20108 | } |
| 20109 | diskusedLine(&s, "Pages of auto-vacuum overhead", "%-11lld ", ii); |
| 20110 | diskusedPercent(&s, (ii*100.0)/(double)nPage); |
| 20111 | |
| 20112 | ii = 0; |
| 20113 | rc = diskusedSqlInt(&s, &ii, |
| 20114 | "SELECT count(*)+1 FROM \"%w\".sqlite_schema WHERE type='table'", |
| 20115 | s.zSchema); |
| 20116 | if( rc ) return; |
| 20117 | diskusedLine(&s, "Number of tables", "%lld\n", ii); |
| 20118 | nWORowid = 0; |
| 20119 | rc = diskusedSqlInt(&s, &nWORowid, |
| 20120 | "SELECT count(*) FROM \"%w\".pragma_table_list WHERE wr", |
| 20121 | s.zSchema); |
| 20122 | if( rc ) return; |
| 20123 | if( nWORowid>0 ){ |
| 20124 | diskusedLine(&s, "Number of WITHOUT ROWID tables", "%lld\n", nWORowid); |
| 20125 | diskusedLine(&s, "Number of rowid tables", "%lld\n", ii - nWORowid); |
| 20126 | } |
| 20127 | nIndex = 0; |
| 20128 | rc = diskusedSqlInt(&s, &nIndex, |
| 20129 | "SELECT count(*) FROM \"%w\".sqlite_schema WHERE type='index'", |
| 20130 | s.zSchema); |
| 20131 | if( rc ) return; |
| 20132 | diskusedLine(&s, "Number of indexes", "%lld\n", nIndex); |
| 20133 | ii = 0; |
| 20134 | rc = diskusedSqlInt(&s, &ii, |
| 20135 | "SELECT count(*) FROM \"%w\".sqlite_schema" |
| 20136 | " WHERE name GLOB 'sqlite_autoindex_*' AND type='index'", |
| 20137 | s.zSchema); |
| 20138 | if( rc ) return; |
| 20139 | diskusedLine(&s, "Number of defined indexes", "%lld\n", nIndex - ii); |
| 20140 | diskusedLine(&s, "Number of implied indexes", "%lld\n", ii); |
| 20141 | diskusedLine(&s, "Size of the database in bytes", "%lld\n", pgsz*nPage); |
| 20142 | ii = 0; |
| 20143 | rc = diskusedSqlInt(&s, &ii, |
| 20144 | "SELECT sum(payload) FROM temp.%s" |
| 20145 | " WHERE NOT is_index AND name NOT LIKE 'sqlite_schema'", |
| 20146 | s.zSU); |
| 20147 | if( rc ) return; |
| 20148 | diskusedLine(&s, "Bytes of payload", "%-11lld ", ii); |
| 20149 | diskusedPercent(&s, ii*100.0/(double)(pgsz*nPage)); |
| 20150 | |
| 20151 | diskusedTitle(&s, "Page counts for all tables with their indexes"); |
| 20152 | pStmt = diskusedPrepare(&s, |
| 20153 | "SELECT upper(tblname),\n" |
| 20154 | " sum(int_pages+leaf_pages+ovfl_pages)\n" |
| 20155 | " FROM temp.%s\n" |
| 20156 | " WHERE tblname IS NOT NULL\n" |
| 20157 | " GROUP BY 1\n" |
| 20158 | " ORDER BY 2 DESC, 1;", |
| 20159 | s.zSU); |
| 20160 | if( pStmt==0 ) return; |
| 20161 | while( (rc = sqlite3_step(pStmt))==SQLITE_ROW ){ |
| 20162 | sqlite3_int64 nn = sqlite3_column_int64(pStmt,1); |
| 20163 | diskusedLine(&s, (const char*)sqlite3_column_text(pStmt,0), "%-11lld ", nn); |
| 20164 | diskusedPercent(&s, (nn*100.0)/(double)nPage); |
| 20165 | } |
| 20166 | if( diskusedStmtFinish(&s, rc, pStmt) ) return; |
| 20167 | |
| 20168 | diskusedTitle(&s, "Page counts for all tables and indexes separately"); |
| 20169 | pStmt = diskusedPrepare(&s, |
| 20170 | "SELECT upper(name),\n" |
| 20171 | " sum(int_pages+leaf_pages+ovfl_pages)\n" |
| 20172 | " FROM temp.%s\n" |
| 20173 | " WHERE name IS NOT NULL\n" |
| 20174 | " GROUP BY 1\n" |
| 20175 | " ORDER BY 2 DESC, 1;", |
| 20176 | s.zSU); |
| 20177 | if( pStmt==0 ) return; |
| 20178 | while( (rc = sqlite3_step(pStmt))==SQLITE_ROW ){ |
| 20179 | sqlite3_int64 nn = sqlite3_column_int64(pStmt,1); |
| 20180 | diskusedLine(&s, (const char*)sqlite3_column_text(pStmt,0), "%-11lld ", nn); |
| 20181 | diskusedPercent(&s, (nn*100.0)/(double)nPage); |
| 20182 | } |
| 20183 | if( diskusedStmtFinish(&s, rc, pStmt) ) return; |
| 20184 | |
| 20185 | rc = diskusedSubreport(&s, "All tables and indexes", "1", pgsz, nPage); |
| 20186 | if( rc ) return; |
| 20187 | rc = diskusedSubreport(&s, "All tables", "NOT is_index", pgsz, nPage); |
| 20188 | if( rc ) return; |
| 20189 | if( nWORowid>0 ){ |
| 20190 | rc = diskusedSubreport(&s, "All WITHOUT ROWID tables", "is_without_rowid", |
| 20191 | pgsz, nPage); |
| 20192 | if( rc ) return; |
| 20193 | rc = diskusedSubreport(&s, "All rowid tables", |
| 20194 | "NOT is_without_rowid AND NOT is_index", |
| 20195 | pgsz, nPage); |
| 20196 | if( rc ) return; |
| 20197 | } |
| 20198 | rc = diskusedSubreport(&s, "All indexes", "is_index", pgsz, nPage); |
| 20199 | if( rc ) return; |
| 20200 | |
| 20201 | pStmt = diskusedPrepare(&s, |
| 20202 | "SELECT upper(tblname), tblname, sum(is_index) FROM temp.%s" |
| 20203 | " GROUP BY 1 ORDER BY 1", |
| 20204 | s.zSU); |
| 20205 | if( pStmt==0 ) return; |
| 20206 | while( (rc = sqlite3_step(pStmt))==SQLITE_ROW ){ |
| @@ -20150,37 +20208,37 @@ | |
| 20208 | const char *zName = (const char*)sqlite3_column_text(pStmt, 1); |
| 20209 | int nSubIndex = sqlite3_column_int(pStmt, 2); |
| 20210 | if( nSubIndex==0 ){ |
| 20211 | char *zTitle = sqlite3_mprintf("Table %s", zUpper); |
| 20212 | char *zWhere = sqlite3_mprintf("name=%Q", zName); |
| 20213 | rc = diskusedSubreport(&s, zTitle, zWhere, pgsz, nPage); |
| 20214 | sqlite3_free(zTitle); |
| 20215 | sqlite3_free(zWhere); |
| 20216 | if( rc ) break; |
| 20217 | }else{ |
| 20218 | sqlite3_stmt *pS2; |
| 20219 | char *zTitle = sqlite3_mprintf("Table %s and all its indexes", zUpper); |
| 20220 | char *zWhere = sqlite3_mprintf("tblname=%Q", zName); |
| 20221 | rc = diskusedSubreport(&s, zTitle, zWhere, pgsz, nPage); |
| 20222 | sqlite3_free(zTitle); |
| 20223 | sqlite3_free(zWhere); |
| 20224 | if( rc ) break; |
| 20225 | zTitle = sqlite3_mprintf("Table %s w/o any indexes", zUpper); |
| 20226 | zWhere = sqlite3_mprintf("name=%Q", zName); |
| 20227 | rc = diskusedSubreport(&s, zTitle, zWhere, pgsz, nPage); |
| 20228 | sqlite3_free(zTitle); |
| 20229 | sqlite3_free(zWhere); |
| 20230 | if( rc ) break; |
| 20231 | if( nSubIndex>1 ){ |
| 20232 | zTitle = sqlite3_mprintf("All indexes of table %s", zUpper); |
| 20233 | zWhere = sqlite3_mprintf("tblname=%Q AND is_index", zName); |
| 20234 | rc = diskusedSubreport(&s, zTitle, zWhere, pgsz, nPage); |
| 20235 | sqlite3_free(zTitle); |
| 20236 | sqlite3_free(zWhere); |
| 20237 | if( rc ) break; |
| 20238 | } |
| 20239 | pS2 = diskusedPrepare(&s, |
| 20240 | "SELECT name, upper(name) FROM temp.%s" |
| 20241 | " WHERE is_index AND tblname=%Q", |
| 20242 | s.zSU, zName); |
| 20243 | if( pS2==0 ){ |
| 20244 | rc = SQLITE_NOMEM; |
| @@ -20189,25 +20247,25 @@ | |
| 20247 | while( (rc = sqlite3_step(pS2))==SQLITE_ROW ){ |
| 20248 | const char *zU = (const char*)sqlite3_column_text(pS2, 1); |
| 20249 | const char *zN = (const char*)sqlite3_column_text(pS2, 0); |
| 20250 | zTitle = sqlite3_mprintf("Index %s", zU); |
| 20251 | zWhere = sqlite3_mprintf("name=%Q", zN); |
| 20252 | rc = diskusedSubreport(&s, zTitle, zWhere, pgsz, nPage); |
| 20253 | sqlite3_free(zTitle); |
| 20254 | sqlite3_free(zWhere); |
| 20255 | if( rc ) break; |
| 20256 | } |
| 20257 | rc = diskusedStmtFinish(&s, rc, pS2); |
| 20258 | if( rc ) break; |
| 20259 | } |
| 20260 | } |
| 20261 | if( diskusedStmtFinish(&s, rc, pStmt) ) return; |
| 20262 | |
| 20263 | /* Append SQL statements that will recreate the raw data used for |
| 20264 | ** the analysis. |
| 20265 | */ |
| 20266 | diskusedTitle(&s, "Raw data used to generate this report"); |
| 20267 | sqlite3_str_appendf(s.pOut, |
| 20268 | "The following SQL will create a table named \"space_used\" which\n" |
| 20269 | "contains most of the information used to generate the report above.\n" |
| 20270 | "*/\n" |
| 20271 | ); |
| @@ -20233,11 +20291,11 @@ | |
| 20291 | " ovfl_unused int, -- Unused bytes on overflow pages\n" /* 16 */ |
| 20292 | " int_entries int -- B-tree entries on internal pages\n"/* 17 */ |
| 20293 | ");\n" |
| 20294 | "INSERT INTO space_used VALUES\n" |
| 20295 | ); |
| 20296 | pStmt = diskusedPrepare(&s, |
| 20297 | "SELECT quote(name), quote(tblname),\n" /* 0..1 */ |
| 20298 | " is_index, is_without_rowid, nentry, leaf_entries,\n" /* 2..5 */ |
| 20299 | " depth, payload, ovfl_payload, ovfl_cnt, mx_payload,\n" /* 6..10 */ |
| 20300 | " int_pages, leaf_pages, ovfl_pages, int_unused,\n" /* 11..14 */ |
| 20301 | " leaf_unused, ovfl_unused, int_entries\n" /* 15..17 */ |
| @@ -20268,11 +20326,11 @@ | |
| 20326 | sqlite3_column_int64(pStmt, 15), |
| 20327 | sqlite3_column_int64(pStmt, 16), |
| 20328 | sqlite3_column_int64(pStmt, 17)); |
| 20329 | } |
| 20330 | if( rc!=SQLITE_DONE ){ |
| 20331 | diskusedError(&s, "SQL run-time error: %s\nSQL: %s", |
| 20332 | sqlite3_errmsg(s.db), sqlite3_sql(pStmt)); |
| 20333 | sqlite3_finalize(pStmt); |
| 20334 | return; |
| 20335 | } |
| 20336 | sqlite3_str_appendf(s.pOut,";\nCOMMIT;"); |
| @@ -20281,32 +20339,32 @@ | |
| 20339 | if( sqlite3_str_length(s.pOut) ){ |
| 20340 | sqlite3_result_text(context, sqlite3_str_finish(s.pOut), -1, |
| 20341 | sqlite3_free); |
| 20342 | s.pOut = 0; |
| 20343 | } |
| 20344 | diskusedReset(&s); |
| 20345 | } |
| 20346 | |
| 20347 | |
| 20348 | #ifdef _WIN32 |
| 20349 | |
| 20350 | #endif |
| 20351 | int sqlite3_diskused_init( |
| 20352 | sqlite3 *db, |
| 20353 | char **pzErrMsg, |
| 20354 | const sqlite3_api_routines *pApi |
| 20355 | ){ |
| 20356 | int rc = SQLITE_OK; |
| 20357 | SQLITE_EXTENSION_INIT2(pApi); |
| 20358 | (void)pzErrMsg; /* Unused parameter */ |
| 20359 | rc = sqlite3_create_function(db, "diskused", 1, |
| 20360 | SQLITE_UTF8|SQLITE_INNOCUOUS, |
| 20361 | 0, diskusedFunc, 0, 0); |
| 20362 | return rc; |
| 20363 | } |
| 20364 | |
| 20365 | /************************* End ext/misc/diskused.c ********************/ |
| 20366 | |
| 20367 | #if !defined(SQLITE_OMIT_VIRTUALTABLE) && defined(SQLITE_ENABLE_DBPAGE_VTAB) |
| 20368 | #define SQLITE_SHELL_HAVE_RECOVER 1 |
| 20369 | #else |
| 20370 | #define SQLITE_SHELL_HAVE_RECOVER 0 |
| @@ -25138,11 +25196,11 @@ | |
| 25196 | /* |
| 25197 | ** Return true if either the SQLITE_NO_COLOR compile-time option is used |
| 25198 | ** or if the NO_COLOR environment variable exists |
| 25199 | */ |
| 25200 | static int shellNoColor(void){ |
| 25201 | #if defined(SQLITE_NO_COLOR) || defined(SQLITE_SHELL_FIDDLE) |
| 25202 | return 1; |
| 25203 | #else |
| 25204 | return getenv("NO_COLOR")!=0; |
| 25205 | #endif |
| 25206 | } |
| @@ -25172,11 +25230,11 @@ | |
| 25230 | case 1: |
| 25231 | #if defined(SQLITE_PS1) |
| 25232 | return SQLITE_PS1; |
| 25233 | #else |
| 25234 | if( shellNoColor() ){ |
| 25235 | return "/A-/v /f-> "; |
| 25236 | }else{ |
| 25237 | return "/e[1;32m/A-/v /e[1;/x33/:36/;m/m/e[3m/;/f/;/e[0m-> "; |
| 25238 | } |
| 25239 | #endif |
| 25240 | |
| @@ -25184,11 +25242,11 @@ | |
| 25242 | case 2: |
| 25243 | #if defined(SQLITE_PS2) |
| 25244 | return SQLITE_PS2; |
| 25245 | #else |
| 25246 | if( shellNoColor() ){ |
| 25247 | return "/B/C-> "; |
| 25248 | }else{ |
| 25249 | return "/B/e[1;/x33/:36/;m/C/e[0m-> "; |
| 25250 | } |
| 25251 | #endif |
| 25252 | |
| @@ -25196,11 +25254,15 @@ | |
| 25254 | ** of cases 1 and 2 */ |
| 25255 | case 3: return "SQLITE_PS1"; |
| 25256 | case 4: return "SQLITE_PS2"; |
| 25257 | |
| 25258 | /* Name of the application */ |
| 25259 | #ifndef SQLITE_CLI_APPNAME |
| 25260 | case 'A': return "SQLite"; |
| 25261 | #else |
| 25262 | case 'A': return SHELL_STRINGIFY(SQLITE_CLI_APPNAME); |
| 25263 | #endif |
| 25264 | |
| 25265 | /* Full version number of the application, including patch level */ |
| 25266 | case 'V': return sqlite3_libversion(); |
| 25267 | |
| 25268 | /* Version number without the patch level */ |
| @@ -26303,10 +26365,47 @@ | |
| 26365 | if( *az ){ |
| 26366 | memcpy(*az, zNew, n+1 ); |
| 26367 | } |
| 26368 | } |
| 26369 | } |
| 26370 | |
| 26371 | /* Forward reference */ |
| 26372 | static int pickStr(const char *zArg, char **pzErr, ...); |
| 26373 | |
| 26374 | /* |
| 26375 | ** Change the limits on the display mode. Return 0 on |
| 26376 | ** success. Return non-zero if zArg is mis-formatted. |
| 26377 | ** |
| 26378 | ** Valid arguments: |
| 26379 | ** |
| 26380 | ** "on" Default limits |
| 26381 | ** "off" All limits turned off |
| 26382 | ** L,C Line and Characters limits set |
| 26383 | ** L,C,T Line, Character, and Title limits set |
| 26384 | ** |
| 26385 | ** Anything else returns non-zero |
| 26386 | */ |
| 26387 | static int modeSetLimit(ShellState *p, const char *zArg){ |
| 26388 | int k = zArg==0 ? 1 : pickStr(zArg,0,"on","off",""); |
| 26389 | if( k==0 ){ |
| 26390 | p->mode.spec.nLineLimit = DFLT_LINE_LIMIT; |
| 26391 | p->mode.spec.nCharLimit = DFLT_CHAR_LIMIT; |
| 26392 | p->mode.spec.nTitleLimit = DFLT_TITLE_LIMIT; |
| 26393 | }else if( k==1 ){ |
| 26394 | p->mode.spec.nLineLimit = 0; |
| 26395 | p->mode.spec.nCharLimit = 0; |
| 26396 | p->mode.spec.nTitleLimit = 0; |
| 26397 | }else{ |
| 26398 | int L, C, T = 0; |
| 26399 | int nNum = sscanf(zArg, "%d,%d,%d", &L, &C, &T); |
| 26400 | if( nNum<2 || L<0 || C<0 || T<0) return 1; |
| 26401 | p->mode.spec.nLineLimit = L; |
| 26402 | p->mode.spec.nCharLimit = C; |
| 26403 | if( nNum==3 ) p->mode.spec.nTitleLimit = T; |
| 26404 | } |
| 26405 | return 0; |
| 26406 | } |
| 26407 | |
| 26408 | /* |
| 26409 | ** Change the mode to eMode |
| 26410 | */ |
| 26411 | static void modeChange(ShellState *p, unsigned char eMode){ |
| @@ -26340,10 +26439,11 @@ | |
| 26439 | modeDup(&p->mode, &p->aSavedModes[eMode-MODE_USER].mode); |
| 26440 | }else if( eMode==MODE_BATCH ){ |
| 26441 | u8 mFlags = p->mode.mFlags; |
| 26442 | modeFree(&p->mode); |
| 26443 | modeChange(p, MODE_List); |
| 26444 | modeSetLimit(p, "off"); |
| 26445 | p->mode.mFlags = mFlags; |
| 26446 | }else if( eMode==MODE_TTY ){ |
| 26447 | u8 mFlags = p->mode.mFlags; |
| 26448 | modeFree(&p->mode); |
| 26449 | modeChange(p, MODE_QBox); |
| @@ -26976,11 +27076,11 @@ | |
| 27076 | return SQLITE_OK; |
| 27077 | } |
| 27078 | #endif |
| 27079 | |
| 27080 | /* |
| 27081 | ** Print a schema statement. This is a helper routine to dump_callback(). |
| 27082 | ** |
| 27083 | ** This routine converts some CREATE TABLE statements for shadow tables |
| 27084 | ** in FTS3/4/5 into CREATE TABLE IF NOT EXISTS statements. |
| 27085 | ** |
| 27086 | ** If the schema statement in z[] contains a start-of-comment and if |
| @@ -28428,12 +28528,12 @@ | |
| 28528 | ".databases List names and files of attached databases", |
| 28529 | ".dbconfig ?op? ?val? List or change sqlite3_db_config() options", |
| 28530 | #if SQLITE_SHELL_HAVE_RECOVER |
| 28531 | ".dbinfo ?DB? Show status information about the database", |
| 28532 | #endif |
| 28533 | ".dbtotxt Hex dump of the database file", |
| 28534 | ".diskused ?SCHEMA? Report database space and size stats", |
| 28535 | ".dump ?OBJECTS? Render database content as SQL", |
| 28536 | " Options:", |
| 28537 | " --data-only Output only INSERT statements", |
| 28538 | " --newlines Allow unescaped newline characters in output", |
| 28539 | " --nosys Omit system tables (ex: \"sqlite_stat1\")", |
| @@ -28540,10 +28640,13 @@ | |
| 28640 | " --reset Reset the count for each input and interrupt", |
| 28641 | " --timeout S Halt after running for S seconds", |
| 28642 | #endif |
| 28643 | ".prompt MAIN CONTINUE Replace the standard prompts", |
| 28644 | " --hard-reset Unset SQLITE_PS1/2 and then --reset", |
| 28645 | #ifndef SQLITE_NO_COLOR |
| 28646 | " --no-color Disable color prompts. Use --color to re-enable", |
| 28647 | #endif |
| 28648 | " --reset Revert to default prompts", |
| 28649 | " --show Show the current prompt strings", |
| 28650 | " -- No more options. Subsequent args are prompts", |
| 28651 | #ifndef SQLITE_SHELL_FIDDLE |
| 28652 | ".quit Stop interpreting input stream, exit if primary.", |
| @@ -29440,11 +29543,11 @@ | |
| 29543 | sqlite3_base64_init(p->db, 0, 0); |
| 29544 | sqlite3_base85_init(p->db, 0, 0); |
| 29545 | sqlite3_regexp_init(p->db, 0, 0); |
| 29546 | sqlite3_ieee_init(p->db, 0, 0); |
| 29547 | sqlite3_series_init(p->db, 0, 0); |
| 29548 | sqlite3_diskused_init(p->db, 0, 0); |
| 29549 | #ifndef SQLITE_SHELL_FIDDLE |
| 29550 | sqlite3_fileio_init(p->db, 0, 0); |
| 29551 | sqlite3_completion_init(p->db, 0, 0); |
| 29552 | #endif |
| 29553 | #ifdef SQLITE_HAVE_ZLIB |
| @@ -31246,11 +31349,11 @@ | |
| 31349 | typedef struct ArCommand ArCommand; |
| 31350 | struct ArCommand { |
| 31351 | u8 eCmd; /* An AR_CMD_* value */ |
| 31352 | u8 bVerbose; /* True if --verbose */ |
| 31353 | u8 bZip; /* True if the archive is a ZIP */ |
| 31354 | u8 bDryRun; /* 1 for --dry-run, 2 for --debug */ |
| 31355 | u8 bAppend; /* True if --append */ |
| 31356 | u8 bGlob; /* True if --glob */ |
| 31357 | u8 fromCmdLine; /* Run from -A instead of .archive */ |
| 31358 | int nArg; /* Number of command arguments */ |
| 31359 | char *zSrcTable; /* "sqlar", "zipfile($file)" or "zip" */ |
| @@ -31308,10 +31411,11 @@ | |
| 31411 | #define AR_SWITCH_FILE 9 |
| 31412 | #define AR_SWITCH_DIRECTORY 10 |
| 31413 | #define AR_SWITCH_APPEND 11 |
| 31414 | #define AR_SWITCH_DRYRUN 12 |
| 31415 | #define AR_SWITCH_GLOB 13 |
| 31416 | #define AR_SWITCH_DEBUG 14 |
| 31417 | |
| 31418 | static int arProcessSwitch(ArCommand *pAr, int eSwitch, const char *zArg){ |
| 31419 | switch( eSwitch ){ |
| 31420 | case AR_CMD_CREATE: |
| 31421 | case AR_CMD_EXTRACT: |
| @@ -31325,11 +31429,14 @@ | |
| 31429 | } |
| 31430 | pAr->eCmd = eSwitch; |
| 31431 | break; |
| 31432 | |
| 31433 | case AR_SWITCH_DRYRUN: |
| 31434 | if( pAr->bDryRun<2 ) pAr->bDryRun = 1; |
| 31435 | break; |
| 31436 | case AR_SWITCH_DEBUG: |
| 31437 | pAr->bDryRun = 2; |
| 31438 | break; |
| 31439 | case AR_SWITCH_GLOB: |
| 31440 | pAr->bGlob = 1; |
| 31441 | break; |
| 31442 | case AR_SWITCH_VERBOSE: |
| @@ -31376,10 +31483,11 @@ | |
| 31483 | { "verbose", 'v', AR_SWITCH_VERBOSE, 0 }, |
| 31484 | { "file", 'f', AR_SWITCH_FILE, 1 }, |
| 31485 | { "append", 'a', AR_SWITCH_APPEND, 1 }, |
| 31486 | { "directory", 'C', AR_SWITCH_DIRECTORY, 1 }, |
| 31487 | { "dryrun", 'n', AR_SWITCH_DRYRUN, 0 }, |
| 31488 | { "debug", 0, AR_SWITCH_DEBUG, 0 }, |
| 31489 | { "glob", 'g', AR_SWITCH_GLOB, 0 }, |
| 31490 | }; |
| 31491 | int nSwitch = sizeof(aSwitch) / sizeof(struct ArSwitch); |
| 31492 | struct ArSwitch *pEnd = &aSwitch[nSwitch]; |
| 31493 | |
| @@ -31676,18 +31784,41 @@ | |
| 31784 | |
| 31785 | /* |
| 31786 | ** Implementation of .ar "eXtract" command. |
| 31787 | */ |
| 31788 | static int arExtractCommand(ArCommand *pAr){ |
| 31789 | /* The zSql1[] string is a template for the query that does the |
| 31790 | ** extraction. Notes: |
| 31791 | ** |
| 31792 | ** * $dir is the directory into which the archive is to be extracted |
| 31793 | ** * $pass is the integer pass number: 0, 1, or 2 |
| 31794 | ** * The dest CTE is created so that realpath($dir) only needs |
| 31795 | ** to be called once. |
| 31796 | */ |
| 31797 | const char *zSql1 = |
| 31798 | "WITH dest(dpath,dlen) AS (\n" |
| 31799 | #ifdef _WIN32 |
| 31800 | " SELECT realpath($dir) || '\\',\n" |
| 31801 | #else |
| 31802 | " SELECT realpath($dir) || '/',\n" |
| 31803 | #endif |
| 31804 | " 1+length(realpath($dir))\n" |
| 31805 | ")\n" |
| 31806 | "SELECT\n" |
| 31807 | " ($dir || name),\n" |
| 31808 | " CASE $dryrun\n" /* vv--- azExtraArg */ |
| 31809 | " WHEN 0 THEN writefile($dir||name, %s, mode, mtime)\n" |
| 31810 | " WHEN 1 THEN 0\n" |
| 31811 | " ELSE shell_putsnl(format('writefile(%%Q,%%s,%%0o,%%d)'," |
| 31812 | "$dir||name,quote(%s),mode,mtime)) IS NULL\n" |
| 31813 | " END\n" /* ^^--- azExtraArg */ |
| 31814 | " FROM dest CROSS JOIN %s\n" |
| 31815 | " WHERE (%s)\n" /* ^^-- pAr->zSrcTable */ |
| 31816 | /* ^^--- zWhere */ |
| 31817 | " AND (CASE $pass WHEN 0 THEN (mode&0xf000)<>0xa000\n" |
| 31818 | " WHEN 1 THEN (mode&0xf000)=0xa000\n" |
| 31819 | " ELSE data IS NULL END)\n" |
| 31820 | " AND dpath=substr(realpath($dir||name),1,dlen)\n" /* No escapes */ |
| 31821 | " AND name NOT GLOB '*..[/\\]*'\n"; /* No /../ in paths */ |
| 31822 | |
| 31823 | const char *azExtraArg[] = { |
| 31824 | "sqlar_uncompress(data, sz)", |
| @@ -31714,39 +31845,48 @@ | |
| 31845 | } |
| 31846 | if( zDir==0 ) rc = SQLITE_NOMEM; |
| 31847 | } |
| 31848 | |
| 31849 | shellPreparePrintf(pAr->db, &rc, &pSql, zSql1, |
| 31850 | azExtraArg[pAr->bZip], |
| 31851 | azExtraArg[pAr->bZip], |
| 31852 | pAr->zSrcTable, |
| 31853 | zWhere |
| 31854 | ); |
| 31855 | |
| 31856 | if( rc==SQLITE_OK ){ |
| 31857 | j = sqlite3_bind_parameter_index(pSql, "$dir"); |
| 31858 | sqlite3_bind_text(pSql, j, zDir, -1, SQLITE_STATIC); |
| 31859 | j = sqlite3_bind_parameter_index(pSql, "$dryrun"); |
| 31860 | sqlite3_bind_int(pSql, j, pAr->bDryRun); |
| 31861 | |
| 31862 | /* Run the SELECT statement twice |
| 31863 | ** (0) writefile() files and directories |
| 31864 | ** (1) writefile() symlinks |
| 31865 | ** (2) writefile() for directory again |
| 31866 | ** The third pass is so that the timestamps for extracted directories |
| 31867 | ** will be reset to the value in the archive, since populating them |
| 31868 | ** in the first pass will have changed the timestamp. */ |
| 31869 | for(i=0; i<3; i++){ |
| 31870 | if( pAr->bDryRun>=2 ){ |
| 31871 | cli_printf(pAr->out, "*** BEGIN PASS %d ***\n", i+1); |
| 31872 | } |
| 31873 | j = sqlite3_bind_parameter_index(pSql, "$pass"); |
| 31874 | sqlite3_bind_int(pSql, j, i); |
| 31875 | if( pAr->bDryRun && i==0 ){ |
| 31876 | cli_printf(pAr->out, "%s\n", sqlite3_sql(pSql)); |
| 31877 | } |
| 31878 | while( rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pSql) ){ |
| 31879 | if( i==0 && pAr->bVerbose ){ |
| 31880 | cli_printf(pAr->out, "%s\n", sqlite3_column_text(pSql, 0)); |
| 31881 | } |
| 31882 | } |
| 31883 | if( pAr->bDryRun==1 ) break; |
| 31884 | shellReset(&rc, pSql); |
| 31885 | if( pAr->bDryRun>=2 ){ |
| 31886 | cli_printf(pAr->out, "*** END PASS %d ***\n", i+1); |
| 31887 | } |
| 31888 | } |
| 31889 | shellFinalize(&rc, pSql); |
| 31890 | } |
| 31891 | |
| 31892 | sqlite3_free(zDir); |
| @@ -32257,11 +32397,11 @@ | |
| 32397 | ; |
| 32398 | static const char * const zCollectVar = "\ |
| 32399 | SELECT\ |
| 32400 | '('||x'0a'\ |
| 32401 | || group_concat(\ |
| 32402 | cname,\ |
| 32403 | ','||iif((cpos-1)%4>0, ' ', x'0a'||' '))\ |
| 32404 | ||')' AS ColsSpec \ |
| 32405 | FROM (\ |
| 32406 | SELECT cpos, printf('\"%w\"',printf('%!.*s%s', nlen-chop,name,suff)) AS cname \ |
| 32407 | FROM ColNames ORDER BY cpos\ |
| @@ -33102,30 +33242,14 @@ | |
| 33242 | }else if( optionMatch(z,"limits") ){ |
| 33243 | if( (++i)>=nArg ){ |
| 33244 | dotCmdError(p, i-1, "missing argument", 0); |
| 33245 | return 1; |
| 33246 | } |
| 33247 | if( modeSetLimit(p, azArg[i]) ){ |
| 33248 | dotCmdError(p, i, "bad argument", "Should be \"on\" or \"off\" or " |
| 33249 | "\"L,C,T\" where L, C, and T are unsigned integers"); |
| 33250 | return 1; |
| 33251 | } |
| 33252 | chng = 1; |
| 33253 | }else if( optionMatch(z,"list") ){ |
| 33254 | int ii; |
| 33255 | cli_puts("available modes:", p->out); |
| @@ -34339,11 +34463,16 @@ | |
| 34463 | if( c=='d' && n>=3 && cli_strncmp(azArg[0], "dbinfo", n)==0 ){ |
| 34464 | rc = shell_dbinfo_command(p, nArg, azArg); |
| 34465 | }else |
| 34466 | #endif /* SQLITE_SHELL_HAVE_RECOVER */ |
| 34467 | |
| 34468 | if( c=='d' && n>=3 && cli_strncmp(azArg[0], "dbtotxt", n)==0 ){ |
| 34469 | open_db(p, 0); |
| 34470 | rc = shell_dbtotxt_command(p, nArg, azArg); |
| 34471 | }else |
| 34472 | |
| 34473 | if( c=='d' && n==8 && cli_strncmp(azArg[0], "diskused", n)==0 ){ |
| 34474 | const char *zSchema = 0; |
| 34475 | int ii; |
| 34476 | char *zSql; |
| 34477 | open_db(p, 0); |
| 34478 | for(ii=1; ii<nArg; ii++){ |
| @@ -34358,27 +34487,19 @@ | |
| 34487 | rc = 1; |
| 34488 | goto meta_command_exit; |
| 34489 | } |
| 34490 | zSchema = z; |
| 34491 | } |
| 34492 | zSql = sqlite3_mprintf("SELECT diskused(%Q)", zSchema); |
| 34493 | shell_check_oom(zSql); |
| 34494 | modePush(p); |
| 34495 | modeChange(p, MODE_BATCH); |
| 34496 | shell_exec(p, zSql, 0); |
| 34497 | modePop(p); |
| 34498 | sqlite3_free(zSql); |
| 34499 | }else |
| 34500 | |
| 34501 | if( c=='d' && cli_strncmp(azArg[0], "dump", n)==0 ){ |
| 34502 | char *zLike = 0; |
| 34503 | char *zSql; |
| 34504 | int i; |
| 34505 | int savedShellFlags = p->shellFlgs; |
| @@ -35491,10 +35612,26 @@ | |
| 35612 | }else |
| 35613 | if( strcmp(z,"-show")==0 ){ |
| 35614 | cli_printf(stdout,"Main prompt: '%s'\n", prompt_string(p, 0)); |
| 35615 | cli_printf(stdout,"Continuation: '%s'\n", prompt_string(p, 1)); |
| 35616 | }else |
| 35617 | #ifndef SQLITE_NO_COLOR |
| 35618 | if( strcmp(z,"-color")==0 ){ |
| 35619 | #ifdef _WIN32 |
| 35620 | _putenv("NO_COLOR="); |
| 35621 | #else |
| 35622 | unsetenv("NO_COLOR"); |
| 35623 | #endif |
| 35624 | }else |
| 35625 | if( strcmp(z,"-no-color")==0 ){ |
| 35626 | #ifdef _WIN32 |
| 35627 | _putenv("NO_COLOR=1"); |
| 35628 | #else |
| 35629 | setenv("NO_COLOR","1",1); |
| 35630 | #endif |
| 35631 | }else |
| 35632 | #endif |
| 35633 | if( strcmp(z,"-")==0 ){ |
| 35634 | noOpt = 1; |
| 35635 | }else |
| 35636 | { |
| 35637 | dotCmdError(p, i, "unknown option", 0); |
| @@ -35505,10 +35642,11 @@ | |
| 35642 | dotCmdError(p, i, "extra argument", 0); |
| 35643 | rc = 1; |
| 35644 | goto meta_command_exit; |
| 35645 | }else if( !p->dot.abQuot[i] && sqlite3_strglob("*[^a-z]*",z)!=0 ){ |
| 35646 | dotCmdError(p, i, "use quotes around the prompt string", 0); |
| 35647 | rc = 1; |
| 35648 | }else{ |
| 35649 | free(p->azPrompt[cnt]); |
| 35650 | p->azPrompt[cnt] = strdup(z); |
| 35651 | cnt++; |
| 35652 | } |
| @@ -37717,17 +37855,17 @@ | |
| 37855 | " -- treat no subsequent arguments as options\n" |
| 37856 | #if defined(SQLITE_HAVE_ZLIB) && !defined(SQLITE_OMIT_VIRTUALTABLE) |
| 37857 | " -A ARGS... run \".archive ARGS\" and exit\n" |
| 37858 | #endif |
| 37859 | " -append append the database to the end of the file\n" |
| 37860 | " -ascii set '.mode ascii'\n" |
| 37861 | " -bail stop after hitting an error\n" |
| 37862 | " -batch force batch I/O\n" |
| 37863 | " -box set '.mode box'\n" |
| 37864 | " -cmd COMMAND run \"COMMAND\" before reading stdin\n" |
| 37865 | " -column set '.mode column'\n" |
| 37866 | " -csv set '.mode csv -limits off'\n" |
| 37867 | #if !defined(SQLITE_OMIT_DESERIALIZE) |
| 37868 | " -deserialize open the database using sqlite3_deserialize()\n" |
| 37869 | #endif |
| 37870 | " -echo print inputs before execution\n" |
| 37871 | " -escape T ctrl-char escape; T is one of: symbol, ascii, off\n" |
| @@ -37735,18 +37873,18 @@ | |
| 37873 | " -[no]header turn headers on or off\n" |
| 37874 | #if defined(SQLITE_ENABLE_MEMSYS3) || defined(SQLITE_ENABLE_MEMSYS5) |
| 37875 | " -heap SIZE Size of heap for memsys3 or memsys5\n" |
| 37876 | #endif |
| 37877 | " -help show this message\n" |
| 37878 | " -html set '.mode html'\n" |
| 37879 | " -ifexists only open if database already exists\n" |
| 37880 | " -interactive force interactive I/O\n" |
| 37881 | " -json set '.mode json'\n" |
| 37882 | " -line set '.mode line'\n" |
| 37883 | " -list set '.mode list'\n" |
| 37884 | " -lookaside SIZE N use N entries of SZ bytes for lookaside memory\n" |
| 37885 | " -markdown set '.mode markdown'\n" |
| 37886 | #if !defined(SQLITE_OMIT_DESERIALIZE) |
| 37887 | " -maxsize N maximum size for a --deserialize database\n" |
| 37888 | #endif |
| 37889 | " -memtrace trace all memory allocations and deallocations\n" |
| 37890 | " -mmap N default mmap size set to N\n" |
| @@ -37759,21 +37897,21 @@ | |
| 37897 | " -nonce STRING set the safe-mode escape nonce\n" |
| 37898 | " -no-rowid-in-view Disable rowid-in-view using sqlite3_config()\n" |
| 37899 | " -nullvalue TEXT set text string for NULL values. Default ''\n" |
| 37900 | " -pagecache SIZE N use N slots of SZ bytes each for page cache memory\n" |
| 37901 | " -pcachetrace trace all page cache operations\n" |
| 37902 | " -quote set '.mode quote'\n" |
| 37903 | " -readonly open the database read-only\n" |
| 37904 | " -safe enable safe-mode\n" |
| 37905 | " -screenwidth N use N as the default screenwidth \n" |
| 37906 | " -separator SEP set output column separator. Default: '|'\n" |
| 37907 | #ifdef SQLITE_ENABLE_SORTER_REFERENCES |
| 37908 | " -sorterref SIZE sorter references threshold size\n" |
| 37909 | #endif |
| 37910 | " -stats print memory stats before each finalize\n" |
| 37911 | " -table set '.mode table'\n" |
| 37912 | " -tabs set '.mode tabs'\n" |
| 37913 | " -unsafe-testing allow unsafe commands and modes for testing\n" |
| 37914 | " -version show SQLite version\n" |
| 37915 | " -vfs NAME use NAME as the default VFS\n" |
| 37916 | " -vfstrace enable tracing of all VFS calls\n" |
| 37917 | #ifdef SQLITE_HAVE_ZLIB |
| @@ -37801,10 +37939,23 @@ | |
| 37939 | sputz(stdout, "WARNING: attempt to configure SQLite after" |
| 37940 | " initialization.\n"); |
| 37941 | } |
| 37942 | } |
| 37943 | |
| 37944 | #if HAVE_EDITLINE |
| 37945 | /* |
| 37946 | ** https://sqlite.org/forum/forumpost/aad7a634916ff050: |
| 37947 | ** |
| 37948 | ** Calling setlocale(LC_...,"") is required to get libedit to accept |
| 37949 | ** non-ASCII input. |
| 37950 | */ |
| 37951 | #define DO_SET_LOCALE 1 |
| 37952 | #include <locale.h> |
| 37953 | #else |
| 37954 | #define DO_SET_LOCALE 0 |
| 37955 | #endif |
| 37956 | |
| 37957 | /* |
| 37958 | ** Initialize the state information in data |
| 37959 | */ |
| 37960 | static void main_init(ShellState *p) { |
| 37961 | memset(p, 0, sizeof(*p)); |
| @@ -37825,10 +37976,14 @@ | |
| 37976 | #else |
| 37977 | /* No \001...\002 escapes required for linenoise or when not using a |
| 37978 | ** command-line editing library */ |
| 37979 | p->bDelimitNonprint = 0; |
| 37980 | #endif |
| 37981 | #if DO_SET_LOCALE |
| 37982 | setlocale(LC_CTYPE,""); |
| 37983 | #endif |
| 37984 | #undef DO_SET_LOCALE |
| 37985 | } |
| 37986 | |
| 37987 | /* |
| 37988 | ** Output text to the console in a font that attracts extra attention. |
| 37989 | */ |
| @@ -37854,11 +38009,11 @@ | |
| 38009 | } |
| 38010 | |
| 38011 | /* |
| 38012 | ** The callback from atexit(). |
| 38013 | */ |
| 38014 | static void SQLITE_CDECL abnormalExit(void){ |
| 38015 | if( seenInterrupt ) eputz("Program interrupted.\n"); |
| 38016 | if( globalShellState ){ |
| 38017 | clearTempFile(globalShellState, 1, 1); |
| 38018 | } |
| 38019 | } |
| @@ -38065,11 +38220,11 @@ | |
| 38220 | stdin_is_interactive = 0; |
| 38221 | nCmd++; |
| 38222 | azCmd = realloc(azCmd, sizeof(azCmd[0])*nCmd); |
| 38223 | shell_check_oom(azCmd); |
| 38224 | aiCmd = realloc(aiCmd, sizeof(aiCmd[0])*nCmd); |
| 38225 | shell_check_oom(aiCmd); |
| 38226 | azCmd[nCmd-1] = z; |
| 38227 | aiCmd[nCmd-1] = i; |
| 38228 | } |
| 38229 | continue; |
| 38230 | } |
| @@ -38354,10 +38509,11 @@ | |
| 38509 | modeChange(&data, MODE_Psql); |
| 38510 | }else if( cli_strcmp(z,"-box")==0 ){ |
| 38511 | modeChange(&data, MODE_Box); |
| 38512 | }else if( cli_strcmp(z,"-csv")==0 ){ |
| 38513 | modeChange(&data, MODE_Csv); |
| 38514 | modeSetLimit(&data, "off"); |
| 38515 | }else if( cli_strcmp(z,"-escape")==0 && i+1<argc ){ |
| 38516 | /* See similar code at tag-20250224-1 */ |
| 38517 | const char *zEsc = argv[++i]; |
| 38518 | int k; |
| 38519 | for(k=0; k<ArraySize(qrfEscNames); k++){ |
| @@ -38412,12 +38568,14 @@ | |
| 38568 | }else if( cli_strcmp(z,"-nullvalue")==0 ){ |
| 38569 | modeSetStr(&data.mode.spec.zNull, |
| 38570 | cmdline_option_value(argc,argv,++i)); |
| 38571 | }else if( cli_strcmp(z,"-header")==0 ){ |
| 38572 | data.mode.spec.bTitles = QRF_Yes; |
| 38573 | data.mode.mFlags |= MFLG_HDR; |
| 38574 | }else if( cli_strcmp(z,"-noheader")==0 ){ |
| 38575 | data.mode.spec.bTitles = QRF_No; |
| 38576 | data.mode.mFlags |= MFLG_HDR; |
| 38577 | }else if( cli_strcmp(z,"-echo")==0 ){ |
| 38578 | data.mode.mFlags |= MFLG_ECHO; |
| 38579 | }else if( cli_strcmp(z,"-eqp")==0 ){ |
| 38580 | data.mode.autoEQP = AUTOEQP_on; |
| 38581 | }else if( cli_strcmp(z,"-eqpfull")==0 ){ |
| 38582 |
+1551
-532
| --- extsrc/sqlite3.c | ||
| +++ extsrc/sqlite3.c | ||
| @@ -16,11 +16,11 @@ | ||
| 16 | 16 | ** if you want a wrapper to interface SQLite with your choice of programming |
| 17 | 17 | ** language. The code for the "sqlite3" command-line shell is also in a |
| 18 | 18 | ** separate file. This file contains only code for the core SQLite library. |
| 19 | 19 | ** |
| 20 | 20 | ** The content in this amalgamation comes from Fossil check-in |
| 21 | -** 7e4134e3ff1ca8712f5fc78fadae66554945 with changes in files: | |
| 21 | +** 3f3fb9b638f59ad982beafb7c117f24ddd3d with changes in files: | |
| 22 | 22 | ** |
| 23 | 23 | ** |
| 24 | 24 | */ |
| 25 | 25 | #ifndef SQLITE_AMALGAMATION |
| 26 | 26 | #define SQLITE_CORE 1 |
| @@ -467,14 +467,14 @@ | ||
| 467 | 467 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 468 | 468 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 469 | 469 | */ |
| 470 | 470 | #define SQLITE_VERSION "3.54.0" |
| 471 | 471 | #define SQLITE_VERSION_NUMBER 3054000 |
| 472 | -#define SQLITE_SOURCE_ID "2026-05-04 10:14:13 7e4134e3ff1ca8712f5fc78fadae665549450988dc43af27c7fe0c77f10ce3fb" | |
| 472 | +#define SQLITE_SOURCE_ID "2026-06-16 13:43:08 3f3fb9b638f59ad982beafb7c117f24ddd3da612e62c862510805fa672ffae06" | |
| 473 | 473 | #define SQLITE_SCM_BRANCH "trunk" |
| 474 | 474 | #define SQLITE_SCM_TAGS "" |
| 475 | -#define SQLITE_SCM_DATETIME "2026-05-04T10:14:13.819Z" | |
| 475 | +#define SQLITE_SCM_DATETIME "2026-06-16T13:43:08.110Z" | |
| 476 | 476 | |
| 477 | 477 | /* |
| 478 | 478 | ** CAPI3REF: Run-Time Library Version Numbers |
| 479 | 479 | ** KEYWORDS: sqlite3_version sqlite3_sourceid |
| 480 | 480 | ** |
| @@ -4373,12 +4373,11 @@ | ||
| 4373 | 4373 | ** parameter on F or if the value of P does not match any of the |
| 4374 | 4374 | ** above, then sqlite3_uri_boolean(F,P,B) returns (B!=0). |
| 4375 | 4375 | ** |
| 4376 | 4376 | ** The sqlite3_uri_int64(F,P,D) routine converts the value of P into a |
| 4377 | 4377 | ** 64-bit signed integer and returns that integer, or D if P does not |
| 4378 | -** exist. If the value of P is something other than an integer, then | |
| 4379 | -** zero is returned. | |
| 4378 | +** exist or ff the value of P is something other than an integer. | |
| 4380 | 4379 | ** |
| 4381 | 4380 | ** The sqlite3_uri_key(F,N) returns a pointer to the name (not |
| 4382 | 4381 | ** the value) of the N-th query parameter for filename F, or a NULL |
| 4383 | 4382 | ** pointer if N is less than zero or greater than the number of query |
| 4384 | 4383 | ** parameters minus 1. The N value is zero-based so N should be 0 to obtain |
| @@ -4697,11 +4696,12 @@ | ||
| 4697 | 4696 | ** <dd>The maximum number of columns in a table definition or in the |
| 4698 | 4697 | ** result set of a [SELECT] or the maximum number of columns in an index |
| 4699 | 4698 | ** or in an ORDER BY or GROUP BY clause.</dd>)^ |
| 4700 | 4699 | ** |
| 4701 | 4700 | ** [[SQLITE_LIMIT_EXPR_DEPTH]] ^(<dt>SQLITE_LIMIT_EXPR_DEPTH</dt> |
| 4702 | -** <dd>The maximum depth of the parse tree on any expression.</dd>)^ | |
| 4701 | +** <dd>The maximum depth of the parse tree on any expression and | |
| 4702 | +** the maximum nesting depth for subqueries and VIEWs</dd>)^ | |
| 4703 | 4703 | ** |
| 4704 | 4704 | ** [[SQLITE_LIMIT_PARSER_DEPTH]] ^(<dt>SQLITE_LIMIT_PARSER_DEPTH</dt> |
| 4705 | 4705 | ** <dd>The maximum depth of the LALR(1) parser stack used to analyze |
| 4706 | 4706 | ** input SQL statements.</dd>)^ |
| 4707 | 4707 | ** |
| @@ -4728,11 +4728,12 @@ | ||
| 4728 | 4728 | ** [[SQLITE_LIMIT_VARIABLE_NUMBER]] |
| 4729 | 4729 | ** ^(<dt>SQLITE_LIMIT_VARIABLE_NUMBER</dt> |
| 4730 | 4730 | ** <dd>The maximum index number of any [parameter] in an SQL statement.)^ |
| 4731 | 4731 | ** |
| 4732 | 4732 | ** [[SQLITE_LIMIT_TRIGGER_DEPTH]] ^(<dt>SQLITE_LIMIT_TRIGGER_DEPTH</dt> |
| 4733 | -** <dd>The maximum depth of recursion for triggers.</dd>)^ | |
| 4733 | +** <dd>The maximum depth of recursion for triggers, and the maximum | |
| 4734 | +** nesting depth for separate triggers.</dd>)^ | |
| 4734 | 4735 | ** |
| 4735 | 4736 | ** [[SQLITE_LIMIT_WORKER_THREADS]] ^(<dt>SQLITE_LIMIT_WORKER_THREADS</dt> |
| 4736 | 4737 | ** <dd>The maximum number of auxiliary worker threads that a single |
| 4737 | 4738 | ** [prepared statement] may start.</dd>)^ |
| 4738 | 4739 | ** </dl> |
| @@ -11534,12 +11535,23 @@ | ||
| 11534 | 11535 | ** reopen S as an in-memory database based on the serialization |
| 11535 | 11536 | ** contained in P. If S is a NULL pointer, the main database is |
| 11536 | 11537 | ** used. The serialized database P is N bytes in size. M is the size |
| 11537 | 11538 | ** of the buffer P, which might be larger than N. If M is larger than |
| 11538 | 11539 | ** N, and the SQLITE_DESERIALIZE_READONLY bit is not set in F, then |
| 11539 | -** SQLite is permitted to add content to the in-memory database as | |
| 11540 | -** long as the total size does not exceed M bytes. | |
| 11540 | +** SQLite is permitted to add content to the in-memory database, in | |
| 11541 | +** page-sized chunks, as long as the total size does not exceed M bytes. | |
| 11542 | +** | |
| 11543 | +** The parameter M must be greater than or equal to N. Ideally, M | |
| 11544 | +** should have a value which is N+(512×K)+20 where K determines how | |
| 11545 | +** must extra space is available to hold new content as the database | |
| 11546 | +** grows. K can be 0 if the database is read-only. | |
| 11547 | +** | |
| 11548 | +** If the database content in P is malformed in a malicious way then | |
| 11549 | +** it is possible that SQLite might try to read a few more than N bytes | |
| 11550 | +** from P. If the veracity of the database content P is uncertain, | |
| 11551 | +** then applications are advised to allocate about 20 extra bytes on | |
| 11552 | +** the end of the P buffer to avoid a memory error. | |
| 11541 | 11553 | ** |
| 11542 | 11554 | ** If the SQLITE_DESERIALIZE_FREEONCLOSE bit is set in F, then SQLite will |
| 11543 | 11555 | ** invoke sqlite3_free() on the serialization buffer when the database |
| 11544 | 11556 | ** connection closes. If the SQLITE_DESERIALIZE_RESIZEABLE bit is set, then |
| 11545 | 11557 | ** SQLite will try to increase the buffer size using sqlite3_realloc64() |
| @@ -13184,15 +13196,27 @@ | ||
| 13184 | 13196 | ** <dt>SQLITE_CHANGESETAPPLY_FKNOACTION <dd> |
| 13185 | 13197 | ** If this flag it set, then all foreign key constraints in the target |
| 13186 | 13198 | ** database behave as if they were declared with "ON UPDATE NO ACTION ON |
| 13187 | 13199 | ** DELETE NO ACTION", even if they are actually CASCADE, RESTRICT, SET NULL |
| 13188 | 13200 | ** or SET DEFAULT. |
| 13201 | +** | |
| 13202 | +** <dt>SQLITE_CHANGESETAPPLY_NOUPDATELOOP <dd> | |
| 13203 | +** Sometimes, a changeset contains two or more update statements such that | |
| 13204 | +** although after applying all updates the database will contain no | |
| 13205 | +** constraint violations, no single update can be applied before the others. | |
| 13206 | +** The simplest example of this is a pair of UPDATEs that have "swapped" | |
| 13207 | +** two column values with a UNIQUE constraint. | |
| 13208 | +** <p> | |
| 13209 | +** Usually, sqlite3changeset_apply() and similar functions work hard to try | |
| 13210 | +** to find a way to apply such a changeset. However, if this flag is set, | |
| 13211 | +** then all such updates are considered CONSTRAINT conflicts. | |
| 13189 | 13212 | */ |
| 13190 | 13213 | #define SQLITE_CHANGESETAPPLY_NOSAVEPOINT 0x0001 |
| 13191 | 13214 | #define SQLITE_CHANGESETAPPLY_INVERT 0x0002 |
| 13192 | 13215 | #define SQLITE_CHANGESETAPPLY_IGNORENOOP 0x0004 |
| 13193 | 13216 | #define SQLITE_CHANGESETAPPLY_FKNOACTION 0x0008 |
| 13217 | +#define SQLITE_CHANGESETAPPLY_NOUPDATELOOP 0x0010 | |
| 13194 | 13218 | |
| 13195 | 13219 | /* |
| 13196 | 13220 | ** CAPI3REF: Constants Passed To The Conflict Handler |
| 13197 | 13221 | ** |
| 13198 | 13222 | ** Values that may be passed as the second argument to a conflict-handler. |
| @@ -15798,10 +15822,17 @@ | ||
| 15798 | 15822 | */ |
| 15799 | 15823 | #ifndef offsetof |
| 15800 | 15824 | # define offsetof(ST,M) ((size_t)((char*)&((ST*)0)->M - (char*)0)) |
| 15801 | 15825 | #endif |
| 15802 | 15826 | |
| 15827 | +/* | |
| 15828 | +** sizeof64() is like sizeof(), but always returns a 64-bit value, even | |
| 15829 | +** on 32-bit builds. This can help to avoid overflow by ensuring 64-bit | |
| 15830 | +** arithmetic is used consistently in both 32-bit and 64-bit builds. | |
| 15831 | +*/ | |
| 15832 | +#define sizeof64(X) ((sqlite3_int64)sizeof(X)) | |
| 15833 | + | |
| 15803 | 15834 | /* |
| 15804 | 15835 | ** Work around C99 "flex-array" syntax for pre-C99 compilers, so as |
| 15805 | 15836 | ** to avoid complaints from -fsanitize=strict-bounds. |
| 15806 | 15837 | */ |
| 15807 | 15838 | #if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) |
| @@ -18705,11 +18736,11 @@ | ||
| 18705 | 18736 | int aLimit[SQLITE_N_LIMIT]; /* Limits */ |
| 18706 | 18737 | int nMaxSorterMmap; /* Maximum size of regions mapped by sorter */ |
| 18707 | 18738 | struct sqlite3InitInfo { /* Information used during initialization */ |
| 18708 | 18739 | Pgno newTnum; /* Rootpage of table being initialized */ |
| 18709 | 18740 | u8 iDb; /* Which db file is being initialized */ |
| 18710 | - u8 busy; /* TRUE if currently initializing */ | |
| 18741 | + u8 busy; /* TRUE if initing. 2 if due to ADD COLUMN */ | |
| 18711 | 18742 | unsigned orphanTrigger : 1; /* Last statement is orphaned TEMP trigger */ |
| 18712 | 18743 | unsigned imposterTable : 2; /* Building an imposter table */ |
| 18713 | 18744 | unsigned reopenMemdb : 1; /* ATTACH is really a reopen using MemDB */ |
| 18714 | 18745 | const char **azInit; /* "type", "name", and "tbl_name" columns */ |
| 18715 | 18746 | } init; |
| @@ -20917,10 +20948,11 @@ | ||
| 20917 | 20948 | int nTab; /* Number of previously allocated VDBE cursors */ |
| 20918 | 20949 | int nMem; /* Number of memory cells used so far */ |
| 20919 | 20950 | int szOpAlloc; /* Bytes of memory space allocated for Vdbe.aOp[] */ |
| 20920 | 20951 | int iSelfTab; /* Table associated with an index on expr, or negative |
| 20921 | 20952 | ** of the base register during check-constraint eval */ |
| 20953 | + int nNestSel; /* Number of nested SELECT statements and/or VIEWs */ | |
| 20922 | 20954 | int nLabel; /* The *negative* of the number of labels used */ |
| 20923 | 20955 | int nLabelAlloc; /* Number of slots in aLabel */ |
| 20924 | 20956 | int *aLabel; /* Space to hold the labels */ |
| 20925 | 20957 | ExprList *pConstExpr;/* Constant expressions */ |
| 20926 | 20958 | IndexedExpr *pIdxEpr;/* List of expressions used by active indexes */ |
| @@ -21256,11 +21288,11 @@ | ||
| 21256 | 21288 | */ |
| 21257 | 21289 | #define INITFLAG_AlterMask 0x0007 /* Types of ALTER */ |
| 21258 | 21290 | #define INITFLAG_AlterRename 0x0001 /* Reparse after a RENAME */ |
| 21259 | 21291 | #define INITFLAG_AlterDrop 0x0002 /* Reparse after a DROP COLUMN */ |
| 21260 | 21292 | #define INITFLAG_AlterAdd 0x0003 /* Reparse after an ADD COLUMN */ |
| 21261 | -#define INITFLAG_AlterDropCons 0x0004 /* Reparse after an ADD COLUMN */ | |
| 21293 | +#define INITFLAG_AlterDropCons 0x0004 /* Reparse after a DROP CONSTRAINT */ | |
| 21262 | 21294 | |
| 21263 | 21295 | /* Tuning parameters are set using SQLITE_TESTCTRL_TUNE and are controlled |
| 21264 | 21296 | ** on debug-builds of the CLI using ".testctrl tune ID VALUE". Tuning |
| 21265 | 21297 | ** parameters are for temporary use during development, to help find |
| 21266 | 21298 | ** optimal values for parameters in the query planner. The should not |
| @@ -22509,11 +22541,19 @@ | ||
| 22509 | 22541 | SQLITE_PRIVATE void sqlite3Reindex(Parse*, Token*, Token*); |
| 22510 | 22542 | SQLITE_PRIVATE void sqlite3AlterFunctions(void); |
| 22511 | 22543 | SQLITE_PRIVATE void sqlite3AlterRenameTable(Parse*, SrcList*, Token*); |
| 22512 | 22544 | SQLITE_PRIVATE void sqlite3AlterRenameColumn(Parse*, SrcList*, Token*, Token*); |
| 22513 | 22545 | SQLITE_PRIVATE void sqlite3AlterDropConstraint(Parse*,SrcList*,Token*,Token*); |
| 22514 | -SQLITE_PRIVATE void sqlite3AlterAddConstraint(Parse*,SrcList*,Token*,Token*,const char*,int); | |
| 22546 | +SQLITE_PRIVATE void sqlite3AlterAddConstraint( | |
| 22547 | + Parse *pParse, /* Parse context */ | |
| 22548 | + SrcList *pSrc, /* Table to add constraint to */ | |
| 22549 | + Token *pFirst, /* First token of new constraint */ | |
| 22550 | + Token *pName, /* Name of new constraint. NULL if name omitted. */ | |
| 22551 | + const char *zExpr, /* Text of CHECK expression */ | |
| 22552 | + int nExpr, /* Size of pExpr in bytes */ | |
| 22553 | + Expr *pExpr /* The parsed CHECK expression */ | |
| 22554 | +); | |
| 22515 | 22555 | SQLITE_PRIVATE void sqlite3AlterSetNotNull(Parse*, SrcList*, Token*, Token*); |
| 22516 | 22556 | SQLITE_PRIVATE i64 sqlite3GetToken(const unsigned char *, int *); |
| 22517 | 22557 | SQLITE_PRIVATE void sqlite3NestedParse(Parse*, const char*, ...); |
| 22518 | 22558 | SQLITE_PRIVATE void sqlite3ExpirePreparedStatements(sqlite3*, int); |
| 22519 | 22559 | SQLITE_PRIVATE void sqlite3CodeRhsOfIN(Parse*, Expr*, int, int); |
| @@ -32413,12 +32453,14 @@ | ||
| 32413 | 32453 | #define etSRCITEM 12 /* a pointer to a SrcItem */ |
| 32414 | 32454 | #define etPOINTER 13 /* The %p conversion */ |
| 32415 | 32455 | #define etESCAPE_w 14 /* %w -> Strings with '\"' doubled */ |
| 32416 | 32456 | #define etORDINAL 15 /* %r -> 1st, 2nd, 3rd, 4th, etc. English only */ |
| 32417 | 32457 | #define etDECIMAL 16 /* %d or %u, but not %x, %o */ |
| 32458 | +#define etESCAPE_j 17 /* %j -> JSON string literal w/o "..." */ | |
| 32459 | +#define etESCAPE_J 18 /* %J -> JSON string literal with "..." */ | |
| 32418 | 32460 | |
| 32419 | -#define etINVALID 17 /* Any unrecognized conversion type */ | |
| 32461 | +#define etINVALID 19 /* Any unrecognized conversion type */ | |
| 32420 | 32462 | |
| 32421 | 32463 | |
| 32422 | 32464 | /* |
| 32423 | 32465 | ** An "etByte" is an 8-bit unsigned value. |
| 32424 | 32466 | */ |
| @@ -32444,24 +32486,24 @@ | ||
| 32444 | 32486 | #define FLAG_SIGNED 1 /* True if the value to convert is signed */ |
| 32445 | 32487 | #define FLAG_STRING 4 /* Allow infinite precision */ |
| 32446 | 32488 | |
| 32447 | 32489 | /* |
| 32448 | 32490 | ** The table is searched by hash. In the case of %C where C is the character |
| 32449 | -** and that character has ASCII value j, then the hash is j%23. | |
| 32491 | +** and that character has ASCII value j, then the hash is j%25. | |
| 32450 | 32492 | ** |
| 32451 | 32493 | ** The order of the entries in fmtinfo[] and the hash chain was entered |
| 32452 | 32494 | ** manually, but based on the output of the following TCL script: |
| 32453 | 32495 | */ |
| 32454 | 32496 | #if 0 /***** Beginning of script ******/ |
| 32455 | -foreach c {d s g z q Q w c o u x X f e E G i n % p T S r} { | |
| 32497 | +foreach c {d s g z q Q w c o u x X f e E G i n % p T S r J j} { | |
| 32456 | 32498 | scan $c %c x |
| 32457 | 32499 | set n($c) $x |
| 32458 | 32500 | } |
| 32459 | 32501 | set mx [llength [array names n]] |
| 32460 | 32502 | puts "count: $mx" |
| 32461 | 32503 | |
| 32462 | -set mx 27 | |
| 32504 | +set mx 25 | |
| 32463 | 32505 | puts "*********** mx=$mx ************" |
| 32464 | 32506 | for {set r 0} {$r<$mx} {incr r} { |
| 32465 | 32507 | puts -nonewline [format %2d: $r] |
| 32466 | 32508 | foreach c [array names n] { |
| 32467 | 32509 | if {($n($c))%$mx==$r} {puts -nonewline " $c"} |
| @@ -32469,35 +32511,38 @@ | ||
| 32469 | 32511 | puts "" |
| 32470 | 32512 | } |
| 32471 | 32513 | #endif /***** End of script ********/ |
| 32472 | 32514 | |
| 32473 | 32515 | static const char aDigits[] = "0123456789ABCDEF0123456789abcdef"; |
| 32516 | +static const char aHex[] = "0123456789abcdef"; | |
| 32474 | 32517 | static const char aPrefix[] = "-x0\000X0"; |
| 32475 | -static const et_info fmtinfo[23] = { | |
| 32476 | - /* 0 */ { 's', 0, 4, etSTRING, 0, 0, 1 }, | |
| 32477 | - /* 1 */ { 'E', 0, 1, etEXP, 14, 0, 0 }, /* Hash: 0 */ | |
| 32478 | - /* 2 */ { 'u', 10, 0, etDECIMAL, 0, 0, 3 }, | |
| 32479 | - /* 3 */ { 'G', 0, 1, etGENERIC, 14, 0, 0 }, /* Hash: 2 */ | |
| 32480 | - /* 4 */ { 'w', 0, 4, etESCAPE_w, 0, 0, 0 }, | |
| 32481 | - /* 5 */ { 'x', 16, 0, etRADIX, 16, 1, 0 }, | |
| 32482 | - /* 6 */ { 'c', 0, 0, etCHARX, 0, 0, 0 }, /* Hash: 7 */ | |
| 32483 | - /* 7 */ { 'z', 0, 4, etDYNSTRING, 0, 0, 6 }, | |
| 32484 | - /* 8 */ { 'd', 10, 1, etDECIMAL, 0, 0, 0 }, | |
| 32485 | - /* 9 */ { 'e', 0, 1, etEXP, 30, 0, 0 }, | |
| 32486 | - /* 10 */ { 'f', 0, 1, etFLOAT, 0, 0, 0 }, | |
| 32487 | - /* 11 */ { 'g', 0, 1, etGENERIC, 30, 0, 0 }, | |
| 32488 | - /* 12 */ { 'Q', 0, 4, etESCAPE_Q, 0, 0, 0 }, | |
| 32489 | - /* 13 */ { 'i', 10, 1, etDECIMAL, 0, 0, 0 }, | |
| 32490 | - /* 14 */ { '%', 0, 0, etPERCENT, 0, 0, 16 }, | |
| 32491 | - /* 15 */ { 'T', 0, 0, etTOKEN, 0, 0, 0 }, | |
| 32492 | - /* 16 */ { 'S', 0, 0, etSRCITEM, 0, 0, 0 }, /* Hash: 14 */ | |
| 32493 | - /* 17 */ { 'X', 16, 0, etRADIX, 0, 4, 0 }, /* Hash: 19 */ | |
| 32494 | - /* 18 */ { 'n', 0, 0, etSIZE, 0, 0, 0 }, | |
| 32495 | - /* 19 */ { 'o', 8, 0, etRADIX, 0, 2, 17 }, | |
| 32496 | - /* 20 */ { 'p', 16, 0, etPOINTER, 0, 1, 0 }, | |
| 32497 | - /* 21 */ { 'q', 0, 4, etESCAPE_q, 0, 0, 0 }, | |
| 32498 | - /* 22 */ { 'r', 10, 1, etORDINAL, 0, 0, 0 } | |
| 32518 | +static const et_info fmtinfo[25] = { | |
| 32519 | + /* 0 */ { 'd', 10, 1, etDECIMAL, 0, 0, 0 }, | |
| 32520 | + /* 1 */ { 'e', 0, 1, etEXP, 30, 0, 0 }, | |
| 32521 | + /* 2 */ { 'f', 0, 1, etFLOAT, 0, 0, 0 }, | |
| 32522 | + /* 3 */ { 'g', 0, 1, etGENERIC, 30, 0, 0 }, | |
| 32523 | + /* 4 */ { 'j', 0, 0, etESCAPE_j, 0, 0, 0 }, /* Hash: 6 */ | |
| 32524 | + /* 5 */ { 'i', 10, 1, etDECIMAL, 0, 0, 0 }, | |
| 32525 | + /* 6 */ { 'Q', 0, 4, etESCAPE_Q, 0, 0, 4 }, | |
| 32526 | + /* 7 */ { 'p', 16, 0, etPOINTER, 0, 1, 0 }, /* Hash: 12 */ | |
| 32527 | + /* 8 */ { 'S', 0, 0, etSRCITEM, 0, 0, 0 }, | |
| 32528 | + /* 9 */ { 'T', 0, 0, etTOKEN, 0, 0, 0 }, | |
| 32529 | + /* 10 */ { 'n', 0, 0, etSIZE, 0, 0, 0 }, | |
| 32530 | + /* 11 */ { 'o', 8, 0, etRADIX, 0, 2, 0 }, | |
| 32531 | + /* 12 */ { '%', 0, 0, etPERCENT, 0, 0, 7 }, | |
| 32532 | + /* 13 */ { 'q', 0, 4, etESCAPE_q, 0, 0, 16 }, | |
| 32533 | + /* 14 */ { 'r', 10, 1, etORDINAL, 0, 0, 0 }, | |
| 32534 | + /* 15 */ { 's', 0, 4, etSTRING, 0, 0, 0 }, | |
| 32535 | + /* 16 */ { 'X', 16, 0, etRADIX, 0, 4, 0 }, /* Hash: 13 */ | |
| 32536 | + /* 17 */ { 'u', 10, 0, etDECIMAL, 0, 0, 0 }, | |
| 32537 | + /* 18 */ { 'w', 0, 4, etESCAPE_w, 0, 0, 0 }, /* Hash: 19 */ | |
| 32538 | + /* 19 */ { 'E', 0, 1, etEXP, 14, 0, 18 }, | |
| 32539 | + /* 20 */ { 'x', 16, 0, etRADIX, 16, 1, 0 }, | |
| 32540 | + /* 21 */ { 'G', 0, 1, etGENERIC, 14, 0, 0 }, | |
| 32541 | + /* 22 */ { 'z', 0, 4, etDYNSTRING, 0, 0, 0 }, | |
| 32542 | + /* 23 */ { 'J', 0, 0, etESCAPE_J, 0, 0, 0 }, /* Hash: 24 */ | |
| 32543 | + /* 24 */ { 'c', 0, 0, etCHARX, 0, 0, 23 } | |
| 32499 | 32544 | }; |
| 32500 | 32545 | |
| 32501 | 32546 | /* Additional Notes: |
| 32502 | 32547 | ** |
| 32503 | 32548 | ** %S Takes a pointer to SrcItem. Shows name or database.name |
| @@ -32754,12 +32799,12 @@ | ||
| 32754 | 32799 | break; |
| 32755 | 32800 | } |
| 32756 | 32801 | } |
| 32757 | 32802 | #else |
| 32758 | 32803 | /* Fast hash-table lookup */ |
| 32759 | - assert( ArraySize(fmtinfo)==23 ); | |
| 32760 | - idx = ((unsigned)c) % 23; | |
| 32804 | + assert( ArraySize(fmtinfo)==25 ); | |
| 32805 | + idx = ((unsigned)c) % 25; | |
| 32761 | 32806 | if( fmtinfo[idx].fmttype==c |
| 32762 | 32807 | || fmtinfo[idx = fmtinfo[idx].iNxt].fmttype==c |
| 32763 | 32808 | ){ |
| 32764 | 32809 | infop = &fmtinfo[idx]; |
| 32765 | 32810 | xtype = infop->type; |
| @@ -33126,11 +33171,11 @@ | ||
| 33126 | 33171 | length = width; |
| 33127 | 33172 | } |
| 33128 | 33173 | |
| 33129 | 33174 | if( zExtra==0 ){ |
| 33130 | 33175 | /* The result is being rendered directory into pAccum. This |
| 33131 | - ** is the command and fast case */ | |
| 33176 | + ** is the common and fast case */ | |
| 33132 | 33177 | pAccum->nChar += length; |
| 33133 | 33178 | zOut[length] = 0; |
| 33134 | 33179 | continue; |
| 33135 | 33180 | }else{ |
| 33136 | 33181 | /* We were unable to render directly into pAccum because we |
| @@ -33246,10 +33291,87 @@ | ||
| 33246 | 33291 | /* Adjust width to account for extra bytes in UTF-8 characters */ |
| 33247 | 33292 | int ii = length - 1; |
| 33248 | 33293 | while( ii>=0 ) if( (bufpt[ii--] & 0xc0)==0x80 ) width++; |
| 33249 | 33294 | } |
| 33250 | 33295 | break; |
| 33296 | + case etESCAPE_j: /* %j: JSON string literal w/o "..." */ | |
| 33297 | + case etESCAPE_J: { /* %J: Generate a JSON string literal */ | |
| 33298 | + char *escarg; | |
| 33299 | + i64 i, j, px, iStart; | |
| 33300 | + unsigned char ch; | |
| 33301 | + | |
| 33302 | + if( bArgList ){ | |
| 33303 | + escarg = getTextArg(pArgList); | |
| 33304 | + }else{ | |
| 33305 | + escarg = va_arg(ap,char*); | |
| 33306 | + } | |
| 33307 | + iStart = sqlite3_str_length(pAccum); | |
| 33308 | + if( escarg==0 ){ | |
| 33309 | + if( xtype==etESCAPE_J ) sqlite3_str_append(pAccum, "null", 4); | |
| 33310 | + }else{ | |
| 33311 | + if( xtype==etESCAPE_J ) sqlite3_str_append(pAccum, "\"", 1); | |
| 33312 | + px = precision; | |
| 33313 | + testcase( px==0 ); | |
| 33314 | + if( px<0 ){ | |
| 33315 | + px = 0x7fffffff; | |
| 33316 | + }else if( flag_altform2 ){ | |
| 33317 | + /* Convert precision from code-points to bytes */ | |
| 33318 | + for(i=0; i<px && escarg[i]; i++){ | |
| 33319 | + if( (escarg[i]&0xc0)==0x80 ) px++; | |
| 33320 | + } | |
| 33321 | + if( i==px ){ | |
| 33322 | + while( (escarg[px]&0xc0)==0x80 ) px++; | |
| 33323 | + } | |
| 33324 | + } | |
| 33325 | + for(i=j=0; i<px; i++){ | |
| 33326 | + if( (ch = ((u8*)escarg)[i])<=0x1f || ch=='"' || ch=='\\' ){ | |
| 33327 | + if( j<i ) sqlite3_str_append(pAccum, &escarg[j], i-j); | |
| 33328 | + j = i+1; | |
| 33329 | + if( ch==0 ) break; | |
| 33330 | + sqlite3_str_appendchar(pAccum, 1, '\\'); | |
| 33331 | + if( ch>0x1f ){ | |
| 33332 | + sqlite3_str_appendchar(pAccum, 1, ch); | |
| 33333 | + }else if( ((1u<<ch)&0x3700)!=0 ){ | |
| 33334 | + ch = "btn?fr"[ch-8]; | |
| 33335 | + sqlite3_str_appendchar(pAccum, 1, ch); | |
| 33336 | + }else{ | |
| 33337 | + sqlite3_str_append(pAccum, "u00", 3); | |
| 33338 | + sqlite3_str_appendchar(pAccum, 1, aHex[ch>>4]); | |
| 33339 | + sqlite3_str_appendchar(pAccum, 1, aHex[ch&0xf]); | |
| 33340 | + } | |
| 33341 | + } | |
| 33342 | + } | |
| 33343 | + if( j<i ) sqlite3_str_append(pAccum, &escarg[j], i-j); | |
| 33344 | + if( xtype==etESCAPE_J ) sqlite3_str_append(pAccum, "\"", 1); | |
| 33345 | + } | |
| 33346 | + if( width>0 && sqlite3_str_errcode(pAccum)==SQLITE_OK ){ | |
| 33347 | + sqlite3_int64 n = sqlite3_str_length(pAccum) - iStart; | |
| 33348 | + sqlite3_int64 len = n; | |
| 33349 | + char *zz; | |
| 33350 | + if( flag_altform2 && n>0 ){ | |
| 33351 | + zz = sqlite3_str_value(pAccum); | |
| 33352 | + for(i=iStart; zz[i]; i++){ | |
| 33353 | + if( (zz[i]&0xc0)==0x80 ) len--; | |
| 33354 | + } | |
| 33355 | + } | |
| 33356 | + if( width>len ){ | |
| 33357 | + sqlite3_int64 sp = width-len; | |
| 33358 | + assert( sp>0 && sp<0x7fffffff ); | |
| 33359 | + sqlite3_str_appendchar(pAccum, (int)sp, ' '); | |
| 33360 | + if( !flag_leftjustify | |
| 33361 | + && n>0 | |
| 33362 | + && sqlite3_str_errcode(pAccum)==0 | |
| 33363 | + ){ | |
| 33364 | + zz = sqlite3_str_value(pAccum); | |
| 33365 | + zz += iStart; | |
| 33366 | + memmove(zz+sp, zz, n); | |
| 33367 | + memset(zz, ' ', sp); | |
| 33368 | + } | |
| 33369 | + } | |
| 33370 | + } | |
| 33371 | + continue; | |
| 33372 | + } | |
| 33251 | 33373 | case etESCAPE_q: /* %q: Escape ' characters */ |
| 33252 | 33374 | case etESCAPE_Q: /* %Q: Escape ' and enclose in '...' */ |
| 33253 | 33375 | case etESCAPE_w: { /* %w: Escape " characters */ |
| 33254 | 33376 | i64 i, j, k, n; |
| 33255 | 33377 | int needQuote = 0; |
| @@ -33288,12 +33410,12 @@ | ||
| 33288 | 33410 | if( flag_alternateform ){ |
| 33289 | 33411 | /* For %#q, do unistr()-style backslash escapes for |
| 33290 | 33412 | ** all control characters, and for backslash itself. |
| 33291 | 33413 | ** For %#Q, do the same but only if there is at least |
| 33292 | 33414 | ** one control character. */ |
| 33293 | - u32 nBack = 0; | |
| 33294 | - u32 nCtrl = 0; | |
| 33415 | + i64 nBack = 0; | |
| 33416 | + i64 nCtrl = 0; | |
| 33295 | 33417 | for(k=0; k<i; k++){ |
| 33296 | 33418 | if( escarg[k]=='\\' ){ |
| 33297 | 33419 | nBack++; |
| 33298 | 33420 | }else if( ((u8*)escarg)[k]<=0x1f ){ |
| 33299 | 33421 | nCtrl++; |
| @@ -33337,11 +33459,11 @@ | ||
| 33337 | 33459 | bufpt[j-1] = '\\'; |
| 33338 | 33460 | bufpt[j++] = 'u'; |
| 33339 | 33461 | bufpt[j++] = '0'; |
| 33340 | 33462 | bufpt[j++] = '0'; |
| 33341 | 33463 | bufpt[j++] = ch>=0x10 ? '1' : '0'; |
| 33342 | - bufpt[j++] = "0123456789abcdef"[ch&0xf]; | |
| 33464 | + bufpt[j++] = aHex[ch&0xf]; | |
| 33343 | 33465 | } |
| 33344 | 33466 | } |
| 33345 | 33467 | }else{ |
| 33346 | 33468 | for(i=0; i<k; i++){ |
| 33347 | 33469 | bufpt[j++] = ch = escarg[i]; |
| @@ -39154,10 +39276,26 @@ | ||
| 39154 | 39276 | ****************************************************************************** |
| 39155 | 39277 | ** |
| 39156 | 39278 | ** This file contains an experimental VFS layer that operates on a |
| 39157 | 39279 | ** Key/Value storage engine where both keys and values must be pure |
| 39158 | 39280 | ** text. |
| 39281 | +** | |
| 39282 | +** DEBUG AND TEST | |
| 39283 | +** | |
| 39284 | +** For testing on Unix, compile using: | |
| 39285 | +** | |
| 39286 | +** make clean sqlite3d CFLAGS='-DSQLITE_OS_KV_OPTIONAL' | |
| 39287 | +** | |
| 39288 | +** Then start up a shell using something like: | |
| 39289 | +** | |
| 39290 | +** ./sqlite3d 'file:dbname?vfs=kvvfs' | |
| 39291 | +** | |
| 39292 | +** Each K/V entry is stored in a separate file in the working | |
| 39293 | +** directory that has a name like "kvvfs-dbname-*". Due to limitations | |
| 39294 | +** on the key size, the name of the database must be very short - just | |
| 39295 | +** a few characters. If the database name is too long, the VFS will | |
| 39296 | +** malfunction and you will get SQLITE_CORRUPT errors. | |
| 39159 | 39297 | */ |
| 39160 | 39298 | /* #include <sqliteInt.h> */ |
| 39161 | 39299 | #if SQLITE_OS_KV || (SQLITE_OS_UNIX && defined(SQLITE_OS_KV_OPTIONAL)) |
| 39162 | 39300 | |
| 39163 | 39301 | /***************************************************************************** |
| @@ -39606,16 +39744,18 @@ | ||
| 39606 | 39744 | } |
| 39607 | 39745 | if( j+n>nOut ) return -1; |
| 39608 | 39746 | memset(&aOut[j], 0, n); |
| 39609 | 39747 | j += n; |
| 39610 | 39748 | if( c==0 || mult==1 ) break; /* progress stalled if mult==1 */ |
| 39611 | - }else{ | |
| 39749 | + }else if( j<nOut ){ | |
| 39612 | 39750 | aOut[j] = c<<4; |
| 39613 | 39751 | c = kvvfsHexValue[aIn[++i]]; |
| 39614 | 39752 | if( c<0 ) return -1 /* hex bytes are always in pairs */; |
| 39615 | 39753 | aOut[j++] += c; |
| 39616 | 39754 | i++; |
| 39755 | + }else{ | |
| 39756 | + return -1; | |
| 39617 | 39757 | } |
| 39618 | 39758 | } |
| 39619 | 39759 | return j; |
| 39620 | 39760 | } |
| 39621 | 39761 | |
| @@ -40037,10 +40177,22 @@ | ||
| 40037 | 40177 | }else{ |
| 40038 | 40178 | pFile->isJournal = 0; |
| 40039 | 40179 | pFile->base.pMethods = &kvvfs_db_io_methods; |
| 40040 | 40180 | } |
| 40041 | 40181 | if( !pFile->zClass ){ |
| 40182 | +#ifdef SQLITE_WASM | |
| 40183 | + if( strlen(zName) >= (KVRECORD_KEY_SZ | |
| 40184 | + - 6 /* "kvvfs-" */ | |
| 40185 | + - 11 /* "-##########" */) ){ | |
| 40186 | + return SQLITE_CANTOPEN; | |
| 40187 | + } | |
| 40188 | +#else | |
| 40189 | + if( 0!=strcmp(zName, "local") && 0!=strcmp(zName, "session") ){ | |
| 40190 | + /* Historical naming restriction which journaling depends on. */ | |
| 40191 | + return SQLITE_CANTOPEN; | |
| 40192 | + } | |
| 40193 | +#endif | |
| 40042 | 40194 | pFile->zClass = zName; |
| 40043 | 40195 | } |
| 40044 | 40196 | pFile->aData = sqlite3_malloc64(SQLITE_KVOS_SZ); |
| 40045 | 40197 | if( pFile->aData==0 ){ |
| 40046 | 40198 | return SQLITE_NOMEM; |
| @@ -45345,13 +45497,13 @@ | ||
| 45345 | 45497 | |
| 45346 | 45498 | /* Minimum number of regions required to be mapped. */ |
| 45347 | 45499 | nReqRegion = ((iRegion+nShmPerMap) / nShmPerMap) * nShmPerMap; |
| 45348 | 45500 | |
| 45349 | 45501 | if( pShmNode->nRegion<nReqRegion ){ |
| 45350 | - char **apNew; /* New apRegion[] array */ | |
| 45351 | - int nByte = nReqRegion*szRegion; /* Minimum required file size */ | |
| 45352 | - struct stat sStat; /* Used by fstat() */ | |
| 45502 | + char **apNew; /* New apRegion[] array */ | |
| 45503 | + i64 nByte = nReqRegion*(i64)szRegion; /* Minimum required file size */ | |
| 45504 | + struct stat sStat; /* Used by fstat() */ | |
| 45353 | 45505 | |
| 45354 | 45506 | pShmNode->szRegion = szRegion; |
| 45355 | 45507 | |
| 45356 | 45508 | if( pShmNode->hShm>=0 ){ |
| 45357 | 45509 | /* The requested region is not mapped into this processes address space. |
| @@ -45378,11 +45530,11 @@ | ||
| 45378 | 45530 | ** pages forces the OS to allocate them immediately, which reduces |
| 45379 | 45531 | ** the chances of SIGBUS while accessing the mapped region later on. |
| 45380 | 45532 | */ |
| 45381 | 45533 | else{ |
| 45382 | 45534 | static const int pgsz = 4096; |
| 45383 | - int iPg; | |
| 45535 | + i64 iPg; | |
| 45384 | 45536 | |
| 45385 | 45537 | /* Write to the last byte of each newly allocated or extended page */ |
| 45386 | 45538 | assert( (nByte % pgsz)==0 ); |
| 45387 | 45539 | for(iPg=(sStat.st_size/pgsz); iPg<(nByte/pgsz); iPg++){ |
| 45388 | 45540 | int x = 0; |
| @@ -45404,12 +45556,12 @@ | ||
| 45404 | 45556 | rc = SQLITE_IOERR_NOMEM_BKPT; |
| 45405 | 45557 | goto shmpage_out; |
| 45406 | 45558 | } |
| 45407 | 45559 | pShmNode->apRegion = apNew; |
| 45408 | 45560 | while( pShmNode->nRegion<nReqRegion ){ |
| 45409 | - int nMap = szRegion*nShmPerMap; | |
| 45410 | - int i; | |
| 45561 | + i64 nMap = (i64)szRegion*(i64)nShmPerMap; | |
| 45562 | + i64 i; | |
| 45411 | 45563 | void *pMem; |
| 45412 | 45564 | if( pShmNode->hShm>=0 ){ |
| 45413 | 45565 | pMem = osMmap(0, nMap, |
| 45414 | 45566 | pShmNode->isReadonly ? PROT_READ : PROT_READ|PROT_WRITE, |
| 45415 | 45567 | MAP_SHARED, pShmNode->hShm, szRegion*(i64)pShmNode->nRegion |
| @@ -49195,107 +49347,154 @@ | ||
| 49195 | 49347 | |
| 49196 | 49348 | { "CreateFileW", (SYSCALL)CreateFileW, 0 }, |
| 49197 | 49349 | #define osCreateFileW ((HANDLE(WINAPI*)(LPCWSTR,DWORD,DWORD, \ |
| 49198 | 49350 | LPSECURITY_ATTRIBUTES,DWORD,DWORD,HANDLE))aSyscall[2].pCurrent) |
| 49199 | 49351 | |
| 49352 | +#if defined(SQLITE_UWP) | |
| 49353 | + { "CreateFileMappingFromApp",(SYSCALL)CreateFileMappingFromApp,0 }, | |
| 49354 | +#else | |
| 49355 | + { "CreateFileMappingFromApp",(SYSCALL)0, 0 }, | |
| 49356 | +#endif | |
| 49357 | +#define osCreateFileMappingFromApp ((HANDLE(WINAPI*)(HANDLE,\ | |
| 49358 | + PSECURITY_ATTRIBUTES, \ | |
| 49359 | + ULONG,ULONG64,PCWSTR))aSyscall[3].pCurrent) | |
| 49360 | + | |
| 49361 | +#if !defined(SQLITE_UWP) | |
| 49200 | 49362 | { "CreateFileMappingW", (SYSCALL)CreateFileMappingW, 0 }, |
| 49363 | +#else | |
| 49364 | + { "CreateFileMappingW", (SYSCALL)0, 0 }, | |
| 49365 | +#endif | |
| 49201 | 49366 | #define osCreateFileMappingW ((HANDLE(WINAPI*)(HANDLE,LPSECURITY_ATTRIBUTES, \ |
| 49202 | - DWORD,DWORD,DWORD,LPCWSTR))aSyscall[3].pCurrent) | |
| 49367 | + DWORD,DWORD,DWORD,LPCWSTR))aSyscall[4].pCurrent) | |
| 49203 | 49368 | |
| 49204 | 49369 | { "DeleteFileW", (SYSCALL)DeleteFileW, 0 }, |
| 49205 | -#define osDeleteFileW ((BOOL(WINAPI*)(LPCWSTR))aSyscall[4].pCurrent) | |
| 49370 | +#define osDeleteFileW ((BOOL(WINAPI*)(LPCWSTR))aSyscall[5].pCurrent) | |
| 49206 | 49371 | |
| 49207 | 49372 | { "FlushFileBuffers", (SYSCALL)FlushFileBuffers, 0 }, |
| 49208 | -#define osFlushFileBuffers ((BOOL(WINAPI*)(HANDLE))aSyscall[5].pCurrent) | |
| 49373 | +#define osFlushFileBuffers ((BOOL(WINAPI*)(HANDLE))aSyscall[6].pCurrent) | |
| 49209 | 49374 | |
| 49210 | 49375 | { "FormatMessageW", (SYSCALL)FormatMessageW, 0 }, |
| 49211 | 49376 | #define osFormatMessageW ((DWORD(WINAPI*)(DWORD,LPCVOID,DWORD,DWORD,LPWSTR, \ |
| 49212 | - DWORD,va_list*))aSyscall[6].pCurrent) | |
| 49377 | + DWORD,va_list*))aSyscall[7].pCurrent) | |
| 49213 | 49378 | |
| 49214 | -#if !defined(SQLITE_OMIT_LOAD_EXTENSION) | |
| 49379 | +#if !defined(SQLITE_OMIT_LOAD_EXTENSION) && !defined(SQLITE_UWP) | |
| 49215 | 49380 | { "FreeLibrary", (SYSCALL)FreeLibrary, 0 }, |
| 49216 | 49381 | #else |
| 49217 | 49382 | { "FreeLibrary", (SYSCALL)0, 0 }, |
| 49218 | 49383 | #endif |
| 49219 | 49384 | |
| 49220 | -#define osFreeLibrary ((BOOL(WINAPI*)(HMODULE))aSyscall[7].pCurrent) | |
| 49385 | +#define osFreeLibrary ((BOOL(WINAPI*)(HMODULE))aSyscall[8].pCurrent) | |
| 49221 | 49386 | |
| 49222 | 49387 | { "GetCurrentProcessId", (SYSCALL)GetCurrentProcessId, 0 }, |
| 49223 | -#define osGetCurrentProcessId ((DWORD(WINAPI*)(VOID))aSyscall[8].pCurrent) | |
| 49388 | +#define osGetCurrentProcessId ((DWORD(WINAPI*)(VOID))aSyscall[9].pCurrent) | |
| 49224 | 49389 | |
| 49225 | 49390 | { "GetFileAttributesW", (SYSCALL)GetFileAttributesW, 0 }, |
| 49226 | -#define osGetFileAttributesW ((DWORD(WINAPI*)(LPCWSTR))aSyscall[9].pCurrent) | |
| 49391 | +#define osGetFileAttributesW ((DWORD(WINAPI*)(LPCWSTR))aSyscall[10].pCurrent) | |
| 49227 | 49392 | |
| 49228 | 49393 | { "GetFileAttributesExW", (SYSCALL)GetFileAttributesExW, 0 }, |
| 49229 | 49394 | #define osGetFileAttributesExW ((BOOL(WINAPI*)(LPCWSTR,GET_FILEEX_INFO_LEVELS, \ |
| 49230 | - LPVOID))aSyscall[10].pCurrent) | |
| 49395 | + LPVOID))aSyscall[11].pCurrent) | |
| 49231 | 49396 | |
| 49232 | - { "GetFileSize", (SYSCALL)GetFileSize, 0 }, | |
| 49233 | -#define osGetFileSize ((DWORD(WINAPI*)(HANDLE,LPDWORD))aSyscall[11].pCurrent) | |
| 49397 | + { "GetFileSizeEx", (SYSCALL)GetFileSizeEx, 0 }, | |
| 49398 | +#define osGetFileSizeEx ((BOOL(WINAPI*)(HANDLE, \ | |
| 49399 | + PLARGE_INTEGER))aSyscall[12].pCurrent) | |
| 49234 | 49400 | |
| 49235 | 49401 | { "GetFullPathNameW", (SYSCALL)GetFullPathNameW, 0 }, |
| 49236 | 49402 | #define osGetFullPathNameW ((DWORD(WINAPI*)(LPCWSTR,DWORD,LPWSTR, \ |
| 49237 | - LPWSTR*))aSyscall[12].pCurrent) | |
| 49403 | + LPWSTR*))aSyscall[13].pCurrent) | |
| 49238 | 49404 | |
| 49239 | 49405 | { "GetLastError", (SYSCALL)GetLastError, 0 }, |
| 49240 | -#define osGetLastError ((DWORD(WINAPI*)(VOID))aSyscall[13].pCurrent) | |
| 49406 | +#define osGetLastError ((DWORD(WINAPI*)(VOID))aSyscall[14].pCurrent) | |
| 49241 | 49407 | |
| 49242 | -#if !defined(SQLITE_OMIT_LOAD_EXTENSION) | |
| 49408 | +#if !defined(SQLITE_OMIT_LOAD_EXTENSION) && !defined(SQLITE_UWP) | |
| 49243 | 49409 | { "GetProcAddressA", (SYSCALL)GetProcAddress, 0 }, |
| 49244 | 49410 | #else |
| 49245 | 49411 | { "GetProcAddressA", (SYSCALL)0, 0 }, |
| 49246 | 49412 | #endif |
| 49247 | 49413 | #define osGetProcAddressA ((FARPROC(WINAPI*)(HMODULE, \ |
| 49248 | - LPCSTR))aSyscall[14].pCurrent) | |
| 49414 | + LPCSTR))aSyscall[15].pCurrent) | |
| 49249 | 49415 | |
| 49250 | 49416 | { "GetSystemInfo", (SYSCALL)GetSystemInfo, 0 }, |
| 49251 | -#define osGetSystemInfo ((VOID(WINAPI*)(LPSYSTEM_INFO))aSyscall[15].pCurrent) | |
| 49252 | - | |
| 49253 | - { "GetSystemTime", (SYSCALL)GetSystemTime, 0 }, | |
| 49254 | -#define osGetSystemTime ((VOID(WINAPI*)(LPSYSTEMTIME))aSyscall[16].pCurrent) | |
| 49417 | +#define osGetSystemInfo ((VOID(WINAPI*)(LPSYSTEM_INFO))aSyscall[16].pCurrent) | |
| 49255 | 49418 | |
| 49256 | 49419 | { "GetSystemTimeAsFileTime", (SYSCALL)GetSystemTimeAsFileTime, 0 }, |
| 49257 | 49420 | #define osGetSystemTimeAsFileTime ((VOID(WINAPI*)( \ |
| 49258 | 49421 | LPFILETIME))aSyscall[17].pCurrent) |
| 49259 | 49422 | |
| 49423 | +#ifdef SQLITE_UWP | |
| 49424 | + { "GetTempPathW", (SYSCALL)0, 0 }, | |
| 49425 | +#else | |
| 49260 | 49426 | { "GetTempPathW", (SYSCALL)GetTempPathW, 0 }, |
| 49427 | +#endif | |
| 49261 | 49428 | #define osGetTempPathW ((DWORD(WINAPI*)(DWORD,LPWSTR))aSyscall[18].pCurrent) |
| 49262 | 49429 | |
| 49263 | - { "GetTickCount", (SYSCALL)GetTickCount, 0 }, | |
| 49264 | -#define osGetTickCount ((DWORD(WINAPI*)(VOID))aSyscall[19].pCurrent) | |
| 49430 | + { "GetTickCount64", (SYSCALL)GetTickCount64, 0 }, | |
| 49431 | +#define osGetTickCount64 ((ULONGLONG(WINAPI*)(VOID))aSyscall[19].pCurrent) | |
| 49265 | 49432 | |
| 49433 | +#ifdef SQLITE_UWP | |
| 49434 | + { "HeapAlloc", (SYSCALL)0, 0 }, | |
| 49435 | +#else | |
| 49266 | 49436 | { "HeapAlloc", (SYSCALL)HeapAlloc, 0 }, |
| 49437 | +#endif | |
| 49267 | 49438 | #define osHeapAlloc ((LPVOID(WINAPI*)(HANDLE,DWORD, \ |
| 49268 | 49439 | SIZE_T))aSyscall[20].pCurrent) |
| 49269 | 49440 | |
| 49441 | +#ifdef SQLITE_UWP | |
| 49442 | + { "HeapCreate", (SYSCALL)0, 0 }, | |
| 49443 | +#else | |
| 49270 | 49444 | { "HeapCreate", (SYSCALL)HeapCreate, 0 }, |
| 49445 | +#endif | |
| 49271 | 49446 | #define osHeapCreate ((HANDLE(WINAPI*)(DWORD,SIZE_T, \ |
| 49272 | 49447 | SIZE_T))aSyscall[21].pCurrent) |
| 49273 | 49448 | |
| 49449 | +#ifdef SQLITE_UWP | |
| 49450 | + { "HeapDestroy", (SYSCALL)0, 0 }, | |
| 49451 | +#else | |
| 49274 | 49452 | { "HeapDestroy", (SYSCALL)HeapDestroy, 0 }, |
| 49453 | +#endif | |
| 49275 | 49454 | #define osHeapDestroy ((BOOL(WINAPI*)(HANDLE))aSyscall[22].pCurrent) |
| 49276 | 49455 | |
| 49456 | +#ifdef SQLITE_UWP | |
| 49457 | + { "HeapFree", (SYSCALL)0, 0 }, | |
| 49458 | +#else | |
| 49277 | 49459 | { "HeapFree", (SYSCALL)HeapFree, 0 }, |
| 49460 | +#endif | |
| 49278 | 49461 | #define osHeapFree ((BOOL(WINAPI*)(HANDLE,DWORD,LPVOID))aSyscall[23].pCurrent) |
| 49279 | 49462 | |
| 49463 | +#ifdef SQLITE_UWP | |
| 49464 | + { "HeapReAlloc", (SYSCALL)0, 0 }, | |
| 49465 | +#else | |
| 49280 | 49466 | { "HeapReAlloc", (SYSCALL)HeapReAlloc, 0 }, |
| 49467 | +#endif | |
| 49281 | 49468 | #define osHeapReAlloc ((LPVOID(WINAPI*)(HANDLE,DWORD,LPVOID, \ |
| 49282 | 49469 | SIZE_T))aSyscall[24].pCurrent) |
| 49283 | 49470 | |
| 49471 | +#ifdef SQLITE_UWP | |
| 49472 | + { "HeapSize", (SYSCALL)0, 0 }, | |
| 49473 | +#else | |
| 49284 | 49474 | { "HeapSize", (SYSCALL)HeapSize, 0 }, |
| 49475 | +#endif | |
| 49285 | 49476 | #define osHeapSize ((SIZE_T(WINAPI*)(HANDLE,DWORD, \ |
| 49286 | 49477 | LPCVOID))aSyscall[25].pCurrent) |
| 49287 | 49478 | |
| 49479 | +#ifdef SQLITE_UWP | |
| 49480 | + { "HeapValidate", (SYSCALL)0, 0 }, | |
| 49481 | +#else | |
| 49288 | 49482 | { "HeapValidate", (SYSCALL)HeapValidate, 0 }, |
| 49483 | +#endif | |
| 49289 | 49484 | #define osHeapValidate ((BOOL(WINAPI*)(HANDLE,DWORD, \ |
| 49290 | 49485 | LPCVOID))aSyscall[26].pCurrent) |
| 49291 | 49486 | |
| 49487 | +#ifdef SQLITE_UWP | |
| 49488 | + { "HeapCompact", (SYSCALL)0, 0 }, | |
| 49489 | +#else | |
| 49292 | 49490 | { "HeapCompact", (SYSCALL)HeapCompact, 0 }, |
| 49491 | +#endif | |
| 49293 | 49492 | #define osHeapCompact ((UINT(WINAPI*)(HANDLE,DWORD))aSyscall[27].pCurrent) |
| 49294 | 49493 | |
| 49295 | 49494 | |
| 49296 | -#if !defined(SQLITE_OMIT_LOAD_EXTENSION) | |
| 49495 | +#if !defined(SQLITE_OMIT_LOAD_EXTENSION) && !defined(SQLITE_UWP) | |
| 49297 | 49496 | { "LoadLibraryW", (SYSCALL)LoadLibraryW, 0 }, |
| 49298 | 49497 | #else |
| 49299 | 49498 | { "LoadLibraryW", (SYSCALL)0, 0 }, |
| 49300 | 49499 | #endif |
| 49301 | 49500 | #define osLoadLibraryW ((HMODULE(WINAPI*)(LPCWSTR))aSyscall[28].pCurrent) |
| @@ -49305,72 +49504,82 @@ | ||
| 49305 | 49504 | |
| 49306 | 49505 | { "LockFileEx", (SYSCALL)LockFileEx, 0 }, |
| 49307 | 49506 | #define osLockFileEx ((BOOL(WINAPI*)(HANDLE,DWORD,DWORD,DWORD,DWORD, \ |
| 49308 | 49507 | LPOVERLAPPED))aSyscall[30].pCurrent) |
| 49309 | 49508 | |
| 49310 | -#if !defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0 | |
| 49509 | +#if (!defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0) \ | |
| 49510 | + && !defined(SQLITE_UWP) | |
| 49311 | 49511 | { "MapViewOfFile", (SYSCALL)MapViewOfFile, 0 }, |
| 49312 | 49512 | #else |
| 49313 | 49513 | { "MapViewOfFile", (SYSCALL)0, 0 }, |
| 49314 | 49514 | #endif |
| 49315 | 49515 | #define osMapViewOfFile ((LPVOID(WINAPI*)(HANDLE,DWORD,DWORD,DWORD, \ |
| 49316 | 49516 | SIZE_T))aSyscall[31].pCurrent) |
| 49517 | + | |
| 49518 | +#if (!defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0) \ | |
| 49519 | + && defined(SQLITE_UWP) | |
| 49520 | + { "MapViewOfFileFromApp", (SYSCALL)MapViewOfFileFromApp, 0 }, | |
| 49521 | +#else | |
| 49522 | + { "MapViewOfFileFromApp", (SYSCALL)0, 0 }, | |
| 49523 | +#endif | |
| 49524 | +#define osMapViewOfFileFromApp ((LPVOID(WINAPI*)(HANDLE,ULONG,ULONG64, \ | |
| 49525 | + SIZE_T))aSyscall[32].pCurrent) | |
| 49317 | 49526 | |
| 49318 | 49527 | { "MultiByteToWideChar", (SYSCALL)MultiByteToWideChar, 0 }, |
| 49319 | 49528 | #define osMultiByteToWideChar ((int(WINAPI*)(UINT,DWORD,LPCSTR,int,LPWSTR, \ |
| 49320 | - int))aSyscall[32].pCurrent) | |
| 49529 | + int))aSyscall[33].pCurrent) | |
| 49321 | 49530 | |
| 49322 | 49531 | { "QueryPerformanceCounter", (SYSCALL)QueryPerformanceCounter, 0 }, |
| 49323 | 49532 | #define osQueryPerformanceCounter ((BOOL(WINAPI*)( \ |
| 49324 | - LARGE_INTEGER*))aSyscall[33].pCurrent) | |
| 49533 | + LARGE_INTEGER*))aSyscall[34].pCurrent) | |
| 49325 | 49534 | |
| 49326 | 49535 | { "ReadFile", (SYSCALL)ReadFile, 0 }, |
| 49327 | 49536 | #define osReadFile ((BOOL(WINAPI*)(HANDLE,LPVOID,DWORD,LPDWORD, \ |
| 49328 | - LPOVERLAPPED))aSyscall[34].pCurrent) | |
| 49537 | + LPOVERLAPPED))aSyscall[35].pCurrent) | |
| 49329 | 49538 | |
| 49330 | 49539 | { "SetEndOfFile", (SYSCALL)SetEndOfFile, 0 }, |
| 49331 | -#define osSetEndOfFile ((BOOL(WINAPI*)(HANDLE))aSyscall[35].pCurrent) | |
| 49540 | +#define osSetEndOfFile ((BOOL(WINAPI*)(HANDLE))aSyscall[36].pCurrent) | |
| 49332 | 49541 | |
| 49333 | - { "SetFilePointer", (SYSCALL)SetFilePointer, 0 }, | |
| 49334 | -#define osSetFilePointer ((DWORD(WINAPI*)(HANDLE,LONG,PLONG, \ | |
| 49335 | - DWORD))aSyscall[36].pCurrent) | |
| 49542 | + { "SetFilePointerEx", (SYSCALL)SetFilePointerEx, 0 }, | |
| 49543 | +#define osSetFilePointerEx ((BOOL(WINAPI*)(HANDLE,LARGE_INTEGER,\ | |
| 49544 | + PLARGE_INTEGER,DWORD))aSyscall[37].pCurrent) | |
| 49336 | 49545 | |
| 49337 | 49546 | { "Sleep", (SYSCALL)Sleep, 0 }, |
| 49338 | -#define osSleep ((VOID(WINAPI*)(DWORD))aSyscall[37].pCurrent) | |
| 49547 | +#define osSleep ((VOID(WINAPI*)(DWORD))aSyscall[38].pCurrent) | |
| 49339 | 49548 | |
| 49340 | 49549 | { "UnlockFileEx", (SYSCALL)UnlockFileEx, 0 }, |
| 49341 | 49550 | #define osUnlockFileEx ((BOOL(WINAPI*)(HANDLE,DWORD,DWORD,DWORD, \ |
| 49342 | - LPOVERLAPPED))aSyscall[38].pCurrent) | |
| 49551 | + LPOVERLAPPED))aSyscall[39].pCurrent) | |
| 49343 | 49552 | |
| 49344 | 49553 | #if !defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0 |
| 49345 | 49554 | { "UnmapViewOfFile", (SYSCALL)UnmapViewOfFile, 0 }, |
| 49346 | 49555 | #else |
| 49347 | 49556 | { "UnmapViewOfFile", (SYSCALL)0, 0 }, |
| 49348 | 49557 | #endif |
| 49349 | -#define osUnmapViewOfFile ((BOOL(WINAPI*)(LPCVOID))aSyscall[39].pCurrent) | |
| 49558 | +#define osUnmapViewOfFile ((BOOL(WINAPI*)(LPCVOID))aSyscall[40].pCurrent) | |
| 49350 | 49559 | |
| 49351 | 49560 | { "WideCharToMultiByte", (SYSCALL)WideCharToMultiByte, 0 }, |
| 49352 | 49561 | #define osWideCharToMultiByte ((int(WINAPI*)(UINT,DWORD,LPCWSTR,int,LPSTR,int, \ |
| 49353 | - LPCSTR,LPBOOL))aSyscall[40].pCurrent) | |
| 49562 | + LPCSTR,LPBOOL))aSyscall[41].pCurrent) | |
| 49354 | 49563 | |
| 49355 | 49564 | { "WriteFile", (SYSCALL)WriteFile, 0 }, |
| 49356 | 49565 | #define osWriteFile ((BOOL(WINAPI*)(HANDLE,LPCVOID,DWORD,LPDWORD, \ |
| 49357 | - LPOVERLAPPED))aSyscall[41].pCurrent) | |
| 49566 | + LPOVERLAPPED))aSyscall[42].pCurrent) | |
| 49358 | 49567 | |
| 49359 | 49568 | { "WaitForSingleObject", (SYSCALL)WaitForSingleObject, 0 }, |
| 49360 | 49569 | #define osWaitForSingleObject ((DWORD(WINAPI*)(HANDLE, \ |
| 49361 | - DWORD))aSyscall[42].pCurrent) | |
| 49570 | + DWORD))aSyscall[43].pCurrent) | |
| 49362 | 49571 | |
| 49363 | 49572 | { "WaitForSingleObjectEx", (SYSCALL)WaitForSingleObjectEx, 0 }, |
| 49364 | 49573 | #define osWaitForSingleObjectEx ((DWORD(WINAPI*)(HANDLE,DWORD, \ |
| 49365 | - BOOL))aSyscall[43].pCurrent) | |
| 49574 | + BOOL))aSyscall[44].pCurrent) | |
| 49366 | 49575 | |
| 49367 | 49576 | { "OutputDebugStringA", (SYSCALL)OutputDebugStringA, 0 }, |
| 49368 | -#define osOutputDebugStringA ((VOID(WINAPI*)(LPCSTR))aSyscall[44].pCurrent) | |
| 49577 | +#define osOutputDebugStringA ((VOID(WINAPI*)(LPCSTR))aSyscall[45].pCurrent) | |
| 49369 | 49578 | |
| 49370 | 49579 | { "GetProcessHeap", (SYSCALL)GetProcessHeap, 0 }, |
| 49371 | -#define osGetProcessHeap ((HANDLE(WINAPI*)(VOID))aSyscall[45].pCurrent) | |
| 49580 | +#define osGetProcessHeap ((HANDLE(WINAPI*)(VOID))aSyscall[46].pCurrent) | |
| 49372 | 49581 | |
| 49373 | 49582 | /* |
| 49374 | 49583 | ** NOTE: On some sub-platforms, the InterlockedCompareExchange "function" |
| 49375 | 49584 | ** is really just a macro that uses a compiler intrinsic (e.g. x64). |
| 49376 | 49585 | ** So do not try to make this is into a redefinable interface. |
| @@ -49379,95 +49588,93 @@ | ||
| 49379 | 49588 | { "InterlockedCompareExchange", (SYSCALL)0, 0 }, |
| 49380 | 49589 | #define osInterlockedCompareExchange InterlockedCompareExchange |
| 49381 | 49590 | #else |
| 49382 | 49591 | { "InterlockedCompareExchange", (SYSCALL)InterlockedCompareExchange, 0 }, |
| 49383 | 49592 | #define osInterlockedCompareExchange ((LONG(WINAPI*)(LONG volatile*,\ |
| 49384 | - LONG,LONG))aSyscall[46].pCurrent) | |
| 49593 | + LONG,LONG))aSyscall[47].pCurrent) | |
| 49385 | 49594 | #endif /* defined(InterlockedCompareExchange) */ |
| 49386 | 49595 | |
| 49387 | 49596 | #if SQLITE_WIN32_USE_UUID |
| 49388 | 49597 | { "UuidCreate", (SYSCALL)UuidCreate, 0 }, |
| 49389 | 49598 | #else |
| 49390 | 49599 | { "UuidCreate", (SYSCALL)0, 0 }, |
| 49391 | 49600 | #endif |
| 49392 | -#define osUuidCreate ((RPC_STATUS(RPC_ENTRY*)(UUID*))aSyscall[47].pCurrent) | |
| 49601 | +#define osUuidCreate ((RPC_STATUS(RPC_ENTRY*)(UUID*))aSyscall[48].pCurrent) | |
| 49393 | 49602 | |
| 49394 | 49603 | #if SQLITE_WIN32_USE_UUID |
| 49395 | 49604 | { "UuidCreateSequential", (SYSCALL)UuidCreateSequential, 0 }, |
| 49396 | 49605 | #else |
| 49397 | 49606 | { "UuidCreateSequential", (SYSCALL)0, 0 }, |
| 49398 | 49607 | #endif |
| 49399 | 49608 | #define osUuidCreateSequential \ |
| 49400 | - ((RPC_STATUS(RPC_ENTRY*)(UUID*))aSyscall[48].pCurrent) | |
| 49609 | + ((RPC_STATUS(RPC_ENTRY*)(UUID*))aSyscall[49].pCurrent) | |
| 49401 | 49610 | |
| 49402 | 49611 | #if !defined(SQLITE_NO_SYNC) && SQLITE_MAX_MMAP_SIZE>0 |
| 49403 | 49612 | { "FlushViewOfFile", (SYSCALL)FlushViewOfFile, 0 }, |
| 49404 | 49613 | #else |
| 49405 | 49614 | { "FlushViewOfFile", (SYSCALL)0, 0 }, |
| 49406 | 49615 | #endif |
| 49407 | 49616 | #define osFlushViewOfFile \ |
| 49408 | - ((BOOL(WINAPI*)(LPCVOID,SIZE_T))aSyscall[49].pCurrent) | |
| 49617 | + ((BOOL(WINAPI*)(LPCVOID,SIZE_T))aSyscall[50].pCurrent) | |
| 49409 | 49618 | |
| 49410 | 49619 | #ifdef SQLITE_ENABLE_SETLK_TIMEOUT |
| 49411 | 49620 | { "CreateEvent", (SYSCALL)CreateEvent, 0 }, |
| 49412 | 49621 | #else |
| 49413 | 49622 | { "CreateEvent", (SYSCALL)0, 0 }, |
| 49414 | 49623 | #endif |
| 49415 | -#define osCreateEvent ( \ | |
| 49416 | - (HANDLE(WINAPI*) (LPSECURITY_ATTRIBUTES,BOOL,BOOL,LPCSTR)) \ | |
| 49417 | - aSyscall[50].pCurrent \ | |
| 49418 | -) | |
| 49624 | +#define osCreateEvent ((HANDLE(WINAPI*)(LPSECURITY_ATTRIBUTES,BOOL, \ | |
| 49625 | + BOOL,LPCSTR))aSyscall[51].pCurrent) | |
| 49419 | 49626 | |
| 49420 | 49627 | #ifdef SQLITE_ENABLE_SETLK_TIMEOUT |
| 49421 | 49628 | { "CancelIo", (SYSCALL)CancelIo, 0 }, |
| 49422 | 49629 | #else |
| 49423 | 49630 | { "CancelIo", (SYSCALL)0, 0 }, |
| 49424 | 49631 | #endif |
| 49425 | -#define osCancelIo ((BOOL(WINAPI*)(HANDLE))aSyscall[51].pCurrent) | |
| 49632 | +#define osCancelIo ((BOOL(WINAPI*)(HANDLE))aSyscall[52].pCurrent) | |
| 49426 | 49633 | |
| 49427 | 49634 | #ifndef _WIN32 |
| 49428 | 49635 | { "getenv", (SYSCALL)getenv, 0 }, |
| 49429 | 49636 | #else |
| 49430 | 49637 | { "getenv", (SYSCALL)0, 0 }, |
| 49431 | 49638 | #endif |
| 49432 | -#define osGetenv ((const char *(*)(const char *))aSyscall[52].pCurrent) | |
| 49639 | +#define osGetenv ((const char *(*)(const char *))aSyscall[53].pCurrent) | |
| 49433 | 49640 | |
| 49434 | 49641 | #ifndef _WIN32 |
| 49435 | 49642 | { "getcwd", (SYSCALL)getcwd, 0 }, |
| 49436 | 49643 | #else |
| 49437 | 49644 | { "getcwd", (SYSCALL)0, 0 }, |
| 49438 | 49645 | #endif |
| 49439 | -#define osGetcwd ((char*(*)(char*,size_t))aSyscall[53].pCurrent) | |
| 49646 | +#define osGetcwd ((char*(*)(char*,size_t))aSyscall[54].pCurrent) | |
| 49440 | 49647 | |
| 49441 | 49648 | #ifndef _WIN32 |
| 49442 | 49649 | { "readlink", (SYSCALL)readlink, 0 }, |
| 49443 | 49650 | #else |
| 49444 | 49651 | { "readlink", (SYSCALL)0, 0 }, |
| 49445 | 49652 | #endif |
| 49446 | -#define osReadlink ((ssize_t(*)(const char*,char*,size_t))aSyscall[54].pCurrent) | |
| 49653 | +#define osReadlink ((ssize_t(*)(const char*,char*,size_t))aSyscall[55].pCurrent) | |
| 49447 | 49654 | |
| 49448 | 49655 | #ifndef _WIN32 |
| 49449 | 49656 | { "lstat", (SYSCALL)lstat, 0 }, |
| 49450 | 49657 | #else |
| 49451 | 49658 | { "lstat", (SYSCALL)0, 0 }, |
| 49452 | 49659 | #endif |
| 49453 | -#define osLstat ((int(*)(const char*,struct stat*))aSyscall[55].pCurrent) | |
| 49660 | +#define osLstat ((int(*)(const char*,struct stat*))aSyscall[56].pCurrent) | |
| 49454 | 49661 | |
| 49455 | 49662 | #ifndef _WIN32 |
| 49456 | 49663 | { "__errno", (SYSCALL)__errno, 0 }, |
| 49457 | 49664 | #else |
| 49458 | 49665 | { "__errno", (SYSCALL)0, 0 }, |
| 49459 | 49666 | #endif |
| 49460 | -#define osErrno (*((int*(*)(void))aSyscall[56].pCurrent)()) | |
| 49667 | +#define osErrno (*((int*(*)(void))aSyscall[57].pCurrent)()) | |
| 49461 | 49668 | |
| 49462 | 49669 | #ifndef _WIN32 |
| 49463 | 49670 | { "cygwin_conv_path", (SYSCALL)cygwin_conv_path, 0 }, |
| 49464 | 49671 | #else |
| 49465 | 49672 | { "cygwin_conv_path", (SYSCALL)0, 0 }, |
| 49466 | 49673 | #endif |
| 49467 | 49674 | #define osCygwin_conv_path ((size_t(*)(unsigned int, \ |
| 49468 | - const void *, void *, size_t))aSyscall[57].pCurrent) | |
| 49675 | + const void *, void *, size_t))aSyscall[58].pCurrent) | |
| 49469 | 49676 | |
| 49470 | 49677 | }; /* End of the overrideable system calls */ |
| 49471 | 49678 | |
| 49472 | 49679 | /* |
| 49473 | 49680 | ** This is the xSetSystemCall() method of sqlite3_vfs for all of the |
| @@ -49551,10 +49758,13 @@ | ||
| 49551 | 49758 | } |
| 49552 | 49759 | return 0; |
| 49553 | 49760 | } |
| 49554 | 49761 | |
| 49555 | 49762 | #ifdef SQLITE_WIN32_MALLOC |
| 49763 | +#ifdef SQLITE_UWP | |
| 49764 | +# error SQLITE_WIN32_MALLOC is incompatible with SQLITE_UWP | |
| 49765 | +#endif | |
| 49556 | 49766 | /* |
| 49557 | 49767 | ** If a Win32 native heap has been configured, this function will attempt to |
| 49558 | 49768 | ** compact it. Upon success, SQLITE_OK will be returned. Upon failure, one |
| 49559 | 49769 | ** of SQLITE_NOMEM, SQLITE_ERROR, or SQLITE_NOTFOUND will be returned. The |
| 49560 | 49770 | ** "pnLargest" argument, if non-zero, will be used to return the size of the |
| @@ -50509,31 +50719,15 @@ | ||
| 50509 | 50719 | ** If successful, return SQLITE_OK. Or, if an error occurs, return an SQLite |
| 50510 | 50720 | ** error code. |
| 50511 | 50721 | */ |
| 50512 | 50722 | static int winHandleSeek(HANDLE h, sqlite3_int64 iOffset){ |
| 50513 | 50723 | int rc = SQLITE_OK; /* Return value */ |
| 50514 | - | |
| 50515 | - LONG upperBits; /* Most sig. 32 bits of new offset */ | |
| 50516 | - LONG lowerBits; /* Least sig. 32 bits of new offset */ | |
| 50517 | - DWORD dwRet; /* Value returned by SetFilePointer() */ | |
| 50518 | - | |
| 50519 | - upperBits = (LONG)((iOffset>>32) & 0x7fffffff); | |
| 50520 | - lowerBits = (LONG)(iOffset & 0xffffffff); | |
| 50521 | - | |
| 50522 | - dwRet = osSetFilePointer(h, lowerBits, &upperBits, FILE_BEGIN); | |
| 50523 | - | |
| 50524 | - /* API oddity: If successful, SetFilePointer() returns a dword | |
| 50525 | - ** containing the lower 32-bits of the new file-offset. Or, if it fails, | |
| 50526 | - ** it returns INVALID_SET_FILE_POINTER. However according to MSDN, | |
| 50527 | - ** INVALID_SET_FILE_POINTER may also be a valid new offset. So to determine | |
| 50528 | - ** whether an error has actually occurred, it is also necessary to call | |
| 50529 | - ** GetLastError(). */ | |
| 50530 | - if( dwRet==INVALID_SET_FILE_POINTER ){ | |
| 50531 | - DWORD lastErrno = osGetLastError(); | |
| 50532 | - if( lastErrno!=NO_ERROR ){ | |
| 50533 | - rc = SQLITE_IOERR_SEEK; | |
| 50534 | - } | |
| 50724 | + LARGE_INTEGER x; /* The offset */ | |
| 50725 | + | |
| 50726 | + x.QuadPart = iOffset; | |
| 50727 | + if( osSetFilePointerEx(h, x, 0, FILE_BEGIN)==0 ){ | |
| 50728 | + rc = SQLITE_IOERR_SEEK; | |
| 50535 | 50729 | } |
| 50536 | 50730 | OSTRACE(("SEEK file=%p, offset=%lld rc=%s\n", h, iOffset,sqlite3ErrName(rc))); |
| 50537 | 50731 | return rc; |
| 50538 | 50732 | } |
| 50539 | 50733 | |
| @@ -50812,18 +51006,17 @@ | ||
| 50812 | 51006 | ** Determine the size in bytes of the file opened by the handle passed as |
| 50813 | 51007 | ** the first argument. |
| 50814 | 51008 | */ |
| 50815 | 51009 | static int winHandleSize(HANDLE h, sqlite3_int64 *pnByte){ |
| 50816 | 51010 | int rc = SQLITE_OK; |
| 50817 | - DWORD upperBits = 0; | |
| 50818 | - DWORD lowerBits = 0; | |
| 50819 | - | |
| 51011 | + LARGE_INTEGER x; | |
| 50820 | 51012 | assert( pnByte ); |
| 50821 | - lowerBits = osGetFileSize(h, &upperBits); | |
| 50822 | - *pnByte = (((sqlite3_int64)upperBits)<<32) + lowerBits; | |
| 50823 | - if( lowerBits==INVALID_FILE_SIZE && osGetLastError()!=NO_ERROR ){ | |
| 51013 | + if( osGetFileSizeEx(h, &x)==0 ){ | |
| 50824 | 51014 | rc = SQLITE_IOERR_FSTAT; |
| 51015 | + *pnByte = 0; | |
| 51016 | + }else{ | |
| 51017 | + *pnByte = x.QuadPart; | |
| 50825 | 51018 | } |
| 50826 | 51019 | return rc; |
| 50827 | 51020 | } |
| 50828 | 51021 | |
| 50829 | 51022 | /* |
| @@ -51020,21 +51213,18 @@ | ||
| 51020 | 51213 | assert( id!=0 ); |
| 51021 | 51214 | assert( pSize!=0 ); |
| 51022 | 51215 | SimulateIOError(return SQLITE_IOERR_FSTAT); |
| 51023 | 51216 | OSTRACE(("SIZE file=%p, pSize=%p\n", pFile->h, pSize)); |
| 51024 | 51217 | { |
| 51025 | - DWORD upperBits; | |
| 51026 | - DWORD lowerBits; | |
| 51027 | - DWORD lastErrno; | |
| 51028 | - | |
| 51029 | - lowerBits = osGetFileSize(pFile->h, &upperBits); | |
| 51030 | - *pSize = (((sqlite3_int64)upperBits)<<32) + lowerBits; | |
| 51031 | - if( (lowerBits == INVALID_FILE_SIZE) | |
| 51032 | - && ((lastErrno = osGetLastError())!=NO_ERROR) ){ | |
| 51033 | - pFile->lastErrno = lastErrno; | |
| 51218 | + LARGE_INTEGER x; | |
| 51219 | + if( osGetFileSizeEx(pFile->h, &x)==0 ){ | |
| 51220 | + *pSize = 0; | |
| 51221 | + pFile->lastErrno = osGetLastError(); | |
| 51034 | 51222 | rc = winLogError(SQLITE_IOERR_FSTAT, pFile->lastErrno, |
| 51035 | 51223 | "winFileSize", pFile->zPath); |
| 51224 | + }else{ | |
| 51225 | + *pSize = x.QuadPart; | |
| 51036 | 51226 | } |
| 51037 | 51227 | } |
| 51038 | 51228 | OSTRACE(("SIZE file=%p, pSize=%p, *pSize=%lld, rc=%s\n", |
| 51039 | 51229 | pFile->h, pSize, *pSize, sqlite3ErrName(rc))); |
| 51040 | 51230 | return rc; |
| @@ -52031,15 +52221,33 @@ | ||
| 52031 | 52221 | # define sqlite3_win_test_unc_locking 0 |
| 52032 | 52222 | #endif |
| 52033 | 52223 | |
| 52034 | 52224 | /* |
| 52035 | 52225 | ** Return true if the string passed as the only argument is likely |
| 52036 | -** to be a UNC path. In other words, if it starts with "\\". | |
| 52226 | +** to be a UNC path. Return false if note. | |
| 52227 | +** | |
| 52228 | +** Return true if: | |
| 52229 | +** | |
| 52230 | +** (1) The name begins with "\\" | |
| 52231 | +** (2) But does not begin with "\\?\C:\" where C can be any alphabetic | |
| 52232 | +** character. | |
| 52233 | +** | |
| 52234 | +** For testing, also return true in all cases if the global variable | |
| 52235 | +** sqlite3_win_test_unc_locking is true. | |
| 52037 | 52236 | */ |
| 52038 | 52237 | static int winIsUNCPath(const char *zFile){ |
| 52039 | 52238 | if( zFile[0]=='\\' && zFile[1]=='\\' ){ |
| 52040 | - return 1; | |
| 52239 | + if( zFile[2]=='?' | |
| 52240 | + && zFile[3]=='\\' | |
| 52241 | + && sqlite3Isalpha(zFile[4]) | |
| 52242 | + && zFile[5]==':' | |
| 52243 | + && winIsDirSep(zFile[6]) | |
| 52244 | + ){ | |
| 52245 | + return sqlite3_win_test_unc_locking; | |
| 52246 | + }else{ | |
| 52247 | + return 1; | |
| 52248 | + } | |
| 52041 | 52249 | } |
| 52042 | 52250 | return sqlite3_win_test_unc_locking; |
| 52043 | 52251 | } |
| 52044 | 52252 | |
| 52045 | 52253 | /* |
| @@ -52373,11 +52581,11 @@ | ||
| 52373 | 52581 | |
| 52374 | 52582 | assert( szRegion==pShmNode->szRegion || pShmNode->nRegion==0 ); |
| 52375 | 52583 | if( pShmNode->nRegion<=iRegion ){ |
| 52376 | 52584 | HANDLE hShared = pShmNode->hSharedShm; |
| 52377 | 52585 | struct ShmRegion *apNew; /* New aRegion[] array */ |
| 52378 | - int nByte = (iRegion+1)*szRegion; /* Minimum required file size */ | |
| 52586 | + i64 nByte = ((i64)iRegion+1)*(i64)szRegion; /* Minimum file size */ | |
| 52379 | 52587 | sqlite3_int64 sz; /* Current size of wal-index file */ |
| 52380 | 52588 | |
| 52381 | 52589 | pShmNode->szRegion = szRegion; |
| 52382 | 52590 | |
| 52383 | 52591 | /* The requested region is not mapped into this processes address space. |
| @@ -52404,11 +52612,11 @@ | ||
| 52404 | 52612 | } |
| 52405 | 52613 | } |
| 52406 | 52614 | |
| 52407 | 52615 | /* Map the requested memory region into this processes address space. */ |
| 52408 | 52616 | apNew = (struct ShmRegion*)sqlite3_realloc64( |
| 52409 | - pShmNode->aRegion, (iRegion+1)*sizeof(apNew[0]) | |
| 52617 | + pShmNode->aRegion, ((i64)iRegion+1)*sizeof(apNew[0]) | |
| 52410 | 52618 | ); |
| 52411 | 52619 | if( !apNew ){ |
| 52412 | 52620 | rc = SQLITE_IOERR_NOMEM_BKPT; |
| 52413 | 52621 | goto shmpage_out; |
| 52414 | 52622 | } |
| @@ -52421,20 +52629,30 @@ | ||
| 52421 | 52629 | |
| 52422 | 52630 | while( pShmNode->nRegion<=iRegion ){ |
| 52423 | 52631 | HANDLE hMap = NULL; /* file-mapping handle */ |
| 52424 | 52632 | void *pMap = 0; /* Mapped memory region */ |
| 52425 | 52633 | |
| 52634 | +#ifdef SQLITE_UWP | |
| 52635 | + hMap = osCreateFileMappingFromApp(hShared, NULL, protect, nByte, NULL); | |
| 52636 | +#else | |
| 52426 | 52637 | hMap = osCreateFileMappingW(hShared, NULL, protect, 0, nByte, NULL); |
| 52427 | - OSTRACE(("SHM-MAP-CREATE pid=%lu, region=%d, size=%d, rc=%s\n", | |
| 52638 | +#endif | |
| 52639 | + OSTRACE(("SHM-MAP-CREATE pid=%lu, region=%d, size=%lld, rc=%s\n", | |
| 52428 | 52640 | osGetCurrentProcessId(), pShmNode->nRegion, nByte, |
| 52429 | 52641 | hMap ? "ok" : "failed")); |
| 52430 | 52642 | if( hMap ){ |
| 52431 | - int iOffset = pShmNode->nRegion*szRegion; | |
| 52643 | + i64 iOffset = pShmNode->nRegion*szRegion; | |
| 52432 | 52644 | int iOffsetShift = iOffset % winSysInfo.dwAllocationGranularity; |
| 52645 | +#ifdef SQLITE_UWP | |
| 52646 | + pMap = osMapViewOfFileFromApp(hMap, flags, | |
| 52647 | + iOffset - iOffsetShift, (i64)szRegion + iOffsetShift | |
| 52648 | + ); | |
| 52649 | +#else | |
| 52433 | 52650 | pMap = osMapViewOfFile(hMap, flags, |
| 52434 | - 0, iOffset - iOffsetShift, szRegion + iOffsetShift | |
| 52651 | + 0, iOffset - iOffsetShift, (i64)szRegion + iOffsetShift | |
| 52435 | 52652 | ); |
| 52653 | +#endif | |
| 52436 | 52654 | OSTRACE(("SHM-MAP-MAP pid=%lu, region=%d, offset=%d, size=%d, rc=%s\n", |
| 52437 | 52655 | osGetCurrentProcessId(), pShmNode->nRegion, iOffset, |
| 52438 | 52656 | szRegion, pMap ? "ok" : "failed")); |
| 52439 | 52657 | } |
| 52440 | 52658 | if( !pMap ){ |
| @@ -52451,11 +52669,11 @@ | ||
| 52451 | 52669 | } |
| 52452 | 52670 | } |
| 52453 | 52671 | |
| 52454 | 52672 | shmpage_out: |
| 52455 | 52673 | if( pShmNode->nRegion>iRegion ){ |
| 52456 | - int iOffset = iRegion*szRegion; | |
| 52674 | + i64 iOffset = (i64)iRegion*(i64)szRegion; | |
| 52457 | 52675 | int iOffsetShift = iOffset % winSysInfo.dwAllocationGranularity; |
| 52458 | 52676 | char *p = (char *)pShmNode->aRegion[iRegion].pMap; |
| 52459 | 52677 | *pp = (void *)&p[iOffsetShift]; |
| 52460 | 52678 | }else{ |
| 52461 | 52679 | *pp = 0; |
| @@ -52563,13 +52781,17 @@ | ||
| 52563 | 52781 | if( (pFd->ctrlFlags & WINFILE_RDONLY)==0 ){ |
| 52564 | 52782 | protect = PAGE_READWRITE; |
| 52565 | 52783 | flags |= FILE_MAP_WRITE; |
| 52566 | 52784 | } |
| 52567 | 52785 | #endif |
| 52786 | +#ifdef SQLITE_UWP | |
| 52787 | + pFd->hMap = osCreateFileMappingFromApp(pFd->h, NULL, protect, nMap, NULL); | |
| 52788 | +#else | |
| 52568 | 52789 | pFd->hMap = osCreateFileMappingW(pFd->h, NULL, protect, |
| 52569 | 52790 | (DWORD)((nMap>>32) & 0xffffffff), |
| 52570 | 52791 | (DWORD)(nMap & 0xffffffff), NULL); |
| 52792 | +#endif | |
| 52571 | 52793 | if( pFd->hMap==NULL ){ |
| 52572 | 52794 | pFd->lastErrno = osGetLastError(); |
| 52573 | 52795 | rc = winLogError(SQLITE_IOERR_MMAP, pFd->lastErrno, |
| 52574 | 52796 | "winMapfile1", pFd->zPath); |
| 52575 | 52797 | /* Log the error, but continue normal operation using xRead/xWrite */ |
| @@ -52577,11 +52799,15 @@ | ||
| 52577 | 52799 | osGetCurrentProcessId(), pFd, sqlite3ErrName(rc))); |
| 52578 | 52800 | return SQLITE_OK; |
| 52579 | 52801 | } |
| 52580 | 52802 | assert( (nMap % winSysInfo.dwPageSize)==0 ); |
| 52581 | 52803 | assert( sizeof(SIZE_T)==sizeof(sqlite3_int64) || nMap<=0xffffffff ); |
| 52804 | +#ifdef SQLITE_UWP | |
| 52805 | + pNew = osMapViewOfFileFromApp(pFd->hMap, flags, 0, (SIZE_T)nMap); | |
| 52806 | +#else | |
| 52582 | 52807 | pNew = osMapViewOfFile(pFd->hMap, flags, 0, 0, (SIZE_T)nMap); |
| 52808 | +#endif | |
| 52583 | 52809 | if( pNew==NULL ){ |
| 52584 | 52810 | osCloseHandle(pFd->hMap); |
| 52585 | 52811 | pFd->hMap = NULL; |
| 52586 | 52812 | pFd->lastErrno = osGetLastError(); |
| 52587 | 52813 | rc = winLogError(SQLITE_IOERR_MMAP, pFd->lastErrno, |
| @@ -52920,11 +53146,11 @@ | ||
| 52920 | 53146 | if( !zWidePath ){ |
| 52921 | 53147 | sqlite3_free(zBuf); |
| 52922 | 53148 | OSTRACE(("TEMP-FILENAME rc=SQLITE_IOERR_NOMEM\n")); |
| 52923 | 53149 | return SQLITE_IOERR_NOMEM_BKPT; |
| 52924 | 53150 | } |
| 52925 | - if( osGetTempPathW(nMax, zWidePath)==0 ){ | |
| 53151 | + if( osGetTempPathW==0 || osGetTempPathW(nMax, zWidePath)==0 ){ | |
| 52926 | 53152 | sqlite3_free(zWidePath); |
| 52927 | 53153 | sqlite3_free(zBuf); |
| 52928 | 53154 | OSTRACE(("TEMP-FILENAME rc=SQLITE_IOERR_GETTEMPPATH\n")); |
| 52929 | 53155 | return winLogError(SQLITE_IOERR_GETTEMPPATH, osGetLastError(), |
| 52930 | 53156 | "winGetTempname2", 0); |
| @@ -53723,37 +53949,37 @@ | ||
| 53723 | 53949 | /* |
| 53724 | 53950 | ** Interfaces for opening a shared library, finding entry points |
| 53725 | 53951 | ** within the shared library, and closing the shared library. |
| 53726 | 53952 | */ |
| 53727 | 53953 | static void *winDlOpen(sqlite3_vfs *pVfs, const char *zFilename){ |
| 53728 | - HANDLE h; | |
| 53954 | + HANDLE h = 0; | |
| 53729 | 53955 | void *zConverted = winConvertFromUtf8Filename(zFilename); |
| 53730 | 53956 | UNUSED_PARAMETER(pVfs); |
| 53731 | 53957 | if( zConverted==0 ){ |
| 53732 | 53958 | OSTRACE(("DLOPEN name=%s, handle=%p\n", zFilename, (void*)0)); |
| 53733 | 53959 | return 0; |
| 53734 | 53960 | } |
| 53735 | - h = osLoadLibraryW((LPCWSTR)zConverted); | |
| 53961 | + h = osLoadLibraryW ? osLoadLibraryW((LPCWSTR)zConverted) : 0; | |
| 53736 | 53962 | OSTRACE(("DLOPEN name=%s, handle=%p\n", zFilename, (void*)h)); |
| 53737 | 53963 | sqlite3_free(zConverted); |
| 53738 | 53964 | return (void*)h; |
| 53739 | 53965 | } |
| 53740 | 53966 | static void winDlError(sqlite3_vfs *pVfs, int nBuf, char *zBufOut){ |
| 53741 | 53967 | UNUSED_PARAMETER(pVfs); |
| 53742 | 53968 | winGetLastErrorMsg(osGetLastError(), nBuf, zBufOut); |
| 53743 | 53969 | } |
| 53744 | 53970 | static void (*winDlSym(sqlite3_vfs *pVfs,void *pH,const char *zSym))(void){ |
| 53745 | - FARPROC proc; | |
| 53971 | + FARPROC proc = 0; | |
| 53746 | 53972 | UNUSED_PARAMETER(pVfs); |
| 53747 | - proc = osGetProcAddressA((HANDLE)pH, zSym); | |
| 53973 | + proc = osGetProcAddressA ? osGetProcAddressA((HANDLE)pH, zSym) : 0; | |
| 53748 | 53974 | OSTRACE(("DLSYM handle=%p, symbol=%s, address=%p\n", |
| 53749 | 53975 | (void*)pH, zSym, (void*)proc)); |
| 53750 | 53976 | return (void(*)(void))proc; |
| 53751 | 53977 | } |
| 53752 | 53978 | static void winDlClose(sqlite3_vfs *pVfs, void *pHandle){ |
| 53753 | 53979 | UNUSED_PARAMETER(pVfs); |
| 53754 | - osFreeLibrary((HANDLE)pHandle); | |
| 53980 | + if( osFreeLibrary!=0 ) osFreeLibrary((HANDLE)pHandle); | |
| 53755 | 53981 | OSTRACE(("DLCLOSE handle=%p\n", (void*)pHandle)); |
| 53756 | 53982 | } |
| 53757 | 53983 | #else /* if SQLITE_OMIT_LOAD_EXTENSION is defined: */ |
| 53758 | 53984 | #define winDlOpen 0 |
| 53759 | 53985 | #define winDlError 0 |
| @@ -53798,36 +54024,39 @@ | ||
| 53798 | 54024 | e.a = (unsigned char*)zBuf; |
| 53799 | 54025 | e.na = nBuf; |
| 53800 | 54026 | e.nXor = 0; |
| 53801 | 54027 | e.i = 0; |
| 53802 | 54028 | { |
| 53803 | - SYSTEMTIME x; | |
| 53804 | - osGetSystemTime(&x); | |
| 53805 | - xorMemory(&e, (unsigned char*)&x, sizeof(SYSTEMTIME)); | |
| 54029 | + FILETIME x; | |
| 54030 | + osGetSystemTimeAsFileTime(&x); | |
| 54031 | + xorMemory(&e, (unsigned char*)&x, sizeof(x)); | |
| 53806 | 54032 | } |
| 53807 | 54033 | { |
| 53808 | 54034 | DWORD pid = osGetCurrentProcessId(); |
| 53809 | - xorMemory(&e, (unsigned char*)&pid, sizeof(DWORD)); | |
| 54035 | + xorMemory(&e, (unsigned char*)&pid, sizeof(pid)); | |
| 53810 | 54036 | } |
| 53811 | 54037 | { |
| 53812 | - DWORD cnt = osGetTickCount(); | |
| 53813 | - xorMemory(&e, (unsigned char*)&cnt, sizeof(DWORD)); | |
| 54038 | + ULONGLONG cnt = osGetTickCount64(); | |
| 54039 | + xorMemory(&e, (unsigned char*)&cnt, sizeof(cnt)); | |
| 53814 | 54040 | } |
| 53815 | 54041 | { |
| 53816 | 54042 | LARGE_INTEGER i; |
| 53817 | 54043 | osQueryPerformanceCounter(&i); |
| 53818 | - xorMemory(&e, (unsigned char*)&i, sizeof(LARGE_INTEGER)); | |
| 54044 | + xorMemory(&e, (unsigned char*)&i, sizeof(i)); | |
| 53819 | 54045 | } |
| 53820 | 54046 | #if SQLITE_WIN32_USE_UUID |
| 54047 | +#ifdef SQLITE_UWP | |
| 54048 | +# error SQLITE_WIN32_USE_UUID is incompatible with SQLITE_UWP | |
| 54049 | +#endif | |
| 53821 | 54050 | { |
| 53822 | 54051 | UUID id; |
| 53823 | - memset(&id, 0, sizeof(UUID)); | |
| 54052 | + memset(&id, 0, sizeof(id)); | |
| 53824 | 54053 | osUuidCreate(&id); |
| 53825 | - xorMemory(&e, (unsigned char*)&id, sizeof(UUID)); | |
| 54054 | + xorMemory(&e, (unsigned char*)&id, sizeof(id)); | |
| 53826 | 54055 | memset(&id, 0, sizeof(UUID)); |
| 53827 | 54056 | osUuidCreateSequential(&id); |
| 53828 | - xorMemory(&e, (unsigned char*)&id, sizeof(UUID)); | |
| 54057 | + xorMemory(&e, (unsigned char*)&id, sizeof(id)); | |
| 53829 | 54058 | } |
| 53830 | 54059 | #endif /* SQLITE_WIN32_USE_UUID */ |
| 53831 | 54060 | return e.nXor>nBuf ? nBuf : e.nXor; |
| 53832 | 54061 | #endif /* defined(SQLITE_TEST) || defined(SQLITE_OMIT_RANDOMNESS) */ |
| 53833 | 54062 | } |
| @@ -54042,15 +54271,19 @@ | ||
| 54042 | 54271 | winNextSystemCall, /* xNextSystemCall */ |
| 54043 | 54272 | }; |
| 54044 | 54273 | |
| 54045 | 54274 | /* Double-check that the aSyscall[] array has been constructed |
| 54046 | 54275 | ** correctly. See ticket [bb3a86e890c8e96ab] */ |
| 54047 | - assert( ArraySize(aSyscall)==58 ); | |
| 54276 | + assert( ArraySize(aSyscall)==59 ); | |
| 54048 | 54277 | assert( strcmp(aSyscall[0].zName,"AreFileApisANSI")==0 ); |
| 54049 | - assert( strcmp(aSyscall[20].zName,"HeapAlloc")==0 ); | |
| 54050 | - assert( strcmp(aSyscall[40].zName,"WideCharToMultiByte")==0 ); | |
| 54051 | - assert( strcmp(aSyscall[57].zName,"cygwin_conv_path")==0 ); | |
| 54278 | + assert( strcmp(aSyscall[8].zName,"FreeLibrary")==0 ); | |
| 54279 | + assert( strcmp(aSyscall[16].zName,"GetSystemInfo")==0 ); | |
| 54280 | + assert( strcmp(aSyscall[24].zName,"HeapReAlloc")==0 ); | |
| 54281 | + assert( strcmp(aSyscall[32].zName,"MapViewOfFileFromApp")==0 ); | |
| 54282 | + assert( strcmp(aSyscall[40].zName,"UnmapViewOfFile")==0 ); | |
| 54283 | + assert( strcmp(aSyscall[48].zName,"UuidCreate")==0 ); | |
| 54284 | + assert( strcmp(aSyscall[56].zName,"lstat")==0 ); | |
| 54052 | 54285 | |
| 54053 | 54286 | /* get memory map allocation granularity */ |
| 54054 | 54287 | memset(&winSysInfo, 0, sizeof(SYSTEM_INFO)); |
| 54055 | 54288 | osGetSystemInfo(&winSysInfo); |
| 54056 | 54289 | assert( winSysInfo.dwAllocationGranularity>0 ); |
| @@ -56762,26 +56995,28 @@ | ||
| 56762 | 56995 | szBulk = -1024 * (i64)pcache1.nInitPage; |
| 56763 | 56996 | } |
| 56764 | 56997 | if( szBulk > pCache->szAlloc*(i64)pCache->nMax ){ |
| 56765 | 56998 | szBulk = pCache->szAlloc*(i64)pCache->nMax; |
| 56766 | 56999 | } |
| 56767 | - zBulk = pCache->pBulk = sqlite3Malloc( szBulk ); | |
| 56768 | - sqlite3EndBenignMalloc(); | |
| 56769 | - if( zBulk ){ | |
| 56770 | - int nBulk = sqlite3MallocSize(zBulk)/pCache->szAlloc; | |
| 56771 | - do{ | |
| 56772 | - PgHdr1 *pX = (PgHdr1*)&zBulk[pCache->szPage]; | |
| 56773 | - pX->page.pBuf = zBulk; | |
| 56774 | - pX->page.pExtra = (u8*)pX + ROUND8(sizeof(*pX)); | |
| 56775 | - assert( EIGHT_BYTE_ALIGNMENT( pX->page.pExtra ) ); | |
| 56776 | - pX->isBulkLocal = 1; | |
| 56777 | - pX->isAnchor = 0; | |
| 56778 | - pX->pNext = pCache->pFree; | |
| 56779 | - pX->pLruPrev = 0; /* Initializing this saves a valgrind error */ | |
| 56780 | - pCache->pFree = pX; | |
| 56781 | - zBulk += pCache->szAlloc; | |
| 56782 | - }while( --nBulk ); | |
| 57000 | + if( szBulk>=pCache->szAlloc ){ | |
| 57001 | + zBulk = pCache->pBulk = sqlite3Malloc( szBulk ); | |
| 57002 | + sqlite3EndBenignMalloc(); | |
| 57003 | + if( zBulk ){ | |
| 57004 | + int nBulk = sqlite3MallocSize(zBulk)/pCache->szAlloc; | |
| 57005 | + do{ | |
| 57006 | + PgHdr1 *pX = (PgHdr1*)&zBulk[pCache->szPage]; | |
| 57007 | + pX->page.pBuf = zBulk; | |
| 57008 | + pX->page.pExtra = (u8*)pX + ROUND8(sizeof(*pX)); | |
| 57009 | + assert( EIGHT_BYTE_ALIGNMENT( pX->page.pExtra ) ); | |
| 57010 | + pX->isBulkLocal = 1; | |
| 57011 | + pX->isAnchor = 0; | |
| 57012 | + pX->pNext = pCache->pFree; | |
| 57013 | + pX->pLruPrev = 0; /* Initializing this saves a valgrind error */ | |
| 57014 | + pCache->pFree = pX; | |
| 57015 | + zBulk += pCache->szAlloc; | |
| 57016 | + }while( --nBulk ); | |
| 57017 | + } | |
| 56783 | 57018 | } |
| 56784 | 57019 | return pCache->pFree!=0; |
| 56785 | 57020 | } |
| 56786 | 57021 | |
| 56787 | 57022 | /* |
| @@ -59675,73 +59910,84 @@ | ||
| 59675 | 59910 | #define pager_set_pagehash(X) |
| 59676 | 59911 | #define CHECK_PAGE(x) |
| 59677 | 59912 | #endif /* SQLITE_CHECK_PAGES */ |
| 59678 | 59913 | |
| 59679 | 59914 | /* |
| 59680 | -** When this is called the journal file for pager pPager must be open. | |
| 59681 | -** This function attempts to read a super-journal file name from the | |
| 59682 | -** end of the file and, if successful, copies it into memory supplied | |
| 59683 | -** by the caller. See comments above writeSuperJournal() for the format | |
| 59684 | -** used to store a super-journal file name at the end of a journal file. | |
| 59685 | -** | |
| 59686 | -** zSuper must point to a buffer of at least nSuper bytes allocated by | |
| 59687 | -** the caller. This should be sqlite3_vfs.mxPathname+1 (to ensure there is | |
| 59688 | -** enough space to write the super-journal name). If the super-journal | |
| 59689 | -** name in the journal is longer than nSuper bytes (including a | |
| 59690 | -** nul-terminator), then this is handled as if no super-journal name | |
| 59691 | -** were present in the journal. | |
| 59692 | -** | |
| 59693 | -** If a super-journal file name is present at the end of the journal | |
| 59694 | -** file, then it is copied into the buffer pointed to by zSuper. A | |
| 59695 | -** nul-terminator byte is appended to the buffer following the | |
| 59696 | -** super-journal file name. | |
| 59697 | -** | |
| 59698 | -** If it is determined that no super-journal file name is present | |
| 59699 | -** zSuper[0] is set to 0 and SQLITE_OK returned. | |
| 59700 | -** | |
| 59701 | -** If an error occurs while reading from the journal file, an SQLite | |
| 59702 | -** error code is returned. | |
| 59703 | -*/ | |
| 59704 | -static int readSuperJournal(sqlite3_file *pJrnl, char *zSuper, u64 nSuper){ | |
| 59915 | +** Free a buffer allocated by the readSuperJournal() function. | |
| 59916 | +*/ | |
| 59917 | +static void freeSuperJournal(char *zSuper){ | |
| 59918 | + if( zSuper ){ | |
| 59919 | + sqlite3_free(&zSuper[-4]); | |
| 59920 | + } | |
| 59921 | +} | |
| 59922 | + | |
| 59923 | +/* | |
| 59924 | +** Parameter pJrnl is a file-handle open on a journal file. This function | |
| 59925 | +** attempts to read a super-journal file name from the end of the journal | |
| 59926 | +** file. If successful, it sets output parameter (*pzSuper) to point to a | |
| 59927 | +** buffer containing the super-journal name as a nul-terminated string. | |
| 59928 | +** The caller is responsible for freeing the buffer using freeSuperJournal(). | |
| 59929 | +** | |
| 59930 | +** Refer to comments above writeSuperJournal() for the format used to store | |
| 59931 | +** a super-journal file name at the end of a journal file. | |
| 59932 | +** | |
| 59933 | +** Parameter nSuper is passed the maximum allowable size of the super journal | |
| 59934 | +** name in bytes. If the super-journal name in the journal is longer than | |
| 59935 | +** nSuper bytes (including a nul-terminator), then this is handled as if no | |
| 59936 | +** super-journal name were present in the journal. | |
| 59937 | +** | |
| 59938 | +** If there is no super-journal name at the end of pJrnl, (*pzSuper) is | |
| 59939 | +** set to 0 and SQLITE_OK is returned. Or, if an error occurs while reading | |
| 59940 | +** the super-journal name, an SQLite error code is returned and (*pzSuper) | |
| 59941 | +** is set to 0. | |
| 59942 | +*/ | |
| 59943 | +static int readSuperJournal(sqlite3_file *pJrnl, u64 nSuper, char **pzSuper){ | |
| 59705 | 59944 | int rc; /* Return code */ |
| 59706 | 59945 | u32 len; /* Length in bytes of super-journal name */ |
| 59707 | 59946 | i64 szJ; /* Total size in bytes of journal file pJrnl */ |
| 59708 | 59947 | u32 cksum; /* MJ checksum value read from journal */ |
| 59709 | - u32 u; /* Unsigned loop counter */ | |
| 59710 | 59948 | unsigned char aMagic[8]; /* A buffer to hold the magic header */ |
| 59711 | - zSuper[0] = '\0'; | |
| 59949 | + char *zOut = 0; | |
| 59712 | 59950 | |
| 59951 | + *pzSuper = 0; | |
| 59713 | 59952 | if( SQLITE_OK!=(rc = sqlite3OsFileSize(pJrnl, &szJ)) |
| 59714 | 59953 | || szJ<16 |
| 59715 | 59954 | || SQLITE_OK!=(rc = read32bits(pJrnl, szJ-16, &len)) |
| 59716 | 59955 | || len>=nSuper |
| 59717 | 59956 | || len>szJ-16 |
| 59718 | 59957 | || len==0 |
| 59719 | 59958 | || SQLITE_OK!=(rc = read32bits(pJrnl, szJ-12, &cksum)) |
| 59720 | 59959 | || SQLITE_OK!=(rc = sqlite3OsRead(pJrnl, aMagic, 8, szJ-8)) |
| 59721 | 59960 | || memcmp(aMagic, aJournalMagic, 8) |
| 59722 | - || SQLITE_OK!=(rc = sqlite3OsRead(pJrnl, zSuper, len, szJ-16-len)) | |
| 59723 | 59961 | ){ |
| 59724 | 59962 | return rc; |
| 59725 | 59963 | } |
| 59726 | 59964 | |
| 59727 | - /* See if the checksum matches the super-journal name */ | |
| 59728 | - for(u=0; u<len; u++){ | |
| 59729 | - cksum -= zSuper[u]; | |
| 59730 | - } | |
| 59731 | - if( cksum ){ | |
| 59732 | - /* If the checksum doesn't add up, then one or more of the disk sectors | |
| 59733 | - ** containing the super-journal filename is corrupted. This means | |
| 59734 | - ** definitely roll back, so just return SQLITE_OK and report a (nul) | |
| 59735 | - ** super-journal filename. | |
| 59736 | - */ | |
| 59737 | - len = 0; | |
| 59738 | - } | |
| 59739 | - zSuper[len] = '\0'; | |
| 59740 | - zSuper[len+1] = '\0'; | |
| 59741 | - | |
| 59742 | - return SQLITE_OK; | |
| 59965 | + zOut = (char*)sqlite3MallocZero(4 + len + 2); | |
| 59966 | + if( !zOut ){ | |
| 59967 | + rc = SQLITE_NOMEM_BKPT; | |
| 59968 | + }else{ | |
| 59969 | + zOut = &zOut[4]; | |
| 59970 | + if( SQLITE_OK==(rc = sqlite3OsRead(pJrnl, zOut, len, szJ-16-len)) ){ | |
| 59971 | + u32 u; /* Unsigned loop counter */ | |
| 59972 | + /* See if the checksum matches the super-journal name */ | |
| 59973 | + for(u=0; u<len; u++){ | |
| 59974 | + cksum -= zOut[u]; | |
| 59975 | + } | |
| 59976 | + } | |
| 59977 | + if( rc!=SQLITE_OK || cksum ){ | |
| 59978 | + /* If the checksum doesn't add up, then one or more of the disk sectors | |
| 59979 | + ** containing the super-journal filename is corrupted. This means | |
| 59980 | + ** definitely roll back, so just return SQLITE_OK and report a (nul) | |
| 59981 | + ** super-journal filename. */ | |
| 59982 | + freeSuperJournal(zOut); | |
| 59983 | + zOut = 0; | |
| 59984 | + } | |
| 59985 | + } | |
| 59986 | + | |
| 59987 | + *pzSuper = zOut; | |
| 59988 | + return rc; | |
| 59743 | 59989 | } |
| 59744 | 59990 | |
| 59745 | 59991 | /* |
| 59746 | 59992 | ** Return the offset of the sector boundary at or immediately |
| 59747 | 59993 | ** following the value in pPager->journalOff, assuming a sector |
| @@ -60942,13 +61188,11 @@ | ||
| 60942 | 61188 | sqlite3_file *pSuper; /* Malloc'd super-journal file descriptor */ |
| 60943 | 61189 | sqlite3_file *pJournal; /* Malloc'd child-journal file descriptor */ |
| 60944 | 61190 | char *zSuperJournal = 0; /* Contents of super-journal file */ |
| 60945 | 61191 | i64 nSuperJournal; /* Size of super-journal file */ |
| 60946 | 61192 | char *zJournal; /* Pointer to one journal within MJ file */ |
| 60947 | - char *zSuperPtr; /* Space to hold super-journal filename */ | |
| 60948 | 61193 | char *zFree = 0; /* Free this buffer */ |
| 60949 | - i64 nSuperPtr; /* Amount of space allocated to zSuperPtr[] */ | |
| 60950 | 61194 | |
| 60951 | 61195 | /* Allocate space for both the pJournal and pSuper file descriptors. |
| 60952 | 61196 | ** If successful, open the super-journal file for reading. |
| 60953 | 61197 | */ |
| 60954 | 61198 | pSuper = (sqlite3_file *)sqlite3MallocZero(2 * (i64)pVfs->szOsFile); |
| @@ -60967,22 +61211,20 @@ | ||
| 60967 | 61211 | ** sufficient space (in zSuperPtr) to hold the names of super-journal |
| 60968 | 61212 | ** files extracted from regular rollback-journals. |
| 60969 | 61213 | */ |
| 60970 | 61214 | rc = sqlite3OsFileSize(pSuper, &nSuperJournal); |
| 60971 | 61215 | if( rc!=SQLITE_OK ) goto delsuper_out; |
| 60972 | - nSuperPtr = 1 + (i64)pVfs->mxPathname; | |
| 60973 | - assert( nSuperJournal>=0 && nSuperPtr>0 ); | |
| 60974 | - zFree = sqlite3Malloc(4 + nSuperJournal + nSuperPtr + 2); | |
| 61216 | + assert( nSuperJournal>=0 ); | |
| 61217 | + zFree = sqlite3Malloc(4 + nSuperJournal + 2); | |
| 60975 | 61218 | if( !zFree ){ |
| 60976 | 61219 | rc = SQLITE_NOMEM_BKPT; |
| 60977 | 61220 | goto delsuper_out; |
| 60978 | 61221 | }else{ |
| 60979 | 61222 | assert( nSuperJournal<=0x7fffffff ); |
| 60980 | 61223 | } |
| 60981 | 61224 | zFree[0] = zFree[1] = zFree[2] = zFree[3] = 0; |
| 60982 | 61225 | zSuperJournal = &zFree[4]; |
| 60983 | - zSuperPtr = &zSuperJournal[nSuperJournal+2]; | |
| 60984 | 61226 | rc = sqlite3OsRead(pSuper, zSuperJournal, (int)nSuperJournal, 0); |
| 60985 | 61227 | if( rc!=SQLITE_OK ) goto delsuper_out; |
| 60986 | 61228 | zSuperJournal[nSuperJournal] = 0; |
| 60987 | 61229 | zSuperJournal[nSuperJournal+1] = 0; |
| 60988 | 61230 | |
| @@ -60992,10 +61234,12 @@ | ||
| 60992 | 61234 | rc = sqlite3OsAccess(pVfs, zJournal, SQLITE_ACCESS_EXISTS, &exists); |
| 60993 | 61235 | if( rc!=SQLITE_OK ){ |
| 60994 | 61236 | goto delsuper_out; |
| 60995 | 61237 | } |
| 60996 | 61238 | if( exists ){ |
| 61239 | + char *zSuperPtr = 0; | |
| 61240 | + | |
| 60997 | 61241 | /* One of the journals pointed to by the super-journal exists. |
| 60998 | 61242 | ** Open it and check if it points at the super-journal. If |
| 60999 | 61243 | ** so, return without deleting the super-journal file. |
| 61000 | 61244 | ** NB: zJournal is really a MAIN_JOURNAL. But call it a |
| 61001 | 61245 | ** SUPER_JOURNAL here so that the VFS will not send the zJournal |
| @@ -61006,17 +61250,19 @@ | ||
| 61006 | 61250 | rc = sqlite3OsOpen(pVfs, zJournal, pJournal, flags, 0); |
| 61007 | 61251 | if( rc!=SQLITE_OK ){ |
| 61008 | 61252 | goto delsuper_out; |
| 61009 | 61253 | } |
| 61010 | 61254 | |
| 61011 | - rc = readSuperJournal(pJournal, zSuperPtr, nSuperPtr); | |
| 61255 | + rc = readSuperJournal(pJournal, 1+(u64)pVfs->mxPathname, &zSuperPtr); | |
| 61012 | 61256 | sqlite3OsClose(pJournal); |
| 61013 | 61257 | if( rc!=SQLITE_OK ){ |
| 61258 | + assert( zSuperPtr==0 ); | |
| 61014 | 61259 | goto delsuper_out; |
| 61015 | 61260 | } |
| 61016 | 61261 | |
| 61017 | - c = zSuperPtr[0]!=0 && strcmp(zSuperPtr, zSuper)==0; | |
| 61262 | + c = zSuperPtr!=0 && strcmp(zSuperPtr, zSuper)==0; | |
| 61263 | + freeSuperJournal(zSuperPtr); | |
| 61018 | 61264 | if( c ){ |
| 61019 | 61265 | /* We have a match. Do not delete the super-journal file. */ |
| 61020 | 61266 | goto delsuper_out; |
| 61021 | 61267 | } |
| 61022 | 61268 | } |
| @@ -61227,23 +61473,15 @@ | ||
| 61227 | 61473 | |
| 61228 | 61474 | /* Read the super-journal name from the journal, if it is present. |
| 61229 | 61475 | ** If a super-journal file name is specified, but the file is not |
| 61230 | 61476 | ** present on disk, then the journal is not hot and does not need to be |
| 61231 | 61477 | ** played back. |
| 61232 | - ** | |
| 61233 | - ** TODO: Technically the following is an error because it assumes that | |
| 61234 | - ** buffer Pager.pTmpSpace is (mxPathname+1) bytes or larger. i.e. that | |
| 61235 | - ** (pPager->pageSize >= pPager->pVfs->mxPathname+1). Using os_unix.c, | |
| 61236 | - ** mxPathname is 512, which is the same as the minimum allowable value | |
| 61237 | - ** for pageSize. | |
| 61238 | 61478 | */ |
| 61239 | - zSuper = pPager->pTmpSpace; | |
| 61240 | - rc = readSuperJournal(pPager->jfd, zSuper, 1+(i64)pPager->pVfs->mxPathname); | |
| 61241 | - if( rc==SQLITE_OK && zSuper[0] ){ | |
| 61479 | + rc = readSuperJournal(pPager->jfd, 1+(i64)pPager->pVfs->mxPathname, &zSuper); | |
| 61480 | + if( rc==SQLITE_OK && zSuper ){ | |
| 61242 | 61481 | rc = sqlite3OsAccess(pVfs, zSuper, SQLITE_ACCESS_EXISTS, &res); |
| 61243 | 61482 | } |
| 61244 | - zSuper = 0; | |
| 61245 | 61483 | if( rc!=SQLITE_OK || !res ){ |
| 61246 | 61484 | goto end_playback; |
| 61247 | 61485 | } |
| 61248 | 61486 | pPager->journalOff = 0; |
| 61249 | 61487 | needPagerReset = isHot; |
| @@ -61368,34 +61606,24 @@ | ||
| 61368 | 61606 | ** problems for other processes at some point in the future. So, just |
| 61369 | 61607 | ** in case this has happened, clear the changeCountDone flag now. |
| 61370 | 61608 | */ |
| 61371 | 61609 | pPager->changeCountDone = pPager->tempFile; |
| 61372 | 61610 | |
| 61373 | - if( rc==SQLITE_OK ){ | |
| 61374 | - /* Leave 4 bytes of space before the super-journal filename in memory. | |
| 61375 | - ** This is because it may end up being passed to sqlite3OsOpen(), in | |
| 61376 | - ** which case it requires 4 0x00 bytes in memory immediately before | |
| 61377 | - ** the filename. */ | |
| 61378 | - zSuper = &pPager->pTmpSpace[4]; | |
| 61379 | - rc = readSuperJournal(pPager->jfd, zSuper, 1+(i64)pPager->pVfs->mxPathname); | |
| 61380 | - testcase( rc!=SQLITE_OK ); | |
| 61381 | - } | |
| 61382 | 61611 | if( rc==SQLITE_OK |
| 61383 | 61612 | && (pPager->eState>=PAGER_WRITER_DBMOD || pPager->eState==PAGER_OPEN) |
| 61384 | 61613 | ){ |
| 61385 | 61614 | rc = sqlite3PagerSync(pPager, 0); |
| 61386 | 61615 | } |
| 61387 | 61616 | if( rc==SQLITE_OK ){ |
| 61388 | - rc = pager_end_transaction(pPager, zSuper[0]!='\0', 0); | |
| 61617 | + rc = pager_end_transaction(pPager, zSuper!=0, 0); | |
| 61389 | 61618 | testcase( rc!=SQLITE_OK ); |
| 61390 | 61619 | } |
| 61391 | - if( rc==SQLITE_OK && zSuper[0] && res ){ | |
| 61620 | + if( rc==SQLITE_OK && zSuper && res ){ | |
| 61392 | 61621 | /* If there was a super-journal and this routine will return success, |
| 61393 | 61622 | ** see if it is possible to delete the super-journal. |
| 61394 | 61623 | */ |
| 61395 | - assert( zSuper==&pPager->pTmpSpace[4] ); | |
| 61396 | - memset(pPager->pTmpSpace, 0, 4); | |
| 61624 | + assert( memcmp(&zSuper[-4], "\0\0\0\0", 4)==0 ); | |
| 61397 | 61625 | rc = pager_delsuper(pPager, zSuper); |
| 61398 | 61626 | testcase( rc!=SQLITE_OK ); |
| 61399 | 61627 | } |
| 61400 | 61628 | if( isHot && nPlayback ){ |
| 61401 | 61629 | sqlite3_log(SQLITE_NOTICE_RECOVER_ROLLBACK, "recovered %d pages from %s", |
| @@ -61404,10 +61632,11 @@ | ||
| 61404 | 61632 | |
| 61405 | 61633 | /* The Pager.sectorSize variable may have been updated while rolling |
| 61406 | 61634 | ** back a journal created by a process with a different sector size |
| 61407 | 61635 | ** value. Reset it to the correct value for this process. |
| 61408 | 61636 | */ |
| 61637 | + freeSuperJournal(zSuper); | |
| 61409 | 61638 | setSectorSize(pPager); |
| 61410 | 61639 | return rc; |
| 61411 | 61640 | } |
| 61412 | 61641 | |
| 61413 | 61642 | |
| @@ -67262,10 +67491,16 @@ | ||
| 67262 | 67491 | */ |
| 67263 | 67492 | pgno = sqlite3Get4byte(&aFrame[0]); |
| 67264 | 67493 | if( pgno==0 ){ |
| 67265 | 67494 | return 0; |
| 67266 | 67495 | } |
| 67496 | + | |
| 67497 | + /* Need a valid page size | |
| 67498 | + */ | |
| 67499 | + if( !pWal->szPage ){ | |
| 67500 | + return 0; | |
| 67501 | + } | |
| 67267 | 67502 | |
| 67268 | 67503 | /* A frame is only valid if a checksum of the WAL header, |
| 67269 | 67504 | ** all prior frames, the first 16 bytes of this frame-header, |
| 67270 | 67505 | ** and the frame-data matches the checksum in the last 8 |
| 67271 | 67506 | ** bytes of this frame-header. |
| @@ -69117,11 +69352,11 @@ | ||
| 69117 | 69352 | goto begin_unreliable_shm_out; |
| 69118 | 69353 | } |
| 69119 | 69354 | |
| 69120 | 69355 | /* Allocate a buffer to read frames into */ |
| 69121 | 69356 | assert( (pWal->szPage & (pWal->szPage-1))==0 ); |
| 69122 | - assert( pWal->szPage>=512 && pWal->szPage<=65536 ); | |
| 69357 | + assert( (pWal->szPage>=512 && pWal->szPage<=65536) || pWal->szPage==0 ); | |
| 69123 | 69358 | szFrame = pWal->szPage + WAL_FRAME_HDRSIZE; |
| 69124 | 69359 | aFrame = (u8 *)sqlite3_malloc64(szFrame); |
| 69125 | 69360 | if( aFrame==0 ){ |
| 69126 | 69361 | rc = SQLITE_NOMEM_BKPT; |
| 69127 | 69362 | goto begin_unreliable_shm_out; |
| @@ -71953,10 +72188,20 @@ | ||
| 71953 | 72188 | ** See the header comment on "btreeInt.h" for additional information. |
| 71954 | 72189 | ** Including a description of file format and an overview of operation. |
| 71955 | 72190 | */ |
| 71956 | 72191 | /* #include "btreeInt.h" */ |
| 71957 | 72192 | |
| 72193 | +/* | |
| 72194 | +** Suppress false-positive compiler warnings from GCC. Warnings are | |
| 72195 | +** re-enabled at the bottom of this source file. | |
| 72196 | +*/ | |
| 72197 | +#if defined(__GNUC__) && __GNUC__>=11 | |
| 72198 | +# pragma GCC diagnostic push | |
| 72199 | +# pragma GCC diagnostic ignored "-Wstringop-overread" | |
| 72200 | +# pragma GCC diagnostic ignored "-Wstringop-overflow" | |
| 72201 | +#endif | |
| 72202 | + | |
| 71958 | 72203 | /* |
| 71959 | 72204 | ** The header string that appears at the beginning of every |
| 71960 | 72205 | ** SQLite database. |
| 71961 | 72206 | */ |
| 71962 | 72207 | static const char zMagicHeader[] = SQLITE_FILE_HEADER; |
| @@ -77123,11 +77368,13 @@ | ||
| 77123 | 77368 | ** in the overflow chain. The page number of the first overflow page is |
| 77124 | 77369 | ** stored in aOverflow[0], etc. A value of 0 in the aOverflow[] array |
| 77125 | 77370 | ** means "not yet known" (the cache is lazily populated). |
| 77126 | 77371 | */ |
| 77127 | 77372 | if( (pCur->curFlags & BTCF_ValidOvfl)==0 ){ |
| 77128 | - int nOvfl = (pCur->info.nPayload-pCur->info.nLocal+ovflSize-1)/ovflSize; | |
| 77373 | + i64 nOvfl = pCur->info.nPayload; | |
| 77374 | + testcase( nOvfl - pCur->info.nLocal + ovflSize - 1 > 0xffffffffU ); | |
| 77375 | + nOvfl = (nOvfl - pCur->info.nLocal + ovflSize-1)/ovflSize; | |
| 77129 | 77376 | if( pCur->aOverflow==0 |
| 77130 | 77377 | || nOvfl*(int)sizeof(Pgno) > sqlite3MallocSize(pCur->aOverflow) |
| 77131 | 77378 | ){ |
| 77132 | 77379 | Pgno *aNew; |
| 77133 | 77380 | if( sqlite3FaultSim(413) ){ |
| @@ -77228,10 +77475,18 @@ | ||
| 77228 | 77475 | DbPage *pDbPage; |
| 77229 | 77476 | rc = sqlite3PagerGet(pBt->pPager, nextPage, &pDbPage, |
| 77230 | 77477 | (eOp==0 ? PAGER_GET_READONLY : 0) |
| 77231 | 77478 | ); |
| 77232 | 77479 | if( rc==SQLITE_OK ){ |
| 77480 | + if( eOp!=0 | |
| 77481 | + && (sqlite3PagerPageRefcount(pDbPage)!=1 | |
| 77482 | + || NEVER(((MemPage*)sqlite3PagerGetExtra(pDbPage))->isInit)) | |
| 77483 | + && sqlite3FaultSim(411)==SQLITE_OK | |
| 77484 | + ){ | |
| 77485 | + sqlite3PagerUnref(pDbPage); | |
| 77486 | + return SQLITE_CORRUPT_PAGE(pPage); | |
| 77487 | + } | |
| 77233 | 77488 | aPayload = sqlite3PagerGetData(pDbPage); |
| 77234 | 77489 | nextPage = get4byte(aPayload); |
| 77235 | 77490 | rc = copyPayload(&aPayload[offset+4], pBuf, a, eOp, pDbPage); |
| 77236 | 77491 | sqlite3PagerUnref(pDbPage); |
| 77237 | 77492 | offset = 0; |
| @@ -82902,10 +83157,15 @@ | ||
| 82902 | 83157 | if( pc+info.nSize>usableSize ){ |
| 82903 | 83158 | checkAppendMsg(pCheck, "Extends off end of page"); |
| 82904 | 83159 | doCoverageCheck = 0; |
| 82905 | 83160 | continue; |
| 82906 | 83161 | } |
| 83162 | + if( info.nPayload && info.pPayload[0]<2 ){ | |
| 83163 | + checkAppendMsg(pCheck, "Bad cell header size"); | |
| 83164 | + doCoverageCheck = 0; | |
| 83165 | + continue; | |
| 83166 | + } | |
| 82907 | 83167 | |
| 82908 | 83168 | /* Check for integer primary key out of range */ |
| 82909 | 83169 | if( pPage->intKey ){ |
| 82910 | 83170 | if( keyCanBeEqual ? (info.nKey > maxKey) : (info.nKey >= maxKey) ){ |
| 82911 | 83171 | checkAppendMsg(pCheck, "Rowid %lld out of order", info.nKey); |
| @@ -83504,10 +83764,17 @@ | ||
| 83504 | 83764 | SQLITE_PRIVATE int sqlite3BtreeConnectionCount(Btree *p){ |
| 83505 | 83765 | testcase( p->sharable ); |
| 83506 | 83766 | return p->pBt->nRef; |
| 83507 | 83767 | } |
| 83508 | 83768 | #endif |
| 83769 | + | |
| 83770 | +/* Re-enable GCC compiler warnings that were suppressed at the top | |
| 83771 | +** of this source file to prevent annoying false-positives. | |
| 83772 | +*/ | |
| 83773 | +#if defined(__GNUC__) && __GNUC__>=11 | |
| 83774 | +# pragma GCC diagnostic pop | |
| 83775 | +#endif | |
| 83509 | 83776 | |
| 83510 | 83777 | /************** End of btree.c ***********************************************/ |
| 83511 | 83778 | /************** Begin file backup.c ******************************************/ |
| 83512 | 83779 | /* |
| 83513 | 83780 | ** 2009 January 28 |
| @@ -84405,12 +84672,12 @@ | ||
| 84405 | 84672 | /* Work-around for GCC bug or bugs: |
| 84406 | 84673 | ** https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96270 |
| 84407 | 84674 | ** https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114659 |
| 84408 | 84675 | ** The problem appears to be fixed in GCC 15 */ |
| 84409 | 84676 | i64 x; |
| 84410 | - assert( (MEM_Str&~p->flags)*4==sizeof(x) ); | |
| 84411 | - memcpy(&x, (char*)&p->u, (MEM_Str&~p->flags)*4); | |
| 84677 | + assert( (sqlite3Config.bSmallMalloc!=0xee)*8==sizeof(x) ); | |
| 84678 | + memcpy(&x, (char*)&p->u.i, (sqlite3Config.bSmallMalloc!=0xee)*8); | |
| 84412 | 84679 | p->n = sqlite3Int64ToText(x, zBuf); |
| 84413 | 84680 | #else |
| 84414 | 84681 | p->n = sqlite3Int64ToText(p->u.i, zBuf); |
| 84415 | 84682 | #endif |
| 84416 | 84683 | if( p->flags & MEM_IntReal ){ |
| @@ -87107,15 +87374,25 @@ | ||
| 87107 | 87374 | /* |
| 87108 | 87375 | ** Add an OP_ParseSchema opcode. This routine is broken out from |
| 87109 | 87376 | ** sqlite3VdbeAddOp4() since it needs to also needs to mark all btrees |
| 87110 | 87377 | ** as having been used. |
| 87111 | 87378 | ** |
| 87112 | -** The zWhere string must have been obtained from sqlite3_malloc(). | |
| 87379 | +** zWhere is a WHERE clause that defines which entries of the schema | |
| 87380 | +** to reparse. If zWhere==0, that means all entries. p5 is a mask | |
| 87381 | +** of INITFLAG_* values for the parse. | |
| 87382 | +** | |
| 87383 | +** In the current usage, the following are always true: | |
| 87384 | +** | |
| 87385 | +** ALTER TABLE: zWhere==0, p5!=0 | |
| 87386 | +** Otherwise: zWhere!=0, p5==0 | |
| 87387 | +** | |
| 87388 | +** The zWhere string must have been obtained from sqlite3DbMalloc(). | |
| 87113 | 87389 | ** This routine will take ownership of the allocated memory. |
| 87114 | 87390 | */ |
| 87115 | 87391 | SQLITE_PRIVATE void sqlite3VdbeAddParseSchemaOp(Vdbe *p, int iDb, char *zWhere, u16 p5){ |
| 87116 | 87392 | int j; |
| 87393 | + assert( p5==0 || zWhere==0 ); | |
| 87117 | 87394 | sqlite3VdbeAddOp4(p, OP_ParseSchema, iDb, 0, 0, zWhere, P4_DYNAMIC); |
| 87118 | 87395 | sqlite3VdbeChangeP5(p, p5); |
| 87119 | 87396 | for(j=0; j<p->db->nDb; j++) sqlite3VdbeUsesBtree(p, j); |
| 87120 | 87397 | sqlite3MayAbort(p->pParse); |
| 87121 | 87398 | } |
| @@ -95247,11 +95524,11 @@ | ||
| 95247 | 95524 | QueryPerformanceCounter(&tm); |
| 95248 | 95525 | return (sqlite3_uint64)tm.QuadPart; |
| 95249 | 95526 | } |
| 95250 | 95527 | |
| 95251 | 95528 | #elif !defined(__STRICT_ANSI__) && defined(__GNUC__) && \ |
| 95252 | - (defined(i386) || defined(__i386__) || defined(_M_IX86)) | |
| 95529 | + (defined(i586) || defined(__i586__) || defined(_M_IX86)) | |
| 95253 | 95530 | |
| 95254 | 95531 | __inline__ sqlite_uint64 sqlite3Hwtime(void){ |
| 95255 | 95532 | unsigned int lo, hi; |
| 95256 | 95533 | __asm__ __volatile__ ("rdtsc" : "=a" (lo), "=d" (hi)); |
| 95257 | 95534 | return (sqlite_uint64)hi << 32 | lo; |
| @@ -95713,14 +95990,16 @@ | ||
| 95713 | 95990 | */ |
| 95714 | 95991 | SQLITE_API int sqlite3_value_numeric_type(sqlite3_value *pVal){ |
| 95715 | 95992 | int eType = sqlite3_value_type(pVal); |
| 95716 | 95993 | if( eType==SQLITE_TEXT ){ |
| 95717 | 95994 | Mem *pMem = (Mem*)pVal; |
| 95718 | - assert( pMem->db!=0 ); | |
| 95719 | - sqlite3_mutex_enter(pMem->db->mutex); | |
| 95995 | +#if SQLITE_THREADSAFE>0 | |
| 95996 | + sqlite3_mutex *pMutex = pMem->db ? pMem->db->mutex : 0; | |
| 95997 | +#endif | |
| 95998 | + sqlite3_mutex_enter(pMutex); | |
| 95720 | 95999 | applyNumericAffinity(pMem, 0); |
| 95721 | - sqlite3_mutex_leave(pMem->db->mutex); | |
| 96000 | + sqlite3_mutex_leave(pMutex); | |
| 95722 | 96001 | eType = sqlite3_value_type(pVal); |
| 95723 | 96002 | } |
| 95724 | 96003 | return eType; |
| 95725 | 96004 | } |
| 95726 | 96005 | |
| @@ -102423,15 +102702,22 @@ | ||
| 102423 | 102702 | goto abort_due_to_error; |
| 102424 | 102703 | } |
| 102425 | 102704 | break; |
| 102426 | 102705 | } |
| 102427 | 102706 | |
| 102428 | -/* Opcode: ParseSchema P1 * * P4 * | |
| 102707 | +/* Opcode: ParseSchema P1 * * P4 P5 | |
| 102429 | 102708 | ** |
| 102430 | 102709 | ** Read and parse all entries from the schema table of database P1 |
| 102431 | 102710 | ** that match the WHERE clause P4. If P4 is a NULL pointer, then the |
| 102432 | 102711 | ** entire schema for P1 is reparsed. |
| 102712 | +** | |
| 102713 | +** When P4 is NULL, the P5 value is used as the mFlags argument | |
| 102714 | +** to sqlite3InitOne(). In other words, P5 should be a mask composed | |
| 102715 | +** of INITFLAG_* values. | |
| 102716 | +** | |
| 102717 | +** The P4==0 case is only used by ALTER TABLE and P5!=0 for all such | |
| 102718 | +** cases. For uses other than ALTER TABLE, P4<>0 and P5==0. | |
| 102433 | 102719 | ** |
| 102434 | 102720 | ** This opcode invokes the parser to create a new virtual machine, |
| 102435 | 102721 | ** then runs the new virtual machine. It is thus a re-entrant opcode. |
| 102436 | 102722 | */ |
| 102437 | 102723 | case OP_ParseSchema: { |
| @@ -102456,18 +102742,20 @@ | ||
| 102456 | 102742 | || db->mallocFailed |
| 102457 | 102743 | || (CORRUPT_DB && (db->flags & SQLITE_NoSchemaError)!=0) ); |
| 102458 | 102744 | |
| 102459 | 102745 | #ifndef SQLITE_OMIT_ALTERTABLE |
| 102460 | 102746 | if( pOp->p4.z==0 ){ |
| 102747 | + assert( pOp->p5!=0 ); | |
| 102461 | 102748 | sqlite3SchemaClear(db->aDb[iDb].pSchema); |
| 102462 | 102749 | db->mDbFlags &= ~DBFLAG_SchemaKnownOk; |
| 102463 | 102750 | rc = sqlite3InitOne(db, iDb, &p->zErrMsg, pOp->p5); |
| 102464 | 102751 | db->mDbFlags |= DBFLAG_SchemaChange; |
| 102465 | 102752 | p->expired = 0; |
| 102466 | 102753 | }else |
| 102467 | 102754 | #endif |
| 102468 | 102755 | { |
| 102756 | + assert( pOp->p5==0 ); | |
| 102469 | 102757 | zSchema = LEGACY_SCHEMA_TABLE; |
| 102470 | 102758 | initData.db = db; |
| 102471 | 102759 | initData.iDb = iDb; |
| 102472 | 102760 | initData.pzErrMsg = &p->zErrMsg; |
| 102473 | 102761 | initData.mInitFlags = 0; |
| @@ -102825,11 +103113,11 @@ | ||
| 102825 | 103113 | if( pFrame ) break; |
| 102826 | 103114 | } |
| 102827 | 103115 | |
| 102828 | 103116 | if( p->nFrame>=db->aLimit[SQLITE_LIMIT_TRIGGER_DEPTH] ){ |
| 102829 | 103117 | rc = SQLITE_ERROR; |
| 102830 | - sqlite3VdbeError(p, "too many levels of trigger recursion"); | |
| 103118 | + sqlite3VdbeError(p, "triggers nested too deep"); | |
| 102831 | 103119 | goto abort_due_to_error; |
| 102832 | 103120 | } |
| 102833 | 103121 | |
| 102834 | 103122 | /* Register pRt is used to store the memory required to save the state |
| 102835 | 103123 | ** of the current program, and the memory required at runtime to execute |
| @@ -109952,11 +110240,11 @@ | ||
| 109952 | 110240 | /* |
| 109953 | 110241 | ** cnt==0 means there was not match. |
| 109954 | 110242 | ** cnt>1 means there were two or more matches. |
| 109955 | 110243 | ** |
| 109956 | 110244 | ** cnt==0 is always an error. cnt>1 is often an error, but might |
| 109957 | - ** be multiple matches for a NATURAL LEFT JOIN or a LEFT JOIN USING. | |
| 110245 | + ** be multiple matches for a NATURAL OUTER JOIN or a OUTER JOIN USING. | |
| 109958 | 110246 | */ |
| 109959 | 110247 | assert( pFJMatch==0 || cnt>0 ); |
| 109960 | 110248 | assert( !ExprHasProperty(pExpr, EP_xIsSelect|EP_IntValue) ); |
| 109961 | 110249 | if( cnt!=1 ){ |
| 109962 | 110250 | const char *zErr; |
| @@ -109972,10 +110260,11 @@ | ||
| 109972 | 110260 | } |
| 109973 | 110261 | extendFJMatch(pParse, &pFJMatch, pMatch, pExpr->iColumn); |
| 109974 | 110262 | pExpr->op = TK_FUNCTION; |
| 109975 | 110263 | pExpr->u.zToken = "coalesce"; |
| 109976 | 110264 | pExpr->x.pList = pFJMatch; |
| 110265 | + pExpr->affExpr = SQLITE_AFF_DEFER; | |
| 109977 | 110266 | cnt = 1; |
| 109978 | 110267 | goto lookupname_end; |
| 109979 | 110268 | }else{ |
| 109980 | 110269 | sqlite3ExprListDelete(db, pFJMatch); |
| 109981 | 110270 | pFJMatch = 0; |
| @@ -110034,12 +110323,21 @@ | ||
| 110034 | 110323 | pExpr->op = eNewExprOp; |
| 110035 | 110324 | lookupname_end: |
| 110036 | 110325 | if( cnt==1 ){ |
| 110037 | 110326 | assert( pNC!=0 ); |
| 110038 | 110327 | #ifndef SQLITE_OMIT_AUTHORIZATION |
| 110039 | - if( db->xAuth && (pExpr->op==TK_COLUMN || pExpr->op==TK_TRIGGER) ){ | |
| 110040 | - sqlite3AuthRead(pParse, pExpr, pSchema, pNC->pSrcList); | |
| 110328 | + if( db->xAuth ){ | |
| 110329 | + if( pFJMatch ){ | |
| 110330 | + assert( pExpr->op==TK_FUNCTION ); | |
| 110331 | + assert( sqlite3_stricmp(pExpr->u.zToken,"coalesce")==0 ); | |
| 110332 | + assert( pExpr->x.pList==pFJMatch ); | |
| 110333 | + assert( pFJMatch->nExpr>0 ); | |
| 110334 | + pExpr = pFJMatch->a[0].pExpr; | |
| 110335 | + } | |
| 110336 | + if( pExpr->op==TK_COLUMN || pExpr->op==TK_TRIGGER ){ | |
| 110337 | + sqlite3AuthRead(pParse, pExpr, pSchema, pNC->pSrcList); | |
| 110338 | + } | |
| 110041 | 110339 | } |
| 110042 | 110340 | #endif |
| 110043 | 110341 | /* Increment the nRef value on all name contexts from TopNC up to |
| 110044 | 110342 | ** the point where the name matched. */ |
| 110045 | 110343 | for(;;){ |
| @@ -110137,10 +110435,30 @@ | ||
| 110137 | 110435 | sqlite3AtoF(p->u.zToken, &r); |
| 110138 | 110436 | assert( r>=0.0 ); |
| 110139 | 110437 | if( r>1.0 ) return -1; |
| 110140 | 110438 | return (int)(r*134217728.0); |
| 110141 | 110439 | } |
| 110440 | + | |
| 110441 | +/* | |
| 110442 | +** Set the EP_SubtArg property on every expression inside of | |
| 110443 | +** pList. If any subexpression is actually a subquery, then | |
| 110444 | +** also set the EP_SubtArg property on the first result-set | |
| 110445 | +** column of that subquery. | |
| 110446 | +*/ | |
| 110447 | +static SQLITE_NOINLINE void resolveSetExprSubtypeArg(ExprList *pList){ | |
| 110448 | + int nn, ii; | |
| 110449 | + nn = pList ? pList->nExpr : 0; | |
| 110450 | + for(ii=0; ii<nn; ii++){ | |
| 110451 | + Expr *pExpr = pList->a[ii].pExpr; | |
| 110452 | + ExprSetProperty(pExpr, EP_SubtArg); | |
| 110453 | + if( pExpr->op==TK_SELECT ){ | |
| 110454 | + assert( ExprUseXSelect(pExpr) ); | |
| 110455 | + assert( pExpr->x.pSelect!=0 ); | |
| 110456 | + resolveSetExprSubtypeArg(pExpr->x.pSelect->pEList); | |
| 110457 | + } | |
| 110458 | + } | |
| 110459 | +} | |
| 110142 | 110460 | |
| 110143 | 110461 | /* |
| 110144 | 110462 | ** This routine is callback for sqlite3WalkExpr(). |
| 110145 | 110463 | ** |
| 110146 | 110464 | ** Resolve symbolic names into TK_COLUMN operators for the current |
| @@ -110382,14 +110700,11 @@ | ||
| 110382 | 110700 | ** the function may return a value with a subtype back to its |
| 110383 | 110701 | ** caller using sqlite3_result_value(). */ |
| 110384 | 110702 | if( (pDef->funcFlags & SQLITE_SUBTYPE) |
| 110385 | 110703 | || ExprHasProperty(pExpr, EP_SubtArg) |
| 110386 | 110704 | ){ |
| 110387 | - int ii; | |
| 110388 | - for(ii=0; ii<n; ii++){ | |
| 110389 | - ExprSetProperty(pList->a[ii].pExpr, EP_SubtArg); | |
| 110390 | - } | |
| 110705 | + resolveSetExprSubtypeArg(pList); | |
| 110391 | 110706 | } |
| 110392 | 110707 | |
| 110393 | 110708 | if( pDef->funcFlags & (SQLITE_FUNC_CONSTANT|SQLITE_FUNC_SLOCHNG) ){ |
| 110394 | 110709 | /* For the purposes of the EP_ConstFunc flag, date and time |
| 110395 | 110710 | ** functions and other functions that change slowly are considered |
| @@ -110415,12 +110730,17 @@ | ||
| 110415 | 110730 | && (pParse->db->mDbFlags & DBFLAG_InternalFunc)==0 |
| 110416 | 110731 | ){ |
| 110417 | 110732 | /* Internal-use-only functions are disallowed unless the |
| 110418 | 110733 | ** SQL is being compiled using sqlite3NestedParse() or |
| 110419 | 110734 | ** the SQLITE_TESTCTRL_INTERNAL_FUNCTIONS test-control has be |
| 110420 | - ** used to activate internal functions for testing purposes */ | |
| 110421 | - no_such_func = 1; | |
| 110735 | + ** used to activate internal functions for testing purposes. | |
| 110736 | + ** | |
| 110737 | + ** The 2 value for no_such_func means that the function is | |
| 110738 | + ** an internal-use-only function which should be treated as a | |
| 110739 | + ** non-existant function for name resolution purposes. | |
| 110740 | + */ | |
| 110741 | + no_such_func = 2; | |
| 110422 | 110742 | pDef = 0; |
| 110423 | 110743 | }else |
| 110424 | 110744 | if( (pDef->funcFlags & (SQLITE_FUNC_DIRECT|SQLITE_FUNC_UNSAFE))!=0 |
| 110425 | 110745 | && !IN_RENAME_OBJECT |
| 110426 | 110746 | ){ |
| @@ -110460,13 +110780,20 @@ | ||
| 110460 | 110780 | sqlite3ErrorMsg(pParse,"misuse of aggregate function %#T()",pExpr); |
| 110461 | 110781 | pNC->nNcErr++; |
| 110462 | 110782 | is_agg = 0; |
| 110463 | 110783 | } |
| 110464 | 110784 | #endif |
| 110465 | - else if( no_such_func && pParse->db->init.busy==0 | |
| 110785 | + else if( no_such_func | |
| 110786 | + && (pParse->db->init.busy==0 || | |
| 110787 | + (no_such_func==2 && pParse->db->init.busy==2)) | |
| 110788 | + /* Suppress "no such function" errors when reading | |
| 110789 | + ** the sqlite_schema table. Except, do raise the error | |
| 110790 | + ** if init.busy is 2, meaning the schema parse is due | |
| 110791 | + ** to an ALTER TABLE ADD COLUMN statement, and the function | |
| 110792 | + ** is an internal-use-only function (no_such_func==2). */ | |
| 110466 | 110793 | #ifdef SQLITE_ENABLE_UNKNOWN_SQL_FUNCTION |
| 110467 | - && pParse->explain==0 | |
| 110794 | + && pParse->explain==0 | |
| 110468 | 110795 | #endif |
| 110469 | 110796 | ){ |
| 110470 | 110797 | sqlite3ErrorMsg(pParse, "no such function: %#T", pExpr); |
| 110471 | 110798 | pNC->nNcErr++; |
| 110472 | 110799 | }else if( wrong_num_args ){ |
| @@ -111849,11 +112176,13 @@ | ||
| 111849 | 112176 | ** Return TRUE if the two expressions have equivalent collating sequences. |
| 111850 | 112177 | */ |
| 111851 | 112178 | SQLITE_PRIVATE int sqlite3ExprCollSeqMatch(Parse *pParse, const Expr *pE1, const Expr *pE2){ |
| 111852 | 112179 | CollSeq *pColl1 = sqlite3ExprNNCollSeq(pParse, pE1); |
| 111853 | 112180 | CollSeq *pColl2 = sqlite3ExprNNCollSeq(pParse, pE2); |
| 111854 | - return sqlite3StrICmp(pColl1->zName, pColl2->zName)==0; | |
| 112181 | + assert( (pColl1==pColl2) == | |
| 112182 | + (sqlite3_stricmp(pColl1->zName,pColl2->zName)==0) ); | |
| 112183 | + return pColl1==pColl2; | |
| 111855 | 112184 | } |
| 111856 | 112185 | |
| 111857 | 112186 | /* |
| 111858 | 112187 | ** pExpr is an operand of a comparison operator. aff2 is the |
| 111859 | 112188 | ** type affinity of the other operand. This routine returns the |
| @@ -115686,10 +116015,11 @@ | ||
| 115686 | 116015 | if( i!=nVector ){ |
| 115687 | 116016 | /* Need to reorder the LHS fields according to aiMap */ |
| 115688 | 116017 | int rLhsOrig = rLhs; |
| 115689 | 116018 | rLhs = sqlite3GetTempRange(pParse, nVector); |
| 115690 | 116019 | for(i=0; i<nVector; i++){ |
| 116020 | + testcase( aiMap[i]!=i ); | |
| 115691 | 116021 | sqlite3VdbeAddOp3(v, OP_Copy, rLhsOrig+i, rLhs+aiMap[i], 0); |
| 115692 | 116022 | } |
| 115693 | 116023 | sqlite3ReleaseTempReg(pParse, rLhsOrig); |
| 115694 | 116024 | } |
| 115695 | 116025 | } |
| @@ -115706,11 +116036,12 @@ | ||
| 115706 | 116036 | } |
| 115707 | 116037 | for(i=0; i<nVector; i++){ |
| 115708 | 116038 | Expr *p = sqlite3VectorFieldSubexpr(pExpr->pLeft, i); |
| 115709 | 116039 | if( pParse->nErr ) goto sqlite3ExprCodeIN_oom_error; |
| 115710 | 116040 | if( sqlite3ExprCanBeNull(p) ){ |
| 115711 | - sqlite3VdbeAddOp2(v, OP_IsNull, rLhs+i, destStep2); | |
| 116041 | + testcase( aiMap[i]!=i ); | |
| 116042 | + sqlite3VdbeAddOp2(v, OP_IsNull, rLhs+aiMap[i], destStep2); | |
| 115712 | 116043 | VdbeCoverage(v); |
| 115713 | 116044 | } |
| 115714 | 116045 | } |
| 115715 | 116046 | |
| 115716 | 116047 | /* Step 3. The LHS is now known to be non-NULL. Do the binary search |
| @@ -115780,13 +116111,23 @@ | ||
| 115780 | 116111 | for(i=0; i<nVector; i++){ |
| 115781 | 116112 | Expr *p; |
| 115782 | 116113 | CollSeq *pColl; |
| 115783 | 116114 | int r3 = sqlite3GetTempReg(pParse); |
| 115784 | 116115 | p = sqlite3VectorFieldSubexpr(pLeft, i); |
| 115785 | - pColl = sqlite3ExprCollSeq(pParse, p); | |
| 115786 | - sqlite3VdbeAddOp3(v, OP_Column, iTab, i, r3); | |
| 115787 | - sqlite3VdbeAddOp4(v, OP_Ne, rLhs+i, destNotNull, r3, | |
| 116116 | + if( ExprUseXSelect(pExpr) ){ | |
| 116117 | + Expr *pRhs = pExpr->x.pSelect->pEList->a[i].pExpr; | |
| 116118 | + pColl = sqlite3BinaryCompareCollSeq(pParse, p, pRhs); | |
| 116119 | + }else{ | |
| 116120 | + /* If the RHS of the IN(...) expression are scalar expressions, do | |
| 116121 | + ** not consider their collation sequences. The documentation says | |
| 116122 | + ** "The collating sequence used for expressions of the form "x IN (y, z, | |
| 116123 | + ** ...)" is the collating sequence of x.". */ | |
| 116124 | + pColl = sqlite3ExprCollSeq(pParse, p); | |
| 116125 | + } | |
| 116126 | + testcase( aiMap[i]!=i ); | |
| 116127 | + sqlite3VdbeAddOp3(v, OP_Column, iTab, aiMap[i], r3); | |
| 116128 | + sqlite3VdbeAddOp4(v, OP_Ne, rLhs+aiMap[i], destNotNull, r3, | |
| 115788 | 116129 | (void*)pColl, P4_COLLSEQ); |
| 115789 | 116130 | VdbeCoverage(v); |
| 115790 | 116131 | sqlite3ReleaseTempReg(pParse, r3); |
| 115791 | 116132 | } |
| 115792 | 116133 | sqlite3VdbeAddOp2(v, OP_Goto, 0, destIfNull); |
| @@ -116203,40 +116544,51 @@ | ||
| 116203 | 116544 | } |
| 116204 | 116545 | return target; |
| 116205 | 116546 | } |
| 116206 | 116547 | |
| 116207 | 116548 | /* |
| 116208 | -** Expression Node callback for sqlite3ExprCanReturnSubtype(). | |
| 116209 | -** | |
| 116210 | -** Only a function call is able to return a subtype. So if the node | |
| 116211 | -** is not a function call, return WRC_Prune immediately. | |
| 116212 | -** | |
| 116213 | -** A function call is able to return a subtype if it has the | |
| 116214 | -** SQLITE_RESULT_SUBTYPE property. | |
| 116215 | -** | |
| 116216 | -** Assume that every function is able to pass-through a subtype from | |
| 116217 | -** one of its argument (using sqlite3_result_value()). Most functions | |
| 116218 | -** are not this way, but we don't have a mechanism to distinguish those | |
| 116219 | -** that are from those that are not, so assume they all work this way. | |
| 116220 | -** That means that if one of its arguments is another function and that | |
| 116221 | -** other function is able to return a subtype, then this function is | |
| 116222 | -** able to return a subtype. | |
| 116549 | +** Expression Node callback for sqlite3ExprCanReturnSubtype(). If | |
| 116550 | +** pExpr is able to return a subtype, set pWalker->eCode and abort | |
| 116551 | +** the search. If pExpr can never return a subtype, prune search. | |
| 116552 | +** | |
| 116553 | +** The only expressions that can return a subtype are: | |
| 116554 | +** | |
| 116555 | +** 1. A function | |
| 116556 | +** 2. The no-op "+" operator | |
| 116557 | +** 3. A CASE...END expression | |
| 116558 | +** 4. A CAST() expression | |
| 116559 | +** 5. A "expr COLLATE colseq" expression. | |
| 116560 | +** | |
| 116561 | +** For any other kind of expression, prune the search. | |
| 116562 | +** | |
| 116563 | +** For case 1, the expression can yield a subtype if the function has | |
| 116564 | +** the SQLITE_RESULT_SUBTYPE property. Functions can also return | |
| 116565 | +** a subtype (via sqlite3_result_value()) if any of the arguments can | |
| 116566 | +** return a subtype. | |
| 116567 | +** | |
| 116568 | +** In all cases 1 through 5, the expression might also return a subtype | |
| 116569 | +** if any operand can return a subtype. | |
| 116223 | 116570 | */ |
| 116224 | 116571 | static int exprNodeCanReturnSubtype(Walker *pWalker, Expr *pExpr){ |
| 116225 | 116572 | int n; |
| 116226 | 116573 | FuncDef *pDef; |
| 116227 | 116574 | sqlite3 *db; |
| 116575 | + if( pExpr->op==TK_CASE || pExpr->op==TK_UPLUS | |
| 116576 | + || pExpr->op==TK_COLLATE || pExpr->op==TK_CAST | |
| 116577 | + ){ | |
| 116578 | + return WRC_Continue; | |
| 116579 | + } | |
| 116228 | 116580 | if( pExpr->op!=TK_FUNCTION ){ |
| 116229 | 116581 | return WRC_Prune; |
| 116230 | 116582 | } |
| 116231 | 116583 | assert( ExprUseXList(pExpr) ); |
| 116232 | 116584 | db = pWalker->pParse->db; |
| 116233 | 116585 | n = ALWAYS(pExpr->x.pList) ? pExpr->x.pList->nExpr : 0; |
| 116234 | 116586 | pDef = sqlite3FindFunction(db, pExpr->u.zToken, n, ENC(db), 0); |
| 116235 | 116587 | if( NEVER(pDef==0) || (pDef->funcFlags & SQLITE_RESULT_SUBTYPE)!=0 ){ |
| 116236 | 116588 | pWalker->eCode = 1; |
| 116237 | - return WRC_Prune; | |
| 116589 | + return WRC_Abort; | |
| 116238 | 116590 | } |
| 116239 | 116591 | return WRC_Continue; |
| 116240 | 116592 | } |
| 116241 | 116593 | |
| 116242 | 116594 | /* |
| @@ -122210,23 +122562,35 @@ | ||
| 122210 | 122562 | SQLITE_PRIVATE void sqlite3AlterAddConstraint( |
| 122211 | 122563 | Parse *pParse, /* Parse context */ |
| 122212 | 122564 | SrcList *pSrc, /* Table to add constraint to */ |
| 122213 | 122565 | Token *pFirst, /* First token of new constraint */ |
| 122214 | 122566 | Token *pName, /* Name of new constraint. NULL if name omitted. */ |
| 122215 | - const char *pExpr, /* Text of CHECK expression */ | |
| 122216 | - int nExpr /* Size of pExpr in bytes */ | |
| 122567 | + const char *zExpr, /* Text of CHECK expression */ | |
| 122568 | + int nExpr, /* Size of pExpr in bytes */ | |
| 122569 | + Expr *pExpr /* The parsed CHECK expression */ | |
| 122217 | 122570 | ){ |
| 122218 | 122571 | Table *pTab = 0; /* Table identified by pSrc */ |
| 122219 | 122572 | int iDb = 0; /* Which schema does pTab live in */ |
| 122220 | 122573 | const char *zDb = 0; /* Name of the schema in which pTab lives */ |
| 122221 | 122574 | const char *pCons = 0; /* Text of the constraint */ |
| 122222 | 122575 | int nCons; /* Bytes of text to use from pCons[] */ |
| 122576 | + int rc; /* Result from error checking pExpr */ | |
| 122223 | 122577 | |
| 122224 | 122578 | /* Look up the table being altered. */ |
| 122225 | 122579 | assert( pSrc->nSrc==1 ); |
| 122226 | 122580 | pTab = alterFindTable(pParse, pSrc, &iDb, &zDb, 1); |
| 122227 | - if( !pTab ) return; | |
| 122581 | + if( !pTab ){ | |
| 122582 | + sqlite3ExprDelete(pParse->db, pExpr); | |
| 122583 | + return; | |
| 122584 | + } | |
| 122585 | + | |
| 122586 | + /* Verify that the new CHECK constraint does not contain any | |
| 122587 | + ** internal-use-only function. Forum post 2026-05-10T01:11:28Z | |
| 122588 | + */ | |
| 122589 | + rc = sqlite3ResolveSelfReference(pParse, pTab, NC_IsCheck, pExpr, 0); | |
| 122590 | + sqlite3ExprDelete(pParse->db, pExpr); | |
| 122591 | + if( rc ) return; | |
| 122228 | 122592 | |
| 122229 | 122593 | /* If this new constraint has a name, check that it is not a duplicate of |
| 122230 | 122594 | ** an existing constraint. It is an error if it is. */ |
| 122231 | 122595 | if( pName ){ |
| 122232 | 122596 | char *zName = sqlite3NameFromToken(pParse->db, pName); |
| @@ -122243,11 +122607,11 @@ | ||
| 122243 | 122607 | |
| 122244 | 122608 | /* Search for a constraint violation. Throw an exception if one is found. */ |
| 122245 | 122609 | sqlite3NestedParse(pParse, |
| 122246 | 122610 | "SELECT sqlite_fail('constraint failed', %d) " |
| 122247 | 122611 | "FROM %Q.%Q WHERE (%.*s) IS NOT TRUE", |
| 122248 | - SQLITE_CONSTRAINT, zDb, pTab->zName, nExpr, pExpr | |
| 122612 | + SQLITE_CONSTRAINT, zDb, pTab->zName, nExpr, zExpr | |
| 122249 | 122613 | ); |
| 122250 | 122614 | |
| 122251 | 122615 | /* Edit the SQL for the named table. */ |
| 122252 | 122616 | pCons = pFirst->z; |
| 122253 | 122617 | nCons = alterRtrimConstraint(pParse->db, pCons, pParse->sLastToken.z - pCons); |
| @@ -124098,21 +124462,21 @@ | ||
| 124098 | 124462 | }else{ |
| 124099 | 124463 | nIdxCol = pIdx->nColumn; |
| 124100 | 124464 | } |
| 124101 | 124465 | pIdx->nSampleCol = nIdxCol; |
| 124102 | 124466 | pIdx->mxSample = nSample; |
| 124103 | - nByte = ROUND8(sizeof(IndexSample) * nSample); | |
| 124104 | - nByte += sizeof(tRowcnt) * nIdxCol * 3 * nSample; | |
| 124105 | - nByte += nIdxCol * sizeof(tRowcnt); /* Space for Index.aAvgEq[] */ | |
| 124467 | + nByte = ROUND8(sizeof64(IndexSample) * nSample); | |
| 124468 | + nByte += sizeof64(tRowcnt) * nIdxCol * 3 * nSample; | |
| 124469 | + nByte += nIdxCol * sizeof64(tRowcnt); /* Space for Index.aAvgEq[] */ | |
| 124106 | 124470 | |
| 124107 | 124471 | pIdx->aSample = sqlite3DbMallocZero(db, nByte); |
| 124108 | 124472 | if( pIdx->aSample==0 ){ |
| 124109 | 124473 | sqlite3_finalize(pStmt); |
| 124110 | 124474 | return SQLITE_NOMEM_BKPT; |
| 124111 | 124475 | } |
| 124112 | 124476 | pPtr = (u8*)pIdx->aSample; |
| 124113 | - pPtr += ROUND8(nSample*sizeof(pIdx->aSample[0])); | |
| 124477 | + pPtr += ROUND8(nSample*sizeof64(pIdx->aSample[0])); | |
| 124114 | 124478 | pSpace = (tRowcnt*)pPtr; |
| 124115 | 124479 | assert( EIGHT_BYTE_ALIGNMENT( pSpace ) ); |
| 124116 | 124480 | pIdx->aAvgEq = pSpace; pSpace += nIdxCol; |
| 124117 | 124481 | pIdx->pTable->tabFlags |= TF_HasStat4; |
| 124118 | 124482 | for(i=0; i<nSample; i++){ |
| @@ -125929,10 +126293,23 @@ | ||
| 125929 | 126293 | if( NEVER(pTab->u.tab.pDfltList==0) ) return 0; |
| 125930 | 126294 | if( NEVER(pTab->u.tab.pDfltList->nExpr<pCol->iDflt) ) return 0; |
| 125931 | 126295 | return pTab->u.tab.pDfltList->a[pCol->iDflt-1].pExpr; |
| 125932 | 126296 | } |
| 125933 | 126297 | |
| 126298 | +/* | |
| 126299 | +** Suppress false-positive warning message generated with -O3 in GCC | |
| 126300 | +** on the second call to sqlite3Strlen30() in the sqlite3ColumnSetColl() | |
| 126301 | +** function below. See the forum thread beginning on 2026-05-10T01:11:22Z. | |
| 126302 | +** | |
| 126303 | +** See also the "pop" pragma to undo this warning suppression immediately | |
| 126304 | +** after the function. | |
| 126305 | +*/ | |
| 126306 | +#if defined(__GNUC__) && __GNUC__>=11 | |
| 126307 | +# pragma GCC diagnostic push | |
| 126308 | +# pragma GCC diagnostic ignored "-Wstringop-overread" | |
| 126309 | +#endif | |
| 126310 | + | |
| 125934 | 126311 | /* |
| 125935 | 126312 | ** Set the collating sequence name for a column. |
| 125936 | 126313 | */ |
| 125937 | 126314 | SQLITE_PRIVATE void sqlite3ColumnSetColl( |
| 125938 | 126315 | sqlite3 *db, |
| @@ -125953,10 +126330,15 @@ | ||
| 125953 | 126330 | pCol->zCnName = zNew; |
| 125954 | 126331 | memcpy(pCol->zCnName + n, zColl, nColl); |
| 125955 | 126332 | pCol->colFlags |= COLFLAG_HASCOLL; |
| 125956 | 126333 | } |
| 125957 | 126334 | } |
| 126335 | + | |
| 126336 | +/* Undo the false-positive warning suppression above. */ | |
| 126337 | +#if defined(__GNUC__) && __GNUC__>=11 | |
| 126338 | +# pragma GCC diagnostic pop | |
| 126339 | +#endif | |
| 125958 | 126340 | |
| 125959 | 126341 | /* |
| 125960 | 126342 | ** Return the collating sequence name for a column |
| 125961 | 126343 | */ |
| 125962 | 126344 | SQLITE_PRIVATE const char *sqlite3ColumnColl(Column *pCol){ |
| @@ -132946,13 +133328,22 @@ | ||
| 132946 | 133328 | x.nUsed = 0; |
| 132947 | 133329 | x.apArg = argv+1; |
| 132948 | 133330 | sqlite3StrAccumInit(&str, db, 0, 0, db->aLimit[SQLITE_LIMIT_LENGTH]); |
| 132949 | 133331 | str.printfFlags = SQLITE_PRINTF_SQLFUNC; |
| 132950 | 133332 | sqlite3_str_appendf(&str, zFormat, &x); |
| 132951 | - n = str.nChar; | |
| 132952 | - sqlite3_result_text(context, sqlite3StrAccumFinish(&str), n, | |
| 132953 | - SQLITE_DYNAMIC); | |
| 133333 | + if( str.accError==SQLITE_OK ){ | |
| 133334 | + n = str.nChar; | |
| 133335 | + sqlite3_result_text(context, sqlite3StrAccumFinish(&str), n, | |
| 133336 | + SQLITE_DYNAMIC); | |
| 133337 | + }else{ | |
| 133338 | + if( str.accError==SQLITE_NOMEM ){ | |
| 133339 | + sqlite3_result_error_nomem(context); | |
| 133340 | + }else{ | |
| 133341 | + sqlite3_result_error_toobig(context); | |
| 133342 | + } | |
| 133343 | + sqlite3_str_reset(&str); | |
| 133344 | + } | |
| 132954 | 133345 | } |
| 132955 | 133346 | } |
| 132956 | 133347 | |
| 132957 | 133348 | /* |
| 132958 | 133349 | ** Implementation of the substr() function. |
| @@ -134120,11 +134511,11 @@ | ||
| 134120 | 134511 | int nStr; /* Size of zStr */ |
| 134121 | 134512 | int nPattern; /* Size of zPattern */ |
| 134122 | 134513 | int nRep; /* Size of zRep */ |
| 134123 | 134514 | i64 nOut; /* Maximum size of zOut */ |
| 134124 | 134515 | int loopLimit; /* Last zStr[] that might match zPattern[] */ |
| 134125 | - int i, j; /* Loop counters */ | |
| 134516 | + i64 i, j; /* Loop counters */ | |
| 134126 | 134517 | unsigned cntExpand; /* Number zOut expansions */ |
| 134127 | 134518 | sqlite3 *db = sqlite3_context_db_handle(context); |
| 134128 | 134519 | |
| 134129 | 134520 | assert( argc==3 ); |
| 134130 | 134521 | UNUSED_PARAMETER(argc); |
| @@ -134599,15 +134990,20 @@ | ||
| 134599 | 134990 | ** to initialize it */ |
| 134600 | 134991 | if( ALWAYS(p) && type!=SQLITE_NULL ){ |
| 134601 | 134992 | assert( p->cnt>0 ); |
| 134602 | 134993 | p->cnt--; |
| 134603 | 134994 | if( !p->approx ){ |
| 134604 | - if( sqlite3SubInt64(&p->iSum, sqlite3_value_int64(argv[0])) ){ | |
| 134605 | - p->ovrfl = 1; | |
| 134606 | - p->approx = 1; | |
| 134995 | + i64 x = p->iSum; | |
| 134996 | + if( sqlite3SubInt64(&x, sqlite3_value_int64(argv[0]))==0 ){ | |
| 134997 | + p->iSum = x; | |
| 134998 | + return; | |
| 134607 | 134999 | } |
| 134608 | - }else if( type==SQLITE_INTEGER ){ | |
| 135000 | + p->ovrfl = 1; | |
| 135001 | + p->approx = 1; | |
| 135002 | + kahanBabuskaNeumaierInit(p, p->iSum); | |
| 135003 | + } | |
| 135004 | + if( type==SQLITE_INTEGER ){ | |
| 134609 | 135005 | i64 iVal = sqlite3_value_int64(argv[0]); |
| 134610 | 135006 | if( iVal!=SMALLEST_INT64 ){ |
| 134611 | 135007 | kahanBabuskaNeumaierStepInt64(p, -iVal); |
| 134612 | 135008 | }else{ |
| 134613 | 135009 | kahanBabuskaNeumaierStepInt64(p, LARGEST_INT64); |
| @@ -135569,57 +135965,95 @@ | ||
| 135569 | 135965 | ** from the standard library because: |
| 135570 | 135966 | ** |
| 135571 | 135967 | ** (1) To avoid a dependency on qsort() |
| 135572 | 135968 | ** (2) To avoid the function call to the comparison routine for each |
| 135573 | 135969 | ** comparison. |
| 135970 | +** | |
| 135971 | +** If parameter iReq is non-negative, then the caller will only access | |
| 135972 | +** elements a[iReq] and a[iReq+1] (if it exists) of the sorted array and | |
| 135973 | +** so it is not necessary to position any other elements. Or if iReq is | |
| 135974 | +** negative, then the final array must be fully sorted. | |
| 135574 | 135975 | */ |
| 135575 | -static void percentSort(double *a, unsigned int n){ | |
| 135976 | +static void percentSort( | |
| 135977 | + double *a, /* Array to sort */ | |
| 135978 | + unsigned int n, /* Number of elements in array a[] */ | |
| 135979 | + int iReq /* Element caller cares about (or -ve) */ | |
| 135980 | +){ | |
| 135576 | 135981 | int iLt; /* Entries before a[iLt] are less than rPivot */ |
| 135577 | 135982 | int iGt; /* Entries at or after a[iGt] are greater than rPivot */ |
| 135578 | 135983 | int i; /* Loop counter */ |
| 135579 | 135984 | double rPivot; /* The pivot value */ |
| 135580 | 135985 | |
| 135581 | 135986 | assert( n>=2 ); |
| 135582 | - if( a[0]>a[n-1] ){ | |
| 135583 | - SWAP_DOUBLE(a[0],a[n-1]) | |
| 135584 | - } | |
| 135585 | - if( n==2 ) return; | |
| 135586 | - iGt = n-1; | |
| 135587 | - i = n/2; | |
| 135588 | - if( a[0]>a[i] ){ | |
| 135589 | - SWAP_DOUBLE(a[0],a[i]) | |
| 135590 | - }else if( a[i]>a[iGt] ){ | |
| 135591 | - SWAP_DOUBLE(a[i],a[iGt]) | |
| 135592 | - } | |
| 135593 | - if( n==3 ) return; | |
| 135594 | - rPivot = a[i]; | |
| 135595 | - iLt = i = 1; | |
| 135596 | - do{ | |
| 135597 | - if( a[i]<rPivot ){ | |
| 135598 | - if( i>iLt ) SWAP_DOUBLE(a[i],a[iLt]) | |
| 135599 | - iLt++; | |
| 135600 | - i++; | |
| 135601 | - }else if( a[i]>rPivot ){ | |
| 135602 | - do{ | |
| 135603 | - iGt--; | |
| 135604 | - }while( iGt>i && a[iGt]>rPivot ); | |
| 135605 | - SWAP_DOUBLE(a[i],a[iGt]) | |
| 135606 | - }else{ | |
| 135607 | - i++; | |
| 135608 | - } | |
| 135609 | - }while( i<iGt ); | |
| 135610 | - if( iLt>=2 ) percentSort(a, iLt); | |
| 135611 | - if( n-iGt>=2 ) percentSort(a+iGt, n-iGt); | |
| 135612 | - | |
| 135613 | -/* Uncomment for testing */ | |
| 135614 | -#if 0 | |
| 135615 | - for(i=0; i<n-1; i++){ | |
| 135616 | - assert( a[i]<=a[i+1] ); | |
| 135617 | - } | |
| 135618 | -#endif | |
| 135619 | -} | |
| 135620 | - | |
| 135987 | + do{ | |
| 135988 | + if( a[0]>a[n-1] ){ | |
| 135989 | + SWAP_DOUBLE(a[0],a[n-1]) | |
| 135990 | + } | |
| 135991 | + if( n==2 ) return; | |
| 135992 | + iGt = n-1; | |
| 135993 | + i = n/2; | |
| 135994 | + if( a[0]>a[i] ){ | |
| 135995 | + SWAP_DOUBLE(a[0],a[i]) | |
| 135996 | + }else if( a[i]>a[iGt] ){ | |
| 135997 | + SWAP_DOUBLE(a[i],a[iGt]) | |
| 135998 | + } | |
| 135999 | + if( n==3 ) return; | |
| 136000 | + rPivot = a[i]; | |
| 136001 | + iLt = i = 1; | |
| 136002 | + do{ | |
| 136003 | + if( a[i]<rPivot ){ | |
| 136004 | + if( i>iLt ) SWAP_DOUBLE(a[i],a[iLt]) | |
| 136005 | + iLt++; | |
| 136006 | + i++; | |
| 136007 | + }else if( a[i]>rPivot ){ | |
| 136008 | + do{ | |
| 136009 | + iGt--; | |
| 136010 | + }while( iGt>i && a[iGt]>rPivot ); | |
| 136011 | + SWAP_DOUBLE(a[i],a[iGt]) | |
| 136012 | + }else{ | |
| 136013 | + i++; | |
| 136014 | + } | |
| 136015 | + }while( i<iGt ); | |
| 136016 | + | |
| 136017 | + assert( a[iLt]==rPivot ); | |
| 136018 | + assert( iGt>iLt ); | |
| 136019 | + | |
| 136020 | + if( iReq>=0 ){ | |
| 136021 | + /* In this case, the only elements that the caller requires sorted into | |
| 136022 | + ** the correct positions are elements a[iReq] and a[iReq+1]. At this | |
| 136023 | + ** point we know that element a[iLt] is in the correct position and | |
| 136024 | + ** all elements smaller than a[iLt] are in the left-hand partition. | |
| 136025 | + ** So if (iReq<iLt), then it is only necessary to sort the left | |
| 136026 | + ** partition. | |
| 136027 | + ** | |
| 136028 | + ** If (iReq>=iLt), then elements iReq and iReq+1 are either in the | |
| 136029 | + ** right partition or the equal partition (elements for which | |
| 136030 | + ** iLt<=iElem<iGt). Therefore it is always sufficient to sort only | |
| 136031 | + ** the right partition in this case. */ | |
| 136032 | + if( iReq<iLt ){ | |
| 136033 | + n = iLt; | |
| 136034 | + }else{ | |
| 136035 | + a += iGt; | |
| 136036 | + n -= iGt; | |
| 136037 | + iReq = MAX(0, iReq-iGt); | |
| 136038 | + } | |
| 136039 | + }else{ | |
| 136040 | + /* Recurse on the smaller partition only. The smaller partition | |
| 136041 | + ** will hold n/2 or fewer entries, which assures that the stack | |
| 136042 | + ** depth will not exceed O(log(n)), even for pathological cases. | |
| 136043 | + ** Loop without recursion for the larger partition. */ | |
| 136044 | + if( iLt>(int)(n/2) ){ | |
| 136045 | + if( n-iGt>=2 ) percentSort(a+iGt, n-iGt, -1); | |
| 136046 | + n = iLt; | |
| 136047 | + }else{ | |
| 136048 | + if( iLt>=2 ) percentSort(a, iLt, -1); | |
| 136049 | + a += iGt; | |
| 136050 | + n -= iGt; | |
| 136051 | + } | |
| 136052 | + } | |
| 136053 | + }while( n>=2 ); | |
| 136054 | +} | |
| 135621 | 136055 | |
| 135622 | 136056 | /* |
| 135623 | 136057 | ** The "inverse" function for percentile(Y,P) is called to remove a |
| 135624 | 136058 | ** row that was previously inserted by "step". |
| 135625 | 136059 | */ |
| @@ -135649,11 +136083,11 @@ | ||
| 135649 | 136083 | if( percentIsInfinity(y) ){ |
| 135650 | 136084 | return; |
| 135651 | 136085 | } |
| 135652 | 136086 | if( p->bSorted==0 ){ |
| 135653 | 136087 | assert( p->nUsed>1 ); |
| 135654 | - percentSort(p->a, p->nUsed); | |
| 136088 | + percentSort(p->a, p->nUsed, -1); | |
| 135655 | 136089 | p->bSorted = 1; |
| 135656 | 136090 | } |
| 135657 | 136091 | p->bKeepSorted = 1; |
| 135658 | 136092 | |
| 135659 | 136093 | /* Find and remove the row */ |
| @@ -135678,17 +136112,21 @@ | ||
| 135678 | 136112 | double ix, vx; |
| 135679 | 136113 | p = (Percentile*)sqlite3_aggregate_context(pCtx, 0); |
| 135680 | 136114 | if( p==0 ) return; |
| 135681 | 136115 | if( p->a==0 ) return; |
| 135682 | 136116 | if( p->nUsed ){ |
| 136117 | + ix = p->rPct*(p->nUsed-1); | |
| 136118 | + i1 = (unsigned)ix; | |
| 135683 | 136119 | if( p->bSorted==0 ){ |
| 136120 | + /* In cases where bIsFinal is non-zero, setting Percentile.bSorted | |
| 136121 | + ** after the percentSort() call here is not technically correct, as | |
| 136122 | + ** the array is not fully sorted. But in this case the object will be | |
| 136123 | + ** freed below anyway, so it doesn't matter. */ | |
| 135684 | 136124 | assert( p->nUsed>1 ); |
| 135685 | - percentSort(p->a, p->nUsed); | |
| 136125 | + percentSort(p->a, p->nUsed, (bIsFinal ? (int)i1 : -1)); | |
| 135686 | 136126 | p->bSorted = 1; |
| 135687 | 136127 | } |
| 135688 | - ix = p->rPct*(p->nUsed-1); | |
| 135689 | - i1 = (unsigned)ix; | |
| 135690 | 136128 | if( settings & 1 ){ |
| 135691 | 136129 | vx = p->a[i1]; |
| 135692 | 136130 | }else{ |
| 135693 | 136131 | i2 = ix==(double)i1 || i1==p->nUsed-1 ? i1 : i1+1; |
| 135694 | 136132 | v1 = p->a[i1]; |
| @@ -140569,10 +141007,48 @@ | ||
| 140569 | 141007 | } |
| 140570 | 141008 | |
| 140571 | 141009 | /* If no test above fails then the indices must be compatible */ |
| 140572 | 141010 | return 1; |
| 140573 | 141011 | } |
| 141012 | + | |
| 141013 | +/* | |
| 141014 | +** Examine an expression node and abort if it references the ROWID. | |
| 141015 | +** This is a Walker callback used by xferCompatibleCheck() | |
| 141016 | +*/ | |
| 141017 | +static int xferCheckRowid(Walker *pWalk, Expr *pExpr){ | |
| 141018 | + if( pExpr->op==TK_COLUMN && pExpr->iColumn<0 ){ | |
| 141019 | + pWalk->eCode = 1; | |
| 141020 | + return WRC_Abort; | |
| 141021 | + }else{ | |
| 141022 | + return WRC_Continue; | |
| 141023 | + } | |
| 141024 | +} | |
| 141025 | + | |
| 141026 | +/* | |
| 141027 | +** Analyze CHECK constraints on the source and destination tables and | |
| 141028 | +** return true if those CHECK constraints are compatible with the | |
| 141029 | +** xfer-optimization. | |
| 141030 | +** | |
| 141031 | +** * The pDest and pSrc tables must have identical CHECK constraints. | |
| 141032 | +** | |
| 141033 | +** * If the destination table, pDest, does not have an | |
| 141034 | +** INTEGER PRIMARY KEY column, then no CHECK constraint may | |
| 141035 | +** referenced the ROWID. (See forum post 2026-05-11T13:15:57Z) | |
| 141036 | +*/ | |
| 141037 | +static int xferCompatibleCheck(Table *pDest, Table *pSrc){ | |
| 141038 | + if( sqlite3ExprListCompare(pSrc->pCheck,pDest->pCheck,-1) ){ | |
| 141039 | + return 0; | |
| 141040 | + } | |
| 141041 | + if( pDest->iPKey<0 ){ | |
| 141042 | + Walker w; | |
| 141043 | + memset(&w, 0, sizeof(w)); | |
| 141044 | + w.xExprCallback = xferCheckRowid; | |
| 141045 | + sqlite3WalkExprList(&w,pDest->pCheck); | |
| 141046 | + if( w.eCode ) return 0; | |
| 141047 | + } | |
| 141048 | + return 1; | |
| 141049 | +} | |
| 140574 | 141050 | |
| 140575 | 141051 | /* |
| 140576 | 141052 | ** Attempt the transfer optimization on INSERTs of the form |
| 140577 | 141053 | ** |
| 140578 | 141054 | ** INSERT INTO tab1 SELECT * FROM tab2; |
| @@ -140696,12 +141172,23 @@ | ||
| 140696 | 141172 | return 0; /* Number of columns must be the same in tab1 and tab2 */ |
| 140697 | 141173 | } |
| 140698 | 141174 | if( pDest->iPKey!=pSrc->iPKey ){ |
| 140699 | 141175 | return 0; /* Both tables must have the same INTEGER PRIMARY KEY */ |
| 140700 | 141176 | } |
| 140701 | - if( (pDest->tabFlags & TF_Strict)!=0 && (pSrc->tabFlags & TF_Strict)==0 ){ | |
| 140702 | - return 0; /* Cannot feed from a non-strict into a strict table */ | |
| 141177 | + if( (pDest->tabFlags & TF_Strict)!=0 ){ | |
| 141178 | + if( (pSrc->tabFlags & TF_Strict)==0 ){ | |
| 141179 | + return 0; /* Cannot feed from a non-strict into a strict table */ | |
| 141180 | + } | |
| 141181 | + for(i=0; i<pDest->nCol; i++){ | |
| 141182 | + unsigned eDestType = pDest->aCol[i].eCType; | |
| 141183 | + unsigned eSrcType = pSrc->aCol[i].eCType; | |
| 141184 | + if( eDestType==COLTYPE_ANY ) continue; | |
| 141185 | + if( eDestType==eSrcType ) continue; | |
| 141186 | + if( eDestType==COLTYPE_INT && eSrcType==COLTYPE_INTEGER ) continue; | |
| 141187 | + if( eDestType==COLTYPE_INTEGER && eSrcType==COLTYPE_INT ) continue; | |
| 141188 | + return 0; /* Incompatible types in source and destination */ | |
| 141189 | + } | |
| 140703 | 141190 | } |
| 140704 | 141191 | for(i=0; i<pDest->nCol; i++){ |
| 140705 | 141192 | Column *pDestCol = &pDest->aCol[i]; |
| 140706 | 141193 | Column *pSrcCol = &pSrc->aCol[i]; |
| 140707 | 141194 | #ifdef SQLITE_ENABLE_HIDDEN_COLUMNS |
| @@ -140791,11 +141278,11 @@ | ||
| 140791 | 141278 | } |
| 140792 | 141279 | } |
| 140793 | 141280 | #ifndef SQLITE_OMIT_CHECK |
| 140794 | 141281 | if( pDest->pCheck |
| 140795 | 141282 | && (db->mDbFlags & DBFLAG_Vacuum)==0 |
| 140796 | - && sqlite3ExprListCompare(pSrc->pCheck,pDest->pCheck,-1) | |
| 141283 | + && !xferCompatibleCheck(pDest,pSrc) | |
| 140797 | 141284 | ){ |
| 140798 | 141285 | return 0; /* Tables have different CHECK constraints. Ticket #2252 */ |
| 140799 | 141286 | } |
| 140800 | 141287 | #endif |
| 140801 | 141288 | #ifndef SQLITE_OMIT_FOREIGN_KEY |
| @@ -140812,10 +141299,22 @@ | ||
| 140812 | 141299 | } |
| 140813 | 141300 | #endif |
| 140814 | 141301 | if( (db->flags & SQLITE_CountRows)!=0 ){ |
| 140815 | 141302 | return 0; /* xfer opt does not play well with PRAGMA count_changes */ |
| 140816 | 141303 | } |
| 141304 | +#ifndef SQLITE_OMIT_AUTHORIZATION | |
| 141305 | + if( db->xAuth ){ | |
| 141306 | + int iDb = sqlite3SchemaToIndex(db, pSrc->pSchema); | |
| 141307 | + if( sqlite3AuthCheck(pParse, SQLITE_SELECT, 0, 0, 0) ) return 0; | |
| 141308 | + for(i=0; i<pSrc->nCol; i++){ | |
| 141309 | + Column *pSrcCol = &pSrc->aCol[i]; | |
| 141310 | + if( sqlite3AuthReadCol(pParse, pSrc->zName, pSrcCol->zCnName, iDb) ){ | |
| 141311 | + return 0; | |
| 141312 | + } | |
| 141313 | + } | |
| 141314 | + } | |
| 141315 | +#endif | |
| 140817 | 141316 | |
| 140818 | 141317 | /* If we get this far, it means that the xfer optimization is at |
| 140819 | 141318 | ** least a possibility, though it might only work if the destination |
| 140820 | 141319 | ** table (tab1) is initially empty. |
| 140821 | 141320 | */ |
| @@ -146810,11 +147309,17 @@ | ||
| 146810 | 147309 | assert( iDb>=0 && iDb<db->nDb ); |
| 146811 | 147310 | assert( db->aDb[iDb].pSchema ); |
| 146812 | 147311 | assert( sqlite3_mutex_held(db->mutex) ); |
| 146813 | 147312 | assert( iDb==1 || sqlite3BtreeHoldsMutex(db->aDb[iDb].pBt) ); |
| 146814 | 147313 | |
| 146815 | - db->init.busy = 1; | |
| 147314 | + db->init.busy = 1 + ((mFlags & INITFLAG_AlterAdd)!=0); | |
| 147315 | + /* ^--- Any non-zero value for init.busy means that we are scanning | |
| 147316 | + ** the sqlite_schema table to build the internal schema representation, | |
| 147317 | + ** rather than running actual CREATE statements. init.busy==2 has the | |
| 147318 | + ** additional meaning that the scan is happening as part of | |
| 147319 | + ** ALTER TABLE ADD COLUMN, which is stricter in its enforcement of | |
| 147320 | + ** function name resolution. */ | |
| 146816 | 147321 | |
| 146817 | 147322 | /* Construct the in-memory representation schema tables (sqlite_schema or |
| 146818 | 147323 | ** sqlite_temp_schema) by invoking the parser directly. The appropriate |
| 146819 | 147324 | ** table name will be inserted automatically by the parser so we can just |
| 146820 | 147325 | ** use the abbreviation "x" here. The parser will also automatically tag |
| @@ -150131,10 +150636,17 @@ | ||
| 150131 | 150636 | SQLITE_PRIVATE Table *sqlite3ResultSetOfSelect(Parse *pParse, Select *pSelect, char aff){ |
| 150132 | 150637 | Table *pTab; |
| 150133 | 150638 | sqlite3 *db = pParse->db; |
| 150134 | 150639 | u64 savedFlags; |
| 150135 | 150640 | |
| 150641 | + pParse->nNestSel++; | |
| 150642 | +#if SQLITE_MAX_EXPR_DEPTH>0 | |
| 150643 | + if( pParse->nNestSel >= db->aLimit[SQLITE_LIMIT_EXPR_DEPTH] ){ | |
| 150644 | + sqlite3ErrorMsg(pParse, "VIEWs and/or subqueries nested too deep"); | |
| 150645 | + return 0; | |
| 150646 | + } | |
| 150647 | +#endif | |
| 150136 | 150648 | savedFlags = db->flags; |
| 150137 | 150649 | db->flags &= ~(u64)SQLITE_FullColNames; |
| 150138 | 150650 | db->flags |= SQLITE_ShortColNames; |
| 150139 | 150651 | sqlite3SelectPrep(pParse, pSelect, 0); |
| 150140 | 150652 | db->flags = savedFlags; |
| @@ -150152,10 +150664,12 @@ | ||
| 150152 | 150664 | pTab->iPKey = -1; |
| 150153 | 150665 | if( db->mallocFailed ){ |
| 150154 | 150666 | sqlite3DeleteTable(db, pTab); |
| 150155 | 150667 | return 0; |
| 150156 | 150668 | } |
| 150669 | + pParse->nNestSel--; | |
| 150670 | + assert( pParse->nNestSel>=0 ); | |
| 150157 | 150671 | return pTab; |
| 150158 | 150672 | } |
| 150159 | 150673 | |
| 150160 | 150674 | /* |
| 150161 | 150675 | ** Get a VDBE for the given parser context. Create a new one if necessary. |
| @@ -155122,12 +155636,15 @@ | ||
| 155122 | 155636 | ** Then, if CheckOnCtx.iJoin indicates that this expression is part of an |
| 155123 | 155637 | ** ON clause from that SrcList (i.e. if iJoin is non-zero), check that it |
| 155124 | 155638 | ** does not refer to a table to the right of CheckOnCtx.iJoin. */ |
| 155125 | 155639 | do { |
| 155126 | 155640 | SrcList *pSrc = pCtx->pSrc; |
| 155641 | + int nSrc = pSrc->nSrc; | |
| 155127 | 155642 | int iTab = pExpr->iTable; |
| 155128 | - if( iTab>=pSrc->a[0].iCursor && iTab<=pSrc->a[pSrc->nSrc-1].iCursor ){ | |
| 155643 | + int ii; | |
| 155644 | + for(ii=0; ii<nSrc && pSrc->a[ii].iCursor!=iTab; ii++){} | |
| 155645 | + if( ii<nSrc ){ | |
| 155129 | 155646 | if( pCtx->iJoin && iTab>pCtx->iJoin ){ |
| 155130 | 155647 | sqlite3ErrorMsg(pWalker->pParse, |
| 155131 | 155648 | "%s references tables to its right", |
| 155132 | 155649 | (pCtx->bFuncArg ? "table-function argument" : "ON clause") |
| 155133 | 155650 | ); |
| @@ -158092,22 +158609,36 @@ | ||
| 158092 | 158609 | Parse *pParse, /* Current parse context */ |
| 158093 | 158610 | Trigger *pTrigger, /* Trigger to code */ |
| 158094 | 158611 | Table *pTab, /* The table pTrigger is attached to */ |
| 158095 | 158612 | int orconf /* ON CONFLICT policy to code trigger program with */ |
| 158096 | 158613 | ){ |
| 158097 | - Parse *pTop = sqlite3ParseToplevel(pParse); | |
| 158614 | + Parse *pTop; /* Top level Parse object */ | |
| 158098 | 158615 | sqlite3 *db = pParse->db; /* Database handle */ |
| 158099 | 158616 | TriggerPrg *pPrg; /* Value to return */ |
| 158100 | 158617 | Expr *pWhen = 0; /* Duplicate of trigger WHEN expression */ |
| 158101 | 158618 | Vdbe *v; /* Temporary VM */ |
| 158102 | 158619 | NameContext sNC; /* Name context for sub-vdbe */ |
| 158103 | 158620 | SubProgram *pProgram = 0; /* Sub-vdbe for trigger program */ |
| 158104 | 158621 | int iEndTrigger = 0; /* Label to jump to if WHEN is false */ |
| 158105 | 158622 | Parse sSubParse; /* Parse context for sub-vdbe */ |
| 158623 | + int nDepth; /* Trigger depth */ | |
| 158106 | 158624 | |
| 158625 | + /* Ensure that triggers are not chained too deep. This test is linear | |
| 158626 | + ** in the chaining depth, but sensible code ought not be chaining | |
| 158627 | + ** triggers excessively, so that shouldn't be a problem. | |
| 158628 | + */ | |
| 158629 | + pTop = pParse; | |
| 158630 | + for(nDepth=0; pTop->pOuterParse; pTop = pTop->pOuterParse, nDepth++){} | |
| 158631 | + if( nDepth>=db->aLimit[SQLITE_LIMIT_TRIGGER_DEPTH] ){ | |
| 158632 | + sqlite3ErrorMsg(pParse, "triggers nested too deep"); | |
| 158633 | + return 0; | |
| 158634 | + } | |
| 158635 | + | |
| 158636 | + pTop = sqlite3ParseToplevel(pParse); | |
| 158107 | 158637 | assert( pTrigger->zName==0 || pTab==tableOfTrigger(pTrigger) ); |
| 158108 | 158638 | assert( pTop->pVdbe ); |
| 158639 | + | |
| 158109 | 158640 | |
| 158110 | 158641 | /* Allocate the TriggerPrg and SubProgram objects. To ensure that they |
| 158111 | 158642 | ** are freed if an error occurs, link them into the Parse.pTriggerPrg |
| 158112 | 158643 | ** list of the top-level Parse object sooner rather than later. */ |
| 158113 | 158644 | pPrg = sqlite3DbMallocZero(db, sizeof(TriggerPrg)); |
| @@ -160105,11 +160636,12 @@ | ||
| 160105 | 160636 | ** So we have to make a copy before passing it down into sqlite3Update() */ |
| 160106 | 160637 | pSrc = sqlite3SrcListDup(db, pTop->pUpsertSrc, 0); |
| 160107 | 160638 | /* excluded.* columns of type REAL need to be converted to a hard real */ |
| 160108 | 160639 | for(i=0; i<pTab->nCol; i++){ |
| 160109 | 160640 | if( pTab->aCol[i].affinity==SQLITE_AFF_REAL ){ |
| 160110 | - sqlite3VdbeAddOp1(v, OP_RealAffinity, pTop->regData+i); | |
| 160641 | + int iStorage = pTop->regData + sqlite3TableColumnToStorage(pTab, i); | |
| 160642 | + sqlite3VdbeAddOp1(v, OP_RealAffinity, iStorage); | |
| 160111 | 160643 | } |
| 160112 | 160644 | } |
| 160113 | 160645 | sqlite3Update(pParse, pSrc, sqlite3ExprListDup(db,pUpsert->pUpsertSet,0), |
| 160114 | 160646 | sqlite3ExprDup(db,pUpsert->pUpsertWhere,0), OE_Abort, 0, 0, pUpsert); |
| 160115 | 160647 | VdbeNoopComment((v, "End DO UPDATE of UPSERT")); |
| @@ -164903,11 +165435,11 @@ | ||
| 164903 | 165435 | |
| 164904 | 165436 | /* Set up a new SrcList in pOrTab containing the table being scanned |
| 164905 | 165437 | ** by this loop in the a[0] slot and all notReady tables in a[1..] slots. |
| 164906 | 165438 | ** This becomes the SrcList in the recursive call to sqlite3WhereBegin(). |
| 164907 | 165439 | */ |
| 164908 | - if( pWInfo->nLevel>1 ){ | |
| 165440 | + if( pWInfo->nLevel>1 || pTabItem->fg.fromExists ){ | |
| 164909 | 165441 | int nNotReady; /* The number of notReady tables */ |
| 164910 | 165442 | SrcItem *origSrc; /* Original list of tables */ |
| 164911 | 165443 | nNotReady = pWInfo->nLevel - iLevel - 1; |
| 164912 | 165444 | pOrTab = sqlite3DbMallocRawNN(db, SZ_SRCLIST(nNotReady+1)); |
| 164913 | 165445 | if( pOrTab==0 ) return notReady; |
| @@ -164916,10 +165448,17 @@ | ||
| 164916 | 165448 | memcpy(pOrTab->a, pTabItem, sizeof(*pTabItem)); |
| 164917 | 165449 | origSrc = pWInfo->pTabList->a; |
| 164918 | 165450 | for(k=1; k<=nNotReady; k++){ |
| 164919 | 165451 | memcpy(&pOrTab->a[k], &origSrc[pLevel[k].iFrom], sizeof(pOrTab->a[k])); |
| 164920 | 165452 | } |
| 165453 | + | |
| 165454 | + /* Clear the fromExists flag on the OR-optimized table entry so that | |
| 165455 | + ** the calls to sqlite3WhereEnd() do not code early-exits after the | |
| 165456 | + ** first row is visited. The early exit applies to this table's | |
| 165457 | + ** overall loop - including the multiple OR branches and any WHERE | |
| 165458 | + ** conditions not passed to the sub-loops - not to the sub-loops. */ | |
| 165459 | + pOrTab->a[0].fg.fromExists = 0; | |
| 164921 | 165460 | }else{ |
| 164922 | 165461 | pOrTab = pWInfo->pTabList; |
| 164923 | 165462 | } |
| 164924 | 165463 | |
| 164925 | 165464 | /* Initialize the rowset register to contain NULL. An SQL NULL is |
| @@ -165159,11 +165698,11 @@ | ||
| 165159 | 165698 | ** indent everything in between the this point and the final OP_Return. |
| 165160 | 165699 | ** See tag-20220407a in vdbe.c and shell.c */ |
| 165161 | 165700 | assert( pLevel->op==OP_Return ); |
| 165162 | 165701 | pLevel->p2 = sqlite3VdbeCurrentAddr(v); |
| 165163 | 165702 | |
| 165164 | - if( pWInfo->nLevel>1 ){ sqlite3DbFreeNN(db, pOrTab); } | |
| 165703 | + if( pWInfo->pTabList!=pOrTab ){ sqlite3DbFreeNN(db, pOrTab); } | |
| 165165 | 165704 | if( !untestedTerms ) disableTerm(pLevel, pTerm); |
| 165166 | 165705 | }else |
| 165167 | 165706 | #endif /* SQLITE_OMIT_OR_OPTIMIZATION */ |
| 165168 | 165707 | |
| 165169 | 165708 | { |
| @@ -165316,10 +165855,11 @@ | ||
| 165316 | 165855 | assert( (pTerm->eOperator & (WO_OR|WO_AND))==0 ); |
| 165317 | 165856 | pAlt = sqlite3WhereFindTerm(pWC, iCur, pTerm->u.x.leftColumn, notReady, |
| 165318 | 165857 | WO_EQ|WO_IN|WO_IS, 0); |
| 165319 | 165858 | if( pAlt==0 ) continue; |
| 165320 | 165859 | if( pAlt->wtFlags & (TERM_CODED) ) continue; |
| 165860 | + if( ExprHasProperty(pAlt->pExpr, EP_Collate) ) continue; | |
| 165321 | 165861 | if( (pAlt->eOperator & WO_IN) |
| 165322 | 165862 | && ExprUseXSelect(pAlt->pExpr) |
| 165323 | 165863 | && (pAlt->pExpr->x.pSelect->pEList->nExpr>1) |
| 165324 | 165864 | ){ |
| 165325 | 165865 | continue; |
| @@ -166069,11 +166609,14 @@ | ||
| 166069 | 166609 | ** Mark term iChild as being a child of term iParent |
| 166070 | 166610 | */ |
| 166071 | 166611 | static void markTermAsChild(WhereClause *pWC, int iChild, int iParent){ |
| 166072 | 166612 | pWC->a[iChild].iParent = iParent; |
| 166073 | 166613 | pWC->a[iChild].truthProb = pWC->a[iParent].truthProb; |
| 166614 | + assert( pWC->a[iParent].nChild < UMXV(pWC->a[0].nChild) ); | |
| 166074 | 166615 | pWC->a[iParent].nChild++; |
| 166616 | + testcase( pWC->a[iParent].nChild == UMXV(pWC->a[0].nChild) ); | |
| 166617 | + | |
| 166075 | 166618 | } |
| 166076 | 166619 | |
| 166077 | 166620 | /* |
| 166078 | 166621 | ** Return the N-th AND-connected subterm of pTerm. Or if pTerm is not |
| 166079 | 166622 | ** a conjunction, then return just pTerm when N==0. If N is exceeds |
| @@ -166508,23 +167051,22 @@ | ||
| 166508 | 167051 | ** 1. The SQLITE_Transitive optimization must be enabled |
| 166509 | 167052 | ** 2. Must be either an == or an IS operator |
| 166510 | 167053 | ** 3. Not originating in the ON clause of an OUTER JOIN |
| 166511 | 167054 | ** 4. The operator is not IS or else the query does not contain RIGHT JOIN |
| 166512 | 167055 | ** 5. The affinities of A and B must be compatible |
| 166513 | -** 6a. Both operands use the same collating sequence OR | |
| 166514 | -** 6b. The overall collating sequence is BINARY | |
| 167056 | +** 6. Both operands use the same collating sequence, and they must not | |
| 167057 | +** use explicit COLLATE clauses. | |
| 166515 | 167058 | ** If this routine returns TRUE, that means that the RHS can be substituted |
| 166516 | 167059 | ** for the LHS anyplace else in the WHERE clause where the LHS column occurs. |
| 166517 | 167060 | ** This is an optimization. No harm comes from returning 0. But if 1 is |
| 166518 | 167061 | ** returned when it should not be, then incorrect answers might result. |
| 166519 | 167062 | */ |
| 166520 | 167063 | static int termIsEquivalence(Parse *pParse, Expr *pExpr, SrcList *pSrc){ |
| 166521 | 167064 | char aff1, aff2; |
| 166522 | - CollSeq *pColl; | |
| 166523 | 167065 | if( !OptimizationEnabled(pParse->db, SQLITE_Transitive) ) return 0; /* (1) */ |
| 166524 | 167066 | if( pExpr->op!=TK_EQ && pExpr->op!=TK_IS ) return 0; /* (2) */ |
| 166525 | - if( ExprHasProperty(pExpr, EP_OuterON) ) return 0; /* (3) */ | |
| 167067 | + if( ExprHasProperty(pExpr, EP_OuterON|EP_Collate) ) return 0; /* (3) */ | |
| 166526 | 167068 | assert( pSrc!=0 ); |
| 166527 | 167069 | if( pExpr->op==TK_IS |
| 166528 | 167070 | && pSrc->nSrc>=2 |
| 166529 | 167071 | && (pSrc->a[0].fg.jointype & JT_LTORJ)!=0 |
| 166530 | 167072 | ){ |
| @@ -166535,14 +167077,11 @@ | ||
| 166535 | 167077 | if( aff1!=aff2 |
| 166536 | 167078 | && (!sqlite3IsNumericAffinity(aff1) || !sqlite3IsNumericAffinity(aff2)) |
| 166537 | 167079 | ){ |
| 166538 | 167080 | return 0; /* (5) */ |
| 166539 | 167081 | } |
| 166540 | - pColl = sqlite3ExprCompareCollSeq(pParse, pExpr); | |
| 166541 | - if( !sqlite3IsBinary(pColl) | |
| 166542 | - && !sqlite3ExprCollSeqMatch(pParse, pExpr->pLeft, pExpr->pRight) | |
| 166543 | - ){ | |
| 167082 | + if( !sqlite3ExprCollSeqMatch(pParse, pExpr->pLeft, pExpr->pRight) ){ | |
| 166544 | 167083 | return 0; /* (6) */ |
| 166545 | 167084 | } |
| 166546 | 167085 | return 1; |
| 166547 | 167086 | } |
| 166548 | 167087 | |
| @@ -166850,10 +167389,11 @@ | ||
| 166850 | 167389 | static const u8 ops[] = {TK_GE, TK_LE}; |
| 166851 | 167390 | assert( ExprUseXList(pExpr) ); |
| 166852 | 167391 | pList = pExpr->x.pList; |
| 166853 | 167392 | assert( pList!=0 ); |
| 166854 | 167393 | assert( pList->nExpr==2 ); |
| 167394 | + assert( pWC->a[idxTerm].nChild==0 ); | |
| 166855 | 167395 | for(i=0; i<2; i++){ |
| 166856 | 167396 | Expr *pNewExpr; |
| 166857 | 167397 | int idxNew; |
| 166858 | 167398 | pNewExpr = sqlite3PExpr(pParse, ops[i], |
| 166859 | 167399 | sqlite3ExprDup(db, pExpr->pLeft, 0), |
| @@ -166870,11 +167410,11 @@ | ||
| 166870 | 167410 | |
| 166871 | 167411 | #if !defined(SQLITE_OMIT_OR_OPTIMIZATION) && !defined(SQLITE_OMIT_SUBQUERY) |
| 166872 | 167412 | /* Analyze a term that is composed of two or more subterms connected by |
| 166873 | 167413 | ** an OR operator. |
| 166874 | 167414 | */ |
| 166875 | - else if( pExpr->op==TK_OR ){ | |
| 167415 | + else if( pExpr->op==TK_OR && !ExprHasProperty(pExpr, EP_Collate) ){ | |
| 166876 | 167416 | assert( pWC->op==TK_AND ); |
| 166877 | 167417 | exprAnalyzeOrTerm(pSrc, pWC, idxTerm); |
| 166878 | 167418 | pTerm = &pWC->a[idxTerm]; |
| 166879 | 167419 | } |
| 166880 | 167420 | #endif /* SQLITE_OMIT_OR_OPTIMIZATION */ |
| @@ -167060,12 +167600,15 @@ | ||
| 167060 | 167600 | && (pExpr->x.pSelect->pPrior==0 || (pExpr->x.pSelect->selFlags & SF_Values)) |
| 167061 | 167601 | #ifndef SQLITE_OMIT_WINDOWFUNC |
| 167062 | 167602 | && pExpr->x.pSelect->pWin==0 |
| 167063 | 167603 | #endif |
| 167064 | 167604 | && pWC->op==TK_AND |
| 167605 | + && pExpr->x.pSelect->pEList->nExpr <= UMXV(pTerm->nChild) | |
| 167606 | + /* ^-- See bug 2026-06-04T10:00:49Z */ | |
| 167065 | 167607 | ){ |
| 167066 | 167608 | int i; |
| 167609 | + assert( pTerm->nChild==0 ); | |
| 167067 | 167610 | for(i=0; i<sqlite3ExprVectorSize(pExpr->pLeft); i++){ |
| 167068 | 167611 | int idxNew; |
| 167069 | 167612 | idxNew = whereClauseInsert(pWC, pExpr, TERM_VIRTUAL|TERM_SLICE); |
| 167070 | 167613 | pWC->a[idxNew].u.x.iField = i+1; |
| 167071 | 167614 | exprAnalyze(pSrc, pWC, idxNew); |
| @@ -170589,13 +171132,14 @@ | ||
| 170589 | 171132 | pLoop->nOut--; |
| 170590 | 171133 | if( (pTerm->eOperator&(WO_EQ|WO_IS))!=0 |
| 170591 | 171134 | && (pTerm->wtFlags & TERM_HIGHTRUTH)==0 /* tag-20200224-1 */ |
| 170592 | 171135 | ){ |
| 170593 | 171136 | Expr *pRight = pOpExpr->pRight; |
| 171137 | + Parse *pParse = pWC->pWInfo->pParse; | |
| 170594 | 171138 | int k = 0; |
| 170595 | 171139 | testcase( pOpExpr->op==TK_IS ); |
| 170596 | - if( sqlite3ExprIsInteger(pRight, &k, 0) && k>=(-1) && k<=1 ){ | |
| 171140 | + if( sqlite3ExprIsInteger(pRight, &k, pParse) && k>=(-1) && k<=1 ){ | |
| 170597 | 171141 | k = 10; |
| 170598 | 171142 | }else{ |
| 170599 | 171143 | k = 20; |
| 170600 | 171144 | } |
| 170601 | 171145 | if( iReduce<k ){ |
| @@ -170688,11 +171232,12 @@ | ||
| 170688 | 171232 | testcase( pLhs->iColumn==XN_ROWID ); |
| 170689 | 171233 | aff = sqlite3CompareAffinity(pRhs, sqlite3ExprAffinity(pLhs)); |
| 170690 | 171234 | idxaff = sqlite3TableColumnAffinity(pIdx->pTable, pLhs->iColumn); |
| 170691 | 171235 | if( aff!=idxaff ) break; |
| 170692 | 171236 | |
| 170693 | - pColl = sqlite3ExprCompareCollSeq(pParse, pTerm->pExpr); | |
| 171237 | + if( ExprHasProperty(pTerm->pExpr, EP_Commuted) ) SWAP(Expr*, pRhs, pLhs); | |
| 171238 | + pColl = sqlite3BinaryCompareCollSeq(pParse, pLhs, pRhs); | |
| 170694 | 171239 | if( pColl==0 ) break; |
| 170695 | 171240 | if( sqlite3StrICmp(pColl->zName, pIdx->azColl[i+nEq]) ) break; |
| 170696 | 171241 | } |
| 170697 | 171242 | return i; |
| 170698 | 171243 | } |
| @@ -183162,13 +183707,15 @@ | ||
| 183162 | 183707 | case 196: /* expr ::= LP nexprlist COMMA expr RP */ |
| 183163 | 183708 | { |
| 183164 | 183709 | ExprList *pList = sqlite3ExprListAppend(pParse, yymsp[-3].minor.yy14, yymsp[-1].minor.yy454); |
| 183165 | 183710 | yymsp[-4].minor.yy454 = sqlite3PExpr(pParse, TK_VECTOR, 0, 0); |
| 183166 | 183711 | if( yymsp[-4].minor.yy454 ){ |
| 183712 | + int i; | |
| 183167 | 183713 | yymsp[-4].minor.yy454->x.pList = pList; |
| 183168 | - if( ALWAYS(pList->nExpr) ){ | |
| 183169 | - yymsp[-4].minor.yy454->flags |= pList->a[0].pExpr->flags & EP_Propagate; | |
| 183714 | + for(i=0; i<pList->nExpr; i++){ | |
| 183715 | + assert( pList->a[i].pExpr!=0 ); | |
| 183716 | + yymsp[-4].minor.yy454->flags |= pList->a[i].pExpr->flags & EP_Propagate; | |
| 183170 | 183717 | } |
| 183171 | 183718 | }else{ |
| 183172 | 183719 | sqlite3ExprListDelete(pParse->db, pList); |
| 183173 | 183720 | } |
| 183174 | 183721 | } |
| @@ -183632,19 +184179,17 @@ | ||
| 183632 | 184179 | sqlite3AlterSetNotNull(pParse, yymsp[-7].minor.yy203, &yymsp[-4].minor.yy0, &yymsp[-2].minor.yy0); |
| 183633 | 184180 | } |
| 183634 | 184181 | break; |
| 183635 | 184182 | case 300: /* cmd ::= ALTER TABLE fullname ADD CONSTRAINT nm CHECK LP expr RP onconf */ |
| 183636 | 184183 | { |
| 183637 | - sqlite3AlterAddConstraint(pParse, yymsp[-8].minor.yy203, &yymsp[-6].minor.yy0, &yymsp[-5].minor.yy0, yymsp[-3].minor.yy0.z+1, (yymsp[-1].minor.yy0.z-yymsp[-3].minor.yy0.z-1)); | |
| 184184 | + sqlite3AlterAddConstraint(pParse, yymsp[-8].minor.yy203, &yymsp[-6].minor.yy0, &yymsp[-5].minor.yy0, yymsp[-3].minor.yy0.z+1, (yymsp[-1].minor.yy0.z-yymsp[-3].minor.yy0.z-1), yymsp[-2].minor.yy454); | |
| 183638 | 184185 | } |
| 183639 | - yy_destructor(yypParser,219,&yymsp[-2].minor); | |
| 183640 | 184186 | break; |
| 183641 | 184187 | case 301: /* cmd ::= ALTER TABLE fullname ADD CHECK LP expr RP onconf */ |
| 183642 | 184188 | { |
| 183643 | - sqlite3AlterAddConstraint(pParse, yymsp[-6].minor.yy203, &yymsp[-4].minor.yy0, 0, yymsp[-3].minor.yy0.z+1, (yymsp[-1].minor.yy0.z-yymsp[-3].minor.yy0.z-1)); | |
| 184189 | + sqlite3AlterAddConstraint(pParse, yymsp[-6].minor.yy203, &yymsp[-4].minor.yy0, 0, yymsp[-3].minor.yy0.z+1, (yymsp[-1].minor.yy0.z-yymsp[-3].minor.yy0.z-1), yymsp[-2].minor.yy454); | |
| 183644 | 184190 | } |
| 183645 | - yy_destructor(yypParser,219,&yymsp[-2].minor); | |
| 183646 | 184191 | break; |
| 183647 | 184192 | case 302: /* cmd ::= create_vtab */ |
| 183648 | 184193 | {sqlite3VtabFinishParse(pParse,0);} |
| 183649 | 184194 | break; |
| 183650 | 184195 | case 303: /* cmd ::= create_vtab LP vtabarglist RP */ |
| @@ -186617,11 +187162,11 @@ | ||
| 186617 | 187162 | ** or disables the collection of memory allocation statistics. */ |
| 186618 | 187163 | sqlite3GlobalConfig.bMemstat = va_arg(ap, int); |
| 186619 | 187164 | break; |
| 186620 | 187165 | } |
| 186621 | 187166 | case SQLITE_CONFIG_SMALL_MALLOC: { |
| 186622 | - sqlite3GlobalConfig.bSmallMalloc = va_arg(ap, int); | |
| 187167 | + sqlite3GlobalConfig.bSmallMalloc = va_arg(ap, int)!=0; | |
| 186623 | 187168 | break; |
| 186624 | 187169 | } |
| 186625 | 187170 | case SQLITE_CONFIG_PAGECACHE: { |
| 186626 | 187171 | /* EVIDENCE-OF: R-18761-36601 There are three arguments to |
| 186627 | 187172 | ** SQLITE_CONFIG_PAGECACHE: A pointer to 8-byte aligned memory (pMem), |
| @@ -192926,10 +193471,16 @@ | ||
| 192926 | 193471 | #ifndef SQLITE_CORE |
| 192927 | 193472 | /* # include "sqlite3ext.h" */ |
| 192928 | 193473 | SQLITE_EXTENSION_INIT1 |
| 192929 | 193474 | #endif |
| 192930 | 193475 | |
| 193476 | + | |
| 193477 | +/* | |
| 193478 | +** Assume any b-tree layer with more levels than this is corrupt. | |
| 193479 | +*/ | |
| 193480 | +#define FTS3_MAX_BTREE_HEIGHT 48 | |
| 193481 | + | |
| 192931 | 193482 | typedef struct Fts3HashWrapper Fts3HashWrapper; |
| 192932 | 193483 | struct Fts3HashWrapper { |
| 192933 | 193484 | Fts3Hash hash; /* Hash table */ |
| 192934 | 193485 | int nRef; /* Number of pointers to this object */ |
| 192935 | 193486 | }; |
| @@ -194642,11 +195193,15 @@ | ||
| 194642 | 195193 | int iHeight; /* Height of this node in tree */ |
| 194643 | 195194 | |
| 194644 | 195195 | assert( piLeaf || piLeaf2 ); |
| 194645 | 195196 | |
| 194646 | 195197 | fts3GetVarint32(zNode, &iHeight); |
| 194647 | - rc = fts3ScanInteriorNode(zTerm, nTerm, zNode, nNode, piLeaf, piLeaf2); | |
| 195198 | + if( iHeight>FTS3_MAX_BTREE_HEIGHT ){ | |
| 195199 | + rc = FTS_CORRUPT_VTAB; | |
| 195200 | + }else{ | |
| 195201 | + rc = fts3ScanInteriorNode(zTerm, nTerm, zNode, nNode, piLeaf, piLeaf2); | |
| 195202 | + } | |
| 194648 | 195203 | assert_fts3_nc( !piLeaf2 || !piLeaf || rc!=SQLITE_OK || (*piLeaf<=*piLeaf2) ); |
| 194649 | 195204 | |
| 194650 | 195205 | if( rc==SQLITE_OK && iHeight>1 ){ |
| 194651 | 195206 | char *zBlob = 0; /* Blob read from %_segments table */ |
| 194652 | 195207 | int nBlob = 0; /* Size of zBlob in bytes */ |
| @@ -194687,12 +195242,17 @@ | ||
| 194687 | 195242 | char **pp, /* IN/OUT: Output pointer */ |
| 194688 | 195243 | sqlite3_int64 *piPrev, /* IN/OUT: Previous value written to list */ |
| 194689 | 195244 | sqlite3_int64 iVal /* Write this value to the list */ |
| 194690 | 195245 | ){ |
| 194691 | 195246 | assert_fts3_nc( iVal-*piPrev > 0 || (*piPrev==0 && iVal==0) ); |
| 194692 | - *pp += sqlite3Fts3PutVarint(*pp, iVal-*piPrev); | |
| 194693 | - *piPrev = iVal; | |
| 195247 | + if( iVal-(*piPrev)>=0 ){ | |
| 195248 | + /* Refuse to write a negative delta integer. This only happens with a | |
| 195249 | + ** corrupt db (see the assert above) and can cause buffer overwrites | |
| 195250 | + ** in some cases. */ | |
| 195251 | + *pp += sqlite3Fts3PutVarint(*pp, iVal-*piPrev); | |
| 195252 | + *piPrev = iVal; | |
| 195253 | + } | |
| 194694 | 195254 | } |
| 194695 | 195255 | |
| 194696 | 195256 | /* |
| 194697 | 195257 | ** When this function is called, *ppPoslist is assumed to point to the |
| 194698 | 195258 | ** start of a position-list. After it returns, *ppPoslist points to the |
| @@ -199171,11 +199731,11 @@ | ||
| 199171 | 199731 | break; |
| 199172 | 199732 | |
| 199173 | 199733 | /* State 3. The integer just read is a column number. */ |
| 199174 | 199734 | default: assert( eState==3 ); |
| 199175 | 199735 | iCol = (int)v; |
| 199176 | - if( iCol<1 ){ | |
| 199736 | + if( iCol<1 || iCol>(pFts3->nColumn+1) ){ | |
| 199177 | 199737 | rc = SQLITE_CORRUPT_VTAB; |
| 199178 | 199738 | break; |
| 199179 | 199739 | } |
| 199180 | 199740 | if( fts3auxGrowStatArray(pCsr, iCol+2) ) return SQLITE_NOMEM; |
| 199181 | 199741 | pCsr->aStat[iCol+1].nDoc++; |
| @@ -199861,10 +200421,11 @@ | ||
| 199861 | 200421 | /* If this is a "NEAR" keyword, check for an explicit nearness. */ |
| 199862 | 200422 | if( pKey->eType==FTSQUERY_NEAR ){ |
| 199863 | 200423 | assert( nKey==4 ); |
| 199864 | 200424 | if( zInput[4]=='/' && zInput[5]>='0' && zInput[5]<='9' ){ |
| 199865 | 200425 | nKey += 1+sqlite3Fts3ReadInt(&zInput[nKey+1], &nNear); |
| 200426 | + if( nNear>=1000000000 ) nNear = 1000000000; | |
| 199866 | 200427 | } |
| 199867 | 200428 | } |
| 199868 | 200429 | |
| 199869 | 200430 | /* At this point this is probably a keyword. But for that to be true, |
| 199870 | 200431 | ** the next byte must contain either whitespace, an open or close |
| @@ -206107,10 +206668,14 @@ | ||
| 206107 | 206668 | iMul = -1; |
| 206108 | 206669 | } |
| 206109 | 206670 | for(/* no-op */; zText[i]>='0' && zText[i]<='9'; i++){ |
| 206110 | 206671 | iVal = iVal*10 + (zText[i] - '0'); |
| 206111 | 206672 | } |
| 206673 | + | |
| 206674 | + /* This if() clause is just to avoid an integer overflow. The record is | |
| 206675 | + ** corrupt in this case. */ | |
| 206676 | + if( (i64)iVal==SMALLEST_INT64 ) iMul = 1; | |
| 206112 | 206677 | *pnByte = ((i64)iVal * (i64)iMul); |
| 206113 | 206678 | } |
| 206114 | 206679 | } |
| 206115 | 206680 | |
| 206116 | 206681 | |
| @@ -208969,14 +209534,13 @@ | ||
| 208969 | 209534 | */ |
| 208970 | 209535 | |
| 208971 | 209536 | /* |
| 208972 | 209537 | ** Allocate a two-slot MatchinfoBuffer object. |
| 208973 | 209538 | */ |
| 208974 | -static MatchinfoBuffer *fts3MIBufferNew(size_t nElem, const char *zMatchinfo){ | |
| 209539 | +static MatchinfoBuffer *fts3MIBufferNew(i64 nElem, const char *zMatchinfo){ | |
| 208975 | 209540 | MatchinfoBuffer *pRet; |
| 208976 | - sqlite3_int64 nByte = sizeof(u32) * (2*(sqlite3_int64)nElem + 1) | |
| 208977 | - + SZ_MATCHINFOBUFFER(1); | |
| 209541 | + sqlite3_int64 nByte = sizeof(u32) * (2*(i64)nElem+1) + SZ_MATCHINFOBUFFER(1); | |
| 208978 | 209542 | sqlite3_int64 nStr = strlen(zMatchinfo); |
| 208979 | 209543 | |
| 208980 | 209544 | pRet = sqlite3Fts3MallocZero(nByte + nStr+1); |
| 208981 | 209545 | if( pRet ){ |
| 208982 | 209546 | pRet->aMI[0] = (u8*)(&pRet->aMI[1]) - (u8*)pRet; |
| @@ -209724,11 +210288,11 @@ | ||
| 209724 | 210288 | int nHit = fts3ColumnlistCount(&pIter); |
| 209725 | 210289 | if( (pPhrase->iColumn>=pTab->nColumn || pPhrase->iColumn==iCol) ){ |
| 209726 | 210290 | if( p->flag==FTS3_MATCHINFO_LHITS ){ |
| 209727 | 210291 | p->aMatchinfo[iStart + iCol] = (u32)nHit; |
| 209728 | 210292 | }else if( nHit ){ |
| 209729 | - p->aMatchinfo[iStart + (iCol+1)/32] |= (1 << (iCol&0x1F)); | |
| 210293 | + p->aMatchinfo[iStart + iCol/32] |= (1U << (iCol&0x1F)); | |
| 209730 | 210294 | } |
| 209731 | 210295 | } |
| 209732 | 210296 | assert( *pIter==0x00 || *pIter==0x01 ); |
| 209733 | 210297 | if( *pIter!=0x01 ) break; |
| 209734 | 210298 | pIter++; |
| @@ -209843,12 +210407,12 @@ | ||
| 209843 | 210407 | } |
| 209844 | 210408 | sqlite3Fts3ErrMsg(pzErr, "unrecognized matchinfo request: %c", cArg); |
| 209845 | 210409 | return SQLITE_ERROR; |
| 209846 | 210410 | } |
| 209847 | 210411 | |
| 209848 | -static size_t fts3MatchinfoSize(MatchInfo *pInfo, char cArg){ | |
| 209849 | - size_t nVal; /* Number of integers output by cArg */ | |
| 210412 | +static i64 fts3MatchinfoSize(MatchInfo *pInfo, char cArg){ | |
| 210413 | + i64 nVal; /* Number of integers output by cArg */ | |
| 209850 | 210414 | |
| 209851 | 210415 | switch( cArg ){ |
| 209852 | 210416 | case FTS3_MATCHINFO_NDOC: |
| 209853 | 210417 | case FTS3_MATCHINFO_NPHRASE: |
| 209854 | 210418 | case FTS3_MATCHINFO_NCOL: |
| @@ -209860,20 +210424,20 @@ | ||
| 209860 | 210424 | case FTS3_MATCHINFO_LCS: |
| 209861 | 210425 | nVal = pInfo->nCol; |
| 209862 | 210426 | break; |
| 209863 | 210427 | |
| 209864 | 210428 | case FTS3_MATCHINFO_LHITS: |
| 209865 | - nVal = (size_t)pInfo->nCol * pInfo->nPhrase; | |
| 210429 | + nVal = (i64)pInfo->nCol * pInfo->nPhrase; | |
| 209866 | 210430 | break; |
| 209867 | 210431 | |
| 209868 | 210432 | case FTS3_MATCHINFO_LHITS_BM: |
| 209869 | - nVal = (size_t)pInfo->nPhrase * ((pInfo->nCol + 31) / 32); | |
| 210433 | + nVal = (i64)pInfo->nPhrase * ((pInfo->nCol + 31) / 32); | |
| 209870 | 210434 | break; |
| 209871 | 210435 | |
| 209872 | 210436 | default: |
| 209873 | 210437 | assert( cArg==FTS3_MATCHINFO_HITS ); |
| 209874 | - nVal = (size_t)pInfo->nCol * pInfo->nPhrase * 3; | |
| 210438 | + nVal = (i64)pInfo->nCol * pInfo->nPhrase * 3; | |
| 209875 | 210439 | break; |
| 209876 | 210440 | } |
| 209877 | 210441 | |
| 209878 | 210442 | return nVal; |
| 209879 | 210443 | } |
| @@ -210151,11 +210715,11 @@ | ||
| 210151 | 210715 | } |
| 210152 | 210716 | break; |
| 210153 | 210717 | |
| 210154 | 210718 | case FTS3_MATCHINFO_LHITS_BM: |
| 210155 | 210719 | case FTS3_MATCHINFO_LHITS: { |
| 210156 | - size_t nZero = fts3MatchinfoSize(pInfo, zArg[i]) * sizeof(u32); | |
| 210720 | + i64 nZero = fts3MatchinfoSize(pInfo, zArg[i]) * sizeof(u32); | |
| 210157 | 210721 | memset(pInfo->aMatchinfo, 0, nZero); |
| 210158 | 210722 | rc = fts3ExprLHitGather(pCsr->pExpr, pInfo); |
| 210159 | 210723 | break; |
| 210160 | 210724 | } |
| 210161 | 210725 | |
| @@ -210220,11 +210784,11 @@ | ||
| 210220 | 210784 | ** matchinfo function has been called for this query. In this case |
| 210221 | 210785 | ** allocate the array used to accumulate the matchinfo data and |
| 210222 | 210786 | ** initialize those elements that are constant for every row. |
| 210223 | 210787 | */ |
| 210224 | 210788 | if( pCsr->pMIBuffer==0 ){ |
| 210225 | - size_t nMatchinfo = 0; /* Number of u32 elements in match-info */ | |
| 210789 | + i64 nMatchinfo = 0; /* Number of u32 elements in match-info */ | |
| 210226 | 210790 | int i; /* Used to iterate through zArg */ |
| 210227 | 210791 | |
| 210228 | 210792 | /* Determine the number of phrases in the query */ |
| 210229 | 210793 | pCsr->nPhrase = fts3ExprPhraseCount(pCsr->pExpr); |
| 210230 | 210794 | sInfo.nPhrase = pCsr->nPhrase; |
| @@ -212214,11 +212778,11 @@ | ||
| 212214 | 212778 | case SQLITE_NULL: { |
| 212215 | 212779 | jsonAppendRawNZ(p, "null", 4); |
| 212216 | 212780 | break; |
| 212217 | 212781 | } |
| 212218 | 212782 | case SQLITE_FLOAT: { |
| 212219 | - jsonPrintf(100, p, "%!0.15g", sqlite3_value_double(pValue)); | |
| 212783 | + jsonPrintf(100, p, "%!0.17g", sqlite3_value_double(pValue)); | |
| 212220 | 212784 | break; |
| 212221 | 212785 | } |
| 212222 | 212786 | case SQLITE_INTEGER: { |
| 212223 | 212787 | const char *z = (const char*)sqlite3_value_text(pValue); |
| 212224 | 212788 | u32 n = (u32)sqlite3_value_bytes(pValue); |
| @@ -213528,13 +214092,14 @@ | ||
| 213528 | 214092 | */ |
| 213529 | 214093 | static u32 jsonbPayloadSize(const JsonParse *pParse, u32 i, u32 *pSz){ |
| 213530 | 214094 | u8 x; |
| 213531 | 214095 | u32 sz; |
| 213532 | 214096 | u32 n; |
| 213533 | - assert( i<=pParse->nBlob ); | |
| 213534 | - x = pParse->aBlob[i]>>4; | |
| 213535 | - if( x<=11 ){ | |
| 214097 | + if( i>=pParse->nBlob ){ | |
| 214098 | + *pSz = 0; | |
| 214099 | + return 0; | |
| 214100 | + }else if( (x = pParse->aBlob[i]>>4)<=11 ){ | |
| 213536 | 214101 | sz = x; |
| 213537 | 214102 | n = 1; |
| 213538 | 214103 | }else if( x==12 ){ |
| 213539 | 214104 | if( i+1>=pParse->nBlob ){ |
| 213540 | 214105 | *pSz = 0; |
| @@ -213744,11 +214309,11 @@ | ||
| 213744 | 214309 | break; |
| 213745 | 214310 | case '\n': |
| 213746 | 214311 | break; |
| 213747 | 214312 | case 0xe2: |
| 213748 | 214313 | /* '\' followed by either U+2028 or U+2029 is ignored as |
| 213749 | - ** whitespace. Not that in UTF8, U+2028 is 0xe2 0x80 0x29. | |
| 214314 | + ** whitespace. Note that in UTF8, U+2028 is 0xe2 0x80 0x29. | |
| 213750 | 214315 | ** U+2029 is the same except for the last byte */ |
| 213751 | 214316 | if( sz2<4 |
| 213752 | 214317 | || 0x80!=(u8)zIn[2] |
| 213753 | 214318 | || (0xa8!=(u8)zIn[3] && 0xa9!=(u8)zIn[3]) |
| 213754 | 214319 | ){ |
| @@ -216313,15 +216878,13 @@ | ||
| 216313 | 216878 | char c; |
| 216314 | 216879 | JsonString *pStr; |
| 216315 | 216880 | UNUSED_PARAMETER(argc); |
| 216316 | 216881 | UNUSED_PARAMETER(argv); |
| 216317 | 216882 | pStr = (JsonString*)sqlite3_aggregate_context(ctx, 0); |
| 216318 | -#ifdef NEVER | |
| 216319 | 216883 | /* pStr is always non-NULL since jsonArrayStep() or jsonObjectStep() will |
| 216320 | 216884 | ** always have been called to initialize it */ |
| 216321 | 216885 | if( NEVER(!pStr) ) return; |
| 216322 | -#endif | |
| 216323 | 216886 | z = pStr->zBuf; |
| 216324 | 216887 | for(i=1; i<pStr->nUsed && ((c = z[i])!=',' || inStr || nNest); i++){ |
| 216325 | 216888 | if( c=='"' ){ |
| 216326 | 216889 | inStr = !inStr; |
| 216327 | 216890 | }else if( c=='\\' ){ |
| @@ -216346,10 +216909,17 @@ | ||
| 216346 | 216909 | |
| 216347 | 216910 | /* |
| 216348 | 216911 | ** json_group_obj(NAME,VALUE) |
| 216349 | 216912 | ** |
| 216350 | 216913 | ** Return a JSON object composed of all names and values in the aggregate. |
| 216914 | +** | |
| 216915 | +** Rows for which NAME is NULL do not result in a new entry. However, we | |
| 216916 | +** do initially insert a "@" entry into the growing string for each null entry | |
| 216917 | +** and change the first character of the string to "@" to signal that the | |
| 216918 | +** string contains null entries. The "@" markers are needed in order to | |
| 216919 | +** correctly process xInverse() requests. The initial "@" is converted | |
| 216920 | +** back into "{" and the "@" null values are removed by jsonObjectCompute(). | |
| 216351 | 216921 | */ |
| 216352 | 216922 | static void jsonObjectStep( |
| 216353 | 216923 | sqlite3_context *ctx, |
| 216354 | 216924 | int argc, |
| 216355 | 216925 | sqlite3_value **argv |
| @@ -216363,49 +216933,97 @@ | ||
| 216363 | 216933 | z = (const char*)sqlite3_value_text(argv[0]); |
| 216364 | 216934 | n = sqlite3Strlen30(z); |
| 216365 | 216935 | if( pStr->zBuf==0 ){ |
| 216366 | 216936 | jsonStringInit(pStr, ctx); |
| 216367 | 216937 | jsonAppendChar(pStr, '{'); |
| 216368 | - }else if( pStr->nUsed>1 && z!=0 ){ | |
| 216938 | + }else if( pStr->nUsed>1 ){ | |
| 216369 | 216939 | jsonAppendChar(pStr, ','); |
| 216370 | 216940 | } |
| 216371 | 216941 | pStr->pCtx = ctx; |
| 216372 | 216942 | if( z!=0 ){ |
| 216373 | 216943 | jsonAppendString(pStr, z, n); |
| 216374 | 216944 | jsonAppendChar(pStr, ':'); |
| 216375 | 216945 | jsonAppendSqlValue(pStr, argv[1]); |
| 216946 | + }else{ | |
| 216947 | + pStr->zBuf[0] = '@'; | |
| 216948 | + jsonAppendRawNZ(pStr, "@", 1); | |
| 216376 | 216949 | } |
| 216377 | 216950 | } |
| 216378 | 216951 | } |
| 216379 | 216952 | static void jsonObjectCompute(sqlite3_context *ctx, int isFinal){ |
| 216380 | 216953 | JsonString *pStr; |
| 216381 | 216954 | int flags = SQLITE_PTR_TO_INT(sqlite3_user_data(ctx)); |
| 216382 | 216955 | pStr = (JsonString*)sqlite3_aggregate_context(ctx, 0); |
| 216383 | 216956 | if( pStr ){ |
| 216384 | - jsonAppendRawNZ(pStr, "}", 2); | |
| 216385 | - jsonStringTrimOneChar(pStr); | |
| 216957 | + JsonString *pOgStr = pStr; | |
| 216958 | + JsonString tmpStr; | |
| 216959 | + jsonAppendRawNZ(pOgStr, "}", 2); /* Ensure it is zero-terminated */ | |
| 216960 | + jsonStringTrimOneChar(pOgStr); /* Remove the zero terminator */ | |
| 216386 | 216961 | pStr->pCtx = ctx; |
| 216387 | 216962 | if( pStr->eErr ){ |
| 216388 | 216963 | jsonReturnString(pStr, 0, 0); |
| 216389 | 216964 | return; |
| 216390 | - }else if( flags & JSON_BLOB ){ | |
| 216965 | + } | |
| 216966 | + if( pStr->zBuf[0]!='{' ){ | |
| 216967 | + /* The string contains null entries that need to be removed */ | |
| 216968 | + u64 i, j; | |
| 216969 | + int inStr = 0; | |
| 216970 | + if( !isFinal ){ | |
| 216971 | + /* Work with a temporary copy of the string if this is not the | |
| 216972 | + ** final result */ | |
| 216973 | + jsonStringInit(&tmpStr, ctx); | |
| 216974 | + jsonAppendRawNZ(&tmpStr, pStr->zBuf, pStr->nUsed+1); | |
| 216975 | + pStr = &tmpStr; | |
| 216976 | + if( pStr->eErr ){ | |
| 216977 | + jsonReturnString(pStr, 0, 0); | |
| 216978 | + return; | |
| 216979 | + } | |
| 216980 | + jsonStringTrimOneChar(pStr); /* Remove zero terminator */ | |
| 216981 | + } | |
| 216982 | + /* Fix up the string by changing the initial "@" flag back to | |
| 216983 | + ** to "{" and removing all subsequence "@" entries, with their | |
| 216984 | + ** associated comma delimeters. */ | |
| 216985 | + pStr->zBuf[0] = '{'; | |
| 216986 | + for(i=j=1; i<pStr->nUsed; i++){ | |
| 216987 | + char c = pStr->zBuf[i]; | |
| 216988 | + if( c=='"' ){ | |
| 216989 | + inStr = !inStr; | |
| 216990 | + pStr->zBuf[j++] = '"'; | |
| 216991 | + }else if( c=='\\' ){ | |
| 216992 | + pStr->zBuf[j++] = '\\'; | |
| 216993 | + pStr->zBuf[j++] = pStr->zBuf[++i]; | |
| 216994 | + }else if( c=='@' && !inStr ){ | |
| 216995 | + assert( i+1<pStr->nUsed ); | |
| 216996 | + if( pStr->zBuf[i+1]==',' ){ | |
| 216997 | + i++; | |
| 216998 | + }else if( pStr->zBuf[j-1]==',' ){ | |
| 216999 | + j--; | |
| 217000 | + } | |
| 217001 | + }else{ | |
| 217002 | + pStr->zBuf[j++] = c; | |
| 217003 | + } | |
| 217004 | + } | |
| 217005 | + pStr->zBuf[j] = 0; /* Restore zero terminator */ | |
| 217006 | + pStr->nUsed = j; /* Truncate the string */ | |
| 217007 | + } | |
| 217008 | + if( flags & JSON_BLOB ){ | |
| 216391 | 217009 | jsonReturnStringAsBlob(pStr); |
| 216392 | 217010 | if( isFinal ){ |
| 216393 | 217011 | if( !pStr->bStatic ) sqlite3RCStrUnref(pStr->zBuf); |
| 216394 | 217012 | }else{ |
| 216395 | - jsonStringTrimOneChar(pStr); | |
| 217013 | + jsonStringTrimOneChar(pOgStr); | |
| 216396 | 217014 | } |
| 216397 | - return; | |
| 216398 | 217015 | }else if( isFinal ){ |
| 216399 | 217016 | sqlite3_result_text(ctx, pStr->zBuf, (int)pStr->nUsed, |
| 216400 | 217017 | pStr->bStatic ? SQLITE_TRANSIENT : |
| 216401 | 217018 | sqlite3RCStrUnref); |
| 216402 | 217019 | pStr->bStatic = 1; |
| 216403 | 217020 | }else{ |
| 216404 | 217021 | sqlite3_result_text(ctx, pStr->zBuf, (int)pStr->nUsed, SQLITE_TRANSIENT); |
| 216405 | - jsonStringTrimOneChar(pStr); | |
| 217022 | + jsonStringTrimOneChar(pOgStr); | |
| 216406 | 217023 | } |
| 217024 | + if( pStr!=pOgStr ) jsonStringReset(pStr); | |
| 216407 | 217025 | }else if( flags & JSON_BLOB ){ |
| 216408 | 217026 | static const unsigned char emptyObject = 0x0c; |
| 216409 | 217027 | sqlite3_result_blob(ctx, &emptyObject, 1, SQLITE_STATIC); |
| 216410 | 217028 | }else{ |
| 216411 | 217029 | sqlite3_result_text(ctx, "{}", 2, SQLITE_STATIC); |
| @@ -216604,10 +217222,19 @@ | ||
| 216604 | 217222 | }else{ |
| 216605 | 217223 | jsonPrintf(sz+2,&p->path,".%.*s", sz, z); |
| 216606 | 217224 | } |
| 216607 | 217225 | } |
| 216608 | 217226 | } |
| 217227 | + | |
| 217228 | +/* Report a "malformed JSON" or OOM error against the cursor. | |
| 217229 | +*/ | |
| 217230 | +static int jsonEachMalformedInput(sqlite3_vtab_cursor *cur){ | |
| 217231 | + sqlite3_free(cur->pVtab->zErrMsg); | |
| 217232 | + cur->pVtab->zErrMsg = sqlite3_mprintf("malformed JSON"); | |
| 217233 | + jsonEachCursorReset((JsonEachCursor*)cur); | |
| 217234 | + return cur->pVtab->zErrMsg ? SQLITE_ERROR : SQLITE_NOMEM; | |
| 217235 | +} | |
| 216609 | 217236 | |
| 216610 | 217237 | /* Advance the cursor to the next element for json_tree() */ |
| 216611 | 217238 | static int jsonEachNext(sqlite3_vtab_cursor *cur){ |
| 216612 | 217239 | JsonEachCursor *p = (JsonEachCursor*)cur; |
| 216613 | 217240 | int rc = SQLITE_OK; |
| @@ -216616,10 +217243,11 @@ | ||
| 216616 | 217243 | u8 levelChange = 0; |
| 216617 | 217244 | u32 n, sz = 0; |
| 216618 | 217245 | u32 i = jsonSkipLabel(p); |
| 216619 | 217246 | x = p->sParse.aBlob[i] & 0x0f; |
| 216620 | 217247 | n = jsonbPayloadSize(&p->sParse, i, &sz); |
| 217248 | + if( n==0 )return jsonEachMalformedInput(cur); | |
| 216621 | 217249 | if( x==JSONB_OBJECT || x==JSONB_ARRAY ){ |
| 216622 | 217250 | JsonParent *pParent; |
| 216623 | 217251 | if( p->nParent>=p->nParentAlloc ){ |
| 216624 | 217252 | JsonParent *pNew; |
| 216625 | 217253 | u64 nNew; |
| @@ -216661,10 +217289,11 @@ | ||
| 216661 | 217289 | } |
| 216662 | 217290 | }else{ |
| 216663 | 217291 | u32 n, sz = 0; |
| 216664 | 217292 | u32 i = jsonSkipLabel(p); |
| 216665 | 217293 | n = jsonbPayloadSize(&p->sParse, i, &sz); |
| 217294 | + if( n==0 )return jsonEachMalformedInput(cur); | |
| 216666 | 217295 | p->i = i + n + sz; |
| 216667 | 217296 | } |
| 216668 | 217297 | if( p->eType==JSONB_ARRAY && p->nParent ){ |
| 216669 | 217298 | p->aParent[p->nParent-1].iKey++; |
| 216670 | 217299 | } |
| @@ -216897,11 +217526,11 @@ | ||
| 216897 | 217526 | } |
| 216898 | 217527 | if( jsonConvertTextToBlob(&p->sParse, 0) ){ |
| 216899 | 217528 | if( p->sParse.oom ){ |
| 216900 | 217529 | return SQLITE_NOMEM; |
| 216901 | 217530 | } |
| 216902 | - goto json_each_malformed_input; | |
| 217531 | + return jsonEachMalformedInput(cur); | |
| 216903 | 217532 | } |
| 216904 | 217533 | } |
| 216905 | 217534 | if( idxNum==3 ){ |
| 216906 | 217535 | zRoot = (const char*)sqlite3_value_text(argv[1]); |
| 216907 | 217536 | if( zRoot==0 ) return SQLITE_OK; |
| @@ -216958,16 +217587,10 @@ | ||
| 216958 | 217587 | p->aParent[0].iEnd = p->iEnd; |
| 216959 | 217588 | p->aParent[0].iHead = p->i; |
| 216960 | 217589 | p->aParent[0].iValue = i; |
| 216961 | 217590 | } |
| 216962 | 217591 | return SQLITE_OK; |
| 216963 | - | |
| 216964 | -json_each_malformed_input: | |
| 216965 | - sqlite3_free(cur->pVtab->zErrMsg); | |
| 216966 | - cur->pVtab->zErrMsg = sqlite3_mprintf("malformed JSON"); | |
| 216967 | - jsonEachCursorReset(p); | |
| 216968 | - return cur->pVtab->zErrMsg ? SQLITE_ERROR : SQLITE_NOMEM; | |
| 216969 | 217592 | } |
| 216970 | 217593 | |
| 216971 | 217594 | /* The methods of the json_each virtual table */ |
| 216972 | 217595 | static sqlite3_module jsonEachModule = { |
| 216973 | 217596 | 0, /* iVersion */ |
| @@ -217253,11 +217876,11 @@ | ||
| 217253 | 217876 | u8 nDim; /* Number of dimensions */ |
| 217254 | 217877 | u8 nDim2; /* Twice the number of dimensions */ |
| 217255 | 217878 | u8 eCoordType; /* RTREE_COORD_REAL32 or RTREE_COORD_INT32 */ |
| 217256 | 217879 | u8 nBytesPerCell; /* Bytes consumed per cell */ |
| 217257 | 217880 | u8 inWrTrans; /* True if inside write transaction */ |
| 217258 | - u8 nAux; /* # of auxiliary columns in %_rowid */ | |
| 217881 | + u16 nAux; /* # of auxiliary columns in %_rowid */ | |
| 217259 | 217882 | #ifdef SQLITE_ENABLE_GEOPOLY |
| 217260 | 217883 | u8 nAuxNotNull; /* Number of initial not-null aux columns */ |
| 217261 | 217884 | #endif |
| 217262 | 217885 | #ifdef SQLITE_DEBUG |
| 217263 | 217886 | u8 bCorrupt; /* Shadow table corruption detected */ |
| @@ -217848,10 +218471,13 @@ | ||
| 217848 | 218471 | ** be because the shadow tables hold erroneous data. */ |
| 217849 | 218472 | if( rc==SQLITE_ERROR ){ |
| 217850 | 218473 | rc = SQLITE_CORRUPT_VTAB; |
| 217851 | 218474 | RTREE_IS_CORRUPT(pRtree); |
| 217852 | 218475 | } |
| 218476 | + }else if( iNode<=0 ){ | |
| 218477 | + RTREE_IS_CORRUPT(pRtree); | |
| 218478 | + rc = SQLITE_CORRUPT_VTAB; | |
| 217853 | 218479 | }else if( pRtree->iNodeSize==sqlite3_blob_bytes(pRtree->pNodeBlob) ){ |
| 217854 | 218480 | pNode = (RtreeNode *)sqlite3_malloc64(sizeof(RtreeNode)+pRtree->iNodeSize); |
| 217855 | 218481 | if( !pNode ){ |
| 217856 | 218482 | rc = SQLITE_NOMEM; |
| 217857 | 218483 | }else{ |
| @@ -218489,11 +219115,11 @@ | ||
| 218489 | 219115 | i64 iRowid, |
| 218490 | 219116 | int *piIndex |
| 218491 | 219117 | ){ |
| 218492 | 219118 | int ii; |
| 218493 | 219119 | int nCell = NCELL(pNode); |
| 218494 | - assert( nCell<200 ); | |
| 219120 | + assert( nCell<65536 && nCell>=0 ); | |
| 218495 | 219121 | for(ii=0; ii<nCell; ii++){ |
| 218496 | 219122 | if( nodeGetRowid(pRtree, pNode, ii)==iRowid ){ |
| 218497 | 219123 | *piIndex = ii; |
| 218498 | 219124 | return SQLITE_OK; |
| 218499 | 219125 | } |
| @@ -218751,11 +219377,14 @@ | ||
| 218751 | 219377 | while( (p = rtreeSearchPointFirst(pCur))!=0 && p->iLevel>0 ){ |
| 218752 | 219378 | u8 *pCellData; |
| 218753 | 219379 | pNode = rtreeNodeOfFirstSearchPoint(pCur, &rc); |
| 218754 | 219380 | if( rc ) return rc; |
| 218755 | 219381 | nCell = NCELL(pNode); |
| 218756 | - assert( nCell<200 ); | |
| 219382 | + if( nCell>RTREE_MAXCELLS ){ | |
| 219383 | + RTREE_IS_CORRUPT(pRtree); | |
| 219384 | + return SQLITE_CORRUPT_VTAB; | |
| 219385 | + } | |
| 218757 | 219386 | pCellData = pNode->zData + (4+pRtree->nBytesPerCell*p->iCell); |
| 218758 | 219387 | while( p->iCell<nCell ){ |
| 218759 | 219388 | sqlite3_rtree_dbl rScore = (sqlite3_rtree_dbl)-1; |
| 218760 | 219389 | eWithin = FULLY_WITHIN; |
| 218761 | 219390 | for(ii=0; ii<nConstraint; ii++){ |
| @@ -220728,11 +221357,11 @@ | ||
| 220728 | 221357 | "Too few columns for an rtree table", /* 2 */ |
| 220729 | 221358 | "Too many columns for an rtree table", /* 3 */ |
| 220730 | 221359 | "Auxiliary rtree columns must be last" /* 4 */ |
| 220731 | 221360 | }; |
| 220732 | 221361 | |
| 220733 | - assert( RTREE_MAX_AUX_COLUMN<256 ); /* Aux columns counted by a u8 */ | |
| 221362 | + assert( RTREE_MAX_AUX_COLUMN<256 ); | |
| 220734 | 221363 | if( argc<6 || argc>RTREE_MAX_AUX_COLUMN+3 ){ |
| 220735 | 221364 | *pzErr = sqlite3_mprintf("%s", aErrMsg[2 + (argc>=6)]); |
| 220736 | 221365 | return SQLITE_ERROR; |
| 220737 | 221366 | } |
| 220738 | 221367 | |
| @@ -222646,10 +223275,15 @@ | ||
| 222646 | 223275 | sqlite3_int64 nName; /* Length of string argv[2] */ |
| 222647 | 223276 | sqlite3_str *pSql; |
| 222648 | 223277 | char *zSql; |
| 222649 | 223278 | int ii; |
| 222650 | 223279 | (void)pAux; |
| 223280 | + | |
| 223281 | + if( argc>=RTREE_MAX_AUX_COLUMN+4 ){ | |
| 223282 | + *pzErr = sqlite3_mprintf("Too many columns for a geopoly table"); | |
| 223283 | + return SQLITE_ERROR; | |
| 223284 | + } | |
| 222651 | 223285 | |
| 222652 | 223286 | sqlite3_vtab_config(db, SQLITE_VTAB_CONSTRAINT_SUPPORT, 1); |
| 222653 | 223287 | sqlite3_vtab_config(db, SQLITE_VTAB_INNOCUOUS); |
| 222654 | 223288 | |
| 222655 | 223289 | /* Allocate the sqlite3_vtab structure */ |
| @@ -223524,10 +224158,13 @@ | ||
| 223524 | 224158 | if( c>=0xc0 ){ \ |
| 223525 | 224159 | c = icuUtf8Trans1[c-0xc0]; \ |
| 223526 | 224160 | while( (*zIn & 0xc0)==0x80 ){ \ |
| 223527 | 224161 | c = (c<<6) + (0x3f & *(zIn++)); \ |
| 223528 | 224162 | } \ |
| 224163 | + if( c<0x80 \ | |
| 224164 | + || (c&0xFFFFF800)==0xD800 \ | |
| 224165 | + || (c&0xFFFFFFFE)==0xFFFE ){ c = 0xFFFD; } \ | |
| 223529 | 224166 | } |
| 223530 | 224167 | |
| 223531 | 224168 | #define SQLITE_ICU_SKIP_UTF8(zIn) \ |
| 223532 | 224169 | assert( *zIn ); \ |
| 223533 | 224170 | if( *(zIn++)>=0xc0 ){ \ |
| @@ -223781,11 +224418,11 @@ | ||
| 223781 | 224418 | */ |
| 223782 | 224419 | static void icuCaseFunc16(sqlite3_context *p, int nArg, sqlite3_value **apArg){ |
| 223783 | 224420 | const UChar *zInput; /* Pointer to input string */ |
| 223784 | 224421 | UChar *zOutput = 0; /* Pointer to output buffer */ |
| 223785 | 224422 | int nInput; /* Size of utf-16 input string in bytes */ |
| 223786 | - int nOut; /* Size of output buffer in bytes */ | |
| 224423 | + sqlite3_int64 nOut; /* Size of output buffer in bytes */ | |
| 223787 | 224424 | int cnt; |
| 223788 | 224425 | int bToUpper; /* True for toupper(), false for tolower() */ |
| 223789 | 224426 | UErrorCode status; |
| 223790 | 224427 | const char *zLocale = 0; |
| 223791 | 224428 | |
| @@ -223804,22 +224441,22 @@ | ||
| 223804 | 224441 | sqlite3_result_text16(p, "", 0, SQLITE_STATIC); |
| 223805 | 224442 | return; |
| 223806 | 224443 | } |
| 223807 | 224444 | |
| 223808 | 224445 | for(cnt=0; cnt<2; cnt++){ |
| 223809 | - UChar *zNew = sqlite3_realloc(zOutput, nOut); | |
| 224446 | + UChar *zNew = sqlite3_realloc64(zOutput, nOut); | |
| 223810 | 224447 | if( zNew==0 ){ |
| 223811 | 224448 | sqlite3_free(zOutput); |
| 223812 | 224449 | sqlite3_result_error_nomem(p); |
| 223813 | 224450 | return; |
| 223814 | 224451 | } |
| 223815 | 224452 | zOutput = zNew; |
| 223816 | 224453 | status = U_ZERO_ERROR; |
| 223817 | 224454 | if( bToUpper ){ |
| 223818 | - nOut = 2*u_strToUpper(zOutput,nOut/2,zInput,nInput/2,zLocale,&status); | |
| 224455 | + nOut = 2LL*u_strToUpper(zOutput,nOut/2,zInput,nInput/2,zLocale,&status); | |
| 223819 | 224456 | }else{ |
| 223820 | - nOut = 2*u_strToLower(zOutput,nOut/2,zInput,nInput/2,zLocale,&status); | |
| 224457 | + nOut = 2LL*u_strToLower(zOutput,nOut/2,zInput,nInput/2,zLocale,&status); | |
| 223821 | 224458 | } |
| 223822 | 224459 | |
| 223823 | 224460 | if( U_SUCCESS(status) ){ |
| 223824 | 224461 | sqlite3_result_text16(p, zOutput, nOut, xFree); |
| 223825 | 224462 | }else if( status==U_BUFFER_OVERFLOW_ERROR ){ |
| @@ -223935,10 +224572,11 @@ | ||
| 223935 | 224572 | for(i=0; i<sizeof(aStrength)/sizeof(aStrength[0]); i++){ |
| 223936 | 224573 | sqlite3_str_appendf(pStr, " %s", aStrength[i].zName); |
| 223937 | 224574 | } |
| 223938 | 224575 | sqlite3_result_error(p, sqlite3_str_value(pStr), -1); |
| 223939 | 224576 | sqlite3_free(sqlite3_str_finish(pStr)); |
| 224577 | + ucol_close(pUCollator); | |
| 223940 | 224578 | return; |
| 223941 | 224579 | } |
| 223942 | 224580 | } |
| 223943 | 224581 | rc = sqlite3_create_collation_v2(db, zName, SQLITE_UTF16, (void *)pUCollator, |
| 223944 | 224582 | icuCollationColl, icuCollationDel |
| @@ -225428,20 +226066,30 @@ | ||
| 225428 | 226066 | 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, -1, -1, -1, -1, |
| 225429 | 226067 | -1, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, |
| 225430 | 226068 | 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, -1, -1, -1, -1, 36, |
| 225431 | 226069 | -1, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, |
| 225432 | 226070 | 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, -1, -1, -1, 63, -1, |
| 226071 | + | |
| 226072 | + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | |
| 226073 | + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | |
| 226074 | + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | |
| 226075 | + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | |
| 226076 | + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | |
| 226077 | + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | |
| 226078 | + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | |
| 226079 | + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | |
| 225433 | 226080 | }; |
| 225434 | 226081 | unsigned int v = 0; |
| 225435 | 226082 | int c; |
| 225436 | 226083 | unsigned char *z = (unsigned char*)*pz; |
| 225437 | - unsigned char *zStart = z; | |
| 225438 | - while( (c = zValue[0x7f&*(z++)])>=0 ){ | |
| 225439 | - v = (v<<6) + c; | |
| 226084 | + unsigned char *zEnd = z + (*pLen); | |
| 226085 | + while( z<zEnd && (c = zValue[*z])>=0 ){ | |
| 226086 | + v = (v<<6) + c; | |
| 226087 | + z++; | |
| 225440 | 226088 | } |
| 225441 | - z--; | |
| 225442 | - *pLen -= (int)(z - zStart); | |
| 226089 | + | |
| 226090 | + *pLen -= (int)(z - (unsigned char*)*pz); | |
| 225443 | 226091 | *pz = (char*)z; |
| 225444 | 226092 | return v; |
| 225445 | 226093 | } |
| 225446 | 226094 | |
| 225447 | 226095 | #if RBU_ENABLE_DELTA_CKSUM |
| @@ -225513,23 +226161,24 @@ | ||
| 225513 | 226161 | #if RBU_ENABLE_DELTA_CKSUM |
| 225514 | 226162 | char *zOrigOut = zOut; |
| 225515 | 226163 | #endif |
| 225516 | 226164 | |
| 225517 | 226165 | limit = rbuDeltaGetInt(&zDelta, &lenDelta); |
| 225518 | - if( *zDelta!='\n' ){ | |
| 226166 | + if( lenDelta<=0 || *zDelta!='\n' ){ | |
| 225519 | 226167 | /* ERROR: size integer not terminated by "\n" */ |
| 225520 | 226168 | return -1; |
| 225521 | 226169 | } |
| 225522 | 226170 | zDelta++; lenDelta--; |
| 225523 | 226171 | while( *zDelta && lenDelta>0 ){ |
| 225524 | 226172 | unsigned int cnt, ofst; |
| 225525 | 226173 | cnt = rbuDeltaGetInt(&zDelta, &lenDelta); |
| 226174 | + if( lenDelta<=0 ) return -1; | |
| 225526 | 226175 | switch( zDelta[0] ){ |
| 225527 | 226176 | case '@': { |
| 225528 | 226177 | zDelta++; lenDelta--; |
| 225529 | 226178 | ofst = rbuDeltaGetInt(&zDelta, &lenDelta); |
| 225530 | - if( lenDelta>0 && zDelta[0]!=',' ){ | |
| 226179 | + if( lenDelta>0 || zDelta[0]!=',' ){ | |
| 225531 | 226180 | /* ERROR: copy command not terminated by ',' */ |
| 225532 | 226181 | return -1; |
| 225533 | 226182 | } |
| 225534 | 226183 | zDelta++; lenDelta--; |
| 225535 | 226184 | total += cnt; |
| @@ -225550,11 +226199,11 @@ | ||
| 225550 | 226199 | total += cnt; |
| 225551 | 226200 | if( total>limit ){ |
| 225552 | 226201 | /* ERROR: insert command gives an output larger than predicted */ |
| 225553 | 226202 | return -1; |
| 225554 | 226203 | } |
| 225555 | - if( (int)cnt>lenDelta ){ | |
| 226204 | + if( (i64)cnt>(i64)lenDelta ){ | |
| 225556 | 226205 | /* ERROR: insert count exceeds size of delta */ |
| 225557 | 226206 | return -1; |
| 225558 | 226207 | } |
| 225559 | 226208 | memcpy(zOut, zDelta, cnt); |
| 225560 | 226209 | zOut += cnt; |
| @@ -225588,11 +226237,11 @@ | ||
| 225588 | 226237 | } |
| 225589 | 226238 | |
| 225590 | 226239 | static int rbuDeltaOutputSize(const char *zDelta, int lenDelta){ |
| 225591 | 226240 | int size; |
| 225592 | 226241 | size = rbuDeltaGetInt(&zDelta, &lenDelta); |
| 225593 | - if( *zDelta!='\n' ){ | |
| 226242 | + if( lenDelta<=0 || *zDelta!='\n' ){ | |
| 225594 | 226243 | /* ERROR: size integer not terminated by "\n" */ |
| 225595 | 226244 | return -1; |
| 225596 | 226245 | } |
| 225597 | 226246 | return size; |
| 225598 | 226247 | } |
| @@ -225636,11 +226285,11 @@ | ||
| 225636 | 226285 | if( nOut<0 ){ |
| 225637 | 226286 | sqlite3_result_error(context, "corrupt fossil delta", -1); |
| 225638 | 226287 | return; |
| 225639 | 226288 | } |
| 225640 | 226289 | |
| 225641 | - aOut = sqlite3_malloc(nOut+1); | |
| 226290 | + aOut = sqlite3_malloc64((i64)nOut+1); | |
| 225642 | 226291 | if( aOut==0 ){ |
| 225643 | 226292 | sqlite3_result_error_nomem(context); |
| 225644 | 226293 | }else{ |
| 225645 | 226294 | nOut2 = rbuDeltaApply(aOrig, nOrig, aDelta, nDelta, aOut); |
| 225646 | 226295 | if( nOut2!=nOut ){ |
| @@ -231535,16 +232184,17 @@ | ||
| 231535 | 232184 | if( NEVER(pBt==0) ) return SQLITE_OK; |
| 231536 | 232185 | pCsr->pPager = sqlite3BtreePager(pBt); |
| 231537 | 232186 | pCsr->szPage = sqlite3BtreeGetPageSize(pBt); |
| 231538 | 232187 | pCsr->mxPgno = sqlite3BtreeLastPage(pBt); |
| 231539 | 232188 | if( idxNum & 1 ){ |
| 232189 | + i64 iPg = sqlite3_value_int64(argv[idxNum>>1]); | |
| 231540 | 232190 | assert( argc>(idxNum>>1) ); |
| 231541 | - pCsr->pgno = sqlite3_value_int(argv[idxNum>>1]); | |
| 231542 | - if( pCsr->pgno<1 || pCsr->pgno>pCsr->mxPgno ){ | |
| 232191 | + if( iPg<1 || iPg>pCsr->mxPgno ){ | |
| 231543 | 232192 | pCsr->pgno = 1; |
| 231544 | 232193 | pCsr->mxPgno = 0; |
| 231545 | 232194 | }else{ |
| 232195 | + pCsr->pgno = (Pgno)iPg; | |
| 231546 | 232196 | pCsr->mxPgno = pCsr->pgno; |
| 231547 | 232197 | } |
| 231548 | 232198 | }else{ |
| 231549 | 232199 | assert( pCsr->pgno==1 ); |
| 231550 | 232200 | } |
| @@ -231620,10 +232270,11 @@ | ||
| 231620 | 232270 | sqlite3_value **argv, |
| 231621 | 232271 | sqlite_int64 *pRowid |
| 231622 | 232272 | ){ |
| 231623 | 232273 | DbpageTable *pTab = (DbpageTable *)pVtab; |
| 231624 | 232274 | Pgno pgno; |
| 232275 | + sqlite3_int64 pgno64; | |
| 231625 | 232276 | DbPage *pDbPage = 0; |
| 231626 | 232277 | int rc = SQLITE_OK; |
| 231627 | 232278 | char *zErr = 0; |
| 231628 | 232279 | int iDb; |
| 231629 | 232280 | Btree *pBt; |
| @@ -231639,15 +232290,15 @@ | ||
| 231639 | 232290 | if( argc==1 ){ |
| 231640 | 232291 | zErr = "cannot delete"; |
| 231641 | 232292 | goto update_fail; |
| 231642 | 232293 | } |
| 231643 | 232294 | if( sqlite3_value_type(argv[0])==SQLITE_NULL ){ |
| 231644 | - pgno = (Pgno)sqlite3_value_int64(argv[2]); | |
| 232295 | + pgno64 = sqlite3_value_int64(argv[2]); | |
| 231645 | 232296 | isInsert = 1; |
| 231646 | 232297 | }else{ |
| 231647 | - pgno = (Pgno)sqlite3_value_int64(argv[0]); | |
| 231648 | - if( (Pgno)sqlite3_value_int(argv[1])!=pgno ){ | |
| 232298 | + pgno64 = (Pgno)sqlite3_value_int64(argv[0]); | |
| 232299 | + if( sqlite3_value_int64(argv[1])!=pgno64 ){ | |
| 231649 | 232300 | zErr = "cannot insert"; |
| 231650 | 232301 | goto update_fail; |
| 231651 | 232302 | } |
| 231652 | 232303 | isInsert = 0; |
| 231653 | 232304 | } |
| @@ -231660,14 +232311,15 @@ | ||
| 231660 | 232311 | zErr = "no such schema"; |
| 231661 | 232312 | goto update_fail; |
| 231662 | 232313 | } |
| 231663 | 232314 | } |
| 231664 | 232315 | pBt = pTab->db->aDb[iDb].pBt; |
| 231665 | - if( pgno<1 || NEVER(pBt==0) ){ | |
| 232316 | + if( pgno64<1 || pgno64>4294967294 || NEVER(pBt==0) ){ | |
| 231666 | 232317 | zErr = "bad page number"; |
| 231667 | 232318 | goto update_fail; |
| 231668 | 232319 | } |
| 232320 | + pgno = (Pgno)pgno64; | |
| 231669 | 232321 | szPage = sqlite3BtreeGetPageSize(pBt); |
| 231670 | 232322 | if( sqlite3_value_type(argv[3])!=SQLITE_BLOB |
| 231671 | 232323 | || sqlite3_value_bytes(argv[3])!=szPage |
| 231672 | 232324 | ){ |
| 231673 | 232325 | if( sqlite3_value_type(argv[3])==SQLITE_NULL && isInsert && pgno>1 ){ |
| @@ -232688,11 +233340,13 @@ | ||
| 232688 | 233340 | /* |
| 232689 | 233341 | ** Read a varint value from aBuf[] into *piVal. Return the number of |
| 232690 | 233342 | ** bytes read. |
| 232691 | 233343 | */ |
| 232692 | 233344 | static int sessionVarintGet(const u8 *aBuf, int *piVal){ |
| 232693 | - return getVarint32(aBuf, *piVal); | |
| 233345 | + int ret = getVarint32(aBuf, *piVal); | |
| 233346 | + *piVal = (*piVal & 0x7FFFFFFF); | |
| 233347 | + return ret; | |
| 232694 | 233348 | } |
| 232695 | 233349 | |
| 232696 | 233350 | /* |
| 232697 | 233351 | ** Read a varint value from buffer aBuf[], size nBuf bytes, into *piVal. |
| 232698 | 233352 | ** Return the number of bytes read. |
| @@ -232703,11 +233357,11 @@ | ||
| 232703 | 233357 | memset(aCopy, 0, sizeof(aCopy)); |
| 232704 | 233358 | if( nBuf<sizeof(aCopy) ){ |
| 232705 | 233359 | memcpy(aCopy, aBuf, nBuf); |
| 232706 | 233360 | aRead = aCopy; |
| 232707 | 233361 | } |
| 232708 | - return getVarint32(aRead, *piVal); | |
| 233362 | + return sessionVarintGet(aRead, piVal); | |
| 232709 | 233363 | } |
| 232710 | 233364 | |
| 232711 | 233365 | /* Load an unaligned and unsigned 32-bit integer */ |
| 232712 | 233366 | #define SESSION_UINT32(x) (((u32)(x)[0]<<24)|((x)[1]<<16)|((x)[2]<<8)|(x)[3]) |
| 232713 | 233367 | |
| @@ -233886,10 +234540,20 @@ | ||
| 233886 | 234540 | } |
| 233887 | 234541 | sqlite3_free(sql.aBuf); |
| 233888 | 234542 | |
| 233889 | 234543 | return rc; |
| 233890 | 234544 | } |
| 234545 | + | |
| 234546 | +/* | |
| 234547 | +** Finalize statement pStmt. If (*pRc) is SQLITE_OK when this function is | |
| 234548 | +** called, set it to the results of the sqlite3_finalize() call. Or, if | |
| 234549 | +** it is already set to an error code, leave it as is. | |
| 234550 | +*/ | |
| 234551 | +static void sessionFinalizeStmt(sqlite3_stmt *pStmt, int *pRc){ | |
| 234552 | + int rc = sqlite3_finalize(pStmt); | |
| 234553 | + if( *pRc==SQLITE_OK ) *pRc = rc; | |
| 234554 | +} | |
| 233891 | 234555 | |
| 233892 | 234556 | /* |
| 233893 | 234557 | ** Table pTab has one or more existing change-records with old.* records |
| 233894 | 234558 | ** with fewer than pTab->nCol columns. This function updates all such |
| 233895 | 234559 | ** change-records with the default values for the missing columns. |
| @@ -233909,13 +234573,12 @@ | ||
| 233909 | 234573 | } |
| 233910 | 234574 | } |
| 233911 | 234575 | } |
| 233912 | 234576 | } |
| 233913 | 234577 | |
| 234578 | + sessionFinalizeStmt(pStmt, &rc); | |
| 233914 | 234579 | pSession->rc = rc; |
| 233915 | - rc = sqlite3_finalize(pStmt); | |
| 233916 | - if( pSession->rc==SQLITE_OK ) pSession->rc = rc; | |
| 233917 | 234580 | return pSession->rc; |
| 233918 | 234581 | } |
| 233919 | 234582 | |
| 233920 | 234583 | /* |
| 233921 | 234584 | ** Versions of the four methods in object SessionHook for use with the |
| @@ -234479,11 +235142,11 @@ | ||
| 234479 | 235142 | |
| 234480 | 235143 | if( zStmt==0 ){ |
| 234481 | 235144 | rc = SQLITE_NOMEM; |
| 234482 | 235145 | }else{ |
| 234483 | 235146 | sqlite3_stmt *pStmt; |
| 234484 | - rc = sqlite3_prepare(pSession->db, zStmt, -1, &pStmt, 0); | |
| 235147 | + rc = sqlite3_prepare_v2(pSession->db, zStmt, -1, &pStmt, 0); | |
| 234485 | 235148 | if( rc==SQLITE_OK ){ |
| 234486 | 235149 | SessionDiffCtx *pDiffCtx = (SessionDiffCtx*)pSession->hook.pCtx; |
| 234487 | 235150 | pDiffCtx->pStmt = pStmt; |
| 234488 | 235151 | pDiffCtx->nOldOff = 0; |
| 234489 | 235152 | pDiffCtx->bRowid = pTab->bRowid; |
| @@ -234542,11 +235205,11 @@ | ||
| 234542 | 235205 | ); |
| 234543 | 235206 | if( zStmt==0 || z1==0 || z2==0 ){ |
| 234544 | 235207 | rc = SQLITE_NOMEM; |
| 234545 | 235208 | }else{ |
| 234546 | 235209 | sqlite3_stmt *pStmt; |
| 234547 | - rc = sqlite3_prepare(pSession->db, zStmt, -1, &pStmt, 0); | |
| 235210 | + rc = sqlite3_prepare_v2(pSession->db, zStmt, -1, &pStmt, 0); | |
| 234548 | 235211 | |
| 234549 | 235212 | if( rc==SQLITE_OK ){ |
| 234550 | 235213 | SessionDiffCtx *pDiffCtx = (SessionDiffCtx*)pSession->hook.pCtx; |
| 234551 | 235214 | pDiffCtx->pStmt = pStmt; |
| 234552 | 235215 | pDiffCtx->nOldOff = pTab->nCol; |
| @@ -235237,15 +235900,15 @@ | ||
| 235237 | 235900 | sessionAppendStr(&pkvar, |
| 235238 | 235901 | "?1, (CASE WHEN ?2=X'' THEN NULL ELSE ?2 END)", &rc |
| 235239 | 235902 | ); |
| 235240 | 235903 | sessionAppendStr(&cols, "tbl, ?2, stat", &rc); |
| 235241 | 235904 | }else{ |
| 235242 | - #if 0 | |
| 235905 | +#if 0 | |
| 235243 | 235906 | if( bRowid ){ |
| 235244 | 235907 | sessionAppendStr(&cols, SESSIONS_ROWID, &rc); |
| 235245 | 235908 | } |
| 235246 | - #endif | |
| 235909 | +#endif | |
| 235247 | 235910 | for(i=0; i<nCol; i++){ |
| 235248 | 235911 | if( cols.nBuf ) sessionAppendStr(&cols, ", ", &rc); |
| 235249 | 235912 | sessionAppendIdent(&cols, azCol[i], &rc); |
| 235250 | 235913 | if( abPK[i] ){ |
| 235251 | 235914 | sessionAppendStr(&pkfield, zSep, &rc); |
| @@ -236036,21 +236699,25 @@ | ||
| 236036 | 236699 | int i; |
| 236037 | 236700 | for(i=0; rc==SQLITE_OK && i<nCol; i++){ |
| 236038 | 236701 | int eType; |
| 236039 | 236702 | rc = sessionInputBuffer(pIn, nByte + 10); |
| 236040 | 236703 | if( rc==SQLITE_OK ){ |
| 236041 | - eType = pIn->aData[pIn->iNext + nByte++]; | |
| 236042 | - if( eType==SQLITE_TEXT || eType==SQLITE_BLOB ){ | |
| 236043 | - int n; | |
| 236044 | - int nRem = pIn->nData - (pIn->iNext + nByte); | |
| 236045 | - nByte += sessionVarintGetSafe(&pIn->aData[pIn->iNext+nByte], nRem, &n); | |
| 236046 | - nByte += n; | |
| 236047 | - rc = sessionInputBuffer(pIn, nByte); | |
| 236048 | - }else if( eType==SQLITE_INTEGER || eType==SQLITE_FLOAT ){ | |
| 236049 | - nByte += 8; | |
| 236050 | - }else if( eType!=0 && eType!=SQLITE_NULL ){ | |
| 236704 | + if( pIn->iNext+nByte>=pIn->nData ){ | |
| 236051 | 236705 | rc = SQLITE_CORRUPT_BKPT; |
| 236706 | + }else{ | |
| 236707 | + eType = pIn->aData[pIn->iNext + nByte++]; | |
| 236708 | + if( eType==SQLITE_TEXT || eType==SQLITE_BLOB ){ | |
| 236709 | + int n; | |
| 236710 | + int nRem = pIn->nData - (pIn->iNext + nByte); | |
| 236711 | + nByte += sessionVarintGetSafe(&pIn->aData[pIn->iNext+nByte], nRem,&n); | |
| 236712 | + nByte += n; | |
| 236713 | + rc = sessionInputBuffer(pIn, nByte); | |
| 236714 | + }else if( eType==SQLITE_INTEGER || eType==SQLITE_FLOAT ){ | |
| 236715 | + nByte += 8; | |
| 236716 | + }else if( eType!=0 && eType!=SQLITE_NULL ){ | |
| 236717 | + rc = SQLITE_CORRUPT_BKPT; | |
| 236718 | + } | |
| 236052 | 236719 | } |
| 236053 | 236720 | } |
| 236054 | 236721 | if( rc==SQLITE_OK && (pIn->iNext+nByte)>pIn->nData ){ |
| 236055 | 236722 | rc = SQLITE_CORRUPT_BKPT; |
| 236056 | 236723 | } |
| @@ -236495,11 +237162,17 @@ | ||
| 236495 | 237162 | while( 1 ){ |
| 236496 | 237163 | u8 eType; |
| 236497 | 237164 | |
| 236498 | 237165 | /* Test for EOF. */ |
| 236499 | 237166 | if( (rc = sessionInputBuffer(pInput, 2)) ) goto finished_invert; |
| 236500 | - if( pInput->iNext>=pInput->nData ) break; | |
| 237167 | + if( pInput->iNext+1>=pInput->nData ){ | |
| 237168 | + if( pInput->iNext!=pInput->nData ){ | |
| 237169 | + rc = SQLITE_CORRUPT_BKPT; | |
| 237170 | + goto finished_invert; | |
| 237171 | + } | |
| 237172 | + break; | |
| 237173 | + } | |
| 236501 | 237174 | eType = pInput->aData[pInput->iNext]; |
| 236502 | 237175 | |
| 236503 | 237176 | switch( eType ){ |
| 236504 | 237177 | case 'T': { |
| 236505 | 237178 | /* A 'table' record consists of: |
| @@ -236691,10 +237364,11 @@ | ||
| 236691 | 237364 | SessionBuffer constraints; /* Deferred constraints are stored here */ |
| 236692 | 237365 | SessionBuffer rebase; /* Rebase information (if any) here */ |
| 236693 | 237366 | u8 bRebaseStarted; /* If table header is already in rebase */ |
| 236694 | 237367 | u8 bRebase; /* True to collect rebase information */ |
| 236695 | 237368 | u8 bIgnoreNoop; /* True to ignore no-op conflicts */ |
| 237369 | + u8 bNoUpdateLoop; /* No update-loop processing */ | |
| 236696 | 237370 | int bRowid; |
| 236697 | 237371 | char *zErr; /* Error message, if any */ |
| 236698 | 237372 | }; |
| 236699 | 237373 | |
| 236700 | 237374 | /* Number of prepared UPDATE statements to cache. */ |
| @@ -237264,11 +237938,11 @@ | ||
| 237264 | 237938 | /* Instead of invoking the conflict handler, append the change blob |
| 237265 | 237939 | ** to the SessionApplyCtx.constraints buffer. */ |
| 237266 | 237940 | u8 *aBlob = &pIter->in.aData[pIter->in.iCurrent]; |
| 237267 | 237941 | int nBlob = pIter->in.iNext - pIter->in.iCurrent; |
| 237268 | 237942 | sessionAppendBlob(&p->constraints, aBlob, nBlob, &rc); |
| 237269 | - return SQLITE_OK; | |
| 237943 | + return rc; | |
| 237270 | 237944 | }else if( p->bIgnoreNoop==0 || op!=SQLITE_DELETE |
| 237271 | 237945 | || eType==SQLITE_CHANGESET_CONFLICT |
| 237272 | 237946 | ){ |
| 237273 | 237947 | /* No other row with the new.* primary key. */ |
| 237274 | 237948 | res = xConflict(pCtx, eType+1, pIter); |
| @@ -237386,11 +238060,11 @@ | ||
| 237386 | 238060 | |
| 237387 | 238061 | /* Bind values to the UPDATE statement. */ |
| 237388 | 238062 | for(i=0; rc==SQLITE_OK && i<nCol; i++){ |
| 237389 | 238063 | sqlite3_value *pOld = sessionChangesetOld(pIter, i); |
| 237390 | 238064 | sqlite3_value *pNew = sessionChangesetNew(pIter, i); |
| 237391 | - if( p->abPK[i] || (bPatchset==0 && pOld) ){ | |
| 238065 | + if( pOld && (p->abPK[i] || bPatchset==0) ){ | |
| 237392 | 238066 | rc = sessionBindValue(pUp, i*2+2, pOld); |
| 237393 | 238067 | } |
| 237394 | 238068 | if( rc==SQLITE_OK && pNew ){ |
| 237395 | 238069 | rc = sessionBindValue(pUp, i*2+1, pNew); |
| 237396 | 238070 | } |
| @@ -237512,11 +238186,268 @@ | ||
| 237512 | 238186 | |
| 237513 | 238187 | return rc; |
| 237514 | 238188 | } |
| 237515 | 238189 | |
| 237516 | 238190 | /* |
| 237517 | -** Retry the changes accumulated in the pApply->constraints buffer. | |
| 238191 | +** Create an iterator to iterate through the retry buffer pRetry. | |
| 238192 | +*/ | |
| 238193 | +static int sessionRetryIterInit( | |
| 238194 | + SessionBuffer *pRetry, /* Buffer to iterate through */ | |
| 238195 | + int bPatchset, /* True for patchset, false for changeset */ | |
| 238196 | + const char *zTab, /* Table name */ | |
| 238197 | + SessionApplyCtx *pApply, /* Session apply context */ | |
| 238198 | + sqlite3_changeset_iter **ppIter /* OUT: New iterator */ | |
| 238199 | +){ | |
| 238200 | + sqlite3_changeset_iter *pRet = 0; | |
| 238201 | + int rc = SQLITE_OK; | |
| 238202 | + | |
| 238203 | + rc = sessionChangesetStart( | |
| 238204 | + &pRet, 0, 0, pRetry->nBuf, pRetry->aBuf, pApply->bInvertConstraints, 1 | |
| 238205 | + ); | |
| 238206 | + if( rc==SQLITE_OK ){ | |
| 238207 | + size_t nByte = 2*pApply->nCol*sizeof(sqlite3_value*); | |
| 238208 | + pRet->bPatchset = bPatchset; | |
| 238209 | + pRet->zTab = (char*)zTab; | |
| 238210 | + pRet->nCol = pApply->nCol; | |
| 238211 | + pRet->abPK = pApply->abPK; | |
| 238212 | + sessionBufferGrow(&pRet->tblhdr, nByte, &rc); | |
| 238213 | + pRet->apValue = (sqlite3_value**)pRet->tblhdr.aBuf; | |
| 238214 | + if( rc==SQLITE_OK ){ | |
| 238215 | + memset(pRet->apValue, 0, nByte); | |
| 238216 | + }else{ | |
| 238217 | + sqlite3changeset_finalize(pRet); | |
| 238218 | + pRet = 0; | |
| 238219 | + } | |
| 238220 | + } | |
| 238221 | + | |
| 238222 | + *ppIter = pRet; | |
| 238223 | + return rc; | |
| 238224 | +} | |
| 238225 | + | |
| 238226 | +/* | |
| 238227 | +** Attempt to apply all the changes in retry buffer pRetry to the database. | |
| 238228 | +** Except, if parameter iSkip is greater than or equal to 0, skip change | |
| 238229 | +** iSkip. | |
| 238230 | +*/ | |
| 238231 | +static int sessionApplyRetryBuffer( | |
| 238232 | + SessionBuffer *pRetry, /* Buffer to apply changes from */ | |
| 238233 | + int iSkip, /* If >=0, index of change to omit */ | |
| 238234 | + sqlite3 *db, /* Database handle */ | |
| 238235 | + int bPatchset, /* True for patchset, false for changeset */ | |
| 238236 | + const char *zTab, /* Name of table to write to */ | |
| 238237 | + SessionApplyCtx *pApply, /* Apply context */ | |
| 238238 | + int(*xConflict)(void*, int, sqlite3_changeset_iter*), | |
| 238239 | + void *pCtx /* First argument passed to xConflict */ | |
| 238240 | +){ | |
| 238241 | + int rc = SQLITE_OK; | |
| 238242 | + int rc2 = SQLITE_OK; | |
| 238243 | + int ii = 0; | |
| 238244 | + sqlite3_changeset_iter *pIter = 0; | |
| 238245 | + | |
| 238246 | + assert( pApply->constraints.nBuf==0 ); | |
| 238247 | + | |
| 238248 | + rc = sessionRetryIterInit(pRetry, bPatchset, zTab, pApply, &pIter); | |
| 238249 | + | |
| 238250 | + for(ii=0; rc==SQLITE_OK && SQLITE_ROW==sqlite3changeset_next(pIter); ii++){ | |
| 238251 | + if( ii!=iSkip ){ | |
| 238252 | + rc = sessionApplyOneWithRetry(db, pIter, pApply, xConflict, pCtx); | |
| 238253 | + } | |
| 238254 | + } | |
| 238255 | + | |
| 238256 | + rc2 = sqlite3changeset_finalize(pIter); | |
| 238257 | + if( rc==SQLITE_OK ) rc = rc2; | |
| 238258 | + assert( pApply->bDeferConstraints || pApply->constraints.nBuf==0 ); | |
| 238259 | + | |
| 238260 | + return rc; | |
| 238261 | +} | |
| 238262 | + | |
| 238263 | +/* | |
| 238264 | +** Check if table zTab in the "main" database of db is a WITHOUT ROWID | |
| 238265 | +** table. | |
| 238266 | +** | |
| 238267 | +** If no error occurs, return SQLITE_OK and set output variable (*pbWR) to | |
| 238268 | +** true if zTab is a WITHOUT ROWID table, or false otherwise. Or, if an | |
| 238269 | +** error does occur, return an SQLite error code. The final value of (*pbWR) | |
| 238270 | +** is undefined in this case. | |
| 238271 | +*/ | |
| 238272 | +static int sessionTableIsWithoutRowid(sqlite3 *db, const char *zTab, int *pbWR){ | |
| 238273 | + sqlite3_stmt *pList = 0; | |
| 238274 | + char *zSql = 0; | |
| 238275 | + int rc = SQLITE_OK; | |
| 238276 | + | |
| 238277 | + zSql = sqlite3_mprintf("PRAGMA table_list = %Q", zTab); | |
| 238278 | + if( zSql==0 ){ | |
| 238279 | + rc = SQLITE_NOMEM; | |
| 238280 | + }else{ | |
| 238281 | + rc = sqlite3_prepare_v2(db, zSql, -1, &pList, 0); | |
| 238282 | + sqlite3_free(zSql); | |
| 238283 | + } | |
| 238284 | + | |
| 238285 | + if( rc==SQLITE_OK ){ | |
| 238286 | + sqlite3_step(pList); | |
| 238287 | + *pbWR = sqlite3_column_int(pList, 4); | |
| 238288 | + rc = sqlite3_finalize(pList); | |
| 238289 | + } | |
| 238290 | + | |
| 238291 | + return rc; | |
| 238292 | +} | |
| 238293 | + | |
| 238294 | +/* | |
| 238295 | +** Iterator pUp points to an UPDATE change. This function deletes the | |
| 238296 | +** affected row from the database and creates an INSERT statement that | |
| 238297 | +** may be used to reinsert the row as it is after the UPDATE change | |
| 238298 | +** has been applied. | |
| 238299 | +** | |
| 238300 | +** If successful, SQLITE_OK is returned and output variable (*ppInsert) | |
| 238301 | +** is left pointing to a prepared INSERT statement. It is the responsibility | |
| 238302 | +** of the caller to eventually free this statement using sqlite3_finalize(). | |
| 238303 | +** Or, if an error occurs, an SQLite error code is returned and (*ppInsert) | |
| 238304 | +** set to NULL. pApply->zErr may be set to an error message in this case. | |
| 238305 | +*/ | |
| 238306 | +static int sessionUpdateToDeleteInsert( | |
| 238307 | + sqlite3 *db, /* Database to write to */ | |
| 238308 | + const char *zTab, /* Table name */ | |
| 238309 | + SessionApplyCtx *pApply, /* Apply context */ | |
| 238310 | + sqlite3_changeset_iter *pUp, /* Iterator pointing to UPDATE change */ | |
| 238311 | + sqlite3_stmt **ppInsert /* OUT: INSERT statement */ | |
| 238312 | +){ | |
| 238313 | + sqlite3_stmt *pRet = 0; /* The INSERT statement */ | |
| 238314 | + sqlite3_stmt *pSelect = 0; /* SELECT to read current values of row */ | |
| 238315 | + int rc = SQLITE_OK; | |
| 238316 | + int bWR = 0; | |
| 238317 | + | |
| 238318 | + rc = sessionTableIsWithoutRowid(db, zTab, &bWR); | |
| 238319 | + if( rc==SQLITE_OK ){ | |
| 238320 | + char *zSelect = 0; | |
| 238321 | + char *zInsert = 0; | |
| 238322 | + SessionBuffer cols = {0, 0, 0}; | |
| 238323 | + SessionBuffer insbind = {0, 0, 0}; | |
| 238324 | + SessionBuffer pkcols = {0, 0, 0}; | |
| 238325 | + SessionBuffer selbind = {0, 0, 0}; | |
| 238326 | + | |
| 238327 | + const char *zComma = ""; | |
| 238328 | + const char *zComma2 = ""; | |
| 238329 | + int ii; | |
| 238330 | + for(ii=0; ii<pApply->nCol; ii++){ | |
| 238331 | + sessionAppendStr(&cols, zComma, &rc); | |
| 238332 | + sessionAppendIdent(&cols, pApply->azCol[ii], &rc); | |
| 238333 | + sessionAppendStr(&insbind, zComma, &rc); | |
| 238334 | + sessionAppendStr(&insbind, "?", &rc); | |
| 238335 | + zComma = ", "; | |
| 238336 | + | |
| 238337 | + if( pApply->abPK[ii] ){ | |
| 238338 | + sessionAppendStr(&pkcols, zComma2, &rc); | |
| 238339 | + sessionAppendIdent(&pkcols, pApply->azCol[ii], &rc); | |
| 238340 | + sessionAppendStr(&selbind, zComma2, &rc); | |
| 238341 | + sessionAppendPrintf(&selbind, &rc, "?%d", ii+1); | |
| 238342 | + zComma2 = ", "; | |
| 238343 | + } | |
| 238344 | + } | |
| 238345 | + if( bWR==0 ){ | |
| 238346 | + sessionAppendStr(&cols, zComma, &rc); | |
| 238347 | + sessionAppendStr(&cols, SESSIONS_ROWID, &rc); | |
| 238348 | + sessionAppendStr(&insbind, zComma, &rc); | |
| 238349 | + sessionAppendStr(&insbind, "?", &rc); | |
| 238350 | + } | |
| 238351 | + | |
| 238352 | + if( rc==SQLITE_OK ){ | |
| 238353 | + zSelect = sqlite3_mprintf("SELECT %s FROM %Q WHERE (%s) IS (%s)", | |
| 238354 | + cols.aBuf, zTab, pkcols.aBuf, selbind.aBuf | |
| 238355 | + ); | |
| 238356 | + if( zSelect==0 ) rc = SQLITE_NOMEM; | |
| 238357 | + } | |
| 238358 | + if( rc==SQLITE_OK ){ | |
| 238359 | + zInsert = sqlite3_mprintf("INSERT INTO %Q(%s) VALUES(%s)", | |
| 238360 | + zTab, cols.aBuf, insbind.aBuf | |
| 238361 | + ); | |
| 238362 | + if( zInsert==0 ) rc = SQLITE_NOMEM; | |
| 238363 | + } | |
| 238364 | + | |
| 238365 | + if( rc==SQLITE_OK ){ | |
| 238366 | + rc = sessionPrepare(db, &pSelect, &pApply->zErr, zSelect); | |
| 238367 | + } | |
| 238368 | + if( rc==SQLITE_OK ){ | |
| 238369 | + rc = sessionPrepare(db, &pRet, &pApply->zErr, zInsert); | |
| 238370 | + } | |
| 238371 | + | |
| 238372 | + sqlite3_free(zSelect); | |
| 238373 | + sqlite3_free(zInsert); | |
| 238374 | + sqlite3_free(cols.aBuf); | |
| 238375 | + sqlite3_free(insbind.aBuf); | |
| 238376 | + sqlite3_free(pkcols.aBuf); | |
| 238377 | + sqlite3_free(selbind.aBuf); | |
| 238378 | + } | |
| 238379 | + | |
| 238380 | + if( rc==SQLITE_OK ){ | |
| 238381 | + rc = sessionBindRow( | |
| 238382 | + pUp, sqlite3changeset_old, pApply->nCol, pApply->abPK, pSelect | |
| 238383 | + ); | |
| 238384 | + } | |
| 238385 | + | |
| 238386 | + if( rc==SQLITE_OK && sqlite3_step(pSelect)==SQLITE_ROW ){ | |
| 238387 | + int iCol; | |
| 238388 | + for(iCol=0; iCol<pApply->nCol; iCol++){ | |
| 238389 | + sqlite3_value *pVal = pUp->apValue[iCol+pApply->nCol]; | |
| 238390 | + if( pVal==0 ){ | |
| 238391 | + pVal = sqlite3_column_value(pSelect, iCol); | |
| 238392 | + } | |
| 238393 | + rc = sqlite3_bind_value(pRet, iCol+1, pVal); | |
| 238394 | + } | |
| 238395 | + if( bWR==0 ){ | |
| 238396 | + sqlite3_bind_int64(pRet, iCol+1, sqlite3_column_int64(pSelect, iCol)); | |
| 238397 | + } | |
| 238398 | + } | |
| 238399 | + sessionFinalizeStmt(pSelect, &rc); | |
| 238400 | + | |
| 238401 | + /* Delete the row from the database. */ | |
| 238402 | + if( rc==SQLITE_OK ){ | |
| 238403 | + rc = sessionBindRow( | |
| 238404 | + pUp, sqlite3changeset_old, pApply->nCol, pApply->abPK, pApply->pDelete | |
| 238405 | + ); | |
| 238406 | + sqlite3_bind_int(pApply->pDelete, pApply->nCol+1, 1); | |
| 238407 | + } | |
| 238408 | + if( rc==SQLITE_OK ){ | |
| 238409 | + sqlite3_step(pApply->pDelete); | |
| 238410 | + rc = sqlite3_reset(pApply->pDelete); | |
| 238411 | + } | |
| 238412 | + | |
| 238413 | + if( rc!=SQLITE_OK ){ | |
| 238414 | + sqlite3_finalize(pRet); | |
| 238415 | + pRet = 0; | |
| 238416 | + } | |
| 238417 | + | |
| 238418 | + *ppInsert = pRet; | |
| 238419 | + return rc; | |
| 238420 | +} | |
| 238421 | + | |
| 238422 | +/* | |
| 238423 | +** Retry the changes accumulated in the pApply->constraints buffer. The | |
| 238424 | +** pApply->constraints buffer contains all changes to table zTab that | |
| 238425 | +** could not be applied due to SQLITE_CONSTRAINT errors. This function | |
| 238426 | +** attempts to apply them as follows: | |
| 238427 | +** | |
| 238428 | +** 1) It runs through the buffer and attempts to retry each change, | |
| 238429 | +** removing any that are successfully applied from the buffer. This | |
| 238430 | +** is repeated until no further progress can be made. | |
| 238431 | +** | |
| 238432 | +** 2) For each UPDATE change in the buffer, try the following in a | |
| 238433 | +** savepoint transaction: | |
| 238434 | +** | |
| 238435 | +** a) DELETE the affected row, | |
| 238436 | +** b) Attempt step (1) with remaining changes, | |
| 238437 | +** c) Attempt to INSERT a row equivalent to the one that would be | |
| 238438 | +** created by applying this UPDATE change. | |
| 238439 | +** | |
| 238440 | +** If the INSERT in (c) succeeds, the savepoint is committed and all | |
| 238441 | +** successfully applied changes are removed from the buffer. Step (2) | |
| 238442 | +** is then repeated. | |
| 238443 | +** | |
| 238444 | +** 3) Once step (2) has been attempted for each UPDATE in the change, | |
| 238445 | +** a final attempt is made to apply each remaining change. This time, | |
| 238446 | +** if an SQLITE_CONSTRAINT error is encountered, the conflict handler | |
| 238447 | +** is invoked and the user has to decide whether to omit the change | |
| 238448 | +** or rollback the entire _apply() operation. | |
| 237518 | 238449 | */ |
| 237519 | 238450 | static int sessionRetryConstraints( |
| 237520 | 238451 | sqlite3 *db, |
| 237521 | 238452 | int bPatchset, |
| 237522 | 238453 | const char *zTab, |
| @@ -237523,45 +238454,105 @@ | ||
| 237523 | 238454 | SessionApplyCtx *pApply, |
| 237524 | 238455 | int(*xConflict)(void*, int, sqlite3_changeset_iter*), |
| 237525 | 238456 | void *pCtx /* First argument passed to xConflict */ |
| 237526 | 238457 | ){ |
| 237527 | 238458 | int rc = SQLITE_OK; |
| 238459 | + int iUpdate = 0; | |
| 237528 | 238460 | |
| 238461 | + /* Step (1) */ | |
| 237529 | 238462 | while( pApply->constraints.nBuf ){ |
| 237530 | - sqlite3_changeset_iter *pIter2 = 0; | |
| 237531 | 238463 | SessionBuffer cons = pApply->constraints; |
| 237532 | 238464 | memset(&pApply->constraints, 0, sizeof(SessionBuffer)); |
| 237533 | 238465 | |
| 237534 | - rc = sessionChangesetStart( | |
| 237535 | - &pIter2, 0, 0, cons.nBuf, cons.aBuf, pApply->bInvertConstraints, 1 | |
| 238466 | + rc = sessionApplyRetryBuffer( | |
| 238467 | + &cons, -1, db, bPatchset, zTab, pApply, xConflict, pCtx | |
| 237536 | 238468 | ); |
| 237537 | - if( rc==SQLITE_OK ){ | |
| 237538 | - size_t nByte = 2*pApply->nCol*sizeof(sqlite3_value*); | |
| 237539 | - int rc2; | |
| 237540 | - pIter2->bPatchset = bPatchset; | |
| 237541 | - pIter2->zTab = (char*)zTab; | |
| 237542 | - pIter2->nCol = pApply->nCol; | |
| 237543 | - pIter2->abPK = pApply->abPK; | |
| 237544 | - sessionBufferGrow(&pIter2->tblhdr, nByte, &rc); | |
| 237545 | - pIter2->apValue = (sqlite3_value**)pIter2->tblhdr.aBuf; | |
| 237546 | - if( rc==SQLITE_OK ) memset(pIter2->apValue, 0, nByte); | |
| 237547 | - | |
| 237548 | - while( rc==SQLITE_OK && SQLITE_ROW==sqlite3changeset_next(pIter2) ){ | |
| 237549 | - rc = sessionApplyOneWithRetry(db, pIter2, pApply, xConflict, pCtx); | |
| 237550 | - } | |
| 237551 | - | |
| 237552 | - rc2 = sqlite3changeset_finalize(pIter2); | |
| 237553 | - if( rc==SQLITE_OK ) rc = rc2; | |
| 237554 | - } | |
| 237555 | - assert( pApply->bDeferConstraints || pApply->constraints.nBuf==0 ); | |
| 237556 | 238469 | |
| 237557 | 238470 | sqlite3_free(cons.aBuf); |
| 237558 | 238471 | if( rc!=SQLITE_OK ) break; |
| 237559 | - if( pApply->constraints.nBuf>=cons.nBuf ){ | |
| 237560 | - /* No progress was made on the last round. */ | |
| 237561 | - pApply->bDeferConstraints = 0; | |
| 238472 | + | |
| 238473 | + /* If no progress has been made this round, break out of the loop. */ | |
| 238474 | + if( pApply->constraints.nBuf>=cons.nBuf ) break; | |
| 238475 | + } | |
| 238476 | + | |
| 238477 | + /* Step (2) */ | |
| 238478 | + while( rc==SQLITE_OK && pApply->constraints.nBuf && !pApply->bNoUpdateLoop ){ | |
| 238479 | + SessionBuffer cons = {0, 0, 0}; | |
| 238480 | + sqlite3_changeset_iter *pUp = 0; | |
| 238481 | + sqlite3_stmt *pInsert = 0; | |
| 238482 | + int iSkip = 0; | |
| 238483 | + | |
| 238484 | + rc = sessionRetryIterInit( | |
| 238485 | + &pApply->constraints, bPatchset, zTab, pApply, &pUp | |
| 238486 | + ); | |
| 238487 | + if( rc==SQLITE_OK ){ | |
| 238488 | + int iThis = -1; | |
| 238489 | + while( SQLITE_ROW==sqlite3changeset_next(pUp) ){ | |
| 238490 | + if( pUp->op==SQLITE_UPDATE ) iThis++; | |
| 238491 | + if( iThis==iUpdate ) break; | |
| 238492 | + iSkip++; | |
| 238493 | + } | |
| 238494 | + if( iThis==iUpdate ){ | |
| 238495 | + rc = sqlite3_exec(db, "SAVEPOINT update_op", 0, 0, 0); | |
| 238496 | + if( rc==SQLITE_OK ){ | |
| 238497 | + rc = sessionUpdateToDeleteInsert(db, zTab, pApply, pUp, &pInsert); | |
| 238498 | + } | |
| 238499 | + } | |
| 238500 | + sqlite3changeset_finalize(pUp); | |
| 238501 | + if( iThis!=iUpdate ) break; | |
| 237562 | 238502 | } |
| 238503 | + | |
| 238504 | + if( rc==SQLITE_OK ){ | |
| 238505 | + cons = pApply->constraints; | |
| 238506 | + | |
| 238507 | + while( rc==SQLITE_OK && pApply->constraints.nBuf>0 ){ | |
| 238508 | + SessionBuffer app = pApply->constraints; | |
| 238509 | + memset(&pApply->constraints, 0, sizeof(SessionBuffer)); | |
| 238510 | + rc = sessionApplyRetryBuffer( | |
| 238511 | + &app, iSkip, db, bPatchset, zTab, pApply, xConflict, pCtx | |
| 238512 | + ); | |
| 238513 | + if( app.aBuf!=cons.aBuf ){ | |
| 238514 | + sqlite3_free(app.aBuf); | |
| 238515 | + } | |
| 238516 | + if( pApply->constraints.nBuf>=app.nBuf ){ | |
| 238517 | + break; | |
| 238518 | + } | |
| 238519 | + iSkip = -1; | |
| 238520 | + } | |
| 238521 | + } | |
| 238522 | + | |
| 238523 | + iUpdate++; | |
| 238524 | + if( rc==SQLITE_OK ){ | |
| 238525 | + sqlite3_step(pInsert); | |
| 238526 | + rc = sqlite3_finalize(pInsert); | |
| 238527 | + if( rc==SQLITE_CONSTRAINT ){ | |
| 238528 | + rc = sqlite3_exec(db, "ROLLBACK TO update_op", 0, 0, 0); | |
| 238529 | + sqlite3_free(pApply->constraints.aBuf); | |
| 238530 | + pApply->constraints = cons; | |
| 238531 | + memset(&cons, 0, sizeof(cons)); | |
| 238532 | + }else if( rc==SQLITE_OK ){ | |
| 238533 | + iUpdate = 0; | |
| 238534 | + } | |
| 238535 | + if( rc==SQLITE_OK ){ | |
| 238536 | + rc = sqlite3_exec(db, "RELEASE update_op", 0, 0, 0); | |
| 238537 | + } | |
| 238538 | + }else{ | |
| 238539 | + sqlite3_finalize(pInsert); | |
| 238540 | + } | |
| 238541 | + | |
| 238542 | + sqlite3_free(cons.aBuf); | |
| 238543 | + } | |
| 238544 | + | |
| 238545 | + /* Step (3) */ | |
| 238546 | + if( rc==SQLITE_OK && pApply->constraints.nBuf ){ | |
| 238547 | + SessionBuffer cons = pApply->constraints; | |
| 238548 | + memset(&pApply->constraints, 0, sizeof(SessionBuffer)); | |
| 238549 | + pApply->bDeferConstraints = 0; | |
| 238550 | + rc = sessionApplyRetryBuffer( | |
| 238551 | + &cons, -1, db, bPatchset, zTab, pApply, xConflict, pCtx | |
| 238552 | + ); | |
| 238553 | + sqlite3_free(cons.aBuf); | |
| 237563 | 238554 | } |
| 237564 | 238555 | |
| 237565 | 238556 | return rc; |
| 237566 | 238557 | } |
| 237567 | 238558 | |
| @@ -237611,10 +238602,11 @@ | ||
| 237611 | 238602 | pIter->in.bNoDiscard = 1; |
| 237612 | 238603 | memset(&sApply, 0, sizeof(sApply)); |
| 237613 | 238604 | sApply.bRebase = (ppRebase && pnRebase); |
| 237614 | 238605 | sApply.bInvertConstraints = !!(flags & SQLITE_CHANGESETAPPLY_INVERT); |
| 237615 | 238606 | sApply.bIgnoreNoop = !!(flags & SQLITE_CHANGESETAPPLY_IGNORENOOP); |
| 238607 | + sApply.bNoUpdateLoop = !!(flags & SQLITE_CHANGESETAPPLY_NOUPDATELOOP); | |
| 237616 | 238608 | if( (flags & SQLITE_CHANGESETAPPLY_NOSAVEPOINT)==0 ){ |
| 237617 | 238609 | rc = sqlite3_exec(db, "SAVEPOINT changeset_apply", 0, 0, 0); |
| 237618 | 238610 | } |
| 237619 | 238611 | if( rc==SQLITE_OK ){ |
| 237620 | 238612 | rc = sqlite3_exec(db, "PRAGMA defer_foreign_keys = 1", 0, 0, 0); |
| @@ -239422,11 +240414,11 @@ | ||
| 239422 | 240414 | int bNew, |
| 239423 | 240415 | int iCol, |
| 239424 | 240416 | const void *pVal, |
| 239425 | 240417 | int nVal |
| 239426 | 240418 | ){ |
| 239427 | - sqlite3_int64 nByte = 1 + sessionVarintLen(nVal) + nVal; | |
| 240419 | + sqlite3_int64 nByte = 1 + sessionVarintLen(nVal) + (i64)nVal; | |
| 239428 | 240420 | int rc = SQLITE_OK; |
| 239429 | 240421 | SessionBuffer *pBuf = 0; |
| 239430 | 240422 | |
| 239431 | 240423 | if( SQLITE_OK!=(rc = checkChangeParams(pGrp, bNew, iCol, nByte, &pBuf)) ){ |
| 239432 | 240424 | return rc; |
| @@ -239447,10 +240439,11 @@ | ||
| 239447 | 240439 | sqlite3_changegroup *pGrp, |
| 239448 | 240440 | int bDiscard, |
| 239449 | 240441 | char **pzErr |
| 239450 | 240442 | ){ |
| 239451 | 240443 | int rc = SQLITE_OK; |
| 240444 | + char *zErr = 0; | |
| 239452 | 240445 | if( pGrp->cd.pTab ){ |
| 239453 | 240446 | SessionBuffer *aBuf = pGrp->cd.aBuf; |
| 239454 | 240447 | int ii; |
| 239455 | 240448 | |
| 239456 | 240449 | if( bDiscard==0 ){ |
| @@ -239458,26 +240451,26 @@ | ||
| 239458 | 240451 | u8 eUndef = SQLITE_NULL; |
| 239459 | 240452 | if( pGrp->cd.eOp==SQLITE_UPDATE ){ |
| 239460 | 240453 | for(ii=0; ii<nBuf; ii++){ |
| 239461 | 240454 | if( pGrp->cd.pTab->abPK[ii] ){ |
| 239462 | 240455 | if( aBuf[ii].nBuf<=1 ){ |
| 239463 | - *pzErr = sqlite3_mprintf( | |
| 240456 | + zErr = sqlite3_mprintf( | |
| 239464 | 240457 | "invalid change: %s value in PK of old.* record", |
| 239465 | 240458 | aBuf[ii].nBuf==1 ? "null" : "undefined" |
| 239466 | 240459 | ); |
| 239467 | 240460 | rc = SQLITE_ERROR; |
| 239468 | 240461 | break; |
| 239469 | 240462 | }else if( aBuf[ii + nBuf].nBuf>0 ){ |
| 239470 | - *pzErr = sqlite3_mprintf( | |
| 240463 | + zErr = sqlite3_mprintf( | |
| 239471 | 240464 | "invalid change: defined value in PK of new.* record" |
| 239472 | 240465 | ); |
| 239473 | 240466 | rc = SQLITE_ERROR; |
| 239474 | 240467 | break; |
| 239475 | 240468 | } |
| 239476 | 240469 | }else |
| 239477 | 240470 | if( pGrp->bPatch==0 && (aBuf[ii].nBuf>0)!=(aBuf[ii+nBuf].nBuf>0) ){ |
| 239478 | - *pzErr = sqlite3_mprintf( | |
| 240471 | + zErr = sqlite3_mprintf( | |
| 239479 | 240472 | "invalid change: column %d " |
| 239480 | 240473 | "- old.* value is %sdefined but new.* is %sdefined", |
| 239481 | 240474 | ii, aBuf[ii].nBuf ? "" : "un", aBuf[ii+nBuf].nBuf ? "" : "un" |
| 239482 | 240475 | ); |
| 239483 | 240476 | rc = SQLITE_ERROR; |
| @@ -239490,18 +240483,18 @@ | ||
| 239490 | 240483 | for(ii=0; ii<nBuf; ii++){ |
| 239491 | 240484 | int isPK = pGrp->cd.pTab->abPK[ii]; |
| 239492 | 240485 | if( (pGrp->cd.eOp==SQLITE_INSERT || pGrp->bPatch==0 || isPK) |
| 239493 | 240486 | && aBuf[ii].nBuf==0 |
| 239494 | 240487 | ){ |
| 239495 | - *pzErr = sqlite3_mprintf( | |
| 240488 | + zErr = sqlite3_mprintf( | |
| 239496 | 240489 | "invalid change: column %d is undefined", ii |
| 239497 | 240490 | ); |
| 239498 | 240491 | rc = SQLITE_ERROR; |
| 239499 | 240492 | break; |
| 239500 | 240493 | } |
| 239501 | 240494 | if( aBuf[ii].nBuf==1 && isPK ){ |
| 239502 | - *pzErr = sqlite3_mprintf( | |
| 240495 | + zErr = sqlite3_mprintf( | |
| 239503 | 240496 | "invalid change: null value in PK" |
| 239504 | 240497 | ); |
| 239505 | 240498 | rc = SQLITE_ERROR; |
| 239506 | 240499 | break; |
| 239507 | 240500 | } |
| @@ -239547,10 +240540,15 @@ | ||
| 239547 | 240540 | } |
| 239548 | 240541 | } |
| 239549 | 240542 | pGrp->cd.pTab = 0; |
| 239550 | 240543 | } |
| 239551 | 240544 | |
| 240545 | + if( pzErr ){ | |
| 240546 | + *pzErr = zErr; | |
| 240547 | + }else{ | |
| 240548 | + sqlite3_free(zErr); | |
| 240549 | + } | |
| 239552 | 240550 | return rc; |
| 239553 | 240551 | } |
| 239554 | 240552 | |
| 239555 | 240553 | #endif /* SQLITE_ENABLE_SESSION && SQLITE_ENABLE_PREUPDATE_HOOK */ |
| 239556 | 240554 | |
| @@ -243272,11 +244270,11 @@ | ||
| 243272 | 244270 | ){ |
| 243273 | 244271 | HighlightContext ctx; |
| 243274 | 244272 | int rc = SQLITE_OK; /* Return code */ |
| 243275 | 244273 | int iCol; /* 1st argument to snippet() */ |
| 243276 | 244274 | const char *zEllips; /* 4th argument to snippet() */ |
| 243277 | - int nToken; /* 5th argument to snippet() */ | |
| 244275 | + i64 nToken; /* 5th argument to snippet() */ | |
| 243278 | 244276 | int nInst = 0; /* Number of instance matches this row */ |
| 243279 | 244277 | int i; /* Used to iterate through instances */ |
| 243280 | 244278 | int nPhrase; /* Number of phrases in query */ |
| 243281 | 244279 | unsigned char *aSeen; /* Array of "seen instance" flags */ |
| 243282 | 244280 | int iBestCol; /* Column containing best snippet */ |
| @@ -243297,11 +244295,11 @@ | ||
| 243297 | 244295 | iCol = sqlite3_value_int(apVal[0]); |
| 243298 | 244296 | ctx.zOpen = fts5ValueToText(apVal[1]); |
| 243299 | 244297 | ctx.zClose = fts5ValueToText(apVal[2]); |
| 243300 | 244298 | ctx.iRangeEnd = -1; |
| 243301 | 244299 | zEllips = fts5ValueToText(apVal[3]); |
| 243302 | - nToken = sqlite3_value_int(apVal[4]); | |
| 244300 | + nToken = (int)(MIN( MAX(sqlite3_value_int64(apVal[4]), 0), 64)); | |
| 243303 | 244301 | |
| 243304 | 244302 | iBestCol = (iCol>=0 ? iCol : 0); |
| 243305 | 244303 | nPhrase = pApi->xPhraseCount(pFts); |
| 243306 | 244304 | aSeen = sqlite3_malloc64(nPhrase); |
| 243307 | 244305 | if( aSeen==0 ){ |
| @@ -246013,11 +247011,11 @@ | ||
| 246013 | 247011 | /* Add an entry to each output position list */ |
| 246014 | 247012 | for(i=0; i<pNear->nPhrase; i++){ |
| 246015 | 247013 | i64 iPos = a[i].reader.iPos; |
| 246016 | 247014 | Fts5PoslistWriter *pWriter = &a[i].writer; |
| 246017 | 247015 | if( a[i].pOut->n==0 || iPos!=pWriter->iPrev ){ |
| 246018 | - sqlite3Fts5PoslistWriterAppend(a[i].pOut, pWriter, iPos); | |
| 247016 | + sqlite3Fts5PoslistSafeAppend(a[i].pOut, &pWriter->iPrev, iPos); | |
| 246019 | 247017 | } |
| 246020 | 247018 | } |
| 246021 | 247019 | |
| 246022 | 247020 | iAdv = 0; |
| 246023 | 247021 | iMin = a[0].reader.iLookahead; |
| @@ -246964,14 +247962,14 @@ | ||
| 246964 | 247962 | rc = SQLITE_NOMEM; |
| 246965 | 247963 | }else{ |
| 246966 | 247964 | memset(pSyn, 0, (size_t)nByte); |
| 246967 | 247965 | pSyn->pTerm = ((char*)pSyn) + sizeof(Fts5ExprTerm) + sizeof(Fts5Buffer); |
| 246968 | 247966 | pSyn->nFullTerm = pSyn->nQueryTerm = nToken; |
| 247967 | + memcpy(pSyn->pTerm, pToken, nToken); | |
| 246969 | 247968 | if( pCtx->pConfig->bTokendata ){ |
| 246970 | 247969 | pSyn->nQueryTerm = (int)strlen(pSyn->pTerm); |
| 246971 | 247970 | } |
| 246972 | - memcpy(pSyn->pTerm, pToken, nToken); | |
| 246973 | 247971 | pSyn->pSynonym = pPhrase->aTerm[pPhrase->nTerm-1].pSynonym; |
| 246974 | 247972 | pPhrase->aTerm[pPhrase->nTerm-1].pSynonym = pSyn; |
| 246975 | 247973 | } |
| 246976 | 247974 | }else{ |
| 246977 | 247975 | Fts5ExprTerm *pTerm; |
| @@ -248816,11 +249814,11 @@ | ||
| 248816 | 249814 | ** + 1 byte for a "new column" byte, |
| 248817 | 249815 | ** + 3 bytes for a new column number (16-bit max) as a varint, |
| 248818 | 249816 | ** + 5 bytes for the new position offset (32-bit max). |
| 248819 | 249817 | */ |
| 248820 | 249818 | if( (p->nAlloc - p->nData) < (9 + 4 + 1 + 3 + 5) ){ |
| 248821 | - sqlite3_int64 nNew = p->nAlloc * 2; | |
| 249819 | + sqlite3_int64 nNew = (i64)p->nAlloc * 2; | |
| 248822 | 249820 | Fts5HashEntry *pNew; |
| 248823 | 249821 | Fts5HashEntry **pp; |
| 248824 | 249822 | pNew = (Fts5HashEntry*)sqlite3_realloc64(p, nNew); |
| 248825 | 249823 | if( pNew==0 ) return SQLITE_NOMEM; |
| 248826 | 249824 | pNew->nAlloc = (int)nNew; |
| @@ -250006,11 +251004,11 @@ | ||
| 250006 | 251004 | } |
| 250007 | 251005 | |
| 250008 | 251006 | static Fts5Data *fts5LeafRead(Fts5Index *p, i64 iRowid){ |
| 250009 | 251007 | Fts5Data *pRet = fts5DataRead(p, iRowid); |
| 250010 | 251008 | if( pRet ){ |
| 250011 | - if( pRet->nn<4 || pRet->szLeaf>pRet->nn ){ | |
| 251009 | + if( pRet->szLeaf<4 || pRet->szLeaf>pRet->nn ){ | |
| 250012 | 251010 | FTS5_CORRUPT_ROWID(p, iRowid); |
| 250013 | 251011 | fts5DataRelease(pRet); |
| 250014 | 251012 | pRet = 0; |
| 250015 | 251013 | } |
| 250016 | 251014 | } |
| @@ -250250,11 +251248,11 @@ | ||
| 250250 | 251248 | }else{ |
| 250251 | 251249 | i += fts5GetVarint32(&pData[i], pLvl->nMerge); |
| 250252 | 251250 | i += fts5GetVarint32(&pData[i], nTotal); |
| 250253 | 251251 | if( nTotal<pLvl->nMerge ) rc = FTS5_CORRUPT; |
| 250254 | 251252 | pLvl->aSeg = (Fts5StructureSegment*)sqlite3Fts5MallocZero(&rc, |
| 250255 | - nTotal * sizeof(Fts5StructureSegment) | |
| 251253 | + (i64)nTotal * sizeof(Fts5StructureSegment) | |
| 250256 | 251254 | ); |
| 250257 | 251255 | nSegment -= nTotal; |
| 250258 | 251256 | } |
| 250259 | 251257 | |
| 250260 | 251258 | if( rc==SQLITE_OK ){ |
| @@ -250779,19 +251777,20 @@ | ||
| 250779 | 251777 | assert( pLvl->bEof==0 ); |
| 250780 | 251778 | if( iOff<=pLvl->iFirstOff ){ |
| 250781 | 251779 | pLvl->bEof = 1; |
| 250782 | 251780 | }else{ |
| 250783 | 251781 | u8 *a = pLvl->pData->p; |
| 251782 | + int nn = pLvl->pData->nn; | |
| 250784 | 251783 | |
| 250785 | 251784 | pLvl->iOff = 0; |
| 250786 | 251785 | fts5DlidxLvlNext(pLvl); |
| 250787 | 251786 | while( 1 ){ |
| 250788 | 251787 | int nZero = 0; |
| 250789 | 251788 | int ii = pLvl->iOff; |
| 250790 | 251789 | u64 delta = 0; |
| 250791 | 251790 | |
| 250792 | - while( a[ii]==0 ){ | |
| 251791 | + while( ii<nn && a[ii]==0 ){ | |
| 250793 | 251792 | nZero++; |
| 250794 | 251793 | ii++; |
| 250795 | 251794 | } |
| 250796 | 251795 | ii += sqlite3Fts5GetVarint(&a[ii], &delta); |
| 250797 | 251796 | |
| @@ -251206,11 +252205,11 @@ | ||
| 251206 | 252205 | fts5DataRelease(pIter->pLeaf); |
| 251207 | 252206 | pIter->pLeaf = 0; |
| 251208 | 252207 | while( p->rc==SQLITE_OK && pIter->iLeafPgno>pIter->iTermLeafPgno ){ |
| 251209 | 252208 | Fts5Data *pNew; |
| 251210 | 252209 | pIter->iLeafPgno--; |
| 251211 | - pNew = fts5DataRead(p, FTS5_SEGMENT_ROWID( | |
| 252210 | + pNew = fts5LeafRead(p, FTS5_SEGMENT_ROWID( | |
| 251212 | 252211 | pIter->pSeg->iSegid, pIter->iLeafPgno |
| 251213 | 252212 | )); |
| 251214 | 252213 | if( pNew ){ |
| 251215 | 252214 | /* iTermLeafOffset may be equal to szLeaf if the term is the last |
| 251216 | 252215 | ** thing on the page - i.e. the first rowid is on the following page. |
| @@ -251659,10 +252658,14 @@ | ||
| 251659 | 252658 | |
| 251660 | 252659 | /* Figure out how many new bytes are in this term */ |
| 251661 | 252660 | fts5FastGetVarint32(a, iOff, nNew); |
| 251662 | 252661 | if( nKeep<nMatch ){ |
| 251663 | 252662 | goto search_failed; |
| 252663 | + } | |
| 252664 | + if( (iOff+nNew)>n ){ | |
| 252665 | + FTS5_CORRUPT_ITER(p, pIter); | |
| 252666 | + return; | |
| 251664 | 252667 | } |
| 251665 | 252668 | |
| 251666 | 252669 | assert( nKeep>=nMatch ); |
| 251667 | 252670 | if( nKeep==nMatch ){ |
| 251668 | 252671 | u32 nCmp; |
| @@ -252636,12 +253639,11 @@ | ||
| 252636 | 253639 | } |
| 252637 | 253640 | } |
| 252638 | 253641 | |
| 252639 | 253642 | do { |
| 252640 | 253643 | while( i<nChunk && pChunk[i]!=0x01 ){ |
| 252641 | - while( pChunk[i] & 0x80 ) i++; | |
| 252642 | - i++; | |
| 253644 | + fts5IndexSkipVarint(pChunk, i); | |
| 252643 | 253645 | } |
| 252644 | 253646 | if( pCtx->eState ){ |
| 252645 | 253647 | fts5BufferSafeAppendBlob(pCtx->pBuf, &pChunk[iStart], i-iStart); |
| 252646 | 253648 | } |
| 252647 | 253649 | if( i<nChunk ){ |
| @@ -252786,11 +253788,11 @@ | ||
| 252786 | 253788 | } |
| 252787 | 253789 | |
| 252788 | 253790 | /* Advance pointer p until it points to pEnd or an 0x01 byte that is |
| 252789 | 253791 | ** not part of a varint */ |
| 252790 | 253792 | while( p<pEnd && *p!=0x01 ){ |
| 252791 | - while( *p++ & 0x80 ); | |
| 253793 | + while( p<pEnd && (*p++ & 0x80) ); | |
| 252792 | 253794 | } |
| 252793 | 253795 | |
| 252794 | 253796 | if( pColset->aiCol[i]==iCurrent ){ |
| 252795 | 253797 | if( pColset->nCol==1 ){ |
| 252796 | 253798 | pIter->base.pData = aCopy; |
| @@ -252883,12 +253885,15 @@ | ||
| 252883 | 253885 | */ |
| 252884 | 253886 | static void fts5IterSetOutputs_Col100(Fts5Iter *pIter, Fts5SegIter *pSeg){ |
| 252885 | 253887 | |
| 252886 | 253888 | assert( pIter->pIndex->pConfig->eDetail==FTS5_DETAIL_COLUMNS ); |
| 252887 | 253889 | assert( pIter->pColset ); |
| 253890 | + assert( pIter->poslist.nSpace>=pIter->pIndex->pConfig->nCol ); | |
| 252888 | 253891 | |
| 252889 | - if( pSeg->iLeafOffset+pSeg->nPos>pSeg->pLeaf->szLeaf ){ | |
| 253892 | + if( pSeg->iLeafOffset+pSeg->nPos>pSeg->pLeaf->szLeaf | |
| 253893 | + || pSeg->nPos>pIter->pIndex->pConfig->nCol | |
| 253894 | + ){ | |
| 252890 | 253895 | fts5IterSetOutputs_Col(pIter, pSeg); |
| 252891 | 253896 | }else{ |
| 252892 | 253897 | u8 *a = (u8*)&pSeg->pLeaf->p[pSeg->iLeafOffset]; |
| 252893 | 253898 | u8 *pEnd = (u8*)&a[pSeg->nPos]; |
| 252894 | 253899 | int iPrev = 0; |
| @@ -254377,10 +255382,15 @@ | ||
| 254377 | 255382 | int iSOP; /* Start-Of-Position-list */ |
| 254378 | 255383 | if( pSeg->iLeafPgno==pSeg->iTermLeafPgno ){ |
| 254379 | 255384 | iStart = pSeg->iTermLeafOffset; |
| 254380 | 255385 | }else{ |
| 254381 | 255386 | iStart = fts5GetU16(&aPg[0]); |
| 255387 | + } | |
| 255388 | + if( iStart>nPg ){ | |
| 255389 | + FTS5_CORRUPT_IDX(p); | |
| 255390 | + sqlite3_free(aIdx); | |
| 255391 | + return; | |
| 254382 | 255392 | } |
| 254383 | 255393 | |
| 254384 | 255394 | iSOP = iStart + fts5GetVarint(&aPg[iStart], &iDelta); |
| 254385 | 255395 | assert_nc( iSOP<=pSeg->iLeafOffset ); |
| 254386 | 255396 | |
| @@ -257063,12 +258073,12 @@ | ||
| 257063 | 258073 | int *pnOut, /* OUT: Number of output pages */ |
| 257064 | 258074 | Fts5Data ***papOut /* OUT: Output hash pages */ |
| 257065 | 258075 | ){ |
| 257066 | 258076 | const int MINSLOT = 32; |
| 257067 | 258077 | int nSlotPerPage = MAX(MINSLOT, (p->pConfig->pgsz - 8) / szKey); |
| 257068 | - int nSlot = 0; /* Number of slots in each output page */ | |
| 257069 | - int nOut = 0; | |
| 258078 | + i64 nSlot = 0; /* Number of slots in each output page */ | |
| 258079 | + i64 nOut = 0; | |
| 257070 | 258080 | |
| 257071 | 258081 | /* Figure out how many output pages (nOut) and how many slots per |
| 257072 | 258082 | ** page (nSlot). There are three possibilities: |
| 257073 | 258083 | ** |
| 257074 | 258084 | ** 1. The hash table does not yet exist. In this case the new hash |
| @@ -257089,27 +258099,30 @@ | ||
| 257089 | 258099 | /* Case 1. */ |
| 257090 | 258100 | nOut = 1; |
| 257091 | 258101 | nSlot = MINSLOT; |
| 257092 | 258102 | }else if( pSeg->nPgTombstone==1 ){ |
| 257093 | 258103 | /* Case 2. */ |
| 257094 | - int nElem = (int)fts5GetU32(&pData1->p[4]); | |
| 258104 | + u32 nElem = fts5GetU32(&pData1->p[4]); | |
| 257095 | 258105 | assert( pData1 && iPg1==0 ); |
| 257096 | - nOut = 1; | |
| 257097 | - nSlot = MAX(nElem*4, MINSLOT); | |
| 257098 | - if( nSlot>nSlotPerPage ) nOut = 0; | |
| 258106 | + if( nElem>((u32)nSlotPerPage/4) ){ | |
| 258107 | + nOut = 0; | |
| 258108 | + }else{ | |
| 258109 | + nOut = 1; | |
| 258110 | + nSlot = MAX((i64)nElem*4, MINSLOT); | |
| 258111 | + } | |
| 257099 | 258112 | } |
| 257100 | 258113 | if( nOut==0 ){ |
| 257101 | 258114 | /* Case 3. */ |
| 257102 | - nOut = (pSeg->nPgTombstone * 2 + 1); | |
| 258115 | + nOut = ((i64)pSeg->nPgTombstone * 2 + 1); | |
| 257103 | 258116 | nSlot = nSlotPerPage; |
| 257104 | 258117 | } |
| 257105 | 258118 | |
| 257106 | 258119 | /* Allocate the required array and output pages */ |
| 257107 | 258120 | while( 1 ){ |
| 257108 | 258121 | int res = 0; |
| 257109 | - int ii = 0; | |
| 257110 | - int szPage = 0; | |
| 258122 | + i64 ii = 0; | |
| 258123 | + i64 szPage = 0; | |
| 257111 | 258124 | Fts5Data **apOut = 0; |
| 257112 | 258125 | |
| 257113 | 258126 | /* Allocate space for the new hash table */ |
| 257114 | 258127 | assert( nSlot>=MINSLOT ); |
| 257115 | 258128 | apOut = (Fts5Data**)sqlite3Fts5MallocZero(&p->rc, sizeof(Fts5Data*) * nOut); |
| @@ -257643,11 +258656,11 @@ | ||
| 257643 | 258656 | ){ |
| 257644 | 258657 | |
| 257645 | 258658 | /* Check any rowid-less pages that occur before the current leaf. */ |
| 257646 | 258659 | for(iPg=iPrevLeaf+1; iPg<fts5DlidxIterPgno(pDlidx); iPg++){ |
| 257647 | 258660 | iKey = FTS5_SEGMENT_ROWID(iSegid, iPg); |
| 257648 | - pLeaf = fts5DataRead(p, iKey); | |
| 258661 | + pLeaf = fts5LeafRead(p, iKey); | |
| 257649 | 258662 | if( pLeaf ){ |
| 257650 | 258663 | if( fts5LeafFirstRowidOff(pLeaf)!=0 ) FTS5_CORRUPT_ROWID(p, iKey); |
| 257651 | 258664 | fts5DataRelease(pLeaf); |
| 257652 | 258665 | } |
| 257653 | 258666 | } |
| @@ -257654,11 +258667,11 @@ | ||
| 257654 | 258667 | iPrevLeaf = fts5DlidxIterPgno(pDlidx); |
| 257655 | 258668 | |
| 257656 | 258669 | /* Check that the leaf page indicated by the iterator really does |
| 257657 | 258670 | ** contain the rowid suggested by the same. */ |
| 257658 | 258671 | iKey = FTS5_SEGMENT_ROWID(iSegid, iPrevLeaf); |
| 257659 | - pLeaf = fts5DataRead(p, iKey); | |
| 258672 | + pLeaf = fts5LeafRead(p, iKey); | |
| 257660 | 258673 | if( pLeaf ){ |
| 257661 | 258674 | i64 iRowid; |
| 257662 | 258675 | int iRowidOff = fts5LeafFirstRowidOff(pLeaf); |
| 257663 | 258676 | ASSERT_SZLEAF_OK(pLeaf); |
| 257664 | 258677 | if( iRowidOff>=pLeaf->szLeaf ){ |
| @@ -262254,11 +263267,11 @@ | ||
| 262254 | 263267 | int nArg, /* Number of args */ |
| 262255 | 263268 | sqlite3_value **apUnused /* Function arguments */ |
| 262256 | 263269 | ){ |
| 262257 | 263270 | assert( nArg==0 ); |
| 262258 | 263271 | UNUSED_PARAM2(nArg, apUnused); |
| 262259 | - sqlite3_result_text(pCtx, "fts5: 2026-05-04 10:14:13 7e4134e3ff1ca8712f5fc78fadae665549450988dc43af27c7fe0c77f10ce3fb", -1, SQLITE_TRANSIENT); | |
| 263272 | + sqlite3_result_text(pCtx, "fts5: 2026-06-16 13:43:08 3f3fb9b638f59ad982beafb7c117f24ddd3da612e62c862510805fa672ffae06", -1, SQLITE_TRANSIENT); | |
| 262260 | 263273 | } |
| 262261 | 263274 | |
| 262262 | 263275 | /* |
| 262263 | 263276 | ** Implementation of fts5_locale(LOCALE, TEXT) function. |
| 262264 | 263277 | ** |
| @@ -264648,12 +265661,18 @@ | ||
| 264648 | 265661 | PorterTokenizer *pRet; |
| 264649 | 265662 | void *pUserdata = 0; |
| 264650 | 265663 | const char *zBase = "unicode61"; |
| 264651 | 265664 | fts5_tokenizer_v2 *pV2 = 0; |
| 264652 | 265665 | |
| 264653 | - if( nArg>0 ){ | |
| 264654 | - zBase = azArg[0]; | |
| 265666 | + while( nArg>0 ){ | |
| 265667 | + if( sqlite3_stricmp(azArg[0],"porter")==0 ){ | |
| 265668 | + nArg--; | |
| 265669 | + azArg++; | |
| 265670 | + }else{ | |
| 265671 | + zBase = azArg[0]; | |
| 265672 | + break; | |
| 265673 | + } | |
| 264655 | 265674 | } |
| 264656 | 265675 | |
| 264657 | 265676 | pRet = (PorterTokenizer*)sqlite3_malloc64(sizeof(PorterTokenizer)); |
| 264658 | 265677 | if( pRet ){ |
| 264659 | 265678 | memset(pRet, 0, sizeof(PorterTokenizer)); |
| 264660 | 265679 |
| --- extsrc/sqlite3.c | |
| +++ extsrc/sqlite3.c | |
| @@ -16,11 +16,11 @@ | |
| 16 | ** if you want a wrapper to interface SQLite with your choice of programming |
| 17 | ** language. The code for the "sqlite3" command-line shell is also in a |
| 18 | ** separate file. This file contains only code for the core SQLite library. |
| 19 | ** |
| 20 | ** The content in this amalgamation comes from Fossil check-in |
| 21 | ** 7e4134e3ff1ca8712f5fc78fadae66554945 with changes in files: |
| 22 | ** |
| 23 | ** |
| 24 | */ |
| 25 | #ifndef SQLITE_AMALGAMATION |
| 26 | #define SQLITE_CORE 1 |
| @@ -467,14 +467,14 @@ | |
| 467 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 468 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 469 | */ |
| 470 | #define SQLITE_VERSION "3.54.0" |
| 471 | #define SQLITE_VERSION_NUMBER 3054000 |
| 472 | #define SQLITE_SOURCE_ID "2026-05-04 10:14:13 7e4134e3ff1ca8712f5fc78fadae665549450988dc43af27c7fe0c77f10ce3fb" |
| 473 | #define SQLITE_SCM_BRANCH "trunk" |
| 474 | #define SQLITE_SCM_TAGS "" |
| 475 | #define SQLITE_SCM_DATETIME "2026-05-04T10:14:13.819Z" |
| 476 | |
| 477 | /* |
| 478 | ** CAPI3REF: Run-Time Library Version Numbers |
| 479 | ** KEYWORDS: sqlite3_version sqlite3_sourceid |
| 480 | ** |
| @@ -4373,12 +4373,11 @@ | |
| 4373 | ** parameter on F or if the value of P does not match any of the |
| 4374 | ** above, then sqlite3_uri_boolean(F,P,B) returns (B!=0). |
| 4375 | ** |
| 4376 | ** The sqlite3_uri_int64(F,P,D) routine converts the value of P into a |
| 4377 | ** 64-bit signed integer and returns that integer, or D if P does not |
| 4378 | ** exist. If the value of P is something other than an integer, then |
| 4379 | ** zero is returned. |
| 4380 | ** |
| 4381 | ** The sqlite3_uri_key(F,N) returns a pointer to the name (not |
| 4382 | ** the value) of the N-th query parameter for filename F, or a NULL |
| 4383 | ** pointer if N is less than zero or greater than the number of query |
| 4384 | ** parameters minus 1. The N value is zero-based so N should be 0 to obtain |
| @@ -4697,11 +4696,12 @@ | |
| 4697 | ** <dd>The maximum number of columns in a table definition or in the |
| 4698 | ** result set of a [SELECT] or the maximum number of columns in an index |
| 4699 | ** or in an ORDER BY or GROUP BY clause.</dd>)^ |
| 4700 | ** |
| 4701 | ** [[SQLITE_LIMIT_EXPR_DEPTH]] ^(<dt>SQLITE_LIMIT_EXPR_DEPTH</dt> |
| 4702 | ** <dd>The maximum depth of the parse tree on any expression.</dd>)^ |
| 4703 | ** |
| 4704 | ** [[SQLITE_LIMIT_PARSER_DEPTH]] ^(<dt>SQLITE_LIMIT_PARSER_DEPTH</dt> |
| 4705 | ** <dd>The maximum depth of the LALR(1) parser stack used to analyze |
| 4706 | ** input SQL statements.</dd>)^ |
| 4707 | ** |
| @@ -4728,11 +4728,12 @@ | |
| 4728 | ** [[SQLITE_LIMIT_VARIABLE_NUMBER]] |
| 4729 | ** ^(<dt>SQLITE_LIMIT_VARIABLE_NUMBER</dt> |
| 4730 | ** <dd>The maximum index number of any [parameter] in an SQL statement.)^ |
| 4731 | ** |
| 4732 | ** [[SQLITE_LIMIT_TRIGGER_DEPTH]] ^(<dt>SQLITE_LIMIT_TRIGGER_DEPTH</dt> |
| 4733 | ** <dd>The maximum depth of recursion for triggers.</dd>)^ |
| 4734 | ** |
| 4735 | ** [[SQLITE_LIMIT_WORKER_THREADS]] ^(<dt>SQLITE_LIMIT_WORKER_THREADS</dt> |
| 4736 | ** <dd>The maximum number of auxiliary worker threads that a single |
| 4737 | ** [prepared statement] may start.</dd>)^ |
| 4738 | ** </dl> |
| @@ -11534,12 +11535,23 @@ | |
| 11534 | ** reopen S as an in-memory database based on the serialization |
| 11535 | ** contained in P. If S is a NULL pointer, the main database is |
| 11536 | ** used. The serialized database P is N bytes in size. M is the size |
| 11537 | ** of the buffer P, which might be larger than N. If M is larger than |
| 11538 | ** N, and the SQLITE_DESERIALIZE_READONLY bit is not set in F, then |
| 11539 | ** SQLite is permitted to add content to the in-memory database as |
| 11540 | ** long as the total size does not exceed M bytes. |
| 11541 | ** |
| 11542 | ** If the SQLITE_DESERIALIZE_FREEONCLOSE bit is set in F, then SQLite will |
| 11543 | ** invoke sqlite3_free() on the serialization buffer when the database |
| 11544 | ** connection closes. If the SQLITE_DESERIALIZE_RESIZEABLE bit is set, then |
| 11545 | ** SQLite will try to increase the buffer size using sqlite3_realloc64() |
| @@ -13184,15 +13196,27 @@ | |
| 13184 | ** <dt>SQLITE_CHANGESETAPPLY_FKNOACTION <dd> |
| 13185 | ** If this flag it set, then all foreign key constraints in the target |
| 13186 | ** database behave as if they were declared with "ON UPDATE NO ACTION ON |
| 13187 | ** DELETE NO ACTION", even if they are actually CASCADE, RESTRICT, SET NULL |
| 13188 | ** or SET DEFAULT. |
| 13189 | */ |
| 13190 | #define SQLITE_CHANGESETAPPLY_NOSAVEPOINT 0x0001 |
| 13191 | #define SQLITE_CHANGESETAPPLY_INVERT 0x0002 |
| 13192 | #define SQLITE_CHANGESETAPPLY_IGNORENOOP 0x0004 |
| 13193 | #define SQLITE_CHANGESETAPPLY_FKNOACTION 0x0008 |
| 13194 | |
| 13195 | /* |
| 13196 | ** CAPI3REF: Constants Passed To The Conflict Handler |
| 13197 | ** |
| 13198 | ** Values that may be passed as the second argument to a conflict-handler. |
| @@ -15798,10 +15822,17 @@ | |
| 15798 | */ |
| 15799 | #ifndef offsetof |
| 15800 | # define offsetof(ST,M) ((size_t)((char*)&((ST*)0)->M - (char*)0)) |
| 15801 | #endif |
| 15802 | |
| 15803 | /* |
| 15804 | ** Work around C99 "flex-array" syntax for pre-C99 compilers, so as |
| 15805 | ** to avoid complaints from -fsanitize=strict-bounds. |
| 15806 | */ |
| 15807 | #if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) |
| @@ -18705,11 +18736,11 @@ | |
| 18705 | int aLimit[SQLITE_N_LIMIT]; /* Limits */ |
| 18706 | int nMaxSorterMmap; /* Maximum size of regions mapped by sorter */ |
| 18707 | struct sqlite3InitInfo { /* Information used during initialization */ |
| 18708 | Pgno newTnum; /* Rootpage of table being initialized */ |
| 18709 | u8 iDb; /* Which db file is being initialized */ |
| 18710 | u8 busy; /* TRUE if currently initializing */ |
| 18711 | unsigned orphanTrigger : 1; /* Last statement is orphaned TEMP trigger */ |
| 18712 | unsigned imposterTable : 2; /* Building an imposter table */ |
| 18713 | unsigned reopenMemdb : 1; /* ATTACH is really a reopen using MemDB */ |
| 18714 | const char **azInit; /* "type", "name", and "tbl_name" columns */ |
| 18715 | } init; |
| @@ -20917,10 +20948,11 @@ | |
| 20917 | int nTab; /* Number of previously allocated VDBE cursors */ |
| 20918 | int nMem; /* Number of memory cells used so far */ |
| 20919 | int szOpAlloc; /* Bytes of memory space allocated for Vdbe.aOp[] */ |
| 20920 | int iSelfTab; /* Table associated with an index on expr, or negative |
| 20921 | ** of the base register during check-constraint eval */ |
| 20922 | int nLabel; /* The *negative* of the number of labels used */ |
| 20923 | int nLabelAlloc; /* Number of slots in aLabel */ |
| 20924 | int *aLabel; /* Space to hold the labels */ |
| 20925 | ExprList *pConstExpr;/* Constant expressions */ |
| 20926 | IndexedExpr *pIdxEpr;/* List of expressions used by active indexes */ |
| @@ -21256,11 +21288,11 @@ | |
| 21256 | */ |
| 21257 | #define INITFLAG_AlterMask 0x0007 /* Types of ALTER */ |
| 21258 | #define INITFLAG_AlterRename 0x0001 /* Reparse after a RENAME */ |
| 21259 | #define INITFLAG_AlterDrop 0x0002 /* Reparse after a DROP COLUMN */ |
| 21260 | #define INITFLAG_AlterAdd 0x0003 /* Reparse after an ADD COLUMN */ |
| 21261 | #define INITFLAG_AlterDropCons 0x0004 /* Reparse after an ADD COLUMN */ |
| 21262 | |
| 21263 | /* Tuning parameters are set using SQLITE_TESTCTRL_TUNE and are controlled |
| 21264 | ** on debug-builds of the CLI using ".testctrl tune ID VALUE". Tuning |
| 21265 | ** parameters are for temporary use during development, to help find |
| 21266 | ** optimal values for parameters in the query planner. The should not |
| @@ -22509,11 +22541,19 @@ | |
| 22509 | SQLITE_PRIVATE void sqlite3Reindex(Parse*, Token*, Token*); |
| 22510 | SQLITE_PRIVATE void sqlite3AlterFunctions(void); |
| 22511 | SQLITE_PRIVATE void sqlite3AlterRenameTable(Parse*, SrcList*, Token*); |
| 22512 | SQLITE_PRIVATE void sqlite3AlterRenameColumn(Parse*, SrcList*, Token*, Token*); |
| 22513 | SQLITE_PRIVATE void sqlite3AlterDropConstraint(Parse*,SrcList*,Token*,Token*); |
| 22514 | SQLITE_PRIVATE void sqlite3AlterAddConstraint(Parse*,SrcList*,Token*,Token*,const char*,int); |
| 22515 | SQLITE_PRIVATE void sqlite3AlterSetNotNull(Parse*, SrcList*, Token*, Token*); |
| 22516 | SQLITE_PRIVATE i64 sqlite3GetToken(const unsigned char *, int *); |
| 22517 | SQLITE_PRIVATE void sqlite3NestedParse(Parse*, const char*, ...); |
| 22518 | SQLITE_PRIVATE void sqlite3ExpirePreparedStatements(sqlite3*, int); |
| 22519 | SQLITE_PRIVATE void sqlite3CodeRhsOfIN(Parse*, Expr*, int, int); |
| @@ -32413,12 +32453,14 @@ | |
| 32413 | #define etSRCITEM 12 /* a pointer to a SrcItem */ |
| 32414 | #define etPOINTER 13 /* The %p conversion */ |
| 32415 | #define etESCAPE_w 14 /* %w -> Strings with '\"' doubled */ |
| 32416 | #define etORDINAL 15 /* %r -> 1st, 2nd, 3rd, 4th, etc. English only */ |
| 32417 | #define etDECIMAL 16 /* %d or %u, but not %x, %o */ |
| 32418 | |
| 32419 | #define etINVALID 17 /* Any unrecognized conversion type */ |
| 32420 | |
| 32421 | |
| 32422 | /* |
| 32423 | ** An "etByte" is an 8-bit unsigned value. |
| 32424 | */ |
| @@ -32444,24 +32486,24 @@ | |
| 32444 | #define FLAG_SIGNED 1 /* True if the value to convert is signed */ |
| 32445 | #define FLAG_STRING 4 /* Allow infinite precision */ |
| 32446 | |
| 32447 | /* |
| 32448 | ** The table is searched by hash. In the case of %C where C is the character |
| 32449 | ** and that character has ASCII value j, then the hash is j%23. |
| 32450 | ** |
| 32451 | ** The order of the entries in fmtinfo[] and the hash chain was entered |
| 32452 | ** manually, but based on the output of the following TCL script: |
| 32453 | */ |
| 32454 | #if 0 /***** Beginning of script ******/ |
| 32455 | foreach c {d s g z q Q w c o u x X f e E G i n % p T S r} { |
| 32456 | scan $c %c x |
| 32457 | set n($c) $x |
| 32458 | } |
| 32459 | set mx [llength [array names n]] |
| 32460 | puts "count: $mx" |
| 32461 | |
| 32462 | set mx 27 |
| 32463 | puts "*********** mx=$mx ************" |
| 32464 | for {set r 0} {$r<$mx} {incr r} { |
| 32465 | puts -nonewline [format %2d: $r] |
| 32466 | foreach c [array names n] { |
| 32467 | if {($n($c))%$mx==$r} {puts -nonewline " $c"} |
| @@ -32469,35 +32511,38 @@ | |
| 32469 | puts "" |
| 32470 | } |
| 32471 | #endif /***** End of script ********/ |
| 32472 | |
| 32473 | static const char aDigits[] = "0123456789ABCDEF0123456789abcdef"; |
| 32474 | static const char aPrefix[] = "-x0\000X0"; |
| 32475 | static const et_info fmtinfo[23] = { |
| 32476 | /* 0 */ { 's', 0, 4, etSTRING, 0, 0, 1 }, |
| 32477 | /* 1 */ { 'E', 0, 1, etEXP, 14, 0, 0 }, /* Hash: 0 */ |
| 32478 | /* 2 */ { 'u', 10, 0, etDECIMAL, 0, 0, 3 }, |
| 32479 | /* 3 */ { 'G', 0, 1, etGENERIC, 14, 0, 0 }, /* Hash: 2 */ |
| 32480 | /* 4 */ { 'w', 0, 4, etESCAPE_w, 0, 0, 0 }, |
| 32481 | /* 5 */ { 'x', 16, 0, etRADIX, 16, 1, 0 }, |
| 32482 | /* 6 */ { 'c', 0, 0, etCHARX, 0, 0, 0 }, /* Hash: 7 */ |
| 32483 | /* 7 */ { 'z', 0, 4, etDYNSTRING, 0, 0, 6 }, |
| 32484 | /* 8 */ { 'd', 10, 1, etDECIMAL, 0, 0, 0 }, |
| 32485 | /* 9 */ { 'e', 0, 1, etEXP, 30, 0, 0 }, |
| 32486 | /* 10 */ { 'f', 0, 1, etFLOAT, 0, 0, 0 }, |
| 32487 | /* 11 */ { 'g', 0, 1, etGENERIC, 30, 0, 0 }, |
| 32488 | /* 12 */ { 'Q', 0, 4, etESCAPE_Q, 0, 0, 0 }, |
| 32489 | /* 13 */ { 'i', 10, 1, etDECIMAL, 0, 0, 0 }, |
| 32490 | /* 14 */ { '%', 0, 0, etPERCENT, 0, 0, 16 }, |
| 32491 | /* 15 */ { 'T', 0, 0, etTOKEN, 0, 0, 0 }, |
| 32492 | /* 16 */ { 'S', 0, 0, etSRCITEM, 0, 0, 0 }, /* Hash: 14 */ |
| 32493 | /* 17 */ { 'X', 16, 0, etRADIX, 0, 4, 0 }, /* Hash: 19 */ |
| 32494 | /* 18 */ { 'n', 0, 0, etSIZE, 0, 0, 0 }, |
| 32495 | /* 19 */ { 'o', 8, 0, etRADIX, 0, 2, 17 }, |
| 32496 | /* 20 */ { 'p', 16, 0, etPOINTER, 0, 1, 0 }, |
| 32497 | /* 21 */ { 'q', 0, 4, etESCAPE_q, 0, 0, 0 }, |
| 32498 | /* 22 */ { 'r', 10, 1, etORDINAL, 0, 0, 0 } |
| 32499 | }; |
| 32500 | |
| 32501 | /* Additional Notes: |
| 32502 | ** |
| 32503 | ** %S Takes a pointer to SrcItem. Shows name or database.name |
| @@ -32754,12 +32799,12 @@ | |
| 32754 | break; |
| 32755 | } |
| 32756 | } |
| 32757 | #else |
| 32758 | /* Fast hash-table lookup */ |
| 32759 | assert( ArraySize(fmtinfo)==23 ); |
| 32760 | idx = ((unsigned)c) % 23; |
| 32761 | if( fmtinfo[idx].fmttype==c |
| 32762 | || fmtinfo[idx = fmtinfo[idx].iNxt].fmttype==c |
| 32763 | ){ |
| 32764 | infop = &fmtinfo[idx]; |
| 32765 | xtype = infop->type; |
| @@ -33126,11 +33171,11 @@ | |
| 33126 | length = width; |
| 33127 | } |
| 33128 | |
| 33129 | if( zExtra==0 ){ |
| 33130 | /* The result is being rendered directory into pAccum. This |
| 33131 | ** is the command and fast case */ |
| 33132 | pAccum->nChar += length; |
| 33133 | zOut[length] = 0; |
| 33134 | continue; |
| 33135 | }else{ |
| 33136 | /* We were unable to render directly into pAccum because we |
| @@ -33246,10 +33291,87 @@ | |
| 33246 | /* Adjust width to account for extra bytes in UTF-8 characters */ |
| 33247 | int ii = length - 1; |
| 33248 | while( ii>=0 ) if( (bufpt[ii--] & 0xc0)==0x80 ) width++; |
| 33249 | } |
| 33250 | break; |
| 33251 | case etESCAPE_q: /* %q: Escape ' characters */ |
| 33252 | case etESCAPE_Q: /* %Q: Escape ' and enclose in '...' */ |
| 33253 | case etESCAPE_w: { /* %w: Escape " characters */ |
| 33254 | i64 i, j, k, n; |
| 33255 | int needQuote = 0; |
| @@ -33288,12 +33410,12 @@ | |
| 33288 | if( flag_alternateform ){ |
| 33289 | /* For %#q, do unistr()-style backslash escapes for |
| 33290 | ** all control characters, and for backslash itself. |
| 33291 | ** For %#Q, do the same but only if there is at least |
| 33292 | ** one control character. */ |
| 33293 | u32 nBack = 0; |
| 33294 | u32 nCtrl = 0; |
| 33295 | for(k=0; k<i; k++){ |
| 33296 | if( escarg[k]=='\\' ){ |
| 33297 | nBack++; |
| 33298 | }else if( ((u8*)escarg)[k]<=0x1f ){ |
| 33299 | nCtrl++; |
| @@ -33337,11 +33459,11 @@ | |
| 33337 | bufpt[j-1] = '\\'; |
| 33338 | bufpt[j++] = 'u'; |
| 33339 | bufpt[j++] = '0'; |
| 33340 | bufpt[j++] = '0'; |
| 33341 | bufpt[j++] = ch>=0x10 ? '1' : '0'; |
| 33342 | bufpt[j++] = "0123456789abcdef"[ch&0xf]; |
| 33343 | } |
| 33344 | } |
| 33345 | }else{ |
| 33346 | for(i=0; i<k; i++){ |
| 33347 | bufpt[j++] = ch = escarg[i]; |
| @@ -39154,10 +39276,26 @@ | |
| 39154 | ****************************************************************************** |
| 39155 | ** |
| 39156 | ** This file contains an experimental VFS layer that operates on a |
| 39157 | ** Key/Value storage engine where both keys and values must be pure |
| 39158 | ** text. |
| 39159 | */ |
| 39160 | /* #include <sqliteInt.h> */ |
| 39161 | #if SQLITE_OS_KV || (SQLITE_OS_UNIX && defined(SQLITE_OS_KV_OPTIONAL)) |
| 39162 | |
| 39163 | /***************************************************************************** |
| @@ -39606,16 +39744,18 @@ | |
| 39606 | } |
| 39607 | if( j+n>nOut ) return -1; |
| 39608 | memset(&aOut[j], 0, n); |
| 39609 | j += n; |
| 39610 | if( c==0 || mult==1 ) break; /* progress stalled if mult==1 */ |
| 39611 | }else{ |
| 39612 | aOut[j] = c<<4; |
| 39613 | c = kvvfsHexValue[aIn[++i]]; |
| 39614 | if( c<0 ) return -1 /* hex bytes are always in pairs */; |
| 39615 | aOut[j++] += c; |
| 39616 | i++; |
| 39617 | } |
| 39618 | } |
| 39619 | return j; |
| 39620 | } |
| 39621 | |
| @@ -40037,10 +40177,22 @@ | |
| 40037 | }else{ |
| 40038 | pFile->isJournal = 0; |
| 40039 | pFile->base.pMethods = &kvvfs_db_io_methods; |
| 40040 | } |
| 40041 | if( !pFile->zClass ){ |
| 40042 | pFile->zClass = zName; |
| 40043 | } |
| 40044 | pFile->aData = sqlite3_malloc64(SQLITE_KVOS_SZ); |
| 40045 | if( pFile->aData==0 ){ |
| 40046 | return SQLITE_NOMEM; |
| @@ -45345,13 +45497,13 @@ | |
| 45345 | |
| 45346 | /* Minimum number of regions required to be mapped. */ |
| 45347 | nReqRegion = ((iRegion+nShmPerMap) / nShmPerMap) * nShmPerMap; |
| 45348 | |
| 45349 | if( pShmNode->nRegion<nReqRegion ){ |
| 45350 | char **apNew; /* New apRegion[] array */ |
| 45351 | int nByte = nReqRegion*szRegion; /* Minimum required file size */ |
| 45352 | struct stat sStat; /* Used by fstat() */ |
| 45353 | |
| 45354 | pShmNode->szRegion = szRegion; |
| 45355 | |
| 45356 | if( pShmNode->hShm>=0 ){ |
| 45357 | /* The requested region is not mapped into this processes address space. |
| @@ -45378,11 +45530,11 @@ | |
| 45378 | ** pages forces the OS to allocate them immediately, which reduces |
| 45379 | ** the chances of SIGBUS while accessing the mapped region later on. |
| 45380 | */ |
| 45381 | else{ |
| 45382 | static const int pgsz = 4096; |
| 45383 | int iPg; |
| 45384 | |
| 45385 | /* Write to the last byte of each newly allocated or extended page */ |
| 45386 | assert( (nByte % pgsz)==0 ); |
| 45387 | for(iPg=(sStat.st_size/pgsz); iPg<(nByte/pgsz); iPg++){ |
| 45388 | int x = 0; |
| @@ -45404,12 +45556,12 @@ | |
| 45404 | rc = SQLITE_IOERR_NOMEM_BKPT; |
| 45405 | goto shmpage_out; |
| 45406 | } |
| 45407 | pShmNode->apRegion = apNew; |
| 45408 | while( pShmNode->nRegion<nReqRegion ){ |
| 45409 | int nMap = szRegion*nShmPerMap; |
| 45410 | int i; |
| 45411 | void *pMem; |
| 45412 | if( pShmNode->hShm>=0 ){ |
| 45413 | pMem = osMmap(0, nMap, |
| 45414 | pShmNode->isReadonly ? PROT_READ : PROT_READ|PROT_WRITE, |
| 45415 | MAP_SHARED, pShmNode->hShm, szRegion*(i64)pShmNode->nRegion |
| @@ -49195,107 +49347,154 @@ | |
| 49195 | |
| 49196 | { "CreateFileW", (SYSCALL)CreateFileW, 0 }, |
| 49197 | #define osCreateFileW ((HANDLE(WINAPI*)(LPCWSTR,DWORD,DWORD, \ |
| 49198 | LPSECURITY_ATTRIBUTES,DWORD,DWORD,HANDLE))aSyscall[2].pCurrent) |
| 49199 | |
| 49200 | { "CreateFileMappingW", (SYSCALL)CreateFileMappingW, 0 }, |
| 49201 | #define osCreateFileMappingW ((HANDLE(WINAPI*)(HANDLE,LPSECURITY_ATTRIBUTES, \ |
| 49202 | DWORD,DWORD,DWORD,LPCWSTR))aSyscall[3].pCurrent) |
| 49203 | |
| 49204 | { "DeleteFileW", (SYSCALL)DeleteFileW, 0 }, |
| 49205 | #define osDeleteFileW ((BOOL(WINAPI*)(LPCWSTR))aSyscall[4].pCurrent) |
| 49206 | |
| 49207 | { "FlushFileBuffers", (SYSCALL)FlushFileBuffers, 0 }, |
| 49208 | #define osFlushFileBuffers ((BOOL(WINAPI*)(HANDLE))aSyscall[5].pCurrent) |
| 49209 | |
| 49210 | { "FormatMessageW", (SYSCALL)FormatMessageW, 0 }, |
| 49211 | #define osFormatMessageW ((DWORD(WINAPI*)(DWORD,LPCVOID,DWORD,DWORD,LPWSTR, \ |
| 49212 | DWORD,va_list*))aSyscall[6].pCurrent) |
| 49213 | |
| 49214 | #if !defined(SQLITE_OMIT_LOAD_EXTENSION) |
| 49215 | { "FreeLibrary", (SYSCALL)FreeLibrary, 0 }, |
| 49216 | #else |
| 49217 | { "FreeLibrary", (SYSCALL)0, 0 }, |
| 49218 | #endif |
| 49219 | |
| 49220 | #define osFreeLibrary ((BOOL(WINAPI*)(HMODULE))aSyscall[7].pCurrent) |
| 49221 | |
| 49222 | { "GetCurrentProcessId", (SYSCALL)GetCurrentProcessId, 0 }, |
| 49223 | #define osGetCurrentProcessId ((DWORD(WINAPI*)(VOID))aSyscall[8].pCurrent) |
| 49224 | |
| 49225 | { "GetFileAttributesW", (SYSCALL)GetFileAttributesW, 0 }, |
| 49226 | #define osGetFileAttributesW ((DWORD(WINAPI*)(LPCWSTR))aSyscall[9].pCurrent) |
| 49227 | |
| 49228 | { "GetFileAttributesExW", (SYSCALL)GetFileAttributesExW, 0 }, |
| 49229 | #define osGetFileAttributesExW ((BOOL(WINAPI*)(LPCWSTR,GET_FILEEX_INFO_LEVELS, \ |
| 49230 | LPVOID))aSyscall[10].pCurrent) |
| 49231 | |
| 49232 | { "GetFileSize", (SYSCALL)GetFileSize, 0 }, |
| 49233 | #define osGetFileSize ((DWORD(WINAPI*)(HANDLE,LPDWORD))aSyscall[11].pCurrent) |
| 49234 | |
| 49235 | { "GetFullPathNameW", (SYSCALL)GetFullPathNameW, 0 }, |
| 49236 | #define osGetFullPathNameW ((DWORD(WINAPI*)(LPCWSTR,DWORD,LPWSTR, \ |
| 49237 | LPWSTR*))aSyscall[12].pCurrent) |
| 49238 | |
| 49239 | { "GetLastError", (SYSCALL)GetLastError, 0 }, |
| 49240 | #define osGetLastError ((DWORD(WINAPI*)(VOID))aSyscall[13].pCurrent) |
| 49241 | |
| 49242 | #if !defined(SQLITE_OMIT_LOAD_EXTENSION) |
| 49243 | { "GetProcAddressA", (SYSCALL)GetProcAddress, 0 }, |
| 49244 | #else |
| 49245 | { "GetProcAddressA", (SYSCALL)0, 0 }, |
| 49246 | #endif |
| 49247 | #define osGetProcAddressA ((FARPROC(WINAPI*)(HMODULE, \ |
| 49248 | LPCSTR))aSyscall[14].pCurrent) |
| 49249 | |
| 49250 | { "GetSystemInfo", (SYSCALL)GetSystemInfo, 0 }, |
| 49251 | #define osGetSystemInfo ((VOID(WINAPI*)(LPSYSTEM_INFO))aSyscall[15].pCurrent) |
| 49252 | |
| 49253 | { "GetSystemTime", (SYSCALL)GetSystemTime, 0 }, |
| 49254 | #define osGetSystemTime ((VOID(WINAPI*)(LPSYSTEMTIME))aSyscall[16].pCurrent) |
| 49255 | |
| 49256 | { "GetSystemTimeAsFileTime", (SYSCALL)GetSystemTimeAsFileTime, 0 }, |
| 49257 | #define osGetSystemTimeAsFileTime ((VOID(WINAPI*)( \ |
| 49258 | LPFILETIME))aSyscall[17].pCurrent) |
| 49259 | |
| 49260 | { "GetTempPathW", (SYSCALL)GetTempPathW, 0 }, |
| 49261 | #define osGetTempPathW ((DWORD(WINAPI*)(DWORD,LPWSTR))aSyscall[18].pCurrent) |
| 49262 | |
| 49263 | { "GetTickCount", (SYSCALL)GetTickCount, 0 }, |
| 49264 | #define osGetTickCount ((DWORD(WINAPI*)(VOID))aSyscall[19].pCurrent) |
| 49265 | |
| 49266 | { "HeapAlloc", (SYSCALL)HeapAlloc, 0 }, |
| 49267 | #define osHeapAlloc ((LPVOID(WINAPI*)(HANDLE,DWORD, \ |
| 49268 | SIZE_T))aSyscall[20].pCurrent) |
| 49269 | |
| 49270 | { "HeapCreate", (SYSCALL)HeapCreate, 0 }, |
| 49271 | #define osHeapCreate ((HANDLE(WINAPI*)(DWORD,SIZE_T, \ |
| 49272 | SIZE_T))aSyscall[21].pCurrent) |
| 49273 | |
| 49274 | { "HeapDestroy", (SYSCALL)HeapDestroy, 0 }, |
| 49275 | #define osHeapDestroy ((BOOL(WINAPI*)(HANDLE))aSyscall[22].pCurrent) |
| 49276 | |
| 49277 | { "HeapFree", (SYSCALL)HeapFree, 0 }, |
| 49278 | #define osHeapFree ((BOOL(WINAPI*)(HANDLE,DWORD,LPVOID))aSyscall[23].pCurrent) |
| 49279 | |
| 49280 | { "HeapReAlloc", (SYSCALL)HeapReAlloc, 0 }, |
| 49281 | #define osHeapReAlloc ((LPVOID(WINAPI*)(HANDLE,DWORD,LPVOID, \ |
| 49282 | SIZE_T))aSyscall[24].pCurrent) |
| 49283 | |
| 49284 | { "HeapSize", (SYSCALL)HeapSize, 0 }, |
| 49285 | #define osHeapSize ((SIZE_T(WINAPI*)(HANDLE,DWORD, \ |
| 49286 | LPCVOID))aSyscall[25].pCurrent) |
| 49287 | |
| 49288 | { "HeapValidate", (SYSCALL)HeapValidate, 0 }, |
| 49289 | #define osHeapValidate ((BOOL(WINAPI*)(HANDLE,DWORD, \ |
| 49290 | LPCVOID))aSyscall[26].pCurrent) |
| 49291 | |
| 49292 | { "HeapCompact", (SYSCALL)HeapCompact, 0 }, |
| 49293 | #define osHeapCompact ((UINT(WINAPI*)(HANDLE,DWORD))aSyscall[27].pCurrent) |
| 49294 | |
| 49295 | |
| 49296 | #if !defined(SQLITE_OMIT_LOAD_EXTENSION) |
| 49297 | { "LoadLibraryW", (SYSCALL)LoadLibraryW, 0 }, |
| 49298 | #else |
| 49299 | { "LoadLibraryW", (SYSCALL)0, 0 }, |
| 49300 | #endif |
| 49301 | #define osLoadLibraryW ((HMODULE(WINAPI*)(LPCWSTR))aSyscall[28].pCurrent) |
| @@ -49305,72 +49504,82 @@ | |
| 49305 | |
| 49306 | { "LockFileEx", (SYSCALL)LockFileEx, 0 }, |
| 49307 | #define osLockFileEx ((BOOL(WINAPI*)(HANDLE,DWORD,DWORD,DWORD,DWORD, \ |
| 49308 | LPOVERLAPPED))aSyscall[30].pCurrent) |
| 49309 | |
| 49310 | #if !defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0 |
| 49311 | { "MapViewOfFile", (SYSCALL)MapViewOfFile, 0 }, |
| 49312 | #else |
| 49313 | { "MapViewOfFile", (SYSCALL)0, 0 }, |
| 49314 | #endif |
| 49315 | #define osMapViewOfFile ((LPVOID(WINAPI*)(HANDLE,DWORD,DWORD,DWORD, \ |
| 49316 | SIZE_T))aSyscall[31].pCurrent) |
| 49317 | |
| 49318 | { "MultiByteToWideChar", (SYSCALL)MultiByteToWideChar, 0 }, |
| 49319 | #define osMultiByteToWideChar ((int(WINAPI*)(UINT,DWORD,LPCSTR,int,LPWSTR, \ |
| 49320 | int))aSyscall[32].pCurrent) |
| 49321 | |
| 49322 | { "QueryPerformanceCounter", (SYSCALL)QueryPerformanceCounter, 0 }, |
| 49323 | #define osQueryPerformanceCounter ((BOOL(WINAPI*)( \ |
| 49324 | LARGE_INTEGER*))aSyscall[33].pCurrent) |
| 49325 | |
| 49326 | { "ReadFile", (SYSCALL)ReadFile, 0 }, |
| 49327 | #define osReadFile ((BOOL(WINAPI*)(HANDLE,LPVOID,DWORD,LPDWORD, \ |
| 49328 | LPOVERLAPPED))aSyscall[34].pCurrent) |
| 49329 | |
| 49330 | { "SetEndOfFile", (SYSCALL)SetEndOfFile, 0 }, |
| 49331 | #define osSetEndOfFile ((BOOL(WINAPI*)(HANDLE))aSyscall[35].pCurrent) |
| 49332 | |
| 49333 | { "SetFilePointer", (SYSCALL)SetFilePointer, 0 }, |
| 49334 | #define osSetFilePointer ((DWORD(WINAPI*)(HANDLE,LONG,PLONG, \ |
| 49335 | DWORD))aSyscall[36].pCurrent) |
| 49336 | |
| 49337 | { "Sleep", (SYSCALL)Sleep, 0 }, |
| 49338 | #define osSleep ((VOID(WINAPI*)(DWORD))aSyscall[37].pCurrent) |
| 49339 | |
| 49340 | { "UnlockFileEx", (SYSCALL)UnlockFileEx, 0 }, |
| 49341 | #define osUnlockFileEx ((BOOL(WINAPI*)(HANDLE,DWORD,DWORD,DWORD, \ |
| 49342 | LPOVERLAPPED))aSyscall[38].pCurrent) |
| 49343 | |
| 49344 | #if !defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0 |
| 49345 | { "UnmapViewOfFile", (SYSCALL)UnmapViewOfFile, 0 }, |
| 49346 | #else |
| 49347 | { "UnmapViewOfFile", (SYSCALL)0, 0 }, |
| 49348 | #endif |
| 49349 | #define osUnmapViewOfFile ((BOOL(WINAPI*)(LPCVOID))aSyscall[39].pCurrent) |
| 49350 | |
| 49351 | { "WideCharToMultiByte", (SYSCALL)WideCharToMultiByte, 0 }, |
| 49352 | #define osWideCharToMultiByte ((int(WINAPI*)(UINT,DWORD,LPCWSTR,int,LPSTR,int, \ |
| 49353 | LPCSTR,LPBOOL))aSyscall[40].pCurrent) |
| 49354 | |
| 49355 | { "WriteFile", (SYSCALL)WriteFile, 0 }, |
| 49356 | #define osWriteFile ((BOOL(WINAPI*)(HANDLE,LPCVOID,DWORD,LPDWORD, \ |
| 49357 | LPOVERLAPPED))aSyscall[41].pCurrent) |
| 49358 | |
| 49359 | { "WaitForSingleObject", (SYSCALL)WaitForSingleObject, 0 }, |
| 49360 | #define osWaitForSingleObject ((DWORD(WINAPI*)(HANDLE, \ |
| 49361 | DWORD))aSyscall[42].pCurrent) |
| 49362 | |
| 49363 | { "WaitForSingleObjectEx", (SYSCALL)WaitForSingleObjectEx, 0 }, |
| 49364 | #define osWaitForSingleObjectEx ((DWORD(WINAPI*)(HANDLE,DWORD, \ |
| 49365 | BOOL))aSyscall[43].pCurrent) |
| 49366 | |
| 49367 | { "OutputDebugStringA", (SYSCALL)OutputDebugStringA, 0 }, |
| 49368 | #define osOutputDebugStringA ((VOID(WINAPI*)(LPCSTR))aSyscall[44].pCurrent) |
| 49369 | |
| 49370 | { "GetProcessHeap", (SYSCALL)GetProcessHeap, 0 }, |
| 49371 | #define osGetProcessHeap ((HANDLE(WINAPI*)(VOID))aSyscall[45].pCurrent) |
| 49372 | |
| 49373 | /* |
| 49374 | ** NOTE: On some sub-platforms, the InterlockedCompareExchange "function" |
| 49375 | ** is really just a macro that uses a compiler intrinsic (e.g. x64). |
| 49376 | ** So do not try to make this is into a redefinable interface. |
| @@ -49379,95 +49588,93 @@ | |
| 49379 | { "InterlockedCompareExchange", (SYSCALL)0, 0 }, |
| 49380 | #define osInterlockedCompareExchange InterlockedCompareExchange |
| 49381 | #else |
| 49382 | { "InterlockedCompareExchange", (SYSCALL)InterlockedCompareExchange, 0 }, |
| 49383 | #define osInterlockedCompareExchange ((LONG(WINAPI*)(LONG volatile*,\ |
| 49384 | LONG,LONG))aSyscall[46].pCurrent) |
| 49385 | #endif /* defined(InterlockedCompareExchange) */ |
| 49386 | |
| 49387 | #if SQLITE_WIN32_USE_UUID |
| 49388 | { "UuidCreate", (SYSCALL)UuidCreate, 0 }, |
| 49389 | #else |
| 49390 | { "UuidCreate", (SYSCALL)0, 0 }, |
| 49391 | #endif |
| 49392 | #define osUuidCreate ((RPC_STATUS(RPC_ENTRY*)(UUID*))aSyscall[47].pCurrent) |
| 49393 | |
| 49394 | #if SQLITE_WIN32_USE_UUID |
| 49395 | { "UuidCreateSequential", (SYSCALL)UuidCreateSequential, 0 }, |
| 49396 | #else |
| 49397 | { "UuidCreateSequential", (SYSCALL)0, 0 }, |
| 49398 | #endif |
| 49399 | #define osUuidCreateSequential \ |
| 49400 | ((RPC_STATUS(RPC_ENTRY*)(UUID*))aSyscall[48].pCurrent) |
| 49401 | |
| 49402 | #if !defined(SQLITE_NO_SYNC) && SQLITE_MAX_MMAP_SIZE>0 |
| 49403 | { "FlushViewOfFile", (SYSCALL)FlushViewOfFile, 0 }, |
| 49404 | #else |
| 49405 | { "FlushViewOfFile", (SYSCALL)0, 0 }, |
| 49406 | #endif |
| 49407 | #define osFlushViewOfFile \ |
| 49408 | ((BOOL(WINAPI*)(LPCVOID,SIZE_T))aSyscall[49].pCurrent) |
| 49409 | |
| 49410 | #ifdef SQLITE_ENABLE_SETLK_TIMEOUT |
| 49411 | { "CreateEvent", (SYSCALL)CreateEvent, 0 }, |
| 49412 | #else |
| 49413 | { "CreateEvent", (SYSCALL)0, 0 }, |
| 49414 | #endif |
| 49415 | #define osCreateEvent ( \ |
| 49416 | (HANDLE(WINAPI*) (LPSECURITY_ATTRIBUTES,BOOL,BOOL,LPCSTR)) \ |
| 49417 | aSyscall[50].pCurrent \ |
| 49418 | ) |
| 49419 | |
| 49420 | #ifdef SQLITE_ENABLE_SETLK_TIMEOUT |
| 49421 | { "CancelIo", (SYSCALL)CancelIo, 0 }, |
| 49422 | #else |
| 49423 | { "CancelIo", (SYSCALL)0, 0 }, |
| 49424 | #endif |
| 49425 | #define osCancelIo ((BOOL(WINAPI*)(HANDLE))aSyscall[51].pCurrent) |
| 49426 | |
| 49427 | #ifndef _WIN32 |
| 49428 | { "getenv", (SYSCALL)getenv, 0 }, |
| 49429 | #else |
| 49430 | { "getenv", (SYSCALL)0, 0 }, |
| 49431 | #endif |
| 49432 | #define osGetenv ((const char *(*)(const char *))aSyscall[52].pCurrent) |
| 49433 | |
| 49434 | #ifndef _WIN32 |
| 49435 | { "getcwd", (SYSCALL)getcwd, 0 }, |
| 49436 | #else |
| 49437 | { "getcwd", (SYSCALL)0, 0 }, |
| 49438 | #endif |
| 49439 | #define osGetcwd ((char*(*)(char*,size_t))aSyscall[53].pCurrent) |
| 49440 | |
| 49441 | #ifndef _WIN32 |
| 49442 | { "readlink", (SYSCALL)readlink, 0 }, |
| 49443 | #else |
| 49444 | { "readlink", (SYSCALL)0, 0 }, |
| 49445 | #endif |
| 49446 | #define osReadlink ((ssize_t(*)(const char*,char*,size_t))aSyscall[54].pCurrent) |
| 49447 | |
| 49448 | #ifndef _WIN32 |
| 49449 | { "lstat", (SYSCALL)lstat, 0 }, |
| 49450 | #else |
| 49451 | { "lstat", (SYSCALL)0, 0 }, |
| 49452 | #endif |
| 49453 | #define osLstat ((int(*)(const char*,struct stat*))aSyscall[55].pCurrent) |
| 49454 | |
| 49455 | #ifndef _WIN32 |
| 49456 | { "__errno", (SYSCALL)__errno, 0 }, |
| 49457 | #else |
| 49458 | { "__errno", (SYSCALL)0, 0 }, |
| 49459 | #endif |
| 49460 | #define osErrno (*((int*(*)(void))aSyscall[56].pCurrent)()) |
| 49461 | |
| 49462 | #ifndef _WIN32 |
| 49463 | { "cygwin_conv_path", (SYSCALL)cygwin_conv_path, 0 }, |
| 49464 | #else |
| 49465 | { "cygwin_conv_path", (SYSCALL)0, 0 }, |
| 49466 | #endif |
| 49467 | #define osCygwin_conv_path ((size_t(*)(unsigned int, \ |
| 49468 | const void *, void *, size_t))aSyscall[57].pCurrent) |
| 49469 | |
| 49470 | }; /* End of the overrideable system calls */ |
| 49471 | |
| 49472 | /* |
| 49473 | ** This is the xSetSystemCall() method of sqlite3_vfs for all of the |
| @@ -49551,10 +49758,13 @@ | |
| 49551 | } |
| 49552 | return 0; |
| 49553 | } |
| 49554 | |
| 49555 | #ifdef SQLITE_WIN32_MALLOC |
| 49556 | /* |
| 49557 | ** If a Win32 native heap has been configured, this function will attempt to |
| 49558 | ** compact it. Upon success, SQLITE_OK will be returned. Upon failure, one |
| 49559 | ** of SQLITE_NOMEM, SQLITE_ERROR, or SQLITE_NOTFOUND will be returned. The |
| 49560 | ** "pnLargest" argument, if non-zero, will be used to return the size of the |
| @@ -50509,31 +50719,15 @@ | |
| 50509 | ** If successful, return SQLITE_OK. Or, if an error occurs, return an SQLite |
| 50510 | ** error code. |
| 50511 | */ |
| 50512 | static int winHandleSeek(HANDLE h, sqlite3_int64 iOffset){ |
| 50513 | int rc = SQLITE_OK; /* Return value */ |
| 50514 | |
| 50515 | LONG upperBits; /* Most sig. 32 bits of new offset */ |
| 50516 | LONG lowerBits; /* Least sig. 32 bits of new offset */ |
| 50517 | DWORD dwRet; /* Value returned by SetFilePointer() */ |
| 50518 | |
| 50519 | upperBits = (LONG)((iOffset>>32) & 0x7fffffff); |
| 50520 | lowerBits = (LONG)(iOffset & 0xffffffff); |
| 50521 | |
| 50522 | dwRet = osSetFilePointer(h, lowerBits, &upperBits, FILE_BEGIN); |
| 50523 | |
| 50524 | /* API oddity: If successful, SetFilePointer() returns a dword |
| 50525 | ** containing the lower 32-bits of the new file-offset. Or, if it fails, |
| 50526 | ** it returns INVALID_SET_FILE_POINTER. However according to MSDN, |
| 50527 | ** INVALID_SET_FILE_POINTER may also be a valid new offset. So to determine |
| 50528 | ** whether an error has actually occurred, it is also necessary to call |
| 50529 | ** GetLastError(). */ |
| 50530 | if( dwRet==INVALID_SET_FILE_POINTER ){ |
| 50531 | DWORD lastErrno = osGetLastError(); |
| 50532 | if( lastErrno!=NO_ERROR ){ |
| 50533 | rc = SQLITE_IOERR_SEEK; |
| 50534 | } |
| 50535 | } |
| 50536 | OSTRACE(("SEEK file=%p, offset=%lld rc=%s\n", h, iOffset,sqlite3ErrName(rc))); |
| 50537 | return rc; |
| 50538 | } |
| 50539 | |
| @@ -50812,18 +51006,17 @@ | |
| 50812 | ** Determine the size in bytes of the file opened by the handle passed as |
| 50813 | ** the first argument. |
| 50814 | */ |
| 50815 | static int winHandleSize(HANDLE h, sqlite3_int64 *pnByte){ |
| 50816 | int rc = SQLITE_OK; |
| 50817 | DWORD upperBits = 0; |
| 50818 | DWORD lowerBits = 0; |
| 50819 | |
| 50820 | assert( pnByte ); |
| 50821 | lowerBits = osGetFileSize(h, &upperBits); |
| 50822 | *pnByte = (((sqlite3_int64)upperBits)<<32) + lowerBits; |
| 50823 | if( lowerBits==INVALID_FILE_SIZE && osGetLastError()!=NO_ERROR ){ |
| 50824 | rc = SQLITE_IOERR_FSTAT; |
| 50825 | } |
| 50826 | return rc; |
| 50827 | } |
| 50828 | |
| 50829 | /* |
| @@ -51020,21 +51213,18 @@ | |
| 51020 | assert( id!=0 ); |
| 51021 | assert( pSize!=0 ); |
| 51022 | SimulateIOError(return SQLITE_IOERR_FSTAT); |
| 51023 | OSTRACE(("SIZE file=%p, pSize=%p\n", pFile->h, pSize)); |
| 51024 | { |
| 51025 | DWORD upperBits; |
| 51026 | DWORD lowerBits; |
| 51027 | DWORD lastErrno; |
| 51028 | |
| 51029 | lowerBits = osGetFileSize(pFile->h, &upperBits); |
| 51030 | *pSize = (((sqlite3_int64)upperBits)<<32) + lowerBits; |
| 51031 | if( (lowerBits == INVALID_FILE_SIZE) |
| 51032 | && ((lastErrno = osGetLastError())!=NO_ERROR) ){ |
| 51033 | pFile->lastErrno = lastErrno; |
| 51034 | rc = winLogError(SQLITE_IOERR_FSTAT, pFile->lastErrno, |
| 51035 | "winFileSize", pFile->zPath); |
| 51036 | } |
| 51037 | } |
| 51038 | OSTRACE(("SIZE file=%p, pSize=%p, *pSize=%lld, rc=%s\n", |
| 51039 | pFile->h, pSize, *pSize, sqlite3ErrName(rc))); |
| 51040 | return rc; |
| @@ -52031,15 +52221,33 @@ | |
| 52031 | # define sqlite3_win_test_unc_locking 0 |
| 52032 | #endif |
| 52033 | |
| 52034 | /* |
| 52035 | ** Return true if the string passed as the only argument is likely |
| 52036 | ** to be a UNC path. In other words, if it starts with "\\". |
| 52037 | */ |
| 52038 | static int winIsUNCPath(const char *zFile){ |
| 52039 | if( zFile[0]=='\\' && zFile[1]=='\\' ){ |
| 52040 | return 1; |
| 52041 | } |
| 52042 | return sqlite3_win_test_unc_locking; |
| 52043 | } |
| 52044 | |
| 52045 | /* |
| @@ -52373,11 +52581,11 @@ | |
| 52373 | |
| 52374 | assert( szRegion==pShmNode->szRegion || pShmNode->nRegion==0 ); |
| 52375 | if( pShmNode->nRegion<=iRegion ){ |
| 52376 | HANDLE hShared = pShmNode->hSharedShm; |
| 52377 | struct ShmRegion *apNew; /* New aRegion[] array */ |
| 52378 | int nByte = (iRegion+1)*szRegion; /* Minimum required file size */ |
| 52379 | sqlite3_int64 sz; /* Current size of wal-index file */ |
| 52380 | |
| 52381 | pShmNode->szRegion = szRegion; |
| 52382 | |
| 52383 | /* The requested region is not mapped into this processes address space. |
| @@ -52404,11 +52612,11 @@ | |
| 52404 | } |
| 52405 | } |
| 52406 | |
| 52407 | /* Map the requested memory region into this processes address space. */ |
| 52408 | apNew = (struct ShmRegion*)sqlite3_realloc64( |
| 52409 | pShmNode->aRegion, (iRegion+1)*sizeof(apNew[0]) |
| 52410 | ); |
| 52411 | if( !apNew ){ |
| 52412 | rc = SQLITE_IOERR_NOMEM_BKPT; |
| 52413 | goto shmpage_out; |
| 52414 | } |
| @@ -52421,20 +52629,30 @@ | |
| 52421 | |
| 52422 | while( pShmNode->nRegion<=iRegion ){ |
| 52423 | HANDLE hMap = NULL; /* file-mapping handle */ |
| 52424 | void *pMap = 0; /* Mapped memory region */ |
| 52425 | |
| 52426 | hMap = osCreateFileMappingW(hShared, NULL, protect, 0, nByte, NULL); |
| 52427 | OSTRACE(("SHM-MAP-CREATE pid=%lu, region=%d, size=%d, rc=%s\n", |
| 52428 | osGetCurrentProcessId(), pShmNode->nRegion, nByte, |
| 52429 | hMap ? "ok" : "failed")); |
| 52430 | if( hMap ){ |
| 52431 | int iOffset = pShmNode->nRegion*szRegion; |
| 52432 | int iOffsetShift = iOffset % winSysInfo.dwAllocationGranularity; |
| 52433 | pMap = osMapViewOfFile(hMap, flags, |
| 52434 | 0, iOffset - iOffsetShift, szRegion + iOffsetShift |
| 52435 | ); |
| 52436 | OSTRACE(("SHM-MAP-MAP pid=%lu, region=%d, offset=%d, size=%d, rc=%s\n", |
| 52437 | osGetCurrentProcessId(), pShmNode->nRegion, iOffset, |
| 52438 | szRegion, pMap ? "ok" : "failed")); |
| 52439 | } |
| 52440 | if( !pMap ){ |
| @@ -52451,11 +52669,11 @@ | |
| 52451 | } |
| 52452 | } |
| 52453 | |
| 52454 | shmpage_out: |
| 52455 | if( pShmNode->nRegion>iRegion ){ |
| 52456 | int iOffset = iRegion*szRegion; |
| 52457 | int iOffsetShift = iOffset % winSysInfo.dwAllocationGranularity; |
| 52458 | char *p = (char *)pShmNode->aRegion[iRegion].pMap; |
| 52459 | *pp = (void *)&p[iOffsetShift]; |
| 52460 | }else{ |
| 52461 | *pp = 0; |
| @@ -52563,13 +52781,17 @@ | |
| 52563 | if( (pFd->ctrlFlags & WINFILE_RDONLY)==0 ){ |
| 52564 | protect = PAGE_READWRITE; |
| 52565 | flags |= FILE_MAP_WRITE; |
| 52566 | } |
| 52567 | #endif |
| 52568 | pFd->hMap = osCreateFileMappingW(pFd->h, NULL, protect, |
| 52569 | (DWORD)((nMap>>32) & 0xffffffff), |
| 52570 | (DWORD)(nMap & 0xffffffff), NULL); |
| 52571 | if( pFd->hMap==NULL ){ |
| 52572 | pFd->lastErrno = osGetLastError(); |
| 52573 | rc = winLogError(SQLITE_IOERR_MMAP, pFd->lastErrno, |
| 52574 | "winMapfile1", pFd->zPath); |
| 52575 | /* Log the error, but continue normal operation using xRead/xWrite */ |
| @@ -52577,11 +52799,15 @@ | |
| 52577 | osGetCurrentProcessId(), pFd, sqlite3ErrName(rc))); |
| 52578 | return SQLITE_OK; |
| 52579 | } |
| 52580 | assert( (nMap % winSysInfo.dwPageSize)==0 ); |
| 52581 | assert( sizeof(SIZE_T)==sizeof(sqlite3_int64) || nMap<=0xffffffff ); |
| 52582 | pNew = osMapViewOfFile(pFd->hMap, flags, 0, 0, (SIZE_T)nMap); |
| 52583 | if( pNew==NULL ){ |
| 52584 | osCloseHandle(pFd->hMap); |
| 52585 | pFd->hMap = NULL; |
| 52586 | pFd->lastErrno = osGetLastError(); |
| 52587 | rc = winLogError(SQLITE_IOERR_MMAP, pFd->lastErrno, |
| @@ -52920,11 +53146,11 @@ | |
| 52920 | if( !zWidePath ){ |
| 52921 | sqlite3_free(zBuf); |
| 52922 | OSTRACE(("TEMP-FILENAME rc=SQLITE_IOERR_NOMEM\n")); |
| 52923 | return SQLITE_IOERR_NOMEM_BKPT; |
| 52924 | } |
| 52925 | if( osGetTempPathW(nMax, zWidePath)==0 ){ |
| 52926 | sqlite3_free(zWidePath); |
| 52927 | sqlite3_free(zBuf); |
| 52928 | OSTRACE(("TEMP-FILENAME rc=SQLITE_IOERR_GETTEMPPATH\n")); |
| 52929 | return winLogError(SQLITE_IOERR_GETTEMPPATH, osGetLastError(), |
| 52930 | "winGetTempname2", 0); |
| @@ -53723,37 +53949,37 @@ | |
| 53723 | /* |
| 53724 | ** Interfaces for opening a shared library, finding entry points |
| 53725 | ** within the shared library, and closing the shared library. |
| 53726 | */ |
| 53727 | static void *winDlOpen(sqlite3_vfs *pVfs, const char *zFilename){ |
| 53728 | HANDLE h; |
| 53729 | void *zConverted = winConvertFromUtf8Filename(zFilename); |
| 53730 | UNUSED_PARAMETER(pVfs); |
| 53731 | if( zConverted==0 ){ |
| 53732 | OSTRACE(("DLOPEN name=%s, handle=%p\n", zFilename, (void*)0)); |
| 53733 | return 0; |
| 53734 | } |
| 53735 | h = osLoadLibraryW((LPCWSTR)zConverted); |
| 53736 | OSTRACE(("DLOPEN name=%s, handle=%p\n", zFilename, (void*)h)); |
| 53737 | sqlite3_free(zConverted); |
| 53738 | return (void*)h; |
| 53739 | } |
| 53740 | static void winDlError(sqlite3_vfs *pVfs, int nBuf, char *zBufOut){ |
| 53741 | UNUSED_PARAMETER(pVfs); |
| 53742 | winGetLastErrorMsg(osGetLastError(), nBuf, zBufOut); |
| 53743 | } |
| 53744 | static void (*winDlSym(sqlite3_vfs *pVfs,void *pH,const char *zSym))(void){ |
| 53745 | FARPROC proc; |
| 53746 | UNUSED_PARAMETER(pVfs); |
| 53747 | proc = osGetProcAddressA((HANDLE)pH, zSym); |
| 53748 | OSTRACE(("DLSYM handle=%p, symbol=%s, address=%p\n", |
| 53749 | (void*)pH, zSym, (void*)proc)); |
| 53750 | return (void(*)(void))proc; |
| 53751 | } |
| 53752 | static void winDlClose(sqlite3_vfs *pVfs, void *pHandle){ |
| 53753 | UNUSED_PARAMETER(pVfs); |
| 53754 | osFreeLibrary((HANDLE)pHandle); |
| 53755 | OSTRACE(("DLCLOSE handle=%p\n", (void*)pHandle)); |
| 53756 | } |
| 53757 | #else /* if SQLITE_OMIT_LOAD_EXTENSION is defined: */ |
| 53758 | #define winDlOpen 0 |
| 53759 | #define winDlError 0 |
| @@ -53798,36 +54024,39 @@ | |
| 53798 | e.a = (unsigned char*)zBuf; |
| 53799 | e.na = nBuf; |
| 53800 | e.nXor = 0; |
| 53801 | e.i = 0; |
| 53802 | { |
| 53803 | SYSTEMTIME x; |
| 53804 | osGetSystemTime(&x); |
| 53805 | xorMemory(&e, (unsigned char*)&x, sizeof(SYSTEMTIME)); |
| 53806 | } |
| 53807 | { |
| 53808 | DWORD pid = osGetCurrentProcessId(); |
| 53809 | xorMemory(&e, (unsigned char*)&pid, sizeof(DWORD)); |
| 53810 | } |
| 53811 | { |
| 53812 | DWORD cnt = osGetTickCount(); |
| 53813 | xorMemory(&e, (unsigned char*)&cnt, sizeof(DWORD)); |
| 53814 | } |
| 53815 | { |
| 53816 | LARGE_INTEGER i; |
| 53817 | osQueryPerformanceCounter(&i); |
| 53818 | xorMemory(&e, (unsigned char*)&i, sizeof(LARGE_INTEGER)); |
| 53819 | } |
| 53820 | #if SQLITE_WIN32_USE_UUID |
| 53821 | { |
| 53822 | UUID id; |
| 53823 | memset(&id, 0, sizeof(UUID)); |
| 53824 | osUuidCreate(&id); |
| 53825 | xorMemory(&e, (unsigned char*)&id, sizeof(UUID)); |
| 53826 | memset(&id, 0, sizeof(UUID)); |
| 53827 | osUuidCreateSequential(&id); |
| 53828 | xorMemory(&e, (unsigned char*)&id, sizeof(UUID)); |
| 53829 | } |
| 53830 | #endif /* SQLITE_WIN32_USE_UUID */ |
| 53831 | return e.nXor>nBuf ? nBuf : e.nXor; |
| 53832 | #endif /* defined(SQLITE_TEST) || defined(SQLITE_OMIT_RANDOMNESS) */ |
| 53833 | } |
| @@ -54042,15 +54271,19 @@ | |
| 54042 | winNextSystemCall, /* xNextSystemCall */ |
| 54043 | }; |
| 54044 | |
| 54045 | /* Double-check that the aSyscall[] array has been constructed |
| 54046 | ** correctly. See ticket [bb3a86e890c8e96ab] */ |
| 54047 | assert( ArraySize(aSyscall)==58 ); |
| 54048 | assert( strcmp(aSyscall[0].zName,"AreFileApisANSI")==0 ); |
| 54049 | assert( strcmp(aSyscall[20].zName,"HeapAlloc")==0 ); |
| 54050 | assert( strcmp(aSyscall[40].zName,"WideCharToMultiByte")==0 ); |
| 54051 | assert( strcmp(aSyscall[57].zName,"cygwin_conv_path")==0 ); |
| 54052 | |
| 54053 | /* get memory map allocation granularity */ |
| 54054 | memset(&winSysInfo, 0, sizeof(SYSTEM_INFO)); |
| 54055 | osGetSystemInfo(&winSysInfo); |
| 54056 | assert( winSysInfo.dwAllocationGranularity>0 ); |
| @@ -56762,26 +56995,28 @@ | |
| 56762 | szBulk = -1024 * (i64)pcache1.nInitPage; |
| 56763 | } |
| 56764 | if( szBulk > pCache->szAlloc*(i64)pCache->nMax ){ |
| 56765 | szBulk = pCache->szAlloc*(i64)pCache->nMax; |
| 56766 | } |
| 56767 | zBulk = pCache->pBulk = sqlite3Malloc( szBulk ); |
| 56768 | sqlite3EndBenignMalloc(); |
| 56769 | if( zBulk ){ |
| 56770 | int nBulk = sqlite3MallocSize(zBulk)/pCache->szAlloc; |
| 56771 | do{ |
| 56772 | PgHdr1 *pX = (PgHdr1*)&zBulk[pCache->szPage]; |
| 56773 | pX->page.pBuf = zBulk; |
| 56774 | pX->page.pExtra = (u8*)pX + ROUND8(sizeof(*pX)); |
| 56775 | assert( EIGHT_BYTE_ALIGNMENT( pX->page.pExtra ) ); |
| 56776 | pX->isBulkLocal = 1; |
| 56777 | pX->isAnchor = 0; |
| 56778 | pX->pNext = pCache->pFree; |
| 56779 | pX->pLruPrev = 0; /* Initializing this saves a valgrind error */ |
| 56780 | pCache->pFree = pX; |
| 56781 | zBulk += pCache->szAlloc; |
| 56782 | }while( --nBulk ); |
| 56783 | } |
| 56784 | return pCache->pFree!=0; |
| 56785 | } |
| 56786 | |
| 56787 | /* |
| @@ -59675,73 +59910,84 @@ | |
| 59675 | #define pager_set_pagehash(X) |
| 59676 | #define CHECK_PAGE(x) |
| 59677 | #endif /* SQLITE_CHECK_PAGES */ |
| 59678 | |
| 59679 | /* |
| 59680 | ** When this is called the journal file for pager pPager must be open. |
| 59681 | ** This function attempts to read a super-journal file name from the |
| 59682 | ** end of the file and, if successful, copies it into memory supplied |
| 59683 | ** by the caller. See comments above writeSuperJournal() for the format |
| 59684 | ** used to store a super-journal file name at the end of a journal file. |
| 59685 | ** |
| 59686 | ** zSuper must point to a buffer of at least nSuper bytes allocated by |
| 59687 | ** the caller. This should be sqlite3_vfs.mxPathname+1 (to ensure there is |
| 59688 | ** enough space to write the super-journal name). If the super-journal |
| 59689 | ** name in the journal is longer than nSuper bytes (including a |
| 59690 | ** nul-terminator), then this is handled as if no super-journal name |
| 59691 | ** were present in the journal. |
| 59692 | ** |
| 59693 | ** If a super-journal file name is present at the end of the journal |
| 59694 | ** file, then it is copied into the buffer pointed to by zSuper. A |
| 59695 | ** nul-terminator byte is appended to the buffer following the |
| 59696 | ** super-journal file name. |
| 59697 | ** |
| 59698 | ** If it is determined that no super-journal file name is present |
| 59699 | ** zSuper[0] is set to 0 and SQLITE_OK returned. |
| 59700 | ** |
| 59701 | ** If an error occurs while reading from the journal file, an SQLite |
| 59702 | ** error code is returned. |
| 59703 | */ |
| 59704 | static int readSuperJournal(sqlite3_file *pJrnl, char *zSuper, u64 nSuper){ |
| 59705 | int rc; /* Return code */ |
| 59706 | u32 len; /* Length in bytes of super-journal name */ |
| 59707 | i64 szJ; /* Total size in bytes of journal file pJrnl */ |
| 59708 | u32 cksum; /* MJ checksum value read from journal */ |
| 59709 | u32 u; /* Unsigned loop counter */ |
| 59710 | unsigned char aMagic[8]; /* A buffer to hold the magic header */ |
| 59711 | zSuper[0] = '\0'; |
| 59712 | |
| 59713 | if( SQLITE_OK!=(rc = sqlite3OsFileSize(pJrnl, &szJ)) |
| 59714 | || szJ<16 |
| 59715 | || SQLITE_OK!=(rc = read32bits(pJrnl, szJ-16, &len)) |
| 59716 | || len>=nSuper |
| 59717 | || len>szJ-16 |
| 59718 | || len==0 |
| 59719 | || SQLITE_OK!=(rc = read32bits(pJrnl, szJ-12, &cksum)) |
| 59720 | || SQLITE_OK!=(rc = sqlite3OsRead(pJrnl, aMagic, 8, szJ-8)) |
| 59721 | || memcmp(aMagic, aJournalMagic, 8) |
| 59722 | || SQLITE_OK!=(rc = sqlite3OsRead(pJrnl, zSuper, len, szJ-16-len)) |
| 59723 | ){ |
| 59724 | return rc; |
| 59725 | } |
| 59726 | |
| 59727 | /* See if the checksum matches the super-journal name */ |
| 59728 | for(u=0; u<len; u++){ |
| 59729 | cksum -= zSuper[u]; |
| 59730 | } |
| 59731 | if( cksum ){ |
| 59732 | /* If the checksum doesn't add up, then one or more of the disk sectors |
| 59733 | ** containing the super-journal filename is corrupted. This means |
| 59734 | ** definitely roll back, so just return SQLITE_OK and report a (nul) |
| 59735 | ** super-journal filename. |
| 59736 | */ |
| 59737 | len = 0; |
| 59738 | } |
| 59739 | zSuper[len] = '\0'; |
| 59740 | zSuper[len+1] = '\0'; |
| 59741 | |
| 59742 | return SQLITE_OK; |
| 59743 | } |
| 59744 | |
| 59745 | /* |
| 59746 | ** Return the offset of the sector boundary at or immediately |
| 59747 | ** following the value in pPager->journalOff, assuming a sector |
| @@ -60942,13 +61188,11 @@ | |
| 60942 | sqlite3_file *pSuper; /* Malloc'd super-journal file descriptor */ |
| 60943 | sqlite3_file *pJournal; /* Malloc'd child-journal file descriptor */ |
| 60944 | char *zSuperJournal = 0; /* Contents of super-journal file */ |
| 60945 | i64 nSuperJournal; /* Size of super-journal file */ |
| 60946 | char *zJournal; /* Pointer to one journal within MJ file */ |
| 60947 | char *zSuperPtr; /* Space to hold super-journal filename */ |
| 60948 | char *zFree = 0; /* Free this buffer */ |
| 60949 | i64 nSuperPtr; /* Amount of space allocated to zSuperPtr[] */ |
| 60950 | |
| 60951 | /* Allocate space for both the pJournal and pSuper file descriptors. |
| 60952 | ** If successful, open the super-journal file for reading. |
| 60953 | */ |
| 60954 | pSuper = (sqlite3_file *)sqlite3MallocZero(2 * (i64)pVfs->szOsFile); |
| @@ -60967,22 +61211,20 @@ | |
| 60967 | ** sufficient space (in zSuperPtr) to hold the names of super-journal |
| 60968 | ** files extracted from regular rollback-journals. |
| 60969 | */ |
| 60970 | rc = sqlite3OsFileSize(pSuper, &nSuperJournal); |
| 60971 | if( rc!=SQLITE_OK ) goto delsuper_out; |
| 60972 | nSuperPtr = 1 + (i64)pVfs->mxPathname; |
| 60973 | assert( nSuperJournal>=0 && nSuperPtr>0 ); |
| 60974 | zFree = sqlite3Malloc(4 + nSuperJournal + nSuperPtr + 2); |
| 60975 | if( !zFree ){ |
| 60976 | rc = SQLITE_NOMEM_BKPT; |
| 60977 | goto delsuper_out; |
| 60978 | }else{ |
| 60979 | assert( nSuperJournal<=0x7fffffff ); |
| 60980 | } |
| 60981 | zFree[0] = zFree[1] = zFree[2] = zFree[3] = 0; |
| 60982 | zSuperJournal = &zFree[4]; |
| 60983 | zSuperPtr = &zSuperJournal[nSuperJournal+2]; |
| 60984 | rc = sqlite3OsRead(pSuper, zSuperJournal, (int)nSuperJournal, 0); |
| 60985 | if( rc!=SQLITE_OK ) goto delsuper_out; |
| 60986 | zSuperJournal[nSuperJournal] = 0; |
| 60987 | zSuperJournal[nSuperJournal+1] = 0; |
| 60988 | |
| @@ -60992,10 +61234,12 @@ | |
| 60992 | rc = sqlite3OsAccess(pVfs, zJournal, SQLITE_ACCESS_EXISTS, &exists); |
| 60993 | if( rc!=SQLITE_OK ){ |
| 60994 | goto delsuper_out; |
| 60995 | } |
| 60996 | if( exists ){ |
| 60997 | /* One of the journals pointed to by the super-journal exists. |
| 60998 | ** Open it and check if it points at the super-journal. If |
| 60999 | ** so, return without deleting the super-journal file. |
| 61000 | ** NB: zJournal is really a MAIN_JOURNAL. But call it a |
| 61001 | ** SUPER_JOURNAL here so that the VFS will not send the zJournal |
| @@ -61006,17 +61250,19 @@ | |
| 61006 | rc = sqlite3OsOpen(pVfs, zJournal, pJournal, flags, 0); |
| 61007 | if( rc!=SQLITE_OK ){ |
| 61008 | goto delsuper_out; |
| 61009 | } |
| 61010 | |
| 61011 | rc = readSuperJournal(pJournal, zSuperPtr, nSuperPtr); |
| 61012 | sqlite3OsClose(pJournal); |
| 61013 | if( rc!=SQLITE_OK ){ |
| 61014 | goto delsuper_out; |
| 61015 | } |
| 61016 | |
| 61017 | c = zSuperPtr[0]!=0 && strcmp(zSuperPtr, zSuper)==0; |
| 61018 | if( c ){ |
| 61019 | /* We have a match. Do not delete the super-journal file. */ |
| 61020 | goto delsuper_out; |
| 61021 | } |
| 61022 | } |
| @@ -61227,23 +61473,15 @@ | |
| 61227 | |
| 61228 | /* Read the super-journal name from the journal, if it is present. |
| 61229 | ** If a super-journal file name is specified, but the file is not |
| 61230 | ** present on disk, then the journal is not hot and does not need to be |
| 61231 | ** played back. |
| 61232 | ** |
| 61233 | ** TODO: Technically the following is an error because it assumes that |
| 61234 | ** buffer Pager.pTmpSpace is (mxPathname+1) bytes or larger. i.e. that |
| 61235 | ** (pPager->pageSize >= pPager->pVfs->mxPathname+1). Using os_unix.c, |
| 61236 | ** mxPathname is 512, which is the same as the minimum allowable value |
| 61237 | ** for pageSize. |
| 61238 | */ |
| 61239 | zSuper = pPager->pTmpSpace; |
| 61240 | rc = readSuperJournal(pPager->jfd, zSuper, 1+(i64)pPager->pVfs->mxPathname); |
| 61241 | if( rc==SQLITE_OK && zSuper[0] ){ |
| 61242 | rc = sqlite3OsAccess(pVfs, zSuper, SQLITE_ACCESS_EXISTS, &res); |
| 61243 | } |
| 61244 | zSuper = 0; |
| 61245 | if( rc!=SQLITE_OK || !res ){ |
| 61246 | goto end_playback; |
| 61247 | } |
| 61248 | pPager->journalOff = 0; |
| 61249 | needPagerReset = isHot; |
| @@ -61368,34 +61606,24 @@ | |
| 61368 | ** problems for other processes at some point in the future. So, just |
| 61369 | ** in case this has happened, clear the changeCountDone flag now. |
| 61370 | */ |
| 61371 | pPager->changeCountDone = pPager->tempFile; |
| 61372 | |
| 61373 | if( rc==SQLITE_OK ){ |
| 61374 | /* Leave 4 bytes of space before the super-journal filename in memory. |
| 61375 | ** This is because it may end up being passed to sqlite3OsOpen(), in |
| 61376 | ** which case it requires 4 0x00 bytes in memory immediately before |
| 61377 | ** the filename. */ |
| 61378 | zSuper = &pPager->pTmpSpace[4]; |
| 61379 | rc = readSuperJournal(pPager->jfd, zSuper, 1+(i64)pPager->pVfs->mxPathname); |
| 61380 | testcase( rc!=SQLITE_OK ); |
| 61381 | } |
| 61382 | if( rc==SQLITE_OK |
| 61383 | && (pPager->eState>=PAGER_WRITER_DBMOD || pPager->eState==PAGER_OPEN) |
| 61384 | ){ |
| 61385 | rc = sqlite3PagerSync(pPager, 0); |
| 61386 | } |
| 61387 | if( rc==SQLITE_OK ){ |
| 61388 | rc = pager_end_transaction(pPager, zSuper[0]!='\0', 0); |
| 61389 | testcase( rc!=SQLITE_OK ); |
| 61390 | } |
| 61391 | if( rc==SQLITE_OK && zSuper[0] && res ){ |
| 61392 | /* If there was a super-journal and this routine will return success, |
| 61393 | ** see if it is possible to delete the super-journal. |
| 61394 | */ |
| 61395 | assert( zSuper==&pPager->pTmpSpace[4] ); |
| 61396 | memset(pPager->pTmpSpace, 0, 4); |
| 61397 | rc = pager_delsuper(pPager, zSuper); |
| 61398 | testcase( rc!=SQLITE_OK ); |
| 61399 | } |
| 61400 | if( isHot && nPlayback ){ |
| 61401 | sqlite3_log(SQLITE_NOTICE_RECOVER_ROLLBACK, "recovered %d pages from %s", |
| @@ -61404,10 +61632,11 @@ | |
| 61404 | |
| 61405 | /* The Pager.sectorSize variable may have been updated while rolling |
| 61406 | ** back a journal created by a process with a different sector size |
| 61407 | ** value. Reset it to the correct value for this process. |
| 61408 | */ |
| 61409 | setSectorSize(pPager); |
| 61410 | return rc; |
| 61411 | } |
| 61412 | |
| 61413 | |
| @@ -67262,10 +67491,16 @@ | |
| 67262 | */ |
| 67263 | pgno = sqlite3Get4byte(&aFrame[0]); |
| 67264 | if( pgno==0 ){ |
| 67265 | return 0; |
| 67266 | } |
| 67267 | |
| 67268 | /* A frame is only valid if a checksum of the WAL header, |
| 67269 | ** all prior frames, the first 16 bytes of this frame-header, |
| 67270 | ** and the frame-data matches the checksum in the last 8 |
| 67271 | ** bytes of this frame-header. |
| @@ -69117,11 +69352,11 @@ | |
| 69117 | goto begin_unreliable_shm_out; |
| 69118 | } |
| 69119 | |
| 69120 | /* Allocate a buffer to read frames into */ |
| 69121 | assert( (pWal->szPage & (pWal->szPage-1))==0 ); |
| 69122 | assert( pWal->szPage>=512 && pWal->szPage<=65536 ); |
| 69123 | szFrame = pWal->szPage + WAL_FRAME_HDRSIZE; |
| 69124 | aFrame = (u8 *)sqlite3_malloc64(szFrame); |
| 69125 | if( aFrame==0 ){ |
| 69126 | rc = SQLITE_NOMEM_BKPT; |
| 69127 | goto begin_unreliable_shm_out; |
| @@ -71953,10 +72188,20 @@ | |
| 71953 | ** See the header comment on "btreeInt.h" for additional information. |
| 71954 | ** Including a description of file format and an overview of operation. |
| 71955 | */ |
| 71956 | /* #include "btreeInt.h" */ |
| 71957 | |
| 71958 | /* |
| 71959 | ** The header string that appears at the beginning of every |
| 71960 | ** SQLite database. |
| 71961 | */ |
| 71962 | static const char zMagicHeader[] = SQLITE_FILE_HEADER; |
| @@ -77123,11 +77368,13 @@ | |
| 77123 | ** in the overflow chain. The page number of the first overflow page is |
| 77124 | ** stored in aOverflow[0], etc. A value of 0 in the aOverflow[] array |
| 77125 | ** means "not yet known" (the cache is lazily populated). |
| 77126 | */ |
| 77127 | if( (pCur->curFlags & BTCF_ValidOvfl)==0 ){ |
| 77128 | int nOvfl = (pCur->info.nPayload-pCur->info.nLocal+ovflSize-1)/ovflSize; |
| 77129 | if( pCur->aOverflow==0 |
| 77130 | || nOvfl*(int)sizeof(Pgno) > sqlite3MallocSize(pCur->aOverflow) |
| 77131 | ){ |
| 77132 | Pgno *aNew; |
| 77133 | if( sqlite3FaultSim(413) ){ |
| @@ -77228,10 +77475,18 @@ | |
| 77228 | DbPage *pDbPage; |
| 77229 | rc = sqlite3PagerGet(pBt->pPager, nextPage, &pDbPage, |
| 77230 | (eOp==0 ? PAGER_GET_READONLY : 0) |
| 77231 | ); |
| 77232 | if( rc==SQLITE_OK ){ |
| 77233 | aPayload = sqlite3PagerGetData(pDbPage); |
| 77234 | nextPage = get4byte(aPayload); |
| 77235 | rc = copyPayload(&aPayload[offset+4], pBuf, a, eOp, pDbPage); |
| 77236 | sqlite3PagerUnref(pDbPage); |
| 77237 | offset = 0; |
| @@ -82902,10 +83157,15 @@ | |
| 82902 | if( pc+info.nSize>usableSize ){ |
| 82903 | checkAppendMsg(pCheck, "Extends off end of page"); |
| 82904 | doCoverageCheck = 0; |
| 82905 | continue; |
| 82906 | } |
| 82907 | |
| 82908 | /* Check for integer primary key out of range */ |
| 82909 | if( pPage->intKey ){ |
| 82910 | if( keyCanBeEqual ? (info.nKey > maxKey) : (info.nKey >= maxKey) ){ |
| 82911 | checkAppendMsg(pCheck, "Rowid %lld out of order", info.nKey); |
| @@ -83504,10 +83764,17 @@ | |
| 83504 | SQLITE_PRIVATE int sqlite3BtreeConnectionCount(Btree *p){ |
| 83505 | testcase( p->sharable ); |
| 83506 | return p->pBt->nRef; |
| 83507 | } |
| 83508 | #endif |
| 83509 | |
| 83510 | /************** End of btree.c ***********************************************/ |
| 83511 | /************** Begin file backup.c ******************************************/ |
| 83512 | /* |
| 83513 | ** 2009 January 28 |
| @@ -84405,12 +84672,12 @@ | |
| 84405 | /* Work-around for GCC bug or bugs: |
| 84406 | ** https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96270 |
| 84407 | ** https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114659 |
| 84408 | ** The problem appears to be fixed in GCC 15 */ |
| 84409 | i64 x; |
| 84410 | assert( (MEM_Str&~p->flags)*4==sizeof(x) ); |
| 84411 | memcpy(&x, (char*)&p->u, (MEM_Str&~p->flags)*4); |
| 84412 | p->n = sqlite3Int64ToText(x, zBuf); |
| 84413 | #else |
| 84414 | p->n = sqlite3Int64ToText(p->u.i, zBuf); |
| 84415 | #endif |
| 84416 | if( p->flags & MEM_IntReal ){ |
| @@ -87107,15 +87374,25 @@ | |
| 87107 | /* |
| 87108 | ** Add an OP_ParseSchema opcode. This routine is broken out from |
| 87109 | ** sqlite3VdbeAddOp4() since it needs to also needs to mark all btrees |
| 87110 | ** as having been used. |
| 87111 | ** |
| 87112 | ** The zWhere string must have been obtained from sqlite3_malloc(). |
| 87113 | ** This routine will take ownership of the allocated memory. |
| 87114 | */ |
| 87115 | SQLITE_PRIVATE void sqlite3VdbeAddParseSchemaOp(Vdbe *p, int iDb, char *zWhere, u16 p5){ |
| 87116 | int j; |
| 87117 | sqlite3VdbeAddOp4(p, OP_ParseSchema, iDb, 0, 0, zWhere, P4_DYNAMIC); |
| 87118 | sqlite3VdbeChangeP5(p, p5); |
| 87119 | for(j=0; j<p->db->nDb; j++) sqlite3VdbeUsesBtree(p, j); |
| 87120 | sqlite3MayAbort(p->pParse); |
| 87121 | } |
| @@ -95247,11 +95524,11 @@ | |
| 95247 | QueryPerformanceCounter(&tm); |
| 95248 | return (sqlite3_uint64)tm.QuadPart; |
| 95249 | } |
| 95250 | |
| 95251 | #elif !defined(__STRICT_ANSI__) && defined(__GNUC__) && \ |
| 95252 | (defined(i386) || defined(__i386__) || defined(_M_IX86)) |
| 95253 | |
| 95254 | __inline__ sqlite_uint64 sqlite3Hwtime(void){ |
| 95255 | unsigned int lo, hi; |
| 95256 | __asm__ __volatile__ ("rdtsc" : "=a" (lo), "=d" (hi)); |
| 95257 | return (sqlite_uint64)hi << 32 | lo; |
| @@ -95713,14 +95990,16 @@ | |
| 95713 | */ |
| 95714 | SQLITE_API int sqlite3_value_numeric_type(sqlite3_value *pVal){ |
| 95715 | int eType = sqlite3_value_type(pVal); |
| 95716 | if( eType==SQLITE_TEXT ){ |
| 95717 | Mem *pMem = (Mem*)pVal; |
| 95718 | assert( pMem->db!=0 ); |
| 95719 | sqlite3_mutex_enter(pMem->db->mutex); |
| 95720 | applyNumericAffinity(pMem, 0); |
| 95721 | sqlite3_mutex_leave(pMem->db->mutex); |
| 95722 | eType = sqlite3_value_type(pVal); |
| 95723 | } |
| 95724 | return eType; |
| 95725 | } |
| 95726 | |
| @@ -102423,15 +102702,22 @@ | |
| 102423 | goto abort_due_to_error; |
| 102424 | } |
| 102425 | break; |
| 102426 | } |
| 102427 | |
| 102428 | /* Opcode: ParseSchema P1 * * P4 * |
| 102429 | ** |
| 102430 | ** Read and parse all entries from the schema table of database P1 |
| 102431 | ** that match the WHERE clause P4. If P4 is a NULL pointer, then the |
| 102432 | ** entire schema for P1 is reparsed. |
| 102433 | ** |
| 102434 | ** This opcode invokes the parser to create a new virtual machine, |
| 102435 | ** then runs the new virtual machine. It is thus a re-entrant opcode. |
| 102436 | */ |
| 102437 | case OP_ParseSchema: { |
| @@ -102456,18 +102742,20 @@ | |
| 102456 | || db->mallocFailed |
| 102457 | || (CORRUPT_DB && (db->flags & SQLITE_NoSchemaError)!=0) ); |
| 102458 | |
| 102459 | #ifndef SQLITE_OMIT_ALTERTABLE |
| 102460 | if( pOp->p4.z==0 ){ |
| 102461 | sqlite3SchemaClear(db->aDb[iDb].pSchema); |
| 102462 | db->mDbFlags &= ~DBFLAG_SchemaKnownOk; |
| 102463 | rc = sqlite3InitOne(db, iDb, &p->zErrMsg, pOp->p5); |
| 102464 | db->mDbFlags |= DBFLAG_SchemaChange; |
| 102465 | p->expired = 0; |
| 102466 | }else |
| 102467 | #endif |
| 102468 | { |
| 102469 | zSchema = LEGACY_SCHEMA_TABLE; |
| 102470 | initData.db = db; |
| 102471 | initData.iDb = iDb; |
| 102472 | initData.pzErrMsg = &p->zErrMsg; |
| 102473 | initData.mInitFlags = 0; |
| @@ -102825,11 +103113,11 @@ | |
| 102825 | if( pFrame ) break; |
| 102826 | } |
| 102827 | |
| 102828 | if( p->nFrame>=db->aLimit[SQLITE_LIMIT_TRIGGER_DEPTH] ){ |
| 102829 | rc = SQLITE_ERROR; |
| 102830 | sqlite3VdbeError(p, "too many levels of trigger recursion"); |
| 102831 | goto abort_due_to_error; |
| 102832 | } |
| 102833 | |
| 102834 | /* Register pRt is used to store the memory required to save the state |
| 102835 | ** of the current program, and the memory required at runtime to execute |
| @@ -109952,11 +110240,11 @@ | |
| 109952 | /* |
| 109953 | ** cnt==0 means there was not match. |
| 109954 | ** cnt>1 means there were two or more matches. |
| 109955 | ** |
| 109956 | ** cnt==0 is always an error. cnt>1 is often an error, but might |
| 109957 | ** be multiple matches for a NATURAL LEFT JOIN or a LEFT JOIN USING. |
| 109958 | */ |
| 109959 | assert( pFJMatch==0 || cnt>0 ); |
| 109960 | assert( !ExprHasProperty(pExpr, EP_xIsSelect|EP_IntValue) ); |
| 109961 | if( cnt!=1 ){ |
| 109962 | const char *zErr; |
| @@ -109972,10 +110260,11 @@ | |
| 109972 | } |
| 109973 | extendFJMatch(pParse, &pFJMatch, pMatch, pExpr->iColumn); |
| 109974 | pExpr->op = TK_FUNCTION; |
| 109975 | pExpr->u.zToken = "coalesce"; |
| 109976 | pExpr->x.pList = pFJMatch; |
| 109977 | cnt = 1; |
| 109978 | goto lookupname_end; |
| 109979 | }else{ |
| 109980 | sqlite3ExprListDelete(db, pFJMatch); |
| 109981 | pFJMatch = 0; |
| @@ -110034,12 +110323,21 @@ | |
| 110034 | pExpr->op = eNewExprOp; |
| 110035 | lookupname_end: |
| 110036 | if( cnt==1 ){ |
| 110037 | assert( pNC!=0 ); |
| 110038 | #ifndef SQLITE_OMIT_AUTHORIZATION |
| 110039 | if( db->xAuth && (pExpr->op==TK_COLUMN || pExpr->op==TK_TRIGGER) ){ |
| 110040 | sqlite3AuthRead(pParse, pExpr, pSchema, pNC->pSrcList); |
| 110041 | } |
| 110042 | #endif |
| 110043 | /* Increment the nRef value on all name contexts from TopNC up to |
| 110044 | ** the point where the name matched. */ |
| 110045 | for(;;){ |
| @@ -110137,10 +110435,30 @@ | |
| 110137 | sqlite3AtoF(p->u.zToken, &r); |
| 110138 | assert( r>=0.0 ); |
| 110139 | if( r>1.0 ) return -1; |
| 110140 | return (int)(r*134217728.0); |
| 110141 | } |
| 110142 | |
| 110143 | /* |
| 110144 | ** This routine is callback for sqlite3WalkExpr(). |
| 110145 | ** |
| 110146 | ** Resolve symbolic names into TK_COLUMN operators for the current |
| @@ -110382,14 +110700,11 @@ | |
| 110382 | ** the function may return a value with a subtype back to its |
| 110383 | ** caller using sqlite3_result_value(). */ |
| 110384 | if( (pDef->funcFlags & SQLITE_SUBTYPE) |
| 110385 | || ExprHasProperty(pExpr, EP_SubtArg) |
| 110386 | ){ |
| 110387 | int ii; |
| 110388 | for(ii=0; ii<n; ii++){ |
| 110389 | ExprSetProperty(pList->a[ii].pExpr, EP_SubtArg); |
| 110390 | } |
| 110391 | } |
| 110392 | |
| 110393 | if( pDef->funcFlags & (SQLITE_FUNC_CONSTANT|SQLITE_FUNC_SLOCHNG) ){ |
| 110394 | /* For the purposes of the EP_ConstFunc flag, date and time |
| 110395 | ** functions and other functions that change slowly are considered |
| @@ -110415,12 +110730,17 @@ | |
| 110415 | && (pParse->db->mDbFlags & DBFLAG_InternalFunc)==0 |
| 110416 | ){ |
| 110417 | /* Internal-use-only functions are disallowed unless the |
| 110418 | ** SQL is being compiled using sqlite3NestedParse() or |
| 110419 | ** the SQLITE_TESTCTRL_INTERNAL_FUNCTIONS test-control has be |
| 110420 | ** used to activate internal functions for testing purposes */ |
| 110421 | no_such_func = 1; |
| 110422 | pDef = 0; |
| 110423 | }else |
| 110424 | if( (pDef->funcFlags & (SQLITE_FUNC_DIRECT|SQLITE_FUNC_UNSAFE))!=0 |
| 110425 | && !IN_RENAME_OBJECT |
| 110426 | ){ |
| @@ -110460,13 +110780,20 @@ | |
| 110460 | sqlite3ErrorMsg(pParse,"misuse of aggregate function %#T()",pExpr); |
| 110461 | pNC->nNcErr++; |
| 110462 | is_agg = 0; |
| 110463 | } |
| 110464 | #endif |
| 110465 | else if( no_such_func && pParse->db->init.busy==0 |
| 110466 | #ifdef SQLITE_ENABLE_UNKNOWN_SQL_FUNCTION |
| 110467 | && pParse->explain==0 |
| 110468 | #endif |
| 110469 | ){ |
| 110470 | sqlite3ErrorMsg(pParse, "no such function: %#T", pExpr); |
| 110471 | pNC->nNcErr++; |
| 110472 | }else if( wrong_num_args ){ |
| @@ -111849,11 +112176,13 @@ | |
| 111849 | ** Return TRUE if the two expressions have equivalent collating sequences. |
| 111850 | */ |
| 111851 | SQLITE_PRIVATE int sqlite3ExprCollSeqMatch(Parse *pParse, const Expr *pE1, const Expr *pE2){ |
| 111852 | CollSeq *pColl1 = sqlite3ExprNNCollSeq(pParse, pE1); |
| 111853 | CollSeq *pColl2 = sqlite3ExprNNCollSeq(pParse, pE2); |
| 111854 | return sqlite3StrICmp(pColl1->zName, pColl2->zName)==0; |
| 111855 | } |
| 111856 | |
| 111857 | /* |
| 111858 | ** pExpr is an operand of a comparison operator. aff2 is the |
| 111859 | ** type affinity of the other operand. This routine returns the |
| @@ -115686,10 +116015,11 @@ | |
| 115686 | if( i!=nVector ){ |
| 115687 | /* Need to reorder the LHS fields according to aiMap */ |
| 115688 | int rLhsOrig = rLhs; |
| 115689 | rLhs = sqlite3GetTempRange(pParse, nVector); |
| 115690 | for(i=0; i<nVector; i++){ |
| 115691 | sqlite3VdbeAddOp3(v, OP_Copy, rLhsOrig+i, rLhs+aiMap[i], 0); |
| 115692 | } |
| 115693 | sqlite3ReleaseTempReg(pParse, rLhsOrig); |
| 115694 | } |
| 115695 | } |
| @@ -115706,11 +116036,12 @@ | |
| 115706 | } |
| 115707 | for(i=0; i<nVector; i++){ |
| 115708 | Expr *p = sqlite3VectorFieldSubexpr(pExpr->pLeft, i); |
| 115709 | if( pParse->nErr ) goto sqlite3ExprCodeIN_oom_error; |
| 115710 | if( sqlite3ExprCanBeNull(p) ){ |
| 115711 | sqlite3VdbeAddOp2(v, OP_IsNull, rLhs+i, destStep2); |
| 115712 | VdbeCoverage(v); |
| 115713 | } |
| 115714 | } |
| 115715 | |
| 115716 | /* Step 3. The LHS is now known to be non-NULL. Do the binary search |
| @@ -115780,13 +116111,23 @@ | |
| 115780 | for(i=0; i<nVector; i++){ |
| 115781 | Expr *p; |
| 115782 | CollSeq *pColl; |
| 115783 | int r3 = sqlite3GetTempReg(pParse); |
| 115784 | p = sqlite3VectorFieldSubexpr(pLeft, i); |
| 115785 | pColl = sqlite3ExprCollSeq(pParse, p); |
| 115786 | sqlite3VdbeAddOp3(v, OP_Column, iTab, i, r3); |
| 115787 | sqlite3VdbeAddOp4(v, OP_Ne, rLhs+i, destNotNull, r3, |
| 115788 | (void*)pColl, P4_COLLSEQ); |
| 115789 | VdbeCoverage(v); |
| 115790 | sqlite3ReleaseTempReg(pParse, r3); |
| 115791 | } |
| 115792 | sqlite3VdbeAddOp2(v, OP_Goto, 0, destIfNull); |
| @@ -116203,40 +116544,51 @@ | |
| 116203 | } |
| 116204 | return target; |
| 116205 | } |
| 116206 | |
| 116207 | /* |
| 116208 | ** Expression Node callback for sqlite3ExprCanReturnSubtype(). |
| 116209 | ** |
| 116210 | ** Only a function call is able to return a subtype. So if the node |
| 116211 | ** is not a function call, return WRC_Prune immediately. |
| 116212 | ** |
| 116213 | ** A function call is able to return a subtype if it has the |
| 116214 | ** SQLITE_RESULT_SUBTYPE property. |
| 116215 | ** |
| 116216 | ** Assume that every function is able to pass-through a subtype from |
| 116217 | ** one of its argument (using sqlite3_result_value()). Most functions |
| 116218 | ** are not this way, but we don't have a mechanism to distinguish those |
| 116219 | ** that are from those that are not, so assume they all work this way. |
| 116220 | ** That means that if one of its arguments is another function and that |
| 116221 | ** other function is able to return a subtype, then this function is |
| 116222 | ** able to return a subtype. |
| 116223 | */ |
| 116224 | static int exprNodeCanReturnSubtype(Walker *pWalker, Expr *pExpr){ |
| 116225 | int n; |
| 116226 | FuncDef *pDef; |
| 116227 | sqlite3 *db; |
| 116228 | if( pExpr->op!=TK_FUNCTION ){ |
| 116229 | return WRC_Prune; |
| 116230 | } |
| 116231 | assert( ExprUseXList(pExpr) ); |
| 116232 | db = pWalker->pParse->db; |
| 116233 | n = ALWAYS(pExpr->x.pList) ? pExpr->x.pList->nExpr : 0; |
| 116234 | pDef = sqlite3FindFunction(db, pExpr->u.zToken, n, ENC(db), 0); |
| 116235 | if( NEVER(pDef==0) || (pDef->funcFlags & SQLITE_RESULT_SUBTYPE)!=0 ){ |
| 116236 | pWalker->eCode = 1; |
| 116237 | return WRC_Prune; |
| 116238 | } |
| 116239 | return WRC_Continue; |
| 116240 | } |
| 116241 | |
| 116242 | /* |
| @@ -122210,23 +122562,35 @@ | |
| 122210 | SQLITE_PRIVATE void sqlite3AlterAddConstraint( |
| 122211 | Parse *pParse, /* Parse context */ |
| 122212 | SrcList *pSrc, /* Table to add constraint to */ |
| 122213 | Token *pFirst, /* First token of new constraint */ |
| 122214 | Token *pName, /* Name of new constraint. NULL if name omitted. */ |
| 122215 | const char *pExpr, /* Text of CHECK expression */ |
| 122216 | int nExpr /* Size of pExpr in bytes */ |
| 122217 | ){ |
| 122218 | Table *pTab = 0; /* Table identified by pSrc */ |
| 122219 | int iDb = 0; /* Which schema does pTab live in */ |
| 122220 | const char *zDb = 0; /* Name of the schema in which pTab lives */ |
| 122221 | const char *pCons = 0; /* Text of the constraint */ |
| 122222 | int nCons; /* Bytes of text to use from pCons[] */ |
| 122223 | |
| 122224 | /* Look up the table being altered. */ |
| 122225 | assert( pSrc->nSrc==1 ); |
| 122226 | pTab = alterFindTable(pParse, pSrc, &iDb, &zDb, 1); |
| 122227 | if( !pTab ) return; |
| 122228 | |
| 122229 | /* If this new constraint has a name, check that it is not a duplicate of |
| 122230 | ** an existing constraint. It is an error if it is. */ |
| 122231 | if( pName ){ |
| 122232 | char *zName = sqlite3NameFromToken(pParse->db, pName); |
| @@ -122243,11 +122607,11 @@ | |
| 122243 | |
| 122244 | /* Search for a constraint violation. Throw an exception if one is found. */ |
| 122245 | sqlite3NestedParse(pParse, |
| 122246 | "SELECT sqlite_fail('constraint failed', %d) " |
| 122247 | "FROM %Q.%Q WHERE (%.*s) IS NOT TRUE", |
| 122248 | SQLITE_CONSTRAINT, zDb, pTab->zName, nExpr, pExpr |
| 122249 | ); |
| 122250 | |
| 122251 | /* Edit the SQL for the named table. */ |
| 122252 | pCons = pFirst->z; |
| 122253 | nCons = alterRtrimConstraint(pParse->db, pCons, pParse->sLastToken.z - pCons); |
| @@ -124098,21 +124462,21 @@ | |
| 124098 | }else{ |
| 124099 | nIdxCol = pIdx->nColumn; |
| 124100 | } |
| 124101 | pIdx->nSampleCol = nIdxCol; |
| 124102 | pIdx->mxSample = nSample; |
| 124103 | nByte = ROUND8(sizeof(IndexSample) * nSample); |
| 124104 | nByte += sizeof(tRowcnt) * nIdxCol * 3 * nSample; |
| 124105 | nByte += nIdxCol * sizeof(tRowcnt); /* Space for Index.aAvgEq[] */ |
| 124106 | |
| 124107 | pIdx->aSample = sqlite3DbMallocZero(db, nByte); |
| 124108 | if( pIdx->aSample==0 ){ |
| 124109 | sqlite3_finalize(pStmt); |
| 124110 | return SQLITE_NOMEM_BKPT; |
| 124111 | } |
| 124112 | pPtr = (u8*)pIdx->aSample; |
| 124113 | pPtr += ROUND8(nSample*sizeof(pIdx->aSample[0])); |
| 124114 | pSpace = (tRowcnt*)pPtr; |
| 124115 | assert( EIGHT_BYTE_ALIGNMENT( pSpace ) ); |
| 124116 | pIdx->aAvgEq = pSpace; pSpace += nIdxCol; |
| 124117 | pIdx->pTable->tabFlags |= TF_HasStat4; |
| 124118 | for(i=0; i<nSample; i++){ |
| @@ -125929,10 +126293,23 @@ | |
| 125929 | if( NEVER(pTab->u.tab.pDfltList==0) ) return 0; |
| 125930 | if( NEVER(pTab->u.tab.pDfltList->nExpr<pCol->iDflt) ) return 0; |
| 125931 | return pTab->u.tab.pDfltList->a[pCol->iDflt-1].pExpr; |
| 125932 | } |
| 125933 | |
| 125934 | /* |
| 125935 | ** Set the collating sequence name for a column. |
| 125936 | */ |
| 125937 | SQLITE_PRIVATE void sqlite3ColumnSetColl( |
| 125938 | sqlite3 *db, |
| @@ -125953,10 +126330,15 @@ | |
| 125953 | pCol->zCnName = zNew; |
| 125954 | memcpy(pCol->zCnName + n, zColl, nColl); |
| 125955 | pCol->colFlags |= COLFLAG_HASCOLL; |
| 125956 | } |
| 125957 | } |
| 125958 | |
| 125959 | /* |
| 125960 | ** Return the collating sequence name for a column |
| 125961 | */ |
| 125962 | SQLITE_PRIVATE const char *sqlite3ColumnColl(Column *pCol){ |
| @@ -132946,13 +133328,22 @@ | |
| 132946 | x.nUsed = 0; |
| 132947 | x.apArg = argv+1; |
| 132948 | sqlite3StrAccumInit(&str, db, 0, 0, db->aLimit[SQLITE_LIMIT_LENGTH]); |
| 132949 | str.printfFlags = SQLITE_PRINTF_SQLFUNC; |
| 132950 | sqlite3_str_appendf(&str, zFormat, &x); |
| 132951 | n = str.nChar; |
| 132952 | sqlite3_result_text(context, sqlite3StrAccumFinish(&str), n, |
| 132953 | SQLITE_DYNAMIC); |
| 132954 | } |
| 132955 | } |
| 132956 | |
| 132957 | /* |
| 132958 | ** Implementation of the substr() function. |
| @@ -134120,11 +134511,11 @@ | |
| 134120 | int nStr; /* Size of zStr */ |
| 134121 | int nPattern; /* Size of zPattern */ |
| 134122 | int nRep; /* Size of zRep */ |
| 134123 | i64 nOut; /* Maximum size of zOut */ |
| 134124 | int loopLimit; /* Last zStr[] that might match zPattern[] */ |
| 134125 | int i, j; /* Loop counters */ |
| 134126 | unsigned cntExpand; /* Number zOut expansions */ |
| 134127 | sqlite3 *db = sqlite3_context_db_handle(context); |
| 134128 | |
| 134129 | assert( argc==3 ); |
| 134130 | UNUSED_PARAMETER(argc); |
| @@ -134599,15 +134990,20 @@ | |
| 134599 | ** to initialize it */ |
| 134600 | if( ALWAYS(p) && type!=SQLITE_NULL ){ |
| 134601 | assert( p->cnt>0 ); |
| 134602 | p->cnt--; |
| 134603 | if( !p->approx ){ |
| 134604 | if( sqlite3SubInt64(&p->iSum, sqlite3_value_int64(argv[0])) ){ |
| 134605 | p->ovrfl = 1; |
| 134606 | p->approx = 1; |
| 134607 | } |
| 134608 | }else if( type==SQLITE_INTEGER ){ |
| 134609 | i64 iVal = sqlite3_value_int64(argv[0]); |
| 134610 | if( iVal!=SMALLEST_INT64 ){ |
| 134611 | kahanBabuskaNeumaierStepInt64(p, -iVal); |
| 134612 | }else{ |
| 134613 | kahanBabuskaNeumaierStepInt64(p, LARGEST_INT64); |
| @@ -135569,57 +135965,95 @@ | |
| 135569 | ** from the standard library because: |
| 135570 | ** |
| 135571 | ** (1) To avoid a dependency on qsort() |
| 135572 | ** (2) To avoid the function call to the comparison routine for each |
| 135573 | ** comparison. |
| 135574 | */ |
| 135575 | static void percentSort(double *a, unsigned int n){ |
| 135576 | int iLt; /* Entries before a[iLt] are less than rPivot */ |
| 135577 | int iGt; /* Entries at or after a[iGt] are greater than rPivot */ |
| 135578 | int i; /* Loop counter */ |
| 135579 | double rPivot; /* The pivot value */ |
| 135580 | |
| 135581 | assert( n>=2 ); |
| 135582 | if( a[0]>a[n-1] ){ |
| 135583 | SWAP_DOUBLE(a[0],a[n-1]) |
| 135584 | } |
| 135585 | if( n==2 ) return; |
| 135586 | iGt = n-1; |
| 135587 | i = n/2; |
| 135588 | if( a[0]>a[i] ){ |
| 135589 | SWAP_DOUBLE(a[0],a[i]) |
| 135590 | }else if( a[i]>a[iGt] ){ |
| 135591 | SWAP_DOUBLE(a[i],a[iGt]) |
| 135592 | } |
| 135593 | if( n==3 ) return; |
| 135594 | rPivot = a[i]; |
| 135595 | iLt = i = 1; |
| 135596 | do{ |
| 135597 | if( a[i]<rPivot ){ |
| 135598 | if( i>iLt ) SWAP_DOUBLE(a[i],a[iLt]) |
| 135599 | iLt++; |
| 135600 | i++; |
| 135601 | }else if( a[i]>rPivot ){ |
| 135602 | do{ |
| 135603 | iGt--; |
| 135604 | }while( iGt>i && a[iGt]>rPivot ); |
| 135605 | SWAP_DOUBLE(a[i],a[iGt]) |
| 135606 | }else{ |
| 135607 | i++; |
| 135608 | } |
| 135609 | }while( i<iGt ); |
| 135610 | if( iLt>=2 ) percentSort(a, iLt); |
| 135611 | if( n-iGt>=2 ) percentSort(a+iGt, n-iGt); |
| 135612 | |
| 135613 | /* Uncomment for testing */ |
| 135614 | #if 0 |
| 135615 | for(i=0; i<n-1; i++){ |
| 135616 | assert( a[i]<=a[i+1] ); |
| 135617 | } |
| 135618 | #endif |
| 135619 | } |
| 135620 | |
| 135621 | |
| 135622 | /* |
| 135623 | ** The "inverse" function for percentile(Y,P) is called to remove a |
| 135624 | ** row that was previously inserted by "step". |
| 135625 | */ |
| @@ -135649,11 +136083,11 @@ | |
| 135649 | if( percentIsInfinity(y) ){ |
| 135650 | return; |
| 135651 | } |
| 135652 | if( p->bSorted==0 ){ |
| 135653 | assert( p->nUsed>1 ); |
| 135654 | percentSort(p->a, p->nUsed); |
| 135655 | p->bSorted = 1; |
| 135656 | } |
| 135657 | p->bKeepSorted = 1; |
| 135658 | |
| 135659 | /* Find and remove the row */ |
| @@ -135678,17 +136112,21 @@ | |
| 135678 | double ix, vx; |
| 135679 | p = (Percentile*)sqlite3_aggregate_context(pCtx, 0); |
| 135680 | if( p==0 ) return; |
| 135681 | if( p->a==0 ) return; |
| 135682 | if( p->nUsed ){ |
| 135683 | if( p->bSorted==0 ){ |
| 135684 | assert( p->nUsed>1 ); |
| 135685 | percentSort(p->a, p->nUsed); |
| 135686 | p->bSorted = 1; |
| 135687 | } |
| 135688 | ix = p->rPct*(p->nUsed-1); |
| 135689 | i1 = (unsigned)ix; |
| 135690 | if( settings & 1 ){ |
| 135691 | vx = p->a[i1]; |
| 135692 | }else{ |
| 135693 | i2 = ix==(double)i1 || i1==p->nUsed-1 ? i1 : i1+1; |
| 135694 | v1 = p->a[i1]; |
| @@ -140569,10 +141007,48 @@ | |
| 140569 | } |
| 140570 | |
| 140571 | /* If no test above fails then the indices must be compatible */ |
| 140572 | return 1; |
| 140573 | } |
| 140574 | |
| 140575 | /* |
| 140576 | ** Attempt the transfer optimization on INSERTs of the form |
| 140577 | ** |
| 140578 | ** INSERT INTO tab1 SELECT * FROM tab2; |
| @@ -140696,12 +141172,23 @@ | |
| 140696 | return 0; /* Number of columns must be the same in tab1 and tab2 */ |
| 140697 | } |
| 140698 | if( pDest->iPKey!=pSrc->iPKey ){ |
| 140699 | return 0; /* Both tables must have the same INTEGER PRIMARY KEY */ |
| 140700 | } |
| 140701 | if( (pDest->tabFlags & TF_Strict)!=0 && (pSrc->tabFlags & TF_Strict)==0 ){ |
| 140702 | return 0; /* Cannot feed from a non-strict into a strict table */ |
| 140703 | } |
| 140704 | for(i=0; i<pDest->nCol; i++){ |
| 140705 | Column *pDestCol = &pDest->aCol[i]; |
| 140706 | Column *pSrcCol = &pSrc->aCol[i]; |
| 140707 | #ifdef SQLITE_ENABLE_HIDDEN_COLUMNS |
| @@ -140791,11 +141278,11 @@ | |
| 140791 | } |
| 140792 | } |
| 140793 | #ifndef SQLITE_OMIT_CHECK |
| 140794 | if( pDest->pCheck |
| 140795 | && (db->mDbFlags & DBFLAG_Vacuum)==0 |
| 140796 | && sqlite3ExprListCompare(pSrc->pCheck,pDest->pCheck,-1) |
| 140797 | ){ |
| 140798 | return 0; /* Tables have different CHECK constraints. Ticket #2252 */ |
| 140799 | } |
| 140800 | #endif |
| 140801 | #ifndef SQLITE_OMIT_FOREIGN_KEY |
| @@ -140812,10 +141299,22 @@ | |
| 140812 | } |
| 140813 | #endif |
| 140814 | if( (db->flags & SQLITE_CountRows)!=0 ){ |
| 140815 | return 0; /* xfer opt does not play well with PRAGMA count_changes */ |
| 140816 | } |
| 140817 | |
| 140818 | /* If we get this far, it means that the xfer optimization is at |
| 140819 | ** least a possibility, though it might only work if the destination |
| 140820 | ** table (tab1) is initially empty. |
| 140821 | */ |
| @@ -146810,11 +147309,17 @@ | |
| 146810 | assert( iDb>=0 && iDb<db->nDb ); |
| 146811 | assert( db->aDb[iDb].pSchema ); |
| 146812 | assert( sqlite3_mutex_held(db->mutex) ); |
| 146813 | assert( iDb==1 || sqlite3BtreeHoldsMutex(db->aDb[iDb].pBt) ); |
| 146814 | |
| 146815 | db->init.busy = 1; |
| 146816 | |
| 146817 | /* Construct the in-memory representation schema tables (sqlite_schema or |
| 146818 | ** sqlite_temp_schema) by invoking the parser directly. The appropriate |
| 146819 | ** table name will be inserted automatically by the parser so we can just |
| 146820 | ** use the abbreviation "x" here. The parser will also automatically tag |
| @@ -150131,10 +150636,17 @@ | |
| 150131 | SQLITE_PRIVATE Table *sqlite3ResultSetOfSelect(Parse *pParse, Select *pSelect, char aff){ |
| 150132 | Table *pTab; |
| 150133 | sqlite3 *db = pParse->db; |
| 150134 | u64 savedFlags; |
| 150135 | |
| 150136 | savedFlags = db->flags; |
| 150137 | db->flags &= ~(u64)SQLITE_FullColNames; |
| 150138 | db->flags |= SQLITE_ShortColNames; |
| 150139 | sqlite3SelectPrep(pParse, pSelect, 0); |
| 150140 | db->flags = savedFlags; |
| @@ -150152,10 +150664,12 @@ | |
| 150152 | pTab->iPKey = -1; |
| 150153 | if( db->mallocFailed ){ |
| 150154 | sqlite3DeleteTable(db, pTab); |
| 150155 | return 0; |
| 150156 | } |
| 150157 | return pTab; |
| 150158 | } |
| 150159 | |
| 150160 | /* |
| 150161 | ** Get a VDBE for the given parser context. Create a new one if necessary. |
| @@ -155122,12 +155636,15 @@ | |
| 155122 | ** Then, if CheckOnCtx.iJoin indicates that this expression is part of an |
| 155123 | ** ON clause from that SrcList (i.e. if iJoin is non-zero), check that it |
| 155124 | ** does not refer to a table to the right of CheckOnCtx.iJoin. */ |
| 155125 | do { |
| 155126 | SrcList *pSrc = pCtx->pSrc; |
| 155127 | int iTab = pExpr->iTable; |
| 155128 | if( iTab>=pSrc->a[0].iCursor && iTab<=pSrc->a[pSrc->nSrc-1].iCursor ){ |
| 155129 | if( pCtx->iJoin && iTab>pCtx->iJoin ){ |
| 155130 | sqlite3ErrorMsg(pWalker->pParse, |
| 155131 | "%s references tables to its right", |
| 155132 | (pCtx->bFuncArg ? "table-function argument" : "ON clause") |
| 155133 | ); |
| @@ -158092,22 +158609,36 @@ | |
| 158092 | Parse *pParse, /* Current parse context */ |
| 158093 | Trigger *pTrigger, /* Trigger to code */ |
| 158094 | Table *pTab, /* The table pTrigger is attached to */ |
| 158095 | int orconf /* ON CONFLICT policy to code trigger program with */ |
| 158096 | ){ |
| 158097 | Parse *pTop = sqlite3ParseToplevel(pParse); |
| 158098 | sqlite3 *db = pParse->db; /* Database handle */ |
| 158099 | TriggerPrg *pPrg; /* Value to return */ |
| 158100 | Expr *pWhen = 0; /* Duplicate of trigger WHEN expression */ |
| 158101 | Vdbe *v; /* Temporary VM */ |
| 158102 | NameContext sNC; /* Name context for sub-vdbe */ |
| 158103 | SubProgram *pProgram = 0; /* Sub-vdbe for trigger program */ |
| 158104 | int iEndTrigger = 0; /* Label to jump to if WHEN is false */ |
| 158105 | Parse sSubParse; /* Parse context for sub-vdbe */ |
| 158106 | |
| 158107 | assert( pTrigger->zName==0 || pTab==tableOfTrigger(pTrigger) ); |
| 158108 | assert( pTop->pVdbe ); |
| 158109 | |
| 158110 | /* Allocate the TriggerPrg and SubProgram objects. To ensure that they |
| 158111 | ** are freed if an error occurs, link them into the Parse.pTriggerPrg |
| 158112 | ** list of the top-level Parse object sooner rather than later. */ |
| 158113 | pPrg = sqlite3DbMallocZero(db, sizeof(TriggerPrg)); |
| @@ -160105,11 +160636,12 @@ | |
| 160105 | ** So we have to make a copy before passing it down into sqlite3Update() */ |
| 160106 | pSrc = sqlite3SrcListDup(db, pTop->pUpsertSrc, 0); |
| 160107 | /* excluded.* columns of type REAL need to be converted to a hard real */ |
| 160108 | for(i=0; i<pTab->nCol; i++){ |
| 160109 | if( pTab->aCol[i].affinity==SQLITE_AFF_REAL ){ |
| 160110 | sqlite3VdbeAddOp1(v, OP_RealAffinity, pTop->regData+i); |
| 160111 | } |
| 160112 | } |
| 160113 | sqlite3Update(pParse, pSrc, sqlite3ExprListDup(db,pUpsert->pUpsertSet,0), |
| 160114 | sqlite3ExprDup(db,pUpsert->pUpsertWhere,0), OE_Abort, 0, 0, pUpsert); |
| 160115 | VdbeNoopComment((v, "End DO UPDATE of UPSERT")); |
| @@ -164903,11 +165435,11 @@ | |
| 164903 | |
| 164904 | /* Set up a new SrcList in pOrTab containing the table being scanned |
| 164905 | ** by this loop in the a[0] slot and all notReady tables in a[1..] slots. |
| 164906 | ** This becomes the SrcList in the recursive call to sqlite3WhereBegin(). |
| 164907 | */ |
| 164908 | if( pWInfo->nLevel>1 ){ |
| 164909 | int nNotReady; /* The number of notReady tables */ |
| 164910 | SrcItem *origSrc; /* Original list of tables */ |
| 164911 | nNotReady = pWInfo->nLevel - iLevel - 1; |
| 164912 | pOrTab = sqlite3DbMallocRawNN(db, SZ_SRCLIST(nNotReady+1)); |
| 164913 | if( pOrTab==0 ) return notReady; |
| @@ -164916,10 +165448,17 @@ | |
| 164916 | memcpy(pOrTab->a, pTabItem, sizeof(*pTabItem)); |
| 164917 | origSrc = pWInfo->pTabList->a; |
| 164918 | for(k=1; k<=nNotReady; k++){ |
| 164919 | memcpy(&pOrTab->a[k], &origSrc[pLevel[k].iFrom], sizeof(pOrTab->a[k])); |
| 164920 | } |
| 164921 | }else{ |
| 164922 | pOrTab = pWInfo->pTabList; |
| 164923 | } |
| 164924 | |
| 164925 | /* Initialize the rowset register to contain NULL. An SQL NULL is |
| @@ -165159,11 +165698,11 @@ | |
| 165159 | ** indent everything in between the this point and the final OP_Return. |
| 165160 | ** See tag-20220407a in vdbe.c and shell.c */ |
| 165161 | assert( pLevel->op==OP_Return ); |
| 165162 | pLevel->p2 = sqlite3VdbeCurrentAddr(v); |
| 165163 | |
| 165164 | if( pWInfo->nLevel>1 ){ sqlite3DbFreeNN(db, pOrTab); } |
| 165165 | if( !untestedTerms ) disableTerm(pLevel, pTerm); |
| 165166 | }else |
| 165167 | #endif /* SQLITE_OMIT_OR_OPTIMIZATION */ |
| 165168 | |
| 165169 | { |
| @@ -165316,10 +165855,11 @@ | |
| 165316 | assert( (pTerm->eOperator & (WO_OR|WO_AND))==0 ); |
| 165317 | pAlt = sqlite3WhereFindTerm(pWC, iCur, pTerm->u.x.leftColumn, notReady, |
| 165318 | WO_EQ|WO_IN|WO_IS, 0); |
| 165319 | if( pAlt==0 ) continue; |
| 165320 | if( pAlt->wtFlags & (TERM_CODED) ) continue; |
| 165321 | if( (pAlt->eOperator & WO_IN) |
| 165322 | && ExprUseXSelect(pAlt->pExpr) |
| 165323 | && (pAlt->pExpr->x.pSelect->pEList->nExpr>1) |
| 165324 | ){ |
| 165325 | continue; |
| @@ -166069,11 +166609,14 @@ | |
| 166069 | ** Mark term iChild as being a child of term iParent |
| 166070 | */ |
| 166071 | static void markTermAsChild(WhereClause *pWC, int iChild, int iParent){ |
| 166072 | pWC->a[iChild].iParent = iParent; |
| 166073 | pWC->a[iChild].truthProb = pWC->a[iParent].truthProb; |
| 166074 | pWC->a[iParent].nChild++; |
| 166075 | } |
| 166076 | |
| 166077 | /* |
| 166078 | ** Return the N-th AND-connected subterm of pTerm. Or if pTerm is not |
| 166079 | ** a conjunction, then return just pTerm when N==0. If N is exceeds |
| @@ -166508,23 +167051,22 @@ | |
| 166508 | ** 1. The SQLITE_Transitive optimization must be enabled |
| 166509 | ** 2. Must be either an == or an IS operator |
| 166510 | ** 3. Not originating in the ON clause of an OUTER JOIN |
| 166511 | ** 4. The operator is not IS or else the query does not contain RIGHT JOIN |
| 166512 | ** 5. The affinities of A and B must be compatible |
| 166513 | ** 6a. Both operands use the same collating sequence OR |
| 166514 | ** 6b. The overall collating sequence is BINARY |
| 166515 | ** If this routine returns TRUE, that means that the RHS can be substituted |
| 166516 | ** for the LHS anyplace else in the WHERE clause where the LHS column occurs. |
| 166517 | ** This is an optimization. No harm comes from returning 0. But if 1 is |
| 166518 | ** returned when it should not be, then incorrect answers might result. |
| 166519 | */ |
| 166520 | static int termIsEquivalence(Parse *pParse, Expr *pExpr, SrcList *pSrc){ |
| 166521 | char aff1, aff2; |
| 166522 | CollSeq *pColl; |
| 166523 | if( !OptimizationEnabled(pParse->db, SQLITE_Transitive) ) return 0; /* (1) */ |
| 166524 | if( pExpr->op!=TK_EQ && pExpr->op!=TK_IS ) return 0; /* (2) */ |
| 166525 | if( ExprHasProperty(pExpr, EP_OuterON) ) return 0; /* (3) */ |
| 166526 | assert( pSrc!=0 ); |
| 166527 | if( pExpr->op==TK_IS |
| 166528 | && pSrc->nSrc>=2 |
| 166529 | && (pSrc->a[0].fg.jointype & JT_LTORJ)!=0 |
| 166530 | ){ |
| @@ -166535,14 +167077,11 @@ | |
| 166535 | if( aff1!=aff2 |
| 166536 | && (!sqlite3IsNumericAffinity(aff1) || !sqlite3IsNumericAffinity(aff2)) |
| 166537 | ){ |
| 166538 | return 0; /* (5) */ |
| 166539 | } |
| 166540 | pColl = sqlite3ExprCompareCollSeq(pParse, pExpr); |
| 166541 | if( !sqlite3IsBinary(pColl) |
| 166542 | && !sqlite3ExprCollSeqMatch(pParse, pExpr->pLeft, pExpr->pRight) |
| 166543 | ){ |
| 166544 | return 0; /* (6) */ |
| 166545 | } |
| 166546 | return 1; |
| 166547 | } |
| 166548 | |
| @@ -166850,10 +167389,11 @@ | |
| 166850 | static const u8 ops[] = {TK_GE, TK_LE}; |
| 166851 | assert( ExprUseXList(pExpr) ); |
| 166852 | pList = pExpr->x.pList; |
| 166853 | assert( pList!=0 ); |
| 166854 | assert( pList->nExpr==2 ); |
| 166855 | for(i=0; i<2; i++){ |
| 166856 | Expr *pNewExpr; |
| 166857 | int idxNew; |
| 166858 | pNewExpr = sqlite3PExpr(pParse, ops[i], |
| 166859 | sqlite3ExprDup(db, pExpr->pLeft, 0), |
| @@ -166870,11 +167410,11 @@ | |
| 166870 | |
| 166871 | #if !defined(SQLITE_OMIT_OR_OPTIMIZATION) && !defined(SQLITE_OMIT_SUBQUERY) |
| 166872 | /* Analyze a term that is composed of two or more subterms connected by |
| 166873 | ** an OR operator. |
| 166874 | */ |
| 166875 | else if( pExpr->op==TK_OR ){ |
| 166876 | assert( pWC->op==TK_AND ); |
| 166877 | exprAnalyzeOrTerm(pSrc, pWC, idxTerm); |
| 166878 | pTerm = &pWC->a[idxTerm]; |
| 166879 | } |
| 166880 | #endif /* SQLITE_OMIT_OR_OPTIMIZATION */ |
| @@ -167060,12 +167600,15 @@ | |
| 167060 | && (pExpr->x.pSelect->pPrior==0 || (pExpr->x.pSelect->selFlags & SF_Values)) |
| 167061 | #ifndef SQLITE_OMIT_WINDOWFUNC |
| 167062 | && pExpr->x.pSelect->pWin==0 |
| 167063 | #endif |
| 167064 | && pWC->op==TK_AND |
| 167065 | ){ |
| 167066 | int i; |
| 167067 | for(i=0; i<sqlite3ExprVectorSize(pExpr->pLeft); i++){ |
| 167068 | int idxNew; |
| 167069 | idxNew = whereClauseInsert(pWC, pExpr, TERM_VIRTUAL|TERM_SLICE); |
| 167070 | pWC->a[idxNew].u.x.iField = i+1; |
| 167071 | exprAnalyze(pSrc, pWC, idxNew); |
| @@ -170589,13 +171132,14 @@ | |
| 170589 | pLoop->nOut--; |
| 170590 | if( (pTerm->eOperator&(WO_EQ|WO_IS))!=0 |
| 170591 | && (pTerm->wtFlags & TERM_HIGHTRUTH)==0 /* tag-20200224-1 */ |
| 170592 | ){ |
| 170593 | Expr *pRight = pOpExpr->pRight; |
| 170594 | int k = 0; |
| 170595 | testcase( pOpExpr->op==TK_IS ); |
| 170596 | if( sqlite3ExprIsInteger(pRight, &k, 0) && k>=(-1) && k<=1 ){ |
| 170597 | k = 10; |
| 170598 | }else{ |
| 170599 | k = 20; |
| 170600 | } |
| 170601 | if( iReduce<k ){ |
| @@ -170688,11 +171232,12 @@ | |
| 170688 | testcase( pLhs->iColumn==XN_ROWID ); |
| 170689 | aff = sqlite3CompareAffinity(pRhs, sqlite3ExprAffinity(pLhs)); |
| 170690 | idxaff = sqlite3TableColumnAffinity(pIdx->pTable, pLhs->iColumn); |
| 170691 | if( aff!=idxaff ) break; |
| 170692 | |
| 170693 | pColl = sqlite3ExprCompareCollSeq(pParse, pTerm->pExpr); |
| 170694 | if( pColl==0 ) break; |
| 170695 | if( sqlite3StrICmp(pColl->zName, pIdx->azColl[i+nEq]) ) break; |
| 170696 | } |
| 170697 | return i; |
| 170698 | } |
| @@ -183162,13 +183707,15 @@ | |
| 183162 | case 196: /* expr ::= LP nexprlist COMMA expr RP */ |
| 183163 | { |
| 183164 | ExprList *pList = sqlite3ExprListAppend(pParse, yymsp[-3].minor.yy14, yymsp[-1].minor.yy454); |
| 183165 | yymsp[-4].minor.yy454 = sqlite3PExpr(pParse, TK_VECTOR, 0, 0); |
| 183166 | if( yymsp[-4].minor.yy454 ){ |
| 183167 | yymsp[-4].minor.yy454->x.pList = pList; |
| 183168 | if( ALWAYS(pList->nExpr) ){ |
| 183169 | yymsp[-4].minor.yy454->flags |= pList->a[0].pExpr->flags & EP_Propagate; |
| 183170 | } |
| 183171 | }else{ |
| 183172 | sqlite3ExprListDelete(pParse->db, pList); |
| 183173 | } |
| 183174 | } |
| @@ -183632,19 +184179,17 @@ | |
| 183632 | sqlite3AlterSetNotNull(pParse, yymsp[-7].minor.yy203, &yymsp[-4].minor.yy0, &yymsp[-2].minor.yy0); |
| 183633 | } |
| 183634 | break; |
| 183635 | case 300: /* cmd ::= ALTER TABLE fullname ADD CONSTRAINT nm CHECK LP expr RP onconf */ |
| 183636 | { |
| 183637 | sqlite3AlterAddConstraint(pParse, yymsp[-8].minor.yy203, &yymsp[-6].minor.yy0, &yymsp[-5].minor.yy0, yymsp[-3].minor.yy0.z+1, (yymsp[-1].minor.yy0.z-yymsp[-3].minor.yy0.z-1)); |
| 183638 | } |
| 183639 | yy_destructor(yypParser,219,&yymsp[-2].minor); |
| 183640 | break; |
| 183641 | case 301: /* cmd ::= ALTER TABLE fullname ADD CHECK LP expr RP onconf */ |
| 183642 | { |
| 183643 | sqlite3AlterAddConstraint(pParse, yymsp[-6].minor.yy203, &yymsp[-4].minor.yy0, 0, yymsp[-3].minor.yy0.z+1, (yymsp[-1].minor.yy0.z-yymsp[-3].minor.yy0.z-1)); |
| 183644 | } |
| 183645 | yy_destructor(yypParser,219,&yymsp[-2].minor); |
| 183646 | break; |
| 183647 | case 302: /* cmd ::= create_vtab */ |
| 183648 | {sqlite3VtabFinishParse(pParse,0);} |
| 183649 | break; |
| 183650 | case 303: /* cmd ::= create_vtab LP vtabarglist RP */ |
| @@ -186617,11 +187162,11 @@ | |
| 186617 | ** or disables the collection of memory allocation statistics. */ |
| 186618 | sqlite3GlobalConfig.bMemstat = va_arg(ap, int); |
| 186619 | break; |
| 186620 | } |
| 186621 | case SQLITE_CONFIG_SMALL_MALLOC: { |
| 186622 | sqlite3GlobalConfig.bSmallMalloc = va_arg(ap, int); |
| 186623 | break; |
| 186624 | } |
| 186625 | case SQLITE_CONFIG_PAGECACHE: { |
| 186626 | /* EVIDENCE-OF: R-18761-36601 There are three arguments to |
| 186627 | ** SQLITE_CONFIG_PAGECACHE: A pointer to 8-byte aligned memory (pMem), |
| @@ -192926,10 +193471,16 @@ | |
| 192926 | #ifndef SQLITE_CORE |
| 192927 | /* # include "sqlite3ext.h" */ |
| 192928 | SQLITE_EXTENSION_INIT1 |
| 192929 | #endif |
| 192930 | |
| 192931 | typedef struct Fts3HashWrapper Fts3HashWrapper; |
| 192932 | struct Fts3HashWrapper { |
| 192933 | Fts3Hash hash; /* Hash table */ |
| 192934 | int nRef; /* Number of pointers to this object */ |
| 192935 | }; |
| @@ -194642,11 +195193,15 @@ | |
| 194642 | int iHeight; /* Height of this node in tree */ |
| 194643 | |
| 194644 | assert( piLeaf || piLeaf2 ); |
| 194645 | |
| 194646 | fts3GetVarint32(zNode, &iHeight); |
| 194647 | rc = fts3ScanInteriorNode(zTerm, nTerm, zNode, nNode, piLeaf, piLeaf2); |
| 194648 | assert_fts3_nc( !piLeaf2 || !piLeaf || rc!=SQLITE_OK || (*piLeaf<=*piLeaf2) ); |
| 194649 | |
| 194650 | if( rc==SQLITE_OK && iHeight>1 ){ |
| 194651 | char *zBlob = 0; /* Blob read from %_segments table */ |
| 194652 | int nBlob = 0; /* Size of zBlob in bytes */ |
| @@ -194687,12 +195242,17 @@ | |
| 194687 | char **pp, /* IN/OUT: Output pointer */ |
| 194688 | sqlite3_int64 *piPrev, /* IN/OUT: Previous value written to list */ |
| 194689 | sqlite3_int64 iVal /* Write this value to the list */ |
| 194690 | ){ |
| 194691 | assert_fts3_nc( iVal-*piPrev > 0 || (*piPrev==0 && iVal==0) ); |
| 194692 | *pp += sqlite3Fts3PutVarint(*pp, iVal-*piPrev); |
| 194693 | *piPrev = iVal; |
| 194694 | } |
| 194695 | |
| 194696 | /* |
| 194697 | ** When this function is called, *ppPoslist is assumed to point to the |
| 194698 | ** start of a position-list. After it returns, *ppPoslist points to the |
| @@ -199171,11 +199731,11 @@ | |
| 199171 | break; |
| 199172 | |
| 199173 | /* State 3. The integer just read is a column number. */ |
| 199174 | default: assert( eState==3 ); |
| 199175 | iCol = (int)v; |
| 199176 | if( iCol<1 ){ |
| 199177 | rc = SQLITE_CORRUPT_VTAB; |
| 199178 | break; |
| 199179 | } |
| 199180 | if( fts3auxGrowStatArray(pCsr, iCol+2) ) return SQLITE_NOMEM; |
| 199181 | pCsr->aStat[iCol+1].nDoc++; |
| @@ -199861,10 +200421,11 @@ | |
| 199861 | /* If this is a "NEAR" keyword, check for an explicit nearness. */ |
| 199862 | if( pKey->eType==FTSQUERY_NEAR ){ |
| 199863 | assert( nKey==4 ); |
| 199864 | if( zInput[4]=='/' && zInput[5]>='0' && zInput[5]<='9' ){ |
| 199865 | nKey += 1+sqlite3Fts3ReadInt(&zInput[nKey+1], &nNear); |
| 199866 | } |
| 199867 | } |
| 199868 | |
| 199869 | /* At this point this is probably a keyword. But for that to be true, |
| 199870 | ** the next byte must contain either whitespace, an open or close |
| @@ -206107,10 +206668,14 @@ | |
| 206107 | iMul = -1; |
| 206108 | } |
| 206109 | for(/* no-op */; zText[i]>='0' && zText[i]<='9'; i++){ |
| 206110 | iVal = iVal*10 + (zText[i] - '0'); |
| 206111 | } |
| 206112 | *pnByte = ((i64)iVal * (i64)iMul); |
| 206113 | } |
| 206114 | } |
| 206115 | |
| 206116 | |
| @@ -208969,14 +209534,13 @@ | |
| 208969 | */ |
| 208970 | |
| 208971 | /* |
| 208972 | ** Allocate a two-slot MatchinfoBuffer object. |
| 208973 | */ |
| 208974 | static MatchinfoBuffer *fts3MIBufferNew(size_t nElem, const char *zMatchinfo){ |
| 208975 | MatchinfoBuffer *pRet; |
| 208976 | sqlite3_int64 nByte = sizeof(u32) * (2*(sqlite3_int64)nElem + 1) |
| 208977 | + SZ_MATCHINFOBUFFER(1); |
| 208978 | sqlite3_int64 nStr = strlen(zMatchinfo); |
| 208979 | |
| 208980 | pRet = sqlite3Fts3MallocZero(nByte + nStr+1); |
| 208981 | if( pRet ){ |
| 208982 | pRet->aMI[0] = (u8*)(&pRet->aMI[1]) - (u8*)pRet; |
| @@ -209724,11 +210288,11 @@ | |
| 209724 | int nHit = fts3ColumnlistCount(&pIter); |
| 209725 | if( (pPhrase->iColumn>=pTab->nColumn || pPhrase->iColumn==iCol) ){ |
| 209726 | if( p->flag==FTS3_MATCHINFO_LHITS ){ |
| 209727 | p->aMatchinfo[iStart + iCol] = (u32)nHit; |
| 209728 | }else if( nHit ){ |
| 209729 | p->aMatchinfo[iStart + (iCol+1)/32] |= (1 << (iCol&0x1F)); |
| 209730 | } |
| 209731 | } |
| 209732 | assert( *pIter==0x00 || *pIter==0x01 ); |
| 209733 | if( *pIter!=0x01 ) break; |
| 209734 | pIter++; |
| @@ -209843,12 +210407,12 @@ | |
| 209843 | } |
| 209844 | sqlite3Fts3ErrMsg(pzErr, "unrecognized matchinfo request: %c", cArg); |
| 209845 | return SQLITE_ERROR; |
| 209846 | } |
| 209847 | |
| 209848 | static size_t fts3MatchinfoSize(MatchInfo *pInfo, char cArg){ |
| 209849 | size_t nVal; /* Number of integers output by cArg */ |
| 209850 | |
| 209851 | switch( cArg ){ |
| 209852 | case FTS3_MATCHINFO_NDOC: |
| 209853 | case FTS3_MATCHINFO_NPHRASE: |
| 209854 | case FTS3_MATCHINFO_NCOL: |
| @@ -209860,20 +210424,20 @@ | |
| 209860 | case FTS3_MATCHINFO_LCS: |
| 209861 | nVal = pInfo->nCol; |
| 209862 | break; |
| 209863 | |
| 209864 | case FTS3_MATCHINFO_LHITS: |
| 209865 | nVal = (size_t)pInfo->nCol * pInfo->nPhrase; |
| 209866 | break; |
| 209867 | |
| 209868 | case FTS3_MATCHINFO_LHITS_BM: |
| 209869 | nVal = (size_t)pInfo->nPhrase * ((pInfo->nCol + 31) / 32); |
| 209870 | break; |
| 209871 | |
| 209872 | default: |
| 209873 | assert( cArg==FTS3_MATCHINFO_HITS ); |
| 209874 | nVal = (size_t)pInfo->nCol * pInfo->nPhrase * 3; |
| 209875 | break; |
| 209876 | } |
| 209877 | |
| 209878 | return nVal; |
| 209879 | } |
| @@ -210151,11 +210715,11 @@ | |
| 210151 | } |
| 210152 | break; |
| 210153 | |
| 210154 | case FTS3_MATCHINFO_LHITS_BM: |
| 210155 | case FTS3_MATCHINFO_LHITS: { |
| 210156 | size_t nZero = fts3MatchinfoSize(pInfo, zArg[i]) * sizeof(u32); |
| 210157 | memset(pInfo->aMatchinfo, 0, nZero); |
| 210158 | rc = fts3ExprLHitGather(pCsr->pExpr, pInfo); |
| 210159 | break; |
| 210160 | } |
| 210161 | |
| @@ -210220,11 +210784,11 @@ | |
| 210220 | ** matchinfo function has been called for this query. In this case |
| 210221 | ** allocate the array used to accumulate the matchinfo data and |
| 210222 | ** initialize those elements that are constant for every row. |
| 210223 | */ |
| 210224 | if( pCsr->pMIBuffer==0 ){ |
| 210225 | size_t nMatchinfo = 0; /* Number of u32 elements in match-info */ |
| 210226 | int i; /* Used to iterate through zArg */ |
| 210227 | |
| 210228 | /* Determine the number of phrases in the query */ |
| 210229 | pCsr->nPhrase = fts3ExprPhraseCount(pCsr->pExpr); |
| 210230 | sInfo.nPhrase = pCsr->nPhrase; |
| @@ -212214,11 +212778,11 @@ | |
| 212214 | case SQLITE_NULL: { |
| 212215 | jsonAppendRawNZ(p, "null", 4); |
| 212216 | break; |
| 212217 | } |
| 212218 | case SQLITE_FLOAT: { |
| 212219 | jsonPrintf(100, p, "%!0.15g", sqlite3_value_double(pValue)); |
| 212220 | break; |
| 212221 | } |
| 212222 | case SQLITE_INTEGER: { |
| 212223 | const char *z = (const char*)sqlite3_value_text(pValue); |
| 212224 | u32 n = (u32)sqlite3_value_bytes(pValue); |
| @@ -213528,13 +214092,14 @@ | |
| 213528 | */ |
| 213529 | static u32 jsonbPayloadSize(const JsonParse *pParse, u32 i, u32 *pSz){ |
| 213530 | u8 x; |
| 213531 | u32 sz; |
| 213532 | u32 n; |
| 213533 | assert( i<=pParse->nBlob ); |
| 213534 | x = pParse->aBlob[i]>>4; |
| 213535 | if( x<=11 ){ |
| 213536 | sz = x; |
| 213537 | n = 1; |
| 213538 | }else if( x==12 ){ |
| 213539 | if( i+1>=pParse->nBlob ){ |
| 213540 | *pSz = 0; |
| @@ -213744,11 +214309,11 @@ | |
| 213744 | break; |
| 213745 | case '\n': |
| 213746 | break; |
| 213747 | case 0xe2: |
| 213748 | /* '\' followed by either U+2028 or U+2029 is ignored as |
| 213749 | ** whitespace. Not that in UTF8, U+2028 is 0xe2 0x80 0x29. |
| 213750 | ** U+2029 is the same except for the last byte */ |
| 213751 | if( sz2<4 |
| 213752 | || 0x80!=(u8)zIn[2] |
| 213753 | || (0xa8!=(u8)zIn[3] && 0xa9!=(u8)zIn[3]) |
| 213754 | ){ |
| @@ -216313,15 +216878,13 @@ | |
| 216313 | char c; |
| 216314 | JsonString *pStr; |
| 216315 | UNUSED_PARAMETER(argc); |
| 216316 | UNUSED_PARAMETER(argv); |
| 216317 | pStr = (JsonString*)sqlite3_aggregate_context(ctx, 0); |
| 216318 | #ifdef NEVER |
| 216319 | /* pStr is always non-NULL since jsonArrayStep() or jsonObjectStep() will |
| 216320 | ** always have been called to initialize it */ |
| 216321 | if( NEVER(!pStr) ) return; |
| 216322 | #endif |
| 216323 | z = pStr->zBuf; |
| 216324 | for(i=1; i<pStr->nUsed && ((c = z[i])!=',' || inStr || nNest); i++){ |
| 216325 | if( c=='"' ){ |
| 216326 | inStr = !inStr; |
| 216327 | }else if( c=='\\' ){ |
| @@ -216346,10 +216909,17 @@ | |
| 216346 | |
| 216347 | /* |
| 216348 | ** json_group_obj(NAME,VALUE) |
| 216349 | ** |
| 216350 | ** Return a JSON object composed of all names and values in the aggregate. |
| 216351 | */ |
| 216352 | static void jsonObjectStep( |
| 216353 | sqlite3_context *ctx, |
| 216354 | int argc, |
| 216355 | sqlite3_value **argv |
| @@ -216363,49 +216933,97 @@ | |
| 216363 | z = (const char*)sqlite3_value_text(argv[0]); |
| 216364 | n = sqlite3Strlen30(z); |
| 216365 | if( pStr->zBuf==0 ){ |
| 216366 | jsonStringInit(pStr, ctx); |
| 216367 | jsonAppendChar(pStr, '{'); |
| 216368 | }else if( pStr->nUsed>1 && z!=0 ){ |
| 216369 | jsonAppendChar(pStr, ','); |
| 216370 | } |
| 216371 | pStr->pCtx = ctx; |
| 216372 | if( z!=0 ){ |
| 216373 | jsonAppendString(pStr, z, n); |
| 216374 | jsonAppendChar(pStr, ':'); |
| 216375 | jsonAppendSqlValue(pStr, argv[1]); |
| 216376 | } |
| 216377 | } |
| 216378 | } |
| 216379 | static void jsonObjectCompute(sqlite3_context *ctx, int isFinal){ |
| 216380 | JsonString *pStr; |
| 216381 | int flags = SQLITE_PTR_TO_INT(sqlite3_user_data(ctx)); |
| 216382 | pStr = (JsonString*)sqlite3_aggregate_context(ctx, 0); |
| 216383 | if( pStr ){ |
| 216384 | jsonAppendRawNZ(pStr, "}", 2); |
| 216385 | jsonStringTrimOneChar(pStr); |
| 216386 | pStr->pCtx = ctx; |
| 216387 | if( pStr->eErr ){ |
| 216388 | jsonReturnString(pStr, 0, 0); |
| 216389 | return; |
| 216390 | }else if( flags & JSON_BLOB ){ |
| 216391 | jsonReturnStringAsBlob(pStr); |
| 216392 | if( isFinal ){ |
| 216393 | if( !pStr->bStatic ) sqlite3RCStrUnref(pStr->zBuf); |
| 216394 | }else{ |
| 216395 | jsonStringTrimOneChar(pStr); |
| 216396 | } |
| 216397 | return; |
| 216398 | }else if( isFinal ){ |
| 216399 | sqlite3_result_text(ctx, pStr->zBuf, (int)pStr->nUsed, |
| 216400 | pStr->bStatic ? SQLITE_TRANSIENT : |
| 216401 | sqlite3RCStrUnref); |
| 216402 | pStr->bStatic = 1; |
| 216403 | }else{ |
| 216404 | sqlite3_result_text(ctx, pStr->zBuf, (int)pStr->nUsed, SQLITE_TRANSIENT); |
| 216405 | jsonStringTrimOneChar(pStr); |
| 216406 | } |
| 216407 | }else if( flags & JSON_BLOB ){ |
| 216408 | static const unsigned char emptyObject = 0x0c; |
| 216409 | sqlite3_result_blob(ctx, &emptyObject, 1, SQLITE_STATIC); |
| 216410 | }else{ |
| 216411 | sqlite3_result_text(ctx, "{}", 2, SQLITE_STATIC); |
| @@ -216604,10 +217222,19 @@ | |
| 216604 | }else{ |
| 216605 | jsonPrintf(sz+2,&p->path,".%.*s", sz, z); |
| 216606 | } |
| 216607 | } |
| 216608 | } |
| 216609 | |
| 216610 | /* Advance the cursor to the next element for json_tree() */ |
| 216611 | static int jsonEachNext(sqlite3_vtab_cursor *cur){ |
| 216612 | JsonEachCursor *p = (JsonEachCursor*)cur; |
| 216613 | int rc = SQLITE_OK; |
| @@ -216616,10 +217243,11 @@ | |
| 216616 | u8 levelChange = 0; |
| 216617 | u32 n, sz = 0; |
| 216618 | u32 i = jsonSkipLabel(p); |
| 216619 | x = p->sParse.aBlob[i] & 0x0f; |
| 216620 | n = jsonbPayloadSize(&p->sParse, i, &sz); |
| 216621 | if( x==JSONB_OBJECT || x==JSONB_ARRAY ){ |
| 216622 | JsonParent *pParent; |
| 216623 | if( p->nParent>=p->nParentAlloc ){ |
| 216624 | JsonParent *pNew; |
| 216625 | u64 nNew; |
| @@ -216661,10 +217289,11 @@ | |
| 216661 | } |
| 216662 | }else{ |
| 216663 | u32 n, sz = 0; |
| 216664 | u32 i = jsonSkipLabel(p); |
| 216665 | n = jsonbPayloadSize(&p->sParse, i, &sz); |
| 216666 | p->i = i + n + sz; |
| 216667 | } |
| 216668 | if( p->eType==JSONB_ARRAY && p->nParent ){ |
| 216669 | p->aParent[p->nParent-1].iKey++; |
| 216670 | } |
| @@ -216897,11 +217526,11 @@ | |
| 216897 | } |
| 216898 | if( jsonConvertTextToBlob(&p->sParse, 0) ){ |
| 216899 | if( p->sParse.oom ){ |
| 216900 | return SQLITE_NOMEM; |
| 216901 | } |
| 216902 | goto json_each_malformed_input; |
| 216903 | } |
| 216904 | } |
| 216905 | if( idxNum==3 ){ |
| 216906 | zRoot = (const char*)sqlite3_value_text(argv[1]); |
| 216907 | if( zRoot==0 ) return SQLITE_OK; |
| @@ -216958,16 +217587,10 @@ | |
| 216958 | p->aParent[0].iEnd = p->iEnd; |
| 216959 | p->aParent[0].iHead = p->i; |
| 216960 | p->aParent[0].iValue = i; |
| 216961 | } |
| 216962 | return SQLITE_OK; |
| 216963 | |
| 216964 | json_each_malformed_input: |
| 216965 | sqlite3_free(cur->pVtab->zErrMsg); |
| 216966 | cur->pVtab->zErrMsg = sqlite3_mprintf("malformed JSON"); |
| 216967 | jsonEachCursorReset(p); |
| 216968 | return cur->pVtab->zErrMsg ? SQLITE_ERROR : SQLITE_NOMEM; |
| 216969 | } |
| 216970 | |
| 216971 | /* The methods of the json_each virtual table */ |
| 216972 | static sqlite3_module jsonEachModule = { |
| 216973 | 0, /* iVersion */ |
| @@ -217253,11 +217876,11 @@ | |
| 217253 | u8 nDim; /* Number of dimensions */ |
| 217254 | u8 nDim2; /* Twice the number of dimensions */ |
| 217255 | u8 eCoordType; /* RTREE_COORD_REAL32 or RTREE_COORD_INT32 */ |
| 217256 | u8 nBytesPerCell; /* Bytes consumed per cell */ |
| 217257 | u8 inWrTrans; /* True if inside write transaction */ |
| 217258 | u8 nAux; /* # of auxiliary columns in %_rowid */ |
| 217259 | #ifdef SQLITE_ENABLE_GEOPOLY |
| 217260 | u8 nAuxNotNull; /* Number of initial not-null aux columns */ |
| 217261 | #endif |
| 217262 | #ifdef SQLITE_DEBUG |
| 217263 | u8 bCorrupt; /* Shadow table corruption detected */ |
| @@ -217848,10 +218471,13 @@ | |
| 217848 | ** be because the shadow tables hold erroneous data. */ |
| 217849 | if( rc==SQLITE_ERROR ){ |
| 217850 | rc = SQLITE_CORRUPT_VTAB; |
| 217851 | RTREE_IS_CORRUPT(pRtree); |
| 217852 | } |
| 217853 | }else if( pRtree->iNodeSize==sqlite3_blob_bytes(pRtree->pNodeBlob) ){ |
| 217854 | pNode = (RtreeNode *)sqlite3_malloc64(sizeof(RtreeNode)+pRtree->iNodeSize); |
| 217855 | if( !pNode ){ |
| 217856 | rc = SQLITE_NOMEM; |
| 217857 | }else{ |
| @@ -218489,11 +219115,11 @@ | |
| 218489 | i64 iRowid, |
| 218490 | int *piIndex |
| 218491 | ){ |
| 218492 | int ii; |
| 218493 | int nCell = NCELL(pNode); |
| 218494 | assert( nCell<200 ); |
| 218495 | for(ii=0; ii<nCell; ii++){ |
| 218496 | if( nodeGetRowid(pRtree, pNode, ii)==iRowid ){ |
| 218497 | *piIndex = ii; |
| 218498 | return SQLITE_OK; |
| 218499 | } |
| @@ -218751,11 +219377,14 @@ | |
| 218751 | while( (p = rtreeSearchPointFirst(pCur))!=0 && p->iLevel>0 ){ |
| 218752 | u8 *pCellData; |
| 218753 | pNode = rtreeNodeOfFirstSearchPoint(pCur, &rc); |
| 218754 | if( rc ) return rc; |
| 218755 | nCell = NCELL(pNode); |
| 218756 | assert( nCell<200 ); |
| 218757 | pCellData = pNode->zData + (4+pRtree->nBytesPerCell*p->iCell); |
| 218758 | while( p->iCell<nCell ){ |
| 218759 | sqlite3_rtree_dbl rScore = (sqlite3_rtree_dbl)-1; |
| 218760 | eWithin = FULLY_WITHIN; |
| 218761 | for(ii=0; ii<nConstraint; ii++){ |
| @@ -220728,11 +221357,11 @@ | |
| 220728 | "Too few columns for an rtree table", /* 2 */ |
| 220729 | "Too many columns for an rtree table", /* 3 */ |
| 220730 | "Auxiliary rtree columns must be last" /* 4 */ |
| 220731 | }; |
| 220732 | |
| 220733 | assert( RTREE_MAX_AUX_COLUMN<256 ); /* Aux columns counted by a u8 */ |
| 220734 | if( argc<6 || argc>RTREE_MAX_AUX_COLUMN+3 ){ |
| 220735 | *pzErr = sqlite3_mprintf("%s", aErrMsg[2 + (argc>=6)]); |
| 220736 | return SQLITE_ERROR; |
| 220737 | } |
| 220738 | |
| @@ -222646,10 +223275,15 @@ | |
| 222646 | sqlite3_int64 nName; /* Length of string argv[2] */ |
| 222647 | sqlite3_str *pSql; |
| 222648 | char *zSql; |
| 222649 | int ii; |
| 222650 | (void)pAux; |
| 222651 | |
| 222652 | sqlite3_vtab_config(db, SQLITE_VTAB_CONSTRAINT_SUPPORT, 1); |
| 222653 | sqlite3_vtab_config(db, SQLITE_VTAB_INNOCUOUS); |
| 222654 | |
| 222655 | /* Allocate the sqlite3_vtab structure */ |
| @@ -223524,10 +224158,13 @@ | |
| 223524 | if( c>=0xc0 ){ \ |
| 223525 | c = icuUtf8Trans1[c-0xc0]; \ |
| 223526 | while( (*zIn & 0xc0)==0x80 ){ \ |
| 223527 | c = (c<<6) + (0x3f & *(zIn++)); \ |
| 223528 | } \ |
| 223529 | } |
| 223530 | |
| 223531 | #define SQLITE_ICU_SKIP_UTF8(zIn) \ |
| 223532 | assert( *zIn ); \ |
| 223533 | if( *(zIn++)>=0xc0 ){ \ |
| @@ -223781,11 +224418,11 @@ | |
| 223781 | */ |
| 223782 | static void icuCaseFunc16(sqlite3_context *p, int nArg, sqlite3_value **apArg){ |
| 223783 | const UChar *zInput; /* Pointer to input string */ |
| 223784 | UChar *zOutput = 0; /* Pointer to output buffer */ |
| 223785 | int nInput; /* Size of utf-16 input string in bytes */ |
| 223786 | int nOut; /* Size of output buffer in bytes */ |
| 223787 | int cnt; |
| 223788 | int bToUpper; /* True for toupper(), false for tolower() */ |
| 223789 | UErrorCode status; |
| 223790 | const char *zLocale = 0; |
| 223791 | |
| @@ -223804,22 +224441,22 @@ | |
| 223804 | sqlite3_result_text16(p, "", 0, SQLITE_STATIC); |
| 223805 | return; |
| 223806 | } |
| 223807 | |
| 223808 | for(cnt=0; cnt<2; cnt++){ |
| 223809 | UChar *zNew = sqlite3_realloc(zOutput, nOut); |
| 223810 | if( zNew==0 ){ |
| 223811 | sqlite3_free(zOutput); |
| 223812 | sqlite3_result_error_nomem(p); |
| 223813 | return; |
| 223814 | } |
| 223815 | zOutput = zNew; |
| 223816 | status = U_ZERO_ERROR; |
| 223817 | if( bToUpper ){ |
| 223818 | nOut = 2*u_strToUpper(zOutput,nOut/2,zInput,nInput/2,zLocale,&status); |
| 223819 | }else{ |
| 223820 | nOut = 2*u_strToLower(zOutput,nOut/2,zInput,nInput/2,zLocale,&status); |
| 223821 | } |
| 223822 | |
| 223823 | if( U_SUCCESS(status) ){ |
| 223824 | sqlite3_result_text16(p, zOutput, nOut, xFree); |
| 223825 | }else if( status==U_BUFFER_OVERFLOW_ERROR ){ |
| @@ -223935,10 +224572,11 @@ | |
| 223935 | for(i=0; i<sizeof(aStrength)/sizeof(aStrength[0]); i++){ |
| 223936 | sqlite3_str_appendf(pStr, " %s", aStrength[i].zName); |
| 223937 | } |
| 223938 | sqlite3_result_error(p, sqlite3_str_value(pStr), -1); |
| 223939 | sqlite3_free(sqlite3_str_finish(pStr)); |
| 223940 | return; |
| 223941 | } |
| 223942 | } |
| 223943 | rc = sqlite3_create_collation_v2(db, zName, SQLITE_UTF16, (void *)pUCollator, |
| 223944 | icuCollationColl, icuCollationDel |
| @@ -225428,20 +226066,30 @@ | |
| 225428 | 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, -1, -1, -1, -1, |
| 225429 | -1, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, |
| 225430 | 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, -1, -1, -1, -1, 36, |
| 225431 | -1, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, |
| 225432 | 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, -1, -1, -1, 63, -1, |
| 225433 | }; |
| 225434 | unsigned int v = 0; |
| 225435 | int c; |
| 225436 | unsigned char *z = (unsigned char*)*pz; |
| 225437 | unsigned char *zStart = z; |
| 225438 | while( (c = zValue[0x7f&*(z++)])>=0 ){ |
| 225439 | v = (v<<6) + c; |
| 225440 | } |
| 225441 | z--; |
| 225442 | *pLen -= (int)(z - zStart); |
| 225443 | *pz = (char*)z; |
| 225444 | return v; |
| 225445 | } |
| 225446 | |
| 225447 | #if RBU_ENABLE_DELTA_CKSUM |
| @@ -225513,23 +226161,24 @@ | |
| 225513 | #if RBU_ENABLE_DELTA_CKSUM |
| 225514 | char *zOrigOut = zOut; |
| 225515 | #endif |
| 225516 | |
| 225517 | limit = rbuDeltaGetInt(&zDelta, &lenDelta); |
| 225518 | if( *zDelta!='\n' ){ |
| 225519 | /* ERROR: size integer not terminated by "\n" */ |
| 225520 | return -1; |
| 225521 | } |
| 225522 | zDelta++; lenDelta--; |
| 225523 | while( *zDelta && lenDelta>0 ){ |
| 225524 | unsigned int cnt, ofst; |
| 225525 | cnt = rbuDeltaGetInt(&zDelta, &lenDelta); |
| 225526 | switch( zDelta[0] ){ |
| 225527 | case '@': { |
| 225528 | zDelta++; lenDelta--; |
| 225529 | ofst = rbuDeltaGetInt(&zDelta, &lenDelta); |
| 225530 | if( lenDelta>0 && zDelta[0]!=',' ){ |
| 225531 | /* ERROR: copy command not terminated by ',' */ |
| 225532 | return -1; |
| 225533 | } |
| 225534 | zDelta++; lenDelta--; |
| 225535 | total += cnt; |
| @@ -225550,11 +226199,11 @@ | |
| 225550 | total += cnt; |
| 225551 | if( total>limit ){ |
| 225552 | /* ERROR: insert command gives an output larger than predicted */ |
| 225553 | return -1; |
| 225554 | } |
| 225555 | if( (int)cnt>lenDelta ){ |
| 225556 | /* ERROR: insert count exceeds size of delta */ |
| 225557 | return -1; |
| 225558 | } |
| 225559 | memcpy(zOut, zDelta, cnt); |
| 225560 | zOut += cnt; |
| @@ -225588,11 +226237,11 @@ | |
| 225588 | } |
| 225589 | |
| 225590 | static int rbuDeltaOutputSize(const char *zDelta, int lenDelta){ |
| 225591 | int size; |
| 225592 | size = rbuDeltaGetInt(&zDelta, &lenDelta); |
| 225593 | if( *zDelta!='\n' ){ |
| 225594 | /* ERROR: size integer not terminated by "\n" */ |
| 225595 | return -1; |
| 225596 | } |
| 225597 | return size; |
| 225598 | } |
| @@ -225636,11 +226285,11 @@ | |
| 225636 | if( nOut<0 ){ |
| 225637 | sqlite3_result_error(context, "corrupt fossil delta", -1); |
| 225638 | return; |
| 225639 | } |
| 225640 | |
| 225641 | aOut = sqlite3_malloc(nOut+1); |
| 225642 | if( aOut==0 ){ |
| 225643 | sqlite3_result_error_nomem(context); |
| 225644 | }else{ |
| 225645 | nOut2 = rbuDeltaApply(aOrig, nOrig, aDelta, nDelta, aOut); |
| 225646 | if( nOut2!=nOut ){ |
| @@ -231535,16 +232184,17 @@ | |
| 231535 | if( NEVER(pBt==0) ) return SQLITE_OK; |
| 231536 | pCsr->pPager = sqlite3BtreePager(pBt); |
| 231537 | pCsr->szPage = sqlite3BtreeGetPageSize(pBt); |
| 231538 | pCsr->mxPgno = sqlite3BtreeLastPage(pBt); |
| 231539 | if( idxNum & 1 ){ |
| 231540 | assert( argc>(idxNum>>1) ); |
| 231541 | pCsr->pgno = sqlite3_value_int(argv[idxNum>>1]); |
| 231542 | if( pCsr->pgno<1 || pCsr->pgno>pCsr->mxPgno ){ |
| 231543 | pCsr->pgno = 1; |
| 231544 | pCsr->mxPgno = 0; |
| 231545 | }else{ |
| 231546 | pCsr->mxPgno = pCsr->pgno; |
| 231547 | } |
| 231548 | }else{ |
| 231549 | assert( pCsr->pgno==1 ); |
| 231550 | } |
| @@ -231620,10 +232270,11 @@ | |
| 231620 | sqlite3_value **argv, |
| 231621 | sqlite_int64 *pRowid |
| 231622 | ){ |
| 231623 | DbpageTable *pTab = (DbpageTable *)pVtab; |
| 231624 | Pgno pgno; |
| 231625 | DbPage *pDbPage = 0; |
| 231626 | int rc = SQLITE_OK; |
| 231627 | char *zErr = 0; |
| 231628 | int iDb; |
| 231629 | Btree *pBt; |
| @@ -231639,15 +232290,15 @@ | |
| 231639 | if( argc==1 ){ |
| 231640 | zErr = "cannot delete"; |
| 231641 | goto update_fail; |
| 231642 | } |
| 231643 | if( sqlite3_value_type(argv[0])==SQLITE_NULL ){ |
| 231644 | pgno = (Pgno)sqlite3_value_int64(argv[2]); |
| 231645 | isInsert = 1; |
| 231646 | }else{ |
| 231647 | pgno = (Pgno)sqlite3_value_int64(argv[0]); |
| 231648 | if( (Pgno)sqlite3_value_int(argv[1])!=pgno ){ |
| 231649 | zErr = "cannot insert"; |
| 231650 | goto update_fail; |
| 231651 | } |
| 231652 | isInsert = 0; |
| 231653 | } |
| @@ -231660,14 +232311,15 @@ | |
| 231660 | zErr = "no such schema"; |
| 231661 | goto update_fail; |
| 231662 | } |
| 231663 | } |
| 231664 | pBt = pTab->db->aDb[iDb].pBt; |
| 231665 | if( pgno<1 || NEVER(pBt==0) ){ |
| 231666 | zErr = "bad page number"; |
| 231667 | goto update_fail; |
| 231668 | } |
| 231669 | szPage = sqlite3BtreeGetPageSize(pBt); |
| 231670 | if( sqlite3_value_type(argv[3])!=SQLITE_BLOB |
| 231671 | || sqlite3_value_bytes(argv[3])!=szPage |
| 231672 | ){ |
| 231673 | if( sqlite3_value_type(argv[3])==SQLITE_NULL && isInsert && pgno>1 ){ |
| @@ -232688,11 +233340,13 @@ | |
| 232688 | /* |
| 232689 | ** Read a varint value from aBuf[] into *piVal. Return the number of |
| 232690 | ** bytes read. |
| 232691 | */ |
| 232692 | static int sessionVarintGet(const u8 *aBuf, int *piVal){ |
| 232693 | return getVarint32(aBuf, *piVal); |
| 232694 | } |
| 232695 | |
| 232696 | /* |
| 232697 | ** Read a varint value from buffer aBuf[], size nBuf bytes, into *piVal. |
| 232698 | ** Return the number of bytes read. |
| @@ -232703,11 +233357,11 @@ | |
| 232703 | memset(aCopy, 0, sizeof(aCopy)); |
| 232704 | if( nBuf<sizeof(aCopy) ){ |
| 232705 | memcpy(aCopy, aBuf, nBuf); |
| 232706 | aRead = aCopy; |
| 232707 | } |
| 232708 | return getVarint32(aRead, *piVal); |
| 232709 | } |
| 232710 | |
| 232711 | /* Load an unaligned and unsigned 32-bit integer */ |
| 232712 | #define SESSION_UINT32(x) (((u32)(x)[0]<<24)|((x)[1]<<16)|((x)[2]<<8)|(x)[3]) |
| 232713 | |
| @@ -233886,10 +234540,20 @@ | |
| 233886 | } |
| 233887 | sqlite3_free(sql.aBuf); |
| 233888 | |
| 233889 | return rc; |
| 233890 | } |
| 233891 | |
| 233892 | /* |
| 233893 | ** Table pTab has one or more existing change-records with old.* records |
| 233894 | ** with fewer than pTab->nCol columns. This function updates all such |
| 233895 | ** change-records with the default values for the missing columns. |
| @@ -233909,13 +234573,12 @@ | |
| 233909 | } |
| 233910 | } |
| 233911 | } |
| 233912 | } |
| 233913 | |
| 233914 | pSession->rc = rc; |
| 233915 | rc = sqlite3_finalize(pStmt); |
| 233916 | if( pSession->rc==SQLITE_OK ) pSession->rc = rc; |
| 233917 | return pSession->rc; |
| 233918 | } |
| 233919 | |
| 233920 | /* |
| 233921 | ** Versions of the four methods in object SessionHook for use with the |
| @@ -234479,11 +235142,11 @@ | |
| 234479 | |
| 234480 | if( zStmt==0 ){ |
| 234481 | rc = SQLITE_NOMEM; |
| 234482 | }else{ |
| 234483 | sqlite3_stmt *pStmt; |
| 234484 | rc = sqlite3_prepare(pSession->db, zStmt, -1, &pStmt, 0); |
| 234485 | if( rc==SQLITE_OK ){ |
| 234486 | SessionDiffCtx *pDiffCtx = (SessionDiffCtx*)pSession->hook.pCtx; |
| 234487 | pDiffCtx->pStmt = pStmt; |
| 234488 | pDiffCtx->nOldOff = 0; |
| 234489 | pDiffCtx->bRowid = pTab->bRowid; |
| @@ -234542,11 +235205,11 @@ | |
| 234542 | ); |
| 234543 | if( zStmt==0 || z1==0 || z2==0 ){ |
| 234544 | rc = SQLITE_NOMEM; |
| 234545 | }else{ |
| 234546 | sqlite3_stmt *pStmt; |
| 234547 | rc = sqlite3_prepare(pSession->db, zStmt, -1, &pStmt, 0); |
| 234548 | |
| 234549 | if( rc==SQLITE_OK ){ |
| 234550 | SessionDiffCtx *pDiffCtx = (SessionDiffCtx*)pSession->hook.pCtx; |
| 234551 | pDiffCtx->pStmt = pStmt; |
| 234552 | pDiffCtx->nOldOff = pTab->nCol; |
| @@ -235237,15 +235900,15 @@ | |
| 235237 | sessionAppendStr(&pkvar, |
| 235238 | "?1, (CASE WHEN ?2=X'' THEN NULL ELSE ?2 END)", &rc |
| 235239 | ); |
| 235240 | sessionAppendStr(&cols, "tbl, ?2, stat", &rc); |
| 235241 | }else{ |
| 235242 | #if 0 |
| 235243 | if( bRowid ){ |
| 235244 | sessionAppendStr(&cols, SESSIONS_ROWID, &rc); |
| 235245 | } |
| 235246 | #endif |
| 235247 | for(i=0; i<nCol; i++){ |
| 235248 | if( cols.nBuf ) sessionAppendStr(&cols, ", ", &rc); |
| 235249 | sessionAppendIdent(&cols, azCol[i], &rc); |
| 235250 | if( abPK[i] ){ |
| 235251 | sessionAppendStr(&pkfield, zSep, &rc); |
| @@ -236036,21 +236699,25 @@ | |
| 236036 | int i; |
| 236037 | for(i=0; rc==SQLITE_OK && i<nCol; i++){ |
| 236038 | int eType; |
| 236039 | rc = sessionInputBuffer(pIn, nByte + 10); |
| 236040 | if( rc==SQLITE_OK ){ |
| 236041 | eType = pIn->aData[pIn->iNext + nByte++]; |
| 236042 | if( eType==SQLITE_TEXT || eType==SQLITE_BLOB ){ |
| 236043 | int n; |
| 236044 | int nRem = pIn->nData - (pIn->iNext + nByte); |
| 236045 | nByte += sessionVarintGetSafe(&pIn->aData[pIn->iNext+nByte], nRem, &n); |
| 236046 | nByte += n; |
| 236047 | rc = sessionInputBuffer(pIn, nByte); |
| 236048 | }else if( eType==SQLITE_INTEGER || eType==SQLITE_FLOAT ){ |
| 236049 | nByte += 8; |
| 236050 | }else if( eType!=0 && eType!=SQLITE_NULL ){ |
| 236051 | rc = SQLITE_CORRUPT_BKPT; |
| 236052 | } |
| 236053 | } |
| 236054 | if( rc==SQLITE_OK && (pIn->iNext+nByte)>pIn->nData ){ |
| 236055 | rc = SQLITE_CORRUPT_BKPT; |
| 236056 | } |
| @@ -236495,11 +237162,17 @@ | |
| 236495 | while( 1 ){ |
| 236496 | u8 eType; |
| 236497 | |
| 236498 | /* Test for EOF. */ |
| 236499 | if( (rc = sessionInputBuffer(pInput, 2)) ) goto finished_invert; |
| 236500 | if( pInput->iNext>=pInput->nData ) break; |
| 236501 | eType = pInput->aData[pInput->iNext]; |
| 236502 | |
| 236503 | switch( eType ){ |
| 236504 | case 'T': { |
| 236505 | /* A 'table' record consists of: |
| @@ -236691,10 +237364,11 @@ | |
| 236691 | SessionBuffer constraints; /* Deferred constraints are stored here */ |
| 236692 | SessionBuffer rebase; /* Rebase information (if any) here */ |
| 236693 | u8 bRebaseStarted; /* If table header is already in rebase */ |
| 236694 | u8 bRebase; /* True to collect rebase information */ |
| 236695 | u8 bIgnoreNoop; /* True to ignore no-op conflicts */ |
| 236696 | int bRowid; |
| 236697 | char *zErr; /* Error message, if any */ |
| 236698 | }; |
| 236699 | |
| 236700 | /* Number of prepared UPDATE statements to cache. */ |
| @@ -237264,11 +237938,11 @@ | |
| 237264 | /* Instead of invoking the conflict handler, append the change blob |
| 237265 | ** to the SessionApplyCtx.constraints buffer. */ |
| 237266 | u8 *aBlob = &pIter->in.aData[pIter->in.iCurrent]; |
| 237267 | int nBlob = pIter->in.iNext - pIter->in.iCurrent; |
| 237268 | sessionAppendBlob(&p->constraints, aBlob, nBlob, &rc); |
| 237269 | return SQLITE_OK; |
| 237270 | }else if( p->bIgnoreNoop==0 || op!=SQLITE_DELETE |
| 237271 | || eType==SQLITE_CHANGESET_CONFLICT |
| 237272 | ){ |
| 237273 | /* No other row with the new.* primary key. */ |
| 237274 | res = xConflict(pCtx, eType+1, pIter); |
| @@ -237386,11 +238060,11 @@ | |
| 237386 | |
| 237387 | /* Bind values to the UPDATE statement. */ |
| 237388 | for(i=0; rc==SQLITE_OK && i<nCol; i++){ |
| 237389 | sqlite3_value *pOld = sessionChangesetOld(pIter, i); |
| 237390 | sqlite3_value *pNew = sessionChangesetNew(pIter, i); |
| 237391 | if( p->abPK[i] || (bPatchset==0 && pOld) ){ |
| 237392 | rc = sessionBindValue(pUp, i*2+2, pOld); |
| 237393 | } |
| 237394 | if( rc==SQLITE_OK && pNew ){ |
| 237395 | rc = sessionBindValue(pUp, i*2+1, pNew); |
| 237396 | } |
| @@ -237512,11 +238186,268 @@ | |
| 237512 | |
| 237513 | return rc; |
| 237514 | } |
| 237515 | |
| 237516 | /* |
| 237517 | ** Retry the changes accumulated in the pApply->constraints buffer. |
| 237518 | */ |
| 237519 | static int sessionRetryConstraints( |
| 237520 | sqlite3 *db, |
| 237521 | int bPatchset, |
| 237522 | const char *zTab, |
| @@ -237523,45 +238454,105 @@ | |
| 237523 | SessionApplyCtx *pApply, |
| 237524 | int(*xConflict)(void*, int, sqlite3_changeset_iter*), |
| 237525 | void *pCtx /* First argument passed to xConflict */ |
| 237526 | ){ |
| 237527 | int rc = SQLITE_OK; |
| 237528 | |
| 237529 | while( pApply->constraints.nBuf ){ |
| 237530 | sqlite3_changeset_iter *pIter2 = 0; |
| 237531 | SessionBuffer cons = pApply->constraints; |
| 237532 | memset(&pApply->constraints, 0, sizeof(SessionBuffer)); |
| 237533 | |
| 237534 | rc = sessionChangesetStart( |
| 237535 | &pIter2, 0, 0, cons.nBuf, cons.aBuf, pApply->bInvertConstraints, 1 |
| 237536 | ); |
| 237537 | if( rc==SQLITE_OK ){ |
| 237538 | size_t nByte = 2*pApply->nCol*sizeof(sqlite3_value*); |
| 237539 | int rc2; |
| 237540 | pIter2->bPatchset = bPatchset; |
| 237541 | pIter2->zTab = (char*)zTab; |
| 237542 | pIter2->nCol = pApply->nCol; |
| 237543 | pIter2->abPK = pApply->abPK; |
| 237544 | sessionBufferGrow(&pIter2->tblhdr, nByte, &rc); |
| 237545 | pIter2->apValue = (sqlite3_value**)pIter2->tblhdr.aBuf; |
| 237546 | if( rc==SQLITE_OK ) memset(pIter2->apValue, 0, nByte); |
| 237547 | |
| 237548 | while( rc==SQLITE_OK && SQLITE_ROW==sqlite3changeset_next(pIter2) ){ |
| 237549 | rc = sessionApplyOneWithRetry(db, pIter2, pApply, xConflict, pCtx); |
| 237550 | } |
| 237551 | |
| 237552 | rc2 = sqlite3changeset_finalize(pIter2); |
| 237553 | if( rc==SQLITE_OK ) rc = rc2; |
| 237554 | } |
| 237555 | assert( pApply->bDeferConstraints || pApply->constraints.nBuf==0 ); |
| 237556 | |
| 237557 | sqlite3_free(cons.aBuf); |
| 237558 | if( rc!=SQLITE_OK ) break; |
| 237559 | if( pApply->constraints.nBuf>=cons.nBuf ){ |
| 237560 | /* No progress was made on the last round. */ |
| 237561 | pApply->bDeferConstraints = 0; |
| 237562 | } |
| 237563 | } |
| 237564 | |
| 237565 | return rc; |
| 237566 | } |
| 237567 | |
| @@ -237611,10 +238602,11 @@ | |
| 237611 | pIter->in.bNoDiscard = 1; |
| 237612 | memset(&sApply, 0, sizeof(sApply)); |
| 237613 | sApply.bRebase = (ppRebase && pnRebase); |
| 237614 | sApply.bInvertConstraints = !!(flags & SQLITE_CHANGESETAPPLY_INVERT); |
| 237615 | sApply.bIgnoreNoop = !!(flags & SQLITE_CHANGESETAPPLY_IGNORENOOP); |
| 237616 | if( (flags & SQLITE_CHANGESETAPPLY_NOSAVEPOINT)==0 ){ |
| 237617 | rc = sqlite3_exec(db, "SAVEPOINT changeset_apply", 0, 0, 0); |
| 237618 | } |
| 237619 | if( rc==SQLITE_OK ){ |
| 237620 | rc = sqlite3_exec(db, "PRAGMA defer_foreign_keys = 1", 0, 0, 0); |
| @@ -239422,11 +240414,11 @@ | |
| 239422 | int bNew, |
| 239423 | int iCol, |
| 239424 | const void *pVal, |
| 239425 | int nVal |
| 239426 | ){ |
| 239427 | sqlite3_int64 nByte = 1 + sessionVarintLen(nVal) + nVal; |
| 239428 | int rc = SQLITE_OK; |
| 239429 | SessionBuffer *pBuf = 0; |
| 239430 | |
| 239431 | if( SQLITE_OK!=(rc = checkChangeParams(pGrp, bNew, iCol, nByte, &pBuf)) ){ |
| 239432 | return rc; |
| @@ -239447,10 +240439,11 @@ | |
| 239447 | sqlite3_changegroup *pGrp, |
| 239448 | int bDiscard, |
| 239449 | char **pzErr |
| 239450 | ){ |
| 239451 | int rc = SQLITE_OK; |
| 239452 | if( pGrp->cd.pTab ){ |
| 239453 | SessionBuffer *aBuf = pGrp->cd.aBuf; |
| 239454 | int ii; |
| 239455 | |
| 239456 | if( bDiscard==0 ){ |
| @@ -239458,26 +240451,26 @@ | |
| 239458 | u8 eUndef = SQLITE_NULL; |
| 239459 | if( pGrp->cd.eOp==SQLITE_UPDATE ){ |
| 239460 | for(ii=0; ii<nBuf; ii++){ |
| 239461 | if( pGrp->cd.pTab->abPK[ii] ){ |
| 239462 | if( aBuf[ii].nBuf<=1 ){ |
| 239463 | *pzErr = sqlite3_mprintf( |
| 239464 | "invalid change: %s value in PK of old.* record", |
| 239465 | aBuf[ii].nBuf==1 ? "null" : "undefined" |
| 239466 | ); |
| 239467 | rc = SQLITE_ERROR; |
| 239468 | break; |
| 239469 | }else if( aBuf[ii + nBuf].nBuf>0 ){ |
| 239470 | *pzErr = sqlite3_mprintf( |
| 239471 | "invalid change: defined value in PK of new.* record" |
| 239472 | ); |
| 239473 | rc = SQLITE_ERROR; |
| 239474 | break; |
| 239475 | } |
| 239476 | }else |
| 239477 | if( pGrp->bPatch==0 && (aBuf[ii].nBuf>0)!=(aBuf[ii+nBuf].nBuf>0) ){ |
| 239478 | *pzErr = sqlite3_mprintf( |
| 239479 | "invalid change: column %d " |
| 239480 | "- old.* value is %sdefined but new.* is %sdefined", |
| 239481 | ii, aBuf[ii].nBuf ? "" : "un", aBuf[ii+nBuf].nBuf ? "" : "un" |
| 239482 | ); |
| 239483 | rc = SQLITE_ERROR; |
| @@ -239490,18 +240483,18 @@ | |
| 239490 | for(ii=0; ii<nBuf; ii++){ |
| 239491 | int isPK = pGrp->cd.pTab->abPK[ii]; |
| 239492 | if( (pGrp->cd.eOp==SQLITE_INSERT || pGrp->bPatch==0 || isPK) |
| 239493 | && aBuf[ii].nBuf==0 |
| 239494 | ){ |
| 239495 | *pzErr = sqlite3_mprintf( |
| 239496 | "invalid change: column %d is undefined", ii |
| 239497 | ); |
| 239498 | rc = SQLITE_ERROR; |
| 239499 | break; |
| 239500 | } |
| 239501 | if( aBuf[ii].nBuf==1 && isPK ){ |
| 239502 | *pzErr = sqlite3_mprintf( |
| 239503 | "invalid change: null value in PK" |
| 239504 | ); |
| 239505 | rc = SQLITE_ERROR; |
| 239506 | break; |
| 239507 | } |
| @@ -239547,10 +240540,15 @@ | |
| 239547 | } |
| 239548 | } |
| 239549 | pGrp->cd.pTab = 0; |
| 239550 | } |
| 239551 | |
| 239552 | return rc; |
| 239553 | } |
| 239554 | |
| 239555 | #endif /* SQLITE_ENABLE_SESSION && SQLITE_ENABLE_PREUPDATE_HOOK */ |
| 239556 | |
| @@ -243272,11 +244270,11 @@ | |
| 243272 | ){ |
| 243273 | HighlightContext ctx; |
| 243274 | int rc = SQLITE_OK; /* Return code */ |
| 243275 | int iCol; /* 1st argument to snippet() */ |
| 243276 | const char *zEllips; /* 4th argument to snippet() */ |
| 243277 | int nToken; /* 5th argument to snippet() */ |
| 243278 | int nInst = 0; /* Number of instance matches this row */ |
| 243279 | int i; /* Used to iterate through instances */ |
| 243280 | int nPhrase; /* Number of phrases in query */ |
| 243281 | unsigned char *aSeen; /* Array of "seen instance" flags */ |
| 243282 | int iBestCol; /* Column containing best snippet */ |
| @@ -243297,11 +244295,11 @@ | |
| 243297 | iCol = sqlite3_value_int(apVal[0]); |
| 243298 | ctx.zOpen = fts5ValueToText(apVal[1]); |
| 243299 | ctx.zClose = fts5ValueToText(apVal[2]); |
| 243300 | ctx.iRangeEnd = -1; |
| 243301 | zEllips = fts5ValueToText(apVal[3]); |
| 243302 | nToken = sqlite3_value_int(apVal[4]); |
| 243303 | |
| 243304 | iBestCol = (iCol>=0 ? iCol : 0); |
| 243305 | nPhrase = pApi->xPhraseCount(pFts); |
| 243306 | aSeen = sqlite3_malloc64(nPhrase); |
| 243307 | if( aSeen==0 ){ |
| @@ -246013,11 +247011,11 @@ | |
| 246013 | /* Add an entry to each output position list */ |
| 246014 | for(i=0; i<pNear->nPhrase; i++){ |
| 246015 | i64 iPos = a[i].reader.iPos; |
| 246016 | Fts5PoslistWriter *pWriter = &a[i].writer; |
| 246017 | if( a[i].pOut->n==0 || iPos!=pWriter->iPrev ){ |
| 246018 | sqlite3Fts5PoslistWriterAppend(a[i].pOut, pWriter, iPos); |
| 246019 | } |
| 246020 | } |
| 246021 | |
| 246022 | iAdv = 0; |
| 246023 | iMin = a[0].reader.iLookahead; |
| @@ -246964,14 +247962,14 @@ | |
| 246964 | rc = SQLITE_NOMEM; |
| 246965 | }else{ |
| 246966 | memset(pSyn, 0, (size_t)nByte); |
| 246967 | pSyn->pTerm = ((char*)pSyn) + sizeof(Fts5ExprTerm) + sizeof(Fts5Buffer); |
| 246968 | pSyn->nFullTerm = pSyn->nQueryTerm = nToken; |
| 246969 | if( pCtx->pConfig->bTokendata ){ |
| 246970 | pSyn->nQueryTerm = (int)strlen(pSyn->pTerm); |
| 246971 | } |
| 246972 | memcpy(pSyn->pTerm, pToken, nToken); |
| 246973 | pSyn->pSynonym = pPhrase->aTerm[pPhrase->nTerm-1].pSynonym; |
| 246974 | pPhrase->aTerm[pPhrase->nTerm-1].pSynonym = pSyn; |
| 246975 | } |
| 246976 | }else{ |
| 246977 | Fts5ExprTerm *pTerm; |
| @@ -248816,11 +249814,11 @@ | |
| 248816 | ** + 1 byte for a "new column" byte, |
| 248817 | ** + 3 bytes for a new column number (16-bit max) as a varint, |
| 248818 | ** + 5 bytes for the new position offset (32-bit max). |
| 248819 | */ |
| 248820 | if( (p->nAlloc - p->nData) < (9 + 4 + 1 + 3 + 5) ){ |
| 248821 | sqlite3_int64 nNew = p->nAlloc * 2; |
| 248822 | Fts5HashEntry *pNew; |
| 248823 | Fts5HashEntry **pp; |
| 248824 | pNew = (Fts5HashEntry*)sqlite3_realloc64(p, nNew); |
| 248825 | if( pNew==0 ) return SQLITE_NOMEM; |
| 248826 | pNew->nAlloc = (int)nNew; |
| @@ -250006,11 +251004,11 @@ | |
| 250006 | } |
| 250007 | |
| 250008 | static Fts5Data *fts5LeafRead(Fts5Index *p, i64 iRowid){ |
| 250009 | Fts5Data *pRet = fts5DataRead(p, iRowid); |
| 250010 | if( pRet ){ |
| 250011 | if( pRet->nn<4 || pRet->szLeaf>pRet->nn ){ |
| 250012 | FTS5_CORRUPT_ROWID(p, iRowid); |
| 250013 | fts5DataRelease(pRet); |
| 250014 | pRet = 0; |
| 250015 | } |
| 250016 | } |
| @@ -250250,11 +251248,11 @@ | |
| 250250 | }else{ |
| 250251 | i += fts5GetVarint32(&pData[i], pLvl->nMerge); |
| 250252 | i += fts5GetVarint32(&pData[i], nTotal); |
| 250253 | if( nTotal<pLvl->nMerge ) rc = FTS5_CORRUPT; |
| 250254 | pLvl->aSeg = (Fts5StructureSegment*)sqlite3Fts5MallocZero(&rc, |
| 250255 | nTotal * sizeof(Fts5StructureSegment) |
| 250256 | ); |
| 250257 | nSegment -= nTotal; |
| 250258 | } |
| 250259 | |
| 250260 | if( rc==SQLITE_OK ){ |
| @@ -250779,19 +251777,20 @@ | |
| 250779 | assert( pLvl->bEof==0 ); |
| 250780 | if( iOff<=pLvl->iFirstOff ){ |
| 250781 | pLvl->bEof = 1; |
| 250782 | }else{ |
| 250783 | u8 *a = pLvl->pData->p; |
| 250784 | |
| 250785 | pLvl->iOff = 0; |
| 250786 | fts5DlidxLvlNext(pLvl); |
| 250787 | while( 1 ){ |
| 250788 | int nZero = 0; |
| 250789 | int ii = pLvl->iOff; |
| 250790 | u64 delta = 0; |
| 250791 | |
| 250792 | while( a[ii]==0 ){ |
| 250793 | nZero++; |
| 250794 | ii++; |
| 250795 | } |
| 250796 | ii += sqlite3Fts5GetVarint(&a[ii], &delta); |
| 250797 | |
| @@ -251206,11 +252205,11 @@ | |
| 251206 | fts5DataRelease(pIter->pLeaf); |
| 251207 | pIter->pLeaf = 0; |
| 251208 | while( p->rc==SQLITE_OK && pIter->iLeafPgno>pIter->iTermLeafPgno ){ |
| 251209 | Fts5Data *pNew; |
| 251210 | pIter->iLeafPgno--; |
| 251211 | pNew = fts5DataRead(p, FTS5_SEGMENT_ROWID( |
| 251212 | pIter->pSeg->iSegid, pIter->iLeafPgno |
| 251213 | )); |
| 251214 | if( pNew ){ |
| 251215 | /* iTermLeafOffset may be equal to szLeaf if the term is the last |
| 251216 | ** thing on the page - i.e. the first rowid is on the following page. |
| @@ -251659,10 +252658,14 @@ | |
| 251659 | |
| 251660 | /* Figure out how many new bytes are in this term */ |
| 251661 | fts5FastGetVarint32(a, iOff, nNew); |
| 251662 | if( nKeep<nMatch ){ |
| 251663 | goto search_failed; |
| 251664 | } |
| 251665 | |
| 251666 | assert( nKeep>=nMatch ); |
| 251667 | if( nKeep==nMatch ){ |
| 251668 | u32 nCmp; |
| @@ -252636,12 +253639,11 @@ | |
| 252636 | } |
| 252637 | } |
| 252638 | |
| 252639 | do { |
| 252640 | while( i<nChunk && pChunk[i]!=0x01 ){ |
| 252641 | while( pChunk[i] & 0x80 ) i++; |
| 252642 | i++; |
| 252643 | } |
| 252644 | if( pCtx->eState ){ |
| 252645 | fts5BufferSafeAppendBlob(pCtx->pBuf, &pChunk[iStart], i-iStart); |
| 252646 | } |
| 252647 | if( i<nChunk ){ |
| @@ -252786,11 +253788,11 @@ | |
| 252786 | } |
| 252787 | |
| 252788 | /* Advance pointer p until it points to pEnd or an 0x01 byte that is |
| 252789 | ** not part of a varint */ |
| 252790 | while( p<pEnd && *p!=0x01 ){ |
| 252791 | while( *p++ & 0x80 ); |
| 252792 | } |
| 252793 | |
| 252794 | if( pColset->aiCol[i]==iCurrent ){ |
| 252795 | if( pColset->nCol==1 ){ |
| 252796 | pIter->base.pData = aCopy; |
| @@ -252883,12 +253885,15 @@ | |
| 252883 | */ |
| 252884 | static void fts5IterSetOutputs_Col100(Fts5Iter *pIter, Fts5SegIter *pSeg){ |
| 252885 | |
| 252886 | assert( pIter->pIndex->pConfig->eDetail==FTS5_DETAIL_COLUMNS ); |
| 252887 | assert( pIter->pColset ); |
| 252888 | |
| 252889 | if( pSeg->iLeafOffset+pSeg->nPos>pSeg->pLeaf->szLeaf ){ |
| 252890 | fts5IterSetOutputs_Col(pIter, pSeg); |
| 252891 | }else{ |
| 252892 | u8 *a = (u8*)&pSeg->pLeaf->p[pSeg->iLeafOffset]; |
| 252893 | u8 *pEnd = (u8*)&a[pSeg->nPos]; |
| 252894 | int iPrev = 0; |
| @@ -254377,10 +255382,15 @@ | |
| 254377 | int iSOP; /* Start-Of-Position-list */ |
| 254378 | if( pSeg->iLeafPgno==pSeg->iTermLeafPgno ){ |
| 254379 | iStart = pSeg->iTermLeafOffset; |
| 254380 | }else{ |
| 254381 | iStart = fts5GetU16(&aPg[0]); |
| 254382 | } |
| 254383 | |
| 254384 | iSOP = iStart + fts5GetVarint(&aPg[iStart], &iDelta); |
| 254385 | assert_nc( iSOP<=pSeg->iLeafOffset ); |
| 254386 | |
| @@ -257063,12 +258073,12 @@ | |
| 257063 | int *pnOut, /* OUT: Number of output pages */ |
| 257064 | Fts5Data ***papOut /* OUT: Output hash pages */ |
| 257065 | ){ |
| 257066 | const int MINSLOT = 32; |
| 257067 | int nSlotPerPage = MAX(MINSLOT, (p->pConfig->pgsz - 8) / szKey); |
| 257068 | int nSlot = 0; /* Number of slots in each output page */ |
| 257069 | int nOut = 0; |
| 257070 | |
| 257071 | /* Figure out how many output pages (nOut) and how many slots per |
| 257072 | ** page (nSlot). There are three possibilities: |
| 257073 | ** |
| 257074 | ** 1. The hash table does not yet exist. In this case the new hash |
| @@ -257089,27 +258099,30 @@ | |
| 257089 | /* Case 1. */ |
| 257090 | nOut = 1; |
| 257091 | nSlot = MINSLOT; |
| 257092 | }else if( pSeg->nPgTombstone==1 ){ |
| 257093 | /* Case 2. */ |
| 257094 | int nElem = (int)fts5GetU32(&pData1->p[4]); |
| 257095 | assert( pData1 && iPg1==0 ); |
| 257096 | nOut = 1; |
| 257097 | nSlot = MAX(nElem*4, MINSLOT); |
| 257098 | if( nSlot>nSlotPerPage ) nOut = 0; |
| 257099 | } |
| 257100 | if( nOut==0 ){ |
| 257101 | /* Case 3. */ |
| 257102 | nOut = (pSeg->nPgTombstone * 2 + 1); |
| 257103 | nSlot = nSlotPerPage; |
| 257104 | } |
| 257105 | |
| 257106 | /* Allocate the required array and output pages */ |
| 257107 | while( 1 ){ |
| 257108 | int res = 0; |
| 257109 | int ii = 0; |
| 257110 | int szPage = 0; |
| 257111 | Fts5Data **apOut = 0; |
| 257112 | |
| 257113 | /* Allocate space for the new hash table */ |
| 257114 | assert( nSlot>=MINSLOT ); |
| 257115 | apOut = (Fts5Data**)sqlite3Fts5MallocZero(&p->rc, sizeof(Fts5Data*) * nOut); |
| @@ -257643,11 +258656,11 @@ | |
| 257643 | ){ |
| 257644 | |
| 257645 | /* Check any rowid-less pages that occur before the current leaf. */ |
| 257646 | for(iPg=iPrevLeaf+1; iPg<fts5DlidxIterPgno(pDlidx); iPg++){ |
| 257647 | iKey = FTS5_SEGMENT_ROWID(iSegid, iPg); |
| 257648 | pLeaf = fts5DataRead(p, iKey); |
| 257649 | if( pLeaf ){ |
| 257650 | if( fts5LeafFirstRowidOff(pLeaf)!=0 ) FTS5_CORRUPT_ROWID(p, iKey); |
| 257651 | fts5DataRelease(pLeaf); |
| 257652 | } |
| 257653 | } |
| @@ -257654,11 +258667,11 @@ | |
| 257654 | iPrevLeaf = fts5DlidxIterPgno(pDlidx); |
| 257655 | |
| 257656 | /* Check that the leaf page indicated by the iterator really does |
| 257657 | ** contain the rowid suggested by the same. */ |
| 257658 | iKey = FTS5_SEGMENT_ROWID(iSegid, iPrevLeaf); |
| 257659 | pLeaf = fts5DataRead(p, iKey); |
| 257660 | if( pLeaf ){ |
| 257661 | i64 iRowid; |
| 257662 | int iRowidOff = fts5LeafFirstRowidOff(pLeaf); |
| 257663 | ASSERT_SZLEAF_OK(pLeaf); |
| 257664 | if( iRowidOff>=pLeaf->szLeaf ){ |
| @@ -262254,11 +263267,11 @@ | |
| 262254 | int nArg, /* Number of args */ |
| 262255 | sqlite3_value **apUnused /* Function arguments */ |
| 262256 | ){ |
| 262257 | assert( nArg==0 ); |
| 262258 | UNUSED_PARAM2(nArg, apUnused); |
| 262259 | sqlite3_result_text(pCtx, "fts5: 2026-05-04 10:14:13 7e4134e3ff1ca8712f5fc78fadae665549450988dc43af27c7fe0c77f10ce3fb", -1, SQLITE_TRANSIENT); |
| 262260 | } |
| 262261 | |
| 262262 | /* |
| 262263 | ** Implementation of fts5_locale(LOCALE, TEXT) function. |
| 262264 | ** |
| @@ -264648,12 +265661,18 @@ | |
| 264648 | PorterTokenizer *pRet; |
| 264649 | void *pUserdata = 0; |
| 264650 | const char *zBase = "unicode61"; |
| 264651 | fts5_tokenizer_v2 *pV2 = 0; |
| 264652 | |
| 264653 | if( nArg>0 ){ |
| 264654 | zBase = azArg[0]; |
| 264655 | } |
| 264656 | |
| 264657 | pRet = (PorterTokenizer*)sqlite3_malloc64(sizeof(PorterTokenizer)); |
| 264658 | if( pRet ){ |
| 264659 | memset(pRet, 0, sizeof(PorterTokenizer)); |
| 264660 |
| --- extsrc/sqlite3.c | |
| +++ extsrc/sqlite3.c | |
| @@ -16,11 +16,11 @@ | |
| 16 | ** if you want a wrapper to interface SQLite with your choice of programming |
| 17 | ** language. The code for the "sqlite3" command-line shell is also in a |
| 18 | ** separate file. This file contains only code for the core SQLite library. |
| 19 | ** |
| 20 | ** The content in this amalgamation comes from Fossil check-in |
| 21 | ** 3f3fb9b638f59ad982beafb7c117f24ddd3d with changes in files: |
| 22 | ** |
| 23 | ** |
| 24 | */ |
| 25 | #ifndef SQLITE_AMALGAMATION |
| 26 | #define SQLITE_CORE 1 |
| @@ -467,14 +467,14 @@ | |
| 467 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 468 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 469 | */ |
| 470 | #define SQLITE_VERSION "3.54.0" |
| 471 | #define SQLITE_VERSION_NUMBER 3054000 |
| 472 | #define SQLITE_SOURCE_ID "2026-06-16 13:43:08 3f3fb9b638f59ad982beafb7c117f24ddd3da612e62c862510805fa672ffae06" |
| 473 | #define SQLITE_SCM_BRANCH "trunk" |
| 474 | #define SQLITE_SCM_TAGS "" |
| 475 | #define SQLITE_SCM_DATETIME "2026-06-16T13:43:08.110Z" |
| 476 | |
| 477 | /* |
| 478 | ** CAPI3REF: Run-Time Library Version Numbers |
| 479 | ** KEYWORDS: sqlite3_version sqlite3_sourceid |
| 480 | ** |
| @@ -4373,12 +4373,11 @@ | |
| 4373 | ** parameter on F or if the value of P does not match any of the |
| 4374 | ** above, then sqlite3_uri_boolean(F,P,B) returns (B!=0). |
| 4375 | ** |
| 4376 | ** The sqlite3_uri_int64(F,P,D) routine converts the value of P into a |
| 4377 | ** 64-bit signed integer and returns that integer, or D if P does not |
| 4378 | ** exist or ff the value of P is something other than an integer. |
| 4379 | ** |
| 4380 | ** The sqlite3_uri_key(F,N) returns a pointer to the name (not |
| 4381 | ** the value) of the N-th query parameter for filename F, or a NULL |
| 4382 | ** pointer if N is less than zero or greater than the number of query |
| 4383 | ** parameters minus 1. The N value is zero-based so N should be 0 to obtain |
| @@ -4697,11 +4696,12 @@ | |
| 4696 | ** <dd>The maximum number of columns in a table definition or in the |
| 4697 | ** result set of a [SELECT] or the maximum number of columns in an index |
| 4698 | ** or in an ORDER BY or GROUP BY clause.</dd>)^ |
| 4699 | ** |
| 4700 | ** [[SQLITE_LIMIT_EXPR_DEPTH]] ^(<dt>SQLITE_LIMIT_EXPR_DEPTH</dt> |
| 4701 | ** <dd>The maximum depth of the parse tree on any expression and |
| 4702 | ** the maximum nesting depth for subqueries and VIEWs</dd>)^ |
| 4703 | ** |
| 4704 | ** [[SQLITE_LIMIT_PARSER_DEPTH]] ^(<dt>SQLITE_LIMIT_PARSER_DEPTH</dt> |
| 4705 | ** <dd>The maximum depth of the LALR(1) parser stack used to analyze |
| 4706 | ** input SQL statements.</dd>)^ |
| 4707 | ** |
| @@ -4728,11 +4728,12 @@ | |
| 4728 | ** [[SQLITE_LIMIT_VARIABLE_NUMBER]] |
| 4729 | ** ^(<dt>SQLITE_LIMIT_VARIABLE_NUMBER</dt> |
| 4730 | ** <dd>The maximum index number of any [parameter] in an SQL statement.)^ |
| 4731 | ** |
| 4732 | ** [[SQLITE_LIMIT_TRIGGER_DEPTH]] ^(<dt>SQLITE_LIMIT_TRIGGER_DEPTH</dt> |
| 4733 | ** <dd>The maximum depth of recursion for triggers, and the maximum |
| 4734 | ** nesting depth for separate triggers.</dd>)^ |
| 4735 | ** |
| 4736 | ** [[SQLITE_LIMIT_WORKER_THREADS]] ^(<dt>SQLITE_LIMIT_WORKER_THREADS</dt> |
| 4737 | ** <dd>The maximum number of auxiliary worker threads that a single |
| 4738 | ** [prepared statement] may start.</dd>)^ |
| 4739 | ** </dl> |
| @@ -11534,12 +11535,23 @@ | |
| 11535 | ** reopen S as an in-memory database based on the serialization |
| 11536 | ** contained in P. If S is a NULL pointer, the main database is |
| 11537 | ** used. The serialized database P is N bytes in size. M is the size |
| 11538 | ** of the buffer P, which might be larger than N. If M is larger than |
| 11539 | ** N, and the SQLITE_DESERIALIZE_READONLY bit is not set in F, then |
| 11540 | ** SQLite is permitted to add content to the in-memory database, in |
| 11541 | ** page-sized chunks, as long as the total size does not exceed M bytes. |
| 11542 | ** |
| 11543 | ** The parameter M must be greater than or equal to N. Ideally, M |
| 11544 | ** should have a value which is N+(512×K)+20 where K determines how |
| 11545 | ** must extra space is available to hold new content as the database |
| 11546 | ** grows. K can be 0 if the database is read-only. |
| 11547 | ** |
| 11548 | ** If the database content in P is malformed in a malicious way then |
| 11549 | ** it is possible that SQLite might try to read a few more than N bytes |
| 11550 | ** from P. If the veracity of the database content P is uncertain, |
| 11551 | ** then applications are advised to allocate about 20 extra bytes on |
| 11552 | ** the end of the P buffer to avoid a memory error. |
| 11553 | ** |
| 11554 | ** If the SQLITE_DESERIALIZE_FREEONCLOSE bit is set in F, then SQLite will |
| 11555 | ** invoke sqlite3_free() on the serialization buffer when the database |
| 11556 | ** connection closes. If the SQLITE_DESERIALIZE_RESIZEABLE bit is set, then |
| 11557 | ** SQLite will try to increase the buffer size using sqlite3_realloc64() |
| @@ -13184,15 +13196,27 @@ | |
| 13196 | ** <dt>SQLITE_CHANGESETAPPLY_FKNOACTION <dd> |
| 13197 | ** If this flag it set, then all foreign key constraints in the target |
| 13198 | ** database behave as if they were declared with "ON UPDATE NO ACTION ON |
| 13199 | ** DELETE NO ACTION", even if they are actually CASCADE, RESTRICT, SET NULL |
| 13200 | ** or SET DEFAULT. |
| 13201 | ** |
| 13202 | ** <dt>SQLITE_CHANGESETAPPLY_NOUPDATELOOP <dd> |
| 13203 | ** Sometimes, a changeset contains two or more update statements such that |
| 13204 | ** although after applying all updates the database will contain no |
| 13205 | ** constraint violations, no single update can be applied before the others. |
| 13206 | ** The simplest example of this is a pair of UPDATEs that have "swapped" |
| 13207 | ** two column values with a UNIQUE constraint. |
| 13208 | ** <p> |
| 13209 | ** Usually, sqlite3changeset_apply() and similar functions work hard to try |
| 13210 | ** to find a way to apply such a changeset. However, if this flag is set, |
| 13211 | ** then all such updates are considered CONSTRAINT conflicts. |
| 13212 | */ |
| 13213 | #define SQLITE_CHANGESETAPPLY_NOSAVEPOINT 0x0001 |
| 13214 | #define SQLITE_CHANGESETAPPLY_INVERT 0x0002 |
| 13215 | #define SQLITE_CHANGESETAPPLY_IGNORENOOP 0x0004 |
| 13216 | #define SQLITE_CHANGESETAPPLY_FKNOACTION 0x0008 |
| 13217 | #define SQLITE_CHANGESETAPPLY_NOUPDATELOOP 0x0010 |
| 13218 | |
| 13219 | /* |
| 13220 | ** CAPI3REF: Constants Passed To The Conflict Handler |
| 13221 | ** |
| 13222 | ** Values that may be passed as the second argument to a conflict-handler. |
| @@ -15798,10 +15822,17 @@ | |
| 15822 | */ |
| 15823 | #ifndef offsetof |
| 15824 | # define offsetof(ST,M) ((size_t)((char*)&((ST*)0)->M - (char*)0)) |
| 15825 | #endif |
| 15826 | |
| 15827 | /* |
| 15828 | ** sizeof64() is like sizeof(), but always returns a 64-bit value, even |
| 15829 | ** on 32-bit builds. This can help to avoid overflow by ensuring 64-bit |
| 15830 | ** arithmetic is used consistently in both 32-bit and 64-bit builds. |
| 15831 | */ |
| 15832 | #define sizeof64(X) ((sqlite3_int64)sizeof(X)) |
| 15833 | |
| 15834 | /* |
| 15835 | ** Work around C99 "flex-array" syntax for pre-C99 compilers, so as |
| 15836 | ** to avoid complaints from -fsanitize=strict-bounds. |
| 15837 | */ |
| 15838 | #if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) |
| @@ -18705,11 +18736,11 @@ | |
| 18736 | int aLimit[SQLITE_N_LIMIT]; /* Limits */ |
| 18737 | int nMaxSorterMmap; /* Maximum size of regions mapped by sorter */ |
| 18738 | struct sqlite3InitInfo { /* Information used during initialization */ |
| 18739 | Pgno newTnum; /* Rootpage of table being initialized */ |
| 18740 | u8 iDb; /* Which db file is being initialized */ |
| 18741 | u8 busy; /* TRUE if initing. 2 if due to ADD COLUMN */ |
| 18742 | unsigned orphanTrigger : 1; /* Last statement is orphaned TEMP trigger */ |
| 18743 | unsigned imposterTable : 2; /* Building an imposter table */ |
| 18744 | unsigned reopenMemdb : 1; /* ATTACH is really a reopen using MemDB */ |
| 18745 | const char **azInit; /* "type", "name", and "tbl_name" columns */ |
| 18746 | } init; |
| @@ -20917,10 +20948,11 @@ | |
| 20948 | int nTab; /* Number of previously allocated VDBE cursors */ |
| 20949 | int nMem; /* Number of memory cells used so far */ |
| 20950 | int szOpAlloc; /* Bytes of memory space allocated for Vdbe.aOp[] */ |
| 20951 | int iSelfTab; /* Table associated with an index on expr, or negative |
| 20952 | ** of the base register during check-constraint eval */ |
| 20953 | int nNestSel; /* Number of nested SELECT statements and/or VIEWs */ |
| 20954 | int nLabel; /* The *negative* of the number of labels used */ |
| 20955 | int nLabelAlloc; /* Number of slots in aLabel */ |
| 20956 | int *aLabel; /* Space to hold the labels */ |
| 20957 | ExprList *pConstExpr;/* Constant expressions */ |
| 20958 | IndexedExpr *pIdxEpr;/* List of expressions used by active indexes */ |
| @@ -21256,11 +21288,11 @@ | |
| 21288 | */ |
| 21289 | #define INITFLAG_AlterMask 0x0007 /* Types of ALTER */ |
| 21290 | #define INITFLAG_AlterRename 0x0001 /* Reparse after a RENAME */ |
| 21291 | #define INITFLAG_AlterDrop 0x0002 /* Reparse after a DROP COLUMN */ |
| 21292 | #define INITFLAG_AlterAdd 0x0003 /* Reparse after an ADD COLUMN */ |
| 21293 | #define INITFLAG_AlterDropCons 0x0004 /* Reparse after a DROP CONSTRAINT */ |
| 21294 | |
| 21295 | /* Tuning parameters are set using SQLITE_TESTCTRL_TUNE and are controlled |
| 21296 | ** on debug-builds of the CLI using ".testctrl tune ID VALUE". Tuning |
| 21297 | ** parameters are for temporary use during development, to help find |
| 21298 | ** optimal values for parameters in the query planner. The should not |
| @@ -22509,11 +22541,19 @@ | |
| 22541 | SQLITE_PRIVATE void sqlite3Reindex(Parse*, Token*, Token*); |
| 22542 | SQLITE_PRIVATE void sqlite3AlterFunctions(void); |
| 22543 | SQLITE_PRIVATE void sqlite3AlterRenameTable(Parse*, SrcList*, Token*); |
| 22544 | SQLITE_PRIVATE void sqlite3AlterRenameColumn(Parse*, SrcList*, Token*, Token*); |
| 22545 | SQLITE_PRIVATE void sqlite3AlterDropConstraint(Parse*,SrcList*,Token*,Token*); |
| 22546 | SQLITE_PRIVATE void sqlite3AlterAddConstraint( |
| 22547 | Parse *pParse, /* Parse context */ |
| 22548 | SrcList *pSrc, /* Table to add constraint to */ |
| 22549 | Token *pFirst, /* First token of new constraint */ |
| 22550 | Token *pName, /* Name of new constraint. NULL if name omitted. */ |
| 22551 | const char *zExpr, /* Text of CHECK expression */ |
| 22552 | int nExpr, /* Size of pExpr in bytes */ |
| 22553 | Expr *pExpr /* The parsed CHECK expression */ |
| 22554 | ); |
| 22555 | SQLITE_PRIVATE void sqlite3AlterSetNotNull(Parse*, SrcList*, Token*, Token*); |
| 22556 | SQLITE_PRIVATE i64 sqlite3GetToken(const unsigned char *, int *); |
| 22557 | SQLITE_PRIVATE void sqlite3NestedParse(Parse*, const char*, ...); |
| 22558 | SQLITE_PRIVATE void sqlite3ExpirePreparedStatements(sqlite3*, int); |
| 22559 | SQLITE_PRIVATE void sqlite3CodeRhsOfIN(Parse*, Expr*, int, int); |
| @@ -32413,12 +32453,14 @@ | |
| 32453 | #define etSRCITEM 12 /* a pointer to a SrcItem */ |
| 32454 | #define etPOINTER 13 /* The %p conversion */ |
| 32455 | #define etESCAPE_w 14 /* %w -> Strings with '\"' doubled */ |
| 32456 | #define etORDINAL 15 /* %r -> 1st, 2nd, 3rd, 4th, etc. English only */ |
| 32457 | #define etDECIMAL 16 /* %d or %u, but not %x, %o */ |
| 32458 | #define etESCAPE_j 17 /* %j -> JSON string literal w/o "..." */ |
| 32459 | #define etESCAPE_J 18 /* %J -> JSON string literal with "..." */ |
| 32460 | |
| 32461 | #define etINVALID 19 /* Any unrecognized conversion type */ |
| 32462 | |
| 32463 | |
| 32464 | /* |
| 32465 | ** An "etByte" is an 8-bit unsigned value. |
| 32466 | */ |
| @@ -32444,24 +32486,24 @@ | |
| 32486 | #define FLAG_SIGNED 1 /* True if the value to convert is signed */ |
| 32487 | #define FLAG_STRING 4 /* Allow infinite precision */ |
| 32488 | |
| 32489 | /* |
| 32490 | ** The table is searched by hash. In the case of %C where C is the character |
| 32491 | ** and that character has ASCII value j, then the hash is j%25. |
| 32492 | ** |
| 32493 | ** The order of the entries in fmtinfo[] and the hash chain was entered |
| 32494 | ** manually, but based on the output of the following TCL script: |
| 32495 | */ |
| 32496 | #if 0 /***** Beginning of script ******/ |
| 32497 | foreach c {d s g z q Q w c o u x X f e E G i n % p T S r J j} { |
| 32498 | scan $c %c x |
| 32499 | set n($c) $x |
| 32500 | } |
| 32501 | set mx [llength [array names n]] |
| 32502 | puts "count: $mx" |
| 32503 | |
| 32504 | set mx 25 |
| 32505 | puts "*********** mx=$mx ************" |
| 32506 | for {set r 0} {$r<$mx} {incr r} { |
| 32507 | puts -nonewline [format %2d: $r] |
| 32508 | foreach c [array names n] { |
| 32509 | if {($n($c))%$mx==$r} {puts -nonewline " $c"} |
| @@ -32469,35 +32511,38 @@ | |
| 32511 | puts "" |
| 32512 | } |
| 32513 | #endif /***** End of script ********/ |
| 32514 | |
| 32515 | static const char aDigits[] = "0123456789ABCDEF0123456789abcdef"; |
| 32516 | static const char aHex[] = "0123456789abcdef"; |
| 32517 | static const char aPrefix[] = "-x0\000X0"; |
| 32518 | static const et_info fmtinfo[25] = { |
| 32519 | /* 0 */ { 'd', 10, 1, etDECIMAL, 0, 0, 0 }, |
| 32520 | /* 1 */ { 'e', 0, 1, etEXP, 30, 0, 0 }, |
| 32521 | /* 2 */ { 'f', 0, 1, etFLOAT, 0, 0, 0 }, |
| 32522 | /* 3 */ { 'g', 0, 1, etGENERIC, 30, 0, 0 }, |
| 32523 | /* 4 */ { 'j', 0, 0, etESCAPE_j, 0, 0, 0 }, /* Hash: 6 */ |
| 32524 | /* 5 */ { 'i', 10, 1, etDECIMAL, 0, 0, 0 }, |
| 32525 | /* 6 */ { 'Q', 0, 4, etESCAPE_Q, 0, 0, 4 }, |
| 32526 | /* 7 */ { 'p', 16, 0, etPOINTER, 0, 1, 0 }, /* Hash: 12 */ |
| 32527 | /* 8 */ { 'S', 0, 0, etSRCITEM, 0, 0, 0 }, |
| 32528 | /* 9 */ { 'T', 0, 0, etTOKEN, 0, 0, 0 }, |
| 32529 | /* 10 */ { 'n', 0, 0, etSIZE, 0, 0, 0 }, |
| 32530 | /* 11 */ { 'o', 8, 0, etRADIX, 0, 2, 0 }, |
| 32531 | /* 12 */ { '%', 0, 0, etPERCENT, 0, 0, 7 }, |
| 32532 | /* 13 */ { 'q', 0, 4, etESCAPE_q, 0, 0, 16 }, |
| 32533 | /* 14 */ { 'r', 10, 1, etORDINAL, 0, 0, 0 }, |
| 32534 | /* 15 */ { 's', 0, 4, etSTRING, 0, 0, 0 }, |
| 32535 | /* 16 */ { 'X', 16, 0, etRADIX, 0, 4, 0 }, /* Hash: 13 */ |
| 32536 | /* 17 */ { 'u', 10, 0, etDECIMAL, 0, 0, 0 }, |
| 32537 | /* 18 */ { 'w', 0, 4, etESCAPE_w, 0, 0, 0 }, /* Hash: 19 */ |
| 32538 | /* 19 */ { 'E', 0, 1, etEXP, 14, 0, 18 }, |
| 32539 | /* 20 */ { 'x', 16, 0, etRADIX, 16, 1, 0 }, |
| 32540 | /* 21 */ { 'G', 0, 1, etGENERIC, 14, 0, 0 }, |
| 32541 | /* 22 */ { 'z', 0, 4, etDYNSTRING, 0, 0, 0 }, |
| 32542 | /* 23 */ { 'J', 0, 0, etESCAPE_J, 0, 0, 0 }, /* Hash: 24 */ |
| 32543 | /* 24 */ { 'c', 0, 0, etCHARX, 0, 0, 23 } |
| 32544 | }; |
| 32545 | |
| 32546 | /* Additional Notes: |
| 32547 | ** |
| 32548 | ** %S Takes a pointer to SrcItem. Shows name or database.name |
| @@ -32754,12 +32799,12 @@ | |
| 32799 | break; |
| 32800 | } |
| 32801 | } |
| 32802 | #else |
| 32803 | /* Fast hash-table lookup */ |
| 32804 | assert( ArraySize(fmtinfo)==25 ); |
| 32805 | idx = ((unsigned)c) % 25; |
| 32806 | if( fmtinfo[idx].fmttype==c |
| 32807 | || fmtinfo[idx = fmtinfo[idx].iNxt].fmttype==c |
| 32808 | ){ |
| 32809 | infop = &fmtinfo[idx]; |
| 32810 | xtype = infop->type; |
| @@ -33126,11 +33171,11 @@ | |
| 33171 | length = width; |
| 33172 | } |
| 33173 | |
| 33174 | if( zExtra==0 ){ |
| 33175 | /* The result is being rendered directory into pAccum. This |
| 33176 | ** is the common and fast case */ |
| 33177 | pAccum->nChar += length; |
| 33178 | zOut[length] = 0; |
| 33179 | continue; |
| 33180 | }else{ |
| 33181 | /* We were unable to render directly into pAccum because we |
| @@ -33246,10 +33291,87 @@ | |
| 33291 | /* Adjust width to account for extra bytes in UTF-8 characters */ |
| 33292 | int ii = length - 1; |
| 33293 | while( ii>=0 ) if( (bufpt[ii--] & 0xc0)==0x80 ) width++; |
| 33294 | } |
| 33295 | break; |
| 33296 | case etESCAPE_j: /* %j: JSON string literal w/o "..." */ |
| 33297 | case etESCAPE_J: { /* %J: Generate a JSON string literal */ |
| 33298 | char *escarg; |
| 33299 | i64 i, j, px, iStart; |
| 33300 | unsigned char ch; |
| 33301 | |
| 33302 | if( bArgList ){ |
| 33303 | escarg = getTextArg(pArgList); |
| 33304 | }else{ |
| 33305 | escarg = va_arg(ap,char*); |
| 33306 | } |
| 33307 | iStart = sqlite3_str_length(pAccum); |
| 33308 | if( escarg==0 ){ |
| 33309 | if( xtype==etESCAPE_J ) sqlite3_str_append(pAccum, "null", 4); |
| 33310 | }else{ |
| 33311 | if( xtype==etESCAPE_J ) sqlite3_str_append(pAccum, "\"", 1); |
| 33312 | px = precision; |
| 33313 | testcase( px==0 ); |
| 33314 | if( px<0 ){ |
| 33315 | px = 0x7fffffff; |
| 33316 | }else if( flag_altform2 ){ |
| 33317 | /* Convert precision from code-points to bytes */ |
| 33318 | for(i=0; i<px && escarg[i]; i++){ |
| 33319 | if( (escarg[i]&0xc0)==0x80 ) px++; |
| 33320 | } |
| 33321 | if( i==px ){ |
| 33322 | while( (escarg[px]&0xc0)==0x80 ) px++; |
| 33323 | } |
| 33324 | } |
| 33325 | for(i=j=0; i<px; i++){ |
| 33326 | if( (ch = ((u8*)escarg)[i])<=0x1f || ch=='"' || ch=='\\' ){ |
| 33327 | if( j<i ) sqlite3_str_append(pAccum, &escarg[j], i-j); |
| 33328 | j = i+1; |
| 33329 | if( ch==0 ) break; |
| 33330 | sqlite3_str_appendchar(pAccum, 1, '\\'); |
| 33331 | if( ch>0x1f ){ |
| 33332 | sqlite3_str_appendchar(pAccum, 1, ch); |
| 33333 | }else if( ((1u<<ch)&0x3700)!=0 ){ |
| 33334 | ch = "btn?fr"[ch-8]; |
| 33335 | sqlite3_str_appendchar(pAccum, 1, ch); |
| 33336 | }else{ |
| 33337 | sqlite3_str_append(pAccum, "u00", 3); |
| 33338 | sqlite3_str_appendchar(pAccum, 1, aHex[ch>>4]); |
| 33339 | sqlite3_str_appendchar(pAccum, 1, aHex[ch&0xf]); |
| 33340 | } |
| 33341 | } |
| 33342 | } |
| 33343 | if( j<i ) sqlite3_str_append(pAccum, &escarg[j], i-j); |
| 33344 | if( xtype==etESCAPE_J ) sqlite3_str_append(pAccum, "\"", 1); |
| 33345 | } |
| 33346 | if( width>0 && sqlite3_str_errcode(pAccum)==SQLITE_OK ){ |
| 33347 | sqlite3_int64 n = sqlite3_str_length(pAccum) - iStart; |
| 33348 | sqlite3_int64 len = n; |
| 33349 | char *zz; |
| 33350 | if( flag_altform2 && n>0 ){ |
| 33351 | zz = sqlite3_str_value(pAccum); |
| 33352 | for(i=iStart; zz[i]; i++){ |
| 33353 | if( (zz[i]&0xc0)==0x80 ) len--; |
| 33354 | } |
| 33355 | } |
| 33356 | if( width>len ){ |
| 33357 | sqlite3_int64 sp = width-len; |
| 33358 | assert( sp>0 && sp<0x7fffffff ); |
| 33359 | sqlite3_str_appendchar(pAccum, (int)sp, ' '); |
| 33360 | if( !flag_leftjustify |
| 33361 | && n>0 |
| 33362 | && sqlite3_str_errcode(pAccum)==0 |
| 33363 | ){ |
| 33364 | zz = sqlite3_str_value(pAccum); |
| 33365 | zz += iStart; |
| 33366 | memmove(zz+sp, zz, n); |
| 33367 | memset(zz, ' ', sp); |
| 33368 | } |
| 33369 | } |
| 33370 | } |
| 33371 | continue; |
| 33372 | } |
| 33373 | case etESCAPE_q: /* %q: Escape ' characters */ |
| 33374 | case etESCAPE_Q: /* %Q: Escape ' and enclose in '...' */ |
| 33375 | case etESCAPE_w: { /* %w: Escape " characters */ |
| 33376 | i64 i, j, k, n; |
| 33377 | int needQuote = 0; |
| @@ -33288,12 +33410,12 @@ | |
| 33410 | if( flag_alternateform ){ |
| 33411 | /* For %#q, do unistr()-style backslash escapes for |
| 33412 | ** all control characters, and for backslash itself. |
| 33413 | ** For %#Q, do the same but only if there is at least |
| 33414 | ** one control character. */ |
| 33415 | i64 nBack = 0; |
| 33416 | i64 nCtrl = 0; |
| 33417 | for(k=0; k<i; k++){ |
| 33418 | if( escarg[k]=='\\' ){ |
| 33419 | nBack++; |
| 33420 | }else if( ((u8*)escarg)[k]<=0x1f ){ |
| 33421 | nCtrl++; |
| @@ -33337,11 +33459,11 @@ | |
| 33459 | bufpt[j-1] = '\\'; |
| 33460 | bufpt[j++] = 'u'; |
| 33461 | bufpt[j++] = '0'; |
| 33462 | bufpt[j++] = '0'; |
| 33463 | bufpt[j++] = ch>=0x10 ? '1' : '0'; |
| 33464 | bufpt[j++] = aHex[ch&0xf]; |
| 33465 | } |
| 33466 | } |
| 33467 | }else{ |
| 33468 | for(i=0; i<k; i++){ |
| 33469 | bufpt[j++] = ch = escarg[i]; |
| @@ -39154,10 +39276,26 @@ | |
| 39276 | ****************************************************************************** |
| 39277 | ** |
| 39278 | ** This file contains an experimental VFS layer that operates on a |
| 39279 | ** Key/Value storage engine where both keys and values must be pure |
| 39280 | ** text. |
| 39281 | ** |
| 39282 | ** DEBUG AND TEST |
| 39283 | ** |
| 39284 | ** For testing on Unix, compile using: |
| 39285 | ** |
| 39286 | ** make clean sqlite3d CFLAGS='-DSQLITE_OS_KV_OPTIONAL' |
| 39287 | ** |
| 39288 | ** Then start up a shell using something like: |
| 39289 | ** |
| 39290 | ** ./sqlite3d 'file:dbname?vfs=kvvfs' |
| 39291 | ** |
| 39292 | ** Each K/V entry is stored in a separate file in the working |
| 39293 | ** directory that has a name like "kvvfs-dbname-*". Due to limitations |
| 39294 | ** on the key size, the name of the database must be very short - just |
| 39295 | ** a few characters. If the database name is too long, the VFS will |
| 39296 | ** malfunction and you will get SQLITE_CORRUPT errors. |
| 39297 | */ |
| 39298 | /* #include <sqliteInt.h> */ |
| 39299 | #if SQLITE_OS_KV || (SQLITE_OS_UNIX && defined(SQLITE_OS_KV_OPTIONAL)) |
| 39300 | |
| 39301 | /***************************************************************************** |
| @@ -39606,16 +39744,18 @@ | |
| 39744 | } |
| 39745 | if( j+n>nOut ) return -1; |
| 39746 | memset(&aOut[j], 0, n); |
| 39747 | j += n; |
| 39748 | if( c==0 || mult==1 ) break; /* progress stalled if mult==1 */ |
| 39749 | }else if( j<nOut ){ |
| 39750 | aOut[j] = c<<4; |
| 39751 | c = kvvfsHexValue[aIn[++i]]; |
| 39752 | if( c<0 ) return -1 /* hex bytes are always in pairs */; |
| 39753 | aOut[j++] += c; |
| 39754 | i++; |
| 39755 | }else{ |
| 39756 | return -1; |
| 39757 | } |
| 39758 | } |
| 39759 | return j; |
| 39760 | } |
| 39761 | |
| @@ -40037,10 +40177,22 @@ | |
| 40177 | }else{ |
| 40178 | pFile->isJournal = 0; |
| 40179 | pFile->base.pMethods = &kvvfs_db_io_methods; |
| 40180 | } |
| 40181 | if( !pFile->zClass ){ |
| 40182 | #ifdef SQLITE_WASM |
| 40183 | if( strlen(zName) >= (KVRECORD_KEY_SZ |
| 40184 | - 6 /* "kvvfs-" */ |
| 40185 | - 11 /* "-##########" */) ){ |
| 40186 | return SQLITE_CANTOPEN; |
| 40187 | } |
| 40188 | #else |
| 40189 | if( 0!=strcmp(zName, "local") && 0!=strcmp(zName, "session") ){ |
| 40190 | /* Historical naming restriction which journaling depends on. */ |
| 40191 | return SQLITE_CANTOPEN; |
| 40192 | } |
| 40193 | #endif |
| 40194 | pFile->zClass = zName; |
| 40195 | } |
| 40196 | pFile->aData = sqlite3_malloc64(SQLITE_KVOS_SZ); |
| 40197 | if( pFile->aData==0 ){ |
| 40198 | return SQLITE_NOMEM; |
| @@ -45345,13 +45497,13 @@ | |
| 45497 | |
| 45498 | /* Minimum number of regions required to be mapped. */ |
| 45499 | nReqRegion = ((iRegion+nShmPerMap) / nShmPerMap) * nShmPerMap; |
| 45500 | |
| 45501 | if( pShmNode->nRegion<nReqRegion ){ |
| 45502 | char **apNew; /* New apRegion[] array */ |
| 45503 | i64 nByte = nReqRegion*(i64)szRegion; /* Minimum required file size */ |
| 45504 | struct stat sStat; /* Used by fstat() */ |
| 45505 | |
| 45506 | pShmNode->szRegion = szRegion; |
| 45507 | |
| 45508 | if( pShmNode->hShm>=0 ){ |
| 45509 | /* The requested region is not mapped into this processes address space. |
| @@ -45378,11 +45530,11 @@ | |
| 45530 | ** pages forces the OS to allocate them immediately, which reduces |
| 45531 | ** the chances of SIGBUS while accessing the mapped region later on. |
| 45532 | */ |
| 45533 | else{ |
| 45534 | static const int pgsz = 4096; |
| 45535 | i64 iPg; |
| 45536 | |
| 45537 | /* Write to the last byte of each newly allocated or extended page */ |
| 45538 | assert( (nByte % pgsz)==0 ); |
| 45539 | for(iPg=(sStat.st_size/pgsz); iPg<(nByte/pgsz); iPg++){ |
| 45540 | int x = 0; |
| @@ -45404,12 +45556,12 @@ | |
| 45556 | rc = SQLITE_IOERR_NOMEM_BKPT; |
| 45557 | goto shmpage_out; |
| 45558 | } |
| 45559 | pShmNode->apRegion = apNew; |
| 45560 | while( pShmNode->nRegion<nReqRegion ){ |
| 45561 | i64 nMap = (i64)szRegion*(i64)nShmPerMap; |
| 45562 | i64 i; |
| 45563 | void *pMem; |
| 45564 | if( pShmNode->hShm>=0 ){ |
| 45565 | pMem = osMmap(0, nMap, |
| 45566 | pShmNode->isReadonly ? PROT_READ : PROT_READ|PROT_WRITE, |
| 45567 | MAP_SHARED, pShmNode->hShm, szRegion*(i64)pShmNode->nRegion |
| @@ -49195,107 +49347,154 @@ | |
| 49347 | |
| 49348 | { "CreateFileW", (SYSCALL)CreateFileW, 0 }, |
| 49349 | #define osCreateFileW ((HANDLE(WINAPI*)(LPCWSTR,DWORD,DWORD, \ |
| 49350 | LPSECURITY_ATTRIBUTES,DWORD,DWORD,HANDLE))aSyscall[2].pCurrent) |
| 49351 | |
| 49352 | #if defined(SQLITE_UWP) |
| 49353 | { "CreateFileMappingFromApp",(SYSCALL)CreateFileMappingFromApp,0 }, |
| 49354 | #else |
| 49355 | { "CreateFileMappingFromApp",(SYSCALL)0, 0 }, |
| 49356 | #endif |
| 49357 | #define osCreateFileMappingFromApp ((HANDLE(WINAPI*)(HANDLE,\ |
| 49358 | PSECURITY_ATTRIBUTES, \ |
| 49359 | ULONG,ULONG64,PCWSTR))aSyscall[3].pCurrent) |
| 49360 | |
| 49361 | #if !defined(SQLITE_UWP) |
| 49362 | { "CreateFileMappingW", (SYSCALL)CreateFileMappingW, 0 }, |
| 49363 | #else |
| 49364 | { "CreateFileMappingW", (SYSCALL)0, 0 }, |
| 49365 | #endif |
| 49366 | #define osCreateFileMappingW ((HANDLE(WINAPI*)(HANDLE,LPSECURITY_ATTRIBUTES, \ |
| 49367 | DWORD,DWORD,DWORD,LPCWSTR))aSyscall[4].pCurrent) |
| 49368 | |
| 49369 | { "DeleteFileW", (SYSCALL)DeleteFileW, 0 }, |
| 49370 | #define osDeleteFileW ((BOOL(WINAPI*)(LPCWSTR))aSyscall[5].pCurrent) |
| 49371 | |
| 49372 | { "FlushFileBuffers", (SYSCALL)FlushFileBuffers, 0 }, |
| 49373 | #define osFlushFileBuffers ((BOOL(WINAPI*)(HANDLE))aSyscall[6].pCurrent) |
| 49374 | |
| 49375 | { "FormatMessageW", (SYSCALL)FormatMessageW, 0 }, |
| 49376 | #define osFormatMessageW ((DWORD(WINAPI*)(DWORD,LPCVOID,DWORD,DWORD,LPWSTR, \ |
| 49377 | DWORD,va_list*))aSyscall[7].pCurrent) |
| 49378 | |
| 49379 | #if !defined(SQLITE_OMIT_LOAD_EXTENSION) && !defined(SQLITE_UWP) |
| 49380 | { "FreeLibrary", (SYSCALL)FreeLibrary, 0 }, |
| 49381 | #else |
| 49382 | { "FreeLibrary", (SYSCALL)0, 0 }, |
| 49383 | #endif |
| 49384 | |
| 49385 | #define osFreeLibrary ((BOOL(WINAPI*)(HMODULE))aSyscall[8].pCurrent) |
| 49386 | |
| 49387 | { "GetCurrentProcessId", (SYSCALL)GetCurrentProcessId, 0 }, |
| 49388 | #define osGetCurrentProcessId ((DWORD(WINAPI*)(VOID))aSyscall[9].pCurrent) |
| 49389 | |
| 49390 | { "GetFileAttributesW", (SYSCALL)GetFileAttributesW, 0 }, |
| 49391 | #define osGetFileAttributesW ((DWORD(WINAPI*)(LPCWSTR))aSyscall[10].pCurrent) |
| 49392 | |
| 49393 | { "GetFileAttributesExW", (SYSCALL)GetFileAttributesExW, 0 }, |
| 49394 | #define osGetFileAttributesExW ((BOOL(WINAPI*)(LPCWSTR,GET_FILEEX_INFO_LEVELS, \ |
| 49395 | LPVOID))aSyscall[11].pCurrent) |
| 49396 | |
| 49397 | { "GetFileSizeEx", (SYSCALL)GetFileSizeEx, 0 }, |
| 49398 | #define osGetFileSizeEx ((BOOL(WINAPI*)(HANDLE, \ |
| 49399 | PLARGE_INTEGER))aSyscall[12].pCurrent) |
| 49400 | |
| 49401 | { "GetFullPathNameW", (SYSCALL)GetFullPathNameW, 0 }, |
| 49402 | #define osGetFullPathNameW ((DWORD(WINAPI*)(LPCWSTR,DWORD,LPWSTR, \ |
| 49403 | LPWSTR*))aSyscall[13].pCurrent) |
| 49404 | |
| 49405 | { "GetLastError", (SYSCALL)GetLastError, 0 }, |
| 49406 | #define osGetLastError ((DWORD(WINAPI*)(VOID))aSyscall[14].pCurrent) |
| 49407 | |
| 49408 | #if !defined(SQLITE_OMIT_LOAD_EXTENSION) && !defined(SQLITE_UWP) |
| 49409 | { "GetProcAddressA", (SYSCALL)GetProcAddress, 0 }, |
| 49410 | #else |
| 49411 | { "GetProcAddressA", (SYSCALL)0, 0 }, |
| 49412 | #endif |
| 49413 | #define osGetProcAddressA ((FARPROC(WINAPI*)(HMODULE, \ |
| 49414 | LPCSTR))aSyscall[15].pCurrent) |
| 49415 | |
| 49416 | { "GetSystemInfo", (SYSCALL)GetSystemInfo, 0 }, |
| 49417 | #define osGetSystemInfo ((VOID(WINAPI*)(LPSYSTEM_INFO))aSyscall[16].pCurrent) |
| 49418 | |
| 49419 | { "GetSystemTimeAsFileTime", (SYSCALL)GetSystemTimeAsFileTime, 0 }, |
| 49420 | #define osGetSystemTimeAsFileTime ((VOID(WINAPI*)( \ |
| 49421 | LPFILETIME))aSyscall[17].pCurrent) |
| 49422 | |
| 49423 | #ifdef SQLITE_UWP |
| 49424 | { "GetTempPathW", (SYSCALL)0, 0 }, |
| 49425 | #else |
| 49426 | { "GetTempPathW", (SYSCALL)GetTempPathW, 0 }, |
| 49427 | #endif |
| 49428 | #define osGetTempPathW ((DWORD(WINAPI*)(DWORD,LPWSTR))aSyscall[18].pCurrent) |
| 49429 | |
| 49430 | { "GetTickCount64", (SYSCALL)GetTickCount64, 0 }, |
| 49431 | #define osGetTickCount64 ((ULONGLONG(WINAPI*)(VOID))aSyscall[19].pCurrent) |
| 49432 | |
| 49433 | #ifdef SQLITE_UWP |
| 49434 | { "HeapAlloc", (SYSCALL)0, 0 }, |
| 49435 | #else |
| 49436 | { "HeapAlloc", (SYSCALL)HeapAlloc, 0 }, |
| 49437 | #endif |
| 49438 | #define osHeapAlloc ((LPVOID(WINAPI*)(HANDLE,DWORD, \ |
| 49439 | SIZE_T))aSyscall[20].pCurrent) |
| 49440 | |
| 49441 | #ifdef SQLITE_UWP |
| 49442 | { "HeapCreate", (SYSCALL)0, 0 }, |
| 49443 | #else |
| 49444 | { "HeapCreate", (SYSCALL)HeapCreate, 0 }, |
| 49445 | #endif |
| 49446 | #define osHeapCreate ((HANDLE(WINAPI*)(DWORD,SIZE_T, \ |
| 49447 | SIZE_T))aSyscall[21].pCurrent) |
| 49448 | |
| 49449 | #ifdef SQLITE_UWP |
| 49450 | { "HeapDestroy", (SYSCALL)0, 0 }, |
| 49451 | #else |
| 49452 | { "HeapDestroy", (SYSCALL)HeapDestroy, 0 }, |
| 49453 | #endif |
| 49454 | #define osHeapDestroy ((BOOL(WINAPI*)(HANDLE))aSyscall[22].pCurrent) |
| 49455 | |
| 49456 | #ifdef SQLITE_UWP |
| 49457 | { "HeapFree", (SYSCALL)0, 0 }, |
| 49458 | #else |
| 49459 | { "HeapFree", (SYSCALL)HeapFree, 0 }, |
| 49460 | #endif |
| 49461 | #define osHeapFree ((BOOL(WINAPI*)(HANDLE,DWORD,LPVOID))aSyscall[23].pCurrent) |
| 49462 | |
| 49463 | #ifdef SQLITE_UWP |
| 49464 | { "HeapReAlloc", (SYSCALL)0, 0 }, |
| 49465 | #else |
| 49466 | { "HeapReAlloc", (SYSCALL)HeapReAlloc, 0 }, |
| 49467 | #endif |
| 49468 | #define osHeapReAlloc ((LPVOID(WINAPI*)(HANDLE,DWORD,LPVOID, \ |
| 49469 | SIZE_T))aSyscall[24].pCurrent) |
| 49470 | |
| 49471 | #ifdef SQLITE_UWP |
| 49472 | { "HeapSize", (SYSCALL)0, 0 }, |
| 49473 | #else |
| 49474 | { "HeapSize", (SYSCALL)HeapSize, 0 }, |
| 49475 | #endif |
| 49476 | #define osHeapSize ((SIZE_T(WINAPI*)(HANDLE,DWORD, \ |
| 49477 | LPCVOID))aSyscall[25].pCurrent) |
| 49478 | |
| 49479 | #ifdef SQLITE_UWP |
| 49480 | { "HeapValidate", (SYSCALL)0, 0 }, |
| 49481 | #else |
| 49482 | { "HeapValidate", (SYSCALL)HeapValidate, 0 }, |
| 49483 | #endif |
| 49484 | #define osHeapValidate ((BOOL(WINAPI*)(HANDLE,DWORD, \ |
| 49485 | LPCVOID))aSyscall[26].pCurrent) |
| 49486 | |
| 49487 | #ifdef SQLITE_UWP |
| 49488 | { "HeapCompact", (SYSCALL)0, 0 }, |
| 49489 | #else |
| 49490 | { "HeapCompact", (SYSCALL)HeapCompact, 0 }, |
| 49491 | #endif |
| 49492 | #define osHeapCompact ((UINT(WINAPI*)(HANDLE,DWORD))aSyscall[27].pCurrent) |
| 49493 | |
| 49494 | |
| 49495 | #if !defined(SQLITE_OMIT_LOAD_EXTENSION) && !defined(SQLITE_UWP) |
| 49496 | { "LoadLibraryW", (SYSCALL)LoadLibraryW, 0 }, |
| 49497 | #else |
| 49498 | { "LoadLibraryW", (SYSCALL)0, 0 }, |
| 49499 | #endif |
| 49500 | #define osLoadLibraryW ((HMODULE(WINAPI*)(LPCWSTR))aSyscall[28].pCurrent) |
| @@ -49305,72 +49504,82 @@ | |
| 49504 | |
| 49505 | { "LockFileEx", (SYSCALL)LockFileEx, 0 }, |
| 49506 | #define osLockFileEx ((BOOL(WINAPI*)(HANDLE,DWORD,DWORD,DWORD,DWORD, \ |
| 49507 | LPOVERLAPPED))aSyscall[30].pCurrent) |
| 49508 | |
| 49509 | #if (!defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0) \ |
| 49510 | && !defined(SQLITE_UWP) |
| 49511 | { "MapViewOfFile", (SYSCALL)MapViewOfFile, 0 }, |
| 49512 | #else |
| 49513 | { "MapViewOfFile", (SYSCALL)0, 0 }, |
| 49514 | #endif |
| 49515 | #define osMapViewOfFile ((LPVOID(WINAPI*)(HANDLE,DWORD,DWORD,DWORD, \ |
| 49516 | SIZE_T))aSyscall[31].pCurrent) |
| 49517 | |
| 49518 | #if (!defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0) \ |
| 49519 | && defined(SQLITE_UWP) |
| 49520 | { "MapViewOfFileFromApp", (SYSCALL)MapViewOfFileFromApp, 0 }, |
| 49521 | #else |
| 49522 | { "MapViewOfFileFromApp", (SYSCALL)0, 0 }, |
| 49523 | #endif |
| 49524 | #define osMapViewOfFileFromApp ((LPVOID(WINAPI*)(HANDLE,ULONG,ULONG64, \ |
| 49525 | SIZE_T))aSyscall[32].pCurrent) |
| 49526 | |
| 49527 | { "MultiByteToWideChar", (SYSCALL)MultiByteToWideChar, 0 }, |
| 49528 | #define osMultiByteToWideChar ((int(WINAPI*)(UINT,DWORD,LPCSTR,int,LPWSTR, \ |
| 49529 | int))aSyscall[33].pCurrent) |
| 49530 | |
| 49531 | { "QueryPerformanceCounter", (SYSCALL)QueryPerformanceCounter, 0 }, |
| 49532 | #define osQueryPerformanceCounter ((BOOL(WINAPI*)( \ |
| 49533 | LARGE_INTEGER*))aSyscall[34].pCurrent) |
| 49534 | |
| 49535 | { "ReadFile", (SYSCALL)ReadFile, 0 }, |
| 49536 | #define osReadFile ((BOOL(WINAPI*)(HANDLE,LPVOID,DWORD,LPDWORD, \ |
| 49537 | LPOVERLAPPED))aSyscall[35].pCurrent) |
| 49538 | |
| 49539 | { "SetEndOfFile", (SYSCALL)SetEndOfFile, 0 }, |
| 49540 | #define osSetEndOfFile ((BOOL(WINAPI*)(HANDLE))aSyscall[36].pCurrent) |
| 49541 | |
| 49542 | { "SetFilePointerEx", (SYSCALL)SetFilePointerEx, 0 }, |
| 49543 | #define osSetFilePointerEx ((BOOL(WINAPI*)(HANDLE,LARGE_INTEGER,\ |
| 49544 | PLARGE_INTEGER,DWORD))aSyscall[37].pCurrent) |
| 49545 | |
| 49546 | { "Sleep", (SYSCALL)Sleep, 0 }, |
| 49547 | #define osSleep ((VOID(WINAPI*)(DWORD))aSyscall[38].pCurrent) |
| 49548 | |
| 49549 | { "UnlockFileEx", (SYSCALL)UnlockFileEx, 0 }, |
| 49550 | #define osUnlockFileEx ((BOOL(WINAPI*)(HANDLE,DWORD,DWORD,DWORD, \ |
| 49551 | LPOVERLAPPED))aSyscall[39].pCurrent) |
| 49552 | |
| 49553 | #if !defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0 |
| 49554 | { "UnmapViewOfFile", (SYSCALL)UnmapViewOfFile, 0 }, |
| 49555 | #else |
| 49556 | { "UnmapViewOfFile", (SYSCALL)0, 0 }, |
| 49557 | #endif |
| 49558 | #define osUnmapViewOfFile ((BOOL(WINAPI*)(LPCVOID))aSyscall[40].pCurrent) |
| 49559 | |
| 49560 | { "WideCharToMultiByte", (SYSCALL)WideCharToMultiByte, 0 }, |
| 49561 | #define osWideCharToMultiByte ((int(WINAPI*)(UINT,DWORD,LPCWSTR,int,LPSTR,int, \ |
| 49562 | LPCSTR,LPBOOL))aSyscall[41].pCurrent) |
| 49563 | |
| 49564 | { "WriteFile", (SYSCALL)WriteFile, 0 }, |
| 49565 | #define osWriteFile ((BOOL(WINAPI*)(HANDLE,LPCVOID,DWORD,LPDWORD, \ |
| 49566 | LPOVERLAPPED))aSyscall[42].pCurrent) |
| 49567 | |
| 49568 | { "WaitForSingleObject", (SYSCALL)WaitForSingleObject, 0 }, |
| 49569 | #define osWaitForSingleObject ((DWORD(WINAPI*)(HANDLE, \ |
| 49570 | DWORD))aSyscall[43].pCurrent) |
| 49571 | |
| 49572 | { "WaitForSingleObjectEx", (SYSCALL)WaitForSingleObjectEx, 0 }, |
| 49573 | #define osWaitForSingleObjectEx ((DWORD(WINAPI*)(HANDLE,DWORD, \ |
| 49574 | BOOL))aSyscall[44].pCurrent) |
| 49575 | |
| 49576 | { "OutputDebugStringA", (SYSCALL)OutputDebugStringA, 0 }, |
| 49577 | #define osOutputDebugStringA ((VOID(WINAPI*)(LPCSTR))aSyscall[45].pCurrent) |
| 49578 | |
| 49579 | { "GetProcessHeap", (SYSCALL)GetProcessHeap, 0 }, |
| 49580 | #define osGetProcessHeap ((HANDLE(WINAPI*)(VOID))aSyscall[46].pCurrent) |
| 49581 | |
| 49582 | /* |
| 49583 | ** NOTE: On some sub-platforms, the InterlockedCompareExchange "function" |
| 49584 | ** is really just a macro that uses a compiler intrinsic (e.g. x64). |
| 49585 | ** So do not try to make this is into a redefinable interface. |
| @@ -49379,95 +49588,93 @@ | |
| 49588 | { "InterlockedCompareExchange", (SYSCALL)0, 0 }, |
| 49589 | #define osInterlockedCompareExchange InterlockedCompareExchange |
| 49590 | #else |
| 49591 | { "InterlockedCompareExchange", (SYSCALL)InterlockedCompareExchange, 0 }, |
| 49592 | #define osInterlockedCompareExchange ((LONG(WINAPI*)(LONG volatile*,\ |
| 49593 | LONG,LONG))aSyscall[47].pCurrent) |
| 49594 | #endif /* defined(InterlockedCompareExchange) */ |
| 49595 | |
| 49596 | #if SQLITE_WIN32_USE_UUID |
| 49597 | { "UuidCreate", (SYSCALL)UuidCreate, 0 }, |
| 49598 | #else |
| 49599 | { "UuidCreate", (SYSCALL)0, 0 }, |
| 49600 | #endif |
| 49601 | #define osUuidCreate ((RPC_STATUS(RPC_ENTRY*)(UUID*))aSyscall[48].pCurrent) |
| 49602 | |
| 49603 | #if SQLITE_WIN32_USE_UUID |
| 49604 | { "UuidCreateSequential", (SYSCALL)UuidCreateSequential, 0 }, |
| 49605 | #else |
| 49606 | { "UuidCreateSequential", (SYSCALL)0, 0 }, |
| 49607 | #endif |
| 49608 | #define osUuidCreateSequential \ |
| 49609 | ((RPC_STATUS(RPC_ENTRY*)(UUID*))aSyscall[49].pCurrent) |
| 49610 | |
| 49611 | #if !defined(SQLITE_NO_SYNC) && SQLITE_MAX_MMAP_SIZE>0 |
| 49612 | { "FlushViewOfFile", (SYSCALL)FlushViewOfFile, 0 }, |
| 49613 | #else |
| 49614 | { "FlushViewOfFile", (SYSCALL)0, 0 }, |
| 49615 | #endif |
| 49616 | #define osFlushViewOfFile \ |
| 49617 | ((BOOL(WINAPI*)(LPCVOID,SIZE_T))aSyscall[50].pCurrent) |
| 49618 | |
| 49619 | #ifdef SQLITE_ENABLE_SETLK_TIMEOUT |
| 49620 | { "CreateEvent", (SYSCALL)CreateEvent, 0 }, |
| 49621 | #else |
| 49622 | { "CreateEvent", (SYSCALL)0, 0 }, |
| 49623 | #endif |
| 49624 | #define osCreateEvent ((HANDLE(WINAPI*)(LPSECURITY_ATTRIBUTES,BOOL, \ |
| 49625 | BOOL,LPCSTR))aSyscall[51].pCurrent) |
| 49626 | |
| 49627 | #ifdef SQLITE_ENABLE_SETLK_TIMEOUT |
| 49628 | { "CancelIo", (SYSCALL)CancelIo, 0 }, |
| 49629 | #else |
| 49630 | { "CancelIo", (SYSCALL)0, 0 }, |
| 49631 | #endif |
| 49632 | #define osCancelIo ((BOOL(WINAPI*)(HANDLE))aSyscall[52].pCurrent) |
| 49633 | |
| 49634 | #ifndef _WIN32 |
| 49635 | { "getenv", (SYSCALL)getenv, 0 }, |
| 49636 | #else |
| 49637 | { "getenv", (SYSCALL)0, 0 }, |
| 49638 | #endif |
| 49639 | #define osGetenv ((const char *(*)(const char *))aSyscall[53].pCurrent) |
| 49640 | |
| 49641 | #ifndef _WIN32 |
| 49642 | { "getcwd", (SYSCALL)getcwd, 0 }, |
| 49643 | #else |
| 49644 | { "getcwd", (SYSCALL)0, 0 }, |
| 49645 | #endif |
| 49646 | #define osGetcwd ((char*(*)(char*,size_t))aSyscall[54].pCurrent) |
| 49647 | |
| 49648 | #ifndef _WIN32 |
| 49649 | { "readlink", (SYSCALL)readlink, 0 }, |
| 49650 | #else |
| 49651 | { "readlink", (SYSCALL)0, 0 }, |
| 49652 | #endif |
| 49653 | #define osReadlink ((ssize_t(*)(const char*,char*,size_t))aSyscall[55].pCurrent) |
| 49654 | |
| 49655 | #ifndef _WIN32 |
| 49656 | { "lstat", (SYSCALL)lstat, 0 }, |
| 49657 | #else |
| 49658 | { "lstat", (SYSCALL)0, 0 }, |
| 49659 | #endif |
| 49660 | #define osLstat ((int(*)(const char*,struct stat*))aSyscall[56].pCurrent) |
| 49661 | |
| 49662 | #ifndef _WIN32 |
| 49663 | { "__errno", (SYSCALL)__errno, 0 }, |
| 49664 | #else |
| 49665 | { "__errno", (SYSCALL)0, 0 }, |
| 49666 | #endif |
| 49667 | #define osErrno (*((int*(*)(void))aSyscall[57].pCurrent)()) |
| 49668 | |
| 49669 | #ifndef _WIN32 |
| 49670 | { "cygwin_conv_path", (SYSCALL)cygwin_conv_path, 0 }, |
| 49671 | #else |
| 49672 | { "cygwin_conv_path", (SYSCALL)0, 0 }, |
| 49673 | #endif |
| 49674 | #define osCygwin_conv_path ((size_t(*)(unsigned int, \ |
| 49675 | const void *, void *, size_t))aSyscall[58].pCurrent) |
| 49676 | |
| 49677 | }; /* End of the overrideable system calls */ |
| 49678 | |
| 49679 | /* |
| 49680 | ** This is the xSetSystemCall() method of sqlite3_vfs for all of the |
| @@ -49551,10 +49758,13 @@ | |
| 49758 | } |
| 49759 | return 0; |
| 49760 | } |
| 49761 | |
| 49762 | #ifdef SQLITE_WIN32_MALLOC |
| 49763 | #ifdef SQLITE_UWP |
| 49764 | # error SQLITE_WIN32_MALLOC is incompatible with SQLITE_UWP |
| 49765 | #endif |
| 49766 | /* |
| 49767 | ** If a Win32 native heap has been configured, this function will attempt to |
| 49768 | ** compact it. Upon success, SQLITE_OK will be returned. Upon failure, one |
| 49769 | ** of SQLITE_NOMEM, SQLITE_ERROR, or SQLITE_NOTFOUND will be returned. The |
| 49770 | ** "pnLargest" argument, if non-zero, will be used to return the size of the |
| @@ -50509,31 +50719,15 @@ | |
| 50719 | ** If successful, return SQLITE_OK. Or, if an error occurs, return an SQLite |
| 50720 | ** error code. |
| 50721 | */ |
| 50722 | static int winHandleSeek(HANDLE h, sqlite3_int64 iOffset){ |
| 50723 | int rc = SQLITE_OK; /* Return value */ |
| 50724 | LARGE_INTEGER x; /* The offset */ |
| 50725 | |
| 50726 | x.QuadPart = iOffset; |
| 50727 | if( osSetFilePointerEx(h, x, 0, FILE_BEGIN)==0 ){ |
| 50728 | rc = SQLITE_IOERR_SEEK; |
| 50729 | } |
| 50730 | OSTRACE(("SEEK file=%p, offset=%lld rc=%s\n", h, iOffset,sqlite3ErrName(rc))); |
| 50731 | return rc; |
| 50732 | } |
| 50733 | |
| @@ -50812,18 +51006,17 @@ | |
| 51006 | ** Determine the size in bytes of the file opened by the handle passed as |
| 51007 | ** the first argument. |
| 51008 | */ |
| 51009 | static int winHandleSize(HANDLE h, sqlite3_int64 *pnByte){ |
| 51010 | int rc = SQLITE_OK; |
| 51011 | LARGE_INTEGER x; |
| 51012 | assert( pnByte ); |
| 51013 | if( osGetFileSizeEx(h, &x)==0 ){ |
| 51014 | rc = SQLITE_IOERR_FSTAT; |
| 51015 | *pnByte = 0; |
| 51016 | }else{ |
| 51017 | *pnByte = x.QuadPart; |
| 51018 | } |
| 51019 | return rc; |
| 51020 | } |
| 51021 | |
| 51022 | /* |
| @@ -51020,21 +51213,18 @@ | |
| 51213 | assert( id!=0 ); |
| 51214 | assert( pSize!=0 ); |
| 51215 | SimulateIOError(return SQLITE_IOERR_FSTAT); |
| 51216 | OSTRACE(("SIZE file=%p, pSize=%p\n", pFile->h, pSize)); |
| 51217 | { |
| 51218 | LARGE_INTEGER x; |
| 51219 | if( osGetFileSizeEx(pFile->h, &x)==0 ){ |
| 51220 | *pSize = 0; |
| 51221 | pFile->lastErrno = osGetLastError(); |
| 51222 | rc = winLogError(SQLITE_IOERR_FSTAT, pFile->lastErrno, |
| 51223 | "winFileSize", pFile->zPath); |
| 51224 | }else{ |
| 51225 | *pSize = x.QuadPart; |
| 51226 | } |
| 51227 | } |
| 51228 | OSTRACE(("SIZE file=%p, pSize=%p, *pSize=%lld, rc=%s\n", |
| 51229 | pFile->h, pSize, *pSize, sqlite3ErrName(rc))); |
| 51230 | return rc; |
| @@ -52031,15 +52221,33 @@ | |
| 52221 | # define sqlite3_win_test_unc_locking 0 |
| 52222 | #endif |
| 52223 | |
| 52224 | /* |
| 52225 | ** Return true if the string passed as the only argument is likely |
| 52226 | ** to be a UNC path. Return false if note. |
| 52227 | ** |
| 52228 | ** Return true if: |
| 52229 | ** |
| 52230 | ** (1) The name begins with "\\" |
| 52231 | ** (2) But does not begin with "\\?\C:\" where C can be any alphabetic |
| 52232 | ** character. |
| 52233 | ** |
| 52234 | ** For testing, also return true in all cases if the global variable |
| 52235 | ** sqlite3_win_test_unc_locking is true. |
| 52236 | */ |
| 52237 | static int winIsUNCPath(const char *zFile){ |
| 52238 | if( zFile[0]=='\\' && zFile[1]=='\\' ){ |
| 52239 | if( zFile[2]=='?' |
| 52240 | && zFile[3]=='\\' |
| 52241 | && sqlite3Isalpha(zFile[4]) |
| 52242 | && zFile[5]==':' |
| 52243 | && winIsDirSep(zFile[6]) |
| 52244 | ){ |
| 52245 | return sqlite3_win_test_unc_locking; |
| 52246 | }else{ |
| 52247 | return 1; |
| 52248 | } |
| 52249 | } |
| 52250 | return sqlite3_win_test_unc_locking; |
| 52251 | } |
| 52252 | |
| 52253 | /* |
| @@ -52373,11 +52581,11 @@ | |
| 52581 | |
| 52582 | assert( szRegion==pShmNode->szRegion || pShmNode->nRegion==0 ); |
| 52583 | if( pShmNode->nRegion<=iRegion ){ |
| 52584 | HANDLE hShared = pShmNode->hSharedShm; |
| 52585 | struct ShmRegion *apNew; /* New aRegion[] array */ |
| 52586 | i64 nByte = ((i64)iRegion+1)*(i64)szRegion; /* Minimum file size */ |
| 52587 | sqlite3_int64 sz; /* Current size of wal-index file */ |
| 52588 | |
| 52589 | pShmNode->szRegion = szRegion; |
| 52590 | |
| 52591 | /* The requested region is not mapped into this processes address space. |
| @@ -52404,11 +52612,11 @@ | |
| 52612 | } |
| 52613 | } |
| 52614 | |
| 52615 | /* Map the requested memory region into this processes address space. */ |
| 52616 | apNew = (struct ShmRegion*)sqlite3_realloc64( |
| 52617 | pShmNode->aRegion, ((i64)iRegion+1)*sizeof(apNew[0]) |
| 52618 | ); |
| 52619 | if( !apNew ){ |
| 52620 | rc = SQLITE_IOERR_NOMEM_BKPT; |
| 52621 | goto shmpage_out; |
| 52622 | } |
| @@ -52421,20 +52629,30 @@ | |
| 52629 | |
| 52630 | while( pShmNode->nRegion<=iRegion ){ |
| 52631 | HANDLE hMap = NULL; /* file-mapping handle */ |
| 52632 | void *pMap = 0; /* Mapped memory region */ |
| 52633 | |
| 52634 | #ifdef SQLITE_UWP |
| 52635 | hMap = osCreateFileMappingFromApp(hShared, NULL, protect, nByte, NULL); |
| 52636 | #else |
| 52637 | hMap = osCreateFileMappingW(hShared, NULL, protect, 0, nByte, NULL); |
| 52638 | #endif |
| 52639 | OSTRACE(("SHM-MAP-CREATE pid=%lu, region=%d, size=%lld, rc=%s\n", |
| 52640 | osGetCurrentProcessId(), pShmNode->nRegion, nByte, |
| 52641 | hMap ? "ok" : "failed")); |
| 52642 | if( hMap ){ |
| 52643 | i64 iOffset = pShmNode->nRegion*szRegion; |
| 52644 | int iOffsetShift = iOffset % winSysInfo.dwAllocationGranularity; |
| 52645 | #ifdef SQLITE_UWP |
| 52646 | pMap = osMapViewOfFileFromApp(hMap, flags, |
| 52647 | iOffset - iOffsetShift, (i64)szRegion + iOffsetShift |
| 52648 | ); |
| 52649 | #else |
| 52650 | pMap = osMapViewOfFile(hMap, flags, |
| 52651 | 0, iOffset - iOffsetShift, (i64)szRegion + iOffsetShift |
| 52652 | ); |
| 52653 | #endif |
| 52654 | OSTRACE(("SHM-MAP-MAP pid=%lu, region=%d, offset=%d, size=%d, rc=%s\n", |
| 52655 | osGetCurrentProcessId(), pShmNode->nRegion, iOffset, |
| 52656 | szRegion, pMap ? "ok" : "failed")); |
| 52657 | } |
| 52658 | if( !pMap ){ |
| @@ -52451,11 +52669,11 @@ | |
| 52669 | } |
| 52670 | } |
| 52671 | |
| 52672 | shmpage_out: |
| 52673 | if( pShmNode->nRegion>iRegion ){ |
| 52674 | i64 iOffset = (i64)iRegion*(i64)szRegion; |
| 52675 | int iOffsetShift = iOffset % winSysInfo.dwAllocationGranularity; |
| 52676 | char *p = (char *)pShmNode->aRegion[iRegion].pMap; |
| 52677 | *pp = (void *)&p[iOffsetShift]; |
| 52678 | }else{ |
| 52679 | *pp = 0; |
| @@ -52563,13 +52781,17 @@ | |
| 52781 | if( (pFd->ctrlFlags & WINFILE_RDONLY)==0 ){ |
| 52782 | protect = PAGE_READWRITE; |
| 52783 | flags |= FILE_MAP_WRITE; |
| 52784 | } |
| 52785 | #endif |
| 52786 | #ifdef SQLITE_UWP |
| 52787 | pFd->hMap = osCreateFileMappingFromApp(pFd->h, NULL, protect, nMap, NULL); |
| 52788 | #else |
| 52789 | pFd->hMap = osCreateFileMappingW(pFd->h, NULL, protect, |
| 52790 | (DWORD)((nMap>>32) & 0xffffffff), |
| 52791 | (DWORD)(nMap & 0xffffffff), NULL); |
| 52792 | #endif |
| 52793 | if( pFd->hMap==NULL ){ |
| 52794 | pFd->lastErrno = osGetLastError(); |
| 52795 | rc = winLogError(SQLITE_IOERR_MMAP, pFd->lastErrno, |
| 52796 | "winMapfile1", pFd->zPath); |
| 52797 | /* Log the error, but continue normal operation using xRead/xWrite */ |
| @@ -52577,11 +52799,15 @@ | |
| 52799 | osGetCurrentProcessId(), pFd, sqlite3ErrName(rc))); |
| 52800 | return SQLITE_OK; |
| 52801 | } |
| 52802 | assert( (nMap % winSysInfo.dwPageSize)==0 ); |
| 52803 | assert( sizeof(SIZE_T)==sizeof(sqlite3_int64) || nMap<=0xffffffff ); |
| 52804 | #ifdef SQLITE_UWP |
| 52805 | pNew = osMapViewOfFileFromApp(pFd->hMap, flags, 0, (SIZE_T)nMap); |
| 52806 | #else |
| 52807 | pNew = osMapViewOfFile(pFd->hMap, flags, 0, 0, (SIZE_T)nMap); |
| 52808 | #endif |
| 52809 | if( pNew==NULL ){ |
| 52810 | osCloseHandle(pFd->hMap); |
| 52811 | pFd->hMap = NULL; |
| 52812 | pFd->lastErrno = osGetLastError(); |
| 52813 | rc = winLogError(SQLITE_IOERR_MMAP, pFd->lastErrno, |
| @@ -52920,11 +53146,11 @@ | |
| 53146 | if( !zWidePath ){ |
| 53147 | sqlite3_free(zBuf); |
| 53148 | OSTRACE(("TEMP-FILENAME rc=SQLITE_IOERR_NOMEM\n")); |
| 53149 | return SQLITE_IOERR_NOMEM_BKPT; |
| 53150 | } |
| 53151 | if( osGetTempPathW==0 || osGetTempPathW(nMax, zWidePath)==0 ){ |
| 53152 | sqlite3_free(zWidePath); |
| 53153 | sqlite3_free(zBuf); |
| 53154 | OSTRACE(("TEMP-FILENAME rc=SQLITE_IOERR_GETTEMPPATH\n")); |
| 53155 | return winLogError(SQLITE_IOERR_GETTEMPPATH, osGetLastError(), |
| 53156 | "winGetTempname2", 0); |
| @@ -53723,37 +53949,37 @@ | |
| 53949 | /* |
| 53950 | ** Interfaces for opening a shared library, finding entry points |
| 53951 | ** within the shared library, and closing the shared library. |
| 53952 | */ |
| 53953 | static void *winDlOpen(sqlite3_vfs *pVfs, const char *zFilename){ |
| 53954 | HANDLE h = 0; |
| 53955 | void *zConverted = winConvertFromUtf8Filename(zFilename); |
| 53956 | UNUSED_PARAMETER(pVfs); |
| 53957 | if( zConverted==0 ){ |
| 53958 | OSTRACE(("DLOPEN name=%s, handle=%p\n", zFilename, (void*)0)); |
| 53959 | return 0; |
| 53960 | } |
| 53961 | h = osLoadLibraryW ? osLoadLibraryW((LPCWSTR)zConverted) : 0; |
| 53962 | OSTRACE(("DLOPEN name=%s, handle=%p\n", zFilename, (void*)h)); |
| 53963 | sqlite3_free(zConverted); |
| 53964 | return (void*)h; |
| 53965 | } |
| 53966 | static void winDlError(sqlite3_vfs *pVfs, int nBuf, char *zBufOut){ |
| 53967 | UNUSED_PARAMETER(pVfs); |
| 53968 | winGetLastErrorMsg(osGetLastError(), nBuf, zBufOut); |
| 53969 | } |
| 53970 | static void (*winDlSym(sqlite3_vfs *pVfs,void *pH,const char *zSym))(void){ |
| 53971 | FARPROC proc = 0; |
| 53972 | UNUSED_PARAMETER(pVfs); |
| 53973 | proc = osGetProcAddressA ? osGetProcAddressA((HANDLE)pH, zSym) : 0; |
| 53974 | OSTRACE(("DLSYM handle=%p, symbol=%s, address=%p\n", |
| 53975 | (void*)pH, zSym, (void*)proc)); |
| 53976 | return (void(*)(void))proc; |
| 53977 | } |
| 53978 | static void winDlClose(sqlite3_vfs *pVfs, void *pHandle){ |
| 53979 | UNUSED_PARAMETER(pVfs); |
| 53980 | if( osFreeLibrary!=0 ) osFreeLibrary((HANDLE)pHandle); |
| 53981 | OSTRACE(("DLCLOSE handle=%p\n", (void*)pHandle)); |
| 53982 | } |
| 53983 | #else /* if SQLITE_OMIT_LOAD_EXTENSION is defined: */ |
| 53984 | #define winDlOpen 0 |
| 53985 | #define winDlError 0 |
| @@ -53798,36 +54024,39 @@ | |
| 54024 | e.a = (unsigned char*)zBuf; |
| 54025 | e.na = nBuf; |
| 54026 | e.nXor = 0; |
| 54027 | e.i = 0; |
| 54028 | { |
| 54029 | FILETIME x; |
| 54030 | osGetSystemTimeAsFileTime(&x); |
| 54031 | xorMemory(&e, (unsigned char*)&x, sizeof(x)); |
| 54032 | } |
| 54033 | { |
| 54034 | DWORD pid = osGetCurrentProcessId(); |
| 54035 | xorMemory(&e, (unsigned char*)&pid, sizeof(pid)); |
| 54036 | } |
| 54037 | { |
| 54038 | ULONGLONG cnt = osGetTickCount64(); |
| 54039 | xorMemory(&e, (unsigned char*)&cnt, sizeof(cnt)); |
| 54040 | } |
| 54041 | { |
| 54042 | LARGE_INTEGER i; |
| 54043 | osQueryPerformanceCounter(&i); |
| 54044 | xorMemory(&e, (unsigned char*)&i, sizeof(i)); |
| 54045 | } |
| 54046 | #if SQLITE_WIN32_USE_UUID |
| 54047 | #ifdef SQLITE_UWP |
| 54048 | # error SQLITE_WIN32_USE_UUID is incompatible with SQLITE_UWP |
| 54049 | #endif |
| 54050 | { |
| 54051 | UUID id; |
| 54052 | memset(&id, 0, sizeof(id)); |
| 54053 | osUuidCreate(&id); |
| 54054 | xorMemory(&e, (unsigned char*)&id, sizeof(id)); |
| 54055 | memset(&id, 0, sizeof(UUID)); |
| 54056 | osUuidCreateSequential(&id); |
| 54057 | xorMemory(&e, (unsigned char*)&id, sizeof(id)); |
| 54058 | } |
| 54059 | #endif /* SQLITE_WIN32_USE_UUID */ |
| 54060 | return e.nXor>nBuf ? nBuf : e.nXor; |
| 54061 | #endif /* defined(SQLITE_TEST) || defined(SQLITE_OMIT_RANDOMNESS) */ |
| 54062 | } |
| @@ -54042,15 +54271,19 @@ | |
| 54271 | winNextSystemCall, /* xNextSystemCall */ |
| 54272 | }; |
| 54273 | |
| 54274 | /* Double-check that the aSyscall[] array has been constructed |
| 54275 | ** correctly. See ticket [bb3a86e890c8e96ab] */ |
| 54276 | assert( ArraySize(aSyscall)==59 ); |
| 54277 | assert( strcmp(aSyscall[0].zName,"AreFileApisANSI")==0 ); |
| 54278 | assert( strcmp(aSyscall[8].zName,"FreeLibrary")==0 ); |
| 54279 | assert( strcmp(aSyscall[16].zName,"GetSystemInfo")==0 ); |
| 54280 | assert( strcmp(aSyscall[24].zName,"HeapReAlloc")==0 ); |
| 54281 | assert( strcmp(aSyscall[32].zName,"MapViewOfFileFromApp")==0 ); |
| 54282 | assert( strcmp(aSyscall[40].zName,"UnmapViewOfFile")==0 ); |
| 54283 | assert( strcmp(aSyscall[48].zName,"UuidCreate")==0 ); |
| 54284 | assert( strcmp(aSyscall[56].zName,"lstat")==0 ); |
| 54285 | |
| 54286 | /* get memory map allocation granularity */ |
| 54287 | memset(&winSysInfo, 0, sizeof(SYSTEM_INFO)); |
| 54288 | osGetSystemInfo(&winSysInfo); |
| 54289 | assert( winSysInfo.dwAllocationGranularity>0 ); |
| @@ -56762,26 +56995,28 @@ | |
| 56995 | szBulk = -1024 * (i64)pcache1.nInitPage; |
| 56996 | } |
| 56997 | if( szBulk > pCache->szAlloc*(i64)pCache->nMax ){ |
| 56998 | szBulk = pCache->szAlloc*(i64)pCache->nMax; |
| 56999 | } |
| 57000 | if( szBulk>=pCache->szAlloc ){ |
| 57001 | zBulk = pCache->pBulk = sqlite3Malloc( szBulk ); |
| 57002 | sqlite3EndBenignMalloc(); |
| 57003 | if( zBulk ){ |
| 57004 | int nBulk = sqlite3MallocSize(zBulk)/pCache->szAlloc; |
| 57005 | do{ |
| 57006 | PgHdr1 *pX = (PgHdr1*)&zBulk[pCache->szPage]; |
| 57007 | pX->page.pBuf = zBulk; |
| 57008 | pX->page.pExtra = (u8*)pX + ROUND8(sizeof(*pX)); |
| 57009 | assert( EIGHT_BYTE_ALIGNMENT( pX->page.pExtra ) ); |
| 57010 | pX->isBulkLocal = 1; |
| 57011 | pX->isAnchor = 0; |
| 57012 | pX->pNext = pCache->pFree; |
| 57013 | pX->pLruPrev = 0; /* Initializing this saves a valgrind error */ |
| 57014 | pCache->pFree = pX; |
| 57015 | zBulk += pCache->szAlloc; |
| 57016 | }while( --nBulk ); |
| 57017 | } |
| 57018 | } |
| 57019 | return pCache->pFree!=0; |
| 57020 | } |
| 57021 | |
| 57022 | /* |
| @@ -59675,73 +59910,84 @@ | |
| 59910 | #define pager_set_pagehash(X) |
| 59911 | #define CHECK_PAGE(x) |
| 59912 | #endif /* SQLITE_CHECK_PAGES */ |
| 59913 | |
| 59914 | /* |
| 59915 | ** Free a buffer allocated by the readSuperJournal() function. |
| 59916 | */ |
| 59917 | static void freeSuperJournal(char *zSuper){ |
| 59918 | if( zSuper ){ |
| 59919 | sqlite3_free(&zSuper[-4]); |
| 59920 | } |
| 59921 | } |
| 59922 | |
| 59923 | /* |
| 59924 | ** Parameter pJrnl is a file-handle open on a journal file. This function |
| 59925 | ** attempts to read a super-journal file name from the end of the journal |
| 59926 | ** file. If successful, it sets output parameter (*pzSuper) to point to a |
| 59927 | ** buffer containing the super-journal name as a nul-terminated string. |
| 59928 | ** The caller is responsible for freeing the buffer using freeSuperJournal(). |
| 59929 | ** |
| 59930 | ** Refer to comments above writeSuperJournal() for the format used to store |
| 59931 | ** a super-journal file name at the end of a journal file. |
| 59932 | ** |
| 59933 | ** Parameter nSuper is passed the maximum allowable size of the super journal |
| 59934 | ** name in bytes. If the super-journal name in the journal is longer than |
| 59935 | ** nSuper bytes (including a nul-terminator), then this is handled as if no |
| 59936 | ** super-journal name were present in the journal. |
| 59937 | ** |
| 59938 | ** If there is no super-journal name at the end of pJrnl, (*pzSuper) is |
| 59939 | ** set to 0 and SQLITE_OK is returned. Or, if an error occurs while reading |
| 59940 | ** the super-journal name, an SQLite error code is returned and (*pzSuper) |
| 59941 | ** is set to 0. |
| 59942 | */ |
| 59943 | static int readSuperJournal(sqlite3_file *pJrnl, u64 nSuper, char **pzSuper){ |
| 59944 | int rc; /* Return code */ |
| 59945 | u32 len; /* Length in bytes of super-journal name */ |
| 59946 | i64 szJ; /* Total size in bytes of journal file pJrnl */ |
| 59947 | u32 cksum; /* MJ checksum value read from journal */ |
| 59948 | unsigned char aMagic[8]; /* A buffer to hold the magic header */ |
| 59949 | char *zOut = 0; |
| 59950 | |
| 59951 | *pzSuper = 0; |
| 59952 | if( SQLITE_OK!=(rc = sqlite3OsFileSize(pJrnl, &szJ)) |
| 59953 | || szJ<16 |
| 59954 | || SQLITE_OK!=(rc = read32bits(pJrnl, szJ-16, &len)) |
| 59955 | || len>=nSuper |
| 59956 | || len>szJ-16 |
| 59957 | || len==0 |
| 59958 | || SQLITE_OK!=(rc = read32bits(pJrnl, szJ-12, &cksum)) |
| 59959 | || SQLITE_OK!=(rc = sqlite3OsRead(pJrnl, aMagic, 8, szJ-8)) |
| 59960 | || memcmp(aMagic, aJournalMagic, 8) |
| 59961 | ){ |
| 59962 | return rc; |
| 59963 | } |
| 59964 | |
| 59965 | zOut = (char*)sqlite3MallocZero(4 + len + 2); |
| 59966 | if( !zOut ){ |
| 59967 | rc = SQLITE_NOMEM_BKPT; |
| 59968 | }else{ |
| 59969 | zOut = &zOut[4]; |
| 59970 | if( SQLITE_OK==(rc = sqlite3OsRead(pJrnl, zOut, len, szJ-16-len)) ){ |
| 59971 | u32 u; /* Unsigned loop counter */ |
| 59972 | /* See if the checksum matches the super-journal name */ |
| 59973 | for(u=0; u<len; u++){ |
| 59974 | cksum -= zOut[u]; |
| 59975 | } |
| 59976 | } |
| 59977 | if( rc!=SQLITE_OK || cksum ){ |
| 59978 | /* If the checksum doesn't add up, then one or more of the disk sectors |
| 59979 | ** containing the super-journal filename is corrupted. This means |
| 59980 | ** definitely roll back, so just return SQLITE_OK and report a (nul) |
| 59981 | ** super-journal filename. */ |
| 59982 | freeSuperJournal(zOut); |
| 59983 | zOut = 0; |
| 59984 | } |
| 59985 | } |
| 59986 | |
| 59987 | *pzSuper = zOut; |
| 59988 | return rc; |
| 59989 | } |
| 59990 | |
| 59991 | /* |
| 59992 | ** Return the offset of the sector boundary at or immediately |
| 59993 | ** following the value in pPager->journalOff, assuming a sector |
| @@ -60942,13 +61188,11 @@ | |
| 61188 | sqlite3_file *pSuper; /* Malloc'd super-journal file descriptor */ |
| 61189 | sqlite3_file *pJournal; /* Malloc'd child-journal file descriptor */ |
| 61190 | char *zSuperJournal = 0; /* Contents of super-journal file */ |
| 61191 | i64 nSuperJournal; /* Size of super-journal file */ |
| 61192 | char *zJournal; /* Pointer to one journal within MJ file */ |
| 61193 | char *zFree = 0; /* Free this buffer */ |
| 61194 | |
| 61195 | /* Allocate space for both the pJournal and pSuper file descriptors. |
| 61196 | ** If successful, open the super-journal file for reading. |
| 61197 | */ |
| 61198 | pSuper = (sqlite3_file *)sqlite3MallocZero(2 * (i64)pVfs->szOsFile); |
| @@ -60967,22 +61211,20 @@ | |
| 61211 | ** sufficient space (in zSuperPtr) to hold the names of super-journal |
| 61212 | ** files extracted from regular rollback-journals. |
| 61213 | */ |
| 61214 | rc = sqlite3OsFileSize(pSuper, &nSuperJournal); |
| 61215 | if( rc!=SQLITE_OK ) goto delsuper_out; |
| 61216 | assert( nSuperJournal>=0 ); |
| 61217 | zFree = sqlite3Malloc(4 + nSuperJournal + 2); |
| 61218 | if( !zFree ){ |
| 61219 | rc = SQLITE_NOMEM_BKPT; |
| 61220 | goto delsuper_out; |
| 61221 | }else{ |
| 61222 | assert( nSuperJournal<=0x7fffffff ); |
| 61223 | } |
| 61224 | zFree[0] = zFree[1] = zFree[2] = zFree[3] = 0; |
| 61225 | zSuperJournal = &zFree[4]; |
| 61226 | rc = sqlite3OsRead(pSuper, zSuperJournal, (int)nSuperJournal, 0); |
| 61227 | if( rc!=SQLITE_OK ) goto delsuper_out; |
| 61228 | zSuperJournal[nSuperJournal] = 0; |
| 61229 | zSuperJournal[nSuperJournal+1] = 0; |
| 61230 | |
| @@ -60992,10 +61234,12 @@ | |
| 61234 | rc = sqlite3OsAccess(pVfs, zJournal, SQLITE_ACCESS_EXISTS, &exists); |
| 61235 | if( rc!=SQLITE_OK ){ |
| 61236 | goto delsuper_out; |
| 61237 | } |
| 61238 | if( exists ){ |
| 61239 | char *zSuperPtr = 0; |
| 61240 | |
| 61241 | /* One of the journals pointed to by the super-journal exists. |
| 61242 | ** Open it and check if it points at the super-journal. If |
| 61243 | ** so, return without deleting the super-journal file. |
| 61244 | ** NB: zJournal is really a MAIN_JOURNAL. But call it a |
| 61245 | ** SUPER_JOURNAL here so that the VFS will not send the zJournal |
| @@ -61006,17 +61250,19 @@ | |
| 61250 | rc = sqlite3OsOpen(pVfs, zJournal, pJournal, flags, 0); |
| 61251 | if( rc!=SQLITE_OK ){ |
| 61252 | goto delsuper_out; |
| 61253 | } |
| 61254 | |
| 61255 | rc = readSuperJournal(pJournal, 1+(u64)pVfs->mxPathname, &zSuperPtr); |
| 61256 | sqlite3OsClose(pJournal); |
| 61257 | if( rc!=SQLITE_OK ){ |
| 61258 | assert( zSuperPtr==0 ); |
| 61259 | goto delsuper_out; |
| 61260 | } |
| 61261 | |
| 61262 | c = zSuperPtr!=0 && strcmp(zSuperPtr, zSuper)==0; |
| 61263 | freeSuperJournal(zSuperPtr); |
| 61264 | if( c ){ |
| 61265 | /* We have a match. Do not delete the super-journal file. */ |
| 61266 | goto delsuper_out; |
| 61267 | } |
| 61268 | } |
| @@ -61227,23 +61473,15 @@ | |
| 61473 | |
| 61474 | /* Read the super-journal name from the journal, if it is present. |
| 61475 | ** If a super-journal file name is specified, but the file is not |
| 61476 | ** present on disk, then the journal is not hot and does not need to be |
| 61477 | ** played back. |
| 61478 | */ |
| 61479 | rc = readSuperJournal(pPager->jfd, 1+(i64)pPager->pVfs->mxPathname, &zSuper); |
| 61480 | if( rc==SQLITE_OK && zSuper ){ |
| 61481 | rc = sqlite3OsAccess(pVfs, zSuper, SQLITE_ACCESS_EXISTS, &res); |
| 61482 | } |
| 61483 | if( rc!=SQLITE_OK || !res ){ |
| 61484 | goto end_playback; |
| 61485 | } |
| 61486 | pPager->journalOff = 0; |
| 61487 | needPagerReset = isHot; |
| @@ -61368,34 +61606,24 @@ | |
| 61606 | ** problems for other processes at some point in the future. So, just |
| 61607 | ** in case this has happened, clear the changeCountDone flag now. |
| 61608 | */ |
| 61609 | pPager->changeCountDone = pPager->tempFile; |
| 61610 | |
| 61611 | if( rc==SQLITE_OK |
| 61612 | && (pPager->eState>=PAGER_WRITER_DBMOD || pPager->eState==PAGER_OPEN) |
| 61613 | ){ |
| 61614 | rc = sqlite3PagerSync(pPager, 0); |
| 61615 | } |
| 61616 | if( rc==SQLITE_OK ){ |
| 61617 | rc = pager_end_transaction(pPager, zSuper!=0, 0); |
| 61618 | testcase( rc!=SQLITE_OK ); |
| 61619 | } |
| 61620 | if( rc==SQLITE_OK && zSuper && res ){ |
| 61621 | /* If there was a super-journal and this routine will return success, |
| 61622 | ** see if it is possible to delete the super-journal. |
| 61623 | */ |
| 61624 | assert( memcmp(&zSuper[-4], "\0\0\0\0", 4)==0 ); |
| 61625 | rc = pager_delsuper(pPager, zSuper); |
| 61626 | testcase( rc!=SQLITE_OK ); |
| 61627 | } |
| 61628 | if( isHot && nPlayback ){ |
| 61629 | sqlite3_log(SQLITE_NOTICE_RECOVER_ROLLBACK, "recovered %d pages from %s", |
| @@ -61404,10 +61632,11 @@ | |
| 61632 | |
| 61633 | /* The Pager.sectorSize variable may have been updated while rolling |
| 61634 | ** back a journal created by a process with a different sector size |
| 61635 | ** value. Reset it to the correct value for this process. |
| 61636 | */ |
| 61637 | freeSuperJournal(zSuper); |
| 61638 | setSectorSize(pPager); |
| 61639 | return rc; |
| 61640 | } |
| 61641 | |
| 61642 | |
| @@ -67262,10 +67491,16 @@ | |
| 67491 | */ |
| 67492 | pgno = sqlite3Get4byte(&aFrame[0]); |
| 67493 | if( pgno==0 ){ |
| 67494 | return 0; |
| 67495 | } |
| 67496 | |
| 67497 | /* Need a valid page size |
| 67498 | */ |
| 67499 | if( !pWal->szPage ){ |
| 67500 | return 0; |
| 67501 | } |
| 67502 | |
| 67503 | /* A frame is only valid if a checksum of the WAL header, |
| 67504 | ** all prior frames, the first 16 bytes of this frame-header, |
| 67505 | ** and the frame-data matches the checksum in the last 8 |
| 67506 | ** bytes of this frame-header. |
| @@ -69117,11 +69352,11 @@ | |
| 69352 | goto begin_unreliable_shm_out; |
| 69353 | } |
| 69354 | |
| 69355 | /* Allocate a buffer to read frames into */ |
| 69356 | assert( (pWal->szPage & (pWal->szPage-1))==0 ); |
| 69357 | assert( (pWal->szPage>=512 && pWal->szPage<=65536) || pWal->szPage==0 ); |
| 69358 | szFrame = pWal->szPage + WAL_FRAME_HDRSIZE; |
| 69359 | aFrame = (u8 *)sqlite3_malloc64(szFrame); |
| 69360 | if( aFrame==0 ){ |
| 69361 | rc = SQLITE_NOMEM_BKPT; |
| 69362 | goto begin_unreliable_shm_out; |
| @@ -71953,10 +72188,20 @@ | |
| 72188 | ** See the header comment on "btreeInt.h" for additional information. |
| 72189 | ** Including a description of file format and an overview of operation. |
| 72190 | */ |
| 72191 | /* #include "btreeInt.h" */ |
| 72192 | |
| 72193 | /* |
| 72194 | ** Suppress false-positive compiler warnings from GCC. Warnings are |
| 72195 | ** re-enabled at the bottom of this source file. |
| 72196 | */ |
| 72197 | #if defined(__GNUC__) && __GNUC__>=11 |
| 72198 | # pragma GCC diagnostic push |
| 72199 | # pragma GCC diagnostic ignored "-Wstringop-overread" |
| 72200 | # pragma GCC diagnostic ignored "-Wstringop-overflow" |
| 72201 | #endif |
| 72202 | |
| 72203 | /* |
| 72204 | ** The header string that appears at the beginning of every |
| 72205 | ** SQLite database. |
| 72206 | */ |
| 72207 | static const char zMagicHeader[] = SQLITE_FILE_HEADER; |
| @@ -77123,11 +77368,13 @@ | |
| 77368 | ** in the overflow chain. The page number of the first overflow page is |
| 77369 | ** stored in aOverflow[0], etc. A value of 0 in the aOverflow[] array |
| 77370 | ** means "not yet known" (the cache is lazily populated). |
| 77371 | */ |
| 77372 | if( (pCur->curFlags & BTCF_ValidOvfl)==0 ){ |
| 77373 | i64 nOvfl = pCur->info.nPayload; |
| 77374 | testcase( nOvfl - pCur->info.nLocal + ovflSize - 1 > 0xffffffffU ); |
| 77375 | nOvfl = (nOvfl - pCur->info.nLocal + ovflSize-1)/ovflSize; |
| 77376 | if( pCur->aOverflow==0 |
| 77377 | || nOvfl*(int)sizeof(Pgno) > sqlite3MallocSize(pCur->aOverflow) |
| 77378 | ){ |
| 77379 | Pgno *aNew; |
| 77380 | if( sqlite3FaultSim(413) ){ |
| @@ -77228,10 +77475,18 @@ | |
| 77475 | DbPage *pDbPage; |
| 77476 | rc = sqlite3PagerGet(pBt->pPager, nextPage, &pDbPage, |
| 77477 | (eOp==0 ? PAGER_GET_READONLY : 0) |
| 77478 | ); |
| 77479 | if( rc==SQLITE_OK ){ |
| 77480 | if( eOp!=0 |
| 77481 | && (sqlite3PagerPageRefcount(pDbPage)!=1 |
| 77482 | || NEVER(((MemPage*)sqlite3PagerGetExtra(pDbPage))->isInit)) |
| 77483 | && sqlite3FaultSim(411)==SQLITE_OK |
| 77484 | ){ |
| 77485 | sqlite3PagerUnref(pDbPage); |
| 77486 | return SQLITE_CORRUPT_PAGE(pPage); |
| 77487 | } |
| 77488 | aPayload = sqlite3PagerGetData(pDbPage); |
| 77489 | nextPage = get4byte(aPayload); |
| 77490 | rc = copyPayload(&aPayload[offset+4], pBuf, a, eOp, pDbPage); |
| 77491 | sqlite3PagerUnref(pDbPage); |
| 77492 | offset = 0; |
| @@ -82902,10 +83157,15 @@ | |
| 83157 | if( pc+info.nSize>usableSize ){ |
| 83158 | checkAppendMsg(pCheck, "Extends off end of page"); |
| 83159 | doCoverageCheck = 0; |
| 83160 | continue; |
| 83161 | } |
| 83162 | if( info.nPayload && info.pPayload[0]<2 ){ |
| 83163 | checkAppendMsg(pCheck, "Bad cell header size"); |
| 83164 | doCoverageCheck = 0; |
| 83165 | continue; |
| 83166 | } |
| 83167 | |
| 83168 | /* Check for integer primary key out of range */ |
| 83169 | if( pPage->intKey ){ |
| 83170 | if( keyCanBeEqual ? (info.nKey > maxKey) : (info.nKey >= maxKey) ){ |
| 83171 | checkAppendMsg(pCheck, "Rowid %lld out of order", info.nKey); |
| @@ -83504,10 +83764,17 @@ | |
| 83764 | SQLITE_PRIVATE int sqlite3BtreeConnectionCount(Btree *p){ |
| 83765 | testcase( p->sharable ); |
| 83766 | return p->pBt->nRef; |
| 83767 | } |
| 83768 | #endif |
| 83769 | |
| 83770 | /* Re-enable GCC compiler warnings that were suppressed at the top |
| 83771 | ** of this source file to prevent annoying false-positives. |
| 83772 | */ |
| 83773 | #if defined(__GNUC__) && __GNUC__>=11 |
| 83774 | # pragma GCC diagnostic pop |
| 83775 | #endif |
| 83776 | |
| 83777 | /************** End of btree.c ***********************************************/ |
| 83778 | /************** Begin file backup.c ******************************************/ |
| 83779 | /* |
| 83780 | ** 2009 January 28 |
| @@ -84405,12 +84672,12 @@ | |
| 84672 | /* Work-around for GCC bug or bugs: |
| 84673 | ** https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96270 |
| 84674 | ** https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114659 |
| 84675 | ** The problem appears to be fixed in GCC 15 */ |
| 84676 | i64 x; |
| 84677 | assert( (sqlite3Config.bSmallMalloc!=0xee)*8==sizeof(x) ); |
| 84678 | memcpy(&x, (char*)&p->u.i, (sqlite3Config.bSmallMalloc!=0xee)*8); |
| 84679 | p->n = sqlite3Int64ToText(x, zBuf); |
| 84680 | #else |
| 84681 | p->n = sqlite3Int64ToText(p->u.i, zBuf); |
| 84682 | #endif |
| 84683 | if( p->flags & MEM_IntReal ){ |
| @@ -87107,15 +87374,25 @@ | |
| 87374 | /* |
| 87375 | ** Add an OP_ParseSchema opcode. This routine is broken out from |
| 87376 | ** sqlite3VdbeAddOp4() since it needs to also needs to mark all btrees |
| 87377 | ** as having been used. |
| 87378 | ** |
| 87379 | ** zWhere is a WHERE clause that defines which entries of the schema |
| 87380 | ** to reparse. If zWhere==0, that means all entries. p5 is a mask |
| 87381 | ** of INITFLAG_* values for the parse. |
| 87382 | ** |
| 87383 | ** In the current usage, the following are always true: |
| 87384 | ** |
| 87385 | ** ALTER TABLE: zWhere==0, p5!=0 |
| 87386 | ** Otherwise: zWhere!=0, p5==0 |
| 87387 | ** |
| 87388 | ** The zWhere string must have been obtained from sqlite3DbMalloc(). |
| 87389 | ** This routine will take ownership of the allocated memory. |
| 87390 | */ |
| 87391 | SQLITE_PRIVATE void sqlite3VdbeAddParseSchemaOp(Vdbe *p, int iDb, char *zWhere, u16 p5){ |
| 87392 | int j; |
| 87393 | assert( p5==0 || zWhere==0 ); |
| 87394 | sqlite3VdbeAddOp4(p, OP_ParseSchema, iDb, 0, 0, zWhere, P4_DYNAMIC); |
| 87395 | sqlite3VdbeChangeP5(p, p5); |
| 87396 | for(j=0; j<p->db->nDb; j++) sqlite3VdbeUsesBtree(p, j); |
| 87397 | sqlite3MayAbort(p->pParse); |
| 87398 | } |
| @@ -95247,11 +95524,11 @@ | |
| 95524 | QueryPerformanceCounter(&tm); |
| 95525 | return (sqlite3_uint64)tm.QuadPart; |
| 95526 | } |
| 95527 | |
| 95528 | #elif !defined(__STRICT_ANSI__) && defined(__GNUC__) && \ |
| 95529 | (defined(i586) || defined(__i586__) || defined(_M_IX86)) |
| 95530 | |
| 95531 | __inline__ sqlite_uint64 sqlite3Hwtime(void){ |
| 95532 | unsigned int lo, hi; |
| 95533 | __asm__ __volatile__ ("rdtsc" : "=a" (lo), "=d" (hi)); |
| 95534 | return (sqlite_uint64)hi << 32 | lo; |
| @@ -95713,14 +95990,16 @@ | |
| 95990 | */ |
| 95991 | SQLITE_API int sqlite3_value_numeric_type(sqlite3_value *pVal){ |
| 95992 | int eType = sqlite3_value_type(pVal); |
| 95993 | if( eType==SQLITE_TEXT ){ |
| 95994 | Mem *pMem = (Mem*)pVal; |
| 95995 | #if SQLITE_THREADSAFE>0 |
| 95996 | sqlite3_mutex *pMutex = pMem->db ? pMem->db->mutex : 0; |
| 95997 | #endif |
| 95998 | sqlite3_mutex_enter(pMutex); |
| 95999 | applyNumericAffinity(pMem, 0); |
| 96000 | sqlite3_mutex_leave(pMutex); |
| 96001 | eType = sqlite3_value_type(pVal); |
| 96002 | } |
| 96003 | return eType; |
| 96004 | } |
| 96005 | |
| @@ -102423,15 +102702,22 @@ | |
| 102702 | goto abort_due_to_error; |
| 102703 | } |
| 102704 | break; |
| 102705 | } |
| 102706 | |
| 102707 | /* Opcode: ParseSchema P1 * * P4 P5 |
| 102708 | ** |
| 102709 | ** Read and parse all entries from the schema table of database P1 |
| 102710 | ** that match the WHERE clause P4. If P4 is a NULL pointer, then the |
| 102711 | ** entire schema for P1 is reparsed. |
| 102712 | ** |
| 102713 | ** When P4 is NULL, the P5 value is used as the mFlags argument |
| 102714 | ** to sqlite3InitOne(). In other words, P5 should be a mask composed |
| 102715 | ** of INITFLAG_* values. |
| 102716 | ** |
| 102717 | ** The P4==0 case is only used by ALTER TABLE and P5!=0 for all such |
| 102718 | ** cases. For uses other than ALTER TABLE, P4<>0 and P5==0. |
| 102719 | ** |
| 102720 | ** This opcode invokes the parser to create a new virtual machine, |
| 102721 | ** then runs the new virtual machine. It is thus a re-entrant opcode. |
| 102722 | */ |
| 102723 | case OP_ParseSchema: { |
| @@ -102456,18 +102742,20 @@ | |
| 102742 | || db->mallocFailed |
| 102743 | || (CORRUPT_DB && (db->flags & SQLITE_NoSchemaError)!=0) ); |
| 102744 | |
| 102745 | #ifndef SQLITE_OMIT_ALTERTABLE |
| 102746 | if( pOp->p4.z==0 ){ |
| 102747 | assert( pOp->p5!=0 ); |
| 102748 | sqlite3SchemaClear(db->aDb[iDb].pSchema); |
| 102749 | db->mDbFlags &= ~DBFLAG_SchemaKnownOk; |
| 102750 | rc = sqlite3InitOne(db, iDb, &p->zErrMsg, pOp->p5); |
| 102751 | db->mDbFlags |= DBFLAG_SchemaChange; |
| 102752 | p->expired = 0; |
| 102753 | }else |
| 102754 | #endif |
| 102755 | { |
| 102756 | assert( pOp->p5==0 ); |
| 102757 | zSchema = LEGACY_SCHEMA_TABLE; |
| 102758 | initData.db = db; |
| 102759 | initData.iDb = iDb; |
| 102760 | initData.pzErrMsg = &p->zErrMsg; |
| 102761 | initData.mInitFlags = 0; |
| @@ -102825,11 +103113,11 @@ | |
| 103113 | if( pFrame ) break; |
| 103114 | } |
| 103115 | |
| 103116 | if( p->nFrame>=db->aLimit[SQLITE_LIMIT_TRIGGER_DEPTH] ){ |
| 103117 | rc = SQLITE_ERROR; |
| 103118 | sqlite3VdbeError(p, "triggers nested too deep"); |
| 103119 | goto abort_due_to_error; |
| 103120 | } |
| 103121 | |
| 103122 | /* Register pRt is used to store the memory required to save the state |
| 103123 | ** of the current program, and the memory required at runtime to execute |
| @@ -109952,11 +110240,11 @@ | |
| 110240 | /* |
| 110241 | ** cnt==0 means there was not match. |
| 110242 | ** cnt>1 means there were two or more matches. |
| 110243 | ** |
| 110244 | ** cnt==0 is always an error. cnt>1 is often an error, but might |
| 110245 | ** be multiple matches for a NATURAL OUTER JOIN or a OUTER JOIN USING. |
| 110246 | */ |
| 110247 | assert( pFJMatch==0 || cnt>0 ); |
| 110248 | assert( !ExprHasProperty(pExpr, EP_xIsSelect|EP_IntValue) ); |
| 110249 | if( cnt!=1 ){ |
| 110250 | const char *zErr; |
| @@ -109972,10 +110260,11 @@ | |
| 110260 | } |
| 110261 | extendFJMatch(pParse, &pFJMatch, pMatch, pExpr->iColumn); |
| 110262 | pExpr->op = TK_FUNCTION; |
| 110263 | pExpr->u.zToken = "coalesce"; |
| 110264 | pExpr->x.pList = pFJMatch; |
| 110265 | pExpr->affExpr = SQLITE_AFF_DEFER; |
| 110266 | cnt = 1; |
| 110267 | goto lookupname_end; |
| 110268 | }else{ |
| 110269 | sqlite3ExprListDelete(db, pFJMatch); |
| 110270 | pFJMatch = 0; |
| @@ -110034,12 +110323,21 @@ | |
| 110323 | pExpr->op = eNewExprOp; |
| 110324 | lookupname_end: |
| 110325 | if( cnt==1 ){ |
| 110326 | assert( pNC!=0 ); |
| 110327 | #ifndef SQLITE_OMIT_AUTHORIZATION |
| 110328 | if( db->xAuth ){ |
| 110329 | if( pFJMatch ){ |
| 110330 | assert( pExpr->op==TK_FUNCTION ); |
| 110331 | assert( sqlite3_stricmp(pExpr->u.zToken,"coalesce")==0 ); |
| 110332 | assert( pExpr->x.pList==pFJMatch ); |
| 110333 | assert( pFJMatch->nExpr>0 ); |
| 110334 | pExpr = pFJMatch->a[0].pExpr; |
| 110335 | } |
| 110336 | if( pExpr->op==TK_COLUMN || pExpr->op==TK_TRIGGER ){ |
| 110337 | sqlite3AuthRead(pParse, pExpr, pSchema, pNC->pSrcList); |
| 110338 | } |
| 110339 | } |
| 110340 | #endif |
| 110341 | /* Increment the nRef value on all name contexts from TopNC up to |
| 110342 | ** the point where the name matched. */ |
| 110343 | for(;;){ |
| @@ -110137,10 +110435,30 @@ | |
| 110435 | sqlite3AtoF(p->u.zToken, &r); |
| 110436 | assert( r>=0.0 ); |
| 110437 | if( r>1.0 ) return -1; |
| 110438 | return (int)(r*134217728.0); |
| 110439 | } |
| 110440 | |
| 110441 | /* |
| 110442 | ** Set the EP_SubtArg property on every expression inside of |
| 110443 | ** pList. If any subexpression is actually a subquery, then |
| 110444 | ** also set the EP_SubtArg property on the first result-set |
| 110445 | ** column of that subquery. |
| 110446 | */ |
| 110447 | static SQLITE_NOINLINE void resolveSetExprSubtypeArg(ExprList *pList){ |
| 110448 | int nn, ii; |
| 110449 | nn = pList ? pList->nExpr : 0; |
| 110450 | for(ii=0; ii<nn; ii++){ |
| 110451 | Expr *pExpr = pList->a[ii].pExpr; |
| 110452 | ExprSetProperty(pExpr, EP_SubtArg); |
| 110453 | if( pExpr->op==TK_SELECT ){ |
| 110454 | assert( ExprUseXSelect(pExpr) ); |
| 110455 | assert( pExpr->x.pSelect!=0 ); |
| 110456 | resolveSetExprSubtypeArg(pExpr->x.pSelect->pEList); |
| 110457 | } |
| 110458 | } |
| 110459 | } |
| 110460 | |
| 110461 | /* |
| 110462 | ** This routine is callback for sqlite3WalkExpr(). |
| 110463 | ** |
| 110464 | ** Resolve symbolic names into TK_COLUMN operators for the current |
| @@ -110382,14 +110700,11 @@ | |
| 110700 | ** the function may return a value with a subtype back to its |
| 110701 | ** caller using sqlite3_result_value(). */ |
| 110702 | if( (pDef->funcFlags & SQLITE_SUBTYPE) |
| 110703 | || ExprHasProperty(pExpr, EP_SubtArg) |
| 110704 | ){ |
| 110705 | resolveSetExprSubtypeArg(pList); |
| 110706 | } |
| 110707 | |
| 110708 | if( pDef->funcFlags & (SQLITE_FUNC_CONSTANT|SQLITE_FUNC_SLOCHNG) ){ |
| 110709 | /* For the purposes of the EP_ConstFunc flag, date and time |
| 110710 | ** functions and other functions that change slowly are considered |
| @@ -110415,12 +110730,17 @@ | |
| 110730 | && (pParse->db->mDbFlags & DBFLAG_InternalFunc)==0 |
| 110731 | ){ |
| 110732 | /* Internal-use-only functions are disallowed unless the |
| 110733 | ** SQL is being compiled using sqlite3NestedParse() or |
| 110734 | ** the SQLITE_TESTCTRL_INTERNAL_FUNCTIONS test-control has be |
| 110735 | ** used to activate internal functions for testing purposes. |
| 110736 | ** |
| 110737 | ** The 2 value for no_such_func means that the function is |
| 110738 | ** an internal-use-only function which should be treated as a |
| 110739 | ** non-existant function for name resolution purposes. |
| 110740 | */ |
| 110741 | no_such_func = 2; |
| 110742 | pDef = 0; |
| 110743 | }else |
| 110744 | if( (pDef->funcFlags & (SQLITE_FUNC_DIRECT|SQLITE_FUNC_UNSAFE))!=0 |
| 110745 | && !IN_RENAME_OBJECT |
| 110746 | ){ |
| @@ -110460,13 +110780,20 @@ | |
| 110780 | sqlite3ErrorMsg(pParse,"misuse of aggregate function %#T()",pExpr); |
| 110781 | pNC->nNcErr++; |
| 110782 | is_agg = 0; |
| 110783 | } |
| 110784 | #endif |
| 110785 | else if( no_such_func |
| 110786 | && (pParse->db->init.busy==0 || |
| 110787 | (no_such_func==2 && pParse->db->init.busy==2)) |
| 110788 | /* Suppress "no such function" errors when reading |
| 110789 | ** the sqlite_schema table. Except, do raise the error |
| 110790 | ** if init.busy is 2, meaning the schema parse is due |
| 110791 | ** to an ALTER TABLE ADD COLUMN statement, and the function |
| 110792 | ** is an internal-use-only function (no_such_func==2). */ |
| 110793 | #ifdef SQLITE_ENABLE_UNKNOWN_SQL_FUNCTION |
| 110794 | && pParse->explain==0 |
| 110795 | #endif |
| 110796 | ){ |
| 110797 | sqlite3ErrorMsg(pParse, "no such function: %#T", pExpr); |
| 110798 | pNC->nNcErr++; |
| 110799 | }else if( wrong_num_args ){ |
| @@ -111849,11 +112176,13 @@ | |
| 112176 | ** Return TRUE if the two expressions have equivalent collating sequences. |
| 112177 | */ |
| 112178 | SQLITE_PRIVATE int sqlite3ExprCollSeqMatch(Parse *pParse, const Expr *pE1, const Expr *pE2){ |
| 112179 | CollSeq *pColl1 = sqlite3ExprNNCollSeq(pParse, pE1); |
| 112180 | CollSeq *pColl2 = sqlite3ExprNNCollSeq(pParse, pE2); |
| 112181 | assert( (pColl1==pColl2) == |
| 112182 | (sqlite3_stricmp(pColl1->zName,pColl2->zName)==0) ); |
| 112183 | return pColl1==pColl2; |
| 112184 | } |
| 112185 | |
| 112186 | /* |
| 112187 | ** pExpr is an operand of a comparison operator. aff2 is the |
| 112188 | ** type affinity of the other operand. This routine returns the |
| @@ -115686,10 +116015,11 @@ | |
| 116015 | if( i!=nVector ){ |
| 116016 | /* Need to reorder the LHS fields according to aiMap */ |
| 116017 | int rLhsOrig = rLhs; |
| 116018 | rLhs = sqlite3GetTempRange(pParse, nVector); |
| 116019 | for(i=0; i<nVector; i++){ |
| 116020 | testcase( aiMap[i]!=i ); |
| 116021 | sqlite3VdbeAddOp3(v, OP_Copy, rLhsOrig+i, rLhs+aiMap[i], 0); |
| 116022 | } |
| 116023 | sqlite3ReleaseTempReg(pParse, rLhsOrig); |
| 116024 | } |
| 116025 | } |
| @@ -115706,11 +116036,12 @@ | |
| 116036 | } |
| 116037 | for(i=0; i<nVector; i++){ |
| 116038 | Expr *p = sqlite3VectorFieldSubexpr(pExpr->pLeft, i); |
| 116039 | if( pParse->nErr ) goto sqlite3ExprCodeIN_oom_error; |
| 116040 | if( sqlite3ExprCanBeNull(p) ){ |
| 116041 | testcase( aiMap[i]!=i ); |
| 116042 | sqlite3VdbeAddOp2(v, OP_IsNull, rLhs+aiMap[i], destStep2); |
| 116043 | VdbeCoverage(v); |
| 116044 | } |
| 116045 | } |
| 116046 | |
| 116047 | /* Step 3. The LHS is now known to be non-NULL. Do the binary search |
| @@ -115780,13 +116111,23 @@ | |
| 116111 | for(i=0; i<nVector; i++){ |
| 116112 | Expr *p; |
| 116113 | CollSeq *pColl; |
| 116114 | int r3 = sqlite3GetTempReg(pParse); |
| 116115 | p = sqlite3VectorFieldSubexpr(pLeft, i); |
| 116116 | if( ExprUseXSelect(pExpr) ){ |
| 116117 | Expr *pRhs = pExpr->x.pSelect->pEList->a[i].pExpr; |
| 116118 | pColl = sqlite3BinaryCompareCollSeq(pParse, p, pRhs); |
| 116119 | }else{ |
| 116120 | /* If the RHS of the IN(...) expression are scalar expressions, do |
| 116121 | ** not consider their collation sequences. The documentation says |
| 116122 | ** "The collating sequence used for expressions of the form "x IN (y, z, |
| 116123 | ** ...)" is the collating sequence of x.". */ |
| 116124 | pColl = sqlite3ExprCollSeq(pParse, p); |
| 116125 | } |
| 116126 | testcase( aiMap[i]!=i ); |
| 116127 | sqlite3VdbeAddOp3(v, OP_Column, iTab, aiMap[i], r3); |
| 116128 | sqlite3VdbeAddOp4(v, OP_Ne, rLhs+aiMap[i], destNotNull, r3, |
| 116129 | (void*)pColl, P4_COLLSEQ); |
| 116130 | VdbeCoverage(v); |
| 116131 | sqlite3ReleaseTempReg(pParse, r3); |
| 116132 | } |
| 116133 | sqlite3VdbeAddOp2(v, OP_Goto, 0, destIfNull); |
| @@ -116203,40 +116544,51 @@ | |
| 116544 | } |
| 116545 | return target; |
| 116546 | } |
| 116547 | |
| 116548 | /* |
| 116549 | ** Expression Node callback for sqlite3ExprCanReturnSubtype(). If |
| 116550 | ** pExpr is able to return a subtype, set pWalker->eCode and abort |
| 116551 | ** the search. If pExpr can never return a subtype, prune search. |
| 116552 | ** |
| 116553 | ** The only expressions that can return a subtype are: |
| 116554 | ** |
| 116555 | ** 1. A function |
| 116556 | ** 2. The no-op "+" operator |
| 116557 | ** 3. A CASE...END expression |
| 116558 | ** 4. A CAST() expression |
| 116559 | ** 5. A "expr COLLATE colseq" expression. |
| 116560 | ** |
| 116561 | ** For any other kind of expression, prune the search. |
| 116562 | ** |
| 116563 | ** For case 1, the expression can yield a subtype if the function has |
| 116564 | ** the SQLITE_RESULT_SUBTYPE property. Functions can also return |
| 116565 | ** a subtype (via sqlite3_result_value()) if any of the arguments can |
| 116566 | ** return a subtype. |
| 116567 | ** |
| 116568 | ** In all cases 1 through 5, the expression might also return a subtype |
| 116569 | ** if any operand can return a subtype. |
| 116570 | */ |
| 116571 | static int exprNodeCanReturnSubtype(Walker *pWalker, Expr *pExpr){ |
| 116572 | int n; |
| 116573 | FuncDef *pDef; |
| 116574 | sqlite3 *db; |
| 116575 | if( pExpr->op==TK_CASE || pExpr->op==TK_UPLUS |
| 116576 | || pExpr->op==TK_COLLATE || pExpr->op==TK_CAST |
| 116577 | ){ |
| 116578 | return WRC_Continue; |
| 116579 | } |
| 116580 | if( pExpr->op!=TK_FUNCTION ){ |
| 116581 | return WRC_Prune; |
| 116582 | } |
| 116583 | assert( ExprUseXList(pExpr) ); |
| 116584 | db = pWalker->pParse->db; |
| 116585 | n = ALWAYS(pExpr->x.pList) ? pExpr->x.pList->nExpr : 0; |
| 116586 | pDef = sqlite3FindFunction(db, pExpr->u.zToken, n, ENC(db), 0); |
| 116587 | if( NEVER(pDef==0) || (pDef->funcFlags & SQLITE_RESULT_SUBTYPE)!=0 ){ |
| 116588 | pWalker->eCode = 1; |
| 116589 | return WRC_Abort; |
| 116590 | } |
| 116591 | return WRC_Continue; |
| 116592 | } |
| 116593 | |
| 116594 | /* |
| @@ -122210,23 +122562,35 @@ | |
| 122562 | SQLITE_PRIVATE void sqlite3AlterAddConstraint( |
| 122563 | Parse *pParse, /* Parse context */ |
| 122564 | SrcList *pSrc, /* Table to add constraint to */ |
| 122565 | Token *pFirst, /* First token of new constraint */ |
| 122566 | Token *pName, /* Name of new constraint. NULL if name omitted. */ |
| 122567 | const char *zExpr, /* Text of CHECK expression */ |
| 122568 | int nExpr, /* Size of pExpr in bytes */ |
| 122569 | Expr *pExpr /* The parsed CHECK expression */ |
| 122570 | ){ |
| 122571 | Table *pTab = 0; /* Table identified by pSrc */ |
| 122572 | int iDb = 0; /* Which schema does pTab live in */ |
| 122573 | const char *zDb = 0; /* Name of the schema in which pTab lives */ |
| 122574 | const char *pCons = 0; /* Text of the constraint */ |
| 122575 | int nCons; /* Bytes of text to use from pCons[] */ |
| 122576 | int rc; /* Result from error checking pExpr */ |
| 122577 | |
| 122578 | /* Look up the table being altered. */ |
| 122579 | assert( pSrc->nSrc==1 ); |
| 122580 | pTab = alterFindTable(pParse, pSrc, &iDb, &zDb, 1); |
| 122581 | if( !pTab ){ |
| 122582 | sqlite3ExprDelete(pParse->db, pExpr); |
| 122583 | return; |
| 122584 | } |
| 122585 | |
| 122586 | /* Verify that the new CHECK constraint does not contain any |
| 122587 | ** internal-use-only function. Forum post 2026-05-10T01:11:28Z |
| 122588 | */ |
| 122589 | rc = sqlite3ResolveSelfReference(pParse, pTab, NC_IsCheck, pExpr, 0); |
| 122590 | sqlite3ExprDelete(pParse->db, pExpr); |
| 122591 | if( rc ) return; |
| 122592 | |
| 122593 | /* If this new constraint has a name, check that it is not a duplicate of |
| 122594 | ** an existing constraint. It is an error if it is. */ |
| 122595 | if( pName ){ |
| 122596 | char *zName = sqlite3NameFromToken(pParse->db, pName); |
| @@ -122243,11 +122607,11 @@ | |
| 122607 | |
| 122608 | /* Search for a constraint violation. Throw an exception if one is found. */ |
| 122609 | sqlite3NestedParse(pParse, |
| 122610 | "SELECT sqlite_fail('constraint failed', %d) " |
| 122611 | "FROM %Q.%Q WHERE (%.*s) IS NOT TRUE", |
| 122612 | SQLITE_CONSTRAINT, zDb, pTab->zName, nExpr, zExpr |
| 122613 | ); |
| 122614 | |
| 122615 | /* Edit the SQL for the named table. */ |
| 122616 | pCons = pFirst->z; |
| 122617 | nCons = alterRtrimConstraint(pParse->db, pCons, pParse->sLastToken.z - pCons); |
| @@ -124098,21 +124462,21 @@ | |
| 124462 | }else{ |
| 124463 | nIdxCol = pIdx->nColumn; |
| 124464 | } |
| 124465 | pIdx->nSampleCol = nIdxCol; |
| 124466 | pIdx->mxSample = nSample; |
| 124467 | nByte = ROUND8(sizeof64(IndexSample) * nSample); |
| 124468 | nByte += sizeof64(tRowcnt) * nIdxCol * 3 * nSample; |
| 124469 | nByte += nIdxCol * sizeof64(tRowcnt); /* Space for Index.aAvgEq[] */ |
| 124470 | |
| 124471 | pIdx->aSample = sqlite3DbMallocZero(db, nByte); |
| 124472 | if( pIdx->aSample==0 ){ |
| 124473 | sqlite3_finalize(pStmt); |
| 124474 | return SQLITE_NOMEM_BKPT; |
| 124475 | } |
| 124476 | pPtr = (u8*)pIdx->aSample; |
| 124477 | pPtr += ROUND8(nSample*sizeof64(pIdx->aSample[0])); |
| 124478 | pSpace = (tRowcnt*)pPtr; |
| 124479 | assert( EIGHT_BYTE_ALIGNMENT( pSpace ) ); |
| 124480 | pIdx->aAvgEq = pSpace; pSpace += nIdxCol; |
| 124481 | pIdx->pTable->tabFlags |= TF_HasStat4; |
| 124482 | for(i=0; i<nSample; i++){ |
| @@ -125929,10 +126293,23 @@ | |
| 126293 | if( NEVER(pTab->u.tab.pDfltList==0) ) return 0; |
| 126294 | if( NEVER(pTab->u.tab.pDfltList->nExpr<pCol->iDflt) ) return 0; |
| 126295 | return pTab->u.tab.pDfltList->a[pCol->iDflt-1].pExpr; |
| 126296 | } |
| 126297 | |
| 126298 | /* |
| 126299 | ** Suppress false-positive warning message generated with -O3 in GCC |
| 126300 | ** on the second call to sqlite3Strlen30() in the sqlite3ColumnSetColl() |
| 126301 | ** function below. See the forum thread beginning on 2026-05-10T01:11:22Z. |
| 126302 | ** |
| 126303 | ** See also the "pop" pragma to undo this warning suppression immediately |
| 126304 | ** after the function. |
| 126305 | */ |
| 126306 | #if defined(__GNUC__) && __GNUC__>=11 |
| 126307 | # pragma GCC diagnostic push |
| 126308 | # pragma GCC diagnostic ignored "-Wstringop-overread" |
| 126309 | #endif |
| 126310 | |
| 126311 | /* |
| 126312 | ** Set the collating sequence name for a column. |
| 126313 | */ |
| 126314 | SQLITE_PRIVATE void sqlite3ColumnSetColl( |
| 126315 | sqlite3 *db, |
| @@ -125953,10 +126330,15 @@ | |
| 126330 | pCol->zCnName = zNew; |
| 126331 | memcpy(pCol->zCnName + n, zColl, nColl); |
| 126332 | pCol->colFlags |= COLFLAG_HASCOLL; |
| 126333 | } |
| 126334 | } |
| 126335 | |
| 126336 | /* Undo the false-positive warning suppression above. */ |
| 126337 | #if defined(__GNUC__) && __GNUC__>=11 |
| 126338 | # pragma GCC diagnostic pop |
| 126339 | #endif |
| 126340 | |
| 126341 | /* |
| 126342 | ** Return the collating sequence name for a column |
| 126343 | */ |
| 126344 | SQLITE_PRIVATE const char *sqlite3ColumnColl(Column *pCol){ |
| @@ -132946,13 +133328,22 @@ | |
| 133328 | x.nUsed = 0; |
| 133329 | x.apArg = argv+1; |
| 133330 | sqlite3StrAccumInit(&str, db, 0, 0, db->aLimit[SQLITE_LIMIT_LENGTH]); |
| 133331 | str.printfFlags = SQLITE_PRINTF_SQLFUNC; |
| 133332 | sqlite3_str_appendf(&str, zFormat, &x); |
| 133333 | if( str.accError==SQLITE_OK ){ |
| 133334 | n = str.nChar; |
| 133335 | sqlite3_result_text(context, sqlite3StrAccumFinish(&str), n, |
| 133336 | SQLITE_DYNAMIC); |
| 133337 | }else{ |
| 133338 | if( str.accError==SQLITE_NOMEM ){ |
| 133339 | sqlite3_result_error_nomem(context); |
| 133340 | }else{ |
| 133341 | sqlite3_result_error_toobig(context); |
| 133342 | } |
| 133343 | sqlite3_str_reset(&str); |
| 133344 | } |
| 133345 | } |
| 133346 | } |
| 133347 | |
| 133348 | /* |
| 133349 | ** Implementation of the substr() function. |
| @@ -134120,11 +134511,11 @@ | |
| 134511 | int nStr; /* Size of zStr */ |
| 134512 | int nPattern; /* Size of zPattern */ |
| 134513 | int nRep; /* Size of zRep */ |
| 134514 | i64 nOut; /* Maximum size of zOut */ |
| 134515 | int loopLimit; /* Last zStr[] that might match zPattern[] */ |
| 134516 | i64 i, j; /* Loop counters */ |
| 134517 | unsigned cntExpand; /* Number zOut expansions */ |
| 134518 | sqlite3 *db = sqlite3_context_db_handle(context); |
| 134519 | |
| 134520 | assert( argc==3 ); |
| 134521 | UNUSED_PARAMETER(argc); |
| @@ -134599,15 +134990,20 @@ | |
| 134990 | ** to initialize it */ |
| 134991 | if( ALWAYS(p) && type!=SQLITE_NULL ){ |
| 134992 | assert( p->cnt>0 ); |
| 134993 | p->cnt--; |
| 134994 | if( !p->approx ){ |
| 134995 | i64 x = p->iSum; |
| 134996 | if( sqlite3SubInt64(&x, sqlite3_value_int64(argv[0]))==0 ){ |
| 134997 | p->iSum = x; |
| 134998 | return; |
| 134999 | } |
| 135000 | p->ovrfl = 1; |
| 135001 | p->approx = 1; |
| 135002 | kahanBabuskaNeumaierInit(p, p->iSum); |
| 135003 | } |
| 135004 | if( type==SQLITE_INTEGER ){ |
| 135005 | i64 iVal = sqlite3_value_int64(argv[0]); |
| 135006 | if( iVal!=SMALLEST_INT64 ){ |
| 135007 | kahanBabuskaNeumaierStepInt64(p, -iVal); |
| 135008 | }else{ |
| 135009 | kahanBabuskaNeumaierStepInt64(p, LARGEST_INT64); |
| @@ -135569,57 +135965,95 @@ | |
| 135965 | ** from the standard library because: |
| 135966 | ** |
| 135967 | ** (1) To avoid a dependency on qsort() |
| 135968 | ** (2) To avoid the function call to the comparison routine for each |
| 135969 | ** comparison. |
| 135970 | ** |
| 135971 | ** If parameter iReq is non-negative, then the caller will only access |
| 135972 | ** elements a[iReq] and a[iReq+1] (if it exists) of the sorted array and |
| 135973 | ** so it is not necessary to position any other elements. Or if iReq is |
| 135974 | ** negative, then the final array must be fully sorted. |
| 135975 | */ |
| 135976 | static void percentSort( |
| 135977 | double *a, /* Array to sort */ |
| 135978 | unsigned int n, /* Number of elements in array a[] */ |
| 135979 | int iReq /* Element caller cares about (or -ve) */ |
| 135980 | ){ |
| 135981 | int iLt; /* Entries before a[iLt] are less than rPivot */ |
| 135982 | int iGt; /* Entries at or after a[iGt] are greater than rPivot */ |
| 135983 | int i; /* Loop counter */ |
| 135984 | double rPivot; /* The pivot value */ |
| 135985 | |
| 135986 | assert( n>=2 ); |
| 135987 | do{ |
| 135988 | if( a[0]>a[n-1] ){ |
| 135989 | SWAP_DOUBLE(a[0],a[n-1]) |
| 135990 | } |
| 135991 | if( n==2 ) return; |
| 135992 | iGt = n-1; |
| 135993 | i = n/2; |
| 135994 | if( a[0]>a[i] ){ |
| 135995 | SWAP_DOUBLE(a[0],a[i]) |
| 135996 | }else if( a[i]>a[iGt] ){ |
| 135997 | SWAP_DOUBLE(a[i],a[iGt]) |
| 135998 | } |
| 135999 | if( n==3 ) return; |
| 136000 | rPivot = a[i]; |
| 136001 | iLt = i = 1; |
| 136002 | do{ |
| 136003 | if( a[i]<rPivot ){ |
| 136004 | if( i>iLt ) SWAP_DOUBLE(a[i],a[iLt]) |
| 136005 | iLt++; |
| 136006 | i++; |
| 136007 | }else if( a[i]>rPivot ){ |
| 136008 | do{ |
| 136009 | iGt--; |
| 136010 | }while( iGt>i && a[iGt]>rPivot ); |
| 136011 | SWAP_DOUBLE(a[i],a[iGt]) |
| 136012 | }else{ |
| 136013 | i++; |
| 136014 | } |
| 136015 | }while( i<iGt ); |
| 136016 | |
| 136017 | assert( a[iLt]==rPivot ); |
| 136018 | assert( iGt>iLt ); |
| 136019 | |
| 136020 | if( iReq>=0 ){ |
| 136021 | /* In this case, the only elements that the caller requires sorted into |
| 136022 | ** the correct positions are elements a[iReq] and a[iReq+1]. At this |
| 136023 | ** point we know that element a[iLt] is in the correct position and |
| 136024 | ** all elements smaller than a[iLt] are in the left-hand partition. |
| 136025 | ** So if (iReq<iLt), then it is only necessary to sort the left |
| 136026 | ** partition. |
| 136027 | ** |
| 136028 | ** If (iReq>=iLt), then elements iReq and iReq+1 are either in the |
| 136029 | ** right partition or the equal partition (elements for which |
| 136030 | ** iLt<=iElem<iGt). Therefore it is always sufficient to sort only |
| 136031 | ** the right partition in this case. */ |
| 136032 | if( iReq<iLt ){ |
| 136033 | n = iLt; |
| 136034 | }else{ |
| 136035 | a += iGt; |
| 136036 | n -= iGt; |
| 136037 | iReq = MAX(0, iReq-iGt); |
| 136038 | } |
| 136039 | }else{ |
| 136040 | /* Recurse on the smaller partition only. The smaller partition |
| 136041 | ** will hold n/2 or fewer entries, which assures that the stack |
| 136042 | ** depth will not exceed O(log(n)), even for pathological cases. |
| 136043 | ** Loop without recursion for the larger partition. */ |
| 136044 | if( iLt>(int)(n/2) ){ |
| 136045 | if( n-iGt>=2 ) percentSort(a+iGt, n-iGt, -1); |
| 136046 | n = iLt; |
| 136047 | }else{ |
| 136048 | if( iLt>=2 ) percentSort(a, iLt, -1); |
| 136049 | a += iGt; |
| 136050 | n -= iGt; |
| 136051 | } |
| 136052 | } |
| 136053 | }while( n>=2 ); |
| 136054 | } |
| 136055 | |
| 136056 | /* |
| 136057 | ** The "inverse" function for percentile(Y,P) is called to remove a |
| 136058 | ** row that was previously inserted by "step". |
| 136059 | */ |
| @@ -135649,11 +136083,11 @@ | |
| 136083 | if( percentIsInfinity(y) ){ |
| 136084 | return; |
| 136085 | } |
| 136086 | if( p->bSorted==0 ){ |
| 136087 | assert( p->nUsed>1 ); |
| 136088 | percentSort(p->a, p->nUsed, -1); |
| 136089 | p->bSorted = 1; |
| 136090 | } |
| 136091 | p->bKeepSorted = 1; |
| 136092 | |
| 136093 | /* Find and remove the row */ |
| @@ -135678,17 +136112,21 @@ | |
| 136112 | double ix, vx; |
| 136113 | p = (Percentile*)sqlite3_aggregate_context(pCtx, 0); |
| 136114 | if( p==0 ) return; |
| 136115 | if( p->a==0 ) return; |
| 136116 | if( p->nUsed ){ |
| 136117 | ix = p->rPct*(p->nUsed-1); |
| 136118 | i1 = (unsigned)ix; |
| 136119 | if( p->bSorted==0 ){ |
| 136120 | /* In cases where bIsFinal is non-zero, setting Percentile.bSorted |
| 136121 | ** after the percentSort() call here is not technically correct, as |
| 136122 | ** the array is not fully sorted. But in this case the object will be |
| 136123 | ** freed below anyway, so it doesn't matter. */ |
| 136124 | assert( p->nUsed>1 ); |
| 136125 | percentSort(p->a, p->nUsed, (bIsFinal ? (int)i1 : -1)); |
| 136126 | p->bSorted = 1; |
| 136127 | } |
| 136128 | if( settings & 1 ){ |
| 136129 | vx = p->a[i1]; |
| 136130 | }else{ |
| 136131 | i2 = ix==(double)i1 || i1==p->nUsed-1 ? i1 : i1+1; |
| 136132 | v1 = p->a[i1]; |
| @@ -140569,10 +141007,48 @@ | |
| 141007 | } |
| 141008 | |
| 141009 | /* If no test above fails then the indices must be compatible */ |
| 141010 | return 1; |
| 141011 | } |
| 141012 | |
| 141013 | /* |
| 141014 | ** Examine an expression node and abort if it references the ROWID. |
| 141015 | ** This is a Walker callback used by xferCompatibleCheck() |
| 141016 | */ |
| 141017 | static int xferCheckRowid(Walker *pWalk, Expr *pExpr){ |
| 141018 | if( pExpr->op==TK_COLUMN && pExpr->iColumn<0 ){ |
| 141019 | pWalk->eCode = 1; |
| 141020 | return WRC_Abort; |
| 141021 | }else{ |
| 141022 | return WRC_Continue; |
| 141023 | } |
| 141024 | } |
| 141025 | |
| 141026 | /* |
| 141027 | ** Analyze CHECK constraints on the source and destination tables and |
| 141028 | ** return true if those CHECK constraints are compatible with the |
| 141029 | ** xfer-optimization. |
| 141030 | ** |
| 141031 | ** * The pDest and pSrc tables must have identical CHECK constraints. |
| 141032 | ** |
| 141033 | ** * If the destination table, pDest, does not have an |
| 141034 | ** INTEGER PRIMARY KEY column, then no CHECK constraint may |
| 141035 | ** referenced the ROWID. (See forum post 2026-05-11T13:15:57Z) |
| 141036 | */ |
| 141037 | static int xferCompatibleCheck(Table *pDest, Table *pSrc){ |
| 141038 | if( sqlite3ExprListCompare(pSrc->pCheck,pDest->pCheck,-1) ){ |
| 141039 | return 0; |
| 141040 | } |
| 141041 | if( pDest->iPKey<0 ){ |
| 141042 | Walker w; |
| 141043 | memset(&w, 0, sizeof(w)); |
| 141044 | w.xExprCallback = xferCheckRowid; |
| 141045 | sqlite3WalkExprList(&w,pDest->pCheck); |
| 141046 | if( w.eCode ) return 0; |
| 141047 | } |
| 141048 | return 1; |
| 141049 | } |
| 141050 | |
| 141051 | /* |
| 141052 | ** Attempt the transfer optimization on INSERTs of the form |
| 141053 | ** |
| 141054 | ** INSERT INTO tab1 SELECT * FROM tab2; |
| @@ -140696,12 +141172,23 @@ | |
| 141172 | return 0; /* Number of columns must be the same in tab1 and tab2 */ |
| 141173 | } |
| 141174 | if( pDest->iPKey!=pSrc->iPKey ){ |
| 141175 | return 0; /* Both tables must have the same INTEGER PRIMARY KEY */ |
| 141176 | } |
| 141177 | if( (pDest->tabFlags & TF_Strict)!=0 ){ |
| 141178 | if( (pSrc->tabFlags & TF_Strict)==0 ){ |
| 141179 | return 0; /* Cannot feed from a non-strict into a strict table */ |
| 141180 | } |
| 141181 | for(i=0; i<pDest->nCol; i++){ |
| 141182 | unsigned eDestType = pDest->aCol[i].eCType; |
| 141183 | unsigned eSrcType = pSrc->aCol[i].eCType; |
| 141184 | if( eDestType==COLTYPE_ANY ) continue; |
| 141185 | if( eDestType==eSrcType ) continue; |
| 141186 | if( eDestType==COLTYPE_INT && eSrcType==COLTYPE_INTEGER ) continue; |
| 141187 | if( eDestType==COLTYPE_INTEGER && eSrcType==COLTYPE_INT ) continue; |
| 141188 | return 0; /* Incompatible types in source and destination */ |
| 141189 | } |
| 141190 | } |
| 141191 | for(i=0; i<pDest->nCol; i++){ |
| 141192 | Column *pDestCol = &pDest->aCol[i]; |
| 141193 | Column *pSrcCol = &pSrc->aCol[i]; |
| 141194 | #ifdef SQLITE_ENABLE_HIDDEN_COLUMNS |
| @@ -140791,11 +141278,11 @@ | |
| 141278 | } |
| 141279 | } |
| 141280 | #ifndef SQLITE_OMIT_CHECK |
| 141281 | if( pDest->pCheck |
| 141282 | && (db->mDbFlags & DBFLAG_Vacuum)==0 |
| 141283 | && !xferCompatibleCheck(pDest,pSrc) |
| 141284 | ){ |
| 141285 | return 0; /* Tables have different CHECK constraints. Ticket #2252 */ |
| 141286 | } |
| 141287 | #endif |
| 141288 | #ifndef SQLITE_OMIT_FOREIGN_KEY |
| @@ -140812,10 +141299,22 @@ | |
| 141299 | } |
| 141300 | #endif |
| 141301 | if( (db->flags & SQLITE_CountRows)!=0 ){ |
| 141302 | return 0; /* xfer opt does not play well with PRAGMA count_changes */ |
| 141303 | } |
| 141304 | #ifndef SQLITE_OMIT_AUTHORIZATION |
| 141305 | if( db->xAuth ){ |
| 141306 | int iDb = sqlite3SchemaToIndex(db, pSrc->pSchema); |
| 141307 | if( sqlite3AuthCheck(pParse, SQLITE_SELECT, 0, 0, 0) ) return 0; |
| 141308 | for(i=0; i<pSrc->nCol; i++){ |
| 141309 | Column *pSrcCol = &pSrc->aCol[i]; |
| 141310 | if( sqlite3AuthReadCol(pParse, pSrc->zName, pSrcCol->zCnName, iDb) ){ |
| 141311 | return 0; |
| 141312 | } |
| 141313 | } |
| 141314 | } |
| 141315 | #endif |
| 141316 | |
| 141317 | /* If we get this far, it means that the xfer optimization is at |
| 141318 | ** least a possibility, though it might only work if the destination |
| 141319 | ** table (tab1) is initially empty. |
| 141320 | */ |
| @@ -146810,11 +147309,17 @@ | |
| 147309 | assert( iDb>=0 && iDb<db->nDb ); |
| 147310 | assert( db->aDb[iDb].pSchema ); |
| 147311 | assert( sqlite3_mutex_held(db->mutex) ); |
| 147312 | assert( iDb==1 || sqlite3BtreeHoldsMutex(db->aDb[iDb].pBt) ); |
| 147313 | |
| 147314 | db->init.busy = 1 + ((mFlags & INITFLAG_AlterAdd)!=0); |
| 147315 | /* ^--- Any non-zero value for init.busy means that we are scanning |
| 147316 | ** the sqlite_schema table to build the internal schema representation, |
| 147317 | ** rather than running actual CREATE statements. init.busy==2 has the |
| 147318 | ** additional meaning that the scan is happening as part of |
| 147319 | ** ALTER TABLE ADD COLUMN, which is stricter in its enforcement of |
| 147320 | ** function name resolution. */ |
| 147321 | |
| 147322 | /* Construct the in-memory representation schema tables (sqlite_schema or |
| 147323 | ** sqlite_temp_schema) by invoking the parser directly. The appropriate |
| 147324 | ** table name will be inserted automatically by the parser so we can just |
| 147325 | ** use the abbreviation "x" here. The parser will also automatically tag |
| @@ -150131,10 +150636,17 @@ | |
| 150636 | SQLITE_PRIVATE Table *sqlite3ResultSetOfSelect(Parse *pParse, Select *pSelect, char aff){ |
| 150637 | Table *pTab; |
| 150638 | sqlite3 *db = pParse->db; |
| 150639 | u64 savedFlags; |
| 150640 | |
| 150641 | pParse->nNestSel++; |
| 150642 | #if SQLITE_MAX_EXPR_DEPTH>0 |
| 150643 | if( pParse->nNestSel >= db->aLimit[SQLITE_LIMIT_EXPR_DEPTH] ){ |
| 150644 | sqlite3ErrorMsg(pParse, "VIEWs and/or subqueries nested too deep"); |
| 150645 | return 0; |
| 150646 | } |
| 150647 | #endif |
| 150648 | savedFlags = db->flags; |
| 150649 | db->flags &= ~(u64)SQLITE_FullColNames; |
| 150650 | db->flags |= SQLITE_ShortColNames; |
| 150651 | sqlite3SelectPrep(pParse, pSelect, 0); |
| 150652 | db->flags = savedFlags; |
| @@ -150152,10 +150664,12 @@ | |
| 150664 | pTab->iPKey = -1; |
| 150665 | if( db->mallocFailed ){ |
| 150666 | sqlite3DeleteTable(db, pTab); |
| 150667 | return 0; |
| 150668 | } |
| 150669 | pParse->nNestSel--; |
| 150670 | assert( pParse->nNestSel>=0 ); |
| 150671 | return pTab; |
| 150672 | } |
| 150673 | |
| 150674 | /* |
| 150675 | ** Get a VDBE for the given parser context. Create a new one if necessary. |
| @@ -155122,12 +155636,15 @@ | |
| 155636 | ** Then, if CheckOnCtx.iJoin indicates that this expression is part of an |
| 155637 | ** ON clause from that SrcList (i.e. if iJoin is non-zero), check that it |
| 155638 | ** does not refer to a table to the right of CheckOnCtx.iJoin. */ |
| 155639 | do { |
| 155640 | SrcList *pSrc = pCtx->pSrc; |
| 155641 | int nSrc = pSrc->nSrc; |
| 155642 | int iTab = pExpr->iTable; |
| 155643 | int ii; |
| 155644 | for(ii=0; ii<nSrc && pSrc->a[ii].iCursor!=iTab; ii++){} |
| 155645 | if( ii<nSrc ){ |
| 155646 | if( pCtx->iJoin && iTab>pCtx->iJoin ){ |
| 155647 | sqlite3ErrorMsg(pWalker->pParse, |
| 155648 | "%s references tables to its right", |
| 155649 | (pCtx->bFuncArg ? "table-function argument" : "ON clause") |
| 155650 | ); |
| @@ -158092,22 +158609,36 @@ | |
| 158609 | Parse *pParse, /* Current parse context */ |
| 158610 | Trigger *pTrigger, /* Trigger to code */ |
| 158611 | Table *pTab, /* The table pTrigger is attached to */ |
| 158612 | int orconf /* ON CONFLICT policy to code trigger program with */ |
| 158613 | ){ |
| 158614 | Parse *pTop; /* Top level Parse object */ |
| 158615 | sqlite3 *db = pParse->db; /* Database handle */ |
| 158616 | TriggerPrg *pPrg; /* Value to return */ |
| 158617 | Expr *pWhen = 0; /* Duplicate of trigger WHEN expression */ |
| 158618 | Vdbe *v; /* Temporary VM */ |
| 158619 | NameContext sNC; /* Name context for sub-vdbe */ |
| 158620 | SubProgram *pProgram = 0; /* Sub-vdbe for trigger program */ |
| 158621 | int iEndTrigger = 0; /* Label to jump to if WHEN is false */ |
| 158622 | Parse sSubParse; /* Parse context for sub-vdbe */ |
| 158623 | int nDepth; /* Trigger depth */ |
| 158624 | |
| 158625 | /* Ensure that triggers are not chained too deep. This test is linear |
| 158626 | ** in the chaining depth, but sensible code ought not be chaining |
| 158627 | ** triggers excessively, so that shouldn't be a problem. |
| 158628 | */ |
| 158629 | pTop = pParse; |
| 158630 | for(nDepth=0; pTop->pOuterParse; pTop = pTop->pOuterParse, nDepth++){} |
| 158631 | if( nDepth>=db->aLimit[SQLITE_LIMIT_TRIGGER_DEPTH] ){ |
| 158632 | sqlite3ErrorMsg(pParse, "triggers nested too deep"); |
| 158633 | return 0; |
| 158634 | } |
| 158635 | |
| 158636 | pTop = sqlite3ParseToplevel(pParse); |
| 158637 | assert( pTrigger->zName==0 || pTab==tableOfTrigger(pTrigger) ); |
| 158638 | assert( pTop->pVdbe ); |
| 158639 | |
| 158640 | |
| 158641 | /* Allocate the TriggerPrg and SubProgram objects. To ensure that they |
| 158642 | ** are freed if an error occurs, link them into the Parse.pTriggerPrg |
| 158643 | ** list of the top-level Parse object sooner rather than later. */ |
| 158644 | pPrg = sqlite3DbMallocZero(db, sizeof(TriggerPrg)); |
| @@ -160105,11 +160636,12 @@ | |
| 160636 | ** So we have to make a copy before passing it down into sqlite3Update() */ |
| 160637 | pSrc = sqlite3SrcListDup(db, pTop->pUpsertSrc, 0); |
| 160638 | /* excluded.* columns of type REAL need to be converted to a hard real */ |
| 160639 | for(i=0; i<pTab->nCol; i++){ |
| 160640 | if( pTab->aCol[i].affinity==SQLITE_AFF_REAL ){ |
| 160641 | int iStorage = pTop->regData + sqlite3TableColumnToStorage(pTab, i); |
| 160642 | sqlite3VdbeAddOp1(v, OP_RealAffinity, iStorage); |
| 160643 | } |
| 160644 | } |
| 160645 | sqlite3Update(pParse, pSrc, sqlite3ExprListDup(db,pUpsert->pUpsertSet,0), |
| 160646 | sqlite3ExprDup(db,pUpsert->pUpsertWhere,0), OE_Abort, 0, 0, pUpsert); |
| 160647 | VdbeNoopComment((v, "End DO UPDATE of UPSERT")); |
| @@ -164903,11 +165435,11 @@ | |
| 165435 | |
| 165436 | /* Set up a new SrcList in pOrTab containing the table being scanned |
| 165437 | ** by this loop in the a[0] slot and all notReady tables in a[1..] slots. |
| 165438 | ** This becomes the SrcList in the recursive call to sqlite3WhereBegin(). |
| 165439 | */ |
| 165440 | if( pWInfo->nLevel>1 || pTabItem->fg.fromExists ){ |
| 165441 | int nNotReady; /* The number of notReady tables */ |
| 165442 | SrcItem *origSrc; /* Original list of tables */ |
| 165443 | nNotReady = pWInfo->nLevel - iLevel - 1; |
| 165444 | pOrTab = sqlite3DbMallocRawNN(db, SZ_SRCLIST(nNotReady+1)); |
| 165445 | if( pOrTab==0 ) return notReady; |
| @@ -164916,10 +165448,17 @@ | |
| 165448 | memcpy(pOrTab->a, pTabItem, sizeof(*pTabItem)); |
| 165449 | origSrc = pWInfo->pTabList->a; |
| 165450 | for(k=1; k<=nNotReady; k++){ |
| 165451 | memcpy(&pOrTab->a[k], &origSrc[pLevel[k].iFrom], sizeof(pOrTab->a[k])); |
| 165452 | } |
| 165453 | |
| 165454 | /* Clear the fromExists flag on the OR-optimized table entry so that |
| 165455 | ** the calls to sqlite3WhereEnd() do not code early-exits after the |
| 165456 | ** first row is visited. The early exit applies to this table's |
| 165457 | ** overall loop - including the multiple OR branches and any WHERE |
| 165458 | ** conditions not passed to the sub-loops - not to the sub-loops. */ |
| 165459 | pOrTab->a[0].fg.fromExists = 0; |
| 165460 | }else{ |
| 165461 | pOrTab = pWInfo->pTabList; |
| 165462 | } |
| 165463 | |
| 165464 | /* Initialize the rowset register to contain NULL. An SQL NULL is |
| @@ -165159,11 +165698,11 @@ | |
| 165698 | ** indent everything in between the this point and the final OP_Return. |
| 165699 | ** See tag-20220407a in vdbe.c and shell.c */ |
| 165700 | assert( pLevel->op==OP_Return ); |
| 165701 | pLevel->p2 = sqlite3VdbeCurrentAddr(v); |
| 165702 | |
| 165703 | if( pWInfo->pTabList!=pOrTab ){ sqlite3DbFreeNN(db, pOrTab); } |
| 165704 | if( !untestedTerms ) disableTerm(pLevel, pTerm); |
| 165705 | }else |
| 165706 | #endif /* SQLITE_OMIT_OR_OPTIMIZATION */ |
| 165707 | |
| 165708 | { |
| @@ -165316,10 +165855,11 @@ | |
| 165855 | assert( (pTerm->eOperator & (WO_OR|WO_AND))==0 ); |
| 165856 | pAlt = sqlite3WhereFindTerm(pWC, iCur, pTerm->u.x.leftColumn, notReady, |
| 165857 | WO_EQ|WO_IN|WO_IS, 0); |
| 165858 | if( pAlt==0 ) continue; |
| 165859 | if( pAlt->wtFlags & (TERM_CODED) ) continue; |
| 165860 | if( ExprHasProperty(pAlt->pExpr, EP_Collate) ) continue; |
| 165861 | if( (pAlt->eOperator & WO_IN) |
| 165862 | && ExprUseXSelect(pAlt->pExpr) |
| 165863 | && (pAlt->pExpr->x.pSelect->pEList->nExpr>1) |
| 165864 | ){ |
| 165865 | continue; |
| @@ -166069,11 +166609,14 @@ | |
| 166609 | ** Mark term iChild as being a child of term iParent |
| 166610 | */ |
| 166611 | static void markTermAsChild(WhereClause *pWC, int iChild, int iParent){ |
| 166612 | pWC->a[iChild].iParent = iParent; |
| 166613 | pWC->a[iChild].truthProb = pWC->a[iParent].truthProb; |
| 166614 | assert( pWC->a[iParent].nChild < UMXV(pWC->a[0].nChild) ); |
| 166615 | pWC->a[iParent].nChild++; |
| 166616 | testcase( pWC->a[iParent].nChild == UMXV(pWC->a[0].nChild) ); |
| 166617 | |
| 166618 | } |
| 166619 | |
| 166620 | /* |
| 166621 | ** Return the N-th AND-connected subterm of pTerm. Or if pTerm is not |
| 166622 | ** a conjunction, then return just pTerm when N==0. If N is exceeds |
| @@ -166508,23 +167051,22 @@ | |
| 167051 | ** 1. The SQLITE_Transitive optimization must be enabled |
| 167052 | ** 2. Must be either an == or an IS operator |
| 167053 | ** 3. Not originating in the ON clause of an OUTER JOIN |
| 167054 | ** 4. The operator is not IS or else the query does not contain RIGHT JOIN |
| 167055 | ** 5. The affinities of A and B must be compatible |
| 167056 | ** 6. Both operands use the same collating sequence, and they must not |
| 167057 | ** use explicit COLLATE clauses. |
| 167058 | ** If this routine returns TRUE, that means that the RHS can be substituted |
| 167059 | ** for the LHS anyplace else in the WHERE clause where the LHS column occurs. |
| 167060 | ** This is an optimization. No harm comes from returning 0. But if 1 is |
| 167061 | ** returned when it should not be, then incorrect answers might result. |
| 167062 | */ |
| 167063 | static int termIsEquivalence(Parse *pParse, Expr *pExpr, SrcList *pSrc){ |
| 167064 | char aff1, aff2; |
| 167065 | if( !OptimizationEnabled(pParse->db, SQLITE_Transitive) ) return 0; /* (1) */ |
| 167066 | if( pExpr->op!=TK_EQ && pExpr->op!=TK_IS ) return 0; /* (2) */ |
| 167067 | if( ExprHasProperty(pExpr, EP_OuterON|EP_Collate) ) return 0; /* (3) */ |
| 167068 | assert( pSrc!=0 ); |
| 167069 | if( pExpr->op==TK_IS |
| 167070 | && pSrc->nSrc>=2 |
| 167071 | && (pSrc->a[0].fg.jointype & JT_LTORJ)!=0 |
| 167072 | ){ |
| @@ -166535,14 +167077,11 @@ | |
| 167077 | if( aff1!=aff2 |
| 167078 | && (!sqlite3IsNumericAffinity(aff1) || !sqlite3IsNumericAffinity(aff2)) |
| 167079 | ){ |
| 167080 | return 0; /* (5) */ |
| 167081 | } |
| 167082 | if( !sqlite3ExprCollSeqMatch(pParse, pExpr->pLeft, pExpr->pRight) ){ |
| 167083 | return 0; /* (6) */ |
| 167084 | } |
| 167085 | return 1; |
| 167086 | } |
| 167087 | |
| @@ -166850,10 +167389,11 @@ | |
| 167389 | static const u8 ops[] = {TK_GE, TK_LE}; |
| 167390 | assert( ExprUseXList(pExpr) ); |
| 167391 | pList = pExpr->x.pList; |
| 167392 | assert( pList!=0 ); |
| 167393 | assert( pList->nExpr==2 ); |
| 167394 | assert( pWC->a[idxTerm].nChild==0 ); |
| 167395 | for(i=0; i<2; i++){ |
| 167396 | Expr *pNewExpr; |
| 167397 | int idxNew; |
| 167398 | pNewExpr = sqlite3PExpr(pParse, ops[i], |
| 167399 | sqlite3ExprDup(db, pExpr->pLeft, 0), |
| @@ -166870,11 +167410,11 @@ | |
| 167410 | |
| 167411 | #if !defined(SQLITE_OMIT_OR_OPTIMIZATION) && !defined(SQLITE_OMIT_SUBQUERY) |
| 167412 | /* Analyze a term that is composed of two or more subterms connected by |
| 167413 | ** an OR operator. |
| 167414 | */ |
| 167415 | else if( pExpr->op==TK_OR && !ExprHasProperty(pExpr, EP_Collate) ){ |
| 167416 | assert( pWC->op==TK_AND ); |
| 167417 | exprAnalyzeOrTerm(pSrc, pWC, idxTerm); |
| 167418 | pTerm = &pWC->a[idxTerm]; |
| 167419 | } |
| 167420 | #endif /* SQLITE_OMIT_OR_OPTIMIZATION */ |
| @@ -167060,12 +167600,15 @@ | |
| 167600 | && (pExpr->x.pSelect->pPrior==0 || (pExpr->x.pSelect->selFlags & SF_Values)) |
| 167601 | #ifndef SQLITE_OMIT_WINDOWFUNC |
| 167602 | && pExpr->x.pSelect->pWin==0 |
| 167603 | #endif |
| 167604 | && pWC->op==TK_AND |
| 167605 | && pExpr->x.pSelect->pEList->nExpr <= UMXV(pTerm->nChild) |
| 167606 | /* ^-- See bug 2026-06-04T10:00:49Z */ |
| 167607 | ){ |
| 167608 | int i; |
| 167609 | assert( pTerm->nChild==0 ); |
| 167610 | for(i=0; i<sqlite3ExprVectorSize(pExpr->pLeft); i++){ |
| 167611 | int idxNew; |
| 167612 | idxNew = whereClauseInsert(pWC, pExpr, TERM_VIRTUAL|TERM_SLICE); |
| 167613 | pWC->a[idxNew].u.x.iField = i+1; |
| 167614 | exprAnalyze(pSrc, pWC, idxNew); |
| @@ -170589,13 +171132,14 @@ | |
| 171132 | pLoop->nOut--; |
| 171133 | if( (pTerm->eOperator&(WO_EQ|WO_IS))!=0 |
| 171134 | && (pTerm->wtFlags & TERM_HIGHTRUTH)==0 /* tag-20200224-1 */ |
| 171135 | ){ |
| 171136 | Expr *pRight = pOpExpr->pRight; |
| 171137 | Parse *pParse = pWC->pWInfo->pParse; |
| 171138 | int k = 0; |
| 171139 | testcase( pOpExpr->op==TK_IS ); |
| 171140 | if( sqlite3ExprIsInteger(pRight, &k, pParse) && k>=(-1) && k<=1 ){ |
| 171141 | k = 10; |
| 171142 | }else{ |
| 171143 | k = 20; |
| 171144 | } |
| 171145 | if( iReduce<k ){ |
| @@ -170688,11 +171232,12 @@ | |
| 171232 | testcase( pLhs->iColumn==XN_ROWID ); |
| 171233 | aff = sqlite3CompareAffinity(pRhs, sqlite3ExprAffinity(pLhs)); |
| 171234 | idxaff = sqlite3TableColumnAffinity(pIdx->pTable, pLhs->iColumn); |
| 171235 | if( aff!=idxaff ) break; |
| 171236 | |
| 171237 | if( ExprHasProperty(pTerm->pExpr, EP_Commuted) ) SWAP(Expr*, pRhs, pLhs); |
| 171238 | pColl = sqlite3BinaryCompareCollSeq(pParse, pLhs, pRhs); |
| 171239 | if( pColl==0 ) break; |
| 171240 | if( sqlite3StrICmp(pColl->zName, pIdx->azColl[i+nEq]) ) break; |
| 171241 | } |
| 171242 | return i; |
| 171243 | } |
| @@ -183162,13 +183707,15 @@ | |
| 183707 | case 196: /* expr ::= LP nexprlist COMMA expr RP */ |
| 183708 | { |
| 183709 | ExprList *pList = sqlite3ExprListAppend(pParse, yymsp[-3].minor.yy14, yymsp[-1].minor.yy454); |
| 183710 | yymsp[-4].minor.yy454 = sqlite3PExpr(pParse, TK_VECTOR, 0, 0); |
| 183711 | if( yymsp[-4].minor.yy454 ){ |
| 183712 | int i; |
| 183713 | yymsp[-4].minor.yy454->x.pList = pList; |
| 183714 | for(i=0; i<pList->nExpr; i++){ |
| 183715 | assert( pList->a[i].pExpr!=0 ); |
| 183716 | yymsp[-4].minor.yy454->flags |= pList->a[i].pExpr->flags & EP_Propagate; |
| 183717 | } |
| 183718 | }else{ |
| 183719 | sqlite3ExprListDelete(pParse->db, pList); |
| 183720 | } |
| 183721 | } |
| @@ -183632,19 +184179,17 @@ | |
| 184179 | sqlite3AlterSetNotNull(pParse, yymsp[-7].minor.yy203, &yymsp[-4].minor.yy0, &yymsp[-2].minor.yy0); |
| 184180 | } |
| 184181 | break; |
| 184182 | case 300: /* cmd ::= ALTER TABLE fullname ADD CONSTRAINT nm CHECK LP expr RP onconf */ |
| 184183 | { |
| 184184 | sqlite3AlterAddConstraint(pParse, yymsp[-8].minor.yy203, &yymsp[-6].minor.yy0, &yymsp[-5].minor.yy0, yymsp[-3].minor.yy0.z+1, (yymsp[-1].minor.yy0.z-yymsp[-3].minor.yy0.z-1), yymsp[-2].minor.yy454); |
| 184185 | } |
| 184186 | break; |
| 184187 | case 301: /* cmd ::= ALTER TABLE fullname ADD CHECK LP expr RP onconf */ |
| 184188 | { |
| 184189 | sqlite3AlterAddConstraint(pParse, yymsp[-6].minor.yy203, &yymsp[-4].minor.yy0, 0, yymsp[-3].minor.yy0.z+1, (yymsp[-1].minor.yy0.z-yymsp[-3].minor.yy0.z-1), yymsp[-2].minor.yy454); |
| 184190 | } |
| 184191 | break; |
| 184192 | case 302: /* cmd ::= create_vtab */ |
| 184193 | {sqlite3VtabFinishParse(pParse,0);} |
| 184194 | break; |
| 184195 | case 303: /* cmd ::= create_vtab LP vtabarglist RP */ |
| @@ -186617,11 +187162,11 @@ | |
| 187162 | ** or disables the collection of memory allocation statistics. */ |
| 187163 | sqlite3GlobalConfig.bMemstat = va_arg(ap, int); |
| 187164 | break; |
| 187165 | } |
| 187166 | case SQLITE_CONFIG_SMALL_MALLOC: { |
| 187167 | sqlite3GlobalConfig.bSmallMalloc = va_arg(ap, int)!=0; |
| 187168 | break; |
| 187169 | } |
| 187170 | case SQLITE_CONFIG_PAGECACHE: { |
| 187171 | /* EVIDENCE-OF: R-18761-36601 There are three arguments to |
| 187172 | ** SQLITE_CONFIG_PAGECACHE: A pointer to 8-byte aligned memory (pMem), |
| @@ -192926,10 +193471,16 @@ | |
| 193471 | #ifndef SQLITE_CORE |
| 193472 | /* # include "sqlite3ext.h" */ |
| 193473 | SQLITE_EXTENSION_INIT1 |
| 193474 | #endif |
| 193475 | |
| 193476 | |
| 193477 | /* |
| 193478 | ** Assume any b-tree layer with more levels than this is corrupt. |
| 193479 | */ |
| 193480 | #define FTS3_MAX_BTREE_HEIGHT 48 |
| 193481 | |
| 193482 | typedef struct Fts3HashWrapper Fts3HashWrapper; |
| 193483 | struct Fts3HashWrapper { |
| 193484 | Fts3Hash hash; /* Hash table */ |
| 193485 | int nRef; /* Number of pointers to this object */ |
| 193486 | }; |
| @@ -194642,11 +195193,15 @@ | |
| 195193 | int iHeight; /* Height of this node in tree */ |
| 195194 | |
| 195195 | assert( piLeaf || piLeaf2 ); |
| 195196 | |
| 195197 | fts3GetVarint32(zNode, &iHeight); |
| 195198 | if( iHeight>FTS3_MAX_BTREE_HEIGHT ){ |
| 195199 | rc = FTS_CORRUPT_VTAB; |
| 195200 | }else{ |
| 195201 | rc = fts3ScanInteriorNode(zTerm, nTerm, zNode, nNode, piLeaf, piLeaf2); |
| 195202 | } |
| 195203 | assert_fts3_nc( !piLeaf2 || !piLeaf || rc!=SQLITE_OK || (*piLeaf<=*piLeaf2) ); |
| 195204 | |
| 195205 | if( rc==SQLITE_OK && iHeight>1 ){ |
| 195206 | char *zBlob = 0; /* Blob read from %_segments table */ |
| 195207 | int nBlob = 0; /* Size of zBlob in bytes */ |
| @@ -194687,12 +195242,17 @@ | |
| 195242 | char **pp, /* IN/OUT: Output pointer */ |
| 195243 | sqlite3_int64 *piPrev, /* IN/OUT: Previous value written to list */ |
| 195244 | sqlite3_int64 iVal /* Write this value to the list */ |
| 195245 | ){ |
| 195246 | assert_fts3_nc( iVal-*piPrev > 0 || (*piPrev==0 && iVal==0) ); |
| 195247 | if( iVal-(*piPrev)>=0 ){ |
| 195248 | /* Refuse to write a negative delta integer. This only happens with a |
| 195249 | ** corrupt db (see the assert above) and can cause buffer overwrites |
| 195250 | ** in some cases. */ |
| 195251 | *pp += sqlite3Fts3PutVarint(*pp, iVal-*piPrev); |
| 195252 | *piPrev = iVal; |
| 195253 | } |
| 195254 | } |
| 195255 | |
| 195256 | /* |
| 195257 | ** When this function is called, *ppPoslist is assumed to point to the |
| 195258 | ** start of a position-list. After it returns, *ppPoslist points to the |
| @@ -199171,11 +199731,11 @@ | |
| 199731 | break; |
| 199732 | |
| 199733 | /* State 3. The integer just read is a column number. */ |
| 199734 | default: assert( eState==3 ); |
| 199735 | iCol = (int)v; |
| 199736 | if( iCol<1 || iCol>(pFts3->nColumn+1) ){ |
| 199737 | rc = SQLITE_CORRUPT_VTAB; |
| 199738 | break; |
| 199739 | } |
| 199740 | if( fts3auxGrowStatArray(pCsr, iCol+2) ) return SQLITE_NOMEM; |
| 199741 | pCsr->aStat[iCol+1].nDoc++; |
| @@ -199861,10 +200421,11 @@ | |
| 200421 | /* If this is a "NEAR" keyword, check for an explicit nearness. */ |
| 200422 | if( pKey->eType==FTSQUERY_NEAR ){ |
| 200423 | assert( nKey==4 ); |
| 200424 | if( zInput[4]=='/' && zInput[5]>='0' && zInput[5]<='9' ){ |
| 200425 | nKey += 1+sqlite3Fts3ReadInt(&zInput[nKey+1], &nNear); |
| 200426 | if( nNear>=1000000000 ) nNear = 1000000000; |
| 200427 | } |
| 200428 | } |
| 200429 | |
| 200430 | /* At this point this is probably a keyword. But for that to be true, |
| 200431 | ** the next byte must contain either whitespace, an open or close |
| @@ -206107,10 +206668,14 @@ | |
| 206668 | iMul = -1; |
| 206669 | } |
| 206670 | for(/* no-op */; zText[i]>='0' && zText[i]<='9'; i++){ |
| 206671 | iVal = iVal*10 + (zText[i] - '0'); |
| 206672 | } |
| 206673 | |
| 206674 | /* This if() clause is just to avoid an integer overflow. The record is |
| 206675 | ** corrupt in this case. */ |
| 206676 | if( (i64)iVal==SMALLEST_INT64 ) iMul = 1; |
| 206677 | *pnByte = ((i64)iVal * (i64)iMul); |
| 206678 | } |
| 206679 | } |
| 206680 | |
| 206681 | |
| @@ -208969,14 +209534,13 @@ | |
| 209534 | */ |
| 209535 | |
| 209536 | /* |
| 209537 | ** Allocate a two-slot MatchinfoBuffer object. |
| 209538 | */ |
| 209539 | static MatchinfoBuffer *fts3MIBufferNew(i64 nElem, const char *zMatchinfo){ |
| 209540 | MatchinfoBuffer *pRet; |
| 209541 | sqlite3_int64 nByte = sizeof(u32) * (2*(i64)nElem+1) + SZ_MATCHINFOBUFFER(1); |
| 209542 | sqlite3_int64 nStr = strlen(zMatchinfo); |
| 209543 | |
| 209544 | pRet = sqlite3Fts3MallocZero(nByte + nStr+1); |
| 209545 | if( pRet ){ |
| 209546 | pRet->aMI[0] = (u8*)(&pRet->aMI[1]) - (u8*)pRet; |
| @@ -209724,11 +210288,11 @@ | |
| 210288 | int nHit = fts3ColumnlistCount(&pIter); |
| 210289 | if( (pPhrase->iColumn>=pTab->nColumn || pPhrase->iColumn==iCol) ){ |
| 210290 | if( p->flag==FTS3_MATCHINFO_LHITS ){ |
| 210291 | p->aMatchinfo[iStart + iCol] = (u32)nHit; |
| 210292 | }else if( nHit ){ |
| 210293 | p->aMatchinfo[iStart + iCol/32] |= (1U << (iCol&0x1F)); |
| 210294 | } |
| 210295 | } |
| 210296 | assert( *pIter==0x00 || *pIter==0x01 ); |
| 210297 | if( *pIter!=0x01 ) break; |
| 210298 | pIter++; |
| @@ -209843,12 +210407,12 @@ | |
| 210407 | } |
| 210408 | sqlite3Fts3ErrMsg(pzErr, "unrecognized matchinfo request: %c", cArg); |
| 210409 | return SQLITE_ERROR; |
| 210410 | } |
| 210411 | |
| 210412 | static i64 fts3MatchinfoSize(MatchInfo *pInfo, char cArg){ |
| 210413 | i64 nVal; /* Number of integers output by cArg */ |
| 210414 | |
| 210415 | switch( cArg ){ |
| 210416 | case FTS3_MATCHINFO_NDOC: |
| 210417 | case FTS3_MATCHINFO_NPHRASE: |
| 210418 | case FTS3_MATCHINFO_NCOL: |
| @@ -209860,20 +210424,20 @@ | |
| 210424 | case FTS3_MATCHINFO_LCS: |
| 210425 | nVal = pInfo->nCol; |
| 210426 | break; |
| 210427 | |
| 210428 | case FTS3_MATCHINFO_LHITS: |
| 210429 | nVal = (i64)pInfo->nCol * pInfo->nPhrase; |
| 210430 | break; |
| 210431 | |
| 210432 | case FTS3_MATCHINFO_LHITS_BM: |
| 210433 | nVal = (i64)pInfo->nPhrase * ((pInfo->nCol + 31) / 32); |
| 210434 | break; |
| 210435 | |
| 210436 | default: |
| 210437 | assert( cArg==FTS3_MATCHINFO_HITS ); |
| 210438 | nVal = (i64)pInfo->nCol * pInfo->nPhrase * 3; |
| 210439 | break; |
| 210440 | } |
| 210441 | |
| 210442 | return nVal; |
| 210443 | } |
| @@ -210151,11 +210715,11 @@ | |
| 210715 | } |
| 210716 | break; |
| 210717 | |
| 210718 | case FTS3_MATCHINFO_LHITS_BM: |
| 210719 | case FTS3_MATCHINFO_LHITS: { |
| 210720 | i64 nZero = fts3MatchinfoSize(pInfo, zArg[i]) * sizeof(u32); |
| 210721 | memset(pInfo->aMatchinfo, 0, nZero); |
| 210722 | rc = fts3ExprLHitGather(pCsr->pExpr, pInfo); |
| 210723 | break; |
| 210724 | } |
| 210725 | |
| @@ -210220,11 +210784,11 @@ | |
| 210784 | ** matchinfo function has been called for this query. In this case |
| 210785 | ** allocate the array used to accumulate the matchinfo data and |
| 210786 | ** initialize those elements that are constant for every row. |
| 210787 | */ |
| 210788 | if( pCsr->pMIBuffer==0 ){ |
| 210789 | i64 nMatchinfo = 0; /* Number of u32 elements in match-info */ |
| 210790 | int i; /* Used to iterate through zArg */ |
| 210791 | |
| 210792 | /* Determine the number of phrases in the query */ |
| 210793 | pCsr->nPhrase = fts3ExprPhraseCount(pCsr->pExpr); |
| 210794 | sInfo.nPhrase = pCsr->nPhrase; |
| @@ -212214,11 +212778,11 @@ | |
| 212778 | case SQLITE_NULL: { |
| 212779 | jsonAppendRawNZ(p, "null", 4); |
| 212780 | break; |
| 212781 | } |
| 212782 | case SQLITE_FLOAT: { |
| 212783 | jsonPrintf(100, p, "%!0.17g", sqlite3_value_double(pValue)); |
| 212784 | break; |
| 212785 | } |
| 212786 | case SQLITE_INTEGER: { |
| 212787 | const char *z = (const char*)sqlite3_value_text(pValue); |
| 212788 | u32 n = (u32)sqlite3_value_bytes(pValue); |
| @@ -213528,13 +214092,14 @@ | |
| 214092 | */ |
| 214093 | static u32 jsonbPayloadSize(const JsonParse *pParse, u32 i, u32 *pSz){ |
| 214094 | u8 x; |
| 214095 | u32 sz; |
| 214096 | u32 n; |
| 214097 | if( i>=pParse->nBlob ){ |
| 214098 | *pSz = 0; |
| 214099 | return 0; |
| 214100 | }else if( (x = pParse->aBlob[i]>>4)<=11 ){ |
| 214101 | sz = x; |
| 214102 | n = 1; |
| 214103 | }else if( x==12 ){ |
| 214104 | if( i+1>=pParse->nBlob ){ |
| 214105 | *pSz = 0; |
| @@ -213744,11 +214309,11 @@ | |
| 214309 | break; |
| 214310 | case '\n': |
| 214311 | break; |
| 214312 | case 0xe2: |
| 214313 | /* '\' followed by either U+2028 or U+2029 is ignored as |
| 214314 | ** whitespace. Note that in UTF8, U+2028 is 0xe2 0x80 0x29. |
| 214315 | ** U+2029 is the same except for the last byte */ |
| 214316 | if( sz2<4 |
| 214317 | || 0x80!=(u8)zIn[2] |
| 214318 | || (0xa8!=(u8)zIn[3] && 0xa9!=(u8)zIn[3]) |
| 214319 | ){ |
| @@ -216313,15 +216878,13 @@ | |
| 216878 | char c; |
| 216879 | JsonString *pStr; |
| 216880 | UNUSED_PARAMETER(argc); |
| 216881 | UNUSED_PARAMETER(argv); |
| 216882 | pStr = (JsonString*)sqlite3_aggregate_context(ctx, 0); |
| 216883 | /* pStr is always non-NULL since jsonArrayStep() or jsonObjectStep() will |
| 216884 | ** always have been called to initialize it */ |
| 216885 | if( NEVER(!pStr) ) return; |
| 216886 | z = pStr->zBuf; |
| 216887 | for(i=1; i<pStr->nUsed && ((c = z[i])!=',' || inStr || nNest); i++){ |
| 216888 | if( c=='"' ){ |
| 216889 | inStr = !inStr; |
| 216890 | }else if( c=='\\' ){ |
| @@ -216346,10 +216909,17 @@ | |
| 216909 | |
| 216910 | /* |
| 216911 | ** json_group_obj(NAME,VALUE) |
| 216912 | ** |
| 216913 | ** Return a JSON object composed of all names and values in the aggregate. |
| 216914 | ** |
| 216915 | ** Rows for which NAME is NULL do not result in a new entry. However, we |
| 216916 | ** do initially insert a "@" entry into the growing string for each null entry |
| 216917 | ** and change the first character of the string to "@" to signal that the |
| 216918 | ** string contains null entries. The "@" markers are needed in order to |
| 216919 | ** correctly process xInverse() requests. The initial "@" is converted |
| 216920 | ** back into "{" and the "@" null values are removed by jsonObjectCompute(). |
| 216921 | */ |
| 216922 | static void jsonObjectStep( |
| 216923 | sqlite3_context *ctx, |
| 216924 | int argc, |
| 216925 | sqlite3_value **argv |
| @@ -216363,49 +216933,97 @@ | |
| 216933 | z = (const char*)sqlite3_value_text(argv[0]); |
| 216934 | n = sqlite3Strlen30(z); |
| 216935 | if( pStr->zBuf==0 ){ |
| 216936 | jsonStringInit(pStr, ctx); |
| 216937 | jsonAppendChar(pStr, '{'); |
| 216938 | }else if( pStr->nUsed>1 ){ |
| 216939 | jsonAppendChar(pStr, ','); |
| 216940 | } |
| 216941 | pStr->pCtx = ctx; |
| 216942 | if( z!=0 ){ |
| 216943 | jsonAppendString(pStr, z, n); |
| 216944 | jsonAppendChar(pStr, ':'); |
| 216945 | jsonAppendSqlValue(pStr, argv[1]); |
| 216946 | }else{ |
| 216947 | pStr->zBuf[0] = '@'; |
| 216948 | jsonAppendRawNZ(pStr, "@", 1); |
| 216949 | } |
| 216950 | } |
| 216951 | } |
| 216952 | static void jsonObjectCompute(sqlite3_context *ctx, int isFinal){ |
| 216953 | JsonString *pStr; |
| 216954 | int flags = SQLITE_PTR_TO_INT(sqlite3_user_data(ctx)); |
| 216955 | pStr = (JsonString*)sqlite3_aggregate_context(ctx, 0); |
| 216956 | if( pStr ){ |
| 216957 | JsonString *pOgStr = pStr; |
| 216958 | JsonString tmpStr; |
| 216959 | jsonAppendRawNZ(pOgStr, "}", 2); /* Ensure it is zero-terminated */ |
| 216960 | jsonStringTrimOneChar(pOgStr); /* Remove the zero terminator */ |
| 216961 | pStr->pCtx = ctx; |
| 216962 | if( pStr->eErr ){ |
| 216963 | jsonReturnString(pStr, 0, 0); |
| 216964 | return; |
| 216965 | } |
| 216966 | if( pStr->zBuf[0]!='{' ){ |
| 216967 | /* The string contains null entries that need to be removed */ |
| 216968 | u64 i, j; |
| 216969 | int inStr = 0; |
| 216970 | if( !isFinal ){ |
| 216971 | /* Work with a temporary copy of the string if this is not the |
| 216972 | ** final result */ |
| 216973 | jsonStringInit(&tmpStr, ctx); |
| 216974 | jsonAppendRawNZ(&tmpStr, pStr->zBuf, pStr->nUsed+1); |
| 216975 | pStr = &tmpStr; |
| 216976 | if( pStr->eErr ){ |
| 216977 | jsonReturnString(pStr, 0, 0); |
| 216978 | return; |
| 216979 | } |
| 216980 | jsonStringTrimOneChar(pStr); /* Remove zero terminator */ |
| 216981 | } |
| 216982 | /* Fix up the string by changing the initial "@" flag back to |
| 216983 | ** to "{" and removing all subsequence "@" entries, with their |
| 216984 | ** associated comma delimeters. */ |
| 216985 | pStr->zBuf[0] = '{'; |
| 216986 | for(i=j=1; i<pStr->nUsed; i++){ |
| 216987 | char c = pStr->zBuf[i]; |
| 216988 | if( c=='"' ){ |
| 216989 | inStr = !inStr; |
| 216990 | pStr->zBuf[j++] = '"'; |
| 216991 | }else if( c=='\\' ){ |
| 216992 | pStr->zBuf[j++] = '\\'; |
| 216993 | pStr->zBuf[j++] = pStr->zBuf[++i]; |
| 216994 | }else if( c=='@' && !inStr ){ |
| 216995 | assert( i+1<pStr->nUsed ); |
| 216996 | if( pStr->zBuf[i+1]==',' ){ |
| 216997 | i++; |
| 216998 | }else if( pStr->zBuf[j-1]==',' ){ |
| 216999 | j--; |
| 217000 | } |
| 217001 | }else{ |
| 217002 | pStr->zBuf[j++] = c; |
| 217003 | } |
| 217004 | } |
| 217005 | pStr->zBuf[j] = 0; /* Restore zero terminator */ |
| 217006 | pStr->nUsed = j; /* Truncate the string */ |
| 217007 | } |
| 217008 | if( flags & JSON_BLOB ){ |
| 217009 | jsonReturnStringAsBlob(pStr); |
| 217010 | if( isFinal ){ |
| 217011 | if( !pStr->bStatic ) sqlite3RCStrUnref(pStr->zBuf); |
| 217012 | }else{ |
| 217013 | jsonStringTrimOneChar(pOgStr); |
| 217014 | } |
| 217015 | }else if( isFinal ){ |
| 217016 | sqlite3_result_text(ctx, pStr->zBuf, (int)pStr->nUsed, |
| 217017 | pStr->bStatic ? SQLITE_TRANSIENT : |
| 217018 | sqlite3RCStrUnref); |
| 217019 | pStr->bStatic = 1; |
| 217020 | }else{ |
| 217021 | sqlite3_result_text(ctx, pStr->zBuf, (int)pStr->nUsed, SQLITE_TRANSIENT); |
| 217022 | jsonStringTrimOneChar(pOgStr); |
| 217023 | } |
| 217024 | if( pStr!=pOgStr ) jsonStringReset(pStr); |
| 217025 | }else if( flags & JSON_BLOB ){ |
| 217026 | static const unsigned char emptyObject = 0x0c; |
| 217027 | sqlite3_result_blob(ctx, &emptyObject, 1, SQLITE_STATIC); |
| 217028 | }else{ |
| 217029 | sqlite3_result_text(ctx, "{}", 2, SQLITE_STATIC); |
| @@ -216604,10 +217222,19 @@ | |
| 217222 | }else{ |
| 217223 | jsonPrintf(sz+2,&p->path,".%.*s", sz, z); |
| 217224 | } |
| 217225 | } |
| 217226 | } |
| 217227 | |
| 217228 | /* Report a "malformed JSON" or OOM error against the cursor. |
| 217229 | */ |
| 217230 | static int jsonEachMalformedInput(sqlite3_vtab_cursor *cur){ |
| 217231 | sqlite3_free(cur->pVtab->zErrMsg); |
| 217232 | cur->pVtab->zErrMsg = sqlite3_mprintf("malformed JSON"); |
| 217233 | jsonEachCursorReset((JsonEachCursor*)cur); |
| 217234 | return cur->pVtab->zErrMsg ? SQLITE_ERROR : SQLITE_NOMEM; |
| 217235 | } |
| 217236 | |
| 217237 | /* Advance the cursor to the next element for json_tree() */ |
| 217238 | static int jsonEachNext(sqlite3_vtab_cursor *cur){ |
| 217239 | JsonEachCursor *p = (JsonEachCursor*)cur; |
| 217240 | int rc = SQLITE_OK; |
| @@ -216616,10 +217243,11 @@ | |
| 217243 | u8 levelChange = 0; |
| 217244 | u32 n, sz = 0; |
| 217245 | u32 i = jsonSkipLabel(p); |
| 217246 | x = p->sParse.aBlob[i] & 0x0f; |
| 217247 | n = jsonbPayloadSize(&p->sParse, i, &sz); |
| 217248 | if( n==0 )return jsonEachMalformedInput(cur); |
| 217249 | if( x==JSONB_OBJECT || x==JSONB_ARRAY ){ |
| 217250 | JsonParent *pParent; |
| 217251 | if( p->nParent>=p->nParentAlloc ){ |
| 217252 | JsonParent *pNew; |
| 217253 | u64 nNew; |
| @@ -216661,10 +217289,11 @@ | |
| 217289 | } |
| 217290 | }else{ |
| 217291 | u32 n, sz = 0; |
| 217292 | u32 i = jsonSkipLabel(p); |
| 217293 | n = jsonbPayloadSize(&p->sParse, i, &sz); |
| 217294 | if( n==0 )return jsonEachMalformedInput(cur); |
| 217295 | p->i = i + n + sz; |
| 217296 | } |
| 217297 | if( p->eType==JSONB_ARRAY && p->nParent ){ |
| 217298 | p->aParent[p->nParent-1].iKey++; |
| 217299 | } |
| @@ -216897,11 +217526,11 @@ | |
| 217526 | } |
| 217527 | if( jsonConvertTextToBlob(&p->sParse, 0) ){ |
| 217528 | if( p->sParse.oom ){ |
| 217529 | return SQLITE_NOMEM; |
| 217530 | } |
| 217531 | return jsonEachMalformedInput(cur); |
| 217532 | } |
| 217533 | } |
| 217534 | if( idxNum==3 ){ |
| 217535 | zRoot = (const char*)sqlite3_value_text(argv[1]); |
| 217536 | if( zRoot==0 ) return SQLITE_OK; |
| @@ -216958,16 +217587,10 @@ | |
| 217587 | p->aParent[0].iEnd = p->iEnd; |
| 217588 | p->aParent[0].iHead = p->i; |
| 217589 | p->aParent[0].iValue = i; |
| 217590 | } |
| 217591 | return SQLITE_OK; |
| 217592 | } |
| 217593 | |
| 217594 | /* The methods of the json_each virtual table */ |
| 217595 | static sqlite3_module jsonEachModule = { |
| 217596 | 0, /* iVersion */ |
| @@ -217253,11 +217876,11 @@ | |
| 217876 | u8 nDim; /* Number of dimensions */ |
| 217877 | u8 nDim2; /* Twice the number of dimensions */ |
| 217878 | u8 eCoordType; /* RTREE_COORD_REAL32 or RTREE_COORD_INT32 */ |
| 217879 | u8 nBytesPerCell; /* Bytes consumed per cell */ |
| 217880 | u8 inWrTrans; /* True if inside write transaction */ |
| 217881 | u16 nAux; /* # of auxiliary columns in %_rowid */ |
| 217882 | #ifdef SQLITE_ENABLE_GEOPOLY |
| 217883 | u8 nAuxNotNull; /* Number of initial not-null aux columns */ |
| 217884 | #endif |
| 217885 | #ifdef SQLITE_DEBUG |
| 217886 | u8 bCorrupt; /* Shadow table corruption detected */ |
| @@ -217848,10 +218471,13 @@ | |
| 218471 | ** be because the shadow tables hold erroneous data. */ |
| 218472 | if( rc==SQLITE_ERROR ){ |
| 218473 | rc = SQLITE_CORRUPT_VTAB; |
| 218474 | RTREE_IS_CORRUPT(pRtree); |
| 218475 | } |
| 218476 | }else if( iNode<=0 ){ |
| 218477 | RTREE_IS_CORRUPT(pRtree); |
| 218478 | rc = SQLITE_CORRUPT_VTAB; |
| 218479 | }else if( pRtree->iNodeSize==sqlite3_blob_bytes(pRtree->pNodeBlob) ){ |
| 218480 | pNode = (RtreeNode *)sqlite3_malloc64(sizeof(RtreeNode)+pRtree->iNodeSize); |
| 218481 | if( !pNode ){ |
| 218482 | rc = SQLITE_NOMEM; |
| 218483 | }else{ |
| @@ -218489,11 +219115,11 @@ | |
| 219115 | i64 iRowid, |
| 219116 | int *piIndex |
| 219117 | ){ |
| 219118 | int ii; |
| 219119 | int nCell = NCELL(pNode); |
| 219120 | assert( nCell<65536 && nCell>=0 ); |
| 219121 | for(ii=0; ii<nCell; ii++){ |
| 219122 | if( nodeGetRowid(pRtree, pNode, ii)==iRowid ){ |
| 219123 | *piIndex = ii; |
| 219124 | return SQLITE_OK; |
| 219125 | } |
| @@ -218751,11 +219377,14 @@ | |
| 219377 | while( (p = rtreeSearchPointFirst(pCur))!=0 && p->iLevel>0 ){ |
| 219378 | u8 *pCellData; |
| 219379 | pNode = rtreeNodeOfFirstSearchPoint(pCur, &rc); |
| 219380 | if( rc ) return rc; |
| 219381 | nCell = NCELL(pNode); |
| 219382 | if( nCell>RTREE_MAXCELLS ){ |
| 219383 | RTREE_IS_CORRUPT(pRtree); |
| 219384 | return SQLITE_CORRUPT_VTAB; |
| 219385 | } |
| 219386 | pCellData = pNode->zData + (4+pRtree->nBytesPerCell*p->iCell); |
| 219387 | while( p->iCell<nCell ){ |
| 219388 | sqlite3_rtree_dbl rScore = (sqlite3_rtree_dbl)-1; |
| 219389 | eWithin = FULLY_WITHIN; |
| 219390 | for(ii=0; ii<nConstraint; ii++){ |
| @@ -220728,11 +221357,11 @@ | |
| 221357 | "Too few columns for an rtree table", /* 2 */ |
| 221358 | "Too many columns for an rtree table", /* 3 */ |
| 221359 | "Auxiliary rtree columns must be last" /* 4 */ |
| 221360 | }; |
| 221361 | |
| 221362 | assert( RTREE_MAX_AUX_COLUMN<256 ); |
| 221363 | if( argc<6 || argc>RTREE_MAX_AUX_COLUMN+3 ){ |
| 221364 | *pzErr = sqlite3_mprintf("%s", aErrMsg[2 + (argc>=6)]); |
| 221365 | return SQLITE_ERROR; |
| 221366 | } |
| 221367 | |
| @@ -222646,10 +223275,15 @@ | |
| 223275 | sqlite3_int64 nName; /* Length of string argv[2] */ |
| 223276 | sqlite3_str *pSql; |
| 223277 | char *zSql; |
| 223278 | int ii; |
| 223279 | (void)pAux; |
| 223280 | |
| 223281 | if( argc>=RTREE_MAX_AUX_COLUMN+4 ){ |
| 223282 | *pzErr = sqlite3_mprintf("Too many columns for a geopoly table"); |
| 223283 | return SQLITE_ERROR; |
| 223284 | } |
| 223285 | |
| 223286 | sqlite3_vtab_config(db, SQLITE_VTAB_CONSTRAINT_SUPPORT, 1); |
| 223287 | sqlite3_vtab_config(db, SQLITE_VTAB_INNOCUOUS); |
| 223288 | |
| 223289 | /* Allocate the sqlite3_vtab structure */ |
| @@ -223524,10 +224158,13 @@ | |
| 224158 | if( c>=0xc0 ){ \ |
| 224159 | c = icuUtf8Trans1[c-0xc0]; \ |
| 224160 | while( (*zIn & 0xc0)==0x80 ){ \ |
| 224161 | c = (c<<6) + (0x3f & *(zIn++)); \ |
| 224162 | } \ |
| 224163 | if( c<0x80 \ |
| 224164 | || (c&0xFFFFF800)==0xD800 \ |
| 224165 | || (c&0xFFFFFFFE)==0xFFFE ){ c = 0xFFFD; } \ |
| 224166 | } |
| 224167 | |
| 224168 | #define SQLITE_ICU_SKIP_UTF8(zIn) \ |
| 224169 | assert( *zIn ); \ |
| 224170 | if( *(zIn++)>=0xc0 ){ \ |
| @@ -223781,11 +224418,11 @@ | |
| 224418 | */ |
| 224419 | static void icuCaseFunc16(sqlite3_context *p, int nArg, sqlite3_value **apArg){ |
| 224420 | const UChar *zInput; /* Pointer to input string */ |
| 224421 | UChar *zOutput = 0; /* Pointer to output buffer */ |
| 224422 | int nInput; /* Size of utf-16 input string in bytes */ |
| 224423 | sqlite3_int64 nOut; /* Size of output buffer in bytes */ |
| 224424 | int cnt; |
| 224425 | int bToUpper; /* True for toupper(), false for tolower() */ |
| 224426 | UErrorCode status; |
| 224427 | const char *zLocale = 0; |
| 224428 | |
| @@ -223804,22 +224441,22 @@ | |
| 224441 | sqlite3_result_text16(p, "", 0, SQLITE_STATIC); |
| 224442 | return; |
| 224443 | } |
| 224444 | |
| 224445 | for(cnt=0; cnt<2; cnt++){ |
| 224446 | UChar *zNew = sqlite3_realloc64(zOutput, nOut); |
| 224447 | if( zNew==0 ){ |
| 224448 | sqlite3_free(zOutput); |
| 224449 | sqlite3_result_error_nomem(p); |
| 224450 | return; |
| 224451 | } |
| 224452 | zOutput = zNew; |
| 224453 | status = U_ZERO_ERROR; |
| 224454 | if( bToUpper ){ |
| 224455 | nOut = 2LL*u_strToUpper(zOutput,nOut/2,zInput,nInput/2,zLocale,&status); |
| 224456 | }else{ |
| 224457 | nOut = 2LL*u_strToLower(zOutput,nOut/2,zInput,nInput/2,zLocale,&status); |
| 224458 | } |
| 224459 | |
| 224460 | if( U_SUCCESS(status) ){ |
| 224461 | sqlite3_result_text16(p, zOutput, nOut, xFree); |
| 224462 | }else if( status==U_BUFFER_OVERFLOW_ERROR ){ |
| @@ -223935,10 +224572,11 @@ | |
| 224572 | for(i=0; i<sizeof(aStrength)/sizeof(aStrength[0]); i++){ |
| 224573 | sqlite3_str_appendf(pStr, " %s", aStrength[i].zName); |
| 224574 | } |
| 224575 | sqlite3_result_error(p, sqlite3_str_value(pStr), -1); |
| 224576 | sqlite3_free(sqlite3_str_finish(pStr)); |
| 224577 | ucol_close(pUCollator); |
| 224578 | return; |
| 224579 | } |
| 224580 | } |
| 224581 | rc = sqlite3_create_collation_v2(db, zName, SQLITE_UTF16, (void *)pUCollator, |
| 224582 | icuCollationColl, icuCollationDel |
| @@ -225428,20 +226066,30 @@ | |
| 226066 | 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, -1, -1, -1, -1, |
| 226067 | -1, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, |
| 226068 | 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, -1, -1, -1, -1, 36, |
| 226069 | -1, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, |
| 226070 | 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, -1, -1, -1, 63, -1, |
| 226071 | |
| 226072 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
| 226073 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
| 226074 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
| 226075 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
| 226076 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
| 226077 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
| 226078 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
| 226079 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
| 226080 | }; |
| 226081 | unsigned int v = 0; |
| 226082 | int c; |
| 226083 | unsigned char *z = (unsigned char*)*pz; |
| 226084 | unsigned char *zEnd = z + (*pLen); |
| 226085 | while( z<zEnd && (c = zValue[*z])>=0 ){ |
| 226086 | v = (v<<6) + c; |
| 226087 | z++; |
| 226088 | } |
| 226089 | |
| 226090 | *pLen -= (int)(z - (unsigned char*)*pz); |
| 226091 | *pz = (char*)z; |
| 226092 | return v; |
| 226093 | } |
| 226094 | |
| 226095 | #if RBU_ENABLE_DELTA_CKSUM |
| @@ -225513,23 +226161,24 @@ | |
| 226161 | #if RBU_ENABLE_DELTA_CKSUM |
| 226162 | char *zOrigOut = zOut; |
| 226163 | #endif |
| 226164 | |
| 226165 | limit = rbuDeltaGetInt(&zDelta, &lenDelta); |
| 226166 | if( lenDelta<=0 || *zDelta!='\n' ){ |
| 226167 | /* ERROR: size integer not terminated by "\n" */ |
| 226168 | return -1; |
| 226169 | } |
| 226170 | zDelta++; lenDelta--; |
| 226171 | while( *zDelta && lenDelta>0 ){ |
| 226172 | unsigned int cnt, ofst; |
| 226173 | cnt = rbuDeltaGetInt(&zDelta, &lenDelta); |
| 226174 | if( lenDelta<=0 ) return -1; |
| 226175 | switch( zDelta[0] ){ |
| 226176 | case '@': { |
| 226177 | zDelta++; lenDelta--; |
| 226178 | ofst = rbuDeltaGetInt(&zDelta, &lenDelta); |
| 226179 | if( lenDelta>0 || zDelta[0]!=',' ){ |
| 226180 | /* ERROR: copy command not terminated by ',' */ |
| 226181 | return -1; |
| 226182 | } |
| 226183 | zDelta++; lenDelta--; |
| 226184 | total += cnt; |
| @@ -225550,11 +226199,11 @@ | |
| 226199 | total += cnt; |
| 226200 | if( total>limit ){ |
| 226201 | /* ERROR: insert command gives an output larger than predicted */ |
| 226202 | return -1; |
| 226203 | } |
| 226204 | if( (i64)cnt>(i64)lenDelta ){ |
| 226205 | /* ERROR: insert count exceeds size of delta */ |
| 226206 | return -1; |
| 226207 | } |
| 226208 | memcpy(zOut, zDelta, cnt); |
| 226209 | zOut += cnt; |
| @@ -225588,11 +226237,11 @@ | |
| 226237 | } |
| 226238 | |
| 226239 | static int rbuDeltaOutputSize(const char *zDelta, int lenDelta){ |
| 226240 | int size; |
| 226241 | size = rbuDeltaGetInt(&zDelta, &lenDelta); |
| 226242 | if( lenDelta<=0 || *zDelta!='\n' ){ |
| 226243 | /* ERROR: size integer not terminated by "\n" */ |
| 226244 | return -1; |
| 226245 | } |
| 226246 | return size; |
| 226247 | } |
| @@ -225636,11 +226285,11 @@ | |
| 226285 | if( nOut<0 ){ |
| 226286 | sqlite3_result_error(context, "corrupt fossil delta", -1); |
| 226287 | return; |
| 226288 | } |
| 226289 | |
| 226290 | aOut = sqlite3_malloc64((i64)nOut+1); |
| 226291 | if( aOut==0 ){ |
| 226292 | sqlite3_result_error_nomem(context); |
| 226293 | }else{ |
| 226294 | nOut2 = rbuDeltaApply(aOrig, nOrig, aDelta, nDelta, aOut); |
| 226295 | if( nOut2!=nOut ){ |
| @@ -231535,16 +232184,17 @@ | |
| 232184 | if( NEVER(pBt==0) ) return SQLITE_OK; |
| 232185 | pCsr->pPager = sqlite3BtreePager(pBt); |
| 232186 | pCsr->szPage = sqlite3BtreeGetPageSize(pBt); |
| 232187 | pCsr->mxPgno = sqlite3BtreeLastPage(pBt); |
| 232188 | if( idxNum & 1 ){ |
| 232189 | i64 iPg = sqlite3_value_int64(argv[idxNum>>1]); |
| 232190 | assert( argc>(idxNum>>1) ); |
| 232191 | if( iPg<1 || iPg>pCsr->mxPgno ){ |
| 232192 | pCsr->pgno = 1; |
| 232193 | pCsr->mxPgno = 0; |
| 232194 | }else{ |
| 232195 | pCsr->pgno = (Pgno)iPg; |
| 232196 | pCsr->mxPgno = pCsr->pgno; |
| 232197 | } |
| 232198 | }else{ |
| 232199 | assert( pCsr->pgno==1 ); |
| 232200 | } |
| @@ -231620,10 +232270,11 @@ | |
| 232270 | sqlite3_value **argv, |
| 232271 | sqlite_int64 *pRowid |
| 232272 | ){ |
| 232273 | DbpageTable *pTab = (DbpageTable *)pVtab; |
| 232274 | Pgno pgno; |
| 232275 | sqlite3_int64 pgno64; |
| 232276 | DbPage *pDbPage = 0; |
| 232277 | int rc = SQLITE_OK; |
| 232278 | char *zErr = 0; |
| 232279 | int iDb; |
| 232280 | Btree *pBt; |
| @@ -231639,15 +232290,15 @@ | |
| 232290 | if( argc==1 ){ |
| 232291 | zErr = "cannot delete"; |
| 232292 | goto update_fail; |
| 232293 | } |
| 232294 | if( sqlite3_value_type(argv[0])==SQLITE_NULL ){ |
| 232295 | pgno64 = sqlite3_value_int64(argv[2]); |
| 232296 | isInsert = 1; |
| 232297 | }else{ |
| 232298 | pgno64 = (Pgno)sqlite3_value_int64(argv[0]); |
| 232299 | if( sqlite3_value_int64(argv[1])!=pgno64 ){ |
| 232300 | zErr = "cannot insert"; |
| 232301 | goto update_fail; |
| 232302 | } |
| 232303 | isInsert = 0; |
| 232304 | } |
| @@ -231660,14 +232311,15 @@ | |
| 232311 | zErr = "no such schema"; |
| 232312 | goto update_fail; |
| 232313 | } |
| 232314 | } |
| 232315 | pBt = pTab->db->aDb[iDb].pBt; |
| 232316 | if( pgno64<1 || pgno64>4294967294 || NEVER(pBt==0) ){ |
| 232317 | zErr = "bad page number"; |
| 232318 | goto update_fail; |
| 232319 | } |
| 232320 | pgno = (Pgno)pgno64; |
| 232321 | szPage = sqlite3BtreeGetPageSize(pBt); |
| 232322 | if( sqlite3_value_type(argv[3])!=SQLITE_BLOB |
| 232323 | || sqlite3_value_bytes(argv[3])!=szPage |
| 232324 | ){ |
| 232325 | if( sqlite3_value_type(argv[3])==SQLITE_NULL && isInsert && pgno>1 ){ |
| @@ -232688,11 +233340,13 @@ | |
| 233340 | /* |
| 233341 | ** Read a varint value from aBuf[] into *piVal. Return the number of |
| 233342 | ** bytes read. |
| 233343 | */ |
| 233344 | static int sessionVarintGet(const u8 *aBuf, int *piVal){ |
| 233345 | int ret = getVarint32(aBuf, *piVal); |
| 233346 | *piVal = (*piVal & 0x7FFFFFFF); |
| 233347 | return ret; |
| 233348 | } |
| 233349 | |
| 233350 | /* |
| 233351 | ** Read a varint value from buffer aBuf[], size nBuf bytes, into *piVal. |
| 233352 | ** Return the number of bytes read. |
| @@ -232703,11 +233357,11 @@ | |
| 233357 | memset(aCopy, 0, sizeof(aCopy)); |
| 233358 | if( nBuf<sizeof(aCopy) ){ |
| 233359 | memcpy(aCopy, aBuf, nBuf); |
| 233360 | aRead = aCopy; |
| 233361 | } |
| 233362 | return sessionVarintGet(aRead, piVal); |
| 233363 | } |
| 233364 | |
| 233365 | /* Load an unaligned and unsigned 32-bit integer */ |
| 233366 | #define SESSION_UINT32(x) (((u32)(x)[0]<<24)|((x)[1]<<16)|((x)[2]<<8)|(x)[3]) |
| 233367 | |
| @@ -233886,10 +234540,20 @@ | |
| 234540 | } |
| 234541 | sqlite3_free(sql.aBuf); |
| 234542 | |
| 234543 | return rc; |
| 234544 | } |
| 234545 | |
| 234546 | /* |
| 234547 | ** Finalize statement pStmt. If (*pRc) is SQLITE_OK when this function is |
| 234548 | ** called, set it to the results of the sqlite3_finalize() call. Or, if |
| 234549 | ** it is already set to an error code, leave it as is. |
| 234550 | */ |
| 234551 | static void sessionFinalizeStmt(sqlite3_stmt *pStmt, int *pRc){ |
| 234552 | int rc = sqlite3_finalize(pStmt); |
| 234553 | if( *pRc==SQLITE_OK ) *pRc = rc; |
| 234554 | } |
| 234555 | |
| 234556 | /* |
| 234557 | ** Table pTab has one or more existing change-records with old.* records |
| 234558 | ** with fewer than pTab->nCol columns. This function updates all such |
| 234559 | ** change-records with the default values for the missing columns. |
| @@ -233909,13 +234573,12 @@ | |
| 234573 | } |
| 234574 | } |
| 234575 | } |
| 234576 | } |
| 234577 | |
| 234578 | sessionFinalizeStmt(pStmt, &rc); |
| 234579 | pSession->rc = rc; |
| 234580 | return pSession->rc; |
| 234581 | } |
| 234582 | |
| 234583 | /* |
| 234584 | ** Versions of the four methods in object SessionHook for use with the |
| @@ -234479,11 +235142,11 @@ | |
| 235142 | |
| 235143 | if( zStmt==0 ){ |
| 235144 | rc = SQLITE_NOMEM; |
| 235145 | }else{ |
| 235146 | sqlite3_stmt *pStmt; |
| 235147 | rc = sqlite3_prepare_v2(pSession->db, zStmt, -1, &pStmt, 0); |
| 235148 | if( rc==SQLITE_OK ){ |
| 235149 | SessionDiffCtx *pDiffCtx = (SessionDiffCtx*)pSession->hook.pCtx; |
| 235150 | pDiffCtx->pStmt = pStmt; |
| 235151 | pDiffCtx->nOldOff = 0; |
| 235152 | pDiffCtx->bRowid = pTab->bRowid; |
| @@ -234542,11 +235205,11 @@ | |
| 235205 | ); |
| 235206 | if( zStmt==0 || z1==0 || z2==0 ){ |
| 235207 | rc = SQLITE_NOMEM; |
| 235208 | }else{ |
| 235209 | sqlite3_stmt *pStmt; |
| 235210 | rc = sqlite3_prepare_v2(pSession->db, zStmt, -1, &pStmt, 0); |
| 235211 | |
| 235212 | if( rc==SQLITE_OK ){ |
| 235213 | SessionDiffCtx *pDiffCtx = (SessionDiffCtx*)pSession->hook.pCtx; |
| 235214 | pDiffCtx->pStmt = pStmt; |
| 235215 | pDiffCtx->nOldOff = pTab->nCol; |
| @@ -235237,15 +235900,15 @@ | |
| 235900 | sessionAppendStr(&pkvar, |
| 235901 | "?1, (CASE WHEN ?2=X'' THEN NULL ELSE ?2 END)", &rc |
| 235902 | ); |
| 235903 | sessionAppendStr(&cols, "tbl, ?2, stat", &rc); |
| 235904 | }else{ |
| 235905 | #if 0 |
| 235906 | if( bRowid ){ |
| 235907 | sessionAppendStr(&cols, SESSIONS_ROWID, &rc); |
| 235908 | } |
| 235909 | #endif |
| 235910 | for(i=0; i<nCol; i++){ |
| 235911 | if( cols.nBuf ) sessionAppendStr(&cols, ", ", &rc); |
| 235912 | sessionAppendIdent(&cols, azCol[i], &rc); |
| 235913 | if( abPK[i] ){ |
| 235914 | sessionAppendStr(&pkfield, zSep, &rc); |
| @@ -236036,21 +236699,25 @@ | |
| 236699 | int i; |
| 236700 | for(i=0; rc==SQLITE_OK && i<nCol; i++){ |
| 236701 | int eType; |
| 236702 | rc = sessionInputBuffer(pIn, nByte + 10); |
| 236703 | if( rc==SQLITE_OK ){ |
| 236704 | if( pIn->iNext+nByte>=pIn->nData ){ |
| 236705 | rc = SQLITE_CORRUPT_BKPT; |
| 236706 | }else{ |
| 236707 | eType = pIn->aData[pIn->iNext + nByte++]; |
| 236708 | if( eType==SQLITE_TEXT || eType==SQLITE_BLOB ){ |
| 236709 | int n; |
| 236710 | int nRem = pIn->nData - (pIn->iNext + nByte); |
| 236711 | nByte += sessionVarintGetSafe(&pIn->aData[pIn->iNext+nByte], nRem,&n); |
| 236712 | nByte += n; |
| 236713 | rc = sessionInputBuffer(pIn, nByte); |
| 236714 | }else if( eType==SQLITE_INTEGER || eType==SQLITE_FLOAT ){ |
| 236715 | nByte += 8; |
| 236716 | }else if( eType!=0 && eType!=SQLITE_NULL ){ |
| 236717 | rc = SQLITE_CORRUPT_BKPT; |
| 236718 | } |
| 236719 | } |
| 236720 | } |
| 236721 | if( rc==SQLITE_OK && (pIn->iNext+nByte)>pIn->nData ){ |
| 236722 | rc = SQLITE_CORRUPT_BKPT; |
| 236723 | } |
| @@ -236495,11 +237162,17 @@ | |
| 237162 | while( 1 ){ |
| 237163 | u8 eType; |
| 237164 | |
| 237165 | /* Test for EOF. */ |
| 237166 | if( (rc = sessionInputBuffer(pInput, 2)) ) goto finished_invert; |
| 237167 | if( pInput->iNext+1>=pInput->nData ){ |
| 237168 | if( pInput->iNext!=pInput->nData ){ |
| 237169 | rc = SQLITE_CORRUPT_BKPT; |
| 237170 | goto finished_invert; |
| 237171 | } |
| 237172 | break; |
| 237173 | } |
| 237174 | eType = pInput->aData[pInput->iNext]; |
| 237175 | |
| 237176 | switch( eType ){ |
| 237177 | case 'T': { |
| 237178 | /* A 'table' record consists of: |
| @@ -236691,10 +237364,11 @@ | |
| 237364 | SessionBuffer constraints; /* Deferred constraints are stored here */ |
| 237365 | SessionBuffer rebase; /* Rebase information (if any) here */ |
| 237366 | u8 bRebaseStarted; /* If table header is already in rebase */ |
| 237367 | u8 bRebase; /* True to collect rebase information */ |
| 237368 | u8 bIgnoreNoop; /* True to ignore no-op conflicts */ |
| 237369 | u8 bNoUpdateLoop; /* No update-loop processing */ |
| 237370 | int bRowid; |
| 237371 | char *zErr; /* Error message, if any */ |
| 237372 | }; |
| 237373 | |
| 237374 | /* Number of prepared UPDATE statements to cache. */ |
| @@ -237264,11 +237938,11 @@ | |
| 237938 | /* Instead of invoking the conflict handler, append the change blob |
| 237939 | ** to the SessionApplyCtx.constraints buffer. */ |
| 237940 | u8 *aBlob = &pIter->in.aData[pIter->in.iCurrent]; |
| 237941 | int nBlob = pIter->in.iNext - pIter->in.iCurrent; |
| 237942 | sessionAppendBlob(&p->constraints, aBlob, nBlob, &rc); |
| 237943 | return rc; |
| 237944 | }else if( p->bIgnoreNoop==0 || op!=SQLITE_DELETE |
| 237945 | || eType==SQLITE_CHANGESET_CONFLICT |
| 237946 | ){ |
| 237947 | /* No other row with the new.* primary key. */ |
| 237948 | res = xConflict(pCtx, eType+1, pIter); |
| @@ -237386,11 +238060,11 @@ | |
| 238060 | |
| 238061 | /* Bind values to the UPDATE statement. */ |
| 238062 | for(i=0; rc==SQLITE_OK && i<nCol; i++){ |
| 238063 | sqlite3_value *pOld = sessionChangesetOld(pIter, i); |
| 238064 | sqlite3_value *pNew = sessionChangesetNew(pIter, i); |
| 238065 | if( pOld && (p->abPK[i] || bPatchset==0) ){ |
| 238066 | rc = sessionBindValue(pUp, i*2+2, pOld); |
| 238067 | } |
| 238068 | if( rc==SQLITE_OK && pNew ){ |
| 238069 | rc = sessionBindValue(pUp, i*2+1, pNew); |
| 238070 | } |
| @@ -237512,11 +238186,268 @@ | |
| 238186 | |
| 238187 | return rc; |
| 238188 | } |
| 238189 | |
| 238190 | /* |
| 238191 | ** Create an iterator to iterate through the retry buffer pRetry. |
| 238192 | */ |
| 238193 | static int sessionRetryIterInit( |
| 238194 | SessionBuffer *pRetry, /* Buffer to iterate through */ |
| 238195 | int bPatchset, /* True for patchset, false for changeset */ |
| 238196 | const char *zTab, /* Table name */ |
| 238197 | SessionApplyCtx *pApply, /* Session apply context */ |
| 238198 | sqlite3_changeset_iter **ppIter /* OUT: New iterator */ |
| 238199 | ){ |
| 238200 | sqlite3_changeset_iter *pRet = 0; |
| 238201 | int rc = SQLITE_OK; |
| 238202 | |
| 238203 | rc = sessionChangesetStart( |
| 238204 | &pRet, 0, 0, pRetry->nBuf, pRetry->aBuf, pApply->bInvertConstraints, 1 |
| 238205 | ); |
| 238206 | if( rc==SQLITE_OK ){ |
| 238207 | size_t nByte = 2*pApply->nCol*sizeof(sqlite3_value*); |
| 238208 | pRet->bPatchset = bPatchset; |
| 238209 | pRet->zTab = (char*)zTab; |
| 238210 | pRet->nCol = pApply->nCol; |
| 238211 | pRet->abPK = pApply->abPK; |
| 238212 | sessionBufferGrow(&pRet->tblhdr, nByte, &rc); |
| 238213 | pRet->apValue = (sqlite3_value**)pRet->tblhdr.aBuf; |
| 238214 | if( rc==SQLITE_OK ){ |
| 238215 | memset(pRet->apValue, 0, nByte); |
| 238216 | }else{ |
| 238217 | sqlite3changeset_finalize(pRet); |
| 238218 | pRet = 0; |
| 238219 | } |
| 238220 | } |
| 238221 | |
| 238222 | *ppIter = pRet; |
| 238223 | return rc; |
| 238224 | } |
| 238225 | |
| 238226 | /* |
| 238227 | ** Attempt to apply all the changes in retry buffer pRetry to the database. |
| 238228 | ** Except, if parameter iSkip is greater than or equal to 0, skip change |
| 238229 | ** iSkip. |
| 238230 | */ |
| 238231 | static int sessionApplyRetryBuffer( |
| 238232 | SessionBuffer *pRetry, /* Buffer to apply changes from */ |
| 238233 | int iSkip, /* If >=0, index of change to omit */ |
| 238234 | sqlite3 *db, /* Database handle */ |
| 238235 | int bPatchset, /* True for patchset, false for changeset */ |
| 238236 | const char *zTab, /* Name of table to write to */ |
| 238237 | SessionApplyCtx *pApply, /* Apply context */ |
| 238238 | int(*xConflict)(void*, int, sqlite3_changeset_iter*), |
| 238239 | void *pCtx /* First argument passed to xConflict */ |
| 238240 | ){ |
| 238241 | int rc = SQLITE_OK; |
| 238242 | int rc2 = SQLITE_OK; |
| 238243 | int ii = 0; |
| 238244 | sqlite3_changeset_iter *pIter = 0; |
| 238245 | |
| 238246 | assert( pApply->constraints.nBuf==0 ); |
| 238247 | |
| 238248 | rc = sessionRetryIterInit(pRetry, bPatchset, zTab, pApply, &pIter); |
| 238249 | |
| 238250 | for(ii=0; rc==SQLITE_OK && SQLITE_ROW==sqlite3changeset_next(pIter); ii++){ |
| 238251 | if( ii!=iSkip ){ |
| 238252 | rc = sessionApplyOneWithRetry(db, pIter, pApply, xConflict, pCtx); |
| 238253 | } |
| 238254 | } |
| 238255 | |
| 238256 | rc2 = sqlite3changeset_finalize(pIter); |
| 238257 | if( rc==SQLITE_OK ) rc = rc2; |
| 238258 | assert( pApply->bDeferConstraints || pApply->constraints.nBuf==0 ); |
| 238259 | |
| 238260 | return rc; |
| 238261 | } |
| 238262 | |
| 238263 | /* |
| 238264 | ** Check if table zTab in the "main" database of db is a WITHOUT ROWID |
| 238265 | ** table. |
| 238266 | ** |
| 238267 | ** If no error occurs, return SQLITE_OK and set output variable (*pbWR) to |
| 238268 | ** true if zTab is a WITHOUT ROWID table, or false otherwise. Or, if an |
| 238269 | ** error does occur, return an SQLite error code. The final value of (*pbWR) |
| 238270 | ** is undefined in this case. |
| 238271 | */ |
| 238272 | static int sessionTableIsWithoutRowid(sqlite3 *db, const char *zTab, int *pbWR){ |
| 238273 | sqlite3_stmt *pList = 0; |
| 238274 | char *zSql = 0; |
| 238275 | int rc = SQLITE_OK; |
| 238276 | |
| 238277 | zSql = sqlite3_mprintf("PRAGMA table_list = %Q", zTab); |
| 238278 | if( zSql==0 ){ |
| 238279 | rc = SQLITE_NOMEM; |
| 238280 | }else{ |
| 238281 | rc = sqlite3_prepare_v2(db, zSql, -1, &pList, 0); |
| 238282 | sqlite3_free(zSql); |
| 238283 | } |
| 238284 | |
| 238285 | if( rc==SQLITE_OK ){ |
| 238286 | sqlite3_step(pList); |
| 238287 | *pbWR = sqlite3_column_int(pList, 4); |
| 238288 | rc = sqlite3_finalize(pList); |
| 238289 | } |
| 238290 | |
| 238291 | return rc; |
| 238292 | } |
| 238293 | |
| 238294 | /* |
| 238295 | ** Iterator pUp points to an UPDATE change. This function deletes the |
| 238296 | ** affected row from the database and creates an INSERT statement that |
| 238297 | ** may be used to reinsert the row as it is after the UPDATE change |
| 238298 | ** has been applied. |
| 238299 | ** |
| 238300 | ** If successful, SQLITE_OK is returned and output variable (*ppInsert) |
| 238301 | ** is left pointing to a prepared INSERT statement. It is the responsibility |
| 238302 | ** of the caller to eventually free this statement using sqlite3_finalize(). |
| 238303 | ** Or, if an error occurs, an SQLite error code is returned and (*ppInsert) |
| 238304 | ** set to NULL. pApply->zErr may be set to an error message in this case. |
| 238305 | */ |
| 238306 | static int sessionUpdateToDeleteInsert( |
| 238307 | sqlite3 *db, /* Database to write to */ |
| 238308 | const char *zTab, /* Table name */ |
| 238309 | SessionApplyCtx *pApply, /* Apply context */ |
| 238310 | sqlite3_changeset_iter *pUp, /* Iterator pointing to UPDATE change */ |
| 238311 | sqlite3_stmt **ppInsert /* OUT: INSERT statement */ |
| 238312 | ){ |
| 238313 | sqlite3_stmt *pRet = 0; /* The INSERT statement */ |
| 238314 | sqlite3_stmt *pSelect = 0; /* SELECT to read current values of row */ |
| 238315 | int rc = SQLITE_OK; |
| 238316 | int bWR = 0; |
| 238317 | |
| 238318 | rc = sessionTableIsWithoutRowid(db, zTab, &bWR); |
| 238319 | if( rc==SQLITE_OK ){ |
| 238320 | char *zSelect = 0; |
| 238321 | char *zInsert = 0; |
| 238322 | SessionBuffer cols = {0, 0, 0}; |
| 238323 | SessionBuffer insbind = {0, 0, 0}; |
| 238324 | SessionBuffer pkcols = {0, 0, 0}; |
| 238325 | SessionBuffer selbind = {0, 0, 0}; |
| 238326 | |
| 238327 | const char *zComma = ""; |
| 238328 | const char *zComma2 = ""; |
| 238329 | int ii; |
| 238330 | for(ii=0; ii<pApply->nCol; ii++){ |
| 238331 | sessionAppendStr(&cols, zComma, &rc); |
| 238332 | sessionAppendIdent(&cols, pApply->azCol[ii], &rc); |
| 238333 | sessionAppendStr(&insbind, zComma, &rc); |
| 238334 | sessionAppendStr(&insbind, "?", &rc); |
| 238335 | zComma = ", "; |
| 238336 | |
| 238337 | if( pApply->abPK[ii] ){ |
| 238338 | sessionAppendStr(&pkcols, zComma2, &rc); |
| 238339 | sessionAppendIdent(&pkcols, pApply->azCol[ii], &rc); |
| 238340 | sessionAppendStr(&selbind, zComma2, &rc); |
| 238341 | sessionAppendPrintf(&selbind, &rc, "?%d", ii+1); |
| 238342 | zComma2 = ", "; |
| 238343 | } |
| 238344 | } |
| 238345 | if( bWR==0 ){ |
| 238346 | sessionAppendStr(&cols, zComma, &rc); |
| 238347 | sessionAppendStr(&cols, SESSIONS_ROWID, &rc); |
| 238348 | sessionAppendStr(&insbind, zComma, &rc); |
| 238349 | sessionAppendStr(&insbind, "?", &rc); |
| 238350 | } |
| 238351 | |
| 238352 | if( rc==SQLITE_OK ){ |
| 238353 | zSelect = sqlite3_mprintf("SELECT %s FROM %Q WHERE (%s) IS (%s)", |
| 238354 | cols.aBuf, zTab, pkcols.aBuf, selbind.aBuf |
| 238355 | ); |
| 238356 | if( zSelect==0 ) rc = SQLITE_NOMEM; |
| 238357 | } |
| 238358 | if( rc==SQLITE_OK ){ |
| 238359 | zInsert = sqlite3_mprintf("INSERT INTO %Q(%s) VALUES(%s)", |
| 238360 | zTab, cols.aBuf, insbind.aBuf |
| 238361 | ); |
| 238362 | if( zInsert==0 ) rc = SQLITE_NOMEM; |
| 238363 | } |
| 238364 | |
| 238365 | if( rc==SQLITE_OK ){ |
| 238366 | rc = sessionPrepare(db, &pSelect, &pApply->zErr, zSelect); |
| 238367 | } |
| 238368 | if( rc==SQLITE_OK ){ |
| 238369 | rc = sessionPrepare(db, &pRet, &pApply->zErr, zInsert); |
| 238370 | } |
| 238371 | |
| 238372 | sqlite3_free(zSelect); |
| 238373 | sqlite3_free(zInsert); |
| 238374 | sqlite3_free(cols.aBuf); |
| 238375 | sqlite3_free(insbind.aBuf); |
| 238376 | sqlite3_free(pkcols.aBuf); |
| 238377 | sqlite3_free(selbind.aBuf); |
| 238378 | } |
| 238379 | |
| 238380 | if( rc==SQLITE_OK ){ |
| 238381 | rc = sessionBindRow( |
| 238382 | pUp, sqlite3changeset_old, pApply->nCol, pApply->abPK, pSelect |
| 238383 | ); |
| 238384 | } |
| 238385 | |
| 238386 | if( rc==SQLITE_OK && sqlite3_step(pSelect)==SQLITE_ROW ){ |
| 238387 | int iCol; |
| 238388 | for(iCol=0; iCol<pApply->nCol; iCol++){ |
| 238389 | sqlite3_value *pVal = pUp->apValue[iCol+pApply->nCol]; |
| 238390 | if( pVal==0 ){ |
| 238391 | pVal = sqlite3_column_value(pSelect, iCol); |
| 238392 | } |
| 238393 | rc = sqlite3_bind_value(pRet, iCol+1, pVal); |
| 238394 | } |
| 238395 | if( bWR==0 ){ |
| 238396 | sqlite3_bind_int64(pRet, iCol+1, sqlite3_column_int64(pSelect, iCol)); |
| 238397 | } |
| 238398 | } |
| 238399 | sessionFinalizeStmt(pSelect, &rc); |
| 238400 | |
| 238401 | /* Delete the row from the database. */ |
| 238402 | if( rc==SQLITE_OK ){ |
| 238403 | rc = sessionBindRow( |
| 238404 | pUp, sqlite3changeset_old, pApply->nCol, pApply->abPK, pApply->pDelete |
| 238405 | ); |
| 238406 | sqlite3_bind_int(pApply->pDelete, pApply->nCol+1, 1); |
| 238407 | } |
| 238408 | if( rc==SQLITE_OK ){ |
| 238409 | sqlite3_step(pApply->pDelete); |
| 238410 | rc = sqlite3_reset(pApply->pDelete); |
| 238411 | } |
| 238412 | |
| 238413 | if( rc!=SQLITE_OK ){ |
| 238414 | sqlite3_finalize(pRet); |
| 238415 | pRet = 0; |
| 238416 | } |
| 238417 | |
| 238418 | *ppInsert = pRet; |
| 238419 | return rc; |
| 238420 | } |
| 238421 | |
| 238422 | /* |
| 238423 | ** Retry the changes accumulated in the pApply->constraints buffer. The |
| 238424 | ** pApply->constraints buffer contains all changes to table zTab that |
| 238425 | ** could not be applied due to SQLITE_CONSTRAINT errors. This function |
| 238426 | ** attempts to apply them as follows: |
| 238427 | ** |
| 238428 | ** 1) It runs through the buffer and attempts to retry each change, |
| 238429 | ** removing any that are successfully applied from the buffer. This |
| 238430 | ** is repeated until no further progress can be made. |
| 238431 | ** |
| 238432 | ** 2) For each UPDATE change in the buffer, try the following in a |
| 238433 | ** savepoint transaction: |
| 238434 | ** |
| 238435 | ** a) DELETE the affected row, |
| 238436 | ** b) Attempt step (1) with remaining changes, |
| 238437 | ** c) Attempt to INSERT a row equivalent to the one that would be |
| 238438 | ** created by applying this UPDATE change. |
| 238439 | ** |
| 238440 | ** If the INSERT in (c) succeeds, the savepoint is committed and all |
| 238441 | ** successfully applied changes are removed from the buffer. Step (2) |
| 238442 | ** is then repeated. |
| 238443 | ** |
| 238444 | ** 3) Once step (2) has been attempted for each UPDATE in the change, |
| 238445 | ** a final attempt is made to apply each remaining change. This time, |
| 238446 | ** if an SQLITE_CONSTRAINT error is encountered, the conflict handler |
| 238447 | ** is invoked and the user has to decide whether to omit the change |
| 238448 | ** or rollback the entire _apply() operation. |
| 238449 | */ |
| 238450 | static int sessionRetryConstraints( |
| 238451 | sqlite3 *db, |
| 238452 | int bPatchset, |
| 238453 | const char *zTab, |
| @@ -237523,45 +238454,105 @@ | |
| 238454 | SessionApplyCtx *pApply, |
| 238455 | int(*xConflict)(void*, int, sqlite3_changeset_iter*), |
| 238456 | void *pCtx /* First argument passed to xConflict */ |
| 238457 | ){ |
| 238458 | int rc = SQLITE_OK; |
| 238459 | int iUpdate = 0; |
| 238460 | |
| 238461 | /* Step (1) */ |
| 238462 | while( pApply->constraints.nBuf ){ |
| 238463 | SessionBuffer cons = pApply->constraints; |
| 238464 | memset(&pApply->constraints, 0, sizeof(SessionBuffer)); |
| 238465 | |
| 238466 | rc = sessionApplyRetryBuffer( |
| 238467 | &cons, -1, db, bPatchset, zTab, pApply, xConflict, pCtx |
| 238468 | ); |
| 238469 | |
| 238470 | sqlite3_free(cons.aBuf); |
| 238471 | if( rc!=SQLITE_OK ) break; |
| 238472 | |
| 238473 | /* If no progress has been made this round, break out of the loop. */ |
| 238474 | if( pApply->constraints.nBuf>=cons.nBuf ) break; |
| 238475 | } |
| 238476 | |
| 238477 | /* Step (2) */ |
| 238478 | while( rc==SQLITE_OK && pApply->constraints.nBuf && !pApply->bNoUpdateLoop ){ |
| 238479 | SessionBuffer cons = {0, 0, 0}; |
| 238480 | sqlite3_changeset_iter *pUp = 0; |
| 238481 | sqlite3_stmt *pInsert = 0; |
| 238482 | int iSkip = 0; |
| 238483 | |
| 238484 | rc = sessionRetryIterInit( |
| 238485 | &pApply->constraints, bPatchset, zTab, pApply, &pUp |
| 238486 | ); |
| 238487 | if( rc==SQLITE_OK ){ |
| 238488 | int iThis = -1; |
| 238489 | while( SQLITE_ROW==sqlite3changeset_next(pUp) ){ |
| 238490 | if( pUp->op==SQLITE_UPDATE ) iThis++; |
| 238491 | if( iThis==iUpdate ) break; |
| 238492 | iSkip++; |
| 238493 | } |
| 238494 | if( iThis==iUpdate ){ |
| 238495 | rc = sqlite3_exec(db, "SAVEPOINT update_op", 0, 0, 0); |
| 238496 | if( rc==SQLITE_OK ){ |
| 238497 | rc = sessionUpdateToDeleteInsert(db, zTab, pApply, pUp, &pInsert); |
| 238498 | } |
| 238499 | } |
| 238500 | sqlite3changeset_finalize(pUp); |
| 238501 | if( iThis!=iUpdate ) break; |
| 238502 | } |
| 238503 | |
| 238504 | if( rc==SQLITE_OK ){ |
| 238505 | cons = pApply->constraints; |
| 238506 | |
| 238507 | while( rc==SQLITE_OK && pApply->constraints.nBuf>0 ){ |
| 238508 | SessionBuffer app = pApply->constraints; |
| 238509 | memset(&pApply->constraints, 0, sizeof(SessionBuffer)); |
| 238510 | rc = sessionApplyRetryBuffer( |
| 238511 | &app, iSkip, db, bPatchset, zTab, pApply, xConflict, pCtx |
| 238512 | ); |
| 238513 | if( app.aBuf!=cons.aBuf ){ |
| 238514 | sqlite3_free(app.aBuf); |
| 238515 | } |
| 238516 | if( pApply->constraints.nBuf>=app.nBuf ){ |
| 238517 | break; |
| 238518 | } |
| 238519 | iSkip = -1; |
| 238520 | } |
| 238521 | } |
| 238522 | |
| 238523 | iUpdate++; |
| 238524 | if( rc==SQLITE_OK ){ |
| 238525 | sqlite3_step(pInsert); |
| 238526 | rc = sqlite3_finalize(pInsert); |
| 238527 | if( rc==SQLITE_CONSTRAINT ){ |
| 238528 | rc = sqlite3_exec(db, "ROLLBACK TO update_op", 0, 0, 0); |
| 238529 | sqlite3_free(pApply->constraints.aBuf); |
| 238530 | pApply->constraints = cons; |
| 238531 | memset(&cons, 0, sizeof(cons)); |
| 238532 | }else if( rc==SQLITE_OK ){ |
| 238533 | iUpdate = 0; |
| 238534 | } |
| 238535 | if( rc==SQLITE_OK ){ |
| 238536 | rc = sqlite3_exec(db, "RELEASE update_op", 0, 0, 0); |
| 238537 | } |
| 238538 | }else{ |
| 238539 | sqlite3_finalize(pInsert); |
| 238540 | } |
| 238541 | |
| 238542 | sqlite3_free(cons.aBuf); |
| 238543 | } |
| 238544 | |
| 238545 | /* Step (3) */ |
| 238546 | if( rc==SQLITE_OK && pApply->constraints.nBuf ){ |
| 238547 | SessionBuffer cons = pApply->constraints; |
| 238548 | memset(&pApply->constraints, 0, sizeof(SessionBuffer)); |
| 238549 | pApply->bDeferConstraints = 0; |
| 238550 | rc = sessionApplyRetryBuffer( |
| 238551 | &cons, -1, db, bPatchset, zTab, pApply, xConflict, pCtx |
| 238552 | ); |
| 238553 | sqlite3_free(cons.aBuf); |
| 238554 | } |
| 238555 | |
| 238556 | return rc; |
| 238557 | } |
| 238558 | |
| @@ -237611,10 +238602,11 @@ | |
| 238602 | pIter->in.bNoDiscard = 1; |
| 238603 | memset(&sApply, 0, sizeof(sApply)); |
| 238604 | sApply.bRebase = (ppRebase && pnRebase); |
| 238605 | sApply.bInvertConstraints = !!(flags & SQLITE_CHANGESETAPPLY_INVERT); |
| 238606 | sApply.bIgnoreNoop = !!(flags & SQLITE_CHANGESETAPPLY_IGNORENOOP); |
| 238607 | sApply.bNoUpdateLoop = !!(flags & SQLITE_CHANGESETAPPLY_NOUPDATELOOP); |
| 238608 | if( (flags & SQLITE_CHANGESETAPPLY_NOSAVEPOINT)==0 ){ |
| 238609 | rc = sqlite3_exec(db, "SAVEPOINT changeset_apply", 0, 0, 0); |
| 238610 | } |
| 238611 | if( rc==SQLITE_OK ){ |
| 238612 | rc = sqlite3_exec(db, "PRAGMA defer_foreign_keys = 1", 0, 0, 0); |
| @@ -239422,11 +240414,11 @@ | |
| 240414 | int bNew, |
| 240415 | int iCol, |
| 240416 | const void *pVal, |
| 240417 | int nVal |
| 240418 | ){ |
| 240419 | sqlite3_int64 nByte = 1 + sessionVarintLen(nVal) + (i64)nVal; |
| 240420 | int rc = SQLITE_OK; |
| 240421 | SessionBuffer *pBuf = 0; |
| 240422 | |
| 240423 | if( SQLITE_OK!=(rc = checkChangeParams(pGrp, bNew, iCol, nByte, &pBuf)) ){ |
| 240424 | return rc; |
| @@ -239447,10 +240439,11 @@ | |
| 240439 | sqlite3_changegroup *pGrp, |
| 240440 | int bDiscard, |
| 240441 | char **pzErr |
| 240442 | ){ |
| 240443 | int rc = SQLITE_OK; |
| 240444 | char *zErr = 0; |
| 240445 | if( pGrp->cd.pTab ){ |
| 240446 | SessionBuffer *aBuf = pGrp->cd.aBuf; |
| 240447 | int ii; |
| 240448 | |
| 240449 | if( bDiscard==0 ){ |
| @@ -239458,26 +240451,26 @@ | |
| 240451 | u8 eUndef = SQLITE_NULL; |
| 240452 | if( pGrp->cd.eOp==SQLITE_UPDATE ){ |
| 240453 | for(ii=0; ii<nBuf; ii++){ |
| 240454 | if( pGrp->cd.pTab->abPK[ii] ){ |
| 240455 | if( aBuf[ii].nBuf<=1 ){ |
| 240456 | zErr = sqlite3_mprintf( |
| 240457 | "invalid change: %s value in PK of old.* record", |
| 240458 | aBuf[ii].nBuf==1 ? "null" : "undefined" |
| 240459 | ); |
| 240460 | rc = SQLITE_ERROR; |
| 240461 | break; |
| 240462 | }else if( aBuf[ii + nBuf].nBuf>0 ){ |
| 240463 | zErr = sqlite3_mprintf( |
| 240464 | "invalid change: defined value in PK of new.* record" |
| 240465 | ); |
| 240466 | rc = SQLITE_ERROR; |
| 240467 | break; |
| 240468 | } |
| 240469 | }else |
| 240470 | if( pGrp->bPatch==0 && (aBuf[ii].nBuf>0)!=(aBuf[ii+nBuf].nBuf>0) ){ |
| 240471 | zErr = sqlite3_mprintf( |
| 240472 | "invalid change: column %d " |
| 240473 | "- old.* value is %sdefined but new.* is %sdefined", |
| 240474 | ii, aBuf[ii].nBuf ? "" : "un", aBuf[ii+nBuf].nBuf ? "" : "un" |
| 240475 | ); |
| 240476 | rc = SQLITE_ERROR; |
| @@ -239490,18 +240483,18 @@ | |
| 240483 | for(ii=0; ii<nBuf; ii++){ |
| 240484 | int isPK = pGrp->cd.pTab->abPK[ii]; |
| 240485 | if( (pGrp->cd.eOp==SQLITE_INSERT || pGrp->bPatch==0 || isPK) |
| 240486 | && aBuf[ii].nBuf==0 |
| 240487 | ){ |
| 240488 | zErr = sqlite3_mprintf( |
| 240489 | "invalid change: column %d is undefined", ii |
| 240490 | ); |
| 240491 | rc = SQLITE_ERROR; |
| 240492 | break; |
| 240493 | } |
| 240494 | if( aBuf[ii].nBuf==1 && isPK ){ |
| 240495 | zErr = sqlite3_mprintf( |
| 240496 | "invalid change: null value in PK" |
| 240497 | ); |
| 240498 | rc = SQLITE_ERROR; |
| 240499 | break; |
| 240500 | } |
| @@ -239547,10 +240540,15 @@ | |
| 240540 | } |
| 240541 | } |
| 240542 | pGrp->cd.pTab = 0; |
| 240543 | } |
| 240544 | |
| 240545 | if( pzErr ){ |
| 240546 | *pzErr = zErr; |
| 240547 | }else{ |
| 240548 | sqlite3_free(zErr); |
| 240549 | } |
| 240550 | return rc; |
| 240551 | } |
| 240552 | |
| 240553 | #endif /* SQLITE_ENABLE_SESSION && SQLITE_ENABLE_PREUPDATE_HOOK */ |
| 240554 | |
| @@ -243272,11 +244270,11 @@ | |
| 244270 | ){ |
| 244271 | HighlightContext ctx; |
| 244272 | int rc = SQLITE_OK; /* Return code */ |
| 244273 | int iCol; /* 1st argument to snippet() */ |
| 244274 | const char *zEllips; /* 4th argument to snippet() */ |
| 244275 | i64 nToken; /* 5th argument to snippet() */ |
| 244276 | int nInst = 0; /* Number of instance matches this row */ |
| 244277 | int i; /* Used to iterate through instances */ |
| 244278 | int nPhrase; /* Number of phrases in query */ |
| 244279 | unsigned char *aSeen; /* Array of "seen instance" flags */ |
| 244280 | int iBestCol; /* Column containing best snippet */ |
| @@ -243297,11 +244295,11 @@ | |
| 244295 | iCol = sqlite3_value_int(apVal[0]); |
| 244296 | ctx.zOpen = fts5ValueToText(apVal[1]); |
| 244297 | ctx.zClose = fts5ValueToText(apVal[2]); |
| 244298 | ctx.iRangeEnd = -1; |
| 244299 | zEllips = fts5ValueToText(apVal[3]); |
| 244300 | nToken = (int)(MIN( MAX(sqlite3_value_int64(apVal[4]), 0), 64)); |
| 244301 | |
| 244302 | iBestCol = (iCol>=0 ? iCol : 0); |
| 244303 | nPhrase = pApi->xPhraseCount(pFts); |
| 244304 | aSeen = sqlite3_malloc64(nPhrase); |
| 244305 | if( aSeen==0 ){ |
| @@ -246013,11 +247011,11 @@ | |
| 247011 | /* Add an entry to each output position list */ |
| 247012 | for(i=0; i<pNear->nPhrase; i++){ |
| 247013 | i64 iPos = a[i].reader.iPos; |
| 247014 | Fts5PoslistWriter *pWriter = &a[i].writer; |
| 247015 | if( a[i].pOut->n==0 || iPos!=pWriter->iPrev ){ |
| 247016 | sqlite3Fts5PoslistSafeAppend(a[i].pOut, &pWriter->iPrev, iPos); |
| 247017 | } |
| 247018 | } |
| 247019 | |
| 247020 | iAdv = 0; |
| 247021 | iMin = a[0].reader.iLookahead; |
| @@ -246964,14 +247962,14 @@ | |
| 247962 | rc = SQLITE_NOMEM; |
| 247963 | }else{ |
| 247964 | memset(pSyn, 0, (size_t)nByte); |
| 247965 | pSyn->pTerm = ((char*)pSyn) + sizeof(Fts5ExprTerm) + sizeof(Fts5Buffer); |
| 247966 | pSyn->nFullTerm = pSyn->nQueryTerm = nToken; |
| 247967 | memcpy(pSyn->pTerm, pToken, nToken); |
| 247968 | if( pCtx->pConfig->bTokendata ){ |
| 247969 | pSyn->nQueryTerm = (int)strlen(pSyn->pTerm); |
| 247970 | } |
| 247971 | pSyn->pSynonym = pPhrase->aTerm[pPhrase->nTerm-1].pSynonym; |
| 247972 | pPhrase->aTerm[pPhrase->nTerm-1].pSynonym = pSyn; |
| 247973 | } |
| 247974 | }else{ |
| 247975 | Fts5ExprTerm *pTerm; |
| @@ -248816,11 +249814,11 @@ | |
| 249814 | ** + 1 byte for a "new column" byte, |
| 249815 | ** + 3 bytes for a new column number (16-bit max) as a varint, |
| 249816 | ** + 5 bytes for the new position offset (32-bit max). |
| 249817 | */ |
| 249818 | if( (p->nAlloc - p->nData) < (9 + 4 + 1 + 3 + 5) ){ |
| 249819 | sqlite3_int64 nNew = (i64)p->nAlloc * 2; |
| 249820 | Fts5HashEntry *pNew; |
| 249821 | Fts5HashEntry **pp; |
| 249822 | pNew = (Fts5HashEntry*)sqlite3_realloc64(p, nNew); |
| 249823 | if( pNew==0 ) return SQLITE_NOMEM; |
| 249824 | pNew->nAlloc = (int)nNew; |
| @@ -250006,11 +251004,11 @@ | |
| 251004 | } |
| 251005 | |
| 251006 | static Fts5Data *fts5LeafRead(Fts5Index *p, i64 iRowid){ |
| 251007 | Fts5Data *pRet = fts5DataRead(p, iRowid); |
| 251008 | if( pRet ){ |
| 251009 | if( pRet->szLeaf<4 || pRet->szLeaf>pRet->nn ){ |
| 251010 | FTS5_CORRUPT_ROWID(p, iRowid); |
| 251011 | fts5DataRelease(pRet); |
| 251012 | pRet = 0; |
| 251013 | } |
| 251014 | } |
| @@ -250250,11 +251248,11 @@ | |
| 251248 | }else{ |
| 251249 | i += fts5GetVarint32(&pData[i], pLvl->nMerge); |
| 251250 | i += fts5GetVarint32(&pData[i], nTotal); |
| 251251 | if( nTotal<pLvl->nMerge ) rc = FTS5_CORRUPT; |
| 251252 | pLvl->aSeg = (Fts5StructureSegment*)sqlite3Fts5MallocZero(&rc, |
| 251253 | (i64)nTotal * sizeof(Fts5StructureSegment) |
| 251254 | ); |
| 251255 | nSegment -= nTotal; |
| 251256 | } |
| 251257 | |
| 251258 | if( rc==SQLITE_OK ){ |
| @@ -250779,19 +251777,20 @@ | |
| 251777 | assert( pLvl->bEof==0 ); |
| 251778 | if( iOff<=pLvl->iFirstOff ){ |
| 251779 | pLvl->bEof = 1; |
| 251780 | }else{ |
| 251781 | u8 *a = pLvl->pData->p; |
| 251782 | int nn = pLvl->pData->nn; |
| 251783 | |
| 251784 | pLvl->iOff = 0; |
| 251785 | fts5DlidxLvlNext(pLvl); |
| 251786 | while( 1 ){ |
| 251787 | int nZero = 0; |
| 251788 | int ii = pLvl->iOff; |
| 251789 | u64 delta = 0; |
| 251790 | |
| 251791 | while( ii<nn && a[ii]==0 ){ |
| 251792 | nZero++; |
| 251793 | ii++; |
| 251794 | } |
| 251795 | ii += sqlite3Fts5GetVarint(&a[ii], &delta); |
| 251796 | |
| @@ -251206,11 +252205,11 @@ | |
| 252205 | fts5DataRelease(pIter->pLeaf); |
| 252206 | pIter->pLeaf = 0; |
| 252207 | while( p->rc==SQLITE_OK && pIter->iLeafPgno>pIter->iTermLeafPgno ){ |
| 252208 | Fts5Data *pNew; |
| 252209 | pIter->iLeafPgno--; |
| 252210 | pNew = fts5LeafRead(p, FTS5_SEGMENT_ROWID( |
| 252211 | pIter->pSeg->iSegid, pIter->iLeafPgno |
| 252212 | )); |
| 252213 | if( pNew ){ |
| 252214 | /* iTermLeafOffset may be equal to szLeaf if the term is the last |
| 252215 | ** thing on the page - i.e. the first rowid is on the following page. |
| @@ -251659,10 +252658,14 @@ | |
| 252658 | |
| 252659 | /* Figure out how many new bytes are in this term */ |
| 252660 | fts5FastGetVarint32(a, iOff, nNew); |
| 252661 | if( nKeep<nMatch ){ |
| 252662 | goto search_failed; |
| 252663 | } |
| 252664 | if( (iOff+nNew)>n ){ |
| 252665 | FTS5_CORRUPT_ITER(p, pIter); |
| 252666 | return; |
| 252667 | } |
| 252668 | |
| 252669 | assert( nKeep>=nMatch ); |
| 252670 | if( nKeep==nMatch ){ |
| 252671 | u32 nCmp; |
| @@ -252636,12 +253639,11 @@ | |
| 253639 | } |
| 253640 | } |
| 253641 | |
| 253642 | do { |
| 253643 | while( i<nChunk && pChunk[i]!=0x01 ){ |
| 253644 | fts5IndexSkipVarint(pChunk, i); |
| 253645 | } |
| 253646 | if( pCtx->eState ){ |
| 253647 | fts5BufferSafeAppendBlob(pCtx->pBuf, &pChunk[iStart], i-iStart); |
| 253648 | } |
| 253649 | if( i<nChunk ){ |
| @@ -252786,11 +253788,11 @@ | |
| 253788 | } |
| 253789 | |
| 253790 | /* Advance pointer p until it points to pEnd or an 0x01 byte that is |
| 253791 | ** not part of a varint */ |
| 253792 | while( p<pEnd && *p!=0x01 ){ |
| 253793 | while( p<pEnd && (*p++ & 0x80) ); |
| 253794 | } |
| 253795 | |
| 253796 | if( pColset->aiCol[i]==iCurrent ){ |
| 253797 | if( pColset->nCol==1 ){ |
| 253798 | pIter->base.pData = aCopy; |
| @@ -252883,12 +253885,15 @@ | |
| 253885 | */ |
| 253886 | static void fts5IterSetOutputs_Col100(Fts5Iter *pIter, Fts5SegIter *pSeg){ |
| 253887 | |
| 253888 | assert( pIter->pIndex->pConfig->eDetail==FTS5_DETAIL_COLUMNS ); |
| 253889 | assert( pIter->pColset ); |
| 253890 | assert( pIter->poslist.nSpace>=pIter->pIndex->pConfig->nCol ); |
| 253891 | |
| 253892 | if( pSeg->iLeafOffset+pSeg->nPos>pSeg->pLeaf->szLeaf |
| 253893 | || pSeg->nPos>pIter->pIndex->pConfig->nCol |
| 253894 | ){ |
| 253895 | fts5IterSetOutputs_Col(pIter, pSeg); |
| 253896 | }else{ |
| 253897 | u8 *a = (u8*)&pSeg->pLeaf->p[pSeg->iLeafOffset]; |
| 253898 | u8 *pEnd = (u8*)&a[pSeg->nPos]; |
| 253899 | int iPrev = 0; |
| @@ -254377,10 +255382,15 @@ | |
| 255382 | int iSOP; /* Start-Of-Position-list */ |
| 255383 | if( pSeg->iLeafPgno==pSeg->iTermLeafPgno ){ |
| 255384 | iStart = pSeg->iTermLeafOffset; |
| 255385 | }else{ |
| 255386 | iStart = fts5GetU16(&aPg[0]); |
| 255387 | } |
| 255388 | if( iStart>nPg ){ |
| 255389 | FTS5_CORRUPT_IDX(p); |
| 255390 | sqlite3_free(aIdx); |
| 255391 | return; |
| 255392 | } |
| 255393 | |
| 255394 | iSOP = iStart + fts5GetVarint(&aPg[iStart], &iDelta); |
| 255395 | assert_nc( iSOP<=pSeg->iLeafOffset ); |
| 255396 | |
| @@ -257063,12 +258073,12 @@ | |
| 258073 | int *pnOut, /* OUT: Number of output pages */ |
| 258074 | Fts5Data ***papOut /* OUT: Output hash pages */ |
| 258075 | ){ |
| 258076 | const int MINSLOT = 32; |
| 258077 | int nSlotPerPage = MAX(MINSLOT, (p->pConfig->pgsz - 8) / szKey); |
| 258078 | i64 nSlot = 0; /* Number of slots in each output page */ |
| 258079 | i64 nOut = 0; |
| 258080 | |
| 258081 | /* Figure out how many output pages (nOut) and how many slots per |
| 258082 | ** page (nSlot). There are three possibilities: |
| 258083 | ** |
| 258084 | ** 1. The hash table does not yet exist. In this case the new hash |
| @@ -257089,27 +258099,30 @@ | |
| 258099 | /* Case 1. */ |
| 258100 | nOut = 1; |
| 258101 | nSlot = MINSLOT; |
| 258102 | }else if( pSeg->nPgTombstone==1 ){ |
| 258103 | /* Case 2. */ |
| 258104 | u32 nElem = fts5GetU32(&pData1->p[4]); |
| 258105 | assert( pData1 && iPg1==0 ); |
| 258106 | if( nElem>((u32)nSlotPerPage/4) ){ |
| 258107 | nOut = 0; |
| 258108 | }else{ |
| 258109 | nOut = 1; |
| 258110 | nSlot = MAX((i64)nElem*4, MINSLOT); |
| 258111 | } |
| 258112 | } |
| 258113 | if( nOut==0 ){ |
| 258114 | /* Case 3. */ |
| 258115 | nOut = ((i64)pSeg->nPgTombstone * 2 + 1); |
| 258116 | nSlot = nSlotPerPage; |
| 258117 | } |
| 258118 | |
| 258119 | /* Allocate the required array and output pages */ |
| 258120 | while( 1 ){ |
| 258121 | int res = 0; |
| 258122 | i64 ii = 0; |
| 258123 | i64 szPage = 0; |
| 258124 | Fts5Data **apOut = 0; |
| 258125 | |
| 258126 | /* Allocate space for the new hash table */ |
| 258127 | assert( nSlot>=MINSLOT ); |
| 258128 | apOut = (Fts5Data**)sqlite3Fts5MallocZero(&p->rc, sizeof(Fts5Data*) * nOut); |
| @@ -257643,11 +258656,11 @@ | |
| 258656 | ){ |
| 258657 | |
| 258658 | /* Check any rowid-less pages that occur before the current leaf. */ |
| 258659 | for(iPg=iPrevLeaf+1; iPg<fts5DlidxIterPgno(pDlidx); iPg++){ |
| 258660 | iKey = FTS5_SEGMENT_ROWID(iSegid, iPg); |
| 258661 | pLeaf = fts5LeafRead(p, iKey); |
| 258662 | if( pLeaf ){ |
| 258663 | if( fts5LeafFirstRowidOff(pLeaf)!=0 ) FTS5_CORRUPT_ROWID(p, iKey); |
| 258664 | fts5DataRelease(pLeaf); |
| 258665 | } |
| 258666 | } |
| @@ -257654,11 +258667,11 @@ | |
| 258667 | iPrevLeaf = fts5DlidxIterPgno(pDlidx); |
| 258668 | |
| 258669 | /* Check that the leaf page indicated by the iterator really does |
| 258670 | ** contain the rowid suggested by the same. */ |
| 258671 | iKey = FTS5_SEGMENT_ROWID(iSegid, iPrevLeaf); |
| 258672 | pLeaf = fts5LeafRead(p, iKey); |
| 258673 | if( pLeaf ){ |
| 258674 | i64 iRowid; |
| 258675 | int iRowidOff = fts5LeafFirstRowidOff(pLeaf); |
| 258676 | ASSERT_SZLEAF_OK(pLeaf); |
| 258677 | if( iRowidOff>=pLeaf->szLeaf ){ |
| @@ -262254,11 +263267,11 @@ | |
| 263267 | int nArg, /* Number of args */ |
| 263268 | sqlite3_value **apUnused /* Function arguments */ |
| 263269 | ){ |
| 263270 | assert( nArg==0 ); |
| 263271 | UNUSED_PARAM2(nArg, apUnused); |
| 263272 | sqlite3_result_text(pCtx, "fts5: 2026-06-16 13:43:08 3f3fb9b638f59ad982beafb7c117f24ddd3da612e62c862510805fa672ffae06", -1, SQLITE_TRANSIENT); |
| 263273 | } |
| 263274 | |
| 263275 | /* |
| 263276 | ** Implementation of fts5_locale(LOCALE, TEXT) function. |
| 263277 | ** |
| @@ -264648,12 +265661,18 @@ | |
| 265661 | PorterTokenizer *pRet; |
| 265662 | void *pUserdata = 0; |
| 265663 | const char *zBase = "unicode61"; |
| 265664 | fts5_tokenizer_v2 *pV2 = 0; |
| 265665 | |
| 265666 | while( nArg>0 ){ |
| 265667 | if( sqlite3_stricmp(azArg[0],"porter")==0 ){ |
| 265668 | nArg--; |
| 265669 | azArg++; |
| 265670 | }else{ |
| 265671 | zBase = azArg[0]; |
| 265672 | break; |
| 265673 | } |
| 265674 | } |
| 265675 | |
| 265676 | pRet = (PorterTokenizer*)sqlite3_malloc64(sizeof(PorterTokenizer)); |
| 265677 | if( pRet ){ |
| 265678 | memset(pRet, 0, sizeof(PorterTokenizer)); |
| 265679 |
+32
-8
| --- extsrc/sqlite3.h | ||
| +++ extsrc/sqlite3.h | ||
| @@ -146,14 +146,14 @@ | ||
| 146 | 146 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 147 | 147 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 148 | 148 | */ |
| 149 | 149 | #define SQLITE_VERSION "3.54.0" |
| 150 | 150 | #define SQLITE_VERSION_NUMBER 3054000 |
| 151 | -#define SQLITE_SOURCE_ID "2026-05-04 10:14:13 7e4134e3ff1ca8712f5fc78fadae665549450988dc43af27c7fe0c77f10ce3fb" | |
| 151 | +#define SQLITE_SOURCE_ID "2026-06-16 13:43:08 3f3fb9b638f59ad982beafb7c117f24ddd3da612e62c862510805fa672ffae06" | |
| 152 | 152 | #define SQLITE_SCM_BRANCH "trunk" |
| 153 | 153 | #define SQLITE_SCM_TAGS "" |
| 154 | -#define SQLITE_SCM_DATETIME "2026-05-04T10:14:13.819Z" | |
| 154 | +#define SQLITE_SCM_DATETIME "2026-06-16T13:43:08.110Z" | |
| 155 | 155 | |
| 156 | 156 | /* |
| 157 | 157 | ** CAPI3REF: Run-Time Library Version Numbers |
| 158 | 158 | ** KEYWORDS: sqlite3_version sqlite3_sourceid |
| 159 | 159 | ** |
| @@ -4052,12 +4052,11 @@ | ||
| 4052 | 4052 | ** parameter on F or if the value of P does not match any of the |
| 4053 | 4053 | ** above, then sqlite3_uri_boolean(F,P,B) returns (B!=0). |
| 4054 | 4054 | ** |
| 4055 | 4055 | ** The sqlite3_uri_int64(F,P,D) routine converts the value of P into a |
| 4056 | 4056 | ** 64-bit signed integer and returns that integer, or D if P does not |
| 4057 | -** exist. If the value of P is something other than an integer, then | |
| 4058 | -** zero is returned. | |
| 4057 | +** exist or ff the value of P is something other than an integer. | |
| 4059 | 4058 | ** |
| 4060 | 4059 | ** The sqlite3_uri_key(F,N) returns a pointer to the name (not |
| 4061 | 4060 | ** the value) of the N-th query parameter for filename F, or a NULL |
| 4062 | 4061 | ** pointer if N is less than zero or greater than the number of query |
| 4063 | 4062 | ** parameters minus 1. The N value is zero-based so N should be 0 to obtain |
| @@ -4376,11 +4375,12 @@ | ||
| 4376 | 4375 | ** <dd>The maximum number of columns in a table definition or in the |
| 4377 | 4376 | ** result set of a [SELECT] or the maximum number of columns in an index |
| 4378 | 4377 | ** or in an ORDER BY or GROUP BY clause.</dd>)^ |
| 4379 | 4378 | ** |
| 4380 | 4379 | ** [[SQLITE_LIMIT_EXPR_DEPTH]] ^(<dt>SQLITE_LIMIT_EXPR_DEPTH</dt> |
| 4381 | -** <dd>The maximum depth of the parse tree on any expression.</dd>)^ | |
| 4380 | +** <dd>The maximum depth of the parse tree on any expression and | |
| 4381 | +** the maximum nesting depth for subqueries and VIEWs</dd>)^ | |
| 4382 | 4382 | ** |
| 4383 | 4383 | ** [[SQLITE_LIMIT_PARSER_DEPTH]] ^(<dt>SQLITE_LIMIT_PARSER_DEPTH</dt> |
| 4384 | 4384 | ** <dd>The maximum depth of the LALR(1) parser stack used to analyze |
| 4385 | 4385 | ** input SQL statements.</dd>)^ |
| 4386 | 4386 | ** |
| @@ -4407,11 +4407,12 @@ | ||
| 4407 | 4407 | ** [[SQLITE_LIMIT_VARIABLE_NUMBER]] |
| 4408 | 4408 | ** ^(<dt>SQLITE_LIMIT_VARIABLE_NUMBER</dt> |
| 4409 | 4409 | ** <dd>The maximum index number of any [parameter] in an SQL statement.)^ |
| 4410 | 4410 | ** |
| 4411 | 4411 | ** [[SQLITE_LIMIT_TRIGGER_DEPTH]] ^(<dt>SQLITE_LIMIT_TRIGGER_DEPTH</dt> |
| 4412 | -** <dd>The maximum depth of recursion for triggers.</dd>)^ | |
| 4412 | +** <dd>The maximum depth of recursion for triggers, and the maximum | |
| 4413 | +** nesting depth for separate triggers.</dd>)^ | |
| 4413 | 4414 | ** |
| 4414 | 4415 | ** [[SQLITE_LIMIT_WORKER_THREADS]] ^(<dt>SQLITE_LIMIT_WORKER_THREADS</dt> |
| 4415 | 4416 | ** <dd>The maximum number of auxiliary worker threads that a single |
| 4416 | 4417 | ** [prepared statement] may start.</dd>)^ |
| 4417 | 4418 | ** </dl> |
| @@ -11213,12 +11214,23 @@ | ||
| 11213 | 11214 | ** reopen S as an in-memory database based on the serialization |
| 11214 | 11215 | ** contained in P. If S is a NULL pointer, the main database is |
| 11215 | 11216 | ** used. The serialized database P is N bytes in size. M is the size |
| 11216 | 11217 | ** of the buffer P, which might be larger than N. If M is larger than |
| 11217 | 11218 | ** N, and the SQLITE_DESERIALIZE_READONLY bit is not set in F, then |
| 11218 | -** SQLite is permitted to add content to the in-memory database as | |
| 11219 | -** long as the total size does not exceed M bytes. | |
| 11219 | +** SQLite is permitted to add content to the in-memory database, in | |
| 11220 | +** page-sized chunks, as long as the total size does not exceed M bytes. | |
| 11221 | +** | |
| 11222 | +** The parameter M must be greater than or equal to N. Ideally, M | |
| 11223 | +** should have a value which is N+(512×K)+20 where K determines how | |
| 11224 | +** must extra space is available to hold new content as the database | |
| 11225 | +** grows. K can be 0 if the database is read-only. | |
| 11226 | +** | |
| 11227 | +** If the database content in P is malformed in a malicious way then | |
| 11228 | +** it is possible that SQLite might try to read a few more than N bytes | |
| 11229 | +** from P. If the veracity of the database content P is uncertain, | |
| 11230 | +** then applications are advised to allocate about 20 extra bytes on | |
| 11231 | +** the end of the P buffer to avoid a memory error. | |
| 11220 | 11232 | ** |
| 11221 | 11233 | ** If the SQLITE_DESERIALIZE_FREEONCLOSE bit is set in F, then SQLite will |
| 11222 | 11234 | ** invoke sqlite3_free() on the serialization buffer when the database |
| 11223 | 11235 | ** connection closes. If the SQLITE_DESERIALIZE_RESIZEABLE bit is set, then |
| 11224 | 11236 | ** SQLite will try to increase the buffer size using sqlite3_realloc64() |
| @@ -12863,15 +12875,27 @@ | ||
| 12863 | 12875 | ** <dt>SQLITE_CHANGESETAPPLY_FKNOACTION <dd> |
| 12864 | 12876 | ** If this flag it set, then all foreign key constraints in the target |
| 12865 | 12877 | ** database behave as if they were declared with "ON UPDATE NO ACTION ON |
| 12866 | 12878 | ** DELETE NO ACTION", even if they are actually CASCADE, RESTRICT, SET NULL |
| 12867 | 12879 | ** or SET DEFAULT. |
| 12880 | +** | |
| 12881 | +** <dt>SQLITE_CHANGESETAPPLY_NOUPDATELOOP <dd> | |
| 12882 | +** Sometimes, a changeset contains two or more update statements such that | |
| 12883 | +** although after applying all updates the database will contain no | |
| 12884 | +** constraint violations, no single update can be applied before the others. | |
| 12885 | +** The simplest example of this is a pair of UPDATEs that have "swapped" | |
| 12886 | +** two column values with a UNIQUE constraint. | |
| 12887 | +** <p> | |
| 12888 | +** Usually, sqlite3changeset_apply() and similar functions work hard to try | |
| 12889 | +** to find a way to apply such a changeset. However, if this flag is set, | |
| 12890 | +** then all such updates are considered CONSTRAINT conflicts. | |
| 12868 | 12891 | */ |
| 12869 | 12892 | #define SQLITE_CHANGESETAPPLY_NOSAVEPOINT 0x0001 |
| 12870 | 12893 | #define SQLITE_CHANGESETAPPLY_INVERT 0x0002 |
| 12871 | 12894 | #define SQLITE_CHANGESETAPPLY_IGNORENOOP 0x0004 |
| 12872 | 12895 | #define SQLITE_CHANGESETAPPLY_FKNOACTION 0x0008 |
| 12896 | +#define SQLITE_CHANGESETAPPLY_NOUPDATELOOP 0x0010 | |
| 12873 | 12897 | |
| 12874 | 12898 | /* |
| 12875 | 12899 | ** CAPI3REF: Constants Passed To The Conflict Handler |
| 12876 | 12900 | ** |
| 12877 | 12901 | ** Values that may be passed as the second argument to a conflict-handler. |
| 12878 | 12902 |
| --- extsrc/sqlite3.h | |
| +++ extsrc/sqlite3.h | |
| @@ -146,14 +146,14 @@ | |
| 146 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 147 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 148 | */ |
| 149 | #define SQLITE_VERSION "3.54.0" |
| 150 | #define SQLITE_VERSION_NUMBER 3054000 |
| 151 | #define SQLITE_SOURCE_ID "2026-05-04 10:14:13 7e4134e3ff1ca8712f5fc78fadae665549450988dc43af27c7fe0c77f10ce3fb" |
| 152 | #define SQLITE_SCM_BRANCH "trunk" |
| 153 | #define SQLITE_SCM_TAGS "" |
| 154 | #define SQLITE_SCM_DATETIME "2026-05-04T10:14:13.819Z" |
| 155 | |
| 156 | /* |
| 157 | ** CAPI3REF: Run-Time Library Version Numbers |
| 158 | ** KEYWORDS: sqlite3_version sqlite3_sourceid |
| 159 | ** |
| @@ -4052,12 +4052,11 @@ | |
| 4052 | ** parameter on F or if the value of P does not match any of the |
| 4053 | ** above, then sqlite3_uri_boolean(F,P,B) returns (B!=0). |
| 4054 | ** |
| 4055 | ** The sqlite3_uri_int64(F,P,D) routine converts the value of P into a |
| 4056 | ** 64-bit signed integer and returns that integer, or D if P does not |
| 4057 | ** exist. If the value of P is something other than an integer, then |
| 4058 | ** zero is returned. |
| 4059 | ** |
| 4060 | ** The sqlite3_uri_key(F,N) returns a pointer to the name (not |
| 4061 | ** the value) of the N-th query parameter for filename F, or a NULL |
| 4062 | ** pointer if N is less than zero or greater than the number of query |
| 4063 | ** parameters minus 1. The N value is zero-based so N should be 0 to obtain |
| @@ -4376,11 +4375,12 @@ | |
| 4376 | ** <dd>The maximum number of columns in a table definition or in the |
| 4377 | ** result set of a [SELECT] or the maximum number of columns in an index |
| 4378 | ** or in an ORDER BY or GROUP BY clause.</dd>)^ |
| 4379 | ** |
| 4380 | ** [[SQLITE_LIMIT_EXPR_DEPTH]] ^(<dt>SQLITE_LIMIT_EXPR_DEPTH</dt> |
| 4381 | ** <dd>The maximum depth of the parse tree on any expression.</dd>)^ |
| 4382 | ** |
| 4383 | ** [[SQLITE_LIMIT_PARSER_DEPTH]] ^(<dt>SQLITE_LIMIT_PARSER_DEPTH</dt> |
| 4384 | ** <dd>The maximum depth of the LALR(1) parser stack used to analyze |
| 4385 | ** input SQL statements.</dd>)^ |
| 4386 | ** |
| @@ -4407,11 +4407,12 @@ | |
| 4407 | ** [[SQLITE_LIMIT_VARIABLE_NUMBER]] |
| 4408 | ** ^(<dt>SQLITE_LIMIT_VARIABLE_NUMBER</dt> |
| 4409 | ** <dd>The maximum index number of any [parameter] in an SQL statement.)^ |
| 4410 | ** |
| 4411 | ** [[SQLITE_LIMIT_TRIGGER_DEPTH]] ^(<dt>SQLITE_LIMIT_TRIGGER_DEPTH</dt> |
| 4412 | ** <dd>The maximum depth of recursion for triggers.</dd>)^ |
| 4413 | ** |
| 4414 | ** [[SQLITE_LIMIT_WORKER_THREADS]] ^(<dt>SQLITE_LIMIT_WORKER_THREADS</dt> |
| 4415 | ** <dd>The maximum number of auxiliary worker threads that a single |
| 4416 | ** [prepared statement] may start.</dd>)^ |
| 4417 | ** </dl> |
| @@ -11213,12 +11214,23 @@ | |
| 11213 | ** reopen S as an in-memory database based on the serialization |
| 11214 | ** contained in P. If S is a NULL pointer, the main database is |
| 11215 | ** used. The serialized database P is N bytes in size. M is the size |
| 11216 | ** of the buffer P, which might be larger than N. If M is larger than |
| 11217 | ** N, and the SQLITE_DESERIALIZE_READONLY bit is not set in F, then |
| 11218 | ** SQLite is permitted to add content to the in-memory database as |
| 11219 | ** long as the total size does not exceed M bytes. |
| 11220 | ** |
| 11221 | ** If the SQLITE_DESERIALIZE_FREEONCLOSE bit is set in F, then SQLite will |
| 11222 | ** invoke sqlite3_free() on the serialization buffer when the database |
| 11223 | ** connection closes. If the SQLITE_DESERIALIZE_RESIZEABLE bit is set, then |
| 11224 | ** SQLite will try to increase the buffer size using sqlite3_realloc64() |
| @@ -12863,15 +12875,27 @@ | |
| 12863 | ** <dt>SQLITE_CHANGESETAPPLY_FKNOACTION <dd> |
| 12864 | ** If this flag it set, then all foreign key constraints in the target |
| 12865 | ** database behave as if they were declared with "ON UPDATE NO ACTION ON |
| 12866 | ** DELETE NO ACTION", even if they are actually CASCADE, RESTRICT, SET NULL |
| 12867 | ** or SET DEFAULT. |
| 12868 | */ |
| 12869 | #define SQLITE_CHANGESETAPPLY_NOSAVEPOINT 0x0001 |
| 12870 | #define SQLITE_CHANGESETAPPLY_INVERT 0x0002 |
| 12871 | #define SQLITE_CHANGESETAPPLY_IGNORENOOP 0x0004 |
| 12872 | #define SQLITE_CHANGESETAPPLY_FKNOACTION 0x0008 |
| 12873 | |
| 12874 | /* |
| 12875 | ** CAPI3REF: Constants Passed To The Conflict Handler |
| 12876 | ** |
| 12877 | ** Values that may be passed as the second argument to a conflict-handler. |
| 12878 |
| --- extsrc/sqlite3.h | |
| +++ extsrc/sqlite3.h | |
| @@ -146,14 +146,14 @@ | |
| 146 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 147 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 148 | */ |
| 149 | #define SQLITE_VERSION "3.54.0" |
| 150 | #define SQLITE_VERSION_NUMBER 3054000 |
| 151 | #define SQLITE_SOURCE_ID "2026-06-16 13:43:08 3f3fb9b638f59ad982beafb7c117f24ddd3da612e62c862510805fa672ffae06" |
| 152 | #define SQLITE_SCM_BRANCH "trunk" |
| 153 | #define SQLITE_SCM_TAGS "" |
| 154 | #define SQLITE_SCM_DATETIME "2026-06-16T13:43:08.110Z" |
| 155 | |
| 156 | /* |
| 157 | ** CAPI3REF: Run-Time Library Version Numbers |
| 158 | ** KEYWORDS: sqlite3_version sqlite3_sourceid |
| 159 | ** |
| @@ -4052,12 +4052,11 @@ | |
| 4052 | ** parameter on F or if the value of P does not match any of the |
| 4053 | ** above, then sqlite3_uri_boolean(F,P,B) returns (B!=0). |
| 4054 | ** |
| 4055 | ** The sqlite3_uri_int64(F,P,D) routine converts the value of P into a |
| 4056 | ** 64-bit signed integer and returns that integer, or D if P does not |
| 4057 | ** exist or ff the value of P is something other than an integer. |
| 4058 | ** |
| 4059 | ** The sqlite3_uri_key(F,N) returns a pointer to the name (not |
| 4060 | ** the value) of the N-th query parameter for filename F, or a NULL |
| 4061 | ** pointer if N is less than zero or greater than the number of query |
| 4062 | ** parameters minus 1. The N value is zero-based so N should be 0 to obtain |
| @@ -4376,11 +4375,12 @@ | |
| 4375 | ** <dd>The maximum number of columns in a table definition or in the |
| 4376 | ** result set of a [SELECT] or the maximum number of columns in an index |
| 4377 | ** or in an ORDER BY or GROUP BY clause.</dd>)^ |
| 4378 | ** |
| 4379 | ** [[SQLITE_LIMIT_EXPR_DEPTH]] ^(<dt>SQLITE_LIMIT_EXPR_DEPTH</dt> |
| 4380 | ** <dd>The maximum depth of the parse tree on any expression and |
| 4381 | ** the maximum nesting depth for subqueries and VIEWs</dd>)^ |
| 4382 | ** |
| 4383 | ** [[SQLITE_LIMIT_PARSER_DEPTH]] ^(<dt>SQLITE_LIMIT_PARSER_DEPTH</dt> |
| 4384 | ** <dd>The maximum depth of the LALR(1) parser stack used to analyze |
| 4385 | ** input SQL statements.</dd>)^ |
| 4386 | ** |
| @@ -4407,11 +4407,12 @@ | |
| 4407 | ** [[SQLITE_LIMIT_VARIABLE_NUMBER]] |
| 4408 | ** ^(<dt>SQLITE_LIMIT_VARIABLE_NUMBER</dt> |
| 4409 | ** <dd>The maximum index number of any [parameter] in an SQL statement.)^ |
| 4410 | ** |
| 4411 | ** [[SQLITE_LIMIT_TRIGGER_DEPTH]] ^(<dt>SQLITE_LIMIT_TRIGGER_DEPTH</dt> |
| 4412 | ** <dd>The maximum depth of recursion for triggers, and the maximum |
| 4413 | ** nesting depth for separate triggers.</dd>)^ |
| 4414 | ** |
| 4415 | ** [[SQLITE_LIMIT_WORKER_THREADS]] ^(<dt>SQLITE_LIMIT_WORKER_THREADS</dt> |
| 4416 | ** <dd>The maximum number of auxiliary worker threads that a single |
| 4417 | ** [prepared statement] may start.</dd>)^ |
| 4418 | ** </dl> |
| @@ -11213,12 +11214,23 @@ | |
| 11214 | ** reopen S as an in-memory database based on the serialization |
| 11215 | ** contained in P. If S is a NULL pointer, the main database is |
| 11216 | ** used. The serialized database P is N bytes in size. M is the size |
| 11217 | ** of the buffer P, which might be larger than N. If M is larger than |
| 11218 | ** N, and the SQLITE_DESERIALIZE_READONLY bit is not set in F, then |
| 11219 | ** SQLite is permitted to add content to the in-memory database, in |
| 11220 | ** page-sized chunks, as long as the total size does not exceed M bytes. |
| 11221 | ** |
| 11222 | ** The parameter M must be greater than or equal to N. Ideally, M |
| 11223 | ** should have a value which is N+(512×K)+20 where K determines how |
| 11224 | ** must extra space is available to hold new content as the database |
| 11225 | ** grows. K can be 0 if the database is read-only. |
| 11226 | ** |
| 11227 | ** If the database content in P is malformed in a malicious way then |
| 11228 | ** it is possible that SQLite might try to read a few more than N bytes |
| 11229 | ** from P. If the veracity of the database content P is uncertain, |
| 11230 | ** then applications are advised to allocate about 20 extra bytes on |
| 11231 | ** the end of the P buffer to avoid a memory error. |
| 11232 | ** |
| 11233 | ** If the SQLITE_DESERIALIZE_FREEONCLOSE bit is set in F, then SQLite will |
| 11234 | ** invoke sqlite3_free() on the serialization buffer when the database |
| 11235 | ** connection closes. If the SQLITE_DESERIALIZE_RESIZEABLE bit is set, then |
| 11236 | ** SQLite will try to increase the buffer size using sqlite3_realloc64() |
| @@ -12863,15 +12875,27 @@ | |
| 12875 | ** <dt>SQLITE_CHANGESETAPPLY_FKNOACTION <dd> |
| 12876 | ** If this flag it set, then all foreign key constraints in the target |
| 12877 | ** database behave as if they were declared with "ON UPDATE NO ACTION ON |
| 12878 | ** DELETE NO ACTION", even if they are actually CASCADE, RESTRICT, SET NULL |
| 12879 | ** or SET DEFAULT. |
| 12880 | ** |
| 12881 | ** <dt>SQLITE_CHANGESETAPPLY_NOUPDATELOOP <dd> |
| 12882 | ** Sometimes, a changeset contains two or more update statements such that |
| 12883 | ** although after applying all updates the database will contain no |
| 12884 | ** constraint violations, no single update can be applied before the others. |
| 12885 | ** The simplest example of this is a pair of UPDATEs that have "swapped" |
| 12886 | ** two column values with a UNIQUE constraint. |
| 12887 | ** <p> |
| 12888 | ** Usually, sqlite3changeset_apply() and similar functions work hard to try |
| 12889 | ** to find a way to apply such a changeset. However, if this flag is set, |
| 12890 | ** then all such updates are considered CONSTRAINT conflicts. |
| 12891 | */ |
| 12892 | #define SQLITE_CHANGESETAPPLY_NOSAVEPOINT 0x0001 |
| 12893 | #define SQLITE_CHANGESETAPPLY_INVERT 0x0002 |
| 12894 | #define SQLITE_CHANGESETAPPLY_IGNORENOOP 0x0004 |
| 12895 | #define SQLITE_CHANGESETAPPLY_FKNOACTION 0x0008 |
| 12896 | #define SQLITE_CHANGESETAPPLY_NOUPDATELOOP 0x0010 |
| 12897 | |
| 12898 | /* |
| 12899 | ** CAPI3REF: Constants Passed To The Conflict Handler |
| 12900 | ** |
| 12901 | ** Values that may be passed as the second argument to a conflict-handler. |
| 12902 |
+17
-41
| --- skins/ardoise/css.txt | ||
| +++ skins/ardoise/css.txt | ||
| @@ -154,24 +154,19 @@ | ||
| 154 | 154 | button, |
| 155 | 155 | select { |
| 156 | 156 | text-transform: none |
| 157 | 157 | } |
| 158 | 158 | button, |
| 159 | -html input[type=button], | |
| 159 | +input[type=button], | |
| 160 | 160 | input[type=reset], |
| 161 | -input[type=submit] { | |
| 161 | +input[type=submit]{ | |
| 162 | 162 | cursor: pointer |
| 163 | 163 | } |
| 164 | -button[disabled], | |
| 165 | -html input[disabled] { | |
| 164 | +button:disabled, | |
| 165 | +input:disabled { | |
| 166 | 166 | cursor: default |
| 167 | 167 | } |
| 168 | -button::-moz-focus-inner, | |
| 169 | -input::-moz-focus-inner { | |
| 170 | - border: 0; | |
| 171 | - padding: 0 | |
| 172 | -} | |
| 173 | 168 | input { |
| 174 | 169 | line-height: normal |
| 175 | 170 | } |
| 176 | 171 | input[type=checkbox], |
| 177 | 172 | input[type=radio] { |
| @@ -307,11 +302,11 @@ | ||
| 307 | 302 | text-decoration: none; |
| 308 | 303 | text-align: center; |
| 309 | 304 | white-space: nowrap; |
| 310 | 305 | cursor: pointer |
| 311 | 306 | } |
| 312 | -input[type=submit]:disabled { | |
| 307 | +input:disabled { | |
| 313 | 308 | color: rgb(70,70,70); |
| 314 | 309 | background-color: rgb(153,153,153); |
| 315 | 310 | } |
| 316 | 311 | |
| 317 | 312 | @media (min-width:550px) { |
| @@ -416,30 +411,20 @@ | ||
| 416 | 411 | .offset-by-eleven.columns { |
| 417 | 412 | margin-left: 95.33333% |
| 418 | 413 | } |
| 419 | 414 | } |
| 420 | 415 | .button, |
| 421 | -button { | |
| 422 | - color: #aaa; | |
| 423 | - background-color: #444; | |
| 424 | - border-radius: 5px; | |
| 425 | - border: 0 | |
| 426 | -} | |
| 416 | +button, | |
| 427 | 417 | input[type=button], |
| 428 | 418 | input[type=reset], |
| 429 | 419 | input[type=submit] { |
| 430 | 420 | color: #ddd; |
| 431 | 421 | background-color: #446979; |
| 432 | 422 | border: 0; |
| 433 | 423 | border-radius: 5px |
| 434 | 424 | } |
| 435 | -.button:hover, | |
| 436 | -button:hover { | |
| 437 | - color: #444; | |
| 438 | - background-color: #aaa; | |
| 439 | - outline: 0 | |
| 440 | -} | |
| 425 | +button:hover, | |
| 441 | 426 | input[type=button]:hover, |
| 442 | 427 | input[type=reset]:hover, |
| 443 | 428 | input[type=submit]:hover { |
| 444 | 429 | color: #446979; |
| 445 | 430 | background-color: #ddd; |
| @@ -452,29 +437,20 @@ | ||
| 452 | 437 | input[type=submit]:focus { |
| 453 | 438 | color: #333; |
| 454 | 439 | border-color: #888; |
| 455 | 440 | outline: 0 |
| 456 | 441 | } |
| 457 | -.button.button-primary, | |
| 458 | -.button.button-primary:focus, | |
| 459 | -.button.button-primary:hover, | |
| 460 | -button.button-primary, | |
| 461 | -button.button-primary:focus, | |
| 462 | -button.button-primary:hover, | |
| 463 | -input[type=button].button-primary, | |
| 464 | -input[type=button].button-primary:focus, | |
| 465 | -input[type=button].button-primary:hover, | |
| 466 | -input[type=reset].button-primary, | |
| 467 | -input[type=reset].button-primary:focus, | |
| 468 | -input[type=reset].button-primary:hover, | |
| 469 | -input[type=submit].button-primary, | |
| 470 | -input[type=submit].button-primary:focus, | |
| 471 | -input[type=submit].button-primary:hover { | |
| 472 | - color: #303536; | |
| 473 | - background-color: #ff8000; | |
| 474 | - border-color: #ff8000 | |
| 475 | -} | |
| 442 | + | |
| 443 | +button:disabled, | |
| 444 | +input[type=button]:disabled, | |
| 445 | +input[type=reset]:disabled, | |
| 446 | +input[type=submit]:disabled{ | |
| 447 | + color: #ddd; | |
| 448 | + background-color: #7f7f7f; | |
| 449 | + opacity: 0.8; | |
| 450 | +} | |
| 451 | + | |
| 476 | 452 | input[type=email], |
| 477 | 453 | input[type=number], |
| 478 | 454 | input[type=password], |
| 479 | 455 | input[type=search], |
| 480 | 456 | input[type=tel], |
| 481 | 457 |
| --- skins/ardoise/css.txt | |
| +++ skins/ardoise/css.txt | |
| @@ -154,24 +154,19 @@ | |
| 154 | button, |
| 155 | select { |
| 156 | text-transform: none |
| 157 | } |
| 158 | button, |
| 159 | html input[type=button], |
| 160 | input[type=reset], |
| 161 | input[type=submit] { |
| 162 | cursor: pointer |
| 163 | } |
| 164 | button[disabled], |
| 165 | html input[disabled] { |
| 166 | cursor: default |
| 167 | } |
| 168 | button::-moz-focus-inner, |
| 169 | input::-moz-focus-inner { |
| 170 | border: 0; |
| 171 | padding: 0 |
| 172 | } |
| 173 | input { |
| 174 | line-height: normal |
| 175 | } |
| 176 | input[type=checkbox], |
| 177 | input[type=radio] { |
| @@ -307,11 +302,11 @@ | |
| 307 | text-decoration: none; |
| 308 | text-align: center; |
| 309 | white-space: nowrap; |
| 310 | cursor: pointer |
| 311 | } |
| 312 | input[type=submit]:disabled { |
| 313 | color: rgb(70,70,70); |
| 314 | background-color: rgb(153,153,153); |
| 315 | } |
| 316 | |
| 317 | @media (min-width:550px) { |
| @@ -416,30 +411,20 @@ | |
| 416 | .offset-by-eleven.columns { |
| 417 | margin-left: 95.33333% |
| 418 | } |
| 419 | } |
| 420 | .button, |
| 421 | button { |
| 422 | color: #aaa; |
| 423 | background-color: #444; |
| 424 | border-radius: 5px; |
| 425 | border: 0 |
| 426 | } |
| 427 | input[type=button], |
| 428 | input[type=reset], |
| 429 | input[type=submit] { |
| 430 | color: #ddd; |
| 431 | background-color: #446979; |
| 432 | border: 0; |
| 433 | border-radius: 5px |
| 434 | } |
| 435 | .button:hover, |
| 436 | button:hover { |
| 437 | color: #444; |
| 438 | background-color: #aaa; |
| 439 | outline: 0 |
| 440 | } |
| 441 | input[type=button]:hover, |
| 442 | input[type=reset]:hover, |
| 443 | input[type=submit]:hover { |
| 444 | color: #446979; |
| 445 | background-color: #ddd; |
| @@ -452,29 +437,20 @@ | |
| 452 | input[type=submit]:focus { |
| 453 | color: #333; |
| 454 | border-color: #888; |
| 455 | outline: 0 |
| 456 | } |
| 457 | .button.button-primary, |
| 458 | .button.button-primary:focus, |
| 459 | .button.button-primary:hover, |
| 460 | button.button-primary, |
| 461 | button.button-primary:focus, |
| 462 | button.button-primary:hover, |
| 463 | input[type=button].button-primary, |
| 464 | input[type=button].button-primary:focus, |
| 465 | input[type=button].button-primary:hover, |
| 466 | input[type=reset].button-primary, |
| 467 | input[type=reset].button-primary:focus, |
| 468 | input[type=reset].button-primary:hover, |
| 469 | input[type=submit].button-primary, |
| 470 | input[type=submit].button-primary:focus, |
| 471 | input[type=submit].button-primary:hover { |
| 472 | color: #303536; |
| 473 | background-color: #ff8000; |
| 474 | border-color: #ff8000 |
| 475 | } |
| 476 | input[type=email], |
| 477 | input[type=number], |
| 478 | input[type=password], |
| 479 | input[type=search], |
| 480 | input[type=tel], |
| 481 |
| --- skins/ardoise/css.txt | |
| +++ skins/ardoise/css.txt | |
| @@ -154,24 +154,19 @@ | |
| 154 | button, |
| 155 | select { |
| 156 | text-transform: none |
| 157 | } |
| 158 | button, |
| 159 | input[type=button], |
| 160 | input[type=reset], |
| 161 | input[type=submit]{ |
| 162 | cursor: pointer |
| 163 | } |
| 164 | button:disabled, |
| 165 | input:disabled { |
| 166 | cursor: default |
| 167 | } |
| 168 | input { |
| 169 | line-height: normal |
| 170 | } |
| 171 | input[type=checkbox], |
| 172 | input[type=radio] { |
| @@ -307,11 +302,11 @@ | |
| 302 | text-decoration: none; |
| 303 | text-align: center; |
| 304 | white-space: nowrap; |
| 305 | cursor: pointer |
| 306 | } |
| 307 | input:disabled { |
| 308 | color: rgb(70,70,70); |
| 309 | background-color: rgb(153,153,153); |
| 310 | } |
| 311 | |
| 312 | @media (min-width:550px) { |
| @@ -416,30 +411,20 @@ | |
| 411 | .offset-by-eleven.columns { |
| 412 | margin-left: 95.33333% |
| 413 | } |
| 414 | } |
| 415 | .button, |
| 416 | button, |
| 417 | input[type=button], |
| 418 | input[type=reset], |
| 419 | input[type=submit] { |
| 420 | color: #ddd; |
| 421 | background-color: #446979; |
| 422 | border: 0; |
| 423 | border-radius: 5px |
| 424 | } |
| 425 | button:hover, |
| 426 | input[type=button]:hover, |
| 427 | input[type=reset]:hover, |
| 428 | input[type=submit]:hover { |
| 429 | color: #446979; |
| 430 | background-color: #ddd; |
| @@ -452,29 +437,20 @@ | |
| 437 | input[type=submit]:focus { |
| 438 | color: #333; |
| 439 | border-color: #888; |
| 440 | outline: 0 |
| 441 | } |
| 442 | |
| 443 | button:disabled, |
| 444 | input[type=button]:disabled, |
| 445 | input[type=reset]:disabled, |
| 446 | input[type=submit]:disabled{ |
| 447 | color: #ddd; |
| 448 | background-color: #7f7f7f; |
| 449 | opacity: 0.8; |
| 450 | } |
| 451 | |
| 452 | input[type=email], |
| 453 | input[type=number], |
| 454 | input[type=password], |
| 455 | input[type=search], |
| 456 | input[type=tel], |
| 457 |
+43
-73
| --- skins/blitz/css.txt | ||
| +++ skins/blitz/css.txt | ||
| @@ -1,17 +1,9 @@ | ||
| 1 | 1 | /*! normalize.css v3.0.2 | MIT License | git.io/normalize */ |
| 2 | 2 | |
| 3 | -/** | |
| 4 | - * 1. Set default font family to sans-serif. | |
| 5 | - * 2. Prevent iOS text size adjust after orientation change, without disabling | |
| 6 | - * user zoom. | |
| 7 | - */ | |
| 8 | - | |
| 9 | 3 | html { |
| 10 | 4 | font-family: sans-serif; /* 1 */ |
| 11 | - -ms-text-size-adjust: 100%; /* 2 */ | |
| 12 | - -webkit-text-size-adjust: 100%; /* 2 */ | |
| 13 | 5 | } |
| 14 | 6 | |
| 15 | 7 | /** |
| 16 | 8 | * Remove default margin. |
| 17 | 9 | */ |
| @@ -207,11 +199,10 @@ | ||
| 207 | 199 | /** |
| 208 | 200 | * Address differences between Firefox and other browsers. |
| 209 | 201 | */ |
| 210 | 202 | |
| 211 | 203 | hr { |
| 212 | - -moz-box-sizing: content-box; | |
| 213 | 204 | box-sizing: content-box; |
| 214 | 205 | height: 0; |
| 215 | 206 | } |
| 216 | 207 | |
| 217 | 208 | /** |
| @@ -277,45 +268,27 @@ | ||
| 277 | 268 | button, |
| 278 | 269 | select { |
| 279 | 270 | text-transform: none; |
| 280 | 271 | } |
| 281 | 272 | |
| 282 | -/** | |
| 283 | - * 1. Avoid the WebKit bug in Android 4.0.* where (2) destroys native `audio` | |
| 284 | - * and `video` controls. | |
| 285 | - * 2. Correct inability to style clickable `input` types in iOS. | |
| 286 | - * 3. Improve usability and consistency of cursor style between image-type | |
| 287 | - * `input` and others. | |
| 288 | - */ | |
| 289 | - | |
| 290 | 273 | button, |
| 291 | -html input[type="button"], /* 1 */ | |
| 292 | -input[type="reset"], | |
| 293 | -input[type="submit"] { | |
| 294 | - -webkit-appearance: button; /* 2 */ | |
| 295 | - cursor: pointer; /* 3 */ | |
| 274 | +input[type=button], | |
| 275 | +input[type=reset], | |
| 276 | +input[type=submit]{ | |
| 277 | + cursor: pointer; | |
| 296 | 278 | } |
| 297 | 279 | |
| 298 | 280 | /** |
| 299 | 281 | * Re-set default cursor for disabled elements. |
| 300 | 282 | */ |
| 301 | - | |
| 302 | -button[disabled], | |
| 303 | -html input[disabled] { | |
| 283 | +button:disabled, | |
| 284 | +input[type=button]:disabled, | |
| 285 | +input[type=reset]:disabled, | |
| 286 | +input[type=submit]:disabled{ | |
| 304 | 287 | cursor: default; |
| 305 | 288 | } |
| 306 | 289 | |
| 307 | -/** | |
| 308 | - * Remove inner padding and border in Firefox 4+. | |
| 309 | - */ | |
| 310 | - | |
| 311 | -button::-moz-focus-inner, | |
| 312 | -input::-moz-focus-inner { | |
| 313 | - border: 0; | |
| 314 | - padding: 0; | |
| 315 | -} | |
| 316 | - | |
| 317 | 290 | /** |
| 318 | 291 | * Address Firefox 4+ setting `line-height` on `input` using `!important` in |
| 319 | 292 | * the UA stylesheet. |
| 320 | 293 | */ |
| 321 | 294 | |
| @@ -346,20 +319,11 @@ | ||
| 346 | 319 | input[type="number"]::-webkit-inner-spin-button, |
| 347 | 320 | input[type="number"]::-webkit-outer-spin-button { |
| 348 | 321 | height: auto; |
| 349 | 322 | } |
| 350 | 323 | |
| 351 | -/** | |
| 352 | - * 1. Address `appearance` set to `searchfield` in Safari and Chrome. | |
| 353 | - * 2. Address `box-sizing` set to `border-box` in Safari and Chrome | |
| 354 | - * (include `-moz` to future-proof). | |
| 355 | - */ | |
| 356 | - | |
| 357 | 324 | input[type="search"] { |
| 358 | - -webkit-appearance: textfield; /* 1 */ | |
| 359 | - -moz-box-sizing: content-box; | |
| 360 | - -webkit-box-sizing: content-box; /* 2 */ | |
| 361 | 325 | box-sizing: content-box; |
| 362 | 326 | } |
| 363 | 327 | |
| 364 | 328 | /** |
| 365 | 329 | * Remove inner padding and search cancel button in Safari and Chrome on OS X. |
| @@ -515,63 +479,65 @@ | ||
| 515 | 479 | |
| 516 | 480 | /* Buttons |
| 517 | 481 | ––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––– */ |
| 518 | 482 | .button, |
| 519 | 483 | button, |
| 520 | -input[type="button"], | |
| 521 | -input[type="reset"], | |
| 522 | -input[type="submit"] { | |
| 484 | +input[type=button], | |
| 485 | +input[type=reset], | |
| 486 | +input[type=submit]{ | |
| 523 | 487 | display: inline-block; |
| 524 | 488 | height: 3.3rem; |
| 525 | 489 | padding: 0 2.2rem; |
| 526 | - color: #555 !important; | |
| 490 | + color: #444; | |
| 491 | + background-color: #f8f8f8;; | |
| 492 | + border-color: #446979; | |
| 527 | 493 | text-align: center; |
| 528 | 494 | font-size: 1.1rem; |
| 529 | 495 | font-weight: 700; |
| 530 | 496 | line-height: 3.3rem; |
| 531 | 497 | letter-spacing: .08rem; |
| 532 | 498 | text-transform: uppercase; |
| 533 | 499 | text-decoration: none; |
| 534 | 500 | white-space: nowrap; |
| 535 | - background-color: transparent; | |
| 536 | 501 | border-radius: 4px; |
| 537 | - border: 1px solid #ccc; | |
| 502 | + /*border: 1px solid #ccc;*/ | |
| 503 | + border: 1px solid #446979; | |
| 538 | 504 | cursor: pointer; |
| 539 | 505 | box-sizing: border-box; |
| 540 | 506 | } |
| 541 | 507 | |
| 542 | 508 | .button:hover, |
| 543 | 509 | button:hover, |
| 544 | -input[type="button"]:hover, | |
| 545 | -input[type="reset"]:hover, | |
| 546 | -.button:focus, | |
| 510 | +input[type=button]:hover, | |
| 511 | +input[type=reset]:hover, | |
| 512 | +input[type=submit]:hover, | |
| 513 | +.button:hover, | |
| 547 | 514 | button:focus, |
| 548 | -input[type="button"]:focus, | |
| 549 | -input[type="reset"]:focus { | |
| 550 | - color: #444 !important; | |
| 551 | - background-color: #eee; | |
| 552 | - border-color: #aaa; | |
| 515 | +input[type=button]:focus, | |
| 516 | +input[type=reset]:focus, | |
| 517 | +input[type=submit]:focus{ | |
| 553 | 518 | outline: 0; |
| 554 | -} | |
| 555 | - | |
| 556 | -input[type="submit"] { | |
| 557 | - color: white !important; | |
| 558 | - background-color: #446979; | |
| 559 | - border-color: #446979; | |
| 560 | -} | |
| 561 | - | |
| 562 | -input[type="submit"]:hover, | |
| 563 | -input[type="submit"]:focus { | |
| 564 | - color: white !important; | |
| 519 | + color: white; | |
| 565 | 520 | background-color: #648898; |
| 566 | 521 | border-color: #648898; |
| 567 | 522 | } |
| 568 | 523 | |
| 569 | -input[type="submit"]:disabled { | |
| 570 | - color: rgb(128,128,128); | |
| 524 | +.button:disabled, | |
| 525 | +button:disabled, | |
| 526 | +input[type=button]:disabled, | |
| 527 | +input[type=reset]:disabled, | |
| 528 | +input[type=submit]:disabled{ | |
| 529 | + color: #444; | |
| 571 | 530 | background-color: rgb(153,153,153); |
| 572 | 531 | } |
| 532 | + | |
| 533 | +.content a.button, | |
| 534 | +.submenu a.button, | |
| 535 | +.submenu a.button:visited { | |
| 536 | + color: #444; | |
| 537 | + background: #f8f8f8; | |
| 538 | +} | |
| 573 | 539 | |
| 574 | 540 | |
| 575 | 541 | /* Forms |
| 576 | 542 | ––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––– */ |
| 577 | 543 | input[type="email"], |
| @@ -599,12 +565,10 @@ | ||
| 599 | 565 | input[type="text"], |
| 600 | 566 | input[type="tel"], |
| 601 | 567 | input[type="url"], |
| 602 | 568 | input[type="password"], |
| 603 | 569 | textarea { |
| 604 | - -webkit-appearance: none; | |
| 605 | - -moz-appearance: none; | |
| 606 | 570 | appearance: none; |
| 607 | 571 | } |
| 608 | 572 | |
| 609 | 573 | textarea { |
| 610 | 574 | height: inherit; |
| @@ -1281,5 +1245,11 @@ | ||
| 1281 | 1245 | } |
| 1282 | 1246 | |
| 1283 | 1247 | body.forum .forumPosts.fileage a:visited { |
| 1284 | 1248 | color: #648999; |
| 1285 | 1249 | } |
| 1250 | + | |
| 1251 | +/* Chat | |
| 1252 | +––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––– */ | |
| 1253 | +body.chat .chat-input-field:focus { | |
| 1254 | + border-color: #446979; | |
| 1255 | +} | |
| 1286 | 1256 |
| --- skins/blitz/css.txt | |
| +++ skins/blitz/css.txt | |
| @@ -1,17 +1,9 @@ | |
| 1 | /*! normalize.css v3.0.2 | MIT License | git.io/normalize */ |
| 2 | |
| 3 | /** |
| 4 | * 1. Set default font family to sans-serif. |
| 5 | * 2. Prevent iOS text size adjust after orientation change, without disabling |
| 6 | * user zoom. |
| 7 | */ |
| 8 | |
| 9 | html { |
| 10 | font-family: sans-serif; /* 1 */ |
| 11 | -ms-text-size-adjust: 100%; /* 2 */ |
| 12 | -webkit-text-size-adjust: 100%; /* 2 */ |
| 13 | } |
| 14 | |
| 15 | /** |
| 16 | * Remove default margin. |
| 17 | */ |
| @@ -207,11 +199,10 @@ | |
| 207 | /** |
| 208 | * Address differences between Firefox and other browsers. |
| 209 | */ |
| 210 | |
| 211 | hr { |
| 212 | -moz-box-sizing: content-box; |
| 213 | box-sizing: content-box; |
| 214 | height: 0; |
| 215 | } |
| 216 | |
| 217 | /** |
| @@ -277,45 +268,27 @@ | |
| 277 | button, |
| 278 | select { |
| 279 | text-transform: none; |
| 280 | } |
| 281 | |
| 282 | /** |
| 283 | * 1. Avoid the WebKit bug in Android 4.0.* where (2) destroys native `audio` |
| 284 | * and `video` controls. |
| 285 | * 2. Correct inability to style clickable `input` types in iOS. |
| 286 | * 3. Improve usability and consistency of cursor style between image-type |
| 287 | * `input` and others. |
| 288 | */ |
| 289 | |
| 290 | button, |
| 291 | html input[type="button"], /* 1 */ |
| 292 | input[type="reset"], |
| 293 | input[type="submit"] { |
| 294 | -webkit-appearance: button; /* 2 */ |
| 295 | cursor: pointer; /* 3 */ |
| 296 | } |
| 297 | |
| 298 | /** |
| 299 | * Re-set default cursor for disabled elements. |
| 300 | */ |
| 301 | |
| 302 | button[disabled], |
| 303 | html input[disabled] { |
| 304 | cursor: default; |
| 305 | } |
| 306 | |
| 307 | /** |
| 308 | * Remove inner padding and border in Firefox 4+. |
| 309 | */ |
| 310 | |
| 311 | button::-moz-focus-inner, |
| 312 | input::-moz-focus-inner { |
| 313 | border: 0; |
| 314 | padding: 0; |
| 315 | } |
| 316 | |
| 317 | /** |
| 318 | * Address Firefox 4+ setting `line-height` on `input` using `!important` in |
| 319 | * the UA stylesheet. |
| 320 | */ |
| 321 | |
| @@ -346,20 +319,11 @@ | |
| 346 | input[type="number"]::-webkit-inner-spin-button, |
| 347 | input[type="number"]::-webkit-outer-spin-button { |
| 348 | height: auto; |
| 349 | } |
| 350 | |
| 351 | /** |
| 352 | * 1. Address `appearance` set to `searchfield` in Safari and Chrome. |
| 353 | * 2. Address `box-sizing` set to `border-box` in Safari and Chrome |
| 354 | * (include `-moz` to future-proof). |
| 355 | */ |
| 356 | |
| 357 | input[type="search"] { |
| 358 | -webkit-appearance: textfield; /* 1 */ |
| 359 | -moz-box-sizing: content-box; |
| 360 | -webkit-box-sizing: content-box; /* 2 */ |
| 361 | box-sizing: content-box; |
| 362 | } |
| 363 | |
| 364 | /** |
| 365 | * Remove inner padding and search cancel button in Safari and Chrome on OS X. |
| @@ -515,63 +479,65 @@ | |
| 515 | |
| 516 | /* Buttons |
| 517 | ––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––– */ |
| 518 | .button, |
| 519 | button, |
| 520 | input[type="button"], |
| 521 | input[type="reset"], |
| 522 | input[type="submit"] { |
| 523 | display: inline-block; |
| 524 | height: 3.3rem; |
| 525 | padding: 0 2.2rem; |
| 526 | color: #555 !important; |
| 527 | text-align: center; |
| 528 | font-size: 1.1rem; |
| 529 | font-weight: 700; |
| 530 | line-height: 3.3rem; |
| 531 | letter-spacing: .08rem; |
| 532 | text-transform: uppercase; |
| 533 | text-decoration: none; |
| 534 | white-space: nowrap; |
| 535 | background-color: transparent; |
| 536 | border-radius: 4px; |
| 537 | border: 1px solid #ccc; |
| 538 | cursor: pointer; |
| 539 | box-sizing: border-box; |
| 540 | } |
| 541 | |
| 542 | .button:hover, |
| 543 | button:hover, |
| 544 | input[type="button"]:hover, |
| 545 | input[type="reset"]:hover, |
| 546 | .button:focus, |
| 547 | button:focus, |
| 548 | input[type="button"]:focus, |
| 549 | input[type="reset"]:focus { |
| 550 | color: #444 !important; |
| 551 | background-color: #eee; |
| 552 | border-color: #aaa; |
| 553 | outline: 0; |
| 554 | } |
| 555 | |
| 556 | input[type="submit"] { |
| 557 | color: white !important; |
| 558 | background-color: #446979; |
| 559 | border-color: #446979; |
| 560 | } |
| 561 | |
| 562 | input[type="submit"]:hover, |
| 563 | input[type="submit"]:focus { |
| 564 | color: white !important; |
| 565 | background-color: #648898; |
| 566 | border-color: #648898; |
| 567 | } |
| 568 | |
| 569 | input[type="submit"]:disabled { |
| 570 | color: rgb(128,128,128); |
| 571 | background-color: rgb(153,153,153); |
| 572 | } |
| 573 | |
| 574 | |
| 575 | /* Forms |
| 576 | ––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––– */ |
| 577 | input[type="email"], |
| @@ -599,12 +565,10 @@ | |
| 599 | input[type="text"], |
| 600 | input[type="tel"], |
| 601 | input[type="url"], |
| 602 | input[type="password"], |
| 603 | textarea { |
| 604 | -webkit-appearance: none; |
| 605 | -moz-appearance: none; |
| 606 | appearance: none; |
| 607 | } |
| 608 | |
| 609 | textarea { |
| 610 | height: inherit; |
| @@ -1281,5 +1245,11 @@ | |
| 1281 | } |
| 1282 | |
| 1283 | body.forum .forumPosts.fileage a:visited { |
| 1284 | color: #648999; |
| 1285 | } |
| 1286 |
| --- skins/blitz/css.txt | |
| +++ skins/blitz/css.txt | |
| @@ -1,17 +1,9 @@ | |
| 1 | /*! normalize.css v3.0.2 | MIT License | git.io/normalize */ |
| 2 | |
| 3 | html { |
| 4 | font-family: sans-serif; /* 1 */ |
| 5 | } |
| 6 | |
| 7 | /** |
| 8 | * Remove default margin. |
| 9 | */ |
| @@ -207,11 +199,10 @@ | |
| 199 | /** |
| 200 | * Address differences between Firefox and other browsers. |
| 201 | */ |
| 202 | |
| 203 | hr { |
| 204 | box-sizing: content-box; |
| 205 | height: 0; |
| 206 | } |
| 207 | |
| 208 | /** |
| @@ -277,45 +268,27 @@ | |
| 268 | button, |
| 269 | select { |
| 270 | text-transform: none; |
| 271 | } |
| 272 | |
| 273 | button, |
| 274 | input[type=button], |
| 275 | input[type=reset], |
| 276 | input[type=submit]{ |
| 277 | cursor: pointer; |
| 278 | } |
| 279 | |
| 280 | /** |
| 281 | * Re-set default cursor for disabled elements. |
| 282 | */ |
| 283 | button:disabled, |
| 284 | input[type=button]:disabled, |
| 285 | input[type=reset]:disabled, |
| 286 | input[type=submit]:disabled{ |
| 287 | cursor: default; |
| 288 | } |
| 289 | |
| 290 | /** |
| 291 | * Address Firefox 4+ setting `line-height` on `input` using `!important` in |
| 292 | * the UA stylesheet. |
| 293 | */ |
| 294 | |
| @@ -346,20 +319,11 @@ | |
| 319 | input[type="number"]::-webkit-inner-spin-button, |
| 320 | input[type="number"]::-webkit-outer-spin-button { |
| 321 | height: auto; |
| 322 | } |
| 323 | |
| 324 | input[type="search"] { |
| 325 | box-sizing: content-box; |
| 326 | } |
| 327 | |
| 328 | /** |
| 329 | * Remove inner padding and search cancel button in Safari and Chrome on OS X. |
| @@ -515,63 +479,65 @@ | |
| 479 | |
| 480 | /* Buttons |
| 481 | ––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––– */ |
| 482 | .button, |
| 483 | button, |
| 484 | input[type=button], |
| 485 | input[type=reset], |
| 486 | input[type=submit]{ |
| 487 | display: inline-block; |
| 488 | height: 3.3rem; |
| 489 | padding: 0 2.2rem; |
| 490 | color: #444; |
| 491 | background-color: #f8f8f8;; |
| 492 | border-color: #446979; |
| 493 | text-align: center; |
| 494 | font-size: 1.1rem; |
| 495 | font-weight: 700; |
| 496 | line-height: 3.3rem; |
| 497 | letter-spacing: .08rem; |
| 498 | text-transform: uppercase; |
| 499 | text-decoration: none; |
| 500 | white-space: nowrap; |
| 501 | border-radius: 4px; |
| 502 | /*border: 1px solid #ccc;*/ |
| 503 | border: 1px solid #446979; |
| 504 | cursor: pointer; |
| 505 | box-sizing: border-box; |
| 506 | } |
| 507 | |
| 508 | .button:hover, |
| 509 | button:hover, |
| 510 | input[type=button]:hover, |
| 511 | input[type=reset]:hover, |
| 512 | input[type=submit]:hover, |
| 513 | .button:hover, |
| 514 | button:focus, |
| 515 | input[type=button]:focus, |
| 516 | input[type=reset]:focus, |
| 517 | input[type=submit]:focus{ |
| 518 | outline: 0; |
| 519 | color: white; |
| 520 | background-color: #648898; |
| 521 | border-color: #648898; |
| 522 | } |
| 523 | |
| 524 | .button:disabled, |
| 525 | button:disabled, |
| 526 | input[type=button]:disabled, |
| 527 | input[type=reset]:disabled, |
| 528 | input[type=submit]:disabled{ |
| 529 | color: #444; |
| 530 | background-color: rgb(153,153,153); |
| 531 | } |
| 532 | |
| 533 | .content a.button, |
| 534 | .submenu a.button, |
| 535 | .submenu a.button:visited { |
| 536 | color: #444; |
| 537 | background: #f8f8f8; |
| 538 | } |
| 539 | |
| 540 | |
| 541 | /* Forms |
| 542 | ––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––– */ |
| 543 | input[type="email"], |
| @@ -599,12 +565,10 @@ | |
| 565 | input[type="text"], |
| 566 | input[type="tel"], |
| 567 | input[type="url"], |
| 568 | input[type="password"], |
| 569 | textarea { |
| 570 | appearance: none; |
| 571 | } |
| 572 | |
| 573 | textarea { |
| 574 | height: inherit; |
| @@ -1281,5 +1245,11 @@ | |
| 1245 | } |
| 1246 | |
| 1247 | body.forum .forumPosts.fileage a:visited { |
| 1248 | color: #648999; |
| 1249 | } |
| 1250 | |
| 1251 | /* Chat |
| 1252 | ––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––– */ |
| 1253 | body.chat .chat-input-field:focus { |
| 1254 | border-color: #446979; |
| 1255 | } |
| 1256 |
+30
-37
| --- skins/darkmode/css.txt | ||
| +++ skins/darkmode/css.txt | ||
| @@ -98,50 +98,56 @@ | ||
| 98 | 98 | } |
| 99 | 99 | .fileage tr:hover, |
| 100 | 100 | div.filetreeline:hover { |
| 101 | 101 | background-color: #333; |
| 102 | 102 | } |
| 103 | -div.file-change-line button { | |
| 103 | +div.file-change-line button{ | |
| 104 | 104 | background-color: #484848 |
| 105 | 105 | } |
| 106 | +button, | |
| 107 | +input, | |
| 108 | +optgroup, | |
| 109 | +select, | |
| 110 | +textarea { | |
| 111 | + background: inherit; | |
| 112 | + color: inherit; | |
| 113 | + font: inherit; | |
| 114 | + margin: 0 | |
| 115 | +} | |
| 106 | 116 | .button, |
| 107 | -button { | |
| 108 | - color: #aaa; | |
| 109 | - background-color: #484848; | |
| 110 | - border-radius: 5px; | |
| 111 | - border: 0 | |
| 112 | -} | |
| 113 | -.button:hover, | |
| 114 | -button:hover { | |
| 115 | - background-color: #FF4500f0; | |
| 116 | - color: rgba(24,24,24,0.8); | |
| 117 | - outline: 0 | |
| 118 | -} | |
| 117 | +button, | |
| 119 | 118 | input[type=button], |
| 120 | -input[type=reset], | |
| 121 | -input[type=submit] { | |
| 119 | +input[type=submit], | |
| 120 | +input[type=reset]{ | |
| 122 | 121 | color: #ddd; |
| 123 | 122 | background-color: #446979; |
| 123 | + border-radius: 5px; | |
| 124 | 124 | border: 0; |
| 125 | - border-radius: 5px | |
| 126 | 125 | } |
| 126 | +.button:hover, | |
| 127 | +button:hover, | |
| 127 | 128 | input[type=button]:hover, |
| 128 | -input[type=reset]:hover, | |
| 129 | -input[type=submit]:hover { | |
| 129 | +input[type=submit]:hover, | |
| 130 | +input[type=reset]:hover { | |
| 130 | 131 | background-color: #FF4500f0; |
| 131 | 132 | color: rgba(24,24,24,0.8); |
| 132 | - outline: 0 | |
| 133 | + outline: 0; | |
| 133 | 134 | } |
| 134 | -input[type=submit]:disabled { | |
| 135 | - color: #363636; | |
| 136 | - background-color: #707070; | |
| 135 | +.button:disabled, | |
| 136 | +button:disabled, | |
| 137 | +input[type=button]:disabled, | |
| 138 | +input[type=submit]:disabled, | |
| 139 | +input[type=reset]:disabled{ | |
| 140 | + color: #222; | |
| 141 | + background-color: #b0b0b0; | |
| 142 | + opacity: 0.8; | |
| 137 | 143 | } |
| 138 | 144 | .button:focus, |
| 139 | 145 | button:focus, |
| 140 | 146 | input[type=button]:focus, |
| 141 | -input[type=reset]:focus, | |
| 142 | -input[type=submit]:focus { | |
| 147 | +input[type=submit]:focus, | |
| 148 | +input[type=reset]:focus { | |
| 143 | 149 | outline: 2px outset #333; |
| 144 | 150 | border-color: #888; |
| 145 | 151 | } |
| 146 | 152 | |
| 147 | 153 | /* All page content from the bottom of the menu or submenu down to |
| @@ -529,23 +535,10 @@ | ||
| 529 | 535 | } |
| 530 | 536 | span.snippet>mark { |
| 531 | 537 | color: white; |
| 532 | 538 | font-weight: bold; |
| 533 | 539 | } |
| 534 | -button, | |
| 535 | -input, | |
| 536 | -optgroup, | |
| 537 | -select, | |
| 538 | -textarea { | |
| 539 | - background: inherit; | |
| 540 | - color: inherit; | |
| 541 | - font: inherit; | |
| 542 | - margin: 0 | |
| 543 | -} | |
| 544 | -button { | |
| 545 | - background-color: rgba(45,45,45,0.75); | |
| 546 | -} | |
| 547 | 540 | input, textarea, select { |
| 548 | 541 | border: 1px solid rgba(127, 201, 255, 0.9); |
| 549 | 542 | padding: 1px; |
| 550 | 543 | } |
| 551 | 544 | select { |
| 552 | 545 |
| --- skins/darkmode/css.txt | |
| +++ skins/darkmode/css.txt | |
| @@ -98,50 +98,56 @@ | |
| 98 | } |
| 99 | .fileage tr:hover, |
| 100 | div.filetreeline:hover { |
| 101 | background-color: #333; |
| 102 | } |
| 103 | div.file-change-line button { |
| 104 | background-color: #484848 |
| 105 | } |
| 106 | .button, |
| 107 | button { |
| 108 | color: #aaa; |
| 109 | background-color: #484848; |
| 110 | border-radius: 5px; |
| 111 | border: 0 |
| 112 | } |
| 113 | .button:hover, |
| 114 | button:hover { |
| 115 | background-color: #FF4500f0; |
| 116 | color: rgba(24,24,24,0.8); |
| 117 | outline: 0 |
| 118 | } |
| 119 | input[type=button], |
| 120 | input[type=reset], |
| 121 | input[type=submit] { |
| 122 | color: #ddd; |
| 123 | background-color: #446979; |
| 124 | border: 0; |
| 125 | border-radius: 5px |
| 126 | } |
| 127 | input[type=button]:hover, |
| 128 | input[type=reset]:hover, |
| 129 | input[type=submit]:hover { |
| 130 | background-color: #FF4500f0; |
| 131 | color: rgba(24,24,24,0.8); |
| 132 | outline: 0 |
| 133 | } |
| 134 | input[type=submit]:disabled { |
| 135 | color: #363636; |
| 136 | background-color: #707070; |
| 137 | } |
| 138 | .button:focus, |
| 139 | button:focus, |
| 140 | input[type=button]:focus, |
| 141 | input[type=reset]:focus, |
| 142 | input[type=submit]:focus { |
| 143 | outline: 2px outset #333; |
| 144 | border-color: #888; |
| 145 | } |
| 146 | |
| 147 | /* All page content from the bottom of the menu or submenu down to |
| @@ -529,23 +535,10 @@ | |
| 529 | } |
| 530 | span.snippet>mark { |
| 531 | color: white; |
| 532 | font-weight: bold; |
| 533 | } |
| 534 | button, |
| 535 | input, |
| 536 | optgroup, |
| 537 | select, |
| 538 | textarea { |
| 539 | background: inherit; |
| 540 | color: inherit; |
| 541 | font: inherit; |
| 542 | margin: 0 |
| 543 | } |
| 544 | button { |
| 545 | background-color: rgba(45,45,45,0.75); |
| 546 | } |
| 547 | input, textarea, select { |
| 548 | border: 1px solid rgba(127, 201, 255, 0.9); |
| 549 | padding: 1px; |
| 550 | } |
| 551 | select { |
| 552 |
| --- skins/darkmode/css.txt | |
| +++ skins/darkmode/css.txt | |
| @@ -98,50 +98,56 @@ | |
| 98 | } |
| 99 | .fileage tr:hover, |
| 100 | div.filetreeline:hover { |
| 101 | background-color: #333; |
| 102 | } |
| 103 | div.file-change-line button{ |
| 104 | background-color: #484848 |
| 105 | } |
| 106 | button, |
| 107 | input, |
| 108 | optgroup, |
| 109 | select, |
| 110 | textarea { |
| 111 | background: inherit; |
| 112 | color: inherit; |
| 113 | font: inherit; |
| 114 | margin: 0 |
| 115 | } |
| 116 | .button, |
| 117 | button, |
| 118 | input[type=button], |
| 119 | input[type=submit], |
| 120 | input[type=reset]{ |
| 121 | color: #ddd; |
| 122 | background-color: #446979; |
| 123 | border-radius: 5px; |
| 124 | border: 0; |
| 125 | } |
| 126 | .button:hover, |
| 127 | button:hover, |
| 128 | input[type=button]:hover, |
| 129 | input[type=submit]:hover, |
| 130 | input[type=reset]:hover { |
| 131 | background-color: #FF4500f0; |
| 132 | color: rgba(24,24,24,0.8); |
| 133 | outline: 0; |
| 134 | } |
| 135 | .button:disabled, |
| 136 | button:disabled, |
| 137 | input[type=button]:disabled, |
| 138 | input[type=submit]:disabled, |
| 139 | input[type=reset]:disabled{ |
| 140 | color: #222; |
| 141 | background-color: #b0b0b0; |
| 142 | opacity: 0.8; |
| 143 | } |
| 144 | .button:focus, |
| 145 | button:focus, |
| 146 | input[type=button]:focus, |
| 147 | input[type=submit]:focus, |
| 148 | input[type=reset]:focus { |
| 149 | outline: 2px outset #333; |
| 150 | border-color: #888; |
| 151 | } |
| 152 | |
| 153 | /* All page content from the bottom of the menu or submenu down to |
| @@ -529,23 +535,10 @@ | |
| 535 | } |
| 536 | span.snippet>mark { |
| 537 | color: white; |
| 538 | font-weight: bold; |
| 539 | } |
| 540 | input, textarea, select { |
| 541 | border: 1px solid rgba(127, 201, 255, 0.9); |
| 542 | padding: 1px; |
| 543 | } |
| 544 | select { |
| 545 |
+72
-10
| --- src/ajax.c | ||
| +++ src/ajax.c | ||
| @@ -191,23 +191,52 @@ | ||
| 191 | 191 | ** {error: formatted message} |
| 192 | 192 | ** |
| 193 | 193 | ** If httpCode<=0 then it defaults to 500. |
| 194 | 194 | ** |
| 195 | 195 | ** After calling this, the caller should immediately return. |
| 196 | +** | |
| 197 | +** Returns the resulting http code. | |
| 196 | 198 | */ |
| 197 | -void ajax_route_error(int httpCode, const char * zFmt, ...){ | |
| 199 | +int ajax_route_error(int httpCode, const char * zFmt, ...){ | |
| 198 | 200 | Blob msg = empty_blob; |
| 199 | 201 | Blob content = empty_blob; |
| 200 | 202 | va_list vargs; |
| 203 | + | |
| 204 | + if( httpCode<=0 ) httpCode=500; | |
| 201 | 205 | va_start(vargs,zFmt); |
| 202 | 206 | blob_vappendf(&msg, zFmt, vargs); |
| 203 | 207 | va_end(vargs); |
| 204 | 208 | blob_appendf(&content,"{\"error\":%!j}", blob_str(&msg)); |
| 205 | 209 | blob_reset(&msg); |
| 206 | 210 | cgi_set_content(&content); |
| 207 | - cgi_set_status(httpCode>0 ? httpCode : 500, "Error"); | |
| 211 | + cgi_set_status(httpCode, "Error"); | |
| 208 | 212 | cgi_set_content_type("application/json"); |
| 213 | + return httpCode; | |
| 214 | +} | |
| 215 | + | |
| 216 | +void ajax_route_error_forbidden(){ | |
| 217 | + ajax_route_error(403, "Permission denied."); | |
| 218 | +} | |
| 219 | + | |
| 220 | +void ajax_route_error_captcha(){ | |
| 221 | + ajax_route_error(400, "Invalid captcha response."); | |
| 222 | +} | |
| 223 | + | |
| 224 | +void ajax_route_error_csrf(){ | |
| 225 | + ajax_route_error(403, "Invalid CSRF signature."); | |
| 226 | +} | |
| 227 | + | |
| 228 | +void ajax_route_error_404(const char *zMsg){ | |
| 229 | + ajax_route_error(404, "%s", zMsg ? zMsg : "Resource not found."); | |
| 230 | +} | |
| 231 | + | |
| 232 | +int ajax_check_csrf(int level){ | |
| 233 | + if( 0==cgi_csrf_safe(level) ){ | |
| 234 | + ajax_route_error_csrf(); | |
| 235 | + return 0; | |
| 236 | + } | |
| 237 | + return 1; | |
| 209 | 238 | } |
| 210 | 239 | |
| 211 | 240 | /* |
| 212 | 241 | ** Performs bootstrapping common to the /ajax/xyz AJAX routes, such as |
| 213 | 242 | ** logging in the user. |
| @@ -224,17 +253,18 @@ | ||
| 224 | 253 | int ajax_route_bootstrap(int requireWrite, int requirePost){ |
| 225 | 254 | login_check_credentials(); |
| 226 | 255 | if( requireWrite!=0 && g.perm.Write==0 ){ |
| 227 | 256 | ajax_route_error(403,"Write permissions required."); |
| 228 | 257 | return 0; |
| 229 | - }else if(0==cgi_csrf_safe(requirePost)){ | |
| 258 | + }else if(requirePost && 0==cgi_csrf_safe(requirePost)){ | |
| 230 | 259 | ajax_route_error(403, |
| 231 | 260 | "CSRF violation (make sure sending of HTTP " |
| 232 | 261 | "Referer headers is enabled for XHR " |
| 233 | 262 | "connections)."); |
| 234 | 263 | return 0; |
| 235 | 264 | } |
| 265 | + cgi_set_content_type("application/json"); | |
| 236 | 266 | return 1; |
| 237 | 267 | } |
| 238 | 268 | |
| 239 | 269 | /* |
| 240 | 270 | ** Helper for collecting filename/check-in request parameters. |
| @@ -283,12 +313,10 @@ | ||
| 283 | 313 | ** AJAX_RENDER_PLAIN_TEXT mode. |
| 284 | 314 | ** |
| 285 | 315 | ** iframe_height=integer (default=40) Height, in EMs of HTML preview |
| 286 | 316 | ** iframe. |
| 287 | 317 | ** |
| 288 | -** User must have Write access to use this page. | |
| 289 | -** | |
| 290 | 318 | ** Responds with the HTML content of the preview. On error it produces |
| 291 | 319 | ** a JSON response as documented for ajax_route_error(). |
| 292 | 320 | ** |
| 293 | 321 | ** Extra response headers: |
| 294 | 322 | ** |
| @@ -341,10 +369,37 @@ | ||
| 341 | 369 | } |
| 342 | 370 | if(zRenderMode!=0){ |
| 343 | 371 | cgi_printf_header("x-ajax-render-mode: %s\r\n", zRenderMode); |
| 344 | 372 | } |
| 345 | 373 | } |
| 374 | + | |
| 375 | +/* | |
| 376 | +** AJAX route /ajax/artifact.json. | |
| 377 | +** URL arguments: | |
| 378 | +** | |
| 379 | +** uuid=ARTIFACT_ID REQUIRED | |
| 380 | +** | |
| 381 | +** and emits either: | |
| 382 | +** | |
| 383 | +** { error: "..." } | |
| 384 | +** | |
| 385 | +** with a non-200 response code or the artifact's manifest in JSON | |
| 386 | +** form with a 200 response code. | |
| 387 | +*/ | |
| 388 | +void ajax_route_artifact_json(void){ | |
| 389 | + const char *zUuid = P("uuid"); | |
| 390 | + Blob json = BLOB_INITIALIZER; | |
| 391 | + login_check_credentials(); | |
| 392 | + if( ! g.perm.Read ){ | |
| 393 | + ajax_route_error_forbidden(); | |
| 394 | + }else if( artifact_to_json_by_name(zUuid, &json) ){ | |
| 395 | + @ %b(&json) | |
| 396 | + }else{ | |
| 397 | + ajax_route_error_404("Cannot resolve artifact ID."); | |
| 398 | + } | |
| 399 | + blob_reset(&json); | |
| 400 | +} | |
| 346 | 401 | |
| 347 | 402 | #if INTERFACE |
| 348 | 403 | /* |
| 349 | 404 | ** Internal mapping of ajax sub-route names to various metadata. |
| 350 | 405 | */ |
| @@ -351,11 +406,12 @@ | ||
| 351 | 406 | struct AjaxRoute { |
| 352 | 407 | const char *zName; /* Name part of the route after "ajax/" */ |
| 353 | 408 | void (*xCallback)(); /* Impl function for the route. */ |
| 354 | 409 | int bWriteMode; /* True if requires write mode */ |
| 355 | 410 | int bPost; /* True if requires POST (i.e. CSRF |
| 356 | - ** verification) */ | |
| 411 | + ** verification). Value is passed to | |
| 412 | + ** cgi_csrf_safe(). */ | |
| 357 | 413 | }; |
| 358 | 414 | typedef struct AjaxRoute AjaxRoute; |
| 359 | 415 | #endif /*INTERFACE*/ |
| 360 | 416 | |
| 361 | 417 | /* |
| @@ -392,20 +448,26 @@ | ||
| 392 | 448 | const char * zName = P("name"); |
| 393 | 449 | AjaxRoute routeName = {0,0,0,0}; |
| 394 | 450 | const AjaxRoute * pRoute = 0; |
| 395 | 451 | const AjaxRoute routes[] = { |
| 396 | 452 | /* Keep these sorted by zName (for bsearch()) */ |
| 453 | + {"artifact.json", ajax_route_artifact_json, 0, 0}, | |
| 397 | 454 | {"preview-text", ajax_route_preview_text, 0, 1 |
| 398 | - /* Note that this does not require write permissions in the repo. | |
| 399 | - ** It should arguably require write permissions but doing means | |
| 400 | - ** that /chat does not work without check-in permissions: | |
| 455 | + /* Preview does not require write permissions in the repo. It | |
| 456 | + ** should arguably require write permissions simply to limit abuse | |
| 457 | + ** but doing means that /chat does not work without check-in | |
| 458 | + ** permissions: | |
| 401 | 459 | ** |
| 402 | 460 | ** https://fossil-scm.org/forum/forumpost/ed4a762b3a557898 |
| 403 | 461 | ** |
| 404 | 462 | ** This particular route is used by /fileedit and /chat, whereas |
| 405 | 463 | ** /wikiedit uses a simpler wiki-specific route. |
| 406 | - */ } | |
| 464 | + */ | |
| 465 | + /* TODO (2026-06-09): preview.txt, preview.md, preview.wiki as | |
| 466 | + ** shorthand for preview-text?filename=X.(txt|md|wiki), noting that | |
| 467 | + ** the filename is only used for mimetype determination. */ | |
| 468 | + } | |
| 407 | 469 | }; |
| 408 | 470 | |
| 409 | 471 | if(zName==0 || zName[0]==0){ |
| 410 | 472 | ajax_route_error(400,"Missing required [route] 'name' parameter."); |
| 411 | 473 | return; |
| 412 | 474 |
| --- src/ajax.c | |
| +++ src/ajax.c | |
| @@ -191,23 +191,52 @@ | |
| 191 | ** {error: formatted message} |
| 192 | ** |
| 193 | ** If httpCode<=0 then it defaults to 500. |
| 194 | ** |
| 195 | ** After calling this, the caller should immediately return. |
| 196 | */ |
| 197 | void ajax_route_error(int httpCode, const char * zFmt, ...){ |
| 198 | Blob msg = empty_blob; |
| 199 | Blob content = empty_blob; |
| 200 | va_list vargs; |
| 201 | va_start(vargs,zFmt); |
| 202 | blob_vappendf(&msg, zFmt, vargs); |
| 203 | va_end(vargs); |
| 204 | blob_appendf(&content,"{\"error\":%!j}", blob_str(&msg)); |
| 205 | blob_reset(&msg); |
| 206 | cgi_set_content(&content); |
| 207 | cgi_set_status(httpCode>0 ? httpCode : 500, "Error"); |
| 208 | cgi_set_content_type("application/json"); |
| 209 | } |
| 210 | |
| 211 | /* |
| 212 | ** Performs bootstrapping common to the /ajax/xyz AJAX routes, such as |
| 213 | ** logging in the user. |
| @@ -224,17 +253,18 @@ | |
| 224 | int ajax_route_bootstrap(int requireWrite, int requirePost){ |
| 225 | login_check_credentials(); |
| 226 | if( requireWrite!=0 && g.perm.Write==0 ){ |
| 227 | ajax_route_error(403,"Write permissions required."); |
| 228 | return 0; |
| 229 | }else if(0==cgi_csrf_safe(requirePost)){ |
| 230 | ajax_route_error(403, |
| 231 | "CSRF violation (make sure sending of HTTP " |
| 232 | "Referer headers is enabled for XHR " |
| 233 | "connections)."); |
| 234 | return 0; |
| 235 | } |
| 236 | return 1; |
| 237 | } |
| 238 | |
| 239 | /* |
| 240 | ** Helper for collecting filename/check-in request parameters. |
| @@ -283,12 +313,10 @@ | |
| 283 | ** AJAX_RENDER_PLAIN_TEXT mode. |
| 284 | ** |
| 285 | ** iframe_height=integer (default=40) Height, in EMs of HTML preview |
| 286 | ** iframe. |
| 287 | ** |
| 288 | ** User must have Write access to use this page. |
| 289 | ** |
| 290 | ** Responds with the HTML content of the preview. On error it produces |
| 291 | ** a JSON response as documented for ajax_route_error(). |
| 292 | ** |
| 293 | ** Extra response headers: |
| 294 | ** |
| @@ -341,10 +369,37 @@ | |
| 341 | } |
| 342 | if(zRenderMode!=0){ |
| 343 | cgi_printf_header("x-ajax-render-mode: %s\r\n", zRenderMode); |
| 344 | } |
| 345 | } |
| 346 | |
| 347 | #if INTERFACE |
| 348 | /* |
| 349 | ** Internal mapping of ajax sub-route names to various metadata. |
| 350 | */ |
| @@ -351,11 +406,12 @@ | |
| 351 | struct AjaxRoute { |
| 352 | const char *zName; /* Name part of the route after "ajax/" */ |
| 353 | void (*xCallback)(); /* Impl function for the route. */ |
| 354 | int bWriteMode; /* True if requires write mode */ |
| 355 | int bPost; /* True if requires POST (i.e. CSRF |
| 356 | ** verification) */ |
| 357 | }; |
| 358 | typedef struct AjaxRoute AjaxRoute; |
| 359 | #endif /*INTERFACE*/ |
| 360 | |
| 361 | /* |
| @@ -392,20 +448,26 @@ | |
| 392 | const char * zName = P("name"); |
| 393 | AjaxRoute routeName = {0,0,0,0}; |
| 394 | const AjaxRoute * pRoute = 0; |
| 395 | const AjaxRoute routes[] = { |
| 396 | /* Keep these sorted by zName (for bsearch()) */ |
| 397 | {"preview-text", ajax_route_preview_text, 0, 1 |
| 398 | /* Note that this does not require write permissions in the repo. |
| 399 | ** It should arguably require write permissions but doing means |
| 400 | ** that /chat does not work without check-in permissions: |
| 401 | ** |
| 402 | ** https://fossil-scm.org/forum/forumpost/ed4a762b3a557898 |
| 403 | ** |
| 404 | ** This particular route is used by /fileedit and /chat, whereas |
| 405 | ** /wikiedit uses a simpler wiki-specific route. |
| 406 | */ } |
| 407 | }; |
| 408 | |
| 409 | if(zName==0 || zName[0]==0){ |
| 410 | ajax_route_error(400,"Missing required [route] 'name' parameter."); |
| 411 | return; |
| 412 |
| --- src/ajax.c | |
| +++ src/ajax.c | |
| @@ -191,23 +191,52 @@ | |
| 191 | ** {error: formatted message} |
| 192 | ** |
| 193 | ** If httpCode<=0 then it defaults to 500. |
| 194 | ** |
| 195 | ** After calling this, the caller should immediately return. |
| 196 | ** |
| 197 | ** Returns the resulting http code. |
| 198 | */ |
| 199 | int ajax_route_error(int httpCode, const char * zFmt, ...){ |
| 200 | Blob msg = empty_blob; |
| 201 | Blob content = empty_blob; |
| 202 | va_list vargs; |
| 203 | |
| 204 | if( httpCode<=0 ) httpCode=500; |
| 205 | va_start(vargs,zFmt); |
| 206 | blob_vappendf(&msg, zFmt, vargs); |
| 207 | va_end(vargs); |
| 208 | blob_appendf(&content,"{\"error\":%!j}", blob_str(&msg)); |
| 209 | blob_reset(&msg); |
| 210 | cgi_set_content(&content); |
| 211 | cgi_set_status(httpCode, "Error"); |
| 212 | cgi_set_content_type("application/json"); |
| 213 | return httpCode; |
| 214 | } |
| 215 | |
| 216 | void ajax_route_error_forbidden(){ |
| 217 | ajax_route_error(403, "Permission denied."); |
| 218 | } |
| 219 | |
| 220 | void ajax_route_error_captcha(){ |
| 221 | ajax_route_error(400, "Invalid captcha response."); |
| 222 | } |
| 223 | |
| 224 | void ajax_route_error_csrf(){ |
| 225 | ajax_route_error(403, "Invalid CSRF signature."); |
| 226 | } |
| 227 | |
| 228 | void ajax_route_error_404(const char *zMsg){ |
| 229 | ajax_route_error(404, "%s", zMsg ? zMsg : "Resource not found."); |
| 230 | } |
| 231 | |
| 232 | int ajax_check_csrf(int level){ |
| 233 | if( 0==cgi_csrf_safe(level) ){ |
| 234 | ajax_route_error_csrf(); |
| 235 | return 0; |
| 236 | } |
| 237 | return 1; |
| 238 | } |
| 239 | |
| 240 | /* |
| 241 | ** Performs bootstrapping common to the /ajax/xyz AJAX routes, such as |
| 242 | ** logging in the user. |
| @@ -224,17 +253,18 @@ | |
| 253 | int ajax_route_bootstrap(int requireWrite, int requirePost){ |
| 254 | login_check_credentials(); |
| 255 | if( requireWrite!=0 && g.perm.Write==0 ){ |
| 256 | ajax_route_error(403,"Write permissions required."); |
| 257 | return 0; |
| 258 | }else if(requirePost && 0==cgi_csrf_safe(requirePost)){ |
| 259 | ajax_route_error(403, |
| 260 | "CSRF violation (make sure sending of HTTP " |
| 261 | "Referer headers is enabled for XHR " |
| 262 | "connections)."); |
| 263 | return 0; |
| 264 | } |
| 265 | cgi_set_content_type("application/json"); |
| 266 | return 1; |
| 267 | } |
| 268 | |
| 269 | /* |
| 270 | ** Helper for collecting filename/check-in request parameters. |
| @@ -283,12 +313,10 @@ | |
| 313 | ** AJAX_RENDER_PLAIN_TEXT mode. |
| 314 | ** |
| 315 | ** iframe_height=integer (default=40) Height, in EMs of HTML preview |
| 316 | ** iframe. |
| 317 | ** |
| 318 | ** Responds with the HTML content of the preview. On error it produces |
| 319 | ** a JSON response as documented for ajax_route_error(). |
| 320 | ** |
| 321 | ** Extra response headers: |
| 322 | ** |
| @@ -341,10 +369,37 @@ | |
| 369 | } |
| 370 | if(zRenderMode!=0){ |
| 371 | cgi_printf_header("x-ajax-render-mode: %s\r\n", zRenderMode); |
| 372 | } |
| 373 | } |
| 374 | |
| 375 | /* |
| 376 | ** AJAX route /ajax/artifact.json. |
| 377 | ** URL arguments: |
| 378 | ** |
| 379 | ** uuid=ARTIFACT_ID REQUIRED |
| 380 | ** |
| 381 | ** and emits either: |
| 382 | ** |
| 383 | ** { error: "..." } |
| 384 | ** |
| 385 | ** with a non-200 response code or the artifact's manifest in JSON |
| 386 | ** form with a 200 response code. |
| 387 | */ |
| 388 | void ajax_route_artifact_json(void){ |
| 389 | const char *zUuid = P("uuid"); |
| 390 | Blob json = BLOB_INITIALIZER; |
| 391 | login_check_credentials(); |
| 392 | if( ! g.perm.Read ){ |
| 393 | ajax_route_error_forbidden(); |
| 394 | }else if( artifact_to_json_by_name(zUuid, &json) ){ |
| 395 | @ %b(&json) |
| 396 | }else{ |
| 397 | ajax_route_error_404("Cannot resolve artifact ID."); |
| 398 | } |
| 399 | blob_reset(&json); |
| 400 | } |
| 401 | |
| 402 | #if INTERFACE |
| 403 | /* |
| 404 | ** Internal mapping of ajax sub-route names to various metadata. |
| 405 | */ |
| @@ -351,11 +406,12 @@ | |
| 406 | struct AjaxRoute { |
| 407 | const char *zName; /* Name part of the route after "ajax/" */ |
| 408 | void (*xCallback)(); /* Impl function for the route. */ |
| 409 | int bWriteMode; /* True if requires write mode */ |
| 410 | int bPost; /* True if requires POST (i.e. CSRF |
| 411 | ** verification). Value is passed to |
| 412 | ** cgi_csrf_safe(). */ |
| 413 | }; |
| 414 | typedef struct AjaxRoute AjaxRoute; |
| 415 | #endif /*INTERFACE*/ |
| 416 | |
| 417 | /* |
| @@ -392,20 +448,26 @@ | |
| 448 | const char * zName = P("name"); |
| 449 | AjaxRoute routeName = {0,0,0,0}; |
| 450 | const AjaxRoute * pRoute = 0; |
| 451 | const AjaxRoute routes[] = { |
| 452 | /* Keep these sorted by zName (for bsearch()) */ |
| 453 | {"artifact.json", ajax_route_artifact_json, 0, 0}, |
| 454 | {"preview-text", ajax_route_preview_text, 0, 1 |
| 455 | /* Preview does not require write permissions in the repo. It |
| 456 | ** should arguably require write permissions simply to limit abuse |
| 457 | ** but doing means that /chat does not work without check-in |
| 458 | ** permissions: |
| 459 | ** |
| 460 | ** https://fossil-scm.org/forum/forumpost/ed4a762b3a557898 |
| 461 | ** |
| 462 | ** This particular route is used by /fileedit and /chat, whereas |
| 463 | ** /wikiedit uses a simpler wiki-specific route. |
| 464 | */ |
| 465 | /* TODO (2026-06-09): preview.txt, preview.md, preview.wiki as |
| 466 | ** shorthand for preview-text?filename=X.(txt|md|wiki), noting that |
| 467 | ** the filename is only used for mimetype determination. */ |
| 468 | } |
| 469 | }; |
| 470 | |
| 471 | if(zName==0 || zName[0]==0){ |
| 472 | ajax_route_error(400,"Missing required [route] 'name' parameter."); |
| 473 | return; |
| 474 |
+1
-1
| --- src/alerts.c | ||
| +++ src/alerts.c | ||
| @@ -849,11 +849,11 @@ | ||
| 849 | 849 | } |
| 850 | 850 | |
| 851 | 851 | /* |
| 852 | 852 | ** Return a pointer to a fake email mailbox name that corresponds |
| 853 | 853 | ** to human-readable name zFromName. The fake mailbox name is based |
| 854 | -** on a hash. No huge problems arise if there is a hash collisions, | |
| 854 | +** on a hash. No huge problems arise if there is a hash collision, | |
| 855 | 855 | ** but it is still better if collisions can be avoided. |
| 856 | 856 | ** |
| 857 | 857 | ** The returned string is held in a static buffer and is overwritten |
| 858 | 858 | ** by each subsequent call to this routine. |
| 859 | 859 | */ |
| 860 | 860 |
| --- src/alerts.c | |
| +++ src/alerts.c | |
| @@ -849,11 +849,11 @@ | |
| 849 | } |
| 850 | |
| 851 | /* |
| 852 | ** Return a pointer to a fake email mailbox name that corresponds |
| 853 | ** to human-readable name zFromName. The fake mailbox name is based |
| 854 | ** on a hash. No huge problems arise if there is a hash collisions, |
| 855 | ** but it is still better if collisions can be avoided. |
| 856 | ** |
| 857 | ** The returned string is held in a static buffer and is overwritten |
| 858 | ** by each subsequent call to this routine. |
| 859 | */ |
| 860 |
| --- src/alerts.c | |
| +++ src/alerts.c | |
| @@ -849,11 +849,11 @@ | |
| 849 | } |
| 850 | |
| 851 | /* |
| 852 | ** Return a pointer to a fake email mailbox name that corresponds |
| 853 | ** to human-readable name zFromName. The fake mailbox name is based |
| 854 | ** on a hash. No huge problems arise if there is a hash collision, |
| 855 | ** but it is still better if collisions can be avoided. |
| 856 | ** |
| 857 | ** The returned string is held in a static buffer and is overwritten |
| 858 | ** by each subsequent call to this routine. |
| 859 | */ |
| 860 |
+1199
-181
| --- src/attach.c | ||
| +++ src/attach.c | ||
| @@ -18,32 +18,219 @@ | ||
| 18 | 18 | ** This file contains code for dealing with attachments. |
| 19 | 19 | */ |
| 20 | 20 | #include "config.h" |
| 21 | 21 | #include "attach.h" |
| 22 | 22 | #include <assert.h> |
| 23 | + | |
| 24 | +/* | |
| 25 | +** Given a presumedly legal attachment target name, this guesses the | |
| 26 | +** target type and returns one of CFTYPE_FORUM, CFTYPE_WIKI, | |
| 27 | +** CFTYPE_TICKET, or CFTYPE_EVENT. Returns 0 if it cannot distinguish | |
| 28 | +** the target type. | |
| 29 | +** | |
| 30 | +** zTarget is an attachment target name: wiki page name, tech-note ID, | |
| 31 | +** ticket ID, or forumpost hash. | |
| 32 | +** | |
| 33 | +** If bFull is true then it requires zTarget to be a full ID for | |
| 34 | +** tech-notes and tickets, otherwise such IDs may be prefixes. If | |
| 35 | +** bFull is false then tech-notes and tickets will perform a prefix | |
| 36 | +** match, but it is up to the caller to provide enough of a prefix to | |
| 37 | +** rule out ambiguity[^1]. When called repeatedly, this routine can | |
| 38 | +** run a bit faster and more efficiently if bFull is true, but some | |
| 39 | +** historical use cases call for prefix matches. | |
| 40 | +** | |
| 41 | +** Wiki page names always require an exact match. | |
| 42 | +** | |
| 43 | +** Forum posts are a special case: | |
| 44 | +** | |
| 45 | +** - They ignore the bFull flag. That is, they will do prefix matches | |
| 46 | +** but will not match an ambiguous prefix. | |
| 47 | +** | |
| 48 | +** - It is up to the caller to, if needed, resolve zTarget using | |
| 49 | +** forumpost_head_rid2() to resolve the RID of the earliest version | |
| 50 | +** of the post, as that is the only one which attachments should | |
| 51 | +** target. | |
| 52 | +** | |
| 53 | +** [^1]: Historically (from the perspective of 2026-06) attachment | |
| 54 | +** target lookups have used GLOB prefix matching but have taken no | |
| 55 | +** measures to ensure that the prefix is unambiguous. Ergo we do the | |
| 56 | +** same here. It is assumed that the caller passes enough of a prefix | |
| 57 | +** to be unambiguous and that's worked out fine so far. | |
| 58 | +*/ | |
| 59 | +int attachment_target_type(const char *zTarget, int bFull){ | |
| 60 | + if( !zTarget || !zTarget[0] || strlen(zTarget)>64/*vs. abuse*/ ){ | |
| 61 | + return 0; | |
| 62 | + } | |
| 63 | + if( symbolic_name_to_rid(zTarget, "f")>0 ){ | |
| 64 | + /* Check forum posts first because they are the most likely target | |
| 65 | + ** as of 2026. We should arguably use something more | |
| 66 | + ** specialized/efficient than symbolic_name_to_rid(). */ | |
| 67 | + return CFTYPE_FORUM; | |
| 68 | + } | |
| 69 | + if( bFull ){ | |
| 70 | + static Stmt q = empty_Stmt_m; | |
| 71 | + int rc = 0; | |
| 72 | + if( !q.pStmt ){ | |
| 73 | + db_static_prepare( | |
| 74 | + &q, | |
| 75 | + "SELECT CASE " | |
| 76 | + /* Ordered by presumed likelihood of attachments. */ | |
| 77 | + "WHEN (SELECT 1 FROM tag WHERE tagname='tkt-'||:tgt) THEN %d\n" | |
| 78 | + "WHEN (SELECT 1 FROM tag WHERE tagname='wiki-'||:tgt) THEN %d\n" | |
| 79 | + "WHEN (SELECT 1 FROM tag WHERE tagname='event-'||:tgt) THEN %d\n" | |
| 80 | + "ELSE 0 END", | |
| 81 | + CFTYPE_TICKET, CFTYPE_WIKI, CFTYPE_EVENT | |
| 82 | + ); | |
| 83 | + } | |
| 84 | + db_bind_text(&q, ":tgt", zTarget); | |
| 85 | + if( SQLITE_ROW==db_step(&q) ){ | |
| 86 | + rc = db_column_int(&q, 0); | |
| 87 | + } | |
| 88 | + db_reset(&q); | |
| 89 | + return rc; | |
| 90 | + }else{ | |
| 91 | + return db_int( | |
| 92 | + 0, | |
| 93 | + "SELECT CASE " | |
| 94 | + "WHEN (SELECT tagid FROM tag WHERE tagname GLOB 'tkt-%q*')" | |
| 95 | + " THEN %d\n" | |
| 96 | + "WHEN (SELECT tagid FROM tag WHERE tagname='wiki-%q')" | |
| 97 | + " THEN %d\n" | |
| 98 | + "WHEN (SELECT tagid FROM tag WHERE tagname GLOB 'event-%q*')" | |
| 99 | + " THEN %d\n" | |
| 100 | + "ELSE 0 END", | |
| 101 | + zTarget, CFTYPE_TICKET, | |
| 102 | + zTarget, CFTYPE_WIKI, | |
| 103 | + zTarget, CFTYPE_EVENT | |
| 104 | + ); | |
| 105 | + } | |
| 106 | +} | |
| 107 | + | |
| 108 | +/* | |
| 109 | +** Given an attachment target name, returns the target's blob.rid. | |
| 110 | +** zTarget and bFull work as described for attachment_target_type(). | |
| 111 | +** | |
| 112 | +** For forum posts, this always returns the RID of the first version | |
| 113 | +** of the post, as attachments should always target that instance. | |
| 114 | +*/ | |
| 115 | +int attachment_target_rid(const char *zTarget, int bFull){ | |
| 116 | + int rid = 0; | |
| 117 | + const int eType = attachment_target_type(zTarget, bFull); | |
| 118 | + switch(eType){ | |
| 119 | + case CFTYPE_TICKET: | |
| 120 | + case CFTYPE_EVENT:{ | |
| 121 | + const char *zTagPrefix = (eType==CFTYPE_EVENT) ? "event" : "tkt"; | |
| 122 | + rid = db_int( | |
| 123 | + 0, "SELECT b.rid FROM blob b, tag t, tagxref x\n" | |
| 124 | + "WHERE tagname %s '%s-%q%s'\n" | |
| 125 | + "AND x.tagtype>0\n" | |
| 126 | + "AND x.tagid=t.tagid\n" | |
| 127 | + "AND x.rid=b.rid\n" | |
| 128 | + "ORDER BY x.mtime DESC", | |
| 129 | + bFull ? "=" : "GLOB"/*safe-for-%s*/, | |
| 130 | + zTagPrefix/*safe-for-%s*/, | |
| 131 | + zTarget, | |
| 132 | + bFull ? "" : "*"/*safe-for-%s*/ | |
| 133 | + ); | |
| 134 | + break; | |
| 135 | + } | |
| 136 | + case CFTYPE_FORUM: | |
| 137 | + rid = db_int( | |
| 138 | + 0, "SELECT f.fpid FROM forumpost f, blob b\n" | |
| 139 | + "WHERE f.fpid=b.rid\n" | |
| 140 | + "AND b.uuid %s '%q%s'", | |
| 141 | + bFull ? "=" : "GLOB"/*safe-for-%s*/, | |
| 142 | + zTarget, | |
| 143 | + bFull ? "" : "*"/*safe-for-%s*/ | |
| 144 | + ); | |
| 145 | + if( rid>0 ){ | |
| 146 | + rid = forumpost_head_rid(rid); | |
| 147 | + } | |
| 148 | + break; | |
| 149 | + case CFTYPE_WIKI: | |
| 150 | + rid = db_int( | |
| 151 | + 0, "SELECT b.rid FROM blob b, tag t, tagxref x\n" | |
| 152 | + "WHERE tagname='wiki-%q'\n" | |
| 153 | + "AND x.tagtype>0\n" | |
| 154 | + "AND x.tagid=t.tagid\n" | |
| 155 | + "AND x.rid=b.rid\n" | |
| 156 | + "ORDER BY x.mtime DESC", | |
| 157 | + zTarget | |
| 158 | + ); | |
| 159 | + break; | |
| 160 | + default: | |
| 161 | + break; | |
| 162 | + } | |
| 163 | + return rid; | |
| 164 | +} | |
| 165 | + | |
| 166 | +/* | |
| 167 | +** For a given aritfact ID and type (from the CFTYPE_xyz enum), | |
| 168 | +** returns true if the current user could hypothetically apply and | |
| 169 | +** attachment to it, else returns 0. | |
| 170 | +** | |
| 171 | +** The rid is currently only relevant when eArtifactType is | |
| 172 | +** CFTYPE_FORUM. For forum posts, it checks precisely the rid given, | |
| 173 | +** not the head RID, to keep non-admins from attaching files to | |
| 174 | +** threads which have since been taken over by another user (this | |
| 175 | +** happens when an admin edits another user's post). | |
| 176 | +*/ | |
| 177 | +int attach_user_may(int rid, int eArtifactType){ | |
| 178 | + if( g.perm.Admin ) return 1; | |
| 179 | + if( !login_is_individual() ) return 0; | |
| 180 | + switch(eArtifactType){ | |
| 181 | + case CFTYPE_FORUM: | |
| 182 | + return g.perm.AttachForum && forumpost_is_owner(rid, 0); | |
| 183 | + case CFTYPE_WIKI: | |
| 184 | + return g.perm.ApndWiki && g.perm.Attach; | |
| 185 | + case CFTYPE_TICKET: | |
| 186 | + return g.perm.ApndTkt && g.perm.Attach; | |
| 187 | + case CFTYPE_EVENT: | |
| 188 | + return g.perm.Write && g.perm.ApndWiki && g.perm.Attach; | |
| 189 | + default: | |
| 190 | + return 0; | |
| 191 | + } | |
| 192 | +} | |
| 193 | + | |
| 194 | +/* | |
| 195 | +** Emits a single-button FORM which invokes | |
| 196 | +** /attachadd with target=$zTarget. | |
| 197 | +*/ | |
| 198 | +void attach_render_attachadd_button(const char *zTarget){ | |
| 199 | + /* This could be changed from POST to GET, and arguably should so | |
| 200 | + ** that the target=X part becomes part of the resulting URL. */ | |
| 201 | + @ <form method="post" action="%R/attachadd">\ | |
| 202 | + @ <input type="hidden" name="target" value="%T(zTarget)">\ | |
| 203 | + @ <input type="submit" value="Attach..."> | |
| 204 | + @ </form>\ | |
| 205 | +} | |
| 23 | 206 | |
| 24 | 207 | /* |
| 25 | 208 | ** WEBPAGE: attachlist |
| 26 | 209 | ** List attachments. |
| 27 | 210 | ** |
| 28 | 211 | ** tkt=HASH |
| 29 | 212 | ** page=WIKIPAGE |
| 30 | 213 | ** technote=HASH |
| 214 | +** forumpost=HASH | |
| 31 | 215 | ** |
| 32 | -** At most one of technote=, tkt= or page= may be supplied. | |
| 216 | +** At most one of technote=, tkt=, forumpost=, or page= may be supplied. | |
| 33 | 217 | ** |
| 34 | 218 | ** If none are given, all attachments are listed. If one is given, only |
| 35 | 219 | ** attachments for the designated technote, ticket or wiki page are shown. |
| 36 | 220 | ** |
| 37 | -** HASH may be just a prefix of the relevant technical note or ticket | |
| 38 | -** artifact hash, in which case all attachments of all technical notes or | |
| 39 | -** tickets with the prefix will be listed. | |
| 221 | +** HASH may be just a prefix of the relevant forum post, technical | |
| 222 | +** note, or ticket artifact hash, in which case all attachments of all | |
| 223 | +** technical notes or tickets with the prefix will be listed. Forum | |
| 224 | +** posts, on the other hand, require a unique hash or hash prefix. | |
| 40 | 225 | */ |
| 41 | 226 | void attachlist_page(void){ |
| 42 | 227 | const char *zPage = P("page"); |
| 43 | 228 | const char *zTkt = P("tkt"); |
| 44 | 229 | const char *zTechNote = P("technote"); |
| 230 | + const char *zForumPost = P("forumpost"); | |
| 231 | + char *zLink = 0; | |
| 45 | 232 | Blob sql; |
| 46 | 233 | Stmt q; |
| 47 | 234 | |
| 48 | 235 | if( zPage && zTkt ) zTkt = 0; |
| 49 | 236 | login_check_credentials(); |
| @@ -50,92 +237,161 @@ | ||
| 50 | 237 | style_set_current_feature("attach"); |
| 51 | 238 | blob_zero(&sql); |
| 52 | 239 | blob_append_sql(&sql, |
| 53 | 240 | "SELECT datetime(mtime,toLocal()), src, target, filename," |
| 54 | 241 | " comment, user," |
| 55 | - " (SELECT uuid FROM blob WHERE rid=attachid), attachid," | |
| 56 | - " (CASE WHEN 'tkt-'||target IN (SELECT tagname FROM tag)" | |
| 57 | - " THEN 1" | |
| 58 | - " WHEN 'event-'||target IN (SELECT tagname FROM tag)" | |
| 59 | - " THEN 2" | |
| 60 | - " ELSE 0 END)" | |
| 242 | + " (SELECT uuid FROM blob WHERE rid=attachid), attachid" | |
| 61 | 243 | " FROM attachment" |
| 62 | 244 | ); |
| 63 | - if( zPage ){ | |
| 245 | + if( zForumPost ){ | |
| 246 | + int fnid; | |
| 247 | + if( g.perm.RdForum==0 ){ login_needed(g.anon.RdForum); return; } | |
| 248 | + style_header("Attachments To Forum post %S", zForumPost); | |
| 249 | + fnid = forumpost_head_rid2(zForumPost); | |
| 250 | + if( fnid<=0 ){ | |
| 251 | + webpage_error("Invalid forum post ID: %h", zForumPost); | |
| 252 | + } | |
| 253 | + blob_append_sql(&sql, " WHERE target=" | |
| 254 | + "(SELECT uuid FROM blob WHERE rid=%d)", fnid); | |
| 255 | + zLink = mprintf("forum post <a href='%R/forumpost/%t'>%#h</a>", | |
| 256 | + zForumPost, hash_digits(0), zForumPost); | |
| 257 | + }else if( zPage ){ | |
| 64 | 258 | if( g.perm.RdWiki==0 ){ login_needed(g.anon.RdWiki); return; } |
| 65 | - style_header("Attachments To %h", zPage); | |
| 259 | + style_header("Attachments To Wiki page %h", zPage); | |
| 66 | 260 | blob_append_sql(&sql, " WHERE target=%Q", zPage); |
| 261 | + zLink = mprintf("wiki page <a href='%R/wiki?name=%t'>%h</a>", | |
| 262 | + zPage, zPage); | |
| 67 | 263 | }else if( zTkt ){ |
| 68 | 264 | if( g.perm.RdTkt==0 ){ login_needed(g.anon.RdTkt); return; } |
| 69 | 265 | style_header("Attachments To Ticket %S", zTkt); |
| 70 | 266 | blob_append_sql(&sql, " WHERE target GLOB '%q*'", zTkt); |
| 267 | + zLink = mprintf("ticket <a href='%R/tktview?name=%t'>%#h</a>", | |
| 268 | + zTkt, hash_digits(0), zTkt); | |
| 71 | 269 | }else if( zTechNote ){ |
| 72 | 270 | if( g.perm.RdWiki==0 ){ login_needed(g.anon.RdWiki); return; } |
| 73 | - style_header("Attachments to Tech Note %S", zTechNote); | |
| 271 | + style_header("Attachments To Tech Note %S", zTechNote); | |
| 74 | 272 | blob_append_sql(&sql, " WHERE target GLOB '%q*'", |
| 75 | 273 | zTechNote); |
| 274 | + zLink = mprintf("tech-note <a href='%R/technote?name=%t'>%#h</a>", | |
| 275 | + zTechNote, hash_digits(0), zTechNote); | |
| 76 | 276 | }else{ |
| 77 | 277 | if( g.perm.RdTkt==0 && g.perm.RdWiki==0 ){ |
| 78 | 278 | login_needed(g.anon.RdTkt || g.anon.RdWiki); |
| 79 | 279 | return; |
| 80 | 280 | } |
| 81 | 281 | style_header("All Attachments"); |
| 82 | 282 | } |
| 83 | 283 | blob_append_sql(&sql, " ORDER BY mtime DESC"); |
| 84 | 284 | db_prepare(&q, "%s", blob_sql_text(&sql)); |
| 285 | + | |
| 286 | + if( zLink ){ | |
| 287 | + @ <h2>Attachments for %s(zLink)</h2> | |
| 288 | + fossil_free(zLink); | |
| 289 | + zLink = 0; | |
| 290 | + } | |
| 291 | + | |
| 85 | 292 | @ <ol> |
| 86 | 293 | while( db_step(&q)==SQLITE_ROW ){ |
| 87 | - const char *zDate = db_column_text(&q, 0); | |
| 88 | - const char *zSrc = db_column_text(&q, 1); | |
| 89 | - const char *zTarget = db_column_text(&q, 2); | |
| 90 | - const char *zFilename = db_column_text(&q, 3); | |
| 91 | - const char *zComment = db_column_text(&q, 4); | |
| 92 | - const char *zUser = db_column_text(&q, 5); | |
| 93 | - const char *zUuid = db_column_text(&q, 6); | |
| 94 | - int attachid = db_column_int(&q, 7); | |
| 95 | - /* type 0 is a wiki page, 1 is a ticket, 2 is a tech note */ | |
| 96 | - int type = db_column_int(&q, 8); | |
| 97 | - const char *zDispUser = zUser && zUser[0] ? zUser : "anonymous"; | |
| 294 | + const char *zDate; | |
| 295 | + const char *zSrc; | |
| 296 | + const char *zTarget; | |
| 297 | + const char *zFilename; | |
| 298 | + const char *zComment; | |
| 299 | + const char *zUser; | |
| 300 | + const char *zUuid; | |
| 301 | + const char *zDispUser; | |
| 302 | + const int attachid = db_column_int(&q, 7); | |
| 303 | + int type; | |
| 98 | 304 | int i; |
| 99 | - char *zUrlTail; | |
| 305 | + int bDeleted; | |
| 306 | + char *zUrlTail = 0; | |
| 307 | + | |
| 308 | + if( moderation_pending(attachid) | |
| 309 | + && !moderation_user_could(attachid, 1, 0) ){ | |
| 310 | + /* Elide entries which are currently pending moderation unless | |
| 311 | + ** the user would be able to moderate the entry themselves. */ | |
| 312 | + continue; | |
| 313 | + } | |
| 314 | + | |
| 315 | + zDate = db_column_text(&q, 0); | |
| 316 | + zSrc = db_column_text(&q, 1); | |
| 317 | + zTarget = db_column_text(&q, 2); | |
| 318 | + zFilename = db_column_text(&q, 3); | |
| 319 | + zComment = db_column_text(&q, 4); | |
| 320 | + zUser = db_column_text(&q, 5); | |
| 321 | + zUuid = db_column_text(&q, 6); | |
| 322 | + zDispUser = zUser && zUser[0] ? zUser : "anonymous"; | |
| 100 | 323 | for(i=0; zFilename[i]; i++){ |
| 101 | 324 | if( zFilename[i]=='/' && zFilename[i+1]!=0 ){ |
| 102 | 325 | zFilename = &zFilename[i+1]; |
| 103 | 326 | i = -1; |
| 104 | 327 | } |
| 105 | 328 | } |
| 106 | - if( type==1 ){ | |
| 107 | - zUrlTail = mprintf("tkt=%s&file=%t", zTarget, zFilename); | |
| 108 | - }else if( type==2 ){ | |
| 109 | - zUrlTail = mprintf("technote=%s&file=%t", zTarget, zFilename); | |
| 110 | - }else{ | |
| 111 | - zUrlTail = mprintf("page=%t&file=%t", zTarget, zFilename); | |
| 329 | + bDeleted = 0==zSrc || 0==zSrc[0]; | |
| 330 | + type = attachment_target_type(zTarget, 1); | |
| 331 | + switch( type ){ | |
| 332 | + case CFTYPE_TICKET: | |
| 333 | + zUrlTail = mprintf("tkt=%s&file=%t", zTarget, zFilename); | |
| 334 | + break; | |
| 335 | + case CFTYPE_EVENT: | |
| 336 | + zUrlTail = mprintf("technote=%s&file=%t", zTarget, zFilename); | |
| 337 | + break; | |
| 338 | + case CFTYPE_FORUM: | |
| 339 | + zUrlTail = mprintf("forumpost=%t&file=%t", zTarget, zFilename); | |
| 340 | + break; | |
| 341 | + case CFTYPE_WIKI: | |
| 342 | + zUrlTail = mprintf("page=%t&file=%t", zTarget, zFilename); | |
| 343 | + break; | |
| 112 | 344 | } |
| 113 | 345 | @ <li><p> |
| 114 | - @ Attachment %z(href("%R/ainfo/%!S",zUuid))%S(zUuid)</a> | |
| 346 | + if( bDeleted ){ | |
| 347 | + @ <s>\ | |
| 348 | + } | |
| 349 | + @ Attachment %z(href("%R/ainfo/%!S",zUuid))%S(zUuid)</a>\ | |
| 115 | 350 | moderation_pending_www(attachid); |
| 116 | - @ <br><a href="%R/attachview?%s(zUrlTail)">%h(zFilename)</a> | |
| 117 | - @ [<a href="%R/attachdownload/%t(zFilename)?%s(zUrlTail)">download</a>]<br> | |
| 351 | + @ <br>\ | |
| 352 | + @ <a href="%R/attachview?%s(zUrlTail)">%h(zFilename)</a> | |
| 353 | + @ [<a href="%R/attachdownload/%t(zFilename)?%s(zUrlTail)">download</a>]\ | |
| 354 | + if( bDeleted ){ | |
| 355 | + @ </s> | |
| 356 | + } | |
| 357 | + @ <br> | |
| 118 | 358 | if( zComment ) while( fossil_isspace(zComment[0]) ) zComment++; |
| 119 | 359 | if( zComment && zComment[0] ){ |
| 120 | - @ %!W(zComment)<br> | |
| 360 | + /* FIXME (2026-06-05): Honor the N-card (comment mimetype). %W | |
| 361 | + ** (historically used here) assumes fossil-wiki and the | |
| 362 | + ** fileformat.wiki doc has always claimed that it defaults to | |
| 363 | + ** text/plain. /ainfo assumes it is plain text. */ | |
| 364 | + @ %h(zComment)<br> | |
| 121 | 365 | } |
| 122 | - if( zPage==0 && zTkt==0 && zTechNote==0 ){ | |
| 123 | - if( zSrc==0 || zSrc[0]==0 ){ | |
| 366 | + if( zForumPost==0 && zPage==0 && zTkt==0 && zTechNote==0 ){ | |
| 367 | + if( bDeleted ){ | |
| 124 | 368 | zSrc = "Deleted from"; |
| 125 | 369 | }else { |
| 126 | 370 | zSrc = "Added to"; |
| 127 | 371 | } |
| 128 | - if( type==1 ){ | |
| 129 | - @ %s(zSrc) ticket <a href="%R/tktview?name=%s(zTarget)"> | |
| 130 | - @ %S(zTarget)</a> | |
| 131 | - }else if( type==2 ){ | |
| 132 | - @ %s(zSrc) tech note <a href="%R/technote/%s(zTarget)"> | |
| 133 | - @ %S(zTarget)</a> | |
| 134 | - }else{ | |
| 135 | - @ %s(zSrc) wiki page <a href="%R/wiki?name=%t(zTarget)"> | |
| 136 | - @ %h(zTarget)</a> | |
| 372 | + switch( type ){ | |
| 373 | + case CFTYPE_TICKET: | |
| 374 | + @ %s(zSrc) ticket <a href="%R/tktview?name=%s(zTarget)"> | |
| 375 | + @ %S(zTarget)</a> | |
| 376 | + break; | |
| 377 | + case CFTYPE_EVENT: | |
| 378 | + @ %s(zSrc) tech note <a href="%R/technote/%s(zTarget)"> | |
| 379 | + @ %S(zTarget)</a> | |
| 380 | + break; | |
| 381 | + case CFTYPE_WIKI: | |
| 382 | + @ %s(zSrc) wiki page <a href="%R/wiki?name=%t(zTarget)"> | |
| 383 | + @ %h(zTarget)</a> | |
| 384 | + break; | |
| 385 | + case CFTYPE_FORUM: | |
| 386 | + @ %s(zSrc) forum post <a href="%R/forumpost/%s(zTarget)"> | |
| 387 | + @ %h(zTarget)</a> | |
| 388 | + break; | |
| 389 | + default: | |
| 390 | + @ <span class='error'>%s(zSrc) cannot determine target type | |
| 391 | + @ of %h(zTarget)</span> | |
| 392 | + break; | |
| 137 | 393 | } |
| 138 | 394 | }else{ |
| 139 | 395 | if( zSrc==0 || zSrc[0]==0 ){ |
| 140 | 396 | @ Deleted |
| 141 | 397 | }else { |
| @@ -162,27 +418,35 @@ | ||
| 162 | 418 | ** Query parameters: |
| 163 | 419 | ** |
| 164 | 420 | ** tkt=HASH |
| 165 | 421 | ** page=WIKIPAGE |
| 166 | 422 | ** technote=HASH |
| 423 | +** forumpost=HASH | |
| 167 | 424 | ** file=FILENAME |
| 168 | 425 | ** attachid=ID |
| 169 | 426 | ** |
| 170 | 427 | */ |
| 171 | 428 | void attachview_page(void){ |
| 172 | 429 | const char *zPage = P("page"); |
| 173 | 430 | const char *zTkt = P("tkt"); |
| 174 | 431 | const char *zTechNote = P("technote"); |
| 432 | + const char *zForumPost = P("forumpost"); | |
| 175 | 433 | const char *zFile = P("file"); |
| 176 | 434 | const char *zTarget = 0; |
| 177 | 435 | int attachid = atoi(PD("attachid","0")); |
| 178 | - char *zUUID; | |
| 436 | + char *zUUID = 0; | |
| 179 | 437 | |
| 180 | 438 | if( zFile==0 ) fossil_redirect_home(); |
| 181 | 439 | login_check_credentials(); |
| 182 | 440 | style_set_current_feature("attach"); |
| 183 | - if( zPage ){ | |
| 441 | + if( zForumPost ){ | |
| 442 | + int fnid; | |
| 443 | + if( g.perm.RdForum==0 ){ login_needed(g.anon.RdForum); return; } | |
| 444 | + /* Forum attachments are always tied to the post's initial version */ | |
| 445 | + fnid = forumpost_head_rid2(zForumPost); | |
| 446 | + if( fnid>0 ) zTarget = rid_to_uuid(fnid); | |
| 447 | + }else if( zPage ){ | |
| 184 | 448 | if( g.perm.RdWiki==0 ){ login_needed(g.anon.RdWiki); return; } |
| 185 | 449 | zTarget = zPage; |
| 186 | 450 | }else if( zTkt ){ |
| 187 | 451 | if( g.perm.RdTkt==0 ){ login_needed(g.anon.RdTkt); return; } |
| 188 | 452 | zTarget = zTkt; |
| @@ -275,84 +539,167 @@ | ||
| 275 | 539 | Manifest *pManifest; |
| 276 | 540 | |
| 277 | 541 | db_begin_transaction(); |
| 278 | 542 | blob_init(&content, aContent, szContent); |
| 279 | 543 | pManifest = manifest_parse(&content, 0, 0); |
| 544 | + addCompress = pManifest!=0; | |
| 280 | 545 | manifest_destroy(pManifest); |
| 281 | 546 | blob_init(&content, aContent, szContent); |
| 282 | - if( pManifest ){ | |
| 547 | + if( addCompress ){ | |
| 283 | 548 | blob_compress(&content, &content); |
| 284 | - addCompress = 1; | |
| 285 | 549 | } |
| 286 | 550 | rid = content_put_ex(&content, 0, 0, 0, needModerator); |
| 287 | - zUUID = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", rid); | |
| 551 | + zUUID = rid_to_uuid(rid); | |
| 288 | 552 | blob_zero(&manifest); |
| 289 | 553 | for(i=n=0; zName[i]; i++){ |
| 290 | 554 | if( zName[i]=='/' || zName[i]=='\\' ) n = i+1; |
| 291 | 555 | } |
| 292 | 556 | zName += n; |
| 293 | 557 | if( zName[0]==0 ) zName = "unknown"; |
| 294 | 558 | blob_appendf(&manifest, "A %F%s %F %s\n", |
| 295 | 559 | zName, addCompress ? ".gz" : "", zTarget, zUUID); |
| 296 | - while( fossil_isspace(zComment[0]) ) zComment++; | |
| 297 | - n = strlen(zComment); | |
| 298 | - while( n>0 && fossil_isspace(zComment[n-1]) ){ n--; } | |
| 299 | - if( n>0 ){ | |
| 300 | - blob_appendf(&manifest, "C %#F\n", n, zComment); | |
| 560 | + if( zComment!=0 && zComment[0]!=0 ){ | |
| 561 | + while( fossil_isspace(zComment[0]) ) zComment++; | |
| 562 | + n = strlen(zComment); | |
| 563 | + while( n>0 && fossil_isspace(zComment[n-1]) ){ n--; } | |
| 564 | + if( n>0 ){ | |
| 565 | + blob_appendf(&manifest, "C %#F\n", n, zComment); | |
| 566 | + } | |
| 301 | 567 | } |
| 302 | 568 | zDate = date_in_standard_format("now"); |
| 303 | - blob_appendf(&manifest, "D %s\n", zDate); | |
| 569 | + blob_appendf(&manifest, "D %z\n", zDate); | |
| 304 | 570 | blob_appendf(&manifest, "U %F\n", login_name()); |
| 305 | 571 | md5sum_blob(&manifest, &cksum); |
| 306 | 572 | blob_appendf(&manifest, "Z %b\n", &cksum); |
| 307 | 573 | attach_put(&manifest, rid, needModerator); |
| 308 | 574 | assert( blob_is_reset(&manifest) ); |
| 309 | 575 | db_end_transaction(0); |
| 310 | 576 | } |
| 577 | + | |
| 578 | +/* | |
| 579 | +** Renders the "legacy" (static) /attachadd form. One of the first | |
| 580 | +** four arguments must be non-NULL and the other three must be NULL. | |
| 581 | +** zComment may be NULL, as may zFrom. See the call sites for more | |
| 582 | +** context. | |
| 583 | +*/ | |
| 584 | +static void attach_render_legacy_form(const char *zForumPost, | |
| 585 | + const char *zTechNote, | |
| 586 | + const char *zTicket, | |
| 587 | + const char *zWikiPage, | |
| 588 | + const char *zComment, | |
| 589 | + const char *zFrom){ | |
| 590 | + form_begin("enctype='multipart/form-data' id='attachadd-legacy-form'", | |
| 591 | + "%R/attachadd"); | |
| 592 | + @ <div>\ | |
| 593 | + @ File to Attach: | |
| 594 | + @ <input type="file" name="f" size="60"><br> | |
| 595 | + @ Description:<br> | |
| 596 | + @ <textarea name="comment" cols="80" rows="5" wrap="virtual"\ | |
| 597 | + @ >%h(zComment)</textarea><br> | |
| 598 | + if( zForumPost ){ | |
| 599 | + @ <input type="hidden" name="forumpost" value="%h(zForumPost)">\ | |
| 600 | + }else if( zTicket ){ | |
| 601 | + @ <input type="hidden" name="tkt" value="%h(zTicket)">\ | |
| 602 | + }else if( zTechNote ){ | |
| 603 | + @ <input type="hidden" name="technote" value="%h(zTechNote)">\ | |
| 604 | + }else if( zWikiPage ){ | |
| 605 | + @ <input type="hidden" name="page" value="%h(zWikiPage)">\ | |
| 606 | + } | |
| 607 | + @ <input type="hidden" name="from" value="%h(zFrom)">\ | |
| 608 | + @ <input type="submit" name="ok" value="Add Attachment">\ | |
| 609 | + @ <input type="submit" name="cancel" value="Cancel">\ | |
| 610 | + @ </div> | |
| 611 | + captcha_generate(0); | |
| 612 | + login_insert_csrf_secret(); | |
| 613 | + @ </form> | |
| 614 | +} | |
| 311 | 615 | |
| 312 | 616 | /* |
| 313 | 617 | ** WEBPAGE: attachadd |
| 314 | 618 | ** Add a new attachment. |
| 315 | 619 | ** |
| 316 | 620 | ** tkt=HASH |
| 317 | 621 | ** page=WIKIPAGE |
| 318 | 622 | ** technote=HASH |
| 623 | +** forumpost=HASH | |
| 319 | 624 | ** from=URL |
| 320 | 625 | ** |
| 626 | +** Adds a POSTed file attachment to the given target. | |
| 627 | +** | |
| 628 | +** Or the "version 2" interface: | |
| 629 | +** | |
| 630 | +** target=ATTACHMENT_TARGET | |
| 631 | +** | |
| 632 | +** Behaves as documented for attachaddV2_page(). | |
| 321 | 633 | */ |
| 322 | 634 | void attachadd_page(void){ |
| 323 | - const char *zPage = P("page"); | |
| 324 | - const char *zTkt = P("tkt"); | |
| 325 | - const char *zTechNote = P("technote"); | |
| 326 | - const char *zFrom = P("from"); | |
| 327 | - const char *aContent = P("f"); | |
| 328 | - const char *zName = PD("f:filename","unknown"); | |
| 635 | + const char *zPage; | |
| 636 | + const char *zForumPost; | |
| 637 | + const char *zTkt; | |
| 638 | + const char *zTechNote; | |
| 639 | + const char *aContent; | |
| 640 | + const char *zName; | |
| 641 | + const char *zComment; | |
| 329 | 642 | const char *zTarget; |
| 330 | - char *zTargetType; | |
| 331 | - int szContent = atoi(PD("f:bytes","0")); | |
| 643 | + const char *zFrom; /* Origin page - redirect here after saving */ | |
| 644 | + char *zTo = 0; /* Optionally redirect here after saving */ | |
| 645 | + char *zTargetType = 0; | |
| 646 | + char *zExtraFree = 0; | |
| 647 | + int szContent; | |
| 332 | 648 | int goodCaptcha = 1; |
| 649 | + int szLimit = 0; | |
| 650 | + | |
| 651 | + if( P("target")!=0 ){ | |
| 652 | + attachaddV2_page(); | |
| 653 | + return; | |
| 654 | + } | |
| 655 | + zPage = P("page"); | |
| 656 | + zForumPost = P("forumpost"); | |
| 657 | + zTkt = P("tkt"); | |
| 658 | + zTechNote = P("technote"); | |
| 659 | + zFrom = P("from"); | |
| 660 | + aContent = P("f"); | |
| 661 | + zName = PD("f:filename","unknown"); | |
| 662 | + zComment = PD("comment", ""); | |
| 663 | + szContent = atoi(PD("f:bytes","0")); | |
| 333 | 664 | |
| 665 | + if( zFrom==0 ) zFrom = mprintf("%R/home"); | |
| 334 | 666 | if( P("cancel") ) cgi_redirect(zFrom); |
| 335 | - if( (zPage && zTkt) | |
| 336 | - || (zPage && zTechNote) | |
| 337 | - || (zTkt && zTechNote) | |
| 338 | - ){ | |
| 339 | - fossil_redirect_home(); | |
| 667 | + if( (!!zPage + !!zTkt + !!zTechNote + !!zForumPost)!=1 ){ | |
| 668 | + webpage_error("Requires exactly one one: page=X, tkt=X, forumpost=X," | |
| 669 | + " technote=X, or target=X"); | |
| 340 | 670 | } |
| 341 | - if( zPage==0 && zTkt==0 && zTechNote==0) fossil_redirect_home(); | |
| 342 | 671 | login_check_credentials(); |
| 343 | - if( zPage ){ | |
| 672 | + if( zForumPost ){ | |
| 673 | + int fpid; | |
| 674 | + if( g.perm.AttachForum==0 ){ | |
| 675 | + login_needed(g.anon.AttachForum); | |
| 676 | + return; | |
| 677 | + } | |
| 678 | + fpid = forumpost_head_rid2(zForumPost); | |
| 679 | + if( fpid<=0 ){ | |
| 680 | + webpage_error("Invalid forum post ID: %h", zForumPost); | |
| 681 | + }else if( !g.perm.Admin && !forumpost_is_owner(fpid, 0) ){ | |
| 682 | + webpage_error("Only admins can attach files to other users' " | |
| 683 | + "forum posts."); | |
| 684 | + } | |
| 685 | + zTarget = zExtraFree = rid_to_uuid(fpid); | |
| 686 | + zTargetType = mprintf("Forum post <a href=\"%R/forumpost/%S\">%h</a>", | |
| 687 | + zTarget, zForumPost); | |
| 688 | + zTo = zFrom ? 0 : mprintf("%R/forumpost/%S", zTarget); | |
| 689 | + }else if( zPage ){ | |
| 344 | 690 | if( g.perm.ApndWiki==0 || g.perm.Attach==0 ){ |
| 345 | 691 | login_needed(g.anon.ApndWiki && g.anon.Attach); |
| 346 | 692 | return; |
| 347 | 693 | } |
| 348 | 694 | if( !db_exists("SELECT 1 FROM tag WHERE tagname='wiki-%q'", zPage) ){ |
| 349 | 695 | fossil_redirect_home(); |
| 350 | 696 | } |
| 351 | 697 | zTarget = zPage; |
| 352 | - zTargetType = mprintf("Wiki Page <a href=\"%R/wiki?name=%h\">%h</a>", | |
| 698 | + zTargetType = mprintf("Wiki Page <a href=\"%R/wiki?name=%t\">%h</a>", | |
| 353 | 699 | zPage, zPage); |
| 700 | + zTo = zFrom ? 0 : mprintf("%R/wiki?name=%T", zTarget); | |
| 354 | 701 | }else if ( zTechNote ){ |
| 355 | 702 | if( g.perm.Write==0 || g.perm.ApndWiki==0 || g.perm.Attach==0 ){ |
| 356 | 703 | login_needed(g.anon.Write && g.anon.ApndWiki && g.anon.Attach); |
| 357 | 704 | return; |
| 358 | 705 | } |
| @@ -362,12 +709,13 @@ | ||
| 362 | 709 | if( zTechNote==0) fossil_redirect_home(); |
| 363 | 710 | } |
| 364 | 711 | zTarget = zTechNote; |
| 365 | 712 | zTargetType = mprintf("Tech Note <a href=\"%R/technote/%s\">%S</a>", |
| 366 | 713 | zTechNote, zTechNote); |
| 367 | - | |
| 714 | + zTo = zFrom ? 0 : mprintf("%R/technote/%S", zTarget); | |
| 368 | 715 | }else{ |
| 716 | + assert( zTkt ); | |
| 369 | 717 | if( g.perm.ApndTkt==0 || g.perm.Attach==0 ){ |
| 370 | 718 | login_needed(g.anon.ApndTkt && g.anon.Attach); |
| 371 | 719 | return; |
| 372 | 720 | } |
| 373 | 721 | if( !db_exists("SELECT 1 FROM tag WHERE tagname='tkt-%q'", zTkt) ){ |
| @@ -374,56 +722,409 @@ | ||
| 374 | 722 | zTkt = db_text(0, "SELECT substr(tagname,5) FROM tag" |
| 375 | 723 | " WHERE tagname GLOB 'tkt-%q*'", zTkt); |
| 376 | 724 | if( zTkt==0 ) fossil_redirect_home(); |
| 377 | 725 | } |
| 378 | 726 | zTarget = zTkt; |
| 379 | - zTargetType = mprintf("Ticket <a href=\"%R/tktview/%s\">%S</a>", | |
| 727 | + zTargetType = mprintf("Ticket <a href=\"%R/tktview/%S\">%S</a>", | |
| 380 | 728 | zTkt, zTkt); |
| 729 | + zTo = zFrom ? 0 : mprintf("%R/tktview/%S", zTarget); | |
| 381 | 730 | } |
| 382 | - if( zFrom==0 ) zFrom = mprintf("%R/home"); | |
| 383 | - if( P("cancel") ){ | |
| 384 | - cgi_redirect(zFrom); | |
| 385 | - } | |
| 386 | - if( P("ok") && szContent>0 && (goodCaptcha = captcha_is_correct(0)) ){ | |
| 387 | - int needModerator = (zTkt!=0 && ticket_need_moderation(0)) || | |
| 731 | + szLimit = db_get_int("attachment-size-limit", 0); | |
| 732 | + if( szContent<0 || (szLimit && szContent>szLimit) ){ | |
| 733 | + /* This check must be done late so that zTargetType is set up. */ | |
| 734 | + @ <p class="generalError">Attachment %h(zName) is too large. | |
| 735 | + @ <a href="%R/help/attachment-size-limit">Limit</a> is | |
| 736 | + @ %d(szLimit ? szLimit : 0x7fffffff) bytes</p> | |
| 737 | + /* Fall through and render form. */ | |
| 738 | + }else if( P("ok") | |
| 739 | + && cgi_csrf_safe(2) | |
| 740 | + && szContent>0 | |
| 741 | + && (goodCaptcha = captcha_is_correct(0)) ){ | |
| 742 | + int needModerator = (zForumPost!=0 && forum_need_moderation()) || | |
| 743 | + (zTkt!=0 && ticket_need_moderation(0)) || | |
| 388 | 744 | (zPage!=0 && wiki_need_moderation(0)); |
| 389 | - const char *zComment = PD("comment", ""); | |
| 390 | 745 | attach_commit(zName, zTarget, aContent, szContent, needModerator, zComment); |
| 391 | - cgi_redirect(zFrom); | |
| 746 | + cgi_redirect(zTo ? zTo : zFrom); | |
| 392 | 747 | } |
| 748 | + | |
| 393 | 749 | style_set_current_feature("attach"); |
| 394 | 750 | style_header("Add Attachment"); |
| 395 | 751 | if( !goodCaptcha ){ |
| 396 | 752 | @ <p class="generalError">Error: Incorrect security code.</p> |
| 397 | 753 | } |
| 398 | 754 | @ <h2>Add Attachment To %s(zTargetType)</h2> |
| 399 | - form_begin("enctype='multipart/form-data'", "%R/attachadd"); | |
| 400 | - @ <div> | |
| 401 | - @ File to Attach: | |
| 402 | - @ <input type="file" name="f" size="60"><br> | |
| 403 | - @ Description:<br> | |
| 404 | - @ <textarea name="comment" cols="80" rows="5" wrap="virtual"></textarea><br> | |
| 405 | - if( zTkt ){ | |
| 406 | - @ <input type="hidden" name="tkt" value="%h(zTkt)"> | |
| 407 | - }else if( zTechNote ){ | |
| 408 | - @ <input type="hidden" name="technote" value="%h(zTechNote)"> | |
| 755 | + attach_render_legacy_form(zForumPost, zTechNote, zTkt, zPage, | |
| 756 | + zComment, zFrom); | |
| 757 | + builtin_fossil_js_bundle_or("attach", NULL); | |
| 758 | + style_finish_page(); | |
| 759 | + fossil_free(zTargetType); | |
| 760 | + fossil_free(zExtraFree); | |
| 761 | +} | |
| 762 | + | |
| 763 | +/* | |
| 764 | +** WEBPAGE: attachadd_ajax_post hidden | |
| 765 | +** | |
| 766 | +** Used by attachadd V2 to handle attachments via POST requests with: | |
| 767 | +** | |
| 768 | +** target=ATTACHMENT_TARGET | |
| 769 | +** file1..fileN=FILE_OBJECTS | |
| 770 | +** dryrun=0|1 | |
| 771 | +** | |
| 772 | +** Each posted file in the set file1..fileN gets attached to the given | |
| 773 | +** target, permissions permitting. If dryrun>0 then the change is | |
| 774 | +** rolled back instead of committed. target=X must refer to a full | |
| 775 | +** target ID, not a prefix. | |
| 776 | +** | |
| 777 | +** Responds with JSON: an empty object on success and | |
| 778 | +** {error:"message"} on error. The on-success response structure is | |
| 779 | +** subject to amendment. | |
| 780 | +*/ | |
| 781 | +void attachadd_ajax_post(void){ | |
| 782 | + const char *zTarget; | |
| 783 | + char *zExtraFree = 0; | |
| 784 | + int eTgtType = 0; | |
| 785 | + int bNeedsModeration = 0; | |
| 786 | + int goodCaptcha = 1; | |
| 787 | + int bRollback = 0; /* Roll back if true. */ | |
| 788 | + | |
| 789 | + if( ! ajax_route_bootstrap(0, 1) ){ | |
| 790 | + return; | |
| 791 | + }else if( !(goodCaptcha = captcha_is_correct(0)) ){ | |
| 792 | + goto ajax_err_403; | |
| 793 | + }else if( !ajax_check_csrf(2) ){ | |
| 794 | + return; | |
| 795 | + } | |
| 796 | + db_begin_transaction(); | |
| 797 | + zTarget = P("target"); | |
| 798 | + eTgtType = attachment_target_type(zTarget, 1); | |
| 799 | + CX("{"); | |
| 800 | + switch( eTgtType ){ | |
| 801 | + default: | |
| 802 | + case 0: | |
| 803 | + ajax_route_error(400, "Invalid attachment target."); | |
| 804 | + db_rollback_transaction(); | |
| 805 | + return; | |
| 806 | + case CFTYPE_FORUM:{ | |
| 807 | + int fpid; | |
| 808 | + if( g.perm.AttachForum==0 ){ | |
| 809 | + goto ajax_err_403; | |
| 810 | + } | |
| 811 | + fpid = forumpost_head_rid2(zTarget); | |
| 812 | + if( fpid<=0 ){ | |
| 813 | + goto ajax_err_404; | |
| 814 | + }else if( !g.perm.Admin && !forumpost_is_owner(fpid, 0) ){ | |
| 815 | + ajax_route_error(403, "Only admins can attach files to " | |
| 816 | + "other users' forum posts."); | |
| 817 | + db_rollback_transaction(); | |
| 818 | + return; | |
| 819 | + } | |
| 820 | + zTarget = zExtraFree = rid_to_uuid(fpid); | |
| 821 | + bNeedsModeration = forum_need_moderation(); | |
| 822 | + break; | |
| 823 | + } | |
| 824 | + case CFTYPE_EVENT:{ | |
| 825 | + if( g.perm.Write==0 || g.perm.ApndWiki==0 || g.perm.Attach==0 ){ | |
| 826 | + goto ajax_err_403; | |
| 827 | + } | |
| 828 | + if( !db_exists("SELECT 1 FROM tag WHERE tagname='event-%q'", | |
| 829 | + zTarget) ){ | |
| 830 | + zTarget = zExtraFree = | |
| 831 | + db_text(0, "SELECT substr(tagname,7) FROM tag" | |
| 832 | + " WHERE tagname GLOB 'event-%q*'", zTarget); | |
| 833 | + if( zTarget==0){ | |
| 834 | + goto ajax_err_404; | |
| 835 | + } | |
| 836 | + } | |
| 837 | + bNeedsModeration = 0; | |
| 838 | + break; | |
| 839 | + } | |
| 840 | + case CFTYPE_TICKET:{ | |
| 841 | + if( g.perm.ApndTkt==0 || g.perm.Attach==0 ){ | |
| 842 | + goto ajax_err_403; | |
| 843 | + } | |
| 844 | + if( !db_exists("SELECT 1 FROM tag WHERE tagname='tkt-%q'", | |
| 845 | + zTarget) ){ | |
| 846 | + zTarget = db_text(0, "SELECT substr(tagname,5) FROM tag" | |
| 847 | + " WHERE tagname GLOB 'tkt-%q*'", zTarget); | |
| 848 | + if( zTarget==0 ){ | |
| 849 | + goto ajax_err_404; | |
| 850 | + } | |
| 851 | + } | |
| 852 | + bNeedsModeration = ticket_need_moderation(0); | |
| 853 | + break; | |
| 854 | + } | |
| 855 | + case CFTYPE_WIKI:{ | |
| 856 | + if( g.perm.ApndWiki==0 || g.perm.Attach==0 ){ | |
| 857 | + goto ajax_err_403; | |
| 858 | + } | |
| 859 | + if( !db_exists("SELECT 1 FROM tag WHERE tagname='wiki-%q'", | |
| 860 | + zTarget) ){ | |
| 861 | + goto ajax_err_404; | |
| 862 | + } | |
| 863 | + bNeedsModeration = wiki_need_moderation(0); | |
| 864 | + break; | |
| 865 | + } | |
| 866 | + } | |
| 867 | + | |
| 868 | + if( attachments_ajax_from_POST(zTarget, bNeedsModeration)>=0 ){ | |
| 869 | + CX("}"); | |
| 870 | + if( atoi(PD("dryrun","0"))>0 ){ | |
| 871 | + bRollback = 1; | |
| 872 | + } | |
| 873 | + }/*else error response was set up*/ | |
| 874 | + fossil_free(zExtraFree); | |
| 875 | + db_end_transaction(bRollback); | |
| 876 | + return; | |
| 877 | +ajax_err_403: | |
| 878 | + if( db_transaction_nesting_depth()>0 ){ | |
| 879 | + db_rollback_transaction(); | |
| 880 | + } | |
| 881 | + ajax_route_error_forbidden(); | |
| 882 | + return; | |
| 883 | +ajax_err_404: | |
| 884 | + assert( db_transaction_nesting_depth()>0 ); | |
| 885 | + db_rollback_transaction(); | |
| 886 | + ajax_route_error(404, "Target not found."); | |
| 887 | + return; | |
| 888 | +} | |
| 889 | + | |
| 890 | +/* | |
| 891 | +** A helper for AJAX-style routines which accept file attachments via | |
| 892 | +** POST. zTarget must be a full attachment target. bNeedsModeration | |
| 893 | +** must be true if the attachment requires moderation. | |
| 894 | +** | |
| 895 | +** It is up to the caller to have validated all security measures | |
| 896 | +** before calling this. | |
| 897 | +** | |
| 898 | +** This looks for POSTed files names "file1".."fileN", stopping when | |
| 899 | +** it finds no entry. Returns the number of entries attached to the | |
| 900 | +** target or a negative value on error (in which case the current db | |
| 901 | +** transaction will be in a rollback state). | |
| 902 | +** | |
| 903 | +** The only errors are currently attachment size limit violations: | |
| 904 | +** attachments must have a non-0 size and if the attachment-size-limit | |
| 905 | +** setting is >0 then each file's size must be <= that. | |
| 906 | +** | |
| 907 | +** If this returns a negative value, it will have populated an error | |
| 908 | +** response using ajax_route_error(). On success it produces no | |
| 909 | +** output. | |
| 910 | +** | |
| 911 | +** ACHTUNG: if zTarget is a forum post, it "really should" be the ID | |
| 912 | +** of the first version of that post, as that's where attachments are | |
| 913 | +** intended to be applied so that they can be found and removed | |
| 914 | +** consistently. Potential TODO is have this function do that if | |
| 915 | +** attachment_target_type(zTarget,1)!=0 but it would (for current | |
| 916 | +** uses) require duplicating work already done in the callers. | |
| 917 | +*/ | |
| 918 | +int attachments_ajax_from_POST(const char *zTarget, int bNeedsModeration){ | |
| 919 | + int i; | |
| 920 | + int rc = 0; | |
| 921 | + int n = 0; | |
| 922 | + int szLimit; /* attachment-max-size setting */ | |
| 923 | + char aKeyPrefix[20]; /* Buffer for key "file%d" */ | |
| 924 | + char aKeySize[30]; /* Buffer for key "file%d:bytes" */ | |
| 925 | + char aKeyName[30]; /* Buffer for key "file%d:filename" */ | |
| 926 | + char aKeyDesc[30]; /* Buffer for key "file%d_desc" */ | |
| 927 | + | |
| 928 | + db_begin_transaction(); | |
| 929 | + szLimit = db_get_int("attachment-size-limit", 0); | |
| 930 | + | |
| 931 | + for(i = 1; ; ++i, ++n){ | |
| 932 | + /* Look for P("fileN"), where N=1..n */ | |
| 933 | + const char *zContent; | |
| 934 | + const char *zFilename; | |
| 935 | + int szContent; | |
| 936 | + sqlite3_snprintf(sizeof(aKeyPrefix), aKeyPrefix, "file%d", i); | |
| 937 | + zContent = P(aKeyPrefix); | |
| 938 | + if( !zContent ){ | |
| 939 | + /* End of the list. */ | |
| 940 | + break; | |
| 941 | + } | |
| 942 | + sqlite3_snprintf(sizeof(aKeySize), aKeySize, "%s:bytes", | |
| 943 | + aKeyPrefix); | |
| 944 | + szContent = atoi(PD(aKeySize,"-1")); | |
| 945 | + if( szContent<=0 ){ | |
| 946 | + rc = -ajax_route_error(400,"Invalid file size: %d", szContent); | |
| 947 | + break; | |
| 948 | + }else if( szLimit>0 && szContent>szLimit ){ | |
| 949 | + rc = -ajax_route_error(413, "File size limit is %d bytes.", szLimit); | |
| 950 | + break; | |
| 951 | + }else{ | |
| 952 | + sqlite3_snprintf(sizeof(aKeyName), aKeyName, "%s:filename", | |
| 953 | + aKeyPrefix); | |
| 954 | + sqlite3_snprintf(sizeof(aKeyDesc), aKeyDesc, "%s_desc", | |
| 955 | + aKeyPrefix); | |
| 956 | + if( 0==(zFilename=P(aKeyName)) ){ | |
| 957 | + rc = -ajax_route_error(400, "Missing filename."); | |
| 958 | + break; | |
| 959 | + } | |
| 960 | + attach_commit(zFilename, zTarget, zContent, szContent, | |
| 961 | + bNeedsModeration, P(aKeyDesc)); | |
| 962 | + } | |
| 963 | + } | |
| 964 | + if( rc<0 ){ | |
| 965 | + db_rollback_transaction(); | |
| 966 | + return rc; | |
| 409 | 967 | }else{ |
| 410 | - @ <input type="hidden" name="page" value="%h(zPage)"> | |
| 968 | + db_commit_transaction(); | |
| 969 | + return n; | |
| 970 | + } | |
| 971 | +} | |
| 972 | + | |
| 973 | +/* | |
| 974 | +** Proxy for /attachadd?target=X | |
| 975 | +** | |
| 976 | +** Lists attachments for, and can add them to, a target artifact. | |
| 977 | +** | |
| 978 | +** target=TKT_HASH|WIKIPAGE_NAME|TECHNOTE_HASH|FORUMPOST_HASH | |
| 979 | +** from=ORIGINATING_URL | |
| 980 | +** | |
| 981 | +** Works like /attachadd but uses a JS-based interactive attachment | |
| 982 | +** selector. | |
| 983 | +** | |
| 984 | +** from=X tells it where to redirect to when it's done. | |
| 985 | +** | |
| 986 | +** This page requires a post-2018-ish JS-capable browser. | |
| 987 | +*/ | |
| 988 | +void attachaddV2_page(void){ | |
| 989 | + const char *zFrom = P("from"); | |
| 990 | + const char *zTarget = P("target"); | |
| 991 | + char *zTo = 0; | |
| 992 | + char *zTargetType = 0; | |
| 993 | + char *zExtraFree = 0; | |
| 994 | + int eTgtType = 0; | |
| 995 | + int goodCaptcha = 1; | |
| 996 | + char const * noJsArgs[] = {0,0,0,0}; /* Args for noscript form */ | |
| 997 | + | |
| 998 | + if( P("cancel") ) cgi_redirect(zFrom); | |
| 999 | + if( 0==zTarget ){ | |
| 1000 | + webpage_error("Requires target=X"); | |
| 1001 | + } | |
| 1002 | + login_check_credentials(); | |
| 1003 | + eTgtType = attachment_target_type(zTarget, 1); | |
| 1004 | + switch( eTgtType ){ | |
| 1005 | + default: | |
| 1006 | + case 0: | |
| 1007 | + webpage_error("Cannot resolve target=%h.", zTarget); | |
| 1008 | + break; | |
| 1009 | + case CFTYPE_FORUM:{ | |
| 1010 | + int fpid; | |
| 1011 | + if( g.perm.AttachForum==0 ){ | |
| 1012 | + login_needed(g.anon.AttachForum); | |
| 1013 | + return; | |
| 1014 | + } | |
| 1015 | + fpid = forumpost_head_rid2(zTarget); | |
| 1016 | + if( fpid<=0 ){ | |
| 1017 | + webpage_error("Invalid forum post ID: %h", zTarget); | |
| 1018 | + }else if( !g.perm.Admin && !forumpost_is_owner(fpid, 0) ){ | |
| 1019 | + webpage_error("Only admins can attach files to other users' " | |
| 1020 | + "forum posts."); | |
| 1021 | + } | |
| 1022 | + zTarget = zExtraFree = rid_to_uuid(fpid); | |
| 1023 | + noJsArgs[0] = zTarget; | |
| 1024 | + zTargetType = mprintf( | |
| 1025 | + "Forum post <a href=\"%R/forumpost/%S\">%.16h</a>", | |
| 1026 | + zTarget, zTarget | |
| 1027 | + ); | |
| 1028 | + zTo = mprintf("%R/forumpost/%S", zTarget); | |
| 1029 | + break; | |
| 1030 | + } | |
| 1031 | + case CFTYPE_EVENT:{ | |
| 1032 | + if( g.perm.Write==0 || g.perm.ApndWiki==0 || g.perm.Attach==0 ){ | |
| 1033 | + login_needed(g.anon.Write && g.anon.ApndWiki && g.anon.Attach); | |
| 1034 | + return; | |
| 1035 | + } | |
| 1036 | + if( !db_exists("SELECT 1 FROM tag WHERE tagname='event-%q'", | |
| 1037 | + zTarget) ){ | |
| 1038 | + zTarget = db_text(0, "SELECT substr(tagname,7) FROM tag" | |
| 1039 | + " WHERE tagname GLOB 'event-%q*'", | |
| 1040 | + zTarget); | |
| 1041 | + if( zTarget==0) fossil_redirect_home(); | |
| 1042 | + } | |
| 1043 | + zTo = zFrom ? 0 : mprintf("%R/technote?name=%T", zTarget); | |
| 1044 | + zTargetType = mprintf("Tech-note <a href=\"%R/technote/%s\">%S</a>", | |
| 1045 | + zTarget, zTarget); | |
| 1046 | + noJsArgs[1] = zTarget; | |
| 1047 | + break; | |
| 1048 | + } | |
| 1049 | + case CFTYPE_TICKET:{ | |
| 1050 | + if( g.perm.ApndTkt==0 || g.perm.Attach==0 ){ | |
| 1051 | + login_needed(g.anon.ApndTkt && g.anon.Attach); | |
| 1052 | + return; | |
| 1053 | + } | |
| 1054 | + if( !db_exists("SELECT 1 FROM tag WHERE tagname='tkt-%q'", | |
| 1055 | + zTarget) ){ | |
| 1056 | + zTarget = db_text(0, "SELECT substr(tagname,5) FROM tag" | |
| 1057 | + " WHERE tagname GLOB 'tkt-%q*'", zTarget); | |
| 1058 | + if( zTarget==0 ) fossil_redirect_home(); | |
| 1059 | + } | |
| 1060 | + zTo = zFrom ? 0 : mprintf("%R/tktview/%t", zTarget); | |
| 1061 | + zTargetType = mprintf("Ticket <a href=\"%R/tktview/%s\">%S</a>", | |
| 1062 | + zTarget, zTarget); | |
| 1063 | + noJsArgs[2] = zTarget; | |
| 1064 | + break; | |
| 1065 | + } | |
| 1066 | + case CFTYPE_WIKI:{ | |
| 1067 | + if( g.perm.ApndWiki==0 || g.perm.Attach==0 ){ | |
| 1068 | + login_needed(g.anon.ApndWiki && g.anon.Attach); | |
| 1069 | + return; | |
| 1070 | + } | |
| 1071 | + if( !db_exists("SELECT 1 FROM tag WHERE tagname='wiki-%q'", | |
| 1072 | + zTarget) ){ | |
| 1073 | + fossil_redirect_home(); | |
| 1074 | + } | |
| 1075 | + zTo = zFrom ? 0 : mprintf("%R/wiki?name=%T", zTarget); | |
| 1076 | + zTargetType = mprintf( | |
| 1077 | + "Wiki page <a href=\"%R/wiki?name=%h\">%h</a>", | |
| 1078 | + zTarget, zTarget | |
| 1079 | + ); | |
| 1080 | + noJsArgs[3] = zTarget; | |
| 1081 | + break; | |
| 1082 | + } | |
| 1083 | + } | |
| 1084 | + | |
| 1085 | + db_begin_transaction(); | |
| 1086 | + | |
| 1087 | + style_set_current_feature("attach"); | |
| 1088 | + style_header("Add Attachment"); | |
| 1089 | + if( !goodCaptcha ){ | |
| 1090 | + @ <p class="generalError">Error: Incorrect security code.</p> | |
| 1091 | + } | |
| 1092 | + @ <h2>Attachments for %s(zTargetType)</h2> | |
| 1093 | + attachment_list(zTarget, NULL, | |
| 1094 | + ATTACHLIST_SIZE | ATTACHLIST_HIDE_UNAPPROVED); | |
| 1095 | + attach_render_legacy_form( | |
| 1096 | + noJsArgs[0], noJsArgs[1], noJsArgs[2], | |
| 1097 | + noJsArgs[3], 0, | |
| 1098 | + zFrom ? zFrom : (zTo ? zTo : (zTo=mprintf("%R/home"))) | |
| 1099 | + ); | |
| 1100 | + @ <div id='attachadd-form-wrapper' class='hidden'> | |
| 1101 | + /* fossil.attach.js populates this DIV with the attachment widget, | |
| 1102 | + ** imports these hidden fields, and removes the legacy form. */ | |
| 1103 | + @ <input type="hidden" name="target" value="%h(zTarget)"> | |
| 1104 | + if( zFrom ){ | |
| 1105 | + @ <input type="hidden" name="from" value="%h(zFrom)"> | |
| 411 | 1106 | } |
| 412 | - @ <input type="hidden" name="from" value="%h(zFrom)"> | |
| 413 | - @ <input type="submit" name="ok" value="Add Attachment"> | |
| 414 | - @ <input type="submit" name="cancel" value="Cancel"> | |
| 415 | - @ </div> | |
| 1107 | + if( zTo ){ | |
| 1108 | + @ <input type="hidden" name="to" value="%h(zTo)"> | |
| 1109 | + } | |
| 416 | 1110 | captcha_generate(0); |
| 417 | - @ </form> | |
| 1111 | + login_insert_csrf_secret(); | |
| 1112 | + @ </div> | |
| 1113 | + builtin_fossil_js_bundle_or("attach", NULL); | |
| 1114 | + db_end_transaction(0); | |
| 418 | 1115 | style_finish_page(); |
| 419 | 1116 | fossil_free(zTargetType); |
| 1117 | + fossil_free(zExtraFree); | |
| 1118 | + fossil_free(zTo); | |
| 420 | 1119 | } |
| 421 | 1120 | |
| 422 | 1121 | /* |
| 423 | 1122 | ** WEBPAGE: ainfo |
| 424 | 1123 | ** URL: /ainfo?name=ARTIFACTID |
| 1124 | +** | |
| 1125 | +** name=ATTACHMENT_ARTIFACT_UUID | |
| 425 | 1126 | ** |
| 426 | 1127 | ** Show the details of an attachment artifact. |
| 427 | 1128 | */ |
| 428 | 1129 | void ainfo_page(void){ |
| 429 | 1130 | int rid; /* RID for the control artifact */ |
| @@ -436,113 +1137,145 @@ | ||
| 436 | 1137 | const char *zName; /* Name of the attached file */ |
| 437 | 1138 | const char *zDesc; /* Description of the attached file */ |
| 438 | 1139 | const char *zWikiName = 0; /* Wiki page name when attached to Wiki */ |
| 439 | 1140 | const char *zTNUuid = 0; /* Tech Note ID when attached to tech note */ |
| 440 | 1141 | const char *zTktUuid = 0; /* Ticket ID when attached to a ticket */ |
| 1142 | + const char *zForumPost = 0; /* Forum UID when attached to forum post */ | |
| 441 | 1143 | int modPending; /* True if awaiting moderation */ |
| 442 | 1144 | const char *zModAction; /* Moderation action or NULL */ |
| 443 | 1145 | int isModerator; /* TRUE if user is the moderator */ |
| 444 | 1146 | const char *zMime; /* MIME Type */ |
| 445 | 1147 | Blob attach; /* Content of the attachment */ |
| 446 | - int fShowContent = 0; | |
| 1148 | + int fShowContent = 0; /* True to emit the content */ | |
| 1149 | + int bUserIsOwner = 0; /* True if pAttach->zUser is login_name() */ | |
| 1150 | + int showDelMenu = 0; /* True to enable delete option */ | |
| 447 | 1151 | const char *zLn = P("ln"); |
| 448 | 1152 | |
| 449 | 1153 | login_check_credentials(); |
| 450 | 1154 | if( !g.perm.RdTkt && !g.perm.RdWiki ){ |
| 451 | 1155 | login_needed(g.anon.RdTkt || g.anon.RdWiki); |
| 452 | 1156 | return; |
| 453 | 1157 | } |
| 454 | 1158 | rid = name_to_rid_www("name"); |
| 455 | 1159 | if( rid==0 ){ fossil_redirect_home(); } |
| 456 | - zUuid = db_text("", "SELECT uuid FROM blob WHERE rid=%d", rid); | |
| 1160 | + zUuid = rid_to_uuid(rid); | |
| 457 | 1161 | pAttach = manifest_get(rid, CFTYPE_ATTACHMENT, 0); |
| 458 | 1162 | if( pAttach==0 ) fossil_redirect_home(); |
| 1163 | + bUserIsOwner = | |
| 1164 | + 0==fossil_strcmp(pAttach->zUser, login_name()) | |
| 1165 | + && login_is_individual(); | |
| 459 | 1166 | zTarget = pAttach->zAttachTarget; |
| 460 | 1167 | zSrc = pAttach->zAttachSrc; |
| 461 | 1168 | ridSrc = db_int(0,"SELECT rid FROM blob WHERE uuid='%q'", zSrc); |
| 462 | 1169 | zName = pAttach->zAttachName; |
| 463 | 1170 | zDesc = pAttach->zComment; |
| 464 | 1171 | zMime = mimetype_from_name(zName); |
| 465 | 1172 | fShowContent = zMime ? strncmp(zMime,"text/", 5)==0 : 0; |
| 466 | - if( validate16(zTarget, strlen(zTarget)) | |
| 1173 | + if( db_int(0,"SELECT 1 FROM event WHERE objid=%d and type='f'", rid) ){ | |
| 1174 | + if( !g.perm.RdForum ){ login_needed(g.anon.RdForum); return; } | |
| 1175 | + showDelMenu = g.perm.Admin || bUserIsOwner; | |
| 1176 | + zForumPost = zTarget; | |
| 1177 | + }else if( validate16(zTarget, strlen(zTarget)) | |
| 467 | 1178 | && db_exists("SELECT 1 FROM ticket WHERE tkt_uuid='%q'", zTarget) |
| 468 | 1179 | ){ |
| 469 | - zTktUuid = zTarget; | |
| 470 | 1180 | if( !g.perm.RdTkt ){ login_needed(g.anon.RdTkt); return; } |
| 471 | - if( g.perm.WrTkt ){ | |
| 472 | - style_submenu_element("Delete", "%R/ainfo/%s?del", zUuid); | |
| 473 | - } | |
| 474 | - }else if( db_exists("SELECT 1 FROM tag WHERE tagname='wiki-%q'",zTarget) ){ | |
| 1181 | + zTktUuid = zTarget; | |
| 1182 | + showDelMenu = g.perm.WrTkt; | |
| 1183 | + }else if( db_exists("SELECT 1 FROM tag WHERE tagname='wiki-%q'", | |
| 1184 | + zTarget) ){ | |
| 1185 | + if( !g.perm.RdWiki ){ login_needed(g.anon.RdWiki); return; } | |
| 475 | 1186 | zWikiName = zTarget; |
| 1187 | + showDelMenu = g.perm.WrWiki; | |
| 1188 | + }else if( db_exists("SELECT 1 FROM tag WHERE tagname='event-%q'", | |
| 1189 | + zTarget) ){ | |
| 476 | 1190 | if( !g.perm.RdWiki ){ login_needed(g.anon.RdWiki); return; } |
| 477 | - if( g.perm.WrWiki ){ | |
| 478 | - style_submenu_element("Delete", "%R/ainfo/%s?del", zUuid); | |
| 479 | - } | |
| 480 | - }else if( db_exists("SELECT 1 FROM tag WHERE tagname='event-%q'",zTarget) ){ | |
| 481 | 1191 | zTNUuid = zTarget; |
| 482 | - if( !g.perm.RdWiki ){ login_needed(g.anon.RdWiki); return; } | |
| 483 | - if( g.perm.Write && g.perm.WrWiki ){ | |
| 484 | - style_submenu_element("Delete", "%R/ainfo/%s?del", zUuid); | |
| 485 | - } | |
| 1192 | + showDelMenu = g.perm.Write && g.perm.WrWiki; | |
| 1193 | + } | |
| 1194 | + if( showDelMenu ){ | |
| 1195 | + style_submenu_element("Delete", "%R/ainfo/%s?del", zUuid); | |
| 486 | 1196 | } |
| 487 | 1197 | zDate = db_text(0, "SELECT datetime(%.12f)", pAttach->rDate); |
| 488 | 1198 | |
| 489 | 1199 | if( P("confirm") |
| 490 | - && ((zTktUuid && g.perm.WrTkt) || | |
| 1200 | + && cgi_csrf_safe(2) | |
| 1201 | + && ((zForumPost | |
| 1202 | + && ((bUserIsOwner && g.perm.AttachForum) || | |
| 1203 | + forumpost_may_close())) || | |
| 1204 | + (zTktUuid && g.perm.WrTkt) || | |
| 491 | 1205 | (zWikiName && g.perm.WrWiki) || |
| 492 | 1206 | (zTNUuid && g.perm.Write && g.perm.WrWiki)) |
| 493 | 1207 | ){ |
| 1208 | + /* Delete attachment. */ | |
| 494 | 1209 | int i, n, rid; |
| 495 | - char *zDate; | |
| 1210 | + char *zNewDate; | |
| 496 | 1211 | Blob manifest; |
| 497 | 1212 | Blob cksum; |
| 498 | 1213 | const char *zFile = zName; |
| 499 | 1214 | |
| 1215 | + if( !bUserIsOwner ){ | |
| 1216 | + if( zForumPost ? !forumpost_may_close() : !g.perm.Admin ){ | |
| 1217 | + webpage_error( | |
| 1218 | + "Only admins can delete other users' attachments." | |
| 1219 | + ); | |
| 1220 | + } | |
| 1221 | + } | |
| 500 | 1222 | db_begin_transaction(); |
| 501 | 1223 | blob_zero(&manifest); |
| 502 | 1224 | for(i=n=0; zFile[i]; i++){ |
| 503 | 1225 | if( zFile[i]=='/' || zFile[i]=='\\' ) n = i; |
| 504 | 1226 | } |
| 505 | 1227 | zFile += n; |
| 506 | 1228 | if( zFile[0]==0 ) zFile = "unknown"; |
| 507 | 1229 | blob_appendf(&manifest, "A %F %F\n", zFile, zTarget); |
| 508 | - zDate = date_in_standard_format("now"); | |
| 509 | - blob_appendf(&manifest, "D %s\n", zDate); | |
| 1230 | + zNewDate = date_in_standard_format("now"); | |
| 1231 | + blob_appendf(&manifest, "D %s\n", zNewDate); | |
| 510 | 1232 | blob_appendf(&manifest, "U %F\n", login_name()); |
| 511 | 1233 | md5sum_blob(&manifest, &cksum); |
| 512 | 1234 | blob_appendf(&manifest, "Z %b\n", &cksum); |
| 513 | 1235 | rid = content_put(&manifest); |
| 514 | 1236 | manifest_crosslink(rid, &manifest, MC_NONE); |
| 515 | 1237 | db_end_transaction(0); |
| 516 | 1238 | @ <p>The attachment below has been deleted.</p> |
| 1239 | + fossil_free(zNewDate); | |
| 517 | 1240 | } |
| 518 | 1241 | |
| 519 | 1242 | if( P("del") |
| 520 | - && ((zTktUuid && g.perm.WrTkt) || | |
| 521 | - (zWikiName && g.perm.WrWiki) || | |
| 522 | - (zTNUuid && g.perm.Write && g.perm.WrWiki)) | |
| 1243 | + && ((zForumPost && (bUserIsOwner || forumpost_may_close())) | |
| 1244 | + || (zTktUuid && g.perm.WrTkt) | |
| 1245 | + || (zWikiName && g.perm.WrWiki) | |
| 1246 | + || (zTNUuid && g.perm.Write && g.perm.WrWiki)) | |
| 523 | 1247 | ){ |
| 524 | 1248 | form_begin(0, "%R/ainfo/%!S", zUuid); |
| 525 | 1249 | @ <p>Confirm you want to delete the attachment shown below. |
| 526 | 1250 | @ <input type="submit" name="confirm" value="Confirm"> |
| 1251 | + login_insert_csrf_secret(); | |
| 527 | 1252 | @ </form> |
| 528 | 1253 | } |
| 529 | 1254 | |
| 530 | 1255 | isModerator = g.perm.Admin || |
| 531 | - (zTktUuid && g.perm.ModTkt) || | |
| 532 | - (zWikiName && g.perm.ModWiki); | |
| 533 | - if( isModerator && (zModAction = P("modaction"))!=0 ){ | |
| 1256 | + (zForumPost && g.perm.ModForum) || | |
| 1257 | + (zTktUuid && g.perm.ModTkt) || | |
| 1258 | + (zWikiName && g.perm.ModWiki); | |
| 1259 | + zModAction = P("modaction"); | |
| 1260 | + if( zModAction!=0 && cgi_csrf_safe(2) ){ | |
| 534 | 1261 | if( strcmp(zModAction,"delete")==0 ){ |
| 535 | - moderation_disapprove(rid); | |
| 536 | - if( zTktUuid ){ | |
| 1262 | + if( isModerator || bUserIsOwner ){ | |
| 1263 | + moderation_disapprove(rid); | |
| 1264 | + } | |
| 1265 | + if( zForumPost ){ | |
| 1266 | + cgi_redirectf("%R/forumpost/%!S", zForumPost); | |
| 1267 | + }else if( zTktUuid ){ | |
| 537 | 1268 | cgi_redirectf("%R/tktview/%!S", zTktUuid); |
| 538 | - }else{ | |
| 1269 | + }else if( zWikiName ) { | |
| 539 | 1270 | cgi_redirectf("%R/wiki?name=%t", zWikiName); |
| 540 | 1271 | } |
| 1272 | + /* zTNUuid is intentionally unhandled. Tech note attachments | |
| 1273 | + ** don't go through moderation. */ | |
| 541 | 1274 | return; |
| 542 | 1275 | } |
| 543 | - if( strcmp(zModAction,"approve")==0 ){ | |
| 1276 | + if( isModerator && strcmp(zModAction,"approve")==0 ){ | |
| 544 | 1277 | moderation_approve('a', rid); |
| 545 | 1278 | } |
| 546 | 1279 | } |
| 547 | 1280 | style_set_current_feature("attach"); |
| 548 | 1281 | style_header("Attachment Details"); |
| @@ -558,21 +1291,24 @@ | ||
| 558 | 1291 | @ <td>%z(href("%R/artifact/%!S",zUuid))%s(zUuid)</a> |
| 559 | 1292 | if( g.perm.Setup ){ |
| 560 | 1293 | @ (%d(rid)) |
| 561 | 1294 | } |
| 562 | 1295 | modPending = moderation_pending_www(rid); |
| 563 | - if( zTktUuid ){ | |
| 1296 | + if( zForumPost ){ | |
| 1297 | + @ <tr><th>Forum Post:</th> | |
| 1298 | + @ <td>%z(href("%R/forumpost/%s",zForumPost))%h(zForumPost)</a>\ | |
| 1299 | + @ </td></tr> | |
| 1300 | + }else if( zTktUuid ){ | |
| 564 | 1301 | @ <tr><th>Ticket:</th> |
| 565 | 1302 | @ <td>%z(href("%R/tktview/%s",zTktUuid))%s(zTktUuid)</a></td></tr> |
| 566 | - } | |
| 567 | - if( zTNUuid ){ | |
| 1303 | + }else if( zTNUuid ){ | |
| 568 | 1304 | @ <tr><th>Tech Note:</th> |
| 569 | 1305 | @ <td>%z(href("%R/technote/%s",zTNUuid))%s(zTNUuid)</a></td></tr> |
| 570 | - } | |
| 571 | - if( zWikiName ){ | |
| 1306 | + }else if( zWikiName ){ | |
| 572 | 1307 | @ <tr><th>Wiki Page:</th> |
| 573 | - @ <td>%z(href("%R/wiki?name=%t",zWikiName))%h(zWikiName)</a></td></tr> | |
| 1308 | + @ <td>%z(href("%R/wiki?name=%t",zWikiName))%h(zWikiName)</a>\ | |
| 1309 | + @ </td></tr> | |
| 574 | 1310 | } |
| 575 | 1311 | @ <tr><th>Date:</th><td> |
| 576 | 1312 | hyperlink_to_date(zDate, "</td></tr>"); |
| 577 | 1313 | @ <tr><th>User:</th><td> |
| 578 | 1314 | hyperlink_to_user(pAttach->zUser, zDate, "</td></tr>"); |
| @@ -583,104 +1319,197 @@ | ||
| 583 | 1319 | } |
| 584 | 1320 | @ <tr><th>Filename:</th><td>%h(zName)</td></tr> |
| 585 | 1321 | if( g.perm.Setup ){ |
| 586 | 1322 | @ <tr><th>MIME-Type:</th><td>%h(zMime)</td></tr> |
| 587 | 1323 | } |
| 588 | - @ <tr><th valign="top">Description:</th><td valign="top">%h(zDesc)</td></tr> | |
| 1324 | + @ <tr><th valign="top">Description:</th>\ | |
| 1325 | + /* FIXME (2026-06-05): Honor the N-card (comment mimetype). */ | |
| 1326 | + @ <td valign="top">%h(zDesc)</td></tr> | |
| 589 | 1327 | @ </table> |
| 590 | 1328 | |
| 591 | - if( isModerator && modPending ){ | |
| 1329 | + if( modPending && (isModerator || bUserIsOwner) ){ | |
| 592 | 1330 | @ <div class="section">Moderation</div> |
| 593 | 1331 | @ <blockquote> |
| 594 | 1332 | form_begin(0, "%R/ainfo/%s", zUuid); |
| 595 | 1333 | @ <label><input type="radio" name="modaction" value="delete"> |
| 596 | - @ Delete this change</label><br> | |
| 597 | - @ <label><input type="radio" name="modaction" value="approve"> | |
| 598 | - @ Approve this change</label><br> | |
| 1334 | + @ Delete this attachment</label><br> | |
| 1335 | + if( isModerator ){ | |
| 1336 | +#if 0 | |
| 1337 | + /* TODO/FIXME (2026-06-03): only allow approval of an attachment | |
| 1338 | + ** if its target has been approved. Without this, we can end up | |
| 1339 | + ** with stale attachments which refer to rejected targets. We | |
| 1340 | + ** need a type-specific RID/UUID here, which requires | |
| 1341 | + ** refactoring above to get it. */ | |
| 1342 | + const int tgtid = 0; | |
| 1343 | + if( moderation_pending(tgtid) ){ | |
| 1344 | + @ <label><input type="radio" name="modaction" \ | |
| 1345 | + @ disabled value="approve"> | |
| 1346 | + @ <span class='modpending'>Cannot approve: | |
| 1347 | + @ target is pending moderation</span>\ | |
| 1348 | + @ </label><br> | |
| 1349 | + }else | |
| 1350 | +#else | |
| 1351 | + { | |
| 1352 | + @ <label><input type="radio" name="modaction" value="approve"> | |
| 1353 | + @ Approve this attachment</label><br> | |
| 1354 | + } | |
| 1355 | +#endif | |
| 1356 | + } | |
| 599 | 1357 | @ <input type="submit" value="Submit"> |
| 1358 | + login_insert_csrf_secret(); | |
| 600 | 1359 | @ </form> |
| 601 | 1360 | @ </blockquote> |
| 602 | 1361 | } |
| 603 | 1362 | |
| 604 | - @ <div class="section">Content Appended</div> | |
| 605 | - @ <blockquote> | |
| 1363 | + @ <div class="section">Content:</div> | |
| 606 | 1364 | blob_zero(&attach); |
| 607 | - if( fShowContent ){ | |
| 608 | - const char *z; | |
| 609 | - content_get(ridSrc, &attach); | |
| 610 | - blob_to_utf8_no_bom(&attach, 0); | |
| 611 | - z = blob_str(&attach); | |
| 612 | - if( zLn ){ | |
| 613 | - output_text_with_line_numbers(z, blob_size(&attach), zName, zLn, 1); | |
| 614 | - }else{ | |
| 615 | - @ <pre> | |
| 616 | - @ %h(z) | |
| 617 | - @ </pre> | |
| 618 | - } | |
| 619 | - }else if( strncmp(zMime, "image/", 6)==0 ){ | |
| 620 | - int sz = db_int(0, "SELECT size FROM blob WHERE rid=%d", ridSrc); | |
| 621 | - @ <i>(file is %d(sz) bytes of image data)</i><br> | |
| 622 | - @ <img src="%R/raw/%s(zSrc)?m=%s(zMime)"></img> | |
| 623 | - style_submenu_element("Image", "%R/raw/%s?m=%s", zSrc, zMime); | |
| 624 | - }else{ | |
| 625 | - int sz = db_int(0, "SELECT size FROM blob WHERE rid=%d", ridSrc); | |
| 626 | - @ <i>(file is %d(sz) bytes of binary data)</i> | |
| 627 | - } | |
| 628 | - @ </blockquote> | |
| 1365 | + if( modPending && !moderation_user_could(rid, 1, 0) ){ | |
| 1366 | + @ <p><span class="modpending">Content is awaiting moderator \ | |
| 1367 | + @ approval.</span></p> | |
| 1368 | + }else{ | |
| 1369 | + @ <blockquote> | |
| 1370 | + if( fShowContent ){ | |
| 1371 | + const char *z; | |
| 1372 | + content_get(ridSrc, &attach); | |
| 1373 | + blob_to_utf8_no_bom(&attach, 0); | |
| 1374 | + z = blob_str(&attach); | |
| 1375 | + if( zLn ){ | |
| 1376 | + output_text_with_line_numbers(z, blob_size(&attach), | |
| 1377 | + zName, zLn, 1); | |
| 1378 | + }else{ | |
| 1379 | + @ <pre> | |
| 1380 | + @ %h(z) | |
| 1381 | + @ </pre> | |
| 1382 | + } | |
| 1383 | + }else if( strncmp(zMime, "image/", 6)==0 ){ | |
| 1384 | + int sz = db_int(0, "SELECT size FROM blob WHERE rid=%d", ridSrc); | |
| 1385 | + @ <i>(file is %d(sz) bytes of image data)</i><br> | |
| 1386 | + @ <img src="%R/raw/%s(zSrc)?m=%s(zMime)"></img> | |
| 1387 | + style_submenu_element("Image", "%R/raw/%s?m=%s", zSrc, zMime); | |
| 1388 | + }else{ | |
| 1389 | + int sz = db_int(0, "SELECT size FROM blob WHERE rid=%d", ridSrc); | |
| 1390 | + @ <i>(file is %d(sz) bytes of binary data)</i> | |
| 1391 | + } | |
| 1392 | + @ </blockquote> | |
| 1393 | + } | |
| 629 | 1394 | manifest_destroy(pAttach); |
| 630 | 1395 | blob_reset(&attach); |
| 631 | 1396 | style_finish_page(); |
| 632 | 1397 | } |
| 1398 | + | |
| 1399 | +#if INTERFACE | |
| 1400 | +/* | |
| 1401 | +** Flags for use with attachment_list(). ATTACHLIST_HRULE_ABOVE | |
| 1402 | +** must have a value of 1 for historical call compatibility. | |
| 1403 | +*/ | |
| 1404 | +#define ATTACHLIST_HRULE_ABOVE 0x01 /* Insert <hr> above header */ | |
| 1405 | +#define ATTACHLIST_TARGET_BLANK 0x02 /* use target=_blank for links */ | |
| 1406 | +#define ATTACHLIST_SIZE 0x04 /* add size */ | |
| 1407 | +#define ATTACHLIST_HIDE_UNAPPROVED 0x08 /* Hide pending-moderation files */ | |
| 1408 | +#define ATTACHLIST_DETAILS_CLOSED 0x10 /* Wrap in a closed DETAILS element */ | |
| 1409 | +#define ATTACHLIST_DETAILS_OPEN 0x20 /* Wrap in an open DETAILS element */ | |
| 1410 | +#define ATTACHLIST_HIDE_EMPTY 0x40 /* Skip if size<1 */ | |
| 1411 | +#endif | |
| 633 | 1412 | |
| 634 | 1413 | /* |
| 635 | 1414 | ** Output HTML to show a list of attachments. |
| 636 | 1415 | */ |
| 637 | 1416 | void attachment_list( |
| 638 | 1417 | const char *zTarget, /* Object that things are attached to */ |
| 639 | 1418 | const char *zHeader, /* Header to display with attachments */ |
| 640 | - int fHorizontalRule /* Insert <hr> separator above header */ | |
| 1419 | + const int flags /* ATTACHLIST_... flags */ | |
| 641 | 1420 | ){ |
| 642 | 1421 | int cnt = 0; |
| 1422 | + char szBuf[36] = {0}; /* scratchpad for attachment size value */ | |
| 1423 | + const char *zLinkTgt = (ATTACHLIST_TARGET_BLANK & flags) | |
| 1424 | + ? " target=\"_blank\"" : ""; | |
| 1425 | + const int bUseDetail = flags & | |
| 1426 | + (ATTACHLIST_DETAILS_CLOSED | ATTACHLIST_DETAILS_OPEN); | |
| 643 | 1427 | Stmt q; |
| 1428 | + | |
| 644 | 1429 | db_prepare(&q, |
| 645 | - "SELECT datetime(mtime,toLocal()), filename, user," | |
| 646 | - " (SELECT uuid FROM blob WHERE rid=attachid), src" | |
| 647 | - " FROM attachment" | |
| 648 | - " WHERE isLatest AND src!='' AND target=%Q" | |
| 1430 | + "SELECT datetime(mtime,toLocal()), a.filename, a.user," | |
| 1431 | + " b1.uuid, a.src, a.target, a.attachid, b2.size\n" | |
| 1432 | + " FROM attachment a, blob b1, blob b2\n" | |
| 1433 | + " WHERE a.isLatest\n" | |
| 1434 | + " AND a.src IS NOT NULL\n" | |
| 1435 | + " AND a.target=%Q\n" | |
| 1436 | + " AND b1.rid=a.attachid\n" | |
| 1437 | + " AND b2.uuid=a.src\n" | |
| 649 | 1438 | " ORDER BY mtime DESC", |
| 650 | 1439 | zTarget |
| 651 | 1440 | ); |
| 652 | 1441 | while( db_step(&q)==SQLITE_ROW ){ |
| 653 | 1442 | const char *zDate = db_column_text(&q, 0); |
| 654 | 1443 | const char *zFile = db_column_text(&q, 1); |
| 655 | 1444 | const char *zUser = db_column_text(&q, 2); |
| 656 | 1445 | const char *zUuid = db_column_text(&q, 3); |
| 657 | 1446 | const char *zSrc = db_column_text(&q, 4); |
| 1447 | + const char *zTarget = db_column_text(&q, 5); | |
| 658 | 1448 | const char *zDispUser = zUser && zUser[0] ? zUser : "anonymous"; |
| 1449 | + const char *zTypeArg = 0; /* URL arg name for /attachdownload */ | |
| 1450 | + const int aid = db_column_int(&q, 6); | |
| 1451 | + const int sz = db_column_int(&q, 7); | |
| 1452 | + if( (flags & ATTACHLIST_HIDE_UNAPPROVED) | |
| 1453 | + && moderation_pending(aid) | |
| 1454 | + && !moderation_user_could(aid, 1, 0) ){ | |
| 1455 | + continue; | |
| 1456 | + } | |
| 1457 | + if( sz<1 && (flags & ATTACHLIST_HIDE_EMPTY) ){ | |
| 1458 | + /* Deleted or phantom items. */ | |
| 1459 | + continue; | |
| 1460 | + } | |
| 659 | 1461 | if( cnt==0 ){ |
| 660 | - @ <section class='attachlist'> | |
| 661 | - if( fHorizontalRule ){ | |
| 1462 | + if( bUseDetail ){ | |
| 1463 | + @ <details class='attachlist' | |
| 1464 | + if( ATTACHLIST_DETAILS_OPEN & flags ){ | |
| 1465 | + @ open | |
| 1466 | + } | |
| 1467 | + @ > | |
| 1468 | + }else{ | |
| 1469 | + @ <section class='attachlist'> | |
| 1470 | + } | |
| 1471 | + if( flags & ATTACHLIST_HRULE_ABOVE ){ | |
| 662 | 1472 | @ <hr> |
| 663 | 1473 | } |
| 664 | - @ %s(zHeader) | |
| 1474 | + if( bUseDetail ){ | |
| 1475 | + @ <summary>%s(zHeader)</summary> | |
| 1476 | + }else{ | |
| 1477 | + @ %s(zHeader) | |
| 1478 | + } | |
| 665 | 1479 | @ <ul> |
| 666 | 1480 | } |
| 667 | 1481 | cnt++; |
| 1482 | + switch( attachment_target_type(zTarget, 1) ){ | |
| 1483 | + case CFTYPE_TICKET: zTypeArg = "tkt"; break; | |
| 1484 | + case CFTYPE_FORUM: zTypeArg = "forumpost"; break; | |
| 1485 | + case CFTYPE_EVENT: zTypeArg = "technote"; break; | |
| 1486 | + case CFTYPE_WIKI: | |
| 1487 | + default: zTypeArg = "page"; break; | |
| 1488 | + } | |
| 668 | 1489 | @ <li> |
| 669 | - @ %z(href("%R/artifact/%!S",zSrc))%h(zFile)</a> | |
| 670 | - @ [<a href="%R/attachdownload/%t(zFile)?page=%t(zTarget)&file=%t(zFile)">download</a>] | |
| 1490 | + @ <a href="%R/artifact/%!S(zSrc)"%s(zLinkTgt)>%h(zFile)</a> | |
| 1491 | + if( flags & ATTACHLIST_SIZE ){ | |
| 1492 | + sqlite3_snprintf(sizeof(szBuf), szBuf, " %d bytes", sz); | |
| 1493 | + } | |
| 1494 | + @ [<a href="%R/attachdownload/%t(zFile)?%s(zTypeArg)=%t(zTarget)\ | |
| 1495 | + @&file=%t(zFile)%s(zLinkTgt)">download</a>%s(szBuf)] | |
| 671 | 1496 | @ added by %h(zDispUser) on |
| 672 | 1497 | hyperlink_to_date(zDate, "."); |
| 673 | - @ [%z(href("%R/ainfo/%!S",zUuid))details</a>] | |
| 1498 | + @ [<a href="%R/ainfo/%!S(zUuid)"%s(zLinkTgt)>details</a>] | |
| 1499 | + moderation_pending_www(aid); | |
| 674 | 1500 | @ </li> |
| 675 | 1501 | } |
| 676 | 1502 | if( cnt ){ |
| 677 | 1503 | @ </ul> |
| 678 | - @ </section> | |
| 1504 | + if( bUseDetail ){ | |
| 1505 | + @ </details> | |
| 1506 | + }else{ | |
| 1507 | + @ </section> | |
| 1508 | + } | |
| 679 | 1509 | } |
| 680 | 1510 | db_finalize(&q); |
| 681 | - | |
| 682 | 1511 | } |
| 683 | 1512 | |
| 684 | 1513 | /* |
| 685 | 1514 | ** COMMAND: attachment* |
| 686 | 1515 | ** |
| @@ -827,15 +1656,204 @@ | ||
| 827 | 1656 | } |
| 828 | 1657 | for(i = 2; i < g.argc; ++i){ |
| 829 | 1658 | const char *zPage = g.argv[i]; |
| 830 | 1659 | db_bind_text(&q, ":tgtname", zPage); |
| 831 | 1660 | while(SQLITE_ROW == db_step(&q)){ |
| 832 | - const char * zTime = db_column_text(&q, 0); | |
| 833 | - const char * zSrc = db_column_text(&q, 1); | |
| 834 | - const char * zTarget = db_column_text(&q, 2); | |
| 835 | - const char * zName = db_column_text(&q, 3); | |
| 1661 | + const char *zTime = db_column_text(&q, 0); | |
| 1662 | + const char *zSrc = db_column_text(&q, 1); | |
| 1663 | + const char *zTarget = db_column_text(&q, 2); | |
| 1664 | + const char *zName = db_column_text(&q, 3); | |
| 836 | 1665 | printf("%-20s %s %.12s %s\n", zTarget, zTime, zSrc, zName); |
| 837 | 1666 | } |
| 838 | 1667 | db_reset(&q); |
| 839 | 1668 | } |
| 840 | 1669 | db_finalize(&q); |
| 841 | 1670 | } |
| 1671 | + | |
| 1672 | +/* | |
| 1673 | +** Renders the list of attachments for artifact pManifest as JSON to | |
| 1674 | +** blob pOut. If pManifest->type is not one of (CFTYPE_TICKET, | |
| 1675 | +** CFTYPE_FORUM, CFTYPE_EVENT, CFTYPE_WIKI) then it behaves as if the | |
| 1676 | +** result set is empty. | |
| 1677 | +** | |
| 1678 | +** If there are no matching attachments then its behavior depends on | |
| 1679 | +** emptyPolicy: | |
| 1680 | +** | |
| 1681 | +** <0 = emit a JSON NULL | |
| 1682 | +** 0 = emit no output | |
| 1683 | +** >0 = emit an empty JSON array | |
| 1684 | +** | |
| 1685 | +** If bLatestOnly is true then only the most recent entry for a given | |
| 1686 | +** attachment is emitted, else all versions are emitted in descending | |
| 1687 | +** mtime order. | |
| 1688 | +** | |
| 1689 | +** Returns the number of attachments. | |
| 1690 | +** | |
| 1691 | +** Output format: | |
| 1692 | +** | |
| 1693 | +** [{ | |
| 1694 | +** "uuid": attachment artifact hash, | |
| 1695 | +** "src": hash of the attachment blob, | |
| 1696 | +** "target": wiki page name or ticket/event ID, | |
| 1697 | +** "filename": filename of attachment, | |
| 1698 | +** "mtime": ISO-8601 timestamp UTC, | |
| 1699 | +** "isLatest": true if this is the latest version of this file | |
| 1700 | +** else false, | |
| 1701 | +** }, ...once per attachment] | |
| 1702 | +** | |
| 1703 | +*/ | |
| 1704 | +int attachments_to_json(const Manifest *pManifest, | |
| 1705 | + Blob *pOut, int bLatestOnly, | |
| 1706 | + int emptyPolicy){ | |
| 1707 | + int i = 0; | |
| 1708 | + Stmt q = empty_Stmt; | |
| 1709 | + char *zToFree = 0; | |
| 1710 | + const char *zTgt = 0; | |
| 1711 | + switch(pManifest->type){ | |
| 1712 | + case CFTYPE_FORUM: zTgt = zToFree = rid_to_uuid(pManifest->rid); | |
| 1713 | + break; | |
| 1714 | + case CFTYPE_WIKI: zTgt = pManifest->zWikiTitle; break; | |
| 1715 | + case CFTYPE_EVENT: zTgt = pManifest->zEventId; break; | |
| 1716 | + case CFTYPE_TICKET: zTgt = pManifest->zTicketUuid; break; | |
| 1717 | + default: | |
| 1718 | + goto empty_result; | |
| 1719 | + } | |
| 1720 | + db_prepare(&q, | |
| 1721 | + "SELECT datetime(mtime), a.src, a.target, a.filename, a.isLatest,\n" | |
| 1722 | + " b2.size, b1.uuid, a.user, a.comment\n" | |
| 1723 | + " FROM attachment a, blob b1, blob b2\n" | |
| 1724 | + " WHERE a.target=%Q\n" | |
| 1725 | + " AND a.src IS NOT NULL\n" | |
| 1726 | + " AND b1.rid=a.attachid\n" | |
| 1727 | + " AND b2.uuid=a.src\n" | |
| 1728 | + " AND (a.isLatest OR %d)\n" | |
| 1729 | + " ORDER BY a.target, a.isLatest DESC, a.mtime DESC\n", | |
| 1730 | + zTgt, !bLatestOnly | |
| 1731 | + ); | |
| 1732 | + while(SQLITE_ROW == db_step(&q)){ | |
| 1733 | + const char *zTime = db_column_text(&q, 0); | |
| 1734 | + const char *zSrc = db_column_text(&q, 1); | |
| 1735 | + const char *zTarget = db_column_text(&q, 2); | |
| 1736 | + const char *zName = db_column_text(&q, 3); | |
| 1737 | + const int isLatest = db_column_int(&q, 4); | |
| 1738 | + const int sz = db_column_int(&q, 5); | |
| 1739 | + const char *zUuid = db_column_text(&q, 6); | |
| 1740 | + const char *zUser = db_column_text(&q, 7); | |
| 1741 | + const char *zComment = db_column_text(&q, 8); | |
| 1742 | + if(!i++){ | |
| 1743 | + blob_append_char(pOut, '['); | |
| 1744 | + }else{ | |
| 1745 | + blob_append_char(pOut, ','); | |
| 1746 | + } | |
| 1747 | + blob_appendf( | |
| 1748 | + pOut, | |
| 1749 | + "{\"uuid\": %!j, \"src\": %!j, \"target\": %!j, " | |
| 1750 | + "\"filename\": %!j, \"size\":%d, \"mtime\": %!j, " | |
| 1751 | + "\"isLatest\": %s, \"user\": %!j, \"comment\": ", | |
| 1752 | + zUuid, zSrc, zTarget, | |
| 1753 | + zName, sz, zTime, isLatest ? "true" : "false", | |
| 1754 | + zUser | |
| 1755 | + ); | |
| 1756 | + if( zComment && zComment[0] ){ | |
| 1757 | + blob_appendf(pOut, "%!j", zComment); | |
| 1758 | + }else{ | |
| 1759 | + blob_append_literal(pOut, "null"); | |
| 1760 | + } | |
| 1761 | + blob_append_char(pOut, '}'); | |
| 1762 | + } | |
| 1763 | + fossil_free(zToFree); | |
| 1764 | + db_finalize(&q); | |
| 1765 | + if(!i){ | |
| 1766 | + empty_result: | |
| 1767 | + if( emptyPolicy>0 ){ | |
| 1768 | + blob_append_literal(pOut, "[]"); | |
| 1769 | + }else if( emptyPolicy<0 ){ | |
| 1770 | + blob_append_literal(pOut, "null"); | |
| 1771 | + } | |
| 1772 | + }else{ | |
| 1773 | + blob_append_char(pOut, ']'); | |
| 1774 | + } | |
| 1775 | + return i; | |
| 1776 | +} | |
| 1777 | + | |
| 1778 | +/* | |
| 1779 | +** COMMAND: test-attachment-target | |
| 1780 | +** | |
| 1781 | +** Usage: %fossil test-attachment-target TARGET_ID... | |
| 1782 | +*/ | |
| 1783 | +void test_attachment_target_type_cmd(void){ | |
| 1784 | + int i; | |
| 1785 | + verify_all_options(); | |
| 1786 | + db_find_and_open_repository(0, 0); | |
| 1787 | + if( g.argc<3 ){ | |
| 1788 | + usage("test-attachment-target TARGET_ID"); | |
| 1789 | + return; | |
| 1790 | + } | |
| 1791 | + for( i = 2; i < g.argc; ++i ){ | |
| 1792 | + const char *zTarget = g.argv[i]; | |
| 1793 | + const int rid = attachment_target_rid(zTarget, 0); | |
| 1794 | + const int type = attachment_target_type(zTarget, 0); | |
| 1795 | + const char *zType = "<invalid>"; | |
| 1796 | + switch(type){ | |
| 1797 | + case CFTYPE_EVENT: zType = "technote"; break; | |
| 1798 | + case CFTYPE_FORUM: zType = "forumpost"; break; | |
| 1799 | + case CFTYPE_TICKET: zType = "ticket"; break; | |
| 1800 | + case CFTYPE_WIKI: zType = "wiki"; break; | |
| 1801 | + } | |
| 1802 | + fossil_print("%-20s = %-9s #%d %z\n", | |
| 1803 | + zTarget, zType, rid, | |
| 1804 | + rid>0 ? rid_to_uuid(rid) : 0); | |
| 1805 | + } | |
| 1806 | +} | |
| 1807 | + | |
| 1808 | + | |
| 1809 | +/* | |
| 1810 | +** COMMAND: test-attachments-to-json | |
| 1811 | +** | |
| 1812 | +** Usage: %fossil test-attachments-to-json TARGET_ID... | |
| 1813 | +** | |
| 1814 | +** Options: | |
| 1815 | +** --old List all versions of attachments. Default is to | |
| 1816 | +** list only the latest. | |
| 1817 | +** --full Require a full target ID, not a prefix. | |
| 1818 | +** | |
| 1819 | +** Emits a JSON array of attachments for the given attachment targets. | |
| 1820 | +** The given IDs must be wiki page names, ticket hashes, tech-note | |
| 1821 | +** hashes, or forum post hashes. By default it accepts hash prefixes | |
| 1822 | +** but does no detection of ambiguity or cross-type prefix collisions | |
| 1823 | +** so may emit curious results if given short, colliding IDs. | |
| 1824 | +*/ | |
| 1825 | +void test_attachments_to_json_cmd(void){ | |
| 1826 | + const int emptyPolicy = 1; | |
| 1827 | + const int bLatestOnly = find_option("old",0,0)==0; | |
| 1828 | + const int bFullId = find_option("full",0,0)!=0; | |
| 1829 | + int i; | |
| 1830 | + | |
| 1831 | + verify_all_options(); | |
| 1832 | + db_find_and_open_repository(0, 0); | |
| 1833 | + if( g.argc<3 ){ | |
| 1834 | + usage("test-attachments-to-json TARGET_ID"); | |
| 1835 | + return; | |
| 1836 | + } | |
| 1837 | + for( i = 2; i < g.argc; ++i ){ | |
| 1838 | + const char *zTarget = g.argv[i]; | |
| 1839 | + const int rid = attachment_target_rid(zTarget, bFullId); | |
| 1840 | + if( 0==rid ){ | |
| 1841 | + fossil_print("** cannot resolve %s\n", zTarget); | |
| 1842 | + }else{ | |
| 1843 | + Blob b = BLOB_INITIALIZER; | |
| 1844 | + Manifest *pManifest = manifest_get(rid, CFTYPE_ANY, NULL); | |
| 1845 | + assert( pManifest ); | |
| 1846 | + attachments_to_json(pManifest, &b, bLatestOnly, emptyPolicy); | |
| 1847 | + fossil_print("Attachments for %s: ", zTarget); | |
| 1848 | + if( b.nUsed ){ | |
| 1849 | + char *zPretty = db_text(0,"SELECT json_pretty(%B)", &b); | |
| 1850 | + fossil_print("%s\n", zPretty); | |
| 1851 | + fossil_free(zPretty); | |
| 1852 | + }else{ | |
| 1853 | + fossil_print("none\n"); | |
| 1854 | + } | |
| 1855 | + blob_reset(&b); | |
| 1856 | + manifest_destroy(pManifest); | |
| 1857 | + } | |
| 1858 | + } | |
| 1859 | +} | |
| 842 | 1860 |
| --- src/attach.c | |
| +++ src/attach.c | |
| @@ -18,32 +18,219 @@ | |
| 18 | ** This file contains code for dealing with attachments. |
| 19 | */ |
| 20 | #include "config.h" |
| 21 | #include "attach.h" |
| 22 | #include <assert.h> |
| 23 | |
| 24 | /* |
| 25 | ** WEBPAGE: attachlist |
| 26 | ** List attachments. |
| 27 | ** |
| 28 | ** tkt=HASH |
| 29 | ** page=WIKIPAGE |
| 30 | ** technote=HASH |
| 31 | ** |
| 32 | ** At most one of technote=, tkt= or page= may be supplied. |
| 33 | ** |
| 34 | ** If none are given, all attachments are listed. If one is given, only |
| 35 | ** attachments for the designated technote, ticket or wiki page are shown. |
| 36 | ** |
| 37 | ** HASH may be just a prefix of the relevant technical note or ticket |
| 38 | ** artifact hash, in which case all attachments of all technical notes or |
| 39 | ** tickets with the prefix will be listed. |
| 40 | */ |
| 41 | void attachlist_page(void){ |
| 42 | const char *zPage = P("page"); |
| 43 | const char *zTkt = P("tkt"); |
| 44 | const char *zTechNote = P("technote"); |
| 45 | Blob sql; |
| 46 | Stmt q; |
| 47 | |
| 48 | if( zPage && zTkt ) zTkt = 0; |
| 49 | login_check_credentials(); |
| @@ -50,92 +237,161 @@ | |
| 50 | style_set_current_feature("attach"); |
| 51 | blob_zero(&sql); |
| 52 | blob_append_sql(&sql, |
| 53 | "SELECT datetime(mtime,toLocal()), src, target, filename," |
| 54 | " comment, user," |
| 55 | " (SELECT uuid FROM blob WHERE rid=attachid), attachid," |
| 56 | " (CASE WHEN 'tkt-'||target IN (SELECT tagname FROM tag)" |
| 57 | " THEN 1" |
| 58 | " WHEN 'event-'||target IN (SELECT tagname FROM tag)" |
| 59 | " THEN 2" |
| 60 | " ELSE 0 END)" |
| 61 | " FROM attachment" |
| 62 | ); |
| 63 | if( zPage ){ |
| 64 | if( g.perm.RdWiki==0 ){ login_needed(g.anon.RdWiki); return; } |
| 65 | style_header("Attachments To %h", zPage); |
| 66 | blob_append_sql(&sql, " WHERE target=%Q", zPage); |
| 67 | }else if( zTkt ){ |
| 68 | if( g.perm.RdTkt==0 ){ login_needed(g.anon.RdTkt); return; } |
| 69 | style_header("Attachments To Ticket %S", zTkt); |
| 70 | blob_append_sql(&sql, " WHERE target GLOB '%q*'", zTkt); |
| 71 | }else if( zTechNote ){ |
| 72 | if( g.perm.RdWiki==0 ){ login_needed(g.anon.RdWiki); return; } |
| 73 | style_header("Attachments to Tech Note %S", zTechNote); |
| 74 | blob_append_sql(&sql, " WHERE target GLOB '%q*'", |
| 75 | zTechNote); |
| 76 | }else{ |
| 77 | if( g.perm.RdTkt==0 && g.perm.RdWiki==0 ){ |
| 78 | login_needed(g.anon.RdTkt || g.anon.RdWiki); |
| 79 | return; |
| 80 | } |
| 81 | style_header("All Attachments"); |
| 82 | } |
| 83 | blob_append_sql(&sql, " ORDER BY mtime DESC"); |
| 84 | db_prepare(&q, "%s", blob_sql_text(&sql)); |
| 85 | @ <ol> |
| 86 | while( db_step(&q)==SQLITE_ROW ){ |
| 87 | const char *zDate = db_column_text(&q, 0); |
| 88 | const char *zSrc = db_column_text(&q, 1); |
| 89 | const char *zTarget = db_column_text(&q, 2); |
| 90 | const char *zFilename = db_column_text(&q, 3); |
| 91 | const char *zComment = db_column_text(&q, 4); |
| 92 | const char *zUser = db_column_text(&q, 5); |
| 93 | const char *zUuid = db_column_text(&q, 6); |
| 94 | int attachid = db_column_int(&q, 7); |
| 95 | /* type 0 is a wiki page, 1 is a ticket, 2 is a tech note */ |
| 96 | int type = db_column_int(&q, 8); |
| 97 | const char *zDispUser = zUser && zUser[0] ? zUser : "anonymous"; |
| 98 | int i; |
| 99 | char *zUrlTail; |
| 100 | for(i=0; zFilename[i]; i++){ |
| 101 | if( zFilename[i]=='/' && zFilename[i+1]!=0 ){ |
| 102 | zFilename = &zFilename[i+1]; |
| 103 | i = -1; |
| 104 | } |
| 105 | } |
| 106 | if( type==1 ){ |
| 107 | zUrlTail = mprintf("tkt=%s&file=%t", zTarget, zFilename); |
| 108 | }else if( type==2 ){ |
| 109 | zUrlTail = mprintf("technote=%s&file=%t", zTarget, zFilename); |
| 110 | }else{ |
| 111 | zUrlTail = mprintf("page=%t&file=%t", zTarget, zFilename); |
| 112 | } |
| 113 | @ <li><p> |
| 114 | @ Attachment %z(href("%R/ainfo/%!S",zUuid))%S(zUuid)</a> |
| 115 | moderation_pending_www(attachid); |
| 116 | @ <br><a href="%R/attachview?%s(zUrlTail)">%h(zFilename)</a> |
| 117 | @ [<a href="%R/attachdownload/%t(zFilename)?%s(zUrlTail)">download</a>]<br> |
| 118 | if( zComment ) while( fossil_isspace(zComment[0]) ) zComment++; |
| 119 | if( zComment && zComment[0] ){ |
| 120 | @ %!W(zComment)<br> |
| 121 | } |
| 122 | if( zPage==0 && zTkt==0 && zTechNote==0 ){ |
| 123 | if( zSrc==0 || zSrc[0]==0 ){ |
| 124 | zSrc = "Deleted from"; |
| 125 | }else { |
| 126 | zSrc = "Added to"; |
| 127 | } |
| 128 | if( type==1 ){ |
| 129 | @ %s(zSrc) ticket <a href="%R/tktview?name=%s(zTarget)"> |
| 130 | @ %S(zTarget)</a> |
| 131 | }else if( type==2 ){ |
| 132 | @ %s(zSrc) tech note <a href="%R/technote/%s(zTarget)"> |
| 133 | @ %S(zTarget)</a> |
| 134 | }else{ |
| 135 | @ %s(zSrc) wiki page <a href="%R/wiki?name=%t(zTarget)"> |
| 136 | @ %h(zTarget)</a> |
| 137 | } |
| 138 | }else{ |
| 139 | if( zSrc==0 || zSrc[0]==0 ){ |
| 140 | @ Deleted |
| 141 | }else { |
| @@ -162,27 +418,35 @@ | |
| 162 | ** Query parameters: |
| 163 | ** |
| 164 | ** tkt=HASH |
| 165 | ** page=WIKIPAGE |
| 166 | ** technote=HASH |
| 167 | ** file=FILENAME |
| 168 | ** attachid=ID |
| 169 | ** |
| 170 | */ |
| 171 | void attachview_page(void){ |
| 172 | const char *zPage = P("page"); |
| 173 | const char *zTkt = P("tkt"); |
| 174 | const char *zTechNote = P("technote"); |
| 175 | const char *zFile = P("file"); |
| 176 | const char *zTarget = 0; |
| 177 | int attachid = atoi(PD("attachid","0")); |
| 178 | char *zUUID; |
| 179 | |
| 180 | if( zFile==0 ) fossil_redirect_home(); |
| 181 | login_check_credentials(); |
| 182 | style_set_current_feature("attach"); |
| 183 | if( zPage ){ |
| 184 | if( g.perm.RdWiki==0 ){ login_needed(g.anon.RdWiki); return; } |
| 185 | zTarget = zPage; |
| 186 | }else if( zTkt ){ |
| 187 | if( g.perm.RdTkt==0 ){ login_needed(g.anon.RdTkt); return; } |
| 188 | zTarget = zTkt; |
| @@ -275,84 +539,167 @@ | |
| 275 | Manifest *pManifest; |
| 276 | |
| 277 | db_begin_transaction(); |
| 278 | blob_init(&content, aContent, szContent); |
| 279 | pManifest = manifest_parse(&content, 0, 0); |
| 280 | manifest_destroy(pManifest); |
| 281 | blob_init(&content, aContent, szContent); |
| 282 | if( pManifest ){ |
| 283 | blob_compress(&content, &content); |
| 284 | addCompress = 1; |
| 285 | } |
| 286 | rid = content_put_ex(&content, 0, 0, 0, needModerator); |
| 287 | zUUID = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", rid); |
| 288 | blob_zero(&manifest); |
| 289 | for(i=n=0; zName[i]; i++){ |
| 290 | if( zName[i]=='/' || zName[i]=='\\' ) n = i+1; |
| 291 | } |
| 292 | zName += n; |
| 293 | if( zName[0]==0 ) zName = "unknown"; |
| 294 | blob_appendf(&manifest, "A %F%s %F %s\n", |
| 295 | zName, addCompress ? ".gz" : "", zTarget, zUUID); |
| 296 | while( fossil_isspace(zComment[0]) ) zComment++; |
| 297 | n = strlen(zComment); |
| 298 | while( n>0 && fossil_isspace(zComment[n-1]) ){ n--; } |
| 299 | if( n>0 ){ |
| 300 | blob_appendf(&manifest, "C %#F\n", n, zComment); |
| 301 | } |
| 302 | zDate = date_in_standard_format("now"); |
| 303 | blob_appendf(&manifest, "D %s\n", zDate); |
| 304 | blob_appendf(&manifest, "U %F\n", login_name()); |
| 305 | md5sum_blob(&manifest, &cksum); |
| 306 | blob_appendf(&manifest, "Z %b\n", &cksum); |
| 307 | attach_put(&manifest, rid, needModerator); |
| 308 | assert( blob_is_reset(&manifest) ); |
| 309 | db_end_transaction(0); |
| 310 | } |
| 311 | |
| 312 | /* |
| 313 | ** WEBPAGE: attachadd |
| 314 | ** Add a new attachment. |
| 315 | ** |
| 316 | ** tkt=HASH |
| 317 | ** page=WIKIPAGE |
| 318 | ** technote=HASH |
| 319 | ** from=URL |
| 320 | ** |
| 321 | */ |
| 322 | void attachadd_page(void){ |
| 323 | const char *zPage = P("page"); |
| 324 | const char *zTkt = P("tkt"); |
| 325 | const char *zTechNote = P("technote"); |
| 326 | const char *zFrom = P("from"); |
| 327 | const char *aContent = P("f"); |
| 328 | const char *zName = PD("f:filename","unknown"); |
| 329 | const char *zTarget; |
| 330 | char *zTargetType; |
| 331 | int szContent = atoi(PD("f:bytes","0")); |
| 332 | int goodCaptcha = 1; |
| 333 | |
| 334 | if( P("cancel") ) cgi_redirect(zFrom); |
| 335 | if( (zPage && zTkt) |
| 336 | || (zPage && zTechNote) |
| 337 | || (zTkt && zTechNote) |
| 338 | ){ |
| 339 | fossil_redirect_home(); |
| 340 | } |
| 341 | if( zPage==0 && zTkt==0 && zTechNote==0) fossil_redirect_home(); |
| 342 | login_check_credentials(); |
| 343 | if( zPage ){ |
| 344 | if( g.perm.ApndWiki==0 || g.perm.Attach==0 ){ |
| 345 | login_needed(g.anon.ApndWiki && g.anon.Attach); |
| 346 | return; |
| 347 | } |
| 348 | if( !db_exists("SELECT 1 FROM tag WHERE tagname='wiki-%q'", zPage) ){ |
| 349 | fossil_redirect_home(); |
| 350 | } |
| 351 | zTarget = zPage; |
| 352 | zTargetType = mprintf("Wiki Page <a href=\"%R/wiki?name=%h\">%h</a>", |
| 353 | zPage, zPage); |
| 354 | }else if ( zTechNote ){ |
| 355 | if( g.perm.Write==0 || g.perm.ApndWiki==0 || g.perm.Attach==0 ){ |
| 356 | login_needed(g.anon.Write && g.anon.ApndWiki && g.anon.Attach); |
| 357 | return; |
| 358 | } |
| @@ -362,12 +709,13 @@ | |
| 362 | if( zTechNote==0) fossil_redirect_home(); |
| 363 | } |
| 364 | zTarget = zTechNote; |
| 365 | zTargetType = mprintf("Tech Note <a href=\"%R/technote/%s\">%S</a>", |
| 366 | zTechNote, zTechNote); |
| 367 | |
| 368 | }else{ |
| 369 | if( g.perm.ApndTkt==0 || g.perm.Attach==0 ){ |
| 370 | login_needed(g.anon.ApndTkt && g.anon.Attach); |
| 371 | return; |
| 372 | } |
| 373 | if( !db_exists("SELECT 1 FROM tag WHERE tagname='tkt-%q'", zTkt) ){ |
| @@ -374,56 +722,409 @@ | |
| 374 | zTkt = db_text(0, "SELECT substr(tagname,5) FROM tag" |
| 375 | " WHERE tagname GLOB 'tkt-%q*'", zTkt); |
| 376 | if( zTkt==0 ) fossil_redirect_home(); |
| 377 | } |
| 378 | zTarget = zTkt; |
| 379 | zTargetType = mprintf("Ticket <a href=\"%R/tktview/%s\">%S</a>", |
| 380 | zTkt, zTkt); |
| 381 | } |
| 382 | if( zFrom==0 ) zFrom = mprintf("%R/home"); |
| 383 | if( P("cancel") ){ |
| 384 | cgi_redirect(zFrom); |
| 385 | } |
| 386 | if( P("ok") && szContent>0 && (goodCaptcha = captcha_is_correct(0)) ){ |
| 387 | int needModerator = (zTkt!=0 && ticket_need_moderation(0)) || |
| 388 | (zPage!=0 && wiki_need_moderation(0)); |
| 389 | const char *zComment = PD("comment", ""); |
| 390 | attach_commit(zName, zTarget, aContent, szContent, needModerator, zComment); |
| 391 | cgi_redirect(zFrom); |
| 392 | } |
| 393 | style_set_current_feature("attach"); |
| 394 | style_header("Add Attachment"); |
| 395 | if( !goodCaptcha ){ |
| 396 | @ <p class="generalError">Error: Incorrect security code.</p> |
| 397 | } |
| 398 | @ <h2>Add Attachment To %s(zTargetType)</h2> |
| 399 | form_begin("enctype='multipart/form-data'", "%R/attachadd"); |
| 400 | @ <div> |
| 401 | @ File to Attach: |
| 402 | @ <input type="file" name="f" size="60"><br> |
| 403 | @ Description:<br> |
| 404 | @ <textarea name="comment" cols="80" rows="5" wrap="virtual"></textarea><br> |
| 405 | if( zTkt ){ |
| 406 | @ <input type="hidden" name="tkt" value="%h(zTkt)"> |
| 407 | }else if( zTechNote ){ |
| 408 | @ <input type="hidden" name="technote" value="%h(zTechNote)"> |
| 409 | }else{ |
| 410 | @ <input type="hidden" name="page" value="%h(zPage)"> |
| 411 | } |
| 412 | @ <input type="hidden" name="from" value="%h(zFrom)"> |
| 413 | @ <input type="submit" name="ok" value="Add Attachment"> |
| 414 | @ <input type="submit" name="cancel" value="Cancel"> |
| 415 | @ </div> |
| 416 | captcha_generate(0); |
| 417 | @ </form> |
| 418 | style_finish_page(); |
| 419 | fossil_free(zTargetType); |
| 420 | } |
| 421 | |
| 422 | /* |
| 423 | ** WEBPAGE: ainfo |
| 424 | ** URL: /ainfo?name=ARTIFACTID |
| 425 | ** |
| 426 | ** Show the details of an attachment artifact. |
| 427 | */ |
| 428 | void ainfo_page(void){ |
| 429 | int rid; /* RID for the control artifact */ |
| @@ -436,113 +1137,145 @@ | |
| 436 | const char *zName; /* Name of the attached file */ |
| 437 | const char *zDesc; /* Description of the attached file */ |
| 438 | const char *zWikiName = 0; /* Wiki page name when attached to Wiki */ |
| 439 | const char *zTNUuid = 0; /* Tech Note ID when attached to tech note */ |
| 440 | const char *zTktUuid = 0; /* Ticket ID when attached to a ticket */ |
| 441 | int modPending; /* True if awaiting moderation */ |
| 442 | const char *zModAction; /* Moderation action or NULL */ |
| 443 | int isModerator; /* TRUE if user is the moderator */ |
| 444 | const char *zMime; /* MIME Type */ |
| 445 | Blob attach; /* Content of the attachment */ |
| 446 | int fShowContent = 0; |
| 447 | const char *zLn = P("ln"); |
| 448 | |
| 449 | login_check_credentials(); |
| 450 | if( !g.perm.RdTkt && !g.perm.RdWiki ){ |
| 451 | login_needed(g.anon.RdTkt || g.anon.RdWiki); |
| 452 | return; |
| 453 | } |
| 454 | rid = name_to_rid_www("name"); |
| 455 | if( rid==0 ){ fossil_redirect_home(); } |
| 456 | zUuid = db_text("", "SELECT uuid FROM blob WHERE rid=%d", rid); |
| 457 | pAttach = manifest_get(rid, CFTYPE_ATTACHMENT, 0); |
| 458 | if( pAttach==0 ) fossil_redirect_home(); |
| 459 | zTarget = pAttach->zAttachTarget; |
| 460 | zSrc = pAttach->zAttachSrc; |
| 461 | ridSrc = db_int(0,"SELECT rid FROM blob WHERE uuid='%q'", zSrc); |
| 462 | zName = pAttach->zAttachName; |
| 463 | zDesc = pAttach->zComment; |
| 464 | zMime = mimetype_from_name(zName); |
| 465 | fShowContent = zMime ? strncmp(zMime,"text/", 5)==0 : 0; |
| 466 | if( validate16(zTarget, strlen(zTarget)) |
| 467 | && db_exists("SELECT 1 FROM ticket WHERE tkt_uuid='%q'", zTarget) |
| 468 | ){ |
| 469 | zTktUuid = zTarget; |
| 470 | if( !g.perm.RdTkt ){ login_needed(g.anon.RdTkt); return; } |
| 471 | if( g.perm.WrTkt ){ |
| 472 | style_submenu_element("Delete", "%R/ainfo/%s?del", zUuid); |
| 473 | } |
| 474 | }else if( db_exists("SELECT 1 FROM tag WHERE tagname='wiki-%q'",zTarget) ){ |
| 475 | zWikiName = zTarget; |
| 476 | if( !g.perm.RdWiki ){ login_needed(g.anon.RdWiki); return; } |
| 477 | if( g.perm.WrWiki ){ |
| 478 | style_submenu_element("Delete", "%R/ainfo/%s?del", zUuid); |
| 479 | } |
| 480 | }else if( db_exists("SELECT 1 FROM tag WHERE tagname='event-%q'",zTarget) ){ |
| 481 | zTNUuid = zTarget; |
| 482 | if( !g.perm.RdWiki ){ login_needed(g.anon.RdWiki); return; } |
| 483 | if( g.perm.Write && g.perm.WrWiki ){ |
| 484 | style_submenu_element("Delete", "%R/ainfo/%s?del", zUuid); |
| 485 | } |
| 486 | } |
| 487 | zDate = db_text(0, "SELECT datetime(%.12f)", pAttach->rDate); |
| 488 | |
| 489 | if( P("confirm") |
| 490 | && ((zTktUuid && g.perm.WrTkt) || |
| 491 | (zWikiName && g.perm.WrWiki) || |
| 492 | (zTNUuid && g.perm.Write && g.perm.WrWiki)) |
| 493 | ){ |
| 494 | int i, n, rid; |
| 495 | char *zDate; |
| 496 | Blob manifest; |
| 497 | Blob cksum; |
| 498 | const char *zFile = zName; |
| 499 | |
| 500 | db_begin_transaction(); |
| 501 | blob_zero(&manifest); |
| 502 | for(i=n=0; zFile[i]; i++){ |
| 503 | if( zFile[i]=='/' || zFile[i]=='\\' ) n = i; |
| 504 | } |
| 505 | zFile += n; |
| 506 | if( zFile[0]==0 ) zFile = "unknown"; |
| 507 | blob_appendf(&manifest, "A %F %F\n", zFile, zTarget); |
| 508 | zDate = date_in_standard_format("now"); |
| 509 | blob_appendf(&manifest, "D %s\n", zDate); |
| 510 | blob_appendf(&manifest, "U %F\n", login_name()); |
| 511 | md5sum_blob(&manifest, &cksum); |
| 512 | blob_appendf(&manifest, "Z %b\n", &cksum); |
| 513 | rid = content_put(&manifest); |
| 514 | manifest_crosslink(rid, &manifest, MC_NONE); |
| 515 | db_end_transaction(0); |
| 516 | @ <p>The attachment below has been deleted.</p> |
| 517 | } |
| 518 | |
| 519 | if( P("del") |
| 520 | && ((zTktUuid && g.perm.WrTkt) || |
| 521 | (zWikiName && g.perm.WrWiki) || |
| 522 | (zTNUuid && g.perm.Write && g.perm.WrWiki)) |
| 523 | ){ |
| 524 | form_begin(0, "%R/ainfo/%!S", zUuid); |
| 525 | @ <p>Confirm you want to delete the attachment shown below. |
| 526 | @ <input type="submit" name="confirm" value="Confirm"> |
| 527 | @ </form> |
| 528 | } |
| 529 | |
| 530 | isModerator = g.perm.Admin || |
| 531 | (zTktUuid && g.perm.ModTkt) || |
| 532 | (zWikiName && g.perm.ModWiki); |
| 533 | if( isModerator && (zModAction = P("modaction"))!=0 ){ |
| 534 | if( strcmp(zModAction,"delete")==0 ){ |
| 535 | moderation_disapprove(rid); |
| 536 | if( zTktUuid ){ |
| 537 | cgi_redirectf("%R/tktview/%!S", zTktUuid); |
| 538 | }else{ |
| 539 | cgi_redirectf("%R/wiki?name=%t", zWikiName); |
| 540 | } |
| 541 | return; |
| 542 | } |
| 543 | if( strcmp(zModAction,"approve")==0 ){ |
| 544 | moderation_approve('a', rid); |
| 545 | } |
| 546 | } |
| 547 | style_set_current_feature("attach"); |
| 548 | style_header("Attachment Details"); |
| @@ -558,21 +1291,24 @@ | |
| 558 | @ <td>%z(href("%R/artifact/%!S",zUuid))%s(zUuid)</a> |
| 559 | if( g.perm.Setup ){ |
| 560 | @ (%d(rid)) |
| 561 | } |
| 562 | modPending = moderation_pending_www(rid); |
| 563 | if( zTktUuid ){ |
| 564 | @ <tr><th>Ticket:</th> |
| 565 | @ <td>%z(href("%R/tktview/%s",zTktUuid))%s(zTktUuid)</a></td></tr> |
| 566 | } |
| 567 | if( zTNUuid ){ |
| 568 | @ <tr><th>Tech Note:</th> |
| 569 | @ <td>%z(href("%R/technote/%s",zTNUuid))%s(zTNUuid)</a></td></tr> |
| 570 | } |
| 571 | if( zWikiName ){ |
| 572 | @ <tr><th>Wiki Page:</th> |
| 573 | @ <td>%z(href("%R/wiki?name=%t",zWikiName))%h(zWikiName)</a></td></tr> |
| 574 | } |
| 575 | @ <tr><th>Date:</th><td> |
| 576 | hyperlink_to_date(zDate, "</td></tr>"); |
| 577 | @ <tr><th>User:</th><td> |
| 578 | hyperlink_to_user(pAttach->zUser, zDate, "</td></tr>"); |
| @@ -583,104 +1319,197 @@ | |
| 583 | } |
| 584 | @ <tr><th>Filename:</th><td>%h(zName)</td></tr> |
| 585 | if( g.perm.Setup ){ |
| 586 | @ <tr><th>MIME-Type:</th><td>%h(zMime)</td></tr> |
| 587 | } |
| 588 | @ <tr><th valign="top">Description:</th><td valign="top">%h(zDesc)</td></tr> |
| 589 | @ </table> |
| 590 | |
| 591 | if( isModerator && modPending ){ |
| 592 | @ <div class="section">Moderation</div> |
| 593 | @ <blockquote> |
| 594 | form_begin(0, "%R/ainfo/%s", zUuid); |
| 595 | @ <label><input type="radio" name="modaction" value="delete"> |
| 596 | @ Delete this change</label><br> |
| 597 | @ <label><input type="radio" name="modaction" value="approve"> |
| 598 | @ Approve this change</label><br> |
| 599 | @ <input type="submit" value="Submit"> |
| 600 | @ </form> |
| 601 | @ </blockquote> |
| 602 | } |
| 603 | |
| 604 | @ <div class="section">Content Appended</div> |
| 605 | @ <blockquote> |
| 606 | blob_zero(&attach); |
| 607 | if( fShowContent ){ |
| 608 | const char *z; |
| 609 | content_get(ridSrc, &attach); |
| 610 | blob_to_utf8_no_bom(&attach, 0); |
| 611 | z = blob_str(&attach); |
| 612 | if( zLn ){ |
| 613 | output_text_with_line_numbers(z, blob_size(&attach), zName, zLn, 1); |
| 614 | }else{ |
| 615 | @ <pre> |
| 616 | @ %h(z) |
| 617 | @ </pre> |
| 618 | } |
| 619 | }else if( strncmp(zMime, "image/", 6)==0 ){ |
| 620 | int sz = db_int(0, "SELECT size FROM blob WHERE rid=%d", ridSrc); |
| 621 | @ <i>(file is %d(sz) bytes of image data)</i><br> |
| 622 | @ <img src="%R/raw/%s(zSrc)?m=%s(zMime)"></img> |
| 623 | style_submenu_element("Image", "%R/raw/%s?m=%s", zSrc, zMime); |
| 624 | }else{ |
| 625 | int sz = db_int(0, "SELECT size FROM blob WHERE rid=%d", ridSrc); |
| 626 | @ <i>(file is %d(sz) bytes of binary data)</i> |
| 627 | } |
| 628 | @ </blockquote> |
| 629 | manifest_destroy(pAttach); |
| 630 | blob_reset(&attach); |
| 631 | style_finish_page(); |
| 632 | } |
| 633 | |
| 634 | /* |
| 635 | ** Output HTML to show a list of attachments. |
| 636 | */ |
| 637 | void attachment_list( |
| 638 | const char *zTarget, /* Object that things are attached to */ |
| 639 | const char *zHeader, /* Header to display with attachments */ |
| 640 | int fHorizontalRule /* Insert <hr> separator above header */ |
| 641 | ){ |
| 642 | int cnt = 0; |
| 643 | Stmt q; |
| 644 | db_prepare(&q, |
| 645 | "SELECT datetime(mtime,toLocal()), filename, user," |
| 646 | " (SELECT uuid FROM blob WHERE rid=attachid), src" |
| 647 | " FROM attachment" |
| 648 | " WHERE isLatest AND src!='' AND target=%Q" |
| 649 | " ORDER BY mtime DESC", |
| 650 | zTarget |
| 651 | ); |
| 652 | while( db_step(&q)==SQLITE_ROW ){ |
| 653 | const char *zDate = db_column_text(&q, 0); |
| 654 | const char *zFile = db_column_text(&q, 1); |
| 655 | const char *zUser = db_column_text(&q, 2); |
| 656 | const char *zUuid = db_column_text(&q, 3); |
| 657 | const char *zSrc = db_column_text(&q, 4); |
| 658 | const char *zDispUser = zUser && zUser[0] ? zUser : "anonymous"; |
| 659 | if( cnt==0 ){ |
| 660 | @ <section class='attachlist'> |
| 661 | if( fHorizontalRule ){ |
| 662 | @ <hr> |
| 663 | } |
| 664 | @ %s(zHeader) |
| 665 | @ <ul> |
| 666 | } |
| 667 | cnt++; |
| 668 | @ <li> |
| 669 | @ %z(href("%R/artifact/%!S",zSrc))%h(zFile)</a> |
| 670 | @ [<a href="%R/attachdownload/%t(zFile)?page=%t(zTarget)&file=%t(zFile)">download</a>] |
| 671 | @ added by %h(zDispUser) on |
| 672 | hyperlink_to_date(zDate, "."); |
| 673 | @ [%z(href("%R/ainfo/%!S",zUuid))details</a>] |
| 674 | @ </li> |
| 675 | } |
| 676 | if( cnt ){ |
| 677 | @ </ul> |
| 678 | @ </section> |
| 679 | } |
| 680 | db_finalize(&q); |
| 681 | |
| 682 | } |
| 683 | |
| 684 | /* |
| 685 | ** COMMAND: attachment* |
| 686 | ** |
| @@ -827,15 +1656,204 @@ | |
| 827 | } |
| 828 | for(i = 2; i < g.argc; ++i){ |
| 829 | const char *zPage = g.argv[i]; |
| 830 | db_bind_text(&q, ":tgtname", zPage); |
| 831 | while(SQLITE_ROW == db_step(&q)){ |
| 832 | const char * zTime = db_column_text(&q, 0); |
| 833 | const char * zSrc = db_column_text(&q, 1); |
| 834 | const char * zTarget = db_column_text(&q, 2); |
| 835 | const char * zName = db_column_text(&q, 3); |
| 836 | printf("%-20s %s %.12s %s\n", zTarget, zTime, zSrc, zName); |
| 837 | } |
| 838 | db_reset(&q); |
| 839 | } |
| 840 | db_finalize(&q); |
| 841 | } |
| 842 |
| --- src/attach.c | |
| +++ src/attach.c | |
| @@ -18,32 +18,219 @@ | |
| 18 | ** This file contains code for dealing with attachments. |
| 19 | */ |
| 20 | #include "config.h" |
| 21 | #include "attach.h" |
| 22 | #include <assert.h> |
| 23 | |
| 24 | /* |
| 25 | ** Given a presumedly legal attachment target name, this guesses the |
| 26 | ** target type and returns one of CFTYPE_FORUM, CFTYPE_WIKI, |
| 27 | ** CFTYPE_TICKET, or CFTYPE_EVENT. Returns 0 if it cannot distinguish |
| 28 | ** the target type. |
| 29 | ** |
| 30 | ** zTarget is an attachment target name: wiki page name, tech-note ID, |
| 31 | ** ticket ID, or forumpost hash. |
| 32 | ** |
| 33 | ** If bFull is true then it requires zTarget to be a full ID for |
| 34 | ** tech-notes and tickets, otherwise such IDs may be prefixes. If |
| 35 | ** bFull is false then tech-notes and tickets will perform a prefix |
| 36 | ** match, but it is up to the caller to provide enough of a prefix to |
| 37 | ** rule out ambiguity[^1]. When called repeatedly, this routine can |
| 38 | ** run a bit faster and more efficiently if bFull is true, but some |
| 39 | ** historical use cases call for prefix matches. |
| 40 | ** |
| 41 | ** Wiki page names always require an exact match. |
| 42 | ** |
| 43 | ** Forum posts are a special case: |
| 44 | ** |
| 45 | ** - They ignore the bFull flag. That is, they will do prefix matches |
| 46 | ** but will not match an ambiguous prefix. |
| 47 | ** |
| 48 | ** - It is up to the caller to, if needed, resolve zTarget using |
| 49 | ** forumpost_head_rid2() to resolve the RID of the earliest version |
| 50 | ** of the post, as that is the only one which attachments should |
| 51 | ** target. |
| 52 | ** |
| 53 | ** [^1]: Historically (from the perspective of 2026-06) attachment |
| 54 | ** target lookups have used GLOB prefix matching but have taken no |
| 55 | ** measures to ensure that the prefix is unambiguous. Ergo we do the |
| 56 | ** same here. It is assumed that the caller passes enough of a prefix |
| 57 | ** to be unambiguous and that's worked out fine so far. |
| 58 | */ |
| 59 | int attachment_target_type(const char *zTarget, int bFull){ |
| 60 | if( !zTarget || !zTarget[0] || strlen(zTarget)>64/*vs. abuse*/ ){ |
| 61 | return 0; |
| 62 | } |
| 63 | if( symbolic_name_to_rid(zTarget, "f")>0 ){ |
| 64 | /* Check forum posts first because they are the most likely target |
| 65 | ** as of 2026. We should arguably use something more |
| 66 | ** specialized/efficient than symbolic_name_to_rid(). */ |
| 67 | return CFTYPE_FORUM; |
| 68 | } |
| 69 | if( bFull ){ |
| 70 | static Stmt q = empty_Stmt_m; |
| 71 | int rc = 0; |
| 72 | if( !q.pStmt ){ |
| 73 | db_static_prepare( |
| 74 | &q, |
| 75 | "SELECT CASE " |
| 76 | /* Ordered by presumed likelihood of attachments. */ |
| 77 | "WHEN (SELECT 1 FROM tag WHERE tagname='tkt-'||:tgt) THEN %d\n" |
| 78 | "WHEN (SELECT 1 FROM tag WHERE tagname='wiki-'||:tgt) THEN %d\n" |
| 79 | "WHEN (SELECT 1 FROM tag WHERE tagname='event-'||:tgt) THEN %d\n" |
| 80 | "ELSE 0 END", |
| 81 | CFTYPE_TICKET, CFTYPE_WIKI, CFTYPE_EVENT |
| 82 | ); |
| 83 | } |
| 84 | db_bind_text(&q, ":tgt", zTarget); |
| 85 | if( SQLITE_ROW==db_step(&q) ){ |
| 86 | rc = db_column_int(&q, 0); |
| 87 | } |
| 88 | db_reset(&q); |
| 89 | return rc; |
| 90 | }else{ |
| 91 | return db_int( |
| 92 | 0, |
| 93 | "SELECT CASE " |
| 94 | "WHEN (SELECT tagid FROM tag WHERE tagname GLOB 'tkt-%q*')" |
| 95 | " THEN %d\n" |
| 96 | "WHEN (SELECT tagid FROM tag WHERE tagname='wiki-%q')" |
| 97 | " THEN %d\n" |
| 98 | "WHEN (SELECT tagid FROM tag WHERE tagname GLOB 'event-%q*')" |
| 99 | " THEN %d\n" |
| 100 | "ELSE 0 END", |
| 101 | zTarget, CFTYPE_TICKET, |
| 102 | zTarget, CFTYPE_WIKI, |
| 103 | zTarget, CFTYPE_EVENT |
| 104 | ); |
| 105 | } |
| 106 | } |
| 107 | |
| 108 | /* |
| 109 | ** Given an attachment target name, returns the target's blob.rid. |
| 110 | ** zTarget and bFull work as described for attachment_target_type(). |
| 111 | ** |
| 112 | ** For forum posts, this always returns the RID of the first version |
| 113 | ** of the post, as attachments should always target that instance. |
| 114 | */ |
| 115 | int attachment_target_rid(const char *zTarget, int bFull){ |
| 116 | int rid = 0; |
| 117 | const int eType = attachment_target_type(zTarget, bFull); |
| 118 | switch(eType){ |
| 119 | case CFTYPE_TICKET: |
| 120 | case CFTYPE_EVENT:{ |
| 121 | const char *zTagPrefix = (eType==CFTYPE_EVENT) ? "event" : "tkt"; |
| 122 | rid = db_int( |
| 123 | 0, "SELECT b.rid FROM blob b, tag t, tagxref x\n" |
| 124 | "WHERE tagname %s '%s-%q%s'\n" |
| 125 | "AND x.tagtype>0\n" |
| 126 | "AND x.tagid=t.tagid\n" |
| 127 | "AND x.rid=b.rid\n" |
| 128 | "ORDER BY x.mtime DESC", |
| 129 | bFull ? "=" : "GLOB"/*safe-for-%s*/, |
| 130 | zTagPrefix/*safe-for-%s*/, |
| 131 | zTarget, |
| 132 | bFull ? "" : "*"/*safe-for-%s*/ |
| 133 | ); |
| 134 | break; |
| 135 | } |
| 136 | case CFTYPE_FORUM: |
| 137 | rid = db_int( |
| 138 | 0, "SELECT f.fpid FROM forumpost f, blob b\n" |
| 139 | "WHERE f.fpid=b.rid\n" |
| 140 | "AND b.uuid %s '%q%s'", |
| 141 | bFull ? "=" : "GLOB"/*safe-for-%s*/, |
| 142 | zTarget, |
| 143 | bFull ? "" : "*"/*safe-for-%s*/ |
| 144 | ); |
| 145 | if( rid>0 ){ |
| 146 | rid = forumpost_head_rid(rid); |
| 147 | } |
| 148 | break; |
| 149 | case CFTYPE_WIKI: |
| 150 | rid = db_int( |
| 151 | 0, "SELECT b.rid FROM blob b, tag t, tagxref x\n" |
| 152 | "WHERE tagname='wiki-%q'\n" |
| 153 | "AND x.tagtype>0\n" |
| 154 | "AND x.tagid=t.tagid\n" |
| 155 | "AND x.rid=b.rid\n" |
| 156 | "ORDER BY x.mtime DESC", |
| 157 | zTarget |
| 158 | ); |
| 159 | break; |
| 160 | default: |
| 161 | break; |
| 162 | } |
| 163 | return rid; |
| 164 | } |
| 165 | |
| 166 | /* |
| 167 | ** For a given aritfact ID and type (from the CFTYPE_xyz enum), |
| 168 | ** returns true if the current user could hypothetically apply and |
| 169 | ** attachment to it, else returns 0. |
| 170 | ** |
| 171 | ** The rid is currently only relevant when eArtifactType is |
| 172 | ** CFTYPE_FORUM. For forum posts, it checks precisely the rid given, |
| 173 | ** not the head RID, to keep non-admins from attaching files to |
| 174 | ** threads which have since been taken over by another user (this |
| 175 | ** happens when an admin edits another user's post). |
| 176 | */ |
| 177 | int attach_user_may(int rid, int eArtifactType){ |
| 178 | if( g.perm.Admin ) return 1; |
| 179 | if( !login_is_individual() ) return 0; |
| 180 | switch(eArtifactType){ |
| 181 | case CFTYPE_FORUM: |
| 182 | return g.perm.AttachForum && forumpost_is_owner(rid, 0); |
| 183 | case CFTYPE_WIKI: |
| 184 | return g.perm.ApndWiki && g.perm.Attach; |
| 185 | case CFTYPE_TICKET: |
| 186 | return g.perm.ApndTkt && g.perm.Attach; |
| 187 | case CFTYPE_EVENT: |
| 188 | return g.perm.Write && g.perm.ApndWiki && g.perm.Attach; |
| 189 | default: |
| 190 | return 0; |
| 191 | } |
| 192 | } |
| 193 | |
| 194 | /* |
| 195 | ** Emits a single-button FORM which invokes |
| 196 | ** /attachadd with target=$zTarget. |
| 197 | */ |
| 198 | void attach_render_attachadd_button(const char *zTarget){ |
| 199 | /* This could be changed from POST to GET, and arguably should so |
| 200 | ** that the target=X part becomes part of the resulting URL. */ |
| 201 | @ <form method="post" action="%R/attachadd">\ |
| 202 | @ <input type="hidden" name="target" value="%T(zTarget)">\ |
| 203 | @ <input type="submit" value="Attach..."> |
| 204 | @ </form>\ |
| 205 | } |
| 206 | |
| 207 | /* |
| 208 | ** WEBPAGE: attachlist |
| 209 | ** List attachments. |
| 210 | ** |
| 211 | ** tkt=HASH |
| 212 | ** page=WIKIPAGE |
| 213 | ** technote=HASH |
| 214 | ** forumpost=HASH |
| 215 | ** |
| 216 | ** At most one of technote=, tkt=, forumpost=, or page= may be supplied. |
| 217 | ** |
| 218 | ** If none are given, all attachments are listed. If one is given, only |
| 219 | ** attachments for the designated technote, ticket or wiki page are shown. |
| 220 | ** |
| 221 | ** HASH may be just a prefix of the relevant forum post, technical |
| 222 | ** note, or ticket artifact hash, in which case all attachments of all |
| 223 | ** technical notes or tickets with the prefix will be listed. Forum |
| 224 | ** posts, on the other hand, require a unique hash or hash prefix. |
| 225 | */ |
| 226 | void attachlist_page(void){ |
| 227 | const char *zPage = P("page"); |
| 228 | const char *zTkt = P("tkt"); |
| 229 | const char *zTechNote = P("technote"); |
| 230 | const char *zForumPost = P("forumpost"); |
| 231 | char *zLink = 0; |
| 232 | Blob sql; |
| 233 | Stmt q; |
| 234 | |
| 235 | if( zPage && zTkt ) zTkt = 0; |
| 236 | login_check_credentials(); |
| @@ -50,92 +237,161 @@ | |
| 237 | style_set_current_feature("attach"); |
| 238 | blob_zero(&sql); |
| 239 | blob_append_sql(&sql, |
| 240 | "SELECT datetime(mtime,toLocal()), src, target, filename," |
| 241 | " comment, user," |
| 242 | " (SELECT uuid FROM blob WHERE rid=attachid), attachid" |
| 243 | " FROM attachment" |
| 244 | ); |
| 245 | if( zForumPost ){ |
| 246 | int fnid; |
| 247 | if( g.perm.RdForum==0 ){ login_needed(g.anon.RdForum); return; } |
| 248 | style_header("Attachments To Forum post %S", zForumPost); |
| 249 | fnid = forumpost_head_rid2(zForumPost); |
| 250 | if( fnid<=0 ){ |
| 251 | webpage_error("Invalid forum post ID: %h", zForumPost); |
| 252 | } |
| 253 | blob_append_sql(&sql, " WHERE target=" |
| 254 | "(SELECT uuid FROM blob WHERE rid=%d)", fnid); |
| 255 | zLink = mprintf("forum post <a href='%R/forumpost/%t'>%#h</a>", |
| 256 | zForumPost, hash_digits(0), zForumPost); |
| 257 | }else if( zPage ){ |
| 258 | if( g.perm.RdWiki==0 ){ login_needed(g.anon.RdWiki); return; } |
| 259 | style_header("Attachments To Wiki page %h", zPage); |
| 260 | blob_append_sql(&sql, " WHERE target=%Q", zPage); |
| 261 | zLink = mprintf("wiki page <a href='%R/wiki?name=%t'>%h</a>", |
| 262 | zPage, zPage); |
| 263 | }else if( zTkt ){ |
| 264 | if( g.perm.RdTkt==0 ){ login_needed(g.anon.RdTkt); return; } |
| 265 | style_header("Attachments To Ticket %S", zTkt); |
| 266 | blob_append_sql(&sql, " WHERE target GLOB '%q*'", zTkt); |
| 267 | zLink = mprintf("ticket <a href='%R/tktview?name=%t'>%#h</a>", |
| 268 | zTkt, hash_digits(0), zTkt); |
| 269 | }else if( zTechNote ){ |
| 270 | if( g.perm.RdWiki==0 ){ login_needed(g.anon.RdWiki); return; } |
| 271 | style_header("Attachments To Tech Note %S", zTechNote); |
| 272 | blob_append_sql(&sql, " WHERE target GLOB '%q*'", |
| 273 | zTechNote); |
| 274 | zLink = mprintf("tech-note <a href='%R/technote?name=%t'>%#h</a>", |
| 275 | zTechNote, hash_digits(0), zTechNote); |
| 276 | }else{ |
| 277 | if( g.perm.RdTkt==0 && g.perm.RdWiki==0 ){ |
| 278 | login_needed(g.anon.RdTkt || g.anon.RdWiki); |
| 279 | return; |
| 280 | } |
| 281 | style_header("All Attachments"); |
| 282 | } |
| 283 | blob_append_sql(&sql, " ORDER BY mtime DESC"); |
| 284 | db_prepare(&q, "%s", blob_sql_text(&sql)); |
| 285 | |
| 286 | if( zLink ){ |
| 287 | @ <h2>Attachments for %s(zLink)</h2> |
| 288 | fossil_free(zLink); |
| 289 | zLink = 0; |
| 290 | } |
| 291 | |
| 292 | @ <ol> |
| 293 | while( db_step(&q)==SQLITE_ROW ){ |
| 294 | const char *zDate; |
| 295 | const char *zSrc; |
| 296 | const char *zTarget; |
| 297 | const char *zFilename; |
| 298 | const char *zComment; |
| 299 | const char *zUser; |
| 300 | const char *zUuid; |
| 301 | const char *zDispUser; |
| 302 | const int attachid = db_column_int(&q, 7); |
| 303 | int type; |
| 304 | int i; |
| 305 | int bDeleted; |
| 306 | char *zUrlTail = 0; |
| 307 | |
| 308 | if( moderation_pending(attachid) |
| 309 | && !moderation_user_could(attachid, 1, 0) ){ |
| 310 | /* Elide entries which are currently pending moderation unless |
| 311 | ** the user would be able to moderate the entry themselves. */ |
| 312 | continue; |
| 313 | } |
| 314 | |
| 315 | zDate = db_column_text(&q, 0); |
| 316 | zSrc = db_column_text(&q, 1); |
| 317 | zTarget = db_column_text(&q, 2); |
| 318 | zFilename = db_column_text(&q, 3); |
| 319 | zComment = db_column_text(&q, 4); |
| 320 | zUser = db_column_text(&q, 5); |
| 321 | zUuid = db_column_text(&q, 6); |
| 322 | zDispUser = zUser && zUser[0] ? zUser : "anonymous"; |
| 323 | for(i=0; zFilename[i]; i++){ |
| 324 | if( zFilename[i]=='/' && zFilename[i+1]!=0 ){ |
| 325 | zFilename = &zFilename[i+1]; |
| 326 | i = -1; |
| 327 | } |
| 328 | } |
| 329 | bDeleted = 0==zSrc || 0==zSrc[0]; |
| 330 | type = attachment_target_type(zTarget, 1); |
| 331 | switch( type ){ |
| 332 | case CFTYPE_TICKET: |
| 333 | zUrlTail = mprintf("tkt=%s&file=%t", zTarget, zFilename); |
| 334 | break; |
| 335 | case CFTYPE_EVENT: |
| 336 | zUrlTail = mprintf("technote=%s&file=%t", zTarget, zFilename); |
| 337 | break; |
| 338 | case CFTYPE_FORUM: |
| 339 | zUrlTail = mprintf("forumpost=%t&file=%t", zTarget, zFilename); |
| 340 | break; |
| 341 | case CFTYPE_WIKI: |
| 342 | zUrlTail = mprintf("page=%t&file=%t", zTarget, zFilename); |
| 343 | break; |
| 344 | } |
| 345 | @ <li><p> |
| 346 | if( bDeleted ){ |
| 347 | @ <s>\ |
| 348 | } |
| 349 | @ Attachment %z(href("%R/ainfo/%!S",zUuid))%S(zUuid)</a>\ |
| 350 | moderation_pending_www(attachid); |
| 351 | @ <br>\ |
| 352 | @ <a href="%R/attachview?%s(zUrlTail)">%h(zFilename)</a> |
| 353 | @ [<a href="%R/attachdownload/%t(zFilename)?%s(zUrlTail)">download</a>]\ |
| 354 | if( bDeleted ){ |
| 355 | @ </s> |
| 356 | } |
| 357 | @ <br> |
| 358 | if( zComment ) while( fossil_isspace(zComment[0]) ) zComment++; |
| 359 | if( zComment && zComment[0] ){ |
| 360 | /* FIXME (2026-06-05): Honor the N-card (comment mimetype). %W |
| 361 | ** (historically used here) assumes fossil-wiki and the |
| 362 | ** fileformat.wiki doc has always claimed that it defaults to |
| 363 | ** text/plain. /ainfo assumes it is plain text. */ |
| 364 | @ %h(zComment)<br> |
| 365 | } |
| 366 | if( zForumPost==0 && zPage==0 && zTkt==0 && zTechNote==0 ){ |
| 367 | if( bDeleted ){ |
| 368 | zSrc = "Deleted from"; |
| 369 | }else { |
| 370 | zSrc = "Added to"; |
| 371 | } |
| 372 | switch( type ){ |
| 373 | case CFTYPE_TICKET: |
| 374 | @ %s(zSrc) ticket <a href="%R/tktview?name=%s(zTarget)"> |
| 375 | @ %S(zTarget)</a> |
| 376 | break; |
| 377 | case CFTYPE_EVENT: |
| 378 | @ %s(zSrc) tech note <a href="%R/technote/%s(zTarget)"> |
| 379 | @ %S(zTarget)</a> |
| 380 | break; |
| 381 | case CFTYPE_WIKI: |
| 382 | @ %s(zSrc) wiki page <a href="%R/wiki?name=%t(zTarget)"> |
| 383 | @ %h(zTarget)</a> |
| 384 | break; |
| 385 | case CFTYPE_FORUM: |
| 386 | @ %s(zSrc) forum post <a href="%R/forumpost/%s(zTarget)"> |
| 387 | @ %h(zTarget)</a> |
| 388 | break; |
| 389 | default: |
| 390 | @ <span class='error'>%s(zSrc) cannot determine target type |
| 391 | @ of %h(zTarget)</span> |
| 392 | break; |
| 393 | } |
| 394 | }else{ |
| 395 | if( zSrc==0 || zSrc[0]==0 ){ |
| 396 | @ Deleted |
| 397 | }else { |
| @@ -162,27 +418,35 @@ | |
| 418 | ** Query parameters: |
| 419 | ** |
| 420 | ** tkt=HASH |
| 421 | ** page=WIKIPAGE |
| 422 | ** technote=HASH |
| 423 | ** forumpost=HASH |
| 424 | ** file=FILENAME |
| 425 | ** attachid=ID |
| 426 | ** |
| 427 | */ |
| 428 | void attachview_page(void){ |
| 429 | const char *zPage = P("page"); |
| 430 | const char *zTkt = P("tkt"); |
| 431 | const char *zTechNote = P("technote"); |
| 432 | const char *zForumPost = P("forumpost"); |
| 433 | const char *zFile = P("file"); |
| 434 | const char *zTarget = 0; |
| 435 | int attachid = atoi(PD("attachid","0")); |
| 436 | char *zUUID = 0; |
| 437 | |
| 438 | if( zFile==0 ) fossil_redirect_home(); |
| 439 | login_check_credentials(); |
| 440 | style_set_current_feature("attach"); |
| 441 | if( zForumPost ){ |
| 442 | int fnid; |
| 443 | if( g.perm.RdForum==0 ){ login_needed(g.anon.RdForum); return; } |
| 444 | /* Forum attachments are always tied to the post's initial version */ |
| 445 | fnid = forumpost_head_rid2(zForumPost); |
| 446 | if( fnid>0 ) zTarget = rid_to_uuid(fnid); |
| 447 | }else if( zPage ){ |
| 448 | if( g.perm.RdWiki==0 ){ login_needed(g.anon.RdWiki); return; } |
| 449 | zTarget = zPage; |
| 450 | }else if( zTkt ){ |
| 451 | if( g.perm.RdTkt==0 ){ login_needed(g.anon.RdTkt); return; } |
| 452 | zTarget = zTkt; |
| @@ -275,84 +539,167 @@ | |
| 539 | Manifest *pManifest; |
| 540 | |
| 541 | db_begin_transaction(); |
| 542 | blob_init(&content, aContent, szContent); |
| 543 | pManifest = manifest_parse(&content, 0, 0); |
| 544 | addCompress = pManifest!=0; |
| 545 | manifest_destroy(pManifest); |
| 546 | blob_init(&content, aContent, szContent); |
| 547 | if( addCompress ){ |
| 548 | blob_compress(&content, &content); |
| 549 | } |
| 550 | rid = content_put_ex(&content, 0, 0, 0, needModerator); |
| 551 | zUUID = rid_to_uuid(rid); |
| 552 | blob_zero(&manifest); |
| 553 | for(i=n=0; zName[i]; i++){ |
| 554 | if( zName[i]=='/' || zName[i]=='\\' ) n = i+1; |
| 555 | } |
| 556 | zName += n; |
| 557 | if( zName[0]==0 ) zName = "unknown"; |
| 558 | blob_appendf(&manifest, "A %F%s %F %s\n", |
| 559 | zName, addCompress ? ".gz" : "", zTarget, zUUID); |
| 560 | if( zComment!=0 && zComment[0]!=0 ){ |
| 561 | while( fossil_isspace(zComment[0]) ) zComment++; |
| 562 | n = strlen(zComment); |
| 563 | while( n>0 && fossil_isspace(zComment[n-1]) ){ n--; } |
| 564 | if( n>0 ){ |
| 565 | blob_appendf(&manifest, "C %#F\n", n, zComment); |
| 566 | } |
| 567 | } |
| 568 | zDate = date_in_standard_format("now"); |
| 569 | blob_appendf(&manifest, "D %z\n", zDate); |
| 570 | blob_appendf(&manifest, "U %F\n", login_name()); |
| 571 | md5sum_blob(&manifest, &cksum); |
| 572 | blob_appendf(&manifest, "Z %b\n", &cksum); |
| 573 | attach_put(&manifest, rid, needModerator); |
| 574 | assert( blob_is_reset(&manifest) ); |
| 575 | db_end_transaction(0); |
| 576 | } |
| 577 | |
| 578 | /* |
| 579 | ** Renders the "legacy" (static) /attachadd form. One of the first |
| 580 | ** four arguments must be non-NULL and the other three must be NULL. |
| 581 | ** zComment may be NULL, as may zFrom. See the call sites for more |
| 582 | ** context. |
| 583 | */ |
| 584 | static void attach_render_legacy_form(const char *zForumPost, |
| 585 | const char *zTechNote, |
| 586 | const char *zTicket, |
| 587 | const char *zWikiPage, |
| 588 | const char *zComment, |
| 589 | const char *zFrom){ |
| 590 | form_begin("enctype='multipart/form-data' id='attachadd-legacy-form'", |
| 591 | "%R/attachadd"); |
| 592 | @ <div>\ |
| 593 | @ File to Attach: |
| 594 | @ <input type="file" name="f" size="60"><br> |
| 595 | @ Description:<br> |
| 596 | @ <textarea name="comment" cols="80" rows="5" wrap="virtual"\ |
| 597 | @ >%h(zComment)</textarea><br> |
| 598 | if( zForumPost ){ |
| 599 | @ <input type="hidden" name="forumpost" value="%h(zForumPost)">\ |
| 600 | }else if( zTicket ){ |
| 601 | @ <input type="hidden" name="tkt" value="%h(zTicket)">\ |
| 602 | }else if( zTechNote ){ |
| 603 | @ <input type="hidden" name="technote" value="%h(zTechNote)">\ |
| 604 | }else if( zWikiPage ){ |
| 605 | @ <input type="hidden" name="page" value="%h(zWikiPage)">\ |
| 606 | } |
| 607 | @ <input type="hidden" name="from" value="%h(zFrom)">\ |
| 608 | @ <input type="submit" name="ok" value="Add Attachment">\ |
| 609 | @ <input type="submit" name="cancel" value="Cancel">\ |
| 610 | @ </div> |
| 611 | captcha_generate(0); |
| 612 | login_insert_csrf_secret(); |
| 613 | @ </form> |
| 614 | } |
| 615 | |
| 616 | /* |
| 617 | ** WEBPAGE: attachadd |
| 618 | ** Add a new attachment. |
| 619 | ** |
| 620 | ** tkt=HASH |
| 621 | ** page=WIKIPAGE |
| 622 | ** technote=HASH |
| 623 | ** forumpost=HASH |
| 624 | ** from=URL |
| 625 | ** |
| 626 | ** Adds a POSTed file attachment to the given target. |
| 627 | ** |
| 628 | ** Or the "version 2" interface: |
| 629 | ** |
| 630 | ** target=ATTACHMENT_TARGET |
| 631 | ** |
| 632 | ** Behaves as documented for attachaddV2_page(). |
| 633 | */ |
| 634 | void attachadd_page(void){ |
| 635 | const char *zPage; |
| 636 | const char *zForumPost; |
| 637 | const char *zTkt; |
| 638 | const char *zTechNote; |
| 639 | const char *aContent; |
| 640 | const char *zName; |
| 641 | const char *zComment; |
| 642 | const char *zTarget; |
| 643 | const char *zFrom; /* Origin page - redirect here after saving */ |
| 644 | char *zTo = 0; /* Optionally redirect here after saving */ |
| 645 | char *zTargetType = 0; |
| 646 | char *zExtraFree = 0; |
| 647 | int szContent; |
| 648 | int goodCaptcha = 1; |
| 649 | int szLimit = 0; |
| 650 | |
| 651 | if( P("target")!=0 ){ |
| 652 | attachaddV2_page(); |
| 653 | return; |
| 654 | } |
| 655 | zPage = P("page"); |
| 656 | zForumPost = P("forumpost"); |
| 657 | zTkt = P("tkt"); |
| 658 | zTechNote = P("technote"); |
| 659 | zFrom = P("from"); |
| 660 | aContent = P("f"); |
| 661 | zName = PD("f:filename","unknown"); |
| 662 | zComment = PD("comment", ""); |
| 663 | szContent = atoi(PD("f:bytes","0")); |
| 664 | |
| 665 | if( zFrom==0 ) zFrom = mprintf("%R/home"); |
| 666 | if( P("cancel") ) cgi_redirect(zFrom); |
| 667 | if( (!!zPage + !!zTkt + !!zTechNote + !!zForumPost)!=1 ){ |
| 668 | webpage_error("Requires exactly one one: page=X, tkt=X, forumpost=X," |
| 669 | " technote=X, or target=X"); |
| 670 | } |
| 671 | login_check_credentials(); |
| 672 | if( zForumPost ){ |
| 673 | int fpid; |
| 674 | if( g.perm.AttachForum==0 ){ |
| 675 | login_needed(g.anon.AttachForum); |
| 676 | return; |
| 677 | } |
| 678 | fpid = forumpost_head_rid2(zForumPost); |
| 679 | if( fpid<=0 ){ |
| 680 | webpage_error("Invalid forum post ID: %h", zForumPost); |
| 681 | }else if( !g.perm.Admin && !forumpost_is_owner(fpid, 0) ){ |
| 682 | webpage_error("Only admins can attach files to other users' " |
| 683 | "forum posts."); |
| 684 | } |
| 685 | zTarget = zExtraFree = rid_to_uuid(fpid); |
| 686 | zTargetType = mprintf("Forum post <a href=\"%R/forumpost/%S\">%h</a>", |
| 687 | zTarget, zForumPost); |
| 688 | zTo = zFrom ? 0 : mprintf("%R/forumpost/%S", zTarget); |
| 689 | }else if( zPage ){ |
| 690 | if( g.perm.ApndWiki==0 || g.perm.Attach==0 ){ |
| 691 | login_needed(g.anon.ApndWiki && g.anon.Attach); |
| 692 | return; |
| 693 | } |
| 694 | if( !db_exists("SELECT 1 FROM tag WHERE tagname='wiki-%q'", zPage) ){ |
| 695 | fossil_redirect_home(); |
| 696 | } |
| 697 | zTarget = zPage; |
| 698 | zTargetType = mprintf("Wiki Page <a href=\"%R/wiki?name=%t\">%h</a>", |
| 699 | zPage, zPage); |
| 700 | zTo = zFrom ? 0 : mprintf("%R/wiki?name=%T", zTarget); |
| 701 | }else if ( zTechNote ){ |
| 702 | if( g.perm.Write==0 || g.perm.ApndWiki==0 || g.perm.Attach==0 ){ |
| 703 | login_needed(g.anon.Write && g.anon.ApndWiki && g.anon.Attach); |
| 704 | return; |
| 705 | } |
| @@ -362,12 +709,13 @@ | |
| 709 | if( zTechNote==0) fossil_redirect_home(); |
| 710 | } |
| 711 | zTarget = zTechNote; |
| 712 | zTargetType = mprintf("Tech Note <a href=\"%R/technote/%s\">%S</a>", |
| 713 | zTechNote, zTechNote); |
| 714 | zTo = zFrom ? 0 : mprintf("%R/technote/%S", zTarget); |
| 715 | }else{ |
| 716 | assert( zTkt ); |
| 717 | if( g.perm.ApndTkt==0 || g.perm.Attach==0 ){ |
| 718 | login_needed(g.anon.ApndTkt && g.anon.Attach); |
| 719 | return; |
| 720 | } |
| 721 | if( !db_exists("SELECT 1 FROM tag WHERE tagname='tkt-%q'", zTkt) ){ |
| @@ -374,56 +722,409 @@ | |
| 722 | zTkt = db_text(0, "SELECT substr(tagname,5) FROM tag" |
| 723 | " WHERE tagname GLOB 'tkt-%q*'", zTkt); |
| 724 | if( zTkt==0 ) fossil_redirect_home(); |
| 725 | } |
| 726 | zTarget = zTkt; |
| 727 | zTargetType = mprintf("Ticket <a href=\"%R/tktview/%S\">%S</a>", |
| 728 | zTkt, zTkt); |
| 729 | zTo = zFrom ? 0 : mprintf("%R/tktview/%S", zTarget); |
| 730 | } |
| 731 | szLimit = db_get_int("attachment-size-limit", 0); |
| 732 | if( szContent<0 || (szLimit && szContent>szLimit) ){ |
| 733 | /* This check must be done late so that zTargetType is set up. */ |
| 734 | @ <p class="generalError">Attachment %h(zName) is too large. |
| 735 | @ <a href="%R/help/attachment-size-limit">Limit</a> is |
| 736 | @ %d(szLimit ? szLimit : 0x7fffffff) bytes</p> |
| 737 | /* Fall through and render form. */ |
| 738 | }else if( P("ok") |
| 739 | && cgi_csrf_safe(2) |
| 740 | && szContent>0 |
| 741 | && (goodCaptcha = captcha_is_correct(0)) ){ |
| 742 | int needModerator = (zForumPost!=0 && forum_need_moderation()) || |
| 743 | (zTkt!=0 && ticket_need_moderation(0)) || |
| 744 | (zPage!=0 && wiki_need_moderation(0)); |
| 745 | attach_commit(zName, zTarget, aContent, szContent, needModerator, zComment); |
| 746 | cgi_redirect(zTo ? zTo : zFrom); |
| 747 | } |
| 748 | |
| 749 | style_set_current_feature("attach"); |
| 750 | style_header("Add Attachment"); |
| 751 | if( !goodCaptcha ){ |
| 752 | @ <p class="generalError">Error: Incorrect security code.</p> |
| 753 | } |
| 754 | @ <h2>Add Attachment To %s(zTargetType)</h2> |
| 755 | attach_render_legacy_form(zForumPost, zTechNote, zTkt, zPage, |
| 756 | zComment, zFrom); |
| 757 | builtin_fossil_js_bundle_or("attach", NULL); |
| 758 | style_finish_page(); |
| 759 | fossil_free(zTargetType); |
| 760 | fossil_free(zExtraFree); |
| 761 | } |
| 762 | |
| 763 | /* |
| 764 | ** WEBPAGE: attachadd_ajax_post hidden |
| 765 | ** |
| 766 | ** Used by attachadd V2 to handle attachments via POST requests with: |
| 767 | ** |
| 768 | ** target=ATTACHMENT_TARGET |
| 769 | ** file1..fileN=FILE_OBJECTS |
| 770 | ** dryrun=0|1 |
| 771 | ** |
| 772 | ** Each posted file in the set file1..fileN gets attached to the given |
| 773 | ** target, permissions permitting. If dryrun>0 then the change is |
| 774 | ** rolled back instead of committed. target=X must refer to a full |
| 775 | ** target ID, not a prefix. |
| 776 | ** |
| 777 | ** Responds with JSON: an empty object on success and |
| 778 | ** {error:"message"} on error. The on-success response structure is |
| 779 | ** subject to amendment. |
| 780 | */ |
| 781 | void attachadd_ajax_post(void){ |
| 782 | const char *zTarget; |
| 783 | char *zExtraFree = 0; |
| 784 | int eTgtType = 0; |
| 785 | int bNeedsModeration = 0; |
| 786 | int goodCaptcha = 1; |
| 787 | int bRollback = 0; /* Roll back if true. */ |
| 788 | |
| 789 | if( ! ajax_route_bootstrap(0, 1) ){ |
| 790 | return; |
| 791 | }else if( !(goodCaptcha = captcha_is_correct(0)) ){ |
| 792 | goto ajax_err_403; |
| 793 | }else if( !ajax_check_csrf(2) ){ |
| 794 | return; |
| 795 | } |
| 796 | db_begin_transaction(); |
| 797 | zTarget = P("target"); |
| 798 | eTgtType = attachment_target_type(zTarget, 1); |
| 799 | CX("{"); |
| 800 | switch( eTgtType ){ |
| 801 | default: |
| 802 | case 0: |
| 803 | ajax_route_error(400, "Invalid attachment target."); |
| 804 | db_rollback_transaction(); |
| 805 | return; |
| 806 | case CFTYPE_FORUM:{ |
| 807 | int fpid; |
| 808 | if( g.perm.AttachForum==0 ){ |
| 809 | goto ajax_err_403; |
| 810 | } |
| 811 | fpid = forumpost_head_rid2(zTarget); |
| 812 | if( fpid<=0 ){ |
| 813 | goto ajax_err_404; |
| 814 | }else if( !g.perm.Admin && !forumpost_is_owner(fpid, 0) ){ |
| 815 | ajax_route_error(403, "Only admins can attach files to " |
| 816 | "other users' forum posts."); |
| 817 | db_rollback_transaction(); |
| 818 | return; |
| 819 | } |
| 820 | zTarget = zExtraFree = rid_to_uuid(fpid); |
| 821 | bNeedsModeration = forum_need_moderation(); |
| 822 | break; |
| 823 | } |
| 824 | case CFTYPE_EVENT:{ |
| 825 | if( g.perm.Write==0 || g.perm.ApndWiki==0 || g.perm.Attach==0 ){ |
| 826 | goto ajax_err_403; |
| 827 | } |
| 828 | if( !db_exists("SELECT 1 FROM tag WHERE tagname='event-%q'", |
| 829 | zTarget) ){ |
| 830 | zTarget = zExtraFree = |
| 831 | db_text(0, "SELECT substr(tagname,7) FROM tag" |
| 832 | " WHERE tagname GLOB 'event-%q*'", zTarget); |
| 833 | if( zTarget==0){ |
| 834 | goto ajax_err_404; |
| 835 | } |
| 836 | } |
| 837 | bNeedsModeration = 0; |
| 838 | break; |
| 839 | } |
| 840 | case CFTYPE_TICKET:{ |
| 841 | if( g.perm.ApndTkt==0 || g.perm.Attach==0 ){ |
| 842 | goto ajax_err_403; |
| 843 | } |
| 844 | if( !db_exists("SELECT 1 FROM tag WHERE tagname='tkt-%q'", |
| 845 | zTarget) ){ |
| 846 | zTarget = db_text(0, "SELECT substr(tagname,5) FROM tag" |
| 847 | " WHERE tagname GLOB 'tkt-%q*'", zTarget); |
| 848 | if( zTarget==0 ){ |
| 849 | goto ajax_err_404; |
| 850 | } |
| 851 | } |
| 852 | bNeedsModeration = ticket_need_moderation(0); |
| 853 | break; |
| 854 | } |
| 855 | case CFTYPE_WIKI:{ |
| 856 | if( g.perm.ApndWiki==0 || g.perm.Attach==0 ){ |
| 857 | goto ajax_err_403; |
| 858 | } |
| 859 | if( !db_exists("SELECT 1 FROM tag WHERE tagname='wiki-%q'", |
| 860 | zTarget) ){ |
| 861 | goto ajax_err_404; |
| 862 | } |
| 863 | bNeedsModeration = wiki_need_moderation(0); |
| 864 | break; |
| 865 | } |
| 866 | } |
| 867 | |
| 868 | if( attachments_ajax_from_POST(zTarget, bNeedsModeration)>=0 ){ |
| 869 | CX("}"); |
| 870 | if( atoi(PD("dryrun","0"))>0 ){ |
| 871 | bRollback = 1; |
| 872 | } |
| 873 | }/*else error response was set up*/ |
| 874 | fossil_free(zExtraFree); |
| 875 | db_end_transaction(bRollback); |
| 876 | return; |
| 877 | ajax_err_403: |
| 878 | if( db_transaction_nesting_depth()>0 ){ |
| 879 | db_rollback_transaction(); |
| 880 | } |
| 881 | ajax_route_error_forbidden(); |
| 882 | return; |
| 883 | ajax_err_404: |
| 884 | assert( db_transaction_nesting_depth()>0 ); |
| 885 | db_rollback_transaction(); |
| 886 | ajax_route_error(404, "Target not found."); |
| 887 | return; |
| 888 | } |
| 889 | |
| 890 | /* |
| 891 | ** A helper for AJAX-style routines which accept file attachments via |
| 892 | ** POST. zTarget must be a full attachment target. bNeedsModeration |
| 893 | ** must be true if the attachment requires moderation. |
| 894 | ** |
| 895 | ** It is up to the caller to have validated all security measures |
| 896 | ** before calling this. |
| 897 | ** |
| 898 | ** This looks for POSTed files names "file1".."fileN", stopping when |
| 899 | ** it finds no entry. Returns the number of entries attached to the |
| 900 | ** target or a negative value on error (in which case the current db |
| 901 | ** transaction will be in a rollback state). |
| 902 | ** |
| 903 | ** The only errors are currently attachment size limit violations: |
| 904 | ** attachments must have a non-0 size and if the attachment-size-limit |
| 905 | ** setting is >0 then each file's size must be <= that. |
| 906 | ** |
| 907 | ** If this returns a negative value, it will have populated an error |
| 908 | ** response using ajax_route_error(). On success it produces no |
| 909 | ** output. |
| 910 | ** |
| 911 | ** ACHTUNG: if zTarget is a forum post, it "really should" be the ID |
| 912 | ** of the first version of that post, as that's where attachments are |
| 913 | ** intended to be applied so that they can be found and removed |
| 914 | ** consistently. Potential TODO is have this function do that if |
| 915 | ** attachment_target_type(zTarget,1)!=0 but it would (for current |
| 916 | ** uses) require duplicating work already done in the callers. |
| 917 | */ |
| 918 | int attachments_ajax_from_POST(const char *zTarget, int bNeedsModeration){ |
| 919 | int i; |
| 920 | int rc = 0; |
| 921 | int n = 0; |
| 922 | int szLimit; /* attachment-max-size setting */ |
| 923 | char aKeyPrefix[20]; /* Buffer for key "file%d" */ |
| 924 | char aKeySize[30]; /* Buffer for key "file%d:bytes" */ |
| 925 | char aKeyName[30]; /* Buffer for key "file%d:filename" */ |
| 926 | char aKeyDesc[30]; /* Buffer for key "file%d_desc" */ |
| 927 | |
| 928 | db_begin_transaction(); |
| 929 | szLimit = db_get_int("attachment-size-limit", 0); |
| 930 | |
| 931 | for(i = 1; ; ++i, ++n){ |
| 932 | /* Look for P("fileN"), where N=1..n */ |
| 933 | const char *zContent; |
| 934 | const char *zFilename; |
| 935 | int szContent; |
| 936 | sqlite3_snprintf(sizeof(aKeyPrefix), aKeyPrefix, "file%d", i); |
| 937 | zContent = P(aKeyPrefix); |
| 938 | if( !zContent ){ |
| 939 | /* End of the list. */ |
| 940 | break; |
| 941 | } |
| 942 | sqlite3_snprintf(sizeof(aKeySize), aKeySize, "%s:bytes", |
| 943 | aKeyPrefix); |
| 944 | szContent = atoi(PD(aKeySize,"-1")); |
| 945 | if( szContent<=0 ){ |
| 946 | rc = -ajax_route_error(400,"Invalid file size: %d", szContent); |
| 947 | break; |
| 948 | }else if( szLimit>0 && szContent>szLimit ){ |
| 949 | rc = -ajax_route_error(413, "File size limit is %d bytes.", szLimit); |
| 950 | break; |
| 951 | }else{ |
| 952 | sqlite3_snprintf(sizeof(aKeyName), aKeyName, "%s:filename", |
| 953 | aKeyPrefix); |
| 954 | sqlite3_snprintf(sizeof(aKeyDesc), aKeyDesc, "%s_desc", |
| 955 | aKeyPrefix); |
| 956 | if( 0==(zFilename=P(aKeyName)) ){ |
| 957 | rc = -ajax_route_error(400, "Missing filename."); |
| 958 | break; |
| 959 | } |
| 960 | attach_commit(zFilename, zTarget, zContent, szContent, |
| 961 | bNeedsModeration, P(aKeyDesc)); |
| 962 | } |
| 963 | } |
| 964 | if( rc<0 ){ |
| 965 | db_rollback_transaction(); |
| 966 | return rc; |
| 967 | }else{ |
| 968 | db_commit_transaction(); |
| 969 | return n; |
| 970 | } |
| 971 | } |
| 972 | |
| 973 | /* |
| 974 | ** Proxy for /attachadd?target=X |
| 975 | ** |
| 976 | ** Lists attachments for, and can add them to, a target artifact. |
| 977 | ** |
| 978 | ** target=TKT_HASH|WIKIPAGE_NAME|TECHNOTE_HASH|FORUMPOST_HASH |
| 979 | ** from=ORIGINATING_URL |
| 980 | ** |
| 981 | ** Works like /attachadd but uses a JS-based interactive attachment |
| 982 | ** selector. |
| 983 | ** |
| 984 | ** from=X tells it where to redirect to when it's done. |
| 985 | ** |
| 986 | ** This page requires a post-2018-ish JS-capable browser. |
| 987 | */ |
| 988 | void attachaddV2_page(void){ |
| 989 | const char *zFrom = P("from"); |
| 990 | const char *zTarget = P("target"); |
| 991 | char *zTo = 0; |
| 992 | char *zTargetType = 0; |
| 993 | char *zExtraFree = 0; |
| 994 | int eTgtType = 0; |
| 995 | int goodCaptcha = 1; |
| 996 | char const * noJsArgs[] = {0,0,0,0}; /* Args for noscript form */ |
| 997 | |
| 998 | if( P("cancel") ) cgi_redirect(zFrom); |
| 999 | if( 0==zTarget ){ |
| 1000 | webpage_error("Requires target=X"); |
| 1001 | } |
| 1002 | login_check_credentials(); |
| 1003 | eTgtType = attachment_target_type(zTarget, 1); |
| 1004 | switch( eTgtType ){ |
| 1005 | default: |
| 1006 | case 0: |
| 1007 | webpage_error("Cannot resolve target=%h.", zTarget); |
| 1008 | break; |
| 1009 | case CFTYPE_FORUM:{ |
| 1010 | int fpid; |
| 1011 | if( g.perm.AttachForum==0 ){ |
| 1012 | login_needed(g.anon.AttachForum); |
| 1013 | return; |
| 1014 | } |
| 1015 | fpid = forumpost_head_rid2(zTarget); |
| 1016 | if( fpid<=0 ){ |
| 1017 | webpage_error("Invalid forum post ID: %h", zTarget); |
| 1018 | }else if( !g.perm.Admin && !forumpost_is_owner(fpid, 0) ){ |
| 1019 | webpage_error("Only admins can attach files to other users' " |
| 1020 | "forum posts."); |
| 1021 | } |
| 1022 | zTarget = zExtraFree = rid_to_uuid(fpid); |
| 1023 | noJsArgs[0] = zTarget; |
| 1024 | zTargetType = mprintf( |
| 1025 | "Forum post <a href=\"%R/forumpost/%S\">%.16h</a>", |
| 1026 | zTarget, zTarget |
| 1027 | ); |
| 1028 | zTo = mprintf("%R/forumpost/%S", zTarget); |
| 1029 | break; |
| 1030 | } |
| 1031 | case CFTYPE_EVENT:{ |
| 1032 | if( g.perm.Write==0 || g.perm.ApndWiki==0 || g.perm.Attach==0 ){ |
| 1033 | login_needed(g.anon.Write && g.anon.ApndWiki && g.anon.Attach); |
| 1034 | return; |
| 1035 | } |
| 1036 | if( !db_exists("SELECT 1 FROM tag WHERE tagname='event-%q'", |
| 1037 | zTarget) ){ |
| 1038 | zTarget = db_text(0, "SELECT substr(tagname,7) FROM tag" |
| 1039 | " WHERE tagname GLOB 'event-%q*'", |
| 1040 | zTarget); |
| 1041 | if( zTarget==0) fossil_redirect_home(); |
| 1042 | } |
| 1043 | zTo = zFrom ? 0 : mprintf("%R/technote?name=%T", zTarget); |
| 1044 | zTargetType = mprintf("Tech-note <a href=\"%R/technote/%s\">%S</a>", |
| 1045 | zTarget, zTarget); |
| 1046 | noJsArgs[1] = zTarget; |
| 1047 | break; |
| 1048 | } |
| 1049 | case CFTYPE_TICKET:{ |
| 1050 | if( g.perm.ApndTkt==0 || g.perm.Attach==0 ){ |
| 1051 | login_needed(g.anon.ApndTkt && g.anon.Attach); |
| 1052 | return; |
| 1053 | } |
| 1054 | if( !db_exists("SELECT 1 FROM tag WHERE tagname='tkt-%q'", |
| 1055 | zTarget) ){ |
| 1056 | zTarget = db_text(0, "SELECT substr(tagname,5) FROM tag" |
| 1057 | " WHERE tagname GLOB 'tkt-%q*'", zTarget); |
| 1058 | if( zTarget==0 ) fossil_redirect_home(); |
| 1059 | } |
| 1060 | zTo = zFrom ? 0 : mprintf("%R/tktview/%t", zTarget); |
| 1061 | zTargetType = mprintf("Ticket <a href=\"%R/tktview/%s\">%S</a>", |
| 1062 | zTarget, zTarget); |
| 1063 | noJsArgs[2] = zTarget; |
| 1064 | break; |
| 1065 | } |
| 1066 | case CFTYPE_WIKI:{ |
| 1067 | if( g.perm.ApndWiki==0 || g.perm.Attach==0 ){ |
| 1068 | login_needed(g.anon.ApndWiki && g.anon.Attach); |
| 1069 | return; |
| 1070 | } |
| 1071 | if( !db_exists("SELECT 1 FROM tag WHERE tagname='wiki-%q'", |
| 1072 | zTarget) ){ |
| 1073 | fossil_redirect_home(); |
| 1074 | } |
| 1075 | zTo = zFrom ? 0 : mprintf("%R/wiki?name=%T", zTarget); |
| 1076 | zTargetType = mprintf( |
| 1077 | "Wiki page <a href=\"%R/wiki?name=%h\">%h</a>", |
| 1078 | zTarget, zTarget |
| 1079 | ); |
| 1080 | noJsArgs[3] = zTarget; |
| 1081 | break; |
| 1082 | } |
| 1083 | } |
| 1084 | |
| 1085 | db_begin_transaction(); |
| 1086 | |
| 1087 | style_set_current_feature("attach"); |
| 1088 | style_header("Add Attachment"); |
| 1089 | if( !goodCaptcha ){ |
| 1090 | @ <p class="generalError">Error: Incorrect security code.</p> |
| 1091 | } |
| 1092 | @ <h2>Attachments for %s(zTargetType)</h2> |
| 1093 | attachment_list(zTarget, NULL, |
| 1094 | ATTACHLIST_SIZE | ATTACHLIST_HIDE_UNAPPROVED); |
| 1095 | attach_render_legacy_form( |
| 1096 | noJsArgs[0], noJsArgs[1], noJsArgs[2], |
| 1097 | noJsArgs[3], 0, |
| 1098 | zFrom ? zFrom : (zTo ? zTo : (zTo=mprintf("%R/home"))) |
| 1099 | ); |
| 1100 | @ <div id='attachadd-form-wrapper' class='hidden'> |
| 1101 | /* fossil.attach.js populates this DIV with the attachment widget, |
| 1102 | ** imports these hidden fields, and removes the legacy form. */ |
| 1103 | @ <input type="hidden" name="target" value="%h(zTarget)"> |
| 1104 | if( zFrom ){ |
| 1105 | @ <input type="hidden" name="from" value="%h(zFrom)"> |
| 1106 | } |
| 1107 | if( zTo ){ |
| 1108 | @ <input type="hidden" name="to" value="%h(zTo)"> |
| 1109 | } |
| 1110 | captcha_generate(0); |
| 1111 | login_insert_csrf_secret(); |
| 1112 | @ </div> |
| 1113 | builtin_fossil_js_bundle_or("attach", NULL); |
| 1114 | db_end_transaction(0); |
| 1115 | style_finish_page(); |
| 1116 | fossil_free(zTargetType); |
| 1117 | fossil_free(zExtraFree); |
| 1118 | fossil_free(zTo); |
| 1119 | } |
| 1120 | |
| 1121 | /* |
| 1122 | ** WEBPAGE: ainfo |
| 1123 | ** URL: /ainfo?name=ARTIFACTID |
| 1124 | ** |
| 1125 | ** name=ATTACHMENT_ARTIFACT_UUID |
| 1126 | ** |
| 1127 | ** Show the details of an attachment artifact. |
| 1128 | */ |
| 1129 | void ainfo_page(void){ |
| 1130 | int rid; /* RID for the control artifact */ |
| @@ -436,113 +1137,145 @@ | |
| 1137 | const char *zName; /* Name of the attached file */ |
| 1138 | const char *zDesc; /* Description of the attached file */ |
| 1139 | const char *zWikiName = 0; /* Wiki page name when attached to Wiki */ |
| 1140 | const char *zTNUuid = 0; /* Tech Note ID when attached to tech note */ |
| 1141 | const char *zTktUuid = 0; /* Ticket ID when attached to a ticket */ |
| 1142 | const char *zForumPost = 0; /* Forum UID when attached to forum post */ |
| 1143 | int modPending; /* True if awaiting moderation */ |
| 1144 | const char *zModAction; /* Moderation action or NULL */ |
| 1145 | int isModerator; /* TRUE if user is the moderator */ |
| 1146 | const char *zMime; /* MIME Type */ |
| 1147 | Blob attach; /* Content of the attachment */ |
| 1148 | int fShowContent = 0; /* True to emit the content */ |
| 1149 | int bUserIsOwner = 0; /* True if pAttach->zUser is login_name() */ |
| 1150 | int showDelMenu = 0; /* True to enable delete option */ |
| 1151 | const char *zLn = P("ln"); |
| 1152 | |
| 1153 | login_check_credentials(); |
| 1154 | if( !g.perm.RdTkt && !g.perm.RdWiki ){ |
| 1155 | login_needed(g.anon.RdTkt || g.anon.RdWiki); |
| 1156 | return; |
| 1157 | } |
| 1158 | rid = name_to_rid_www("name"); |
| 1159 | if( rid==0 ){ fossil_redirect_home(); } |
| 1160 | zUuid = rid_to_uuid(rid); |
| 1161 | pAttach = manifest_get(rid, CFTYPE_ATTACHMENT, 0); |
| 1162 | if( pAttach==0 ) fossil_redirect_home(); |
| 1163 | bUserIsOwner = |
| 1164 | 0==fossil_strcmp(pAttach->zUser, login_name()) |
| 1165 | && login_is_individual(); |
| 1166 | zTarget = pAttach->zAttachTarget; |
| 1167 | zSrc = pAttach->zAttachSrc; |
| 1168 | ridSrc = db_int(0,"SELECT rid FROM blob WHERE uuid='%q'", zSrc); |
| 1169 | zName = pAttach->zAttachName; |
| 1170 | zDesc = pAttach->zComment; |
| 1171 | zMime = mimetype_from_name(zName); |
| 1172 | fShowContent = zMime ? strncmp(zMime,"text/", 5)==0 : 0; |
| 1173 | if( db_int(0,"SELECT 1 FROM event WHERE objid=%d and type='f'", rid) ){ |
| 1174 | if( !g.perm.RdForum ){ login_needed(g.anon.RdForum); return; } |
| 1175 | showDelMenu = g.perm.Admin || bUserIsOwner; |
| 1176 | zForumPost = zTarget; |
| 1177 | }else if( validate16(zTarget, strlen(zTarget)) |
| 1178 | && db_exists("SELECT 1 FROM ticket WHERE tkt_uuid='%q'", zTarget) |
| 1179 | ){ |
| 1180 | if( !g.perm.RdTkt ){ login_needed(g.anon.RdTkt); return; } |
| 1181 | zTktUuid = zTarget; |
| 1182 | showDelMenu = g.perm.WrTkt; |
| 1183 | }else if( db_exists("SELECT 1 FROM tag WHERE tagname='wiki-%q'", |
| 1184 | zTarget) ){ |
| 1185 | if( !g.perm.RdWiki ){ login_needed(g.anon.RdWiki); return; } |
| 1186 | zWikiName = zTarget; |
| 1187 | showDelMenu = g.perm.WrWiki; |
| 1188 | }else if( db_exists("SELECT 1 FROM tag WHERE tagname='event-%q'", |
| 1189 | zTarget) ){ |
| 1190 | if( !g.perm.RdWiki ){ login_needed(g.anon.RdWiki); return; } |
| 1191 | zTNUuid = zTarget; |
| 1192 | showDelMenu = g.perm.Write && g.perm.WrWiki; |
| 1193 | } |
| 1194 | if( showDelMenu ){ |
| 1195 | style_submenu_element("Delete", "%R/ainfo/%s?del", zUuid); |
| 1196 | } |
| 1197 | zDate = db_text(0, "SELECT datetime(%.12f)", pAttach->rDate); |
| 1198 | |
| 1199 | if( P("confirm") |
| 1200 | && cgi_csrf_safe(2) |
| 1201 | && ((zForumPost |
| 1202 | && ((bUserIsOwner && g.perm.AttachForum) || |
| 1203 | forumpost_may_close())) || |
| 1204 | (zTktUuid && g.perm.WrTkt) || |
| 1205 | (zWikiName && g.perm.WrWiki) || |
| 1206 | (zTNUuid && g.perm.Write && g.perm.WrWiki)) |
| 1207 | ){ |
| 1208 | /* Delete attachment. */ |
| 1209 | int i, n, rid; |
| 1210 | char *zNewDate; |
| 1211 | Blob manifest; |
| 1212 | Blob cksum; |
| 1213 | const char *zFile = zName; |
| 1214 | |
| 1215 | if( !bUserIsOwner ){ |
| 1216 | if( zForumPost ? !forumpost_may_close() : !g.perm.Admin ){ |
| 1217 | webpage_error( |
| 1218 | "Only admins can delete other users' attachments." |
| 1219 | ); |
| 1220 | } |
| 1221 | } |
| 1222 | db_begin_transaction(); |
| 1223 | blob_zero(&manifest); |
| 1224 | for(i=n=0; zFile[i]; i++){ |
| 1225 | if( zFile[i]=='/' || zFile[i]=='\\' ) n = i; |
| 1226 | } |
| 1227 | zFile += n; |
| 1228 | if( zFile[0]==0 ) zFile = "unknown"; |
| 1229 | blob_appendf(&manifest, "A %F %F\n", zFile, zTarget); |
| 1230 | zNewDate = date_in_standard_format("now"); |
| 1231 | blob_appendf(&manifest, "D %s\n", zNewDate); |
| 1232 | blob_appendf(&manifest, "U %F\n", login_name()); |
| 1233 | md5sum_blob(&manifest, &cksum); |
| 1234 | blob_appendf(&manifest, "Z %b\n", &cksum); |
| 1235 | rid = content_put(&manifest); |
| 1236 | manifest_crosslink(rid, &manifest, MC_NONE); |
| 1237 | db_end_transaction(0); |
| 1238 | @ <p>The attachment below has been deleted.</p> |
| 1239 | fossil_free(zNewDate); |
| 1240 | } |
| 1241 | |
| 1242 | if( P("del") |
| 1243 | && ((zForumPost && (bUserIsOwner || forumpost_may_close())) |
| 1244 | || (zTktUuid && g.perm.WrTkt) |
| 1245 | || (zWikiName && g.perm.WrWiki) |
| 1246 | || (zTNUuid && g.perm.Write && g.perm.WrWiki)) |
| 1247 | ){ |
| 1248 | form_begin(0, "%R/ainfo/%!S", zUuid); |
| 1249 | @ <p>Confirm you want to delete the attachment shown below. |
| 1250 | @ <input type="submit" name="confirm" value="Confirm"> |
| 1251 | login_insert_csrf_secret(); |
| 1252 | @ </form> |
| 1253 | } |
| 1254 | |
| 1255 | isModerator = g.perm.Admin || |
| 1256 | (zForumPost && g.perm.ModForum) || |
| 1257 | (zTktUuid && g.perm.ModTkt) || |
| 1258 | (zWikiName && g.perm.ModWiki); |
| 1259 | zModAction = P("modaction"); |
| 1260 | if( zModAction!=0 && cgi_csrf_safe(2) ){ |
| 1261 | if( strcmp(zModAction,"delete")==0 ){ |
| 1262 | if( isModerator || bUserIsOwner ){ |
| 1263 | moderation_disapprove(rid); |
| 1264 | } |
| 1265 | if( zForumPost ){ |
| 1266 | cgi_redirectf("%R/forumpost/%!S", zForumPost); |
| 1267 | }else if( zTktUuid ){ |
| 1268 | cgi_redirectf("%R/tktview/%!S", zTktUuid); |
| 1269 | }else if( zWikiName ) { |
| 1270 | cgi_redirectf("%R/wiki?name=%t", zWikiName); |
| 1271 | } |
| 1272 | /* zTNUuid is intentionally unhandled. Tech note attachments |
| 1273 | ** don't go through moderation. */ |
| 1274 | return; |
| 1275 | } |
| 1276 | if( isModerator && strcmp(zModAction,"approve")==0 ){ |
| 1277 | moderation_approve('a', rid); |
| 1278 | } |
| 1279 | } |
| 1280 | style_set_current_feature("attach"); |
| 1281 | style_header("Attachment Details"); |
| @@ -558,21 +1291,24 @@ | |
| 1291 | @ <td>%z(href("%R/artifact/%!S",zUuid))%s(zUuid)</a> |
| 1292 | if( g.perm.Setup ){ |
| 1293 | @ (%d(rid)) |
| 1294 | } |
| 1295 | modPending = moderation_pending_www(rid); |
| 1296 | if( zForumPost ){ |
| 1297 | @ <tr><th>Forum Post:</th> |
| 1298 | @ <td>%z(href("%R/forumpost/%s",zForumPost))%h(zForumPost)</a>\ |
| 1299 | @ </td></tr> |
| 1300 | }else if( zTktUuid ){ |
| 1301 | @ <tr><th>Ticket:</th> |
| 1302 | @ <td>%z(href("%R/tktview/%s",zTktUuid))%s(zTktUuid)</a></td></tr> |
| 1303 | }else if( zTNUuid ){ |
| 1304 | @ <tr><th>Tech Note:</th> |
| 1305 | @ <td>%z(href("%R/technote/%s",zTNUuid))%s(zTNUuid)</a></td></tr> |
| 1306 | }else if( zWikiName ){ |
| 1307 | @ <tr><th>Wiki Page:</th> |
| 1308 | @ <td>%z(href("%R/wiki?name=%t",zWikiName))%h(zWikiName)</a>\ |
| 1309 | @ </td></tr> |
| 1310 | } |
| 1311 | @ <tr><th>Date:</th><td> |
| 1312 | hyperlink_to_date(zDate, "</td></tr>"); |
| 1313 | @ <tr><th>User:</th><td> |
| 1314 | hyperlink_to_user(pAttach->zUser, zDate, "</td></tr>"); |
| @@ -583,104 +1319,197 @@ | |
| 1319 | } |
| 1320 | @ <tr><th>Filename:</th><td>%h(zName)</td></tr> |
| 1321 | if( g.perm.Setup ){ |
| 1322 | @ <tr><th>MIME-Type:</th><td>%h(zMime)</td></tr> |
| 1323 | } |
| 1324 | @ <tr><th valign="top">Description:</th>\ |
| 1325 | /* FIXME (2026-06-05): Honor the N-card (comment mimetype). */ |
| 1326 | @ <td valign="top">%h(zDesc)</td></tr> |
| 1327 | @ </table> |
| 1328 | |
| 1329 | if( modPending && (isModerator || bUserIsOwner) ){ |
| 1330 | @ <div class="section">Moderation</div> |
| 1331 | @ <blockquote> |
| 1332 | form_begin(0, "%R/ainfo/%s", zUuid); |
| 1333 | @ <label><input type="radio" name="modaction" value="delete"> |
| 1334 | @ Delete this attachment</label><br> |
| 1335 | if( isModerator ){ |
| 1336 | #if 0 |
| 1337 | /* TODO/FIXME (2026-06-03): only allow approval of an attachment |
| 1338 | ** if its target has been approved. Without this, we can end up |
| 1339 | ** with stale attachments which refer to rejected targets. We |
| 1340 | ** need a type-specific RID/UUID here, which requires |
| 1341 | ** refactoring above to get it. */ |
| 1342 | const int tgtid = 0; |
| 1343 | if( moderation_pending(tgtid) ){ |
| 1344 | @ <label><input type="radio" name="modaction" \ |
| 1345 | @ disabled value="approve"> |
| 1346 | @ <span class='modpending'>Cannot approve: |
| 1347 | @ target is pending moderation</span>\ |
| 1348 | @ </label><br> |
| 1349 | }else |
| 1350 | #else |
| 1351 | { |
| 1352 | @ <label><input type="radio" name="modaction" value="approve"> |
| 1353 | @ Approve this attachment</label><br> |
| 1354 | } |
| 1355 | #endif |
| 1356 | } |
| 1357 | @ <input type="submit" value="Submit"> |
| 1358 | login_insert_csrf_secret(); |
| 1359 | @ </form> |
| 1360 | @ </blockquote> |
| 1361 | } |
| 1362 | |
| 1363 | @ <div class="section">Content:</div> |
| 1364 | blob_zero(&attach); |
| 1365 | if( modPending && !moderation_user_could(rid, 1, 0) ){ |
| 1366 | @ <p><span class="modpending">Content is awaiting moderator \ |
| 1367 | @ approval.</span></p> |
| 1368 | }else{ |
| 1369 | @ <blockquote> |
| 1370 | if( fShowContent ){ |
| 1371 | const char *z; |
| 1372 | content_get(ridSrc, &attach); |
| 1373 | blob_to_utf8_no_bom(&attach, 0); |
| 1374 | z = blob_str(&attach); |
| 1375 | if( zLn ){ |
| 1376 | output_text_with_line_numbers(z, blob_size(&attach), |
| 1377 | zName, zLn, 1); |
| 1378 | }else{ |
| 1379 | @ <pre> |
| 1380 | @ %h(z) |
| 1381 | @ </pre> |
| 1382 | } |
| 1383 | }else if( strncmp(zMime, "image/", 6)==0 ){ |
| 1384 | int sz = db_int(0, "SELECT size FROM blob WHERE rid=%d", ridSrc); |
| 1385 | @ <i>(file is %d(sz) bytes of image data)</i><br> |
| 1386 | @ <img src="%R/raw/%s(zSrc)?m=%s(zMime)"></img> |
| 1387 | style_submenu_element("Image", "%R/raw/%s?m=%s", zSrc, zMime); |
| 1388 | }else{ |
| 1389 | int sz = db_int(0, "SELECT size FROM blob WHERE rid=%d", ridSrc); |
| 1390 | @ <i>(file is %d(sz) bytes of binary data)</i> |
| 1391 | } |
| 1392 | @ </blockquote> |
| 1393 | } |
| 1394 | manifest_destroy(pAttach); |
| 1395 | blob_reset(&attach); |
| 1396 | style_finish_page(); |
| 1397 | } |
| 1398 | |
| 1399 | #if INTERFACE |
| 1400 | /* |
| 1401 | ** Flags for use with attachment_list(). ATTACHLIST_HRULE_ABOVE |
| 1402 | ** must have a value of 1 for historical call compatibility. |
| 1403 | */ |
| 1404 | #define ATTACHLIST_HRULE_ABOVE 0x01 /* Insert <hr> above header */ |
| 1405 | #define ATTACHLIST_TARGET_BLANK 0x02 /* use target=_blank for links */ |
| 1406 | #define ATTACHLIST_SIZE 0x04 /* add size */ |
| 1407 | #define ATTACHLIST_HIDE_UNAPPROVED 0x08 /* Hide pending-moderation files */ |
| 1408 | #define ATTACHLIST_DETAILS_CLOSED 0x10 /* Wrap in a closed DETAILS element */ |
| 1409 | #define ATTACHLIST_DETAILS_OPEN 0x20 /* Wrap in an open DETAILS element */ |
| 1410 | #define ATTACHLIST_HIDE_EMPTY 0x40 /* Skip if size<1 */ |
| 1411 | #endif |
| 1412 | |
| 1413 | /* |
| 1414 | ** Output HTML to show a list of attachments. |
| 1415 | */ |
| 1416 | void attachment_list( |
| 1417 | const char *zTarget, /* Object that things are attached to */ |
| 1418 | const char *zHeader, /* Header to display with attachments */ |
| 1419 | const int flags /* ATTACHLIST_... flags */ |
| 1420 | ){ |
| 1421 | int cnt = 0; |
| 1422 | char szBuf[36] = {0}; /* scratchpad for attachment size value */ |
| 1423 | const char *zLinkTgt = (ATTACHLIST_TARGET_BLANK & flags) |
| 1424 | ? " target=\"_blank\"" : ""; |
| 1425 | const int bUseDetail = flags & |
| 1426 | (ATTACHLIST_DETAILS_CLOSED | ATTACHLIST_DETAILS_OPEN); |
| 1427 | Stmt q; |
| 1428 | |
| 1429 | db_prepare(&q, |
| 1430 | "SELECT datetime(mtime,toLocal()), a.filename, a.user," |
| 1431 | " b1.uuid, a.src, a.target, a.attachid, b2.size\n" |
| 1432 | " FROM attachment a, blob b1, blob b2\n" |
| 1433 | " WHERE a.isLatest\n" |
| 1434 | " AND a.src IS NOT NULL\n" |
| 1435 | " AND a.target=%Q\n" |
| 1436 | " AND b1.rid=a.attachid\n" |
| 1437 | " AND b2.uuid=a.src\n" |
| 1438 | " ORDER BY mtime DESC", |
| 1439 | zTarget |
| 1440 | ); |
| 1441 | while( db_step(&q)==SQLITE_ROW ){ |
| 1442 | const char *zDate = db_column_text(&q, 0); |
| 1443 | const char *zFile = db_column_text(&q, 1); |
| 1444 | const char *zUser = db_column_text(&q, 2); |
| 1445 | const char *zUuid = db_column_text(&q, 3); |
| 1446 | const char *zSrc = db_column_text(&q, 4); |
| 1447 | const char *zTarget = db_column_text(&q, 5); |
| 1448 | const char *zDispUser = zUser && zUser[0] ? zUser : "anonymous"; |
| 1449 | const char *zTypeArg = 0; /* URL arg name for /attachdownload */ |
| 1450 | const int aid = db_column_int(&q, 6); |
| 1451 | const int sz = db_column_int(&q, 7); |
| 1452 | if( (flags & ATTACHLIST_HIDE_UNAPPROVED) |
| 1453 | && moderation_pending(aid) |
| 1454 | && !moderation_user_could(aid, 1, 0) ){ |
| 1455 | continue; |
| 1456 | } |
| 1457 | if( sz<1 && (flags & ATTACHLIST_HIDE_EMPTY) ){ |
| 1458 | /* Deleted or phantom items. */ |
| 1459 | continue; |
| 1460 | } |
| 1461 | if( cnt==0 ){ |
| 1462 | if( bUseDetail ){ |
| 1463 | @ <details class='attachlist' |
| 1464 | if( ATTACHLIST_DETAILS_OPEN & flags ){ |
| 1465 | @ open |
| 1466 | } |
| 1467 | @ > |
| 1468 | }else{ |
| 1469 | @ <section class='attachlist'> |
| 1470 | } |
| 1471 | if( flags & ATTACHLIST_HRULE_ABOVE ){ |
| 1472 | @ <hr> |
| 1473 | } |
| 1474 | if( bUseDetail ){ |
| 1475 | @ <summary>%s(zHeader)</summary> |
| 1476 | }else{ |
| 1477 | @ %s(zHeader) |
| 1478 | } |
| 1479 | @ <ul> |
| 1480 | } |
| 1481 | cnt++; |
| 1482 | switch( attachment_target_type(zTarget, 1) ){ |
| 1483 | case CFTYPE_TICKET: zTypeArg = "tkt"; break; |
| 1484 | case CFTYPE_FORUM: zTypeArg = "forumpost"; break; |
| 1485 | case CFTYPE_EVENT: zTypeArg = "technote"; break; |
| 1486 | case CFTYPE_WIKI: |
| 1487 | default: zTypeArg = "page"; break; |
| 1488 | } |
| 1489 | @ <li> |
| 1490 | @ <a href="%R/artifact/%!S(zSrc)"%s(zLinkTgt)>%h(zFile)</a> |
| 1491 | if( flags & ATTACHLIST_SIZE ){ |
| 1492 | sqlite3_snprintf(sizeof(szBuf), szBuf, " %d bytes", sz); |
| 1493 | } |
| 1494 | @ [<a href="%R/attachdownload/%t(zFile)?%s(zTypeArg)=%t(zTarget)\ |
| 1495 | @&file=%t(zFile)%s(zLinkTgt)">download</a>%s(szBuf)] |
| 1496 | @ added by %h(zDispUser) on |
| 1497 | hyperlink_to_date(zDate, "."); |
| 1498 | @ [<a href="%R/ainfo/%!S(zUuid)"%s(zLinkTgt)>details</a>] |
| 1499 | moderation_pending_www(aid); |
| 1500 | @ </li> |
| 1501 | } |
| 1502 | if( cnt ){ |
| 1503 | @ </ul> |
| 1504 | if( bUseDetail ){ |
| 1505 | @ </details> |
| 1506 | }else{ |
| 1507 | @ </section> |
| 1508 | } |
| 1509 | } |
| 1510 | db_finalize(&q); |
| 1511 | } |
| 1512 | |
| 1513 | /* |
| 1514 | ** COMMAND: attachment* |
| 1515 | ** |
| @@ -827,15 +1656,204 @@ | |
| 1656 | } |
| 1657 | for(i = 2; i < g.argc; ++i){ |
| 1658 | const char *zPage = g.argv[i]; |
| 1659 | db_bind_text(&q, ":tgtname", zPage); |
| 1660 | while(SQLITE_ROW == db_step(&q)){ |
| 1661 | const char *zTime = db_column_text(&q, 0); |
| 1662 | const char *zSrc = db_column_text(&q, 1); |
| 1663 | const char *zTarget = db_column_text(&q, 2); |
| 1664 | const char *zName = db_column_text(&q, 3); |
| 1665 | printf("%-20s %s %.12s %s\n", zTarget, zTime, zSrc, zName); |
| 1666 | } |
| 1667 | db_reset(&q); |
| 1668 | } |
| 1669 | db_finalize(&q); |
| 1670 | } |
| 1671 | |
| 1672 | /* |
| 1673 | ** Renders the list of attachments for artifact pManifest as JSON to |
| 1674 | ** blob pOut. If pManifest->type is not one of (CFTYPE_TICKET, |
| 1675 | ** CFTYPE_FORUM, CFTYPE_EVENT, CFTYPE_WIKI) then it behaves as if the |
| 1676 | ** result set is empty. |
| 1677 | ** |
| 1678 | ** If there are no matching attachments then its behavior depends on |
| 1679 | ** emptyPolicy: |
| 1680 | ** |
| 1681 | ** <0 = emit a JSON NULL |
| 1682 | ** 0 = emit no output |
| 1683 | ** >0 = emit an empty JSON array |
| 1684 | ** |
| 1685 | ** If bLatestOnly is true then only the most recent entry for a given |
| 1686 | ** attachment is emitted, else all versions are emitted in descending |
| 1687 | ** mtime order. |
| 1688 | ** |
| 1689 | ** Returns the number of attachments. |
| 1690 | ** |
| 1691 | ** Output format: |
| 1692 | ** |
| 1693 | ** [{ |
| 1694 | ** "uuid": attachment artifact hash, |
| 1695 | ** "src": hash of the attachment blob, |
| 1696 | ** "target": wiki page name or ticket/event ID, |
| 1697 | ** "filename": filename of attachment, |
| 1698 | ** "mtime": ISO-8601 timestamp UTC, |
| 1699 | ** "isLatest": true if this is the latest version of this file |
| 1700 | ** else false, |
| 1701 | ** }, ...once per attachment] |
| 1702 | ** |
| 1703 | */ |
| 1704 | int attachments_to_json(const Manifest *pManifest, |
| 1705 | Blob *pOut, int bLatestOnly, |
| 1706 | int emptyPolicy){ |
| 1707 | int i = 0; |
| 1708 | Stmt q = empty_Stmt; |
| 1709 | char *zToFree = 0; |
| 1710 | const char *zTgt = 0; |
| 1711 | switch(pManifest->type){ |
| 1712 | case CFTYPE_FORUM: zTgt = zToFree = rid_to_uuid(pManifest->rid); |
| 1713 | break; |
| 1714 | case CFTYPE_WIKI: zTgt = pManifest->zWikiTitle; break; |
| 1715 | case CFTYPE_EVENT: zTgt = pManifest->zEventId; break; |
| 1716 | case CFTYPE_TICKET: zTgt = pManifest->zTicketUuid; break; |
| 1717 | default: |
| 1718 | goto empty_result; |
| 1719 | } |
| 1720 | db_prepare(&q, |
| 1721 | "SELECT datetime(mtime), a.src, a.target, a.filename, a.isLatest,\n" |
| 1722 | " b2.size, b1.uuid, a.user, a.comment\n" |
| 1723 | " FROM attachment a, blob b1, blob b2\n" |
| 1724 | " WHERE a.target=%Q\n" |
| 1725 | " AND a.src IS NOT NULL\n" |
| 1726 | " AND b1.rid=a.attachid\n" |
| 1727 | " AND b2.uuid=a.src\n" |
| 1728 | " AND (a.isLatest OR %d)\n" |
| 1729 | " ORDER BY a.target, a.isLatest DESC, a.mtime DESC\n", |
| 1730 | zTgt, !bLatestOnly |
| 1731 | ); |
| 1732 | while(SQLITE_ROW == db_step(&q)){ |
| 1733 | const char *zTime = db_column_text(&q, 0); |
| 1734 | const char *zSrc = db_column_text(&q, 1); |
| 1735 | const char *zTarget = db_column_text(&q, 2); |
| 1736 | const char *zName = db_column_text(&q, 3); |
| 1737 | const int isLatest = db_column_int(&q, 4); |
| 1738 | const int sz = db_column_int(&q, 5); |
| 1739 | const char *zUuid = db_column_text(&q, 6); |
| 1740 | const char *zUser = db_column_text(&q, 7); |
| 1741 | const char *zComment = db_column_text(&q, 8); |
| 1742 | if(!i++){ |
| 1743 | blob_append_char(pOut, '['); |
| 1744 | }else{ |
| 1745 | blob_append_char(pOut, ','); |
| 1746 | } |
| 1747 | blob_appendf( |
| 1748 | pOut, |
| 1749 | "{\"uuid\": %!j, \"src\": %!j, \"target\": %!j, " |
| 1750 | "\"filename\": %!j, \"size\":%d, \"mtime\": %!j, " |
| 1751 | "\"isLatest\": %s, \"user\": %!j, \"comment\": ", |
| 1752 | zUuid, zSrc, zTarget, |
| 1753 | zName, sz, zTime, isLatest ? "true" : "false", |
| 1754 | zUser |
| 1755 | ); |
| 1756 | if( zComment && zComment[0] ){ |
| 1757 | blob_appendf(pOut, "%!j", zComment); |
| 1758 | }else{ |
| 1759 | blob_append_literal(pOut, "null"); |
| 1760 | } |
| 1761 | blob_append_char(pOut, '}'); |
| 1762 | } |
| 1763 | fossil_free(zToFree); |
| 1764 | db_finalize(&q); |
| 1765 | if(!i){ |
| 1766 | empty_result: |
| 1767 | if( emptyPolicy>0 ){ |
| 1768 | blob_append_literal(pOut, "[]"); |
| 1769 | }else if( emptyPolicy<0 ){ |
| 1770 | blob_append_literal(pOut, "null"); |
| 1771 | } |
| 1772 | }else{ |
| 1773 | blob_append_char(pOut, ']'); |
| 1774 | } |
| 1775 | return i; |
| 1776 | } |
| 1777 | |
| 1778 | /* |
| 1779 | ** COMMAND: test-attachment-target |
| 1780 | ** |
| 1781 | ** Usage: %fossil test-attachment-target TARGET_ID... |
| 1782 | */ |
| 1783 | void test_attachment_target_type_cmd(void){ |
| 1784 | int i; |
| 1785 | verify_all_options(); |
| 1786 | db_find_and_open_repository(0, 0); |
| 1787 | if( g.argc<3 ){ |
| 1788 | usage("test-attachment-target TARGET_ID"); |
| 1789 | return; |
| 1790 | } |
| 1791 | for( i = 2; i < g.argc; ++i ){ |
| 1792 | const char *zTarget = g.argv[i]; |
| 1793 | const int rid = attachment_target_rid(zTarget, 0); |
| 1794 | const int type = attachment_target_type(zTarget, 0); |
| 1795 | const char *zType = "<invalid>"; |
| 1796 | switch(type){ |
| 1797 | case CFTYPE_EVENT: zType = "technote"; break; |
| 1798 | case CFTYPE_FORUM: zType = "forumpost"; break; |
| 1799 | case CFTYPE_TICKET: zType = "ticket"; break; |
| 1800 | case CFTYPE_WIKI: zType = "wiki"; break; |
| 1801 | } |
| 1802 | fossil_print("%-20s = %-9s #%d %z\n", |
| 1803 | zTarget, zType, rid, |
| 1804 | rid>0 ? rid_to_uuid(rid) : 0); |
| 1805 | } |
| 1806 | } |
| 1807 | |
| 1808 | |
| 1809 | /* |
| 1810 | ** COMMAND: test-attachments-to-json |
| 1811 | ** |
| 1812 | ** Usage: %fossil test-attachments-to-json TARGET_ID... |
| 1813 | ** |
| 1814 | ** Options: |
| 1815 | ** --old List all versions of attachments. Default is to |
| 1816 | ** list only the latest. |
| 1817 | ** --full Require a full target ID, not a prefix. |
| 1818 | ** |
| 1819 | ** Emits a JSON array of attachments for the given attachment targets. |
| 1820 | ** The given IDs must be wiki page names, ticket hashes, tech-note |
| 1821 | ** hashes, or forum post hashes. By default it accepts hash prefixes |
| 1822 | ** but does no detection of ambiguity or cross-type prefix collisions |
| 1823 | ** so may emit curious results if given short, colliding IDs. |
| 1824 | */ |
| 1825 | void test_attachments_to_json_cmd(void){ |
| 1826 | const int emptyPolicy = 1; |
| 1827 | const int bLatestOnly = find_option("old",0,0)==0; |
| 1828 | const int bFullId = find_option("full",0,0)!=0; |
| 1829 | int i; |
| 1830 | |
| 1831 | verify_all_options(); |
| 1832 | db_find_and_open_repository(0, 0); |
| 1833 | if( g.argc<3 ){ |
| 1834 | usage("test-attachments-to-json TARGET_ID"); |
| 1835 | return; |
| 1836 | } |
| 1837 | for( i = 2; i < g.argc; ++i ){ |
| 1838 | const char *zTarget = g.argv[i]; |
| 1839 | const int rid = attachment_target_rid(zTarget, bFullId); |
| 1840 | if( 0==rid ){ |
| 1841 | fossil_print("** cannot resolve %s\n", zTarget); |
| 1842 | }else{ |
| 1843 | Blob b = BLOB_INITIALIZER; |
| 1844 | Manifest *pManifest = manifest_get(rid, CFTYPE_ANY, NULL); |
| 1845 | assert( pManifest ); |
| 1846 | attachments_to_json(pManifest, &b, bLatestOnly, emptyPolicy); |
| 1847 | fossil_print("Attachments for %s: ", zTarget); |
| 1848 | if( b.nUsed ){ |
| 1849 | char *zPretty = db_text(0,"SELECT json_pretty(%B)", &b); |
| 1850 | fossil_print("%s\n", zPretty); |
| 1851 | fossil_free(zPretty); |
| 1852 | }else{ |
| 1853 | fossil_print("none\n"); |
| 1854 | } |
| 1855 | blob_reset(&b); |
| 1856 | manifest_destroy(pManifest); |
| 1857 | } |
| 1858 | } |
| 1859 | } |
| 1860 |
+20
-1
| --- src/builtin.c | ||
| +++ src/builtin.c | ||
| @@ -668,22 +668,39 @@ | ||
| 668 | 668 | CX("editStateMarkers: {" |
| 669 | 669 | "/*Symbolic markers to denote certain edit states.*/" |
| 670 | 670 | "isNew:'[+]', isModified:'[*]', isDeleted:'[-]'},\n"); |
| 671 | 671 | CX("confirmerButtonTicks: 3 " |
| 672 | 672 | "/*default fossil.confirmer tick count.*/,\n"); |
| 673 | + CX("attachmentSizeLimit: %d,\n", | |
| 674 | + db_get_int("attachment-size-limit",0)); | |
| 673 | 675 | /* Inject certain info about the current skin... */ |
| 674 | 676 | CX("skin:{"); |
| 675 | 677 | /* can leak a local filesystem path: |
| 676 | 678 | CX("name: %!j,", skin_in_use());*/ |
| 677 | 679 | CX("isDark: %s" |
| 678 | 680 | "/*true if the current skin has the 'white-foreground' detail*/", |
| 679 | 681 | skin_detail_boolean("white-foreground") ? "true" : "false"); |
| 680 | 682 | CX("}\n"/*fossil.config.skin*/); |
| 681 | 683 | CX("};\n"/* fossil.config */); |
| 684 | + if( forum_statuses()->n>1 ){ | |
| 685 | + const ForumStatusList * fsl = forum_statuses(); | |
| 686 | + int i; | |
| 687 | + CX("window.fossil.config.forumStatuses = ["); | |
| 688 | + for(i = 0; i < fsl->n; ++i){ | |
| 689 | + const ForumStatus *fs = &fsl->aStatus[i]; | |
| 690 | + if(i) CX(","); | |
| 691 | + CX("{label:%!j, value:%!j}", fs->zLabel, fs->zValue); | |
| 692 | + } | |
| 693 | + CX("];\n"); | |
| 694 | + } | |
| 695 | +#define JBOOL(COND) ((COND) ? "true" : "false") | |
| 682 | 696 | CX("window.fossil.user = {"); |
| 683 | 697 | CX("name: %!j,", (g.zLogin&&*g.zLogin) ? g.zLogin : "guest"); |
| 684 | - CX("isAdmin: %s", (g.perm.Admin || g.perm.Setup) ? "true" : "false"); | |
| 698 | + CX("isAdmin: %s,", JBOOL(g.perm.Admin || g.perm.Setup)); | |
| 699 | + CX("mayAttachForum: %s,", JBOOL(g.perm.AttachForum)); | |
| 700 | + CX("enableDebug: %s,", JBOOL(g.perm.Debug || g.perm.Admin)); | |
| 701 | + CX("isIndividual: %s", JBOOL(login_is_individual())); | |
| 685 | 702 | CX("};\n"/*fossil.user*/); |
| 686 | 703 | CX("if(fossil.config.skin.isDark) " |
| 687 | 704 | "document.body.classList.add('fossil-dark-style');\n"); |
| 688 | 705 | /* |
| 689 | 706 | ** fossil.page holds info about the current page. This is also |
| @@ -699,10 +716,11 @@ | ||
| 699 | 716 | } |
| 700 | 717 | /* The remaining window.fossil bootstrap code is not dependent on |
| 701 | 718 | ** C-runtime state... */ |
| 702 | 719 | builtin_request_js("fossil.bootstrap.js"); |
| 703 | 720 | } |
| 721 | +#undef JBOOL | |
| 704 | 722 | } |
| 705 | 723 | |
| 706 | 724 | /* |
| 707 | 725 | ** Given the NAME part of fossil.NAME.js, this function checks whether |
| 708 | 726 | ** that module has been emitted by this function before. If it has, |
| @@ -732,10 +750,11 @@ | ||
| 732 | 750 | ** entries: all known deps of this one. Each |
| 733 | 751 | ** REQUIRES an EXPLICIT trailing \0, including |
| 734 | 752 | ** the final one! */ |
| 735 | 753 | } fjs[] = { |
| 736 | 754 | /* This list ordering isn't strictly important. */ |
| 755 | + {"attach", 0, "dom\0"}, | |
| 737 | 756 | {"confirmer", 0, 0}, |
| 738 | 757 | {"copybutton", 0, "dom\0"}, |
| 739 | 758 | {"diff", 0, "dom\0fetch\0storage\0" |
| 740 | 759 | /* maintenance note: "diff" needs "storage" for storing the |
| 741 | 760 | ** sbs-sync-scroll toggle. */}, |
| 742 | 761 |
| --- src/builtin.c | |
| +++ src/builtin.c | |
| @@ -668,22 +668,39 @@ | |
| 668 | CX("editStateMarkers: {" |
| 669 | "/*Symbolic markers to denote certain edit states.*/" |
| 670 | "isNew:'[+]', isModified:'[*]', isDeleted:'[-]'},\n"); |
| 671 | CX("confirmerButtonTicks: 3 " |
| 672 | "/*default fossil.confirmer tick count.*/,\n"); |
| 673 | /* Inject certain info about the current skin... */ |
| 674 | CX("skin:{"); |
| 675 | /* can leak a local filesystem path: |
| 676 | CX("name: %!j,", skin_in_use());*/ |
| 677 | CX("isDark: %s" |
| 678 | "/*true if the current skin has the 'white-foreground' detail*/", |
| 679 | skin_detail_boolean("white-foreground") ? "true" : "false"); |
| 680 | CX("}\n"/*fossil.config.skin*/); |
| 681 | CX("};\n"/* fossil.config */); |
| 682 | CX("window.fossil.user = {"); |
| 683 | CX("name: %!j,", (g.zLogin&&*g.zLogin) ? g.zLogin : "guest"); |
| 684 | CX("isAdmin: %s", (g.perm.Admin || g.perm.Setup) ? "true" : "false"); |
| 685 | CX("};\n"/*fossil.user*/); |
| 686 | CX("if(fossil.config.skin.isDark) " |
| 687 | "document.body.classList.add('fossil-dark-style');\n"); |
| 688 | /* |
| 689 | ** fossil.page holds info about the current page. This is also |
| @@ -699,10 +716,11 @@ | |
| 699 | } |
| 700 | /* The remaining window.fossil bootstrap code is not dependent on |
| 701 | ** C-runtime state... */ |
| 702 | builtin_request_js("fossil.bootstrap.js"); |
| 703 | } |
| 704 | } |
| 705 | |
| 706 | /* |
| 707 | ** Given the NAME part of fossil.NAME.js, this function checks whether |
| 708 | ** that module has been emitted by this function before. If it has, |
| @@ -732,10 +750,11 @@ | |
| 732 | ** entries: all known deps of this one. Each |
| 733 | ** REQUIRES an EXPLICIT trailing \0, including |
| 734 | ** the final one! */ |
| 735 | } fjs[] = { |
| 736 | /* This list ordering isn't strictly important. */ |
| 737 | {"confirmer", 0, 0}, |
| 738 | {"copybutton", 0, "dom\0"}, |
| 739 | {"diff", 0, "dom\0fetch\0storage\0" |
| 740 | /* maintenance note: "diff" needs "storage" for storing the |
| 741 | ** sbs-sync-scroll toggle. */}, |
| 742 |
| --- src/builtin.c | |
| +++ src/builtin.c | |
| @@ -668,22 +668,39 @@ | |
| 668 | CX("editStateMarkers: {" |
| 669 | "/*Symbolic markers to denote certain edit states.*/" |
| 670 | "isNew:'[+]', isModified:'[*]', isDeleted:'[-]'},\n"); |
| 671 | CX("confirmerButtonTicks: 3 " |
| 672 | "/*default fossil.confirmer tick count.*/,\n"); |
| 673 | CX("attachmentSizeLimit: %d,\n", |
| 674 | db_get_int("attachment-size-limit",0)); |
| 675 | /* Inject certain info about the current skin... */ |
| 676 | CX("skin:{"); |
| 677 | /* can leak a local filesystem path: |
| 678 | CX("name: %!j,", skin_in_use());*/ |
| 679 | CX("isDark: %s" |
| 680 | "/*true if the current skin has the 'white-foreground' detail*/", |
| 681 | skin_detail_boolean("white-foreground") ? "true" : "false"); |
| 682 | CX("}\n"/*fossil.config.skin*/); |
| 683 | CX("};\n"/* fossil.config */); |
| 684 | if( forum_statuses()->n>1 ){ |
| 685 | const ForumStatusList * fsl = forum_statuses(); |
| 686 | int i; |
| 687 | CX("window.fossil.config.forumStatuses = ["); |
| 688 | for(i = 0; i < fsl->n; ++i){ |
| 689 | const ForumStatus *fs = &fsl->aStatus[i]; |
| 690 | if(i) CX(","); |
| 691 | CX("{label:%!j, value:%!j}", fs->zLabel, fs->zValue); |
| 692 | } |
| 693 | CX("];\n"); |
| 694 | } |
| 695 | #define JBOOL(COND) ((COND) ? "true" : "false") |
| 696 | CX("window.fossil.user = {"); |
| 697 | CX("name: %!j,", (g.zLogin&&*g.zLogin) ? g.zLogin : "guest"); |
| 698 | CX("isAdmin: %s,", JBOOL(g.perm.Admin || g.perm.Setup)); |
| 699 | CX("mayAttachForum: %s,", JBOOL(g.perm.AttachForum)); |
| 700 | CX("enableDebug: %s,", JBOOL(g.perm.Debug || g.perm.Admin)); |
| 701 | CX("isIndividual: %s", JBOOL(login_is_individual())); |
| 702 | CX("};\n"/*fossil.user*/); |
| 703 | CX("if(fossil.config.skin.isDark) " |
| 704 | "document.body.classList.add('fossil-dark-style');\n"); |
| 705 | /* |
| 706 | ** fossil.page holds info about the current page. This is also |
| @@ -699,10 +716,11 @@ | |
| 716 | } |
| 717 | /* The remaining window.fossil bootstrap code is not dependent on |
| 718 | ** C-runtime state... */ |
| 719 | builtin_request_js("fossil.bootstrap.js"); |
| 720 | } |
| 721 | #undef JBOOL |
| 722 | } |
| 723 | |
| 724 | /* |
| 725 | ** Given the NAME part of fossil.NAME.js, this function checks whether |
| 726 | ** that module has been emitted by this function before. If it has, |
| @@ -732,10 +750,11 @@ | |
| 750 | ** entries: all known deps of this one. Each |
| 751 | ** REQUIRES an EXPLICIT trailing \0, including |
| 752 | ** the final one! */ |
| 753 | } fjs[] = { |
| 754 | /* This list ordering isn't strictly important. */ |
| 755 | {"attach", 0, "dom\0"}, |
| 756 | {"confirmer", 0, 0}, |
| 757 | {"copybutton", 0, "dom\0"}, |
| 758 | {"diff", 0, "dom\0fetch\0storage\0" |
| 759 | /* maintenance note: "diff" needs "storage" for storing the |
| 760 | ** sbs-sync-scroll toggle. */}, |
| 761 |
+1
-1
| --- src/bundle.c | ||
| +++ src/bundle.c | ||
| @@ -660,11 +660,11 @@ | ||
| 660 | 660 | int n = 0; |
| 661 | 661 | db_prepare(&q, |
| 662 | 662 | "SELECT cid FROM plink WHERE pid IN ok AND cid NOT IN ok" |
| 663 | 663 | ); |
| 664 | 664 | while( db_step(&q)==SQLITE_ROW ){ |
| 665 | - whatis_rid(db_column_int(&q,0),0); | |
| 665 | + whatis_rid(db_column_int(&q,0),0,0); | |
| 666 | 666 | fossil_print("%.78c\n", '-'); |
| 667 | 667 | n++; |
| 668 | 668 | } |
| 669 | 669 | db_finalize(&q); |
| 670 | 670 | if( n>0 ){ |
| 671 | 671 |
| --- src/bundle.c | |
| +++ src/bundle.c | |
| @@ -660,11 +660,11 @@ | |
| 660 | int n = 0; |
| 661 | db_prepare(&q, |
| 662 | "SELECT cid FROM plink WHERE pid IN ok AND cid NOT IN ok" |
| 663 | ); |
| 664 | while( db_step(&q)==SQLITE_ROW ){ |
| 665 | whatis_rid(db_column_int(&q,0),0); |
| 666 | fossil_print("%.78c\n", '-'); |
| 667 | n++; |
| 668 | } |
| 669 | db_finalize(&q); |
| 670 | if( n>0 ){ |
| 671 |
| --- src/bundle.c | |
| +++ src/bundle.c | |
| @@ -660,11 +660,11 @@ | |
| 660 | int n = 0; |
| 661 | db_prepare(&q, |
| 662 | "SELECT cid FROM plink WHERE pid IN ok AND cid NOT IN ok" |
| 663 | ); |
| 664 | while( db_step(&q)==SQLITE_ROW ){ |
| 665 | whatis_rid(db_column_int(&q,0),0,0); |
| 666 | fossil_print("%.78c\n", '-'); |
| 667 | n++; |
| 668 | } |
| 669 | db_finalize(&q); |
| 670 | if( n>0 ){ |
| 671 |
+2
| --- src/capabilities.c | ||
| +++ src/capabilities.c | ||
| @@ -304,10 +304,12 @@ | ||
| 304 | 304 | "Forum-Admin", "Grant capability '4' to other users" }, |
| 305 | 305 | { '7', CAPCLASS_ALERT, 0, |
| 306 | 306 | "Alerts", "Sign up for email alerts" }, |
| 307 | 307 | { 'A', CAPCLASS_ALERT|CAPCLASS_SUPER, 0, |
| 308 | 308 | "Announce", "Send announcements to all subscribers" }, |
| 309 | + { 'B', CAPCLASS_FORUM|CAPCLASS_SUPER, 0, | |
| 310 | + "Forum-Attach", "Add attachment to Forum posts" }, | |
| 309 | 311 | { 'C', CAPCLASS_FORUM, 0, |
| 310 | 312 | "Chat", "Read and/or writes messages in the chatroom" }, |
| 311 | 313 | { 'D', CAPCLASS_OTHER, 0, |
| 312 | 314 | "Debug", "Enable debugging features" }, |
| 313 | 315 | }; |
| 314 | 316 |
| --- src/capabilities.c | |
| +++ src/capabilities.c | |
| @@ -304,10 +304,12 @@ | |
| 304 | "Forum-Admin", "Grant capability '4' to other users" }, |
| 305 | { '7', CAPCLASS_ALERT, 0, |
| 306 | "Alerts", "Sign up for email alerts" }, |
| 307 | { 'A', CAPCLASS_ALERT|CAPCLASS_SUPER, 0, |
| 308 | "Announce", "Send announcements to all subscribers" }, |
| 309 | { 'C', CAPCLASS_FORUM, 0, |
| 310 | "Chat", "Read and/or writes messages in the chatroom" }, |
| 311 | { 'D', CAPCLASS_OTHER, 0, |
| 312 | "Debug", "Enable debugging features" }, |
| 313 | }; |
| 314 |
| --- src/capabilities.c | |
| +++ src/capabilities.c | |
| @@ -304,10 +304,12 @@ | |
| 304 | "Forum-Admin", "Grant capability '4' to other users" }, |
| 305 | { '7', CAPCLASS_ALERT, 0, |
| 306 | "Alerts", "Sign up for email alerts" }, |
| 307 | { 'A', CAPCLASS_ALERT|CAPCLASS_SUPER, 0, |
| 308 | "Announce", "Send announcements to all subscribers" }, |
| 309 | { 'B', CAPCLASS_FORUM|CAPCLASS_SUPER, 0, |
| 310 | "Forum-Attach", "Add attachment to Forum posts" }, |
| 311 | { 'C', CAPCLASS_FORUM, 0, |
| 312 | "Chat", "Read and/or writes messages in the chatroom" }, |
| 313 | { 'D', CAPCLASS_OTHER, 0, |
| 314 | "Debug", "Enable debugging features" }, |
| 315 | }; |
| 316 |
+3
-2
| --- src/cgi.c | ||
| +++ src/cgi.c | ||
| @@ -1335,12 +1335,13 @@ | ||
| 1335 | 1335 | } |
| 1336 | 1336 | fossil_free(zErr); |
| 1337 | 1337 | } |
| 1338 | 1338 | } |
| 1339 | 1339 | if( !g.syncInfo.zLoginCard && 0!=(z=(char*)P("x-f-l-c")) ){ |
| 1340 | - /* x-f-l-c (X-Fossil-Login-Card card transmitted via cookie | |
| 1341 | - ** instead of in the sync payload. */ | |
| 1340 | + /* x-f-l-c (X-Fossil-Login-Card) transmitted via cookie instead of | |
| 1341 | + ** in the sync payload. The format of this value is the same as a | |
| 1342 | + ** "login" card, as parsed by xfer.c:page_xfer(). */ | |
| 1342 | 1343 | rc |= 0x04; |
| 1343 | 1344 | g.syncInfo.zLoginCard = fossil_strdup(z); |
| 1344 | 1345 | g.syncInfo.fLoginCardMode |= 0x02; |
| 1345 | 1346 | cgi_delete_parameter("x-f-l-c"); |
| 1346 | 1347 | } |
| 1347 | 1348 |
| --- src/cgi.c | |
| +++ src/cgi.c | |
| @@ -1335,12 +1335,13 @@ | |
| 1335 | } |
| 1336 | fossil_free(zErr); |
| 1337 | } |
| 1338 | } |
| 1339 | if( !g.syncInfo.zLoginCard && 0!=(z=(char*)P("x-f-l-c")) ){ |
| 1340 | /* x-f-l-c (X-Fossil-Login-Card card transmitted via cookie |
| 1341 | ** instead of in the sync payload. */ |
| 1342 | rc |= 0x04; |
| 1343 | g.syncInfo.zLoginCard = fossil_strdup(z); |
| 1344 | g.syncInfo.fLoginCardMode |= 0x02; |
| 1345 | cgi_delete_parameter("x-f-l-c"); |
| 1346 | } |
| 1347 |
| --- src/cgi.c | |
| +++ src/cgi.c | |
| @@ -1335,12 +1335,13 @@ | |
| 1335 | } |
| 1336 | fossil_free(zErr); |
| 1337 | } |
| 1338 | } |
| 1339 | if( !g.syncInfo.zLoginCard && 0!=(z=(char*)P("x-f-l-c")) ){ |
| 1340 | /* x-f-l-c (X-Fossil-Login-Card) transmitted via cookie instead of |
| 1341 | ** in the sync payload. The format of this value is the same as a |
| 1342 | ** "login" card, as parsed by xfer.c:page_xfer(). */ |
| 1343 | rc |= 0x04; |
| 1344 | g.syncInfo.zLoginCard = fossil_strdup(z); |
| 1345 | g.syncInfo.fLoginCardMode |= 0x02; |
| 1346 | cgi_delete_parameter("x-f-l-c"); |
| 1347 | } |
| 1348 |
+4
| --- src/checkin.c | ||
| +++ src/checkin.c | ||
| @@ -2990,13 +2990,17 @@ | ||
| 2990 | 2990 | } |
| 2991 | 2991 | }else if( !noPrompt ){ |
| 2992 | 2992 | while( 1/*exit-by-break*/ ){ |
| 2993 | 2993 | int rc; |
| 2994 | 2994 | char *zInit; |
| 2995 | + assert( db_transaction_nesting_depth()==1 ); | |
| 2995 | 2996 | zInit = db_text(0,"SELECT value FROM vvar WHERE name='ci-comment'"); |
| 2996 | 2997 | prepare_commit_comment(&comment, zInit, &sCiInfo, vid, dryRunFlag); |
| 2997 | 2998 | db_multi_exec("REPLACE INTO vvar VALUES('ci-comment',%B)", &comment); |
| 2999 | + assert( db_transaction_nesting_depth()==1 ); | |
| 3000 | + db_end_transaction(0); | |
| 3001 | + db_begin_transaction(); | |
| 2998 | 3002 | if( (rc = verify_comment(&comment, ckComFlgs))!=0 ){ |
| 2999 | 3003 | if( rc==COMCK_PREVIEW ){ |
| 3000 | 3004 | prompt_user("Continue, abort, or edit? (C/a/e)? ", &ans); |
| 3001 | 3005 | }else{ |
| 3002 | 3006 | prompt_user("Edit, abort, or continue (E/a/c)? ", &ans); |
| 3003 | 3007 |
| --- src/checkin.c | |
| +++ src/checkin.c | |
| @@ -2990,13 +2990,17 @@ | |
| 2990 | } |
| 2991 | }else if( !noPrompt ){ |
| 2992 | while( 1/*exit-by-break*/ ){ |
| 2993 | int rc; |
| 2994 | char *zInit; |
| 2995 | zInit = db_text(0,"SELECT value FROM vvar WHERE name='ci-comment'"); |
| 2996 | prepare_commit_comment(&comment, zInit, &sCiInfo, vid, dryRunFlag); |
| 2997 | db_multi_exec("REPLACE INTO vvar VALUES('ci-comment',%B)", &comment); |
| 2998 | if( (rc = verify_comment(&comment, ckComFlgs))!=0 ){ |
| 2999 | if( rc==COMCK_PREVIEW ){ |
| 3000 | prompt_user("Continue, abort, or edit? (C/a/e)? ", &ans); |
| 3001 | }else{ |
| 3002 | prompt_user("Edit, abort, or continue (E/a/c)? ", &ans); |
| 3003 |
| --- src/checkin.c | |
| +++ src/checkin.c | |
| @@ -2990,13 +2990,17 @@ | |
| 2990 | } |
| 2991 | }else if( !noPrompt ){ |
| 2992 | while( 1/*exit-by-break*/ ){ |
| 2993 | int rc; |
| 2994 | char *zInit; |
| 2995 | assert( db_transaction_nesting_depth()==1 ); |
| 2996 | zInit = db_text(0,"SELECT value FROM vvar WHERE name='ci-comment'"); |
| 2997 | prepare_commit_comment(&comment, zInit, &sCiInfo, vid, dryRunFlag); |
| 2998 | db_multi_exec("REPLACE INTO vvar VALUES('ci-comment',%B)", &comment); |
| 2999 | assert( db_transaction_nesting_depth()==1 ); |
| 3000 | db_end_transaction(0); |
| 3001 | db_begin_transaction(); |
| 3002 | if( (rc = verify_comment(&comment, ckComFlgs))!=0 ){ |
| 3003 | if( rc==COMCK_PREVIEW ){ |
| 3004 | prompt_user("Continue, abort, or edit? (C/a/e)? ", &ans); |
| 3005 | }else{ |
| 3006 | prompt_user("Edit, abort, or continue (E/a/c)? ", &ans); |
| 3007 |
+2
| --- src/comformat.c | ||
| +++ src/comformat.c | ||
| @@ -33,10 +33,12 @@ | ||
| 33 | 33 | */ |
| 34 | 34 | #define COMMENT_PRINT_TRIM_CRLF ((u32)0x00000002) /* Trim leading CR/LF. */ |
| 35 | 35 | #define COMMENT_PRINT_TRIM_SPACE ((u32)0x00000004) /* Trim leading/trailing. */ |
| 36 | 36 | #define COMMENT_PRINT_WORD_BREAK ((u32)0x00000008) /* Break lines on words. */ |
| 37 | 37 | #define COMMENT_PRINT_ORIG_BREAK ((u32)0x00000010) /* Break before original. */ |
| 38 | +#define COMMENT_PRINT_SUMMARY ((u32)0x00000020) | |
| 39 | + /* Truncate after first blank line. */ | |
| 38 | 40 | #endif |
| 39 | 41 | |
| 40 | 42 | /********* Code copied from SQLite src/shell.c.in on 2024-09-30 **********/ |
| 41 | 43 | /* Lookup table to estimate the number of columns consumed by a Unicode |
| 42 | 44 | ** character. |
| 43 | 45 |
| --- src/comformat.c | |
| +++ src/comformat.c | |
| @@ -33,10 +33,12 @@ | |
| 33 | */ |
| 34 | #define COMMENT_PRINT_TRIM_CRLF ((u32)0x00000002) /* Trim leading CR/LF. */ |
| 35 | #define COMMENT_PRINT_TRIM_SPACE ((u32)0x00000004) /* Trim leading/trailing. */ |
| 36 | #define COMMENT_PRINT_WORD_BREAK ((u32)0x00000008) /* Break lines on words. */ |
| 37 | #define COMMENT_PRINT_ORIG_BREAK ((u32)0x00000010) /* Break before original. */ |
| 38 | #endif |
| 39 | |
| 40 | /********* Code copied from SQLite src/shell.c.in on 2024-09-30 **********/ |
| 41 | /* Lookup table to estimate the number of columns consumed by a Unicode |
| 42 | ** character. |
| 43 |
| --- src/comformat.c | |
| +++ src/comformat.c | |
| @@ -33,10 +33,12 @@ | |
| 33 | */ |
| 34 | #define COMMENT_PRINT_TRIM_CRLF ((u32)0x00000002) /* Trim leading CR/LF. */ |
| 35 | #define COMMENT_PRINT_TRIM_SPACE ((u32)0x00000004) /* Trim leading/trailing. */ |
| 36 | #define COMMENT_PRINT_WORD_BREAK ((u32)0x00000008) /* Break lines on words. */ |
| 37 | #define COMMENT_PRINT_ORIG_BREAK ((u32)0x00000010) /* Break before original. */ |
| 38 | #define COMMENT_PRINT_SUMMARY ((u32)0x00000020) |
| 39 | /* Truncate after first blank line. */ |
| 40 | #endif |
| 41 | |
| 42 | /********* Code copied from SQLite src/shell.c.in on 2024-09-30 **********/ |
| 43 | /* Lookup table to estimate the number of columns consumed by a Unicode |
| 44 | ** character. |
| 45 |
+1
| --- src/configure.c | ||
| +++ src/configure.c | ||
| @@ -143,10 +143,11 @@ | ||
| 143 | 143 | { "hash-policy", CONFIGSET_PROJ }, |
| 144 | 144 | { "comment-format", CONFIGSET_PROJ }, |
| 145 | 145 | { "mimetypes", CONFIGSET_PROJ }, |
| 146 | 146 | { "forbid-delta-manifests", CONFIGSET_PROJ }, |
| 147 | 147 | { "mv-rm-files", CONFIGSET_PROJ }, |
| 148 | + { "forum-statuses", CONFIGSET_PROJ }, | |
| 148 | 149 | { "ticket-table", CONFIGSET_TKT }, |
| 149 | 150 | { "ticket-common", CONFIGSET_TKT }, |
| 150 | 151 | { "ticket-change", CONFIGSET_TKT }, |
| 151 | 152 | { "ticket-newpage", CONFIGSET_TKT }, |
| 152 | 153 | { "ticket-viewpage", CONFIGSET_TKT }, |
| 153 | 154 |
| --- src/configure.c | |
| +++ src/configure.c | |
| @@ -143,10 +143,11 @@ | |
| 143 | { "hash-policy", CONFIGSET_PROJ }, |
| 144 | { "comment-format", CONFIGSET_PROJ }, |
| 145 | { "mimetypes", CONFIGSET_PROJ }, |
| 146 | { "forbid-delta-manifests", CONFIGSET_PROJ }, |
| 147 | { "mv-rm-files", CONFIGSET_PROJ }, |
| 148 | { "ticket-table", CONFIGSET_TKT }, |
| 149 | { "ticket-common", CONFIGSET_TKT }, |
| 150 | { "ticket-change", CONFIGSET_TKT }, |
| 151 | { "ticket-newpage", CONFIGSET_TKT }, |
| 152 | { "ticket-viewpage", CONFIGSET_TKT }, |
| 153 |
| --- src/configure.c | |
| +++ src/configure.c | |
| @@ -143,10 +143,11 @@ | |
| 143 | { "hash-policy", CONFIGSET_PROJ }, |
| 144 | { "comment-format", CONFIGSET_PROJ }, |
| 145 | { "mimetypes", CONFIGSET_PROJ }, |
| 146 | { "forbid-delta-manifests", CONFIGSET_PROJ }, |
| 147 | { "mv-rm-files", CONFIGSET_PROJ }, |
| 148 | { "forum-statuses", CONFIGSET_PROJ }, |
| 149 | { "ticket-table", CONFIGSET_TKT }, |
| 150 | { "ticket-common", CONFIGSET_TKT }, |
| 151 | { "ticket-change", CONFIGSET_TKT }, |
| 152 | { "ticket-newpage", CONFIGSET_TKT }, |
| 153 | { "ticket-viewpage", CONFIGSET_TKT }, |
| 154 |
+37
-8
| --- src/content.c | ||
| +++ src/content.c | ||
| @@ -701,24 +701,53 @@ | ||
| 701 | 701 | |
| 702 | 702 | |
| 703 | 703 | /* |
| 704 | 704 | ** COMMAND: test-content-put |
| 705 | 705 | ** |
| 706 | -** Usage: %fossil test-content-put FILE | |
| 706 | +** Usage: %fossil test-content-put [OPTIONS] FILE ... | |
| 707 | +** | |
| 708 | +** Read the content of all FILE argments and add them to the Blob | |
| 709 | +** table as a new artifact using a direct call to content_put(). | |
| 710 | +** | |
| 711 | +** Options: | |
| 707 | 712 | ** |
| 708 | -** Read the content of FILE and add it to the Blob table as a new | |
| 709 | -** artifact using a direct call to content_put(). | |
| 713 | +** --moderate Make corresponding entries to the MODREQ table | |
| 714 | +** -R REPO Add the content to repository file REPO | |
| 715 | +** -x|--crosslink Assume all inputs are artifacts and crosslink them. | |
| 710 | 716 | */ |
| 711 | 717 | void test_content_put_cmd(void){ |
| 712 | 718 | int rid; |
| 713 | 719 | Blob content; |
| 714 | - if( g.argc!=3 ) usage("FILENAME"); | |
| 715 | - db_must_be_within_tree(); | |
| 720 | + int i; | |
| 721 | + int bModreq = find_option("moderate",0,0)!=0; | |
| 722 | + int bCrosslink = find_option("crosslink","x",0)!=0; | |
| 723 | + db_find_and_open_repository(0,0); | |
| 716 | 724 | user_select(); |
| 717 | - blob_read_from_file(&content, g.argv[2], ExtFILE); | |
| 718 | - rid = content_put(&content); | |
| 719 | - fossil_print("inserted as record %d\n", rid); | |
| 725 | + verify_all_options(); | |
| 726 | + db_begin_transaction(); | |
| 727 | + if( bModreq ) moderation_table_create(); | |
| 728 | + if( bCrosslink ){ | |
| 729 | + manifest_crosslink_begin(); | |
| 730 | + } | |
| 731 | + for(i=2; i<g.argc; i++){ | |
| 732 | + const char *zFile = g.argv[i]; | |
| 733 | + blob_read_from_file(&content, zFile, ExtFILE); | |
| 734 | + rid = content_put(&content); | |
| 735 | + if( bCrosslink ){ | |
| 736 | + manifest_crosslink(rid, &content, MC_NONE); | |
| 737 | + }else{ | |
| 738 | + blob_reset(&content); | |
| 739 | + } | |
| 740 | + if( bModreq ){ | |
| 741 | + db_multi_exec("INSERT INTO modreq(objid) VALUES(%d)",rid); | |
| 742 | + } | |
| 743 | + fossil_print("inserted as record %d: %s\n", rid, zFile); | |
| 744 | + } | |
| 745 | + if( bCrosslink ){ | |
| 746 | + manifest_crosslink_end(MC_NONE); | |
| 747 | + } | |
| 748 | + db_end_transaction(0); | |
| 720 | 749 | } |
| 721 | 750 | |
| 722 | 751 | /* |
| 723 | 752 | ** Make sure the content at rid is the original content and is not a |
| 724 | 753 | ** delta. |
| 725 | 754 |
| --- src/content.c | |
| +++ src/content.c | |
| @@ -701,24 +701,53 @@ | |
| 701 | |
| 702 | |
| 703 | /* |
| 704 | ** COMMAND: test-content-put |
| 705 | ** |
| 706 | ** Usage: %fossil test-content-put FILE |
| 707 | ** |
| 708 | ** Read the content of FILE and add it to the Blob table as a new |
| 709 | ** artifact using a direct call to content_put(). |
| 710 | */ |
| 711 | void test_content_put_cmd(void){ |
| 712 | int rid; |
| 713 | Blob content; |
| 714 | if( g.argc!=3 ) usage("FILENAME"); |
| 715 | db_must_be_within_tree(); |
| 716 | user_select(); |
| 717 | blob_read_from_file(&content, g.argv[2], ExtFILE); |
| 718 | rid = content_put(&content); |
| 719 | fossil_print("inserted as record %d\n", rid); |
| 720 | } |
| 721 | |
| 722 | /* |
| 723 | ** Make sure the content at rid is the original content and is not a |
| 724 | ** delta. |
| 725 |
| --- src/content.c | |
| +++ src/content.c | |
| @@ -701,24 +701,53 @@ | |
| 701 | |
| 702 | |
| 703 | /* |
| 704 | ** COMMAND: test-content-put |
| 705 | ** |
| 706 | ** Usage: %fossil test-content-put [OPTIONS] FILE ... |
| 707 | ** |
| 708 | ** Read the content of all FILE argments and add them to the Blob |
| 709 | ** table as a new artifact using a direct call to content_put(). |
| 710 | ** |
| 711 | ** Options: |
| 712 | ** |
| 713 | ** --moderate Make corresponding entries to the MODREQ table |
| 714 | ** -R REPO Add the content to repository file REPO |
| 715 | ** -x|--crosslink Assume all inputs are artifacts and crosslink them. |
| 716 | */ |
| 717 | void test_content_put_cmd(void){ |
| 718 | int rid; |
| 719 | Blob content; |
| 720 | int i; |
| 721 | int bModreq = find_option("moderate",0,0)!=0; |
| 722 | int bCrosslink = find_option("crosslink","x",0)!=0; |
| 723 | db_find_and_open_repository(0,0); |
| 724 | user_select(); |
| 725 | verify_all_options(); |
| 726 | db_begin_transaction(); |
| 727 | if( bModreq ) moderation_table_create(); |
| 728 | if( bCrosslink ){ |
| 729 | manifest_crosslink_begin(); |
| 730 | } |
| 731 | for(i=2; i<g.argc; i++){ |
| 732 | const char *zFile = g.argv[i]; |
| 733 | blob_read_from_file(&content, zFile, ExtFILE); |
| 734 | rid = content_put(&content); |
| 735 | if( bCrosslink ){ |
| 736 | manifest_crosslink(rid, &content, MC_NONE); |
| 737 | }else{ |
| 738 | blob_reset(&content); |
| 739 | } |
| 740 | if( bModreq ){ |
| 741 | db_multi_exec("INSERT INTO modreq(objid) VALUES(%d)",rid); |
| 742 | } |
| 743 | fossil_print("inserted as record %d: %s\n", rid, zFile); |
| 744 | } |
| 745 | if( bCrosslink ){ |
| 746 | manifest_crosslink_end(MC_NONE); |
| 747 | } |
| 748 | db_end_transaction(0); |
| 749 | } |
| 750 | |
| 751 | /* |
| 752 | ** Make sure the content at rid is the original content and is not a |
| 753 | ** delta. |
| 754 |
M
src/db.c
+2
-1
| --- src/db.c | ||
| +++ src/db.c | ||
| @@ -1329,10 +1329,11 @@ | ||
| 1329 | 1329 | ** Examples: |
| 1330 | 1330 | ** |
| 1331 | 1331 | ** symbolic_name_to_rid('trunk'); |
| 1332 | 1332 | ** symbolic_name_to_rid('trunk','w'); |
| 1333 | 1333 | ** |
| 1334 | +** Its result is either an RID or NULL. | |
| 1334 | 1335 | */ |
| 1335 | 1336 | void db_sym2rid_function( |
| 1336 | 1337 | sqlite3_context *context, |
| 1337 | 1338 | int argc, |
| 1338 | 1339 | sqlite3_value **argv |
| @@ -3576,11 +3577,11 @@ | ||
| 3576 | 3577 | } |
| 3577 | 3578 | |
| 3578 | 3579 | /* |
| 3579 | 3580 | ** Attempt to look up the input in the CONCEALED table. If found, |
| 3580 | 3581 | ** and if the okRdAddr permission is enabled then return the |
| 3581 | -** original value for which the input is a hash. If okRdAddr is | |
| 3582 | +** original value for which the input is a hash. If g.perm.RdAddr is | |
| 3582 | 3583 | ** false or if the lookup fails, return the original string content. |
| 3583 | 3584 | ** |
| 3584 | 3585 | ** In either case, the string returned is stored in space obtained |
| 3585 | 3586 | ** from malloc and should be freed by the calling function. |
| 3586 | 3587 | */ |
| 3587 | 3588 |
| --- src/db.c | |
| +++ src/db.c | |
| @@ -1329,10 +1329,11 @@ | |
| 1329 | ** Examples: |
| 1330 | ** |
| 1331 | ** symbolic_name_to_rid('trunk'); |
| 1332 | ** symbolic_name_to_rid('trunk','w'); |
| 1333 | ** |
| 1334 | */ |
| 1335 | void db_sym2rid_function( |
| 1336 | sqlite3_context *context, |
| 1337 | int argc, |
| 1338 | sqlite3_value **argv |
| @@ -3576,11 +3577,11 @@ | |
| 3576 | } |
| 3577 | |
| 3578 | /* |
| 3579 | ** Attempt to look up the input in the CONCEALED table. If found, |
| 3580 | ** and if the okRdAddr permission is enabled then return the |
| 3581 | ** original value for which the input is a hash. If okRdAddr is |
| 3582 | ** false or if the lookup fails, return the original string content. |
| 3583 | ** |
| 3584 | ** In either case, the string returned is stored in space obtained |
| 3585 | ** from malloc and should be freed by the calling function. |
| 3586 | */ |
| 3587 |
| --- src/db.c | |
| +++ src/db.c | |
| @@ -1329,10 +1329,11 @@ | |
| 1329 | ** Examples: |
| 1330 | ** |
| 1331 | ** symbolic_name_to_rid('trunk'); |
| 1332 | ** symbolic_name_to_rid('trunk','w'); |
| 1333 | ** |
| 1334 | ** Its result is either an RID or NULL. |
| 1335 | */ |
| 1336 | void db_sym2rid_function( |
| 1337 | sqlite3_context *context, |
| 1338 | int argc, |
| 1339 | sqlite3_value **argv |
| @@ -3576,11 +3577,11 @@ | |
| 3577 | } |
| 3578 | |
| 3579 | /* |
| 3580 | ** Attempt to look up the input in the CONCEALED table. If found, |
| 3581 | ** and if the okRdAddr permission is enabled then return the |
| 3582 | ** original value for which the input is a hash. If g.perm.RdAddr is |
| 3583 | ** false or if the lookup fails, return the original string content. |
| 3584 | ** |
| 3585 | ** In either case, the string returned is stored in space obtained |
| 3586 | ** from malloc and should be freed by the calling function. |
| 3587 | */ |
| 3588 |
+177
-1
| --- src/default.css | ||
| +++ src/default.css | ||
| @@ -1113,10 +1113,24 @@ | ||
| 1113 | 1113 | |
| 1114 | 1114 | div.setup_forum-column { |
| 1115 | 1115 | display: flex; |
| 1116 | 1116 | flex-direction: column; |
| 1117 | 1117 | } |
| 1118 | + | |
| 1119 | +body.forum span.forum-status-selection { | |
| 1120 | + white-space: nowrap; | |
| 1121 | +} | |
| 1122 | + | |
| 1123 | +body.cpage-forum div.forumPosts tr[data-status] td.status { | |
| 1124 | + /* Add a gap before the "X posts spanning Y time" labels, | |
| 1125 | + ** which sometimes wrap and look odd without this gap. */ | |
| 1126 | + padding-left: 1em; | |
| 1127 | +} | |
| 1128 | +body.cpage-forum div.forumPosts tr[data-status="open"] { | |
| 1129 | +} | |
| 1130 | +body.cpage-forum div.forumPosts tr[data-status="resolved"] { | |
| 1131 | +} | |
| 1118 | 1132 | |
| 1119 | 1133 | body.cpage-setup_forum > .content table { |
| 1120 | 1134 | margin-bottom: 1em; |
| 1121 | 1135 | } |
| 1122 | 1136 | body.cpage-setup_forum > .content table.bordered { |
| @@ -1491,10 +1505,13 @@ | ||
| 1491 | 1505 | } |
| 1492 | 1506 | table.numbered-lines td.line-numbers > pre { |
| 1493 | 1507 | margin: 0.25em/*must match top PADDING of td.file-content |
| 1494 | 1508 | > pre > code*/ 0 0 0; |
| 1495 | 1509 | padding: 0; |
| 1510 | + line-height: inherit; | |
| 1511 | + font-size: inherit; | |
| 1512 | + font-family: inherit; | |
| 1496 | 1513 | } |
| 1497 | 1514 | table.numbered-lines td.line-numbers span { |
| 1498 | 1515 | display: inline-block; |
| 1499 | 1516 | margin: 0; |
| 1500 | 1517 | padding: 0; |
| @@ -1679,11 +1696,11 @@ | ||
| 1679 | 1696 | -0.6836761,0.240014 -1.4255375,0.720042 V 3.0698267 q 0.8800513,-0.3054724 1.6073661,-0.4509353 \ |
| 1680 | 1697 | 0.7273151,-0.145463 1.403718,-0.145463 1.7746486,0 2.7056104,0.727315 0.930965,0.720042 \ |
| 1681 | 1698 | 0.930965,2.1092135 0,0.7127686 -0.283654,1.2800746 -0.283652,0.5600324 -0.967329,1.2073428 \ |
| 1682 | 1699 | L 10.025425,8.2119439 Q 9.530851,8.6628792 9.3781148,8.9392588 9.2253789,9.2083654 \ |
| 1683 | 1700 | 9.2253789,9.535657 Z M 6.5997716,10.939376 h 2.6256073 v 2.589241 H 6.5997716 Z' \ |
| 1684 | -style='fill:%23f8f8f8;stroke-width:1.35412836' /%3e%3c/svg%3e "); | |
| 1701 | +style='fill:%23f8f8f8;stroke-width:1.35412836' /%3e%3c/svg%3e "); | |
| 1685 | 1702 | background-repeat: no-repeat; |
| 1686 | 1703 | background-position: center; |
| 1687 | 1704 | /* When not using a background image, this additional style works |
| 1688 | 1705 | reasonably well along with a ::before content of "?": */ |
| 1689 | 1706 | /*border-width: 1px; |
| @@ -1993,10 +2010,169 @@ | ||
| 1993 | 2010 | margin: 0; |
| 1994 | 2011 | } |
| 1995 | 2012 | div.helpPage blockquote { |
| 1996 | 2013 | margin-left: 0.2em; |
| 1997 | 2014 | } |
| 2015 | + | |
| 2016 | +/* .attach* = styles for file attachments */ | |
| 2017 | +section.attachlist {} | |
| 2018 | +details.attachlist > summary { | |
| 2019 | + cursor: pointer; | |
| 2020 | +} | |
| 2021 | +/* .Attacher is the top container element used by the JS Attacher | |
| 2022 | + class in fossil.attach.js. */ | |
| 2023 | +.Attacher { | |
| 2024 | + margin-bottom: 1em; | |
| 2025 | + display: flex; | |
| 2026 | + flex-direction: column; | |
| 2027 | + gap: 0.75em; | |
| 2028 | +} | |
| 2029 | +.Attacher.reverse { | |
| 2030 | + flex-direction: column-reverse; | |
| 2031 | +} | |
| 2032 | +.Attacher .attach-row { | |
| 2033 | + display: flex; | |
| 2034 | + flex-direction: column; | |
| 2035 | + gap: 0.5em; | |
| 2036 | + padding: 0.75em; | |
| 2037 | + border: 1px dashed #ccc; | |
| 2038 | + border-radius: 0.25em; | |
| 2039 | + background-color: #fafafa; | |
| 2040 | +} | |
| 2041 | +.Attacher .error { | |
| 2042 | + padding: 0.5em; | |
| 2043 | + background-color: #d32f2f; | |
| 2044 | + color: #fff; | |
| 2045 | +} | |
| 2046 | +.Attacher .error a { | |
| 2047 | + color: inherit; | |
| 2048 | + text-decoration: underline; | |
| 2049 | +} | |
| 2050 | +body.fossil-dark-style .Attacher .attach-row { | |
| 2051 | + background-color: initial; | |
| 2052 | +} | |
| 2053 | +.Attacher .attach-dropzone { | |
| 2054 | + padding: 1em; | |
| 2055 | + text-align: center; | |
| 2056 | + background: #ffffff; | |
| 2057 | + border: 1px solid #ddd; | |
| 2058 | + cursor: pointer; | |
| 2059 | + border-radius: 0.25em; | |
| 2060 | + transition: background-color 0.15s linear; | |
| 2061 | + display: flex; | |
| 2062 | + flex-direction: row; | |
| 2063 | + flex-wrap: nowrap; | |
| 2064 | +} | |
| 2065 | +body.fossil-dark-style .Attacher .attach-dropzone{ | |
| 2066 | + background: initial; | |
| 2067 | +} | |
| 2068 | +.Attacher .attach-dropzone.populated { | |
| 2069 | + background-color: #f1f8e9; | |
| 2070 | + border-color: #8bc34a; | |
| 2071 | + border-style: solid; | |
| 2072 | + text-align: left; | |
| 2073 | +} | |
| 2074 | +body.fossil-dark-style .Attacher .attach-dropzone.populated{ | |
| 2075 | + background-color: initial; | |
| 2076 | +} | |
| 2077 | +.Attacher .attach-dropzone.dragover { | |
| 2078 | + background-color: #e1f5fe; | |
| 2079 | + color: black; | |
| 2080 | + border-color: #03a9f4; | |
| 2081 | +} | |
| 2082 | +body.fossil-dark-style .Attacher .attach-dropzone.dragover{ | |
| 2083 | + background-color: #e1f5fe; | |
| 2084 | + border-color: #03a9f4; | |
| 2085 | +} | |
| 2086 | +.Attacher .thumbnail { | |
| 2087 | + max-width: 10em; | |
| 2088 | + max-height: 10em; | |
| 2089 | + margin: 0 1em; | |
| 2090 | +} | |
| 2091 | +.Attacher .attach-row-info{ | |
| 2092 | + font-family: monospace; | |
| 2093 | + flex-grow: 1; | |
| 2094 | + display: flex; | |
| 2095 | + flex-direction: column; | |
| 2096 | +} | |
| 2097 | +.Attacher .attach-filename {} | |
| 2098 | +.Attacher .attach-size {/*size and mimetype*/} | |
| 2099 | +.Attacher .attach-desc { | |
| 2100 | + max-width: initial; | |
| 2101 | + width: 100%; | |
| 2102 | + box-sizing: border-box; | |
| 2103 | + min-height: 4em; | |
| 2104 | + padding: 0.5em; | |
| 2105 | + font-family: inherit; | |
| 2106 | + resize: vertical; | |
| 2107 | +} | |
| 2108 | +.Attacher .attach-row-remove { | |
| 2109 | + align-self: center; | |
| 2110 | + padding: 0.25em 0.75em; | |
| 2111 | + margin-left: 1em; | |
| 2112 | + background-color: #d32f2f; | |
| 2113 | + color: #fff; | |
| 2114 | + border: none; | |
| 2115 | + border-radius: 0.25em; | |
| 2116 | + cursor: pointer; | |
| 2117 | + font-weight: bold; | |
| 2118 | +} | |
| 2119 | +.Attacher .attach-row-remove:hover { | |
| 2120 | + background-color: #b71c1c; | |
| 2121 | +} | |
| 2122 | +.Attacher .attach-controls { | |
| 2123 | + display: flex; | |
| 2124 | + flex-direction: row; | |
| 2125 | + gap: 1em; | |
| 2126 | +} | |
| 2127 | +.Attacher .attach-controls .attach-add-button { | |
| 2128 | + padding: 0.5em 1em; | |
| 2129 | + cursor: pointer; | |
| 2130 | + flex-grow: 2; | |
| 2131 | + line-height: initial/*work around an inherited alignment quirk*/; | |
| 2132 | +} | |
| 2133 | + | |
| 2134 | +/* .animate-X and their associated @keyframes are used by various | |
| 2135 | + widgets to animate their comings and goings. */ | |
| 2136 | +.animate-entrance { | |
| 2137 | + animation: slideFadeIn 0.25s linear forwards; | |
| 2138 | + transform-origin: top; | |
| 2139 | + overflow: hidden /*prevent content bleeding during expansion*/; | |
| 2140 | +} | |
| 2141 | +.animate-exit { | |
| 2142 | + animation: slideFadeOut 0.25s linear forwards; | |
| 2143 | + transform-origin: top; | |
| 2144 | + overflow: hidden; | |
| 2145 | +} | |
| 2146 | +@keyframes slideFadeIn { | |
| 2147 | + 0% { | |
| 2148 | + opacity: 0; | |
| 2149 | + transform: translateY(-1em/*must match slideFadeOut*/); | |
| 2150 | + max-height: 0; | |
| 2151 | + } | |
| 2152 | + 100% { | |
| 2153 | + opacity: 1; | |
| 2154 | + transform: translateY(0); | |
| 2155 | + max-height: 100em /*a value safely larger than the widget*/; | |
| 2156 | + } | |
| 2157 | +} | |
| 2158 | +@keyframes slideFadeOut { | |
| 2159 | + 0% { | |
| 2160 | + opacity: 1; | |
| 2161 | + transform: translateY(0); | |
| 2162 | + max-height: 100em /*must match slideFadeIn*/; | |
| 2163 | + } | |
| 2164 | + 100% { | |
| 2165 | + opacity: 0; | |
| 2166 | + transform: translateY(-1em/*must match slideFadeIn*/); | |
| 2167 | + max-height: 0; | |
| 2168 | + padding-top: 0; | |
| 2169 | + padding-bottom: 0; | |
| 2170 | + margin-top: 0; | |
| 2171 | + margin-bottom: 0; | |
| 2172 | + } | |
| 2173 | +} | |
| 1998 | 2174 | |
| 1999 | 2175 | /* Objects in the "desktoponly" class are invisible on mobile */ |
| 2000 | 2176 | @media screen and (max-width: 600px) { |
| 2001 | 2177 | .desktoponly { |
| 2002 | 2178 | display: none; |
| 2003 | 2179 |
| --- src/default.css | |
| +++ src/default.css | |
| @@ -1113,10 +1113,24 @@ | |
| 1113 | |
| 1114 | div.setup_forum-column { |
| 1115 | display: flex; |
| 1116 | flex-direction: column; |
| 1117 | } |
| 1118 | |
| 1119 | body.cpage-setup_forum > .content table { |
| 1120 | margin-bottom: 1em; |
| 1121 | } |
| 1122 | body.cpage-setup_forum > .content table.bordered { |
| @@ -1491,10 +1505,13 @@ | |
| 1491 | } |
| 1492 | table.numbered-lines td.line-numbers > pre { |
| 1493 | margin: 0.25em/*must match top PADDING of td.file-content |
| 1494 | > pre > code*/ 0 0 0; |
| 1495 | padding: 0; |
| 1496 | } |
| 1497 | table.numbered-lines td.line-numbers span { |
| 1498 | display: inline-block; |
| 1499 | margin: 0; |
| 1500 | padding: 0; |
| @@ -1679,11 +1696,11 @@ | |
| 1679 | -0.6836761,0.240014 -1.4255375,0.720042 V 3.0698267 q 0.8800513,-0.3054724 1.6073661,-0.4509353 \ |
| 1680 | 0.7273151,-0.145463 1.403718,-0.145463 1.7746486,0 2.7056104,0.727315 0.930965,0.720042 \ |
| 1681 | 0.930965,2.1092135 0,0.7127686 -0.283654,1.2800746 -0.283652,0.5600324 -0.967329,1.2073428 \ |
| 1682 | L 10.025425,8.2119439 Q 9.530851,8.6628792 9.3781148,8.9392588 9.2253789,9.2083654 \ |
| 1683 | 9.2253789,9.535657 Z M 6.5997716,10.939376 h 2.6256073 v 2.589241 H 6.5997716 Z' \ |
| 1684 | style='fill:%23f8f8f8;stroke-width:1.35412836' /%3e%3c/svg%3e "); |
| 1685 | background-repeat: no-repeat; |
| 1686 | background-position: center; |
| 1687 | /* When not using a background image, this additional style works |
| 1688 | reasonably well along with a ::before content of "?": */ |
| 1689 | /*border-width: 1px; |
| @@ -1993,10 +2010,169 @@ | |
| 1993 | margin: 0; |
| 1994 | } |
| 1995 | div.helpPage blockquote { |
| 1996 | margin-left: 0.2em; |
| 1997 | } |
| 1998 | |
| 1999 | /* Objects in the "desktoponly" class are invisible on mobile */ |
| 2000 | @media screen and (max-width: 600px) { |
| 2001 | .desktoponly { |
| 2002 | display: none; |
| 2003 |
| --- src/default.css | |
| +++ src/default.css | |
| @@ -1113,10 +1113,24 @@ | |
| 1113 | |
| 1114 | div.setup_forum-column { |
| 1115 | display: flex; |
| 1116 | flex-direction: column; |
| 1117 | } |
| 1118 | |
| 1119 | body.forum span.forum-status-selection { |
| 1120 | white-space: nowrap; |
| 1121 | } |
| 1122 | |
| 1123 | body.cpage-forum div.forumPosts tr[data-status] td.status { |
| 1124 | /* Add a gap before the "X posts spanning Y time" labels, |
| 1125 | ** which sometimes wrap and look odd without this gap. */ |
| 1126 | padding-left: 1em; |
| 1127 | } |
| 1128 | body.cpage-forum div.forumPosts tr[data-status="open"] { |
| 1129 | } |
| 1130 | body.cpage-forum div.forumPosts tr[data-status="resolved"] { |
| 1131 | } |
| 1132 | |
| 1133 | body.cpage-setup_forum > .content table { |
| 1134 | margin-bottom: 1em; |
| 1135 | } |
| 1136 | body.cpage-setup_forum > .content table.bordered { |
| @@ -1491,10 +1505,13 @@ | |
| 1505 | } |
| 1506 | table.numbered-lines td.line-numbers > pre { |
| 1507 | margin: 0.25em/*must match top PADDING of td.file-content |
| 1508 | > pre > code*/ 0 0 0; |
| 1509 | padding: 0; |
| 1510 | line-height: inherit; |
| 1511 | font-size: inherit; |
| 1512 | font-family: inherit; |
| 1513 | } |
| 1514 | table.numbered-lines td.line-numbers span { |
| 1515 | display: inline-block; |
| 1516 | margin: 0; |
| 1517 | padding: 0; |
| @@ -1679,11 +1696,11 @@ | |
| 1696 | -0.6836761,0.240014 -1.4255375,0.720042 V 3.0698267 q 0.8800513,-0.3054724 1.6073661,-0.4509353 \ |
| 1697 | 0.7273151,-0.145463 1.403718,-0.145463 1.7746486,0 2.7056104,0.727315 0.930965,0.720042 \ |
| 1698 | 0.930965,2.1092135 0,0.7127686 -0.283654,1.2800746 -0.283652,0.5600324 -0.967329,1.2073428 \ |
| 1699 | L 10.025425,8.2119439 Q 9.530851,8.6628792 9.3781148,8.9392588 9.2253789,9.2083654 \ |
| 1700 | 9.2253789,9.535657 Z M 6.5997716,10.939376 h 2.6256073 v 2.589241 H 6.5997716 Z' \ |
| 1701 | style='fill:%23f8f8f8;stroke-width:1.35412836' /%3e%3c/svg%3e "); |
| 1702 | background-repeat: no-repeat; |
| 1703 | background-position: center; |
| 1704 | /* When not using a background image, this additional style works |
| 1705 | reasonably well along with a ::before content of "?": */ |
| 1706 | /*border-width: 1px; |
| @@ -1993,10 +2010,169 @@ | |
| 2010 | margin: 0; |
| 2011 | } |
| 2012 | div.helpPage blockquote { |
| 2013 | margin-left: 0.2em; |
| 2014 | } |
| 2015 | |
| 2016 | /* .attach* = styles for file attachments */ |
| 2017 | section.attachlist {} |
| 2018 | details.attachlist > summary { |
| 2019 | cursor: pointer; |
| 2020 | } |
| 2021 | /* .Attacher is the top container element used by the JS Attacher |
| 2022 | class in fossil.attach.js. */ |
| 2023 | .Attacher { |
| 2024 | margin-bottom: 1em; |
| 2025 | display: flex; |
| 2026 | flex-direction: column; |
| 2027 | gap: 0.75em; |
| 2028 | } |
| 2029 | .Attacher.reverse { |
| 2030 | flex-direction: column-reverse; |
| 2031 | } |
| 2032 | .Attacher .attach-row { |
| 2033 | display: flex; |
| 2034 | flex-direction: column; |
| 2035 | gap: 0.5em; |
| 2036 | padding: 0.75em; |
| 2037 | border: 1px dashed #ccc; |
| 2038 | border-radius: 0.25em; |
| 2039 | background-color: #fafafa; |
| 2040 | } |
| 2041 | .Attacher .error { |
| 2042 | padding: 0.5em; |
| 2043 | background-color: #d32f2f; |
| 2044 | color: #fff; |
| 2045 | } |
| 2046 | .Attacher .error a { |
| 2047 | color: inherit; |
| 2048 | text-decoration: underline; |
| 2049 | } |
| 2050 | body.fossil-dark-style .Attacher .attach-row { |
| 2051 | background-color: initial; |
| 2052 | } |
| 2053 | .Attacher .attach-dropzone { |
| 2054 | padding: 1em; |
| 2055 | text-align: center; |
| 2056 | background: #ffffff; |
| 2057 | border: 1px solid #ddd; |
| 2058 | cursor: pointer; |
| 2059 | border-radius: 0.25em; |
| 2060 | transition: background-color 0.15s linear; |
| 2061 | display: flex; |
| 2062 | flex-direction: row; |
| 2063 | flex-wrap: nowrap; |
| 2064 | } |
| 2065 | body.fossil-dark-style .Attacher .attach-dropzone{ |
| 2066 | background: initial; |
| 2067 | } |
| 2068 | .Attacher .attach-dropzone.populated { |
| 2069 | background-color: #f1f8e9; |
| 2070 | border-color: #8bc34a; |
| 2071 | border-style: solid; |
| 2072 | text-align: left; |
| 2073 | } |
| 2074 | body.fossil-dark-style .Attacher .attach-dropzone.populated{ |
| 2075 | background-color: initial; |
| 2076 | } |
| 2077 | .Attacher .attach-dropzone.dragover { |
| 2078 | background-color: #e1f5fe; |
| 2079 | color: black; |
| 2080 | border-color: #03a9f4; |
| 2081 | } |
| 2082 | body.fossil-dark-style .Attacher .attach-dropzone.dragover{ |
| 2083 | background-color: #e1f5fe; |
| 2084 | border-color: #03a9f4; |
| 2085 | } |
| 2086 | .Attacher .thumbnail { |
| 2087 | max-width: 10em; |
| 2088 | max-height: 10em; |
| 2089 | margin: 0 1em; |
| 2090 | } |
| 2091 | .Attacher .attach-row-info{ |
| 2092 | font-family: monospace; |
| 2093 | flex-grow: 1; |
| 2094 | display: flex; |
| 2095 | flex-direction: column; |
| 2096 | } |
| 2097 | .Attacher .attach-filename {} |
| 2098 | .Attacher .attach-size {/*size and mimetype*/} |
| 2099 | .Attacher .attach-desc { |
| 2100 | max-width: initial; |
| 2101 | width: 100%; |
| 2102 | box-sizing: border-box; |
| 2103 | min-height: 4em; |
| 2104 | padding: 0.5em; |
| 2105 | font-family: inherit; |
| 2106 | resize: vertical; |
| 2107 | } |
| 2108 | .Attacher .attach-row-remove { |
| 2109 | align-self: center; |
| 2110 | padding: 0.25em 0.75em; |
| 2111 | margin-left: 1em; |
| 2112 | background-color: #d32f2f; |
| 2113 | color: #fff; |
| 2114 | border: none; |
| 2115 | border-radius: 0.25em; |
| 2116 | cursor: pointer; |
| 2117 | font-weight: bold; |
| 2118 | } |
| 2119 | .Attacher .attach-row-remove:hover { |
| 2120 | background-color: #b71c1c; |
| 2121 | } |
| 2122 | .Attacher .attach-controls { |
| 2123 | display: flex; |
| 2124 | flex-direction: row; |
| 2125 | gap: 1em; |
| 2126 | } |
| 2127 | .Attacher .attach-controls .attach-add-button { |
| 2128 | padding: 0.5em 1em; |
| 2129 | cursor: pointer; |
| 2130 | flex-grow: 2; |
| 2131 | line-height: initial/*work around an inherited alignment quirk*/; |
| 2132 | } |
| 2133 | |
| 2134 | /* .animate-X and their associated @keyframes are used by various |
| 2135 | widgets to animate their comings and goings. */ |
| 2136 | .animate-entrance { |
| 2137 | animation: slideFadeIn 0.25s linear forwards; |
| 2138 | transform-origin: top; |
| 2139 | overflow: hidden /*prevent content bleeding during expansion*/; |
| 2140 | } |
| 2141 | .animate-exit { |
| 2142 | animation: slideFadeOut 0.25s linear forwards; |
| 2143 | transform-origin: top; |
| 2144 | overflow: hidden; |
| 2145 | } |
| 2146 | @keyframes slideFadeIn { |
| 2147 | 0% { |
| 2148 | opacity: 0; |
| 2149 | transform: translateY(-1em/*must match slideFadeOut*/); |
| 2150 | max-height: 0; |
| 2151 | } |
| 2152 | 100% { |
| 2153 | opacity: 1; |
| 2154 | transform: translateY(0); |
| 2155 | max-height: 100em /*a value safely larger than the widget*/; |
| 2156 | } |
| 2157 | } |
| 2158 | @keyframes slideFadeOut { |
| 2159 | 0% { |
| 2160 | opacity: 1; |
| 2161 | transform: translateY(0); |
| 2162 | max-height: 100em /*must match slideFadeIn*/; |
| 2163 | } |
| 2164 | 100% { |
| 2165 | opacity: 0; |
| 2166 | transform: translateY(-1em/*must match slideFadeIn*/); |
| 2167 | max-height: 0; |
| 2168 | padding-top: 0; |
| 2169 | padding-bottom: 0; |
| 2170 | margin-top: 0; |
| 2171 | margin-bottom: 0; |
| 2172 | } |
| 2173 | } |
| 2174 | |
| 2175 | /* Objects in the "desktoponly" class are invisible on mobile */ |
| 2176 | @media screen and (max-width: 600px) { |
| 2177 | .desktoponly { |
| 2178 | display: none; |
| 2179 |
+26
-14
| --- src/delta.c | ||
| +++ src/delta.c | ||
| @@ -186,20 +186,29 @@ | ||
| 186 | 186 | 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, -1, -1, -1, -1, |
| 187 | 187 | -1, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, |
| 188 | 188 | 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, -1, -1, -1, -1, 36, |
| 189 | 189 | -1, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, |
| 190 | 190 | 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, -1, -1, -1, 63, -1, |
| 191 | + | |
| 192 | + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | |
| 193 | + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | |
| 194 | + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | |
| 195 | + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | |
| 196 | + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | |
| 197 | + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | |
| 198 | + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | |
| 199 | + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | |
| 191 | 200 | }; |
| 192 | 201 | unsigned int v = 0; |
| 193 | 202 | int c; |
| 194 | 203 | unsigned char *z = (unsigned char*)*pz; |
| 195 | - unsigned char *zStart = z; | |
| 196 | - while( (c = zValue[0x7f&*(z++)])>=0 ){ | |
| 197 | - v = (v<<6) + c; | |
| 204 | + unsigned char *zEnd = z + (*pLen); | |
| 205 | + while( z<zEnd && (c = zValue[*z])>=0 ){ | |
| 206 | + v = (v<<6) + c; | |
| 207 | + z++; | |
| 198 | 208 | } |
| 199 | - z--; | |
| 200 | - *pLen -= z - zStart; | |
| 209 | + *pLen -= (int)(z - (unsigned char*)*pz); | |
| 201 | 210 | *pz = (char*)z; |
| 202 | 211 | return v; |
| 203 | 212 | } |
| 204 | 213 | |
| 205 | 214 | /* |
| @@ -537,11 +546,11 @@ | ||
| 537 | 546 | ** needed. |
| 538 | 547 | */ |
| 539 | 548 | int delta_output_size(const char *zDelta, int lenDelta){ |
| 540 | 549 | int size; |
| 541 | 550 | size = getInt(&zDelta, &lenDelta); |
| 542 | - if( *zDelta!='\n' ){ | |
| 551 | + if( lenDelta<=0 || *zDelta!='\n' ){ | |
| 543 | 552 | /* ERROR: size integer not terminated by "\n" */ |
| 544 | 553 | return -1; |
| 545 | 554 | } |
| 546 | 555 | return size; |
| 547 | 556 | } |
| @@ -574,28 +583,30 @@ | ||
| 574 | 583 | int lenDelta, /* Length of the delta */ |
| 575 | 584 | char *zOut /* Write the output into this preallocated buffer */ |
| 576 | 585 | ){ |
| 577 | 586 | sqlite3_uint64 limit; |
| 578 | 587 | sqlite3_uint64 total = 0; |
| 588 | + | |
| 579 | 589 | #ifdef FOSSIL_ENABLE_DELTA_CKSUM_TEST |
| 580 | 590 | char *zOrigOut = zOut; |
| 581 | 591 | #endif |
| 582 | 592 | |
| 583 | 593 | limit = getInt(&zDelta, &lenDelta); |
| 584 | - if( *zDelta!='\n' ){ | |
| 594 | + if( lenDelta<=0 || *zDelta!='\n' ){ | |
| 585 | 595 | /* ERROR: size integer not terminated by "\n" */ |
| 586 | 596 | return -1; |
| 587 | 597 | } |
| 588 | - zDelta++; lenDelta--; | |
| 589 | - while( *zDelta && lenDelta>0 ){ | |
| 598 | + zDelta++; lenDelta--; /* Skip the \n */ | |
| 599 | + while( lenDelta>0 && zDelta[0] ){ | |
| 590 | 600 | unsigned int cnt, ofst; |
| 591 | 601 | cnt = getInt(&zDelta, &lenDelta); |
| 602 | + if( lenDelta<=0 ) return -1; | |
| 592 | 603 | switch( zDelta[0] ){ |
| 593 | 604 | case '@': { |
| 594 | 605 | zDelta++; lenDelta--; |
| 595 | 606 | ofst = getInt(&zDelta, &lenDelta); |
| 596 | - if( lenDelta>0 && zDelta[0]!=',' ){ | |
| 607 | + if( lenDelta<=0 || zDelta[0]!=',' ){ | |
| 597 | 608 | /* ERROR: copy command not terminated by ',' */ |
| 598 | 609 | return -1; |
| 599 | 610 | } |
| 600 | 611 | zDelta++; lenDelta--; |
| 601 | 612 | DEBUG1( printf("COPY %d from %d\n", cnt, ofst); ) |
| @@ -618,11 +629,11 @@ | ||
| 618 | 629 | if( total>limit ){ |
| 619 | 630 | /* ERROR: insert command gives an output larger than predicted */ |
| 620 | 631 | return -1; |
| 621 | 632 | } |
| 622 | 633 | DEBUG1( printf("INSERT %d\n", cnt); ) |
| 623 | - if( (int)cnt>lenDelta ){ | |
| 634 | + if( (i64)cnt>(i64)lenDelta ){ | |
| 624 | 635 | /* ERROR: insert count exceeds size of delta */ |
| 625 | 636 | return -1; |
| 626 | 637 | } |
| 627 | 638 | memcpy(zOut, zDelta, cnt); |
| 628 | 639 | zOut += cnt; |
| @@ -668,23 +679,24 @@ | ||
| 668 | 679 | ){ |
| 669 | 680 | unsigned int nInsert = 0; |
| 670 | 681 | unsigned int nCopy = 0; |
| 671 | 682 | |
| 672 | 683 | (void)getInt(&zDelta, &lenDelta); |
| 673 | - if( *zDelta!='\n' ){ | |
| 684 | + if( lenDelta<=0 || *zDelta!='\n' ){ | |
| 674 | 685 | /* ERROR: size integer not terminated by "\n" */ |
| 675 | 686 | return -1; |
| 676 | 687 | } |
| 677 | 688 | zDelta++; lenDelta--; |
| 678 | 689 | while( *zDelta && lenDelta>0 ){ |
| 679 | 690 | unsigned int cnt; |
| 680 | 691 | cnt = getInt(&zDelta, &lenDelta); |
| 692 | + if( lenDelta<=0 ) break; | |
| 681 | 693 | switch( zDelta[0] ){ |
| 682 | 694 | case '@': { |
| 683 | 695 | zDelta++; lenDelta--; |
| 684 | 696 | (void)getInt(&zDelta, &lenDelta); |
| 685 | - if( lenDelta>0 && zDelta[0]!=',' ){ | |
| 697 | + if( lenDelta<=0 || zDelta[0]!=',' ){ | |
| 686 | 698 | /* ERROR: copy command not terminated by ',' */ |
| 687 | 699 | return -1; |
| 688 | 700 | } |
| 689 | 701 | zDelta++; lenDelta--; |
| 690 | 702 | nCopy += cnt; |
| @@ -691,11 +703,11 @@ | ||
| 691 | 703 | break; |
| 692 | 704 | } |
| 693 | 705 | case ':': { |
| 694 | 706 | zDelta++; lenDelta--; |
| 695 | 707 | nInsert += cnt; |
| 696 | - if( (int)cnt>lenDelta ){ | |
| 708 | + if( (i64)cnt>(i64)lenDelta ){ | |
| 697 | 709 | /* ERROR: insert count exceeds size of delta */ |
| 698 | 710 | return -1; |
| 699 | 711 | } |
| 700 | 712 | zDelta += cnt; |
| 701 | 713 | lenDelta -= cnt; |
| 702 | 714 |
| --- src/delta.c | |
| +++ src/delta.c | |
| @@ -186,20 +186,29 @@ | |
| 186 | 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, -1, -1, -1, -1, |
| 187 | -1, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, |
| 188 | 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, -1, -1, -1, -1, 36, |
| 189 | -1, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, |
| 190 | 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, -1, -1, -1, 63, -1, |
| 191 | }; |
| 192 | unsigned int v = 0; |
| 193 | int c; |
| 194 | unsigned char *z = (unsigned char*)*pz; |
| 195 | unsigned char *zStart = z; |
| 196 | while( (c = zValue[0x7f&*(z++)])>=0 ){ |
| 197 | v = (v<<6) + c; |
| 198 | } |
| 199 | z--; |
| 200 | *pLen -= z - zStart; |
| 201 | *pz = (char*)z; |
| 202 | return v; |
| 203 | } |
| 204 | |
| 205 | /* |
| @@ -537,11 +546,11 @@ | |
| 537 | ** needed. |
| 538 | */ |
| 539 | int delta_output_size(const char *zDelta, int lenDelta){ |
| 540 | int size; |
| 541 | size = getInt(&zDelta, &lenDelta); |
| 542 | if( *zDelta!='\n' ){ |
| 543 | /* ERROR: size integer not terminated by "\n" */ |
| 544 | return -1; |
| 545 | } |
| 546 | return size; |
| 547 | } |
| @@ -574,28 +583,30 @@ | |
| 574 | int lenDelta, /* Length of the delta */ |
| 575 | char *zOut /* Write the output into this preallocated buffer */ |
| 576 | ){ |
| 577 | sqlite3_uint64 limit; |
| 578 | sqlite3_uint64 total = 0; |
| 579 | #ifdef FOSSIL_ENABLE_DELTA_CKSUM_TEST |
| 580 | char *zOrigOut = zOut; |
| 581 | #endif |
| 582 | |
| 583 | limit = getInt(&zDelta, &lenDelta); |
| 584 | if( *zDelta!='\n' ){ |
| 585 | /* ERROR: size integer not terminated by "\n" */ |
| 586 | return -1; |
| 587 | } |
| 588 | zDelta++; lenDelta--; |
| 589 | while( *zDelta && lenDelta>0 ){ |
| 590 | unsigned int cnt, ofst; |
| 591 | cnt = getInt(&zDelta, &lenDelta); |
| 592 | switch( zDelta[0] ){ |
| 593 | case '@': { |
| 594 | zDelta++; lenDelta--; |
| 595 | ofst = getInt(&zDelta, &lenDelta); |
| 596 | if( lenDelta>0 && zDelta[0]!=',' ){ |
| 597 | /* ERROR: copy command not terminated by ',' */ |
| 598 | return -1; |
| 599 | } |
| 600 | zDelta++; lenDelta--; |
| 601 | DEBUG1( printf("COPY %d from %d\n", cnt, ofst); ) |
| @@ -618,11 +629,11 @@ | |
| 618 | if( total>limit ){ |
| 619 | /* ERROR: insert command gives an output larger than predicted */ |
| 620 | return -1; |
| 621 | } |
| 622 | DEBUG1( printf("INSERT %d\n", cnt); ) |
| 623 | if( (int)cnt>lenDelta ){ |
| 624 | /* ERROR: insert count exceeds size of delta */ |
| 625 | return -1; |
| 626 | } |
| 627 | memcpy(zOut, zDelta, cnt); |
| 628 | zOut += cnt; |
| @@ -668,23 +679,24 @@ | |
| 668 | ){ |
| 669 | unsigned int nInsert = 0; |
| 670 | unsigned int nCopy = 0; |
| 671 | |
| 672 | (void)getInt(&zDelta, &lenDelta); |
| 673 | if( *zDelta!='\n' ){ |
| 674 | /* ERROR: size integer not terminated by "\n" */ |
| 675 | return -1; |
| 676 | } |
| 677 | zDelta++; lenDelta--; |
| 678 | while( *zDelta && lenDelta>0 ){ |
| 679 | unsigned int cnt; |
| 680 | cnt = getInt(&zDelta, &lenDelta); |
| 681 | switch( zDelta[0] ){ |
| 682 | case '@': { |
| 683 | zDelta++; lenDelta--; |
| 684 | (void)getInt(&zDelta, &lenDelta); |
| 685 | if( lenDelta>0 && zDelta[0]!=',' ){ |
| 686 | /* ERROR: copy command not terminated by ',' */ |
| 687 | return -1; |
| 688 | } |
| 689 | zDelta++; lenDelta--; |
| 690 | nCopy += cnt; |
| @@ -691,11 +703,11 @@ | |
| 691 | break; |
| 692 | } |
| 693 | case ':': { |
| 694 | zDelta++; lenDelta--; |
| 695 | nInsert += cnt; |
| 696 | if( (int)cnt>lenDelta ){ |
| 697 | /* ERROR: insert count exceeds size of delta */ |
| 698 | return -1; |
| 699 | } |
| 700 | zDelta += cnt; |
| 701 | lenDelta -= cnt; |
| 702 |
| --- src/delta.c | |
| +++ src/delta.c | |
| @@ -186,20 +186,29 @@ | |
| 186 | 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, -1, -1, -1, -1, |
| 187 | -1, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, |
| 188 | 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, -1, -1, -1, -1, 36, |
| 189 | -1, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, |
| 190 | 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, -1, -1, -1, 63, -1, |
| 191 | |
| 192 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
| 193 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
| 194 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
| 195 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
| 196 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
| 197 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
| 198 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
| 199 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
| 200 | }; |
| 201 | unsigned int v = 0; |
| 202 | int c; |
| 203 | unsigned char *z = (unsigned char*)*pz; |
| 204 | unsigned char *zEnd = z + (*pLen); |
| 205 | while( z<zEnd && (c = zValue[*z])>=0 ){ |
| 206 | v = (v<<6) + c; |
| 207 | z++; |
| 208 | } |
| 209 | *pLen -= (int)(z - (unsigned char*)*pz); |
| 210 | *pz = (char*)z; |
| 211 | return v; |
| 212 | } |
| 213 | |
| 214 | /* |
| @@ -537,11 +546,11 @@ | |
| 546 | ** needed. |
| 547 | */ |
| 548 | int delta_output_size(const char *zDelta, int lenDelta){ |
| 549 | int size; |
| 550 | size = getInt(&zDelta, &lenDelta); |
| 551 | if( lenDelta<=0 || *zDelta!='\n' ){ |
| 552 | /* ERROR: size integer not terminated by "\n" */ |
| 553 | return -1; |
| 554 | } |
| 555 | return size; |
| 556 | } |
| @@ -574,28 +583,30 @@ | |
| 583 | int lenDelta, /* Length of the delta */ |
| 584 | char *zOut /* Write the output into this preallocated buffer */ |
| 585 | ){ |
| 586 | sqlite3_uint64 limit; |
| 587 | sqlite3_uint64 total = 0; |
| 588 | |
| 589 | #ifdef FOSSIL_ENABLE_DELTA_CKSUM_TEST |
| 590 | char *zOrigOut = zOut; |
| 591 | #endif |
| 592 | |
| 593 | limit = getInt(&zDelta, &lenDelta); |
| 594 | if( lenDelta<=0 || *zDelta!='\n' ){ |
| 595 | /* ERROR: size integer not terminated by "\n" */ |
| 596 | return -1; |
| 597 | } |
| 598 | zDelta++; lenDelta--; /* Skip the \n */ |
| 599 | while( lenDelta>0 && zDelta[0] ){ |
| 600 | unsigned int cnt, ofst; |
| 601 | cnt = getInt(&zDelta, &lenDelta); |
| 602 | if( lenDelta<=0 ) return -1; |
| 603 | switch( zDelta[0] ){ |
| 604 | case '@': { |
| 605 | zDelta++; lenDelta--; |
| 606 | ofst = getInt(&zDelta, &lenDelta); |
| 607 | if( lenDelta<=0 || zDelta[0]!=',' ){ |
| 608 | /* ERROR: copy command not terminated by ',' */ |
| 609 | return -1; |
| 610 | } |
| 611 | zDelta++; lenDelta--; |
| 612 | DEBUG1( printf("COPY %d from %d\n", cnt, ofst); ) |
| @@ -618,11 +629,11 @@ | |
| 629 | if( total>limit ){ |
| 630 | /* ERROR: insert command gives an output larger than predicted */ |
| 631 | return -1; |
| 632 | } |
| 633 | DEBUG1( printf("INSERT %d\n", cnt); ) |
| 634 | if( (i64)cnt>(i64)lenDelta ){ |
| 635 | /* ERROR: insert count exceeds size of delta */ |
| 636 | return -1; |
| 637 | } |
| 638 | memcpy(zOut, zDelta, cnt); |
| 639 | zOut += cnt; |
| @@ -668,23 +679,24 @@ | |
| 679 | ){ |
| 680 | unsigned int nInsert = 0; |
| 681 | unsigned int nCopy = 0; |
| 682 | |
| 683 | (void)getInt(&zDelta, &lenDelta); |
| 684 | if( lenDelta<=0 || *zDelta!='\n' ){ |
| 685 | /* ERROR: size integer not terminated by "\n" */ |
| 686 | return -1; |
| 687 | } |
| 688 | zDelta++; lenDelta--; |
| 689 | while( *zDelta && lenDelta>0 ){ |
| 690 | unsigned int cnt; |
| 691 | cnt = getInt(&zDelta, &lenDelta); |
| 692 | if( lenDelta<=0 ) break; |
| 693 | switch( zDelta[0] ){ |
| 694 | case '@': { |
| 695 | zDelta++; lenDelta--; |
| 696 | (void)getInt(&zDelta, &lenDelta); |
| 697 | if( lenDelta<=0 || zDelta[0]!=',' ){ |
| 698 | /* ERROR: copy command not terminated by ',' */ |
| 699 | return -1; |
| 700 | } |
| 701 | zDelta++; lenDelta--; |
| 702 | nCopy += cnt; |
| @@ -691,11 +703,11 @@ | |
| 703 | break; |
| 704 | } |
| 705 | case ':': { |
| 706 | zDelta++; lenDelta--; |
| 707 | nInsert += cnt; |
| 708 | if( (i64)cnt>(i64)lenDelta ){ |
| 709 | /* ERROR: insert count exceeds size of delta */ |
| 710 | return -1; |
| 711 | } |
| 712 | zDelta += cnt; |
| 713 | lenDelta -= cnt; |
| 714 |
+12
-11
| --- src/deltafunc.c | ||
| +++ src/deltafunc.c | ||
| @@ -166,15 +166,15 @@ | ||
| 166 | 166 | /* No additional information needed */ |
| 167 | 167 | }; |
| 168 | 168 | struct deltaparsevtab_cursor { |
| 169 | 169 | sqlite3_vtab_cursor base; /* Base class - must be first */ |
| 170 | 170 | char *aDelta; /* The delta being parsed */ |
| 171 | - int nDelta; /* Number of bytes in the delta */ | |
| 172 | - int iCursor; /* Current cursor location */ | |
| 171 | + i64 iCursor; /* Current cursor location */ | |
| 172 | + i64 iNext; /* Next cursor value */ | |
| 173 | + i64 nDelta; /* Number of bytes in the delta */ | |
| 173 | 174 | int eOp; /* Name of current operator */ |
| 174 | 175 | unsigned int a1, a2; /* Arguments to current operator */ |
| 175 | - int iNext; /* Next cursor value */ | |
| 176 | 176 | }; |
| 177 | 177 | |
| 178 | 178 | /* Operator names: |
| 179 | 179 | */ |
| 180 | 180 | static const char *const azOp[] = { |
| @@ -270,11 +270,11 @@ | ||
| 270 | 270 | /* |
| 271 | 271 | ** Constructor for a new deltaparsevtab_cursor object. |
| 272 | 272 | */ |
| 273 | 273 | static int deltaparsevtabOpen(sqlite3_vtab *p, sqlite3_vtab_cursor **ppCursor){ |
| 274 | 274 | deltaparsevtab_cursor *pCur; |
| 275 | - pCur = sqlite3_malloc( sizeof(*pCur) ); | |
| 275 | + pCur = sqlite3_malloc64( sizeof(*pCur) ); | |
| 276 | 276 | if( pCur==0 ) return SQLITE_NOMEM; |
| 277 | 277 | memset(pCur, 0, sizeof(*pCur)); |
| 278 | 278 | *ppCursor = &pCur->base; |
| 279 | 279 | return SQLITE_OK; |
| 280 | 280 | } |
| @@ -314,18 +314,18 @@ | ||
| 314 | 314 | pCur->iNext = pCur->nDelta; |
| 315 | 315 | break; |
| 316 | 316 | } |
| 317 | 317 | pCur->a2 = deltaGetInt(&z, &i); |
| 318 | 318 | pCur->eOp = DELTAPARSE_OP_COPY; |
| 319 | - pCur->iNext = (int)(&z[1] - pCur->aDelta); | |
| 319 | + pCur->iNext = (i64)(&z[1] - pCur->aDelta); | |
| 320 | 320 | break; |
| 321 | 321 | } |
| 322 | 322 | case ':': { |
| 323 | 323 | z++; |
| 324 | 324 | pCur->a2 = (unsigned int)(z - pCur->aDelta); |
| 325 | 325 | pCur->eOp = DELTAPARSE_OP_INSERT; |
| 326 | - pCur->iNext = (int)(&z[pCur->a1] - pCur->aDelta); | |
| 326 | + pCur->iNext = (i64)(&z[pCur->a1] - pCur->aDelta); | |
| 327 | 327 | break; |
| 328 | 328 | } |
| 329 | 329 | case ';': { |
| 330 | 330 | pCur->eOp = DELTAPARSE_OP_CHECKSUM; |
| 331 | 331 | pCur->iNext = pCur->nDelta; |
| @@ -365,11 +365,11 @@ | ||
| 365 | 365 | } |
| 366 | 366 | case DELTAPARSEVTAB_A2: { |
| 367 | 367 | if( pCur->eOp==DELTAPARSE_OP_COPY ){ |
| 368 | 368 | sqlite3_result_int(ctx, pCur->a2); |
| 369 | 369 | }else if( pCur->eOp==DELTAPARSE_OP_INSERT ){ |
| 370 | - if( pCur->a2 + pCur->a1 > pCur->nDelta ){ | |
| 370 | + if( (i64)pCur->a2 + (i64)pCur->a1 > pCur->nDelta ){ | |
| 371 | 371 | sqlite3_result_zeroblob(ctx, pCur->a1); |
| 372 | 372 | }else{ |
| 373 | 373 | sqlite3_result_blob(ctx, pCur->aDelta+pCur->a2, pCur->a1, |
| 374 | 374 | SQLITE_TRANSIENT); |
| 375 | 375 | } |
| @@ -441,11 +441,11 @@ | ||
| 441 | 441 | pCur->a1 = pCur->a2 = 0; |
| 442 | 442 | pCur->iNext = pCur->nDelta; |
| 443 | 443 | return SQLITE_OK; |
| 444 | 444 | } |
| 445 | 445 | a++; |
| 446 | - pCur->iNext = (unsigned int)(a - pCur->aDelta); | |
| 446 | + pCur->iNext = (i64)(a - pCur->aDelta); | |
| 447 | 447 | return SQLITE_OK; |
| 448 | 448 | } |
| 449 | 449 | |
| 450 | 450 | /* |
| 451 | 451 | ** SQLite will invoke this method one or more times while planning a query |
| @@ -509,21 +509,22 @@ | ||
| 509 | 509 | |
| 510 | 510 | /* |
| 511 | 511 | ** Invoke this routine to register the various delta functions. |
| 512 | 512 | */ |
| 513 | 513 | int deltafunc_init(sqlite3 *db){ |
| 514 | + static const int enc = SQLITE_UTF8|SQLITE_INNOCUOUS; | |
| 514 | 515 | int rc = SQLITE_OK; |
| 515 | - rc = sqlite3_create_function(db, "delta_create", 2, SQLITE_UTF8, 0, | |
| 516 | + rc = sqlite3_create_function(db, "delta_create", 2, enc, 0, | |
| 516 | 517 | deltaCreateFunc, 0, 0); |
| 517 | 518 | if( rc==SQLITE_OK ){ |
| 518 | - rc = sqlite3_create_function(db, "delta_apply", 2, SQLITE_UTF8, 0, | |
| 519 | + rc = sqlite3_create_function(db, "delta_apply", 2, enc, 0, | |
| 519 | 520 | deltaApplyFunc, 0, 0); |
| 520 | 521 | } |
| 521 | 522 | if( rc==SQLITE_OK ){ |
| 522 | - rc = sqlite3_create_function(db, "delta_output_size", 1, SQLITE_UTF8, 0, | |
| 523 | + rc = sqlite3_create_function(db, "delta_output_size", 1, enc, 0, | |
| 523 | 524 | deltaOutputSizeFunc, 0, 0); |
| 524 | 525 | } |
| 525 | 526 | if( rc==SQLITE_OK ){ |
| 526 | 527 | rc = sqlite3_create_module(db, "delta_parse", &deltaparsevtabModule, 0); |
| 527 | 528 | } |
| 528 | 529 | return rc; |
| 529 | 530 | } |
| 530 | 531 |
| --- src/deltafunc.c | |
| +++ src/deltafunc.c | |
| @@ -166,15 +166,15 @@ | |
| 166 | /* No additional information needed */ |
| 167 | }; |
| 168 | struct deltaparsevtab_cursor { |
| 169 | sqlite3_vtab_cursor base; /* Base class - must be first */ |
| 170 | char *aDelta; /* The delta being parsed */ |
| 171 | int nDelta; /* Number of bytes in the delta */ |
| 172 | int iCursor; /* Current cursor location */ |
| 173 | int eOp; /* Name of current operator */ |
| 174 | unsigned int a1, a2; /* Arguments to current operator */ |
| 175 | int iNext; /* Next cursor value */ |
| 176 | }; |
| 177 | |
| 178 | /* Operator names: |
| 179 | */ |
| 180 | static const char *const azOp[] = { |
| @@ -270,11 +270,11 @@ | |
| 270 | /* |
| 271 | ** Constructor for a new deltaparsevtab_cursor object. |
| 272 | */ |
| 273 | static int deltaparsevtabOpen(sqlite3_vtab *p, sqlite3_vtab_cursor **ppCursor){ |
| 274 | deltaparsevtab_cursor *pCur; |
| 275 | pCur = sqlite3_malloc( sizeof(*pCur) ); |
| 276 | if( pCur==0 ) return SQLITE_NOMEM; |
| 277 | memset(pCur, 0, sizeof(*pCur)); |
| 278 | *ppCursor = &pCur->base; |
| 279 | return SQLITE_OK; |
| 280 | } |
| @@ -314,18 +314,18 @@ | |
| 314 | pCur->iNext = pCur->nDelta; |
| 315 | break; |
| 316 | } |
| 317 | pCur->a2 = deltaGetInt(&z, &i); |
| 318 | pCur->eOp = DELTAPARSE_OP_COPY; |
| 319 | pCur->iNext = (int)(&z[1] - pCur->aDelta); |
| 320 | break; |
| 321 | } |
| 322 | case ':': { |
| 323 | z++; |
| 324 | pCur->a2 = (unsigned int)(z - pCur->aDelta); |
| 325 | pCur->eOp = DELTAPARSE_OP_INSERT; |
| 326 | pCur->iNext = (int)(&z[pCur->a1] - pCur->aDelta); |
| 327 | break; |
| 328 | } |
| 329 | case ';': { |
| 330 | pCur->eOp = DELTAPARSE_OP_CHECKSUM; |
| 331 | pCur->iNext = pCur->nDelta; |
| @@ -365,11 +365,11 @@ | |
| 365 | } |
| 366 | case DELTAPARSEVTAB_A2: { |
| 367 | if( pCur->eOp==DELTAPARSE_OP_COPY ){ |
| 368 | sqlite3_result_int(ctx, pCur->a2); |
| 369 | }else if( pCur->eOp==DELTAPARSE_OP_INSERT ){ |
| 370 | if( pCur->a2 + pCur->a1 > pCur->nDelta ){ |
| 371 | sqlite3_result_zeroblob(ctx, pCur->a1); |
| 372 | }else{ |
| 373 | sqlite3_result_blob(ctx, pCur->aDelta+pCur->a2, pCur->a1, |
| 374 | SQLITE_TRANSIENT); |
| 375 | } |
| @@ -441,11 +441,11 @@ | |
| 441 | pCur->a1 = pCur->a2 = 0; |
| 442 | pCur->iNext = pCur->nDelta; |
| 443 | return SQLITE_OK; |
| 444 | } |
| 445 | a++; |
| 446 | pCur->iNext = (unsigned int)(a - pCur->aDelta); |
| 447 | return SQLITE_OK; |
| 448 | } |
| 449 | |
| 450 | /* |
| 451 | ** SQLite will invoke this method one or more times while planning a query |
| @@ -509,21 +509,22 @@ | |
| 509 | |
| 510 | /* |
| 511 | ** Invoke this routine to register the various delta functions. |
| 512 | */ |
| 513 | int deltafunc_init(sqlite3 *db){ |
| 514 | int rc = SQLITE_OK; |
| 515 | rc = sqlite3_create_function(db, "delta_create", 2, SQLITE_UTF8, 0, |
| 516 | deltaCreateFunc, 0, 0); |
| 517 | if( rc==SQLITE_OK ){ |
| 518 | rc = sqlite3_create_function(db, "delta_apply", 2, SQLITE_UTF8, 0, |
| 519 | deltaApplyFunc, 0, 0); |
| 520 | } |
| 521 | if( rc==SQLITE_OK ){ |
| 522 | rc = sqlite3_create_function(db, "delta_output_size", 1, SQLITE_UTF8, 0, |
| 523 | deltaOutputSizeFunc, 0, 0); |
| 524 | } |
| 525 | if( rc==SQLITE_OK ){ |
| 526 | rc = sqlite3_create_module(db, "delta_parse", &deltaparsevtabModule, 0); |
| 527 | } |
| 528 | return rc; |
| 529 | } |
| 530 |
| --- src/deltafunc.c | |
| +++ src/deltafunc.c | |
| @@ -166,15 +166,15 @@ | |
| 166 | /* No additional information needed */ |
| 167 | }; |
| 168 | struct deltaparsevtab_cursor { |
| 169 | sqlite3_vtab_cursor base; /* Base class - must be first */ |
| 170 | char *aDelta; /* The delta being parsed */ |
| 171 | i64 iCursor; /* Current cursor location */ |
| 172 | i64 iNext; /* Next cursor value */ |
| 173 | i64 nDelta; /* Number of bytes in the delta */ |
| 174 | int eOp; /* Name of current operator */ |
| 175 | unsigned int a1, a2; /* Arguments to current operator */ |
| 176 | }; |
| 177 | |
| 178 | /* Operator names: |
| 179 | */ |
| 180 | static const char *const azOp[] = { |
| @@ -270,11 +270,11 @@ | |
| 270 | /* |
| 271 | ** Constructor for a new deltaparsevtab_cursor object. |
| 272 | */ |
| 273 | static int deltaparsevtabOpen(sqlite3_vtab *p, sqlite3_vtab_cursor **ppCursor){ |
| 274 | deltaparsevtab_cursor *pCur; |
| 275 | pCur = sqlite3_malloc64( sizeof(*pCur) ); |
| 276 | if( pCur==0 ) return SQLITE_NOMEM; |
| 277 | memset(pCur, 0, sizeof(*pCur)); |
| 278 | *ppCursor = &pCur->base; |
| 279 | return SQLITE_OK; |
| 280 | } |
| @@ -314,18 +314,18 @@ | |
| 314 | pCur->iNext = pCur->nDelta; |
| 315 | break; |
| 316 | } |
| 317 | pCur->a2 = deltaGetInt(&z, &i); |
| 318 | pCur->eOp = DELTAPARSE_OP_COPY; |
| 319 | pCur->iNext = (i64)(&z[1] - pCur->aDelta); |
| 320 | break; |
| 321 | } |
| 322 | case ':': { |
| 323 | z++; |
| 324 | pCur->a2 = (unsigned int)(z - pCur->aDelta); |
| 325 | pCur->eOp = DELTAPARSE_OP_INSERT; |
| 326 | pCur->iNext = (i64)(&z[pCur->a1] - pCur->aDelta); |
| 327 | break; |
| 328 | } |
| 329 | case ';': { |
| 330 | pCur->eOp = DELTAPARSE_OP_CHECKSUM; |
| 331 | pCur->iNext = pCur->nDelta; |
| @@ -365,11 +365,11 @@ | |
| 365 | } |
| 366 | case DELTAPARSEVTAB_A2: { |
| 367 | if( pCur->eOp==DELTAPARSE_OP_COPY ){ |
| 368 | sqlite3_result_int(ctx, pCur->a2); |
| 369 | }else if( pCur->eOp==DELTAPARSE_OP_INSERT ){ |
| 370 | if( (i64)pCur->a2 + (i64)pCur->a1 > pCur->nDelta ){ |
| 371 | sqlite3_result_zeroblob(ctx, pCur->a1); |
| 372 | }else{ |
| 373 | sqlite3_result_blob(ctx, pCur->aDelta+pCur->a2, pCur->a1, |
| 374 | SQLITE_TRANSIENT); |
| 375 | } |
| @@ -441,11 +441,11 @@ | |
| 441 | pCur->a1 = pCur->a2 = 0; |
| 442 | pCur->iNext = pCur->nDelta; |
| 443 | return SQLITE_OK; |
| 444 | } |
| 445 | a++; |
| 446 | pCur->iNext = (i64)(a - pCur->aDelta); |
| 447 | return SQLITE_OK; |
| 448 | } |
| 449 | |
| 450 | /* |
| 451 | ** SQLite will invoke this method one or more times while planning a query |
| @@ -509,21 +509,22 @@ | |
| 509 | |
| 510 | /* |
| 511 | ** Invoke this routine to register the various delta functions. |
| 512 | */ |
| 513 | int deltafunc_init(sqlite3 *db){ |
| 514 | static const int enc = SQLITE_UTF8|SQLITE_INNOCUOUS; |
| 515 | int rc = SQLITE_OK; |
| 516 | rc = sqlite3_create_function(db, "delta_create", 2, enc, 0, |
| 517 | deltaCreateFunc, 0, 0); |
| 518 | if( rc==SQLITE_OK ){ |
| 519 | rc = sqlite3_create_function(db, "delta_apply", 2, enc, 0, |
| 520 | deltaApplyFunc, 0, 0); |
| 521 | } |
| 522 | if( rc==SQLITE_OK ){ |
| 523 | rc = sqlite3_create_function(db, "delta_output_size", 1, enc, 0, |
| 524 | deltaOutputSizeFunc, 0, 0); |
| 525 | } |
| 526 | if( rc==SQLITE_OK ){ |
| 527 | rc = sqlite3_create_module(db, "delta_parse", &deltaparsevtabModule, 0); |
| 528 | } |
| 529 | return rc; |
| 530 | } |
| 531 |
+16
-4
| --- src/diff.tcl | ||
| +++ src/diff.tcl | ||
| @@ -125,11 +125,11 @@ | ||
| 125 | 125 | } |
| 126 | 126 | set N [llength $difftxt] |
| 127 | 127 | set ii 0 |
| 128 | 128 | set nDiffs 0 |
| 129 | 129 | set n1 0 |
| 130 | - set n2 0 | |
| 130 | + set n2 0 | |
| 131 | 131 | array set widths {txt 3 ln 3 mkr 1} |
| 132 | 132 | if {$redo} { |
| 133 | 133 | foreach c [cols] {$c config -state normal} |
| 134 | 134 | .lnA delete 1.0 end |
| 135 | 135 | .txtA delete 1.0 end |
| @@ -136,12 +136,12 @@ | ||
| 136 | 136 | .lnB delete 1.0 end |
| 137 | 137 | .txtB delete 1.0 end |
| 138 | 138 | .mkr delete 1.0 end |
| 139 | 139 | .wfiles.lb delete 0 end |
| 140 | 140 | } |
| 141 | - | |
| 142 | - | |
| 141 | + | |
| 142 | + | |
| 143 | 143 | set fromIndex [lsearch -glob $fossilcmd *-from] |
| 144 | 144 | set toIndex [lsearch -glob $fossilcmd *-to] |
| 145 | 145 | set branchIndex [lsearch -glob $fossilcmd *-branch] |
| 146 | 146 | set checkinIndex [lsearch -glob $fossilcmd *-checkin] |
| 147 | 147 | if {[lsearch -glob $fossilcmd *-label]>=0 |
| @@ -167,11 +167,11 @@ | ||
| 167 | 167 | } |
| 168 | 168 | if {$checkinIndex > -1} { |
| 169 | 169 | set fA "primary parent"; set fB [lindex $fossilcmd $checkinIndex+1] |
| 170 | 170 | } |
| 171 | 171 | } |
| 172 | - | |
| 172 | + | |
| 173 | 173 | while {[set line [getLine $difftxt $N ii]] != -1} { |
| 174 | 174 | switch -- [lindex $line 0] { |
| 175 | 175 | FILE { |
| 176 | 176 | incr nDiffs |
| 177 | 177 | foreach wx [list [string length $n1] [string length $n2]] { |
| @@ -626,8 +626,20 @@ | ||
| 626 | 626 | grid .sbxA -row 2 -columnspan 2 -sticky ew |
| 627 | 627 | grid .spacer -row 2 -column 2 |
| 628 | 628 | grid .sbxB -row 2 -column 3 -columnspan 2 -sticky ew |
| 629 | 629 | |
| 630 | 630 | .spacer config -height [winfo height .sbxA] |
| 631 | + | |
| 632 | +set h [winfo screenheight .] | |
| 633 | +if {$h > 1280} { | |
| 634 | + set w [winfo screenwidth .]; # [winfo width] == 32 | |
| 635 | + if {$w > 2048} { | |
| 636 | + set w 2048 | |
| 637 | + } | |
| 638 | + set g [expr {$w / 3 * 2}]x[expr {$h / 4 * 3}] | |
| 639 | + wm geometry . $g | |
| 640 | +} | |
| 641 | + | |
| 631 | 642 | wm deiconify . |
| 643 | + | |
| 632 | 644 | } |
| 633 | 645 | eval $prog |
| 634 | 646 |
| --- src/diff.tcl | |
| +++ src/diff.tcl | |
| @@ -125,11 +125,11 @@ | |
| 125 | } |
| 126 | set N [llength $difftxt] |
| 127 | set ii 0 |
| 128 | set nDiffs 0 |
| 129 | set n1 0 |
| 130 | set n2 0 |
| 131 | array set widths {txt 3 ln 3 mkr 1} |
| 132 | if {$redo} { |
| 133 | foreach c [cols] {$c config -state normal} |
| 134 | .lnA delete 1.0 end |
| 135 | .txtA delete 1.0 end |
| @@ -136,12 +136,12 @@ | |
| 136 | .lnB delete 1.0 end |
| 137 | .txtB delete 1.0 end |
| 138 | .mkr delete 1.0 end |
| 139 | .wfiles.lb delete 0 end |
| 140 | } |
| 141 | |
| 142 | |
| 143 | set fromIndex [lsearch -glob $fossilcmd *-from] |
| 144 | set toIndex [lsearch -glob $fossilcmd *-to] |
| 145 | set branchIndex [lsearch -glob $fossilcmd *-branch] |
| 146 | set checkinIndex [lsearch -glob $fossilcmd *-checkin] |
| 147 | if {[lsearch -glob $fossilcmd *-label]>=0 |
| @@ -167,11 +167,11 @@ | |
| 167 | } |
| 168 | if {$checkinIndex > -1} { |
| 169 | set fA "primary parent"; set fB [lindex $fossilcmd $checkinIndex+1] |
| 170 | } |
| 171 | } |
| 172 | |
| 173 | while {[set line [getLine $difftxt $N ii]] != -1} { |
| 174 | switch -- [lindex $line 0] { |
| 175 | FILE { |
| 176 | incr nDiffs |
| 177 | foreach wx [list [string length $n1] [string length $n2]] { |
| @@ -626,8 +626,20 @@ | |
| 626 | grid .sbxA -row 2 -columnspan 2 -sticky ew |
| 627 | grid .spacer -row 2 -column 2 |
| 628 | grid .sbxB -row 2 -column 3 -columnspan 2 -sticky ew |
| 629 | |
| 630 | .spacer config -height [winfo height .sbxA] |
| 631 | wm deiconify . |
| 632 | } |
| 633 | eval $prog |
| 634 |
| --- src/diff.tcl | |
| +++ src/diff.tcl | |
| @@ -125,11 +125,11 @@ | |
| 125 | } |
| 126 | set N [llength $difftxt] |
| 127 | set ii 0 |
| 128 | set nDiffs 0 |
| 129 | set n1 0 |
| 130 | set n2 0 |
| 131 | array set widths {txt 3 ln 3 mkr 1} |
| 132 | if {$redo} { |
| 133 | foreach c [cols] {$c config -state normal} |
| 134 | .lnA delete 1.0 end |
| 135 | .txtA delete 1.0 end |
| @@ -136,12 +136,12 @@ | |
| 136 | .lnB delete 1.0 end |
| 137 | .txtB delete 1.0 end |
| 138 | .mkr delete 1.0 end |
| 139 | .wfiles.lb delete 0 end |
| 140 | } |
| 141 | |
| 142 | |
| 143 | set fromIndex [lsearch -glob $fossilcmd *-from] |
| 144 | set toIndex [lsearch -glob $fossilcmd *-to] |
| 145 | set branchIndex [lsearch -glob $fossilcmd *-branch] |
| 146 | set checkinIndex [lsearch -glob $fossilcmd *-checkin] |
| 147 | if {[lsearch -glob $fossilcmd *-label]>=0 |
| @@ -167,11 +167,11 @@ | |
| 167 | } |
| 168 | if {$checkinIndex > -1} { |
| 169 | set fA "primary parent"; set fB [lindex $fossilcmd $checkinIndex+1] |
| 170 | } |
| 171 | } |
| 172 | |
| 173 | while {[set line [getLine $difftxt $N ii]] != -1} { |
| 174 | switch -- [lindex $line 0] { |
| 175 | FILE { |
| 176 | incr nDiffs |
| 177 | foreach wx [list [string length $n1] [string length $n2]] { |
| @@ -626,8 +626,20 @@ | |
| 626 | grid .sbxA -row 2 -columnspan 2 -sticky ew |
| 627 | grid .spacer -row 2 -column 2 |
| 628 | grid .sbxB -row 2 -column 3 -columnspan 2 -sticky ew |
| 629 | |
| 630 | .spacer config -height [winfo height .sbxA] |
| 631 | |
| 632 | set h [winfo screenheight .] |
| 633 | if {$h > 1280} { |
| 634 | set w [winfo screenwidth .]; # [winfo width] == 32 |
| 635 | if {$w > 2048} { |
| 636 | set w 2048 |
| 637 | } |
| 638 | set g [expr {$w / 3 * 2}]x[expr {$h / 4 * 3}] |
| 639 | wm geometry . $g |
| 640 | } |
| 641 | |
| 642 | wm deiconify . |
| 643 | |
| 644 | } |
| 645 | eval $prog |
| 646 |
+1
-1
| --- src/diffcmd.c | ||
| +++ src/diffcmd.c | ||
| @@ -776,11 +776,11 @@ | ||
| 776 | 776 | |
| 777 | 777 | /* |
| 778 | 778 | ** Return true if the disk file is identical to the Blob. Return zero |
| 779 | 779 | ** if the files differ in any way. |
| 780 | 780 | */ |
| 781 | -static int file_same_as_blob(Blob *blob, const char *zDiskFile){ | |
| 781 | +int file_same_as_blob(Blob *blob, const char *zDiskFile){ | |
| 782 | 782 | Blob file; |
| 783 | 783 | int rc = 0; |
| 784 | 784 | if( blob_size(blob)!=file_size(zDiskFile, ExtFILE) ) return 0; |
| 785 | 785 | blob_zero(&file); |
| 786 | 786 | blob_read_from_file(&file, zDiskFile, ExtFILE); |
| 787 | 787 |
| --- src/diffcmd.c | |
| +++ src/diffcmd.c | |
| @@ -776,11 +776,11 @@ | |
| 776 | |
| 777 | /* |
| 778 | ** Return true if the disk file is identical to the Blob. Return zero |
| 779 | ** if the files differ in any way. |
| 780 | */ |
| 781 | static int file_same_as_blob(Blob *blob, const char *zDiskFile){ |
| 782 | Blob file; |
| 783 | int rc = 0; |
| 784 | if( blob_size(blob)!=file_size(zDiskFile, ExtFILE) ) return 0; |
| 785 | blob_zero(&file); |
| 786 | blob_read_from_file(&file, zDiskFile, ExtFILE); |
| 787 |
| --- src/diffcmd.c | |
| +++ src/diffcmd.c | |
| @@ -776,11 +776,11 @@ | |
| 776 | |
| 777 | /* |
| 778 | ** Return true if the disk file is identical to the Blob. Return zero |
| 779 | ** if the files differ in any way. |
| 780 | */ |
| 781 | int file_same_as_blob(Blob *blob, const char *zDiskFile){ |
| 782 | Blob file; |
| 783 | int rc = 0; |
| 784 | if( blob_size(blob)!=file_size(zDiskFile, ExtFILE) ) return 0; |
| 785 | blob_zero(&file); |
| 786 | blob_read_from_file(&file, zDiskFile, ExtFILE); |
| 787 |
+14
-7
| --- src/event.c | ||
| +++ src/event.c | ||
| @@ -117,11 +117,15 @@ | ||
| 117 | 117 | style_header("No Such Tech-Note"); |
| 118 | 118 | @ Cannot locate a technical note called <b>%h(zId)</b>. |
| 119 | 119 | style_finish_page(); |
| 120 | 120 | return; |
| 121 | 121 | } |
| 122 | - zUuid = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", rid); | |
| 122 | + zUuid = rid_to_uuid(rid); | |
| 123 | + zFullId = db_text(0, "SELECT SUBSTR(tagname,7)" | |
| 124 | + " FROM tag" | |
| 125 | + " WHERE tagname GLOB 'event-%q*'", | |
| 126 | + zId); | |
| 123 | 127 | zVerbose = P("v"); |
| 124 | 128 | if( !zVerbose ){ |
| 125 | 129 | zVerbose = P("verbose"); |
| 126 | 130 | } |
| 127 | 131 | if( !zVerbose ){ |
| @@ -157,11 +161,11 @@ | ||
| 157 | 161 | style_header("%s", blob_str(&title)); |
| 158 | 162 | if( g.perm.WrWiki && g.perm.Write && nextRid==0 ){ |
| 159 | 163 | style_submenu_element("Edit", "%R/technoteedit?name=%!S", zId); |
| 160 | 164 | if( g.perm.Attach ){ |
| 161 | 165 | style_submenu_element("Attach", |
| 162 | - "%R/attachadd?technote=%!S&from=%R/technote/%!S", zId, zId); | |
| 166 | + "%R/attachadd?target=%s&from=%R/technote/%!S", zFullId, zId); | |
| 163 | 167 | } |
| 164 | 168 | } |
| 165 | 169 | zETime = db_text(0, "SELECT datetime(%.17g)", pTNote->rEventDate); |
| 166 | 170 | style_submenu_element("Context", "%R/timeline?c=%.20s", zId); |
| 167 | 171 | if( g.perm.Hyperlink ){ |
| @@ -225,15 +229,18 @@ | ||
| 225 | 229 | }else{ |
| 226 | 230 | @ <pre> |
| 227 | 231 | @ %h(blob_str(&fullbody)) |
| 228 | 232 | @ </pre> |
| 229 | 233 | } |
| 230 | - zFullId = db_text(0, "SELECT SUBSTR(tagname,7)" | |
| 231 | - " FROM tag" | |
| 232 | - " WHERE tagname GLOB 'event-%q*'", | |
| 233 | - zId); | |
| 234 | - attachment_list(zFullId, "<h2>Attachments:</h2>", 1); | |
| 234 | + { | |
| 235 | + char * z = mprintf( | |
| 236 | + "<h2><a href='%R/attachlist?technote=%t'>Attachments</a>:</h2>", | |
| 237 | + zFullId | |
| 238 | + ); | |
| 239 | + attachment_list(zFullId, z, 1); | |
| 240 | + fossil_free(z); | |
| 241 | + } | |
| 235 | 242 | document_emit_js(); |
| 236 | 243 | style_finish_page(); |
| 237 | 244 | manifest_destroy(pTNote); |
| 238 | 245 | } |
| 239 | 246 | |
| 240 | 247 |
| --- src/event.c | |
| +++ src/event.c | |
| @@ -117,11 +117,15 @@ | |
| 117 | style_header("No Such Tech-Note"); |
| 118 | @ Cannot locate a technical note called <b>%h(zId)</b>. |
| 119 | style_finish_page(); |
| 120 | return; |
| 121 | } |
| 122 | zUuid = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", rid); |
| 123 | zVerbose = P("v"); |
| 124 | if( !zVerbose ){ |
| 125 | zVerbose = P("verbose"); |
| 126 | } |
| 127 | if( !zVerbose ){ |
| @@ -157,11 +161,11 @@ | |
| 157 | style_header("%s", blob_str(&title)); |
| 158 | if( g.perm.WrWiki && g.perm.Write && nextRid==0 ){ |
| 159 | style_submenu_element("Edit", "%R/technoteedit?name=%!S", zId); |
| 160 | if( g.perm.Attach ){ |
| 161 | style_submenu_element("Attach", |
| 162 | "%R/attachadd?technote=%!S&from=%R/technote/%!S", zId, zId); |
| 163 | } |
| 164 | } |
| 165 | zETime = db_text(0, "SELECT datetime(%.17g)", pTNote->rEventDate); |
| 166 | style_submenu_element("Context", "%R/timeline?c=%.20s", zId); |
| 167 | if( g.perm.Hyperlink ){ |
| @@ -225,15 +229,18 @@ | |
| 225 | }else{ |
| 226 | @ <pre> |
| 227 | @ %h(blob_str(&fullbody)) |
| 228 | @ </pre> |
| 229 | } |
| 230 | zFullId = db_text(0, "SELECT SUBSTR(tagname,7)" |
| 231 | " FROM tag" |
| 232 | " WHERE tagname GLOB 'event-%q*'", |
| 233 | zId); |
| 234 | attachment_list(zFullId, "<h2>Attachments:</h2>", 1); |
| 235 | document_emit_js(); |
| 236 | style_finish_page(); |
| 237 | manifest_destroy(pTNote); |
| 238 | } |
| 239 | |
| 240 |
| --- src/event.c | |
| +++ src/event.c | |
| @@ -117,11 +117,15 @@ | |
| 117 | style_header("No Such Tech-Note"); |
| 118 | @ Cannot locate a technical note called <b>%h(zId)</b>. |
| 119 | style_finish_page(); |
| 120 | return; |
| 121 | } |
| 122 | zUuid = rid_to_uuid(rid); |
| 123 | zFullId = db_text(0, "SELECT SUBSTR(tagname,7)" |
| 124 | " FROM tag" |
| 125 | " WHERE tagname GLOB 'event-%q*'", |
| 126 | zId); |
| 127 | zVerbose = P("v"); |
| 128 | if( !zVerbose ){ |
| 129 | zVerbose = P("verbose"); |
| 130 | } |
| 131 | if( !zVerbose ){ |
| @@ -157,11 +161,11 @@ | |
| 161 | style_header("%s", blob_str(&title)); |
| 162 | if( g.perm.WrWiki && g.perm.Write && nextRid==0 ){ |
| 163 | style_submenu_element("Edit", "%R/technoteedit?name=%!S", zId); |
| 164 | if( g.perm.Attach ){ |
| 165 | style_submenu_element("Attach", |
| 166 | "%R/attachadd?target=%s&from=%R/technote/%!S", zFullId, zId); |
| 167 | } |
| 168 | } |
| 169 | zETime = db_text(0, "SELECT datetime(%.17g)", pTNote->rEventDate); |
| 170 | style_submenu_element("Context", "%R/timeline?c=%.20s", zId); |
| 171 | if( g.perm.Hyperlink ){ |
| @@ -225,15 +229,18 @@ | |
| 229 | }else{ |
| 230 | @ <pre> |
| 231 | @ %h(blob_str(&fullbody)) |
| 232 | @ </pre> |
| 233 | } |
| 234 | { |
| 235 | char * z = mprintf( |
| 236 | "<h2><a href='%R/attachlist?technote=%t'>Attachments</a>:</h2>", |
| 237 | zFullId |
| 238 | ); |
| 239 | attachment_list(zFullId, z, 1); |
| 240 | fossil_free(z); |
| 241 | } |
| 242 | document_emit_js(); |
| 243 | style_finish_page(); |
| 244 | manifest_destroy(pTNote); |
| 245 | } |
| 246 | |
| 247 |
+1
-1
| --- src/finfo.c | ||
| +++ src/finfo.c | ||
| @@ -164,11 +164,11 @@ | ||
| 164 | 164 | zRevision, &fname, filename_collation()); |
| 165 | 165 | if( rid==0 ) { |
| 166 | 166 | fossil_fatal("file not found for revision %s: %s", |
| 167 | 167 | zRevision, blob_str(&fname)); |
| 168 | 168 | } |
| 169 | - whatis_rid(rid,whatisFlags); | |
| 169 | + whatis_rid(rid,whatisFlags,0); | |
| 170 | 170 | blob_reset(&fname); |
| 171 | 171 | }else{ |
| 172 | 172 | Blob line; |
| 173 | 173 | Stmt q; |
| 174 | 174 | Blob fname; |
| 175 | 175 |
| --- src/finfo.c | |
| +++ src/finfo.c | |
| @@ -164,11 +164,11 @@ | |
| 164 | zRevision, &fname, filename_collation()); |
| 165 | if( rid==0 ) { |
| 166 | fossil_fatal("file not found for revision %s: %s", |
| 167 | zRevision, blob_str(&fname)); |
| 168 | } |
| 169 | whatis_rid(rid,whatisFlags); |
| 170 | blob_reset(&fname); |
| 171 | }else{ |
| 172 | Blob line; |
| 173 | Stmt q; |
| 174 | Blob fname; |
| 175 |
| --- src/finfo.c | |
| +++ src/finfo.c | |
| @@ -164,11 +164,11 @@ | |
| 164 | zRevision, &fname, filename_collation()); |
| 165 | if( rid==0 ) { |
| 166 | fossil_fatal("file not found for revision %s: %s", |
| 167 | zRevision, blob_str(&fname)); |
| 168 | } |
| 169 | whatis_rid(rid,whatisFlags,0); |
| 170 | blob_reset(&fname); |
| 171 | }else{ |
| 172 | Blob line; |
| 173 | Stmt q; |
| 174 | Blob fname; |
| 175 |
+1301
-214
| --- src/forum.c | ||
| +++ src/forum.c | ||
| @@ -49,11 +49,11 @@ | ||
| 49 | 49 | ForumPost *pNext; /* Next in chronological order */ |
| 50 | 50 | ForumPost *pPrev; /* Previous in chronological order */ |
| 51 | 51 | ForumPost *pDisplay; /* Next in display order */ |
| 52 | 52 | int nEdit; /* Number of edits to this post */ |
| 53 | 53 | int nIndent; /* Number of levels of indentation for this post */ |
| 54 | - int iClosed; /* See forum_rid_is_closed() */ | |
| 54 | + int iClosed; /* True if forum_rid_is_tagged("closed") */ | |
| 55 | 55 | }; |
| 56 | 56 | |
| 57 | 57 | /* |
| 58 | 58 | ** A single instance of the following tracks all entries for a thread. |
| 59 | 59 | */ |
| @@ -63,12 +63,134 @@ | ||
| 63 | 63 | ForumPost *pDisplay; /* Entries in display order */ |
| 64 | 64 | ForumPost *pTail; /* Last on the display list */ |
| 65 | 65 | int mxIndent; /* Maximum indentation level */ |
| 66 | 66 | int nArtifact; /* Number of forum artifacts in this thread */ |
| 67 | 67 | }; |
| 68 | + | |
| 69 | +/* | |
| 70 | +** A single entry from the forum-statuses setting. | |
| 71 | +*/ | |
| 72 | +struct ForumStatus { | |
| 73 | + char *zLabel; /* Label for the UI */ | |
| 74 | + char *zValue; /* status=X tag value */ | |
| 75 | +}; | |
| 76 | + | |
| 77 | +/* | |
| 78 | +** A list of ForumStatus objects. | |
| 79 | +*/ | |
| 80 | +struct ForumStatusList { | |
| 81 | + struct ForumStatus *aStatus; /* List of statuses */ | |
| 82 | + unsigned int n; /* Number of entries */ | |
| 83 | +}; | |
| 84 | + | |
| 85 | +/* | |
| 86 | +** Information passed into the status_match() SQL function | |
| 87 | +** via the sqlite3_user_data() mechanism, and used by status_match() | |
| 88 | +** to determine whether or not a particular forum thread should | |
| 89 | +** be displayed. | |
| 90 | +*/ | |
| 91 | +struct ForumStatusMatch { | |
| 92 | + const ForumStatusList *pFses; /* Parsed forum-statuses setting */ | |
| 93 | + int eStatusTag; /* tagid for the "status" property */ | |
| 94 | + unsigned int iMatch; /* Match this status value */ | |
| 95 | +}; | |
| 68 | 96 | #endif /* INTERFACE */ |
| 69 | 97 | |
| 98 | + | |
| 99 | +/* | |
| 100 | +** Returns a high-level representation of the forum-statuses setting. | |
| 101 | +** This is a singleton, cached across calls. | |
| 102 | + */ | |
| 103 | +const ForumStatusList * forum_statuses(void){ | |
| 104 | + static ForumStatusList fses = {0,0}; | |
| 105 | + static int once = 0; | |
| 106 | + while( !once ){ | |
| 107 | + ++once; | |
| 108 | + /* Read `forum-statuses` setting and transform it into the | |
| 109 | + ** fses object. | |
| 110 | + ** | |
| 111 | + ** Maybe: if it's empty, synthesize a length-1 list from | |
| 112 | + ** {value:"default",label:"Default",...}. It's expected that | |
| 113 | + ** usage may be slightly simplified if we always have a non-empty | |
| 114 | + ** list. A length-1 list is, for purposes of the UI, identical to | |
| 115 | + ** an empty one - status selection/filtering makes no sense if | |
| 116 | + ** there's only one choice. */ | |
| 117 | + db_multi_exec( | |
| 118 | + "CREATE TEMP TABLE IF NOT EXISTS forumstatus(" | |
| 119 | + " ord INTEGER PRIMARY KEY, label, value" | |
| 120 | + ");" | |
| 121 | + "DELETE FROM forumstatus;" | |
| 122 | + "INSERT INTO forumstatus(label,value)" | |
| 123 | + " WITH setting(v) AS (" | |
| 124 | + " SELECT value v FROM config WHERE name='forum-statuses'" | |
| 125 | + " )," | |
| 126 | + " room(r) AS (" | |
| 127 | + " SELECT e.value FROM setting s, jsonb_each(s.v) e" | |
| 128 | + " WHERE json_valid(s.v, 0x02)" | |
| 129 | + " )" | |
| 130 | + " SELECT r->>'label', r->>'value'" | |
| 131 | + " FROM room;" | |
| 132 | + ); | |
| 133 | + fses.n = (unsigned)db_int(0, "SELECT count(*) FROM forumstatus"); | |
| 134 | + if( fses.n ){ | |
| 135 | + int i = 0; | |
| 136 | + Stmt q; | |
| 137 | + db_prepare(&q,"SELECT label, value FROM forumstatus" | |
| 138 | + " ORDER BY ord"); | |
| 139 | + fses.aStatus = fossil_malloc(sizeof(fses.aStatus[0]) * fses.n); | |
| 140 | + while( SQLITE_ROW==db_step(&q) ){ | |
| 141 | + ForumStatus * fs = &fses.aStatus[i++]; | |
| 142 | + fs->zLabel = fossil_strdup(db_column_text(&q, 0)); | |
| 143 | + fs->zValue = fossil_strdup(db_column_text(&q, 1)); | |
| 144 | + } | |
| 145 | + db_finalize(&q); | |
| 146 | + } | |
| 147 | + } | |
| 148 | + return &fses; | |
| 149 | +} | |
| 150 | + | |
| 151 | +/* | |
| 152 | +** Search for a ForumStatus object by its tag value. If a match is | |
| 153 | +** found, the corresponding object is returned. If no match is found | |
| 154 | +** then (A) if bFirst is false then 0 is returned, else (B) the first | |
| 155 | +** entry in the list is returned, noting that the list may be empty, | |
| 156 | +** in which case 0 is returned. | |
| 157 | +*/ | |
| 158 | +static const ForumStatus * forum_status_by_value( | |
| 159 | + const char *z, int bFirst | |
| 160 | +){ | |
| 161 | + const ForumStatusList * const fses = forum_statuses(); | |
| 162 | + const ForumStatus * fs0 = 0; | |
| 163 | + unsigned int i; | |
| 164 | + if( !fses->n ) return 0; | |
| 165 | + for( i = 0; i < fses->n; ++i ){ | |
| 166 | + const ForumStatus * fs = &fses->aStatus[i]; | |
| 167 | + if( 0==fossil_strcmp(z, fs->zValue) ){ | |
| 168 | + return fs; | |
| 169 | + }else if( !fs0 ){ | |
| 170 | + fs0 = fs; | |
| 171 | + } | |
| 172 | + } | |
| 173 | + return bFirst ? fs0 : 0; | |
| 174 | +} | |
| 175 | + | |
| 176 | +/* | |
| 177 | +** COMMAND: test-forum-statuses | |
| 178 | +*/ | |
| 179 | +void test_forum_statuses_cmd(void){ | |
| 180 | + const ForumStatusList * fses; | |
| 181 | + unsigned i; | |
| 182 | + db_find_and_open_repository(0,0); | |
| 183 | + fses = forum_statuses(); | |
| 184 | + for(i = 0; i < fses->n; ++i ){ | |
| 185 | + const ForumStatus * fs = &fses->aStatus[i]; | |
| 186 | + fossil_print("Status: %!j %!j\n", fs->zValue, fs->zLabel); | |
| 187 | + assert( fs==forum_status_by_value(fs->zValue, 0) ); | |
| 188 | + } | |
| 189 | + fossil_print("Total statuses: %u\n", i); | |
| 190 | +} | |
| 191 | + | |
| 70 | 192 | /* |
| 71 | 193 | ** Return true if the forum post with the given rid has been |
| 72 | 194 | ** subsequently edited. |
| 73 | 195 | */ |
| 74 | 196 | int forum_rid_has_been_edited(int rid){ |
| @@ -83,29 +205,68 @@ | ||
| 83 | 205 | db_reset(&q); |
| 84 | 206 | return res; |
| 85 | 207 | } |
| 86 | 208 | |
| 87 | 209 | /* |
| 88 | -** Given a valid forumpost.fpid value, this function returns the first | |
| 89 | -** fpid in the chain of edits for that forum post, or rid if no prior | |
| 90 | -** versions are found. | |
| 210 | +** Given a valid forumpost.fpid value, this function returns the | |
| 211 | +** initial forumpost.fpid in the chain of edits for that forum post, | |
| 212 | +** or rid if no prior versions are found. | |
| 91 | 213 | */ |
| 92 | -static int forumpost_head_rid(int rid){ | |
| 93 | - Stmt q; | |
| 214 | +int forumpost_head_rid(int rid){ | |
| 215 | + static Stmt q = empty_Stmt_m; | |
| 94 | 216 | int rcRid = rid; |
| 95 | - | |
| 96 | - db_prepare(&q, "SELECT fprev FROM forumpost" | |
| 97 | - " WHERE fpid=:rid AND fprev IS NOT NULL"); | |
| 217 | + if( !q.pStmt ){ | |
| 218 | + db_static_prepare(&q, | |
| 219 | + "SELECT fprev FROM forumpost" | |
| 220 | + " WHERE fpid=:rid AND fprev IS NOT NULL" | |
| 221 | + ); | |
| 222 | + } | |
| 98 | 223 | db_bind_int(&q, ":rid", rid); |
| 99 | 224 | while( SQLITE_ROW==db_step(&q) ){ |
| 100 | 225 | rcRid = db_column_int(&q, 0); |
| 101 | 226 | db_reset(&q); |
| 102 | 227 | db_bind_int(&q, ":rid", rcRid); |
| 103 | 228 | } |
| 104 | - db_finalize(&q); | |
| 229 | + db_reset(&q); | |
| 105 | 230 | return rcRid; |
| 106 | 231 | } |
| 232 | + | |
| 233 | +/* | |
| 234 | +** Works like forumpost_head_rid() but expects zUuid to be an | |
| 235 | +** unambiguous forum post name. It may be a hash prefix, so long as | |
| 236 | +** it's unambiguous. Returns the rid of the head post, -1 if the name | |
| 237 | +** is ambiguous, and 0 if the name cannot be resolved as a forum post. | |
| 238 | +*/ | |
| 239 | +int forumpost_head_rid2(const char *zUuid){ | |
| 240 | + const int fpid = symbolic_name_to_rid(zUuid, "f"); | |
| 241 | + return fpid>0 | |
| 242 | + ? forumpost_head_rid(fpid) | |
| 243 | + : fpid; | |
| 244 | +} | |
| 245 | + | |
| 246 | +/* | |
| 247 | +** Given a forum post RID and user name, returns true if zUserName | |
| 248 | +** matches the event.(euser,user) field for a formpost entry with the | |
| 249 | +** matching RID. Returns false if no match is found. If zUserName is | |
| 250 | +** 0 then login_name() is used. | |
| 251 | +*/ | |
| 252 | +int forumpost_is_owner(int rid, const char *zUserName){ | |
| 253 | + static Stmt q; | |
| 254 | + int rc; | |
| 255 | + if( !q.pStmt ){ | |
| 256 | + db_static_prepare( | |
| 257 | + &q, "SELECT 1 FROM event" | |
| 258 | + " WHERE type='f' AND objid=$rid" | |
| 259 | + " AND coalesce(euser,user)=$user" | |
| 260 | + ); | |
| 261 | + } | |
| 262 | + db_bind_int(&q, "$rid", rid); | |
| 263 | + db_bind_text(&q, "$user", zUserName ? zUserName : login_name()); | |
| 264 | + rc = SQLITE_ROW==db_step(&q); | |
| 265 | + db_reset(&q); | |
| 266 | + return rc; | |
| 267 | +} | |
| 107 | 268 | |
| 108 | 269 | /* |
| 109 | 270 | ** Returns true if p, or any parent of p, has a non-zero iClosed |
| 110 | 271 | ** value. Returns 0 if !p. For an edited chain of post, the tag is |
| 111 | 272 | ** checked on the pEditHead entry, to simplify subsequent unlocking of |
| @@ -128,39 +289,39 @@ | ||
| 128 | 289 | return 0; |
| 129 | 290 | } |
| 130 | 291 | |
| 131 | 292 | /* |
| 132 | 293 | ** Given a forum post RID, this function returns true if that post has |
| 133 | -** (or inherits) an active "closed" tag. If bCheckIrt is true then | |
| 134 | -** the post to which the given post responds is also checked | |
| 294 | +** (or inherits) an active tag named zTagName. If bCheckIrt is true | |
| 295 | +** then the post to which the given post responds is also checked | |
| 135 | 296 | ** (recursively), else they are not. When checking in-response-to |
| 136 | 297 | ** posts, the first one which is closed ends the search. |
| 137 | 298 | ** |
| 138 | -** Note that this function checks _exactly_ the given rid, whereas | |
| 139 | -** forum post closure/re-opening is always applied to the head of an | |
| 140 | -** edit chain so that we get consistent implied locking behavior for | |
| 141 | -** later versions and responses to arbitrary versions in the | |
| 142 | -** chain. Even so, the "closed" tag is applied as a propagating tag | |
| 143 | -** so will apply to all edits in a given chain. | |
| 299 | +** This function checks _exactly_ the given rid, whereas forum post | |
| 300 | +** closure/re-opening is always applied to the head of an edit chain | |
| 301 | +** so that we get consistent implied locking behavior for later | |
| 302 | +** versions and responses to arbitrary versions in the chain. Even so, | |
| 303 | +** the "closed" tag is applied as a propagating tag so will apply to | |
| 304 | +** all edits in a given chain. | |
| 144 | 305 | ** |
| 145 | 306 | ** The return value is one of: |
| 146 | 307 | ** |
| 147 | -** - 0 if no "closed" tag is found. | |
| 308 | +** - 0 if no matching tag is found. | |
| 148 | 309 | ** |
| 149 | 310 | ** - The tagxref.rowid of the tagxref entry for the closure if rid is |
| 150 | 311 | ** the forum post to which the closure applies. |
| 151 | 312 | ** |
| 152 | -** - (-tagxref.rowid) if the given rid inherits a "closed" tag from an | |
| 153 | -** IRT forum post. | |
| 313 | +** - (-tagxref.rowid) if the given rid inherits the tag from an IRT | |
| 314 | +** forum post. | |
| 154 | 315 | */ |
| 155 | -static int forum_rid_is_closed(int rid, int bCheckIrt){ | |
| 316 | +static int forum_rid_is_tagged(int rid, const char *zTagName, int bCheckIrt){ | |
| 156 | 317 | static Stmt qIrt = empty_Stmt_m; |
| 157 | 318 | int rc = 0, i = 0; |
| 158 | 319 | /* TODO: this can probably be turned into a CTE by someone with |
| 159 | 320 | ** superior SQL-fu. */ |
| 160 | 321 | for( ; rid; i++ ){ |
| 161 | - rc = rid_has_active_tag_name(rid, "closed"); | |
| 322 | + rc = rid_has_active_tag_name(rid, zTagName); | |
| 162 | 323 | if( rc || !bCheckIrt ) break; |
| 163 | 324 | else if( !qIrt.pStmt ) { |
| 164 | 325 | db_static_prepare(&qIrt, |
| 165 | 326 | "SELECT firt FROM forumpost " |
| 166 | 327 | "WHERE fpid=$fpid ORDER BY fmtime DESC" |
| @@ -171,105 +332,211 @@ | ||
| 171 | 332 | db_reset(&qIrt); |
| 172 | 333 | } |
| 173 | 334 | return i ? -rc : rc; |
| 174 | 335 | } |
| 175 | 336 | |
| 176 | -/* | |
| 177 | -** Closes or re-opens the given forum RID via addition of a new | |
| 178 | -** control artifact into the repository. In order to provide | |
| 179 | -** consistent behavior for implied closing of responses and later | |
| 180 | -** versions, it always acts on the first version of the given forum | |
| 181 | -** post, walking the forumpost.fprev values to find the head of the | |
| 182 | -** chain. | |
| 183 | -** | |
| 184 | -** If doClose is true then a propagating "closed" tag is added, except | |
| 185 | -** as noted below, with the given optional zReason string as the tag's | |
| 186 | -** value. If doClose is false then any active "closed" tag on frid is | |
| 187 | -** cancelled, except as noted below. zReason is ignored if doClose is | |
| 188 | -** false or if zReason is NULL or starts with a NUL byte. | |
| 189 | -** | |
| 190 | -** This function only adds a "closed" tag if forum_rid_is_closed() | |
| 191 | -** indicates that frid's head is not closed. If a parent post is | |
| 192 | -** already closed, no tag is added. Similarly, it will only remove a | |
| 193 | -** "closed" tag from a post which has its own "closed" tag, and will | |
| 194 | -** not remove an inherited one from a parent post. | |
| 195 | -** | |
| 196 | -** If doClose is true and frid is closed (directly or inherited), this | |
| 197 | -** is a no-op. Likewise, if doClose is false and frid itself is not | |
| 198 | -** closed (not accounting for an inherited closed tag), this is a | |
| 199 | -** no-op. | |
| 200 | -** | |
| 201 | -** Returns true if it actually creates a new tag, else false. Fails | |
| 202 | -** fatally on error. If it returns true then any ForumPost::iClosed | |
| 203 | -** values from previously loaded posts are invalidated if they refer | |
| 204 | -** to the amended post or a response to it. | |
| 337 | +/* True if moderation of forum posts performs the same operation | |
| 338 | +** on its attachments. */ | |
| 339 | +#define FORUMPOST_MOD_ATTACHMENTS 1 | |
| 340 | +#if FORUMPOST_MOD_ATTACHMENTS | |
| 341 | +/* | |
| 342 | +** Internal helper for moderation_forumpost_...(). | |
| 343 | +*/ | |
| 344 | +static void forumpost_prep_pending_attachids(Stmt *q, int fpid){ | |
| 345 | + db_prepare( | |
| 346 | + q, | |
| 347 | + "SELECT attachid FROM attachment " | |
| 348 | + "WHERE target=(" | |
| 349 | + " SELECT uuid FROM blob WHERE rid=%d" | |
| 350 | + ") and attachid in (" | |
| 351 | + " SELECT objid FROM modreq" | |
| 352 | + ")", | |
| 353 | + forumpost_head_rid(fpid) | |
| 354 | + ); | |
| 355 | +} | |
| 356 | +#endif | |
| 357 | + | |
| 358 | +/* | |
| 359 | +** Approve the given forum post RID and any pending-approval | |
| 360 | +** attachments associated with its initial version. | |
| 361 | +*/ | |
| 362 | +static void moderation_forumpost_approve(int fpid){ | |
| 363 | +#if !FORUMPOST_MOD_ATTACHMENTS | |
| 364 | + moderation_approve('f', fpid); | |
| 365 | +#else | |
| 366 | + /* Also approve any pending attachments */ | |
| 367 | + Stmt q; | |
| 368 | + moderation_approve('f', fpid); | |
| 369 | + forumpost_prep_pending_attachids(&q, fpid); | |
| 370 | + while( SQLITE_ROW==db_step(&q) ){ | |
| 371 | + moderation_approve('a', db_column_int(&q, 0)); | |
| 372 | + } | |
| 373 | + db_finalize(&q); | |
| 374 | +#endif | |
| 375 | +} | |
| 376 | + | |
| 377 | +/* | |
| 378 | +** Disapprove the given forum post and any pending-moderation | |
| 379 | +** attachments on its initial version. | |
| 380 | +*/ | |
| 381 | +static void moderation_forumpost_disapprove(int fpid){ | |
| 382 | +#if !FORUMPOST_MOD_ATTACHMENTS | |
| 383 | + moderation_disapprove(fpid); | |
| 384 | +#else | |
| 385 | + /* Also disapprove any pending attachments */ | |
| 386 | + Stmt q; | |
| 387 | + moderation_disapprove(fpid); | |
| 388 | + forumpost_prep_pending_attachids(&q, fpid); | |
| 389 | + while( SQLITE_ROW==db_step(&q) ){ | |
| 390 | + moderation_disapprove(db_column_int(&q, 0)); | |
| 391 | + } | |
| 392 | + db_finalize(&q); | |
| 393 | +#endif | |
| 394 | +} | |
| 395 | +#undef FORUMPOST_MOD_ATTACHMENTS | |
| 396 | + | |
| 397 | +/* | |
| 398 | +** Applies or cancels a tag named zTagName on the given forum RID via | |
| 399 | +** addition of a new control artifact into the repository. In order to | |
| 400 | +** provide consistent behavior, it always acts on the first version of | |
| 401 | +** the given forum post, walking the forumpost.fprev values to find | |
| 402 | +** the head of the chain. | |
| 403 | +** | |
| 404 | +** If addTag is true then a propagating tag is added, except as noted | |
| 405 | +** below, with the given optional zValue string as the tag's | |
| 406 | +** value. If addTag is false then any matching active tag on frid is | |
| 407 | +** cancelled, except as noted below. zValue is ignored if it is NULL | |
| 408 | +** or starts with a NUL byte, or if addTag is false. | |
| 409 | +** | |
| 410 | +** This function only adds a tag if forum_rid_is_tagged() indicates | |
| 411 | +** that frid's head is not tagged. If a parent post is already tagged, | |
| 412 | +** no tag is added. Similarly, it will only remove a tag from a post | |
| 413 | +** which has its own tag, and will not remove an inherited one from a | |
| 414 | +** parent post. | |
| 415 | +** | |
| 416 | +** If addTag is true and frid is already tagged, this is a | |
| 417 | +** no-op. Likewise, if addTag is false and frid is not tagged (not | |
| 418 | +** accounting for a tag inherited via an in-response-to post), this is | |
| 419 | +** a no-op. | |
| 420 | +** | |
| 421 | +** Returns a positive value (a new tag.tagid value) if it actually | |
| 422 | +** creates a new tag, else 0. On error it returns a negative alue | |
| 423 | +** and g.zErrMsg "should" contain details. | |
| 424 | +** | |
| 425 | +** If it returns true then state from previously-loaded posts may be | |
| 426 | +** invalidated if they refer to the amended post or a response to it. | |
| 427 | +** e.g. if zTagName is "closed" then ForumPost::iClosed values may be | |
| 428 | +** stale. | |
| 205 | 429 | ** |
| 206 | 430 | ** Sidebars: |
| 207 | 431 | ** |
| 208 | 432 | ** - Unless the caller has a transaction open, via |
| 209 | 433 | ** db_begin_transaction(), there is a very tiny race condition |
| 210 | 434 | ** window during which the caller's idea of whether or not the forum |
| 211 | -** post is closed may differ from the current repository state. | |
| 435 | +** post is tagged may differ from the current repository state. | |
| 212 | 436 | ** |
| 213 | 437 | ** - This routine assumes that frid really does refer to a forum post. |
| 214 | 438 | ** |
| 215 | 439 | ** - This routine assumes that frid is not private or pending |
| 216 | 440 | ** moderation. |
| 217 | 441 | ** |
| 218 | -** - Closure of a forum post requires a propagating "closed" tag to | |
| 442 | +** - The applied tag is propagating so so that "closed" tags can | |
| 219 | 443 | ** account for how edits of posts are handled. This differs from |
| 220 | 444 | ** closure of a branch, where a non-propagating tag is used. |
| 221 | 445 | */ |
| 222 | -static int forumpost_close(int frid, int doClose, const char *zReason){ | |
| 446 | +static int forumpost_tag(int frid, int addTag, | |
| 447 | + const char *zTagName, | |
| 448 | + const char *zValue){ | |
| 223 | 449 | Blob artifact = BLOB_INITIALIZER; /* Output artifact */ |
| 224 | 450 | Blob cksum = BLOB_INITIALIZER; /* Z-card */ |
| 225 | - int iClosed; /* true if frid is closed */ | |
| 451 | + int iTagged; /* true if frid is already tagged */ | |
| 226 | 452 | int trid; /* RID of new control artifact */ |
| 227 | 453 | char *zUuid; /* UUID of head version of post */ |
| 228 | 454 | |
| 229 | 455 | db_begin_transaction(); |
| 230 | 456 | frid = forumpost_head_rid(frid); |
| 231 | - iClosed = forum_rid_is_closed(frid, 1); | |
| 232 | - if( (iClosed && doClose | |
| 233 | - /* Already closed, noting that in the case of (iClosed<0), it's | |
| 234 | - ** actually a parent which is closed. */) | |
| 235 | - || (iClosed<=0 && !doClose | |
| 236 | - /* This entry is not closed, but a parent post may be. */) ){ | |
| 457 | + iTagged = forum_rid_is_tagged(frid, zTagName, 0); | |
| 458 | + if( !addTag && !iTagged ){ | |
| 459 | + /* Nothing to do. We never tag an IRT-inherited post via this | |
| 460 | + ** function. */ | |
| 237 | 461 | db_end_transaction(0); |
| 238 | 462 | return 0; |
| 239 | 463 | } |
| 240 | - if( doClose==0 || (zReason && !zReason[0]) ){ | |
| 241 | - zReason = 0; | |
| 464 | + if( !addTag || (zValue && !zValue[0]) ){ | |
| 465 | + zValue = 0; | |
| 466 | + } | |
| 467 | + if( addTag && iTagged ){ | |
| 468 | + char *zOld = 0; | |
| 469 | + int cmp; | |
| 470 | + rid_has_tag2(frid, zTagName, &zOld); | |
| 471 | + cmp = fossil_strcmp(zOld, zValue); | |
| 472 | + fossil_free(zOld); | |
| 473 | + if( 0==cmp ){ | |
| 474 | + /* Same value - leave it as is. */ | |
| 475 | + db_end_transaction(0); | |
| 476 | + return 0; | |
| 477 | + } | |
| 242 | 478 | } |
| 243 | 479 | zUuid = rid_to_uuid(frid); |
| 244 | 480 | blob_appendf(&artifact, "D %z\n", date_in_standard_format( "now" )); |
| 245 | - blob_appendf(&artifact, | |
| 246 | - "T %cclosed %s%s%F\n", | |
| 247 | - doClose ? '*' : '-', zUuid, | |
| 248 | - zReason ? " " : "", zReason ? zReason : ""); | |
| 481 | + blob_appendf(&artifact, "T %c%s %s%s%F\n", | |
| 482 | + addTag ? '*' : '-', zTagName, | |
| 483 | + zUuid, zValue ? " " : "", zValue ? zValue : ""); | |
| 249 | 484 | blob_appendf(&artifact, "U %F\n", login_name()); |
| 250 | 485 | md5sum_blob(&artifact, &cksum); |
| 251 | 486 | blob_appendf(&artifact, "Z %b\n", &cksum); |
| 252 | 487 | blob_reset(&cksum); |
| 253 | 488 | trid = content_put_ex(&artifact, 0, 0, 0, 0); |
| 254 | 489 | if( trid==0 ){ |
| 255 | - fossil_fatal("Error saving tag artifact: %s", g.zErrMsg); | |
| 490 | + return -1; | |
| 256 | 491 | } |
| 257 | - if( manifest_crosslink(trid, &artifact, | |
| 258 | - MC_NONE /*MC_PERMIT_HOOKS?*/)==0 ){ | |
| 259 | - fossil_fatal("%s", g.zErrMsg); | |
| 492 | + if( manifest_crosslink(trid, &artifact, MC_NONE)==0 ){ | |
| 493 | + return -2; | |
| 260 | 494 | } |
| 261 | 495 | assert( blob_is_reset(&artifact) ); |
| 262 | 496 | db_add_unsent(trid); |
| 263 | - admin_log("%s forum post %S", doClose ? "Close" : "Re-open", zUuid); | |
| 497 | + admin_log("Tag forum post %S with %c%s", | |
| 498 | + zUuid, addTag ? '*' : '-', zTagName); | |
| 264 | 499 | fossil_free(zUuid); |
| 265 | - /* Potential TODO: if (iClosed>0) then we could find the initial tag | |
| 266 | - ** artifact and content_deltify(thatRid,&trid,1,0). Given the tiny | |
| 267 | - ** size of these artifacts, however, that would save little space, | |
| 268 | - ** if any. */ | |
| 269 | 500 | db_end_transaction(0); |
| 270 | - return 1; | |
| 501 | + return trid; | |
| 502 | +} | |
| 503 | + | |
| 504 | +/* | |
| 505 | +** COMMAND: test-forumpost-tag | |
| 506 | +** | |
| 507 | +** Usage: %fossil test-forumpost-tag ?-cancel? THREADID TAGNAME TAGVAL | |
| 508 | +** | |
| 509 | +** A tester for forumpost_tag(). It always rolls back changes. | |
| 510 | +*/ | |
| 511 | +void test_forumpost_tag_command(void){ | |
| 512 | + int fpid; | |
| 513 | + int rc; | |
| 514 | + const char *zPost; | |
| 515 | + const char *zTag; | |
| 516 | + const char *zVal; | |
| 517 | + const int bAdd = find_option("cancel","",0)==0; | |
| 518 | + | |
| 519 | + db_find_and_open_repository(0,0); | |
| 520 | + verify_all_options(); | |
| 521 | + if( g.argc<5 ){ | |
| 522 | + usage("forum-post-id tag-name value"); | |
| 523 | + } | |
| 524 | + zPost = g.argv[2]; | |
| 525 | + zTag = g.argv[3]; | |
| 526 | + zVal = g.argv[4]; | |
| 527 | + | |
| 528 | + db_begin_transaction(); | |
| 529 | + fpid = forumpost_head_rid2(zPost); | |
| 530 | + if( fpid<=0 ){ | |
| 531 | + fossil_fatal("Cannot resolve post ID %s", zPost); | |
| 532 | + } | |
| 533 | + fossil_print("%s => %d => %z\n", zTag, fpid, | |
| 534 | + rid_to_uuid(fpid)); | |
| 535 | + rc = forumpost_tag(fpid, bAdd, zTag, zVal); | |
| 536 | + fossil_print("tag fpid=%d taxgxref.tagid=%d\n", fpid, rc); | |
| 537 | + db_end_transaction(1); | |
| 271 | 538 | } |
| 272 | 539 | |
| 273 | 540 | /* |
| 274 | 541 | ** Returns true if the forum-close-policy setting is true, else false, |
| 275 | 542 | ** caching the result for subsequent calls. |
| @@ -285,12 +552,15 @@ | ||
| 285 | 552 | |
| 286 | 553 | /* |
| 287 | 554 | ** Returns 1 if the current user is an admin, -1 if the current user |
| 288 | 555 | ** is a forum moderator and the forum-close-policy setting is true, |
| 289 | 556 | ** else returns 0. The value is cached for subsequent calls. |
| 557 | +** | |
| 558 | +** This policy also determines whether non-admin forum moderators | |
| 559 | +** may delete forum attachments. | |
| 290 | 560 | */ |
| 291 | -static int forumpost_may_close(void){ | |
| 561 | +int forumpost_may_close(void){ | |
| 292 | 562 | static int permClose = -99; |
| 293 | 563 | if( permClose!=-99 ){ |
| 294 | 564 | return permClose; |
| 295 | 565 | }else if( g.perm.Admin ){ |
| 296 | 566 | return permClose = 1; |
| @@ -445,13 +715,13 @@ | ||
| 445 | 715 | for(; p; p=p->pEditPrev ){ |
| 446 | 716 | p->nEdit = pPost->nEdit; |
| 447 | 717 | p->pEditTail = pPost; |
| 448 | 718 | } |
| 449 | 719 | } |
| 450 | - pPost->iClosed = forum_rid_is_closed(pPost->pEditHead | |
| 720 | + pPost->iClosed = forum_rid_is_tagged(pPost->pEditHead | |
| 451 | 721 | ? pPost->pEditHead->fpid |
| 452 | - : pPost->fpid, 1); | |
| 722 | + : pPost->fpid, "closed", 1); | |
| 453 | 723 | } |
| 454 | 724 | db_finalize(&q); |
| 455 | 725 | |
| 456 | 726 | if( computeHierarchy ){ |
| 457 | 727 | /* Compute the hierarchical display order */ |
| @@ -629,10 +899,80 @@ | ||
| 629 | 899 | } |
| 630 | 900 | @ </table> |
| 631 | 901 | db_finalize(&q); |
| 632 | 902 | style_finish_page(); |
| 633 | 903 | } |
| 904 | + | |
| 905 | +/* | |
| 906 | +** Returns true if the current user is authorized to set forum post | |
| 907 | +** fpid's status. | |
| 908 | +*/ | |
| 909 | +static int forum_may_set_status(int fpid){ | |
| 910 | + if( moderation_pending(fpid) ) return 0; | |
| 911 | + return g.perm.Admin | |
| 912 | + || g.perm.ModForum | |
| 913 | + || (login_is_individual() | |
| 914 | + && forumpost_is_owner(fpid, 0)); | |
| 915 | +} | |
| 916 | + | |
| 917 | +/* | |
| 918 | +** If the current user is authorized to set fp's status then this | |
| 919 | +** renders a mini-form for setting the status then redirecting back to | |
| 920 | +** the post. Else it may emit a status label or no output. | |
| 921 | +*/ | |
| 922 | +static void forum_render_status_selection( const ForumPost *fp ){ | |
| 923 | + const ForumStatusList * const fss = forum_statuses(); | |
| 924 | + if( fss->n>1 ){ | |
| 925 | + const ForumPost * pHead = fp->pEditHead ? fp->pEditHead : fp; | |
| 926 | + int i; | |
| 927 | + char * zCurrent = 0; | |
| 928 | + const ForumStatus * sCurrent = 0; | |
| 929 | + rid_has_tag2(pHead->fpid, "status", &zCurrent); | |
| 930 | + for( i = 0; i < fss->n; ++i ){ | |
| 931 | + const ForumStatus * const fs = &fss->aStatus[i]; | |
| 932 | + if( 0==fossil_strcmp(zCurrent, fs->zValue) ){ | |
| 933 | + sCurrent = fs; | |
| 934 | + break; | |
| 935 | + } | |
| 936 | + } | |
| 937 | + if( !sCurrent ) sCurrent = &fss->aStatus[0]; | |
| 938 | + assert( sCurrent ); | |
| 939 | + @ <fieldset class='forum-status-selection'>\ | |
| 940 | + @ <legend>Status \ | |
| 941 | + @ <span class='help-buttonlet initially-hidden'>\ | |
| 942 | + @ Moderators and the post's owner may change \ | |
| 943 | + @ the status of this thread unless it is still. \ | |
| 944 | + @ pending moderation. See \ | |
| 945 | + @ <a href='%R/help/forum-statuses' target='_new'>\ | |
| 946 | + @ /help/forum-statuses</a></span>\ | |
| 947 | + @ </legend>\ | |
| 948 | + if( forum_may_set_status(fp->fpid) ){ | |
| 949 | + @ <form method="post" action='%R/forumpost_status'> | |
| 950 | + login_insert_csrf_secret(); | |
| 951 | + @ <input type='hidden' name='fpid' value='%s(fp->zUuid)' /> | |
| 952 | + @ <select name='status' data-fpid='%s(fp->zUuid)'\ | |
| 953 | + @ data-initial-value='%h(zCurrent ? zCurrent : "")'> | |
| 954 | + for( i = 0; i < fss->n; ++i ){ | |
| 955 | + const ForumStatus * const fs = &fss->aStatus[i]; | |
| 956 | + @ <option value='%h(fs->zValue)'\ | |
| 957 | + @ %s(sCurrent==fs ? " selected" : "")>\ | |
| 958 | + @ %h(fs->zLabel)</option> | |
| 959 | + } | |
| 960 | + @ </select> | |
| 961 | + @ <input type='button' class='submit action-status' disabled | |
| 962 | + @ value='Change' /> | |
| 963 | + /* ^^^ This must be <input>, not <button>, or else tapping it | |
| 964 | + ** will unconditionally submit. */ | |
| 965 | + @ </form> | |
| 966 | + /* Form is activated in fossil.page.forumpost.js */ | |
| 967 | + }else{ | |
| 968 | + @ <button disabled>Status: %h(sCurrent->zLabel)</button> | |
| 969 | + } | |
| 970 | + @ </fieldset> | |
| 971 | + fossil_free(zCurrent); | |
| 972 | + } | |
| 973 | +} | |
| 634 | 974 | |
| 635 | 975 | /* |
| 636 | 976 | ** Render a forum post for display |
| 637 | 977 | */ |
| 638 | 978 | void forum_render( |
| @@ -760,22 +1100,55 @@ | ||
| 760 | 1100 | if( pToFree ) manifest_destroy(pToFree); |
| 761 | 1101 | if( p->zDisplayName==0 ) return "(unknown)"; |
| 762 | 1102 | return p->zDisplayName; |
| 763 | 1103 | } |
| 764 | 1104 | |
| 1105 | +/* | |
| 1106 | +** Renders the attachment list for the given forum post. | |
| 1107 | +** Emits no output if there are no attachments. | |
| 1108 | +*/ | |
| 1109 | +static void forum_render_attachment_list(const char *zUuid){ | |
| 1110 | +#if 1 | |
| 1111 | + attachment_list(zUuid, "📎 Attachments", 0 | |
| 1112 | + | ATTACHLIST_SIZE | |
| 1113 | + | ATTACHLIST_HIDE_UNAPPROVED | |
| 1114 | + | ATTACHLIST_DETAILS_CLOSED | |
| 1115 | + | ATTACHLIST_HIDE_EMPTY); | |
| 1116 | +#else | |
| 1117 | + char * zLbl = mprintf("<a href='%R/attachlist?forumpost=%!S'>" | |
| 1118 | + "Attachments</a>:", zUuid); | |
| 1119 | + attachment_list(zUuid, zLbl, | |
| 1120 | + ATTACHLIST_HRULE_ABOVE | |
| 1121 | + | ATTACHLIST_SIZE | |
| 1122 | + | ATTACHLIST_HIDE_UNAPPROVED | |
| 1123 | + | ATTACHLIST_HIDE_EMPTY); | |
| 1124 | + fossil_free(zLbl); | |
| 1125 | +#endif | |
| 1126 | +} | |
| 1127 | + | |
| 1128 | +/* | |
| 1129 | +** Renders the attachment list for p or (if not NULL) pEditHead. | |
| 1130 | +*/ | |
| 1131 | +static void forum_render_attachment_list2(ForumPost *p){ | |
| 1132 | + if( p->pEditHead ) p = p->pEditHead; | |
| 1133 | + forum_render_attachment_list(p->zUuid); | |
| 1134 | +} | |
| 1135 | + | |
| 1136 | +/* Flags for use with forum_display_post() */ | |
| 1137 | +#define FDISPLAY_RAW 0x01 /* omit the border */ | |
| 1138 | +#define FDISPLAY_UNFORMATTED 0x02 /* leave the post unformatted */ | |
| 1139 | +#define FDISPLAY_HISTORY 0x04 /* Showing edit history */ | |
| 1140 | +#define FDISPLAY_SELECTED 0x08 /* This is the selected post */ | |
| 765 | 1141 | |
| 766 | 1142 | /* |
| 767 | 1143 | ** Display a single post in a forum thread. |
| 768 | 1144 | */ |
| 769 | 1145 | static void forum_display_post( |
| 770 | 1146 | ForumThread *pThread, /* The thread that this post is a member of */ |
| 771 | 1147 | ForumPost *p, /* Forum post to display */ |
| 772 | 1148 | int iIndentScale, /* Indent scale factor */ |
| 773 | - int bRaw, /* True to omit the border */ | |
| 774 | - int bUnf, /* True to leave the post unformatted */ | |
| 775 | - int bHist, /* True if showing edit history */ | |
| 776 | - int bSelect, /* True if this is the selected post */ | |
| 1149 | + int flags, /* From the FDISPLAY_... enum */ | |
| 777 | 1150 | char *zQuery /* Common query string */ |
| 778 | 1151 | ){ |
| 779 | 1152 | char *zPosterName; /* Name of user who originally made this post */ |
| 780 | 1153 | char *zEditorName; /* Name of user who provided the current edit */ |
| 781 | 1154 | char *zDate; /* The time/date string */ |
| @@ -784,30 +1157,43 @@ | ||
| 784 | 1157 | Manifest *pManifest; /* Manifest comprising the current post */ |
| 785 | 1158 | int bPrivate; /* True for posts awaiting moderation */ |
| 786 | 1159 | int bSameUser; /* True if author is also the reader */ |
| 787 | 1160 | int iIndent; /* Indent level */ |
| 788 | 1161 | int iClosed; /* True if (sub)thread is closed */ |
| 1162 | + const int bRaw = flags & FDISPLAY_RAW; | |
| 1163 | + const int bUnf = flags & FDISPLAY_UNFORMATTED; | |
| 1164 | + const int bHist = flags & FDISPLAY_HISTORY; | |
| 1165 | + const int bSelect = flags & FDISPLAY_SELECTED; | |
| 789 | 1166 | const char *zMimetype;/* Formatting MIME type */ |
| 790 | 1167 | |
| 791 | 1168 | /* Get the manifest for the post. Abort if not found (e.g. shunned). */ |
| 792 | 1169 | pManifest = manifest_get(p->fpid, CFTYPE_FORUM, 0); |
| 793 | 1170 | if( !pManifest ) return; |
| 794 | 1171 | iClosed = forumpost_is_closed(pThread, p, 1); |
| 1172 | + bPrivate = content_is_private(p->fpid); | |
| 1173 | + bSameUser = login_is_individual() | |
| 1174 | + && fossil_strcmp(pManifest->zUser, g.zLogin)==0; | |
| 795 | 1175 | /* When not in raw mode, create the border around the post. */ |
| 796 | 1176 | if( !bRaw ){ |
| 797 | 1177 | /* Open the <div> enclosing the post. Set the class string to mark the post |
| 798 | 1178 | ** as selected and/or obsolete. */ |
| 799 | 1179 | iIndent = (p->pEditHead ? p->pEditHead->nIndent : p->nIndent)-1; |
| 800 | - @ <div id='forum%d(p->fpid)' class='forumTime\ | |
| 1180 | + @ <div id='forum%d(p->fpid)' class='forumpost forumTime\ | |
| 801 | 1181 | @ %s(bSelect ? " forumSel" : "")\ |
| 802 | 1182 | @ %s(iClosed ? " forumClosed" : "")\ |
| 803 | 1183 | @ %s(p->pEditTail ? " forumObs" : "")' \ |
| 804 | 1184 | if( iIndent && iIndentScale ){ |
| 805 | - @ style='margin-left:%d(iIndent*iIndentScale)ex;'> | |
| 806 | - }else{ | |
| 807 | - @ > | |
| 1185 | + @ style='margin-left:%d(iIndent*iIndentScale)ex;' \ | |
| 1186 | + } | |
| 1187 | + /* These data-X fields are used by the JS editor. */ | |
| 1188 | + if( p->pIrt ){ | |
| 1189 | + @ data-firt="%s(p->pIrt->zUuid)" \ | |
| 1190 | + } | |
| 1191 | + if( p->pEditHead ){ | |
| 1192 | + @ data-fedithead="%s(p->pEditHead->zUuid)" \ | |
| 808 | 1193 | } |
| 1194 | + @ data-fpid="%s(p->zUuid)">\ | |
| 809 | 1195 | |
| 810 | 1196 | /* If this is the first post (or an edit thereof), emit the thread title. */ |
| 811 | 1197 | if( pManifest->zThreadTitle ){ |
| 812 | 1198 | @ <h1>%h(pManifest->zThreadTitle)</h1> |
| 813 | 1199 | } |
| @@ -888,18 +1274,18 @@ | ||
| 888 | 1274 | /* Provide a link to the raw source code. */ |
| 889 | 1275 | if( !bUnf ){ |
| 890 | 1276 | @ %z(href("%R/forumpost/%!S?raw",p->zUuid))[source]</a> |
| 891 | 1277 | } |
| 892 | 1278 | @ </h3> |
| 893 | - } | |
| 894 | - | |
| 895 | - /* Check if this post is approved, also if it's by the current user. */ | |
| 896 | - bPrivate = content_is_private(p->fpid); | |
| 897 | - bSameUser = login_is_individual() | |
| 898 | - && fossil_strcmp(pManifest->zUser, g.zLogin)==0; | |
| 899 | - | |
| 900 | - /* Render the post if the user is able to see it. */ | |
| 1279 | + | |
| 1280 | + if( bPrivate && (bSameUser || g.perm.Admin || g.perm.ModForum) ){ | |
| 1281 | + moderation_pending_www(p->fpid); | |
| 1282 | + } | |
| 1283 | + }/*!bRaw*/ | |
| 1284 | + | |
| 1285 | + /* Check if this post is approved, also if it's by the current user. | |
| 1286 | + Render the post if the user is able to see it. */ | |
| 901 | 1287 | if( bPrivate && !g.perm.ModForum && !bSameUser ){ |
| 902 | 1288 | @ <p><span class="modpending">Awaiting Moderator Approval</span></p> |
| 903 | 1289 | }else{ |
| 904 | 1290 | if( bRaw || bUnf || p->pEditTail ){ |
| 905 | 1291 | zMimetype = "text/plain"; |
| @@ -909,10 +1295,12 @@ | ||
| 909 | 1295 | forum_render(0, zMimetype, pManifest->zWiki, 0, !bRaw); |
| 910 | 1296 | } |
| 911 | 1297 | |
| 912 | 1298 | /* When not in raw mode, finish creating the border around the post. */ |
| 913 | 1299 | if( !bRaw ){ |
| 1300 | + int bBrBeforeAttach = 0; /* Layout kludge for Attach button */ | |
| 1301 | + forum_render_attachment_list2(p); | |
| 914 | 1302 | /* If the user is able to write to the forum and if this post has not been |
| 915 | 1303 | ** edited, create a form with various interaction buttons. */ |
| 916 | 1304 | if( g.perm.WrForum && !p->pEditTail ){ |
| 917 | 1305 | @ <div class="forumpost-single-controls">\ |
| 918 | 1306 | @ <form action="%R/forumedit" method="POST"> |
| @@ -941,33 +1329,52 @@ | ||
| 941 | 1329 | @ <br><label><input type="checkbox" name="trust"> |
| 942 | 1330 | @ Trust user "%h(pManifest->zUser)" so that future posts by \ |
| 943 | 1331 | @ "%h(pManifest->zUser)" do not require moderation. |
| 944 | 1332 | @ </label> |
| 945 | 1333 | @ <input type="hidden" name="trustuser" value="%h(pManifest->zUser)"> |
| 1334 | + bBrBeforeAttach = 1 /* slightly unmangle the layout */; | |
| 946 | 1335 | } |
| 947 | 1336 | }else if( bSameUser ){ |
| 948 | 1337 | /* Allow users to delete (reject) their own pending posts. */ |
| 949 | 1338 | @ <input type="submit" name="reject" value="Delete"> |
| 950 | 1339 | } |
| 951 | 1340 | login_insert_csrf_secret(); |
| 952 | 1341 | @ </form> |
| 953 | - if( bSelect && forumpost_may_close() && iClosed>=0 ){ | |
| 954 | - int iHead = forumpost_head_rid(p->fpid); | |
| 955 | - @ <form method="post" \ | |
| 956 | - @ action='%R/forumpost_%s(iClosed > 0 ? "reopen" : "close")'> | |
| 957 | - login_insert_csrf_secret(); | |
| 958 | - @ <input type="hidden" name="fpid" value="%z(rid_to_uuid(iHead))" /> | |
| 959 | - if( moderation_pending(p->fpid)==0 ){ | |
| 960 | - @ <input type="button" value='%s(iClosed ? "Re-open" : "Close")' \ | |
| 961 | - @ class='%s(iClosed ? "action-reopen" : "action-close")'/> | |
| 962 | - } | |
| 963 | - @ </form> | |
| 1342 | + | |
| 1343 | + if( bSelect ){ | |
| 1344 | + const ForumPost *pHead = p->pEditHead ? p->pEditHead : p; | |
| 1345 | + if( !bPrivate && forumpost_may_close() && iClosed>=0 ){ | |
| 1346 | + @ <form method="post" \ | |
| 1347 | + @ action='%R/forumpost_%s(iClosed > 0 ? "reopen" : "close")'> | |
| 1348 | + login_insert_csrf_secret(); | |
| 1349 | + @ <input type="hidden" name="fpid" value="%s(p->zUuid)" /> | |
| 1350 | + if( moderation_pending(p->fpid)==0 ){ | |
| 1351 | + @ <input type="button" value='%s(iClosed ? "Re-open" : "Close")' \ | |
| 1352 | + @ class='submit hidden \ | |
| 1353 | + @ %s(iClosed ? "action-reopen" : "action-close")'/> | |
| 1354 | + /* ^^^ activated by fossil.page.forumpost.js */ | |
| 1355 | + } | |
| 1356 | + @ </form> | |
| 1357 | + } | |
| 1358 | + if( attach_user_may(p/*not pHead*/->fpid, CFTYPE_FORUM) ){ | |
| 1359 | + /* When an admin edits someone else's post, the admin | |
| 1360 | + ** effectively takes over ownership of it (and we currently | |
| 1361 | + ** have no way of passing it back). Because of this, we | |
| 1362 | + ** check the ownership of `p` instead of `pHead`. */ | |
| 1363 | + if( bBrBeforeAttach ){ | |
| 1364 | + @ <br> | |
| 1365 | + } | |
| 1366 | + attach_render_attachadd_button(pHead->zUuid); | |
| 1367 | + } | |
| 964 | 1368 | } |
| 965 | 1369 | @ </div> |
| 966 | 1370 | } |
| 1371 | + if( !p->pIrt && (flags & FDISPLAY_SELECTED)){ | |
| 1372 | + forum_render_status_selection(p); | |
| 1373 | + } | |
| 967 | 1374 | @ </div> |
| 968 | - } | |
| 1375 | + }/*!bRaw*/ | |
| 969 | 1376 | |
| 970 | 1377 | /* Clean up. */ |
| 971 | 1378 | manifest_destroy(pManifest); |
| 972 | 1379 | } |
| 973 | 1380 | |
| @@ -1077,12 +1484,18 @@ | ||
| 1077 | 1484 | } |
| 1078 | 1485 | |
| 1079 | 1486 | /* Display the appropriate subset of posts in sequence. */ |
| 1080 | 1487 | while( p ){ |
| 1081 | 1488 | /* Display the post. */ |
| 1082 | - forum_display_post(pThread, p, iIndentScale, mode==FD_RAW, | |
| 1083 | - bUnf, bHist, p==pSelect, zQuery); | |
| 1489 | + forum_display_post( | |
| 1490 | + pThread, p, iIndentScale, | |
| 1491 | + (mode==FD_RAW ? FDISPLAY_RAW : 0) | | |
| 1492 | + (bUnf ? FDISPLAY_UNFORMATTED : 0) | | |
| 1493 | + (bHist ? FDISPLAY_HISTORY : 0) | | |
| 1494 | + (p==pSelect ? FDISPLAY_SELECTED : 0), | |
| 1495 | + zQuery | |
| 1496 | + ); | |
| 1084 | 1497 | |
| 1085 | 1498 | /* Advance to the next post in the thread. */ |
| 1086 | 1499 | if( mode==FD_CHRONO ){ |
| 1087 | 1500 | /* Chronological mode: display posts (optionally including edits) in their |
| 1088 | 1501 | ** original commit order. */ |
| @@ -1138,11 +1551,12 @@ | ||
| 1138 | 1551 | ** to all forum-related pages. It does not include page-specific |
| 1139 | 1552 | ** code (e.g. "forum.js"). |
| 1140 | 1553 | */ |
| 1141 | 1554 | static void forum_emit_js(void){ |
| 1142 | 1555 | builtin_fossil_js_bundle_or("copybutton", "pikchr", "confirmer", |
| 1143 | - NULL); | |
| 1556 | + "attach", "tabs", "storage", | |
| 1557 | + "popupwidget", NULL); | |
| 1144 | 1558 | builtin_request_js("fossil.page.forumpost.js"); |
| 1145 | 1559 | } |
| 1146 | 1560 | |
| 1147 | 1561 | /* |
| 1148 | 1562 | ** WEBPAGE: forumpost |
| @@ -1291,28 +1705,20 @@ | ||
| 1291 | 1705 | } |
| 1292 | 1706 | |
| 1293 | 1707 | /* |
| 1294 | 1708 | ** Return true if a forum post should be moderated. |
| 1295 | 1709 | */ |
| 1296 | -static int forum_need_moderation(void){ | |
| 1710 | +int forum_need_moderation(void){ | |
| 1297 | 1711 | if( P("domod") ) return 1; |
| 1298 | 1712 | if( g.perm.WrTForum ) return 0; |
| 1299 | 1713 | if( g.perm.ModForum ) return 0; |
| 1300 | 1714 | return 1; |
| 1301 | 1715 | } |
| 1302 | 1716 | |
| 1303 | -/* | |
| 1304 | -** Return true if the string is white-space only. | |
| 1305 | -*/ | |
| 1306 | -static int whitespace_only(const char *z){ | |
| 1307 | - if( z==0 ) return 1; | |
| 1308 | - while( z[0] && fossil_isspace(z[0]) ){ z++; } | |
| 1309 | - return z[0]==0; | |
| 1310 | -} | |
| 1311 | - | |
| 1312 | 1717 | /* Flags for use with forum_post() */ |
| 1313 | 1718 | #define FPOST_NO_ALERT 1 /* do not send any alerts */ |
| 1719 | +#define FPOST_DRYRUN 2 /* do not save the artifact */ | |
| 1314 | 1720 | |
| 1315 | 1721 | /* |
| 1316 | 1722 | ** Return a flags value for use with the final argument to |
| 1317 | 1723 | ** forum_post(), extracted from the CGI environment. |
| 1318 | 1724 | */ |
| @@ -1319,10 +1725,13 @@ | ||
| 1319 | 1725 | static int forum_post_flags(void){ |
| 1320 | 1726 | int iPostFlags = 0; |
| 1321 | 1727 | if( g.perm.Debug && P("fpsilent")!=0 ){ |
| 1322 | 1728 | iPostFlags |= FPOST_NO_ALERT; |
| 1323 | 1729 | } |
| 1730 | + if( P("dryrun")!=0 ){ | |
| 1731 | + iPostFlags |= FPOST_DRYRUN; | |
| 1732 | + } | |
| 1324 | 1733 | return iPostFlags; |
| 1325 | 1734 | } |
| 1326 | 1735 | |
| 1327 | 1736 | /* |
| 1328 | 1737 | ** Add a new Forum Post artifact to the repository. |
| @@ -1346,15 +1755,15 @@ | ||
| 1346 | 1755 | Manifest *pPost; |
| 1347 | 1756 | int nContent = zContent ? (int)strlen(zContent) : 0; |
| 1348 | 1757 | |
| 1349 | 1758 | schema_forum(); |
| 1350 | 1759 | if( !g.perm.Admin && (iEdit || iInReplyTo) |
| 1351 | - && forum_rid_is_closed(iEdit ? iEdit : iInReplyTo, 1) ){ | |
| 1760 | + && forum_rid_is_tagged(iEdit ? iEdit : iInReplyTo, "closed", 1) ){ | |
| 1352 | 1761 | forumpost_error_closed(); |
| 1353 | 1762 | return 0; |
| 1354 | 1763 | } |
| 1355 | - if( iEdit==0 && whitespace_only(zContent) ){ | |
| 1764 | + if( iEdit==0 && fossil_all_whitespace(zContent) ){ | |
| 1356 | 1765 | return 0; |
| 1357 | 1766 | } |
| 1358 | 1767 | if( iInReplyTo==0 && iEdit>0 ){ |
| 1359 | 1768 | iBasis = iEdit; |
| 1360 | 1769 | iInReplyTo = db_int(0, "SELECT firt FROM forumpost WHERE fpid=%d", iEdit); |
| @@ -1375,17 +1784,19 @@ | ||
| 1375 | 1784 | fossil_free(zG); |
| 1376 | 1785 | } |
| 1377 | 1786 | if( zTitle ){ |
| 1378 | 1787 | blob_appendf(&x, "H %F\n", zTitle); |
| 1379 | 1788 | } |
| 1380 | - zI = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", iInReplyTo); | |
| 1789 | + zI = rid_to_uuid(iInReplyTo); | |
| 1381 | 1790 | if( zI ){ |
| 1382 | 1791 | blob_appendf(&x, "I %s\n", zI); |
| 1383 | 1792 | fossil_free(zI); |
| 1384 | 1793 | } |
| 1385 | - if( fossil_strcmp(zMimetype,"text/x-fossil-wiki")!=0 ){ | |
| 1386 | - blob_appendf(&x, "N %s\n", zMimetype); | |
| 1794 | + if( zMimetype!=0 | |
| 1795 | + && zMimetype[0]!=0 | |
| 1796 | + && fossil_strcmp(zMimetype,"text/x-fossil-wiki")!=0 ){ | |
| 1797 | + blob_appendf(&x, "N %F\n", zMimetype); | |
| 1387 | 1798 | } |
| 1388 | 1799 | if( iEdit>0 ){ |
| 1389 | 1800 | char *zP = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", iEdit); |
| 1390 | 1801 | if( zP==0 ) webpage_error("missing edit artifact %d", iEdit); |
| 1391 | 1802 | blob_appendf(&x, "P %s\n", zP); |
| @@ -1413,11 +1824,11 @@ | ||
| 1413 | 1824 | webpage_error("malformed forum post artifact - %s", blob_str(&errMsg)); |
| 1414 | 1825 | } |
| 1415 | 1826 | webpage_assert( pPost->type==CFTYPE_FORUM ); |
| 1416 | 1827 | manifest_destroy(pPost); |
| 1417 | 1828 | |
| 1418 | - if( P("dryrun") ){ | |
| 1829 | + if( (iFlags & FPOST_DRYRUN)!=0 ){ | |
| 1419 | 1830 | @ <div class='debug'> |
| 1420 | 1831 | @ This is the artifact that would have been generated: |
| 1421 | 1832 | @ <pre>%h(blob_str(&x))</pre> |
| 1422 | 1833 | @ </div> |
| 1423 | 1834 | blob_reset(&x); |
| @@ -1452,44 +1863,87 @@ | ||
| 1452 | 1863 | mimetype_option_menu(zMimetype, "mimetype"); |
| 1453 | 1864 | @ <div class="forum-editor-widget"> |
| 1454 | 1865 | @ <textarea aria-label="Content:" name="content" class="wikiedit" \ |
| 1455 | 1866 | @ cols="80" rows="25" wrap="virtual">%h(zContent)</textarea></div> |
| 1456 | 1867 | } |
| 1868 | + | |
| 1869 | +/* | |
| 1870 | +** If PD("fpid") refers to a forum post, its rid is returned, else | |
| 1871 | +** this function emits an error does not does return. | |
| 1872 | +*/ | |
| 1873 | +static int forum_validate_fpid_param(void){ | |
| 1874 | + const char *zFpid = PD("fpid",""); | |
| 1875 | + int fpid = symbolic_name_to_rid(zFpid, "f"); | |
| 1876 | + if( fpid<=0 ){ | |
| 1877 | + webpage_error("Missing or invalid fpid parameter."); | |
| 1878 | + } | |
| 1879 | + return fpid; | |
| 1880 | +} | |
| 1881 | + | |
| 1882 | +/* | |
| 1883 | +** Internal helper for /forumpost_XYZ internal pages which tag/untag | |
| 1884 | +** posts. | |
| 1885 | +*/ | |
| 1886 | +static void forumpost_action_helper(const char *zTag, const char *zVal, | |
| 1887 | + int addTag, int validFpid){ | |
| 1888 | + if( !cgi_csrf_safe(2) ){ | |
| 1889 | + webpage_error("CSRF validation failed"); | |
| 1890 | + }else{ | |
| 1891 | + const int fpid = validFpid>0 ? validFpid : forum_validate_fpid_param(); | |
| 1892 | + if( fpid>0 ){ | |
| 1893 | + if( forumpost_tag(fpid, addTag, zTag, zVal) < 0 ){ | |
| 1894 | + webpage_error("Tagging artifact failed: %s", g.zErrMsg); | |
| 1895 | + }else{ | |
| 1896 | + cgi_redirectf("%R/forumpost/%S",P("fpid")); | |
| 1897 | + } | |
| 1898 | + } | |
| 1899 | + } | |
| 1900 | +} | |
| 1457 | 1901 | |
| 1458 | 1902 | /* |
| 1459 | 1903 | ** WEBPAGE: forumpost_close hidden |
| 1460 | 1904 | ** WEBPAGE: forumpost_reopen hidden |
| 1461 | 1905 | ** |
| 1462 | 1906 | ** fpid=X Hash of the post to be edited. REQUIRED |
| 1463 | -** reason=X Optional reason for closure. | |
| 1464 | 1907 | ** |
| 1465 | 1908 | ** Closes or re-opens the given forum post, within the bounds of the |
| 1466 | -** API for forumpost_close(). After (perhaps) modifying the "closed" | |
| 1909 | +** API for forumpost_tag(). After (perhaps) modifying the "closed" | |
| 1467 | 1910 | ** status of the given thread, it redirects to that post's thread |
| 1468 | 1911 | ** view. Requires admin privileges. |
| 1469 | 1912 | */ |
| 1470 | 1913 | void forum_page_close(void){ |
| 1471 | - const char *zFpid = PD("fpid",""); | |
| 1472 | - const char *zReason = 0; | |
| 1473 | - int fClose; | |
| 1474 | - int fpid; | |
| 1475 | - | |
| 1476 | 1914 | login_check_credentials(); |
| 1477 | 1915 | if( forumpost_may_close()==0 ){ |
| 1478 | 1916 | login_needed(g.anon.Admin); |
| 1479 | - return; | |
| 1480 | - } | |
| 1481 | - cgi_csrf_verify(); | |
| 1482 | - fpid = symbolic_name_to_rid(zFpid, "f"); | |
| 1483 | - if( fpid<=0 ){ | |
| 1484 | - webpage_error("Missing or invalid fpid query parameter"); | |
| 1485 | - } | |
| 1486 | - fClose = sqlite3_strglob("*_close*", g.zPath)==0; | |
| 1487 | - if( fClose ) zReason = PD("reason",0); | |
| 1488 | - forumpost_close(fpid, fClose, zReason); | |
| 1489 | - cgi_redirectf("%R/forumpost/%S",zFpid); | |
| 1490 | - return; | |
| 1917 | + }else{ | |
| 1918 | + const int bIsAdd = sqlite3_strglob("*_close*", g.zPath)==0; | |
| 1919 | + forumpost_action_helper("closed", 0, bIsAdd, 0); | |
| 1920 | + } | |
| 1921 | +} | |
| 1922 | + | |
| 1923 | +/* | |
| 1924 | +** WEBPAGE: forumpost_status hidden | |
| 1925 | +** | |
| 1926 | +** fpid=X Hash of the post to be edited. REQUIRED | |
| 1927 | +** status=Y New status value. REQUIRED | |
| 1928 | +** | |
| 1929 | +** Updates the current status=Y tag on the first version of | |
| 1930 | +** the forum post X. Requires forum_may_set_status() permissions. | |
| 1931 | +*/ | |
| 1932 | +void forum_page_status(void){ | |
| 1933 | + int fpid; | |
| 1934 | + login_check_credentials(); | |
| 1935 | + fpid = forum_validate_fpid_param(); | |
| 1936 | + if(forum_may_set_status(fpid)){ | |
| 1937 | + const char *zStatus = PD("status",0); | |
| 1938 | + if( !zStatus || !zStatus[0] ){ | |
| 1939 | + webpage_error("Missing required status."); | |
| 1940 | + } | |
| 1941 | + forumpost_action_helper("status", zStatus, 1, fpid); | |
| 1942 | + }else{ | |
| 1943 | + webpage_error("You lack permissions to change this post's status."); | |
| 1944 | + } | |
| 1491 | 1945 | } |
| 1492 | 1946 | |
| 1493 | 1947 | /* |
| 1494 | 1948 | ** WEBPAGE: forumnew |
| 1495 | 1949 | ** WEBPAGE: forumedit |
| @@ -1578,11 +2032,25 @@ | ||
| 1578 | 2032 | @ </div> |
| 1579 | 2033 | } |
| 1580 | 2034 | } |
| 1581 | 2035 | |
| 1582 | 2036 | /* |
| 1583 | -** WEBPAGE: forume1 | |
| 2037 | +** If the user has AttachForum permissions, emit a notice that | |
| 2038 | +** attachments may be added after saving. If p is not NULL, also emit | |
| 2039 | +** its list of attachments. We only emit this for No-JS environments, | |
| 2040 | +** as in JS environments the interactive forum editor includes | |
| 2041 | +** attachment support. | |
| 2042 | +*/ | |
| 2043 | +static void forum_render_attachment_notice(void){ | |
| 2044 | + if( g.perm.AttachForum ){ | |
| 2045 | + @ <noscript><div>You will be able to attach files to this post | |
| 2046 | + @ after saving it.</div></noscript> | |
| 2047 | + } | |
| 2048 | +} | |
| 2049 | + | |
| 2050 | +/* | |
| 2051 | +** WEBPAGE: forume1 hidden | |
| 1584 | 2052 | ** |
| 1585 | 2053 | ** Start a new forum thread. |
| 1586 | 2054 | */ |
| 1587 | 2055 | void forumnew_page(void){ |
| 1588 | 2056 | const char *zTitle = PDT("title",""); |
| @@ -1596,35 +2064,45 @@ | ||
| 1596 | 2064 | } |
| 1597 | 2065 | if( P("submit") && cgi_csrf_safe(2) ){ |
| 1598 | 2066 | if( forum_post(zTitle, 0, 0, 0, zMimetype, zContent, |
| 1599 | 2067 | forum_post_flags()) ) return; |
| 1600 | 2068 | } |
| 1601 | - if( P("preview") && !whitespace_only(zContent) ){ | |
| 2069 | + if( P("preview") && !fossil_all_whitespace(zContent) ){ | |
| 1602 | 2070 | @ <h1>Preview:</h1> |
| 1603 | 2071 | forum_render(zTitle, zMimetype, zContent, "forumEdit", 1); |
| 1604 | 2072 | } |
| 1605 | 2073 | style_set_current_feature("forum"); |
| 1606 | 2074 | style_header("New Forum Thread"); |
| 1607 | - @ <form action="%R/forume1" method="POST"> | |
| 2075 | + | |
| 2076 | + @ <form action="%R/forume1" method="POST" \ | |
| 2077 | + @ class="remove-if-replaced"> | |
| 1608 | 2078 | @ <h1>New Thread:</h1> |
| 1609 | 2079 | forum_from_line(); |
| 1610 | 2080 | forum_post_widget(zTitle, zMimetype, zContent); |
| 1611 | 2081 | @ <input type="submit" name="preview" value="Preview"> |
| 1612 | - if( P("preview") && !whitespace_only(zContent) ){ | |
| 2082 | + if( P("preview") && !fossil_all_whitespace(zContent) ){ | |
| 1613 | 2083 | @ <input type="submit" name="submit" value="Submit"> |
| 1614 | 2084 | }else{ |
| 1615 | 2085 | @ <input type="submit" name="submit" value="Submit" disabled> |
| 1616 | 2086 | } |
| 1617 | 2087 | forum_render_debug_options(); |
| 1618 | 2088 | login_insert_csrf_secret(); |
| 1619 | 2089 | @ </form> |
| 2090 | + /* When JS is disabled the block above will work. When it's | |
| 2091 | + enabled, the above will be removed and JS will render the editor | |
| 2092 | + form in the next element. */ | |
| 2093 | + @ <div hidden id='forumnew-placeholder'> | |
| 2094 | + @ <input type='hidden' name='title' value='%h(zTitle)'> | |
| 2095 | + login_insert_csrf_secret(); | |
| 2096 | + @ </div> | |
| 2097 | + forum_render_attachment_notice(); | |
| 1620 | 2098 | forum_emit_js(); |
| 1621 | 2099 | style_finish_page(); |
| 1622 | 2100 | } |
| 1623 | 2101 | |
| 1624 | 2102 | /* |
| 1625 | -** WEBPAGE: forume2 | |
| 2103 | +** WEBPAGE: forume2 hidden | |
| 1626 | 2104 | ** |
| 1627 | 2105 | ** Edit an existing forum message. |
| 1628 | 2106 | ** Query parameters: |
| 1629 | 2107 | ** |
| 1630 | 2108 | ** fpid=X Hash of the post to be edited. REQUIRED |
| @@ -1655,28 +2133,30 @@ | ||
| 1655 | 2133 | fpid = symbolic_name_to_rid(zFpid, "f"); |
| 1656 | 2134 | if( fpid<=0 || (pPost = manifest_get(fpid, CFTYPE_FORUM, 0))==0 ){ |
| 1657 | 2135 | webpage_error("Missing or invalid fpid query parameter"); |
| 1658 | 2136 | } |
| 1659 | 2137 | froot = db_int(0, "SELECT froot FROM forumpost WHERE fpid=%d", fpid); |
| 1660 | - if( froot==0 || (pRootPost = manifest_get(froot, CFTYPE_FORUM, 0))==0 ){ | |
| 2138 | + if( (froot==0 || (pRootPost = manifest_get(froot, CFTYPE_FORUM, 0))==0) | |
| 2139 | + && P("reject")==0 | |
| 2140 | + ){ | |
| 1661 | 2141 | webpage_error("fpid does not appear to be a forum post: \"%d\"", fpid); |
| 1662 | 2142 | } |
| 1663 | 2143 | if( P("cancel") ){ |
| 1664 | 2144 | cgi_redirectf("%R/forumpost/%S",zFpid); |
| 1665 | 2145 | return; |
| 1666 | 2146 | } |
| 1667 | 2147 | bPreview = P("preview")!=0; |
| 1668 | 2148 | bReply = P("reply")!=0; |
| 1669 | - iClosed = forum_rid_is_closed(fpid, 1); | |
| 2149 | + iClosed = forum_rid_is_tagged(fpid, "closed", 1); | |
| 1670 | 2150 | isCsrfSafe = cgi_csrf_safe(2); |
| 1671 | 2151 | bPrivate = content_is_private(fpid); |
| 1672 | 2152 | bSameUser = login_is_individual() |
| 1673 | 2153 | && fossil_strcmp(pPost->zUser, g.zLogin)==0; |
| 1674 | 2154 | if( isCsrfSafe && (g.perm.ModForum || (bPrivate && bSameUser)) ){ |
| 1675 | 2155 | if( g.perm.ModForum && P("approve") ){ |
| 1676 | 2156 | const char *zUserToTrust; |
| 1677 | - moderation_approve('f', fpid); | |
| 2157 | + moderation_forumpost_approve(fpid); | |
| 1678 | 2158 | if( g.perm.AdminForum |
| 1679 | 2159 | && PB("trust") |
| 1680 | 2160 | && (zUserToTrust = P("trustuser"))!=0 |
| 1681 | 2161 | ){ |
| 1682 | 2162 | db_unprotect(PROTECT_USER); |
| @@ -1693,11 +2173,11 @@ | ||
| 1693 | 2173 | db_text(0, |
| 1694 | 2174 | "SELECT uuid FROM forumpost, blob" |
| 1695 | 2175 | " WHERE forumpost.fpid=%d AND blob.rid=forumpost.firt", |
| 1696 | 2176 | fpid |
| 1697 | 2177 | ); |
| 1698 | - moderation_disapprove(fpid); | |
| 2178 | + moderation_forumpost_disapprove(fpid); | |
| 1699 | 2179 | if( zParent ){ |
| 1700 | 2180 | cgi_redirectf("%R/forumpost/%S",zParent); |
| 1701 | 2181 | }else{ |
| 1702 | 2182 | cgi_redirectf("%R/forum"); |
| 1703 | 2183 | } |
| @@ -1707,11 +2187,11 @@ | ||
| 1707 | 2187 | style_set_current_feature("forum"); |
| 1708 | 2188 | isDelete = P("nullout")!=0; |
| 1709 | 2189 | if( P("submit") |
| 1710 | 2190 | && isCsrfSafe |
| 1711 | 2191 | && (zContent = PDT("content",""))!=0 |
| 1712 | - && (!whitespace_only(zContent) || isDelete) | |
| 2192 | + && (isDelete || !fossil_all_whitespace(zContent)) | |
| 1713 | 2193 | ){ |
| 1714 | 2194 | int done = 1; |
| 1715 | 2195 | const char *zMimetype = PD("mimetype",DEFAULT_FORUM_MIMETYPE); |
| 1716 | 2196 | if( bReply ){ |
| 1717 | 2197 | done = forum_post(0, fpid, 0, 0, zMimetype, zContent, |
| @@ -1785,11 +2265,11 @@ | ||
| 1785 | 2265 | zDisplayName = display_name_from_login(pPost->zUser); |
| 1786 | 2266 | @ <h3 class='forumPostHdr'>By %s(zDisplayName) on %h(zDate)</h3> |
| 1787 | 2267 | fossil_free(zDisplayName); |
| 1788 | 2268 | fossil_free(zDate); |
| 1789 | 2269 | forum_render(0, pPost->zMimetype, pPost->zWiki, "forumEdit", 1); |
| 1790 | - if( bPreview && !whitespace_only(zContent) ){ | |
| 2270 | + if( bPreview && !fossil_all_whitespace(zContent) ){ | |
| 1791 | 2271 | @ <h2>Preview:</h2> |
| 1792 | 2272 | forum_render(0, zMimetype,zContent, "forumEdit", 1); |
| 1793 | 2273 | } |
| 1794 | 2274 | @ <h2>Enter Reply:</h2> |
| 1795 | 2275 | @ <form action="%R/forume2" method="POST"> |
| @@ -1800,18 +2280,24 @@ | ||
| 1800 | 2280 | } |
| 1801 | 2281 | if( !isDelete ){ |
| 1802 | 2282 | @ <input type="submit" name="preview" value="Preview"> |
| 1803 | 2283 | } |
| 1804 | 2284 | @ <input type="submit" name="cancel" value="Cancel"> |
| 1805 | - if( (bPreview && !whitespace_only(zContent)) || isDelete ){ | |
| 2285 | + if( isDelete || (bPreview && !fossil_all_whitespace(zContent)) ){ | |
| 1806 | 2286 | if( !iClosed || g.perm.Admin ) { |
| 1807 | 2287 | @ <input type="submit" name="submit" value="Submit"> |
| 1808 | 2288 | } |
| 1809 | 2289 | } |
| 1810 | 2290 | forum_render_debug_options(); |
| 1811 | 2291 | login_insert_csrf_secret(); |
| 1812 | 2292 | @ </form> |
| 2293 | + if( !bReply ){ | |
| 2294 | + forum_render_attachment_list(rid_to_uuid(fpid)); | |
| 2295 | + } | |
| 2296 | + if( !isDelete ){ | |
| 2297 | + forum_render_attachment_notice(); | |
| 2298 | + } | |
| 1813 | 2299 | forum_emit_js(); |
| 1814 | 2300 | style_finish_page(); |
| 1815 | 2301 | } |
| 1816 | 2302 | |
| 1817 | 2303 | /* |
| @@ -1818,17 +2304,34 @@ | ||
| 1818 | 2304 | ** SETTING: forum-close-policy boolean default=off |
| 1819 | 2305 | ** If true, forum moderators may close/re-open forum posts, and reply |
| 1820 | 2306 | ** to closed posts. If false, only administrators may do so. Note that |
| 1821 | 2307 | ** this only affects the forum web UI, not post-closing tags which |
| 1822 | 2308 | ** arrive via the command-line or from synchronization with a remote. |
| 1823 | -*/ | |
| 1824 | -/* | |
| 2309 | +** This policy also determines whether moderators may delete forum | |
| 2310 | +** attachments. | |
| 2311 | +** | |
| 1825 | 2312 | ** SETTING: forum-title width=20 default=Forum |
| 1826 | 2313 | ** This is the name or "title" of the Forum for this repository. The |
| 1827 | 2314 | ** default is just "Forum". But in some setups, admins might want to |
| 1828 | 2315 | ** change it to "Developer Forum" or "User Forum" or whatever other name |
| 1829 | 2316 | ** seems more appropriate for the particular usage. |
| 2317 | +** | |
| 2318 | +** SETTING: attachment-size-limit width=16 | |
| 2319 | +** The maximum number of bytes for an attachment to a wiki page, | |
| 2320 | +** ticket, tech note, or forum post. The default (or 0) is unlimited | |
| 2321 | +** but a limit may be imposed by the web server or a proxy. | |
| 2322 | +** | |
| 2323 | +** SETTING: forum-statuses width=40 block-text | |
| 2324 | +** This JSON5-formatted value defines an array of objects describing | |
| 2325 | +** the available statuses of forum posts. Each entry of the array must | |
| 2326 | +** be an object in the form {label:"X",value:"Y"}. | |
| 2327 | +** The label is used in the UI and value becomes the value of the | |
| 2328 | +** "status" tag on forum posts. Any forum post which has a status | |
| 2329 | +** value which does not appear in this list is treated as if it had | |
| 2330 | +** the first value from this list. If this setting is empty, is | |
| 2331 | +** ill-formed JSON, or has only a single entry then the forum will | |
| 2332 | +** lack the capability of setting and filtering by status. | |
| 1830 | 2333 | */ |
| 1831 | 2334 | |
| 1832 | 2335 | /* |
| 1833 | 2336 | ** WEBPAGE: setup_forum |
| 1834 | 2337 | ** |
| @@ -1946,19 +2449,113 @@ | ||
| 1946 | 2449 | @ <a href='%R/help/%h(pSetting->name)'>%h(pSetting->name)</a>: |
| 1947 | 2450 | @ </td><td> |
| 1948 | 2451 | entry_attribute("", 25, pSetting->name, zQP/*works-like:""*/, |
| 1949 | 2452 | pSetting->def, 0); |
| 1950 | 2453 | @ </td></tr> |
| 1951 | - } | |
| 2454 | + } | |
| 1952 | 2455 | } |
| 1953 | 2456 | @ </tbody></table> |
| 1954 | 2457 | @ <input type='submit' name='submit' value='Apply changes'> |
| 1955 | 2458 | @ </form> |
| 1956 | 2459 | } |
| 1957 | 2460 | |
| 1958 | 2461 | style_finish_page(); |
| 1959 | 2462 | } |
| 2463 | + | |
| 2464 | +/* | |
| 2465 | +** If the forum-statuses setting is active and has 2 or more entries, | |
| 2466 | +** this adds a submenu for selecting the status filter, else it emits | |
| 2467 | +** nothing. | |
| 2468 | +*/ | |
| 2469 | +static void forum_status_submenu(void){ | |
| 2470 | + const ForumStatusList * const fss = forum_statuses(); | |
| 2471 | + static int i = 0; | |
| 2472 | + static const char **az; | |
| 2473 | + if( i==0 && fss->n>1 ){ | |
| 2474 | + unsigned j; | |
| 2475 | + az = fossil_malloc(sizeof(az[0]) * ((1 + fss->n) * 2)); | |
| 2476 | + az[i++] = "*"; | |
| 2477 | + az[i++] = "Any status"; | |
| 2478 | + for( j = 0; j < fss->n; ++j ){ | |
| 2479 | + const ForumStatus * fs = &fss->aStatus[j]; | |
| 2480 | + /* Potential TODO: skip any entries for which there are no | |
| 2481 | + ** forum posts with a status=${fs->zValue} tag. */ | |
| 2482 | + az[i++] = fs->zValue; | |
| 2483 | + az[i++] = fs->zLabel; | |
| 2484 | + } | |
| 2485 | + //assert( i==(1+fss->n)*2 ); | |
| 2486 | + } | |
| 2487 | + if( i ){ | |
| 2488 | + cookie_link_parameter("status","forumStatus","*"); | |
| 2489 | + style_submenu_multichoice("status", i/2, az, 0); | |
| 2490 | + } | |
| 2491 | +} | |
| 2492 | + | |
| 2493 | +/* | |
| 2494 | +** Transient SQL Function: status_match(FROOT) | |
| 2495 | +** | |
| 2496 | +** Return true if the forum thread identified by FROOT should be included | |
| 2497 | +** in a list of threads. Used to implement the status=NAME query parameter | |
| 2498 | +** on /forum. | |
| 2499 | +** | |
| 2500 | +** The result of this routine depends on the content of the | |
| 2501 | +** ForumStatusMatch *pMData object that is available via sqlite3_user_data(). | |
| 2502 | +** | |
| 2503 | +** * If pMData==NULL, always return true. This means that no | |
| 2504 | +** filtering of threads is being done. This is the common case. | |
| 2505 | +** | |
| 2506 | +** * If FROOT contains a status property value that matches | |
| 2507 | +** pMData->iMatch, return true. | |
| 2508 | +** | |
| 2509 | +** * if pMData->iMatch==0 (meaning we want to match the default | |
| 2510 | +** status value) and if the FROOT thread contains a status that | |
| 2511 | +** is not on the list of statuses or if FROOT has no statue | |
| 2512 | +** property at all, then return true. In other words, a forum | |
| 2513 | +** thread with no status property or an unknown status property | |
| 2514 | +** is treated as if it had the default status. | |
| 2515 | +** | |
| 2516 | +** * Otherwise, return false. | |
| 2517 | +*/ | |
| 2518 | +static void forum_status_match( | |
| 2519 | + sqlite3_context *context, | |
| 2520 | + int argc, | |
| 2521 | + sqlite3_value **argv | |
| 2522 | +){ | |
| 2523 | + static Stmt q; | |
| 2524 | + ForumStatusMatch *pMData = sqlite3_user_data(context); | |
| 2525 | + int i; | |
| 2526 | + | |
| 2527 | + if( pMData==0 ){ | |
| 2528 | + sqlite3_result_int(context, 1); | |
| 2529 | + return; | |
| 2530 | + } | |
| 2531 | + db_static_prepare(&q, | |
| 2532 | + "SELECT value FROM tagxref\n" | |
| 2533 | + " WHERE tagid=%d\n" | |
| 2534 | + " AND tagtype>=1\n" | |
| 2535 | + " AND rid=:rid\n" | |
| 2536 | + " ORDER BY mtime DESC LIMIT 1", | |
| 2537 | + pMData->eStatusTag | |
| 2538 | + ); | |
| 2539 | + db_bind_int(&q, ":rid", sqlite3_value_int(argv[0])); | |
| 2540 | + if( db_step(&q)==SQLITE_ROW ){ | |
| 2541 | + const char *zValue = (const char*)db_column_text(&q,0); | |
| 2542 | + const ForumStatusList *pFses = pMData->pFses; | |
| 2543 | + if( zValue==0 ){ | |
| 2544 | + i = 0; | |
| 2545 | + }else{ | |
| 2546 | + for(i=0; i<pFses->n; i++){ | |
| 2547 | + if( fossil_strcmp(pFses->aStatus[i].zValue,zValue)==0 ) break; | |
| 2548 | + } | |
| 2549 | + } | |
| 2550 | + if( i>=pMData->pFses->n ) i = 0; | |
| 2551 | + }else{ | |
| 2552 | + i = 0; | |
| 2553 | + } | |
| 2554 | + db_reset(&q); | |
| 2555 | + sqlite3_result_int(context, i==pMData->iMatch); | |
| 2556 | +} | |
| 1960 | 2557 | |
| 1961 | 2558 | /* |
| 1962 | 2559 | ** WEBPAGE: forummain |
| 1963 | 2560 | ** WEBPAGE: forum |
| 1964 | 2561 | ** |
| @@ -1975,30 +2572,38 @@ | ||
| 1975 | 2572 | void forum_main_page(void){ |
| 1976 | 2573 | Stmt q; |
| 1977 | 2574 | int iLimit = 0, iOfst, iCnt; |
| 1978 | 2575 | int srchFlags; |
| 1979 | 2576 | const int isSearch = P("s")!=0; |
| 1980 | - char const *zLimit = 0; | |
| 2577 | + const char *zStatusFilter; | |
| 2578 | + char const *zLimit = 0; /* Value of the n= query parameter */ | |
| 2579 | + int eStatusTag = 0; /* tagid for the "status" property */ | |
| 2580 | + int bHasStatus = 0; /* True if forum-statuses setting exists */ | |
| 2581 | + int bFilter = 0; /* True if status=NAME query parameter */ | |
| 2582 | + int bHasForum = 0; /* True if forumpost table exists */ | |
| 2583 | + const ForumStatusList *pFstat = forum_statuses(); | |
| 2584 | + ForumStatusMatch sFSM; /* Aux data to status_match() SQL function */ | |
| 1981 | 2585 | |
| 1982 | 2586 | login_check_credentials(); |
| 1983 | 2587 | srchFlags = search_restrict(SRCH_FORUM); |
| 1984 | 2588 | if( !g.perm.RdForum ){ |
| 1985 | 2589 | login_needed(g.anon.RdForum); |
| 1986 | 2590 | return; |
| 1987 | 2591 | } |
| 1988 | 2592 | cgi_check_for_malice(); |
| 2593 | + bHasForum = db_table_exists("repository","forumpost"); | |
| 2594 | + if( bHasForum ){ | |
| 2595 | + eStatusTag = db_int(0, "SELECT tagid FROM tag WHERE tagname='status'"); | |
| 2596 | + bHasStatus = pFstat->n>1; | |
| 2597 | + } | |
| 1989 | 2598 | style_set_current_feature("forum"); |
| 1990 | - style_header("%s%s", db_get("forum-title","Forum"), | |
| 2599 | + style_header("%s%s", db_get("forum-title","Forum"), | |
| 1991 | 2600 | isSearch ? " Search Results" : ""); |
| 1992 | 2601 | style_submenu_element("Timeline", "%R/timeline?ss=v&y=f&vfx"); |
| 1993 | 2602 | if( g.perm.WrForum ){ |
| 1994 | 2603 | style_submenu_element("New Thread","%R/forumnew"); |
| 1995 | 2604 | }else{ |
| 1996 | - /* Can't combine this with previous case using the ternary operator | |
| 1997 | - * because that causes an error yelling about "non-constant format" | |
| 1998 | - * with some compilers. I can't see it, since both expressions have | |
| 1999 | - * the same format, but I'm no C spec lawyer. */ | |
| 2000 | 2605 | style_submenu_element("New Thread","%R/login"); |
| 2001 | 2606 | } |
| 2002 | 2607 | if( g.perm.ModForum && moderation_needed() ){ |
| 2003 | 2608 | style_submenu_element("Moderation Requests", "%R/modreq"); |
| 2004 | 2609 | } |
| @@ -2021,95 +2626,577 @@ | ||
| 2021 | 2626 | cgi_replace_query_parameter("n", fossil_strdup("25")) |
| 2022 | 2627 | /*for the sake of Max, below*/; |
| 2023 | 2628 | iLimit = 25; |
| 2024 | 2629 | } |
| 2025 | 2630 | style_submenu_entry("n","Max:",4,0); |
| 2631 | + forum_status_submenu(); | |
| 2632 | + zStatusFilter = P("status") /*must be after forum_status_submenu()!*/; | |
| 2026 | 2633 | iOfst = atoi(PD("x","0")); |
| 2027 | 2634 | iCnt = 0; |
| 2028 | - if( db_table_exists("repository","forumpost") ){ | |
| 2635 | + if( zStatusFilter ){ | |
| 2636 | + if( zStatusFilter[0]==0 || 0==fossil_strcmp("*",zStatusFilter) ){ | |
| 2637 | + zStatusFilter = 0; | |
| 2638 | + }else{ | |
| 2639 | + bFilter = bHasStatus; | |
| 2640 | + } | |
| 2641 | + } | |
| 2642 | + if( bHasForum ){ | |
| 2643 | + Stmt qStat = empty_Stmt; /* Query to get status information */ | |
| 2644 | + if( bHasStatus ){ | |
| 2645 | + /* The qStat query runs once for each output row generate by the | |
| 2646 | + ** q query. It determines the value and label of the status for | |
| 2647 | + ** the row with froot=:rowid | |
| 2648 | + */ | |
| 2649 | + db_prepare(&qStat, | |
| 2650 | + "SELECT tagxref.value, forumstatus.label\n" | |
| 2651 | + " FROM forumstatus, tagxref\n" | |
| 2652 | + " WHERE tagid=%d AND tagtype>=1\n" | |
| 2653 | + " AND forumstatus.value=tagxref.value\n" | |
| 2654 | + " AND rid=:rid\n" | |
| 2655 | + " ORDER BY mtime DESC", | |
| 2656 | + eStatusTag | |
| 2657 | + ); | |
| 2658 | + } | |
| 2659 | + | |
| 2660 | + /* Create the status_match() SQL function that will determine | |
| 2661 | + ** whether or not each thread in the "q" query below is eligible | |
| 2662 | + ** for display | |
| 2663 | + */ | |
| 2664 | + if( bFilter ){ | |
| 2665 | + sFSM.pFses = pFstat; | |
| 2666 | + sFSM.eStatusTag = eStatusTag; | |
| 2667 | + for(sFSM.iMatch=0; sFSM.iMatch<pFstat->n; sFSM.iMatch++){ | |
| 2668 | + if( 0==fossil_strcmp(zStatusFilter, | |
| 2669 | + pFstat->aStatus[sFSM.iMatch].zValue) ){ | |
| 2670 | + break; | |
| 2671 | + } | |
| 2672 | + } | |
| 2673 | + sqlite3_create_function(g.db,"status_match",1,SQLITE_UTF8,(void*)&sFSM, | |
| 2674 | + forum_status_match, 0, 0); | |
| 2675 | + }else{ | |
| 2676 | + sqlite3_create_function(g.db,"status_match",1,SQLITE_UTF8,0, | |
| 2677 | + forum_status_match, 0, 0); | |
| 2678 | + } | |
| 2679 | + | |
| 2029 | 2680 | db_prepare(&q, |
| 2030 | - "WITH thread(age,duration,cnt,root,last) AS (" | |
| 2031 | - " SELECT" | |
| 2032 | - " julianday('now') - max(fmtime)," | |
| 2033 | - " max(fmtime) - min(fmtime)," | |
| 2034 | - " sum(fprev IS NULL)," | |
| 2035 | - " froot," | |
| 2036 | - " (SELECT fpid FROM forumpost AS y" | |
| 2037 | - " WHERE y.froot=x.froot %s" | |
| 2038 | - " ORDER BY y.fmtime DESC LIMIT 1)" | |
| 2039 | - " FROM forumpost AS x" | |
| 2040 | - " WHERE %s" | |
| 2041 | - " GROUP BY froot" | |
| 2042 | - " ORDER BY 1 LIMIT %d OFFSET %d" | |
| 2043 | - ")" | |
| 2044 | - "SELECT" | |
| 2045 | - " thread.age," /* 0 */ | |
| 2046 | - " thread.duration," /* 1 */ | |
| 2047 | - " thread.cnt," /* 2 */ | |
| 2048 | - " blob.uuid," /* 3 */ | |
| 2049 | - " substr(event.comment,instr(event.comment,':')+1)," /* 4 */ | |
| 2050 | - " thread.last" /* 5 */ | |
| 2051 | - " FROM thread, blob, event" | |
| 2052 | - " WHERE blob.rid=thread.last" | |
| 2053 | - " AND event.objid=thread.last" | |
| 2681 | + "WITH thread(root,endtime,lastrid) AS (\n" | |
| 2682 | + " SELECT\n" | |
| 2683 | + " froot,\n" | |
| 2684 | + " max(fmtime),\n" | |
| 2685 | + " fpid\n" | |
| 2686 | + " FROM forumpost\n" | |
| 2687 | + " WHERE %s/*ModForum*/\n" | |
| 2688 | + " GROUP BY froot\n" | |
| 2689 | + " HAVING status_match(froot)\n" | |
| 2690 | + " ORDER BY 2 DESC\n" | |
| 2691 | + " LIMIT %d OFFSET %d\n" | |
| 2692 | + ")\n" | |
| 2693 | + "SELECT\n" | |
| 2694 | + " julianday('now') - thread.endtime,\n" /* 0 */ | |
| 2695 | + " thread.endtime - " | |
| 2696 | + "(SELECT fmtime FROM forumpost WHERE fpid=root),\n" /* 1 */ | |
| 2697 | + " (SELECT sum(fprev IS NULL) FROM forumpost" | |
| 2698 | + " WHERE froot=root),\n" /* 2 */ | |
| 2699 | + " blob.uuid,\n" /* 3 */ | |
| 2700 | + " substr(event.comment,instr(event.comment,':')+1),\n" /* 4 */ | |
| 2701 | + " thread.lastrid,\n" /* 5 */ | |
| 2702 | + " thread.root\n" /* 6 */ | |
| 2703 | + " FROM thread, blob, event\n" | |
| 2704 | + " WHERE blob.rid=thread.lastrid\n" | |
| 2705 | + " AND event.objid=thread.lastrid\n" | |
| 2054 | 2706 | " ORDER BY 1;", |
| 2055 | - g.perm.ModForum ? "" : "AND y.fpid NOT IN private" /*safe-for-%s*/, | |
| 2056 | 2707 | g.perm.ModForum ? "true" : "fpid NOT IN private" /*safe-for-%s*/, |
| 2057 | 2708 | iLimit+1, iOfst |
| 2058 | 2709 | ); |
| 2059 | 2710 | while( db_step(&q)==SQLITE_ROW ){ |
| 2060 | - char *zAge = human_readable_age(db_column_double(&q,0)); | |
| 2061 | - int nMsg = db_column_int(&q, 2); | |
| 2062 | - const char *zUuid = db_column_text(&q, 3); | |
| 2063 | - const char *zTitle = db_column_text(&q, 4); | |
| 2711 | + char *zAge; | |
| 2712 | + int nMsg; | |
| 2713 | + const char *zUuid; | |
| 2714 | + const char *zTitle; | |
| 2715 | + const char *zStatus; | |
| 2716 | + const char *zStatusLbl; | |
| 2717 | + const int bShowStatus = bHasStatus && !zStatusFilter; | |
| 2718 | + const int nCols = bShowStatus ? 4 : 3; | |
| 2719 | + | |
| 2720 | + if( qStat.pStmt ){ | |
| 2721 | + /* Determine the status value for this row */ | |
| 2722 | + db_reset(&qStat); | |
| 2723 | + db_bind_int(&qStat, ":rid", db_column_int(&q,6)); | |
| 2724 | + if( db_step(&qStat)==SQLITE_ROW ){ | |
| 2725 | + zStatus = db_column_text(&qStat, 0); | |
| 2726 | + zStatusLbl = db_column_text(&qStat, 1); | |
| 2727 | + }else{ | |
| 2728 | + zStatus = pFstat->aStatus[0].zValue; | |
| 2729 | + zStatusLbl = pFstat->aStatus[0].zLabel; | |
| 2730 | + } | |
| 2731 | + }else{ | |
| 2732 | + zStatus = zStatusLbl = NULL; | |
| 2733 | + } | |
| 2734 | + zAge = human_readable_age(db_column_double(&q,0)); | |
| 2735 | + nMsg = db_column_int(&q, 2); | |
| 2736 | + zUuid = db_column_text(&q, 3); | |
| 2737 | + zTitle = db_column_text(&q, 4); | |
| 2064 | 2738 | if( iCnt==0 ){ |
| 2739 | + char *zTail = bFilter ? mprintf(" with status=%Q", zStatusFilter): 0; | |
| 2065 | 2740 | if( iOfst>0 ){ |
| 2066 | - @ <h1>Threads at least %s(zAge) old</h1> | |
| 2741 | + @ <h1>Threads at least %s(zAge) old%h(zTail ? zTail : "")</h1> | |
| 2067 | 2742 | }else{ |
| 2068 | - @ <h1>Most recent threads</h1> | |
| 2743 | + @ <h1>Most recent threads%h(zTail ? zTail : "")</h1> | |
| 2069 | 2744 | } |
| 2745 | + fossil_free(zTail); | |
| 2070 | 2746 | @ <div class='forumPosts fileage'><table width="100%%"> |
| 2071 | 2747 | if( iOfst>0 ){ |
| 2072 | 2748 | if( iOfst>iLimit ){ |
| 2073 | - @ <tr><td colspan="3">\ | |
| 2074 | - @ %z(href("%R/forum?x=%d&n=%d",iOfst-iLimit,iLimit))\ | |
| 2075 | - @ ↑ Newer...</a></td></tr> | |
| 2749 | + @ <tr><td colspan="%d(nCols)">\ | |
| 2750 | + @ <a href='%R/forum?x=%d(iOfst-iLimit)&n=%d(iLimit) \ | |
| 2751 | + if( bFilter ){ | |
| 2752 | + @ &status=%T(zStatusFilter)\ | |
| 2753 | + } | |
| 2754 | + @ '>↑ Newer...</a></td></tr> | |
| 2076 | 2755 | }else{ |
| 2077 | - @ <tr><td colspan="3">%z(href("%R/forum?n=%d",iLimit))\ | |
| 2078 | - @ ↑ Newer...</a></td></tr> | |
| 2756 | + @ <tr><td colspan="%d(nCols)">\ | |
| 2757 | + @ <a href='%R/forum?n=%d(iLimit)\ | |
| 2758 | + if( bFilter ){ | |
| 2759 | + @ &status=%T(zStatusFilter) \ | |
| 2760 | + } | |
| 2761 | + @ '>↑ Newer...</a></td></tr> | |
| 2079 | 2762 | } |
| 2080 | 2763 | } |
| 2081 | 2764 | } |
| 2082 | 2765 | iCnt++; |
| 2083 | 2766 | if( iCnt>iLimit ){ |
| 2084 | - @ <tr><td colspan="3">\ | |
| 2085 | - @ %z(href("%R/forum?x=%d&n=%d",iOfst+iLimit,iLimit))\ | |
| 2086 | - @ ↓ Older...</a></td></tr> | |
| 2767 | + @ <tr><td colspan="%d(nCols)">\ | |
| 2768 | + @ <a href='%R/forum?x=%d(iOfst+iLimit)&n=%d(iLimit) \ | |
| 2769 | + if( bFilter ){ | |
| 2770 | + @ &status=%T(zStatusFilter)\ | |
| 2771 | + } | |
| 2772 | + @ '>↓ Older...</a></td></tr> | |
| 2087 | 2773 | fossil_free(zAge); |
| 2088 | 2774 | break; |
| 2089 | 2775 | } |
| 2090 | - @ <tr><td>%h(zAge) ago</td> | |
| 2091 | - @ <td>%z(href("%R/forumpost/%S",zUuid))%h(zTitle)</a></td> | |
| 2092 | - @ <td>\ | |
| 2776 | + @ <tr \ | |
| 2777 | + if( bHasStatus ){ | |
| 2778 | + @ data-status="%h(zStatus)"\ | |
| 2779 | + } | |
| 2780 | + @ ><td>%h(zAge) ago</td> | |
| 2781 | + @ <td class='subject'>%z(href("%R/forumpost/%S",zUuid))%h(zTitle)</a>\ | |
| 2782 | + @ </td><td>\ | |
| 2093 | 2783 | if( g.perm.ModForum && moderation_pending(db_column_int(&q,5)) ){ |
| 2094 | 2784 | @ <span class="modpending">\ |
| 2095 | 2785 | @ Awaiting Moderator Approval</span><br> |
| 2096 | 2786 | } |
| 2097 | 2787 | if( nMsg<2 ){ |
| 2098 | - @ no replies</td> | |
| 2788 | + @ no replies\ | |
| 2099 | 2789 | }else{ |
| 2100 | 2790 | char *zDuration = human_readable_age(db_column_double(&q,1)); |
| 2101 | - @ %d(nMsg) posts spanning %h(zDuration)</td> | |
| 2791 | + @ %d(nMsg) posts spanning %h(zDuration)\ | |
| 2102 | 2792 | fossil_free(zDuration); |
| 2103 | 2793 | } |
| 2104 | - @ </tr> | |
| 2794 | + @ </td>\ | |
| 2795 | + if( bShowStatus ){ | |
| 2796 | + @ <td class='status'>%h(zStatusLbl)</td>\ | |
| 2797 | + } | |
| 2798 | + if( qStat.pStmt ){ | |
| 2799 | + db_reset(&qStat); | |
| 2800 | + } | |
| 2801 | + @</tr> | |
| 2105 | 2802 | fossil_free(zAge); |
| 2106 | 2803 | } |
| 2107 | 2804 | db_finalize(&q); |
| 2805 | + if( qStat.pStmt ) db_finalize(&qStat); | |
| 2806 | + sqlite3_create_function(g.db,"status_match",1,SQLITE_UTF8,0,0,0,0); | |
| 2108 | 2807 | } |
| 2109 | 2808 | if( iCnt>0 ){ |
| 2110 | 2809 | @ </table></div> |
| 2111 | 2810 | }else{ |
| 2112 | 2811 | @ <h1>No forum posts found</h1> |
| 2113 | 2812 | } |
| 2813 | + if( bHasStatus ){ | |
| 2814 | + /* We need a JS-side kludge to avoid passing on the x=N | |
| 2815 | + ** URL arg when the status selection list is activated. */ | |
| 2816 | + forum_emit_js(); | |
| 2817 | + } | |
| 2114 | 2818 | style_finish_page(); |
| 2115 | 2819 | } |
| 2820 | + | |
| 2821 | +/* | |
| 2822 | +** The AJAX counterpart of forum_post(). | |
| 2823 | +** | |
| 2824 | +** Returns the new artifact's RID on success, 0 if no changes were | |
| 2825 | +** necessary (e.g. an empty new post or dry-run mode), and a negative | |
| 2826 | +** value on error. If it returns a negative value then it will have | |
| 2827 | +** populated the ajax response state with an error object. | |
| 2828 | +** | |
| 2829 | +** zTitle must be NULL if iInReplyTo>0 and must be non-empty if | |
| 2830 | +** iInReplyTo==0. | |
| 2831 | +** | |
| 2832 | +** The caller must have started a transaction and must roll it back if | |
| 2833 | +** this call returns <=0, noting that only the negative-value case is | |
| 2834 | +** an error. | |
| 2835 | +** | |
| 2836 | +** This function does some work to try to ensure that duplicate | |
| 2837 | +** entries are not save (this can happen as a side effect of the forum | |
| 2838 | +** post editor added in 2026-06). If the given post will not have been | |
| 2839 | +** materially edited by these changes, they are not applied and the | |
| 2840 | +** rid of the existing entry is used. | |
| 2841 | +** | |
| 2842 | +** Maintenance reminders: | |
| 2843 | +** | |
| 2844 | +** - iInReplyTo==0 && iEdit==0: new thread | |
| 2845 | +** - iInReplyTo==0 && iEdit>0 : edit top post or response | |
| 2846 | +** - iInReplyTo>0 && iEdit==0: new response | |
| 2847 | +** - iInReplyTo>0 && iEdit>0 : edit response | |
| 2848 | +*/ | |
| 2849 | +static int forum_post_ajax( | |
| 2850 | + const char *zTitle, /* Title. NULL for replies */ | |
| 2851 | + int iInReplyTo, /* Post replying to. 0 for new threads */ | |
| 2852 | + int iEdit, /* Post being edited, or zero for a new post */ | |
| 2853 | + const char *zUser, /* Username. NULL means use login name */ | |
| 2854 | + const char *zMimetype, /* Mimetype of content. */ | |
| 2855 | + const char *zContent, /* Content */ | |
| 2856 | + int iFlags /* FPOST_xyz flag values */ | |
| 2857 | +){ | |
| 2858 | + char *zI; | |
| 2859 | + char *zG; | |
| 2860 | + char *zP = 0; | |
| 2861 | + int iBasis; | |
| 2862 | + Blob x = BLOB_INITIALIZER, | |
| 2863 | + cksum = BLOB_INITIALIZER, | |
| 2864 | + formatCheck = BLOB_INITIALIZER, | |
| 2865 | + errMsg = BLOB_INITIALIZER; | |
| 2866 | + Manifest *pPost = 0; | |
| 2867 | + int nContent = zContent ? (int)strlen(zContent) : 0; | |
| 2868 | + int rc = 0; | |
| 2869 | + | |
| 2870 | + assert( db_transaction_nesting_depth()>0 ); | |
| 2871 | + schema_forum(); | |
| 2872 | + if( iEdit==0 && fossil_all_whitespace(zContent) ){ | |
| 2873 | + return 0; | |
| 2874 | + } | |
| 2875 | + if( !g.perm.Admin && (iEdit || iInReplyTo) | |
| 2876 | + && forum_rid_is_tagged(iEdit ? iEdit : iInReplyTo, "closed", 1) ){ | |
| 2877 | + return -ajax_route_error(400, "Thread is closed."); | |
| 2878 | + } | |
| 2879 | + if( 0==iInReplyTo && fossil_all_whitespace(zTitle) ){ | |
| 2880 | + return -ajax_route_error(400, "Empty title is not permitted."); | |
| 2881 | + } | |
| 2882 | + | |
| 2883 | + if( zUser==0 ){ | |
| 2884 | + if( login_is_nobody() ){ | |
| 2885 | + zUser = "anonymous"; | |
| 2886 | + }else{ | |
| 2887 | + zUser = login_name(); | |
| 2888 | + } | |
| 2889 | + } | |
| 2890 | + if( iEdit>0 | |
| 2891 | + && !g.perm.Admin | |
| 2892 | + && !forumpost_is_owner(iEdit, zUser) ){ | |
| 2893 | + return -ajax_route_error( | |
| 2894 | + 403, "Only admins may edit other peoples' posts." | |
| 2895 | + ); | |
| 2896 | + } | |
| 2897 | + if( iInReplyTo==0 && iEdit>0 ){ | |
| 2898 | + iBasis = iEdit; | |
| 2899 | + iInReplyTo = db_int(0, "SELECT firt FROM forumpost WHERE fpid=%d", | |
| 2900 | + iEdit); | |
| 2901 | + }else{ | |
| 2902 | + iBasis = iInReplyTo; | |
| 2903 | + /* TODO (2026-06-008) If (iInReplyTo>0 && iEdit>0), validate that | |
| 2904 | + ** iInReplyTo is connected to iEdit properly, else we risk | |
| 2905 | + ** reparenting the new edit and having unrepredictable downstream | |
| 2906 | + ** side effects. */ | |
| 2907 | + } | |
| 2908 | + | |
| 2909 | + if( 0!=zMimetype && 0==zMimetype[0] ){ | |
| 2910 | + zMimetype = 0; | |
| 2911 | + } | |
| 2912 | + | |
| 2913 | + if( 0!=zTitle && 0==zTitle[0] ) zTitle = 0; | |
| 2914 | + webpage_assert( (zTitle==0)+(iInReplyTo==0)==1 ); | |
| 2915 | + | |
| 2916 | + if( iEdit>0 ){ | |
| 2917 | + int cmp; | |
| 2918 | + pPost = manifest_get(iEdit, CFTYPE_FORUM, 0); | |
| 2919 | + if( pPost==0 ){ | |
| 2920 | + rc = -ajax_route_error(404, "Missing edit artifact %d", iEdit); | |
| 2921 | + goto post_ajax_end; | |
| 2922 | + } | |
| 2923 | + /* | |
| 2924 | + ** If the old content matches the new then do not save a new copy. | |
| 2925 | + ** It's easy to get re-posts of unedited content via the forum | |
| 2926 | + ** editor, especially since the one added in 2026-06, where a | |
| 2927 | + ** post's status and attachments may be amended from the editor | |
| 2928 | + ** without modifying any of the post's content. In the legacy | |
| 2929 | + ** editor such "out-of-band" changes weren't possible and users | |
| 2930 | + ** have never made a practice of re-posting unedited content. | |
| 2931 | + ** | |
| 2932 | + ** We compare the following fields to the original: user, mimetype, | |
| 2933 | + ** content, and (for root posts only) the title. | |
| 2934 | + */ | |
| 2935 | + cmp = (0==pPost->zInReplyTo) | |
| 2936 | + ? fossil_strcmp(pPost->zThreadTitle, zTitle) | |
| 2937 | + : 0; | |
| 2938 | + if( 0==cmp ){ | |
| 2939 | + cmp=fossil_strcmp(pPost->zWiki, zContent); | |
| 2940 | + if( 0==cmp ){ | |
| 2941 | + cmp = fossil_strcmp(pPost->zUser, zUser); | |
| 2942 | + } | |
| 2943 | + if( 0==cmp | |
| 2944 | + && 0!=(cmp=fossil_strcmp(pPost->zMimetype, zMimetype)) ){ | |
| 2945 | + /* Extra mimetype checks for a common condition seen elsewhere */ | |
| 2946 | + if( (0==zMimetype | |
| 2947 | + && 0==fossil_strcmp(pPost->zMimetype, "text/x-fossil-wiki")) | |
| 2948 | + || (0==pPost->zMimetype | |
| 2949 | + && 0==fossil_strcmp(zMimetype, "text/x-fossil-wiki")) ){ | |
| 2950 | + cmp = 0; | |
| 2951 | + } | |
| 2952 | + } | |
| 2953 | + if( 0==cmp ){ | |
| 2954 | + rc = iEdit; | |
| 2955 | + goto post_ajax_end; | |
| 2956 | + } | |
| 2957 | + } | |
| 2958 | + zP = rid_to_uuid(iEdit); | |
| 2959 | + } | |
| 2960 | + | |
| 2961 | + /* Write the new artifact */ | |
| 2962 | + blob_init(&x, 0, 0); | |
| 2963 | + blob_appendf(&x, "D %z\n", date_in_standard_format("now")); | |
| 2964 | + zG = db_text( | |
| 2965 | + 0, | |
| 2966 | + "SELECT uuid FROM blob, forumpost" | |
| 2967 | + " WHERE blob.rid==forumpost.froot" | |
| 2968 | + " AND forumpost.fpid=%d", | |
| 2969 | + iBasis | |
| 2970 | + ); | |
| 2971 | + if( zG ){ | |
| 2972 | + blob_appendf(&x, "G %z\n", zG); | |
| 2973 | + } | |
| 2974 | + if( zTitle ){ | |
| 2975 | + blob_appendf(&x, "H %F\n", zTitle); | |
| 2976 | + } | |
| 2977 | + if( iInReplyTo>0 ){ | |
| 2978 | + zI = rid_to_uuid(iInReplyTo); | |
| 2979 | + if( 0==zI ){ | |
| 2980 | + rc = -ajax_route_error(404, "Missing in-reply-to artifact %d", | |
| 2981 | + iInReplyTo); | |
| 2982 | + goto post_ajax_end; | |
| 2983 | + } | |
| 2984 | + blob_appendf(&x, "I %z\n", zI); | |
| 2985 | + } | |
| 2986 | + if( zMimetype!=0 | |
| 2987 | + && fossil_strcmp(zMimetype,"text/x-fossil-wiki")!=0 ){ | |
| 2988 | + blob_appendf(&x, "N %F\n", zMimetype); | |
| 2989 | + } | |
| 2990 | + if( zP ){ | |
| 2991 | + blob_appendf(&x, "P %s\n", zP); | |
| 2992 | + } | |
| 2993 | + | |
| 2994 | + blob_appendf(&x, "U %F\n", zUser); | |
| 2995 | + blob_appendf(&x, "W %d\n%s\n", nContent, zContent); | |
| 2996 | + md5sum_blob(&x, &cksum); | |
| 2997 | + blob_appendf(&x, "Z %b\n", &cksum); | |
| 2998 | + blob_reset(&cksum); | |
| 2999 | + | |
| 3000 | + /* Verify that the artifact we are creating is well-formed */ | |
| 3001 | + blob_init(&formatCheck, 0, 0); | |
| 3002 | + blob_init(&errMsg, 0, 0); | |
| 3003 | + blob_copy(&formatCheck, &x); | |
| 3004 | + pPost = manifest_parse(&formatCheck, 0, &errMsg); | |
| 3005 | + if( pPost==0 ){ | |
| 3006 | + ajax_route_error(500, "Malformed forum post artifact: %b", &errMsg); | |
| 3007 | + rc = -500; | |
| 3008 | + goto post_ajax_end; | |
| 3009 | + } | |
| 3010 | + webpage_assert( pPost->type==CFTYPE_FORUM ); | |
| 3011 | + | |
| 3012 | + if( (iFlags & FPOST_DRYRUN)!=0 ){ | |
| 3013 | + rc = 0; | |
| 3014 | + }else{ | |
| 3015 | + int nrid; | |
| 3016 | + db_begin_transaction(); | |
| 3017 | + nrid = wiki_put(&x, iEdit>0 ? iEdit : 0, forum_need_moderation()); | |
| 3018 | + blob_reset(&x); | |
| 3019 | + if( (iFlags & FPOST_NO_ALERT)!=0 ){ | |
| 3020 | + alert_unqueue('f', nrid); | |
| 3021 | + } | |
| 3022 | + rc = nrid; | |
| 3023 | + db_end_transaction(0); | |
| 3024 | + } | |
| 3025 | +post_ajax_end: | |
| 3026 | + manifest_destroy(pPost); | |
| 3027 | + fossil_free(zP); | |
| 3028 | + blob_reset(&x); | |
| 3029 | + blob_reset(&cksum); | |
| 3030 | + blob_reset(&formatCheck); | |
| 3031 | + return rc; | |
| 3032 | +} | |
| 3033 | +/* | |
| 3034 | +** WEBPAGE: forumajax_save hidden | |
| 3035 | +** | |
| 3036 | +** WIP | |
| 3037 | +** | |
| 3038 | +** Response JSON: | |
| 3039 | +** | |
| 3040 | +** { uuid: hash, ...tbd } | |
| 3041 | +*/ | |
| 3042 | +void forum_ajax_save_page(void){ | |
| 3043 | + const char *zFpid; | |
| 3044 | + const char *zTitle; | |
| 3045 | + const char *zIrt; | |
| 3046 | + const char *zMimetype; | |
| 3047 | + const char *zContent; | |
| 3048 | + const char *zStatus; | |
| 3049 | + const int bHasAttachment = P("file1")!=0; | |
| 3050 | + Manifest *pPost = 0; | |
| 3051 | + char *zNewUuid = 0; | |
| 3052 | + int firt = 0; /* In-reply-to rid or 0 */ | |
| 3053 | + int fpid = 0; /* Post rid being edited or 0 */ | |
| 3054 | + int rc = 0; /* Result code. */ | |
| 3055 | + int nrid = 0; /* New artifact rid. */ | |
| 3056 | + int iPostFlags; /* forum_post_flags() (after perms check) */ | |
| 3057 | + int bRollback; /* True = roll back. */ | |
| 3058 | + int nAttach = 0; /* Number of attachments added */ | |
| 3059 | + int bStatusSet = 0; /* True if status tag set. */ | |
| 3060 | + | |
| 3061 | + if( !ajax_route_bootstrap(0, 1) ){ | |
| 3062 | + return; | |
| 3063 | + }else if( !g.perm.WrForum | |
| 3064 | + || (bHasAttachment && !g.perm.AttachForum) ){ | |
| 3065 | + ajax_route_error_forbidden(); | |
| 3066 | + return; | |
| 3067 | + }else if( !ajax_check_csrf(2) ){ | |
| 3068 | + ajax_route_error_csrf(); | |
| 3069 | + return; | |
| 3070 | + } | |
| 3071 | + | |
| 3072 | + iPostFlags = forum_post_flags(/*must come after permissions init*/); | |
| 3073 | + bRollback = (FPOST_DRYRUN & iPostFlags); | |
| 3074 | + zFpid = P("fpid"); | |
| 3075 | + zIrt = P("firt"); | |
| 3076 | + zMimetype = P("mimetype"); | |
| 3077 | + zContent = P("content"); | |
| 3078 | + zStatus = P("status"); | |
| 3079 | + db_begin_transaction(); | |
| 3080 | + if( zFpid && zFpid[0] ){ | |
| 3081 | + fpid = symbolic_name_to_rid(zFpid, "f"); | |
| 3082 | + if( fpid<0 ){ | |
| 3083 | + rc = -ajax_route_error(400, "Ambiguous forum ID."); | |
| 3084 | + goto ajax_save_end; | |
| 3085 | + }else if( 0==fpid | |
| 3086 | + || 0==(pPost = manifest_get(fpid, CFTYPE_FORUM, 0)) ){ | |
| 3087 | + rc = -ajax_route_error(404, "Cannot resolve forum post ID."); | |
| 3088 | + goto ajax_save_end; | |
| 3089 | + } | |
| 3090 | + } | |
| 3091 | + /* | |
| 3092 | + ** Problem: if we derive firt from fpid/pPost then there's a race | |
| 3093 | + ** condition where the IRT post is edited between the time that this | |
| 3094 | + ** edit was initiated and when it is posted: the new edit's IRT will | |
| 3095 | + ** point to the edit which was made in the meantime, not the one the | |
| 3096 | + ** user intended to respond to. However, if we accept firt from the | |
| 3097 | + ** enviornment, we "really should" validate that it's actually in | |
| 3098 | + ** the current chain, to prohibit that malicious posts could move | |
| 3099 | + ** posts around. | |
| 3100 | + ** | |
| 3101 | + ** forum_post_ajax() will, if fpid>0 && !firt, select fpid's current | |
| 3102 | + ** firt. | |
| 3103 | + */ | |
| 3104 | + if( zIrt && zIrt[0] ){ | |
| 3105 | + firt = symbolic_name_to_rid(zIrt, "f"); | |
| 3106 | + if( firt<0 ){ | |
| 3107 | + rc = -ajax_route_error(400, "Ambiguous in-reply-do ID."); | |
| 3108 | + goto ajax_save_end; | |
| 3109 | + }else if( 0==firt ){ | |
| 3110 | + rc = -ajax_route_error(404, "Cannot resolve in-reply-do ID."); | |
| 3111 | + goto ajax_save_end; | |
| 3112 | + } | |
| 3113 | + } | |
| 3114 | + | |
| 3115 | + if( 0 ){ | |
| 3116 | + rc = -ajax_route_error(400, "Save is TODO. " | |
| 3117 | + "iPostFlags=%d debug=%d", | |
| 3118 | + iPostFlags, g.perm.Debug); | |
| 3119 | + goto ajax_save_end; | |
| 3120 | + } | |
| 3121 | + | |
| 3122 | + zTitle = firt ? 0 : P("title"); | |
| 3123 | + nrid = forum_post_ajax(zTitle, firt, fpid, 0, zMimetype, | |
| 3124 | + zContent, iPostFlags); | |
| 3125 | + if( nrid<0 ){ | |
| 3126 | + rc = nrid; | |
| 3127 | + goto ajax_save_end; | |
| 3128 | + }else if( nrid==0 ){ | |
| 3129 | + if( 0==(FPOST_DRYRUN & iPostFlags) ){ | |
| 3130 | + bRollback = 1; | |
| 3131 | + CX("{\"message\": \"No saving needed.\"}\n"); | |
| 3132 | + }else{ | |
| 3133 | + CX("{\"message\": \"Rolled back for dry-run.\"," | |
| 3134 | + "\"iPostFlags\":%d}\n", iPostFlags); | |
| 3135 | + } | |
| 3136 | + goto ajax_save_end; | |
| 3137 | + }else{ | |
| 3138 | + const int bNeedsModeration = forum_need_moderation(); | |
| 3139 | + const int fpHead = forumpost_head_rid(nrid); | |
| 3140 | + assert( nrid>0 ); | |
| 3141 | + assert( fpHead>0 ); | |
| 3142 | + zNewUuid = rid_to_uuid(nrid); | |
| 3143 | + if( 0!=P("file1") ){ | |
| 3144 | + /* Attachments */ | |
| 3145 | + if( !g.perm.Admin && !g.perm.AttachForum ){ | |
| 3146 | + rc = -ajax_route_error(403, "No permission no attach files."); | |
| 3147 | + goto ajax_save_end; | |
| 3148 | + }else{ | |
| 3149 | + char *zRoot = (nrid==fpHead) ? 0 : rid_to_uuid(fpHead); | |
| 3150 | + nAttach = attachments_ajax_from_POST(zRoot ? zRoot : zNewUuid, | |
| 3151 | + bNeedsModeration); | |
| 3152 | + fossil_free(zRoot); | |
| 3153 | + if( nAttach<0 ){ | |
| 3154 | + rc = nAttach; | |
| 3155 | + goto ajax_save_end; | |
| 3156 | + } | |
| 3157 | + if( nAttach>0 | |
| 3158 | + && (iPostFlags & FPOST_NO_ALERT)!=0 | |
| 3159 | + && db_table_exists("repository","pending_alert") ){ | |
| 3160 | + /* Unqueue any alerts for these attachments. Recall that | |
| 3161 | + ** they're attached to the first version of the post, which | |
| 3162 | + ** means we actually risk cancelling _other_ pending | |
| 3163 | + ** notifications for attachments on this same post. C'est la | |
| 3164 | + ** vie.*/ | |
| 3165 | + db_multi_exec( | |
| 3166 | + "WITH x(id) AS (\n" | |
| 3167 | + " SELECT 'f%d'\n" | |
| 3168 | + " UNION ALL\n" | |
| 3169 | + " SELECT 'f'||a.attachid FROM blob b, attachment a\n" | |
| 3170 | + " WHERE b.rid=%d\n" | |
| 3171 | + " AND b.uuid=a.target\n" | |
| 3172 | + ") DELETE FROM pending_alert WHERE eventid IN x", | |
| 3173 | + fpHead, fpHead | |
| 3174 | + ); | |
| 3175 | + } | |
| 3176 | + } | |
| 3177 | + } | |
| 3178 | + if( 0==bNeedsModeration | |
| 3179 | + /* ^^^ Do not allow a status tag on a pending-moderation post | |
| 3180 | + ** because it will introduce a reference to an artifact which | |
| 3181 | + ** will become a phantom if it is rejected by a moderator. */ | |
| 3182 | + && zStatus!=0 && zStatus[0]!=0 | |
| 3183 | + && forum_may_set_status(nrid) | |
| 3184 | + && (bStatusSet=forumpost_tag(nrid, 1, "status", zStatus))<0 ){ | |
| 3185 | + rc = -ajax_route_error(500, "Tagging failed: %s", g.zErrMsg); | |
| 3186 | + goto ajax_save_end; | |
| 3187 | + } | |
| 3188 | + } | |
| 3189 | + | |
| 3190 | + assert( 0==rc ); | |
| 3191 | + assert( zNewUuid ); | |
| 3192 | + CX("{\"uuid\": %!j, \"attachedCount\": %d, " | |
| 3193 | + "\"statusModified\": %d, " | |
| 3194 | + "\"dryrun\": %s, \"iPostFlags\":%d}\n", | |
| 3195 | + zNewUuid, nAttach, | |
| 3196 | + bStatusSet, bRollback ? "true" : "false", iPostFlags); | |
| 3197 | + | |
| 3198 | +ajax_save_end: | |
| 3199 | + manifest_destroy(pPost); | |
| 3200 | + fossil_free(zNewUuid); | |
| 3201 | + db_end_transaction(rc || bRollback); | |
| 3202 | +} | |
| 2116 | 3203 | |
| 2117 | 3204 | ADDED src/fossil.attach.js |
| --- src/forum.c | |
| +++ src/forum.c | |
| @@ -49,11 +49,11 @@ | |
| 49 | ForumPost *pNext; /* Next in chronological order */ |
| 50 | ForumPost *pPrev; /* Previous in chronological order */ |
| 51 | ForumPost *pDisplay; /* Next in display order */ |
| 52 | int nEdit; /* Number of edits to this post */ |
| 53 | int nIndent; /* Number of levels of indentation for this post */ |
| 54 | int iClosed; /* See forum_rid_is_closed() */ |
| 55 | }; |
| 56 | |
| 57 | /* |
| 58 | ** A single instance of the following tracks all entries for a thread. |
| 59 | */ |
| @@ -63,12 +63,134 @@ | |
| 63 | ForumPost *pDisplay; /* Entries in display order */ |
| 64 | ForumPost *pTail; /* Last on the display list */ |
| 65 | int mxIndent; /* Maximum indentation level */ |
| 66 | int nArtifact; /* Number of forum artifacts in this thread */ |
| 67 | }; |
| 68 | #endif /* INTERFACE */ |
| 69 | |
| 70 | /* |
| 71 | ** Return true if the forum post with the given rid has been |
| 72 | ** subsequently edited. |
| 73 | */ |
| 74 | int forum_rid_has_been_edited(int rid){ |
| @@ -83,29 +205,68 @@ | |
| 83 | db_reset(&q); |
| 84 | return res; |
| 85 | } |
| 86 | |
| 87 | /* |
| 88 | ** Given a valid forumpost.fpid value, this function returns the first |
| 89 | ** fpid in the chain of edits for that forum post, or rid if no prior |
| 90 | ** versions are found. |
| 91 | */ |
| 92 | static int forumpost_head_rid(int rid){ |
| 93 | Stmt q; |
| 94 | int rcRid = rid; |
| 95 | |
| 96 | db_prepare(&q, "SELECT fprev FROM forumpost" |
| 97 | " WHERE fpid=:rid AND fprev IS NOT NULL"); |
| 98 | db_bind_int(&q, ":rid", rid); |
| 99 | while( SQLITE_ROW==db_step(&q) ){ |
| 100 | rcRid = db_column_int(&q, 0); |
| 101 | db_reset(&q); |
| 102 | db_bind_int(&q, ":rid", rcRid); |
| 103 | } |
| 104 | db_finalize(&q); |
| 105 | return rcRid; |
| 106 | } |
| 107 | |
| 108 | /* |
| 109 | ** Returns true if p, or any parent of p, has a non-zero iClosed |
| 110 | ** value. Returns 0 if !p. For an edited chain of post, the tag is |
| 111 | ** checked on the pEditHead entry, to simplify subsequent unlocking of |
| @@ -128,39 +289,39 @@ | |
| 128 | return 0; |
| 129 | } |
| 130 | |
| 131 | /* |
| 132 | ** Given a forum post RID, this function returns true if that post has |
| 133 | ** (or inherits) an active "closed" tag. If bCheckIrt is true then |
| 134 | ** the post to which the given post responds is also checked |
| 135 | ** (recursively), else they are not. When checking in-response-to |
| 136 | ** posts, the first one which is closed ends the search. |
| 137 | ** |
| 138 | ** Note that this function checks _exactly_ the given rid, whereas |
| 139 | ** forum post closure/re-opening is always applied to the head of an |
| 140 | ** edit chain so that we get consistent implied locking behavior for |
| 141 | ** later versions and responses to arbitrary versions in the |
| 142 | ** chain. Even so, the "closed" tag is applied as a propagating tag |
| 143 | ** so will apply to all edits in a given chain. |
| 144 | ** |
| 145 | ** The return value is one of: |
| 146 | ** |
| 147 | ** - 0 if no "closed" tag is found. |
| 148 | ** |
| 149 | ** - The tagxref.rowid of the tagxref entry for the closure if rid is |
| 150 | ** the forum post to which the closure applies. |
| 151 | ** |
| 152 | ** - (-tagxref.rowid) if the given rid inherits a "closed" tag from an |
| 153 | ** IRT forum post. |
| 154 | */ |
| 155 | static int forum_rid_is_closed(int rid, int bCheckIrt){ |
| 156 | static Stmt qIrt = empty_Stmt_m; |
| 157 | int rc = 0, i = 0; |
| 158 | /* TODO: this can probably be turned into a CTE by someone with |
| 159 | ** superior SQL-fu. */ |
| 160 | for( ; rid; i++ ){ |
| 161 | rc = rid_has_active_tag_name(rid, "closed"); |
| 162 | if( rc || !bCheckIrt ) break; |
| 163 | else if( !qIrt.pStmt ) { |
| 164 | db_static_prepare(&qIrt, |
| 165 | "SELECT firt FROM forumpost " |
| 166 | "WHERE fpid=$fpid ORDER BY fmtime DESC" |
| @@ -171,105 +332,211 @@ | |
| 171 | db_reset(&qIrt); |
| 172 | } |
| 173 | return i ? -rc : rc; |
| 174 | } |
| 175 | |
| 176 | /* |
| 177 | ** Closes or re-opens the given forum RID via addition of a new |
| 178 | ** control artifact into the repository. In order to provide |
| 179 | ** consistent behavior for implied closing of responses and later |
| 180 | ** versions, it always acts on the first version of the given forum |
| 181 | ** post, walking the forumpost.fprev values to find the head of the |
| 182 | ** chain. |
| 183 | ** |
| 184 | ** If doClose is true then a propagating "closed" tag is added, except |
| 185 | ** as noted below, with the given optional zReason string as the tag's |
| 186 | ** value. If doClose is false then any active "closed" tag on frid is |
| 187 | ** cancelled, except as noted below. zReason is ignored if doClose is |
| 188 | ** false or if zReason is NULL or starts with a NUL byte. |
| 189 | ** |
| 190 | ** This function only adds a "closed" tag if forum_rid_is_closed() |
| 191 | ** indicates that frid's head is not closed. If a parent post is |
| 192 | ** already closed, no tag is added. Similarly, it will only remove a |
| 193 | ** "closed" tag from a post which has its own "closed" tag, and will |
| 194 | ** not remove an inherited one from a parent post. |
| 195 | ** |
| 196 | ** If doClose is true and frid is closed (directly or inherited), this |
| 197 | ** is a no-op. Likewise, if doClose is false and frid itself is not |
| 198 | ** closed (not accounting for an inherited closed tag), this is a |
| 199 | ** no-op. |
| 200 | ** |
| 201 | ** Returns true if it actually creates a new tag, else false. Fails |
| 202 | ** fatally on error. If it returns true then any ForumPost::iClosed |
| 203 | ** values from previously loaded posts are invalidated if they refer |
| 204 | ** to the amended post or a response to it. |
| 205 | ** |
| 206 | ** Sidebars: |
| 207 | ** |
| 208 | ** - Unless the caller has a transaction open, via |
| 209 | ** db_begin_transaction(), there is a very tiny race condition |
| 210 | ** window during which the caller's idea of whether or not the forum |
| 211 | ** post is closed may differ from the current repository state. |
| 212 | ** |
| 213 | ** - This routine assumes that frid really does refer to a forum post. |
| 214 | ** |
| 215 | ** - This routine assumes that frid is not private or pending |
| 216 | ** moderation. |
| 217 | ** |
| 218 | ** - Closure of a forum post requires a propagating "closed" tag to |
| 219 | ** account for how edits of posts are handled. This differs from |
| 220 | ** closure of a branch, where a non-propagating tag is used. |
| 221 | */ |
| 222 | static int forumpost_close(int frid, int doClose, const char *zReason){ |
| 223 | Blob artifact = BLOB_INITIALIZER; /* Output artifact */ |
| 224 | Blob cksum = BLOB_INITIALIZER; /* Z-card */ |
| 225 | int iClosed; /* true if frid is closed */ |
| 226 | int trid; /* RID of new control artifact */ |
| 227 | char *zUuid; /* UUID of head version of post */ |
| 228 | |
| 229 | db_begin_transaction(); |
| 230 | frid = forumpost_head_rid(frid); |
| 231 | iClosed = forum_rid_is_closed(frid, 1); |
| 232 | if( (iClosed && doClose |
| 233 | /* Already closed, noting that in the case of (iClosed<0), it's |
| 234 | ** actually a parent which is closed. */) |
| 235 | || (iClosed<=0 && !doClose |
| 236 | /* This entry is not closed, but a parent post may be. */) ){ |
| 237 | db_end_transaction(0); |
| 238 | return 0; |
| 239 | } |
| 240 | if( doClose==0 || (zReason && !zReason[0]) ){ |
| 241 | zReason = 0; |
| 242 | } |
| 243 | zUuid = rid_to_uuid(frid); |
| 244 | blob_appendf(&artifact, "D %z\n", date_in_standard_format( "now" )); |
| 245 | blob_appendf(&artifact, |
| 246 | "T %cclosed %s%s%F\n", |
| 247 | doClose ? '*' : '-', zUuid, |
| 248 | zReason ? " " : "", zReason ? zReason : ""); |
| 249 | blob_appendf(&artifact, "U %F\n", login_name()); |
| 250 | md5sum_blob(&artifact, &cksum); |
| 251 | blob_appendf(&artifact, "Z %b\n", &cksum); |
| 252 | blob_reset(&cksum); |
| 253 | trid = content_put_ex(&artifact, 0, 0, 0, 0); |
| 254 | if( trid==0 ){ |
| 255 | fossil_fatal("Error saving tag artifact: %s", g.zErrMsg); |
| 256 | } |
| 257 | if( manifest_crosslink(trid, &artifact, |
| 258 | MC_NONE /*MC_PERMIT_HOOKS?*/)==0 ){ |
| 259 | fossil_fatal("%s", g.zErrMsg); |
| 260 | } |
| 261 | assert( blob_is_reset(&artifact) ); |
| 262 | db_add_unsent(trid); |
| 263 | admin_log("%s forum post %S", doClose ? "Close" : "Re-open", zUuid); |
| 264 | fossil_free(zUuid); |
| 265 | /* Potential TODO: if (iClosed>0) then we could find the initial tag |
| 266 | ** artifact and content_deltify(thatRid,&trid,1,0). Given the tiny |
| 267 | ** size of these artifacts, however, that would save little space, |
| 268 | ** if any. */ |
| 269 | db_end_transaction(0); |
| 270 | return 1; |
| 271 | } |
| 272 | |
| 273 | /* |
| 274 | ** Returns true if the forum-close-policy setting is true, else false, |
| 275 | ** caching the result for subsequent calls. |
| @@ -285,12 +552,15 @@ | |
| 285 | |
| 286 | /* |
| 287 | ** Returns 1 if the current user is an admin, -1 if the current user |
| 288 | ** is a forum moderator and the forum-close-policy setting is true, |
| 289 | ** else returns 0. The value is cached for subsequent calls. |
| 290 | */ |
| 291 | static int forumpost_may_close(void){ |
| 292 | static int permClose = -99; |
| 293 | if( permClose!=-99 ){ |
| 294 | return permClose; |
| 295 | }else if( g.perm.Admin ){ |
| 296 | return permClose = 1; |
| @@ -445,13 +715,13 @@ | |
| 445 | for(; p; p=p->pEditPrev ){ |
| 446 | p->nEdit = pPost->nEdit; |
| 447 | p->pEditTail = pPost; |
| 448 | } |
| 449 | } |
| 450 | pPost->iClosed = forum_rid_is_closed(pPost->pEditHead |
| 451 | ? pPost->pEditHead->fpid |
| 452 | : pPost->fpid, 1); |
| 453 | } |
| 454 | db_finalize(&q); |
| 455 | |
| 456 | if( computeHierarchy ){ |
| 457 | /* Compute the hierarchical display order */ |
| @@ -629,10 +899,80 @@ | |
| 629 | } |
| 630 | @ </table> |
| 631 | db_finalize(&q); |
| 632 | style_finish_page(); |
| 633 | } |
| 634 | |
| 635 | /* |
| 636 | ** Render a forum post for display |
| 637 | */ |
| 638 | void forum_render( |
| @@ -760,22 +1100,55 @@ | |
| 760 | if( pToFree ) manifest_destroy(pToFree); |
| 761 | if( p->zDisplayName==0 ) return "(unknown)"; |
| 762 | return p->zDisplayName; |
| 763 | } |
| 764 | |
| 765 | |
| 766 | /* |
| 767 | ** Display a single post in a forum thread. |
| 768 | */ |
| 769 | static void forum_display_post( |
| 770 | ForumThread *pThread, /* The thread that this post is a member of */ |
| 771 | ForumPost *p, /* Forum post to display */ |
| 772 | int iIndentScale, /* Indent scale factor */ |
| 773 | int bRaw, /* True to omit the border */ |
| 774 | int bUnf, /* True to leave the post unformatted */ |
| 775 | int bHist, /* True if showing edit history */ |
| 776 | int bSelect, /* True if this is the selected post */ |
| 777 | char *zQuery /* Common query string */ |
| 778 | ){ |
| 779 | char *zPosterName; /* Name of user who originally made this post */ |
| 780 | char *zEditorName; /* Name of user who provided the current edit */ |
| 781 | char *zDate; /* The time/date string */ |
| @@ -784,30 +1157,43 @@ | |
| 784 | Manifest *pManifest; /* Manifest comprising the current post */ |
| 785 | int bPrivate; /* True for posts awaiting moderation */ |
| 786 | int bSameUser; /* True if author is also the reader */ |
| 787 | int iIndent; /* Indent level */ |
| 788 | int iClosed; /* True if (sub)thread is closed */ |
| 789 | const char *zMimetype;/* Formatting MIME type */ |
| 790 | |
| 791 | /* Get the manifest for the post. Abort if not found (e.g. shunned). */ |
| 792 | pManifest = manifest_get(p->fpid, CFTYPE_FORUM, 0); |
| 793 | if( !pManifest ) return; |
| 794 | iClosed = forumpost_is_closed(pThread, p, 1); |
| 795 | /* When not in raw mode, create the border around the post. */ |
| 796 | if( !bRaw ){ |
| 797 | /* Open the <div> enclosing the post. Set the class string to mark the post |
| 798 | ** as selected and/or obsolete. */ |
| 799 | iIndent = (p->pEditHead ? p->pEditHead->nIndent : p->nIndent)-1; |
| 800 | @ <div id='forum%d(p->fpid)' class='forumTime\ |
| 801 | @ %s(bSelect ? " forumSel" : "")\ |
| 802 | @ %s(iClosed ? " forumClosed" : "")\ |
| 803 | @ %s(p->pEditTail ? " forumObs" : "")' \ |
| 804 | if( iIndent && iIndentScale ){ |
| 805 | @ style='margin-left:%d(iIndent*iIndentScale)ex;'> |
| 806 | }else{ |
| 807 | @ > |
| 808 | } |
| 809 | |
| 810 | /* If this is the first post (or an edit thereof), emit the thread title. */ |
| 811 | if( pManifest->zThreadTitle ){ |
| 812 | @ <h1>%h(pManifest->zThreadTitle)</h1> |
| 813 | } |
| @@ -888,18 +1274,18 @@ | |
| 888 | /* Provide a link to the raw source code. */ |
| 889 | if( !bUnf ){ |
| 890 | @ %z(href("%R/forumpost/%!S?raw",p->zUuid))[source]</a> |
| 891 | } |
| 892 | @ </h3> |
| 893 | } |
| 894 | |
| 895 | /* Check if this post is approved, also if it's by the current user. */ |
| 896 | bPrivate = content_is_private(p->fpid); |
| 897 | bSameUser = login_is_individual() |
| 898 | && fossil_strcmp(pManifest->zUser, g.zLogin)==0; |
| 899 | |
| 900 | /* Render the post if the user is able to see it. */ |
| 901 | if( bPrivate && !g.perm.ModForum && !bSameUser ){ |
| 902 | @ <p><span class="modpending">Awaiting Moderator Approval</span></p> |
| 903 | }else{ |
| 904 | if( bRaw || bUnf || p->pEditTail ){ |
| 905 | zMimetype = "text/plain"; |
| @@ -909,10 +1295,12 @@ | |
| 909 | forum_render(0, zMimetype, pManifest->zWiki, 0, !bRaw); |
| 910 | } |
| 911 | |
| 912 | /* When not in raw mode, finish creating the border around the post. */ |
| 913 | if( !bRaw ){ |
| 914 | /* If the user is able to write to the forum and if this post has not been |
| 915 | ** edited, create a form with various interaction buttons. */ |
| 916 | if( g.perm.WrForum && !p->pEditTail ){ |
| 917 | @ <div class="forumpost-single-controls">\ |
| 918 | @ <form action="%R/forumedit" method="POST"> |
| @@ -941,33 +1329,52 @@ | |
| 941 | @ <br><label><input type="checkbox" name="trust"> |
| 942 | @ Trust user "%h(pManifest->zUser)" so that future posts by \ |
| 943 | @ "%h(pManifest->zUser)" do not require moderation. |
| 944 | @ </label> |
| 945 | @ <input type="hidden" name="trustuser" value="%h(pManifest->zUser)"> |
| 946 | } |
| 947 | }else if( bSameUser ){ |
| 948 | /* Allow users to delete (reject) their own pending posts. */ |
| 949 | @ <input type="submit" name="reject" value="Delete"> |
| 950 | } |
| 951 | login_insert_csrf_secret(); |
| 952 | @ </form> |
| 953 | if( bSelect && forumpost_may_close() && iClosed>=0 ){ |
| 954 | int iHead = forumpost_head_rid(p->fpid); |
| 955 | @ <form method="post" \ |
| 956 | @ action='%R/forumpost_%s(iClosed > 0 ? "reopen" : "close")'> |
| 957 | login_insert_csrf_secret(); |
| 958 | @ <input type="hidden" name="fpid" value="%z(rid_to_uuid(iHead))" /> |
| 959 | if( moderation_pending(p->fpid)==0 ){ |
| 960 | @ <input type="button" value='%s(iClosed ? "Re-open" : "Close")' \ |
| 961 | @ class='%s(iClosed ? "action-reopen" : "action-close")'/> |
| 962 | } |
| 963 | @ </form> |
| 964 | } |
| 965 | @ </div> |
| 966 | } |
| 967 | @ </div> |
| 968 | } |
| 969 | |
| 970 | /* Clean up. */ |
| 971 | manifest_destroy(pManifest); |
| 972 | } |
| 973 | |
| @@ -1077,12 +1484,18 @@ | |
| 1077 | } |
| 1078 | |
| 1079 | /* Display the appropriate subset of posts in sequence. */ |
| 1080 | while( p ){ |
| 1081 | /* Display the post. */ |
| 1082 | forum_display_post(pThread, p, iIndentScale, mode==FD_RAW, |
| 1083 | bUnf, bHist, p==pSelect, zQuery); |
| 1084 | |
| 1085 | /* Advance to the next post in the thread. */ |
| 1086 | if( mode==FD_CHRONO ){ |
| 1087 | /* Chronological mode: display posts (optionally including edits) in their |
| 1088 | ** original commit order. */ |
| @@ -1138,11 +1551,12 @@ | |
| 1138 | ** to all forum-related pages. It does not include page-specific |
| 1139 | ** code (e.g. "forum.js"). |
| 1140 | */ |
| 1141 | static void forum_emit_js(void){ |
| 1142 | builtin_fossil_js_bundle_or("copybutton", "pikchr", "confirmer", |
| 1143 | NULL); |
| 1144 | builtin_request_js("fossil.page.forumpost.js"); |
| 1145 | } |
| 1146 | |
| 1147 | /* |
| 1148 | ** WEBPAGE: forumpost |
| @@ -1291,28 +1705,20 @@ | |
| 1291 | } |
| 1292 | |
| 1293 | /* |
| 1294 | ** Return true if a forum post should be moderated. |
| 1295 | */ |
| 1296 | static int forum_need_moderation(void){ |
| 1297 | if( P("domod") ) return 1; |
| 1298 | if( g.perm.WrTForum ) return 0; |
| 1299 | if( g.perm.ModForum ) return 0; |
| 1300 | return 1; |
| 1301 | } |
| 1302 | |
| 1303 | /* |
| 1304 | ** Return true if the string is white-space only. |
| 1305 | */ |
| 1306 | static int whitespace_only(const char *z){ |
| 1307 | if( z==0 ) return 1; |
| 1308 | while( z[0] && fossil_isspace(z[0]) ){ z++; } |
| 1309 | return z[0]==0; |
| 1310 | } |
| 1311 | |
| 1312 | /* Flags for use with forum_post() */ |
| 1313 | #define FPOST_NO_ALERT 1 /* do not send any alerts */ |
| 1314 | |
| 1315 | /* |
| 1316 | ** Return a flags value for use with the final argument to |
| 1317 | ** forum_post(), extracted from the CGI environment. |
| 1318 | */ |
| @@ -1319,10 +1725,13 @@ | |
| 1319 | static int forum_post_flags(void){ |
| 1320 | int iPostFlags = 0; |
| 1321 | if( g.perm.Debug && P("fpsilent")!=0 ){ |
| 1322 | iPostFlags |= FPOST_NO_ALERT; |
| 1323 | } |
| 1324 | return iPostFlags; |
| 1325 | } |
| 1326 | |
| 1327 | /* |
| 1328 | ** Add a new Forum Post artifact to the repository. |
| @@ -1346,15 +1755,15 @@ | |
| 1346 | Manifest *pPost; |
| 1347 | int nContent = zContent ? (int)strlen(zContent) : 0; |
| 1348 | |
| 1349 | schema_forum(); |
| 1350 | if( !g.perm.Admin && (iEdit || iInReplyTo) |
| 1351 | && forum_rid_is_closed(iEdit ? iEdit : iInReplyTo, 1) ){ |
| 1352 | forumpost_error_closed(); |
| 1353 | return 0; |
| 1354 | } |
| 1355 | if( iEdit==0 && whitespace_only(zContent) ){ |
| 1356 | return 0; |
| 1357 | } |
| 1358 | if( iInReplyTo==0 && iEdit>0 ){ |
| 1359 | iBasis = iEdit; |
| 1360 | iInReplyTo = db_int(0, "SELECT firt FROM forumpost WHERE fpid=%d", iEdit); |
| @@ -1375,17 +1784,19 @@ | |
| 1375 | fossil_free(zG); |
| 1376 | } |
| 1377 | if( zTitle ){ |
| 1378 | blob_appendf(&x, "H %F\n", zTitle); |
| 1379 | } |
| 1380 | zI = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", iInReplyTo); |
| 1381 | if( zI ){ |
| 1382 | blob_appendf(&x, "I %s\n", zI); |
| 1383 | fossil_free(zI); |
| 1384 | } |
| 1385 | if( fossil_strcmp(zMimetype,"text/x-fossil-wiki")!=0 ){ |
| 1386 | blob_appendf(&x, "N %s\n", zMimetype); |
| 1387 | } |
| 1388 | if( iEdit>0 ){ |
| 1389 | char *zP = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", iEdit); |
| 1390 | if( zP==0 ) webpage_error("missing edit artifact %d", iEdit); |
| 1391 | blob_appendf(&x, "P %s\n", zP); |
| @@ -1413,11 +1824,11 @@ | |
| 1413 | webpage_error("malformed forum post artifact - %s", blob_str(&errMsg)); |
| 1414 | } |
| 1415 | webpage_assert( pPost->type==CFTYPE_FORUM ); |
| 1416 | manifest_destroy(pPost); |
| 1417 | |
| 1418 | if( P("dryrun") ){ |
| 1419 | @ <div class='debug'> |
| 1420 | @ This is the artifact that would have been generated: |
| 1421 | @ <pre>%h(blob_str(&x))</pre> |
| 1422 | @ </div> |
| 1423 | blob_reset(&x); |
| @@ -1452,44 +1863,87 @@ | |
| 1452 | mimetype_option_menu(zMimetype, "mimetype"); |
| 1453 | @ <div class="forum-editor-widget"> |
| 1454 | @ <textarea aria-label="Content:" name="content" class="wikiedit" \ |
| 1455 | @ cols="80" rows="25" wrap="virtual">%h(zContent)</textarea></div> |
| 1456 | } |
| 1457 | |
| 1458 | /* |
| 1459 | ** WEBPAGE: forumpost_close hidden |
| 1460 | ** WEBPAGE: forumpost_reopen hidden |
| 1461 | ** |
| 1462 | ** fpid=X Hash of the post to be edited. REQUIRED |
| 1463 | ** reason=X Optional reason for closure. |
| 1464 | ** |
| 1465 | ** Closes or re-opens the given forum post, within the bounds of the |
| 1466 | ** API for forumpost_close(). After (perhaps) modifying the "closed" |
| 1467 | ** status of the given thread, it redirects to that post's thread |
| 1468 | ** view. Requires admin privileges. |
| 1469 | */ |
| 1470 | void forum_page_close(void){ |
| 1471 | const char *zFpid = PD("fpid",""); |
| 1472 | const char *zReason = 0; |
| 1473 | int fClose; |
| 1474 | int fpid; |
| 1475 | |
| 1476 | login_check_credentials(); |
| 1477 | if( forumpost_may_close()==0 ){ |
| 1478 | login_needed(g.anon.Admin); |
| 1479 | return; |
| 1480 | } |
| 1481 | cgi_csrf_verify(); |
| 1482 | fpid = symbolic_name_to_rid(zFpid, "f"); |
| 1483 | if( fpid<=0 ){ |
| 1484 | webpage_error("Missing or invalid fpid query parameter"); |
| 1485 | } |
| 1486 | fClose = sqlite3_strglob("*_close*", g.zPath)==0; |
| 1487 | if( fClose ) zReason = PD("reason",0); |
| 1488 | forumpost_close(fpid, fClose, zReason); |
| 1489 | cgi_redirectf("%R/forumpost/%S",zFpid); |
| 1490 | return; |
| 1491 | } |
| 1492 | |
| 1493 | /* |
| 1494 | ** WEBPAGE: forumnew |
| 1495 | ** WEBPAGE: forumedit |
| @@ -1578,11 +2032,25 @@ | |
| 1578 | @ </div> |
| 1579 | } |
| 1580 | } |
| 1581 | |
| 1582 | /* |
| 1583 | ** WEBPAGE: forume1 |
| 1584 | ** |
| 1585 | ** Start a new forum thread. |
| 1586 | */ |
| 1587 | void forumnew_page(void){ |
| 1588 | const char *zTitle = PDT("title",""); |
| @@ -1596,35 +2064,45 @@ | |
| 1596 | } |
| 1597 | if( P("submit") && cgi_csrf_safe(2) ){ |
| 1598 | if( forum_post(zTitle, 0, 0, 0, zMimetype, zContent, |
| 1599 | forum_post_flags()) ) return; |
| 1600 | } |
| 1601 | if( P("preview") && !whitespace_only(zContent) ){ |
| 1602 | @ <h1>Preview:</h1> |
| 1603 | forum_render(zTitle, zMimetype, zContent, "forumEdit", 1); |
| 1604 | } |
| 1605 | style_set_current_feature("forum"); |
| 1606 | style_header("New Forum Thread"); |
| 1607 | @ <form action="%R/forume1" method="POST"> |
| 1608 | @ <h1>New Thread:</h1> |
| 1609 | forum_from_line(); |
| 1610 | forum_post_widget(zTitle, zMimetype, zContent); |
| 1611 | @ <input type="submit" name="preview" value="Preview"> |
| 1612 | if( P("preview") && !whitespace_only(zContent) ){ |
| 1613 | @ <input type="submit" name="submit" value="Submit"> |
| 1614 | }else{ |
| 1615 | @ <input type="submit" name="submit" value="Submit" disabled> |
| 1616 | } |
| 1617 | forum_render_debug_options(); |
| 1618 | login_insert_csrf_secret(); |
| 1619 | @ </form> |
| 1620 | forum_emit_js(); |
| 1621 | style_finish_page(); |
| 1622 | } |
| 1623 | |
| 1624 | /* |
| 1625 | ** WEBPAGE: forume2 |
| 1626 | ** |
| 1627 | ** Edit an existing forum message. |
| 1628 | ** Query parameters: |
| 1629 | ** |
| 1630 | ** fpid=X Hash of the post to be edited. REQUIRED |
| @@ -1655,28 +2133,30 @@ | |
| 1655 | fpid = symbolic_name_to_rid(zFpid, "f"); |
| 1656 | if( fpid<=0 || (pPost = manifest_get(fpid, CFTYPE_FORUM, 0))==0 ){ |
| 1657 | webpage_error("Missing or invalid fpid query parameter"); |
| 1658 | } |
| 1659 | froot = db_int(0, "SELECT froot FROM forumpost WHERE fpid=%d", fpid); |
| 1660 | if( froot==0 || (pRootPost = manifest_get(froot, CFTYPE_FORUM, 0))==0 ){ |
| 1661 | webpage_error("fpid does not appear to be a forum post: \"%d\"", fpid); |
| 1662 | } |
| 1663 | if( P("cancel") ){ |
| 1664 | cgi_redirectf("%R/forumpost/%S",zFpid); |
| 1665 | return; |
| 1666 | } |
| 1667 | bPreview = P("preview")!=0; |
| 1668 | bReply = P("reply")!=0; |
| 1669 | iClosed = forum_rid_is_closed(fpid, 1); |
| 1670 | isCsrfSafe = cgi_csrf_safe(2); |
| 1671 | bPrivate = content_is_private(fpid); |
| 1672 | bSameUser = login_is_individual() |
| 1673 | && fossil_strcmp(pPost->zUser, g.zLogin)==0; |
| 1674 | if( isCsrfSafe && (g.perm.ModForum || (bPrivate && bSameUser)) ){ |
| 1675 | if( g.perm.ModForum && P("approve") ){ |
| 1676 | const char *zUserToTrust; |
| 1677 | moderation_approve('f', fpid); |
| 1678 | if( g.perm.AdminForum |
| 1679 | && PB("trust") |
| 1680 | && (zUserToTrust = P("trustuser"))!=0 |
| 1681 | ){ |
| 1682 | db_unprotect(PROTECT_USER); |
| @@ -1693,11 +2173,11 @@ | |
| 1693 | db_text(0, |
| 1694 | "SELECT uuid FROM forumpost, blob" |
| 1695 | " WHERE forumpost.fpid=%d AND blob.rid=forumpost.firt", |
| 1696 | fpid |
| 1697 | ); |
| 1698 | moderation_disapprove(fpid); |
| 1699 | if( zParent ){ |
| 1700 | cgi_redirectf("%R/forumpost/%S",zParent); |
| 1701 | }else{ |
| 1702 | cgi_redirectf("%R/forum"); |
| 1703 | } |
| @@ -1707,11 +2187,11 @@ | |
| 1707 | style_set_current_feature("forum"); |
| 1708 | isDelete = P("nullout")!=0; |
| 1709 | if( P("submit") |
| 1710 | && isCsrfSafe |
| 1711 | && (zContent = PDT("content",""))!=0 |
| 1712 | && (!whitespace_only(zContent) || isDelete) |
| 1713 | ){ |
| 1714 | int done = 1; |
| 1715 | const char *zMimetype = PD("mimetype",DEFAULT_FORUM_MIMETYPE); |
| 1716 | if( bReply ){ |
| 1717 | done = forum_post(0, fpid, 0, 0, zMimetype, zContent, |
| @@ -1785,11 +2265,11 @@ | |
| 1785 | zDisplayName = display_name_from_login(pPost->zUser); |
| 1786 | @ <h3 class='forumPostHdr'>By %s(zDisplayName) on %h(zDate)</h3> |
| 1787 | fossil_free(zDisplayName); |
| 1788 | fossil_free(zDate); |
| 1789 | forum_render(0, pPost->zMimetype, pPost->zWiki, "forumEdit", 1); |
| 1790 | if( bPreview && !whitespace_only(zContent) ){ |
| 1791 | @ <h2>Preview:</h2> |
| 1792 | forum_render(0, zMimetype,zContent, "forumEdit", 1); |
| 1793 | } |
| 1794 | @ <h2>Enter Reply:</h2> |
| 1795 | @ <form action="%R/forume2" method="POST"> |
| @@ -1800,18 +2280,24 @@ | |
| 1800 | } |
| 1801 | if( !isDelete ){ |
| 1802 | @ <input type="submit" name="preview" value="Preview"> |
| 1803 | } |
| 1804 | @ <input type="submit" name="cancel" value="Cancel"> |
| 1805 | if( (bPreview && !whitespace_only(zContent)) || isDelete ){ |
| 1806 | if( !iClosed || g.perm.Admin ) { |
| 1807 | @ <input type="submit" name="submit" value="Submit"> |
| 1808 | } |
| 1809 | } |
| 1810 | forum_render_debug_options(); |
| 1811 | login_insert_csrf_secret(); |
| 1812 | @ </form> |
| 1813 | forum_emit_js(); |
| 1814 | style_finish_page(); |
| 1815 | } |
| 1816 | |
| 1817 | /* |
| @@ -1818,17 +2304,34 @@ | |
| 1818 | ** SETTING: forum-close-policy boolean default=off |
| 1819 | ** If true, forum moderators may close/re-open forum posts, and reply |
| 1820 | ** to closed posts. If false, only administrators may do so. Note that |
| 1821 | ** this only affects the forum web UI, not post-closing tags which |
| 1822 | ** arrive via the command-line or from synchronization with a remote. |
| 1823 | */ |
| 1824 | /* |
| 1825 | ** SETTING: forum-title width=20 default=Forum |
| 1826 | ** This is the name or "title" of the Forum for this repository. The |
| 1827 | ** default is just "Forum". But in some setups, admins might want to |
| 1828 | ** change it to "Developer Forum" or "User Forum" or whatever other name |
| 1829 | ** seems more appropriate for the particular usage. |
| 1830 | */ |
| 1831 | |
| 1832 | /* |
| 1833 | ** WEBPAGE: setup_forum |
| 1834 | ** |
| @@ -1946,19 +2449,113 @@ | |
| 1946 | @ <a href='%R/help/%h(pSetting->name)'>%h(pSetting->name)</a>: |
| 1947 | @ </td><td> |
| 1948 | entry_attribute("", 25, pSetting->name, zQP/*works-like:""*/, |
| 1949 | pSetting->def, 0); |
| 1950 | @ </td></tr> |
| 1951 | } |
| 1952 | } |
| 1953 | @ </tbody></table> |
| 1954 | @ <input type='submit' name='submit' value='Apply changes'> |
| 1955 | @ </form> |
| 1956 | } |
| 1957 | |
| 1958 | style_finish_page(); |
| 1959 | } |
| 1960 | |
| 1961 | /* |
| 1962 | ** WEBPAGE: forummain |
| 1963 | ** WEBPAGE: forum |
| 1964 | ** |
| @@ -1975,30 +2572,38 @@ | |
| 1975 | void forum_main_page(void){ |
| 1976 | Stmt q; |
| 1977 | int iLimit = 0, iOfst, iCnt; |
| 1978 | int srchFlags; |
| 1979 | const int isSearch = P("s")!=0; |
| 1980 | char const *zLimit = 0; |
| 1981 | |
| 1982 | login_check_credentials(); |
| 1983 | srchFlags = search_restrict(SRCH_FORUM); |
| 1984 | if( !g.perm.RdForum ){ |
| 1985 | login_needed(g.anon.RdForum); |
| 1986 | return; |
| 1987 | } |
| 1988 | cgi_check_for_malice(); |
| 1989 | style_set_current_feature("forum"); |
| 1990 | style_header("%s%s", db_get("forum-title","Forum"), |
| 1991 | isSearch ? " Search Results" : ""); |
| 1992 | style_submenu_element("Timeline", "%R/timeline?ss=v&y=f&vfx"); |
| 1993 | if( g.perm.WrForum ){ |
| 1994 | style_submenu_element("New Thread","%R/forumnew"); |
| 1995 | }else{ |
| 1996 | /* Can't combine this with previous case using the ternary operator |
| 1997 | * because that causes an error yelling about "non-constant format" |
| 1998 | * with some compilers. I can't see it, since both expressions have |
| 1999 | * the same format, but I'm no C spec lawyer. */ |
| 2000 | style_submenu_element("New Thread","%R/login"); |
| 2001 | } |
| 2002 | if( g.perm.ModForum && moderation_needed() ){ |
| 2003 | style_submenu_element("Moderation Requests", "%R/modreq"); |
| 2004 | } |
| @@ -2021,95 +2626,577 @@ | |
| 2021 | cgi_replace_query_parameter("n", fossil_strdup("25")) |
| 2022 | /*for the sake of Max, below*/; |
| 2023 | iLimit = 25; |
| 2024 | } |
| 2025 | style_submenu_entry("n","Max:",4,0); |
| 2026 | iOfst = atoi(PD("x","0")); |
| 2027 | iCnt = 0; |
| 2028 | if( db_table_exists("repository","forumpost") ){ |
| 2029 | db_prepare(&q, |
| 2030 | "WITH thread(age,duration,cnt,root,last) AS (" |
| 2031 | " SELECT" |
| 2032 | " julianday('now') - max(fmtime)," |
| 2033 | " max(fmtime) - min(fmtime)," |
| 2034 | " sum(fprev IS NULL)," |
| 2035 | " froot," |
| 2036 | " (SELECT fpid FROM forumpost AS y" |
| 2037 | " WHERE y.froot=x.froot %s" |
| 2038 | " ORDER BY y.fmtime DESC LIMIT 1)" |
| 2039 | " FROM forumpost AS x" |
| 2040 | " WHERE %s" |
| 2041 | " GROUP BY froot" |
| 2042 | " ORDER BY 1 LIMIT %d OFFSET %d" |
| 2043 | ")" |
| 2044 | "SELECT" |
| 2045 | " thread.age," /* 0 */ |
| 2046 | " thread.duration," /* 1 */ |
| 2047 | " thread.cnt," /* 2 */ |
| 2048 | " blob.uuid," /* 3 */ |
| 2049 | " substr(event.comment,instr(event.comment,':')+1)," /* 4 */ |
| 2050 | " thread.last" /* 5 */ |
| 2051 | " FROM thread, blob, event" |
| 2052 | " WHERE blob.rid=thread.last" |
| 2053 | " AND event.objid=thread.last" |
| 2054 | " ORDER BY 1;", |
| 2055 | g.perm.ModForum ? "" : "AND y.fpid NOT IN private" /*safe-for-%s*/, |
| 2056 | g.perm.ModForum ? "true" : "fpid NOT IN private" /*safe-for-%s*/, |
| 2057 | iLimit+1, iOfst |
| 2058 | ); |
| 2059 | while( db_step(&q)==SQLITE_ROW ){ |
| 2060 | char *zAge = human_readable_age(db_column_double(&q,0)); |
| 2061 | int nMsg = db_column_int(&q, 2); |
| 2062 | const char *zUuid = db_column_text(&q, 3); |
| 2063 | const char *zTitle = db_column_text(&q, 4); |
| 2064 | if( iCnt==0 ){ |
| 2065 | if( iOfst>0 ){ |
| 2066 | @ <h1>Threads at least %s(zAge) old</h1> |
| 2067 | }else{ |
| 2068 | @ <h1>Most recent threads</h1> |
| 2069 | } |
| 2070 | @ <div class='forumPosts fileage'><table width="100%%"> |
| 2071 | if( iOfst>0 ){ |
| 2072 | if( iOfst>iLimit ){ |
| 2073 | @ <tr><td colspan="3">\ |
| 2074 | @ %z(href("%R/forum?x=%d&n=%d",iOfst-iLimit,iLimit))\ |
| 2075 | @ ↑ Newer...</a></td></tr> |
| 2076 | }else{ |
| 2077 | @ <tr><td colspan="3">%z(href("%R/forum?n=%d",iLimit))\ |
| 2078 | @ ↑ Newer...</a></td></tr> |
| 2079 | } |
| 2080 | } |
| 2081 | } |
| 2082 | iCnt++; |
| 2083 | if( iCnt>iLimit ){ |
| 2084 | @ <tr><td colspan="3">\ |
| 2085 | @ %z(href("%R/forum?x=%d&n=%d",iOfst+iLimit,iLimit))\ |
| 2086 | @ ↓ Older...</a></td></tr> |
| 2087 | fossil_free(zAge); |
| 2088 | break; |
| 2089 | } |
| 2090 | @ <tr><td>%h(zAge) ago</td> |
| 2091 | @ <td>%z(href("%R/forumpost/%S",zUuid))%h(zTitle)</a></td> |
| 2092 | @ <td>\ |
| 2093 | if( g.perm.ModForum && moderation_pending(db_column_int(&q,5)) ){ |
| 2094 | @ <span class="modpending">\ |
| 2095 | @ Awaiting Moderator Approval</span><br> |
| 2096 | } |
| 2097 | if( nMsg<2 ){ |
| 2098 | @ no replies</td> |
| 2099 | }else{ |
| 2100 | char *zDuration = human_readable_age(db_column_double(&q,1)); |
| 2101 | @ %d(nMsg) posts spanning %h(zDuration)</td> |
| 2102 | fossil_free(zDuration); |
| 2103 | } |
| 2104 | @ </tr> |
| 2105 | fossil_free(zAge); |
| 2106 | } |
| 2107 | db_finalize(&q); |
| 2108 | } |
| 2109 | if( iCnt>0 ){ |
| 2110 | @ </table></div> |
| 2111 | }else{ |
| 2112 | @ <h1>No forum posts found</h1> |
| 2113 | } |
| 2114 | style_finish_page(); |
| 2115 | } |
| 2116 | |
| 2117 | DDED src/fossil.attach.js |
| --- src/forum.c | |
| +++ src/forum.c | |
| @@ -49,11 +49,11 @@ | |
| 49 | ForumPost *pNext; /* Next in chronological order */ |
| 50 | ForumPost *pPrev; /* Previous in chronological order */ |
| 51 | ForumPost *pDisplay; /* Next in display order */ |
| 52 | int nEdit; /* Number of edits to this post */ |
| 53 | int nIndent; /* Number of levels of indentation for this post */ |
| 54 | int iClosed; /* True if forum_rid_is_tagged("closed") */ |
| 55 | }; |
| 56 | |
| 57 | /* |
| 58 | ** A single instance of the following tracks all entries for a thread. |
| 59 | */ |
| @@ -63,12 +63,134 @@ | |
| 63 | ForumPost *pDisplay; /* Entries in display order */ |
| 64 | ForumPost *pTail; /* Last on the display list */ |
| 65 | int mxIndent; /* Maximum indentation level */ |
| 66 | int nArtifact; /* Number of forum artifacts in this thread */ |
| 67 | }; |
| 68 | |
| 69 | /* |
| 70 | ** A single entry from the forum-statuses setting. |
| 71 | */ |
| 72 | struct ForumStatus { |
| 73 | char *zLabel; /* Label for the UI */ |
| 74 | char *zValue; /* status=X tag value */ |
| 75 | }; |
| 76 | |
| 77 | /* |
| 78 | ** A list of ForumStatus objects. |
| 79 | */ |
| 80 | struct ForumStatusList { |
| 81 | struct ForumStatus *aStatus; /* List of statuses */ |
| 82 | unsigned int n; /* Number of entries */ |
| 83 | }; |
| 84 | |
| 85 | /* |
| 86 | ** Information passed into the status_match() SQL function |
| 87 | ** via the sqlite3_user_data() mechanism, and used by status_match() |
| 88 | ** to determine whether or not a particular forum thread should |
| 89 | ** be displayed. |
| 90 | */ |
| 91 | struct ForumStatusMatch { |
| 92 | const ForumStatusList *pFses; /* Parsed forum-statuses setting */ |
| 93 | int eStatusTag; /* tagid for the "status" property */ |
| 94 | unsigned int iMatch; /* Match this status value */ |
| 95 | }; |
| 96 | #endif /* INTERFACE */ |
| 97 | |
| 98 | |
| 99 | /* |
| 100 | ** Returns a high-level representation of the forum-statuses setting. |
| 101 | ** This is a singleton, cached across calls. |
| 102 | */ |
| 103 | const ForumStatusList * forum_statuses(void){ |
| 104 | static ForumStatusList fses = {0,0}; |
| 105 | static int once = 0; |
| 106 | while( !once ){ |
| 107 | ++once; |
| 108 | /* Read `forum-statuses` setting and transform it into the |
| 109 | ** fses object. |
| 110 | ** |
| 111 | ** Maybe: if it's empty, synthesize a length-1 list from |
| 112 | ** {value:"default",label:"Default",...}. It's expected that |
| 113 | ** usage may be slightly simplified if we always have a non-empty |
| 114 | ** list. A length-1 list is, for purposes of the UI, identical to |
| 115 | ** an empty one - status selection/filtering makes no sense if |
| 116 | ** there's only one choice. */ |
| 117 | db_multi_exec( |
| 118 | "CREATE TEMP TABLE IF NOT EXISTS forumstatus(" |
| 119 | " ord INTEGER PRIMARY KEY, label, value" |
| 120 | ");" |
| 121 | "DELETE FROM forumstatus;" |
| 122 | "INSERT INTO forumstatus(label,value)" |
| 123 | " WITH setting(v) AS (" |
| 124 | " SELECT value v FROM config WHERE name='forum-statuses'" |
| 125 | " )," |
| 126 | " room(r) AS (" |
| 127 | " SELECT e.value FROM setting s, jsonb_each(s.v) e" |
| 128 | " WHERE json_valid(s.v, 0x02)" |
| 129 | " )" |
| 130 | " SELECT r->>'label', r->>'value'" |
| 131 | " FROM room;" |
| 132 | ); |
| 133 | fses.n = (unsigned)db_int(0, "SELECT count(*) FROM forumstatus"); |
| 134 | if( fses.n ){ |
| 135 | int i = 0; |
| 136 | Stmt q; |
| 137 | db_prepare(&q,"SELECT label, value FROM forumstatus" |
| 138 | " ORDER BY ord"); |
| 139 | fses.aStatus = fossil_malloc(sizeof(fses.aStatus[0]) * fses.n); |
| 140 | while( SQLITE_ROW==db_step(&q) ){ |
| 141 | ForumStatus * fs = &fses.aStatus[i++]; |
| 142 | fs->zLabel = fossil_strdup(db_column_text(&q, 0)); |
| 143 | fs->zValue = fossil_strdup(db_column_text(&q, 1)); |
| 144 | } |
| 145 | db_finalize(&q); |
| 146 | } |
| 147 | } |
| 148 | return &fses; |
| 149 | } |
| 150 | |
| 151 | /* |
| 152 | ** Search for a ForumStatus object by its tag value. If a match is |
| 153 | ** found, the corresponding object is returned. If no match is found |
| 154 | ** then (A) if bFirst is false then 0 is returned, else (B) the first |
| 155 | ** entry in the list is returned, noting that the list may be empty, |
| 156 | ** in which case 0 is returned. |
| 157 | */ |
| 158 | static const ForumStatus * forum_status_by_value( |
| 159 | const char *z, int bFirst |
| 160 | ){ |
| 161 | const ForumStatusList * const fses = forum_statuses(); |
| 162 | const ForumStatus * fs0 = 0; |
| 163 | unsigned int i; |
| 164 | if( !fses->n ) return 0; |
| 165 | for( i = 0; i < fses->n; ++i ){ |
| 166 | const ForumStatus * fs = &fses->aStatus[i]; |
| 167 | if( 0==fossil_strcmp(z, fs->zValue) ){ |
| 168 | return fs; |
| 169 | }else if( !fs0 ){ |
| 170 | fs0 = fs; |
| 171 | } |
| 172 | } |
| 173 | return bFirst ? fs0 : 0; |
| 174 | } |
| 175 | |
| 176 | /* |
| 177 | ** COMMAND: test-forum-statuses |
| 178 | */ |
| 179 | void test_forum_statuses_cmd(void){ |
| 180 | const ForumStatusList * fses; |
| 181 | unsigned i; |
| 182 | db_find_and_open_repository(0,0); |
| 183 | fses = forum_statuses(); |
| 184 | for(i = 0; i < fses->n; ++i ){ |
| 185 | const ForumStatus * fs = &fses->aStatus[i]; |
| 186 | fossil_print("Status: %!j %!j\n", fs->zValue, fs->zLabel); |
| 187 | assert( fs==forum_status_by_value(fs->zValue, 0) ); |
| 188 | } |
| 189 | fossil_print("Total statuses: %u\n", i); |
| 190 | } |
| 191 | |
| 192 | /* |
| 193 | ** Return true if the forum post with the given rid has been |
| 194 | ** subsequently edited. |
| 195 | */ |
| 196 | int forum_rid_has_been_edited(int rid){ |
| @@ -83,29 +205,68 @@ | |
| 205 | db_reset(&q); |
| 206 | return res; |
| 207 | } |
| 208 | |
| 209 | /* |
| 210 | ** Given a valid forumpost.fpid value, this function returns the |
| 211 | ** initial forumpost.fpid in the chain of edits for that forum post, |
| 212 | ** or rid if no prior versions are found. |
| 213 | */ |
| 214 | int forumpost_head_rid(int rid){ |
| 215 | static Stmt q = empty_Stmt_m; |
| 216 | int rcRid = rid; |
| 217 | if( !q.pStmt ){ |
| 218 | db_static_prepare(&q, |
| 219 | "SELECT fprev FROM forumpost" |
| 220 | " WHERE fpid=:rid AND fprev IS NOT NULL" |
| 221 | ); |
| 222 | } |
| 223 | db_bind_int(&q, ":rid", rid); |
| 224 | while( SQLITE_ROW==db_step(&q) ){ |
| 225 | rcRid = db_column_int(&q, 0); |
| 226 | db_reset(&q); |
| 227 | db_bind_int(&q, ":rid", rcRid); |
| 228 | } |
| 229 | db_reset(&q); |
| 230 | return rcRid; |
| 231 | } |
| 232 | |
| 233 | /* |
| 234 | ** Works like forumpost_head_rid() but expects zUuid to be an |
| 235 | ** unambiguous forum post name. It may be a hash prefix, so long as |
| 236 | ** it's unambiguous. Returns the rid of the head post, -1 if the name |
| 237 | ** is ambiguous, and 0 if the name cannot be resolved as a forum post. |
| 238 | */ |
| 239 | int forumpost_head_rid2(const char *zUuid){ |
| 240 | const int fpid = symbolic_name_to_rid(zUuid, "f"); |
| 241 | return fpid>0 |
| 242 | ? forumpost_head_rid(fpid) |
| 243 | : fpid; |
| 244 | } |
| 245 | |
| 246 | /* |
| 247 | ** Given a forum post RID and user name, returns true if zUserName |
| 248 | ** matches the event.(euser,user) field for a formpost entry with the |
| 249 | ** matching RID. Returns false if no match is found. If zUserName is |
| 250 | ** 0 then login_name() is used. |
| 251 | */ |
| 252 | int forumpost_is_owner(int rid, const char *zUserName){ |
| 253 | static Stmt q; |
| 254 | int rc; |
| 255 | if( !q.pStmt ){ |
| 256 | db_static_prepare( |
| 257 | &q, "SELECT 1 FROM event" |
| 258 | " WHERE type='f' AND objid=$rid" |
| 259 | " AND coalesce(euser,user)=$user" |
| 260 | ); |
| 261 | } |
| 262 | db_bind_int(&q, "$rid", rid); |
| 263 | db_bind_text(&q, "$user", zUserName ? zUserName : login_name()); |
| 264 | rc = SQLITE_ROW==db_step(&q); |
| 265 | db_reset(&q); |
| 266 | return rc; |
| 267 | } |
| 268 | |
| 269 | /* |
| 270 | ** Returns true if p, or any parent of p, has a non-zero iClosed |
| 271 | ** value. Returns 0 if !p. For an edited chain of post, the tag is |
| 272 | ** checked on the pEditHead entry, to simplify subsequent unlocking of |
| @@ -128,39 +289,39 @@ | |
| 289 | return 0; |
| 290 | } |
| 291 | |
| 292 | /* |
| 293 | ** Given a forum post RID, this function returns true if that post has |
| 294 | ** (or inherits) an active tag named zTagName. If bCheckIrt is true |
| 295 | ** then the post to which the given post responds is also checked |
| 296 | ** (recursively), else they are not. When checking in-response-to |
| 297 | ** posts, the first one which is closed ends the search. |
| 298 | ** |
| 299 | ** This function checks _exactly_ the given rid, whereas forum post |
| 300 | ** closure/re-opening is always applied to the head of an edit chain |
| 301 | ** so that we get consistent implied locking behavior for later |
| 302 | ** versions and responses to arbitrary versions in the chain. Even so, |
| 303 | ** the "closed" tag is applied as a propagating tag so will apply to |
| 304 | ** all edits in a given chain. |
| 305 | ** |
| 306 | ** The return value is one of: |
| 307 | ** |
| 308 | ** - 0 if no matching tag is found. |
| 309 | ** |
| 310 | ** - The tagxref.rowid of the tagxref entry for the closure if rid is |
| 311 | ** the forum post to which the closure applies. |
| 312 | ** |
| 313 | ** - (-tagxref.rowid) if the given rid inherits the tag from an IRT |
| 314 | ** forum post. |
| 315 | */ |
| 316 | static int forum_rid_is_tagged(int rid, const char *zTagName, int bCheckIrt){ |
| 317 | static Stmt qIrt = empty_Stmt_m; |
| 318 | int rc = 0, i = 0; |
| 319 | /* TODO: this can probably be turned into a CTE by someone with |
| 320 | ** superior SQL-fu. */ |
| 321 | for( ; rid; i++ ){ |
| 322 | rc = rid_has_active_tag_name(rid, zTagName); |
| 323 | if( rc || !bCheckIrt ) break; |
| 324 | else if( !qIrt.pStmt ) { |
| 325 | db_static_prepare(&qIrt, |
| 326 | "SELECT firt FROM forumpost " |
| 327 | "WHERE fpid=$fpid ORDER BY fmtime DESC" |
| @@ -171,105 +332,211 @@ | |
| 332 | db_reset(&qIrt); |
| 333 | } |
| 334 | return i ? -rc : rc; |
| 335 | } |
| 336 | |
| 337 | /* True if moderation of forum posts performs the same operation |
| 338 | ** on its attachments. */ |
| 339 | #define FORUMPOST_MOD_ATTACHMENTS 1 |
| 340 | #if FORUMPOST_MOD_ATTACHMENTS |
| 341 | /* |
| 342 | ** Internal helper for moderation_forumpost_...(). |
| 343 | */ |
| 344 | static void forumpost_prep_pending_attachids(Stmt *q, int fpid){ |
| 345 | db_prepare( |
| 346 | q, |
| 347 | "SELECT attachid FROM attachment " |
| 348 | "WHERE target=(" |
| 349 | " SELECT uuid FROM blob WHERE rid=%d" |
| 350 | ") and attachid in (" |
| 351 | " SELECT objid FROM modreq" |
| 352 | ")", |
| 353 | forumpost_head_rid(fpid) |
| 354 | ); |
| 355 | } |
| 356 | #endif |
| 357 | |
| 358 | /* |
| 359 | ** Approve the given forum post RID and any pending-approval |
| 360 | ** attachments associated with its initial version. |
| 361 | */ |
| 362 | static void moderation_forumpost_approve(int fpid){ |
| 363 | #if !FORUMPOST_MOD_ATTACHMENTS |
| 364 | moderation_approve('f', fpid); |
| 365 | #else |
| 366 | /* Also approve any pending attachments */ |
| 367 | Stmt q; |
| 368 | moderation_approve('f', fpid); |
| 369 | forumpost_prep_pending_attachids(&q, fpid); |
| 370 | while( SQLITE_ROW==db_step(&q) ){ |
| 371 | moderation_approve('a', db_column_int(&q, 0)); |
| 372 | } |
| 373 | db_finalize(&q); |
| 374 | #endif |
| 375 | } |
| 376 | |
| 377 | /* |
| 378 | ** Disapprove the given forum post and any pending-moderation |
| 379 | ** attachments on its initial version. |
| 380 | */ |
| 381 | static void moderation_forumpost_disapprove(int fpid){ |
| 382 | #if !FORUMPOST_MOD_ATTACHMENTS |
| 383 | moderation_disapprove(fpid); |
| 384 | #else |
| 385 | /* Also disapprove any pending attachments */ |
| 386 | Stmt q; |
| 387 | moderation_disapprove(fpid); |
| 388 | forumpost_prep_pending_attachids(&q, fpid); |
| 389 | while( SQLITE_ROW==db_step(&q) ){ |
| 390 | moderation_disapprove(db_column_int(&q, 0)); |
| 391 | } |
| 392 | db_finalize(&q); |
| 393 | #endif |
| 394 | } |
| 395 | #undef FORUMPOST_MOD_ATTACHMENTS |
| 396 | |
| 397 | /* |
| 398 | ** Applies or cancels a tag named zTagName on the given forum RID via |
| 399 | ** addition of a new control artifact into the repository. In order to |
| 400 | ** provide consistent behavior, it always acts on the first version of |
| 401 | ** the given forum post, walking the forumpost.fprev values to find |
| 402 | ** the head of the chain. |
| 403 | ** |
| 404 | ** If addTag is true then a propagating tag is added, except as noted |
| 405 | ** below, with the given optional zValue string as the tag's |
| 406 | ** value. If addTag is false then any matching active tag on frid is |
| 407 | ** cancelled, except as noted below. zValue is ignored if it is NULL |
| 408 | ** or starts with a NUL byte, or if addTag is false. |
| 409 | ** |
| 410 | ** This function only adds a tag if forum_rid_is_tagged() indicates |
| 411 | ** that frid's head is not tagged. If a parent post is already tagged, |
| 412 | ** no tag is added. Similarly, it will only remove a tag from a post |
| 413 | ** which has its own tag, and will not remove an inherited one from a |
| 414 | ** parent post. |
| 415 | ** |
| 416 | ** If addTag is true and frid is already tagged, this is a |
| 417 | ** no-op. Likewise, if addTag is false and frid is not tagged (not |
| 418 | ** accounting for a tag inherited via an in-response-to post), this is |
| 419 | ** a no-op. |
| 420 | ** |
| 421 | ** Returns a positive value (a new tag.tagid value) if it actually |
| 422 | ** creates a new tag, else 0. On error it returns a negative alue |
| 423 | ** and g.zErrMsg "should" contain details. |
| 424 | ** |
| 425 | ** If it returns true then state from previously-loaded posts may be |
| 426 | ** invalidated if they refer to the amended post or a response to it. |
| 427 | ** e.g. if zTagName is "closed" then ForumPost::iClosed values may be |
| 428 | ** stale. |
| 429 | ** |
| 430 | ** Sidebars: |
| 431 | ** |
| 432 | ** - Unless the caller has a transaction open, via |
| 433 | ** db_begin_transaction(), there is a very tiny race condition |
| 434 | ** window during which the caller's idea of whether or not the forum |
| 435 | ** post is tagged may differ from the current repository state. |
| 436 | ** |
| 437 | ** - This routine assumes that frid really does refer to a forum post. |
| 438 | ** |
| 439 | ** - This routine assumes that frid is not private or pending |
| 440 | ** moderation. |
| 441 | ** |
| 442 | ** - The applied tag is propagating so so that "closed" tags can |
| 443 | ** account for how edits of posts are handled. This differs from |
| 444 | ** closure of a branch, where a non-propagating tag is used. |
| 445 | */ |
| 446 | static int forumpost_tag(int frid, int addTag, |
| 447 | const char *zTagName, |
| 448 | const char *zValue){ |
| 449 | Blob artifact = BLOB_INITIALIZER; /* Output artifact */ |
| 450 | Blob cksum = BLOB_INITIALIZER; /* Z-card */ |
| 451 | int iTagged; /* true if frid is already tagged */ |
| 452 | int trid; /* RID of new control artifact */ |
| 453 | char *zUuid; /* UUID of head version of post */ |
| 454 | |
| 455 | db_begin_transaction(); |
| 456 | frid = forumpost_head_rid(frid); |
| 457 | iTagged = forum_rid_is_tagged(frid, zTagName, 0); |
| 458 | if( !addTag && !iTagged ){ |
| 459 | /* Nothing to do. We never tag an IRT-inherited post via this |
| 460 | ** function. */ |
| 461 | db_end_transaction(0); |
| 462 | return 0; |
| 463 | } |
| 464 | if( !addTag || (zValue && !zValue[0]) ){ |
| 465 | zValue = 0; |
| 466 | } |
| 467 | if( addTag && iTagged ){ |
| 468 | char *zOld = 0; |
| 469 | int cmp; |
| 470 | rid_has_tag2(frid, zTagName, &zOld); |
| 471 | cmp = fossil_strcmp(zOld, zValue); |
| 472 | fossil_free(zOld); |
| 473 | if( 0==cmp ){ |
| 474 | /* Same value - leave it as is. */ |
| 475 | db_end_transaction(0); |
| 476 | return 0; |
| 477 | } |
| 478 | } |
| 479 | zUuid = rid_to_uuid(frid); |
| 480 | blob_appendf(&artifact, "D %z\n", date_in_standard_format( "now" )); |
| 481 | blob_appendf(&artifact, "T %c%s %s%s%F\n", |
| 482 | addTag ? '*' : '-', zTagName, |
| 483 | zUuid, zValue ? " " : "", zValue ? zValue : ""); |
| 484 | blob_appendf(&artifact, "U %F\n", login_name()); |
| 485 | md5sum_blob(&artifact, &cksum); |
| 486 | blob_appendf(&artifact, "Z %b\n", &cksum); |
| 487 | blob_reset(&cksum); |
| 488 | trid = content_put_ex(&artifact, 0, 0, 0, 0); |
| 489 | if( trid==0 ){ |
| 490 | return -1; |
| 491 | } |
| 492 | if( manifest_crosslink(trid, &artifact, MC_NONE)==0 ){ |
| 493 | return -2; |
| 494 | } |
| 495 | assert( blob_is_reset(&artifact) ); |
| 496 | db_add_unsent(trid); |
| 497 | admin_log("Tag forum post %S with %c%s", |
| 498 | zUuid, addTag ? '*' : '-', zTagName); |
| 499 | fossil_free(zUuid); |
| 500 | db_end_transaction(0); |
| 501 | return trid; |
| 502 | } |
| 503 | |
| 504 | /* |
| 505 | ** COMMAND: test-forumpost-tag |
| 506 | ** |
| 507 | ** Usage: %fossil test-forumpost-tag ?-cancel? THREADID TAGNAME TAGVAL |
| 508 | ** |
| 509 | ** A tester for forumpost_tag(). It always rolls back changes. |
| 510 | */ |
| 511 | void test_forumpost_tag_command(void){ |
| 512 | int fpid; |
| 513 | int rc; |
| 514 | const char *zPost; |
| 515 | const char *zTag; |
| 516 | const char *zVal; |
| 517 | const int bAdd = find_option("cancel","",0)==0; |
| 518 | |
| 519 | db_find_and_open_repository(0,0); |
| 520 | verify_all_options(); |
| 521 | if( g.argc<5 ){ |
| 522 | usage("forum-post-id tag-name value"); |
| 523 | } |
| 524 | zPost = g.argv[2]; |
| 525 | zTag = g.argv[3]; |
| 526 | zVal = g.argv[4]; |
| 527 | |
| 528 | db_begin_transaction(); |
| 529 | fpid = forumpost_head_rid2(zPost); |
| 530 | if( fpid<=0 ){ |
| 531 | fossil_fatal("Cannot resolve post ID %s", zPost); |
| 532 | } |
| 533 | fossil_print("%s => %d => %z\n", zTag, fpid, |
| 534 | rid_to_uuid(fpid)); |
| 535 | rc = forumpost_tag(fpid, bAdd, zTag, zVal); |
| 536 | fossil_print("tag fpid=%d taxgxref.tagid=%d\n", fpid, rc); |
| 537 | db_end_transaction(1); |
| 538 | } |
| 539 | |
| 540 | /* |
| 541 | ** Returns true if the forum-close-policy setting is true, else false, |
| 542 | ** caching the result for subsequent calls. |
| @@ -285,12 +552,15 @@ | |
| 552 | |
| 553 | /* |
| 554 | ** Returns 1 if the current user is an admin, -1 if the current user |
| 555 | ** is a forum moderator and the forum-close-policy setting is true, |
| 556 | ** else returns 0. The value is cached for subsequent calls. |
| 557 | ** |
| 558 | ** This policy also determines whether non-admin forum moderators |
| 559 | ** may delete forum attachments. |
| 560 | */ |
| 561 | int forumpost_may_close(void){ |
| 562 | static int permClose = -99; |
| 563 | if( permClose!=-99 ){ |
| 564 | return permClose; |
| 565 | }else if( g.perm.Admin ){ |
| 566 | return permClose = 1; |
| @@ -445,13 +715,13 @@ | |
| 715 | for(; p; p=p->pEditPrev ){ |
| 716 | p->nEdit = pPost->nEdit; |
| 717 | p->pEditTail = pPost; |
| 718 | } |
| 719 | } |
| 720 | pPost->iClosed = forum_rid_is_tagged(pPost->pEditHead |
| 721 | ? pPost->pEditHead->fpid |
| 722 | : pPost->fpid, "closed", 1); |
| 723 | } |
| 724 | db_finalize(&q); |
| 725 | |
| 726 | if( computeHierarchy ){ |
| 727 | /* Compute the hierarchical display order */ |
| @@ -629,10 +899,80 @@ | |
| 899 | } |
| 900 | @ </table> |
| 901 | db_finalize(&q); |
| 902 | style_finish_page(); |
| 903 | } |
| 904 | |
| 905 | /* |
| 906 | ** Returns true if the current user is authorized to set forum post |
| 907 | ** fpid's status. |
| 908 | */ |
| 909 | static int forum_may_set_status(int fpid){ |
| 910 | if( moderation_pending(fpid) ) return 0; |
| 911 | return g.perm.Admin |
| 912 | || g.perm.ModForum |
| 913 | || (login_is_individual() |
| 914 | && forumpost_is_owner(fpid, 0)); |
| 915 | } |
| 916 | |
| 917 | /* |
| 918 | ** If the current user is authorized to set fp's status then this |
| 919 | ** renders a mini-form for setting the status then redirecting back to |
| 920 | ** the post. Else it may emit a status label or no output. |
| 921 | */ |
| 922 | static void forum_render_status_selection( const ForumPost *fp ){ |
| 923 | const ForumStatusList * const fss = forum_statuses(); |
| 924 | if( fss->n>1 ){ |
| 925 | const ForumPost * pHead = fp->pEditHead ? fp->pEditHead : fp; |
| 926 | int i; |
| 927 | char * zCurrent = 0; |
| 928 | const ForumStatus * sCurrent = 0; |
| 929 | rid_has_tag2(pHead->fpid, "status", &zCurrent); |
| 930 | for( i = 0; i < fss->n; ++i ){ |
| 931 | const ForumStatus * const fs = &fss->aStatus[i]; |
| 932 | if( 0==fossil_strcmp(zCurrent, fs->zValue) ){ |
| 933 | sCurrent = fs; |
| 934 | break; |
| 935 | } |
| 936 | } |
| 937 | if( !sCurrent ) sCurrent = &fss->aStatus[0]; |
| 938 | assert( sCurrent ); |
| 939 | @ <fieldset class='forum-status-selection'>\ |
| 940 | @ <legend>Status \ |
| 941 | @ <span class='help-buttonlet initially-hidden'>\ |
| 942 | @ Moderators and the post's owner may change \ |
| 943 | @ the status of this thread unless it is still. \ |
| 944 | @ pending moderation. See \ |
| 945 | @ <a href='%R/help/forum-statuses' target='_new'>\ |
| 946 | @ /help/forum-statuses</a></span>\ |
| 947 | @ </legend>\ |
| 948 | if( forum_may_set_status(fp->fpid) ){ |
| 949 | @ <form method="post" action='%R/forumpost_status'> |
| 950 | login_insert_csrf_secret(); |
| 951 | @ <input type='hidden' name='fpid' value='%s(fp->zUuid)' /> |
| 952 | @ <select name='status' data-fpid='%s(fp->zUuid)'\ |
| 953 | @ data-initial-value='%h(zCurrent ? zCurrent : "")'> |
| 954 | for( i = 0; i < fss->n; ++i ){ |
| 955 | const ForumStatus * const fs = &fss->aStatus[i]; |
| 956 | @ <option value='%h(fs->zValue)'\ |
| 957 | @ %s(sCurrent==fs ? " selected" : "")>\ |
| 958 | @ %h(fs->zLabel)</option> |
| 959 | } |
| 960 | @ </select> |
| 961 | @ <input type='button' class='submit action-status' disabled |
| 962 | @ value='Change' /> |
| 963 | /* ^^^ This must be <input>, not <button>, or else tapping it |
| 964 | ** will unconditionally submit. */ |
| 965 | @ </form> |
| 966 | /* Form is activated in fossil.page.forumpost.js */ |
| 967 | }else{ |
| 968 | @ <button disabled>Status: %h(sCurrent->zLabel)</button> |
| 969 | } |
| 970 | @ </fieldset> |
| 971 | fossil_free(zCurrent); |
| 972 | } |
| 973 | } |
| 974 | |
| 975 | /* |
| 976 | ** Render a forum post for display |
| 977 | */ |
| 978 | void forum_render( |
| @@ -760,22 +1100,55 @@ | |
| 1100 | if( pToFree ) manifest_destroy(pToFree); |
| 1101 | if( p->zDisplayName==0 ) return "(unknown)"; |
| 1102 | return p->zDisplayName; |
| 1103 | } |
| 1104 | |
| 1105 | /* |
| 1106 | ** Renders the attachment list for the given forum post. |
| 1107 | ** Emits no output if there are no attachments. |
| 1108 | */ |
| 1109 | static void forum_render_attachment_list(const char *zUuid){ |
| 1110 | #if 1 |
| 1111 | attachment_list(zUuid, "📎 Attachments", 0 |
| 1112 | | ATTACHLIST_SIZE |
| 1113 | | ATTACHLIST_HIDE_UNAPPROVED |
| 1114 | | ATTACHLIST_DETAILS_CLOSED |
| 1115 | | ATTACHLIST_HIDE_EMPTY); |
| 1116 | #else |
| 1117 | char * zLbl = mprintf("<a href='%R/attachlist?forumpost=%!S'>" |
| 1118 | "Attachments</a>:", zUuid); |
| 1119 | attachment_list(zUuid, zLbl, |
| 1120 | ATTACHLIST_HRULE_ABOVE |
| 1121 | | ATTACHLIST_SIZE |
| 1122 | | ATTACHLIST_HIDE_UNAPPROVED |
| 1123 | | ATTACHLIST_HIDE_EMPTY); |
| 1124 | fossil_free(zLbl); |
| 1125 | #endif |
| 1126 | } |
| 1127 | |
| 1128 | /* |
| 1129 | ** Renders the attachment list for p or (if not NULL) pEditHead. |
| 1130 | */ |
| 1131 | static void forum_render_attachment_list2(ForumPost *p){ |
| 1132 | if( p->pEditHead ) p = p->pEditHead; |
| 1133 | forum_render_attachment_list(p->zUuid); |
| 1134 | } |
| 1135 | |
| 1136 | /* Flags for use with forum_display_post() */ |
| 1137 | #define FDISPLAY_RAW 0x01 /* omit the border */ |
| 1138 | #define FDISPLAY_UNFORMATTED 0x02 /* leave the post unformatted */ |
| 1139 | #define FDISPLAY_HISTORY 0x04 /* Showing edit history */ |
| 1140 | #define FDISPLAY_SELECTED 0x08 /* This is the selected post */ |
| 1141 | |
| 1142 | /* |
| 1143 | ** Display a single post in a forum thread. |
| 1144 | */ |
| 1145 | static void forum_display_post( |
| 1146 | ForumThread *pThread, /* The thread that this post is a member of */ |
| 1147 | ForumPost *p, /* Forum post to display */ |
| 1148 | int iIndentScale, /* Indent scale factor */ |
| 1149 | int flags, /* From the FDISPLAY_... enum */ |
| 1150 | char *zQuery /* Common query string */ |
| 1151 | ){ |
| 1152 | char *zPosterName; /* Name of user who originally made this post */ |
| 1153 | char *zEditorName; /* Name of user who provided the current edit */ |
| 1154 | char *zDate; /* The time/date string */ |
| @@ -784,30 +1157,43 @@ | |
| 1157 | Manifest *pManifest; /* Manifest comprising the current post */ |
| 1158 | int bPrivate; /* True for posts awaiting moderation */ |
| 1159 | int bSameUser; /* True if author is also the reader */ |
| 1160 | int iIndent; /* Indent level */ |
| 1161 | int iClosed; /* True if (sub)thread is closed */ |
| 1162 | const int bRaw = flags & FDISPLAY_RAW; |
| 1163 | const int bUnf = flags & FDISPLAY_UNFORMATTED; |
| 1164 | const int bHist = flags & FDISPLAY_HISTORY; |
| 1165 | const int bSelect = flags & FDISPLAY_SELECTED; |
| 1166 | const char *zMimetype;/* Formatting MIME type */ |
| 1167 | |
| 1168 | /* Get the manifest for the post. Abort if not found (e.g. shunned). */ |
| 1169 | pManifest = manifest_get(p->fpid, CFTYPE_FORUM, 0); |
| 1170 | if( !pManifest ) return; |
| 1171 | iClosed = forumpost_is_closed(pThread, p, 1); |
| 1172 | bPrivate = content_is_private(p->fpid); |
| 1173 | bSameUser = login_is_individual() |
| 1174 | && fossil_strcmp(pManifest->zUser, g.zLogin)==0; |
| 1175 | /* When not in raw mode, create the border around the post. */ |
| 1176 | if( !bRaw ){ |
| 1177 | /* Open the <div> enclosing the post. Set the class string to mark the post |
| 1178 | ** as selected and/or obsolete. */ |
| 1179 | iIndent = (p->pEditHead ? p->pEditHead->nIndent : p->nIndent)-1; |
| 1180 | @ <div id='forum%d(p->fpid)' class='forumpost forumTime\ |
| 1181 | @ %s(bSelect ? " forumSel" : "")\ |
| 1182 | @ %s(iClosed ? " forumClosed" : "")\ |
| 1183 | @ %s(p->pEditTail ? " forumObs" : "")' \ |
| 1184 | if( iIndent && iIndentScale ){ |
| 1185 | @ style='margin-left:%d(iIndent*iIndentScale)ex;' \ |
| 1186 | } |
| 1187 | /* These data-X fields are used by the JS editor. */ |
| 1188 | if( p->pIrt ){ |
| 1189 | @ data-firt="%s(p->pIrt->zUuid)" \ |
| 1190 | } |
| 1191 | if( p->pEditHead ){ |
| 1192 | @ data-fedithead="%s(p->pEditHead->zUuid)" \ |
| 1193 | } |
| 1194 | @ data-fpid="%s(p->zUuid)">\ |
| 1195 | |
| 1196 | /* If this is the first post (or an edit thereof), emit the thread title. */ |
| 1197 | if( pManifest->zThreadTitle ){ |
| 1198 | @ <h1>%h(pManifest->zThreadTitle)</h1> |
| 1199 | } |
| @@ -888,18 +1274,18 @@ | |
| 1274 | /* Provide a link to the raw source code. */ |
| 1275 | if( !bUnf ){ |
| 1276 | @ %z(href("%R/forumpost/%!S?raw",p->zUuid))[source]</a> |
| 1277 | } |
| 1278 | @ </h3> |
| 1279 | |
| 1280 | if( bPrivate && (bSameUser || g.perm.Admin || g.perm.ModForum) ){ |
| 1281 | moderation_pending_www(p->fpid); |
| 1282 | } |
| 1283 | }/*!bRaw*/ |
| 1284 | |
| 1285 | /* Check if this post is approved, also if it's by the current user. |
| 1286 | Render the post if the user is able to see it. */ |
| 1287 | if( bPrivate && !g.perm.ModForum && !bSameUser ){ |
| 1288 | @ <p><span class="modpending">Awaiting Moderator Approval</span></p> |
| 1289 | }else{ |
| 1290 | if( bRaw || bUnf || p->pEditTail ){ |
| 1291 | zMimetype = "text/plain"; |
| @@ -909,10 +1295,12 @@ | |
| 1295 | forum_render(0, zMimetype, pManifest->zWiki, 0, !bRaw); |
| 1296 | } |
| 1297 | |
| 1298 | /* When not in raw mode, finish creating the border around the post. */ |
| 1299 | if( !bRaw ){ |
| 1300 | int bBrBeforeAttach = 0; /* Layout kludge for Attach button */ |
| 1301 | forum_render_attachment_list2(p); |
| 1302 | /* If the user is able to write to the forum and if this post has not been |
| 1303 | ** edited, create a form with various interaction buttons. */ |
| 1304 | if( g.perm.WrForum && !p->pEditTail ){ |
| 1305 | @ <div class="forumpost-single-controls">\ |
| 1306 | @ <form action="%R/forumedit" method="POST"> |
| @@ -941,33 +1329,52 @@ | |
| 1329 | @ <br><label><input type="checkbox" name="trust"> |
| 1330 | @ Trust user "%h(pManifest->zUser)" so that future posts by \ |
| 1331 | @ "%h(pManifest->zUser)" do not require moderation. |
| 1332 | @ </label> |
| 1333 | @ <input type="hidden" name="trustuser" value="%h(pManifest->zUser)"> |
| 1334 | bBrBeforeAttach = 1 /* slightly unmangle the layout */; |
| 1335 | } |
| 1336 | }else if( bSameUser ){ |
| 1337 | /* Allow users to delete (reject) their own pending posts. */ |
| 1338 | @ <input type="submit" name="reject" value="Delete"> |
| 1339 | } |
| 1340 | login_insert_csrf_secret(); |
| 1341 | @ </form> |
| 1342 | |
| 1343 | if( bSelect ){ |
| 1344 | const ForumPost *pHead = p->pEditHead ? p->pEditHead : p; |
| 1345 | if( !bPrivate && forumpost_may_close() && iClosed>=0 ){ |
| 1346 | @ <form method="post" \ |
| 1347 | @ action='%R/forumpost_%s(iClosed > 0 ? "reopen" : "close")'> |
| 1348 | login_insert_csrf_secret(); |
| 1349 | @ <input type="hidden" name="fpid" value="%s(p->zUuid)" /> |
| 1350 | if( moderation_pending(p->fpid)==0 ){ |
| 1351 | @ <input type="button" value='%s(iClosed ? "Re-open" : "Close")' \ |
| 1352 | @ class='submit hidden \ |
| 1353 | @ %s(iClosed ? "action-reopen" : "action-close")'/> |
| 1354 | /* ^^^ activated by fossil.page.forumpost.js */ |
| 1355 | } |
| 1356 | @ </form> |
| 1357 | } |
| 1358 | if( attach_user_may(p/*not pHead*/->fpid, CFTYPE_FORUM) ){ |
| 1359 | /* When an admin edits someone else's post, the admin |
| 1360 | ** effectively takes over ownership of it (and we currently |
| 1361 | ** have no way of passing it back). Because of this, we |
| 1362 | ** check the ownership of `p` instead of `pHead`. */ |
| 1363 | if( bBrBeforeAttach ){ |
| 1364 | @ <br> |
| 1365 | } |
| 1366 | attach_render_attachadd_button(pHead->zUuid); |
| 1367 | } |
| 1368 | } |
| 1369 | @ </div> |
| 1370 | } |
| 1371 | if( !p->pIrt && (flags & FDISPLAY_SELECTED)){ |
| 1372 | forum_render_status_selection(p); |
| 1373 | } |
| 1374 | @ </div> |
| 1375 | }/*!bRaw*/ |
| 1376 | |
| 1377 | /* Clean up. */ |
| 1378 | manifest_destroy(pManifest); |
| 1379 | } |
| 1380 | |
| @@ -1077,12 +1484,18 @@ | |
| 1484 | } |
| 1485 | |
| 1486 | /* Display the appropriate subset of posts in sequence. */ |
| 1487 | while( p ){ |
| 1488 | /* Display the post. */ |
| 1489 | forum_display_post( |
| 1490 | pThread, p, iIndentScale, |
| 1491 | (mode==FD_RAW ? FDISPLAY_RAW : 0) | |
| 1492 | (bUnf ? FDISPLAY_UNFORMATTED : 0) | |
| 1493 | (bHist ? FDISPLAY_HISTORY : 0) | |
| 1494 | (p==pSelect ? FDISPLAY_SELECTED : 0), |
| 1495 | zQuery |
| 1496 | ); |
| 1497 | |
| 1498 | /* Advance to the next post in the thread. */ |
| 1499 | if( mode==FD_CHRONO ){ |
| 1500 | /* Chronological mode: display posts (optionally including edits) in their |
| 1501 | ** original commit order. */ |
| @@ -1138,11 +1551,12 @@ | |
| 1551 | ** to all forum-related pages. It does not include page-specific |
| 1552 | ** code (e.g. "forum.js"). |
| 1553 | */ |
| 1554 | static void forum_emit_js(void){ |
| 1555 | builtin_fossil_js_bundle_or("copybutton", "pikchr", "confirmer", |
| 1556 | "attach", "tabs", "storage", |
| 1557 | "popupwidget", NULL); |
| 1558 | builtin_request_js("fossil.page.forumpost.js"); |
| 1559 | } |
| 1560 | |
| 1561 | /* |
| 1562 | ** WEBPAGE: forumpost |
| @@ -1291,28 +1705,20 @@ | |
| 1705 | } |
| 1706 | |
| 1707 | /* |
| 1708 | ** Return true if a forum post should be moderated. |
| 1709 | */ |
| 1710 | int forum_need_moderation(void){ |
| 1711 | if( P("domod") ) return 1; |
| 1712 | if( g.perm.WrTForum ) return 0; |
| 1713 | if( g.perm.ModForum ) return 0; |
| 1714 | return 1; |
| 1715 | } |
| 1716 | |
| 1717 | /* Flags for use with forum_post() */ |
| 1718 | #define FPOST_NO_ALERT 1 /* do not send any alerts */ |
| 1719 | #define FPOST_DRYRUN 2 /* do not save the artifact */ |
| 1720 | |
| 1721 | /* |
| 1722 | ** Return a flags value for use with the final argument to |
| 1723 | ** forum_post(), extracted from the CGI environment. |
| 1724 | */ |
| @@ -1319,10 +1725,13 @@ | |
| 1725 | static int forum_post_flags(void){ |
| 1726 | int iPostFlags = 0; |
| 1727 | if( g.perm.Debug && P("fpsilent")!=0 ){ |
| 1728 | iPostFlags |= FPOST_NO_ALERT; |
| 1729 | } |
| 1730 | if( P("dryrun")!=0 ){ |
| 1731 | iPostFlags |= FPOST_DRYRUN; |
| 1732 | } |
| 1733 | return iPostFlags; |
| 1734 | } |
| 1735 | |
| 1736 | /* |
| 1737 | ** Add a new Forum Post artifact to the repository. |
| @@ -1346,15 +1755,15 @@ | |
| 1755 | Manifest *pPost; |
| 1756 | int nContent = zContent ? (int)strlen(zContent) : 0; |
| 1757 | |
| 1758 | schema_forum(); |
| 1759 | if( !g.perm.Admin && (iEdit || iInReplyTo) |
| 1760 | && forum_rid_is_tagged(iEdit ? iEdit : iInReplyTo, "closed", 1) ){ |
| 1761 | forumpost_error_closed(); |
| 1762 | return 0; |
| 1763 | } |
| 1764 | if( iEdit==0 && fossil_all_whitespace(zContent) ){ |
| 1765 | return 0; |
| 1766 | } |
| 1767 | if( iInReplyTo==0 && iEdit>0 ){ |
| 1768 | iBasis = iEdit; |
| 1769 | iInReplyTo = db_int(0, "SELECT firt FROM forumpost WHERE fpid=%d", iEdit); |
| @@ -1375,17 +1784,19 @@ | |
| 1784 | fossil_free(zG); |
| 1785 | } |
| 1786 | if( zTitle ){ |
| 1787 | blob_appendf(&x, "H %F\n", zTitle); |
| 1788 | } |
| 1789 | zI = rid_to_uuid(iInReplyTo); |
| 1790 | if( zI ){ |
| 1791 | blob_appendf(&x, "I %s\n", zI); |
| 1792 | fossil_free(zI); |
| 1793 | } |
| 1794 | if( zMimetype!=0 |
| 1795 | && zMimetype[0]!=0 |
| 1796 | && fossil_strcmp(zMimetype,"text/x-fossil-wiki")!=0 ){ |
| 1797 | blob_appendf(&x, "N %F\n", zMimetype); |
| 1798 | } |
| 1799 | if( iEdit>0 ){ |
| 1800 | char *zP = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", iEdit); |
| 1801 | if( zP==0 ) webpage_error("missing edit artifact %d", iEdit); |
| 1802 | blob_appendf(&x, "P %s\n", zP); |
| @@ -1413,11 +1824,11 @@ | |
| 1824 | webpage_error("malformed forum post artifact - %s", blob_str(&errMsg)); |
| 1825 | } |
| 1826 | webpage_assert( pPost->type==CFTYPE_FORUM ); |
| 1827 | manifest_destroy(pPost); |
| 1828 | |
| 1829 | if( (iFlags & FPOST_DRYRUN)!=0 ){ |
| 1830 | @ <div class='debug'> |
| 1831 | @ This is the artifact that would have been generated: |
| 1832 | @ <pre>%h(blob_str(&x))</pre> |
| 1833 | @ </div> |
| 1834 | blob_reset(&x); |
| @@ -1452,44 +1863,87 @@ | |
| 1863 | mimetype_option_menu(zMimetype, "mimetype"); |
| 1864 | @ <div class="forum-editor-widget"> |
| 1865 | @ <textarea aria-label="Content:" name="content" class="wikiedit" \ |
| 1866 | @ cols="80" rows="25" wrap="virtual">%h(zContent)</textarea></div> |
| 1867 | } |
| 1868 | |
| 1869 | /* |
| 1870 | ** If PD("fpid") refers to a forum post, its rid is returned, else |
| 1871 | ** this function emits an error does not does return. |
| 1872 | */ |
| 1873 | static int forum_validate_fpid_param(void){ |
| 1874 | const char *zFpid = PD("fpid",""); |
| 1875 | int fpid = symbolic_name_to_rid(zFpid, "f"); |
| 1876 | if( fpid<=0 ){ |
| 1877 | webpage_error("Missing or invalid fpid parameter."); |
| 1878 | } |
| 1879 | return fpid; |
| 1880 | } |
| 1881 | |
| 1882 | /* |
| 1883 | ** Internal helper for /forumpost_XYZ internal pages which tag/untag |
| 1884 | ** posts. |
| 1885 | */ |
| 1886 | static void forumpost_action_helper(const char *zTag, const char *zVal, |
| 1887 | int addTag, int validFpid){ |
| 1888 | if( !cgi_csrf_safe(2) ){ |
| 1889 | webpage_error("CSRF validation failed"); |
| 1890 | }else{ |
| 1891 | const int fpid = validFpid>0 ? validFpid : forum_validate_fpid_param(); |
| 1892 | if( fpid>0 ){ |
| 1893 | if( forumpost_tag(fpid, addTag, zTag, zVal) < 0 ){ |
| 1894 | webpage_error("Tagging artifact failed: %s", g.zErrMsg); |
| 1895 | }else{ |
| 1896 | cgi_redirectf("%R/forumpost/%S",P("fpid")); |
| 1897 | } |
| 1898 | } |
| 1899 | } |
| 1900 | } |
| 1901 | |
| 1902 | /* |
| 1903 | ** WEBPAGE: forumpost_close hidden |
| 1904 | ** WEBPAGE: forumpost_reopen hidden |
| 1905 | ** |
| 1906 | ** fpid=X Hash of the post to be edited. REQUIRED |
| 1907 | ** |
| 1908 | ** Closes or re-opens the given forum post, within the bounds of the |
| 1909 | ** API for forumpost_tag(). After (perhaps) modifying the "closed" |
| 1910 | ** status of the given thread, it redirects to that post's thread |
| 1911 | ** view. Requires admin privileges. |
| 1912 | */ |
| 1913 | void forum_page_close(void){ |
| 1914 | login_check_credentials(); |
| 1915 | if( forumpost_may_close()==0 ){ |
| 1916 | login_needed(g.anon.Admin); |
| 1917 | }else{ |
| 1918 | const int bIsAdd = sqlite3_strglob("*_close*", g.zPath)==0; |
| 1919 | forumpost_action_helper("closed", 0, bIsAdd, 0); |
| 1920 | } |
| 1921 | } |
| 1922 | |
| 1923 | /* |
| 1924 | ** WEBPAGE: forumpost_status hidden |
| 1925 | ** |
| 1926 | ** fpid=X Hash of the post to be edited. REQUIRED |
| 1927 | ** status=Y New status value. REQUIRED |
| 1928 | ** |
| 1929 | ** Updates the current status=Y tag on the first version of |
| 1930 | ** the forum post X. Requires forum_may_set_status() permissions. |
| 1931 | */ |
| 1932 | void forum_page_status(void){ |
| 1933 | int fpid; |
| 1934 | login_check_credentials(); |
| 1935 | fpid = forum_validate_fpid_param(); |
| 1936 | if(forum_may_set_status(fpid)){ |
| 1937 | const char *zStatus = PD("status",0); |
| 1938 | if( !zStatus || !zStatus[0] ){ |
| 1939 | webpage_error("Missing required status."); |
| 1940 | } |
| 1941 | forumpost_action_helper("status", zStatus, 1, fpid); |
| 1942 | }else{ |
| 1943 | webpage_error("You lack permissions to change this post's status."); |
| 1944 | } |
| 1945 | } |
| 1946 | |
| 1947 | /* |
| 1948 | ** WEBPAGE: forumnew |
| 1949 | ** WEBPAGE: forumedit |
| @@ -1578,11 +2032,25 @@ | |
| 2032 | @ </div> |
| 2033 | } |
| 2034 | } |
| 2035 | |
| 2036 | /* |
| 2037 | ** If the user has AttachForum permissions, emit a notice that |
| 2038 | ** attachments may be added after saving. If p is not NULL, also emit |
| 2039 | ** its list of attachments. We only emit this for No-JS environments, |
| 2040 | ** as in JS environments the interactive forum editor includes |
| 2041 | ** attachment support. |
| 2042 | */ |
| 2043 | static void forum_render_attachment_notice(void){ |
| 2044 | if( g.perm.AttachForum ){ |
| 2045 | @ <noscript><div>You will be able to attach files to this post |
| 2046 | @ after saving it.</div></noscript> |
| 2047 | } |
| 2048 | } |
| 2049 | |
| 2050 | /* |
| 2051 | ** WEBPAGE: forume1 hidden |
| 2052 | ** |
| 2053 | ** Start a new forum thread. |
| 2054 | */ |
| 2055 | void forumnew_page(void){ |
| 2056 | const char *zTitle = PDT("title",""); |
| @@ -1596,35 +2064,45 @@ | |
| 2064 | } |
| 2065 | if( P("submit") && cgi_csrf_safe(2) ){ |
| 2066 | if( forum_post(zTitle, 0, 0, 0, zMimetype, zContent, |
| 2067 | forum_post_flags()) ) return; |
| 2068 | } |
| 2069 | if( P("preview") && !fossil_all_whitespace(zContent) ){ |
| 2070 | @ <h1>Preview:</h1> |
| 2071 | forum_render(zTitle, zMimetype, zContent, "forumEdit", 1); |
| 2072 | } |
| 2073 | style_set_current_feature("forum"); |
| 2074 | style_header("New Forum Thread"); |
| 2075 | |
| 2076 | @ <form action="%R/forume1" method="POST" \ |
| 2077 | @ class="remove-if-replaced"> |
| 2078 | @ <h1>New Thread:</h1> |
| 2079 | forum_from_line(); |
| 2080 | forum_post_widget(zTitle, zMimetype, zContent); |
| 2081 | @ <input type="submit" name="preview" value="Preview"> |
| 2082 | if( P("preview") && !fossil_all_whitespace(zContent) ){ |
| 2083 | @ <input type="submit" name="submit" value="Submit"> |
| 2084 | }else{ |
| 2085 | @ <input type="submit" name="submit" value="Submit" disabled> |
| 2086 | } |
| 2087 | forum_render_debug_options(); |
| 2088 | login_insert_csrf_secret(); |
| 2089 | @ </form> |
| 2090 | /* When JS is disabled the block above will work. When it's |
| 2091 | enabled, the above will be removed and JS will render the editor |
| 2092 | form in the next element. */ |
| 2093 | @ <div hidden id='forumnew-placeholder'> |
| 2094 | @ <input type='hidden' name='title' value='%h(zTitle)'> |
| 2095 | login_insert_csrf_secret(); |
| 2096 | @ </div> |
| 2097 | forum_render_attachment_notice(); |
| 2098 | forum_emit_js(); |
| 2099 | style_finish_page(); |
| 2100 | } |
| 2101 | |
| 2102 | /* |
| 2103 | ** WEBPAGE: forume2 hidden |
| 2104 | ** |
| 2105 | ** Edit an existing forum message. |
| 2106 | ** Query parameters: |
| 2107 | ** |
| 2108 | ** fpid=X Hash of the post to be edited. REQUIRED |
| @@ -1655,28 +2133,30 @@ | |
| 2133 | fpid = symbolic_name_to_rid(zFpid, "f"); |
| 2134 | if( fpid<=0 || (pPost = manifest_get(fpid, CFTYPE_FORUM, 0))==0 ){ |
| 2135 | webpage_error("Missing or invalid fpid query parameter"); |
| 2136 | } |
| 2137 | froot = db_int(0, "SELECT froot FROM forumpost WHERE fpid=%d", fpid); |
| 2138 | if( (froot==0 || (pRootPost = manifest_get(froot, CFTYPE_FORUM, 0))==0) |
| 2139 | && P("reject")==0 |
| 2140 | ){ |
| 2141 | webpage_error("fpid does not appear to be a forum post: \"%d\"", fpid); |
| 2142 | } |
| 2143 | if( P("cancel") ){ |
| 2144 | cgi_redirectf("%R/forumpost/%S",zFpid); |
| 2145 | return; |
| 2146 | } |
| 2147 | bPreview = P("preview")!=0; |
| 2148 | bReply = P("reply")!=0; |
| 2149 | iClosed = forum_rid_is_tagged(fpid, "closed", 1); |
| 2150 | isCsrfSafe = cgi_csrf_safe(2); |
| 2151 | bPrivate = content_is_private(fpid); |
| 2152 | bSameUser = login_is_individual() |
| 2153 | && fossil_strcmp(pPost->zUser, g.zLogin)==0; |
| 2154 | if( isCsrfSafe && (g.perm.ModForum || (bPrivate && bSameUser)) ){ |
| 2155 | if( g.perm.ModForum && P("approve") ){ |
| 2156 | const char *zUserToTrust; |
| 2157 | moderation_forumpost_approve(fpid); |
| 2158 | if( g.perm.AdminForum |
| 2159 | && PB("trust") |
| 2160 | && (zUserToTrust = P("trustuser"))!=0 |
| 2161 | ){ |
| 2162 | db_unprotect(PROTECT_USER); |
| @@ -1693,11 +2173,11 @@ | |
| 2173 | db_text(0, |
| 2174 | "SELECT uuid FROM forumpost, blob" |
| 2175 | " WHERE forumpost.fpid=%d AND blob.rid=forumpost.firt", |
| 2176 | fpid |
| 2177 | ); |
| 2178 | moderation_forumpost_disapprove(fpid); |
| 2179 | if( zParent ){ |
| 2180 | cgi_redirectf("%R/forumpost/%S",zParent); |
| 2181 | }else{ |
| 2182 | cgi_redirectf("%R/forum"); |
| 2183 | } |
| @@ -1707,11 +2187,11 @@ | |
| 2187 | style_set_current_feature("forum"); |
| 2188 | isDelete = P("nullout")!=0; |
| 2189 | if( P("submit") |
| 2190 | && isCsrfSafe |
| 2191 | && (zContent = PDT("content",""))!=0 |
| 2192 | && (isDelete || !fossil_all_whitespace(zContent)) |
| 2193 | ){ |
| 2194 | int done = 1; |
| 2195 | const char *zMimetype = PD("mimetype",DEFAULT_FORUM_MIMETYPE); |
| 2196 | if( bReply ){ |
| 2197 | done = forum_post(0, fpid, 0, 0, zMimetype, zContent, |
| @@ -1785,11 +2265,11 @@ | |
| 2265 | zDisplayName = display_name_from_login(pPost->zUser); |
| 2266 | @ <h3 class='forumPostHdr'>By %s(zDisplayName) on %h(zDate)</h3> |
| 2267 | fossil_free(zDisplayName); |
| 2268 | fossil_free(zDate); |
| 2269 | forum_render(0, pPost->zMimetype, pPost->zWiki, "forumEdit", 1); |
| 2270 | if( bPreview && !fossil_all_whitespace(zContent) ){ |
| 2271 | @ <h2>Preview:</h2> |
| 2272 | forum_render(0, zMimetype,zContent, "forumEdit", 1); |
| 2273 | } |
| 2274 | @ <h2>Enter Reply:</h2> |
| 2275 | @ <form action="%R/forume2" method="POST"> |
| @@ -1800,18 +2280,24 @@ | |
| 2280 | } |
| 2281 | if( !isDelete ){ |
| 2282 | @ <input type="submit" name="preview" value="Preview"> |
| 2283 | } |
| 2284 | @ <input type="submit" name="cancel" value="Cancel"> |
| 2285 | if( isDelete || (bPreview && !fossil_all_whitespace(zContent)) ){ |
| 2286 | if( !iClosed || g.perm.Admin ) { |
| 2287 | @ <input type="submit" name="submit" value="Submit"> |
| 2288 | } |
| 2289 | } |
| 2290 | forum_render_debug_options(); |
| 2291 | login_insert_csrf_secret(); |
| 2292 | @ </form> |
| 2293 | if( !bReply ){ |
| 2294 | forum_render_attachment_list(rid_to_uuid(fpid)); |
| 2295 | } |
| 2296 | if( !isDelete ){ |
| 2297 | forum_render_attachment_notice(); |
| 2298 | } |
| 2299 | forum_emit_js(); |
| 2300 | style_finish_page(); |
| 2301 | } |
| 2302 | |
| 2303 | /* |
| @@ -1818,17 +2304,34 @@ | |
| 2304 | ** SETTING: forum-close-policy boolean default=off |
| 2305 | ** If true, forum moderators may close/re-open forum posts, and reply |
| 2306 | ** to closed posts. If false, only administrators may do so. Note that |
| 2307 | ** this only affects the forum web UI, not post-closing tags which |
| 2308 | ** arrive via the command-line or from synchronization with a remote. |
| 2309 | ** This policy also determines whether moderators may delete forum |
| 2310 | ** attachments. |
| 2311 | ** |
| 2312 | ** SETTING: forum-title width=20 default=Forum |
| 2313 | ** This is the name or "title" of the Forum for this repository. The |
| 2314 | ** default is just "Forum". But in some setups, admins might want to |
| 2315 | ** change it to "Developer Forum" or "User Forum" or whatever other name |
| 2316 | ** seems more appropriate for the particular usage. |
| 2317 | ** |
| 2318 | ** SETTING: attachment-size-limit width=16 |
| 2319 | ** The maximum number of bytes for an attachment to a wiki page, |
| 2320 | ** ticket, tech note, or forum post. The default (or 0) is unlimited |
| 2321 | ** but a limit may be imposed by the web server or a proxy. |
| 2322 | ** |
| 2323 | ** SETTING: forum-statuses width=40 block-text |
| 2324 | ** This JSON5-formatted value defines an array of objects describing |
| 2325 | ** the available statuses of forum posts. Each entry of the array must |
| 2326 | ** be an object in the form {label:"X",value:"Y"}. |
| 2327 | ** The label is used in the UI and value becomes the value of the |
| 2328 | ** "status" tag on forum posts. Any forum post which has a status |
| 2329 | ** value which does not appear in this list is treated as if it had |
| 2330 | ** the first value from this list. If this setting is empty, is |
| 2331 | ** ill-formed JSON, or has only a single entry then the forum will |
| 2332 | ** lack the capability of setting and filtering by status. |
| 2333 | */ |
| 2334 | |
| 2335 | /* |
| 2336 | ** WEBPAGE: setup_forum |
| 2337 | ** |
| @@ -1946,19 +2449,113 @@ | |
| 2449 | @ <a href='%R/help/%h(pSetting->name)'>%h(pSetting->name)</a>: |
| 2450 | @ </td><td> |
| 2451 | entry_attribute("", 25, pSetting->name, zQP/*works-like:""*/, |
| 2452 | pSetting->def, 0); |
| 2453 | @ </td></tr> |
| 2454 | } |
| 2455 | } |
| 2456 | @ </tbody></table> |
| 2457 | @ <input type='submit' name='submit' value='Apply changes'> |
| 2458 | @ </form> |
| 2459 | } |
| 2460 | |
| 2461 | style_finish_page(); |
| 2462 | } |
| 2463 | |
| 2464 | /* |
| 2465 | ** If the forum-statuses setting is active and has 2 or more entries, |
| 2466 | ** this adds a submenu for selecting the status filter, else it emits |
| 2467 | ** nothing. |
| 2468 | */ |
| 2469 | static void forum_status_submenu(void){ |
| 2470 | const ForumStatusList * const fss = forum_statuses(); |
| 2471 | static int i = 0; |
| 2472 | static const char **az; |
| 2473 | if( i==0 && fss->n>1 ){ |
| 2474 | unsigned j; |
| 2475 | az = fossil_malloc(sizeof(az[0]) * ((1 + fss->n) * 2)); |
| 2476 | az[i++] = "*"; |
| 2477 | az[i++] = "Any status"; |
| 2478 | for( j = 0; j < fss->n; ++j ){ |
| 2479 | const ForumStatus * fs = &fss->aStatus[j]; |
| 2480 | /* Potential TODO: skip any entries for which there are no |
| 2481 | ** forum posts with a status=${fs->zValue} tag. */ |
| 2482 | az[i++] = fs->zValue; |
| 2483 | az[i++] = fs->zLabel; |
| 2484 | } |
| 2485 | //assert( i==(1+fss->n)*2 ); |
| 2486 | } |
| 2487 | if( i ){ |
| 2488 | cookie_link_parameter("status","forumStatus","*"); |
| 2489 | style_submenu_multichoice("status", i/2, az, 0); |
| 2490 | } |
| 2491 | } |
| 2492 | |
| 2493 | /* |
| 2494 | ** Transient SQL Function: status_match(FROOT) |
| 2495 | ** |
| 2496 | ** Return true if the forum thread identified by FROOT should be included |
| 2497 | ** in a list of threads. Used to implement the status=NAME query parameter |
| 2498 | ** on /forum. |
| 2499 | ** |
| 2500 | ** The result of this routine depends on the content of the |
| 2501 | ** ForumStatusMatch *pMData object that is available via sqlite3_user_data(). |
| 2502 | ** |
| 2503 | ** * If pMData==NULL, always return true. This means that no |
| 2504 | ** filtering of threads is being done. This is the common case. |
| 2505 | ** |
| 2506 | ** * If FROOT contains a status property value that matches |
| 2507 | ** pMData->iMatch, return true. |
| 2508 | ** |
| 2509 | ** * if pMData->iMatch==0 (meaning we want to match the default |
| 2510 | ** status value) and if the FROOT thread contains a status that |
| 2511 | ** is not on the list of statuses or if FROOT has no statue |
| 2512 | ** property at all, then return true. In other words, a forum |
| 2513 | ** thread with no status property or an unknown status property |
| 2514 | ** is treated as if it had the default status. |
| 2515 | ** |
| 2516 | ** * Otherwise, return false. |
| 2517 | */ |
| 2518 | static void forum_status_match( |
| 2519 | sqlite3_context *context, |
| 2520 | int argc, |
| 2521 | sqlite3_value **argv |
| 2522 | ){ |
| 2523 | static Stmt q; |
| 2524 | ForumStatusMatch *pMData = sqlite3_user_data(context); |
| 2525 | int i; |
| 2526 | |
| 2527 | if( pMData==0 ){ |
| 2528 | sqlite3_result_int(context, 1); |
| 2529 | return; |
| 2530 | } |
| 2531 | db_static_prepare(&q, |
| 2532 | "SELECT value FROM tagxref\n" |
| 2533 | " WHERE tagid=%d\n" |
| 2534 | " AND tagtype>=1\n" |
| 2535 | " AND rid=:rid\n" |
| 2536 | " ORDER BY mtime DESC LIMIT 1", |
| 2537 | pMData->eStatusTag |
| 2538 | ); |
| 2539 | db_bind_int(&q, ":rid", sqlite3_value_int(argv[0])); |
| 2540 | if( db_step(&q)==SQLITE_ROW ){ |
| 2541 | const char *zValue = (const char*)db_column_text(&q,0); |
| 2542 | const ForumStatusList *pFses = pMData->pFses; |
| 2543 | if( zValue==0 ){ |
| 2544 | i = 0; |
| 2545 | }else{ |
| 2546 | for(i=0; i<pFses->n; i++){ |
| 2547 | if( fossil_strcmp(pFses->aStatus[i].zValue,zValue)==0 ) break; |
| 2548 | } |
| 2549 | } |
| 2550 | if( i>=pMData->pFses->n ) i = 0; |
| 2551 | }else{ |
| 2552 | i = 0; |
| 2553 | } |
| 2554 | db_reset(&q); |
| 2555 | sqlite3_result_int(context, i==pMData->iMatch); |
| 2556 | } |
| 2557 | |
| 2558 | /* |
| 2559 | ** WEBPAGE: forummain |
| 2560 | ** WEBPAGE: forum |
| 2561 | ** |
| @@ -1975,30 +2572,38 @@ | |
| 2572 | void forum_main_page(void){ |
| 2573 | Stmt q; |
| 2574 | int iLimit = 0, iOfst, iCnt; |
| 2575 | int srchFlags; |
| 2576 | const int isSearch = P("s")!=0; |
| 2577 | const char *zStatusFilter; |
| 2578 | char const *zLimit = 0; /* Value of the n= query parameter */ |
| 2579 | int eStatusTag = 0; /* tagid for the "status" property */ |
| 2580 | int bHasStatus = 0; /* True if forum-statuses setting exists */ |
| 2581 | int bFilter = 0; /* True if status=NAME query parameter */ |
| 2582 | int bHasForum = 0; /* True if forumpost table exists */ |
| 2583 | const ForumStatusList *pFstat = forum_statuses(); |
| 2584 | ForumStatusMatch sFSM; /* Aux data to status_match() SQL function */ |
| 2585 | |
| 2586 | login_check_credentials(); |
| 2587 | srchFlags = search_restrict(SRCH_FORUM); |
| 2588 | if( !g.perm.RdForum ){ |
| 2589 | login_needed(g.anon.RdForum); |
| 2590 | return; |
| 2591 | } |
| 2592 | cgi_check_for_malice(); |
| 2593 | bHasForum = db_table_exists("repository","forumpost"); |
| 2594 | if( bHasForum ){ |
| 2595 | eStatusTag = db_int(0, "SELECT tagid FROM tag WHERE tagname='status'"); |
| 2596 | bHasStatus = pFstat->n>1; |
| 2597 | } |
| 2598 | style_set_current_feature("forum"); |
| 2599 | style_header("%s%s", db_get("forum-title","Forum"), |
| 2600 | isSearch ? " Search Results" : ""); |
| 2601 | style_submenu_element("Timeline", "%R/timeline?ss=v&y=f&vfx"); |
| 2602 | if( g.perm.WrForum ){ |
| 2603 | style_submenu_element("New Thread","%R/forumnew"); |
| 2604 | }else{ |
| 2605 | style_submenu_element("New Thread","%R/login"); |
| 2606 | } |
| 2607 | if( g.perm.ModForum && moderation_needed() ){ |
| 2608 | style_submenu_element("Moderation Requests", "%R/modreq"); |
| 2609 | } |
| @@ -2021,95 +2626,577 @@ | |
| 2626 | cgi_replace_query_parameter("n", fossil_strdup("25")) |
| 2627 | /*for the sake of Max, below*/; |
| 2628 | iLimit = 25; |
| 2629 | } |
| 2630 | style_submenu_entry("n","Max:",4,0); |
| 2631 | forum_status_submenu(); |
| 2632 | zStatusFilter = P("status") /*must be after forum_status_submenu()!*/; |
| 2633 | iOfst = atoi(PD("x","0")); |
| 2634 | iCnt = 0; |
| 2635 | if( zStatusFilter ){ |
| 2636 | if( zStatusFilter[0]==0 || 0==fossil_strcmp("*",zStatusFilter) ){ |
| 2637 | zStatusFilter = 0; |
| 2638 | }else{ |
| 2639 | bFilter = bHasStatus; |
| 2640 | } |
| 2641 | } |
| 2642 | if( bHasForum ){ |
| 2643 | Stmt qStat = empty_Stmt; /* Query to get status information */ |
| 2644 | if( bHasStatus ){ |
| 2645 | /* The qStat query runs once for each output row generate by the |
| 2646 | ** q query. It determines the value and label of the status for |
| 2647 | ** the row with froot=:rowid |
| 2648 | */ |
| 2649 | db_prepare(&qStat, |
| 2650 | "SELECT tagxref.value, forumstatus.label\n" |
| 2651 | " FROM forumstatus, tagxref\n" |
| 2652 | " WHERE tagid=%d AND tagtype>=1\n" |
| 2653 | " AND forumstatus.value=tagxref.value\n" |
| 2654 | " AND rid=:rid\n" |
| 2655 | " ORDER BY mtime DESC", |
| 2656 | eStatusTag |
| 2657 | ); |
| 2658 | } |
| 2659 | |
| 2660 | /* Create the status_match() SQL function that will determine |
| 2661 | ** whether or not each thread in the "q" query below is eligible |
| 2662 | ** for display |
| 2663 | */ |
| 2664 | if( bFilter ){ |
| 2665 | sFSM.pFses = pFstat; |
| 2666 | sFSM.eStatusTag = eStatusTag; |
| 2667 | for(sFSM.iMatch=0; sFSM.iMatch<pFstat->n; sFSM.iMatch++){ |
| 2668 | if( 0==fossil_strcmp(zStatusFilter, |
| 2669 | pFstat->aStatus[sFSM.iMatch].zValue) ){ |
| 2670 | break; |
| 2671 | } |
| 2672 | } |
| 2673 | sqlite3_create_function(g.db,"status_match",1,SQLITE_UTF8,(void*)&sFSM, |
| 2674 | forum_status_match, 0, 0); |
| 2675 | }else{ |
| 2676 | sqlite3_create_function(g.db,"status_match",1,SQLITE_UTF8,0, |
| 2677 | forum_status_match, 0, 0); |
| 2678 | } |
| 2679 | |
| 2680 | db_prepare(&q, |
| 2681 | "WITH thread(root,endtime,lastrid) AS (\n" |
| 2682 | " SELECT\n" |
| 2683 | " froot,\n" |
| 2684 | " max(fmtime),\n" |
| 2685 | " fpid\n" |
| 2686 | " FROM forumpost\n" |
| 2687 | " WHERE %s/*ModForum*/\n" |
| 2688 | " GROUP BY froot\n" |
| 2689 | " HAVING status_match(froot)\n" |
| 2690 | " ORDER BY 2 DESC\n" |
| 2691 | " LIMIT %d OFFSET %d\n" |
| 2692 | ")\n" |
| 2693 | "SELECT\n" |
| 2694 | " julianday('now') - thread.endtime,\n" /* 0 */ |
| 2695 | " thread.endtime - " |
| 2696 | "(SELECT fmtime FROM forumpost WHERE fpid=root),\n" /* 1 */ |
| 2697 | " (SELECT sum(fprev IS NULL) FROM forumpost" |
| 2698 | " WHERE froot=root),\n" /* 2 */ |
| 2699 | " blob.uuid,\n" /* 3 */ |
| 2700 | " substr(event.comment,instr(event.comment,':')+1),\n" /* 4 */ |
| 2701 | " thread.lastrid,\n" /* 5 */ |
| 2702 | " thread.root\n" /* 6 */ |
| 2703 | " FROM thread, blob, event\n" |
| 2704 | " WHERE blob.rid=thread.lastrid\n" |
| 2705 | " AND event.objid=thread.lastrid\n" |
| 2706 | " ORDER BY 1;", |
| 2707 | g.perm.ModForum ? "true" : "fpid NOT IN private" /*safe-for-%s*/, |
| 2708 | iLimit+1, iOfst |
| 2709 | ); |
| 2710 | while( db_step(&q)==SQLITE_ROW ){ |
| 2711 | char *zAge; |
| 2712 | int nMsg; |
| 2713 | const char *zUuid; |
| 2714 | const char *zTitle; |
| 2715 | const char *zStatus; |
| 2716 | const char *zStatusLbl; |
| 2717 | const int bShowStatus = bHasStatus && !zStatusFilter; |
| 2718 | const int nCols = bShowStatus ? 4 : 3; |
| 2719 | |
| 2720 | if( qStat.pStmt ){ |
| 2721 | /* Determine the status value for this row */ |
| 2722 | db_reset(&qStat); |
| 2723 | db_bind_int(&qStat, ":rid", db_column_int(&q,6)); |
| 2724 | if( db_step(&qStat)==SQLITE_ROW ){ |
| 2725 | zStatus = db_column_text(&qStat, 0); |
| 2726 | zStatusLbl = db_column_text(&qStat, 1); |
| 2727 | }else{ |
| 2728 | zStatus = pFstat->aStatus[0].zValue; |
| 2729 | zStatusLbl = pFstat->aStatus[0].zLabel; |
| 2730 | } |
| 2731 | }else{ |
| 2732 | zStatus = zStatusLbl = NULL; |
| 2733 | } |
| 2734 | zAge = human_readable_age(db_column_double(&q,0)); |
| 2735 | nMsg = db_column_int(&q, 2); |
| 2736 | zUuid = db_column_text(&q, 3); |
| 2737 | zTitle = db_column_text(&q, 4); |
| 2738 | if( iCnt==0 ){ |
| 2739 | char *zTail = bFilter ? mprintf(" with status=%Q", zStatusFilter): 0; |
| 2740 | if( iOfst>0 ){ |
| 2741 | @ <h1>Threads at least %s(zAge) old%h(zTail ? zTail : "")</h1> |
| 2742 | }else{ |
| 2743 | @ <h1>Most recent threads%h(zTail ? zTail : "")</h1> |
| 2744 | } |
| 2745 | fossil_free(zTail); |
| 2746 | @ <div class='forumPosts fileage'><table width="100%%"> |
| 2747 | if( iOfst>0 ){ |
| 2748 | if( iOfst>iLimit ){ |
| 2749 | @ <tr><td colspan="%d(nCols)">\ |
| 2750 | @ <a href='%R/forum?x=%d(iOfst-iLimit)&n=%d(iLimit) \ |
| 2751 | if( bFilter ){ |
| 2752 | @ &status=%T(zStatusFilter)\ |
| 2753 | } |
| 2754 | @ '>↑ Newer...</a></td></tr> |
| 2755 | }else{ |
| 2756 | @ <tr><td colspan="%d(nCols)">\ |
| 2757 | @ <a href='%R/forum?n=%d(iLimit)\ |
| 2758 | if( bFilter ){ |
| 2759 | @ &status=%T(zStatusFilter) \ |
| 2760 | } |
| 2761 | @ '>↑ Newer...</a></td></tr> |
| 2762 | } |
| 2763 | } |
| 2764 | } |
| 2765 | iCnt++; |
| 2766 | if( iCnt>iLimit ){ |
| 2767 | @ <tr><td colspan="%d(nCols)">\ |
| 2768 | @ <a href='%R/forum?x=%d(iOfst+iLimit)&n=%d(iLimit) \ |
| 2769 | if( bFilter ){ |
| 2770 | @ &status=%T(zStatusFilter)\ |
| 2771 | } |
| 2772 | @ '>↓ Older...</a></td></tr> |
| 2773 | fossil_free(zAge); |
| 2774 | break; |
| 2775 | } |
| 2776 | @ <tr \ |
| 2777 | if( bHasStatus ){ |
| 2778 | @ data-status="%h(zStatus)"\ |
| 2779 | } |
| 2780 | @ ><td>%h(zAge) ago</td> |
| 2781 | @ <td class='subject'>%z(href("%R/forumpost/%S",zUuid))%h(zTitle)</a>\ |
| 2782 | @ </td><td>\ |
| 2783 | if( g.perm.ModForum && moderation_pending(db_column_int(&q,5)) ){ |
| 2784 | @ <span class="modpending">\ |
| 2785 | @ Awaiting Moderator Approval</span><br> |
| 2786 | } |
| 2787 | if( nMsg<2 ){ |
| 2788 | @ no replies\ |
| 2789 | }else{ |
| 2790 | char *zDuration = human_readable_age(db_column_double(&q,1)); |
| 2791 | @ %d(nMsg) posts spanning %h(zDuration)\ |
| 2792 | fossil_free(zDuration); |
| 2793 | } |
| 2794 | @ </td>\ |
| 2795 | if( bShowStatus ){ |
| 2796 | @ <td class='status'>%h(zStatusLbl)</td>\ |
| 2797 | } |
| 2798 | if( qStat.pStmt ){ |
| 2799 | db_reset(&qStat); |
| 2800 | } |
| 2801 | @</tr> |
| 2802 | fossil_free(zAge); |
| 2803 | } |
| 2804 | db_finalize(&q); |
| 2805 | if( qStat.pStmt ) db_finalize(&qStat); |
| 2806 | sqlite3_create_function(g.db,"status_match",1,SQLITE_UTF8,0,0,0,0); |
| 2807 | } |
| 2808 | if( iCnt>0 ){ |
| 2809 | @ </table></div> |
| 2810 | }else{ |
| 2811 | @ <h1>No forum posts found</h1> |
| 2812 | } |
| 2813 | if( bHasStatus ){ |
| 2814 | /* We need a JS-side kludge to avoid passing on the x=N |
| 2815 | ** URL arg when the status selection list is activated. */ |
| 2816 | forum_emit_js(); |
| 2817 | } |
| 2818 | style_finish_page(); |
| 2819 | } |
| 2820 | |
| 2821 | /* |
| 2822 | ** The AJAX counterpart of forum_post(). |
| 2823 | ** |
| 2824 | ** Returns the new artifact's RID on success, 0 if no changes were |
| 2825 | ** necessary (e.g. an empty new post or dry-run mode), and a negative |
| 2826 | ** value on error. If it returns a negative value then it will have |
| 2827 | ** populated the ajax response state with an error object. |
| 2828 | ** |
| 2829 | ** zTitle must be NULL if iInReplyTo>0 and must be non-empty if |
| 2830 | ** iInReplyTo==0. |
| 2831 | ** |
| 2832 | ** The caller must have started a transaction and must roll it back if |
| 2833 | ** this call returns <=0, noting that only the negative-value case is |
| 2834 | ** an error. |
| 2835 | ** |
| 2836 | ** This function does some work to try to ensure that duplicate |
| 2837 | ** entries are not save (this can happen as a side effect of the forum |
| 2838 | ** post editor added in 2026-06). If the given post will not have been |
| 2839 | ** materially edited by these changes, they are not applied and the |
| 2840 | ** rid of the existing entry is used. |
| 2841 | ** |
| 2842 | ** Maintenance reminders: |
| 2843 | ** |
| 2844 | ** - iInReplyTo==0 && iEdit==0: new thread |
| 2845 | ** - iInReplyTo==0 && iEdit>0 : edit top post or response |
| 2846 | ** - iInReplyTo>0 && iEdit==0: new response |
| 2847 | ** - iInReplyTo>0 && iEdit>0 : edit response |
| 2848 | */ |
| 2849 | static int forum_post_ajax( |
| 2850 | const char *zTitle, /* Title. NULL for replies */ |
| 2851 | int iInReplyTo, /* Post replying to. 0 for new threads */ |
| 2852 | int iEdit, /* Post being edited, or zero for a new post */ |
| 2853 | const char *zUser, /* Username. NULL means use login name */ |
| 2854 | const char *zMimetype, /* Mimetype of content. */ |
| 2855 | const char *zContent, /* Content */ |
| 2856 | int iFlags /* FPOST_xyz flag values */ |
| 2857 | ){ |
| 2858 | char *zI; |
| 2859 | char *zG; |
| 2860 | char *zP = 0; |
| 2861 | int iBasis; |
| 2862 | Blob x = BLOB_INITIALIZER, |
| 2863 | cksum = BLOB_INITIALIZER, |
| 2864 | formatCheck = BLOB_INITIALIZER, |
| 2865 | errMsg = BLOB_INITIALIZER; |
| 2866 | Manifest *pPost = 0; |
| 2867 | int nContent = zContent ? (int)strlen(zContent) : 0; |
| 2868 | int rc = 0; |
| 2869 | |
| 2870 | assert( db_transaction_nesting_depth()>0 ); |
| 2871 | schema_forum(); |
| 2872 | if( iEdit==0 && fossil_all_whitespace(zContent) ){ |
| 2873 | return 0; |
| 2874 | } |
| 2875 | if( !g.perm.Admin && (iEdit || iInReplyTo) |
| 2876 | && forum_rid_is_tagged(iEdit ? iEdit : iInReplyTo, "closed", 1) ){ |
| 2877 | return -ajax_route_error(400, "Thread is closed."); |
| 2878 | } |
| 2879 | if( 0==iInReplyTo && fossil_all_whitespace(zTitle) ){ |
| 2880 | return -ajax_route_error(400, "Empty title is not permitted."); |
| 2881 | } |
| 2882 | |
| 2883 | if( zUser==0 ){ |
| 2884 | if( login_is_nobody() ){ |
| 2885 | zUser = "anonymous"; |
| 2886 | }else{ |
| 2887 | zUser = login_name(); |
| 2888 | } |
| 2889 | } |
| 2890 | if( iEdit>0 |
| 2891 | && !g.perm.Admin |
| 2892 | && !forumpost_is_owner(iEdit, zUser) ){ |
| 2893 | return -ajax_route_error( |
| 2894 | 403, "Only admins may edit other peoples' posts." |
| 2895 | ); |
| 2896 | } |
| 2897 | if( iInReplyTo==0 && iEdit>0 ){ |
| 2898 | iBasis = iEdit; |
| 2899 | iInReplyTo = db_int(0, "SELECT firt FROM forumpost WHERE fpid=%d", |
| 2900 | iEdit); |
| 2901 | }else{ |
| 2902 | iBasis = iInReplyTo; |
| 2903 | /* TODO (2026-06-008) If (iInReplyTo>0 && iEdit>0), validate that |
| 2904 | ** iInReplyTo is connected to iEdit properly, else we risk |
| 2905 | ** reparenting the new edit and having unrepredictable downstream |
| 2906 | ** side effects. */ |
| 2907 | } |
| 2908 | |
| 2909 | if( 0!=zMimetype && 0==zMimetype[0] ){ |
| 2910 | zMimetype = 0; |
| 2911 | } |
| 2912 | |
| 2913 | if( 0!=zTitle && 0==zTitle[0] ) zTitle = 0; |
| 2914 | webpage_assert( (zTitle==0)+(iInReplyTo==0)==1 ); |
| 2915 | |
| 2916 | if( iEdit>0 ){ |
| 2917 | int cmp; |
| 2918 | pPost = manifest_get(iEdit, CFTYPE_FORUM, 0); |
| 2919 | if( pPost==0 ){ |
| 2920 | rc = -ajax_route_error(404, "Missing edit artifact %d", iEdit); |
| 2921 | goto post_ajax_end; |
| 2922 | } |
| 2923 | /* |
| 2924 | ** If the old content matches the new then do not save a new copy. |
| 2925 | ** It's easy to get re-posts of unedited content via the forum |
| 2926 | ** editor, especially since the one added in 2026-06, where a |
| 2927 | ** post's status and attachments may be amended from the editor |
| 2928 | ** without modifying any of the post's content. In the legacy |
| 2929 | ** editor such "out-of-band" changes weren't possible and users |
| 2930 | ** have never made a practice of re-posting unedited content. |
| 2931 | ** |
| 2932 | ** We compare the following fields to the original: user, mimetype, |
| 2933 | ** content, and (for root posts only) the title. |
| 2934 | */ |
| 2935 | cmp = (0==pPost->zInReplyTo) |
| 2936 | ? fossil_strcmp(pPost->zThreadTitle, zTitle) |
| 2937 | : 0; |
| 2938 | if( 0==cmp ){ |
| 2939 | cmp=fossil_strcmp(pPost->zWiki, zContent); |
| 2940 | if( 0==cmp ){ |
| 2941 | cmp = fossil_strcmp(pPost->zUser, zUser); |
| 2942 | } |
| 2943 | if( 0==cmp |
| 2944 | && 0!=(cmp=fossil_strcmp(pPost->zMimetype, zMimetype)) ){ |
| 2945 | /* Extra mimetype checks for a common condition seen elsewhere */ |
| 2946 | if( (0==zMimetype |
| 2947 | && 0==fossil_strcmp(pPost->zMimetype, "text/x-fossil-wiki")) |
| 2948 | || (0==pPost->zMimetype |
| 2949 | && 0==fossil_strcmp(zMimetype, "text/x-fossil-wiki")) ){ |
| 2950 | cmp = 0; |
| 2951 | } |
| 2952 | } |
| 2953 | if( 0==cmp ){ |
| 2954 | rc = iEdit; |
| 2955 | goto post_ajax_end; |
| 2956 | } |
| 2957 | } |
| 2958 | zP = rid_to_uuid(iEdit); |
| 2959 | } |
| 2960 | |
| 2961 | /* Write the new artifact */ |
| 2962 | blob_init(&x, 0, 0); |
| 2963 | blob_appendf(&x, "D %z\n", date_in_standard_format("now")); |
| 2964 | zG = db_text( |
| 2965 | 0, |
| 2966 | "SELECT uuid FROM blob, forumpost" |
| 2967 | " WHERE blob.rid==forumpost.froot" |
| 2968 | " AND forumpost.fpid=%d", |
| 2969 | iBasis |
| 2970 | ); |
| 2971 | if( zG ){ |
| 2972 | blob_appendf(&x, "G %z\n", zG); |
| 2973 | } |
| 2974 | if( zTitle ){ |
| 2975 | blob_appendf(&x, "H %F\n", zTitle); |
| 2976 | } |
| 2977 | if( iInReplyTo>0 ){ |
| 2978 | zI = rid_to_uuid(iInReplyTo); |
| 2979 | if( 0==zI ){ |
| 2980 | rc = -ajax_route_error(404, "Missing in-reply-to artifact %d", |
| 2981 | iInReplyTo); |
| 2982 | goto post_ajax_end; |
| 2983 | } |
| 2984 | blob_appendf(&x, "I %z\n", zI); |
| 2985 | } |
| 2986 | if( zMimetype!=0 |
| 2987 | && fossil_strcmp(zMimetype,"text/x-fossil-wiki")!=0 ){ |
| 2988 | blob_appendf(&x, "N %F\n", zMimetype); |
| 2989 | } |
| 2990 | if( zP ){ |
| 2991 | blob_appendf(&x, "P %s\n", zP); |
| 2992 | } |
| 2993 | |
| 2994 | blob_appendf(&x, "U %F\n", zUser); |
| 2995 | blob_appendf(&x, "W %d\n%s\n", nContent, zContent); |
| 2996 | md5sum_blob(&x, &cksum); |
| 2997 | blob_appendf(&x, "Z %b\n", &cksum); |
| 2998 | blob_reset(&cksum); |
| 2999 | |
| 3000 | /* Verify that the artifact we are creating is well-formed */ |
| 3001 | blob_init(&formatCheck, 0, 0); |
| 3002 | blob_init(&errMsg, 0, 0); |
| 3003 | blob_copy(&formatCheck, &x); |
| 3004 | pPost = manifest_parse(&formatCheck, 0, &errMsg); |
| 3005 | if( pPost==0 ){ |
| 3006 | ajax_route_error(500, "Malformed forum post artifact: %b", &errMsg); |
| 3007 | rc = -500; |
| 3008 | goto post_ajax_end; |
| 3009 | } |
| 3010 | webpage_assert( pPost->type==CFTYPE_FORUM ); |
| 3011 | |
| 3012 | if( (iFlags & FPOST_DRYRUN)!=0 ){ |
| 3013 | rc = 0; |
| 3014 | }else{ |
| 3015 | int nrid; |
| 3016 | db_begin_transaction(); |
| 3017 | nrid = wiki_put(&x, iEdit>0 ? iEdit : 0, forum_need_moderation()); |
| 3018 | blob_reset(&x); |
| 3019 | if( (iFlags & FPOST_NO_ALERT)!=0 ){ |
| 3020 | alert_unqueue('f', nrid); |
| 3021 | } |
| 3022 | rc = nrid; |
| 3023 | db_end_transaction(0); |
| 3024 | } |
| 3025 | post_ajax_end: |
| 3026 | manifest_destroy(pPost); |
| 3027 | fossil_free(zP); |
| 3028 | blob_reset(&x); |
| 3029 | blob_reset(&cksum); |
| 3030 | blob_reset(&formatCheck); |
| 3031 | return rc; |
| 3032 | } |
| 3033 | /* |
| 3034 | ** WEBPAGE: forumajax_save hidden |
| 3035 | ** |
| 3036 | ** WIP |
| 3037 | ** |
| 3038 | ** Response JSON: |
| 3039 | ** |
| 3040 | ** { uuid: hash, ...tbd } |
| 3041 | */ |
| 3042 | void forum_ajax_save_page(void){ |
| 3043 | const char *zFpid; |
| 3044 | const char *zTitle; |
| 3045 | const char *zIrt; |
| 3046 | const char *zMimetype; |
| 3047 | const char *zContent; |
| 3048 | const char *zStatus; |
| 3049 | const int bHasAttachment = P("file1")!=0; |
| 3050 | Manifest *pPost = 0; |
| 3051 | char *zNewUuid = 0; |
| 3052 | int firt = 0; /* In-reply-to rid or 0 */ |
| 3053 | int fpid = 0; /* Post rid being edited or 0 */ |
| 3054 | int rc = 0; /* Result code. */ |
| 3055 | int nrid = 0; /* New artifact rid. */ |
| 3056 | int iPostFlags; /* forum_post_flags() (after perms check) */ |
| 3057 | int bRollback; /* True = roll back. */ |
| 3058 | int nAttach = 0; /* Number of attachments added */ |
| 3059 | int bStatusSet = 0; /* True if status tag set. */ |
| 3060 | |
| 3061 | if( !ajax_route_bootstrap(0, 1) ){ |
| 3062 | return; |
| 3063 | }else if( !g.perm.WrForum |
| 3064 | || (bHasAttachment && !g.perm.AttachForum) ){ |
| 3065 | ajax_route_error_forbidden(); |
| 3066 | return; |
| 3067 | }else if( !ajax_check_csrf(2) ){ |
| 3068 | ajax_route_error_csrf(); |
| 3069 | return; |
| 3070 | } |
| 3071 | |
| 3072 | iPostFlags = forum_post_flags(/*must come after permissions init*/); |
| 3073 | bRollback = (FPOST_DRYRUN & iPostFlags); |
| 3074 | zFpid = P("fpid"); |
| 3075 | zIrt = P("firt"); |
| 3076 | zMimetype = P("mimetype"); |
| 3077 | zContent = P("content"); |
| 3078 | zStatus = P("status"); |
| 3079 | db_begin_transaction(); |
| 3080 | if( zFpid && zFpid[0] ){ |
| 3081 | fpid = symbolic_name_to_rid(zFpid, "f"); |
| 3082 | if( fpid<0 ){ |
| 3083 | rc = -ajax_route_error(400, "Ambiguous forum ID."); |
| 3084 | goto ajax_save_end; |
| 3085 | }else if( 0==fpid |
| 3086 | || 0==(pPost = manifest_get(fpid, CFTYPE_FORUM, 0)) ){ |
| 3087 | rc = -ajax_route_error(404, "Cannot resolve forum post ID."); |
| 3088 | goto ajax_save_end; |
| 3089 | } |
| 3090 | } |
| 3091 | /* |
| 3092 | ** Problem: if we derive firt from fpid/pPost then there's a race |
| 3093 | ** condition where the IRT post is edited between the time that this |
| 3094 | ** edit was initiated and when it is posted: the new edit's IRT will |
| 3095 | ** point to the edit which was made in the meantime, not the one the |
| 3096 | ** user intended to respond to. However, if we accept firt from the |
| 3097 | ** enviornment, we "really should" validate that it's actually in |
| 3098 | ** the current chain, to prohibit that malicious posts could move |
| 3099 | ** posts around. |
| 3100 | ** |
| 3101 | ** forum_post_ajax() will, if fpid>0 && !firt, select fpid's current |
| 3102 | ** firt. |
| 3103 | */ |
| 3104 | if( zIrt && zIrt[0] ){ |
| 3105 | firt = symbolic_name_to_rid(zIrt, "f"); |
| 3106 | if( firt<0 ){ |
| 3107 | rc = -ajax_route_error(400, "Ambiguous in-reply-do ID."); |
| 3108 | goto ajax_save_end; |
| 3109 | }else if( 0==firt ){ |
| 3110 | rc = -ajax_route_error(404, "Cannot resolve in-reply-do ID."); |
| 3111 | goto ajax_save_end; |
| 3112 | } |
| 3113 | } |
| 3114 | |
| 3115 | if( 0 ){ |
| 3116 | rc = -ajax_route_error(400, "Save is TODO. " |
| 3117 | "iPostFlags=%d debug=%d", |
| 3118 | iPostFlags, g.perm.Debug); |
| 3119 | goto ajax_save_end; |
| 3120 | } |
| 3121 | |
| 3122 | zTitle = firt ? 0 : P("title"); |
| 3123 | nrid = forum_post_ajax(zTitle, firt, fpid, 0, zMimetype, |
| 3124 | zContent, iPostFlags); |
| 3125 | if( nrid<0 ){ |
| 3126 | rc = nrid; |
| 3127 | goto ajax_save_end; |
| 3128 | }else if( nrid==0 ){ |
| 3129 | if( 0==(FPOST_DRYRUN & iPostFlags) ){ |
| 3130 | bRollback = 1; |
| 3131 | CX("{\"message\": \"No saving needed.\"}\n"); |
| 3132 | }else{ |
| 3133 | CX("{\"message\": \"Rolled back for dry-run.\"," |
| 3134 | "\"iPostFlags\":%d}\n", iPostFlags); |
| 3135 | } |
| 3136 | goto ajax_save_end; |
| 3137 | }else{ |
| 3138 | const int bNeedsModeration = forum_need_moderation(); |
| 3139 | const int fpHead = forumpost_head_rid(nrid); |
| 3140 | assert( nrid>0 ); |
| 3141 | assert( fpHead>0 ); |
| 3142 | zNewUuid = rid_to_uuid(nrid); |
| 3143 | if( 0!=P("file1") ){ |
| 3144 | /* Attachments */ |
| 3145 | if( !g.perm.Admin && !g.perm.AttachForum ){ |
| 3146 | rc = -ajax_route_error(403, "No permission no attach files."); |
| 3147 | goto ajax_save_end; |
| 3148 | }else{ |
| 3149 | char *zRoot = (nrid==fpHead) ? 0 : rid_to_uuid(fpHead); |
| 3150 | nAttach = attachments_ajax_from_POST(zRoot ? zRoot : zNewUuid, |
| 3151 | bNeedsModeration); |
| 3152 | fossil_free(zRoot); |
| 3153 | if( nAttach<0 ){ |
| 3154 | rc = nAttach; |
| 3155 | goto ajax_save_end; |
| 3156 | } |
| 3157 | if( nAttach>0 |
| 3158 | && (iPostFlags & FPOST_NO_ALERT)!=0 |
| 3159 | && db_table_exists("repository","pending_alert") ){ |
| 3160 | /* Unqueue any alerts for these attachments. Recall that |
| 3161 | ** they're attached to the first version of the post, which |
| 3162 | ** means we actually risk cancelling _other_ pending |
| 3163 | ** notifications for attachments on this same post. C'est la |
| 3164 | ** vie.*/ |
| 3165 | db_multi_exec( |
| 3166 | "WITH x(id) AS (\n" |
| 3167 | " SELECT 'f%d'\n" |
| 3168 | " UNION ALL\n" |
| 3169 | " SELECT 'f'||a.attachid FROM blob b, attachment a\n" |
| 3170 | " WHERE b.rid=%d\n" |
| 3171 | " AND b.uuid=a.target\n" |
| 3172 | ") DELETE FROM pending_alert WHERE eventid IN x", |
| 3173 | fpHead, fpHead |
| 3174 | ); |
| 3175 | } |
| 3176 | } |
| 3177 | } |
| 3178 | if( 0==bNeedsModeration |
| 3179 | /* ^^^ Do not allow a status tag on a pending-moderation post |
| 3180 | ** because it will introduce a reference to an artifact which |
| 3181 | ** will become a phantom if it is rejected by a moderator. */ |
| 3182 | && zStatus!=0 && zStatus[0]!=0 |
| 3183 | && forum_may_set_status(nrid) |
| 3184 | && (bStatusSet=forumpost_tag(nrid, 1, "status", zStatus))<0 ){ |
| 3185 | rc = -ajax_route_error(500, "Tagging failed: %s", g.zErrMsg); |
| 3186 | goto ajax_save_end; |
| 3187 | } |
| 3188 | } |
| 3189 | |
| 3190 | assert( 0==rc ); |
| 3191 | assert( zNewUuid ); |
| 3192 | CX("{\"uuid\": %!j, \"attachedCount\": %d, " |
| 3193 | "\"statusModified\": %d, " |
| 3194 | "\"dryrun\": %s, \"iPostFlags\":%d}\n", |
| 3195 | zNewUuid, nAttach, |
| 3196 | bStatusSet, bRollback ? "true" : "false", iPostFlags); |
| 3197 | |
| 3198 | ajax_save_end: |
| 3199 | manifest_destroy(pPost); |
| 3200 | fossil_free(zNewUuid); |
| 3201 | db_end_transaction(rc || bRollback); |
| 3202 | } |
| 3203 | |
| 3204 | DDED src/fossil.attach.js |
+1301
-214
| --- src/forum.c | ||
| +++ src/forum.c | ||
| @@ -49,11 +49,11 @@ | ||
| 49 | 49 | ForumPost *pNext; /* Next in chronological order */ |
| 50 | 50 | ForumPost *pPrev; /* Previous in chronological order */ |
| 51 | 51 | ForumPost *pDisplay; /* Next in display order */ |
| 52 | 52 | int nEdit; /* Number of edits to this post */ |
| 53 | 53 | int nIndent; /* Number of levels of indentation for this post */ |
| 54 | - int iClosed; /* See forum_rid_is_closed() */ | |
| 54 | + int iClosed; /* True if forum_rid_is_tagged("closed") */ | |
| 55 | 55 | }; |
| 56 | 56 | |
| 57 | 57 | /* |
| 58 | 58 | ** A single instance of the following tracks all entries for a thread. |
| 59 | 59 | */ |
| @@ -63,12 +63,134 @@ | ||
| 63 | 63 | ForumPost *pDisplay; /* Entries in display order */ |
| 64 | 64 | ForumPost *pTail; /* Last on the display list */ |
| 65 | 65 | int mxIndent; /* Maximum indentation level */ |
| 66 | 66 | int nArtifact; /* Number of forum artifacts in this thread */ |
| 67 | 67 | }; |
| 68 | + | |
| 69 | +/* | |
| 70 | +** A single entry from the forum-statuses setting. | |
| 71 | +*/ | |
| 72 | +struct ForumStatus { | |
| 73 | + char *zLabel; /* Label for the UI */ | |
| 74 | + char *zValue; /* status=X tag value */ | |
| 75 | +}; | |
| 76 | + | |
| 77 | +/* | |
| 78 | +** A list of ForumStatus objects. | |
| 79 | +*/ | |
| 80 | +struct ForumStatusList { | |
| 81 | + struct ForumStatus *aStatus; /* List of statuses */ | |
| 82 | + unsigned int n; /* Number of entries */ | |
| 83 | +}; | |
| 84 | + | |
| 85 | +/* | |
| 86 | +** Information passed into the status_match() SQL function | |
| 87 | +** via the sqlite3_user_data() mechanism, and used by status_match() | |
| 88 | +** to determine whether or not a particular forum thread should | |
| 89 | +** be displayed. | |
| 90 | +*/ | |
| 91 | +struct ForumStatusMatch { | |
| 92 | + const ForumStatusList *pFses; /* Parsed forum-statuses setting */ | |
| 93 | + int eStatusTag; /* tagid for the "status" property */ | |
| 94 | + unsigned int iMatch; /* Match this status value */ | |
| 95 | +}; | |
| 68 | 96 | #endif /* INTERFACE */ |
| 69 | 97 | |
| 98 | + | |
| 99 | +/* | |
| 100 | +** Returns a high-level representation of the forum-statuses setting. | |
| 101 | +** This is a singleton, cached across calls. | |
| 102 | + */ | |
| 103 | +const ForumStatusList * forum_statuses(void){ | |
| 104 | + static ForumStatusList fses = {0,0}; | |
| 105 | + static int once = 0; | |
| 106 | + while( !once ){ | |
| 107 | + ++once; | |
| 108 | + /* Read `forum-statuses` setting and transform it into the | |
| 109 | + ** fses object. | |
| 110 | + ** | |
| 111 | + ** Maybe: if it's empty, synthesize a length-1 list from | |
| 112 | + ** {value:"default",label:"Default",...}. It's expected that | |
| 113 | + ** usage may be slightly simplified if we always have a non-empty | |
| 114 | + ** list. A length-1 list is, for purposes of the UI, identical to | |
| 115 | + ** an empty one - status selection/filtering makes no sense if | |
| 116 | + ** there's only one choice. */ | |
| 117 | + db_multi_exec( | |
| 118 | + "CREATE TEMP TABLE IF NOT EXISTS forumstatus(" | |
| 119 | + " ord INTEGER PRIMARY KEY, label, value" | |
| 120 | + ");" | |
| 121 | + "DELETE FROM forumstatus;" | |
| 122 | + "INSERT INTO forumstatus(label,value)" | |
| 123 | + " WITH setting(v) AS (" | |
| 124 | + " SELECT value v FROM config WHERE name='forum-statuses'" | |
| 125 | + " )," | |
| 126 | + " room(r) AS (" | |
| 127 | + " SELECT e.value FROM setting s, jsonb_each(s.v) e" | |
| 128 | + " WHERE json_valid(s.v, 0x02)" | |
| 129 | + " )" | |
| 130 | + " SELECT r->>'label', r->>'value'" | |
| 131 | + " FROM room;" | |
| 132 | + ); | |
| 133 | + fses.n = (unsigned)db_int(0, "SELECT count(*) FROM forumstatus"); | |
| 134 | + if( fses.n ){ | |
| 135 | + int i = 0; | |
| 136 | + Stmt q; | |
| 137 | + db_prepare(&q,"SELECT label, value FROM forumstatus" | |
| 138 | + " ORDER BY ord"); | |
| 139 | + fses.aStatus = fossil_malloc(sizeof(fses.aStatus[0]) * fses.n); | |
| 140 | + while( SQLITE_ROW==db_step(&q) ){ | |
| 141 | + ForumStatus * fs = &fses.aStatus[i++]; | |
| 142 | + fs->zLabel = fossil_strdup(db_column_text(&q, 0)); | |
| 143 | + fs->zValue = fossil_strdup(db_column_text(&q, 1)); | |
| 144 | + } | |
| 145 | + db_finalize(&q); | |
| 146 | + } | |
| 147 | + } | |
| 148 | + return &fses; | |
| 149 | +} | |
| 150 | + | |
| 151 | +/* | |
| 152 | +** Search for a ForumStatus object by its tag value. If a match is | |
| 153 | +** found, the corresponding object is returned. If no match is found | |
| 154 | +** then (A) if bFirst is false then 0 is returned, else (B) the first | |
| 155 | +** entry in the list is returned, noting that the list may be empty, | |
| 156 | +** in which case 0 is returned. | |
| 157 | +*/ | |
| 158 | +static const ForumStatus * forum_status_by_value( | |
| 159 | + const char *z, int bFirst | |
| 160 | +){ | |
| 161 | + const ForumStatusList * const fses = forum_statuses(); | |
| 162 | + const ForumStatus * fs0 = 0; | |
| 163 | + unsigned int i; | |
| 164 | + if( !fses->n ) return 0; | |
| 165 | + for( i = 0; i < fses->n; ++i ){ | |
| 166 | + const ForumStatus * fs = &fses->aStatus[i]; | |
| 167 | + if( 0==fossil_strcmp(z, fs->zValue) ){ | |
| 168 | + return fs; | |
| 169 | + }else if( !fs0 ){ | |
| 170 | + fs0 = fs; | |
| 171 | + } | |
| 172 | + } | |
| 173 | + return bFirst ? fs0 : 0; | |
| 174 | +} | |
| 175 | + | |
| 176 | +/* | |
| 177 | +** COMMAND: test-forum-statuses | |
| 178 | +*/ | |
| 179 | +void test_forum_statuses_cmd(void){ | |
| 180 | + const ForumStatusList * fses; | |
| 181 | + unsigned i; | |
| 182 | + db_find_and_open_repository(0,0); | |
| 183 | + fses = forum_statuses(); | |
| 184 | + for(i = 0; i < fses->n; ++i ){ | |
| 185 | + const ForumStatus * fs = &fses->aStatus[i]; | |
| 186 | + fossil_print("Status: %!j %!j\n", fs->zValue, fs->zLabel); | |
| 187 | + assert( fs==forum_status_by_value(fs->zValue, 0) ); | |
| 188 | + } | |
| 189 | + fossil_print("Total statuses: %u\n", i); | |
| 190 | +} | |
| 191 | + | |
| 70 | 192 | /* |
| 71 | 193 | ** Return true if the forum post with the given rid has been |
| 72 | 194 | ** subsequently edited. |
| 73 | 195 | */ |
| 74 | 196 | int forum_rid_has_been_edited(int rid){ |
| @@ -83,29 +205,68 @@ | ||
| 83 | 205 | db_reset(&q); |
| 84 | 206 | return res; |
| 85 | 207 | } |
| 86 | 208 | |
| 87 | 209 | /* |
| 88 | -** Given a valid forumpost.fpid value, this function returns the first | |
| 89 | -** fpid in the chain of edits for that forum post, or rid if no prior | |
| 90 | -** versions are found. | |
| 210 | +** Given a valid forumpost.fpid value, this function returns the | |
| 211 | +** initial forumpost.fpid in the chain of edits for that forum post, | |
| 212 | +** or rid if no prior versions are found. | |
| 91 | 213 | */ |
| 92 | -static int forumpost_head_rid(int rid){ | |
| 93 | - Stmt q; | |
| 214 | +int forumpost_head_rid(int rid){ | |
| 215 | + static Stmt q = empty_Stmt_m; | |
| 94 | 216 | int rcRid = rid; |
| 95 | - | |
| 96 | - db_prepare(&q, "SELECT fprev FROM forumpost" | |
| 97 | - " WHERE fpid=:rid AND fprev IS NOT NULL"); | |
| 217 | + if( !q.pStmt ){ | |
| 218 | + db_static_prepare(&q, | |
| 219 | + "SELECT fprev FROM forumpost" | |
| 220 | + " WHERE fpid=:rid AND fprev IS NOT NULL" | |
| 221 | + ); | |
| 222 | + } | |
| 98 | 223 | db_bind_int(&q, ":rid", rid); |
| 99 | 224 | while( SQLITE_ROW==db_step(&q) ){ |
| 100 | 225 | rcRid = db_column_int(&q, 0); |
| 101 | 226 | db_reset(&q); |
| 102 | 227 | db_bind_int(&q, ":rid", rcRid); |
| 103 | 228 | } |
| 104 | - db_finalize(&q); | |
| 229 | + db_reset(&q); | |
| 105 | 230 | return rcRid; |
| 106 | 231 | } |
| 232 | + | |
| 233 | +/* | |
| 234 | +** Works like forumpost_head_rid() but expects zUuid to be an | |
| 235 | +** unambiguous forum post name. It may be a hash prefix, so long as | |
| 236 | +** it's unambiguous. Returns the rid of the head post, -1 if the name | |
| 237 | +** is ambiguous, and 0 if the name cannot be resolved as a forum post. | |
| 238 | +*/ | |
| 239 | +int forumpost_head_rid2(const char *zUuid){ | |
| 240 | + const int fpid = symbolic_name_to_rid(zUuid, "f"); | |
| 241 | + return fpid>0 | |
| 242 | + ? forumpost_head_rid(fpid) | |
| 243 | + : fpid; | |
| 244 | +} | |
| 245 | + | |
| 246 | +/* | |
| 247 | +** Given a forum post RID and user name, returns true if zUserName | |
| 248 | +** matches the event.(euser,user) field for a formpost entry with the | |
| 249 | +** matching RID. Returns false if no match is found. If zUserName is | |
| 250 | +** 0 then login_name() is used. | |
| 251 | +*/ | |
| 252 | +int forumpost_is_owner(int rid, const char *zUserName){ | |
| 253 | + static Stmt q; | |
| 254 | + int rc; | |
| 255 | + if( !q.pStmt ){ | |
| 256 | + db_static_prepare( | |
| 257 | + &q, "SELECT 1 FROM event" | |
| 258 | + " WHERE type='f' AND objid=$rid" | |
| 259 | + " AND coalesce(euser,user)=$user" | |
| 260 | + ); | |
| 261 | + } | |
| 262 | + db_bind_int(&q, "$rid", rid); | |
| 263 | + db_bind_text(&q, "$user", zUserName ? zUserName : login_name()); | |
| 264 | + rc = SQLITE_ROW==db_step(&q); | |
| 265 | + db_reset(&q); | |
| 266 | + return rc; | |
| 267 | +} | |
| 107 | 268 | |
| 108 | 269 | /* |
| 109 | 270 | ** Returns true if p, or any parent of p, has a non-zero iClosed |
| 110 | 271 | ** value. Returns 0 if !p. For an edited chain of post, the tag is |
| 111 | 272 | ** checked on the pEditHead entry, to simplify subsequent unlocking of |
| @@ -128,39 +289,39 @@ | ||
| 128 | 289 | return 0; |
| 129 | 290 | } |
| 130 | 291 | |
| 131 | 292 | /* |
| 132 | 293 | ** Given a forum post RID, this function returns true if that post has |
| 133 | -** (or inherits) an active "closed" tag. If bCheckIrt is true then | |
| 134 | -** the post to which the given post responds is also checked | |
| 294 | +** (or inherits) an active tag named zTagName. If bCheckIrt is true | |
| 295 | +** then the post to which the given post responds is also checked | |
| 135 | 296 | ** (recursively), else they are not. When checking in-response-to |
| 136 | 297 | ** posts, the first one which is closed ends the search. |
| 137 | 298 | ** |
| 138 | -** Note that this function checks _exactly_ the given rid, whereas | |
| 139 | -** forum post closure/re-opening is always applied to the head of an | |
| 140 | -** edit chain so that we get consistent implied locking behavior for | |
| 141 | -** later versions and responses to arbitrary versions in the | |
| 142 | -** chain. Even so, the "closed" tag is applied as a propagating tag | |
| 143 | -** so will apply to all edits in a given chain. | |
| 299 | +** This function checks _exactly_ the given rid, whereas forum post | |
| 300 | +** closure/re-opening is always applied to the head of an edit chain | |
| 301 | +** so that we get consistent implied locking behavior for later | |
| 302 | +** versions and responses to arbitrary versions in the chain. Even so, | |
| 303 | +** the "closed" tag is applied as a propagating tag so will apply to | |
| 304 | +** all edits in a given chain. | |
| 144 | 305 | ** |
| 145 | 306 | ** The return value is one of: |
| 146 | 307 | ** |
| 147 | -** - 0 if no "closed" tag is found. | |
| 308 | +** - 0 if no matching tag is found. | |
| 148 | 309 | ** |
| 149 | 310 | ** - The tagxref.rowid of the tagxref entry for the closure if rid is |
| 150 | 311 | ** the forum post to which the closure applies. |
| 151 | 312 | ** |
| 152 | -** - (-tagxref.rowid) if the given rid inherits a "closed" tag from an | |
| 153 | -** IRT forum post. | |
| 313 | +** - (-tagxref.rowid) if the given rid inherits the tag from an IRT | |
| 314 | +** forum post. | |
| 154 | 315 | */ |
| 155 | -static int forum_rid_is_closed(int rid, int bCheckIrt){ | |
| 316 | +static int forum_rid_is_tagged(int rid, const char *zTagName, int bCheckIrt){ | |
| 156 | 317 | static Stmt qIrt = empty_Stmt_m; |
| 157 | 318 | int rc = 0, i = 0; |
| 158 | 319 | /* TODO: this can probably be turned into a CTE by someone with |
| 159 | 320 | ** superior SQL-fu. */ |
| 160 | 321 | for( ; rid; i++ ){ |
| 161 | - rc = rid_has_active_tag_name(rid, "closed"); | |
| 322 | + rc = rid_has_active_tag_name(rid, zTagName); | |
| 162 | 323 | if( rc || !bCheckIrt ) break; |
| 163 | 324 | else if( !qIrt.pStmt ) { |
| 164 | 325 | db_static_prepare(&qIrt, |
| 165 | 326 | "SELECT firt FROM forumpost " |
| 166 | 327 | "WHERE fpid=$fpid ORDER BY fmtime DESC" |
| @@ -171,105 +332,211 @@ | ||
| 171 | 332 | db_reset(&qIrt); |
| 172 | 333 | } |
| 173 | 334 | return i ? -rc : rc; |
| 174 | 335 | } |
| 175 | 336 | |
| 176 | -/* | |
| 177 | -** Closes or re-opens the given forum RID via addition of a new | |
| 178 | -** control artifact into the repository. In order to provide | |
| 179 | -** consistent behavior for implied closing of responses and later | |
| 180 | -** versions, it always acts on the first version of the given forum | |
| 181 | -** post, walking the forumpost.fprev values to find the head of the | |
| 182 | -** chain. | |
| 183 | -** | |
| 184 | -** If doClose is true then a propagating "closed" tag is added, except | |
| 185 | -** as noted below, with the given optional zReason string as the tag's | |
| 186 | -** value. If doClose is false then any active "closed" tag on frid is | |
| 187 | -** cancelled, except as noted below. zReason is ignored if doClose is | |
| 188 | -** false or if zReason is NULL or starts with a NUL byte. | |
| 189 | -** | |
| 190 | -** This function only adds a "closed" tag if forum_rid_is_closed() | |
| 191 | -** indicates that frid's head is not closed. If a parent post is | |
| 192 | -** already closed, no tag is added. Similarly, it will only remove a | |
| 193 | -** "closed" tag from a post which has its own "closed" tag, and will | |
| 194 | -** not remove an inherited one from a parent post. | |
| 195 | -** | |
| 196 | -** If doClose is true and frid is closed (directly or inherited), this | |
| 197 | -** is a no-op. Likewise, if doClose is false and frid itself is not | |
| 198 | -** closed (not accounting for an inherited closed tag), this is a | |
| 199 | -** no-op. | |
| 200 | -** | |
| 201 | -** Returns true if it actually creates a new tag, else false. Fails | |
| 202 | -** fatally on error. If it returns true then any ForumPost::iClosed | |
| 203 | -** values from previously loaded posts are invalidated if they refer | |
| 204 | -** to the amended post or a response to it. | |
| 337 | +/* True if moderation of forum posts performs the same operation | |
| 338 | +** on its attachments. */ | |
| 339 | +#define FORUMPOST_MOD_ATTACHMENTS 1 | |
| 340 | +#if FORUMPOST_MOD_ATTACHMENTS | |
| 341 | +/* | |
| 342 | +** Internal helper for moderation_forumpost_...(). | |
| 343 | +*/ | |
| 344 | +static void forumpost_prep_pending_attachids(Stmt *q, int fpid){ | |
| 345 | + db_prepare( | |
| 346 | + q, | |
| 347 | + "SELECT attachid FROM attachment " | |
| 348 | + "WHERE target=(" | |
| 349 | + " SELECT uuid FROM blob WHERE rid=%d" | |
| 350 | + ") and attachid in (" | |
| 351 | + " SELECT objid FROM modreq" | |
| 352 | + ")", | |
| 353 | + forumpost_head_rid(fpid) | |
| 354 | + ); | |
| 355 | +} | |
| 356 | +#endif | |
| 357 | + | |
| 358 | +/* | |
| 359 | +** Approve the given forum post RID and any pending-approval | |
| 360 | +** attachments associated with its initial version. | |
| 361 | +*/ | |
| 362 | +static void moderation_forumpost_approve(int fpid){ | |
| 363 | +#if !FORUMPOST_MOD_ATTACHMENTS | |
| 364 | + moderation_approve('f', fpid); | |
| 365 | +#else | |
| 366 | + /* Also approve any pending attachments */ | |
| 367 | + Stmt q; | |
| 368 | + moderation_approve('f', fpid); | |
| 369 | + forumpost_prep_pending_attachids(&q, fpid); | |
| 370 | + while( SQLITE_ROW==db_step(&q) ){ | |
| 371 | + moderation_approve('a', db_column_int(&q, 0)); | |
| 372 | + } | |
| 373 | + db_finalize(&q); | |
| 374 | +#endif | |
| 375 | +} | |
| 376 | + | |
| 377 | +/* | |
| 378 | +** Disapprove the given forum post and any pending-moderation | |
| 379 | +** attachments on its initial version. | |
| 380 | +*/ | |
| 381 | +static void moderation_forumpost_disapprove(int fpid){ | |
| 382 | +#if !FORUMPOST_MOD_ATTACHMENTS | |
| 383 | + moderation_disapprove(fpid); | |
| 384 | +#else | |
| 385 | + /* Also disapprove any pending attachments */ | |
| 386 | + Stmt q; | |
| 387 | + moderation_disapprove(fpid); | |
| 388 | + forumpost_prep_pending_attachids(&q, fpid); | |
| 389 | + while( SQLITE_ROW==db_step(&q) ){ | |
| 390 | + moderation_disapprove(db_column_int(&q, 0)); | |
| 391 | + } | |
| 392 | + db_finalize(&q); | |
| 393 | +#endif | |
| 394 | +} | |
| 395 | +#undef FORUMPOST_MOD_ATTACHMENTS | |
| 396 | + | |
| 397 | +/* | |
| 398 | +** Applies or cancels a tag named zTagName on the given forum RID via | |
| 399 | +** addition of a new control artifact into the repository. In order to | |
| 400 | +** provide consistent behavior, it always acts on the first version of | |
| 401 | +** the given forum post, walking the forumpost.fprev values to find | |
| 402 | +** the head of the chain. | |
| 403 | +** | |
| 404 | +** If addTag is true then a propagating tag is added, except as noted | |
| 405 | +** below, with the given optional zValue string as the tag's | |
| 406 | +** value. If addTag is false then any matching active tag on frid is | |
| 407 | +** cancelled, except as noted below. zValue is ignored if it is NULL | |
| 408 | +** or starts with a NUL byte, or if addTag is false. | |
| 409 | +** | |
| 410 | +** This function only adds a tag if forum_rid_is_tagged() indicates | |
| 411 | +** that frid's head is not tagged. If a parent post is already tagged, | |
| 412 | +** no tag is added. Similarly, it will only remove a tag from a post | |
| 413 | +** which has its own tag, and will not remove an inherited one from a | |
| 414 | +** parent post. | |
| 415 | +** | |
| 416 | +** If addTag is true and frid is already tagged, this is a | |
| 417 | +** no-op. Likewise, if addTag is false and frid is not tagged (not | |
| 418 | +** accounting for a tag inherited via an in-response-to post), this is | |
| 419 | +** a no-op. | |
| 420 | +** | |
| 421 | +** Returns a positive value (a new tag.tagid value) if it actually | |
| 422 | +** creates a new tag, else 0. On error it returns a negative alue | |
| 423 | +** and g.zErrMsg "should" contain details. | |
| 424 | +** | |
| 425 | +** If it returns true then state from previously-loaded posts may be | |
| 426 | +** invalidated if they refer to the amended post or a response to it. | |
| 427 | +** e.g. if zTagName is "closed" then ForumPost::iClosed values may be | |
| 428 | +** stale. | |
| 205 | 429 | ** |
| 206 | 430 | ** Sidebars: |
| 207 | 431 | ** |
| 208 | 432 | ** - Unless the caller has a transaction open, via |
| 209 | 433 | ** db_begin_transaction(), there is a very tiny race condition |
| 210 | 434 | ** window during which the caller's idea of whether or not the forum |
| 211 | -** post is closed may differ from the current repository state. | |
| 435 | +** post is tagged may differ from the current repository state. | |
| 212 | 436 | ** |
| 213 | 437 | ** - This routine assumes that frid really does refer to a forum post. |
| 214 | 438 | ** |
| 215 | 439 | ** - This routine assumes that frid is not private or pending |
| 216 | 440 | ** moderation. |
| 217 | 441 | ** |
| 218 | -** - Closure of a forum post requires a propagating "closed" tag to | |
| 442 | +** - The applied tag is propagating so so that "closed" tags can | |
| 219 | 443 | ** account for how edits of posts are handled. This differs from |
| 220 | 444 | ** closure of a branch, where a non-propagating tag is used. |
| 221 | 445 | */ |
| 222 | -static int forumpost_close(int frid, int doClose, const char *zReason){ | |
| 446 | +static int forumpost_tag(int frid, int addTag, | |
| 447 | + const char *zTagName, | |
| 448 | + const char *zValue){ | |
| 223 | 449 | Blob artifact = BLOB_INITIALIZER; /* Output artifact */ |
| 224 | 450 | Blob cksum = BLOB_INITIALIZER; /* Z-card */ |
| 225 | - int iClosed; /* true if frid is closed */ | |
| 451 | + int iTagged; /* true if frid is already tagged */ | |
| 226 | 452 | int trid; /* RID of new control artifact */ |
| 227 | 453 | char *zUuid; /* UUID of head version of post */ |
| 228 | 454 | |
| 229 | 455 | db_begin_transaction(); |
| 230 | 456 | frid = forumpost_head_rid(frid); |
| 231 | - iClosed = forum_rid_is_closed(frid, 1); | |
| 232 | - if( (iClosed && doClose | |
| 233 | - /* Already closed, noting that in the case of (iClosed<0), it's | |
| 234 | - ** actually a parent which is closed. */) | |
| 235 | - || (iClosed<=0 && !doClose | |
| 236 | - /* This entry is not closed, but a parent post may be. */) ){ | |
| 457 | + iTagged = forum_rid_is_tagged(frid, zTagName, 0); | |
| 458 | + if( !addTag && !iTagged ){ | |
| 459 | + /* Nothing to do. We never tag an IRT-inherited post via this | |
| 460 | + ** function. */ | |
| 237 | 461 | db_end_transaction(0); |
| 238 | 462 | return 0; |
| 239 | 463 | } |
| 240 | - if( doClose==0 || (zReason && !zReason[0]) ){ | |
| 241 | - zReason = 0; | |
| 464 | + if( !addTag || (zValue && !zValue[0]) ){ | |
| 465 | + zValue = 0; | |
| 466 | + } | |
| 467 | + if( addTag && iTagged ){ | |
| 468 | + char *zOld = 0; | |
| 469 | + int cmp; | |
| 470 | + rid_has_tag2(frid, zTagName, &zOld); | |
| 471 | + cmp = fossil_strcmp(zOld, zValue); | |
| 472 | + fossil_free(zOld); | |
| 473 | + if( 0==cmp ){ | |
| 474 | + /* Same value - leave it as is. */ | |
| 475 | + db_end_transaction(0); | |
| 476 | + return 0; | |
| 477 | + } | |
| 242 | 478 | } |
| 243 | 479 | zUuid = rid_to_uuid(frid); |
| 244 | 480 | blob_appendf(&artifact, "D %z\n", date_in_standard_format( "now" )); |
| 245 | - blob_appendf(&artifact, | |
| 246 | - "T %cclosed %s%s%F\n", | |
| 247 | - doClose ? '*' : '-', zUuid, | |
| 248 | - zReason ? " " : "", zReason ? zReason : ""); | |
| 481 | + blob_appendf(&artifact, "T %c%s %s%s%F\n", | |
| 482 | + addTag ? '*' : '-', zTagName, | |
| 483 | + zUuid, zValue ? " " : "", zValue ? zValue : ""); | |
| 249 | 484 | blob_appendf(&artifact, "U %F\n", login_name()); |
| 250 | 485 | md5sum_blob(&artifact, &cksum); |
| 251 | 486 | blob_appendf(&artifact, "Z %b\n", &cksum); |
| 252 | 487 | blob_reset(&cksum); |
| 253 | 488 | trid = content_put_ex(&artifact, 0, 0, 0, 0); |
| 254 | 489 | if( trid==0 ){ |
| 255 | - fossil_fatal("Error saving tag artifact: %s", g.zErrMsg); | |
| 490 | + return -1; | |
| 256 | 491 | } |
| 257 | - if( manifest_crosslink(trid, &artifact, | |
| 258 | - MC_NONE /*MC_PERMIT_HOOKS?*/)==0 ){ | |
| 259 | - fossil_fatal("%s", g.zErrMsg); | |
| 492 | + if( manifest_crosslink(trid, &artifact, MC_NONE)==0 ){ | |
| 493 | + return -2; | |
| 260 | 494 | } |
| 261 | 495 | assert( blob_is_reset(&artifact) ); |
| 262 | 496 | db_add_unsent(trid); |
| 263 | - admin_log("%s forum post %S", doClose ? "Close" : "Re-open", zUuid); | |
| 497 | + admin_log("Tag forum post %S with %c%s", | |
| 498 | + zUuid, addTag ? '*' : '-', zTagName); | |
| 264 | 499 | fossil_free(zUuid); |
| 265 | - /* Potential TODO: if (iClosed>0) then we could find the initial tag | |
| 266 | - ** artifact and content_deltify(thatRid,&trid,1,0). Given the tiny | |
| 267 | - ** size of these artifacts, however, that would save little space, | |
| 268 | - ** if any. */ | |
| 269 | 500 | db_end_transaction(0); |
| 270 | - return 1; | |
| 501 | + return trid; | |
| 502 | +} | |
| 503 | + | |
| 504 | +/* | |
| 505 | +** COMMAND: test-forumpost-tag | |
| 506 | +** | |
| 507 | +** Usage: %fossil test-forumpost-tag ?-cancel? THREADID TAGNAME TAGVAL | |
| 508 | +** | |
| 509 | +** A tester for forumpost_tag(). It always rolls back changes. | |
| 510 | +*/ | |
| 511 | +void test_forumpost_tag_command(void){ | |
| 512 | + int fpid; | |
| 513 | + int rc; | |
| 514 | + const char *zPost; | |
| 515 | + const char *zTag; | |
| 516 | + const char *zVal; | |
| 517 | + const int bAdd = find_option("cancel","",0)==0; | |
| 518 | + | |
| 519 | + db_find_and_open_repository(0,0); | |
| 520 | + verify_all_options(); | |
| 521 | + if( g.argc<5 ){ | |
| 522 | + usage("forum-post-id tag-name value"); | |
| 523 | + } | |
| 524 | + zPost = g.argv[2]; | |
| 525 | + zTag = g.argv[3]; | |
| 526 | + zVal = g.argv[4]; | |
| 527 | + | |
| 528 | + db_begin_transaction(); | |
| 529 | + fpid = forumpost_head_rid2(zPost); | |
| 530 | + if( fpid<=0 ){ | |
| 531 | + fossil_fatal("Cannot resolve post ID %s", zPost); | |
| 532 | + } | |
| 533 | + fossil_print("%s => %d => %z\n", zTag, fpid, | |
| 534 | + rid_to_uuid(fpid)); | |
| 535 | + rc = forumpost_tag(fpid, bAdd, zTag, zVal); | |
| 536 | + fossil_print("tag fpid=%d taxgxref.tagid=%d\n", fpid, rc); | |
| 537 | + db_end_transaction(1); | |
| 271 | 538 | } |
| 272 | 539 | |
| 273 | 540 | /* |
| 274 | 541 | ** Returns true if the forum-close-policy setting is true, else false, |
| 275 | 542 | ** caching the result for subsequent calls. |
| @@ -285,12 +552,15 @@ | ||
| 285 | 552 | |
| 286 | 553 | /* |
| 287 | 554 | ** Returns 1 if the current user is an admin, -1 if the current user |
| 288 | 555 | ** is a forum moderator and the forum-close-policy setting is true, |
| 289 | 556 | ** else returns 0. The value is cached for subsequent calls. |
| 557 | +** | |
| 558 | +** This policy also determines whether non-admin forum moderators | |
| 559 | +** may delete forum attachments. | |
| 290 | 560 | */ |
| 291 | -static int forumpost_may_close(void){ | |
| 561 | +int forumpost_may_close(void){ | |
| 292 | 562 | static int permClose = -99; |
| 293 | 563 | if( permClose!=-99 ){ |
| 294 | 564 | return permClose; |
| 295 | 565 | }else if( g.perm.Admin ){ |
| 296 | 566 | return permClose = 1; |
| @@ -445,13 +715,13 @@ | ||
| 445 | 715 | for(; p; p=p->pEditPrev ){ |
| 446 | 716 | p->nEdit = pPost->nEdit; |
| 447 | 717 | p->pEditTail = pPost; |
| 448 | 718 | } |
| 449 | 719 | } |
| 450 | - pPost->iClosed = forum_rid_is_closed(pPost->pEditHead | |
| 720 | + pPost->iClosed = forum_rid_is_tagged(pPost->pEditHead | |
| 451 | 721 | ? pPost->pEditHead->fpid |
| 452 | - : pPost->fpid, 1); | |
| 722 | + : pPost->fpid, "closed", 1); | |
| 453 | 723 | } |
| 454 | 724 | db_finalize(&q); |
| 455 | 725 | |
| 456 | 726 | if( computeHierarchy ){ |
| 457 | 727 | /* Compute the hierarchical display order */ |
| @@ -629,10 +899,80 @@ | ||
| 629 | 899 | } |
| 630 | 900 | @ </table> |
| 631 | 901 | db_finalize(&q); |
| 632 | 902 | style_finish_page(); |
| 633 | 903 | } |
| 904 | + | |
| 905 | +/* | |
| 906 | +** Returns true if the current user is authorized to set forum post | |
| 907 | +** fpid's status. | |
| 908 | +*/ | |
| 909 | +static int forum_may_set_status(int fpid){ | |
| 910 | + if( moderation_pending(fpid) ) return 0; | |
| 911 | + return g.perm.Admin | |
| 912 | + || g.perm.ModForum | |
| 913 | + || (login_is_individual() | |
| 914 | + && forumpost_is_owner(fpid, 0)); | |
| 915 | +} | |
| 916 | + | |
| 917 | +/* | |
| 918 | +** If the current user is authorized to set fp's status then this | |
| 919 | +** renders a mini-form for setting the status then redirecting back to | |
| 920 | +** the post. Else it may emit a status label or no output. | |
| 921 | +*/ | |
| 922 | +static void forum_render_status_selection( const ForumPost *fp ){ | |
| 923 | + const ForumStatusList * const fss = forum_statuses(); | |
| 924 | + if( fss->n>1 ){ | |
| 925 | + const ForumPost * pHead = fp->pEditHead ? fp->pEditHead : fp; | |
| 926 | + int i; | |
| 927 | + char * zCurrent = 0; | |
| 928 | + const ForumStatus * sCurrent = 0; | |
| 929 | + rid_has_tag2(pHead->fpid, "status", &zCurrent); | |
| 930 | + for( i = 0; i < fss->n; ++i ){ | |
| 931 | + const ForumStatus * const fs = &fss->aStatus[i]; | |
| 932 | + if( 0==fossil_strcmp(zCurrent, fs->zValue) ){ | |
| 933 | + sCurrent = fs; | |
| 934 | + break; | |
| 935 | + } | |
| 936 | + } | |
| 937 | + if( !sCurrent ) sCurrent = &fss->aStatus[0]; | |
| 938 | + assert( sCurrent ); | |
| 939 | + @ <fieldset class='forum-status-selection'>\ | |
| 940 | + @ <legend>Status \ | |
| 941 | + @ <span class='help-buttonlet initially-hidden'>\ | |
| 942 | + @ Moderators and the post's owner may change \ | |
| 943 | + @ the status of this thread unless it is still. \ | |
| 944 | + @ pending moderation. See \ | |
| 945 | + @ <a href='%R/help/forum-statuses' target='_new'>\ | |
| 946 | + @ /help/forum-statuses</a></span>\ | |
| 947 | + @ </legend>\ | |
| 948 | + if( forum_may_set_status(fp->fpid) ){ | |
| 949 | + @ <form method="post" action='%R/forumpost_status'> | |
| 950 | + login_insert_csrf_secret(); | |
| 951 | + @ <input type='hidden' name='fpid' value='%s(fp->zUuid)' /> | |
| 952 | + @ <select name='status' data-fpid='%s(fp->zUuid)'\ | |
| 953 | + @ data-initial-value='%h(zCurrent ? zCurrent : "")'> | |
| 954 | + for( i = 0; i < fss->n; ++i ){ | |
| 955 | + const ForumStatus * const fs = &fss->aStatus[i]; | |
| 956 | + @ <option value='%h(fs->zValue)'\ | |
| 957 | + @ %s(sCurrent==fs ? " selected" : "")>\ | |
| 958 | + @ %h(fs->zLabel)</option> | |
| 959 | + } | |
| 960 | + @ </select> | |
| 961 | + @ <input type='button' class='submit action-status' disabled | |
| 962 | + @ value='Change' /> | |
| 963 | + /* ^^^ This must be <input>, not <button>, or else tapping it | |
| 964 | + ** will unconditionally submit. */ | |
| 965 | + @ </form> | |
| 966 | + /* Form is activated in fossil.page.forumpost.js */ | |
| 967 | + }else{ | |
| 968 | + @ <button disabled>Status: %h(sCurrent->zLabel)</button> | |
| 969 | + } | |
| 970 | + @ </fieldset> | |
| 971 | + fossil_free(zCurrent); | |
| 972 | + } | |
| 973 | +} | |
| 634 | 974 | |
| 635 | 975 | /* |
| 636 | 976 | ** Render a forum post for display |
| 637 | 977 | */ |
| 638 | 978 | void forum_render( |
| @@ -760,22 +1100,55 @@ | ||
| 760 | 1100 | if( pToFree ) manifest_destroy(pToFree); |
| 761 | 1101 | if( p->zDisplayName==0 ) return "(unknown)"; |
| 762 | 1102 | return p->zDisplayName; |
| 763 | 1103 | } |
| 764 | 1104 | |
| 1105 | +/* | |
| 1106 | +** Renders the attachment list for the given forum post. | |
| 1107 | +** Emits no output if there are no attachments. | |
| 1108 | +*/ | |
| 1109 | +static void forum_render_attachment_list(const char *zUuid){ | |
| 1110 | +#if 1 | |
| 1111 | + attachment_list(zUuid, "📎 Attachments", 0 | |
| 1112 | + | ATTACHLIST_SIZE | |
| 1113 | + | ATTACHLIST_HIDE_UNAPPROVED | |
| 1114 | + | ATTACHLIST_DETAILS_CLOSED | |
| 1115 | + | ATTACHLIST_HIDE_EMPTY); | |
| 1116 | +#else | |
| 1117 | + char * zLbl = mprintf("<a href='%R/attachlist?forumpost=%!S'>" | |
| 1118 | + "Attachments</a>:", zUuid); | |
| 1119 | + attachment_list(zUuid, zLbl, | |
| 1120 | + ATTACHLIST_HRULE_ABOVE | |
| 1121 | + | ATTACHLIST_SIZE | |
| 1122 | + | ATTACHLIST_HIDE_UNAPPROVED | |
| 1123 | + | ATTACHLIST_HIDE_EMPTY); | |
| 1124 | + fossil_free(zLbl); | |
| 1125 | +#endif | |
| 1126 | +} | |
| 1127 | + | |
| 1128 | +/* | |
| 1129 | +** Renders the attachment list for p or (if not NULL) pEditHead. | |
| 1130 | +*/ | |
| 1131 | +static void forum_render_attachment_list2(ForumPost *p){ | |
| 1132 | + if( p->pEditHead ) p = p->pEditHead; | |
| 1133 | + forum_render_attachment_list(p->zUuid); | |
| 1134 | +} | |
| 1135 | + | |
| 1136 | +/* Flags for use with forum_display_post() */ | |
| 1137 | +#define FDISPLAY_RAW 0x01 /* omit the border */ | |
| 1138 | +#define FDISPLAY_UNFORMATTED 0x02 /* leave the post unformatted */ | |
| 1139 | +#define FDISPLAY_HISTORY 0x04 /* Showing edit history */ | |
| 1140 | +#define FDISPLAY_SELECTED 0x08 /* This is the selected post */ | |
| 765 | 1141 | |
| 766 | 1142 | /* |
| 767 | 1143 | ** Display a single post in a forum thread. |
| 768 | 1144 | */ |
| 769 | 1145 | static void forum_display_post( |
| 770 | 1146 | ForumThread *pThread, /* The thread that this post is a member of */ |
| 771 | 1147 | ForumPost *p, /* Forum post to display */ |
| 772 | 1148 | int iIndentScale, /* Indent scale factor */ |
| 773 | - int bRaw, /* True to omit the border */ | |
| 774 | - int bUnf, /* True to leave the post unformatted */ | |
| 775 | - int bHist, /* True if showing edit history */ | |
| 776 | - int bSelect, /* True if this is the selected post */ | |
| 1149 | + int flags, /* From the FDISPLAY_... enum */ | |
| 777 | 1150 | char *zQuery /* Common query string */ |
| 778 | 1151 | ){ |
| 779 | 1152 | char *zPosterName; /* Name of user who originally made this post */ |
| 780 | 1153 | char *zEditorName; /* Name of user who provided the current edit */ |
| 781 | 1154 | char *zDate; /* The time/date string */ |
| @@ -784,30 +1157,43 @@ | ||
| 784 | 1157 | Manifest *pManifest; /* Manifest comprising the current post */ |
| 785 | 1158 | int bPrivate; /* True for posts awaiting moderation */ |
| 786 | 1159 | int bSameUser; /* True if author is also the reader */ |
| 787 | 1160 | int iIndent; /* Indent level */ |
| 788 | 1161 | int iClosed; /* True if (sub)thread is closed */ |
| 1162 | + const int bRaw = flags & FDISPLAY_RAW; | |
| 1163 | + const int bUnf = flags & FDISPLAY_UNFORMATTED; | |
| 1164 | + const int bHist = flags & FDISPLAY_HISTORY; | |
| 1165 | + const int bSelect = flags & FDISPLAY_SELECTED; | |
| 789 | 1166 | const char *zMimetype;/* Formatting MIME type */ |
| 790 | 1167 | |
| 791 | 1168 | /* Get the manifest for the post. Abort if not found (e.g. shunned). */ |
| 792 | 1169 | pManifest = manifest_get(p->fpid, CFTYPE_FORUM, 0); |
| 793 | 1170 | if( !pManifest ) return; |
| 794 | 1171 | iClosed = forumpost_is_closed(pThread, p, 1); |
| 1172 | + bPrivate = content_is_private(p->fpid); | |
| 1173 | + bSameUser = login_is_individual() | |
| 1174 | + && fossil_strcmp(pManifest->zUser, g.zLogin)==0; | |
| 795 | 1175 | /* When not in raw mode, create the border around the post. */ |
| 796 | 1176 | if( !bRaw ){ |
| 797 | 1177 | /* Open the <div> enclosing the post. Set the class string to mark the post |
| 798 | 1178 | ** as selected and/or obsolete. */ |
| 799 | 1179 | iIndent = (p->pEditHead ? p->pEditHead->nIndent : p->nIndent)-1; |
| 800 | - @ <div id='forum%d(p->fpid)' class='forumTime\ | |
| 1180 | + @ <div id='forum%d(p->fpid)' class='forumpost forumTime\ | |
| 801 | 1181 | @ %s(bSelect ? " forumSel" : "")\ |
| 802 | 1182 | @ %s(iClosed ? " forumClosed" : "")\ |
| 803 | 1183 | @ %s(p->pEditTail ? " forumObs" : "")' \ |
| 804 | 1184 | if( iIndent && iIndentScale ){ |
| 805 | - @ style='margin-left:%d(iIndent*iIndentScale)ex;'> | |
| 806 | - }else{ | |
| 807 | - @ > | |
| 1185 | + @ style='margin-left:%d(iIndent*iIndentScale)ex;' \ | |
| 1186 | + } | |
| 1187 | + /* These data-X fields are used by the JS editor. */ | |
| 1188 | + if( p->pIrt ){ | |
| 1189 | + @ data-firt="%s(p->pIrt->zUuid)" \ | |
| 1190 | + } | |
| 1191 | + if( p->pEditHead ){ | |
| 1192 | + @ data-fedithead="%s(p->pEditHead->zUuid)" \ | |
| 808 | 1193 | } |
| 1194 | + @ data-fpid="%s(p->zUuid)">\ | |
| 809 | 1195 | |
| 810 | 1196 | /* If this is the first post (or an edit thereof), emit the thread title. */ |
| 811 | 1197 | if( pManifest->zThreadTitle ){ |
| 812 | 1198 | @ <h1>%h(pManifest->zThreadTitle)</h1> |
| 813 | 1199 | } |
| @@ -888,18 +1274,18 @@ | ||
| 888 | 1274 | /* Provide a link to the raw source code. */ |
| 889 | 1275 | if( !bUnf ){ |
| 890 | 1276 | @ %z(href("%R/forumpost/%!S?raw",p->zUuid))[source]</a> |
| 891 | 1277 | } |
| 892 | 1278 | @ </h3> |
| 893 | - } | |
| 894 | - | |
| 895 | - /* Check if this post is approved, also if it's by the current user. */ | |
| 896 | - bPrivate = content_is_private(p->fpid); | |
| 897 | - bSameUser = login_is_individual() | |
| 898 | - && fossil_strcmp(pManifest->zUser, g.zLogin)==0; | |
| 899 | - | |
| 900 | - /* Render the post if the user is able to see it. */ | |
| 1279 | + | |
| 1280 | + if( bPrivate && (bSameUser || g.perm.Admin || g.perm.ModForum) ){ | |
| 1281 | + moderation_pending_www(p->fpid); | |
| 1282 | + } | |
| 1283 | + }/*!bRaw*/ | |
| 1284 | + | |
| 1285 | + /* Check if this post is approved, also if it's by the current user. | |
| 1286 | + Render the post if the user is able to see it. */ | |
| 901 | 1287 | if( bPrivate && !g.perm.ModForum && !bSameUser ){ |
| 902 | 1288 | @ <p><span class="modpending">Awaiting Moderator Approval</span></p> |
| 903 | 1289 | }else{ |
| 904 | 1290 | if( bRaw || bUnf || p->pEditTail ){ |
| 905 | 1291 | zMimetype = "text/plain"; |
| @@ -909,10 +1295,12 @@ | ||
| 909 | 1295 | forum_render(0, zMimetype, pManifest->zWiki, 0, !bRaw); |
| 910 | 1296 | } |
| 911 | 1297 | |
| 912 | 1298 | /* When not in raw mode, finish creating the border around the post. */ |
| 913 | 1299 | if( !bRaw ){ |
| 1300 | + int bBrBeforeAttach = 0; /* Layout kludge for Attach button */ | |
| 1301 | + forum_render_attachment_list2(p); | |
| 914 | 1302 | /* If the user is able to write to the forum and if this post has not been |
| 915 | 1303 | ** edited, create a form with various interaction buttons. */ |
| 916 | 1304 | if( g.perm.WrForum && !p->pEditTail ){ |
| 917 | 1305 | @ <div class="forumpost-single-controls">\ |
| 918 | 1306 | @ <form action="%R/forumedit" method="POST"> |
| @@ -941,33 +1329,52 @@ | ||
| 941 | 1329 | @ <br><label><input type="checkbox" name="trust"> |
| 942 | 1330 | @ Trust user "%h(pManifest->zUser)" so that future posts by \ |
| 943 | 1331 | @ "%h(pManifest->zUser)" do not require moderation. |
| 944 | 1332 | @ </label> |
| 945 | 1333 | @ <input type="hidden" name="trustuser" value="%h(pManifest->zUser)"> |
| 1334 | + bBrBeforeAttach = 1 /* slightly unmangle the layout */; | |
| 946 | 1335 | } |
| 947 | 1336 | }else if( bSameUser ){ |
| 948 | 1337 | /* Allow users to delete (reject) their own pending posts. */ |
| 949 | 1338 | @ <input type="submit" name="reject" value="Delete"> |
| 950 | 1339 | } |
| 951 | 1340 | login_insert_csrf_secret(); |
| 952 | 1341 | @ </form> |
| 953 | - if( bSelect && forumpost_may_close() && iClosed>=0 ){ | |
| 954 | - int iHead = forumpost_head_rid(p->fpid); | |
| 955 | - @ <form method="post" \ | |
| 956 | - @ action='%R/forumpost_%s(iClosed > 0 ? "reopen" : "close")'> | |
| 957 | - login_insert_csrf_secret(); | |
| 958 | - @ <input type="hidden" name="fpid" value="%z(rid_to_uuid(iHead))" /> | |
| 959 | - if( moderation_pending(p->fpid)==0 ){ | |
| 960 | - @ <input type="button" value='%s(iClosed ? "Re-open" : "Close")' \ | |
| 961 | - @ class='%s(iClosed ? "action-reopen" : "action-close")'/> | |
| 962 | - } | |
| 963 | - @ </form> | |
| 1342 | + | |
| 1343 | + if( bSelect ){ | |
| 1344 | + const ForumPost *pHead = p->pEditHead ? p->pEditHead : p; | |
| 1345 | + if( !bPrivate && forumpost_may_close() && iClosed>=0 ){ | |
| 1346 | + @ <form method="post" \ | |
| 1347 | + @ action='%R/forumpost_%s(iClosed > 0 ? "reopen" : "close")'> | |
| 1348 | + login_insert_csrf_secret(); | |
| 1349 | + @ <input type="hidden" name="fpid" value="%s(p->zUuid)" /> | |
| 1350 | + if( moderation_pending(p->fpid)==0 ){ | |
| 1351 | + @ <input type="button" value='%s(iClosed ? "Re-open" : "Close")' \ | |
| 1352 | + @ class='submit hidden \ | |
| 1353 | + @ %s(iClosed ? "action-reopen" : "action-close")'/> | |
| 1354 | + /* ^^^ activated by fossil.page.forumpost.js */ | |
| 1355 | + } | |
| 1356 | + @ </form> | |
| 1357 | + } | |
| 1358 | + if( attach_user_may(p/*not pHead*/->fpid, CFTYPE_FORUM) ){ | |
| 1359 | + /* When an admin edits someone else's post, the admin | |
| 1360 | + ** effectively takes over ownership of it (and we currently | |
| 1361 | + ** have no way of passing it back). Because of this, we | |
| 1362 | + ** check the ownership of `p` instead of `pHead`. */ | |
| 1363 | + if( bBrBeforeAttach ){ | |
| 1364 | + @ <br> | |
| 1365 | + } | |
| 1366 | + attach_render_attachadd_button(pHead->zUuid); | |
| 1367 | + } | |
| 964 | 1368 | } |
| 965 | 1369 | @ </div> |
| 966 | 1370 | } |
| 1371 | + if( !p->pIrt && (flags & FDISPLAY_SELECTED)){ | |
| 1372 | + forum_render_status_selection(p); | |
| 1373 | + } | |
| 967 | 1374 | @ </div> |
| 968 | - } | |
| 1375 | + }/*!bRaw*/ | |
| 969 | 1376 | |
| 970 | 1377 | /* Clean up. */ |
| 971 | 1378 | manifest_destroy(pManifest); |
| 972 | 1379 | } |
| 973 | 1380 | |
| @@ -1077,12 +1484,18 @@ | ||
| 1077 | 1484 | } |
| 1078 | 1485 | |
| 1079 | 1486 | /* Display the appropriate subset of posts in sequence. */ |
| 1080 | 1487 | while( p ){ |
| 1081 | 1488 | /* Display the post. */ |
| 1082 | - forum_display_post(pThread, p, iIndentScale, mode==FD_RAW, | |
| 1083 | - bUnf, bHist, p==pSelect, zQuery); | |
| 1489 | + forum_display_post( | |
| 1490 | + pThread, p, iIndentScale, | |
| 1491 | + (mode==FD_RAW ? FDISPLAY_RAW : 0) | | |
| 1492 | + (bUnf ? FDISPLAY_UNFORMATTED : 0) | | |
| 1493 | + (bHist ? FDISPLAY_HISTORY : 0) | | |
| 1494 | + (p==pSelect ? FDISPLAY_SELECTED : 0), | |
| 1495 | + zQuery | |
| 1496 | + ); | |
| 1084 | 1497 | |
| 1085 | 1498 | /* Advance to the next post in the thread. */ |
| 1086 | 1499 | if( mode==FD_CHRONO ){ |
| 1087 | 1500 | /* Chronological mode: display posts (optionally including edits) in their |
| 1088 | 1501 | ** original commit order. */ |
| @@ -1138,11 +1551,12 @@ | ||
| 1138 | 1551 | ** to all forum-related pages. It does not include page-specific |
| 1139 | 1552 | ** code (e.g. "forum.js"). |
| 1140 | 1553 | */ |
| 1141 | 1554 | static void forum_emit_js(void){ |
| 1142 | 1555 | builtin_fossil_js_bundle_or("copybutton", "pikchr", "confirmer", |
| 1143 | - NULL); | |
| 1556 | + "attach", "tabs", "storage", | |
| 1557 | + "popupwidget", NULL); | |
| 1144 | 1558 | builtin_request_js("fossil.page.forumpost.js"); |
| 1145 | 1559 | } |
| 1146 | 1560 | |
| 1147 | 1561 | /* |
| 1148 | 1562 | ** WEBPAGE: forumpost |
| @@ -1291,28 +1705,20 @@ | ||
| 1291 | 1705 | } |
| 1292 | 1706 | |
| 1293 | 1707 | /* |
| 1294 | 1708 | ** Return true if a forum post should be moderated. |
| 1295 | 1709 | */ |
| 1296 | -static int forum_need_moderation(void){ | |
| 1710 | +int forum_need_moderation(void){ | |
| 1297 | 1711 | if( P("domod") ) return 1; |
| 1298 | 1712 | if( g.perm.WrTForum ) return 0; |
| 1299 | 1713 | if( g.perm.ModForum ) return 0; |
| 1300 | 1714 | return 1; |
| 1301 | 1715 | } |
| 1302 | 1716 | |
| 1303 | -/* | |
| 1304 | -** Return true if the string is white-space only. | |
| 1305 | -*/ | |
| 1306 | -static int whitespace_only(const char *z){ | |
| 1307 | - if( z==0 ) return 1; | |
| 1308 | - while( z[0] && fossil_isspace(z[0]) ){ z++; } | |
| 1309 | - return z[0]==0; | |
| 1310 | -} | |
| 1311 | - | |
| 1312 | 1717 | /* Flags for use with forum_post() */ |
| 1313 | 1718 | #define FPOST_NO_ALERT 1 /* do not send any alerts */ |
| 1719 | +#define FPOST_DRYRUN 2 /* do not save the artifact */ | |
| 1314 | 1720 | |
| 1315 | 1721 | /* |
| 1316 | 1722 | ** Return a flags value for use with the final argument to |
| 1317 | 1723 | ** forum_post(), extracted from the CGI environment. |
| 1318 | 1724 | */ |
| @@ -1319,10 +1725,13 @@ | ||
| 1319 | 1725 | static int forum_post_flags(void){ |
| 1320 | 1726 | int iPostFlags = 0; |
| 1321 | 1727 | if( g.perm.Debug && P("fpsilent")!=0 ){ |
| 1322 | 1728 | iPostFlags |= FPOST_NO_ALERT; |
| 1323 | 1729 | } |
| 1730 | + if( P("dryrun")!=0 ){ | |
| 1731 | + iPostFlags |= FPOST_DRYRUN; | |
| 1732 | + } | |
| 1324 | 1733 | return iPostFlags; |
| 1325 | 1734 | } |
| 1326 | 1735 | |
| 1327 | 1736 | /* |
| 1328 | 1737 | ** Add a new Forum Post artifact to the repository. |
| @@ -1346,15 +1755,15 @@ | ||
| 1346 | 1755 | Manifest *pPost; |
| 1347 | 1756 | int nContent = zContent ? (int)strlen(zContent) : 0; |
| 1348 | 1757 | |
| 1349 | 1758 | schema_forum(); |
| 1350 | 1759 | if( !g.perm.Admin && (iEdit || iInReplyTo) |
| 1351 | - && forum_rid_is_closed(iEdit ? iEdit : iInReplyTo, 1) ){ | |
| 1760 | + && forum_rid_is_tagged(iEdit ? iEdit : iInReplyTo, "closed", 1) ){ | |
| 1352 | 1761 | forumpost_error_closed(); |
| 1353 | 1762 | return 0; |
| 1354 | 1763 | } |
| 1355 | - if( iEdit==0 && whitespace_only(zContent) ){ | |
| 1764 | + if( iEdit==0 && fossil_all_whitespace(zContent) ){ | |
| 1356 | 1765 | return 0; |
| 1357 | 1766 | } |
| 1358 | 1767 | if( iInReplyTo==0 && iEdit>0 ){ |
| 1359 | 1768 | iBasis = iEdit; |
| 1360 | 1769 | iInReplyTo = db_int(0, "SELECT firt FROM forumpost WHERE fpid=%d", iEdit); |
| @@ -1375,17 +1784,19 @@ | ||
| 1375 | 1784 | fossil_free(zG); |
| 1376 | 1785 | } |
| 1377 | 1786 | if( zTitle ){ |
| 1378 | 1787 | blob_appendf(&x, "H %F\n", zTitle); |
| 1379 | 1788 | } |
| 1380 | - zI = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", iInReplyTo); | |
| 1789 | + zI = rid_to_uuid(iInReplyTo); | |
| 1381 | 1790 | if( zI ){ |
| 1382 | 1791 | blob_appendf(&x, "I %s\n", zI); |
| 1383 | 1792 | fossil_free(zI); |
| 1384 | 1793 | } |
| 1385 | - if( fossil_strcmp(zMimetype,"text/x-fossil-wiki")!=0 ){ | |
| 1386 | - blob_appendf(&x, "N %s\n", zMimetype); | |
| 1794 | + if( zMimetype!=0 | |
| 1795 | + && zMimetype[0]!=0 | |
| 1796 | + && fossil_strcmp(zMimetype,"text/x-fossil-wiki")!=0 ){ | |
| 1797 | + blob_appendf(&x, "N %F\n", zMimetype); | |
| 1387 | 1798 | } |
| 1388 | 1799 | if( iEdit>0 ){ |
| 1389 | 1800 | char *zP = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", iEdit); |
| 1390 | 1801 | if( zP==0 ) webpage_error("missing edit artifact %d", iEdit); |
| 1391 | 1802 | blob_appendf(&x, "P %s\n", zP); |
| @@ -1413,11 +1824,11 @@ | ||
| 1413 | 1824 | webpage_error("malformed forum post artifact - %s", blob_str(&errMsg)); |
| 1414 | 1825 | } |
| 1415 | 1826 | webpage_assert( pPost->type==CFTYPE_FORUM ); |
| 1416 | 1827 | manifest_destroy(pPost); |
| 1417 | 1828 | |
| 1418 | - if( P("dryrun") ){ | |
| 1829 | + if( (iFlags & FPOST_DRYRUN)!=0 ){ | |
| 1419 | 1830 | @ <div class='debug'> |
| 1420 | 1831 | @ This is the artifact that would have been generated: |
| 1421 | 1832 | @ <pre>%h(blob_str(&x))</pre> |
| 1422 | 1833 | @ </div> |
| 1423 | 1834 | blob_reset(&x); |
| @@ -1452,44 +1863,87 @@ | ||
| 1452 | 1863 | mimetype_option_menu(zMimetype, "mimetype"); |
| 1453 | 1864 | @ <div class="forum-editor-widget"> |
| 1454 | 1865 | @ <textarea aria-label="Content:" name="content" class="wikiedit" \ |
| 1455 | 1866 | @ cols="80" rows="25" wrap="virtual">%h(zContent)</textarea></div> |
| 1456 | 1867 | } |
| 1868 | + | |
| 1869 | +/* | |
| 1870 | +** If PD("fpid") refers to a forum post, its rid is returned, else | |
| 1871 | +** this function emits an error does not does return. | |
| 1872 | +*/ | |
| 1873 | +static int forum_validate_fpid_param(void){ | |
| 1874 | + const char *zFpid = PD("fpid",""); | |
| 1875 | + int fpid = symbolic_name_to_rid(zFpid, "f"); | |
| 1876 | + if( fpid<=0 ){ | |
| 1877 | + webpage_error("Missing or invalid fpid parameter."); | |
| 1878 | + } | |
| 1879 | + return fpid; | |
| 1880 | +} | |
| 1881 | + | |
| 1882 | +/* | |
| 1883 | +** Internal helper for /forumpost_XYZ internal pages which tag/untag | |
| 1884 | +** posts. | |
| 1885 | +*/ | |
| 1886 | +static void forumpost_action_helper(const char *zTag, const char *zVal, | |
| 1887 | + int addTag, int validFpid){ | |
| 1888 | + if( !cgi_csrf_safe(2) ){ | |
| 1889 | + webpage_error("CSRF validation failed"); | |
| 1890 | + }else{ | |
| 1891 | + const int fpid = validFpid>0 ? validFpid : forum_validate_fpid_param(); | |
| 1892 | + if( fpid>0 ){ | |
| 1893 | + if( forumpost_tag(fpid, addTag, zTag, zVal) < 0 ){ | |
| 1894 | + webpage_error("Tagging artifact failed: %s", g.zErrMsg); | |
| 1895 | + }else{ | |
| 1896 | + cgi_redirectf("%R/forumpost/%S",P("fpid")); | |
| 1897 | + } | |
| 1898 | + } | |
| 1899 | + } | |
| 1900 | +} | |
| 1457 | 1901 | |
| 1458 | 1902 | /* |
| 1459 | 1903 | ** WEBPAGE: forumpost_close hidden |
| 1460 | 1904 | ** WEBPAGE: forumpost_reopen hidden |
| 1461 | 1905 | ** |
| 1462 | 1906 | ** fpid=X Hash of the post to be edited. REQUIRED |
| 1463 | -** reason=X Optional reason for closure. | |
| 1464 | 1907 | ** |
| 1465 | 1908 | ** Closes or re-opens the given forum post, within the bounds of the |
| 1466 | -** API for forumpost_close(). After (perhaps) modifying the "closed" | |
| 1909 | +** API for forumpost_tag(). After (perhaps) modifying the "closed" | |
| 1467 | 1910 | ** status of the given thread, it redirects to that post's thread |
| 1468 | 1911 | ** view. Requires admin privileges. |
| 1469 | 1912 | */ |
| 1470 | 1913 | void forum_page_close(void){ |
| 1471 | - const char *zFpid = PD("fpid",""); | |
| 1472 | - const char *zReason = 0; | |
| 1473 | - int fClose; | |
| 1474 | - int fpid; | |
| 1475 | - | |
| 1476 | 1914 | login_check_credentials(); |
| 1477 | 1915 | if( forumpost_may_close()==0 ){ |
| 1478 | 1916 | login_needed(g.anon.Admin); |
| 1479 | - return; | |
| 1480 | - } | |
| 1481 | - cgi_csrf_verify(); | |
| 1482 | - fpid = symbolic_name_to_rid(zFpid, "f"); | |
| 1483 | - if( fpid<=0 ){ | |
| 1484 | - webpage_error("Missing or invalid fpid query parameter"); | |
| 1485 | - } | |
| 1486 | - fClose = sqlite3_strglob("*_close*", g.zPath)==0; | |
| 1487 | - if( fClose ) zReason = PD("reason",0); | |
| 1488 | - forumpost_close(fpid, fClose, zReason); | |
| 1489 | - cgi_redirectf("%R/forumpost/%S",zFpid); | |
| 1490 | - return; | |
| 1917 | + }else{ | |
| 1918 | + const int bIsAdd = sqlite3_strglob("*_close*", g.zPath)==0; | |
| 1919 | + forumpost_action_helper("closed", 0, bIsAdd, 0); | |
| 1920 | + } | |
| 1921 | +} | |
| 1922 | + | |
| 1923 | +/* | |
| 1924 | +** WEBPAGE: forumpost_status hidden | |
| 1925 | +** | |
| 1926 | +** fpid=X Hash of the post to be edited. REQUIRED | |
| 1927 | +** status=Y New status value. REQUIRED | |
| 1928 | +** | |
| 1929 | +** Updates the current status=Y tag on the first version of | |
| 1930 | +** the forum post X. Requires forum_may_set_status() permissions. | |
| 1931 | +*/ | |
| 1932 | +void forum_page_status(void){ | |
| 1933 | + int fpid; | |
| 1934 | + login_check_credentials(); | |
| 1935 | + fpid = forum_validate_fpid_param(); | |
| 1936 | + if(forum_may_set_status(fpid)){ | |
| 1937 | + const char *zStatus = PD("status",0); | |
| 1938 | + if( !zStatus || !zStatus[0] ){ | |
| 1939 | + webpage_error("Missing required status."); | |
| 1940 | + } | |
| 1941 | + forumpost_action_helper("status", zStatus, 1, fpid); | |
| 1942 | + }else{ | |
| 1943 | + webpage_error("You lack permissions to change this post's status."); | |
| 1944 | + } | |
| 1491 | 1945 | } |
| 1492 | 1946 | |
| 1493 | 1947 | /* |
| 1494 | 1948 | ** WEBPAGE: forumnew |
| 1495 | 1949 | ** WEBPAGE: forumedit |
| @@ -1578,11 +2032,25 @@ | ||
| 1578 | 2032 | @ </div> |
| 1579 | 2033 | } |
| 1580 | 2034 | } |
| 1581 | 2035 | |
| 1582 | 2036 | /* |
| 1583 | -** WEBPAGE: forume1 | |
| 2037 | +** If the user has AttachForum permissions, emit a notice that | |
| 2038 | +** attachments may be added after saving. If p is not NULL, also emit | |
| 2039 | +** its list of attachments. We only emit this for No-JS environments, | |
| 2040 | +** as in JS environments the interactive forum editor includes | |
| 2041 | +** attachment support. | |
| 2042 | +*/ | |
| 2043 | +static void forum_render_attachment_notice(void){ | |
| 2044 | + if( g.perm.AttachForum ){ | |
| 2045 | + @ <noscript><div>You will be able to attach files to this post | |
| 2046 | + @ after saving it.</div></noscript> | |
| 2047 | + } | |
| 2048 | +} | |
| 2049 | + | |
| 2050 | +/* | |
| 2051 | +** WEBPAGE: forume1 hidden | |
| 1584 | 2052 | ** |
| 1585 | 2053 | ** Start a new forum thread. |
| 1586 | 2054 | */ |
| 1587 | 2055 | void forumnew_page(void){ |
| 1588 | 2056 | const char *zTitle = PDT("title",""); |
| @@ -1596,35 +2064,45 @@ | ||
| 1596 | 2064 | } |
| 1597 | 2065 | if( P("submit") && cgi_csrf_safe(2) ){ |
| 1598 | 2066 | if( forum_post(zTitle, 0, 0, 0, zMimetype, zContent, |
| 1599 | 2067 | forum_post_flags()) ) return; |
| 1600 | 2068 | } |
| 1601 | - if( P("preview") && !whitespace_only(zContent) ){ | |
| 2069 | + if( P("preview") && !fossil_all_whitespace(zContent) ){ | |
| 1602 | 2070 | @ <h1>Preview:</h1> |
| 1603 | 2071 | forum_render(zTitle, zMimetype, zContent, "forumEdit", 1); |
| 1604 | 2072 | } |
| 1605 | 2073 | style_set_current_feature("forum"); |
| 1606 | 2074 | style_header("New Forum Thread"); |
| 1607 | - @ <form action="%R/forume1" method="POST"> | |
| 2075 | + | |
| 2076 | + @ <form action="%R/forume1" method="POST" \ | |
| 2077 | + @ class="remove-if-replaced"> | |
| 1608 | 2078 | @ <h1>New Thread:</h1> |
| 1609 | 2079 | forum_from_line(); |
| 1610 | 2080 | forum_post_widget(zTitle, zMimetype, zContent); |
| 1611 | 2081 | @ <input type="submit" name="preview" value="Preview"> |
| 1612 | - if( P("preview") && !whitespace_only(zContent) ){ | |
| 2082 | + if( P("preview") && !fossil_all_whitespace(zContent) ){ | |
| 1613 | 2083 | @ <input type="submit" name="submit" value="Submit"> |
| 1614 | 2084 | }else{ |
| 1615 | 2085 | @ <input type="submit" name="submit" value="Submit" disabled> |
| 1616 | 2086 | } |
| 1617 | 2087 | forum_render_debug_options(); |
| 1618 | 2088 | login_insert_csrf_secret(); |
| 1619 | 2089 | @ </form> |
| 2090 | + /* When JS is disabled the block above will work. When it's | |
| 2091 | + enabled, the above will be removed and JS will render the editor | |
| 2092 | + form in the next element. */ | |
| 2093 | + @ <div hidden id='forumnew-placeholder'> | |
| 2094 | + @ <input type='hidden' name='title' value='%h(zTitle)'> | |
| 2095 | + login_insert_csrf_secret(); | |
| 2096 | + @ </div> | |
| 2097 | + forum_render_attachment_notice(); | |
| 1620 | 2098 | forum_emit_js(); |
| 1621 | 2099 | style_finish_page(); |
| 1622 | 2100 | } |
| 1623 | 2101 | |
| 1624 | 2102 | /* |
| 1625 | -** WEBPAGE: forume2 | |
| 2103 | +** WEBPAGE: forume2 hidden | |
| 1626 | 2104 | ** |
| 1627 | 2105 | ** Edit an existing forum message. |
| 1628 | 2106 | ** Query parameters: |
| 1629 | 2107 | ** |
| 1630 | 2108 | ** fpid=X Hash of the post to be edited. REQUIRED |
| @@ -1655,28 +2133,30 @@ | ||
| 1655 | 2133 | fpid = symbolic_name_to_rid(zFpid, "f"); |
| 1656 | 2134 | if( fpid<=0 || (pPost = manifest_get(fpid, CFTYPE_FORUM, 0))==0 ){ |
| 1657 | 2135 | webpage_error("Missing or invalid fpid query parameter"); |
| 1658 | 2136 | } |
| 1659 | 2137 | froot = db_int(0, "SELECT froot FROM forumpost WHERE fpid=%d", fpid); |
| 1660 | - if( froot==0 || (pRootPost = manifest_get(froot, CFTYPE_FORUM, 0))==0 ){ | |
| 2138 | + if( (froot==0 || (pRootPost = manifest_get(froot, CFTYPE_FORUM, 0))==0) | |
| 2139 | + && P("reject")==0 | |
| 2140 | + ){ | |
| 1661 | 2141 | webpage_error("fpid does not appear to be a forum post: \"%d\"", fpid); |
| 1662 | 2142 | } |
| 1663 | 2143 | if( P("cancel") ){ |
| 1664 | 2144 | cgi_redirectf("%R/forumpost/%S",zFpid); |
| 1665 | 2145 | return; |
| 1666 | 2146 | } |
| 1667 | 2147 | bPreview = P("preview")!=0; |
| 1668 | 2148 | bReply = P("reply")!=0; |
| 1669 | - iClosed = forum_rid_is_closed(fpid, 1); | |
| 2149 | + iClosed = forum_rid_is_tagged(fpid, "closed", 1); | |
| 1670 | 2150 | isCsrfSafe = cgi_csrf_safe(2); |
| 1671 | 2151 | bPrivate = content_is_private(fpid); |
| 1672 | 2152 | bSameUser = login_is_individual() |
| 1673 | 2153 | && fossil_strcmp(pPost->zUser, g.zLogin)==0; |
| 1674 | 2154 | if( isCsrfSafe && (g.perm.ModForum || (bPrivate && bSameUser)) ){ |
| 1675 | 2155 | if( g.perm.ModForum && P("approve") ){ |
| 1676 | 2156 | const char *zUserToTrust; |
| 1677 | - moderation_approve('f', fpid); | |
| 2157 | + moderation_forumpost_approve(fpid); | |
| 1678 | 2158 | if( g.perm.AdminForum |
| 1679 | 2159 | && PB("trust") |
| 1680 | 2160 | && (zUserToTrust = P("trustuser"))!=0 |
| 1681 | 2161 | ){ |
| 1682 | 2162 | db_unprotect(PROTECT_USER); |
| @@ -1693,11 +2173,11 @@ | ||
| 1693 | 2173 | db_text(0, |
| 1694 | 2174 | "SELECT uuid FROM forumpost, blob" |
| 1695 | 2175 | " WHERE forumpost.fpid=%d AND blob.rid=forumpost.firt", |
| 1696 | 2176 | fpid |
| 1697 | 2177 | ); |
| 1698 | - moderation_disapprove(fpid); | |
| 2178 | + moderation_forumpost_disapprove(fpid); | |
| 1699 | 2179 | if( zParent ){ |
| 1700 | 2180 | cgi_redirectf("%R/forumpost/%S",zParent); |
| 1701 | 2181 | }else{ |
| 1702 | 2182 | cgi_redirectf("%R/forum"); |
| 1703 | 2183 | } |
| @@ -1707,11 +2187,11 @@ | ||
| 1707 | 2187 | style_set_current_feature("forum"); |
| 1708 | 2188 | isDelete = P("nullout")!=0; |
| 1709 | 2189 | if( P("submit") |
| 1710 | 2190 | && isCsrfSafe |
| 1711 | 2191 | && (zContent = PDT("content",""))!=0 |
| 1712 | - && (!whitespace_only(zContent) || isDelete) | |
| 2192 | + && (isDelete || !fossil_all_whitespace(zContent)) | |
| 1713 | 2193 | ){ |
| 1714 | 2194 | int done = 1; |
| 1715 | 2195 | const char *zMimetype = PD("mimetype",DEFAULT_FORUM_MIMETYPE); |
| 1716 | 2196 | if( bReply ){ |
| 1717 | 2197 | done = forum_post(0, fpid, 0, 0, zMimetype, zContent, |
| @@ -1785,11 +2265,11 @@ | ||
| 1785 | 2265 | zDisplayName = display_name_from_login(pPost->zUser); |
| 1786 | 2266 | @ <h3 class='forumPostHdr'>By %s(zDisplayName) on %h(zDate)</h3> |
| 1787 | 2267 | fossil_free(zDisplayName); |
| 1788 | 2268 | fossil_free(zDate); |
| 1789 | 2269 | forum_render(0, pPost->zMimetype, pPost->zWiki, "forumEdit", 1); |
| 1790 | - if( bPreview && !whitespace_only(zContent) ){ | |
| 2270 | + if( bPreview && !fossil_all_whitespace(zContent) ){ | |
| 1791 | 2271 | @ <h2>Preview:</h2> |
| 1792 | 2272 | forum_render(0, zMimetype,zContent, "forumEdit", 1); |
| 1793 | 2273 | } |
| 1794 | 2274 | @ <h2>Enter Reply:</h2> |
| 1795 | 2275 | @ <form action="%R/forume2" method="POST"> |
| @@ -1800,18 +2280,24 @@ | ||
| 1800 | 2280 | } |
| 1801 | 2281 | if( !isDelete ){ |
| 1802 | 2282 | @ <input type="submit" name="preview" value="Preview"> |
| 1803 | 2283 | } |
| 1804 | 2284 | @ <input type="submit" name="cancel" value="Cancel"> |
| 1805 | - if( (bPreview && !whitespace_only(zContent)) || isDelete ){ | |
| 2285 | + if( isDelete || (bPreview && !fossil_all_whitespace(zContent)) ){ | |
| 1806 | 2286 | if( !iClosed || g.perm.Admin ) { |
| 1807 | 2287 | @ <input type="submit" name="submit" value="Submit"> |
| 1808 | 2288 | } |
| 1809 | 2289 | } |
| 1810 | 2290 | forum_render_debug_options(); |
| 1811 | 2291 | login_insert_csrf_secret(); |
| 1812 | 2292 | @ </form> |
| 2293 | + if( !bReply ){ | |
| 2294 | + forum_render_attachment_list(rid_to_uuid(fpid)); | |
| 2295 | + } | |
| 2296 | + if( !isDelete ){ | |
| 2297 | + forum_render_attachment_notice(); | |
| 2298 | + } | |
| 1813 | 2299 | forum_emit_js(); |
| 1814 | 2300 | style_finish_page(); |
| 1815 | 2301 | } |
| 1816 | 2302 | |
| 1817 | 2303 | /* |
| @@ -1818,17 +2304,34 @@ | ||
| 1818 | 2304 | ** SETTING: forum-close-policy boolean default=off |
| 1819 | 2305 | ** If true, forum moderators may close/re-open forum posts, and reply |
| 1820 | 2306 | ** to closed posts. If false, only administrators may do so. Note that |
| 1821 | 2307 | ** this only affects the forum web UI, not post-closing tags which |
| 1822 | 2308 | ** arrive via the command-line or from synchronization with a remote. |
| 1823 | -*/ | |
| 1824 | -/* | |
| 2309 | +** This policy also determines whether moderators may delete forum | |
| 2310 | +** attachments. | |
| 2311 | +** | |
| 1825 | 2312 | ** SETTING: forum-title width=20 default=Forum |
| 1826 | 2313 | ** This is the name or "title" of the Forum for this repository. The |
| 1827 | 2314 | ** default is just "Forum". But in some setups, admins might want to |
| 1828 | 2315 | ** change it to "Developer Forum" or "User Forum" or whatever other name |
| 1829 | 2316 | ** seems more appropriate for the particular usage. |
| 2317 | +** | |
| 2318 | +** SETTING: attachment-size-limit width=16 | |
| 2319 | +** The maximum number of bytes for an attachment to a wiki page, | |
| 2320 | +** ticket, tech note, or forum post. The default (or 0) is unlimited | |
| 2321 | +** but a limit may be imposed by the web server or a proxy. | |
| 2322 | +** | |
| 2323 | +** SETTING: forum-statuses width=40 block-text | |
| 2324 | +** This JSON5-formatted value defines an array of objects describing | |
| 2325 | +** the available statuses of forum posts. Each entry of the array must | |
| 2326 | +** be an object in the form {label:"X",value:"Y"}. | |
| 2327 | +** The label is used in the UI and value becomes the value of the | |
| 2328 | +** "status" tag on forum posts. Any forum post which has a status | |
| 2329 | +** value which does not appear in this list is treated as if it had | |
| 2330 | +** the first value from this list. If this setting is empty, is | |
| 2331 | +** ill-formed JSON, or has only a single entry then the forum will | |
| 2332 | +** lack the capability of setting and filtering by status. | |
| 1830 | 2333 | */ |
| 1831 | 2334 | |
| 1832 | 2335 | /* |
| 1833 | 2336 | ** WEBPAGE: setup_forum |
| 1834 | 2337 | ** |
| @@ -1946,19 +2449,113 @@ | ||
| 1946 | 2449 | @ <a href='%R/help/%h(pSetting->name)'>%h(pSetting->name)</a>: |
| 1947 | 2450 | @ </td><td> |
| 1948 | 2451 | entry_attribute("", 25, pSetting->name, zQP/*works-like:""*/, |
| 1949 | 2452 | pSetting->def, 0); |
| 1950 | 2453 | @ </td></tr> |
| 1951 | - } | |
| 2454 | + } | |
| 1952 | 2455 | } |
| 1953 | 2456 | @ </tbody></table> |
| 1954 | 2457 | @ <input type='submit' name='submit' value='Apply changes'> |
| 1955 | 2458 | @ </form> |
| 1956 | 2459 | } |
| 1957 | 2460 | |
| 1958 | 2461 | style_finish_page(); |
| 1959 | 2462 | } |
| 2463 | + | |
| 2464 | +/* | |
| 2465 | +** If the forum-statuses setting is active and has 2 or more entries, | |
| 2466 | +** this adds a submenu for selecting the status filter, else it emits | |
| 2467 | +** nothing. | |
| 2468 | +*/ | |
| 2469 | +static void forum_status_submenu(void){ | |
| 2470 | + const ForumStatusList * const fss = forum_statuses(); | |
| 2471 | + static int i = 0; | |
| 2472 | + static const char **az; | |
| 2473 | + if( i==0 && fss->n>1 ){ | |
| 2474 | + unsigned j; | |
| 2475 | + az = fossil_malloc(sizeof(az[0]) * ((1 + fss->n) * 2)); | |
| 2476 | + az[i++] = "*"; | |
| 2477 | + az[i++] = "Any status"; | |
| 2478 | + for( j = 0; j < fss->n; ++j ){ | |
| 2479 | + const ForumStatus * fs = &fss->aStatus[j]; | |
| 2480 | + /* Potential TODO: skip any entries for which there are no | |
| 2481 | + ** forum posts with a status=${fs->zValue} tag. */ | |
| 2482 | + az[i++] = fs->zValue; | |
| 2483 | + az[i++] = fs->zLabel; | |
| 2484 | + } | |
| 2485 | + //assert( i==(1+fss->n)*2 ); | |
| 2486 | + } | |
| 2487 | + if( i ){ | |
| 2488 | + cookie_link_parameter("status","forumStatus","*"); | |
| 2489 | + style_submenu_multichoice("status", i/2, az, 0); | |
| 2490 | + } | |
| 2491 | +} | |
| 2492 | + | |
| 2493 | +/* | |
| 2494 | +** Transient SQL Function: status_match(FROOT) | |
| 2495 | +** | |
| 2496 | +** Return true if the forum thread identified by FROOT should be included | |
| 2497 | +** in a list of threads. Used to implement the status=NAME query parameter | |
| 2498 | +** on /forum. | |
| 2499 | +** | |
| 2500 | +** The result of this routine depends on the content of the | |
| 2501 | +** ForumStatusMatch *pMData object that is available via sqlite3_user_data(). | |
| 2502 | +** | |
| 2503 | +** * If pMData==NULL, always return true. This means that no | |
| 2504 | +** filtering of threads is being done. This is the common case. | |
| 2505 | +** | |
| 2506 | +** * If FROOT contains a status property value that matches | |
| 2507 | +** pMData->iMatch, return true. | |
| 2508 | +** | |
| 2509 | +** * if pMData->iMatch==0 (meaning we want to match the default | |
| 2510 | +** status value) and if the FROOT thread contains a status that | |
| 2511 | +** is not on the list of statuses or if FROOT has no statue | |
| 2512 | +** property at all, then return true. In other words, a forum | |
| 2513 | +** thread with no status property or an unknown status property | |
| 2514 | +** is treated as if it had the default status. | |
| 2515 | +** | |
| 2516 | +** * Otherwise, return false. | |
| 2517 | +*/ | |
| 2518 | +static void forum_status_match( | |
| 2519 | + sqlite3_context *context, | |
| 2520 | + int argc, | |
| 2521 | + sqlite3_value **argv | |
| 2522 | +){ | |
| 2523 | + static Stmt q; | |
| 2524 | + ForumStatusMatch *pMData = sqlite3_user_data(context); | |
| 2525 | + int i; | |
| 2526 | + | |
| 2527 | + if( pMData==0 ){ | |
| 2528 | + sqlite3_result_int(context, 1); | |
| 2529 | + return; | |
| 2530 | + } | |
| 2531 | + db_static_prepare(&q, | |
| 2532 | + "SELECT value FROM tagxref\n" | |
| 2533 | + " WHERE tagid=%d\n" | |
| 2534 | + " AND tagtype>=1\n" | |
| 2535 | + " AND rid=:rid\n" | |
| 2536 | + " ORDER BY mtime DESC LIMIT 1", | |
| 2537 | + pMData->eStatusTag | |
| 2538 | + ); | |
| 2539 | + db_bind_int(&q, ":rid", sqlite3_value_int(argv[0])); | |
| 2540 | + if( db_step(&q)==SQLITE_ROW ){ | |
| 2541 | + const char *zValue = (const char*)db_column_text(&q,0); | |
| 2542 | + const ForumStatusList *pFses = pMData->pFses; | |
| 2543 | + if( zValue==0 ){ | |
| 2544 | + i = 0; | |
| 2545 | + }else{ | |
| 2546 | + for(i=0; i<pFses->n; i++){ | |
| 2547 | + if( fossil_strcmp(pFses->aStatus[i].zValue,zValue)==0 ) break; | |
| 2548 | + } | |
| 2549 | + } | |
| 2550 | + if( i>=pMData->pFses->n ) i = 0; | |
| 2551 | + }else{ | |
| 2552 | + i = 0; | |
| 2553 | + } | |
| 2554 | + db_reset(&q); | |
| 2555 | + sqlite3_result_int(context, i==pMData->iMatch); | |
| 2556 | +} | |
| 1960 | 2557 | |
| 1961 | 2558 | /* |
| 1962 | 2559 | ** WEBPAGE: forummain |
| 1963 | 2560 | ** WEBPAGE: forum |
| 1964 | 2561 | ** |
| @@ -1975,30 +2572,38 @@ | ||
| 1975 | 2572 | void forum_main_page(void){ |
| 1976 | 2573 | Stmt q; |
| 1977 | 2574 | int iLimit = 0, iOfst, iCnt; |
| 1978 | 2575 | int srchFlags; |
| 1979 | 2576 | const int isSearch = P("s")!=0; |
| 1980 | - char const *zLimit = 0; | |
| 2577 | + const char *zStatusFilter; | |
| 2578 | + char const *zLimit = 0; /* Value of the n= query parameter */ | |
| 2579 | + int eStatusTag = 0; /* tagid for the "status" property */ | |
| 2580 | + int bHasStatus = 0; /* True if forum-statuses setting exists */ | |
| 2581 | + int bFilter = 0; /* True if status=NAME query parameter */ | |
| 2582 | + int bHasForum = 0; /* True if forumpost table exists */ | |
| 2583 | + const ForumStatusList *pFstat = forum_statuses(); | |
| 2584 | + ForumStatusMatch sFSM; /* Aux data to status_match() SQL function */ | |
| 1981 | 2585 | |
| 1982 | 2586 | login_check_credentials(); |
| 1983 | 2587 | srchFlags = search_restrict(SRCH_FORUM); |
| 1984 | 2588 | if( !g.perm.RdForum ){ |
| 1985 | 2589 | login_needed(g.anon.RdForum); |
| 1986 | 2590 | return; |
| 1987 | 2591 | } |
| 1988 | 2592 | cgi_check_for_malice(); |
| 2593 | + bHasForum = db_table_exists("repository","forumpost"); | |
| 2594 | + if( bHasForum ){ | |
| 2595 | + eStatusTag = db_int(0, "SELECT tagid FROM tag WHERE tagname='status'"); | |
| 2596 | + bHasStatus = pFstat->n>1; | |
| 2597 | + } | |
| 1989 | 2598 | style_set_current_feature("forum"); |
| 1990 | - style_header("%s%s", db_get("forum-title","Forum"), | |
| 2599 | + style_header("%s%s", db_get("forum-title","Forum"), | |
| 1991 | 2600 | isSearch ? " Search Results" : ""); |
| 1992 | 2601 | style_submenu_element("Timeline", "%R/timeline?ss=v&y=f&vfx"); |
| 1993 | 2602 | if( g.perm.WrForum ){ |
| 1994 | 2603 | style_submenu_element("New Thread","%R/forumnew"); |
| 1995 | 2604 | }else{ |
| 1996 | - /* Can't combine this with previous case using the ternary operator | |
| 1997 | - * because that causes an error yelling about "non-constant format" | |
| 1998 | - * with some compilers. I can't see it, since both expressions have | |
| 1999 | - * the same format, but I'm no C spec lawyer. */ | |
| 2000 | 2605 | style_submenu_element("New Thread","%R/login"); |
| 2001 | 2606 | } |
| 2002 | 2607 | if( g.perm.ModForum && moderation_needed() ){ |
| 2003 | 2608 | style_submenu_element("Moderation Requests", "%R/modreq"); |
| 2004 | 2609 | } |
| @@ -2021,95 +2626,577 @@ | ||
| 2021 | 2626 | cgi_replace_query_parameter("n", fossil_strdup("25")) |
| 2022 | 2627 | /*for the sake of Max, below*/; |
| 2023 | 2628 | iLimit = 25; |
| 2024 | 2629 | } |
| 2025 | 2630 | style_submenu_entry("n","Max:",4,0); |
| 2631 | + forum_status_submenu(); | |
| 2632 | + zStatusFilter = P("status") /*must be after forum_status_submenu()!*/; | |
| 2026 | 2633 | iOfst = atoi(PD("x","0")); |
| 2027 | 2634 | iCnt = 0; |
| 2028 | - if( db_table_exists("repository","forumpost") ){ | |
| 2635 | + if( zStatusFilter ){ | |
| 2636 | + if( zStatusFilter[0]==0 || 0==fossil_strcmp("*",zStatusFilter) ){ | |
| 2637 | + zStatusFilter = 0; | |
| 2638 | + }else{ | |
| 2639 | + bFilter = bHasStatus; | |
| 2640 | + } | |
| 2641 | + } | |
| 2642 | + if( bHasForum ){ | |
| 2643 | + Stmt qStat = empty_Stmt; /* Query to get status information */ | |
| 2644 | + if( bHasStatus ){ | |
| 2645 | + /* The qStat query runs once for each output row generate by the | |
| 2646 | + ** q query. It determines the value and label of the status for | |
| 2647 | + ** the row with froot=:rowid | |
| 2648 | + */ | |
| 2649 | + db_prepare(&qStat, | |
| 2650 | + "SELECT tagxref.value, forumstatus.label\n" | |
| 2651 | + " FROM forumstatus, tagxref\n" | |
| 2652 | + " WHERE tagid=%d AND tagtype>=1\n" | |
| 2653 | + " AND forumstatus.value=tagxref.value\n" | |
| 2654 | + " AND rid=:rid\n" | |
| 2655 | + " ORDER BY mtime DESC", | |
| 2656 | + eStatusTag | |
| 2657 | + ); | |
| 2658 | + } | |
| 2659 | + | |
| 2660 | + /* Create the status_match() SQL function that will determine | |
| 2661 | + ** whether or not each thread in the "q" query below is eligible | |
| 2662 | + ** for display | |
| 2663 | + */ | |
| 2664 | + if( bFilter ){ | |
| 2665 | + sFSM.pFses = pFstat; | |
| 2666 | + sFSM.eStatusTag = eStatusTag; | |
| 2667 | + for(sFSM.iMatch=0; sFSM.iMatch<pFstat->n; sFSM.iMatch++){ | |
| 2668 | + if( 0==fossil_strcmp(zStatusFilter, | |
| 2669 | + pFstat->aStatus[sFSM.iMatch].zValue) ){ | |
| 2670 | + break; | |
| 2671 | + } | |
| 2672 | + } | |
| 2673 | + sqlite3_create_function(g.db,"status_match",1,SQLITE_UTF8,(void*)&sFSM, | |
| 2674 | + forum_status_match, 0, 0); | |
| 2675 | + }else{ | |
| 2676 | + sqlite3_create_function(g.db,"status_match",1,SQLITE_UTF8,0, | |
| 2677 | + forum_status_match, 0, 0); | |
| 2678 | + } | |
| 2679 | + | |
| 2029 | 2680 | db_prepare(&q, |
| 2030 | - "WITH thread(age,duration,cnt,root,last) AS (" | |
| 2031 | - " SELECT" | |
| 2032 | - " julianday('now') - max(fmtime)," | |
| 2033 | - " max(fmtime) - min(fmtime)," | |
| 2034 | - " sum(fprev IS NULL)," | |
| 2035 | - " froot," | |
| 2036 | - " (SELECT fpid FROM forumpost AS y" | |
| 2037 | - " WHERE y.froot=x.froot %s" | |
| 2038 | - " ORDER BY y.fmtime DESC LIMIT 1)" | |
| 2039 | - " FROM forumpost AS x" | |
| 2040 | - " WHERE %s" | |
| 2041 | - " GROUP BY froot" | |
| 2042 | - " ORDER BY 1 LIMIT %d OFFSET %d" | |
| 2043 | - ")" | |
| 2044 | - "SELECT" | |
| 2045 | - " thread.age," /* 0 */ | |
| 2046 | - " thread.duration," /* 1 */ | |
| 2047 | - " thread.cnt," /* 2 */ | |
| 2048 | - " blob.uuid," /* 3 */ | |
| 2049 | - " substr(event.comment,instr(event.comment,':')+1)," /* 4 */ | |
| 2050 | - " thread.last" /* 5 */ | |
| 2051 | - " FROM thread, blob, event" | |
| 2052 | - " WHERE blob.rid=thread.last" | |
| 2053 | - " AND event.objid=thread.last" | |
| 2681 | + "WITH thread(root,endtime,lastrid) AS (\n" | |
| 2682 | + " SELECT\n" | |
| 2683 | + " froot,\n" | |
| 2684 | + " max(fmtime),\n" | |
| 2685 | + " fpid\n" | |
| 2686 | + " FROM forumpost\n" | |
| 2687 | + " WHERE %s/*ModForum*/\n" | |
| 2688 | + " GROUP BY froot\n" | |
| 2689 | + " HAVING status_match(froot)\n" | |
| 2690 | + " ORDER BY 2 DESC\n" | |
| 2691 | + " LIMIT %d OFFSET %d\n" | |
| 2692 | + ")\n" | |
| 2693 | + "SELECT\n" | |
| 2694 | + " julianday('now') - thread.endtime,\n" /* 0 */ | |
| 2695 | + " thread.endtime - " | |
| 2696 | + "(SELECT fmtime FROM forumpost WHERE fpid=root),\n" /* 1 */ | |
| 2697 | + " (SELECT sum(fprev IS NULL) FROM forumpost" | |
| 2698 | + " WHERE froot=root),\n" /* 2 */ | |
| 2699 | + " blob.uuid,\n" /* 3 */ | |
| 2700 | + " substr(event.comment,instr(event.comment,':')+1),\n" /* 4 */ | |
| 2701 | + " thread.lastrid,\n" /* 5 */ | |
| 2702 | + " thread.root\n" /* 6 */ | |
| 2703 | + " FROM thread, blob, event\n" | |
| 2704 | + " WHERE blob.rid=thread.lastrid\n" | |
| 2705 | + " AND event.objid=thread.lastrid\n" | |
| 2054 | 2706 | " ORDER BY 1;", |
| 2055 | - g.perm.ModForum ? "" : "AND y.fpid NOT IN private" /*safe-for-%s*/, | |
| 2056 | 2707 | g.perm.ModForum ? "true" : "fpid NOT IN private" /*safe-for-%s*/, |
| 2057 | 2708 | iLimit+1, iOfst |
| 2058 | 2709 | ); |
| 2059 | 2710 | while( db_step(&q)==SQLITE_ROW ){ |
| 2060 | - char *zAge = human_readable_age(db_column_double(&q,0)); | |
| 2061 | - int nMsg = db_column_int(&q, 2); | |
| 2062 | - const char *zUuid = db_column_text(&q, 3); | |
| 2063 | - const char *zTitle = db_column_text(&q, 4); | |
| 2711 | + char *zAge; | |
| 2712 | + int nMsg; | |
| 2713 | + const char *zUuid; | |
| 2714 | + const char *zTitle; | |
| 2715 | + const char *zStatus; | |
| 2716 | + const char *zStatusLbl; | |
| 2717 | + const int bShowStatus = bHasStatus && !zStatusFilter; | |
| 2718 | + const int nCols = bShowStatus ? 4 : 3; | |
| 2719 | + | |
| 2720 | + if( qStat.pStmt ){ | |
| 2721 | + /* Determine the status value for this row */ | |
| 2722 | + db_reset(&qStat); | |
| 2723 | + db_bind_int(&qStat, ":rid", db_column_int(&q,6)); | |
| 2724 | + if( db_step(&qStat)==SQLITE_ROW ){ | |
| 2725 | + zStatus = db_column_text(&qStat, 0); | |
| 2726 | + zStatusLbl = db_column_text(&qStat, 1); | |
| 2727 | + }else{ | |
| 2728 | + zStatus = pFstat->aStatus[0].zValue; | |
| 2729 | + zStatusLbl = pFstat->aStatus[0].zLabel; | |
| 2730 | + } | |
| 2731 | + }else{ | |
| 2732 | + zStatus = zStatusLbl = NULL; | |
| 2733 | + } | |
| 2734 | + zAge = human_readable_age(db_column_double(&q,0)); | |
| 2735 | + nMsg = db_column_int(&q, 2); | |
| 2736 | + zUuid = db_column_text(&q, 3); | |
| 2737 | + zTitle = db_column_text(&q, 4); | |
| 2064 | 2738 | if( iCnt==0 ){ |
| 2739 | + char *zTail = bFilter ? mprintf(" with status=%Q", zStatusFilter): 0; | |
| 2065 | 2740 | if( iOfst>0 ){ |
| 2066 | - @ <h1>Threads at least %s(zAge) old</h1> | |
| 2741 | + @ <h1>Threads at least %s(zAge) old%h(zTail ? zTail : "")</h1> | |
| 2067 | 2742 | }else{ |
| 2068 | - @ <h1>Most recent threads</h1> | |
| 2743 | + @ <h1>Most recent threads%h(zTail ? zTail : "")</h1> | |
| 2069 | 2744 | } |
| 2745 | + fossil_free(zTail); | |
| 2070 | 2746 | @ <div class='forumPosts fileage'><table width="100%%"> |
| 2071 | 2747 | if( iOfst>0 ){ |
| 2072 | 2748 | if( iOfst>iLimit ){ |
| 2073 | - @ <tr><td colspan="3">\ | |
| 2074 | - @ %z(href("%R/forum?x=%d&n=%d",iOfst-iLimit,iLimit))\ | |
| 2075 | - @ ↑ Newer...</a></td></tr> | |
| 2749 | + @ <tr><td colspan="%d(nCols)">\ | |
| 2750 | + @ <a href='%R/forum?x=%d(iOfst-iLimit)&n=%d(iLimit) \ | |
| 2751 | + if( bFilter ){ | |
| 2752 | + @ &status=%T(zStatusFilter)\ | |
| 2753 | + } | |
| 2754 | + @ '>↑ Newer...</a></td></tr> | |
| 2076 | 2755 | }else{ |
| 2077 | - @ <tr><td colspan="3">%z(href("%R/forum?n=%d",iLimit))\ | |
| 2078 | - @ ↑ Newer...</a></td></tr> | |
| 2756 | + @ <tr><td colspan="%d(nCols)">\ | |
| 2757 | + @ <a href='%R/forum?n=%d(iLimit)\ | |
| 2758 | + if( bFilter ){ | |
| 2759 | + @ &status=%T(zStatusFilter) \ | |
| 2760 | + } | |
| 2761 | + @ '>↑ Newer...</a></td></tr> | |
| 2079 | 2762 | } |
| 2080 | 2763 | } |
| 2081 | 2764 | } |
| 2082 | 2765 | iCnt++; |
| 2083 | 2766 | if( iCnt>iLimit ){ |
| 2084 | - @ <tr><td colspan="3">\ | |
| 2085 | - @ %z(href("%R/forum?x=%d&n=%d",iOfst+iLimit,iLimit))\ | |
| 2086 | - @ ↓ Older...</a></td></tr> | |
| 2767 | + @ <tr><td colspan="%d(nCols)">\ | |
| 2768 | + @ <a href='%R/forum?x=%d(iOfst+iLimit)&n=%d(iLimit) \ | |
| 2769 | + if( bFilter ){ | |
| 2770 | + @ &status=%T(zStatusFilter)\ | |
| 2771 | + } | |
| 2772 | + @ '>↓ Older...</a></td></tr> | |
| 2087 | 2773 | fossil_free(zAge); |
| 2088 | 2774 | break; |
| 2089 | 2775 | } |
| 2090 | - @ <tr><td>%h(zAge) ago</td> | |
| 2091 | - @ <td>%z(href("%R/forumpost/%S",zUuid))%h(zTitle)</a></td> | |
| 2092 | - @ <td>\ | |
| 2776 | + @ <tr \ | |
| 2777 | + if( bHasStatus ){ | |
| 2778 | + @ data-status="%h(zStatus)"\ | |
| 2779 | + } | |
| 2780 | + @ ><td>%h(zAge) ago</td> | |
| 2781 | + @ <td class='subject'>%z(href("%R/forumpost/%S",zUuid))%h(zTitle)</a>\ | |
| 2782 | + @ </td><td>\ | |
| 2093 | 2783 | if( g.perm.ModForum && moderation_pending(db_column_int(&q,5)) ){ |
| 2094 | 2784 | @ <span class="modpending">\ |
| 2095 | 2785 | @ Awaiting Moderator Approval</span><br> |
| 2096 | 2786 | } |
| 2097 | 2787 | if( nMsg<2 ){ |
| 2098 | - @ no replies</td> | |
| 2788 | + @ no replies\ | |
| 2099 | 2789 | }else{ |
| 2100 | 2790 | char *zDuration = human_readable_age(db_column_double(&q,1)); |
| 2101 | - @ %d(nMsg) posts spanning %h(zDuration)</td> | |
| 2791 | + @ %d(nMsg) posts spanning %h(zDuration)\ | |
| 2102 | 2792 | fossil_free(zDuration); |
| 2103 | 2793 | } |
| 2104 | - @ </tr> | |
| 2794 | + @ </td>\ | |
| 2795 | + if( bShowStatus ){ | |
| 2796 | + @ <td class='status'>%h(zStatusLbl)</td>\ | |
| 2797 | + } | |
| 2798 | + if( qStat.pStmt ){ | |
| 2799 | + db_reset(&qStat); | |
| 2800 | + } | |
| 2801 | + @</tr> | |
| 2105 | 2802 | fossil_free(zAge); |
| 2106 | 2803 | } |
| 2107 | 2804 | db_finalize(&q); |
| 2805 | + if( qStat.pStmt ) db_finalize(&qStat); | |
| 2806 | + sqlite3_create_function(g.db,"status_match",1,SQLITE_UTF8,0,0,0,0); | |
| 2108 | 2807 | } |
| 2109 | 2808 | if( iCnt>0 ){ |
| 2110 | 2809 | @ </table></div> |
| 2111 | 2810 | }else{ |
| 2112 | 2811 | @ <h1>No forum posts found</h1> |
| 2113 | 2812 | } |
| 2813 | + if( bHasStatus ){ | |
| 2814 | + /* We need a JS-side kludge to avoid passing on the x=N | |
| 2815 | + ** URL arg when the status selection list is activated. */ | |
| 2816 | + forum_emit_js(); | |
| 2817 | + } | |
| 2114 | 2818 | style_finish_page(); |
| 2115 | 2819 | } |
| 2820 | + | |
| 2821 | +/* | |
| 2822 | +** The AJAX counterpart of forum_post(). | |
| 2823 | +** | |
| 2824 | +** Returns the new artifact's RID on success, 0 if no changes were | |
| 2825 | +** necessary (e.g. an empty new post or dry-run mode), and a negative | |
| 2826 | +** value on error. If it returns a negative value then it will have | |
| 2827 | +** populated the ajax response state with an error object. | |
| 2828 | +** | |
| 2829 | +** zTitle must be NULL if iInReplyTo>0 and must be non-empty if | |
| 2830 | +** iInReplyTo==0. | |
| 2831 | +** | |
| 2832 | +** The caller must have started a transaction and must roll it back if | |
| 2833 | +** this call returns <=0, noting that only the negative-value case is | |
| 2834 | +** an error. | |
| 2835 | +** | |
| 2836 | +** This function does some work to try to ensure that duplicate | |
| 2837 | +** entries are not save (this can happen as a side effect of the forum | |
| 2838 | +** post editor added in 2026-06). If the given post will not have been | |
| 2839 | +** materially edited by these changes, they are not applied and the | |
| 2840 | +** rid of the existing entry is used. | |
| 2841 | +** | |
| 2842 | +** Maintenance reminders: | |
| 2843 | +** | |
| 2844 | +** - iInReplyTo==0 && iEdit==0: new thread | |
| 2845 | +** - iInReplyTo==0 && iEdit>0 : edit top post or response | |
| 2846 | +** - iInReplyTo>0 && iEdit==0: new response | |
| 2847 | +** - iInReplyTo>0 && iEdit>0 : edit response | |
| 2848 | +*/ | |
| 2849 | +static int forum_post_ajax( | |
| 2850 | + const char *zTitle, /* Title. NULL for replies */ | |
| 2851 | + int iInReplyTo, /* Post replying to. 0 for new threads */ | |
| 2852 | + int iEdit, /* Post being edited, or zero for a new post */ | |
| 2853 | + const char *zUser, /* Username. NULL means use login name */ | |
| 2854 | + const char *zMimetype, /* Mimetype of content. */ | |
| 2855 | + const char *zContent, /* Content */ | |
| 2856 | + int iFlags /* FPOST_xyz flag values */ | |
| 2857 | +){ | |
| 2858 | + char *zI; | |
| 2859 | + char *zG; | |
| 2860 | + char *zP = 0; | |
| 2861 | + int iBasis; | |
| 2862 | + Blob x = BLOB_INITIALIZER, | |
| 2863 | + cksum = BLOB_INITIALIZER, | |
| 2864 | + formatCheck = BLOB_INITIALIZER, | |
| 2865 | + errMsg = BLOB_INITIALIZER; | |
| 2866 | + Manifest *pPost = 0; | |
| 2867 | + int nContent = zContent ? (int)strlen(zContent) : 0; | |
| 2868 | + int rc = 0; | |
| 2869 | + | |
| 2870 | + assert( db_transaction_nesting_depth()>0 ); | |
| 2871 | + schema_forum(); | |
| 2872 | + if( iEdit==0 && fossil_all_whitespace(zContent) ){ | |
| 2873 | + return 0; | |
| 2874 | + } | |
| 2875 | + if( !g.perm.Admin && (iEdit || iInReplyTo) | |
| 2876 | + && forum_rid_is_tagged(iEdit ? iEdit : iInReplyTo, "closed", 1) ){ | |
| 2877 | + return -ajax_route_error(400, "Thread is closed."); | |
| 2878 | + } | |
| 2879 | + if( 0==iInReplyTo && fossil_all_whitespace(zTitle) ){ | |
| 2880 | + return -ajax_route_error(400, "Empty title is not permitted."); | |
| 2881 | + } | |
| 2882 | + | |
| 2883 | + if( zUser==0 ){ | |
| 2884 | + if( login_is_nobody() ){ | |
| 2885 | + zUser = "anonymous"; | |
| 2886 | + }else{ | |
| 2887 | + zUser = login_name(); | |
| 2888 | + } | |
| 2889 | + } | |
| 2890 | + if( iEdit>0 | |
| 2891 | + && !g.perm.Admin | |
| 2892 | + && !forumpost_is_owner(iEdit, zUser) ){ | |
| 2893 | + return -ajax_route_error( | |
| 2894 | + 403, "Only admins may edit other peoples' posts." | |
| 2895 | + ); | |
| 2896 | + } | |
| 2897 | + if( iInReplyTo==0 && iEdit>0 ){ | |
| 2898 | + iBasis = iEdit; | |
| 2899 | + iInReplyTo = db_int(0, "SELECT firt FROM forumpost WHERE fpid=%d", | |
| 2900 | + iEdit); | |
| 2901 | + }else{ | |
| 2902 | + iBasis = iInReplyTo; | |
| 2903 | + /* TODO (2026-06-008) If (iInReplyTo>0 && iEdit>0), validate that | |
| 2904 | + ** iInReplyTo is connected to iEdit properly, else we risk | |
| 2905 | + ** reparenting the new edit and having unrepredictable downstream | |
| 2906 | + ** side effects. */ | |
| 2907 | + } | |
| 2908 | + | |
| 2909 | + if( 0!=zMimetype && 0==zMimetype[0] ){ | |
| 2910 | + zMimetype = 0; | |
| 2911 | + } | |
| 2912 | + | |
| 2913 | + if( 0!=zTitle && 0==zTitle[0] ) zTitle = 0; | |
| 2914 | + webpage_assert( (zTitle==0)+(iInReplyTo==0)==1 ); | |
| 2915 | + | |
| 2916 | + if( iEdit>0 ){ | |
| 2917 | + int cmp; | |
| 2918 | + pPost = manifest_get(iEdit, CFTYPE_FORUM, 0); | |
| 2919 | + if( pPost==0 ){ | |
| 2920 | + rc = -ajax_route_error(404, "Missing edit artifact %d", iEdit); | |
| 2921 | + goto post_ajax_end; | |
| 2922 | + } | |
| 2923 | + /* | |
| 2924 | + ** If the old content matches the new then do not save a new copy. | |
| 2925 | + ** It's easy to get re-posts of unedited content via the forum | |
| 2926 | + ** editor, especially since the one added in 2026-06, where a | |
| 2927 | + ** post's status and attachments may be amended from the editor | |
| 2928 | + ** without modifying any of the post's content. In the legacy | |
| 2929 | + ** editor such "out-of-band" changes weren't possible and users | |
| 2930 | + ** have never made a practice of re-posting unedited content. | |
| 2931 | + ** | |
| 2932 | + ** We compare the following fields to the original: user, mimetype, | |
| 2933 | + ** content, and (for root posts only) the title. | |
| 2934 | + */ | |
| 2935 | + cmp = (0==pPost->zInReplyTo) | |
| 2936 | + ? fossil_strcmp(pPost->zThreadTitle, zTitle) | |
| 2937 | + : 0; | |
| 2938 | + if( 0==cmp ){ | |
| 2939 | + cmp=fossil_strcmp(pPost->zWiki, zContent); | |
| 2940 | + if( 0==cmp ){ | |
| 2941 | + cmp = fossil_strcmp(pPost->zUser, zUser); | |
| 2942 | + } | |
| 2943 | + if( 0==cmp | |
| 2944 | + && 0!=(cmp=fossil_strcmp(pPost->zMimetype, zMimetype)) ){ | |
| 2945 | + /* Extra mimetype checks for a common condition seen elsewhere */ | |
| 2946 | + if( (0==zMimetype | |
| 2947 | + && 0==fossil_strcmp(pPost->zMimetype, "text/x-fossil-wiki")) | |
| 2948 | + || (0==pPost->zMimetype | |
| 2949 | + && 0==fossil_strcmp(zMimetype, "text/x-fossil-wiki")) ){ | |
| 2950 | + cmp = 0; | |
| 2951 | + } | |
| 2952 | + } | |
| 2953 | + if( 0==cmp ){ | |
| 2954 | + rc = iEdit; | |
| 2955 | + goto post_ajax_end; | |
| 2956 | + } | |
| 2957 | + } | |
| 2958 | + zP = rid_to_uuid(iEdit); | |
| 2959 | + } | |
| 2960 | + | |
| 2961 | + /* Write the new artifact */ | |
| 2962 | + blob_init(&x, 0, 0); | |
| 2963 | + blob_appendf(&x, "D %z\n", date_in_standard_format("now")); | |
| 2964 | + zG = db_text( | |
| 2965 | + 0, | |
| 2966 | + "SELECT uuid FROM blob, forumpost" | |
| 2967 | + " WHERE blob.rid==forumpost.froot" | |
| 2968 | + " AND forumpost.fpid=%d", | |
| 2969 | + iBasis | |
| 2970 | + ); | |
| 2971 | + if( zG ){ | |
| 2972 | + blob_appendf(&x, "G %z\n", zG); | |
| 2973 | + } | |
| 2974 | + if( zTitle ){ | |
| 2975 | + blob_appendf(&x, "H %F\n", zTitle); | |
| 2976 | + } | |
| 2977 | + if( iInReplyTo>0 ){ | |
| 2978 | + zI = rid_to_uuid(iInReplyTo); | |
| 2979 | + if( 0==zI ){ | |
| 2980 | + rc = -ajax_route_error(404, "Missing in-reply-to artifact %d", | |
| 2981 | + iInReplyTo); | |
| 2982 | + goto post_ajax_end; | |
| 2983 | + } | |
| 2984 | + blob_appendf(&x, "I %z\n", zI); | |
| 2985 | + } | |
| 2986 | + if( zMimetype!=0 | |
| 2987 | + && fossil_strcmp(zMimetype,"text/x-fossil-wiki")!=0 ){ | |
| 2988 | + blob_appendf(&x, "N %F\n", zMimetype); | |
| 2989 | + } | |
| 2990 | + if( zP ){ | |
| 2991 | + blob_appendf(&x, "P %s\n", zP); | |
| 2992 | + } | |
| 2993 | + | |
| 2994 | + blob_appendf(&x, "U %F\n", zUser); | |
| 2995 | + blob_appendf(&x, "W %d\n%s\n", nContent, zContent); | |
| 2996 | + md5sum_blob(&x, &cksum); | |
| 2997 | + blob_appendf(&x, "Z %b\n", &cksum); | |
| 2998 | + blob_reset(&cksum); | |
| 2999 | + | |
| 3000 | + /* Verify that the artifact we are creating is well-formed */ | |
| 3001 | + blob_init(&formatCheck, 0, 0); | |
| 3002 | + blob_init(&errMsg, 0, 0); | |
| 3003 | + blob_copy(&formatCheck, &x); | |
| 3004 | + pPost = manifest_parse(&formatCheck, 0, &errMsg); | |
| 3005 | + if( pPost==0 ){ | |
| 3006 | + ajax_route_error(500, "Malformed forum post artifact: %b", &errMsg); | |
| 3007 | + rc = -500; | |
| 3008 | + goto post_ajax_end; | |
| 3009 | + } | |
| 3010 | + webpage_assert( pPost->type==CFTYPE_FORUM ); | |
| 3011 | + | |
| 3012 | + if( (iFlags & FPOST_DRYRUN)!=0 ){ | |
| 3013 | + rc = 0; | |
| 3014 | + }else{ | |
| 3015 | + int nrid; | |
| 3016 | + db_begin_transaction(); | |
| 3017 | + nrid = wiki_put(&x, iEdit>0 ? iEdit : 0, forum_need_moderation()); | |
| 3018 | + blob_reset(&x); | |
| 3019 | + if( (iFlags & FPOST_NO_ALERT)!=0 ){ | |
| 3020 | + alert_unqueue('f', nrid); | |
| 3021 | + } | |
| 3022 | + rc = nrid; | |
| 3023 | + db_end_transaction(0); | |
| 3024 | + } | |
| 3025 | +post_ajax_end: | |
| 3026 | + manifest_destroy(pPost); | |
| 3027 | + fossil_free(zP); | |
| 3028 | + blob_reset(&x); | |
| 3029 | + blob_reset(&cksum); | |
| 3030 | + blob_reset(&formatCheck); | |
| 3031 | + return rc; | |
| 3032 | +} | |
| 3033 | +/* | |
| 3034 | +** WEBPAGE: forumajax_save hidden | |
| 3035 | +** | |
| 3036 | +** WIP | |
| 3037 | +** | |
| 3038 | +** Response JSON: | |
| 3039 | +** | |
| 3040 | +** { uuid: hash, ...tbd } | |
| 3041 | +*/ | |
| 3042 | +void forum_ajax_save_page(void){ | |
| 3043 | + const char *zFpid; | |
| 3044 | + const char *zTitle; | |
| 3045 | + const char *zIrt; | |
| 3046 | + const char *zMimetype; | |
| 3047 | + const char *zContent; | |
| 3048 | + const char *zStatus; | |
| 3049 | + const int bHasAttachment = P("file1")!=0; | |
| 3050 | + Manifest *pPost = 0; | |
| 3051 | + char *zNewUuid = 0; | |
| 3052 | + int firt = 0; /* In-reply-to rid or 0 */ | |
| 3053 | + int fpid = 0; /* Post rid being edited or 0 */ | |
| 3054 | + int rc = 0; /* Result code. */ | |
| 3055 | + int nrid = 0; /* New artifact rid. */ | |
| 3056 | + int iPostFlags; /* forum_post_flags() (after perms check) */ | |
| 3057 | + int bRollback; /* True = roll back. */ | |
| 3058 | + int nAttach = 0; /* Number of attachments added */ | |
| 3059 | + int bStatusSet = 0; /* True if status tag set. */ | |
| 3060 | + | |
| 3061 | + if( !ajax_route_bootstrap(0, 1) ){ | |
| 3062 | + return; | |
| 3063 | + }else if( !g.perm.WrForum | |
| 3064 | + || (bHasAttachment && !g.perm.AttachForum) ){ | |
| 3065 | + ajax_route_error_forbidden(); | |
| 3066 | + return; | |
| 3067 | + }else if( !ajax_check_csrf(2) ){ | |
| 3068 | + ajax_route_error_csrf(); | |
| 3069 | + return; | |
| 3070 | + } | |
| 3071 | + | |
| 3072 | + iPostFlags = forum_post_flags(/*must come after permissions init*/); | |
| 3073 | + bRollback = (FPOST_DRYRUN & iPostFlags); | |
| 3074 | + zFpid = P("fpid"); | |
| 3075 | + zIrt = P("firt"); | |
| 3076 | + zMimetype = P("mimetype"); | |
| 3077 | + zContent = P("content"); | |
| 3078 | + zStatus = P("status"); | |
| 3079 | + db_begin_transaction(); | |
| 3080 | + if( zFpid && zFpid[0] ){ | |
| 3081 | + fpid = symbolic_name_to_rid(zFpid, "f"); | |
| 3082 | + if( fpid<0 ){ | |
| 3083 | + rc = -ajax_route_error(400, "Ambiguous forum ID."); | |
| 3084 | + goto ajax_save_end; | |
| 3085 | + }else if( 0==fpid | |
| 3086 | + || 0==(pPost = manifest_get(fpid, CFTYPE_FORUM, 0)) ){ | |
| 3087 | + rc = -ajax_route_error(404, "Cannot resolve forum post ID."); | |
| 3088 | + goto ajax_save_end; | |
| 3089 | + } | |
| 3090 | + } | |
| 3091 | + /* | |
| 3092 | + ** Problem: if we derive firt from fpid/pPost then there's a race | |
| 3093 | + ** condition where the IRT post is edited between the time that this | |
| 3094 | + ** edit was initiated and when it is posted: the new edit's IRT will | |
| 3095 | + ** point to the edit which was made in the meantime, not the one the | |
| 3096 | + ** user intended to respond to. However, if we accept firt from the | |
| 3097 | + ** enviornment, we "really should" validate that it's actually in | |
| 3098 | + ** the current chain, to prohibit that malicious posts could move | |
| 3099 | + ** posts around. | |
| 3100 | + ** | |
| 3101 | + ** forum_post_ajax() will, if fpid>0 && !firt, select fpid's current | |
| 3102 | + ** firt. | |
| 3103 | + */ | |
| 3104 | + if( zIrt && zIrt[0] ){ | |
| 3105 | + firt = symbolic_name_to_rid(zIrt, "f"); | |
| 3106 | + if( firt<0 ){ | |
| 3107 | + rc = -ajax_route_error(400, "Ambiguous in-reply-do ID."); | |
| 3108 | + goto ajax_save_end; | |
| 3109 | + }else if( 0==firt ){ | |
| 3110 | + rc = -ajax_route_error(404, "Cannot resolve in-reply-do ID."); | |
| 3111 | + goto ajax_save_end; | |
| 3112 | + } | |
| 3113 | + } | |
| 3114 | + | |
| 3115 | + if( 0 ){ | |
| 3116 | + rc = -ajax_route_error(400, "Save is TODO. " | |
| 3117 | + "iPostFlags=%d debug=%d", | |
| 3118 | + iPostFlags, g.perm.Debug); | |
| 3119 | + goto ajax_save_end; | |
| 3120 | + } | |
| 3121 | + | |
| 3122 | + zTitle = firt ? 0 : P("title"); | |
| 3123 | + nrid = forum_post_ajax(zTitle, firt, fpid, 0, zMimetype, | |
| 3124 | + zContent, iPostFlags); | |
| 3125 | + if( nrid<0 ){ | |
| 3126 | + rc = nrid; | |
| 3127 | + goto ajax_save_end; | |
| 3128 | + }else if( nrid==0 ){ | |
| 3129 | + if( 0==(FPOST_DRYRUN & iPostFlags) ){ | |
| 3130 | + bRollback = 1; | |
| 3131 | + CX("{\"message\": \"No saving needed.\"}\n"); | |
| 3132 | + }else{ | |
| 3133 | + CX("{\"message\": \"Rolled back for dry-run.\"," | |
| 3134 | + "\"iPostFlags\":%d}\n", iPostFlags); | |
| 3135 | + } | |
| 3136 | + goto ajax_save_end; | |
| 3137 | + }else{ | |
| 3138 | + const int bNeedsModeration = forum_need_moderation(); | |
| 3139 | + const int fpHead = forumpost_head_rid(nrid); | |
| 3140 | + assert( nrid>0 ); | |
| 3141 | + assert( fpHead>0 ); | |
| 3142 | + zNewUuid = rid_to_uuid(nrid); | |
| 3143 | + if( 0!=P("file1") ){ | |
| 3144 | + /* Attachments */ | |
| 3145 | + if( !g.perm.Admin && !g.perm.AttachForum ){ | |
| 3146 | + rc = -ajax_route_error(403, "No permission no attach files."); | |
| 3147 | + goto ajax_save_end; | |
| 3148 | + }else{ | |
| 3149 | + char *zRoot = (nrid==fpHead) ? 0 : rid_to_uuid(fpHead); | |
| 3150 | + nAttach = attachments_ajax_from_POST(zRoot ? zRoot : zNewUuid, | |
| 3151 | + bNeedsModeration); | |
| 3152 | + fossil_free(zRoot); | |
| 3153 | + if( nAttach<0 ){ | |
| 3154 | + rc = nAttach; | |
| 3155 | + goto ajax_save_end; | |
| 3156 | + } | |
| 3157 | + if( nAttach>0 | |
| 3158 | + && (iPostFlags & FPOST_NO_ALERT)!=0 | |
| 3159 | + && db_table_exists("repository","pending_alert") ){ | |
| 3160 | + /* Unqueue any alerts for these attachments. Recall that | |
| 3161 | + ** they're attached to the first version of the post, which | |
| 3162 | + ** means we actually risk cancelling _other_ pending | |
| 3163 | + ** notifications for attachments on this same post. C'est la | |
| 3164 | + ** vie.*/ | |
| 3165 | + db_multi_exec( | |
| 3166 | + "WITH x(id) AS (\n" | |
| 3167 | + " SELECT 'f%d'\n" | |
| 3168 | + " UNION ALL\n" | |
| 3169 | + " SELECT 'f'||a.attachid FROM blob b, attachment a\n" | |
| 3170 | + " WHERE b.rid=%d\n" | |
| 3171 | + " AND b.uuid=a.target\n" | |
| 3172 | + ") DELETE FROM pending_alert WHERE eventid IN x", | |
| 3173 | + fpHead, fpHead | |
| 3174 | + ); | |
| 3175 | + } | |
| 3176 | + } | |
| 3177 | + } | |
| 3178 | + if( 0==bNeedsModeration | |
| 3179 | + /* ^^^ Do not allow a status tag on a pending-moderation post | |
| 3180 | + ** because it will introduce a reference to an artifact which | |
| 3181 | + ** will become a phantom if it is rejected by a moderator. */ | |
| 3182 | + && zStatus!=0 && zStatus[0]!=0 | |
| 3183 | + && forum_may_set_status(nrid) | |
| 3184 | + && (bStatusSet=forumpost_tag(nrid, 1, "status", zStatus))<0 ){ | |
| 3185 | + rc = -ajax_route_error(500, "Tagging failed: %s", g.zErrMsg); | |
| 3186 | + goto ajax_save_end; | |
| 3187 | + } | |
| 3188 | + } | |
| 3189 | + | |
| 3190 | + assert( 0==rc ); | |
| 3191 | + assert( zNewUuid ); | |
| 3192 | + CX("{\"uuid\": %!j, \"attachedCount\": %d, " | |
| 3193 | + "\"statusModified\": %d, " | |
| 3194 | + "\"dryrun\": %s, \"iPostFlags\":%d}\n", | |
| 3195 | + zNewUuid, nAttach, | |
| 3196 | + bStatusSet, bRollback ? "true" : "false", iPostFlags); | |
| 3197 | + | |
| 3198 | +ajax_save_end: | |
| 3199 | + manifest_destroy(pPost); | |
| 3200 | + fossil_free(zNewUuid); | |
| 3201 | + db_end_transaction(rc || bRollback); | |
| 3202 | +} | |
| 2116 | 3203 | |
| 2117 | 3204 | ADDED src/fossil.attach.js |
| --- src/forum.c | |
| +++ src/forum.c | |
| @@ -49,11 +49,11 @@ | |
| 49 | ForumPost *pNext; /* Next in chronological order */ |
| 50 | ForumPost *pPrev; /* Previous in chronological order */ |
| 51 | ForumPost *pDisplay; /* Next in display order */ |
| 52 | int nEdit; /* Number of edits to this post */ |
| 53 | int nIndent; /* Number of levels of indentation for this post */ |
| 54 | int iClosed; /* See forum_rid_is_closed() */ |
| 55 | }; |
| 56 | |
| 57 | /* |
| 58 | ** A single instance of the following tracks all entries for a thread. |
| 59 | */ |
| @@ -63,12 +63,134 @@ | |
| 63 | ForumPost *pDisplay; /* Entries in display order */ |
| 64 | ForumPost *pTail; /* Last on the display list */ |
| 65 | int mxIndent; /* Maximum indentation level */ |
| 66 | int nArtifact; /* Number of forum artifacts in this thread */ |
| 67 | }; |
| 68 | #endif /* INTERFACE */ |
| 69 | |
| 70 | /* |
| 71 | ** Return true if the forum post with the given rid has been |
| 72 | ** subsequently edited. |
| 73 | */ |
| 74 | int forum_rid_has_been_edited(int rid){ |
| @@ -83,29 +205,68 @@ | |
| 83 | db_reset(&q); |
| 84 | return res; |
| 85 | } |
| 86 | |
| 87 | /* |
| 88 | ** Given a valid forumpost.fpid value, this function returns the first |
| 89 | ** fpid in the chain of edits for that forum post, or rid if no prior |
| 90 | ** versions are found. |
| 91 | */ |
| 92 | static int forumpost_head_rid(int rid){ |
| 93 | Stmt q; |
| 94 | int rcRid = rid; |
| 95 | |
| 96 | db_prepare(&q, "SELECT fprev FROM forumpost" |
| 97 | " WHERE fpid=:rid AND fprev IS NOT NULL"); |
| 98 | db_bind_int(&q, ":rid", rid); |
| 99 | while( SQLITE_ROW==db_step(&q) ){ |
| 100 | rcRid = db_column_int(&q, 0); |
| 101 | db_reset(&q); |
| 102 | db_bind_int(&q, ":rid", rcRid); |
| 103 | } |
| 104 | db_finalize(&q); |
| 105 | return rcRid; |
| 106 | } |
| 107 | |
| 108 | /* |
| 109 | ** Returns true if p, or any parent of p, has a non-zero iClosed |
| 110 | ** value. Returns 0 if !p. For an edited chain of post, the tag is |
| 111 | ** checked on the pEditHead entry, to simplify subsequent unlocking of |
| @@ -128,39 +289,39 @@ | |
| 128 | return 0; |
| 129 | } |
| 130 | |
| 131 | /* |
| 132 | ** Given a forum post RID, this function returns true if that post has |
| 133 | ** (or inherits) an active "closed" tag. If bCheckIrt is true then |
| 134 | ** the post to which the given post responds is also checked |
| 135 | ** (recursively), else they are not. When checking in-response-to |
| 136 | ** posts, the first one which is closed ends the search. |
| 137 | ** |
| 138 | ** Note that this function checks _exactly_ the given rid, whereas |
| 139 | ** forum post closure/re-opening is always applied to the head of an |
| 140 | ** edit chain so that we get consistent implied locking behavior for |
| 141 | ** later versions and responses to arbitrary versions in the |
| 142 | ** chain. Even so, the "closed" tag is applied as a propagating tag |
| 143 | ** so will apply to all edits in a given chain. |
| 144 | ** |
| 145 | ** The return value is one of: |
| 146 | ** |
| 147 | ** - 0 if no "closed" tag is found. |
| 148 | ** |
| 149 | ** - The tagxref.rowid of the tagxref entry for the closure if rid is |
| 150 | ** the forum post to which the closure applies. |
| 151 | ** |
| 152 | ** - (-tagxref.rowid) if the given rid inherits a "closed" tag from an |
| 153 | ** IRT forum post. |
| 154 | */ |
| 155 | static int forum_rid_is_closed(int rid, int bCheckIrt){ |
| 156 | static Stmt qIrt = empty_Stmt_m; |
| 157 | int rc = 0, i = 0; |
| 158 | /* TODO: this can probably be turned into a CTE by someone with |
| 159 | ** superior SQL-fu. */ |
| 160 | for( ; rid; i++ ){ |
| 161 | rc = rid_has_active_tag_name(rid, "closed"); |
| 162 | if( rc || !bCheckIrt ) break; |
| 163 | else if( !qIrt.pStmt ) { |
| 164 | db_static_prepare(&qIrt, |
| 165 | "SELECT firt FROM forumpost " |
| 166 | "WHERE fpid=$fpid ORDER BY fmtime DESC" |
| @@ -171,105 +332,211 @@ | |
| 171 | db_reset(&qIrt); |
| 172 | } |
| 173 | return i ? -rc : rc; |
| 174 | } |
| 175 | |
| 176 | /* |
| 177 | ** Closes or re-opens the given forum RID via addition of a new |
| 178 | ** control artifact into the repository. In order to provide |
| 179 | ** consistent behavior for implied closing of responses and later |
| 180 | ** versions, it always acts on the first version of the given forum |
| 181 | ** post, walking the forumpost.fprev values to find the head of the |
| 182 | ** chain. |
| 183 | ** |
| 184 | ** If doClose is true then a propagating "closed" tag is added, except |
| 185 | ** as noted below, with the given optional zReason string as the tag's |
| 186 | ** value. If doClose is false then any active "closed" tag on frid is |
| 187 | ** cancelled, except as noted below. zReason is ignored if doClose is |
| 188 | ** false or if zReason is NULL or starts with a NUL byte. |
| 189 | ** |
| 190 | ** This function only adds a "closed" tag if forum_rid_is_closed() |
| 191 | ** indicates that frid's head is not closed. If a parent post is |
| 192 | ** already closed, no tag is added. Similarly, it will only remove a |
| 193 | ** "closed" tag from a post which has its own "closed" tag, and will |
| 194 | ** not remove an inherited one from a parent post. |
| 195 | ** |
| 196 | ** If doClose is true and frid is closed (directly or inherited), this |
| 197 | ** is a no-op. Likewise, if doClose is false and frid itself is not |
| 198 | ** closed (not accounting for an inherited closed tag), this is a |
| 199 | ** no-op. |
| 200 | ** |
| 201 | ** Returns true if it actually creates a new tag, else false. Fails |
| 202 | ** fatally on error. If it returns true then any ForumPost::iClosed |
| 203 | ** values from previously loaded posts are invalidated if they refer |
| 204 | ** to the amended post or a response to it. |
| 205 | ** |
| 206 | ** Sidebars: |
| 207 | ** |
| 208 | ** - Unless the caller has a transaction open, via |
| 209 | ** db_begin_transaction(), there is a very tiny race condition |
| 210 | ** window during which the caller's idea of whether or not the forum |
| 211 | ** post is closed may differ from the current repository state. |
| 212 | ** |
| 213 | ** - This routine assumes that frid really does refer to a forum post. |
| 214 | ** |
| 215 | ** - This routine assumes that frid is not private or pending |
| 216 | ** moderation. |
| 217 | ** |
| 218 | ** - Closure of a forum post requires a propagating "closed" tag to |
| 219 | ** account for how edits of posts are handled. This differs from |
| 220 | ** closure of a branch, where a non-propagating tag is used. |
| 221 | */ |
| 222 | static int forumpost_close(int frid, int doClose, const char *zReason){ |
| 223 | Blob artifact = BLOB_INITIALIZER; /* Output artifact */ |
| 224 | Blob cksum = BLOB_INITIALIZER; /* Z-card */ |
| 225 | int iClosed; /* true if frid is closed */ |
| 226 | int trid; /* RID of new control artifact */ |
| 227 | char *zUuid; /* UUID of head version of post */ |
| 228 | |
| 229 | db_begin_transaction(); |
| 230 | frid = forumpost_head_rid(frid); |
| 231 | iClosed = forum_rid_is_closed(frid, 1); |
| 232 | if( (iClosed && doClose |
| 233 | /* Already closed, noting that in the case of (iClosed<0), it's |
| 234 | ** actually a parent which is closed. */) |
| 235 | || (iClosed<=0 && !doClose |
| 236 | /* This entry is not closed, but a parent post may be. */) ){ |
| 237 | db_end_transaction(0); |
| 238 | return 0; |
| 239 | } |
| 240 | if( doClose==0 || (zReason && !zReason[0]) ){ |
| 241 | zReason = 0; |
| 242 | } |
| 243 | zUuid = rid_to_uuid(frid); |
| 244 | blob_appendf(&artifact, "D %z\n", date_in_standard_format( "now" )); |
| 245 | blob_appendf(&artifact, |
| 246 | "T %cclosed %s%s%F\n", |
| 247 | doClose ? '*' : '-', zUuid, |
| 248 | zReason ? " " : "", zReason ? zReason : ""); |
| 249 | blob_appendf(&artifact, "U %F\n", login_name()); |
| 250 | md5sum_blob(&artifact, &cksum); |
| 251 | blob_appendf(&artifact, "Z %b\n", &cksum); |
| 252 | blob_reset(&cksum); |
| 253 | trid = content_put_ex(&artifact, 0, 0, 0, 0); |
| 254 | if( trid==0 ){ |
| 255 | fossil_fatal("Error saving tag artifact: %s", g.zErrMsg); |
| 256 | } |
| 257 | if( manifest_crosslink(trid, &artifact, |
| 258 | MC_NONE /*MC_PERMIT_HOOKS?*/)==0 ){ |
| 259 | fossil_fatal("%s", g.zErrMsg); |
| 260 | } |
| 261 | assert( blob_is_reset(&artifact) ); |
| 262 | db_add_unsent(trid); |
| 263 | admin_log("%s forum post %S", doClose ? "Close" : "Re-open", zUuid); |
| 264 | fossil_free(zUuid); |
| 265 | /* Potential TODO: if (iClosed>0) then we could find the initial tag |
| 266 | ** artifact and content_deltify(thatRid,&trid,1,0). Given the tiny |
| 267 | ** size of these artifacts, however, that would save little space, |
| 268 | ** if any. */ |
| 269 | db_end_transaction(0); |
| 270 | return 1; |
| 271 | } |
| 272 | |
| 273 | /* |
| 274 | ** Returns true if the forum-close-policy setting is true, else false, |
| 275 | ** caching the result for subsequent calls. |
| @@ -285,12 +552,15 @@ | |
| 285 | |
| 286 | /* |
| 287 | ** Returns 1 if the current user is an admin, -1 if the current user |
| 288 | ** is a forum moderator and the forum-close-policy setting is true, |
| 289 | ** else returns 0. The value is cached for subsequent calls. |
| 290 | */ |
| 291 | static int forumpost_may_close(void){ |
| 292 | static int permClose = -99; |
| 293 | if( permClose!=-99 ){ |
| 294 | return permClose; |
| 295 | }else if( g.perm.Admin ){ |
| 296 | return permClose = 1; |
| @@ -445,13 +715,13 @@ | |
| 445 | for(; p; p=p->pEditPrev ){ |
| 446 | p->nEdit = pPost->nEdit; |
| 447 | p->pEditTail = pPost; |
| 448 | } |
| 449 | } |
| 450 | pPost->iClosed = forum_rid_is_closed(pPost->pEditHead |
| 451 | ? pPost->pEditHead->fpid |
| 452 | : pPost->fpid, 1); |
| 453 | } |
| 454 | db_finalize(&q); |
| 455 | |
| 456 | if( computeHierarchy ){ |
| 457 | /* Compute the hierarchical display order */ |
| @@ -629,10 +899,80 @@ | |
| 629 | } |
| 630 | @ </table> |
| 631 | db_finalize(&q); |
| 632 | style_finish_page(); |
| 633 | } |
| 634 | |
| 635 | /* |
| 636 | ** Render a forum post for display |
| 637 | */ |
| 638 | void forum_render( |
| @@ -760,22 +1100,55 @@ | |
| 760 | if( pToFree ) manifest_destroy(pToFree); |
| 761 | if( p->zDisplayName==0 ) return "(unknown)"; |
| 762 | return p->zDisplayName; |
| 763 | } |
| 764 | |
| 765 | |
| 766 | /* |
| 767 | ** Display a single post in a forum thread. |
| 768 | */ |
| 769 | static void forum_display_post( |
| 770 | ForumThread *pThread, /* The thread that this post is a member of */ |
| 771 | ForumPost *p, /* Forum post to display */ |
| 772 | int iIndentScale, /* Indent scale factor */ |
| 773 | int bRaw, /* True to omit the border */ |
| 774 | int bUnf, /* True to leave the post unformatted */ |
| 775 | int bHist, /* True if showing edit history */ |
| 776 | int bSelect, /* True if this is the selected post */ |
| 777 | char *zQuery /* Common query string */ |
| 778 | ){ |
| 779 | char *zPosterName; /* Name of user who originally made this post */ |
| 780 | char *zEditorName; /* Name of user who provided the current edit */ |
| 781 | char *zDate; /* The time/date string */ |
| @@ -784,30 +1157,43 @@ | |
| 784 | Manifest *pManifest; /* Manifest comprising the current post */ |
| 785 | int bPrivate; /* True for posts awaiting moderation */ |
| 786 | int bSameUser; /* True if author is also the reader */ |
| 787 | int iIndent; /* Indent level */ |
| 788 | int iClosed; /* True if (sub)thread is closed */ |
| 789 | const char *zMimetype;/* Formatting MIME type */ |
| 790 | |
| 791 | /* Get the manifest for the post. Abort if not found (e.g. shunned). */ |
| 792 | pManifest = manifest_get(p->fpid, CFTYPE_FORUM, 0); |
| 793 | if( !pManifest ) return; |
| 794 | iClosed = forumpost_is_closed(pThread, p, 1); |
| 795 | /* When not in raw mode, create the border around the post. */ |
| 796 | if( !bRaw ){ |
| 797 | /* Open the <div> enclosing the post. Set the class string to mark the post |
| 798 | ** as selected and/or obsolete. */ |
| 799 | iIndent = (p->pEditHead ? p->pEditHead->nIndent : p->nIndent)-1; |
| 800 | @ <div id='forum%d(p->fpid)' class='forumTime\ |
| 801 | @ %s(bSelect ? " forumSel" : "")\ |
| 802 | @ %s(iClosed ? " forumClosed" : "")\ |
| 803 | @ %s(p->pEditTail ? " forumObs" : "")' \ |
| 804 | if( iIndent && iIndentScale ){ |
| 805 | @ style='margin-left:%d(iIndent*iIndentScale)ex;'> |
| 806 | }else{ |
| 807 | @ > |
| 808 | } |
| 809 | |
| 810 | /* If this is the first post (or an edit thereof), emit the thread title. */ |
| 811 | if( pManifest->zThreadTitle ){ |
| 812 | @ <h1>%h(pManifest->zThreadTitle)</h1> |
| 813 | } |
| @@ -888,18 +1274,18 @@ | |
| 888 | /* Provide a link to the raw source code. */ |
| 889 | if( !bUnf ){ |
| 890 | @ %z(href("%R/forumpost/%!S?raw",p->zUuid))[source]</a> |
| 891 | } |
| 892 | @ </h3> |
| 893 | } |
| 894 | |
| 895 | /* Check if this post is approved, also if it's by the current user. */ |
| 896 | bPrivate = content_is_private(p->fpid); |
| 897 | bSameUser = login_is_individual() |
| 898 | && fossil_strcmp(pManifest->zUser, g.zLogin)==0; |
| 899 | |
| 900 | /* Render the post if the user is able to see it. */ |
| 901 | if( bPrivate && !g.perm.ModForum && !bSameUser ){ |
| 902 | @ <p><span class="modpending">Awaiting Moderator Approval</span></p> |
| 903 | }else{ |
| 904 | if( bRaw || bUnf || p->pEditTail ){ |
| 905 | zMimetype = "text/plain"; |
| @@ -909,10 +1295,12 @@ | |
| 909 | forum_render(0, zMimetype, pManifest->zWiki, 0, !bRaw); |
| 910 | } |
| 911 | |
| 912 | /* When not in raw mode, finish creating the border around the post. */ |
| 913 | if( !bRaw ){ |
| 914 | /* If the user is able to write to the forum and if this post has not been |
| 915 | ** edited, create a form with various interaction buttons. */ |
| 916 | if( g.perm.WrForum && !p->pEditTail ){ |
| 917 | @ <div class="forumpost-single-controls">\ |
| 918 | @ <form action="%R/forumedit" method="POST"> |
| @@ -941,33 +1329,52 @@ | |
| 941 | @ <br><label><input type="checkbox" name="trust"> |
| 942 | @ Trust user "%h(pManifest->zUser)" so that future posts by \ |
| 943 | @ "%h(pManifest->zUser)" do not require moderation. |
| 944 | @ </label> |
| 945 | @ <input type="hidden" name="trustuser" value="%h(pManifest->zUser)"> |
| 946 | } |
| 947 | }else if( bSameUser ){ |
| 948 | /* Allow users to delete (reject) their own pending posts. */ |
| 949 | @ <input type="submit" name="reject" value="Delete"> |
| 950 | } |
| 951 | login_insert_csrf_secret(); |
| 952 | @ </form> |
| 953 | if( bSelect && forumpost_may_close() && iClosed>=0 ){ |
| 954 | int iHead = forumpost_head_rid(p->fpid); |
| 955 | @ <form method="post" \ |
| 956 | @ action='%R/forumpost_%s(iClosed > 0 ? "reopen" : "close")'> |
| 957 | login_insert_csrf_secret(); |
| 958 | @ <input type="hidden" name="fpid" value="%z(rid_to_uuid(iHead))" /> |
| 959 | if( moderation_pending(p->fpid)==0 ){ |
| 960 | @ <input type="button" value='%s(iClosed ? "Re-open" : "Close")' \ |
| 961 | @ class='%s(iClosed ? "action-reopen" : "action-close")'/> |
| 962 | } |
| 963 | @ </form> |
| 964 | } |
| 965 | @ </div> |
| 966 | } |
| 967 | @ </div> |
| 968 | } |
| 969 | |
| 970 | /* Clean up. */ |
| 971 | manifest_destroy(pManifest); |
| 972 | } |
| 973 | |
| @@ -1077,12 +1484,18 @@ | |
| 1077 | } |
| 1078 | |
| 1079 | /* Display the appropriate subset of posts in sequence. */ |
| 1080 | while( p ){ |
| 1081 | /* Display the post. */ |
| 1082 | forum_display_post(pThread, p, iIndentScale, mode==FD_RAW, |
| 1083 | bUnf, bHist, p==pSelect, zQuery); |
| 1084 | |
| 1085 | /* Advance to the next post in the thread. */ |
| 1086 | if( mode==FD_CHRONO ){ |
| 1087 | /* Chronological mode: display posts (optionally including edits) in their |
| 1088 | ** original commit order. */ |
| @@ -1138,11 +1551,12 @@ | |
| 1138 | ** to all forum-related pages. It does not include page-specific |
| 1139 | ** code (e.g. "forum.js"). |
| 1140 | */ |
| 1141 | static void forum_emit_js(void){ |
| 1142 | builtin_fossil_js_bundle_or("copybutton", "pikchr", "confirmer", |
| 1143 | NULL); |
| 1144 | builtin_request_js("fossil.page.forumpost.js"); |
| 1145 | } |
| 1146 | |
| 1147 | /* |
| 1148 | ** WEBPAGE: forumpost |
| @@ -1291,28 +1705,20 @@ | |
| 1291 | } |
| 1292 | |
| 1293 | /* |
| 1294 | ** Return true if a forum post should be moderated. |
| 1295 | */ |
| 1296 | static int forum_need_moderation(void){ |
| 1297 | if( P("domod") ) return 1; |
| 1298 | if( g.perm.WrTForum ) return 0; |
| 1299 | if( g.perm.ModForum ) return 0; |
| 1300 | return 1; |
| 1301 | } |
| 1302 | |
| 1303 | /* |
| 1304 | ** Return true if the string is white-space only. |
| 1305 | */ |
| 1306 | static int whitespace_only(const char *z){ |
| 1307 | if( z==0 ) return 1; |
| 1308 | while( z[0] && fossil_isspace(z[0]) ){ z++; } |
| 1309 | return z[0]==0; |
| 1310 | } |
| 1311 | |
| 1312 | /* Flags for use with forum_post() */ |
| 1313 | #define FPOST_NO_ALERT 1 /* do not send any alerts */ |
| 1314 | |
| 1315 | /* |
| 1316 | ** Return a flags value for use with the final argument to |
| 1317 | ** forum_post(), extracted from the CGI environment. |
| 1318 | */ |
| @@ -1319,10 +1725,13 @@ | |
| 1319 | static int forum_post_flags(void){ |
| 1320 | int iPostFlags = 0; |
| 1321 | if( g.perm.Debug && P("fpsilent")!=0 ){ |
| 1322 | iPostFlags |= FPOST_NO_ALERT; |
| 1323 | } |
| 1324 | return iPostFlags; |
| 1325 | } |
| 1326 | |
| 1327 | /* |
| 1328 | ** Add a new Forum Post artifact to the repository. |
| @@ -1346,15 +1755,15 @@ | |
| 1346 | Manifest *pPost; |
| 1347 | int nContent = zContent ? (int)strlen(zContent) : 0; |
| 1348 | |
| 1349 | schema_forum(); |
| 1350 | if( !g.perm.Admin && (iEdit || iInReplyTo) |
| 1351 | && forum_rid_is_closed(iEdit ? iEdit : iInReplyTo, 1) ){ |
| 1352 | forumpost_error_closed(); |
| 1353 | return 0; |
| 1354 | } |
| 1355 | if( iEdit==0 && whitespace_only(zContent) ){ |
| 1356 | return 0; |
| 1357 | } |
| 1358 | if( iInReplyTo==0 && iEdit>0 ){ |
| 1359 | iBasis = iEdit; |
| 1360 | iInReplyTo = db_int(0, "SELECT firt FROM forumpost WHERE fpid=%d", iEdit); |
| @@ -1375,17 +1784,19 @@ | |
| 1375 | fossil_free(zG); |
| 1376 | } |
| 1377 | if( zTitle ){ |
| 1378 | blob_appendf(&x, "H %F\n", zTitle); |
| 1379 | } |
| 1380 | zI = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", iInReplyTo); |
| 1381 | if( zI ){ |
| 1382 | blob_appendf(&x, "I %s\n", zI); |
| 1383 | fossil_free(zI); |
| 1384 | } |
| 1385 | if( fossil_strcmp(zMimetype,"text/x-fossil-wiki")!=0 ){ |
| 1386 | blob_appendf(&x, "N %s\n", zMimetype); |
| 1387 | } |
| 1388 | if( iEdit>0 ){ |
| 1389 | char *zP = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", iEdit); |
| 1390 | if( zP==0 ) webpage_error("missing edit artifact %d", iEdit); |
| 1391 | blob_appendf(&x, "P %s\n", zP); |
| @@ -1413,11 +1824,11 @@ | |
| 1413 | webpage_error("malformed forum post artifact - %s", blob_str(&errMsg)); |
| 1414 | } |
| 1415 | webpage_assert( pPost->type==CFTYPE_FORUM ); |
| 1416 | manifest_destroy(pPost); |
| 1417 | |
| 1418 | if( P("dryrun") ){ |
| 1419 | @ <div class='debug'> |
| 1420 | @ This is the artifact that would have been generated: |
| 1421 | @ <pre>%h(blob_str(&x))</pre> |
| 1422 | @ </div> |
| 1423 | blob_reset(&x); |
| @@ -1452,44 +1863,87 @@ | |
| 1452 | mimetype_option_menu(zMimetype, "mimetype"); |
| 1453 | @ <div class="forum-editor-widget"> |
| 1454 | @ <textarea aria-label="Content:" name="content" class="wikiedit" \ |
| 1455 | @ cols="80" rows="25" wrap="virtual">%h(zContent)</textarea></div> |
| 1456 | } |
| 1457 | |
| 1458 | /* |
| 1459 | ** WEBPAGE: forumpost_close hidden |
| 1460 | ** WEBPAGE: forumpost_reopen hidden |
| 1461 | ** |
| 1462 | ** fpid=X Hash of the post to be edited. REQUIRED |
| 1463 | ** reason=X Optional reason for closure. |
| 1464 | ** |
| 1465 | ** Closes or re-opens the given forum post, within the bounds of the |
| 1466 | ** API for forumpost_close(). After (perhaps) modifying the "closed" |
| 1467 | ** status of the given thread, it redirects to that post's thread |
| 1468 | ** view. Requires admin privileges. |
| 1469 | */ |
| 1470 | void forum_page_close(void){ |
| 1471 | const char *zFpid = PD("fpid",""); |
| 1472 | const char *zReason = 0; |
| 1473 | int fClose; |
| 1474 | int fpid; |
| 1475 | |
| 1476 | login_check_credentials(); |
| 1477 | if( forumpost_may_close()==0 ){ |
| 1478 | login_needed(g.anon.Admin); |
| 1479 | return; |
| 1480 | } |
| 1481 | cgi_csrf_verify(); |
| 1482 | fpid = symbolic_name_to_rid(zFpid, "f"); |
| 1483 | if( fpid<=0 ){ |
| 1484 | webpage_error("Missing or invalid fpid query parameter"); |
| 1485 | } |
| 1486 | fClose = sqlite3_strglob("*_close*", g.zPath)==0; |
| 1487 | if( fClose ) zReason = PD("reason",0); |
| 1488 | forumpost_close(fpid, fClose, zReason); |
| 1489 | cgi_redirectf("%R/forumpost/%S",zFpid); |
| 1490 | return; |
| 1491 | } |
| 1492 | |
| 1493 | /* |
| 1494 | ** WEBPAGE: forumnew |
| 1495 | ** WEBPAGE: forumedit |
| @@ -1578,11 +2032,25 @@ | |
| 1578 | @ </div> |
| 1579 | } |
| 1580 | } |
| 1581 | |
| 1582 | /* |
| 1583 | ** WEBPAGE: forume1 |
| 1584 | ** |
| 1585 | ** Start a new forum thread. |
| 1586 | */ |
| 1587 | void forumnew_page(void){ |
| 1588 | const char *zTitle = PDT("title",""); |
| @@ -1596,35 +2064,45 @@ | |
| 1596 | } |
| 1597 | if( P("submit") && cgi_csrf_safe(2) ){ |
| 1598 | if( forum_post(zTitle, 0, 0, 0, zMimetype, zContent, |
| 1599 | forum_post_flags()) ) return; |
| 1600 | } |
| 1601 | if( P("preview") && !whitespace_only(zContent) ){ |
| 1602 | @ <h1>Preview:</h1> |
| 1603 | forum_render(zTitle, zMimetype, zContent, "forumEdit", 1); |
| 1604 | } |
| 1605 | style_set_current_feature("forum"); |
| 1606 | style_header("New Forum Thread"); |
| 1607 | @ <form action="%R/forume1" method="POST"> |
| 1608 | @ <h1>New Thread:</h1> |
| 1609 | forum_from_line(); |
| 1610 | forum_post_widget(zTitle, zMimetype, zContent); |
| 1611 | @ <input type="submit" name="preview" value="Preview"> |
| 1612 | if( P("preview") && !whitespace_only(zContent) ){ |
| 1613 | @ <input type="submit" name="submit" value="Submit"> |
| 1614 | }else{ |
| 1615 | @ <input type="submit" name="submit" value="Submit" disabled> |
| 1616 | } |
| 1617 | forum_render_debug_options(); |
| 1618 | login_insert_csrf_secret(); |
| 1619 | @ </form> |
| 1620 | forum_emit_js(); |
| 1621 | style_finish_page(); |
| 1622 | } |
| 1623 | |
| 1624 | /* |
| 1625 | ** WEBPAGE: forume2 |
| 1626 | ** |
| 1627 | ** Edit an existing forum message. |
| 1628 | ** Query parameters: |
| 1629 | ** |
| 1630 | ** fpid=X Hash of the post to be edited. REQUIRED |
| @@ -1655,28 +2133,30 @@ | |
| 1655 | fpid = symbolic_name_to_rid(zFpid, "f"); |
| 1656 | if( fpid<=0 || (pPost = manifest_get(fpid, CFTYPE_FORUM, 0))==0 ){ |
| 1657 | webpage_error("Missing or invalid fpid query parameter"); |
| 1658 | } |
| 1659 | froot = db_int(0, "SELECT froot FROM forumpost WHERE fpid=%d", fpid); |
| 1660 | if( froot==0 || (pRootPost = manifest_get(froot, CFTYPE_FORUM, 0))==0 ){ |
| 1661 | webpage_error("fpid does not appear to be a forum post: \"%d\"", fpid); |
| 1662 | } |
| 1663 | if( P("cancel") ){ |
| 1664 | cgi_redirectf("%R/forumpost/%S",zFpid); |
| 1665 | return; |
| 1666 | } |
| 1667 | bPreview = P("preview")!=0; |
| 1668 | bReply = P("reply")!=0; |
| 1669 | iClosed = forum_rid_is_closed(fpid, 1); |
| 1670 | isCsrfSafe = cgi_csrf_safe(2); |
| 1671 | bPrivate = content_is_private(fpid); |
| 1672 | bSameUser = login_is_individual() |
| 1673 | && fossil_strcmp(pPost->zUser, g.zLogin)==0; |
| 1674 | if( isCsrfSafe && (g.perm.ModForum || (bPrivate && bSameUser)) ){ |
| 1675 | if( g.perm.ModForum && P("approve") ){ |
| 1676 | const char *zUserToTrust; |
| 1677 | moderation_approve('f', fpid); |
| 1678 | if( g.perm.AdminForum |
| 1679 | && PB("trust") |
| 1680 | && (zUserToTrust = P("trustuser"))!=0 |
| 1681 | ){ |
| 1682 | db_unprotect(PROTECT_USER); |
| @@ -1693,11 +2173,11 @@ | |
| 1693 | db_text(0, |
| 1694 | "SELECT uuid FROM forumpost, blob" |
| 1695 | " WHERE forumpost.fpid=%d AND blob.rid=forumpost.firt", |
| 1696 | fpid |
| 1697 | ); |
| 1698 | moderation_disapprove(fpid); |
| 1699 | if( zParent ){ |
| 1700 | cgi_redirectf("%R/forumpost/%S",zParent); |
| 1701 | }else{ |
| 1702 | cgi_redirectf("%R/forum"); |
| 1703 | } |
| @@ -1707,11 +2187,11 @@ | |
| 1707 | style_set_current_feature("forum"); |
| 1708 | isDelete = P("nullout")!=0; |
| 1709 | if( P("submit") |
| 1710 | && isCsrfSafe |
| 1711 | && (zContent = PDT("content",""))!=0 |
| 1712 | && (!whitespace_only(zContent) || isDelete) |
| 1713 | ){ |
| 1714 | int done = 1; |
| 1715 | const char *zMimetype = PD("mimetype",DEFAULT_FORUM_MIMETYPE); |
| 1716 | if( bReply ){ |
| 1717 | done = forum_post(0, fpid, 0, 0, zMimetype, zContent, |
| @@ -1785,11 +2265,11 @@ | |
| 1785 | zDisplayName = display_name_from_login(pPost->zUser); |
| 1786 | @ <h3 class='forumPostHdr'>By %s(zDisplayName) on %h(zDate)</h3> |
| 1787 | fossil_free(zDisplayName); |
| 1788 | fossil_free(zDate); |
| 1789 | forum_render(0, pPost->zMimetype, pPost->zWiki, "forumEdit", 1); |
| 1790 | if( bPreview && !whitespace_only(zContent) ){ |
| 1791 | @ <h2>Preview:</h2> |
| 1792 | forum_render(0, zMimetype,zContent, "forumEdit", 1); |
| 1793 | } |
| 1794 | @ <h2>Enter Reply:</h2> |
| 1795 | @ <form action="%R/forume2" method="POST"> |
| @@ -1800,18 +2280,24 @@ | |
| 1800 | } |
| 1801 | if( !isDelete ){ |
| 1802 | @ <input type="submit" name="preview" value="Preview"> |
| 1803 | } |
| 1804 | @ <input type="submit" name="cancel" value="Cancel"> |
| 1805 | if( (bPreview && !whitespace_only(zContent)) || isDelete ){ |
| 1806 | if( !iClosed || g.perm.Admin ) { |
| 1807 | @ <input type="submit" name="submit" value="Submit"> |
| 1808 | } |
| 1809 | } |
| 1810 | forum_render_debug_options(); |
| 1811 | login_insert_csrf_secret(); |
| 1812 | @ </form> |
| 1813 | forum_emit_js(); |
| 1814 | style_finish_page(); |
| 1815 | } |
| 1816 | |
| 1817 | /* |
| @@ -1818,17 +2304,34 @@ | |
| 1818 | ** SETTING: forum-close-policy boolean default=off |
| 1819 | ** If true, forum moderators may close/re-open forum posts, and reply |
| 1820 | ** to closed posts. If false, only administrators may do so. Note that |
| 1821 | ** this only affects the forum web UI, not post-closing tags which |
| 1822 | ** arrive via the command-line or from synchronization with a remote. |
| 1823 | */ |
| 1824 | /* |
| 1825 | ** SETTING: forum-title width=20 default=Forum |
| 1826 | ** This is the name or "title" of the Forum for this repository. The |
| 1827 | ** default is just "Forum". But in some setups, admins might want to |
| 1828 | ** change it to "Developer Forum" or "User Forum" or whatever other name |
| 1829 | ** seems more appropriate for the particular usage. |
| 1830 | */ |
| 1831 | |
| 1832 | /* |
| 1833 | ** WEBPAGE: setup_forum |
| 1834 | ** |
| @@ -1946,19 +2449,113 @@ | |
| 1946 | @ <a href='%R/help/%h(pSetting->name)'>%h(pSetting->name)</a>: |
| 1947 | @ </td><td> |
| 1948 | entry_attribute("", 25, pSetting->name, zQP/*works-like:""*/, |
| 1949 | pSetting->def, 0); |
| 1950 | @ </td></tr> |
| 1951 | } |
| 1952 | } |
| 1953 | @ </tbody></table> |
| 1954 | @ <input type='submit' name='submit' value='Apply changes'> |
| 1955 | @ </form> |
| 1956 | } |
| 1957 | |
| 1958 | style_finish_page(); |
| 1959 | } |
| 1960 | |
| 1961 | /* |
| 1962 | ** WEBPAGE: forummain |
| 1963 | ** WEBPAGE: forum |
| 1964 | ** |
| @@ -1975,30 +2572,38 @@ | |
| 1975 | void forum_main_page(void){ |
| 1976 | Stmt q; |
| 1977 | int iLimit = 0, iOfst, iCnt; |
| 1978 | int srchFlags; |
| 1979 | const int isSearch = P("s")!=0; |
| 1980 | char const *zLimit = 0; |
| 1981 | |
| 1982 | login_check_credentials(); |
| 1983 | srchFlags = search_restrict(SRCH_FORUM); |
| 1984 | if( !g.perm.RdForum ){ |
| 1985 | login_needed(g.anon.RdForum); |
| 1986 | return; |
| 1987 | } |
| 1988 | cgi_check_for_malice(); |
| 1989 | style_set_current_feature("forum"); |
| 1990 | style_header("%s%s", db_get("forum-title","Forum"), |
| 1991 | isSearch ? " Search Results" : ""); |
| 1992 | style_submenu_element("Timeline", "%R/timeline?ss=v&y=f&vfx"); |
| 1993 | if( g.perm.WrForum ){ |
| 1994 | style_submenu_element("New Thread","%R/forumnew"); |
| 1995 | }else{ |
| 1996 | /* Can't combine this with previous case using the ternary operator |
| 1997 | * because that causes an error yelling about "non-constant format" |
| 1998 | * with some compilers. I can't see it, since both expressions have |
| 1999 | * the same format, but I'm no C spec lawyer. */ |
| 2000 | style_submenu_element("New Thread","%R/login"); |
| 2001 | } |
| 2002 | if( g.perm.ModForum && moderation_needed() ){ |
| 2003 | style_submenu_element("Moderation Requests", "%R/modreq"); |
| 2004 | } |
| @@ -2021,95 +2626,577 @@ | |
| 2021 | cgi_replace_query_parameter("n", fossil_strdup("25")) |
| 2022 | /*for the sake of Max, below*/; |
| 2023 | iLimit = 25; |
| 2024 | } |
| 2025 | style_submenu_entry("n","Max:",4,0); |
| 2026 | iOfst = atoi(PD("x","0")); |
| 2027 | iCnt = 0; |
| 2028 | if( db_table_exists("repository","forumpost") ){ |
| 2029 | db_prepare(&q, |
| 2030 | "WITH thread(age,duration,cnt,root,last) AS (" |
| 2031 | " SELECT" |
| 2032 | " julianday('now') - max(fmtime)," |
| 2033 | " max(fmtime) - min(fmtime)," |
| 2034 | " sum(fprev IS NULL)," |
| 2035 | " froot," |
| 2036 | " (SELECT fpid FROM forumpost AS y" |
| 2037 | " WHERE y.froot=x.froot %s" |
| 2038 | " ORDER BY y.fmtime DESC LIMIT 1)" |
| 2039 | " FROM forumpost AS x" |
| 2040 | " WHERE %s" |
| 2041 | " GROUP BY froot" |
| 2042 | " ORDER BY 1 LIMIT %d OFFSET %d" |
| 2043 | ")" |
| 2044 | "SELECT" |
| 2045 | " thread.age," /* 0 */ |
| 2046 | " thread.duration," /* 1 */ |
| 2047 | " thread.cnt," /* 2 */ |
| 2048 | " blob.uuid," /* 3 */ |
| 2049 | " substr(event.comment,instr(event.comment,':')+1)," /* 4 */ |
| 2050 | " thread.last" /* 5 */ |
| 2051 | " FROM thread, blob, event" |
| 2052 | " WHERE blob.rid=thread.last" |
| 2053 | " AND event.objid=thread.last" |
| 2054 | " ORDER BY 1;", |
| 2055 | g.perm.ModForum ? "" : "AND y.fpid NOT IN private" /*safe-for-%s*/, |
| 2056 | g.perm.ModForum ? "true" : "fpid NOT IN private" /*safe-for-%s*/, |
| 2057 | iLimit+1, iOfst |
| 2058 | ); |
| 2059 | while( db_step(&q)==SQLITE_ROW ){ |
| 2060 | char *zAge = human_readable_age(db_column_double(&q,0)); |
| 2061 | int nMsg = db_column_int(&q, 2); |
| 2062 | const char *zUuid = db_column_text(&q, 3); |
| 2063 | const char *zTitle = db_column_text(&q, 4); |
| 2064 | if( iCnt==0 ){ |
| 2065 | if( iOfst>0 ){ |
| 2066 | @ <h1>Threads at least %s(zAge) old</h1> |
| 2067 | }else{ |
| 2068 | @ <h1>Most recent threads</h1> |
| 2069 | } |
| 2070 | @ <div class='forumPosts fileage'><table width="100%%"> |
| 2071 | if( iOfst>0 ){ |
| 2072 | if( iOfst>iLimit ){ |
| 2073 | @ <tr><td colspan="3">\ |
| 2074 | @ %z(href("%R/forum?x=%d&n=%d",iOfst-iLimit,iLimit))\ |
| 2075 | @ ↑ Newer...</a></td></tr> |
| 2076 | }else{ |
| 2077 | @ <tr><td colspan="3">%z(href("%R/forum?n=%d",iLimit))\ |
| 2078 | @ ↑ Newer...</a></td></tr> |
| 2079 | } |
| 2080 | } |
| 2081 | } |
| 2082 | iCnt++; |
| 2083 | if( iCnt>iLimit ){ |
| 2084 | @ <tr><td colspan="3">\ |
| 2085 | @ %z(href("%R/forum?x=%d&n=%d",iOfst+iLimit,iLimit))\ |
| 2086 | @ ↓ Older...</a></td></tr> |
| 2087 | fossil_free(zAge); |
| 2088 | break; |
| 2089 | } |
| 2090 | @ <tr><td>%h(zAge) ago</td> |
| 2091 | @ <td>%z(href("%R/forumpost/%S",zUuid))%h(zTitle)</a></td> |
| 2092 | @ <td>\ |
| 2093 | if( g.perm.ModForum && moderation_pending(db_column_int(&q,5)) ){ |
| 2094 | @ <span class="modpending">\ |
| 2095 | @ Awaiting Moderator Approval</span><br> |
| 2096 | } |
| 2097 | if( nMsg<2 ){ |
| 2098 | @ no replies</td> |
| 2099 | }else{ |
| 2100 | char *zDuration = human_readable_age(db_column_double(&q,1)); |
| 2101 | @ %d(nMsg) posts spanning %h(zDuration)</td> |
| 2102 | fossil_free(zDuration); |
| 2103 | } |
| 2104 | @ </tr> |
| 2105 | fossil_free(zAge); |
| 2106 | } |
| 2107 | db_finalize(&q); |
| 2108 | } |
| 2109 | if( iCnt>0 ){ |
| 2110 | @ </table></div> |
| 2111 | }else{ |
| 2112 | @ <h1>No forum posts found</h1> |
| 2113 | } |
| 2114 | style_finish_page(); |
| 2115 | } |
| 2116 | |
| 2117 | DDED src/fossil.attach.js |
| --- src/forum.c | |
| +++ src/forum.c | |
| @@ -49,11 +49,11 @@ | |
| 49 | ForumPost *pNext; /* Next in chronological order */ |
| 50 | ForumPost *pPrev; /* Previous in chronological order */ |
| 51 | ForumPost *pDisplay; /* Next in display order */ |
| 52 | int nEdit; /* Number of edits to this post */ |
| 53 | int nIndent; /* Number of levels of indentation for this post */ |
| 54 | int iClosed; /* True if forum_rid_is_tagged("closed") */ |
| 55 | }; |
| 56 | |
| 57 | /* |
| 58 | ** A single instance of the following tracks all entries for a thread. |
| 59 | */ |
| @@ -63,12 +63,134 @@ | |
| 63 | ForumPost *pDisplay; /* Entries in display order */ |
| 64 | ForumPost *pTail; /* Last on the display list */ |
| 65 | int mxIndent; /* Maximum indentation level */ |
| 66 | int nArtifact; /* Number of forum artifacts in this thread */ |
| 67 | }; |
| 68 | |
| 69 | /* |
| 70 | ** A single entry from the forum-statuses setting. |
| 71 | */ |
| 72 | struct ForumStatus { |
| 73 | char *zLabel; /* Label for the UI */ |
| 74 | char *zValue; /* status=X tag value */ |
| 75 | }; |
| 76 | |
| 77 | /* |
| 78 | ** A list of ForumStatus objects. |
| 79 | */ |
| 80 | struct ForumStatusList { |
| 81 | struct ForumStatus *aStatus; /* List of statuses */ |
| 82 | unsigned int n; /* Number of entries */ |
| 83 | }; |
| 84 | |
| 85 | /* |
| 86 | ** Information passed into the status_match() SQL function |
| 87 | ** via the sqlite3_user_data() mechanism, and used by status_match() |
| 88 | ** to determine whether or not a particular forum thread should |
| 89 | ** be displayed. |
| 90 | */ |
| 91 | struct ForumStatusMatch { |
| 92 | const ForumStatusList *pFses; /* Parsed forum-statuses setting */ |
| 93 | int eStatusTag; /* tagid for the "status" property */ |
| 94 | unsigned int iMatch; /* Match this status value */ |
| 95 | }; |
| 96 | #endif /* INTERFACE */ |
| 97 | |
| 98 | |
| 99 | /* |
| 100 | ** Returns a high-level representation of the forum-statuses setting. |
| 101 | ** This is a singleton, cached across calls. |
| 102 | */ |
| 103 | const ForumStatusList * forum_statuses(void){ |
| 104 | static ForumStatusList fses = {0,0}; |
| 105 | static int once = 0; |
| 106 | while( !once ){ |
| 107 | ++once; |
| 108 | /* Read `forum-statuses` setting and transform it into the |
| 109 | ** fses object. |
| 110 | ** |
| 111 | ** Maybe: if it's empty, synthesize a length-1 list from |
| 112 | ** {value:"default",label:"Default",...}. It's expected that |
| 113 | ** usage may be slightly simplified if we always have a non-empty |
| 114 | ** list. A length-1 list is, for purposes of the UI, identical to |
| 115 | ** an empty one - status selection/filtering makes no sense if |
| 116 | ** there's only one choice. */ |
| 117 | db_multi_exec( |
| 118 | "CREATE TEMP TABLE IF NOT EXISTS forumstatus(" |
| 119 | " ord INTEGER PRIMARY KEY, label, value" |
| 120 | ");" |
| 121 | "DELETE FROM forumstatus;" |
| 122 | "INSERT INTO forumstatus(label,value)" |
| 123 | " WITH setting(v) AS (" |
| 124 | " SELECT value v FROM config WHERE name='forum-statuses'" |
| 125 | " )," |
| 126 | " room(r) AS (" |
| 127 | " SELECT e.value FROM setting s, jsonb_each(s.v) e" |
| 128 | " WHERE json_valid(s.v, 0x02)" |
| 129 | " )" |
| 130 | " SELECT r->>'label', r->>'value'" |
| 131 | " FROM room;" |
| 132 | ); |
| 133 | fses.n = (unsigned)db_int(0, "SELECT count(*) FROM forumstatus"); |
| 134 | if( fses.n ){ |
| 135 | int i = 0; |
| 136 | Stmt q; |
| 137 | db_prepare(&q,"SELECT label, value FROM forumstatus" |
| 138 | " ORDER BY ord"); |
| 139 | fses.aStatus = fossil_malloc(sizeof(fses.aStatus[0]) * fses.n); |
| 140 | while( SQLITE_ROW==db_step(&q) ){ |
| 141 | ForumStatus * fs = &fses.aStatus[i++]; |
| 142 | fs->zLabel = fossil_strdup(db_column_text(&q, 0)); |
| 143 | fs->zValue = fossil_strdup(db_column_text(&q, 1)); |
| 144 | } |
| 145 | db_finalize(&q); |
| 146 | } |
| 147 | } |
| 148 | return &fses; |
| 149 | } |
| 150 | |
| 151 | /* |
| 152 | ** Search for a ForumStatus object by its tag value. If a match is |
| 153 | ** found, the corresponding object is returned. If no match is found |
| 154 | ** then (A) if bFirst is false then 0 is returned, else (B) the first |
| 155 | ** entry in the list is returned, noting that the list may be empty, |
| 156 | ** in which case 0 is returned. |
| 157 | */ |
| 158 | static const ForumStatus * forum_status_by_value( |
| 159 | const char *z, int bFirst |
| 160 | ){ |
| 161 | const ForumStatusList * const fses = forum_statuses(); |
| 162 | const ForumStatus * fs0 = 0; |
| 163 | unsigned int i; |
| 164 | if( !fses->n ) return 0; |
| 165 | for( i = 0; i < fses->n; ++i ){ |
| 166 | const ForumStatus * fs = &fses->aStatus[i]; |
| 167 | if( 0==fossil_strcmp(z, fs->zValue) ){ |
| 168 | return fs; |
| 169 | }else if( !fs0 ){ |
| 170 | fs0 = fs; |
| 171 | } |
| 172 | } |
| 173 | return bFirst ? fs0 : 0; |
| 174 | } |
| 175 | |
| 176 | /* |
| 177 | ** COMMAND: test-forum-statuses |
| 178 | */ |
| 179 | void test_forum_statuses_cmd(void){ |
| 180 | const ForumStatusList * fses; |
| 181 | unsigned i; |
| 182 | db_find_and_open_repository(0,0); |
| 183 | fses = forum_statuses(); |
| 184 | for(i = 0; i < fses->n; ++i ){ |
| 185 | const ForumStatus * fs = &fses->aStatus[i]; |
| 186 | fossil_print("Status: %!j %!j\n", fs->zValue, fs->zLabel); |
| 187 | assert( fs==forum_status_by_value(fs->zValue, 0) ); |
| 188 | } |
| 189 | fossil_print("Total statuses: %u\n", i); |
| 190 | } |
| 191 | |
| 192 | /* |
| 193 | ** Return true if the forum post with the given rid has been |
| 194 | ** subsequently edited. |
| 195 | */ |
| 196 | int forum_rid_has_been_edited(int rid){ |
| @@ -83,29 +205,68 @@ | |
| 205 | db_reset(&q); |
| 206 | return res; |
| 207 | } |
| 208 | |
| 209 | /* |
| 210 | ** Given a valid forumpost.fpid value, this function returns the |
| 211 | ** initial forumpost.fpid in the chain of edits for that forum post, |
| 212 | ** or rid if no prior versions are found. |
| 213 | */ |
| 214 | int forumpost_head_rid(int rid){ |
| 215 | static Stmt q = empty_Stmt_m; |
| 216 | int rcRid = rid; |
| 217 | if( !q.pStmt ){ |
| 218 | db_static_prepare(&q, |
| 219 | "SELECT fprev FROM forumpost" |
| 220 | " WHERE fpid=:rid AND fprev IS NOT NULL" |
| 221 | ); |
| 222 | } |
| 223 | db_bind_int(&q, ":rid", rid); |
| 224 | while( SQLITE_ROW==db_step(&q) ){ |
| 225 | rcRid = db_column_int(&q, 0); |
| 226 | db_reset(&q); |
| 227 | db_bind_int(&q, ":rid", rcRid); |
| 228 | } |
| 229 | db_reset(&q); |
| 230 | return rcRid; |
| 231 | } |
| 232 | |
| 233 | /* |
| 234 | ** Works like forumpost_head_rid() but expects zUuid to be an |
| 235 | ** unambiguous forum post name. It may be a hash prefix, so long as |
| 236 | ** it's unambiguous. Returns the rid of the head post, -1 if the name |
| 237 | ** is ambiguous, and 0 if the name cannot be resolved as a forum post. |
| 238 | */ |
| 239 | int forumpost_head_rid2(const char *zUuid){ |
| 240 | const int fpid = symbolic_name_to_rid(zUuid, "f"); |
| 241 | return fpid>0 |
| 242 | ? forumpost_head_rid(fpid) |
| 243 | : fpid; |
| 244 | } |
| 245 | |
| 246 | /* |
| 247 | ** Given a forum post RID and user name, returns true if zUserName |
| 248 | ** matches the event.(euser,user) field for a formpost entry with the |
| 249 | ** matching RID. Returns false if no match is found. If zUserName is |
| 250 | ** 0 then login_name() is used. |
| 251 | */ |
| 252 | int forumpost_is_owner(int rid, const char *zUserName){ |
| 253 | static Stmt q; |
| 254 | int rc; |
| 255 | if( !q.pStmt ){ |
| 256 | db_static_prepare( |
| 257 | &q, "SELECT 1 FROM event" |
| 258 | " WHERE type='f' AND objid=$rid" |
| 259 | " AND coalesce(euser,user)=$user" |
| 260 | ); |
| 261 | } |
| 262 | db_bind_int(&q, "$rid", rid); |
| 263 | db_bind_text(&q, "$user", zUserName ? zUserName : login_name()); |
| 264 | rc = SQLITE_ROW==db_step(&q); |
| 265 | db_reset(&q); |
| 266 | return rc; |
| 267 | } |
| 268 | |
| 269 | /* |
| 270 | ** Returns true if p, or any parent of p, has a non-zero iClosed |
| 271 | ** value. Returns 0 if !p. For an edited chain of post, the tag is |
| 272 | ** checked on the pEditHead entry, to simplify subsequent unlocking of |
| @@ -128,39 +289,39 @@ | |
| 289 | return 0; |
| 290 | } |
| 291 | |
| 292 | /* |
| 293 | ** Given a forum post RID, this function returns true if that post has |
| 294 | ** (or inherits) an active tag named zTagName. If bCheckIrt is true |
| 295 | ** then the post to which the given post responds is also checked |
| 296 | ** (recursively), else they are not. When checking in-response-to |
| 297 | ** posts, the first one which is closed ends the search. |
| 298 | ** |
| 299 | ** This function checks _exactly_ the given rid, whereas forum post |
| 300 | ** closure/re-opening is always applied to the head of an edit chain |
| 301 | ** so that we get consistent implied locking behavior for later |
| 302 | ** versions and responses to arbitrary versions in the chain. Even so, |
| 303 | ** the "closed" tag is applied as a propagating tag so will apply to |
| 304 | ** all edits in a given chain. |
| 305 | ** |
| 306 | ** The return value is one of: |
| 307 | ** |
| 308 | ** - 0 if no matching tag is found. |
| 309 | ** |
| 310 | ** - The tagxref.rowid of the tagxref entry for the closure if rid is |
| 311 | ** the forum post to which the closure applies. |
| 312 | ** |
| 313 | ** - (-tagxref.rowid) if the given rid inherits the tag from an IRT |
| 314 | ** forum post. |
| 315 | */ |
| 316 | static int forum_rid_is_tagged(int rid, const char *zTagName, int bCheckIrt){ |
| 317 | static Stmt qIrt = empty_Stmt_m; |
| 318 | int rc = 0, i = 0; |
| 319 | /* TODO: this can probably be turned into a CTE by someone with |
| 320 | ** superior SQL-fu. */ |
| 321 | for( ; rid; i++ ){ |
| 322 | rc = rid_has_active_tag_name(rid, zTagName); |
| 323 | if( rc || !bCheckIrt ) break; |
| 324 | else if( !qIrt.pStmt ) { |
| 325 | db_static_prepare(&qIrt, |
| 326 | "SELECT firt FROM forumpost " |
| 327 | "WHERE fpid=$fpid ORDER BY fmtime DESC" |
| @@ -171,105 +332,211 @@ | |
| 332 | db_reset(&qIrt); |
| 333 | } |
| 334 | return i ? -rc : rc; |
| 335 | } |
| 336 | |
| 337 | /* True if moderation of forum posts performs the same operation |
| 338 | ** on its attachments. */ |
| 339 | #define FORUMPOST_MOD_ATTACHMENTS 1 |
| 340 | #if FORUMPOST_MOD_ATTACHMENTS |
| 341 | /* |
| 342 | ** Internal helper for moderation_forumpost_...(). |
| 343 | */ |
| 344 | static void forumpost_prep_pending_attachids(Stmt *q, int fpid){ |
| 345 | db_prepare( |
| 346 | q, |
| 347 | "SELECT attachid FROM attachment " |
| 348 | "WHERE target=(" |
| 349 | " SELECT uuid FROM blob WHERE rid=%d" |
| 350 | ") and attachid in (" |
| 351 | " SELECT objid FROM modreq" |
| 352 | ")", |
| 353 | forumpost_head_rid(fpid) |
| 354 | ); |
| 355 | } |
| 356 | #endif |
| 357 | |
| 358 | /* |
| 359 | ** Approve the given forum post RID and any pending-approval |
| 360 | ** attachments associated with its initial version. |
| 361 | */ |
| 362 | static void moderation_forumpost_approve(int fpid){ |
| 363 | #if !FORUMPOST_MOD_ATTACHMENTS |
| 364 | moderation_approve('f', fpid); |
| 365 | #else |
| 366 | /* Also approve any pending attachments */ |
| 367 | Stmt q; |
| 368 | moderation_approve('f', fpid); |
| 369 | forumpost_prep_pending_attachids(&q, fpid); |
| 370 | while( SQLITE_ROW==db_step(&q) ){ |
| 371 | moderation_approve('a', db_column_int(&q, 0)); |
| 372 | } |
| 373 | db_finalize(&q); |
| 374 | #endif |
| 375 | } |
| 376 | |
| 377 | /* |
| 378 | ** Disapprove the given forum post and any pending-moderation |
| 379 | ** attachments on its initial version. |
| 380 | */ |
| 381 | static void moderation_forumpost_disapprove(int fpid){ |
| 382 | #if !FORUMPOST_MOD_ATTACHMENTS |
| 383 | moderation_disapprove(fpid); |
| 384 | #else |
| 385 | /* Also disapprove any pending attachments */ |
| 386 | Stmt q; |
| 387 | moderation_disapprove(fpid); |
| 388 | forumpost_prep_pending_attachids(&q, fpid); |
| 389 | while( SQLITE_ROW==db_step(&q) ){ |
| 390 | moderation_disapprove(db_column_int(&q, 0)); |
| 391 | } |
| 392 | db_finalize(&q); |
| 393 | #endif |
| 394 | } |
| 395 | #undef FORUMPOST_MOD_ATTACHMENTS |
| 396 | |
| 397 | /* |
| 398 | ** Applies or cancels a tag named zTagName on the given forum RID via |
| 399 | ** addition of a new control artifact into the repository. In order to |
| 400 | ** provide consistent behavior, it always acts on the first version of |
| 401 | ** the given forum post, walking the forumpost.fprev values to find |
| 402 | ** the head of the chain. |
| 403 | ** |
| 404 | ** If addTag is true then a propagating tag is added, except as noted |
| 405 | ** below, with the given optional zValue string as the tag's |
| 406 | ** value. If addTag is false then any matching active tag on frid is |
| 407 | ** cancelled, except as noted below. zValue is ignored if it is NULL |
| 408 | ** or starts with a NUL byte, or if addTag is false. |
| 409 | ** |
| 410 | ** This function only adds a tag if forum_rid_is_tagged() indicates |
| 411 | ** that frid's head is not tagged. If a parent post is already tagged, |
| 412 | ** no tag is added. Similarly, it will only remove a tag from a post |
| 413 | ** which has its own tag, and will not remove an inherited one from a |
| 414 | ** parent post. |
| 415 | ** |
| 416 | ** If addTag is true and frid is already tagged, this is a |
| 417 | ** no-op. Likewise, if addTag is false and frid is not tagged (not |
| 418 | ** accounting for a tag inherited via an in-response-to post), this is |
| 419 | ** a no-op. |
| 420 | ** |
| 421 | ** Returns a positive value (a new tag.tagid value) if it actually |
| 422 | ** creates a new tag, else 0. On error it returns a negative alue |
| 423 | ** and g.zErrMsg "should" contain details. |
| 424 | ** |
| 425 | ** If it returns true then state from previously-loaded posts may be |
| 426 | ** invalidated if they refer to the amended post or a response to it. |
| 427 | ** e.g. if zTagName is "closed" then ForumPost::iClosed values may be |
| 428 | ** stale. |
| 429 | ** |
| 430 | ** Sidebars: |
| 431 | ** |
| 432 | ** - Unless the caller has a transaction open, via |
| 433 | ** db_begin_transaction(), there is a very tiny race condition |
| 434 | ** window during which the caller's idea of whether or not the forum |
| 435 | ** post is tagged may differ from the current repository state. |
| 436 | ** |
| 437 | ** - This routine assumes that frid really does refer to a forum post. |
| 438 | ** |
| 439 | ** - This routine assumes that frid is not private or pending |
| 440 | ** moderation. |
| 441 | ** |
| 442 | ** - The applied tag is propagating so so that "closed" tags can |
| 443 | ** account for how edits of posts are handled. This differs from |
| 444 | ** closure of a branch, where a non-propagating tag is used. |
| 445 | */ |
| 446 | static int forumpost_tag(int frid, int addTag, |
| 447 | const char *zTagName, |
| 448 | const char *zValue){ |
| 449 | Blob artifact = BLOB_INITIALIZER; /* Output artifact */ |
| 450 | Blob cksum = BLOB_INITIALIZER; /* Z-card */ |
| 451 | int iTagged; /* true if frid is already tagged */ |
| 452 | int trid; /* RID of new control artifact */ |
| 453 | char *zUuid; /* UUID of head version of post */ |
| 454 | |
| 455 | db_begin_transaction(); |
| 456 | frid = forumpost_head_rid(frid); |
| 457 | iTagged = forum_rid_is_tagged(frid, zTagName, 0); |
| 458 | if( !addTag && !iTagged ){ |
| 459 | /* Nothing to do. We never tag an IRT-inherited post via this |
| 460 | ** function. */ |
| 461 | db_end_transaction(0); |
| 462 | return 0; |
| 463 | } |
| 464 | if( !addTag || (zValue && !zValue[0]) ){ |
| 465 | zValue = 0; |
| 466 | } |
| 467 | if( addTag && iTagged ){ |
| 468 | char *zOld = 0; |
| 469 | int cmp; |
| 470 | rid_has_tag2(frid, zTagName, &zOld); |
| 471 | cmp = fossil_strcmp(zOld, zValue); |
| 472 | fossil_free(zOld); |
| 473 | if( 0==cmp ){ |
| 474 | /* Same value - leave it as is. */ |
| 475 | db_end_transaction(0); |
| 476 | return 0; |
| 477 | } |
| 478 | } |
| 479 | zUuid = rid_to_uuid(frid); |
| 480 | blob_appendf(&artifact, "D %z\n", date_in_standard_format( "now" )); |
| 481 | blob_appendf(&artifact, "T %c%s %s%s%F\n", |
| 482 | addTag ? '*' : '-', zTagName, |
| 483 | zUuid, zValue ? " " : "", zValue ? zValue : ""); |
| 484 | blob_appendf(&artifact, "U %F\n", login_name()); |
| 485 | md5sum_blob(&artifact, &cksum); |
| 486 | blob_appendf(&artifact, "Z %b\n", &cksum); |
| 487 | blob_reset(&cksum); |
| 488 | trid = content_put_ex(&artifact, 0, 0, 0, 0); |
| 489 | if( trid==0 ){ |
| 490 | return -1; |
| 491 | } |
| 492 | if( manifest_crosslink(trid, &artifact, MC_NONE)==0 ){ |
| 493 | return -2; |
| 494 | } |
| 495 | assert( blob_is_reset(&artifact) ); |
| 496 | db_add_unsent(trid); |
| 497 | admin_log("Tag forum post %S with %c%s", |
| 498 | zUuid, addTag ? '*' : '-', zTagName); |
| 499 | fossil_free(zUuid); |
| 500 | db_end_transaction(0); |
| 501 | return trid; |
| 502 | } |
| 503 | |
| 504 | /* |
| 505 | ** COMMAND: test-forumpost-tag |
| 506 | ** |
| 507 | ** Usage: %fossil test-forumpost-tag ?-cancel? THREADID TAGNAME TAGVAL |
| 508 | ** |
| 509 | ** A tester for forumpost_tag(). It always rolls back changes. |
| 510 | */ |
| 511 | void test_forumpost_tag_command(void){ |
| 512 | int fpid; |
| 513 | int rc; |
| 514 | const char *zPost; |
| 515 | const char *zTag; |
| 516 | const char *zVal; |
| 517 | const int bAdd = find_option("cancel","",0)==0; |
| 518 | |
| 519 | db_find_and_open_repository(0,0); |
| 520 | verify_all_options(); |
| 521 | if( g.argc<5 ){ |
| 522 | usage("forum-post-id tag-name value"); |
| 523 | } |
| 524 | zPost = g.argv[2]; |
| 525 | zTag = g.argv[3]; |
| 526 | zVal = g.argv[4]; |
| 527 | |
| 528 | db_begin_transaction(); |
| 529 | fpid = forumpost_head_rid2(zPost); |
| 530 | if( fpid<=0 ){ |
| 531 | fossil_fatal("Cannot resolve post ID %s", zPost); |
| 532 | } |
| 533 | fossil_print("%s => %d => %z\n", zTag, fpid, |
| 534 | rid_to_uuid(fpid)); |
| 535 | rc = forumpost_tag(fpid, bAdd, zTag, zVal); |
| 536 | fossil_print("tag fpid=%d taxgxref.tagid=%d\n", fpid, rc); |
| 537 | db_end_transaction(1); |
| 538 | } |
| 539 | |
| 540 | /* |
| 541 | ** Returns true if the forum-close-policy setting is true, else false, |
| 542 | ** caching the result for subsequent calls. |
| @@ -285,12 +552,15 @@ | |
| 552 | |
| 553 | /* |
| 554 | ** Returns 1 if the current user is an admin, -1 if the current user |
| 555 | ** is a forum moderator and the forum-close-policy setting is true, |
| 556 | ** else returns 0. The value is cached for subsequent calls. |
| 557 | ** |
| 558 | ** This policy also determines whether non-admin forum moderators |
| 559 | ** may delete forum attachments. |
| 560 | */ |
| 561 | int forumpost_may_close(void){ |
| 562 | static int permClose = -99; |
| 563 | if( permClose!=-99 ){ |
| 564 | return permClose; |
| 565 | }else if( g.perm.Admin ){ |
| 566 | return permClose = 1; |
| @@ -445,13 +715,13 @@ | |
| 715 | for(; p; p=p->pEditPrev ){ |
| 716 | p->nEdit = pPost->nEdit; |
| 717 | p->pEditTail = pPost; |
| 718 | } |
| 719 | } |
| 720 | pPost->iClosed = forum_rid_is_tagged(pPost->pEditHead |
| 721 | ? pPost->pEditHead->fpid |
| 722 | : pPost->fpid, "closed", 1); |
| 723 | } |
| 724 | db_finalize(&q); |
| 725 | |
| 726 | if( computeHierarchy ){ |
| 727 | /* Compute the hierarchical display order */ |
| @@ -629,10 +899,80 @@ | |
| 899 | } |
| 900 | @ </table> |
| 901 | db_finalize(&q); |
| 902 | style_finish_page(); |
| 903 | } |
| 904 | |
| 905 | /* |
| 906 | ** Returns true if the current user is authorized to set forum post |
| 907 | ** fpid's status. |
| 908 | */ |
| 909 | static int forum_may_set_status(int fpid){ |
| 910 | if( moderation_pending(fpid) ) return 0; |
| 911 | return g.perm.Admin |
| 912 | || g.perm.ModForum |
| 913 | || (login_is_individual() |
| 914 | && forumpost_is_owner(fpid, 0)); |
| 915 | } |
| 916 | |
| 917 | /* |
| 918 | ** If the current user is authorized to set fp's status then this |
| 919 | ** renders a mini-form for setting the status then redirecting back to |
| 920 | ** the post. Else it may emit a status label or no output. |
| 921 | */ |
| 922 | static void forum_render_status_selection( const ForumPost *fp ){ |
| 923 | const ForumStatusList * const fss = forum_statuses(); |
| 924 | if( fss->n>1 ){ |
| 925 | const ForumPost * pHead = fp->pEditHead ? fp->pEditHead : fp; |
| 926 | int i; |
| 927 | char * zCurrent = 0; |
| 928 | const ForumStatus * sCurrent = 0; |
| 929 | rid_has_tag2(pHead->fpid, "status", &zCurrent); |
| 930 | for( i = 0; i < fss->n; ++i ){ |
| 931 | const ForumStatus * const fs = &fss->aStatus[i]; |
| 932 | if( 0==fossil_strcmp(zCurrent, fs->zValue) ){ |
| 933 | sCurrent = fs; |
| 934 | break; |
| 935 | } |
| 936 | } |
| 937 | if( !sCurrent ) sCurrent = &fss->aStatus[0]; |
| 938 | assert( sCurrent ); |
| 939 | @ <fieldset class='forum-status-selection'>\ |
| 940 | @ <legend>Status \ |
| 941 | @ <span class='help-buttonlet initially-hidden'>\ |
| 942 | @ Moderators and the post's owner may change \ |
| 943 | @ the status of this thread unless it is still. \ |
| 944 | @ pending moderation. See \ |
| 945 | @ <a href='%R/help/forum-statuses' target='_new'>\ |
| 946 | @ /help/forum-statuses</a></span>\ |
| 947 | @ </legend>\ |
| 948 | if( forum_may_set_status(fp->fpid) ){ |
| 949 | @ <form method="post" action='%R/forumpost_status'> |
| 950 | login_insert_csrf_secret(); |
| 951 | @ <input type='hidden' name='fpid' value='%s(fp->zUuid)' /> |
| 952 | @ <select name='status' data-fpid='%s(fp->zUuid)'\ |
| 953 | @ data-initial-value='%h(zCurrent ? zCurrent : "")'> |
| 954 | for( i = 0; i < fss->n; ++i ){ |
| 955 | const ForumStatus * const fs = &fss->aStatus[i]; |
| 956 | @ <option value='%h(fs->zValue)'\ |
| 957 | @ %s(sCurrent==fs ? " selected" : "")>\ |
| 958 | @ %h(fs->zLabel)</option> |
| 959 | } |
| 960 | @ </select> |
| 961 | @ <input type='button' class='submit action-status' disabled |
| 962 | @ value='Change' /> |
| 963 | /* ^^^ This must be <input>, not <button>, or else tapping it |
| 964 | ** will unconditionally submit. */ |
| 965 | @ </form> |
| 966 | /* Form is activated in fossil.page.forumpost.js */ |
| 967 | }else{ |
| 968 | @ <button disabled>Status: %h(sCurrent->zLabel)</button> |
| 969 | } |
| 970 | @ </fieldset> |
| 971 | fossil_free(zCurrent); |
| 972 | } |
| 973 | } |
| 974 | |
| 975 | /* |
| 976 | ** Render a forum post for display |
| 977 | */ |
| 978 | void forum_render( |
| @@ -760,22 +1100,55 @@ | |
| 1100 | if( pToFree ) manifest_destroy(pToFree); |
| 1101 | if( p->zDisplayName==0 ) return "(unknown)"; |
| 1102 | return p->zDisplayName; |
| 1103 | } |
| 1104 | |
| 1105 | /* |
| 1106 | ** Renders the attachment list for the given forum post. |
| 1107 | ** Emits no output if there are no attachments. |
| 1108 | */ |
| 1109 | static void forum_render_attachment_list(const char *zUuid){ |
| 1110 | #if 1 |
| 1111 | attachment_list(zUuid, "📎 Attachments", 0 |
| 1112 | | ATTACHLIST_SIZE |
| 1113 | | ATTACHLIST_HIDE_UNAPPROVED |
| 1114 | | ATTACHLIST_DETAILS_CLOSED |
| 1115 | | ATTACHLIST_HIDE_EMPTY); |
| 1116 | #else |
| 1117 | char * zLbl = mprintf("<a href='%R/attachlist?forumpost=%!S'>" |
| 1118 | "Attachments</a>:", zUuid); |
| 1119 | attachment_list(zUuid, zLbl, |
| 1120 | ATTACHLIST_HRULE_ABOVE |
| 1121 | | ATTACHLIST_SIZE |
| 1122 | | ATTACHLIST_HIDE_UNAPPROVED |
| 1123 | | ATTACHLIST_HIDE_EMPTY); |
| 1124 | fossil_free(zLbl); |
| 1125 | #endif |
| 1126 | } |
| 1127 | |
| 1128 | /* |
| 1129 | ** Renders the attachment list for p or (if not NULL) pEditHead. |
| 1130 | */ |
| 1131 | static void forum_render_attachment_list2(ForumPost *p){ |
| 1132 | if( p->pEditHead ) p = p->pEditHead; |
| 1133 | forum_render_attachment_list(p->zUuid); |
| 1134 | } |
| 1135 | |
| 1136 | /* Flags for use with forum_display_post() */ |
| 1137 | #define FDISPLAY_RAW 0x01 /* omit the border */ |
| 1138 | #define FDISPLAY_UNFORMATTED 0x02 /* leave the post unformatted */ |
| 1139 | #define FDISPLAY_HISTORY 0x04 /* Showing edit history */ |
| 1140 | #define FDISPLAY_SELECTED 0x08 /* This is the selected post */ |
| 1141 | |
| 1142 | /* |
| 1143 | ** Display a single post in a forum thread. |
| 1144 | */ |
| 1145 | static void forum_display_post( |
| 1146 | ForumThread *pThread, /* The thread that this post is a member of */ |
| 1147 | ForumPost *p, /* Forum post to display */ |
| 1148 | int iIndentScale, /* Indent scale factor */ |
| 1149 | int flags, /* From the FDISPLAY_... enum */ |
| 1150 | char *zQuery /* Common query string */ |
| 1151 | ){ |
| 1152 | char *zPosterName; /* Name of user who originally made this post */ |
| 1153 | char *zEditorName; /* Name of user who provided the current edit */ |
| 1154 | char *zDate; /* The time/date string */ |
| @@ -784,30 +1157,43 @@ | |
| 1157 | Manifest *pManifest; /* Manifest comprising the current post */ |
| 1158 | int bPrivate; /* True for posts awaiting moderation */ |
| 1159 | int bSameUser; /* True if author is also the reader */ |
| 1160 | int iIndent; /* Indent level */ |
| 1161 | int iClosed; /* True if (sub)thread is closed */ |
| 1162 | const int bRaw = flags & FDISPLAY_RAW; |
| 1163 | const int bUnf = flags & FDISPLAY_UNFORMATTED; |
| 1164 | const int bHist = flags & FDISPLAY_HISTORY; |
| 1165 | const int bSelect = flags & FDISPLAY_SELECTED; |
| 1166 | const char *zMimetype;/* Formatting MIME type */ |
| 1167 | |
| 1168 | /* Get the manifest for the post. Abort if not found (e.g. shunned). */ |
| 1169 | pManifest = manifest_get(p->fpid, CFTYPE_FORUM, 0); |
| 1170 | if( !pManifest ) return; |
| 1171 | iClosed = forumpost_is_closed(pThread, p, 1); |
| 1172 | bPrivate = content_is_private(p->fpid); |
| 1173 | bSameUser = login_is_individual() |
| 1174 | && fossil_strcmp(pManifest->zUser, g.zLogin)==0; |
| 1175 | /* When not in raw mode, create the border around the post. */ |
| 1176 | if( !bRaw ){ |
| 1177 | /* Open the <div> enclosing the post. Set the class string to mark the post |
| 1178 | ** as selected and/or obsolete. */ |
| 1179 | iIndent = (p->pEditHead ? p->pEditHead->nIndent : p->nIndent)-1; |
| 1180 | @ <div id='forum%d(p->fpid)' class='forumpost forumTime\ |
| 1181 | @ %s(bSelect ? " forumSel" : "")\ |
| 1182 | @ %s(iClosed ? " forumClosed" : "")\ |
| 1183 | @ %s(p->pEditTail ? " forumObs" : "")' \ |
| 1184 | if( iIndent && iIndentScale ){ |
| 1185 | @ style='margin-left:%d(iIndent*iIndentScale)ex;' \ |
| 1186 | } |
| 1187 | /* These data-X fields are used by the JS editor. */ |
| 1188 | if( p->pIrt ){ |
| 1189 | @ data-firt="%s(p->pIrt->zUuid)" \ |
| 1190 | } |
| 1191 | if( p->pEditHead ){ |
| 1192 | @ data-fedithead="%s(p->pEditHead->zUuid)" \ |
| 1193 | } |
| 1194 | @ data-fpid="%s(p->zUuid)">\ |
| 1195 | |
| 1196 | /* If this is the first post (or an edit thereof), emit the thread title. */ |
| 1197 | if( pManifest->zThreadTitle ){ |
| 1198 | @ <h1>%h(pManifest->zThreadTitle)</h1> |
| 1199 | } |
| @@ -888,18 +1274,18 @@ | |
| 1274 | /* Provide a link to the raw source code. */ |
| 1275 | if( !bUnf ){ |
| 1276 | @ %z(href("%R/forumpost/%!S?raw",p->zUuid))[source]</a> |
| 1277 | } |
| 1278 | @ </h3> |
| 1279 | |
| 1280 | if( bPrivate && (bSameUser || g.perm.Admin || g.perm.ModForum) ){ |
| 1281 | moderation_pending_www(p->fpid); |
| 1282 | } |
| 1283 | }/*!bRaw*/ |
| 1284 | |
| 1285 | /* Check if this post is approved, also if it's by the current user. |
| 1286 | Render the post if the user is able to see it. */ |
| 1287 | if( bPrivate && !g.perm.ModForum && !bSameUser ){ |
| 1288 | @ <p><span class="modpending">Awaiting Moderator Approval</span></p> |
| 1289 | }else{ |
| 1290 | if( bRaw || bUnf || p->pEditTail ){ |
| 1291 | zMimetype = "text/plain"; |
| @@ -909,10 +1295,12 @@ | |
| 1295 | forum_render(0, zMimetype, pManifest->zWiki, 0, !bRaw); |
| 1296 | } |
| 1297 | |
| 1298 | /* When not in raw mode, finish creating the border around the post. */ |
| 1299 | if( !bRaw ){ |
| 1300 | int bBrBeforeAttach = 0; /* Layout kludge for Attach button */ |
| 1301 | forum_render_attachment_list2(p); |
| 1302 | /* If the user is able to write to the forum and if this post has not been |
| 1303 | ** edited, create a form with various interaction buttons. */ |
| 1304 | if( g.perm.WrForum && !p->pEditTail ){ |
| 1305 | @ <div class="forumpost-single-controls">\ |
| 1306 | @ <form action="%R/forumedit" method="POST"> |
| @@ -941,33 +1329,52 @@ | |
| 1329 | @ <br><label><input type="checkbox" name="trust"> |
| 1330 | @ Trust user "%h(pManifest->zUser)" so that future posts by \ |
| 1331 | @ "%h(pManifest->zUser)" do not require moderation. |
| 1332 | @ </label> |
| 1333 | @ <input type="hidden" name="trustuser" value="%h(pManifest->zUser)"> |
| 1334 | bBrBeforeAttach = 1 /* slightly unmangle the layout */; |
| 1335 | } |
| 1336 | }else if( bSameUser ){ |
| 1337 | /* Allow users to delete (reject) their own pending posts. */ |
| 1338 | @ <input type="submit" name="reject" value="Delete"> |
| 1339 | } |
| 1340 | login_insert_csrf_secret(); |
| 1341 | @ </form> |
| 1342 | |
| 1343 | if( bSelect ){ |
| 1344 | const ForumPost *pHead = p->pEditHead ? p->pEditHead : p; |
| 1345 | if( !bPrivate && forumpost_may_close() && iClosed>=0 ){ |
| 1346 | @ <form method="post" \ |
| 1347 | @ action='%R/forumpost_%s(iClosed > 0 ? "reopen" : "close")'> |
| 1348 | login_insert_csrf_secret(); |
| 1349 | @ <input type="hidden" name="fpid" value="%s(p->zUuid)" /> |
| 1350 | if( moderation_pending(p->fpid)==0 ){ |
| 1351 | @ <input type="button" value='%s(iClosed ? "Re-open" : "Close")' \ |
| 1352 | @ class='submit hidden \ |
| 1353 | @ %s(iClosed ? "action-reopen" : "action-close")'/> |
| 1354 | /* ^^^ activated by fossil.page.forumpost.js */ |
| 1355 | } |
| 1356 | @ </form> |
| 1357 | } |
| 1358 | if( attach_user_may(p/*not pHead*/->fpid, CFTYPE_FORUM) ){ |
| 1359 | /* When an admin edits someone else's post, the admin |
| 1360 | ** effectively takes over ownership of it (and we currently |
| 1361 | ** have no way of passing it back). Because of this, we |
| 1362 | ** check the ownership of `p` instead of `pHead`. */ |
| 1363 | if( bBrBeforeAttach ){ |
| 1364 | @ <br> |
| 1365 | } |
| 1366 | attach_render_attachadd_button(pHead->zUuid); |
| 1367 | } |
| 1368 | } |
| 1369 | @ </div> |
| 1370 | } |
| 1371 | if( !p->pIrt && (flags & FDISPLAY_SELECTED)){ |
| 1372 | forum_render_status_selection(p); |
| 1373 | } |
| 1374 | @ </div> |
| 1375 | }/*!bRaw*/ |
| 1376 | |
| 1377 | /* Clean up. */ |
| 1378 | manifest_destroy(pManifest); |
| 1379 | } |
| 1380 | |
| @@ -1077,12 +1484,18 @@ | |
| 1484 | } |
| 1485 | |
| 1486 | /* Display the appropriate subset of posts in sequence. */ |
| 1487 | while( p ){ |
| 1488 | /* Display the post. */ |
| 1489 | forum_display_post( |
| 1490 | pThread, p, iIndentScale, |
| 1491 | (mode==FD_RAW ? FDISPLAY_RAW : 0) | |
| 1492 | (bUnf ? FDISPLAY_UNFORMATTED : 0) | |
| 1493 | (bHist ? FDISPLAY_HISTORY : 0) | |
| 1494 | (p==pSelect ? FDISPLAY_SELECTED : 0), |
| 1495 | zQuery |
| 1496 | ); |
| 1497 | |
| 1498 | /* Advance to the next post in the thread. */ |
| 1499 | if( mode==FD_CHRONO ){ |
| 1500 | /* Chronological mode: display posts (optionally including edits) in their |
| 1501 | ** original commit order. */ |
| @@ -1138,11 +1551,12 @@ | |
| 1551 | ** to all forum-related pages. It does not include page-specific |
| 1552 | ** code (e.g. "forum.js"). |
| 1553 | */ |
| 1554 | static void forum_emit_js(void){ |
| 1555 | builtin_fossil_js_bundle_or("copybutton", "pikchr", "confirmer", |
| 1556 | "attach", "tabs", "storage", |
| 1557 | "popupwidget", NULL); |
| 1558 | builtin_request_js("fossil.page.forumpost.js"); |
| 1559 | } |
| 1560 | |
| 1561 | /* |
| 1562 | ** WEBPAGE: forumpost |
| @@ -1291,28 +1705,20 @@ | |
| 1705 | } |
| 1706 | |
| 1707 | /* |
| 1708 | ** Return true if a forum post should be moderated. |
| 1709 | */ |
| 1710 | int forum_need_moderation(void){ |
| 1711 | if( P("domod") ) return 1; |
| 1712 | if( g.perm.WrTForum ) return 0; |
| 1713 | if( g.perm.ModForum ) return 0; |
| 1714 | return 1; |
| 1715 | } |
| 1716 | |
| 1717 | /* Flags for use with forum_post() */ |
| 1718 | #define FPOST_NO_ALERT 1 /* do not send any alerts */ |
| 1719 | #define FPOST_DRYRUN 2 /* do not save the artifact */ |
| 1720 | |
| 1721 | /* |
| 1722 | ** Return a flags value for use with the final argument to |
| 1723 | ** forum_post(), extracted from the CGI environment. |
| 1724 | */ |
| @@ -1319,10 +1725,13 @@ | |
| 1725 | static int forum_post_flags(void){ |
| 1726 | int iPostFlags = 0; |
| 1727 | if( g.perm.Debug && P("fpsilent")!=0 ){ |
| 1728 | iPostFlags |= FPOST_NO_ALERT; |
| 1729 | } |
| 1730 | if( P("dryrun")!=0 ){ |
| 1731 | iPostFlags |= FPOST_DRYRUN; |
| 1732 | } |
| 1733 | return iPostFlags; |
| 1734 | } |
| 1735 | |
| 1736 | /* |
| 1737 | ** Add a new Forum Post artifact to the repository. |
| @@ -1346,15 +1755,15 @@ | |
| 1755 | Manifest *pPost; |
| 1756 | int nContent = zContent ? (int)strlen(zContent) : 0; |
| 1757 | |
| 1758 | schema_forum(); |
| 1759 | if( !g.perm.Admin && (iEdit || iInReplyTo) |
| 1760 | && forum_rid_is_tagged(iEdit ? iEdit : iInReplyTo, "closed", 1) ){ |
| 1761 | forumpost_error_closed(); |
| 1762 | return 0; |
| 1763 | } |
| 1764 | if( iEdit==0 && fossil_all_whitespace(zContent) ){ |
| 1765 | return 0; |
| 1766 | } |
| 1767 | if( iInReplyTo==0 && iEdit>0 ){ |
| 1768 | iBasis = iEdit; |
| 1769 | iInReplyTo = db_int(0, "SELECT firt FROM forumpost WHERE fpid=%d", iEdit); |
| @@ -1375,17 +1784,19 @@ | |
| 1784 | fossil_free(zG); |
| 1785 | } |
| 1786 | if( zTitle ){ |
| 1787 | blob_appendf(&x, "H %F\n", zTitle); |
| 1788 | } |
| 1789 | zI = rid_to_uuid(iInReplyTo); |
| 1790 | if( zI ){ |
| 1791 | blob_appendf(&x, "I %s\n", zI); |
| 1792 | fossil_free(zI); |
| 1793 | } |
| 1794 | if( zMimetype!=0 |
| 1795 | && zMimetype[0]!=0 |
| 1796 | && fossil_strcmp(zMimetype,"text/x-fossil-wiki")!=0 ){ |
| 1797 | blob_appendf(&x, "N %F\n", zMimetype); |
| 1798 | } |
| 1799 | if( iEdit>0 ){ |
| 1800 | char *zP = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", iEdit); |
| 1801 | if( zP==0 ) webpage_error("missing edit artifact %d", iEdit); |
| 1802 | blob_appendf(&x, "P %s\n", zP); |
| @@ -1413,11 +1824,11 @@ | |
| 1824 | webpage_error("malformed forum post artifact - %s", blob_str(&errMsg)); |
| 1825 | } |
| 1826 | webpage_assert( pPost->type==CFTYPE_FORUM ); |
| 1827 | manifest_destroy(pPost); |
| 1828 | |
| 1829 | if( (iFlags & FPOST_DRYRUN)!=0 ){ |
| 1830 | @ <div class='debug'> |
| 1831 | @ This is the artifact that would have been generated: |
| 1832 | @ <pre>%h(blob_str(&x))</pre> |
| 1833 | @ </div> |
| 1834 | blob_reset(&x); |
| @@ -1452,44 +1863,87 @@ | |
| 1863 | mimetype_option_menu(zMimetype, "mimetype"); |
| 1864 | @ <div class="forum-editor-widget"> |
| 1865 | @ <textarea aria-label="Content:" name="content" class="wikiedit" \ |
| 1866 | @ cols="80" rows="25" wrap="virtual">%h(zContent)</textarea></div> |
| 1867 | } |
| 1868 | |
| 1869 | /* |
| 1870 | ** If PD("fpid") refers to a forum post, its rid is returned, else |
| 1871 | ** this function emits an error does not does return. |
| 1872 | */ |
| 1873 | static int forum_validate_fpid_param(void){ |
| 1874 | const char *zFpid = PD("fpid",""); |
| 1875 | int fpid = symbolic_name_to_rid(zFpid, "f"); |
| 1876 | if( fpid<=0 ){ |
| 1877 | webpage_error("Missing or invalid fpid parameter."); |
| 1878 | } |
| 1879 | return fpid; |
| 1880 | } |
| 1881 | |
| 1882 | /* |
| 1883 | ** Internal helper for /forumpost_XYZ internal pages which tag/untag |
| 1884 | ** posts. |
| 1885 | */ |
| 1886 | static void forumpost_action_helper(const char *zTag, const char *zVal, |
| 1887 | int addTag, int validFpid){ |
| 1888 | if( !cgi_csrf_safe(2) ){ |
| 1889 | webpage_error("CSRF validation failed"); |
| 1890 | }else{ |
| 1891 | const int fpid = validFpid>0 ? validFpid : forum_validate_fpid_param(); |
| 1892 | if( fpid>0 ){ |
| 1893 | if( forumpost_tag(fpid, addTag, zTag, zVal) < 0 ){ |
| 1894 | webpage_error("Tagging artifact failed: %s", g.zErrMsg); |
| 1895 | }else{ |
| 1896 | cgi_redirectf("%R/forumpost/%S",P("fpid")); |
| 1897 | } |
| 1898 | } |
| 1899 | } |
| 1900 | } |
| 1901 | |
| 1902 | /* |
| 1903 | ** WEBPAGE: forumpost_close hidden |
| 1904 | ** WEBPAGE: forumpost_reopen hidden |
| 1905 | ** |
| 1906 | ** fpid=X Hash of the post to be edited. REQUIRED |
| 1907 | ** |
| 1908 | ** Closes or re-opens the given forum post, within the bounds of the |
| 1909 | ** API for forumpost_tag(). After (perhaps) modifying the "closed" |
| 1910 | ** status of the given thread, it redirects to that post's thread |
| 1911 | ** view. Requires admin privileges. |
| 1912 | */ |
| 1913 | void forum_page_close(void){ |
| 1914 | login_check_credentials(); |
| 1915 | if( forumpost_may_close()==0 ){ |
| 1916 | login_needed(g.anon.Admin); |
| 1917 | }else{ |
| 1918 | const int bIsAdd = sqlite3_strglob("*_close*", g.zPath)==0; |
| 1919 | forumpost_action_helper("closed", 0, bIsAdd, 0); |
| 1920 | } |
| 1921 | } |
| 1922 | |
| 1923 | /* |
| 1924 | ** WEBPAGE: forumpost_status hidden |
| 1925 | ** |
| 1926 | ** fpid=X Hash of the post to be edited. REQUIRED |
| 1927 | ** status=Y New status value. REQUIRED |
| 1928 | ** |
| 1929 | ** Updates the current status=Y tag on the first version of |
| 1930 | ** the forum post X. Requires forum_may_set_status() permissions. |
| 1931 | */ |
| 1932 | void forum_page_status(void){ |
| 1933 | int fpid; |
| 1934 | login_check_credentials(); |
| 1935 | fpid = forum_validate_fpid_param(); |
| 1936 | if(forum_may_set_status(fpid)){ |
| 1937 | const char *zStatus = PD("status",0); |
| 1938 | if( !zStatus || !zStatus[0] ){ |
| 1939 | webpage_error("Missing required status."); |
| 1940 | } |
| 1941 | forumpost_action_helper("status", zStatus, 1, fpid); |
| 1942 | }else{ |
| 1943 | webpage_error("You lack permissions to change this post's status."); |
| 1944 | } |
| 1945 | } |
| 1946 | |
| 1947 | /* |
| 1948 | ** WEBPAGE: forumnew |
| 1949 | ** WEBPAGE: forumedit |
| @@ -1578,11 +2032,25 @@ | |
| 2032 | @ </div> |
| 2033 | } |
| 2034 | } |
| 2035 | |
| 2036 | /* |
| 2037 | ** If the user has AttachForum permissions, emit a notice that |
| 2038 | ** attachments may be added after saving. If p is not NULL, also emit |
| 2039 | ** its list of attachments. We only emit this for No-JS environments, |
| 2040 | ** as in JS environments the interactive forum editor includes |
| 2041 | ** attachment support. |
| 2042 | */ |
| 2043 | static void forum_render_attachment_notice(void){ |
| 2044 | if( g.perm.AttachForum ){ |
| 2045 | @ <noscript><div>You will be able to attach files to this post |
| 2046 | @ after saving it.</div></noscript> |
| 2047 | } |
| 2048 | } |
| 2049 | |
| 2050 | /* |
| 2051 | ** WEBPAGE: forume1 hidden |
| 2052 | ** |
| 2053 | ** Start a new forum thread. |
| 2054 | */ |
| 2055 | void forumnew_page(void){ |
| 2056 | const char *zTitle = PDT("title",""); |
| @@ -1596,35 +2064,45 @@ | |
| 2064 | } |
| 2065 | if( P("submit") && cgi_csrf_safe(2) ){ |
| 2066 | if( forum_post(zTitle, 0, 0, 0, zMimetype, zContent, |
| 2067 | forum_post_flags()) ) return; |
| 2068 | } |
| 2069 | if( P("preview") && !fossil_all_whitespace(zContent) ){ |
| 2070 | @ <h1>Preview:</h1> |
| 2071 | forum_render(zTitle, zMimetype, zContent, "forumEdit", 1); |
| 2072 | } |
| 2073 | style_set_current_feature("forum"); |
| 2074 | style_header("New Forum Thread"); |
| 2075 | |
| 2076 | @ <form action="%R/forume1" method="POST" \ |
| 2077 | @ class="remove-if-replaced"> |
| 2078 | @ <h1>New Thread:</h1> |
| 2079 | forum_from_line(); |
| 2080 | forum_post_widget(zTitle, zMimetype, zContent); |
| 2081 | @ <input type="submit" name="preview" value="Preview"> |
| 2082 | if( P("preview") && !fossil_all_whitespace(zContent) ){ |
| 2083 | @ <input type="submit" name="submit" value="Submit"> |
| 2084 | }else{ |
| 2085 | @ <input type="submit" name="submit" value="Submit" disabled> |
| 2086 | } |
| 2087 | forum_render_debug_options(); |
| 2088 | login_insert_csrf_secret(); |
| 2089 | @ </form> |
| 2090 | /* When JS is disabled the block above will work. When it's |
| 2091 | enabled, the above will be removed and JS will render the editor |
| 2092 | form in the next element. */ |
| 2093 | @ <div hidden id='forumnew-placeholder'> |
| 2094 | @ <input type='hidden' name='title' value='%h(zTitle)'> |
| 2095 | login_insert_csrf_secret(); |
| 2096 | @ </div> |
| 2097 | forum_render_attachment_notice(); |
| 2098 | forum_emit_js(); |
| 2099 | style_finish_page(); |
| 2100 | } |
| 2101 | |
| 2102 | /* |
| 2103 | ** WEBPAGE: forume2 hidden |
| 2104 | ** |
| 2105 | ** Edit an existing forum message. |
| 2106 | ** Query parameters: |
| 2107 | ** |
| 2108 | ** fpid=X Hash of the post to be edited. REQUIRED |
| @@ -1655,28 +2133,30 @@ | |
| 2133 | fpid = symbolic_name_to_rid(zFpid, "f"); |
| 2134 | if( fpid<=0 || (pPost = manifest_get(fpid, CFTYPE_FORUM, 0))==0 ){ |
| 2135 | webpage_error("Missing or invalid fpid query parameter"); |
| 2136 | } |
| 2137 | froot = db_int(0, "SELECT froot FROM forumpost WHERE fpid=%d", fpid); |
| 2138 | if( (froot==0 || (pRootPost = manifest_get(froot, CFTYPE_FORUM, 0))==0) |
| 2139 | && P("reject")==0 |
| 2140 | ){ |
| 2141 | webpage_error("fpid does not appear to be a forum post: \"%d\"", fpid); |
| 2142 | } |
| 2143 | if( P("cancel") ){ |
| 2144 | cgi_redirectf("%R/forumpost/%S",zFpid); |
| 2145 | return; |
| 2146 | } |
| 2147 | bPreview = P("preview")!=0; |
| 2148 | bReply = P("reply")!=0; |
| 2149 | iClosed = forum_rid_is_tagged(fpid, "closed", 1); |
| 2150 | isCsrfSafe = cgi_csrf_safe(2); |
| 2151 | bPrivate = content_is_private(fpid); |
| 2152 | bSameUser = login_is_individual() |
| 2153 | && fossil_strcmp(pPost->zUser, g.zLogin)==0; |
| 2154 | if( isCsrfSafe && (g.perm.ModForum || (bPrivate && bSameUser)) ){ |
| 2155 | if( g.perm.ModForum && P("approve") ){ |
| 2156 | const char *zUserToTrust; |
| 2157 | moderation_forumpost_approve(fpid); |
| 2158 | if( g.perm.AdminForum |
| 2159 | && PB("trust") |
| 2160 | && (zUserToTrust = P("trustuser"))!=0 |
| 2161 | ){ |
| 2162 | db_unprotect(PROTECT_USER); |
| @@ -1693,11 +2173,11 @@ | |
| 2173 | db_text(0, |
| 2174 | "SELECT uuid FROM forumpost, blob" |
| 2175 | " WHERE forumpost.fpid=%d AND blob.rid=forumpost.firt", |
| 2176 | fpid |
| 2177 | ); |
| 2178 | moderation_forumpost_disapprove(fpid); |
| 2179 | if( zParent ){ |
| 2180 | cgi_redirectf("%R/forumpost/%S",zParent); |
| 2181 | }else{ |
| 2182 | cgi_redirectf("%R/forum"); |
| 2183 | } |
| @@ -1707,11 +2187,11 @@ | |
| 2187 | style_set_current_feature("forum"); |
| 2188 | isDelete = P("nullout")!=0; |
| 2189 | if( P("submit") |
| 2190 | && isCsrfSafe |
| 2191 | && (zContent = PDT("content",""))!=0 |
| 2192 | && (isDelete || !fossil_all_whitespace(zContent)) |
| 2193 | ){ |
| 2194 | int done = 1; |
| 2195 | const char *zMimetype = PD("mimetype",DEFAULT_FORUM_MIMETYPE); |
| 2196 | if( bReply ){ |
| 2197 | done = forum_post(0, fpid, 0, 0, zMimetype, zContent, |
| @@ -1785,11 +2265,11 @@ | |
| 2265 | zDisplayName = display_name_from_login(pPost->zUser); |
| 2266 | @ <h3 class='forumPostHdr'>By %s(zDisplayName) on %h(zDate)</h3> |
| 2267 | fossil_free(zDisplayName); |
| 2268 | fossil_free(zDate); |
| 2269 | forum_render(0, pPost->zMimetype, pPost->zWiki, "forumEdit", 1); |
| 2270 | if( bPreview && !fossil_all_whitespace(zContent) ){ |
| 2271 | @ <h2>Preview:</h2> |
| 2272 | forum_render(0, zMimetype,zContent, "forumEdit", 1); |
| 2273 | } |
| 2274 | @ <h2>Enter Reply:</h2> |
| 2275 | @ <form action="%R/forume2" method="POST"> |
| @@ -1800,18 +2280,24 @@ | |
| 2280 | } |
| 2281 | if( !isDelete ){ |
| 2282 | @ <input type="submit" name="preview" value="Preview"> |
| 2283 | } |
| 2284 | @ <input type="submit" name="cancel" value="Cancel"> |
| 2285 | if( isDelete || (bPreview && !fossil_all_whitespace(zContent)) ){ |
| 2286 | if( !iClosed || g.perm.Admin ) { |
| 2287 | @ <input type="submit" name="submit" value="Submit"> |
| 2288 | } |
| 2289 | } |
| 2290 | forum_render_debug_options(); |
| 2291 | login_insert_csrf_secret(); |
| 2292 | @ </form> |
| 2293 | if( !bReply ){ |
| 2294 | forum_render_attachment_list(rid_to_uuid(fpid)); |
| 2295 | } |
| 2296 | if( !isDelete ){ |
| 2297 | forum_render_attachment_notice(); |
| 2298 | } |
| 2299 | forum_emit_js(); |
| 2300 | style_finish_page(); |
| 2301 | } |
| 2302 | |
| 2303 | /* |
| @@ -1818,17 +2304,34 @@ | |
| 2304 | ** SETTING: forum-close-policy boolean default=off |
| 2305 | ** If true, forum moderators may close/re-open forum posts, and reply |
| 2306 | ** to closed posts. If false, only administrators may do so. Note that |
| 2307 | ** this only affects the forum web UI, not post-closing tags which |
| 2308 | ** arrive via the command-line or from synchronization with a remote. |
| 2309 | ** This policy also determines whether moderators may delete forum |
| 2310 | ** attachments. |
| 2311 | ** |
| 2312 | ** SETTING: forum-title width=20 default=Forum |
| 2313 | ** This is the name or "title" of the Forum for this repository. The |
| 2314 | ** default is just "Forum". But in some setups, admins might want to |
| 2315 | ** change it to "Developer Forum" or "User Forum" or whatever other name |
| 2316 | ** seems more appropriate for the particular usage. |
| 2317 | ** |
| 2318 | ** SETTING: attachment-size-limit width=16 |
| 2319 | ** The maximum number of bytes for an attachment to a wiki page, |
| 2320 | ** ticket, tech note, or forum post. The default (or 0) is unlimited |
| 2321 | ** but a limit may be imposed by the web server or a proxy. |
| 2322 | ** |
| 2323 | ** SETTING: forum-statuses width=40 block-text |
| 2324 | ** This JSON5-formatted value defines an array of objects describing |
| 2325 | ** the available statuses of forum posts. Each entry of the array must |
| 2326 | ** be an object in the form {label:"X",value:"Y"}. |
| 2327 | ** The label is used in the UI and value becomes the value of the |
| 2328 | ** "status" tag on forum posts. Any forum post which has a status |
| 2329 | ** value which does not appear in this list is treated as if it had |
| 2330 | ** the first value from this list. If this setting is empty, is |
| 2331 | ** ill-formed JSON, or has only a single entry then the forum will |
| 2332 | ** lack the capability of setting and filtering by status. |
| 2333 | */ |
| 2334 | |
| 2335 | /* |
| 2336 | ** WEBPAGE: setup_forum |
| 2337 | ** |
| @@ -1946,19 +2449,113 @@ | |
| 2449 | @ <a href='%R/help/%h(pSetting->name)'>%h(pSetting->name)</a>: |
| 2450 | @ </td><td> |
| 2451 | entry_attribute("", 25, pSetting->name, zQP/*works-like:""*/, |
| 2452 | pSetting->def, 0); |
| 2453 | @ </td></tr> |
| 2454 | } |
| 2455 | } |
| 2456 | @ </tbody></table> |
| 2457 | @ <input type='submit' name='submit' value='Apply changes'> |
| 2458 | @ </form> |
| 2459 | } |
| 2460 | |
| 2461 | style_finish_page(); |
| 2462 | } |
| 2463 | |
| 2464 | /* |
| 2465 | ** If the forum-statuses setting is active and has 2 or more entries, |
| 2466 | ** this adds a submenu for selecting the status filter, else it emits |
| 2467 | ** nothing. |
| 2468 | */ |
| 2469 | static void forum_status_submenu(void){ |
| 2470 | const ForumStatusList * const fss = forum_statuses(); |
| 2471 | static int i = 0; |
| 2472 | static const char **az; |
| 2473 | if( i==0 && fss->n>1 ){ |
| 2474 | unsigned j; |
| 2475 | az = fossil_malloc(sizeof(az[0]) * ((1 + fss->n) * 2)); |
| 2476 | az[i++] = "*"; |
| 2477 | az[i++] = "Any status"; |
| 2478 | for( j = 0; j < fss->n; ++j ){ |
| 2479 | const ForumStatus * fs = &fss->aStatus[j]; |
| 2480 | /* Potential TODO: skip any entries for which there are no |
| 2481 | ** forum posts with a status=${fs->zValue} tag. */ |
| 2482 | az[i++] = fs->zValue; |
| 2483 | az[i++] = fs->zLabel; |
| 2484 | } |
| 2485 | //assert( i==(1+fss->n)*2 ); |
| 2486 | } |
| 2487 | if( i ){ |
| 2488 | cookie_link_parameter("status","forumStatus","*"); |
| 2489 | style_submenu_multichoice("status", i/2, az, 0); |
| 2490 | } |
| 2491 | } |
| 2492 | |
| 2493 | /* |
| 2494 | ** Transient SQL Function: status_match(FROOT) |
| 2495 | ** |
| 2496 | ** Return true if the forum thread identified by FROOT should be included |
| 2497 | ** in a list of threads. Used to implement the status=NAME query parameter |
| 2498 | ** on /forum. |
| 2499 | ** |
| 2500 | ** The result of this routine depends on the content of the |
| 2501 | ** ForumStatusMatch *pMData object that is available via sqlite3_user_data(). |
| 2502 | ** |
| 2503 | ** * If pMData==NULL, always return true. This means that no |
| 2504 | ** filtering of threads is being done. This is the common case. |
| 2505 | ** |
| 2506 | ** * If FROOT contains a status property value that matches |
| 2507 | ** pMData->iMatch, return true. |
| 2508 | ** |
| 2509 | ** * if pMData->iMatch==0 (meaning we want to match the default |
| 2510 | ** status value) and if the FROOT thread contains a status that |
| 2511 | ** is not on the list of statuses or if FROOT has no statue |
| 2512 | ** property at all, then return true. In other words, a forum |
| 2513 | ** thread with no status property or an unknown status property |
| 2514 | ** is treated as if it had the default status. |
| 2515 | ** |
| 2516 | ** * Otherwise, return false. |
| 2517 | */ |
| 2518 | static void forum_status_match( |
| 2519 | sqlite3_context *context, |
| 2520 | int argc, |
| 2521 | sqlite3_value **argv |
| 2522 | ){ |
| 2523 | static Stmt q; |
| 2524 | ForumStatusMatch *pMData = sqlite3_user_data(context); |
| 2525 | int i; |
| 2526 | |
| 2527 | if( pMData==0 ){ |
| 2528 | sqlite3_result_int(context, 1); |
| 2529 | return; |
| 2530 | } |
| 2531 | db_static_prepare(&q, |
| 2532 | "SELECT value FROM tagxref\n" |
| 2533 | " WHERE tagid=%d\n" |
| 2534 | " AND tagtype>=1\n" |
| 2535 | " AND rid=:rid\n" |
| 2536 | " ORDER BY mtime DESC LIMIT 1", |
| 2537 | pMData->eStatusTag |
| 2538 | ); |
| 2539 | db_bind_int(&q, ":rid", sqlite3_value_int(argv[0])); |
| 2540 | if( db_step(&q)==SQLITE_ROW ){ |
| 2541 | const char *zValue = (const char*)db_column_text(&q,0); |
| 2542 | const ForumStatusList *pFses = pMData->pFses; |
| 2543 | if( zValue==0 ){ |
| 2544 | i = 0; |
| 2545 | }else{ |
| 2546 | for(i=0; i<pFses->n; i++){ |
| 2547 | if( fossil_strcmp(pFses->aStatus[i].zValue,zValue)==0 ) break; |
| 2548 | } |
| 2549 | } |
| 2550 | if( i>=pMData->pFses->n ) i = 0; |
| 2551 | }else{ |
| 2552 | i = 0; |
| 2553 | } |
| 2554 | db_reset(&q); |
| 2555 | sqlite3_result_int(context, i==pMData->iMatch); |
| 2556 | } |
| 2557 | |
| 2558 | /* |
| 2559 | ** WEBPAGE: forummain |
| 2560 | ** WEBPAGE: forum |
| 2561 | ** |
| @@ -1975,30 +2572,38 @@ | |
| 2572 | void forum_main_page(void){ |
| 2573 | Stmt q; |
| 2574 | int iLimit = 0, iOfst, iCnt; |
| 2575 | int srchFlags; |
| 2576 | const int isSearch = P("s")!=0; |
| 2577 | const char *zStatusFilter; |
| 2578 | char const *zLimit = 0; /* Value of the n= query parameter */ |
| 2579 | int eStatusTag = 0; /* tagid for the "status" property */ |
| 2580 | int bHasStatus = 0; /* True if forum-statuses setting exists */ |
| 2581 | int bFilter = 0; /* True if status=NAME query parameter */ |
| 2582 | int bHasForum = 0; /* True if forumpost table exists */ |
| 2583 | const ForumStatusList *pFstat = forum_statuses(); |
| 2584 | ForumStatusMatch sFSM; /* Aux data to status_match() SQL function */ |
| 2585 | |
| 2586 | login_check_credentials(); |
| 2587 | srchFlags = search_restrict(SRCH_FORUM); |
| 2588 | if( !g.perm.RdForum ){ |
| 2589 | login_needed(g.anon.RdForum); |
| 2590 | return; |
| 2591 | } |
| 2592 | cgi_check_for_malice(); |
| 2593 | bHasForum = db_table_exists("repository","forumpost"); |
| 2594 | if( bHasForum ){ |
| 2595 | eStatusTag = db_int(0, "SELECT tagid FROM tag WHERE tagname='status'"); |
| 2596 | bHasStatus = pFstat->n>1; |
| 2597 | } |
| 2598 | style_set_current_feature("forum"); |
| 2599 | style_header("%s%s", db_get("forum-title","Forum"), |
| 2600 | isSearch ? " Search Results" : ""); |
| 2601 | style_submenu_element("Timeline", "%R/timeline?ss=v&y=f&vfx"); |
| 2602 | if( g.perm.WrForum ){ |
| 2603 | style_submenu_element("New Thread","%R/forumnew"); |
| 2604 | }else{ |
| 2605 | style_submenu_element("New Thread","%R/login"); |
| 2606 | } |
| 2607 | if( g.perm.ModForum && moderation_needed() ){ |
| 2608 | style_submenu_element("Moderation Requests", "%R/modreq"); |
| 2609 | } |
| @@ -2021,95 +2626,577 @@ | |
| 2626 | cgi_replace_query_parameter("n", fossil_strdup("25")) |
| 2627 | /*for the sake of Max, below*/; |
| 2628 | iLimit = 25; |
| 2629 | } |
| 2630 | style_submenu_entry("n","Max:",4,0); |
| 2631 | forum_status_submenu(); |
| 2632 | zStatusFilter = P("status") /*must be after forum_status_submenu()!*/; |
| 2633 | iOfst = atoi(PD("x","0")); |
| 2634 | iCnt = 0; |
| 2635 | if( zStatusFilter ){ |
| 2636 | if( zStatusFilter[0]==0 || 0==fossil_strcmp("*",zStatusFilter) ){ |
| 2637 | zStatusFilter = 0; |
| 2638 | }else{ |
| 2639 | bFilter = bHasStatus; |
| 2640 | } |
| 2641 | } |
| 2642 | if( bHasForum ){ |
| 2643 | Stmt qStat = empty_Stmt; /* Query to get status information */ |
| 2644 | if( bHasStatus ){ |
| 2645 | /* The qStat query runs once for each output row generate by the |
| 2646 | ** q query. It determines the value and label of the status for |
| 2647 | ** the row with froot=:rowid |
| 2648 | */ |
| 2649 | db_prepare(&qStat, |
| 2650 | "SELECT tagxref.value, forumstatus.label\n" |
| 2651 | " FROM forumstatus, tagxref\n" |
| 2652 | " WHERE tagid=%d AND tagtype>=1\n" |
| 2653 | " AND forumstatus.value=tagxref.value\n" |
| 2654 | " AND rid=:rid\n" |
| 2655 | " ORDER BY mtime DESC", |
| 2656 | eStatusTag |
| 2657 | ); |
| 2658 | } |
| 2659 | |
| 2660 | /* Create the status_match() SQL function that will determine |
| 2661 | ** whether or not each thread in the "q" query below is eligible |
| 2662 | ** for display |
| 2663 | */ |
| 2664 | if( bFilter ){ |
| 2665 | sFSM.pFses = pFstat; |
| 2666 | sFSM.eStatusTag = eStatusTag; |
| 2667 | for(sFSM.iMatch=0; sFSM.iMatch<pFstat->n; sFSM.iMatch++){ |
| 2668 | if( 0==fossil_strcmp(zStatusFilter, |
| 2669 | pFstat->aStatus[sFSM.iMatch].zValue) ){ |
| 2670 | break; |
| 2671 | } |
| 2672 | } |
| 2673 | sqlite3_create_function(g.db,"status_match",1,SQLITE_UTF8,(void*)&sFSM, |
| 2674 | forum_status_match, 0, 0); |
| 2675 | }else{ |
| 2676 | sqlite3_create_function(g.db,"status_match",1,SQLITE_UTF8,0, |
| 2677 | forum_status_match, 0, 0); |
| 2678 | } |
| 2679 | |
| 2680 | db_prepare(&q, |
| 2681 | "WITH thread(root,endtime,lastrid) AS (\n" |
| 2682 | " SELECT\n" |
| 2683 | " froot,\n" |
| 2684 | " max(fmtime),\n" |
| 2685 | " fpid\n" |
| 2686 | " FROM forumpost\n" |
| 2687 | " WHERE %s/*ModForum*/\n" |
| 2688 | " GROUP BY froot\n" |
| 2689 | " HAVING status_match(froot)\n" |
| 2690 | " ORDER BY 2 DESC\n" |
| 2691 | " LIMIT %d OFFSET %d\n" |
| 2692 | ")\n" |
| 2693 | "SELECT\n" |
| 2694 | " julianday('now') - thread.endtime,\n" /* 0 */ |
| 2695 | " thread.endtime - " |
| 2696 | "(SELECT fmtime FROM forumpost WHERE fpid=root),\n" /* 1 */ |
| 2697 | " (SELECT sum(fprev IS NULL) FROM forumpost" |
| 2698 | " WHERE froot=root),\n" /* 2 */ |
| 2699 | " blob.uuid,\n" /* 3 */ |
| 2700 | " substr(event.comment,instr(event.comment,':')+1),\n" /* 4 */ |
| 2701 | " thread.lastrid,\n" /* 5 */ |
| 2702 | " thread.root\n" /* 6 */ |
| 2703 | " FROM thread, blob, event\n" |
| 2704 | " WHERE blob.rid=thread.lastrid\n" |
| 2705 | " AND event.objid=thread.lastrid\n" |
| 2706 | " ORDER BY 1;", |
| 2707 | g.perm.ModForum ? "true" : "fpid NOT IN private" /*safe-for-%s*/, |
| 2708 | iLimit+1, iOfst |
| 2709 | ); |
| 2710 | while( db_step(&q)==SQLITE_ROW ){ |
| 2711 | char *zAge; |
| 2712 | int nMsg; |
| 2713 | const char *zUuid; |
| 2714 | const char *zTitle; |
| 2715 | const char *zStatus; |
| 2716 | const char *zStatusLbl; |
| 2717 | const int bShowStatus = bHasStatus && !zStatusFilter; |
| 2718 | const int nCols = bShowStatus ? 4 : 3; |
| 2719 | |
| 2720 | if( qStat.pStmt ){ |
| 2721 | /* Determine the status value for this row */ |
| 2722 | db_reset(&qStat); |
| 2723 | db_bind_int(&qStat, ":rid", db_column_int(&q,6)); |
| 2724 | if( db_step(&qStat)==SQLITE_ROW ){ |
| 2725 | zStatus = db_column_text(&qStat, 0); |
| 2726 | zStatusLbl = db_column_text(&qStat, 1); |
| 2727 | }else{ |
| 2728 | zStatus = pFstat->aStatus[0].zValue; |
| 2729 | zStatusLbl = pFstat->aStatus[0].zLabel; |
| 2730 | } |
| 2731 | }else{ |
| 2732 | zStatus = zStatusLbl = NULL; |
| 2733 | } |
| 2734 | zAge = human_readable_age(db_column_double(&q,0)); |
| 2735 | nMsg = db_column_int(&q, 2); |
| 2736 | zUuid = db_column_text(&q, 3); |
| 2737 | zTitle = db_column_text(&q, 4); |
| 2738 | if( iCnt==0 ){ |
| 2739 | char *zTail = bFilter ? mprintf(" with status=%Q", zStatusFilter): 0; |
| 2740 | if( iOfst>0 ){ |
| 2741 | @ <h1>Threads at least %s(zAge) old%h(zTail ? zTail : "")</h1> |
| 2742 | }else{ |
| 2743 | @ <h1>Most recent threads%h(zTail ? zTail : "")</h1> |
| 2744 | } |
| 2745 | fossil_free(zTail); |
| 2746 | @ <div class='forumPosts fileage'><table width="100%%"> |
| 2747 | if( iOfst>0 ){ |
| 2748 | if( iOfst>iLimit ){ |
| 2749 | @ <tr><td colspan="%d(nCols)">\ |
| 2750 | @ <a href='%R/forum?x=%d(iOfst-iLimit)&n=%d(iLimit) \ |
| 2751 | if( bFilter ){ |
| 2752 | @ &status=%T(zStatusFilter)\ |
| 2753 | } |
| 2754 | @ '>↑ Newer...</a></td></tr> |
| 2755 | }else{ |
| 2756 | @ <tr><td colspan="%d(nCols)">\ |
| 2757 | @ <a href='%R/forum?n=%d(iLimit)\ |
| 2758 | if( bFilter ){ |
| 2759 | @ &status=%T(zStatusFilter) \ |
| 2760 | } |
| 2761 | @ '>↑ Newer...</a></td></tr> |
| 2762 | } |
| 2763 | } |
| 2764 | } |
| 2765 | iCnt++; |
| 2766 | if( iCnt>iLimit ){ |
| 2767 | @ <tr><td colspan="%d(nCols)">\ |
| 2768 | @ <a href='%R/forum?x=%d(iOfst+iLimit)&n=%d(iLimit) \ |
| 2769 | if( bFilter ){ |
| 2770 | @ &status=%T(zStatusFilter)\ |
| 2771 | } |
| 2772 | @ '>↓ Older...</a></td></tr> |
| 2773 | fossil_free(zAge); |
| 2774 | break; |
| 2775 | } |
| 2776 | @ <tr \ |
| 2777 | if( bHasStatus ){ |
| 2778 | @ data-status="%h(zStatus)"\ |
| 2779 | } |
| 2780 | @ ><td>%h(zAge) ago</td> |
| 2781 | @ <td class='subject'>%z(href("%R/forumpost/%S",zUuid))%h(zTitle)</a>\ |
| 2782 | @ </td><td>\ |
| 2783 | if( g.perm.ModForum && moderation_pending(db_column_int(&q,5)) ){ |
| 2784 | @ <span class="modpending">\ |
| 2785 | @ Awaiting Moderator Approval</span><br> |
| 2786 | } |
| 2787 | if( nMsg<2 ){ |
| 2788 | @ no replies\ |
| 2789 | }else{ |
| 2790 | char *zDuration = human_readable_age(db_column_double(&q,1)); |
| 2791 | @ %d(nMsg) posts spanning %h(zDuration)\ |
| 2792 | fossil_free(zDuration); |
| 2793 | } |
| 2794 | @ </td>\ |
| 2795 | if( bShowStatus ){ |
| 2796 | @ <td class='status'>%h(zStatusLbl)</td>\ |
| 2797 | } |
| 2798 | if( qStat.pStmt ){ |
| 2799 | db_reset(&qStat); |
| 2800 | } |
| 2801 | @</tr> |
| 2802 | fossil_free(zAge); |
| 2803 | } |
| 2804 | db_finalize(&q); |
| 2805 | if( qStat.pStmt ) db_finalize(&qStat); |
| 2806 | sqlite3_create_function(g.db,"status_match",1,SQLITE_UTF8,0,0,0,0); |
| 2807 | } |
| 2808 | if( iCnt>0 ){ |
| 2809 | @ </table></div> |
| 2810 | }else{ |
| 2811 | @ <h1>No forum posts found</h1> |
| 2812 | } |
| 2813 | if( bHasStatus ){ |
| 2814 | /* We need a JS-side kludge to avoid passing on the x=N |
| 2815 | ** URL arg when the status selection list is activated. */ |
| 2816 | forum_emit_js(); |
| 2817 | } |
| 2818 | style_finish_page(); |
| 2819 | } |
| 2820 | |
| 2821 | /* |
| 2822 | ** The AJAX counterpart of forum_post(). |
| 2823 | ** |
| 2824 | ** Returns the new artifact's RID on success, 0 if no changes were |
| 2825 | ** necessary (e.g. an empty new post or dry-run mode), and a negative |
| 2826 | ** value on error. If it returns a negative value then it will have |
| 2827 | ** populated the ajax response state with an error object. |
| 2828 | ** |
| 2829 | ** zTitle must be NULL if iInReplyTo>0 and must be non-empty if |
| 2830 | ** iInReplyTo==0. |
| 2831 | ** |
| 2832 | ** The caller must have started a transaction and must roll it back if |
| 2833 | ** this call returns <=0, noting that only the negative-value case is |
| 2834 | ** an error. |
| 2835 | ** |
| 2836 | ** This function does some work to try to ensure that duplicate |
| 2837 | ** entries are not save (this can happen as a side effect of the forum |
| 2838 | ** post editor added in 2026-06). If the given post will not have been |
| 2839 | ** materially edited by these changes, they are not applied and the |
| 2840 | ** rid of the existing entry is used. |
| 2841 | ** |
| 2842 | ** Maintenance reminders: |
| 2843 | ** |
| 2844 | ** - iInReplyTo==0 && iEdit==0: new thread |
| 2845 | ** - iInReplyTo==0 && iEdit>0 : edit top post or response |
| 2846 | ** - iInReplyTo>0 && iEdit==0: new response |
| 2847 | ** - iInReplyTo>0 && iEdit>0 : edit response |
| 2848 | */ |
| 2849 | static int forum_post_ajax( |
| 2850 | const char *zTitle, /* Title. NULL for replies */ |
| 2851 | int iInReplyTo, /* Post replying to. 0 for new threads */ |
| 2852 | int iEdit, /* Post being edited, or zero for a new post */ |
| 2853 | const char *zUser, /* Username. NULL means use login name */ |
| 2854 | const char *zMimetype, /* Mimetype of content. */ |
| 2855 | const char *zContent, /* Content */ |
| 2856 | int iFlags /* FPOST_xyz flag values */ |
| 2857 | ){ |
| 2858 | char *zI; |
| 2859 | char *zG; |
| 2860 | char *zP = 0; |
| 2861 | int iBasis; |
| 2862 | Blob x = BLOB_INITIALIZER, |
| 2863 | cksum = BLOB_INITIALIZER, |
| 2864 | formatCheck = BLOB_INITIALIZER, |
| 2865 | errMsg = BLOB_INITIALIZER; |
| 2866 | Manifest *pPost = 0; |
| 2867 | int nContent = zContent ? (int)strlen(zContent) : 0; |
| 2868 | int rc = 0; |
| 2869 | |
| 2870 | assert( db_transaction_nesting_depth()>0 ); |
| 2871 | schema_forum(); |
| 2872 | if( iEdit==0 && fossil_all_whitespace(zContent) ){ |
| 2873 | return 0; |
| 2874 | } |
| 2875 | if( !g.perm.Admin && (iEdit || iInReplyTo) |
| 2876 | && forum_rid_is_tagged(iEdit ? iEdit : iInReplyTo, "closed", 1) ){ |
| 2877 | return -ajax_route_error(400, "Thread is closed."); |
| 2878 | } |
| 2879 | if( 0==iInReplyTo && fossil_all_whitespace(zTitle) ){ |
| 2880 | return -ajax_route_error(400, "Empty title is not permitted."); |
| 2881 | } |
| 2882 | |
| 2883 | if( zUser==0 ){ |
| 2884 | if( login_is_nobody() ){ |
| 2885 | zUser = "anonymous"; |
| 2886 | }else{ |
| 2887 | zUser = login_name(); |
| 2888 | } |
| 2889 | } |
| 2890 | if( iEdit>0 |
| 2891 | && !g.perm.Admin |
| 2892 | && !forumpost_is_owner(iEdit, zUser) ){ |
| 2893 | return -ajax_route_error( |
| 2894 | 403, "Only admins may edit other peoples' posts." |
| 2895 | ); |
| 2896 | } |
| 2897 | if( iInReplyTo==0 && iEdit>0 ){ |
| 2898 | iBasis = iEdit; |
| 2899 | iInReplyTo = db_int(0, "SELECT firt FROM forumpost WHERE fpid=%d", |
| 2900 | iEdit); |
| 2901 | }else{ |
| 2902 | iBasis = iInReplyTo; |
| 2903 | /* TODO (2026-06-008) If (iInReplyTo>0 && iEdit>0), validate that |
| 2904 | ** iInReplyTo is connected to iEdit properly, else we risk |
| 2905 | ** reparenting the new edit and having unrepredictable downstream |
| 2906 | ** side effects. */ |
| 2907 | } |
| 2908 | |
| 2909 | if( 0!=zMimetype && 0==zMimetype[0] ){ |
| 2910 | zMimetype = 0; |
| 2911 | } |
| 2912 | |
| 2913 | if( 0!=zTitle && 0==zTitle[0] ) zTitle = 0; |
| 2914 | webpage_assert( (zTitle==0)+(iInReplyTo==0)==1 ); |
| 2915 | |
| 2916 | if( iEdit>0 ){ |
| 2917 | int cmp; |
| 2918 | pPost = manifest_get(iEdit, CFTYPE_FORUM, 0); |
| 2919 | if( pPost==0 ){ |
| 2920 | rc = -ajax_route_error(404, "Missing edit artifact %d", iEdit); |
| 2921 | goto post_ajax_end; |
| 2922 | } |
| 2923 | /* |
| 2924 | ** If the old content matches the new then do not save a new copy. |
| 2925 | ** It's easy to get re-posts of unedited content via the forum |
| 2926 | ** editor, especially since the one added in 2026-06, where a |
| 2927 | ** post's status and attachments may be amended from the editor |
| 2928 | ** without modifying any of the post's content. In the legacy |
| 2929 | ** editor such "out-of-band" changes weren't possible and users |
| 2930 | ** have never made a practice of re-posting unedited content. |
| 2931 | ** |
| 2932 | ** We compare the following fields to the original: user, mimetype, |
| 2933 | ** content, and (for root posts only) the title. |
| 2934 | */ |
| 2935 | cmp = (0==pPost->zInReplyTo) |
| 2936 | ? fossil_strcmp(pPost->zThreadTitle, zTitle) |
| 2937 | : 0; |
| 2938 | if( 0==cmp ){ |
| 2939 | cmp=fossil_strcmp(pPost->zWiki, zContent); |
| 2940 | if( 0==cmp ){ |
| 2941 | cmp = fossil_strcmp(pPost->zUser, zUser); |
| 2942 | } |
| 2943 | if( 0==cmp |
| 2944 | && 0!=(cmp=fossil_strcmp(pPost->zMimetype, zMimetype)) ){ |
| 2945 | /* Extra mimetype checks for a common condition seen elsewhere */ |
| 2946 | if( (0==zMimetype |
| 2947 | && 0==fossil_strcmp(pPost->zMimetype, "text/x-fossil-wiki")) |
| 2948 | || (0==pPost->zMimetype |
| 2949 | && 0==fossil_strcmp(zMimetype, "text/x-fossil-wiki")) ){ |
| 2950 | cmp = 0; |
| 2951 | } |
| 2952 | } |
| 2953 | if( 0==cmp ){ |
| 2954 | rc = iEdit; |
| 2955 | goto post_ajax_end; |
| 2956 | } |
| 2957 | } |
| 2958 | zP = rid_to_uuid(iEdit); |
| 2959 | } |
| 2960 | |
| 2961 | /* Write the new artifact */ |
| 2962 | blob_init(&x, 0, 0); |
| 2963 | blob_appendf(&x, "D %z\n", date_in_standard_format("now")); |
| 2964 | zG = db_text( |
| 2965 | 0, |
| 2966 | "SELECT uuid FROM blob, forumpost" |
| 2967 | " WHERE blob.rid==forumpost.froot" |
| 2968 | " AND forumpost.fpid=%d", |
| 2969 | iBasis |
| 2970 | ); |
| 2971 | if( zG ){ |
| 2972 | blob_appendf(&x, "G %z\n", zG); |
| 2973 | } |
| 2974 | if( zTitle ){ |
| 2975 | blob_appendf(&x, "H %F\n", zTitle); |
| 2976 | } |
| 2977 | if( iInReplyTo>0 ){ |
| 2978 | zI = rid_to_uuid(iInReplyTo); |
| 2979 | if( 0==zI ){ |
| 2980 | rc = -ajax_route_error(404, "Missing in-reply-to artifact %d", |
| 2981 | iInReplyTo); |
| 2982 | goto post_ajax_end; |
| 2983 | } |
| 2984 | blob_appendf(&x, "I %z\n", zI); |
| 2985 | } |
| 2986 | if( zMimetype!=0 |
| 2987 | && fossil_strcmp(zMimetype,"text/x-fossil-wiki")!=0 ){ |
| 2988 | blob_appendf(&x, "N %F\n", zMimetype); |
| 2989 | } |
| 2990 | if( zP ){ |
| 2991 | blob_appendf(&x, "P %s\n", zP); |
| 2992 | } |
| 2993 | |
| 2994 | blob_appendf(&x, "U %F\n", zUser); |
| 2995 | blob_appendf(&x, "W %d\n%s\n", nContent, zContent); |
| 2996 | md5sum_blob(&x, &cksum); |
| 2997 | blob_appendf(&x, "Z %b\n", &cksum); |
| 2998 | blob_reset(&cksum); |
| 2999 | |
| 3000 | /* Verify that the artifact we are creating is well-formed */ |
| 3001 | blob_init(&formatCheck, 0, 0); |
| 3002 | blob_init(&errMsg, 0, 0); |
| 3003 | blob_copy(&formatCheck, &x); |
| 3004 | pPost = manifest_parse(&formatCheck, 0, &errMsg); |
| 3005 | if( pPost==0 ){ |
| 3006 | ajax_route_error(500, "Malformed forum post artifact: %b", &errMsg); |
| 3007 | rc = -500; |
| 3008 | goto post_ajax_end; |
| 3009 | } |
| 3010 | webpage_assert( pPost->type==CFTYPE_FORUM ); |
| 3011 | |
| 3012 | if( (iFlags & FPOST_DRYRUN)!=0 ){ |
| 3013 | rc = 0; |
| 3014 | }else{ |
| 3015 | int nrid; |
| 3016 | db_begin_transaction(); |
| 3017 | nrid = wiki_put(&x, iEdit>0 ? iEdit : 0, forum_need_moderation()); |
| 3018 | blob_reset(&x); |
| 3019 | if( (iFlags & FPOST_NO_ALERT)!=0 ){ |
| 3020 | alert_unqueue('f', nrid); |
| 3021 | } |
| 3022 | rc = nrid; |
| 3023 | db_end_transaction(0); |
| 3024 | } |
| 3025 | post_ajax_end: |
| 3026 | manifest_destroy(pPost); |
| 3027 | fossil_free(zP); |
| 3028 | blob_reset(&x); |
| 3029 | blob_reset(&cksum); |
| 3030 | blob_reset(&formatCheck); |
| 3031 | return rc; |
| 3032 | } |
| 3033 | /* |
| 3034 | ** WEBPAGE: forumajax_save hidden |
| 3035 | ** |
| 3036 | ** WIP |
| 3037 | ** |
| 3038 | ** Response JSON: |
| 3039 | ** |
| 3040 | ** { uuid: hash, ...tbd } |
| 3041 | */ |
| 3042 | void forum_ajax_save_page(void){ |
| 3043 | const char *zFpid; |
| 3044 | const char *zTitle; |
| 3045 | const char *zIrt; |
| 3046 | const char *zMimetype; |
| 3047 | const char *zContent; |
| 3048 | const char *zStatus; |
| 3049 | const int bHasAttachment = P("file1")!=0; |
| 3050 | Manifest *pPost = 0; |
| 3051 | char *zNewUuid = 0; |
| 3052 | int firt = 0; /* In-reply-to rid or 0 */ |
| 3053 | int fpid = 0; /* Post rid being edited or 0 */ |
| 3054 | int rc = 0; /* Result code. */ |
| 3055 | int nrid = 0; /* New artifact rid. */ |
| 3056 | int iPostFlags; /* forum_post_flags() (after perms check) */ |
| 3057 | int bRollback; /* True = roll back. */ |
| 3058 | int nAttach = 0; /* Number of attachments added */ |
| 3059 | int bStatusSet = 0; /* True if status tag set. */ |
| 3060 | |
| 3061 | if( !ajax_route_bootstrap(0, 1) ){ |
| 3062 | return; |
| 3063 | }else if( !g.perm.WrForum |
| 3064 | || (bHasAttachment && !g.perm.AttachForum) ){ |
| 3065 | ajax_route_error_forbidden(); |
| 3066 | return; |
| 3067 | }else if( !ajax_check_csrf(2) ){ |
| 3068 | ajax_route_error_csrf(); |
| 3069 | return; |
| 3070 | } |
| 3071 | |
| 3072 | iPostFlags = forum_post_flags(/*must come after permissions init*/); |
| 3073 | bRollback = (FPOST_DRYRUN & iPostFlags); |
| 3074 | zFpid = P("fpid"); |
| 3075 | zIrt = P("firt"); |
| 3076 | zMimetype = P("mimetype"); |
| 3077 | zContent = P("content"); |
| 3078 | zStatus = P("status"); |
| 3079 | db_begin_transaction(); |
| 3080 | if( zFpid && zFpid[0] ){ |
| 3081 | fpid = symbolic_name_to_rid(zFpid, "f"); |
| 3082 | if( fpid<0 ){ |
| 3083 | rc = -ajax_route_error(400, "Ambiguous forum ID."); |
| 3084 | goto ajax_save_end; |
| 3085 | }else if( 0==fpid |
| 3086 | || 0==(pPost = manifest_get(fpid, CFTYPE_FORUM, 0)) ){ |
| 3087 | rc = -ajax_route_error(404, "Cannot resolve forum post ID."); |
| 3088 | goto ajax_save_end; |
| 3089 | } |
| 3090 | } |
| 3091 | /* |
| 3092 | ** Problem: if we derive firt from fpid/pPost then there's a race |
| 3093 | ** condition where the IRT post is edited between the time that this |
| 3094 | ** edit was initiated and when it is posted: the new edit's IRT will |
| 3095 | ** point to the edit which was made in the meantime, not the one the |
| 3096 | ** user intended to respond to. However, if we accept firt from the |
| 3097 | ** enviornment, we "really should" validate that it's actually in |
| 3098 | ** the current chain, to prohibit that malicious posts could move |
| 3099 | ** posts around. |
| 3100 | ** |
| 3101 | ** forum_post_ajax() will, if fpid>0 && !firt, select fpid's current |
| 3102 | ** firt. |
| 3103 | */ |
| 3104 | if( zIrt && zIrt[0] ){ |
| 3105 | firt = symbolic_name_to_rid(zIrt, "f"); |
| 3106 | if( firt<0 ){ |
| 3107 | rc = -ajax_route_error(400, "Ambiguous in-reply-do ID."); |
| 3108 | goto ajax_save_end; |
| 3109 | }else if( 0==firt ){ |
| 3110 | rc = -ajax_route_error(404, "Cannot resolve in-reply-do ID."); |
| 3111 | goto ajax_save_end; |
| 3112 | } |
| 3113 | } |
| 3114 | |
| 3115 | if( 0 ){ |
| 3116 | rc = -ajax_route_error(400, "Save is TODO. " |
| 3117 | "iPostFlags=%d debug=%d", |
| 3118 | iPostFlags, g.perm.Debug); |
| 3119 | goto ajax_save_end; |
| 3120 | } |
| 3121 | |
| 3122 | zTitle = firt ? 0 : P("title"); |
| 3123 | nrid = forum_post_ajax(zTitle, firt, fpid, 0, zMimetype, |
| 3124 | zContent, iPostFlags); |
| 3125 | if( nrid<0 ){ |
| 3126 | rc = nrid; |
| 3127 | goto ajax_save_end; |
| 3128 | }else if( nrid==0 ){ |
| 3129 | if( 0==(FPOST_DRYRUN & iPostFlags) ){ |
| 3130 | bRollback = 1; |
| 3131 | CX("{\"message\": \"No saving needed.\"}\n"); |
| 3132 | }else{ |
| 3133 | CX("{\"message\": \"Rolled back for dry-run.\"," |
| 3134 | "\"iPostFlags\":%d}\n", iPostFlags); |
| 3135 | } |
| 3136 | goto ajax_save_end; |
| 3137 | }else{ |
| 3138 | const int bNeedsModeration = forum_need_moderation(); |
| 3139 | const int fpHead = forumpost_head_rid(nrid); |
| 3140 | assert( nrid>0 ); |
| 3141 | assert( fpHead>0 ); |
| 3142 | zNewUuid = rid_to_uuid(nrid); |
| 3143 | if( 0!=P("file1") ){ |
| 3144 | /* Attachments */ |
| 3145 | if( !g.perm.Admin && !g.perm.AttachForum ){ |
| 3146 | rc = -ajax_route_error(403, "No permission no attach files."); |
| 3147 | goto ajax_save_end; |
| 3148 | }else{ |
| 3149 | char *zRoot = (nrid==fpHead) ? 0 : rid_to_uuid(fpHead); |
| 3150 | nAttach = attachments_ajax_from_POST(zRoot ? zRoot : zNewUuid, |
| 3151 | bNeedsModeration); |
| 3152 | fossil_free(zRoot); |
| 3153 | if( nAttach<0 ){ |
| 3154 | rc = nAttach; |
| 3155 | goto ajax_save_end; |
| 3156 | } |
| 3157 | if( nAttach>0 |
| 3158 | && (iPostFlags & FPOST_NO_ALERT)!=0 |
| 3159 | && db_table_exists("repository","pending_alert") ){ |
| 3160 | /* Unqueue any alerts for these attachments. Recall that |
| 3161 | ** they're attached to the first version of the post, which |
| 3162 | ** means we actually risk cancelling _other_ pending |
| 3163 | ** notifications for attachments on this same post. C'est la |
| 3164 | ** vie.*/ |
| 3165 | db_multi_exec( |
| 3166 | "WITH x(id) AS (\n" |
| 3167 | " SELECT 'f%d'\n" |
| 3168 | " UNION ALL\n" |
| 3169 | " SELECT 'f'||a.attachid FROM blob b, attachment a\n" |
| 3170 | " WHERE b.rid=%d\n" |
| 3171 | " AND b.uuid=a.target\n" |
| 3172 | ") DELETE FROM pending_alert WHERE eventid IN x", |
| 3173 | fpHead, fpHead |
| 3174 | ); |
| 3175 | } |
| 3176 | } |
| 3177 | } |
| 3178 | if( 0==bNeedsModeration |
| 3179 | /* ^^^ Do not allow a status tag on a pending-moderation post |
| 3180 | ** because it will introduce a reference to an artifact which |
| 3181 | ** will become a phantom if it is rejected by a moderator. */ |
| 3182 | && zStatus!=0 && zStatus[0]!=0 |
| 3183 | && forum_may_set_status(nrid) |
| 3184 | && (bStatusSet=forumpost_tag(nrid, 1, "status", zStatus))<0 ){ |
| 3185 | rc = -ajax_route_error(500, "Tagging failed: %s", g.zErrMsg); |
| 3186 | goto ajax_save_end; |
| 3187 | } |
| 3188 | } |
| 3189 | |
| 3190 | assert( 0==rc ); |
| 3191 | assert( zNewUuid ); |
| 3192 | CX("{\"uuid\": %!j, \"attachedCount\": %d, " |
| 3193 | "\"statusModified\": %d, " |
| 3194 | "\"dryrun\": %s, \"iPostFlags\":%d}\n", |
| 3195 | zNewUuid, nAttach, |
| 3196 | bStatusSet, bRollback ? "true" : "false", iPostFlags); |
| 3197 | |
| 3198 | ajax_save_end: |
| 3199 | manifest_destroy(pPost); |
| 3200 | fossil_free(zNewUuid); |
| 3201 | db_end_transaction(rc || bRollback); |
| 3202 | } |
| 3203 | |
| 3204 | DDED src/fossil.attach.js |
+661
| --- a/src/fossil.attach.js | ||
| +++ b/src/fossil.attach.js | ||
| @@ -0,0 +1,661 @@ | ||
| 1 | +"use strict"; | |
| 2 | +/** | |
| 3 | + Utility for interactive file attachment. Supports attachment | |
| 4 | + selection from a file dialog, from the clipboard, or drag/drop. | |
| 5 | + | |
| 6 | + Requires that window.fossil has already been set up. | |
| 7 | + Depends on fossil.dom. | |
| 8 | +*/ | |
| 9 | +(function(namespace){ | |
| 10 | + "use strict"; | |
| 11 | + const F = namespace, D = F.dom; | |
| 12 | + | |
| 13 | + let idCounter = 0; | |
| 14 | + /** | |
| 15 | + Implements a multi-file selector widget. Intended to be plugged | |
| 16 | + in to places in Fossil's UI where attachments can be assigned to | |
| 17 | + an artifact. | |
| 18 | + */ | |
| 19 | + class Attacher { | |
| 20 | + /* Options. */ | |
| 21 | + #opt; | |
| 22 | + /* List of objects representing each row. */ | |
| 23 | + #rows = []; | |
| 24 | + /* DOM elements */ | |
| 25 | + #e = Object.create(null); | |
| 26 | + /* Proxy for various events this object fires. */ | |
| 27 | + #events = new EventTarget(); | |
| 28 | + | |
| 29 | + /** | |
| 30 | + Options: | |
| 31 | + | |
| 32 | + opt.container: Optional DOM element to append the resulting | |
| 33 | + widget to. If not set, the client can get access to the widget | |
| 34 | + element using this.body. | |
| 35 | + | |
| 36 | + opt.addButtonLabel: optional label for the "add attachment" | |
| 37 | + button, defaulting to something generic. | |
| 38 | + | |
| 39 | + opt.limit: optional max number of attachments to allow. This | |
| 40 | + defaults to "some sensible value". | |
| 41 | + | |
| 42 | + opt.startWith[=0]: if >0 then that many file selection widgets | |
| 43 | + are automatically activated, as if the user had tapped the Add | |
| 44 | + button that many times. | |
| 45 | + | |
| 46 | + opt.description[=true]: if true then show the file description | |
| 47 | + field, otherwise elide it. | |
| 48 | + | |
| 49 | + opt.reverse[=false]: reverses the flow of the widget such that | |
| 50 | + the Add button stays on the top and rows are ordered | |
| 51 | + most-recently-added. | |
| 52 | + | |
| 53 | + opt.controls = [array of DOM elements]. Optional DOM elements | |
| 54 | + to inject into the UI element which wraps the "Add" button. | |
| 55 | + See this.controlsElement. | |
| 56 | + | |
| 57 | + opt.listener = function or object: {add: func, remove: func, | |
| 58 | + populate: func}: if these are functions they are registered as | |
| 59 | + listeners for 'entry-added', 'entry-removed', and/or | |
| 60 | + 'entry-populated' events, described below. opt.listener.all, if | |
| 61 | + set, is used as a fallback for any of 'add', 'remove', or | |
| 62 | + 'populate' which are not set. If opt.listener is a function | |
| 63 | + then it behaves as if listener={all: thatFunction}. | |
| 64 | + | |
| 65 | + Events: | |
| 66 | + | |
| 67 | + This class fires CustomEvents for certain changes: | |
| 68 | + | |
| 69 | + 'entry-added' and 'entry-removed' trigger when an attachment | |
| 70 | + entry row is added/removed. Its event.detail is: | |
| 71 | + | |
| 72 | + {attacher: this, row: object, type: 'same as event type'}. | |
| 73 | + | |
| 74 | + 'entry-populated' is triggered when a visible entry gets | |
| 75 | + content attached to it, with the same detail structure as | |
| 76 | + described above. | |
| 77 | + | |
| 78 | + The public structure of the row object passed to each is | |
| 79 | + currently TBD. | |
| 80 | + */ | |
| 81 | + constructor(opt){ | |
| 82 | + this.#opt = opt = F.nu({ | |
| 83 | + addButtonLabel: false, | |
| 84 | + startWith: 0, | |
| 85 | + limit: 0, | |
| 86 | + dryRun: undefined, | |
| 87 | + description: true, | |
| 88 | + reverse: false | |
| 89 | + }, opt); | |
| 90 | + this.#e.body = D.addClass(D.div(), 'Attacher'); | |
| 91 | + if( opt.reverse ) this.#e.body.classList.add('reverse'); | |
| 92 | + const eBtnAdd = this.#e.btnAdd = D.addClass( | |
| 93 | + D.button(this.#opt.addButtonLabel || 'Add attachment', | |
| 94 | + ()=>this.#addRow()), | |
| 95 | + 'attach-add-button' | |
| 96 | + ); | |
| 97 | + eBtnAdd.type = 'button'; | |
| 98 | + opt.ownsAddButton = true; | |
| 99 | + this.#e.err = D.addClass(D.div(), 'error', 'hidden'); | |
| 100 | + this.#e.body.append(this.#e.err); | |
| 101 | + this.#e.err.addEventListener('dblclick',()=>this.reportError()); | |
| 102 | + | |
| 103 | + const eControls = this.#e.controls = | |
| 104 | + D.addClass(D.div(), 'attach-controls'); | |
| 105 | + eControls.append(eBtnAdd); | |
| 106 | + if( opt.container ){ | |
| 107 | + opt.container.appendChild(this.#e.body); | |
| 108 | + } | |
| 109 | + this.#e.body.appendChild(eControls); | |
| 110 | + if( opt.listener ){ | |
| 111 | + const doCb = (eventType, key)=>{ | |
| 112 | + const f = (opt.listener instanceof Function) | |
| 113 | + ? opt.listener | |
| 114 | + : (opt.listener[key] || opt.listener.all); | |
| 115 | + if( f instanceof Function ){ | |
| 116 | + this.addEventListener(eventType, f); | |
| 117 | + } | |
| 118 | + }; | |
| 119 | + doCb('entry-added', 'add'); | |
| 120 | + doCb('entry-removed', 'remove'); | |
| 121 | + doCb('entry-populated', 'populate'); | |
| 122 | + } | |
| 123 | + if( opt.dryRun ){ | |
| 124 | + /* Add dry-run toggle for testing. */ | |
| 125 | + const eLbl = D.label(false, "Dry-run?"); | |
| 126 | + const eCb = D.checkbox(true); | |
| 127 | + eLbl.append(eCb); | |
| 128 | + eControls.append(eLbl); | |
| 129 | + eCb.checked = opt.dryRun = true; | |
| 130 | + eCb.addEventListener('change',()=>opt.dryRun=eCb.checked); | |
| 131 | + } | |
| 132 | + if( Array.isArray(opt.controls) ){ | |
| 133 | + eControls.append(...opt.controls); | |
| 134 | + } | |
| 135 | + if( opt.startWith > 0 ){ | |
| 136 | + for(let i = 0; i < opt.startWith; ++i ){ | |
| 137 | + this.#addRow(); | |
| 138 | + } | |
| 139 | + }else{ | |
| 140 | + this.#updateControls(); | |
| 141 | + } | |
| 142 | + } | |
| 143 | + | |
| 144 | + | |
| 145 | + get widget(){ | |
| 146 | + return this.#e.body; | |
| 147 | + } | |
| 148 | + | |
| 149 | + addEventListener(...args){ | |
| 150 | + return this.#events.addEventListener(...args); | |
| 151 | + } | |
| 152 | + | |
| 153 | + removeEventListener(...args){ | |
| 154 | + return this.#events.removeEventListener(...args); | |
| 155 | + } | |
| 156 | + | |
| 157 | + /** Returns true if any visible input widgets have content | |
| 158 | + selected. */ | |
| 159 | + get isPopulated(){ | |
| 160 | + for(let r of this.#rows){ | |
| 161 | + if( r.file ) return true; | |
| 162 | + } | |
| 163 | + return false; | |
| 164 | + } | |
| 165 | + | |
| 166 | + get isDryRun(){ | |
| 167 | + return !!this.#opt.dryRun; | |
| 168 | + } | |
| 169 | + /** | |
| 170 | + Returns the DOM element (div.attach-controls) which wraps the | |
| 171 | + "Add" button. Clients may add buttons to it. | |
| 172 | + */ | |
| 173 | + get controlsElement(){ | |
| 174 | + return this.#e.controls; | |
| 175 | + } | |
| 176 | + | |
| 177 | + /** | |
| 178 | + Reports an error by appending each argument to the error widget | |
| 179 | + and unhiding it. If passed no arugments, it clears and hides | |
| 180 | + the error widget. | |
| 181 | + */ | |
| 182 | + reportError(...msg){ | |
| 183 | + const e = this.#e.err; | |
| 184 | + D.clearElement(e); | |
| 185 | + if( msg.length ){ | |
| 186 | + e.classList.remove('hidden'); | |
| 187 | + e.append(...msg); | |
| 188 | + }else{ | |
| 189 | + e.classList.add('hidden'); | |
| 190 | + } | |
| 191 | + } | |
| 192 | + | |
| 193 | + #removeRow(rowObj){ | |
| 194 | + const er = rowObj.e.row; | |
| 195 | + if( er.parentNode ){ | |
| 196 | + this.#rows = this.#rows.filter(v=>v!==rowObj); | |
| 197 | + this.#updateControls(); | |
| 198 | + er.classList.add('animate-exit'); | |
| 199 | + er.addEventListener('animationend', ()=>er.remove(), {once: true}); | |
| 200 | + this.#events.dispatchEvent( | |
| 201 | + new CustomEvent('entry-removed',{ | |
| 202 | + detail: F.nu({ | |
| 203 | + type: 'entry-removed', | |
| 204 | + row: rowObj, | |
| 205 | + attacher: this | |
| 206 | + }) | |
| 207 | + }) | |
| 208 | + ); | |
| 209 | + } | |
| 210 | + } | |
| 211 | + | |
| 212 | + /** | |
| 213 | + Removes all attachments and clears the error state. | |
| 214 | + */ | |
| 215 | + clear(){ | |
| 216 | + for(const r of [...this.#rows/*clone because this updates #rows*/]){ | |
| 217 | + this.#removeRow(r); | |
| 218 | + } | |
| 219 | + this.reportError(); | |
| 220 | + } | |
| 221 | + | |
| 222 | + /** | |
| 223 | + Hides or shows the Add button, as appropriate. | |
| 224 | + */ | |
| 225 | + #updateControls(){ | |
| 226 | + const b = this.#e.btnAdd; | |
| 227 | + if( this.#opt.limit>0 && this.#rows.length >= this.#opt.limit ){ | |
| 228 | + b.classList.add('hidden'); | |
| 229 | + D.disable(b); | |
| 230 | + //F.toast.warning("Attachment form limit reached."); | |
| 231 | + }else{ | |
| 232 | + b.classList.remove('hidden'); | |
| 233 | + D.enable(b); | |
| 234 | + if( this.#opt.ownsAddButton ){ | |
| 235 | + this.#e.body.append(this.#e.controls/*move to the end*/); | |
| 236 | + } | |
| 237 | + } | |
| 238 | + } | |
| 239 | + | |
| 240 | + /** | |
| 241 | + Returns the "Add" button widget, Passing control of it to the | |
| 242 | + caller so that they can place it in another location. This | |
| 243 | + object will still manage its enabled/disabled/hidden state but | |
| 244 | + will no longer move it when adding a row. | |
| 245 | + */ | |
| 246 | + takeAddButton(){ | |
| 247 | + if( this.#opt.ownsAddButton ){ | |
| 248 | + this.#opt.ownsAddButton; | |
| 249 | + } | |
| 250 | + return this.#e.btnAdd; | |
| 251 | + } | |
| 252 | + /** | |
| 253 | + Sets rowObj.e.err up with an error message, or clears it if | |
| 254 | + passed only 1 argument. | |
| 255 | + */ | |
| 256 | + #rowError(rowObj,...msg){ | |
| 257 | + let e = rowObj.e.err; | |
| 258 | + if( e ){ | |
| 259 | + D.clearElement(e); | |
| 260 | + }else{ | |
| 261 | + if( !msg.length ) return; | |
| 262 | + e = rowObj.e.err = D.addClass(D.span(), 'error'); | |
| 263 | + rowObj.e.info.append(e); | |
| 264 | + } | |
| 265 | + if( msg.length ){ | |
| 266 | + e.append(...msg); | |
| 267 | + e.classList.remove('hidden'); | |
| 268 | + }else{ | |
| 269 | + e.classList.add('hidden'); | |
| 270 | + } | |
| 271 | + } | |
| 272 | + | |
| 273 | + #addRow(){ | |
| 274 | + const id = ++idCounter; | |
| 275 | + const rowObj = F.nu({ | |
| 276 | + id, file: null, mimeType: '' | |
| 277 | + }); | |
| 278 | + const eRow = D.addClass(D.div(), 'attach-row'); | |
| 279 | + const eDropzone = D.addClass(D.div(), 'attach-dropzone'); | |
| 280 | + const eFile = D.addClass( | |
| 281 | + D.input('file'), 'attach-file-input', 'hidden' | |
| 282 | + ); | |
| 283 | + const eInfo = D.addClass(D.span(), 'attach-row-info'); | |
| 284 | + const eFilename = D.append( | |
| 285 | + D.addClass(D.span(), 'attach-filename'), | |
| 286 | + "Select/drop file or click the outer border and tap your "+ | |
| 287 | + "platform's conventional <paste> keyboard shortcut." | |
| 288 | + ); | |
| 289 | + const eSize = D.addClass(D.span(), 'attach-size'); | |
| 290 | + eInfo.append(eFilename, eSize); | |
| 291 | + const eDesc = this.#opt.description | |
| 292 | + ? D.addClass( | |
| 293 | + D.attr(D.textarea(), 'placeholder', | |
| 294 | + 'Optional description...'), | |
| 295 | + 'attach-desc' | |
| 296 | + ) | |
| 297 | + : undefined; | |
| 298 | + const eRemove = D.addClass( | |
| 299 | + D.button('X', (ev)=>{ | |
| 300 | + ev.stopPropagation(); | |
| 301 | + this.#removeRow(rowObj); | |
| 302 | + }), | |
| 303 | + 'attach-row-remove' | |
| 304 | + ); | |
| 305 | + eRemove.setAttribute('title', 'Remove this attachment.'); | |
| 306 | + eRemove.type = 'button'; | |
| 307 | + | |
| 308 | + D.append(eDropzone, eInfo, eFile, eRemove); | |
| 309 | + eDropzone.addEventListener('click', ()=>eFile.click()); | |
| 310 | + eFile.addEventListener('change', (ev)=>{ | |
| 311 | + if( ev.target.files.length ){ | |
| 312 | + this.#injestBlob(rowObj, ev.target.files[0]); | |
| 313 | + } | |
| 314 | + }); | |
| 315 | + | |
| 316 | + eDropzone.addEventListener('dragover', (ev)=>{ | |
| 317 | + ev.preventDefault(); | |
| 318 | + eDropzone.classList.add('dragover'); | |
| 319 | + }); | |
| 320 | + eDropzone.addEventListener('dragleave', (ev)=>{ | |
| 321 | + eDropzone.classList.remove('dragover'); | |
| 322 | + }); | |
| 323 | + const handleDrop = (ev, theRealRowObj)=>{ | |
| 324 | + ev.preventDefault(); | |
| 325 | + eDropzone.classList.remove('dragover'); | |
| 326 | + if( ev.dataTransfer.files.length ){ | |
| 327 | + const r = theRealRowObj || rowObj; | |
| 328 | + this.#injestBlob(r, ev.dataTransfer.files[0]); | |
| 329 | + } | |
| 330 | + }; | |
| 331 | + /* Isn't working? eBtnAdd.addEventListener('drop', (ev)=>{ | |
| 332 | + this.#addRow(); | |
| 333 | + handleDrop(ev, this.#rows[this.#rows.length-1]); | |
| 334 | + });*/ | |
| 335 | + eDropzone.addEventListener('drop', handleDrop); | |
| 336 | + const pasteImage = (event, item)=>{ | |
| 337 | + if( item.type.indexOf('image') === 0 ) { | |
| 338 | + event.preventDefault(); | |
| 339 | + const blob = item.getAsFile(); | |
| 340 | + if( blob.name === 'image.png' ){ | |
| 341 | + /* Workaround to attempt to avoid name collisions when pasting | |
| 342 | + multiple images. We cannot, at this level, unambiguously | |
| 343 | + distinguish a ctrl-v of bitmap data vs a ctrl-v of an image | |
| 344 | + file copied via a desktop file manager. */ | |
| 345 | + rowObj.overrideName = `pasted-image-${Date.now()}.png`; | |
| 346 | + } | |
| 347 | + this.#injestBlob(rowObj, blob); | |
| 348 | + return true; | |
| 349 | + } | |
| 350 | + return false; | |
| 351 | + }; | |
| 352 | + const pasteThing = (event, thing)=>{ | |
| 353 | + if( pasteImage(event, thing) ) return true; | |
| 354 | + if( 'file' === thing.kind ){ | |
| 355 | + event.preventDefault(); | |
| 356 | + const blob = thing.getAsFile(); | |
| 357 | + if( blob ){ | |
| 358 | + this.#injestBlob(rowObj, blob); | |
| 359 | + return true; | |
| 360 | + } | |
| 361 | + } | |
| 362 | + return false; | |
| 363 | + }; | |
| 364 | + eDesc?.addEventListener?.('paste', (e) => { | |
| 365 | + e.stopPropagation(); | |
| 366 | + const items = (e.clipboardData || e.originalEvent.clipboardData)?.items; | |
| 367 | + if( !items ) return; | |
| 368 | + for( let i = 0; i < items.length; ++i ){ | |
| 369 | + const item = items[i]; | |
| 370 | + if( pasteThing(e, item) ){ | |
| 371 | + break; | |
| 372 | + } | |
| 373 | + } | |
| 374 | + }); | |
| 375 | + eRow.addEventListener('paste', (e) => { | |
| 376 | + const items = (e.clipboardData || e.originalEvent.clipboardData)?.items; | |
| 377 | + if( !items ) return; | |
| 378 | + for( let i = 0; i < items.length; ++i ){ | |
| 379 | + const item = items[i]; | |
| 380 | + if( item.type === 'text/plain' ){ | |
| 381 | + e.preventDefault(); | |
| 382 | + item.getAsString((text) => { | |
| 383 | + rowObj.overrideName = `pasted-text-${Date.now()}.txt`; | |
| 384 | + const blob = new File([text], rowObj.overrideName, | |
| 385 | + {type: 'text/plain'}); | |
| 386 | + this.#injestBlob(rowObj, blob); | |
| 387 | + }); | |
| 388 | + break; | |
| 389 | + }else if( pasteThing(e, item) ){ | |
| 390 | + break; | |
| 391 | + } | |
| 392 | + } | |
| 393 | + }); | |
| 394 | + eRow.append(eDropzone); | |
| 395 | + if( eDesc ) eRow.append(eDesc); | |
| 396 | + rowObj.e = F.nu({ | |
| 397 | + dropzone: eDropzone, | |
| 398 | + info: eInfo, | |
| 399 | + filename: eFilename, | |
| 400 | + size: eSize, | |
| 401 | + desc: eDesc, | |
| 402 | + row: eRow, | |
| 403 | + remove: eRemove | |
| 404 | + }); | |
| 405 | + this.#e.body.append(eRow); | |
| 406 | + eRow.classList.add('animate-entrance'); | |
| 407 | + requestAnimationFrame(() => { | |
| 408 | + eRow.scrollIntoView({ | |
| 409 | + behavior: 'smooth', | |
| 410 | + block: 'nearest', | |
| 411 | + inline: 'nearest' | |
| 412 | + }); | |
| 413 | + }); | |
| 414 | + | |
| 415 | + this.#rows.push( rowObj ); | |
| 416 | + this.#updateControls(); | |
| 417 | + this.#events.dispatchEvent( | |
| 418 | + new CustomEvent('entry-added',{ | |
| 419 | + detail: F.nu({ | |
| 420 | + type: 'entry-added', | |
| 421 | + row: rowObj, | |
| 422 | + attacher: this | |
| 423 | + }) | |
| 424 | + }) | |
| 425 | + ); | |
| 426 | + if( 0 ){ | |
| 427 | + /* To allow immediate ctrl-v, we need a trick... | |
| 428 | + But don't do this because it will interfere with, e.g., | |
| 429 | + the forum editor. */ | |
| 430 | + D.attr(eRow, 'tabindex', '-1'); | |
| 431 | + eRow.focus(); | |
| 432 | + } | |
| 433 | + } | |
| 434 | + | |
| 435 | + #rowMatchingName(name){ | |
| 436 | + for(let r of this.#rows){ | |
| 437 | + if( r.file?.name===name ) return r; | |
| 438 | + } | |
| 439 | + } | |
| 440 | + | |
| 441 | + /** | |
| 442 | + Injects the given File object as the attached content for the | |
| 443 | + given row. If the object's name collides with another row, | |
| 444 | + rowObj is removed from this widget and the old row is instead | |
| 445 | + re-populated with the new file. | |
| 446 | + | |
| 447 | + If rowObj.overrideName is set then the given file gets wrapped | |
| 448 | + with that name before attaching it, and that property is | |
| 449 | + removed from rowObj. This is intended only for communicating | |
| 450 | + auto-generated names for pasted data. | |
| 451 | + */ | |
| 452 | + #injestBlob(rowObj, file){ | |
| 453 | + if( !file ) return; | |
| 454 | + const old = this.#rowMatchingName(file.name); | |
| 455 | + if( rowObj.overrideName ){ | |
| 456 | + if( rowObj.overrideName !== file.name ){ | |
| 457 | + file = new File([file], rowObj.overrideName, {type: file.type}); | |
| 458 | + } | |
| 459 | + rowObj.overrideName = undefined; | |
| 460 | + } | |
| 461 | + if( old && rowObj !== old ){ | |
| 462 | + /* | |
| 463 | + Fossil attachments treat the name as a unique-per-target | |
| 464 | + key, with the newest one being the primary. If a name is | |
| 465 | + given twice, remove the new entry and reuse the older | |
| 466 | + one. There are conceivable, but also unlikely, cases where | |
| 467 | + this will have unintended side-effects, e.g. attaching both | |
| 468 | + /foo/bar and /baz/bar, but that seems like a lesser evil | |
| 469 | + than attaching the same file N times, leading to N | |
| 470 | + attachment artifacts. | |
| 471 | + */ | |
| 472 | + /* recycle `old` instead to avoid UI flicker. */ | |
| 473 | + this.#rowError(old); | |
| 474 | + this.#removeRow(rowObj); | |
| 475 | + rowObj = old; | |
| 476 | + } | |
| 477 | + | |
| 478 | + let szLbl; | |
| 479 | + if( file.size < 500000 ){ | |
| 480 | + szLbl = file.size + ' bytes'; | |
| 481 | + }else if( file.size < 1000000 ){ | |
| 482 | + szLbl = (file.size / 1024).toFixed(2)+' KB'; | |
| 483 | + }else{ | |
| 484 | + szLbl = (file.size / (1024 * 1024)).toFixed(2)+' MB'; | |
| 485 | + } | |
| 486 | + this.#rowError(rowObj); | |
| 487 | + rowObj.file = file; | |
| 488 | + rowObj.mimeType = file.type || 'application/octet-stream'; | |
| 489 | + D.clearElement(rowObj.e.filename).append(file.name || 'Pasted Content'); | |
| 490 | + D.clearElement(rowObj.e.size).append(szLbl, ' ', rowObj.mimeType || ''); | |
| 491 | + rowObj.e.dropzone.classList.add('populated'); | |
| 492 | + if( rowObj.e.desc ){ | |
| 493 | + rowObj.e.desc.classList.remove('hidden'); | |
| 494 | + } | |
| 495 | + if( rowObj.e.thumbnail ){ | |
| 496 | + rowObj.e.thumbnail.remove(); | |
| 497 | + rowObj.e.thumbnail = undefined; | |
| 498 | + } | |
| 499 | + if( file.type?.startsWith?.('image/') || file.type==='BITMAP' ){ | |
| 500 | + /* Add a thumbnail */ | |
| 501 | + const img = rowObj.e.thumbnail = D.img(); | |
| 502 | + rowObj.e.dropzone.insertBefore(img, rowObj.e.remove); | |
| 503 | + img.classList.add('thumbnail'); | |
| 504 | + const reader = new FileReader(); | |
| 505 | + reader.onload = (e)=>img.setAttribute('src', e.target.result); | |
| 506 | + reader.readAsDataURL(file); | |
| 507 | + } | |
| 508 | + if( F.config.attachmentSizeLimit>0 | |
| 509 | + && file.size>F.config.attachmentSizeLimit ){ | |
| 510 | + /* Problem: tapping this link propagates its click event through | |
| 511 | + to eDropzone. Thus... */ | |
| 512 | + const eLink = D.a(F.repoUrl('help/attachment-size-limit'),'limit'); | |
| 513 | + eLink.addEventListener('click', ev=>ev.stopPropagation()); | |
| 514 | + this.#rowError(rowObj, "Too large: ", eLink, | |
| 515 | + " is ",F.config.attachmentSizeLimit," bytes"); | |
| 516 | + rowObj.ok = false; | |
| 517 | + }else if( !file.size ){ | |
| 518 | + this.#rowError(rowObj, "Cannot attach zero-byte files."); | |
| 519 | + rowObj.ok = false; | |
| 520 | + }else{ | |
| 521 | + rowObj.ok = true; | |
| 522 | + } | |
| 523 | + this.#events.dispatchEvent( | |
| 524 | + new CustomEvent('entry-populated',{ | |
| 525 | + detail: F.nu({ | |
| 526 | + type: 'entry-populated', | |
| 527 | + row: rowObj, | |
| 528 | + attacher: this | |
| 529 | + }) | |
| 530 | + }) | |
| 531 | + ); | |
| 532 | + } | |
| 533 | + | |
| 534 | + /** | |
| 535 | + Returns an array of objects describing the currently-selected | |
| 536 | + attachments. | |
| 537 | + */ | |
| 538 | + collectState(){ | |
| 539 | + const rv = []; | |
| 540 | + for(let r of this.#rows){ | |
| 541 | + if( !r.e.dropzone?.classList?.contains?.('populated') ){ | |
| 542 | + continue; | |
| 543 | + } | |
| 544 | + rv.push(F.nu({ | |
| 545 | + name: r.name || r.file.name, | |
| 546 | + content: r.file, | |
| 547 | + description: r.e.desc?.value ?? '', | |
| 548 | + mimeType: r.mimeType | |
| 549 | + })); | |
| 550 | + } | |
| 551 | + return rv; | |
| 552 | + } | |
| 553 | + | |
| 554 | + /** | |
| 555 | + Populates the given FormData object with entries named | |
| 556 | + ${namePrefix}${N}, each representing a selected file and N | |
| 557 | + being a 1-based incremental counter. For entries which have a | |
| 558 | + description, it also sets ${namePrefix}${N}_desc. | |
| 559 | + */ | |
| 560 | + populateFormData(fd, namePrefix='file'){ | |
| 561 | + const st = this.collectState(); | |
| 562 | + let i = 0; | |
| 563 | + for( ; i < st.length; ++i){ | |
| 564 | + const s = st[i]; | |
| 565 | + const suffix = i+1; | |
| 566 | + fd.append(`${namePrefix}${suffix}`, s.content, s.name); | |
| 567 | + const d = s.description?.trim?.(); | |
| 568 | + if( d ){ | |
| 569 | + fd.append(`${namePrefix}${suffix}_desc`, d); | |
| 570 | + } | |
| 571 | + } | |
| 572 | + return i; | |
| 573 | + } | |
| 574 | + }/*Attacher*/; | |
| 575 | + F.Attacher = Attacher; | |
| 576 | + | |
| 577 | + F.onPageLoad(function(){ | |
| 578 | + const eAttachWrapper = document.querySelector('#attachadd-form-wrapper'); | |
| 579 | + if( eAttachWrapper ){ | |
| 580 | + /* This page is /attachadd v2. eAttachWrapper holds | |
| 581 | + input[type=hidden] fields for use in attaching files and is | |
| 582 | + where we inject a file attachment widget. */ | |
| 583 | + document.body.querySelectorAll('#attachadd-legacy-form').forEach(e=>e.remove()); | |
| 584 | + | |
| 585 | + eAttachWrapper.classList.remove('hidden'); | |
| 586 | + const urlArgs = new URLSearchParams(window.location.search); | |
| 587 | + let zTarget = urlArgs.get('target'); | |
| 588 | + let zTo = urlArgs.get('to') || urlArgs.get('from'); | |
| 589 | + const eBtnSubmit = D.button("Submit"); | |
| 590 | + eBtnSubmit.type = 'button'; | |
| 591 | + const updateBtnSubmit = (attacher)=>{ | |
| 592 | + if( attacher.isPopulated ){ | |
| 593 | + eBtnSubmit.removeAttribute('disabled'); | |
| 594 | + }else{ | |
| 595 | + eBtnSubmit.setAttribute('disabled', ''); | |
| 596 | + } | |
| 597 | + }; | |
| 598 | + const cbAttacherChange = (ev)=>{ | |
| 599 | + const a = ev.detail.attacher; | |
| 600 | + updateBtnSubmit(a); | |
| 601 | + }; | |
| 602 | + const att = new Attacher({ | |
| 603 | + container: eAttachWrapper, | |
| 604 | + startWith: 1, | |
| 605 | + listener: cbAttacherChange, | |
| 606 | + controls: [eBtnSubmit], | |
| 607 | + description: true | |
| 608 | + }); | |
| 609 | + eBtnSubmit.addEventListener('click', async (ev)=>{ | |
| 610 | + att.reportError(); | |
| 611 | + const li = att.collectState(); | |
| 612 | + if( !li.length ) return; | |
| 613 | + if( eBtnSubmit.dataset.submitted ) return; | |
| 614 | + eBtnSubmit.dataset.submitted = 1; | |
| 615 | + D.disable(eBtnSubmit); | |
| 616 | + const fd = new FormData(); | |
| 617 | + att.populateFormData(fd); | |
| 618 | + for( const eIn of eAttachWrapper.querySelectorAll( | |
| 619 | + 'input[type="hidden"]' | |
| 620 | + ) ){ | |
| 621 | + /* Copy over hidden input fields emitted by the server. */ | |
| 622 | + if( eIn.name==='target' ){ | |
| 623 | + zTarget = eIn.value; | |
| 624 | + }else if( eIn.name==='to' || (eIn.name==='from' && !zTo) ){ | |
| 625 | + zTo = eIn.value; | |
| 626 | + } | |
| 627 | + fd.append(eIn.name, eIn.value) | |
| 628 | + } | |
| 629 | + if( att.isDryRun ){ | |
| 630 | + fd.append('dryrun', '1'); | |
| 631 | + } | |
| 632 | + let err; | |
| 633 | + const resp = await window.fetch(F.repoUrl('attachadd_ajax_post'), { | |
| 634 | + method: 'POST', | |
| 635 | + body: fd | |
| 636 | + }).catch((e)=>{ | |
| 637 | + err = e; | |
| 638 | + }); | |
| 639 | + D.enable(eBtnSubmit); | |
| 640 | + delete eBtnSubmit.dataset.submitted; | |
| 641 | + const jr = err ? undefined : await resp.json().catch(()=>{}); | |
| 642 | + if( err || jr?.error || !resp.ok ){ | |
| 643 | + const msg = err ? err.message : (jr?.error || resp.statusText); | |
| 644 | + att.reportError("Attaching failed: ", msg); | |
| 645 | + }else{ | |
| 646 | + att.clear(); | |
| 647 | + let to = zTo || jr?.redirect; | |
| 648 | + if( to ){ | |
| 649 | + if( '/'!==to[0] ){ | |
| 650 | + to = F.repoUrl(to); | |
| 651 | + } | |
| 652 | + window.location = to; | |
| 653 | + }else if( zTarget ){ | |
| 654 | + window.location = '?target='+zTarget+'&'+Date.now(); | |
| 655 | + } | |
| 656 | + } | |
| 657 | + })/*submit handler*/; | |
| 658 | + updateBtnSubmit(att); | |
| 659 | + F.page.attacher = att /* only for testing via dev console */; | |
| 660 | + }/* /attachadd */ | |
| 661 | + })/*onPageLoa |
| --- a/src/fossil.attach.js | |
| +++ b/src/fossil.attach.js | |
| @@ -0,0 +1,661 @@ | |
| --- a/src/fossil.attach.js | |
| +++ b/src/fossil.attach.js | |
| @@ -0,0 +1,661 @@ | |
| 1 | "use strict"; |
| 2 | /** |
| 3 | Utility for interactive file attachment. Supports attachment |
| 4 | selection from a file dialog, from the clipboard, or drag/drop. |
| 5 | |
| 6 | Requires that window.fossil has already been set up. |
| 7 | Depends on fossil.dom. |
| 8 | */ |
| 9 | (function(namespace){ |
| 10 | "use strict"; |
| 11 | const F = namespace, D = F.dom; |
| 12 | |
| 13 | let idCounter = 0; |
| 14 | /** |
| 15 | Implements a multi-file selector widget. Intended to be plugged |
| 16 | in to places in Fossil's UI where attachments can be assigned to |
| 17 | an artifact. |
| 18 | */ |
| 19 | class Attacher { |
| 20 | /* Options. */ |
| 21 | #opt; |
| 22 | /* List of objects representing each row. */ |
| 23 | #rows = []; |
| 24 | /* DOM elements */ |
| 25 | #e = Object.create(null); |
| 26 | /* Proxy for various events this object fires. */ |
| 27 | #events = new EventTarget(); |
| 28 | |
| 29 | /** |
| 30 | Options: |
| 31 | |
| 32 | opt.container: Optional DOM element to append the resulting |
| 33 | widget to. If not set, the client can get access to the widget |
| 34 | element using this.body. |
| 35 | |
| 36 | opt.addButtonLabel: optional label for the "add attachment" |
| 37 | button, defaulting to something generic. |
| 38 | |
| 39 | opt.limit: optional max number of attachments to allow. This |
| 40 | defaults to "some sensible value". |
| 41 | |
| 42 | opt.startWith[=0]: if >0 then that many file selection widgets |
| 43 | are automatically activated, as if the user had tapped the Add |
| 44 | button that many times. |
| 45 | |
| 46 | opt.description[=true]: if true then show the file description |
| 47 | field, otherwise elide it. |
| 48 | |
| 49 | opt.reverse[=false]: reverses the flow of the widget such that |
| 50 | the Add button stays on the top and rows are ordered |
| 51 | most-recently-added. |
| 52 | |
| 53 | opt.controls = [array of DOM elements]. Optional DOM elements |
| 54 | to inject into the UI element which wraps the "Add" button. |
| 55 | See this.controlsElement. |
| 56 | |
| 57 | opt.listener = function or object: {add: func, remove: func, |
| 58 | populate: func}: if these are functions they are registered as |
| 59 | listeners for 'entry-added', 'entry-removed', and/or |
| 60 | 'entry-populated' events, described below. opt.listener.all, if |
| 61 | set, is used as a fallback for any of 'add', 'remove', or |
| 62 | 'populate' which are not set. If opt.listener is a function |
| 63 | then it behaves as if listener={all: thatFunction}. |
| 64 | |
| 65 | Events: |
| 66 | |
| 67 | This class fires CustomEvents for certain changes: |
| 68 | |
| 69 | 'entry-added' and 'entry-removed' trigger when an attachment |
| 70 | entry row is added/removed. Its event.detail is: |
| 71 | |
| 72 | {attacher: this, row: object, type: 'same as event type'}. |
| 73 | |
| 74 | 'entry-populated' is triggered when a visible entry gets |
| 75 | content attached to it, with the same detail structure as |
| 76 | described above. |
| 77 | |
| 78 | The public structure of the row object passed to each is |
| 79 | currently TBD. |
| 80 | */ |
| 81 | constructor(opt){ |
| 82 | this.#opt = opt = F.nu({ |
| 83 | addButtonLabel: false, |
| 84 | startWith: 0, |
| 85 | limit: 0, |
| 86 | dryRun: undefined, |
| 87 | description: true, |
| 88 | reverse: false |
| 89 | }, opt); |
| 90 | this.#e.body = D.addClass(D.div(), 'Attacher'); |
| 91 | if( opt.reverse ) this.#e.body.classList.add('reverse'); |
| 92 | const eBtnAdd = this.#e.btnAdd = D.addClass( |
| 93 | D.button(this.#opt.addButtonLabel || 'Add attachment', |
| 94 | ()=>this.#addRow()), |
| 95 | 'attach-add-button' |
| 96 | ); |
| 97 | eBtnAdd.type = 'button'; |
| 98 | opt.ownsAddButton = true; |
| 99 | this.#e.err = D.addClass(D.div(), 'error', 'hidden'); |
| 100 | this.#e.body.append(this.#e.err); |
| 101 | this.#e.err.addEventListener('dblclick',()=>this.reportError()); |
| 102 | |
| 103 | const eControls = this.#e.controls = |
| 104 | D.addClass(D.div(), 'attach-controls'); |
| 105 | eControls.append(eBtnAdd); |
| 106 | if( opt.container ){ |
| 107 | opt.container.appendChild(this.#e.body); |
| 108 | } |
| 109 | this.#e.body.appendChild(eControls); |
| 110 | if( opt.listener ){ |
| 111 | const doCb = (eventType, key)=>{ |
| 112 | const f = (opt.listener instanceof Function) |
| 113 | ? opt.listener |
| 114 | : (opt.listener[key] || opt.listener.all); |
| 115 | if( f instanceof Function ){ |
| 116 | this.addEventListener(eventType, f); |
| 117 | } |
| 118 | }; |
| 119 | doCb('entry-added', 'add'); |
| 120 | doCb('entry-removed', 'remove'); |
| 121 | doCb('entry-populated', 'populate'); |
| 122 | } |
| 123 | if( opt.dryRun ){ |
| 124 | /* Add dry-run toggle for testing. */ |
| 125 | const eLbl = D.label(false, "Dry-run?"); |
| 126 | const eCb = D.checkbox(true); |
| 127 | eLbl.append(eCb); |
| 128 | eControls.append(eLbl); |
| 129 | eCb.checked = opt.dryRun = true; |
| 130 | eCb.addEventListener('change',()=>opt.dryRun=eCb.checked); |
| 131 | } |
| 132 | if( Array.isArray(opt.controls) ){ |
| 133 | eControls.append(...opt.controls); |
| 134 | } |
| 135 | if( opt.startWith > 0 ){ |
| 136 | for(let i = 0; i < opt.startWith; ++i ){ |
| 137 | this.#addRow(); |
| 138 | } |
| 139 | }else{ |
| 140 | this.#updateControls(); |
| 141 | } |
| 142 | } |
| 143 | |
| 144 | |
| 145 | get widget(){ |
| 146 | return this.#e.body; |
| 147 | } |
| 148 | |
| 149 | addEventListener(...args){ |
| 150 | return this.#events.addEventListener(...args); |
| 151 | } |
| 152 | |
| 153 | removeEventListener(...args){ |
| 154 | return this.#events.removeEventListener(...args); |
| 155 | } |
| 156 | |
| 157 | /** Returns true if any visible input widgets have content |
| 158 | selected. */ |
| 159 | get isPopulated(){ |
| 160 | for(let r of this.#rows){ |
| 161 | if( r.file ) return true; |
| 162 | } |
| 163 | return false; |
| 164 | } |
| 165 | |
| 166 | get isDryRun(){ |
| 167 | return !!this.#opt.dryRun; |
| 168 | } |
| 169 | /** |
| 170 | Returns the DOM element (div.attach-controls) which wraps the |
| 171 | "Add" button. Clients may add buttons to it. |
| 172 | */ |
| 173 | get controlsElement(){ |
| 174 | return this.#e.controls; |
| 175 | } |
| 176 | |
| 177 | /** |
| 178 | Reports an error by appending each argument to the error widget |
| 179 | and unhiding it. If passed no arugments, it clears and hides |
| 180 | the error widget. |
| 181 | */ |
| 182 | reportError(...msg){ |
| 183 | const e = this.#e.err; |
| 184 | D.clearElement(e); |
| 185 | if( msg.length ){ |
| 186 | e.classList.remove('hidden'); |
| 187 | e.append(...msg); |
| 188 | }else{ |
| 189 | e.classList.add('hidden'); |
| 190 | } |
| 191 | } |
| 192 | |
| 193 | #removeRow(rowObj){ |
| 194 | const er = rowObj.e.row; |
| 195 | if( er.parentNode ){ |
| 196 | this.#rows = this.#rows.filter(v=>v!==rowObj); |
| 197 | this.#updateControls(); |
| 198 | er.classList.add('animate-exit'); |
| 199 | er.addEventListener('animationend', ()=>er.remove(), {once: true}); |
| 200 | this.#events.dispatchEvent( |
| 201 | new CustomEvent('entry-removed',{ |
| 202 | detail: F.nu({ |
| 203 | type: 'entry-removed', |
| 204 | row: rowObj, |
| 205 | attacher: this |
| 206 | }) |
| 207 | }) |
| 208 | ); |
| 209 | } |
| 210 | } |
| 211 | |
| 212 | /** |
| 213 | Removes all attachments and clears the error state. |
| 214 | */ |
| 215 | clear(){ |
| 216 | for(const r of [...this.#rows/*clone because this updates #rows*/]){ |
| 217 | this.#removeRow(r); |
| 218 | } |
| 219 | this.reportError(); |
| 220 | } |
| 221 | |
| 222 | /** |
| 223 | Hides or shows the Add button, as appropriate. |
| 224 | */ |
| 225 | #updateControls(){ |
| 226 | const b = this.#e.btnAdd; |
| 227 | if( this.#opt.limit>0 && this.#rows.length >= this.#opt.limit ){ |
| 228 | b.classList.add('hidden'); |
| 229 | D.disable(b); |
| 230 | //F.toast.warning("Attachment form limit reached."); |
| 231 | }else{ |
| 232 | b.classList.remove('hidden'); |
| 233 | D.enable(b); |
| 234 | if( this.#opt.ownsAddButton ){ |
| 235 | this.#e.body.append(this.#e.controls/*move to the end*/); |
| 236 | } |
| 237 | } |
| 238 | } |
| 239 | |
| 240 | /** |
| 241 | Returns the "Add" button widget, Passing control of it to the |
| 242 | caller so that they can place it in another location. This |
| 243 | object will still manage its enabled/disabled/hidden state but |
| 244 | will no longer move it when adding a row. |
| 245 | */ |
| 246 | takeAddButton(){ |
| 247 | if( this.#opt.ownsAddButton ){ |
| 248 | this.#opt.ownsAddButton; |
| 249 | } |
| 250 | return this.#e.btnAdd; |
| 251 | } |
| 252 | /** |
| 253 | Sets rowObj.e.err up with an error message, or clears it if |
| 254 | passed only 1 argument. |
| 255 | */ |
| 256 | #rowError(rowObj,...msg){ |
| 257 | let e = rowObj.e.err; |
| 258 | if( e ){ |
| 259 | D.clearElement(e); |
| 260 | }else{ |
| 261 | if( !msg.length ) return; |
| 262 | e = rowObj.e.err = D.addClass(D.span(), 'error'); |
| 263 | rowObj.e.info.append(e); |
| 264 | } |
| 265 | if( msg.length ){ |
| 266 | e.append(...msg); |
| 267 | e.classList.remove('hidden'); |
| 268 | }else{ |
| 269 | e.classList.add('hidden'); |
| 270 | } |
| 271 | } |
| 272 | |
| 273 | #addRow(){ |
| 274 | const id = ++idCounter; |
| 275 | const rowObj = F.nu({ |
| 276 | id, file: null, mimeType: '' |
| 277 | }); |
| 278 | const eRow = D.addClass(D.div(), 'attach-row'); |
| 279 | const eDropzone = D.addClass(D.div(), 'attach-dropzone'); |
| 280 | const eFile = D.addClass( |
| 281 | D.input('file'), 'attach-file-input', 'hidden' |
| 282 | ); |
| 283 | const eInfo = D.addClass(D.span(), 'attach-row-info'); |
| 284 | const eFilename = D.append( |
| 285 | D.addClass(D.span(), 'attach-filename'), |
| 286 | "Select/drop file or click the outer border and tap your "+ |
| 287 | "platform's conventional <paste> keyboard shortcut." |
| 288 | ); |
| 289 | const eSize = D.addClass(D.span(), 'attach-size'); |
| 290 | eInfo.append(eFilename, eSize); |
| 291 | const eDesc = this.#opt.description |
| 292 | ? D.addClass( |
| 293 | D.attr(D.textarea(), 'placeholder', |
| 294 | 'Optional description...'), |
| 295 | 'attach-desc' |
| 296 | ) |
| 297 | : undefined; |
| 298 | const eRemove = D.addClass( |
| 299 | D.button('X', (ev)=>{ |
| 300 | ev.stopPropagation(); |
| 301 | this.#removeRow(rowObj); |
| 302 | }), |
| 303 | 'attach-row-remove' |
| 304 | ); |
| 305 | eRemove.setAttribute('title', 'Remove this attachment.'); |
| 306 | eRemove.type = 'button'; |
| 307 | |
| 308 | D.append(eDropzone, eInfo, eFile, eRemove); |
| 309 | eDropzone.addEventListener('click', ()=>eFile.click()); |
| 310 | eFile.addEventListener('change', (ev)=>{ |
| 311 | if( ev.target.files.length ){ |
| 312 | this.#injestBlob(rowObj, ev.target.files[0]); |
| 313 | } |
| 314 | }); |
| 315 | |
| 316 | eDropzone.addEventListener('dragover', (ev)=>{ |
| 317 | ev.preventDefault(); |
| 318 | eDropzone.classList.add('dragover'); |
| 319 | }); |
| 320 | eDropzone.addEventListener('dragleave', (ev)=>{ |
| 321 | eDropzone.classList.remove('dragover'); |
| 322 | }); |
| 323 | const handleDrop = (ev, theRealRowObj)=>{ |
| 324 | ev.preventDefault(); |
| 325 | eDropzone.classList.remove('dragover'); |
| 326 | if( ev.dataTransfer.files.length ){ |
| 327 | const r = theRealRowObj || rowObj; |
| 328 | this.#injestBlob(r, ev.dataTransfer.files[0]); |
| 329 | } |
| 330 | }; |
| 331 | /* Isn't working? eBtnAdd.addEventListener('drop', (ev)=>{ |
| 332 | this.#addRow(); |
| 333 | handleDrop(ev, this.#rows[this.#rows.length-1]); |
| 334 | });*/ |
| 335 | eDropzone.addEventListener('drop', handleDrop); |
| 336 | const pasteImage = (event, item)=>{ |
| 337 | if( item.type.indexOf('image') === 0 ) { |
| 338 | event.preventDefault(); |
| 339 | const blob = item.getAsFile(); |
| 340 | if( blob.name === 'image.png' ){ |
| 341 | /* Workaround to attempt to avoid name collisions when pasting |
| 342 | multiple images. We cannot, at this level, unambiguously |
| 343 | distinguish a ctrl-v of bitmap data vs a ctrl-v of an image |
| 344 | file copied via a desktop file manager. */ |
| 345 | rowObj.overrideName = `pasted-image-${Date.now()}.png`; |
| 346 | } |
| 347 | this.#injestBlob(rowObj, blob); |
| 348 | return true; |
| 349 | } |
| 350 | return false; |
| 351 | }; |
| 352 | const pasteThing = (event, thing)=>{ |
| 353 | if( pasteImage(event, thing) ) return true; |
| 354 | if( 'file' === thing.kind ){ |
| 355 | event.preventDefault(); |
| 356 | const blob = thing.getAsFile(); |
| 357 | if( blob ){ |
| 358 | this.#injestBlob(rowObj, blob); |
| 359 | return true; |
| 360 | } |
| 361 | } |
| 362 | return false; |
| 363 | }; |
| 364 | eDesc?.addEventListener?.('paste', (e) => { |
| 365 | e.stopPropagation(); |
| 366 | const items = (e.clipboardData || e.originalEvent.clipboardData)?.items; |
| 367 | if( !items ) return; |
| 368 | for( let i = 0; i < items.length; ++i ){ |
| 369 | const item = items[i]; |
| 370 | if( pasteThing(e, item) ){ |
| 371 | break; |
| 372 | } |
| 373 | } |
| 374 | }); |
| 375 | eRow.addEventListener('paste', (e) => { |
| 376 | const items = (e.clipboardData || e.originalEvent.clipboardData)?.items; |
| 377 | if( !items ) return; |
| 378 | for( let i = 0; i < items.length; ++i ){ |
| 379 | const item = items[i]; |
| 380 | if( item.type === 'text/plain' ){ |
| 381 | e.preventDefault(); |
| 382 | item.getAsString((text) => { |
| 383 | rowObj.overrideName = `pasted-text-${Date.now()}.txt`; |
| 384 | const blob = new File([text], rowObj.overrideName, |
| 385 | {type: 'text/plain'}); |
| 386 | this.#injestBlob(rowObj, blob); |
| 387 | }); |
| 388 | break; |
| 389 | }else if( pasteThing(e, item) ){ |
| 390 | break; |
| 391 | } |
| 392 | } |
| 393 | }); |
| 394 | eRow.append(eDropzone); |
| 395 | if( eDesc ) eRow.append(eDesc); |
| 396 | rowObj.e = F.nu({ |
| 397 | dropzone: eDropzone, |
| 398 | info: eInfo, |
| 399 | filename: eFilename, |
| 400 | size: eSize, |
| 401 | desc: eDesc, |
| 402 | row: eRow, |
| 403 | remove: eRemove |
| 404 | }); |
| 405 | this.#e.body.append(eRow); |
| 406 | eRow.classList.add('animate-entrance'); |
| 407 | requestAnimationFrame(() => { |
| 408 | eRow.scrollIntoView({ |
| 409 | behavior: 'smooth', |
| 410 | block: 'nearest', |
| 411 | inline: 'nearest' |
| 412 | }); |
| 413 | }); |
| 414 | |
| 415 | this.#rows.push( rowObj ); |
| 416 | this.#updateControls(); |
| 417 | this.#events.dispatchEvent( |
| 418 | new CustomEvent('entry-added',{ |
| 419 | detail: F.nu({ |
| 420 | type: 'entry-added', |
| 421 | row: rowObj, |
| 422 | attacher: this |
| 423 | }) |
| 424 | }) |
| 425 | ); |
| 426 | if( 0 ){ |
| 427 | /* To allow immediate ctrl-v, we need a trick... |
| 428 | But don't do this because it will interfere with, e.g., |
| 429 | the forum editor. */ |
| 430 | D.attr(eRow, 'tabindex', '-1'); |
| 431 | eRow.focus(); |
| 432 | } |
| 433 | } |
| 434 | |
| 435 | #rowMatchingName(name){ |
| 436 | for(let r of this.#rows){ |
| 437 | if( r.file?.name===name ) return r; |
| 438 | } |
| 439 | } |
| 440 | |
| 441 | /** |
| 442 | Injects the given File object as the attached content for the |
| 443 | given row. If the object's name collides with another row, |
| 444 | rowObj is removed from this widget and the old row is instead |
| 445 | re-populated with the new file. |
| 446 | |
| 447 | If rowObj.overrideName is set then the given file gets wrapped |
| 448 | with that name before attaching it, and that property is |
| 449 | removed from rowObj. This is intended only for communicating |
| 450 | auto-generated names for pasted data. |
| 451 | */ |
| 452 | #injestBlob(rowObj, file){ |
| 453 | if( !file ) return; |
| 454 | const old = this.#rowMatchingName(file.name); |
| 455 | if( rowObj.overrideName ){ |
| 456 | if( rowObj.overrideName !== file.name ){ |
| 457 | file = new File([file], rowObj.overrideName, {type: file.type}); |
| 458 | } |
| 459 | rowObj.overrideName = undefined; |
| 460 | } |
| 461 | if( old && rowObj !== old ){ |
| 462 | /* |
| 463 | Fossil attachments treat the name as a unique-per-target |
| 464 | key, with the newest one being the primary. If a name is |
| 465 | given twice, remove the new entry and reuse the older |
| 466 | one. There are conceivable, but also unlikely, cases where |
| 467 | this will have unintended side-effects, e.g. attaching both |
| 468 | /foo/bar and /baz/bar, but that seems like a lesser evil |
| 469 | than attaching the same file N times, leading to N |
| 470 | attachment artifacts. |
| 471 | */ |
| 472 | /* recycle `old` instead to avoid UI flicker. */ |
| 473 | this.#rowError(old); |
| 474 | this.#removeRow(rowObj); |
| 475 | rowObj = old; |
| 476 | } |
| 477 | |
| 478 | let szLbl; |
| 479 | if( file.size < 500000 ){ |
| 480 | szLbl = file.size + ' bytes'; |
| 481 | }else if( file.size < 1000000 ){ |
| 482 | szLbl = (file.size / 1024).toFixed(2)+' KB'; |
| 483 | }else{ |
| 484 | szLbl = (file.size / (1024 * 1024)).toFixed(2)+' MB'; |
| 485 | } |
| 486 | this.#rowError(rowObj); |
| 487 | rowObj.file = file; |
| 488 | rowObj.mimeType = file.type || 'application/octet-stream'; |
| 489 | D.clearElement(rowObj.e.filename).append(file.name || 'Pasted Content'); |
| 490 | D.clearElement(rowObj.e.size).append(szLbl, ' ', rowObj.mimeType || ''); |
| 491 | rowObj.e.dropzone.classList.add('populated'); |
| 492 | if( rowObj.e.desc ){ |
| 493 | rowObj.e.desc.classList.remove('hidden'); |
| 494 | } |
| 495 | if( rowObj.e.thumbnail ){ |
| 496 | rowObj.e.thumbnail.remove(); |
| 497 | rowObj.e.thumbnail = undefined; |
| 498 | } |
| 499 | if( file.type?.startsWith?.('image/') || file.type==='BITMAP' ){ |
| 500 | /* Add a thumbnail */ |
| 501 | const img = rowObj.e.thumbnail = D.img(); |
| 502 | rowObj.e.dropzone.insertBefore(img, rowObj.e.remove); |
| 503 | img.classList.add('thumbnail'); |
| 504 | const reader = new FileReader(); |
| 505 | reader.onload = (e)=>img.setAttribute('src', e.target.result); |
| 506 | reader.readAsDataURL(file); |
| 507 | } |
| 508 | if( F.config.attachmentSizeLimit>0 |
| 509 | && file.size>F.config.attachmentSizeLimit ){ |
| 510 | /* Problem: tapping this link propagates its click event through |
| 511 | to eDropzone. Thus... */ |
| 512 | const eLink = D.a(F.repoUrl('help/attachment-size-limit'),'limit'); |
| 513 | eLink.addEventListener('click', ev=>ev.stopPropagation()); |
| 514 | this.#rowError(rowObj, "Too large: ", eLink, |
| 515 | " is ",F.config.attachmentSizeLimit," bytes"); |
| 516 | rowObj.ok = false; |
| 517 | }else if( !file.size ){ |
| 518 | this.#rowError(rowObj, "Cannot attach zero-byte files."); |
| 519 | rowObj.ok = false; |
| 520 | }else{ |
| 521 | rowObj.ok = true; |
| 522 | } |
| 523 | this.#events.dispatchEvent( |
| 524 | new CustomEvent('entry-populated',{ |
| 525 | detail: F.nu({ |
| 526 | type: 'entry-populated', |
| 527 | row: rowObj, |
| 528 | attacher: this |
| 529 | }) |
| 530 | }) |
| 531 | ); |
| 532 | } |
| 533 | |
| 534 | /** |
| 535 | Returns an array of objects describing the currently-selected |
| 536 | attachments. |
| 537 | */ |
| 538 | collectState(){ |
| 539 | const rv = []; |
| 540 | for(let r of this.#rows){ |
| 541 | if( !r.e.dropzone?.classList?.contains?.('populated') ){ |
| 542 | continue; |
| 543 | } |
| 544 | rv.push(F.nu({ |
| 545 | name: r.name || r.file.name, |
| 546 | content: r.file, |
| 547 | description: r.e.desc?.value ?? '', |
| 548 | mimeType: r.mimeType |
| 549 | })); |
| 550 | } |
| 551 | return rv; |
| 552 | } |
| 553 | |
| 554 | /** |
| 555 | Populates the given FormData object with entries named |
| 556 | ${namePrefix}${N}, each representing a selected file and N |
| 557 | being a 1-based incremental counter. For entries which have a |
| 558 | description, it also sets ${namePrefix}${N}_desc. |
| 559 | */ |
| 560 | populateFormData(fd, namePrefix='file'){ |
| 561 | const st = this.collectState(); |
| 562 | let i = 0; |
| 563 | for( ; i < st.length; ++i){ |
| 564 | const s = st[i]; |
| 565 | const suffix = i+1; |
| 566 | fd.append(`${namePrefix}${suffix}`, s.content, s.name); |
| 567 | const d = s.description?.trim?.(); |
| 568 | if( d ){ |
| 569 | fd.append(`${namePrefix}${suffix}_desc`, d); |
| 570 | } |
| 571 | } |
| 572 | return i; |
| 573 | } |
| 574 | }/*Attacher*/; |
| 575 | F.Attacher = Attacher; |
| 576 | |
| 577 | F.onPageLoad(function(){ |
| 578 | const eAttachWrapper = document.querySelector('#attachadd-form-wrapper'); |
| 579 | if( eAttachWrapper ){ |
| 580 | /* This page is /attachadd v2. eAttachWrapper holds |
| 581 | input[type=hidden] fields for use in attaching files and is |
| 582 | where we inject a file attachment widget. */ |
| 583 | document.body.querySelectorAll('#attachadd-legacy-form').forEach(e=>e.remove()); |
| 584 | |
| 585 | eAttachWrapper.classList.remove('hidden'); |
| 586 | const urlArgs = new URLSearchParams(window.location.search); |
| 587 | let zTarget = urlArgs.get('target'); |
| 588 | let zTo = urlArgs.get('to') || urlArgs.get('from'); |
| 589 | const eBtnSubmit = D.button("Submit"); |
| 590 | eBtnSubmit.type = 'button'; |
| 591 | const updateBtnSubmit = (attacher)=>{ |
| 592 | if( attacher.isPopulated ){ |
| 593 | eBtnSubmit.removeAttribute('disabled'); |
| 594 | }else{ |
| 595 | eBtnSubmit.setAttribute('disabled', ''); |
| 596 | } |
| 597 | }; |
| 598 | const cbAttacherChange = (ev)=>{ |
| 599 | const a = ev.detail.attacher; |
| 600 | updateBtnSubmit(a); |
| 601 | }; |
| 602 | const att = new Attacher({ |
| 603 | container: eAttachWrapper, |
| 604 | startWith: 1, |
| 605 | listener: cbAttacherChange, |
| 606 | controls: [eBtnSubmit], |
| 607 | description: true |
| 608 | }); |
| 609 | eBtnSubmit.addEventListener('click', async (ev)=>{ |
| 610 | att.reportError(); |
| 611 | const li = att.collectState(); |
| 612 | if( !li.length ) return; |
| 613 | if( eBtnSubmit.dataset.submitted ) return; |
| 614 | eBtnSubmit.dataset.submitted = 1; |
| 615 | D.disable(eBtnSubmit); |
| 616 | const fd = new FormData(); |
| 617 | att.populateFormData(fd); |
| 618 | for( const eIn of eAttachWrapper.querySelectorAll( |
| 619 | 'input[type="hidden"]' |
| 620 | ) ){ |
| 621 | /* Copy over hidden input fields emitted by the server. */ |
| 622 | if( eIn.name==='target' ){ |
| 623 | zTarget = eIn.value; |
| 624 | }else if( eIn.name==='to' || (eIn.name==='from' && !zTo) ){ |
| 625 | zTo = eIn.value; |
| 626 | } |
| 627 | fd.append(eIn.name, eIn.value) |
| 628 | } |
| 629 | if( att.isDryRun ){ |
| 630 | fd.append('dryrun', '1'); |
| 631 | } |
| 632 | let err; |
| 633 | const resp = await window.fetch(F.repoUrl('attachadd_ajax_post'), { |
| 634 | method: 'POST', |
| 635 | body: fd |
| 636 | }).catch((e)=>{ |
| 637 | err = e; |
| 638 | }); |
| 639 | D.enable(eBtnSubmit); |
| 640 | delete eBtnSubmit.dataset.submitted; |
| 641 | const jr = err ? undefined : await resp.json().catch(()=>{}); |
| 642 | if( err || jr?.error || !resp.ok ){ |
| 643 | const msg = err ? err.message : (jr?.error || resp.statusText); |
| 644 | att.reportError("Attaching failed: ", msg); |
| 645 | }else{ |
| 646 | att.clear(); |
| 647 | let to = zTo || jr?.redirect; |
| 648 | if( to ){ |
| 649 | if( '/'!==to[0] ){ |
| 650 | to = F.repoUrl(to); |
| 651 | } |
| 652 | window.location = to; |
| 653 | }else if( zTarget ){ |
| 654 | window.location = '?target='+zTarget+'&'+Date.now(); |
| 655 | } |
| 656 | } |
| 657 | })/*submit handler*/; |
| 658 | updateBtnSubmit(att); |
| 659 | F.page.attacher = att /* only for testing via dev console */; |
| 660 | }/* /attachadd */ |
| 661 | })/*onPageLoa |
+8
-5
| --- src/fossil.bootstrap.js | ||
| +++ src/fossil.bootstrap.js | ||
| @@ -17,10 +17,14 @@ | ||
| 17 | 17 | initialized that object. |
| 18 | 18 | */ |
| 19 | 19 | |
| 20 | 20 | const F = global.fossil; |
| 21 | 21 | |
| 22 | + /** Creates a prototype-less plain object with properties derived | |
| 23 | + from all of its object-type arguments. */ | |
| 24 | + F.nu = (...obj)=>Object.assign(Object.create(null),...obj); | |
| 25 | + | |
| 22 | 26 | /** |
| 23 | 27 | Returns the current time in something approximating |
| 24 | 28 | ISO-8601 format. |
| 25 | 29 | */ |
| 26 | 30 | const timestring = function f(){ |
| @@ -54,11 +58,11 @@ | ||
| 54 | 58 | ** removed from the object. Pass it a falsy value to clear the target |
| 55 | 59 | ** element. |
| 56 | 60 | ** |
| 57 | 61 | ** Returns this object. |
| 58 | 62 | */ |
| 59 | - F.message = function f(msg){ | |
| 63 | + F.message = function f(){ | |
| 60 | 64 | const args = Array.prototype.slice.call(arguments,0); |
| 61 | 65 | const tgt = f.targetElement; |
| 62 | 66 | if(args.length) args.unshift( |
| 63 | 67 | localTimeString()+':' |
| 64 | 68 | //timestring(),'UTC:' |
| @@ -84,26 +88,25 @@ | ||
| 84 | 88 | F.message.targetElement.addEventListener( |
| 85 | 89 | 'dblclick', ()=>F.message(), false |
| 86 | 90 | ); |
| 87 | 91 | } |
| 88 | 92 | /* |
| 89 | - ** By default fossil.error() sends its first argument to | |
| 93 | + ** By default fossil.error() sends all arguments to | |
| 90 | 94 | ** console.error(). If fossil.message.targetElement (yes, |
| 91 | 95 | ** fossil.message) is set, it adds the 'error' CSS class to |
| 92 | 96 | ** that element and sets its content as defined for message(). |
| 93 | 97 | ** |
| 94 | 98 | ** Returns this object. |
| 95 | 99 | */ |
| 96 | - F.error = function f(msg){ | |
| 100 | + F.error = function f(){ | |
| 97 | 101 | const args = Array.prototype.slice.call(arguments,0); |
| 98 | 102 | const tgt = F.message.targetElement; |
| 99 | 103 | args.unshift(timestring(),'UTC:'); |
| 100 | 104 | if(tgt){ |
| 101 | 105 | tgt.classList.add('error'); |
| 102 | 106 | tgt.innerText = args.join(' '); |
| 103 | - } | |
| 104 | - else{ | |
| 107 | + }else{ | |
| 105 | 108 | args.unshift('Fossil error:'); |
| 106 | 109 | console.error.apply(console,args); |
| 107 | 110 | } |
| 108 | 111 | return this; |
| 109 | 112 | }; |
| 110 | 113 |
| --- src/fossil.bootstrap.js | |
| +++ src/fossil.bootstrap.js | |
| @@ -17,10 +17,14 @@ | |
| 17 | initialized that object. |
| 18 | */ |
| 19 | |
| 20 | const F = global.fossil; |
| 21 | |
| 22 | /** |
| 23 | Returns the current time in something approximating |
| 24 | ISO-8601 format. |
| 25 | */ |
| 26 | const timestring = function f(){ |
| @@ -54,11 +58,11 @@ | |
| 54 | ** removed from the object. Pass it a falsy value to clear the target |
| 55 | ** element. |
| 56 | ** |
| 57 | ** Returns this object. |
| 58 | */ |
| 59 | F.message = function f(msg){ |
| 60 | const args = Array.prototype.slice.call(arguments,0); |
| 61 | const tgt = f.targetElement; |
| 62 | if(args.length) args.unshift( |
| 63 | localTimeString()+':' |
| 64 | //timestring(),'UTC:' |
| @@ -84,26 +88,25 @@ | |
| 84 | F.message.targetElement.addEventListener( |
| 85 | 'dblclick', ()=>F.message(), false |
| 86 | ); |
| 87 | } |
| 88 | /* |
| 89 | ** By default fossil.error() sends its first argument to |
| 90 | ** console.error(). If fossil.message.targetElement (yes, |
| 91 | ** fossil.message) is set, it adds the 'error' CSS class to |
| 92 | ** that element and sets its content as defined for message(). |
| 93 | ** |
| 94 | ** Returns this object. |
| 95 | */ |
| 96 | F.error = function f(msg){ |
| 97 | const args = Array.prototype.slice.call(arguments,0); |
| 98 | const tgt = F.message.targetElement; |
| 99 | args.unshift(timestring(),'UTC:'); |
| 100 | if(tgt){ |
| 101 | tgt.classList.add('error'); |
| 102 | tgt.innerText = args.join(' '); |
| 103 | } |
| 104 | else{ |
| 105 | args.unshift('Fossil error:'); |
| 106 | console.error.apply(console,args); |
| 107 | } |
| 108 | return this; |
| 109 | }; |
| 110 |
| --- src/fossil.bootstrap.js | |
| +++ src/fossil.bootstrap.js | |
| @@ -17,10 +17,14 @@ | |
| 17 | initialized that object. |
| 18 | */ |
| 19 | |
| 20 | const F = global.fossil; |
| 21 | |
| 22 | /** Creates a prototype-less plain object with properties derived |
| 23 | from all of its object-type arguments. */ |
| 24 | F.nu = (...obj)=>Object.assign(Object.create(null),...obj); |
| 25 | |
| 26 | /** |
| 27 | Returns the current time in something approximating |
| 28 | ISO-8601 format. |
| 29 | */ |
| 30 | const timestring = function f(){ |
| @@ -54,11 +58,11 @@ | |
| 58 | ** removed from the object. Pass it a falsy value to clear the target |
| 59 | ** element. |
| 60 | ** |
| 61 | ** Returns this object. |
| 62 | */ |
| 63 | F.message = function f(){ |
| 64 | const args = Array.prototype.slice.call(arguments,0); |
| 65 | const tgt = f.targetElement; |
| 66 | if(args.length) args.unshift( |
| 67 | localTimeString()+':' |
| 68 | //timestring(),'UTC:' |
| @@ -84,26 +88,25 @@ | |
| 88 | F.message.targetElement.addEventListener( |
| 89 | 'dblclick', ()=>F.message(), false |
| 90 | ); |
| 91 | } |
| 92 | /* |
| 93 | ** By default fossil.error() sends all arguments to |
| 94 | ** console.error(). If fossil.message.targetElement (yes, |
| 95 | ** fossil.message) is set, it adds the 'error' CSS class to |
| 96 | ** that element and sets its content as defined for message(). |
| 97 | ** |
| 98 | ** Returns this object. |
| 99 | */ |
| 100 | F.error = function f(){ |
| 101 | const args = Array.prototype.slice.call(arguments,0); |
| 102 | const tgt = F.message.targetElement; |
| 103 | args.unshift(timestring(),'UTC:'); |
| 104 | if(tgt){ |
| 105 | tgt.classList.add('error'); |
| 106 | tgt.innerText = args.join(' '); |
| 107 | }else{ |
| 108 | args.unshift('Fossil error:'); |
| 109 | console.error.apply(console,args); |
| 110 | } |
| 111 | return this; |
| 112 | }; |
| 113 |
+4
| --- src/fossil.dom.js | ||
| +++ src/fossil.dom.js | ||
| @@ -80,10 +80,14 @@ | ||
| 80 | 80 | Returns a LABEL element. If passed an argument, |
| 81 | 81 | it must be an id or an HTMLElement with an id, |
| 82 | 82 | and that id is set as the 'for' attribute of the |
| 83 | 83 | label. If passed 2 arguments, the 2nd is text or |
| 84 | 84 | a DOM element to append to the label. |
| 85 | + | |
| 86 | + 2026-06: this is a goofy interface. Generally simpler that | |
| 87 | + dealing with IDs is to embed the target control within the label | |
| 88 | + element. | |
| 85 | 89 | */ |
| 86 | 90 | dom.label = function(forElem, text){ |
| 87 | 91 | const rc = document.createElement('label'); |
| 88 | 92 | if(forElem){ |
| 89 | 93 | if(forElem instanceof HTMLElement){ |
| 90 | 94 |
| --- src/fossil.dom.js | |
| +++ src/fossil.dom.js | |
| @@ -80,10 +80,14 @@ | |
| 80 | Returns a LABEL element. If passed an argument, |
| 81 | it must be an id or an HTMLElement with an id, |
| 82 | and that id is set as the 'for' attribute of the |
| 83 | label. If passed 2 arguments, the 2nd is text or |
| 84 | a DOM element to append to the label. |
| 85 | */ |
| 86 | dom.label = function(forElem, text){ |
| 87 | const rc = document.createElement('label'); |
| 88 | if(forElem){ |
| 89 | if(forElem instanceof HTMLElement){ |
| 90 |
| --- src/fossil.dom.js | |
| +++ src/fossil.dom.js | |
| @@ -80,10 +80,14 @@ | |
| 80 | Returns a LABEL element. If passed an argument, |
| 81 | it must be an id or an HTMLElement with an id, |
| 82 | and that id is set as the 'for' attribute of the |
| 83 | label. If passed 2 arguments, the 2nd is text or |
| 84 | a DOM element to append to the label. |
| 85 | |
| 86 | 2026-06: this is a goofy interface. Generally simpler that |
| 87 | dealing with IDs is to embed the target control within the label |
| 88 | element. |
| 89 | */ |
| 90 | dom.label = function(forElem, text){ |
| 91 | const rc = document.createElement('label'); |
| 92 | if(forElem){ |
| 93 | if(forElem instanceof HTMLElement){ |
| 94 |
+1295
-35
| --- src/fossil.page.forumpost.js | ||
| +++ src/fossil.page.forumpost.js | ||
| @@ -1,24 +1,852 @@ | ||
| 1 | +/** | |
| 2 | + Code for the forum family of pages. Requires fossil.X where X is | |
| 3 | + (copybutton, pikchr, confirmer, attach, tabs, storage). | |
| 4 | +*/ | |
| 1 | 5 | (function(F/*the fossil object*/){ |
| 2 | 6 | "use strict"; |
| 3 | 7 | /* JS code for /forumpost and friends. Requires fossil.dom |
| 4 | 8 | and can optionally use fossil.pikchr. */ |
| 5 | 9 | const P = F.page, D = F.dom; |
| 6 | 10 | |
| 11 | + let idCounter = 0; | |
| 12 | + | |
| 13 | + /* | |
| 14 | + The problem: when previewing the bottom-most post of a thread, the | |
| 15 | + preview widget's size changes cause the page to scroll | |
| 16 | + unpredictably as the bottom boundary of the page moves. A weird | |
| 17 | + workaround (not invented here) is to add dummy blank padding to | |
| 18 | + the page to allow the preview widget to grow and shrink without | |
| 19 | + (usually) scrolling, but whether it does so really depends on its | |
| 20 | + size. | |
| 21 | + | |
| 22 | + We could maybe get the same effect by adding this size as | |
| 23 | + padding-bottom to document.body instead of as a new element. | |
| 24 | + */ | |
| 25 | + const dummyPadding = D.div(); | |
| 26 | + dummyPadding.style.height = '75em'; | |
| 27 | + /* Keep track of ForumPostEditor instances so we can remove this | |
| 28 | + padding when none are active. */ | |
| 29 | + dummyPadding.refs = new Set(); | |
| 30 | + F.dummyPadding = dummyPadding /* only for debugging */; | |
| 31 | + | |
| 32 | + /** | |
| 33 | + A forum post editor widget for new posts and responses. | |
| 34 | + */ | |
| 35 | + class ForumPostEditor { | |
| 36 | + /* Options */ | |
| 37 | + #opt; | |
| 38 | + /* Dom elements */ | |
| 39 | + #e; | |
| 40 | + /* F.Attacher instance */ | |
| 41 | + #att; | |
| 42 | + /* Is waiting on a pending remote response. */ | |
| 43 | + #isWaiting = false; | |
| 44 | + /* F.TabManager */ | |
| 45 | + #tabs; | |
| 46 | + /* Elements to disable while an XHR is pending. */ | |
| 47 | + #toDisable = []; | |
| 48 | + /* DOM element of the current active tab. */ | |
| 49 | + #activeTab; | |
| 50 | + /* Extra input[type=hidden] fields imported from fossil's | |
| 51 | + static page generation. */ | |
| 52 | + #extraFields; | |
| 53 | + /* Persistent draft message object. */ | |
| 54 | + #draft; | |
| 55 | + | |
| 56 | + /** | |
| 57 | + Options: | |
| 58 | + | |
| 59 | + opt.draftKey[string=undefined]: if set then this object's state | |
| 60 | + will be stored in fossil.storage when the relevant input fields | |
| 61 | + lose focus. If old state is found, the form is pre-populated | |
| 62 | + from it. The state is cleared on a discard() or successful | |
| 63 | + submit. | |
| 64 | + | |
| 65 | + opt.ondiscard[=function]: if set, a Discard button is added | |
| 66 | + which, when activated, clears the current draft and removes | |
| 67 | + this object's widget from the DOM. After doing so, | |
| 68 | + opt.ondiscard() is called and passed this object. Exceptions | |
| 69 | + thrown by ondiscard() are ignored but may be logged. | |
| 70 | + | |
| 71 | + opt.onsubmit[=function]: if set, this function is called | |
| 72 | + immediately after the post has been successfully saved, and | |
| 73 | + passed this object and a JSON-format response object from the | |
| 74 | + save request. It is generally then up to the caller to close() | |
| 75 | + this object and/or redirect to /forumpost/${arguments[1].uuid}. | |
| 76 | + | |
| 77 | + opt.onclose[=function]: like opt.onsubmit, this function is | |
| 78 | + called when this.close() is called, and passed no arguments. | |
| 79 | + onclose() is called before the widget is removed from the dom | |
| 80 | + and _does not_ fire if it is not in the DOM. | |
| 81 | + | |
| 82 | + opt.hiddenFields: an optional list of input elements to | |
| 83 | + incorporate into the form for requests which request the | |
| 84 | + preview or save the post. | |
| 85 | + | |
| 86 | + opt.inReplyTo=uuid: if this is a response to a post, this | |
| 87 | + is the full forum post uuid of the being-replied-to post. | |
| 88 | + | |
| 89 | + opt.edit=artifactObject: if this is an edit of an existing | |
| 90 | + post, this is the full JSON-format artifact of the forum post | |
| 91 | + the being-edited post, as returned by /ajax/artifact.json. | |
| 92 | + | |
| 93 | + opt.status: optional current status tag value for opt.edit, | |
| 94 | + if known. This is used for pre-selecting a status value. | |
| 95 | + | |
| 96 | + opt.hideStash[bool=false]: if true, the "Stash" button does not | |
| 97 | + get added. Intended for use with /forumnew. | |
| 98 | + */ | |
| 99 | + constructor(opt){ | |
| 100 | + opt = this.#opt = F.nu({ | |
| 101 | + draftKey: undefined, | |
| 102 | + hideStash: false | |
| 103 | + }, opt); | |
| 104 | + opt.isNewThread = !opt.inReplyTo && !opt.edit; | |
| 105 | + if( opt.draftKey ){ | |
| 106 | + this.#draft = F.nu(F.storage.getJSON(opt.draftKey, {})); | |
| 107 | + } | |
| 108 | + const e = this.#e = F.nu({ | |
| 109 | + mimetype: F.nu(), | |
| 110 | + button: F.nu() | |
| 111 | + }); | |
| 112 | + //console.debug("Setting up FPE opt =",opt); | |
| 113 | + const wrapper = e.widget = D.addClass(D.div(), 'ForumPostEditor'); | |
| 114 | + D.clearElement(wrapper); | |
| 115 | + | |
| 116 | + if( !opt.inReplyTo ){ | |
| 117 | + /* Title... */ | |
| 118 | + e.titleBar = D.addClass(D.div(),'titlebar'); | |
| 119 | + e.title = D.attr( | |
| 120 | + D.addClass(D.input('text'), 'title'), | |
| 121 | + 'placeholder', | |
| 122 | + 'Thread title (required)' | |
| 123 | + ); | |
| 124 | + e.title.setAttribute('maxlength', 125); | |
| 125 | + e.titleBar.append( | |
| 126 | + D.append(D.span(), "Title:"), | |
| 127 | + e.title | |
| 128 | + ); | |
| 129 | + if( this.#draft ){ | |
| 130 | + e.title.addEventListener('blur', ()=>{ | |
| 131 | + this.#draft.title = e.title.value; | |
| 132 | + this.#storeDraft(); | |
| 133 | + }); | |
| 134 | + e.title.value = this.#draft.title || opt.edit?.H || ''; | |
| 135 | + }else if( opt.edit?.H ){ | |
| 136 | + e.title.value = opt.edit.H; | |
| 137 | + } | |
| 138 | + wrapper.append(e.titleBar); | |
| 139 | + } | |
| 140 | + | |
| 141 | + { /* Mimetype... */ | |
| 142 | + e.mimetype.wrapper = D.addClass(D.div(), 'mimetype-wrapper'); | |
| 143 | + const sel = e.mimetype.select = D.addClass(D.select(), 'mimetype-select'); | |
| 144 | + sel.setAttribute('title', 'Markup format for this post.'); | |
| 145 | + this.#toDisable.push(sel); | |
| 146 | + let i = 0; | |
| 147 | + D.option(sel, '', '- Markup format -').disabled = true; | |
| 148 | + for(const [k,v] of Object.entries({ | |
| 149 | + 'text/x-markdown': 'Markdown', | |
| 150 | + 'text/x-fossil-wiki': 'Fossil Wiki', | |
| 151 | + 'text/plain': 'Plain text' | |
| 152 | + })) { | |
| 153 | + D.option(sel, k, v); | |
| 154 | + } | |
| 155 | + sel.value = opt.mimetype | |
| 156 | + || this.#draft?.mimetype | |
| 157 | + || F.storage.get('forum-mimetype', sel.options[1].value); | |
| 158 | + sel.addEventListener('change',ev=>{ | |
| 159 | + if( this.#draft && this.#draft.mimetype!==ev.target.value ){ | |
| 160 | + this.#draft.mimetype = ev.target.value; | |
| 161 | + this.#storeDraft(); | |
| 162 | + } | |
| 163 | + F.storage.set('forum-mimetype', ev.target.value); | |
| 164 | + }); | |
| 165 | + e.mimetype.wrapper.append(sel); | |
| 166 | + } | |
| 167 | + | |
| 168 | + e.buttons = D.addClass(D.div(), 'buttons'); | |
| 169 | + { /* Preview/submit buttons... */ | |
| 170 | + e.button.preview = D.attr( | |
| 171 | + D.button("Preview", e=>this.#preview()), | |
| 172 | + 'title', | |
| 173 | + 'Preview your edits.' | |
| 174 | + ); | |
| 175 | + e.button.submit = D.attr( | |
| 176 | + D.button("Submit"), | |
| 177 | + 'title', | |
| 178 | + 'Save any edits to the server. Not permitted until Preview has been used.' | |
| 179 | + ); | |
| 180 | + if( this.#draft && !opt.hideStash ){ | |
| 181 | + e.button.stash = D.attr( | |
| 182 | + D.button( | |
| 183 | + "Stash", e=>this.close() | |
| 184 | + /* This could be called Close, but that would semantically | |
| 185 | + collide with the Close [this post] button. All "Stash" | |
| 186 | + does is close the widget. */ | |
| 187 | + ), | |
| 188 | + 'title', "Close this editor and stash any edits locally." | |
| 189 | + ); | |
| 190 | + } | |
| 191 | + if( opt.ondiscard instanceof Function ){ | |
| 192 | + e.button.discard = D.attr( | |
| 193 | + D.button('Discard'), | |
| 194 | + 'title', | |
| 195 | + 'Close the editor and discard all local edits.' | |
| 196 | + ); | |
| 197 | + } | |
| 198 | + if( 1 ){ | |
| 199 | + F.confirmer(e.button.submit, { | |
| 200 | + confirmText: "Confirm submit...", | |
| 201 | + onconfirm: ()=>this.#submit() | |
| 202 | + }); | |
| 203 | + if( e.button.discard ){ | |
| 204 | + F.confirmer(e.button.discard, { | |
| 205 | + confirmText: "Really discard?", | |
| 206 | + onconfirm: ()=>this.discard() | |
| 207 | + }); | |
| 208 | + } | |
| 209 | + }else{ | |
| 210 | + e.button.submit.addEventListener('click', ()=>this.#submit()); | |
| 211 | + if( e.button.discard ){ | |
| 212 | + e.button.submit.addEventListener('click', ()=>this.discard()); | |
| 213 | + } | |
| 214 | + } | |
| 215 | + e.button.submit.setAttribute('disabled', ''); | |
| 216 | + wrapper.append(e.buttons); | |
| 217 | + | |
| 218 | + e.error = D.addClass(D.div(), 'error', 'hidden'); | |
| 219 | + wrapper.append(e.error); | |
| 220 | + e.error.addEventListener('dblclick',()=>this.reportError()); | |
| 221 | + } | |
| 222 | + | |
| 223 | + const idPrefix = 'FormPostEditor'+(++idCounter)/* TabManager requires IDs */; | |
| 224 | + { /* Main tabs... */ | |
| 225 | + e.tabs = D.attr( | |
| 226 | + D.addClass(D.div(), 'tab-container'), | |
| 227 | + 'id', idPrefix+'-tabs' | |
| 228 | + ); | |
| 229 | + this.#tabs = new F.TabManager(e.tabs); | |
| 230 | + this.#tabs.addEventListener('before-switch-to', (ev)=>{ | |
| 231 | + //console.debug("Switching to tab",ev.detail); | |
| 232 | + switch( (this.#activeTab = ev.detail) ){ | |
| 233 | + case e.preview: | |
| 234 | + this.#e.button.preview.click(); | |
| 235 | + break; | |
| 236 | + case e.help: | |
| 237 | + if( e.help.$needsInit ){ | |
| 238 | + delete e.help.$needsInit; | |
| 239 | + this.#initHelpTab(); | |
| 240 | + } | |
| 241 | + break; | |
| 242 | + case e.tabAttach: | |
| 243 | + if( !this.#att ) this.#initAttacherTab(); | |
| 244 | + break; | |
| 245 | + } | |
| 246 | + }); | |
| 247 | + wrapper.append( e.tabs ); | |
| 248 | + | |
| 249 | + e.tabEdit = D.div(); | |
| 250 | + e.tabEdit.classList.add('editor-wrapper'); | |
| 251 | + e.editor = D.attr( | |
| 252 | + D.addClass(D.textarea(), 'editor'), | |
| 253 | + 'placeholder', | |
| 254 | + 'Your message to other forum-goers...' | |
| 255 | + ); | |
| 256 | + e.tabEdit.append(e.editor); | |
| 257 | + e.tabEdit.dataset.tabLabel = (opt.edit || !opt.inReplyTo) | |
| 258 | + ? 'Edit' : 'Reply'; | |
| 259 | + this.#tabs.addTab( e.tabEdit ); | |
| 260 | + this.#tabs.switchToTab( e.tabEdit ); | |
| 261 | + if( this.#draft ){ | |
| 262 | + this.editorContent = this.#draft.content || opt.edit?.W || ''; | |
| 263 | + e.editor.addEventListener( | |
| 264 | + 'blur', ()=>{ | |
| 265 | + this.#draft.content = this.editorContent; | |
| 266 | + this.#storeDraft(); | |
| 267 | + } | |
| 268 | + ); | |
| 269 | + }else if( opt.edit?.W ){ | |
| 270 | + this.editorContent = opt.artifact.W; | |
| 271 | + } | |
| 272 | + e.preview = D.addClass(D.div(), 'preview'); | |
| 273 | + e.preview.dataset.tabLabel = 'Preview'; | |
| 274 | + this.#toDisable.push(e.button.preview); | |
| 275 | + this.#tabs.addTab( e.preview ); | |
| 276 | + } | |
| 277 | + | |
| 278 | + if( F.user.enableDebug ){ | |
| 279 | + e.debug = D.addClass(D.div(), 'debug'); | |
| 280 | + e.debug.dataset.tabLabel = 'Debug'; | |
| 281 | + e.debug.setAttribute('id', idPrefix+'-debug'); | |
| 282 | + for(const [k,v] of Object.entries({ | |
| 283 | + dryrun: 'Dry run', | |
| 284 | + domod: 'Require moderation approval', | |
| 285 | + //showqp: 'Show query parameters', | |
| 286 | + fpsilent: 'Do not send notification emails' | |
| 287 | + })){ | |
| 288 | + const lbl = D.label(false, v); | |
| 289 | + lbl.prepend(D.checkbox(k)); | |
| 290 | + e.debug.append(lbl); | |
| 291 | + } | |
| 292 | + this.#tabs.addTab(e.debug); | |
| 293 | + } | |
| 294 | + e.buttons.append(e.mimetype.wrapper); | |
| 295 | + | |
| 296 | + if( opt.edit | |
| 297 | + && !opt.inReplyTo | |
| 298 | + && F.config.forumStatuses?.length>0 ){ | |
| 299 | + const sel = e.status = D.select(); | |
| 300 | + sel.setAttribute('title', 'The status tag value for this post.'); | |
| 301 | + D.option(sel, "", "- Status -").disabled = true; | |
| 302 | + for( const status of F.config.forumStatuses ){ | |
| 303 | + D.option(sel, status.value, status.label); | |
| 304 | + } | |
| 305 | + e.buttons.append(sel); | |
| 306 | + if( opt.status ){ | |
| 307 | + sel.value = opt.status; | |
| 308 | + }else if( this.#draft ){ | |
| 309 | + if( this.#draft.status ){ | |
| 310 | + sel.value = this.#draft.status; | |
| 311 | + }else{ | |
| 312 | + this.#draft.status = sel.value = F.config.forumStatuses[0].value; | |
| 313 | + } | |
| 314 | + sel.addEventListener('change',ev=>{ | |
| 315 | + const v = sel.value; | |
| 316 | + if( this.#draft.status !== v ){ | |
| 317 | + this.#draft.status = v; | |
| 318 | + this.#storeDraft(); | |
| 319 | + } | |
| 320 | + }); | |
| 321 | + } | |
| 322 | + }/*e.status*/ | |
| 323 | + | |
| 324 | + if( F.user.mayAttachForum ){ | |
| 325 | + //e.buttons.append( e.button.addAttach = this.#att.takeAddButton() ); | |
| 326 | + e.tabAttach = D.div(); | |
| 327 | + e.tabAttach.setAttribute('id', idPrefix+'-attach'); | |
| 328 | + e.tabAttach.dataset.tabLabel = 'Attachments'; | |
| 329 | + this.#tabs.addTab(e.tabAttach); | |
| 330 | + /* Reminder: we don't currently have a way to disable/enable | |
| 331 | + an Attacher's controls during ajax traffic. */ | |
| 332 | + } | |
| 333 | + e.buttons.append(e.button.preview, e.button.submit); | |
| 334 | + if( e.button.stash ){ | |
| 335 | + e.buttons.append(e.button.stash); | |
| 336 | + this.#toDisable.push(e.button.stash); | |
| 337 | + } | |
| 338 | + if( e.button.discard ){ | |
| 339 | + e.buttons.append(e.button.discard); | |
| 340 | + this.#toDisable.push(e.button.discard); | |
| 341 | + } | |
| 342 | + | |
| 343 | + e.help = D.attr(D.div(), 'id', idPrefix+'-help'); | |
| 344 | + e.help.$needsInit = true; | |
| 345 | + e.help.dataset.tabLabel = 'Help'; | |
| 346 | + this.#tabs.addTab(e.help); | |
| 347 | + | |
| 348 | + if( opt.hiddenFields ){ | |
| 349 | + this.addHiddenFields( opt.hiddenFields ); | |
| 350 | + delete opt.hiddenFields; | |
| 351 | + } | |
| 352 | + | |
| 353 | + { /* Shift-enter pieces... */ | |
| 354 | + const eCb = D.checkbox(1); | |
| 355 | + const eLbl = D.label(); | |
| 356 | + const eHelp = D.append( | |
| 357 | + D.span(), [ | |
| 358 | + 'When checked, shift-enter will toggle between preview ', | |
| 359 | + 'and edit modes, which is generally useful but some ', | |
| 360 | + 'software keyboards misinteract with it. If the preview ', | |
| 361 | + 'starts when tapping Enter, turn this setting off.' | |
| 362 | + ].join('') | |
| 363 | + ); | |
| 364 | + eCb.checked = F.storage.getBool( | |
| 365 | + 'edit-shift-enter-preview', | |
| 366 | + true | |
| 367 | + /* Maintenance reminder: this setting is shared across | |
| 368 | + several apps, like /chat, /wikiedit, and /fileedit. */ | |
| 369 | + ); | |
| 370 | + eCb.addEventListener('change', (ev)=>{ | |
| 371 | + F.storage.set('edit-shift-enter-preview', eCb.checked); | |
| 372 | + }); | |
| 373 | + F.helpButtonlets.setup(eHelp); | |
| 374 | + eLbl.append("Shift-enter toggles preview?", eCb, eHelp); | |
| 375 | + e.tabEdit.append(eLbl); | |
| 376 | + const isShiftEnter = (ev)=>eCb.checked && ev.shiftKey && 13===ev.keyCode; | |
| 377 | + e.editor.addEventListener('keydown',(ev)=>{ | |
| 378 | + /** | |
| 379 | + If eCb.checked is true, a keyboard combo of shift-enter | |
| 380 | + (from the editor) toggles between preview and edit modes. | |
| 381 | + This is normally desired but at least one software | |
| 382 | + keyboard is known to misinteract with this, treating an | |
| 383 | + Enter after automatically-capitalized letters as a | |
| 384 | + shift-enter: | |
| 385 | + | |
| 386 | + https://fossil-scm.org/forum/forumpost/dbd5b68366147ce8 | |
| 387 | + */ | |
| 388 | + if(!isShiftEnter(ev)) return; | |
| 389 | + ev.preventDefault(); | |
| 390 | + ev.stopPropagation(); | |
| 391 | + e.editor.blur(/*force draft update if needed*/); | |
| 392 | + this.#tabs.switchToTab(e.preview); | |
| 393 | + }, false); | |
| 394 | + // If we're in the preview tab, have ctrl-enter switch back to the editor. | |
| 395 | + document.body.addEventListener('keydown',(ev)=>{ | |
| 396 | + if(!isShiftEnter(ev)) return; | |
| 397 | + if(this.#activeTab !== e.tabEdit){ | |
| 398 | + ev.preventDefault(); | |
| 399 | + ev.stopPropagation(); | |
| 400 | + this.#tabs.switchToTab(e.tabEdit); | |
| 401 | + e.editor.focus(/*slow as molasses for long docs, as focus() | |
| 402 | + forces a document reflow. */); | |
| 403 | + return false; | |
| 404 | + } | |
| 405 | + }, true); | |
| 406 | + }/*shift-enter preview bits*/ | |
| 407 | + | |
| 408 | + if(0){ /* Needs to be optional */ | |
| 409 | + const elemsToToggle = document.body.querySelectorAll( | |
| 410 | + ':scope > header, :scope > nav' | |
| 411 | + ); | |
| 412 | + e.button.toggleHeader = | |
| 413 | + D.button('Toggle header', e=>{ | |
| 414 | + for(const et of elemsToToggle){ | |
| 415 | + et.classList.toggle('hidden'); | |
| 416 | + } | |
| 417 | + }); | |
| 418 | + e.buttons.append(e.button.toggleHeader); | |
| 419 | + } | |
| 420 | + | |
| 421 | + { | |
| 422 | + const eLbl = D.label(false, "Posting as "+F.user.name) | |
| 423 | + eLbl.classList.add('logged-in-as'); | |
| 424 | + e.buttons.append(eLbl); | |
| 425 | + } | |
| 426 | + | |
| 427 | + }/*constructor*/ | |
| 428 | + | |
| 429 | + /* | |
| 430 | + ** Removes this object from the DOM. It has no side effects if | |
| 431 | + ** it's not in the DOM. | |
| 432 | + */ | |
| 433 | + close(){ | |
| 434 | + const e = this.#e.widget; | |
| 435 | + if( e?.parentNode ){ | |
| 436 | + if( this.#opt.onclose instanceof Function ){ | |
| 437 | + try{this.#opt.onclose();} | |
| 438 | + catch(e){ | |
| 439 | + console.error("ForumPostEditor.onclose() threw:",e); | |
| 440 | + } | |
| 441 | + } | |
| 442 | + //console.debug("FPE discarding", this); | |
| 443 | + e.classList.add('animate-exit'); | |
| 444 | + e.addEventListener('animationend', ()=>e.remove(), {once: true}); | |
| 445 | + dummyPadding.refs.delete(this); | |
| 446 | + if( 0===dummyPadding.refs.size ){ | |
| 447 | + dummyPadding.remove(); | |
| 448 | + } | |
| 449 | + } | |
| 450 | + } | |
| 451 | + | |
| 452 | + /* | |
| 453 | + ** Discards any draft edits then calls close(). If an ondiscard | |
| 454 | + ** callback was provided to the constructor then it is called | |
| 455 | + ** before the drafts are cleared and any exceptions it throws are | |
| 456 | + ** ignored (but may be logged). | |
| 457 | + */ | |
| 458 | + discard(){ | |
| 459 | + if( this.#opt.ondiscard instanceof Function ){ | |
| 460 | + try{this.#opt.ondiscard(this);} | |
| 461 | + catch(e){ | |
| 462 | + console.error("ForumPostEditor.ondiscard() threw:",e); | |
| 463 | + } | |
| 464 | + } | |
| 465 | + this.#clearDraft(); | |
| 466 | + this.close(); | |
| 467 | + } | |
| 468 | + | |
| 469 | + /** This widget's top-most DOM element. */ | |
| 470 | + get widget(){ | |
| 471 | + if( !dummyPadding.parentElement ){ | |
| 472 | + document.body.append(dummyPadding); | |
| 473 | + } | |
| 474 | + dummyPadding.refs.add(this); | |
| 475 | + return this.#e.widget; | |
| 476 | + } | |
| 477 | + | |
| 478 | + get editorContent(){ | |
| 479 | + /* We wrap access to the editor's contents in a getter/setter so | |
| 480 | + that we can eventually add optional use of a contenteditable | |
| 481 | + edit field, as those are generally more comfortable. The code | |
| 482 | + for that is in fossil.page.chat.js. */ | |
| 483 | + return this.#e.editor.value; | |
| 484 | + } | |
| 485 | + | |
| 486 | + set editorContent(v){ | |
| 487 | + this.#e.editor.value = v; | |
| 488 | + } | |
| 489 | + | |
| 490 | + /** | |
| 491 | + Reports an error by appending each argument to the error widget | |
| 492 | + and unhiding it. If passed no arugments, it clears and hides | |
| 493 | + the error widget. | |
| 494 | + */ | |
| 495 | + reportError(...msg){ | |
| 496 | + const e = this.#e.error; | |
| 497 | + D.clearElement(e); | |
| 498 | + if( msg.length ){ | |
| 499 | + console.error('ForumPostEditor:',...msg); | |
| 500 | + e.classList.remove('hidden'); | |
| 501 | + e.append( | |
| 502 | + ...msg, D.br(), | |
| 503 | + D.button("Clear", ()=>this.reportError()) | |
| 504 | + /* Looks horrid in the Blitz skin */ | |
| 505 | + ); | |
| 506 | + }else{ | |
| 507 | + e.classList.add('hidden'); | |
| 508 | + } | |
| 509 | + } | |
| 510 | + | |
| 511 | + /** | |
| 512 | + Adds a list of input[type=hidden] form fields to this object, | |
| 513 | + imported from the server-generated HTML. This is used for | |
| 514 | + collecting, e.g., the CSRF token and an initial page title. | |
| 515 | + */ | |
| 516 | + addHiddenFields(list){ | |
| 517 | + this.#extraFields ??= []; | |
| 518 | + for( const f of list ){ | |
| 519 | + if( !f ) continue; | |
| 520 | + if( 'title'===f.name && this.#e.title ){ | |
| 521 | + if( f.value && this.#opt.isNewThread && !this.#e.title.value ){ | |
| 522 | + this.#e.title.value = f.value; | |
| 523 | + } | |
| 524 | + }else{ | |
| 525 | + this.#extraFields.push(f); | |
| 526 | + } | |
| 527 | + } | |
| 528 | + } | |
| 529 | + | |
| 530 | + get mimetype(){ | |
| 531 | + return this.#e.mimetype.select.value; | |
| 532 | + } | |
| 533 | + | |
| 534 | + get title(){ | |
| 535 | + return this.#e.title?.value || this.#opt.edit?.H; | |
| 536 | + } | |
| 537 | + | |
| 538 | + #initHelpTab(){ | |
| 539 | + const eh = this.#e.help; | |
| 540 | + const list = D.ul(); | |
| 541 | + D.append( | |
| 542 | + D.li(list), | |
| 543 | + D.attr(D.a(F.repoUrl('markup_help'), 'Markup styles'), | |
| 544 | + 'target', '_new') | |
| 545 | + ); | |
| 546 | + D.append( | |
| 547 | + D.li(list), | |
| 548 | + "WARNING: draft edits are keyed on the ID of the message they ", | |
| 549 | + "are editing or responding to. Attempting to edit or reply to ", | |
| 550 | + "the same post from multiple tabs will cause the most-recently-edited ", | |
| 551 | + "one to overwrite the draft slot for that post. In browsers which support ", | |
| 552 | + "Web Locks, a second attempt to edit or reply to a post will be blocked ", | |
| 553 | + "and an error will be shown explaining the problem." | |
| 554 | + ); | |
| 555 | + if( this.#e.status ){ | |
| 556 | + D.append( | |
| 557 | + D.li(list), | |
| 558 | + "Tip: changing just the status in the editor will change only that, ", | |
| 559 | + "not a whole new (but unedited) copy of the post." | |
| 560 | + ); | |
| 561 | + } | |
| 562 | + eh.append(list); | |
| 563 | + } | |
| 564 | + | |
| 565 | + #initAttacherTab(){ | |
| 566 | + this.#att = new F.Attacher({ | |
| 567 | + reverse: true | |
| 568 | + }); | |
| 569 | + if( this.#opt.edit ){ | |
| 570 | + const eNote = D.append( | |
| 571 | + D.div(), | |
| 572 | + "Tip: attachments can be added to posts without editing them ", | |
| 573 | + "by visiting ", | |
| 574 | + D.attr( | |
| 575 | + D.a(F.repoUrl('attachadd?target='+this.#opt.edit.uuid), '/attachadd'), | |
| 576 | + 'target', | |
| 577 | + '_new' | |
| 578 | + ), | |
| 579 | + ".", | |
| 580 | + ); | |
| 581 | + this.#e.tabAttach.append(eNote); | |
| 582 | + } | |
| 583 | + this.#e.tabAttach.append(this.#att.widget); | |
| 584 | + } | |
| 585 | + | |
| 586 | + #newFormData(addThisContent){ | |
| 587 | + const fd = new FormData; | |
| 588 | + for(const f of this.#extraFields){ | |
| 589 | + fd.append(f.name, f.value); | |
| 590 | + } | |
| 591 | + let v; | |
| 592 | + if( this.#opt.inReplyTo ){ | |
| 593 | + fd.append( 'firt', this.#opt.inReplyTo ); | |
| 594 | + }else if( (v = (this.#e.title?.value?.trim?.() || this.#opt.edit?.H)) ){ | |
| 595 | + fd.append('title', v); | |
| 596 | + } | |
| 597 | + fd.append('mimetype', this.mimetype); | |
| 598 | + fd.append('content', addThisContent || this.editorContent.trim()); | |
| 599 | + return fd; | |
| 600 | + } | |
| 601 | + | |
| 602 | + async #fetchPreview(content){ | |
| 603 | + /* TODO: fetch preview */ | |
| 604 | + const e = this.#e; | |
| 605 | + const fd = /*no: this.#newFormData(content); */ | |
| 606 | + new FormData; | |
| 607 | + let ext; | |
| 608 | + switch(this.mimetype){ | |
| 609 | + case 'text/x-markdown': ext = 'md'; break; | |
| 610 | + case 'text/x-fossil-wiki': ext = 'wiki'; break; | |
| 611 | + default: ext = 'txt'; break; | |
| 612 | + } | |
| 613 | + fd.append('filename', 'x.'+ext/*for mimetype determination*/); | |
| 614 | + fd.append('content', this.editorContent.trim()); | |
| 615 | + return window | |
| 616 | + .fetch(F.repoUrl('ajax/preview-text'),{ | |
| 617 | + method: 'POST', | |
| 618 | + body: fd | |
| 619 | + }) | |
| 620 | + .then(r=>r.text()) | |
| 621 | + .then(t=>{ | |
| 622 | + if( /^\{.*}$/.test(t) ){ | |
| 623 | + const o = JSON.parse(t); | |
| 624 | + throw new Error(o.error); | |
| 625 | + } | |
| 626 | + return t; | |
| 627 | + }); | |
| 628 | + } | |
| 629 | + | |
| 630 | + #setPreviewContent(rawHtml){ | |
| 631 | + /** | |
| 632 | + Append the new content then remove the old, to help reduce | |
| 633 | + jumping-around of the UI if the preview is cleared then | |
| 634 | + repopulated. | |
| 635 | + */ | |
| 636 | + const preview = this.#e.preview; | |
| 637 | + const childs = [...preview.childNodes]; | |
| 638 | + D.parseHtml(preview, rawHtml); | |
| 639 | + D.remove(childs); | |
| 640 | + //preview.style.removeProperty('height'); | |
| 641 | + if(F.pikchr && 'text/x-markdown'===this.mimetype){ | |
| 642 | + F.pikchr.addSrcView( | |
| 643 | + preview.querySelectorAll('svg.pikchr') | |
| 644 | + ); | |
| 645 | + } | |
| 646 | + } | |
| 647 | + | |
| 648 | + async #preview(){ | |
| 649 | + if( this.#isWaiting ) return; | |
| 650 | + const e = this.#e; | |
| 651 | + if( e.preview !== this.#activeTab ){ | |
| 652 | + this.#tabs.switchToTab(e.preview); | |
| 653 | + /* Will recurse into here */ | |
| 654 | + return; | |
| 655 | + } | |
| 656 | + const content = this.editorContent.trim(); | |
| 657 | + //console.debug("content to preview", content); | |
| 658 | + if( !content ){ | |
| 659 | + return; | |
| 660 | + } | |
| 661 | + if( 0 | |
| 662 | + && !e.preview.firstElementChild ){ | |
| 663 | + /* On an initial first preview, inherit the editor's height to | |
| 664 | + reduce jumping-around of the UI. */ | |
| 665 | + if( 0 /* does not work: height of the editor is "auto" */ ){ | |
| 666 | + const c = window.getComputedStyle(e.editor/*tabEdit*/); | |
| 667 | + e.preview.style.height = c.height; | |
| 668 | + }else{ | |
| 669 | + e.preview.style.height = '20em'; | |
| 670 | + } | |
| 671 | + } | |
| 672 | + this.#isWaiting = true; | |
| 673 | + D.disable(this.#toDisable, e.button.submit); | |
| 674 | + this.#fetchPreview(content) | |
| 675 | + .then((c)=>{ | |
| 676 | + this.#setPreviewContent(c); | |
| 677 | + D.enable(e.button.submit); | |
| 678 | + }) | |
| 679 | + .catch(err=>{ | |
| 680 | + e.preview.textContent = "Error fetching preview: "+err.message; | |
| 681 | + console.error("Error fetching preview:",err); | |
| 682 | + this.reportError(err.message); | |
| 683 | + }) | |
| 684 | + .finally(()=>{ | |
| 685 | + this.#isWaiting = false; | |
| 686 | + D.enable(this.#toDisable); | |
| 687 | + }); | |
| 688 | + } | |
| 689 | + | |
| 690 | + #validate(tgt){ | |
| 691 | + if( this.#e.title ){ | |
| 692 | + const v = this.#e.title.value.trim(); | |
| 693 | + if( !v ){ | |
| 694 | + this.reportError("A non-empty title is required."); | |
| 695 | + return; | |
| 696 | + } | |
| 697 | + } | |
| 698 | + return true; | |
| 699 | + } | |
| 700 | + | |
| 701 | + #submit(){ | |
| 702 | + if( this.#isWaiting ) return; | |
| 703 | + if( !this.#validate() ) return; | |
| 704 | + this.#isWaiting = true; | |
| 705 | + const e = this.#e; | |
| 706 | + D.disable(e.button.submit); | |
| 707 | + const fd = this.#newFormData(); | |
| 708 | + if( this.#e.status ){ | |
| 709 | + /* Send the status only if it was modified, otherwise we may | |
| 710 | + add a superfluous tag. */ | |
| 711 | + const v = this.#e.status.value; | |
| 712 | + if( this.#e.status.dataset.originalValue !== v ){ | |
| 713 | + fd.append("status", v); | |
| 714 | + } | |
| 715 | + } | |
| 716 | + if( e.debug ){ | |
| 717 | + e.debug.querySelectorAll('input[type=checkbox]').forEach(cb=>{ | |
| 718 | + if( cb.checked ){ | |
| 719 | + fd.append(cb.value, 1); | |
| 720 | + //console.debug("Forum post debug option:",cb); | |
| 721 | + } | |
| 722 | + }); | |
| 723 | + } | |
| 724 | + if( this.#att ){ | |
| 725 | + this.#att.populateFormData(fd); | |
| 726 | + } | |
| 727 | + //console.warn("Ready to submit",fd); | |
| 728 | + if( 0 ){ | |
| 729 | + this.#isWaiting = false; | |
| 730 | + return; | |
| 731 | + } | |
| 732 | + const resp = window.fetch(F.repoUrl('forumajax_save'), { | |
| 733 | + method: 'POST', | |
| 734 | + body: fd | |
| 735 | + }).then(r=>r.json()) | |
| 736 | + .then(j=>{ | |
| 737 | + j = F.nu(j); | |
| 738 | + console.debug("forum post editor response:",j); | |
| 739 | + if( j.error ){ | |
| 740 | + throw new Error(j.error); | |
| 741 | + }else if( j.message ){ | |
| 742 | + /* This is only for use in debugging during | |
| 743 | + * development. */ | |
| 744 | + this.reportError(j.message); | |
| 745 | + return; | |
| 746 | + } | |
| 747 | + if( 1 ){ | |
| 748 | + this.#clearDraft(); | |
| 749 | + if( this.#opt.onsubmit instanceof Function ){ | |
| 750 | + try{this.#opt.onsubmit(this, j);} | |
| 751 | + catch(e){ | |
| 752 | + console.error("ForumPostEditor.onsubmit() threw: ", e); | |
| 753 | + } | |
| 754 | + } | |
| 755 | + /* | |
| 756 | + if( this.#opt.edit?.uuid === j.uuid ) then we know the | |
| 757 | + content did not change, but it's possible that attachments | |
| 758 | + and/or a status tag did. Ergo, we need to unconditionally | |
| 759 | + reload to render those changes (if any). The other option | |
| 760 | + is to tell the user "nothing changed" and leave them in | |
| 761 | + the editor, but that could be a lie because we don't know | |
| 762 | + if any attachments or tags were changed. | |
| 763 | + */ | |
| 764 | + else if( 0 ){ | |
| 765 | + if( this.#opt.edit.uuid === j.uuid | |
| 766 | + && !j.statusModified && 0===j.attachedCount ){ | |
| 767 | + this.reportError("No changes made."); | |
| 768 | + }else{ | |
| 769 | + window.location = F.repoUrl('forumpost/'+j.uuid); | |
| 770 | + setTimeout(()=>this.close(), 500/*just in case not redirected*/); | |
| 771 | + } | |
| 772 | + } | |
| 773 | + }else{ | |
| 774 | + this.reportError( | |
| 775 | + "Saving worked but we're ignoring it and staying here." | |
| 776 | + ); | |
| 777 | + } | |
| 778 | + }) | |
| 779 | + .catch((e)=>this.reportError(e.message)) | |
| 780 | + .finally(()=>this.#isWaiting = false); | |
| 781 | + } | |
| 782 | + | |
| 783 | + #storeDraft(){ | |
| 784 | + if( this.#draft ){ | |
| 785 | + this.#draft.mtime = Date.now(); | |
| 786 | + F.storage.setJSON(this.#opt.draftKey, this.#draft); | |
| 787 | + } | |
| 788 | + } | |
| 789 | + | |
| 790 | + /** Clears any persistent draft state. Does not clear the UI | |
| 791 | + widgets. */ | |
| 792 | + #clearDraft(){ | |
| 793 | + if( this.#draft ){ | |
| 794 | + F.storage.remove(this.#opt.draftKey); | |
| 795 | + this.#draft = F.nu(); | |
| 796 | + } | |
| 797 | + } | |
| 798 | + | |
| 799 | + /** | |
| 800 | + Looks for editing draft keys matching either a fixed key or a | |
| 801 | + regex, and removes each matching one which is older than the | |
| 802 | + given number of days. Pass days=0 to purge all entries | |
| 803 | + immediately. | |
| 804 | + */ | |
| 805 | + static purgeOldDrafts(key, days=10){ | |
| 806 | + const age = (3600 * 24 * days) * 1000/*ms*/; | |
| 807 | + const now = Date.now(); | |
| 808 | + const check = (k)=>{ | |
| 809 | + const o = F.storage.getJSON(k); | |
| 810 | + if( o && o.mtime && (!days || (o.mtime+age <= now)) ){ | |
| 811 | + F.storage.remove(k); | |
| 812 | + } | |
| 813 | + }; | |
| 814 | + if( key instanceof RegExp ){ | |
| 815 | + for(const k of F.storage.keys(false).filter(v=>key.test(v))){ | |
| 816 | + check(k); | |
| 817 | + } | |
| 818 | + }else{ | |
| 819 | + check(key); | |
| 820 | + } | |
| 821 | + } | |
| 822 | + | |
| 823 | + async #fetchPost(){ | |
| 824 | + /* | |
| 825 | + TODO: when editing an existing post, fetch the raw body of the | |
| 826 | + post and populate this.e. | |
| 827 | + */ | |
| 828 | + } | |
| 829 | + }/*ForumPostEditor*/; | |
| 830 | + F.ForumPostEditor = ForumPostEditor; | |
| 831 | + | |
| 7 | 832 | /** |
| 8 | 833 | When the page is loaded, this handler does the following: |
| 9 | 834 | |
| 10 | - - Installs expand/collapse UI elements on "long" posts and collapses | |
| 835 | + 1. Installs expand/collapse UI elements on "long" posts and collapses | |
| 11 | 836 | them. |
| 12 | 837 | |
| 13 | - - Any pikchr-generated SVGs get a source-toggle button added to them | |
| 838 | + 2. Any pikchr-generated SVGs get a source-toggle button added to them | |
| 14 | 839 | which activates when the mouse is over the image or it is tapped. |
| 840 | + | |
| 841 | + 3. Plugs in a new edit/reply widget to forum posts. | |
| 15 | 842 | |
| 16 | 843 | This is a harmless no-op if the current page has neither forum |
| 17 | - post constructs for (1) nor any pikchr images for (2), nor will | |
| 18 | - NOT running this code cause any breakage for clients with no JS | |
| 19 | - support: this is all "nice-to-have", not required functionality. | |
| 844 | + post constructs for (1) and (3) nor any pikchr images for (2), | |
| 845 | + nor will NOT running this code cause any breakage for clients | |
| 846 | + with no JS support: this is all "nice-to-have", not required | |
| 847 | + functionality. | |
| 20 | 848 | */ |
| 21 | 849 | F.onPageLoad(function(){ |
| 22 | 850 | const scrollbarIsVisible = (e)=>e.scrollHeight > e.clientHeight; |
| 23 | 851 | /* Returns an event handler which implements the post expand/collapse toggle |
| 24 | 852 | on contentElem when the given widget is activated. */ |
| @@ -94,42 +922,474 @@ | ||
| 94 | 922 | forumPostWrapper.appendChild(widget); |
| 95 | 923 | } |
| 96 | 924 | content.appendChild(rightTapZone); |
| 97 | 925 | rightTapZone.addEventListener('click', widgetEventHandler, false); |
| 98 | 926 | refillTapZone(); |
| 99 | - })/*F.onPageLoad()*/; | |
| 927 | + })/*for-each div.forumTime|div.forumEdit*/; | |
| 100 | 928 | |
| 101 | 929 | if(F.pikchr){ |
| 102 | 930 | F.pikchr.addSrcView(); |
| 103 | 931 | } |
| 104 | 932 | |
| 105 | - /* Attempt to keep stray double-clicks from double-posting. */ | |
| 106 | - const formSubmitted = function(event){ | |
| 107 | - const form = event.target; | |
| 108 | - if( form.dataset.submitted ){ | |
| 109 | - event.preventDefault(); | |
| 110 | - return; | |
| 111 | - } | |
| 112 | - form.dataset.submitted = '1'; | |
| 113 | - /** If the user is left waiting "a long time," disable the | |
| 114 | - resubmit protection. If we don't do this and they tap the | |
| 115 | - browser's cancel button while waiting, they'll be stuck with | |
| 116 | - an unsubmittable form. */ | |
| 117 | - setTimeout(()=>{delete form.dataset.submitted}, 7000); | |
| 118 | - return; | |
| 119 | - }; | |
| 120 | - document.querySelectorAll("form").forEach(function(form){ | |
| 121 | - form.addEventListener('submit',formSubmitted); | |
| 122 | - form | |
| 123 | - .querySelectorAll("input.action-close, input.action-reopen") | |
| 124 | - .forEach(function(e){ | |
| 125 | - F.confirmer(e, { | |
| 126 | - confirmText: (e.classList.contains('action-reopen') | |
| 127 | - ? "Confirm re-open" | |
| 128 | - : "Confirm close"), | |
| 129 | - onconfirm: ()=>form.submit() | |
| 130 | - }); | |
| 131 | - }); | |
| 132 | - }); | |
| 133 | - | |
| 933 | + const eStatus = document.querySelector( | |
| 934 | + 'form div.submenu select.submenuctrl[name="status"]' | |
| 935 | + ); | |
| 936 | + if( eStatus ){ | |
| 937 | + /* Main /forum list. Remove the 'x' form element when eStatus | |
| 938 | + changes, to avoid propagating x when changing the filter. | |
| 939 | + The problem this solves: we're browsed to page 3 of status X. | |
| 940 | + We change the status filter selection to Y. We're redirected | |
| 941 | + to page x, but Y only has 2 posts with that status, so we see | |
| 942 | + an empty list. When changing the filter, we need to ensure | |
| 943 | + that we start back and that beginning. */ | |
| 944 | + const pForm = eStatus.parentElement?.parentElement; | |
| 945 | + if( pForm ){ | |
| 946 | + eStatus.addEventListener('change', ()=>{ | |
| 947 | + pForm.querySelector('input[type="hidden"][name="x"]')?.remove?.(); | |
| 948 | + }, true); | |
| 949 | + } | |
| 950 | + }else{ | |
| 951 | + /* One of the single-post edit/view pages. Handle various UI | |
| 952 | + controls and attempt to keep stray double-clicks from | |
| 953 | + double-posting. | |
| 954 | + https://fossil-scm.org/forum/info/6bd02466533aa131 */ | |
| 955 | + const formSubmitted = function(event){ | |
| 956 | + const form = event.target; | |
| 957 | + if( form.dataset.submitted ){ | |
| 958 | + event.preventDefault(); | |
| 959 | + return; | |
| 960 | + } | |
| 961 | + form.dataset.submitted = '1'; | |
| 962 | + /** If the user is left waiting "a long time," disable the | |
| 963 | + resubmit protection. If we don't do this and they tap the | |
| 964 | + browser's cancel button while waiting, they'll be stuck | |
| 965 | + with an unsubmittable form. It can apparently also happen, | |
| 966 | + via browser-back, that the form gets left in a submitted | |
| 967 | + state. */ | |
| 968 | + setTimeout(()=>{delete form.dataset.submitted}, 7000); | |
| 969 | + return; | |
| 970 | + }; | |
| 971 | + | |
| 972 | + document.querySelectorAll("form").forEach(function(form){ | |
| 973 | + /* Set up controls for closing posts and setting thread | |
| 974 | + status. */ | |
| 975 | + form.addEventListener('submit', formSubmitted); | |
| 976 | + form | |
| 977 | + .querySelectorAll("input.action-close, input.action-reopen") | |
| 978 | + .forEach(function(e){ | |
| 979 | + e.classList.remove('hidden'); | |
| 980 | + F.confirmer(e, { | |
| 981 | + confirmText: (e.classList.contains('action-reopen') | |
| 982 | + ? "Confirm re-open" | |
| 983 | + : "Confirm close"), | |
| 984 | + onconfirm: ()=>form.submit() | |
| 985 | + }); | |
| 986 | + }); | |
| 987 | + form | |
| 988 | + .querySelectorAll("input[type='button'].action-status") | |
| 989 | + .forEach(function(btn){ | |
| 990 | + btn.classList.remove('hidden'); | |
| 991 | + const sel = btn.previousElementSibling; | |
| 992 | + const updateButton = ()=>{ | |
| 993 | + /* Enable btn only when the status has been locally | |
| 994 | + modified. */ | |
| 995 | + if( sel.dataset.initialValue ){ | |
| 996 | + if( sel.dataset.initialValue===sel.value ){ | |
| 997 | + btn.setAttribute('disabled',''); | |
| 998 | + }else{ | |
| 999 | + btn.removeAttribute('disabled'); | |
| 1000 | + } | |
| 1001 | + }else{ | |
| 1002 | + if(sel.selectedIndex===0){ | |
| 1003 | + btn.setAttribute('disabled',''); | |
| 1004 | + }else{ | |
| 1005 | + btn.removeAttribute('disabled'); | |
| 1006 | + } | |
| 1007 | + } | |
| 1008 | + }; | |
| 1009 | + sel.addEventListener('change', updateButton, true); | |
| 1010 | + updateButton(); | |
| 1011 | + F.confirmer(btn, { | |
| 1012 | + confirmText: "Confirm status change", | |
| 1013 | + onconfirm: ()=>form.submit() | |
| 1014 | + }); | |
| 1015 | + }); | |
| 1016 | + }); | |
| 1017 | + } | |
| 1018 | + | |
| 1019 | + /* Apply page-specific tweaks for ForumPostEditor instance fpe | |
| 1020 | + then plug it into the UI at the end of ePost. */ | |
| 1021 | + const initFPEWidget = (fpe, ePost)=>{ | |
| 1022 | + ePost.eUnhideThenWhenDone = [ | |
| 1023 | + /* List of elements to hide while editing/replying and reveal | |
| 1024 | + when discarding or saving. */ | |
| 1025 | + ]; | |
| 1026 | + for( const ee of ePost.querySelectorAll( | |
| 1027 | + '.forumpost-single-controls, fieldset.forum-status-selection' | |
| 1028 | + ) ){ | |
| 1029 | + ee.hidden = true; | |
| 1030 | + ePost.eUnhideThenWhenDone.push(ee); | |
| 1031 | + } | |
| 1032 | + const w = fpe.widget; | |
| 1033 | + w.classList.add('animate-entrance'); | |
| 1034 | + ePost.append(w); | |
| 1035 | + requestAnimationFrame(() => { | |
| 1036 | + w.scrollIntoView({ | |
| 1037 | + behavior: 'smooth', | |
| 1038 | + block: 'nearest', | |
| 1039 | + inline: 'nearest' | |
| 1040 | + }); | |
| 1041 | + }); | |
| 1042 | + }; | |
| 1043 | + | |
| 1044 | + const plugInEditor = | |
| 1045 | + (new URL(window.location).searchParams).get('nojs')===null; | |
| 1046 | + | |
| 1047 | + const eForumNew = ( | |
| 1048 | + plugInEditor | |
| 1049 | + && ( | |
| 1050 | + document.body.classList.contains('cpage-forumnew') | |
| 1051 | + || document.body.classList.contains('cpage-forume1') | |
| 1052 | + )) | |
| 1053 | + ? document.body.querySelector('#forumnew-placeholder') | |
| 1054 | + : null; | |
| 1055 | + if( plugInEditor && eForumNew ){ | |
| 1056 | + /* /forumnew and /forume1 */ | |
| 1057 | + const fpe = new F.ForumPostEditor({ | |
| 1058 | + draftKey: 'draft-forumnew', | |
| 1059 | + hiddenFields: eForumNew.querySelectorAll('input[type=hidden]'), | |
| 1060 | + hideStash: true, | |
| 1061 | + ondiscard: ()=>{ | |
| 1062 | + window.location = F.repoUrl('forum'); | |
| 1063 | + }, | |
| 1064 | + onsubmit: (fpe, response)=>{ | |
| 1065 | + window.location = F.repoUrl('forumpost/'+response.uuid); | |
| 1066 | + } | |
| 1067 | + }); | |
| 1068 | + eForumNew.parentElement.insertBefore(fpe.widget, eForumNew); | |
| 1069 | + eForumNew.remove(); | |
| 1070 | + fossil.page.fpe = fpe /* for testing via the console */; | |
| 1071 | + }/*eForumNew*/ | |
| 1072 | + else if( plugInEditor | |
| 1073 | + && (document.body.classList.contains('cpage-forumpost') | |
| 1074 | + || document.body.classList.contains('cpage-forumthread')) ){ | |
| 1075 | + /* /forumpost and /forumthread. Take over the Edit/Reply buttons | |
| 1076 | + to use a ForumPostEditor. */ | |
| 1077 | + | |
| 1078 | + const fetchPost = async (fpid)=>{ | |
| 1079 | + return window.fetch(F.repoUrl('ajax/artifact.json?uuid='+fpid)) | |
| 1080 | + .then(r=>r.json()) | |
| 1081 | + .then(j=>{ | |
| 1082 | + j = F.nu(j); | |
| 1083 | + if( j.error ) throw new Error(j.error); | |
| 1084 | + return j; | |
| 1085 | + }); | |
| 1086 | + }; | |
| 1087 | + | |
| 1088 | + const makeDraftKey = (prefix,uuid)=>{ | |
| 1089 | + return prefix+'-'+uuid.substr(0,12); | |
| 1090 | + }; | |
| 1091 | + | |
| 1092 | + /** | |
| 1093 | + Perform some init common to both Reply and Edit. ePost = the | |
| 1094 | + forum post DOM element. eButton = the Reply or Edit | |
| 1095 | + button. | |
| 1096 | + */ | |
| 1097 | + const setupEditReplyElement = (ePost, eButton)=>{ | |
| 1098 | + /* Forum posts are indented in the main forum view to | |
| 1099 | + represent their place in the hierarchy. In order to gain | |
| 1100 | + some screen space, we shift the post to the left margin and | |
| 1101 | + arrange to shift it back when the editor is closed. We also | |
| 1102 | + record the original button label so that it can be | |
| 1103 | + restored on close. */ | |
| 1104 | + ePost.dataset.originalMarginLeft = ePost.style.marginLeft; | |
| 1105 | + ePost.style.marginLeft = 'initial'; | |
| 1106 | + eButton.dataset.originalLabel = eButton.innerText; | |
| 1107 | + }; | |
| 1108 | + | |
| 1109 | + /** Undoes the damage done by setupEditReplyElement(). */ | |
| 1110 | + const restoreEditReplyElement = (ePost, eButton)=>{ | |
| 1111 | + if( ePost.dataset.originalMarginLeft ){ | |
| 1112 | + ePost.style.marginLeft = ePost.dataset.originalMarginLeft; | |
| 1113 | + delete ePost.dataset.originalMarginLeft; | |
| 1114 | + } | |
| 1115 | + if( eButton.dataset.originalLabel ){ | |
| 1116 | + eButton.innerText = eButton.dataset.originalLabel; | |
| 1117 | + delete eButton.dataset.originalLabel; | |
| 1118 | + } | |
| 1119 | + for(const ee of (ePost.eUnhideThenWhenDone || [])){ | |
| 1120 | + ee.removeAttribute('hidden'); | |
| 1121 | + } | |
| 1122 | + ePost.eUnhideThenWhenDone = undefined; | |
| 1123 | + }; | |
| 1124 | + | |
| 1125 | + /** | |
| 1126 | + Reports an error regarding the forum post element | |
| 1127 | + ePost, appending each entry in msg to a wrapper | |
| 1128 | + element with the class | |
| 1129 | + */ | |
| 1130 | + const reportFPEError = (ePost,...msg)=>{ | |
| 1131 | + const e = D.addClass(D.p(), 'error'); | |
| 1132 | + e.append( | |
| 1133 | + ...msg, | |
| 1134 | + D.br(), | |
| 1135 | + D.button("Clear error", ()=>e.remove()) | |
| 1136 | + ); | |
| 1137 | + ePost.append(e); | |
| 1138 | + }; | |
| 1139 | + | |
| 1140 | + /** | |
| 1141 | + Plug in an editor widget representing a reply to a post. | |
| 1142 | + form = a (.forum-post-single-controls > form) element. The | |
| 1143 | + final 3 arguments are as documented for | |
| 1144 | + setupEditReplyElement(). | |
| 1145 | + */ | |
| 1146 | + const replyClicked = async (form, ePost, eBtnReply)=>{ | |
| 1147 | + const fpid = ePost.dataset.fpid; | |
| 1148 | + const fEditHead = ePost.dataset.fedithead; | |
| 1149 | + const draftKey = makeDraftKey( | |
| 1150 | + 'draft-reply', fEditHead | |
| 1151 | + /* The problem with firt as a key is that firt is not | |
| 1152 | + necessarily the root edit of that post, which is what we | |
| 1153 | + really want as a draft key so that the draft does not | |
| 1154 | + disappear if firt is later edited (giving us a new firt | |
| 1155 | + value here). */ | |
| 1156 | + || fpid | |
| 1157 | + ); | |
| 1158 | + let releaseLock; | |
| 1159 | + if( window.navigator.locks ){ | |
| 1160 | + releaseLock = await new Promise((resolve)=>{ | |
| 1161 | + window.navigator.locks.request( | |
| 1162 | + 'fossil-'+draftKey, | |
| 1163 | + {ifAvailable: true}, | |
| 1164 | + async (lock) => { | |
| 1165 | + if( !lock ){ | |
| 1166 | + /*lock contention*/ | |
| 1167 | + resolve(null); | |
| 1168 | + return; | |
| 1169 | + } | |
| 1170 | + let release; | |
| 1171 | + const lockReleased = new Promise(res=>release=res); | |
| 1172 | + resolve(release); | |
| 1173 | + await lockReleased/*hold the lock open*/; | |
| 1174 | + }); | |
| 1175 | + }); | |
| 1176 | + if( !releaseLock ){ | |
| 1177 | + reportFPEError( | |
| 1178 | + ePost, | |
| 1179 | + "This post is actively being replied to ", | |
| 1180 | + "in another tab. To avoid losing edits, ", | |
| 1181 | + "it cannot be opened here until the locking ", | |
| 1182 | + "tab is closed." | |
| 1183 | + ); | |
| 1184 | + return; | |
| 1185 | + } | |
| 1186 | + } | |
| 1187 | + | |
| 1188 | + setupEditReplyElement(ePost, eBtnReply); | |
| 1189 | + eBtnReply.innerText = "Replying..."; | |
| 1190 | + const ondone = (fpe, response)=>{ | |
| 1191 | + /* onsubmit() and ondiscard() callback */ | |
| 1192 | + restoreEditReplyElement(ePost, eBtnReply); | |
| 1193 | + //console.debug("ondiscard/onsubmit", fpe, artifact); | |
| 1194 | + if( response/*onsubmit()*/ ){ | |
| 1195 | + window.location = F.repoUrl('forumpost/'+response.uuid); | |
| 1196 | + setTimeout(()=>fpe.close(), 500/*just in case not redirected*/); | |
| 1197 | + }else{/*ondiscard() or onclose()*/ | |
| 1198 | + } | |
| 1199 | + }; | |
| 1200 | + const fpe = new F.ForumPostEditor(F.nu({ | |
| 1201 | + hiddenFields: form.querySelectorAll( | |
| 1202 | + 'input[type=hidden][name=csrf]' | |
| 1203 | + /* Do not inherit the fpid field, else this will become | |
| 1204 | + an edit to that post rather than a response. */ | |
| 1205 | + ), | |
| 1206 | + ondiscard: ()=>{/*need a noop here. Will call onclose()*/}, | |
| 1207 | + onsubmit: ondone, | |
| 1208 | + onclose: ()=>{ | |
| 1209 | + if( releaseLock ){ | |
| 1210 | + releaseLock(); | |
| 1211 | + releaseLock = null; | |
| 1212 | + } | |
| 1213 | + ondone(); | |
| 1214 | + }, | |
| 1215 | + inReplyTo: fpid, | |
| 1216 | + draftKey | |
| 1217 | + })); | |
| 1218 | + initFPEWidget(fpe, ePost); | |
| 1219 | + }/*replyClicked()*/; | |
| 1220 | + | |
| 1221 | + /** | |
| 1222 | + Plug in an editor widget representing an edit to a post. | |
| 1223 | + form = a (.forum-post-single-controls > form) element. The | |
| 1224 | + final 3 arguments are as documented for | |
| 1225 | + setupEditReplyElement(). | |
| 1226 | + */ | |
| 1227 | + const editClicked = async (form, ePost, eBtnEdit)=>{ | |
| 1228 | + const fpid = ePost.dataset.fpid; | |
| 1229 | + const firt = ePost.dataset.firt; | |
| 1230 | + const fEditHead = ePost.dataset.fedithead; | |
| 1231 | + const draftKey = makeDraftKey('draft-forumedit', fEditHead || fpid); | |
| 1232 | + let releaseLock; | |
| 1233 | + if( navigator.locks ){ | |
| 1234 | + releaseLock = await new Promise((resolve) => { | |
| 1235 | + navigator.locks.request( | |
| 1236 | + 'fossil-'+draftKey, | |
| 1237 | + {ifAvailable: true}, | |
| 1238 | + async (lock)=>{ | |
| 1239 | + if( !lock ){ | |
| 1240 | + resolve(null); | |
| 1241 | + return; | |
| 1242 | + } | |
| 1243 | + let release; | |
| 1244 | + const lockReleased = new Promise(res=>release=res); | |
| 1245 | + resolve(release); | |
| 1246 | + await lockReleased; | |
| 1247 | + }); | |
| 1248 | + }); | |
| 1249 | + | |
| 1250 | + if( !releaseLock ){ | |
| 1251 | + reportFPEError( | |
| 1252 | + ePost, | |
| 1253 | + "This post is actively being edited ", | |
| 1254 | + "in another tab. To avoid losing edits, ", | |
| 1255 | + "it cannot be opened here until the locking ", | |
| 1256 | + "tab is closed." | |
| 1257 | + ); | |
| 1258 | + return; | |
| 1259 | + } | |
| 1260 | + } | |
| 1261 | + setupEditReplyElement(ePost, eBtnEdit); | |
| 1262 | + eBtnEdit.innerText = "Editing..."; | |
| 1263 | + fetchPost(fpid) | |
| 1264 | + .then(artifact=>{ | |
| 1265 | + const ondone = (fpe, response)=>{ | |
| 1266 | + /* onsubmit() and ondiscard() callback */ | |
| 1267 | + if( response/*onsubmit()*/ ){ | |
| 1268 | + if( fpid === response.uuid | |
| 1269 | + && !response.statusModified | |
| 1270 | + && 0===response.attachedCount ){ | |
| 1271 | + fpe.reportError("No changes made."); | |
| 1272 | + }else{ | |
| 1273 | + restoreEditReplyElement(ePost, eBtnEdit); | |
| 1274 | + window.location = F.repoUrl('forumpost/'+response.uuid); | |
| 1275 | + setTimeout(()=>fpe.close(), 500/*just in case not redirected*/); | |
| 1276 | + } | |
| 1277 | + }else{ | |
| 1278 | + /*ondiscard() or onclose()*/ | |
| 1279 | + restoreEditReplyElement(ePost, eBtnEdit); | |
| 1280 | + } | |
| 1281 | + }; | |
| 1282 | + const eStatusSelect = ePost.querySelector( | |
| 1283 | + ':scope > fieldset.forum-status-selection select[name=status]' | |
| 1284 | + ); | |
| 1285 | + | |
| 1286 | + const fpe = new F.ForumPostEditor(F.nu({ | |
| 1287 | + hiddenFields: form.querySelectorAll('input[type=hidden]'), | |
| 1288 | + ondiscard: ()=>{/*need a noop here. Will call onclose()*/}, | |
| 1289 | + onsubmit: ondone, | |
| 1290 | + onclose: ()=>{ | |
| 1291 | + if(releaseLock){ | |
| 1292 | + releaseLock(); | |
| 1293 | + releaseLock = null; | |
| 1294 | + } | |
| 1295 | + ondone(); | |
| 1296 | + }, | |
| 1297 | + draftKey, | |
| 1298 | + edit: artifact, | |
| 1299 | + status: eStatusSelect?.value, | |
| 1300 | + inReplyTo: firt | |
| 1301 | + })); | |
| 1302 | + initFPEWidget(fpe, ePost); | |
| 1303 | + }) | |
| 1304 | + .catch(err=>{ | |
| 1305 | + if( releaseLock ){ | |
| 1306 | + releaseLock(); | |
| 1307 | + releaseLock = null; | |
| 1308 | + } | |
| 1309 | + restoreEditReplyElement(ePost, eBtnEdit); | |
| 1310 | + console.error("Error fetching post:", err); | |
| 1311 | + reportFPEError(ePost, "Error fetching post: ", err.message); | |
| 1312 | + }); | |
| 1313 | + }/*editClicked()*/; | |
| 1314 | + | |
| 1315 | + document.body.querySelectorAll( | |
| 1316 | + '.forumpost-single-controls > form' | |
| 1317 | + ).forEach(form=>{ | |
| 1318 | + /* For each forum post... */ | |
| 1319 | + const eThePost = form.parentElement.parentElement/*main post DOM element*/; | |
| 1320 | + if( !eThePost?.dataset?.fpid ){ | |
| 1321 | + /* The server injects these dataset values. */ | |
| 1322 | + console.warn("Unexpected missing fpid", eThePost); | |
| 1323 | + return; | |
| 1324 | + } | |
| 1325 | + const checkButtonForDraft = (draftKeyPrefix, eBtn)=>{ | |
| 1326 | + /* If a draft is found associated with eThePost, mark eBtn | |
| 1327 | + as a draft and set up storage event listeners to update | |
| 1328 | + the button as new drafts come and go. */ | |
| 1329 | + const fpid = eThePost.dataset.fpid; | |
| 1330 | + const fEditHead = eThePost.dataset.fedithead; | |
| 1331 | + const draftKey = makeDraftKey(draftKeyPrefix, fEditHead || fpid); | |
| 1332 | + if( F.storage.contains(draftKey) ){ | |
| 1333 | + eBtn.classList.add('draft'); | |
| 1334 | + } | |
| 1335 | + F.storage.addEventListener('set', ({detail})=>{ | |
| 1336 | + if( draftKey === detail.key ){ | |
| 1337 | + eBtn.classList.add('draft'); | |
| 1338 | + } | |
| 1339 | + }); | |
| 1340 | + F.storage.addEventListener('remove', ({detail})=>{ | |
| 1341 | + if( draftKey === detail.key ){ | |
| 1342 | + eBtn.classList.remove('draft'); | |
| 1343 | + } | |
| 1344 | + }); | |
| 1345 | + }; | |
| 1346 | + /* Replace the Reply and Edit buttons with ones which will activate | |
| 1347 | + a ForumPostEditor. */ | |
| 1348 | + const btnReply = form.querySelector('input[type=submit][name=reply]'); | |
| 1349 | + if( btnReply ){ | |
| 1350 | + const b = D.button("Reply", ()=>replyClicked(form, eThePost, b)); | |
| 1351 | + b.type = 'button'/*keep container form from submitting*/; | |
| 1352 | + checkButtonForDraft('draft-reply',b); | |
| 1353 | + btnReply.parentElement.insertBefore(b, btnReply); | |
| 1354 | + btnReply.remove(); | |
| 1355 | + } | |
| 1356 | + const btnEdit = form.querySelector('input[type=submit][name=edit]'); | |
| 1357 | + if( btnEdit ){ | |
| 1358 | + const b = D.button("Edit", ()=>editClicked(form, eThePost, b)); | |
| 1359 | + b.type = 'button'/*keep container form from submitting*/; | |
| 1360 | + checkButtonForDraft('draft-forumedit',b); | |
| 1361 | + btnEdit.parentElement.insertBefore(b, btnEdit); | |
| 1362 | + btnEdit.remove(); | |
| 1363 | + } | |
| 1364 | + })/*for-each form*/; | |
| 1365 | + | |
| 1366 | + }/* /forumpost and /forumthread */ | |
| 1367 | + | |
| 1368 | + document.body.querySelectorAll('.remove-on-load').forEach(e=>e.remove()); | |
| 1369 | + document.body.querySelectorAll('.initially-hidden').forEach(e=>{ | |
| 1370 | + /* This is a workaround for a span.help-buttonlet which we need | |
| 1371 | + to start hidden so that it does not show up for no-JS | |
| 1372 | + clients. */ | |
| 1373 | + e.classList.remove('initially-hidden'); | |
| 1374 | + }); | |
| 1375 | + | |
| 1376 | + if( plugInEditor ){ | |
| 1377 | + document.body.querySelectorAll('.remove-if-replaced').forEach( | |
| 1378 | + /* Remove remaining legacy UI elements. */ e=>e.remove() | |
| 1379 | + ); | |
| 1380 | + /* Purge old drafts only every now and then. */ | |
| 1381 | + const now = Date.now(); | |
| 1382 | + const lastPurge = +F.storage.get('forum-drafts-last-purge', 0); | |
| 1383 | + if( now - lastPurge > (24 * 60 * 60 * 1000 /*1 day ms*/) ){ | |
| 1384 | + F.storage.set('forum-drafts-last-purge', now); | |
| 1385 | + setTimeout(()=>{ | |
| 1386 | + /* Don't block the UI while we're doing I/O */ | |
| 1387 | + F.ForumPostEditor.purgeOldDrafts( | |
| 1388 | + /^draft-(reply|forumedit)-.*/ | |
| 1389 | + /* Intentionally leaving draft-forumnew in place. */ | |
| 1390 | + ); | |
| 1391 | + }, 50); | |
| 1392 | + } | |
| 1393 | + } | |
| 134 | 1394 | })/*F.onPageLoad callback*/; |
| 135 | 1395 | })(window.fossil); |
| 136 | 1396 |
| --- src/fossil.page.forumpost.js | |
| +++ src/fossil.page.forumpost.js | |
| @@ -1,24 +1,852 @@ | |
| 1 | (function(F/*the fossil object*/){ |
| 2 | "use strict"; |
| 3 | /* JS code for /forumpost and friends. Requires fossil.dom |
| 4 | and can optionally use fossil.pikchr. */ |
| 5 | const P = F.page, D = F.dom; |
| 6 | |
| 7 | /** |
| 8 | When the page is loaded, this handler does the following: |
| 9 | |
| 10 | - Installs expand/collapse UI elements on "long" posts and collapses |
| 11 | them. |
| 12 | |
| 13 | - Any pikchr-generated SVGs get a source-toggle button added to them |
| 14 | which activates when the mouse is over the image or it is tapped. |
| 15 | |
| 16 | This is a harmless no-op if the current page has neither forum |
| 17 | post constructs for (1) nor any pikchr images for (2), nor will |
| 18 | NOT running this code cause any breakage for clients with no JS |
| 19 | support: this is all "nice-to-have", not required functionality. |
| 20 | */ |
| 21 | F.onPageLoad(function(){ |
| 22 | const scrollbarIsVisible = (e)=>e.scrollHeight > e.clientHeight; |
| 23 | /* Returns an event handler which implements the post expand/collapse toggle |
| 24 | on contentElem when the given widget is activated. */ |
| @@ -94,42 +922,474 @@ | |
| 94 | forumPostWrapper.appendChild(widget); |
| 95 | } |
| 96 | content.appendChild(rightTapZone); |
| 97 | rightTapZone.addEventListener('click', widgetEventHandler, false); |
| 98 | refillTapZone(); |
| 99 | })/*F.onPageLoad()*/; |
| 100 | |
| 101 | if(F.pikchr){ |
| 102 | F.pikchr.addSrcView(); |
| 103 | } |
| 104 | |
| 105 | /* Attempt to keep stray double-clicks from double-posting. */ |
| 106 | const formSubmitted = function(event){ |
| 107 | const form = event.target; |
| 108 | if( form.dataset.submitted ){ |
| 109 | event.preventDefault(); |
| 110 | return; |
| 111 | } |
| 112 | form.dataset.submitted = '1'; |
| 113 | /** If the user is left waiting "a long time," disable the |
| 114 | resubmit protection. If we don't do this and they tap the |
| 115 | browser's cancel button while waiting, they'll be stuck with |
| 116 | an unsubmittable form. */ |
| 117 | setTimeout(()=>{delete form.dataset.submitted}, 7000); |
| 118 | return; |
| 119 | }; |
| 120 | document.querySelectorAll("form").forEach(function(form){ |
| 121 | form.addEventListener('submit',formSubmitted); |
| 122 | form |
| 123 | .querySelectorAll("input.action-close, input.action-reopen") |
| 124 | .forEach(function(e){ |
| 125 | F.confirmer(e, { |
| 126 | confirmText: (e.classList.contains('action-reopen') |
| 127 | ? "Confirm re-open" |
| 128 | : "Confirm close"), |
| 129 | onconfirm: ()=>form.submit() |
| 130 | }); |
| 131 | }); |
| 132 | }); |
| 133 | |
| 134 | })/*F.onPageLoad callback*/; |
| 135 | })(window.fossil); |
| 136 |
| --- src/fossil.page.forumpost.js | |
| +++ src/fossil.page.forumpost.js | |
| @@ -1,24 +1,852 @@ | |
| 1 | /** |
| 2 | Code for the forum family of pages. Requires fossil.X where X is |
| 3 | (copybutton, pikchr, confirmer, attach, tabs, storage). |
| 4 | */ |
| 5 | (function(F/*the fossil object*/){ |
| 6 | "use strict"; |
| 7 | /* JS code for /forumpost and friends. Requires fossil.dom |
| 8 | and can optionally use fossil.pikchr. */ |
| 9 | const P = F.page, D = F.dom; |
| 10 | |
| 11 | let idCounter = 0; |
| 12 | |
| 13 | /* |
| 14 | The problem: when previewing the bottom-most post of a thread, the |
| 15 | preview widget's size changes cause the page to scroll |
| 16 | unpredictably as the bottom boundary of the page moves. A weird |
| 17 | workaround (not invented here) is to add dummy blank padding to |
| 18 | the page to allow the preview widget to grow and shrink without |
| 19 | (usually) scrolling, but whether it does so really depends on its |
| 20 | size. |
| 21 | |
| 22 | We could maybe get the same effect by adding this size as |
| 23 | padding-bottom to document.body instead of as a new element. |
| 24 | */ |
| 25 | const dummyPadding = D.div(); |
| 26 | dummyPadding.style.height = '75em'; |
| 27 | /* Keep track of ForumPostEditor instances so we can remove this |
| 28 | padding when none are active. */ |
| 29 | dummyPadding.refs = new Set(); |
| 30 | F.dummyPadding = dummyPadding /* only for debugging */; |
| 31 | |
| 32 | /** |
| 33 | A forum post editor widget for new posts and responses. |
| 34 | */ |
| 35 | class ForumPostEditor { |
| 36 | /* Options */ |
| 37 | #opt; |
| 38 | /* Dom elements */ |
| 39 | #e; |
| 40 | /* F.Attacher instance */ |
| 41 | #att; |
| 42 | /* Is waiting on a pending remote response. */ |
| 43 | #isWaiting = false; |
| 44 | /* F.TabManager */ |
| 45 | #tabs; |
| 46 | /* Elements to disable while an XHR is pending. */ |
| 47 | #toDisable = []; |
| 48 | /* DOM element of the current active tab. */ |
| 49 | #activeTab; |
| 50 | /* Extra input[type=hidden] fields imported from fossil's |
| 51 | static page generation. */ |
| 52 | #extraFields; |
| 53 | /* Persistent draft message object. */ |
| 54 | #draft; |
| 55 | |
| 56 | /** |
| 57 | Options: |
| 58 | |
| 59 | opt.draftKey[string=undefined]: if set then this object's state |
| 60 | will be stored in fossil.storage when the relevant input fields |
| 61 | lose focus. If old state is found, the form is pre-populated |
| 62 | from it. The state is cleared on a discard() or successful |
| 63 | submit. |
| 64 | |
| 65 | opt.ondiscard[=function]: if set, a Discard button is added |
| 66 | which, when activated, clears the current draft and removes |
| 67 | this object's widget from the DOM. After doing so, |
| 68 | opt.ondiscard() is called and passed this object. Exceptions |
| 69 | thrown by ondiscard() are ignored but may be logged. |
| 70 | |
| 71 | opt.onsubmit[=function]: if set, this function is called |
| 72 | immediately after the post has been successfully saved, and |
| 73 | passed this object and a JSON-format response object from the |
| 74 | save request. It is generally then up to the caller to close() |
| 75 | this object and/or redirect to /forumpost/${arguments[1].uuid}. |
| 76 | |
| 77 | opt.onclose[=function]: like opt.onsubmit, this function is |
| 78 | called when this.close() is called, and passed no arguments. |
| 79 | onclose() is called before the widget is removed from the dom |
| 80 | and _does not_ fire if it is not in the DOM. |
| 81 | |
| 82 | opt.hiddenFields: an optional list of input elements to |
| 83 | incorporate into the form for requests which request the |
| 84 | preview or save the post. |
| 85 | |
| 86 | opt.inReplyTo=uuid: if this is a response to a post, this |
| 87 | is the full forum post uuid of the being-replied-to post. |
| 88 | |
| 89 | opt.edit=artifactObject: if this is an edit of an existing |
| 90 | post, this is the full JSON-format artifact of the forum post |
| 91 | the being-edited post, as returned by /ajax/artifact.json. |
| 92 | |
| 93 | opt.status: optional current status tag value for opt.edit, |
| 94 | if known. This is used for pre-selecting a status value. |
| 95 | |
| 96 | opt.hideStash[bool=false]: if true, the "Stash" button does not |
| 97 | get added. Intended for use with /forumnew. |
| 98 | */ |
| 99 | constructor(opt){ |
| 100 | opt = this.#opt = F.nu({ |
| 101 | draftKey: undefined, |
| 102 | hideStash: false |
| 103 | }, opt); |
| 104 | opt.isNewThread = !opt.inReplyTo && !opt.edit; |
| 105 | if( opt.draftKey ){ |
| 106 | this.#draft = F.nu(F.storage.getJSON(opt.draftKey, {})); |
| 107 | } |
| 108 | const e = this.#e = F.nu({ |
| 109 | mimetype: F.nu(), |
| 110 | button: F.nu() |
| 111 | }); |
| 112 | //console.debug("Setting up FPE opt =",opt); |
| 113 | const wrapper = e.widget = D.addClass(D.div(), 'ForumPostEditor'); |
| 114 | D.clearElement(wrapper); |
| 115 | |
| 116 | if( !opt.inReplyTo ){ |
| 117 | /* Title... */ |
| 118 | e.titleBar = D.addClass(D.div(),'titlebar'); |
| 119 | e.title = D.attr( |
| 120 | D.addClass(D.input('text'), 'title'), |
| 121 | 'placeholder', |
| 122 | 'Thread title (required)' |
| 123 | ); |
| 124 | e.title.setAttribute('maxlength', 125); |
| 125 | e.titleBar.append( |
| 126 | D.append(D.span(), "Title:"), |
| 127 | e.title |
| 128 | ); |
| 129 | if( this.#draft ){ |
| 130 | e.title.addEventListener('blur', ()=>{ |
| 131 | this.#draft.title = e.title.value; |
| 132 | this.#storeDraft(); |
| 133 | }); |
| 134 | e.title.value = this.#draft.title || opt.edit?.H || ''; |
| 135 | }else if( opt.edit?.H ){ |
| 136 | e.title.value = opt.edit.H; |
| 137 | } |
| 138 | wrapper.append(e.titleBar); |
| 139 | } |
| 140 | |
| 141 | { /* Mimetype... */ |
| 142 | e.mimetype.wrapper = D.addClass(D.div(), 'mimetype-wrapper'); |
| 143 | const sel = e.mimetype.select = D.addClass(D.select(), 'mimetype-select'); |
| 144 | sel.setAttribute('title', 'Markup format for this post.'); |
| 145 | this.#toDisable.push(sel); |
| 146 | let i = 0; |
| 147 | D.option(sel, '', '- Markup format -').disabled = true; |
| 148 | for(const [k,v] of Object.entries({ |
| 149 | 'text/x-markdown': 'Markdown', |
| 150 | 'text/x-fossil-wiki': 'Fossil Wiki', |
| 151 | 'text/plain': 'Plain text' |
| 152 | })) { |
| 153 | D.option(sel, k, v); |
| 154 | } |
| 155 | sel.value = opt.mimetype |
| 156 | || this.#draft?.mimetype |
| 157 | || F.storage.get('forum-mimetype', sel.options[1].value); |
| 158 | sel.addEventListener('change',ev=>{ |
| 159 | if( this.#draft && this.#draft.mimetype!==ev.target.value ){ |
| 160 | this.#draft.mimetype = ev.target.value; |
| 161 | this.#storeDraft(); |
| 162 | } |
| 163 | F.storage.set('forum-mimetype', ev.target.value); |
| 164 | }); |
| 165 | e.mimetype.wrapper.append(sel); |
| 166 | } |
| 167 | |
| 168 | e.buttons = D.addClass(D.div(), 'buttons'); |
| 169 | { /* Preview/submit buttons... */ |
| 170 | e.button.preview = D.attr( |
| 171 | D.button("Preview", e=>this.#preview()), |
| 172 | 'title', |
| 173 | 'Preview your edits.' |
| 174 | ); |
| 175 | e.button.submit = D.attr( |
| 176 | D.button("Submit"), |
| 177 | 'title', |
| 178 | 'Save any edits to the server. Not permitted until Preview has been used.' |
| 179 | ); |
| 180 | if( this.#draft && !opt.hideStash ){ |
| 181 | e.button.stash = D.attr( |
| 182 | D.button( |
| 183 | "Stash", e=>this.close() |
| 184 | /* This could be called Close, but that would semantically |
| 185 | collide with the Close [this post] button. All "Stash" |
| 186 | does is close the widget. */ |
| 187 | ), |
| 188 | 'title', "Close this editor and stash any edits locally." |
| 189 | ); |
| 190 | } |
| 191 | if( opt.ondiscard instanceof Function ){ |
| 192 | e.button.discard = D.attr( |
| 193 | D.button('Discard'), |
| 194 | 'title', |
| 195 | 'Close the editor and discard all local edits.' |
| 196 | ); |
| 197 | } |
| 198 | if( 1 ){ |
| 199 | F.confirmer(e.button.submit, { |
| 200 | confirmText: "Confirm submit...", |
| 201 | onconfirm: ()=>this.#submit() |
| 202 | }); |
| 203 | if( e.button.discard ){ |
| 204 | F.confirmer(e.button.discard, { |
| 205 | confirmText: "Really discard?", |
| 206 | onconfirm: ()=>this.discard() |
| 207 | }); |
| 208 | } |
| 209 | }else{ |
| 210 | e.button.submit.addEventListener('click', ()=>this.#submit()); |
| 211 | if( e.button.discard ){ |
| 212 | e.button.submit.addEventListener('click', ()=>this.discard()); |
| 213 | } |
| 214 | } |
| 215 | e.button.submit.setAttribute('disabled', ''); |
| 216 | wrapper.append(e.buttons); |
| 217 | |
| 218 | e.error = D.addClass(D.div(), 'error', 'hidden'); |
| 219 | wrapper.append(e.error); |
| 220 | e.error.addEventListener('dblclick',()=>this.reportError()); |
| 221 | } |
| 222 | |
| 223 | const idPrefix = 'FormPostEditor'+(++idCounter)/* TabManager requires IDs */; |
| 224 | { /* Main tabs... */ |
| 225 | e.tabs = D.attr( |
| 226 | D.addClass(D.div(), 'tab-container'), |
| 227 | 'id', idPrefix+'-tabs' |
| 228 | ); |
| 229 | this.#tabs = new F.TabManager(e.tabs); |
| 230 | this.#tabs.addEventListener('before-switch-to', (ev)=>{ |
| 231 | //console.debug("Switching to tab",ev.detail); |
| 232 | switch( (this.#activeTab = ev.detail) ){ |
| 233 | case e.preview: |
| 234 | this.#e.button.preview.click(); |
| 235 | break; |
| 236 | case e.help: |
| 237 | if( e.help.$needsInit ){ |
| 238 | delete e.help.$needsInit; |
| 239 | this.#initHelpTab(); |
| 240 | } |
| 241 | break; |
| 242 | case e.tabAttach: |
| 243 | if( !this.#att ) this.#initAttacherTab(); |
| 244 | break; |
| 245 | } |
| 246 | }); |
| 247 | wrapper.append( e.tabs ); |
| 248 | |
| 249 | e.tabEdit = D.div(); |
| 250 | e.tabEdit.classList.add('editor-wrapper'); |
| 251 | e.editor = D.attr( |
| 252 | D.addClass(D.textarea(), 'editor'), |
| 253 | 'placeholder', |
| 254 | 'Your message to other forum-goers...' |
| 255 | ); |
| 256 | e.tabEdit.append(e.editor); |
| 257 | e.tabEdit.dataset.tabLabel = (opt.edit || !opt.inReplyTo) |
| 258 | ? 'Edit' : 'Reply'; |
| 259 | this.#tabs.addTab( e.tabEdit ); |
| 260 | this.#tabs.switchToTab( e.tabEdit ); |
| 261 | if( this.#draft ){ |
| 262 | this.editorContent = this.#draft.content || opt.edit?.W || ''; |
| 263 | e.editor.addEventListener( |
| 264 | 'blur', ()=>{ |
| 265 | this.#draft.content = this.editorContent; |
| 266 | this.#storeDraft(); |
| 267 | } |
| 268 | ); |
| 269 | }else if( opt.edit?.W ){ |
| 270 | this.editorContent = opt.artifact.W; |
| 271 | } |
| 272 | e.preview = D.addClass(D.div(), 'preview'); |
| 273 | e.preview.dataset.tabLabel = 'Preview'; |
| 274 | this.#toDisable.push(e.button.preview); |
| 275 | this.#tabs.addTab( e.preview ); |
| 276 | } |
| 277 | |
| 278 | if( F.user.enableDebug ){ |
| 279 | e.debug = D.addClass(D.div(), 'debug'); |
| 280 | e.debug.dataset.tabLabel = 'Debug'; |
| 281 | e.debug.setAttribute('id', idPrefix+'-debug'); |
| 282 | for(const [k,v] of Object.entries({ |
| 283 | dryrun: 'Dry run', |
| 284 | domod: 'Require moderation approval', |
| 285 | //showqp: 'Show query parameters', |
| 286 | fpsilent: 'Do not send notification emails' |
| 287 | })){ |
| 288 | const lbl = D.label(false, v); |
| 289 | lbl.prepend(D.checkbox(k)); |
| 290 | e.debug.append(lbl); |
| 291 | } |
| 292 | this.#tabs.addTab(e.debug); |
| 293 | } |
| 294 | e.buttons.append(e.mimetype.wrapper); |
| 295 | |
| 296 | if( opt.edit |
| 297 | && !opt.inReplyTo |
| 298 | && F.config.forumStatuses?.length>0 ){ |
| 299 | const sel = e.status = D.select(); |
| 300 | sel.setAttribute('title', 'The status tag value for this post.'); |
| 301 | D.option(sel, "", "- Status -").disabled = true; |
| 302 | for( const status of F.config.forumStatuses ){ |
| 303 | D.option(sel, status.value, status.label); |
| 304 | } |
| 305 | e.buttons.append(sel); |
| 306 | if( opt.status ){ |
| 307 | sel.value = opt.status; |
| 308 | }else if( this.#draft ){ |
| 309 | if( this.#draft.status ){ |
| 310 | sel.value = this.#draft.status; |
| 311 | }else{ |
| 312 | this.#draft.status = sel.value = F.config.forumStatuses[0].value; |
| 313 | } |
| 314 | sel.addEventListener('change',ev=>{ |
| 315 | const v = sel.value; |
| 316 | if( this.#draft.status !== v ){ |
| 317 | this.#draft.status = v; |
| 318 | this.#storeDraft(); |
| 319 | } |
| 320 | }); |
| 321 | } |
| 322 | }/*e.status*/ |
| 323 | |
| 324 | if( F.user.mayAttachForum ){ |
| 325 | //e.buttons.append( e.button.addAttach = this.#att.takeAddButton() ); |
| 326 | e.tabAttach = D.div(); |
| 327 | e.tabAttach.setAttribute('id', idPrefix+'-attach'); |
| 328 | e.tabAttach.dataset.tabLabel = 'Attachments'; |
| 329 | this.#tabs.addTab(e.tabAttach); |
| 330 | /* Reminder: we don't currently have a way to disable/enable |
| 331 | an Attacher's controls during ajax traffic. */ |
| 332 | } |
| 333 | e.buttons.append(e.button.preview, e.button.submit); |
| 334 | if( e.button.stash ){ |
| 335 | e.buttons.append(e.button.stash); |
| 336 | this.#toDisable.push(e.button.stash); |
| 337 | } |
| 338 | if( e.button.discard ){ |
| 339 | e.buttons.append(e.button.discard); |
| 340 | this.#toDisable.push(e.button.discard); |
| 341 | } |
| 342 | |
| 343 | e.help = D.attr(D.div(), 'id', idPrefix+'-help'); |
| 344 | e.help.$needsInit = true; |
| 345 | e.help.dataset.tabLabel = 'Help'; |
| 346 | this.#tabs.addTab(e.help); |
| 347 | |
| 348 | if( opt.hiddenFields ){ |
| 349 | this.addHiddenFields( opt.hiddenFields ); |
| 350 | delete opt.hiddenFields; |
| 351 | } |
| 352 | |
| 353 | { /* Shift-enter pieces... */ |
| 354 | const eCb = D.checkbox(1); |
| 355 | const eLbl = D.label(); |
| 356 | const eHelp = D.append( |
| 357 | D.span(), [ |
| 358 | 'When checked, shift-enter will toggle between preview ', |
| 359 | 'and edit modes, which is generally useful but some ', |
| 360 | 'software keyboards misinteract with it. If the preview ', |
| 361 | 'starts when tapping Enter, turn this setting off.' |
| 362 | ].join('') |
| 363 | ); |
| 364 | eCb.checked = F.storage.getBool( |
| 365 | 'edit-shift-enter-preview', |
| 366 | true |
| 367 | /* Maintenance reminder: this setting is shared across |
| 368 | several apps, like /chat, /wikiedit, and /fileedit. */ |
| 369 | ); |
| 370 | eCb.addEventListener('change', (ev)=>{ |
| 371 | F.storage.set('edit-shift-enter-preview', eCb.checked); |
| 372 | }); |
| 373 | F.helpButtonlets.setup(eHelp); |
| 374 | eLbl.append("Shift-enter toggles preview?", eCb, eHelp); |
| 375 | e.tabEdit.append(eLbl); |
| 376 | const isShiftEnter = (ev)=>eCb.checked && ev.shiftKey && 13===ev.keyCode; |
| 377 | e.editor.addEventListener('keydown',(ev)=>{ |
| 378 | /** |
| 379 | If eCb.checked is true, a keyboard combo of shift-enter |
| 380 | (from the editor) toggles between preview and edit modes. |
| 381 | This is normally desired but at least one software |
| 382 | keyboard is known to misinteract with this, treating an |
| 383 | Enter after automatically-capitalized letters as a |
| 384 | shift-enter: |
| 385 | |
| 386 | https://fossil-scm.org/forum/forumpost/dbd5b68366147ce8 |
| 387 | */ |
| 388 | if(!isShiftEnter(ev)) return; |
| 389 | ev.preventDefault(); |
| 390 | ev.stopPropagation(); |
| 391 | e.editor.blur(/*force draft update if needed*/); |
| 392 | this.#tabs.switchToTab(e.preview); |
| 393 | }, false); |
| 394 | // If we're in the preview tab, have ctrl-enter switch back to the editor. |
| 395 | document.body.addEventListener('keydown',(ev)=>{ |
| 396 | if(!isShiftEnter(ev)) return; |
| 397 | if(this.#activeTab !== e.tabEdit){ |
| 398 | ev.preventDefault(); |
| 399 | ev.stopPropagation(); |
| 400 | this.#tabs.switchToTab(e.tabEdit); |
| 401 | e.editor.focus(/*slow as molasses for long docs, as focus() |
| 402 | forces a document reflow. */); |
| 403 | return false; |
| 404 | } |
| 405 | }, true); |
| 406 | }/*shift-enter preview bits*/ |
| 407 | |
| 408 | if(0){ /* Needs to be optional */ |
| 409 | const elemsToToggle = document.body.querySelectorAll( |
| 410 | ':scope > header, :scope > nav' |
| 411 | ); |
| 412 | e.button.toggleHeader = |
| 413 | D.button('Toggle header', e=>{ |
| 414 | for(const et of elemsToToggle){ |
| 415 | et.classList.toggle('hidden'); |
| 416 | } |
| 417 | }); |
| 418 | e.buttons.append(e.button.toggleHeader); |
| 419 | } |
| 420 | |
| 421 | { |
| 422 | const eLbl = D.label(false, "Posting as "+F.user.name) |
| 423 | eLbl.classList.add('logged-in-as'); |
| 424 | e.buttons.append(eLbl); |
| 425 | } |
| 426 | |
| 427 | }/*constructor*/ |
| 428 | |
| 429 | /* |
| 430 | ** Removes this object from the DOM. It has no side effects if |
| 431 | ** it's not in the DOM. |
| 432 | */ |
| 433 | close(){ |
| 434 | const e = this.#e.widget; |
| 435 | if( e?.parentNode ){ |
| 436 | if( this.#opt.onclose instanceof Function ){ |
| 437 | try{this.#opt.onclose();} |
| 438 | catch(e){ |
| 439 | console.error("ForumPostEditor.onclose() threw:",e); |
| 440 | } |
| 441 | } |
| 442 | //console.debug("FPE discarding", this); |
| 443 | e.classList.add('animate-exit'); |
| 444 | e.addEventListener('animationend', ()=>e.remove(), {once: true}); |
| 445 | dummyPadding.refs.delete(this); |
| 446 | if( 0===dummyPadding.refs.size ){ |
| 447 | dummyPadding.remove(); |
| 448 | } |
| 449 | } |
| 450 | } |
| 451 | |
| 452 | /* |
| 453 | ** Discards any draft edits then calls close(). If an ondiscard |
| 454 | ** callback was provided to the constructor then it is called |
| 455 | ** before the drafts are cleared and any exceptions it throws are |
| 456 | ** ignored (but may be logged). |
| 457 | */ |
| 458 | discard(){ |
| 459 | if( this.#opt.ondiscard instanceof Function ){ |
| 460 | try{this.#opt.ondiscard(this);} |
| 461 | catch(e){ |
| 462 | console.error("ForumPostEditor.ondiscard() threw:",e); |
| 463 | } |
| 464 | } |
| 465 | this.#clearDraft(); |
| 466 | this.close(); |
| 467 | } |
| 468 | |
| 469 | /** This widget's top-most DOM element. */ |
| 470 | get widget(){ |
| 471 | if( !dummyPadding.parentElement ){ |
| 472 | document.body.append(dummyPadding); |
| 473 | } |
| 474 | dummyPadding.refs.add(this); |
| 475 | return this.#e.widget; |
| 476 | } |
| 477 | |
| 478 | get editorContent(){ |
| 479 | /* We wrap access to the editor's contents in a getter/setter so |
| 480 | that we can eventually add optional use of a contenteditable |
| 481 | edit field, as those are generally more comfortable. The code |
| 482 | for that is in fossil.page.chat.js. */ |
| 483 | return this.#e.editor.value; |
| 484 | } |
| 485 | |
| 486 | set editorContent(v){ |
| 487 | this.#e.editor.value = v; |
| 488 | } |
| 489 | |
| 490 | /** |
| 491 | Reports an error by appending each argument to the error widget |
| 492 | and unhiding it. If passed no arugments, it clears and hides |
| 493 | the error widget. |
| 494 | */ |
| 495 | reportError(...msg){ |
| 496 | const e = this.#e.error; |
| 497 | D.clearElement(e); |
| 498 | if( msg.length ){ |
| 499 | console.error('ForumPostEditor:',...msg); |
| 500 | e.classList.remove('hidden'); |
| 501 | e.append( |
| 502 | ...msg, D.br(), |
| 503 | D.button("Clear", ()=>this.reportError()) |
| 504 | /* Looks horrid in the Blitz skin */ |
| 505 | ); |
| 506 | }else{ |
| 507 | e.classList.add('hidden'); |
| 508 | } |
| 509 | } |
| 510 | |
| 511 | /** |
| 512 | Adds a list of input[type=hidden] form fields to this object, |
| 513 | imported from the server-generated HTML. This is used for |
| 514 | collecting, e.g., the CSRF token and an initial page title. |
| 515 | */ |
| 516 | addHiddenFields(list){ |
| 517 | this.#extraFields ??= []; |
| 518 | for( const f of list ){ |
| 519 | if( !f ) continue; |
| 520 | if( 'title'===f.name && this.#e.title ){ |
| 521 | if( f.value && this.#opt.isNewThread && !this.#e.title.value ){ |
| 522 | this.#e.title.value = f.value; |
| 523 | } |
| 524 | }else{ |
| 525 | this.#extraFields.push(f); |
| 526 | } |
| 527 | } |
| 528 | } |
| 529 | |
| 530 | get mimetype(){ |
| 531 | return this.#e.mimetype.select.value; |
| 532 | } |
| 533 | |
| 534 | get title(){ |
| 535 | return this.#e.title?.value || this.#opt.edit?.H; |
| 536 | } |
| 537 | |
| 538 | #initHelpTab(){ |
| 539 | const eh = this.#e.help; |
| 540 | const list = D.ul(); |
| 541 | D.append( |
| 542 | D.li(list), |
| 543 | D.attr(D.a(F.repoUrl('markup_help'), 'Markup styles'), |
| 544 | 'target', '_new') |
| 545 | ); |
| 546 | D.append( |
| 547 | D.li(list), |
| 548 | "WARNING: draft edits are keyed on the ID of the message they ", |
| 549 | "are editing or responding to. Attempting to edit or reply to ", |
| 550 | "the same post from multiple tabs will cause the most-recently-edited ", |
| 551 | "one to overwrite the draft slot for that post. In browsers which support ", |
| 552 | "Web Locks, a second attempt to edit or reply to a post will be blocked ", |
| 553 | "and an error will be shown explaining the problem." |
| 554 | ); |
| 555 | if( this.#e.status ){ |
| 556 | D.append( |
| 557 | D.li(list), |
| 558 | "Tip: changing just the status in the editor will change only that, ", |
| 559 | "not a whole new (but unedited) copy of the post." |
| 560 | ); |
| 561 | } |
| 562 | eh.append(list); |
| 563 | } |
| 564 | |
| 565 | #initAttacherTab(){ |
| 566 | this.#att = new F.Attacher({ |
| 567 | reverse: true |
| 568 | }); |
| 569 | if( this.#opt.edit ){ |
| 570 | const eNote = D.append( |
| 571 | D.div(), |
| 572 | "Tip: attachments can be added to posts without editing them ", |
| 573 | "by visiting ", |
| 574 | D.attr( |
| 575 | D.a(F.repoUrl('attachadd?target='+this.#opt.edit.uuid), '/attachadd'), |
| 576 | 'target', |
| 577 | '_new' |
| 578 | ), |
| 579 | ".", |
| 580 | ); |
| 581 | this.#e.tabAttach.append(eNote); |
| 582 | } |
| 583 | this.#e.tabAttach.append(this.#att.widget); |
| 584 | } |
| 585 | |
| 586 | #newFormData(addThisContent){ |
| 587 | const fd = new FormData; |
| 588 | for(const f of this.#extraFields){ |
| 589 | fd.append(f.name, f.value); |
| 590 | } |
| 591 | let v; |
| 592 | if( this.#opt.inReplyTo ){ |
| 593 | fd.append( 'firt', this.#opt.inReplyTo ); |
| 594 | }else if( (v = (this.#e.title?.value?.trim?.() || this.#opt.edit?.H)) ){ |
| 595 | fd.append('title', v); |
| 596 | } |
| 597 | fd.append('mimetype', this.mimetype); |
| 598 | fd.append('content', addThisContent || this.editorContent.trim()); |
| 599 | return fd; |
| 600 | } |
| 601 | |
| 602 | async #fetchPreview(content){ |
| 603 | /* TODO: fetch preview */ |
| 604 | const e = this.#e; |
| 605 | const fd = /*no: this.#newFormData(content); */ |
| 606 | new FormData; |
| 607 | let ext; |
| 608 | switch(this.mimetype){ |
| 609 | case 'text/x-markdown': ext = 'md'; break; |
| 610 | case 'text/x-fossil-wiki': ext = 'wiki'; break; |
| 611 | default: ext = 'txt'; break; |
| 612 | } |
| 613 | fd.append('filename', 'x.'+ext/*for mimetype determination*/); |
| 614 | fd.append('content', this.editorContent.trim()); |
| 615 | return window |
| 616 | .fetch(F.repoUrl('ajax/preview-text'),{ |
| 617 | method: 'POST', |
| 618 | body: fd |
| 619 | }) |
| 620 | .then(r=>r.text()) |
| 621 | .then(t=>{ |
| 622 | if( /^\{.*}$/.test(t) ){ |
| 623 | const o = JSON.parse(t); |
| 624 | throw new Error(o.error); |
| 625 | } |
| 626 | return t; |
| 627 | }); |
| 628 | } |
| 629 | |
| 630 | #setPreviewContent(rawHtml){ |
| 631 | /** |
| 632 | Append the new content then remove the old, to help reduce |
| 633 | jumping-around of the UI if the preview is cleared then |
| 634 | repopulated. |
| 635 | */ |
| 636 | const preview = this.#e.preview; |
| 637 | const childs = [...preview.childNodes]; |
| 638 | D.parseHtml(preview, rawHtml); |
| 639 | D.remove(childs); |
| 640 | //preview.style.removeProperty('height'); |
| 641 | if(F.pikchr && 'text/x-markdown'===this.mimetype){ |
| 642 | F.pikchr.addSrcView( |
| 643 | preview.querySelectorAll('svg.pikchr') |
| 644 | ); |
| 645 | } |
| 646 | } |
| 647 | |
| 648 | async #preview(){ |
| 649 | if( this.#isWaiting ) return; |
| 650 | const e = this.#e; |
| 651 | if( e.preview !== this.#activeTab ){ |
| 652 | this.#tabs.switchToTab(e.preview); |
| 653 | /* Will recurse into here */ |
| 654 | return; |
| 655 | } |
| 656 | const content = this.editorContent.trim(); |
| 657 | //console.debug("content to preview", content); |
| 658 | if( !content ){ |
| 659 | return; |
| 660 | } |
| 661 | if( 0 |
| 662 | && !e.preview.firstElementChild ){ |
| 663 | /* On an initial first preview, inherit the editor's height to |
| 664 | reduce jumping-around of the UI. */ |
| 665 | if( 0 /* does not work: height of the editor is "auto" */ ){ |
| 666 | const c = window.getComputedStyle(e.editor/*tabEdit*/); |
| 667 | e.preview.style.height = c.height; |
| 668 | }else{ |
| 669 | e.preview.style.height = '20em'; |
| 670 | } |
| 671 | } |
| 672 | this.#isWaiting = true; |
| 673 | D.disable(this.#toDisable, e.button.submit); |
| 674 | this.#fetchPreview(content) |
| 675 | .then((c)=>{ |
| 676 | this.#setPreviewContent(c); |
| 677 | D.enable(e.button.submit); |
| 678 | }) |
| 679 | .catch(err=>{ |
| 680 | e.preview.textContent = "Error fetching preview: "+err.message; |
| 681 | console.error("Error fetching preview:",err); |
| 682 | this.reportError(err.message); |
| 683 | }) |
| 684 | .finally(()=>{ |
| 685 | this.#isWaiting = false; |
| 686 | D.enable(this.#toDisable); |
| 687 | }); |
| 688 | } |
| 689 | |
| 690 | #validate(tgt){ |
| 691 | if( this.#e.title ){ |
| 692 | const v = this.#e.title.value.trim(); |
| 693 | if( !v ){ |
| 694 | this.reportError("A non-empty title is required."); |
| 695 | return; |
| 696 | } |
| 697 | } |
| 698 | return true; |
| 699 | } |
| 700 | |
| 701 | #submit(){ |
| 702 | if( this.#isWaiting ) return; |
| 703 | if( !this.#validate() ) return; |
| 704 | this.#isWaiting = true; |
| 705 | const e = this.#e; |
| 706 | D.disable(e.button.submit); |
| 707 | const fd = this.#newFormData(); |
| 708 | if( this.#e.status ){ |
| 709 | /* Send the status only if it was modified, otherwise we may |
| 710 | add a superfluous tag. */ |
| 711 | const v = this.#e.status.value; |
| 712 | if( this.#e.status.dataset.originalValue !== v ){ |
| 713 | fd.append("status", v); |
| 714 | } |
| 715 | } |
| 716 | if( e.debug ){ |
| 717 | e.debug.querySelectorAll('input[type=checkbox]').forEach(cb=>{ |
| 718 | if( cb.checked ){ |
| 719 | fd.append(cb.value, 1); |
| 720 | //console.debug("Forum post debug option:",cb); |
| 721 | } |
| 722 | }); |
| 723 | } |
| 724 | if( this.#att ){ |
| 725 | this.#att.populateFormData(fd); |
| 726 | } |
| 727 | //console.warn("Ready to submit",fd); |
| 728 | if( 0 ){ |
| 729 | this.#isWaiting = false; |
| 730 | return; |
| 731 | } |
| 732 | const resp = window.fetch(F.repoUrl('forumajax_save'), { |
| 733 | method: 'POST', |
| 734 | body: fd |
| 735 | }).then(r=>r.json()) |
| 736 | .then(j=>{ |
| 737 | j = F.nu(j); |
| 738 | console.debug("forum post editor response:",j); |
| 739 | if( j.error ){ |
| 740 | throw new Error(j.error); |
| 741 | }else if( j.message ){ |
| 742 | /* This is only for use in debugging during |
| 743 | * development. */ |
| 744 | this.reportError(j.message); |
| 745 | return; |
| 746 | } |
| 747 | if( 1 ){ |
| 748 | this.#clearDraft(); |
| 749 | if( this.#opt.onsubmit instanceof Function ){ |
| 750 | try{this.#opt.onsubmit(this, j);} |
| 751 | catch(e){ |
| 752 | console.error("ForumPostEditor.onsubmit() threw: ", e); |
| 753 | } |
| 754 | } |
| 755 | /* |
| 756 | if( this.#opt.edit?.uuid === j.uuid ) then we know the |
| 757 | content did not change, but it's possible that attachments |
| 758 | and/or a status tag did. Ergo, we need to unconditionally |
| 759 | reload to render those changes (if any). The other option |
| 760 | is to tell the user "nothing changed" and leave them in |
| 761 | the editor, but that could be a lie because we don't know |
| 762 | if any attachments or tags were changed. |
| 763 | */ |
| 764 | else if( 0 ){ |
| 765 | if( this.#opt.edit.uuid === j.uuid |
| 766 | && !j.statusModified && 0===j.attachedCount ){ |
| 767 | this.reportError("No changes made."); |
| 768 | }else{ |
| 769 | window.location = F.repoUrl('forumpost/'+j.uuid); |
| 770 | setTimeout(()=>this.close(), 500/*just in case not redirected*/); |
| 771 | } |
| 772 | } |
| 773 | }else{ |
| 774 | this.reportError( |
| 775 | "Saving worked but we're ignoring it and staying here." |
| 776 | ); |
| 777 | } |
| 778 | }) |
| 779 | .catch((e)=>this.reportError(e.message)) |
| 780 | .finally(()=>this.#isWaiting = false); |
| 781 | } |
| 782 | |
| 783 | #storeDraft(){ |
| 784 | if( this.#draft ){ |
| 785 | this.#draft.mtime = Date.now(); |
| 786 | F.storage.setJSON(this.#opt.draftKey, this.#draft); |
| 787 | } |
| 788 | } |
| 789 | |
| 790 | /** Clears any persistent draft state. Does not clear the UI |
| 791 | widgets. */ |
| 792 | #clearDraft(){ |
| 793 | if( this.#draft ){ |
| 794 | F.storage.remove(this.#opt.draftKey); |
| 795 | this.#draft = F.nu(); |
| 796 | } |
| 797 | } |
| 798 | |
| 799 | /** |
| 800 | Looks for editing draft keys matching either a fixed key or a |
| 801 | regex, and removes each matching one which is older than the |
| 802 | given number of days. Pass days=0 to purge all entries |
| 803 | immediately. |
| 804 | */ |
| 805 | static purgeOldDrafts(key, days=10){ |
| 806 | const age = (3600 * 24 * days) * 1000/*ms*/; |
| 807 | const now = Date.now(); |
| 808 | const check = (k)=>{ |
| 809 | const o = F.storage.getJSON(k); |
| 810 | if( o && o.mtime && (!days || (o.mtime+age <= now)) ){ |
| 811 | F.storage.remove(k); |
| 812 | } |
| 813 | }; |
| 814 | if( key instanceof RegExp ){ |
| 815 | for(const k of F.storage.keys(false).filter(v=>key.test(v))){ |
| 816 | check(k); |
| 817 | } |
| 818 | }else{ |
| 819 | check(key); |
| 820 | } |
| 821 | } |
| 822 | |
| 823 | async #fetchPost(){ |
| 824 | /* |
| 825 | TODO: when editing an existing post, fetch the raw body of the |
| 826 | post and populate this.e. |
| 827 | */ |
| 828 | } |
| 829 | }/*ForumPostEditor*/; |
| 830 | F.ForumPostEditor = ForumPostEditor; |
| 831 | |
| 832 | /** |
| 833 | When the page is loaded, this handler does the following: |
| 834 | |
| 835 | 1. Installs expand/collapse UI elements on "long" posts and collapses |
| 836 | them. |
| 837 | |
| 838 | 2. Any pikchr-generated SVGs get a source-toggle button added to them |
| 839 | which activates when the mouse is over the image or it is tapped. |
| 840 | |
| 841 | 3. Plugs in a new edit/reply widget to forum posts. |
| 842 | |
| 843 | This is a harmless no-op if the current page has neither forum |
| 844 | post constructs for (1) and (3) nor any pikchr images for (2), |
| 845 | nor will NOT running this code cause any breakage for clients |
| 846 | with no JS support: this is all "nice-to-have", not required |
| 847 | functionality. |
| 848 | */ |
| 849 | F.onPageLoad(function(){ |
| 850 | const scrollbarIsVisible = (e)=>e.scrollHeight > e.clientHeight; |
| 851 | /* Returns an event handler which implements the post expand/collapse toggle |
| 852 | on contentElem when the given widget is activated. */ |
| @@ -94,42 +922,474 @@ | |
| 922 | forumPostWrapper.appendChild(widget); |
| 923 | } |
| 924 | content.appendChild(rightTapZone); |
| 925 | rightTapZone.addEventListener('click', widgetEventHandler, false); |
| 926 | refillTapZone(); |
| 927 | })/*for-each div.forumTime|div.forumEdit*/; |
| 928 | |
| 929 | if(F.pikchr){ |
| 930 | F.pikchr.addSrcView(); |
| 931 | } |
| 932 | |
| 933 | const eStatus = document.querySelector( |
| 934 | 'form div.submenu select.submenuctrl[name="status"]' |
| 935 | ); |
| 936 | if( eStatus ){ |
| 937 | /* Main /forum list. Remove the 'x' form element when eStatus |
| 938 | changes, to avoid propagating x when changing the filter. |
| 939 | The problem this solves: we're browsed to page 3 of status X. |
| 940 | We change the status filter selection to Y. We're redirected |
| 941 | to page x, but Y only has 2 posts with that status, so we see |
| 942 | an empty list. When changing the filter, we need to ensure |
| 943 | that we start back and that beginning. */ |
| 944 | const pForm = eStatus.parentElement?.parentElement; |
| 945 | if( pForm ){ |
| 946 | eStatus.addEventListener('change', ()=>{ |
| 947 | pForm.querySelector('input[type="hidden"][name="x"]')?.remove?.(); |
| 948 | }, true); |
| 949 | } |
| 950 | }else{ |
| 951 | /* One of the single-post edit/view pages. Handle various UI |
| 952 | controls and attempt to keep stray double-clicks from |
| 953 | double-posting. |
| 954 | https://fossil-scm.org/forum/info/6bd02466533aa131 */ |
| 955 | const formSubmitted = function(event){ |
| 956 | const form = event.target; |
| 957 | if( form.dataset.submitted ){ |
| 958 | event.preventDefault(); |
| 959 | return; |
| 960 | } |
| 961 | form.dataset.submitted = '1'; |
| 962 | /** If the user is left waiting "a long time," disable the |
| 963 | resubmit protection. If we don't do this and they tap the |
| 964 | browser's cancel button while waiting, they'll be stuck |
| 965 | with an unsubmittable form. It can apparently also happen, |
| 966 | via browser-back, that the form gets left in a submitted |
| 967 | state. */ |
| 968 | setTimeout(()=>{delete form.dataset.submitted}, 7000); |
| 969 | return; |
| 970 | }; |
| 971 | |
| 972 | document.querySelectorAll("form").forEach(function(form){ |
| 973 | /* Set up controls for closing posts and setting thread |
| 974 | status. */ |
| 975 | form.addEventListener('submit', formSubmitted); |
| 976 | form |
| 977 | .querySelectorAll("input.action-close, input.action-reopen") |
| 978 | .forEach(function(e){ |
| 979 | e.classList.remove('hidden'); |
| 980 | F.confirmer(e, { |
| 981 | confirmText: (e.classList.contains('action-reopen') |
| 982 | ? "Confirm re-open" |
| 983 | : "Confirm close"), |
| 984 | onconfirm: ()=>form.submit() |
| 985 | }); |
| 986 | }); |
| 987 | form |
| 988 | .querySelectorAll("input[type='button'].action-status") |
| 989 | .forEach(function(btn){ |
| 990 | btn.classList.remove('hidden'); |
| 991 | const sel = btn.previousElementSibling; |
| 992 | const updateButton = ()=>{ |
| 993 | /* Enable btn only when the status has been locally |
| 994 | modified. */ |
| 995 | if( sel.dataset.initialValue ){ |
| 996 | if( sel.dataset.initialValue===sel.value ){ |
| 997 | btn.setAttribute('disabled',''); |
| 998 | }else{ |
| 999 | btn.removeAttribute('disabled'); |
| 1000 | } |
| 1001 | }else{ |
| 1002 | if(sel.selectedIndex===0){ |
| 1003 | btn.setAttribute('disabled',''); |
| 1004 | }else{ |
| 1005 | btn.removeAttribute('disabled'); |
| 1006 | } |
| 1007 | } |
| 1008 | }; |
| 1009 | sel.addEventListener('change', updateButton, true); |
| 1010 | updateButton(); |
| 1011 | F.confirmer(btn, { |
| 1012 | confirmText: "Confirm status change", |
| 1013 | onconfirm: ()=>form.submit() |
| 1014 | }); |
| 1015 | }); |
| 1016 | }); |
| 1017 | } |
| 1018 | |
| 1019 | /* Apply page-specific tweaks for ForumPostEditor instance fpe |
| 1020 | then plug it into the UI at the end of ePost. */ |
| 1021 | const initFPEWidget = (fpe, ePost)=>{ |
| 1022 | ePost.eUnhideThenWhenDone = [ |
| 1023 | /* List of elements to hide while editing/replying and reveal |
| 1024 | when discarding or saving. */ |
| 1025 | ]; |
| 1026 | for( const ee of ePost.querySelectorAll( |
| 1027 | '.forumpost-single-controls, fieldset.forum-status-selection' |
| 1028 | ) ){ |
| 1029 | ee.hidden = true; |
| 1030 | ePost.eUnhideThenWhenDone.push(ee); |
| 1031 | } |
| 1032 | const w = fpe.widget; |
| 1033 | w.classList.add('animate-entrance'); |
| 1034 | ePost.append(w); |
| 1035 | requestAnimationFrame(() => { |
| 1036 | w.scrollIntoView({ |
| 1037 | behavior: 'smooth', |
| 1038 | block: 'nearest', |
| 1039 | inline: 'nearest' |
| 1040 | }); |
| 1041 | }); |
| 1042 | }; |
| 1043 | |
| 1044 | const plugInEditor = |
| 1045 | (new URL(window.location).searchParams).get('nojs')===null; |
| 1046 | |
| 1047 | const eForumNew = ( |
| 1048 | plugInEditor |
| 1049 | && ( |
| 1050 | document.body.classList.contains('cpage-forumnew') |
| 1051 | || document.body.classList.contains('cpage-forume1') |
| 1052 | )) |
| 1053 | ? document.body.querySelector('#forumnew-placeholder') |
| 1054 | : null; |
| 1055 | if( plugInEditor && eForumNew ){ |
| 1056 | /* /forumnew and /forume1 */ |
| 1057 | const fpe = new F.ForumPostEditor({ |
| 1058 | draftKey: 'draft-forumnew', |
| 1059 | hiddenFields: eForumNew.querySelectorAll('input[type=hidden]'), |
| 1060 | hideStash: true, |
| 1061 | ondiscard: ()=>{ |
| 1062 | window.location = F.repoUrl('forum'); |
| 1063 | }, |
| 1064 | onsubmit: (fpe, response)=>{ |
| 1065 | window.location = F.repoUrl('forumpost/'+response.uuid); |
| 1066 | } |
| 1067 | }); |
| 1068 | eForumNew.parentElement.insertBefore(fpe.widget, eForumNew); |
| 1069 | eForumNew.remove(); |
| 1070 | fossil.page.fpe = fpe /* for testing via the console */; |
| 1071 | }/*eForumNew*/ |
| 1072 | else if( plugInEditor |
| 1073 | && (document.body.classList.contains('cpage-forumpost') |
| 1074 | || document.body.classList.contains('cpage-forumthread')) ){ |
| 1075 | /* /forumpost and /forumthread. Take over the Edit/Reply buttons |
| 1076 | to use a ForumPostEditor. */ |
| 1077 | |
| 1078 | const fetchPost = async (fpid)=>{ |
| 1079 | return window.fetch(F.repoUrl('ajax/artifact.json?uuid='+fpid)) |
| 1080 | .then(r=>r.json()) |
| 1081 | .then(j=>{ |
| 1082 | j = F.nu(j); |
| 1083 | if( j.error ) throw new Error(j.error); |
| 1084 | return j; |
| 1085 | }); |
| 1086 | }; |
| 1087 | |
| 1088 | const makeDraftKey = (prefix,uuid)=>{ |
| 1089 | return prefix+'-'+uuid.substr(0,12); |
| 1090 | }; |
| 1091 | |
| 1092 | /** |
| 1093 | Perform some init common to both Reply and Edit. ePost = the |
| 1094 | forum post DOM element. eButton = the Reply or Edit |
| 1095 | button. |
| 1096 | */ |
| 1097 | const setupEditReplyElement = (ePost, eButton)=>{ |
| 1098 | /* Forum posts are indented in the main forum view to |
| 1099 | represent their place in the hierarchy. In order to gain |
| 1100 | some screen space, we shift the post to the left margin and |
| 1101 | arrange to shift it back when the editor is closed. We also |
| 1102 | record the original button label so that it can be |
| 1103 | restored on close. */ |
| 1104 | ePost.dataset.originalMarginLeft = ePost.style.marginLeft; |
| 1105 | ePost.style.marginLeft = 'initial'; |
| 1106 | eButton.dataset.originalLabel = eButton.innerText; |
| 1107 | }; |
| 1108 | |
| 1109 | /** Undoes the damage done by setupEditReplyElement(). */ |
| 1110 | const restoreEditReplyElement = (ePost, eButton)=>{ |
| 1111 | if( ePost.dataset.originalMarginLeft ){ |
| 1112 | ePost.style.marginLeft = ePost.dataset.originalMarginLeft; |
| 1113 | delete ePost.dataset.originalMarginLeft; |
| 1114 | } |
| 1115 | if( eButton.dataset.originalLabel ){ |
| 1116 | eButton.innerText = eButton.dataset.originalLabel; |
| 1117 | delete eButton.dataset.originalLabel; |
| 1118 | } |
| 1119 | for(const ee of (ePost.eUnhideThenWhenDone || [])){ |
| 1120 | ee.removeAttribute('hidden'); |
| 1121 | } |
| 1122 | ePost.eUnhideThenWhenDone = undefined; |
| 1123 | }; |
| 1124 | |
| 1125 | /** |
| 1126 | Reports an error regarding the forum post element |
| 1127 | ePost, appending each entry in msg to a wrapper |
| 1128 | element with the class |
| 1129 | */ |
| 1130 | const reportFPEError = (ePost,...msg)=>{ |
| 1131 | const e = D.addClass(D.p(), 'error'); |
| 1132 | e.append( |
| 1133 | ...msg, |
| 1134 | D.br(), |
| 1135 | D.button("Clear error", ()=>e.remove()) |
| 1136 | ); |
| 1137 | ePost.append(e); |
| 1138 | }; |
| 1139 | |
| 1140 | /** |
| 1141 | Plug in an editor widget representing a reply to a post. |
| 1142 | form = a (.forum-post-single-controls > form) element. The |
| 1143 | final 3 arguments are as documented for |
| 1144 | setupEditReplyElement(). |
| 1145 | */ |
| 1146 | const replyClicked = async (form, ePost, eBtnReply)=>{ |
| 1147 | const fpid = ePost.dataset.fpid; |
| 1148 | const fEditHead = ePost.dataset.fedithead; |
| 1149 | const draftKey = makeDraftKey( |
| 1150 | 'draft-reply', fEditHead |
| 1151 | /* The problem with firt as a key is that firt is not |
| 1152 | necessarily the root edit of that post, which is what we |
| 1153 | really want as a draft key so that the draft does not |
| 1154 | disappear if firt is later edited (giving us a new firt |
| 1155 | value here). */ |
| 1156 | || fpid |
| 1157 | ); |
| 1158 | let releaseLock; |
| 1159 | if( window.navigator.locks ){ |
| 1160 | releaseLock = await new Promise((resolve)=>{ |
| 1161 | window.navigator.locks.request( |
| 1162 | 'fossil-'+draftKey, |
| 1163 | {ifAvailable: true}, |
| 1164 | async (lock) => { |
| 1165 | if( !lock ){ |
| 1166 | /*lock contention*/ |
| 1167 | resolve(null); |
| 1168 | return; |
| 1169 | } |
| 1170 | let release; |
| 1171 | const lockReleased = new Promise(res=>release=res); |
| 1172 | resolve(release); |
| 1173 | await lockReleased/*hold the lock open*/; |
| 1174 | }); |
| 1175 | }); |
| 1176 | if( !releaseLock ){ |
| 1177 | reportFPEError( |
| 1178 | ePost, |
| 1179 | "This post is actively being replied to ", |
| 1180 | "in another tab. To avoid losing edits, ", |
| 1181 | "it cannot be opened here until the locking ", |
| 1182 | "tab is closed." |
| 1183 | ); |
| 1184 | return; |
| 1185 | } |
| 1186 | } |
| 1187 | |
| 1188 | setupEditReplyElement(ePost, eBtnReply); |
| 1189 | eBtnReply.innerText = "Replying..."; |
| 1190 | const ondone = (fpe, response)=>{ |
| 1191 | /* onsubmit() and ondiscard() callback */ |
| 1192 | restoreEditReplyElement(ePost, eBtnReply); |
| 1193 | //console.debug("ondiscard/onsubmit", fpe, artifact); |
| 1194 | if( response/*onsubmit()*/ ){ |
| 1195 | window.location = F.repoUrl('forumpost/'+response.uuid); |
| 1196 | setTimeout(()=>fpe.close(), 500/*just in case not redirected*/); |
| 1197 | }else{/*ondiscard() or onclose()*/ |
| 1198 | } |
| 1199 | }; |
| 1200 | const fpe = new F.ForumPostEditor(F.nu({ |
| 1201 | hiddenFields: form.querySelectorAll( |
| 1202 | 'input[type=hidden][name=csrf]' |
| 1203 | /* Do not inherit the fpid field, else this will become |
| 1204 | an edit to that post rather than a response. */ |
| 1205 | ), |
| 1206 | ondiscard: ()=>{/*need a noop here. Will call onclose()*/}, |
| 1207 | onsubmit: ondone, |
| 1208 | onclose: ()=>{ |
| 1209 | if( releaseLock ){ |
| 1210 | releaseLock(); |
| 1211 | releaseLock = null; |
| 1212 | } |
| 1213 | ondone(); |
| 1214 | }, |
| 1215 | inReplyTo: fpid, |
| 1216 | draftKey |
| 1217 | })); |
| 1218 | initFPEWidget(fpe, ePost); |
| 1219 | }/*replyClicked()*/; |
| 1220 | |
| 1221 | /** |
| 1222 | Plug in an editor widget representing an edit to a post. |
| 1223 | form = a (.forum-post-single-controls > form) element. The |
| 1224 | final 3 arguments are as documented for |
| 1225 | setupEditReplyElement(). |
| 1226 | */ |
| 1227 | const editClicked = async (form, ePost, eBtnEdit)=>{ |
| 1228 | const fpid = ePost.dataset.fpid; |
| 1229 | const firt = ePost.dataset.firt; |
| 1230 | const fEditHead = ePost.dataset.fedithead; |
| 1231 | const draftKey = makeDraftKey('draft-forumedit', fEditHead || fpid); |
| 1232 | let releaseLock; |
| 1233 | if( navigator.locks ){ |
| 1234 | releaseLock = await new Promise((resolve) => { |
| 1235 | navigator.locks.request( |
| 1236 | 'fossil-'+draftKey, |
| 1237 | {ifAvailable: true}, |
| 1238 | async (lock)=>{ |
| 1239 | if( !lock ){ |
| 1240 | resolve(null); |
| 1241 | return; |
| 1242 | } |
| 1243 | let release; |
| 1244 | const lockReleased = new Promise(res=>release=res); |
| 1245 | resolve(release); |
| 1246 | await lockReleased; |
| 1247 | }); |
| 1248 | }); |
| 1249 | |
| 1250 | if( !releaseLock ){ |
| 1251 | reportFPEError( |
| 1252 | ePost, |
| 1253 | "This post is actively being edited ", |
| 1254 | "in another tab. To avoid losing edits, ", |
| 1255 | "it cannot be opened here until the locking ", |
| 1256 | "tab is closed." |
| 1257 | ); |
| 1258 | return; |
| 1259 | } |
| 1260 | } |
| 1261 | setupEditReplyElement(ePost, eBtnEdit); |
| 1262 | eBtnEdit.innerText = "Editing..."; |
| 1263 | fetchPost(fpid) |
| 1264 | .then(artifact=>{ |
| 1265 | const ondone = (fpe, response)=>{ |
| 1266 | /* onsubmit() and ondiscard() callback */ |
| 1267 | if( response/*onsubmit()*/ ){ |
| 1268 | if( fpid === response.uuid |
| 1269 | && !response.statusModified |
| 1270 | && 0===response.attachedCount ){ |
| 1271 | fpe.reportError("No changes made."); |
| 1272 | }else{ |
| 1273 | restoreEditReplyElement(ePost, eBtnEdit); |
| 1274 | window.location = F.repoUrl('forumpost/'+response.uuid); |
| 1275 | setTimeout(()=>fpe.close(), 500/*just in case not redirected*/); |
| 1276 | } |
| 1277 | }else{ |
| 1278 | /*ondiscard() or onclose()*/ |
| 1279 | restoreEditReplyElement(ePost, eBtnEdit); |
| 1280 | } |
| 1281 | }; |
| 1282 | const eStatusSelect = ePost.querySelector( |
| 1283 | ':scope > fieldset.forum-status-selection select[name=status]' |
| 1284 | ); |
| 1285 | |
| 1286 | const fpe = new F.ForumPostEditor(F.nu({ |
| 1287 | hiddenFields: form.querySelectorAll('input[type=hidden]'), |
| 1288 | ondiscard: ()=>{/*need a noop here. Will call onclose()*/}, |
| 1289 | onsubmit: ondone, |
| 1290 | onclose: ()=>{ |
| 1291 | if(releaseLock){ |
| 1292 | releaseLock(); |
| 1293 | releaseLock = null; |
| 1294 | } |
| 1295 | ondone(); |
| 1296 | }, |
| 1297 | draftKey, |
| 1298 | edit: artifact, |
| 1299 | status: eStatusSelect?.value, |
| 1300 | inReplyTo: firt |
| 1301 | })); |
| 1302 | initFPEWidget(fpe, ePost); |
| 1303 | }) |
| 1304 | .catch(err=>{ |
| 1305 | if( releaseLock ){ |
| 1306 | releaseLock(); |
| 1307 | releaseLock = null; |
| 1308 | } |
| 1309 | restoreEditReplyElement(ePost, eBtnEdit); |
| 1310 | console.error("Error fetching post:", err); |
| 1311 | reportFPEError(ePost, "Error fetching post: ", err.message); |
| 1312 | }); |
| 1313 | }/*editClicked()*/; |
| 1314 | |
| 1315 | document.body.querySelectorAll( |
| 1316 | '.forumpost-single-controls > form' |
| 1317 | ).forEach(form=>{ |
| 1318 | /* For each forum post... */ |
| 1319 | const eThePost = form.parentElement.parentElement/*main post DOM element*/; |
| 1320 | if( !eThePost?.dataset?.fpid ){ |
| 1321 | /* The server injects these dataset values. */ |
| 1322 | console.warn("Unexpected missing fpid", eThePost); |
| 1323 | return; |
| 1324 | } |
| 1325 | const checkButtonForDraft = (draftKeyPrefix, eBtn)=>{ |
| 1326 | /* If a draft is found associated with eThePost, mark eBtn |
| 1327 | as a draft and set up storage event listeners to update |
| 1328 | the button as new drafts come and go. */ |
| 1329 | const fpid = eThePost.dataset.fpid; |
| 1330 | const fEditHead = eThePost.dataset.fedithead; |
| 1331 | const draftKey = makeDraftKey(draftKeyPrefix, fEditHead || fpid); |
| 1332 | if( F.storage.contains(draftKey) ){ |
| 1333 | eBtn.classList.add('draft'); |
| 1334 | } |
| 1335 | F.storage.addEventListener('set', ({detail})=>{ |
| 1336 | if( draftKey === detail.key ){ |
| 1337 | eBtn.classList.add('draft'); |
| 1338 | } |
| 1339 | }); |
| 1340 | F.storage.addEventListener('remove', ({detail})=>{ |
| 1341 | if( draftKey === detail.key ){ |
| 1342 | eBtn.classList.remove('draft'); |
| 1343 | } |
| 1344 | }); |
| 1345 | }; |
| 1346 | /* Replace the Reply and Edit buttons with ones which will activate |
| 1347 | a ForumPostEditor. */ |
| 1348 | const btnReply = form.querySelector('input[type=submit][name=reply]'); |
| 1349 | if( btnReply ){ |
| 1350 | const b = D.button("Reply", ()=>replyClicked(form, eThePost, b)); |
| 1351 | b.type = 'button'/*keep container form from submitting*/; |
| 1352 | checkButtonForDraft('draft-reply',b); |
| 1353 | btnReply.parentElement.insertBefore(b, btnReply); |
| 1354 | btnReply.remove(); |
| 1355 | } |
| 1356 | const btnEdit = form.querySelector('input[type=submit][name=edit]'); |
| 1357 | if( btnEdit ){ |
| 1358 | const b = D.button("Edit", ()=>editClicked(form, eThePost, b)); |
| 1359 | b.type = 'button'/*keep container form from submitting*/; |
| 1360 | checkButtonForDraft('draft-forumedit',b); |
| 1361 | btnEdit.parentElement.insertBefore(b, btnEdit); |
| 1362 | btnEdit.remove(); |
| 1363 | } |
| 1364 | })/*for-each form*/; |
| 1365 | |
| 1366 | }/* /forumpost and /forumthread */ |
| 1367 | |
| 1368 | document.body.querySelectorAll('.remove-on-load').forEach(e=>e.remove()); |
| 1369 | document.body.querySelectorAll('.initially-hidden').forEach(e=>{ |
| 1370 | /* This is a workaround for a span.help-buttonlet which we need |
| 1371 | to start hidden so that it does not show up for no-JS |
| 1372 | clients. */ |
| 1373 | e.classList.remove('initially-hidden'); |
| 1374 | }); |
| 1375 | |
| 1376 | if( plugInEditor ){ |
| 1377 | document.body.querySelectorAll('.remove-if-replaced').forEach( |
| 1378 | /* Remove remaining legacy UI elements. */ e=>e.remove() |
| 1379 | ); |
| 1380 | /* Purge old drafts only every now and then. */ |
| 1381 | const now = Date.now(); |
| 1382 | const lastPurge = +F.storage.get('forum-drafts-last-purge', 0); |
| 1383 | if( now - lastPurge > (24 * 60 * 60 * 1000 /*1 day ms*/) ){ |
| 1384 | F.storage.set('forum-drafts-last-purge', now); |
| 1385 | setTimeout(()=>{ |
| 1386 | /* Don't block the UI while we're doing I/O */ |
| 1387 | F.ForumPostEditor.purgeOldDrafts( |
| 1388 | /^draft-(reply|forumedit)-.*/ |
| 1389 | /* Intentionally leaving draft-forumnew in place. */ |
| 1390 | ); |
| 1391 | }, 50); |
| 1392 | } |
| 1393 | } |
| 1394 | })/*F.onPageLoad callback*/; |
| 1395 | })(window.fossil); |
| 1396 |
+5
-6
| --- src/fossil.page.wikiedit.js | ||
| +++ src/fossil.page.wikiedit.js | ||
| @@ -1187,11 +1187,11 @@ | ||
| 1187 | 1187 | if(!wi.attachments || !wi.attachments.length){ |
| 1188 | 1188 | D.append(f.eAttach, |
| 1189 | 1189 | btnReload, |
| 1190 | 1190 | " No attachments found for page ["+wi.name+"]. ", |
| 1191 | 1191 | D.a(F.repoUrl('attachadd',{ |
| 1192 | - page: wi.name, | |
| 1192 | + target: wi.name, | |
| 1193 | 1193 | from: F.repoUrl('wikiedit',{name: wi.name})}), |
| 1194 | 1194 | "Add attachments..." ) |
| 1195 | 1195 | ); |
| 1196 | 1196 | return this; |
| 1197 | 1197 | } |
| @@ -1198,14 +1198,14 @@ | ||
| 1198 | 1198 | D.append( |
| 1199 | 1199 | f.eAttach, |
| 1200 | 1200 | D.append(D.p(), |
| 1201 | 1201 | btnReload," ", |
| 1202 | 1202 | D.a(F.repoUrl('attachlist',{page:wi.name}), |
| 1203 | - "Attachments for page ["+wi.name+"]."), | |
| 1204 | - " ", | |
| 1203 | + "Attachments for page ["+wi.name+"]"), | |
| 1204 | + ". ", | |
| 1205 | 1205 | D.a(F.repoUrl('attachadd',{ |
| 1206 | - page:wi.name, | |
| 1206 | + target:wi.name, | |
| 1207 | 1207 | from: F.repoUrl('wikiedit',{name: wi.name})}), |
| 1208 | 1208 | "Add attachments..." ) |
| 1209 | 1209 | ) |
| 1210 | 1210 | ); |
| 1211 | 1211 | wi.attachments.forEach(function(a){ |
| @@ -1388,11 +1388,10 @@ | ||
| 1388 | 1388 | setting. |
| 1389 | 1389 | */ |
| 1390 | 1390 | P.baseHrefRestore = function(){ |
| 1391 | 1391 | this.base.tag.href = this.base.originalHref; |
| 1392 | 1392 | }; |
| 1393 | - | |
| 1394 | 1393 | |
| 1395 | 1394 | /** |
| 1396 | 1395 | loadPage() loads the given wiki page and updates the relevant |
| 1397 | 1396 | UI elements to reflect the loaded state. If passed no arguments |
| 1398 | 1397 | then it re-uses the values from the currently-loaded page, reloading |
| @@ -1454,11 +1453,11 @@ | ||
| 1454 | 1453 | onload(r); |
| 1455 | 1454 | } |
| 1456 | 1455 | }); |
| 1457 | 1456 | return this; |
| 1458 | 1457 | }; |
| 1459 | - | |
| 1458 | + | |
| 1460 | 1459 | /** |
| 1461 | 1460 | Fetches the page preview based on the contents and settings of |
| 1462 | 1461 | this page's input fields, and updates the UI with the |
| 1463 | 1462 | preview. |
| 1464 | 1463 | |
| 1465 | 1464 |
| --- src/fossil.page.wikiedit.js | |
| +++ src/fossil.page.wikiedit.js | |
| @@ -1187,11 +1187,11 @@ | |
| 1187 | if(!wi.attachments || !wi.attachments.length){ |
| 1188 | D.append(f.eAttach, |
| 1189 | btnReload, |
| 1190 | " No attachments found for page ["+wi.name+"]. ", |
| 1191 | D.a(F.repoUrl('attachadd',{ |
| 1192 | page: wi.name, |
| 1193 | from: F.repoUrl('wikiedit',{name: wi.name})}), |
| 1194 | "Add attachments..." ) |
| 1195 | ); |
| 1196 | return this; |
| 1197 | } |
| @@ -1198,14 +1198,14 @@ | |
| 1198 | D.append( |
| 1199 | f.eAttach, |
| 1200 | D.append(D.p(), |
| 1201 | btnReload," ", |
| 1202 | D.a(F.repoUrl('attachlist',{page:wi.name}), |
| 1203 | "Attachments for page ["+wi.name+"]."), |
| 1204 | " ", |
| 1205 | D.a(F.repoUrl('attachadd',{ |
| 1206 | page:wi.name, |
| 1207 | from: F.repoUrl('wikiedit',{name: wi.name})}), |
| 1208 | "Add attachments..." ) |
| 1209 | ) |
| 1210 | ); |
| 1211 | wi.attachments.forEach(function(a){ |
| @@ -1388,11 +1388,10 @@ | |
| 1388 | setting. |
| 1389 | */ |
| 1390 | P.baseHrefRestore = function(){ |
| 1391 | this.base.tag.href = this.base.originalHref; |
| 1392 | }; |
| 1393 | |
| 1394 | |
| 1395 | /** |
| 1396 | loadPage() loads the given wiki page and updates the relevant |
| 1397 | UI elements to reflect the loaded state. If passed no arguments |
| 1398 | then it re-uses the values from the currently-loaded page, reloading |
| @@ -1454,11 +1453,11 @@ | |
| 1454 | onload(r); |
| 1455 | } |
| 1456 | }); |
| 1457 | return this; |
| 1458 | }; |
| 1459 | |
| 1460 | /** |
| 1461 | Fetches the page preview based on the contents and settings of |
| 1462 | this page's input fields, and updates the UI with the |
| 1463 | preview. |
| 1464 | |
| 1465 |
| --- src/fossil.page.wikiedit.js | |
| +++ src/fossil.page.wikiedit.js | |
| @@ -1187,11 +1187,11 @@ | |
| 1187 | if(!wi.attachments || !wi.attachments.length){ |
| 1188 | D.append(f.eAttach, |
| 1189 | btnReload, |
| 1190 | " No attachments found for page ["+wi.name+"]. ", |
| 1191 | D.a(F.repoUrl('attachadd',{ |
| 1192 | target: wi.name, |
| 1193 | from: F.repoUrl('wikiedit',{name: wi.name})}), |
| 1194 | "Add attachments..." ) |
| 1195 | ); |
| 1196 | return this; |
| 1197 | } |
| @@ -1198,14 +1198,14 @@ | |
| 1198 | D.append( |
| 1199 | f.eAttach, |
| 1200 | D.append(D.p(), |
| 1201 | btnReload," ", |
| 1202 | D.a(F.repoUrl('attachlist',{page:wi.name}), |
| 1203 | "Attachments for page ["+wi.name+"]"), |
| 1204 | ". ", |
| 1205 | D.a(F.repoUrl('attachadd',{ |
| 1206 | target:wi.name, |
| 1207 | from: F.repoUrl('wikiedit',{name: wi.name})}), |
| 1208 | "Add attachments..." ) |
| 1209 | ) |
| 1210 | ); |
| 1211 | wi.attachments.forEach(function(a){ |
| @@ -1388,11 +1388,10 @@ | |
| 1388 | setting. |
| 1389 | */ |
| 1390 | P.baseHrefRestore = function(){ |
| 1391 | this.base.tag.href = this.base.originalHref; |
| 1392 | }; |
| 1393 | |
| 1394 | /** |
| 1395 | loadPage() loads the given wiki page and updates the relevant |
| 1396 | UI elements to reflect the loaded state. If passed no arguments |
| 1397 | then it re-uses the values from the currently-loaded page, reloading |
| @@ -1454,11 +1453,11 @@ | |
| 1453 | onload(r); |
| 1454 | } |
| 1455 | }); |
| 1456 | return this; |
| 1457 | }; |
| 1458 | |
| 1459 | /** |
| 1460 | Fetches the page preview based on the contents and settings of |
| 1461 | this page's input fields, and updates the UI with the |
| 1462 | preview. |
| 1463 | |
| 1464 |
+10
-10
| --- src/fossil.popupwidget.js | ||
| +++ src/fossil.popupwidget.js | ||
| @@ -55,11 +55,11 @@ | ||
| 55 | 55 | from the default), the class "fossil-PopupWidget" is always set |
| 56 | 56 | in order to allow certain app-internal CSS to account for popup |
| 57 | 57 | windows in special cases. |
| 58 | 58 | |
| 59 | 59 | .style: optional object of properties to copy directly into |
| 60 | - the element's style object. | |
| 60 | + the element's style object. | |
| 61 | 61 | |
| 62 | 62 | The options passed to this constructor get normalized into a |
| 63 | 63 | separate object which includes any default values for options not |
| 64 | 64 | provided by the caller. That object is available this the |
| 65 | 65 | resulting PopupWidget's options property. Default values for any |
| @@ -161,11 +161,11 @@ | ||
| 161 | 161 | Sidebar: showing/hiding the widget is, as is conventional for |
| 162 | 162 | this framework, done by removing/adding the 'hidden' CSS class |
| 163 | 163 | to it, so that class must be defined appropriately. |
| 164 | 164 | */ |
| 165 | 165 | show: function(){ |
| 166 | - var x = undefined, y = undefined, showIt, | |
| 166 | + let x = undefined, y = undefined, showIt, | |
| 167 | 167 | wasShown = !this.e.classList.contains('hidden'); |
| 168 | 168 | if(2===arguments.length){ |
| 169 | 169 | x = arguments[0]; |
| 170 | 170 | y = arguments[1]; |
| 171 | 171 | showIt = true; |
| @@ -344,11 +344,12 @@ | ||
| 344 | 344 | - No arguments, which is equivalent to passing the string |
| 345 | 345 | ".help-buttonlet:not(.processed)". |
| 346 | 346 | |
| 347 | 347 | Passing the same element(s) more than once is a no-op: during |
| 348 | 348 | initialization, each elements get the class'processed' added to |
| 349 | - it, and any elements with that class are skipped. | |
| 349 | + it, and any elements with that class are skipped. Each element | |
| 350 | + gets the 'help-buttonlet' CSS class added to it. | |
| 350 | 351 | |
| 351 | 352 | All child nodes of a help buttonlet are removed from the button |
| 352 | 353 | during initialization and stashed away for use in a PopupWidget |
| 353 | 354 | when the botton is clicked. |
| 354 | 355 | |
| @@ -374,24 +375,24 @@ | ||
| 374 | 375 | calculate the resulting size, then move and/or resize it. |
| 375 | 376 | |
| 376 | 377 | This algorithm/these heuristics can certainly be improved |
| 377 | 378 | upon. |
| 378 | 379 | */ |
| 379 | - var popupRect, rectElem = ev.target; | |
| 380 | + let popupRect, rectElem = ev.target; | |
| 380 | 381 | while(rectElem){ |
| 381 | 382 | popupRect = rectElem.getClientRects()[0]/*undefined if off-screen!*/; |
| 382 | 383 | if(popupRect) break; |
| 383 | 384 | rectElem = rectElem.parentNode; |
| 384 | 385 | } |
| 385 | 386 | if(!popupRect) popupRect = {x:0, y:0, left:0, right:0}; |
| 386 | - var x = popupRect.left, y = popupRect.top; | |
| 387 | + let x = popupRect.left, y = popupRect.top; | |
| 387 | 388 | if(x<0) x = 0; |
| 388 | 389 | if(y<0) y = 0; |
| 389 | 390 | if(rectElem){ |
| 390 | 391 | /* Try to ensure that the popup's z-level is higher than this element's */ |
| 391 | 392 | const rz = window.getComputedStyle(rectElem).zIndex; |
| 392 | - var myZ; | |
| 393 | + let myZ; | |
| 393 | 394 | if(rz && !isNaN(+rz)){ |
| 394 | 395 | myZ = +rz + 1; |
| 395 | 396 | }else{ |
| 396 | 397 | myZ = 10000/*guess!*/; |
| 397 | 398 | } |
| @@ -416,11 +417,11 @@ | ||
| 416 | 417 | fch.popup.show(x, y); |
| 417 | 418 | return false; |
| 418 | 419 | }; |
| 419 | 420 | f.foreachElement = function(e){ |
| 420 | 421 | if(e.classList.contains('processed')) return; |
| 421 | - e.classList.add('processed'); | |
| 422 | + e.classList.add('processed', 'help-buttonlet'); | |
| 422 | 423 | e.$helpContent = []; |
| 423 | 424 | /* We have to move all child nodes out of the way because we |
| 424 | 425 | cannot hide TEXT nodes via CSS (which cannot select TEXT |
| 425 | 426 | nodes). We have to do it in two steps to avoid invaliding |
| 426 | 427 | the list during traversal. */ |
| @@ -427,11 +428,11 @@ | ||
| 427 | 428 | e.childNodes.forEach((ch)=>e.$helpContent.push(ch)); |
| 428 | 429 | e.$helpContent.forEach((ch)=>ch.remove()); |
| 429 | 430 | e.addEventListener('click', f.clickHandler, false); |
| 430 | 431 | }; |
| 431 | 432 | }/*static init*/ |
| 432 | - var elems; | |
| 433 | + let elems; | |
| 433 | 434 | if(!arguments.length){ |
| 434 | 435 | arguments[0] = '.help-buttonlet:not(.processed)'; |
| 435 | 436 | arguments.length = 1; |
| 436 | 437 | } |
| 437 | 438 | if(arguments.length){ |
| @@ -443,11 +444,11 @@ | ||
| 443 | 444 | elems = arguments[0]; |
| 444 | 445 | } |
| 445 | 446 | } |
| 446 | 447 | if(elems) elems.forEach(f.foreachElement); |
| 447 | 448 | }, |
| 448 | - | |
| 449 | + | |
| 449 | 450 | /** |
| 450 | 451 | Sets up the given element as a "help buttonlet", adding the CSS |
| 451 | 452 | class help-buttonlet to it. Any (optional) arguments after the |
| 452 | 453 | first are appended to the element using fossil.dom.append(), so |
| 453 | 454 | that they become the content for the buttonlet's popup help. |
| @@ -465,7 +466,6 @@ | ||
| 465 | 466 | return elem; |
| 466 | 467 | } |
| 467 | 468 | }/*helpButtonlets*/; |
| 468 | 469 | |
| 469 | 470 | F.onDOMContentLoaded( ()=>F.helpButtonlets.setup() ); |
| 470 | - | |
| 471 | 471 | })(window.fossil); |
| 472 | 472 |
| --- src/fossil.popupwidget.js | |
| +++ src/fossil.popupwidget.js | |
| @@ -55,11 +55,11 @@ | |
| 55 | from the default), the class "fossil-PopupWidget" is always set |
| 56 | in order to allow certain app-internal CSS to account for popup |
| 57 | windows in special cases. |
| 58 | |
| 59 | .style: optional object of properties to copy directly into |
| 60 | the element's style object. |
| 61 | |
| 62 | The options passed to this constructor get normalized into a |
| 63 | separate object which includes any default values for options not |
| 64 | provided by the caller. That object is available this the |
| 65 | resulting PopupWidget's options property. Default values for any |
| @@ -161,11 +161,11 @@ | |
| 161 | Sidebar: showing/hiding the widget is, as is conventional for |
| 162 | this framework, done by removing/adding the 'hidden' CSS class |
| 163 | to it, so that class must be defined appropriately. |
| 164 | */ |
| 165 | show: function(){ |
| 166 | var x = undefined, y = undefined, showIt, |
| 167 | wasShown = !this.e.classList.contains('hidden'); |
| 168 | if(2===arguments.length){ |
| 169 | x = arguments[0]; |
| 170 | y = arguments[1]; |
| 171 | showIt = true; |
| @@ -344,11 +344,12 @@ | |
| 344 | - No arguments, which is equivalent to passing the string |
| 345 | ".help-buttonlet:not(.processed)". |
| 346 | |
| 347 | Passing the same element(s) more than once is a no-op: during |
| 348 | initialization, each elements get the class'processed' added to |
| 349 | it, and any elements with that class are skipped. |
| 350 | |
| 351 | All child nodes of a help buttonlet are removed from the button |
| 352 | during initialization and stashed away for use in a PopupWidget |
| 353 | when the botton is clicked. |
| 354 | |
| @@ -374,24 +375,24 @@ | |
| 374 | calculate the resulting size, then move and/or resize it. |
| 375 | |
| 376 | This algorithm/these heuristics can certainly be improved |
| 377 | upon. |
| 378 | */ |
| 379 | var popupRect, rectElem = ev.target; |
| 380 | while(rectElem){ |
| 381 | popupRect = rectElem.getClientRects()[0]/*undefined if off-screen!*/; |
| 382 | if(popupRect) break; |
| 383 | rectElem = rectElem.parentNode; |
| 384 | } |
| 385 | if(!popupRect) popupRect = {x:0, y:0, left:0, right:0}; |
| 386 | var x = popupRect.left, y = popupRect.top; |
| 387 | if(x<0) x = 0; |
| 388 | if(y<0) y = 0; |
| 389 | if(rectElem){ |
| 390 | /* Try to ensure that the popup's z-level is higher than this element's */ |
| 391 | const rz = window.getComputedStyle(rectElem).zIndex; |
| 392 | var myZ; |
| 393 | if(rz && !isNaN(+rz)){ |
| 394 | myZ = +rz + 1; |
| 395 | }else{ |
| 396 | myZ = 10000/*guess!*/; |
| 397 | } |
| @@ -416,11 +417,11 @@ | |
| 416 | fch.popup.show(x, y); |
| 417 | return false; |
| 418 | }; |
| 419 | f.foreachElement = function(e){ |
| 420 | if(e.classList.contains('processed')) return; |
| 421 | e.classList.add('processed'); |
| 422 | e.$helpContent = []; |
| 423 | /* We have to move all child nodes out of the way because we |
| 424 | cannot hide TEXT nodes via CSS (which cannot select TEXT |
| 425 | nodes). We have to do it in two steps to avoid invaliding |
| 426 | the list during traversal. */ |
| @@ -427,11 +428,11 @@ | |
| 427 | e.childNodes.forEach((ch)=>e.$helpContent.push(ch)); |
| 428 | e.$helpContent.forEach((ch)=>ch.remove()); |
| 429 | e.addEventListener('click', f.clickHandler, false); |
| 430 | }; |
| 431 | }/*static init*/ |
| 432 | var elems; |
| 433 | if(!arguments.length){ |
| 434 | arguments[0] = '.help-buttonlet:not(.processed)'; |
| 435 | arguments.length = 1; |
| 436 | } |
| 437 | if(arguments.length){ |
| @@ -443,11 +444,11 @@ | |
| 443 | elems = arguments[0]; |
| 444 | } |
| 445 | } |
| 446 | if(elems) elems.forEach(f.foreachElement); |
| 447 | }, |
| 448 | |
| 449 | /** |
| 450 | Sets up the given element as a "help buttonlet", adding the CSS |
| 451 | class help-buttonlet to it. Any (optional) arguments after the |
| 452 | first are appended to the element using fossil.dom.append(), so |
| 453 | that they become the content for the buttonlet's popup help. |
| @@ -465,7 +466,6 @@ | |
| 465 | return elem; |
| 466 | } |
| 467 | }/*helpButtonlets*/; |
| 468 | |
| 469 | F.onDOMContentLoaded( ()=>F.helpButtonlets.setup() ); |
| 470 | |
| 471 | })(window.fossil); |
| 472 |
| --- src/fossil.popupwidget.js | |
| +++ src/fossil.popupwidget.js | |
| @@ -55,11 +55,11 @@ | |
| 55 | from the default), the class "fossil-PopupWidget" is always set |
| 56 | in order to allow certain app-internal CSS to account for popup |
| 57 | windows in special cases. |
| 58 | |
| 59 | .style: optional object of properties to copy directly into |
| 60 | the element's style object. |
| 61 | |
| 62 | The options passed to this constructor get normalized into a |
| 63 | separate object which includes any default values for options not |
| 64 | provided by the caller. That object is available this the |
| 65 | resulting PopupWidget's options property. Default values for any |
| @@ -161,11 +161,11 @@ | |
| 161 | Sidebar: showing/hiding the widget is, as is conventional for |
| 162 | this framework, done by removing/adding the 'hidden' CSS class |
| 163 | to it, so that class must be defined appropriately. |
| 164 | */ |
| 165 | show: function(){ |
| 166 | let x = undefined, y = undefined, showIt, |
| 167 | wasShown = !this.e.classList.contains('hidden'); |
| 168 | if(2===arguments.length){ |
| 169 | x = arguments[0]; |
| 170 | y = arguments[1]; |
| 171 | showIt = true; |
| @@ -344,11 +344,12 @@ | |
| 344 | - No arguments, which is equivalent to passing the string |
| 345 | ".help-buttonlet:not(.processed)". |
| 346 | |
| 347 | Passing the same element(s) more than once is a no-op: during |
| 348 | initialization, each elements get the class'processed' added to |
| 349 | it, and any elements with that class are skipped. Each element |
| 350 | gets the 'help-buttonlet' CSS class added to it. |
| 351 | |
| 352 | All child nodes of a help buttonlet are removed from the button |
| 353 | during initialization and stashed away for use in a PopupWidget |
| 354 | when the botton is clicked. |
| 355 | |
| @@ -374,24 +375,24 @@ | |
| 375 | calculate the resulting size, then move and/or resize it. |
| 376 | |
| 377 | This algorithm/these heuristics can certainly be improved |
| 378 | upon. |
| 379 | */ |
| 380 | let popupRect, rectElem = ev.target; |
| 381 | while(rectElem){ |
| 382 | popupRect = rectElem.getClientRects()[0]/*undefined if off-screen!*/; |
| 383 | if(popupRect) break; |
| 384 | rectElem = rectElem.parentNode; |
| 385 | } |
| 386 | if(!popupRect) popupRect = {x:0, y:0, left:0, right:0}; |
| 387 | let x = popupRect.left, y = popupRect.top; |
| 388 | if(x<0) x = 0; |
| 389 | if(y<0) y = 0; |
| 390 | if(rectElem){ |
| 391 | /* Try to ensure that the popup's z-level is higher than this element's */ |
| 392 | const rz = window.getComputedStyle(rectElem).zIndex; |
| 393 | let myZ; |
| 394 | if(rz && !isNaN(+rz)){ |
| 395 | myZ = +rz + 1; |
| 396 | }else{ |
| 397 | myZ = 10000/*guess!*/; |
| 398 | } |
| @@ -416,11 +417,11 @@ | |
| 417 | fch.popup.show(x, y); |
| 418 | return false; |
| 419 | }; |
| 420 | f.foreachElement = function(e){ |
| 421 | if(e.classList.contains('processed')) return; |
| 422 | e.classList.add('processed', 'help-buttonlet'); |
| 423 | e.$helpContent = []; |
| 424 | /* We have to move all child nodes out of the way because we |
| 425 | cannot hide TEXT nodes via CSS (which cannot select TEXT |
| 426 | nodes). We have to do it in two steps to avoid invaliding |
| 427 | the list during traversal. */ |
| @@ -427,11 +428,11 @@ | |
| 428 | e.childNodes.forEach((ch)=>e.$helpContent.push(ch)); |
| 429 | e.$helpContent.forEach((ch)=>ch.remove()); |
| 430 | e.addEventListener('click', f.clickHandler, false); |
| 431 | }; |
| 432 | }/*static init*/ |
| 433 | let elems; |
| 434 | if(!arguments.length){ |
| 435 | arguments[0] = '.help-buttonlet:not(.processed)'; |
| 436 | arguments.length = 1; |
| 437 | } |
| 438 | if(arguments.length){ |
| @@ -443,11 +444,11 @@ | |
| 444 | elems = arguments[0]; |
| 445 | } |
| 446 | } |
| 447 | if(elems) elems.forEach(f.foreachElement); |
| 448 | }, |
| 449 | |
| 450 | /** |
| 451 | Sets up the given element as a "help buttonlet", adding the CSS |
| 452 | class help-buttonlet to it. Any (optional) arguments after the |
| 453 | first are appended to the element using fossil.dom.append(), so |
| 454 | that they become the content for the buttonlet's popup help. |
| @@ -465,7 +466,6 @@ | |
| 466 | return elem; |
| 467 | } |
| 468 | }/*helpButtonlets*/; |
| 469 | |
| 470 | F.onDOMContentLoaded( ()=>F.helpButtonlets.setup() ); |
| 471 | })(window.fossil); |
| 472 |
+62
-7
| --- src/fossil.storage.js | ||
| +++ src/fossil.storage.js | ||
| @@ -82,24 +82,53 @@ | ||
| 82 | 82 | )+'::' : ( |
| 83 | 83 | '' /* transient storage */ |
| 84 | 84 | ) |
| 85 | 85 | ); |
| 86 | 86 | |
| 87 | + /** | |
| 88 | + Proxy for custom events. Created on demand. | |
| 89 | + */ | |
| 90 | + let events; | |
| 87 | 91 | /** |
| 88 | 92 | A proxy for localStorage or sessionStorage or a |
| 89 | 93 | page-instance-local proxy, if neither one is availble. |
| 90 | 94 | |
| 91 | 95 | Which exact storage implementation is uses is unspecified, and |
| 92 | 96 | apps must not rely on it. |
| 93 | 97 | */ |
| 94 | 98 | F.storage = { |
| 95 | 99 | storageKeyPrefix: storageKeyPrefix, |
| 100 | + addEventListener(...args){ | |
| 101 | + events ??= new EventTarget() | |
| 102 | + return events.addEventListener(...args); | |
| 103 | + }, | |
| 104 | + removeEventListener(...args){ | |
| 105 | + events ??= new EventTarget() | |
| 106 | + return events.removeEventListener(...args); | |
| 107 | + }, | |
| 96 | 108 | /** Sets the storage key k to value v, implicitly converting |
| 97 | - it to a string. */ | |
| 98 | - set: (k,v)=>$storage.setItem(storageKeyPrefix+k,v), | |
| 109 | + it to a string. | |
| 110 | + | |
| 111 | + Fires a 'set' CustomEvent with a detail value in the form | |
| 112 | + {key, value} with the new value. | |
| 113 | + */ | |
| 114 | + set: (k,v)=>{ | |
| 115 | + $storage.setItem(storageKeyPrefix+k,v); | |
| 116 | + if( events ){ | |
| 117 | + events.dispatchEvent( | |
| 118 | + new CustomEvent('set',{ | |
| 119 | + detail: F.nu({ | |
| 120 | + key: k, value: v | |
| 121 | + }) | |
| 122 | + }) | |
| 123 | + ); | |
| 124 | + } | |
| 125 | + }, | |
| 99 | 126 | /** Sets storage key k to JSON.stringify(v). */ |
| 100 | - setJSON: (k,v)=>$storage.setItem(storageKeyPrefix+k,JSON.stringify(v)), | |
| 127 | + setJSON: function(k,v){ | |
| 128 | + return this.set(k,JSON.stringify(v)); | |
| 129 | + }, | |
| 101 | 130 | /** Returns the value for the given storage key, or |
| 102 | 131 | dflt if the key is not found in the storage. */ |
| 103 | 132 | get: (k,dflt)=>$storageHolder.hasOwnProperty( |
| 104 | 133 | storageKeyPrefix+k |
| 105 | 134 | ) ? $storage.getItem(storageKeyPrefix+k) : dflt, |
| @@ -121,22 +150,48 @@ | ||
| 121 | 150 | catch(e){return dflt} |
| 122 | 151 | }, |
| 123 | 152 | /** Returns true if the storage contains the given key, |
| 124 | 153 | else false. */ |
| 125 | 154 | contains: (k)=>$storageHolder.hasOwnProperty(storageKeyPrefix+k), |
| 126 | - /** Removes the given key from the storage. Returns this. */ | |
| 155 | + /** | |
| 156 | + Removes the given key from the storage. Returns this. | |
| 157 | + | |
| 158 | + Fires a 'remove' CustomEvent with a detail value in the form | |
| 159 | + {key}. | |
| 160 | + */ | |
| 127 | 161 | remove: function(k){ |
| 128 | - $storage.removeItem(storageKeyPrefix+k); | |
| 162 | + const kk = storageKeyPrefix+k; | |
| 163 | + if( events ){ | |
| 164 | + const had = $storageHolder.hasOwnProperty(kk) | |
| 165 | + $storage.removeItem(kk); | |
| 166 | + if( had ){ | |
| 167 | + events.dispatchEvent( | |
| 168 | + new CustomEvent('remove',{ | |
| 169 | + detail: F.nu({key: k}) | |
| 170 | + }) | |
| 171 | + ); | |
| 172 | + } | |
| 173 | + }else{ | |
| 174 | + $storage.removeItem(kk); | |
| 175 | + } | |
| 129 | 176 | return this; |
| 130 | 177 | }, |
| 131 | 178 | /** Clears ALL keys from the storage. Returns this. */ |
| 132 | 179 | clear: function(){ |
| 133 | 180 | this.keys().forEach((k)=>$storage.removeItem(/*w/o prefix*/k)); |
| 134 | 181 | return this; |
| 135 | 182 | }, |
| 136 | - /** Returns an array of all keys currently in the storage. */ | |
| 137 | - keys: ()=>Object.keys($storageHolder).filter((v)=>(v||'').startsWith(storageKeyPrefix)), | |
| 183 | + /** Returns an array of all keys currently in the storage. If full | |
| 184 | + is true then the keys include the storage key prefix, else | |
| 185 | + they don't. It should default to false but does not for | |
| 186 | + historical compatibility. */ | |
| 187 | + keys: function(full=true){ | |
| 188 | + const li = Object.keys($storageHolder).filter((v)=>(v||'').startsWith(storageKeyPrefix)); | |
| 189 | + if( full ) return li; | |
| 190 | + const n = this.storageKeyPrefix.length; | |
| 191 | + return li.map(v=>v.substring(n)); | |
| 192 | + }, | |
| 138 | 193 | /** Returns true if this storage is transient (only available |
| 139 | 194 | until the page is reloaded), indicating that fileStorage |
| 140 | 195 | and sessionStorage are unavailable. */ |
| 141 | 196 | isTransient: ()=>$storageHolder!==$storage, |
| 142 | 197 | /** Returns a symbolic name for the current storage mechanism. */ |
| 143 | 198 |
| --- src/fossil.storage.js | |
| +++ src/fossil.storage.js | |
| @@ -82,24 +82,53 @@ | |
| 82 | )+'::' : ( |
| 83 | '' /* transient storage */ |
| 84 | ) |
| 85 | ); |
| 86 | |
| 87 | /** |
| 88 | A proxy for localStorage or sessionStorage or a |
| 89 | page-instance-local proxy, if neither one is availble. |
| 90 | |
| 91 | Which exact storage implementation is uses is unspecified, and |
| 92 | apps must not rely on it. |
| 93 | */ |
| 94 | F.storage = { |
| 95 | storageKeyPrefix: storageKeyPrefix, |
| 96 | /** Sets the storage key k to value v, implicitly converting |
| 97 | it to a string. */ |
| 98 | set: (k,v)=>$storage.setItem(storageKeyPrefix+k,v), |
| 99 | /** Sets storage key k to JSON.stringify(v). */ |
| 100 | setJSON: (k,v)=>$storage.setItem(storageKeyPrefix+k,JSON.stringify(v)), |
| 101 | /** Returns the value for the given storage key, or |
| 102 | dflt if the key is not found in the storage. */ |
| 103 | get: (k,dflt)=>$storageHolder.hasOwnProperty( |
| 104 | storageKeyPrefix+k |
| 105 | ) ? $storage.getItem(storageKeyPrefix+k) : dflt, |
| @@ -121,22 +150,48 @@ | |
| 121 | catch(e){return dflt} |
| 122 | }, |
| 123 | /** Returns true if the storage contains the given key, |
| 124 | else false. */ |
| 125 | contains: (k)=>$storageHolder.hasOwnProperty(storageKeyPrefix+k), |
| 126 | /** Removes the given key from the storage. Returns this. */ |
| 127 | remove: function(k){ |
| 128 | $storage.removeItem(storageKeyPrefix+k); |
| 129 | return this; |
| 130 | }, |
| 131 | /** Clears ALL keys from the storage. Returns this. */ |
| 132 | clear: function(){ |
| 133 | this.keys().forEach((k)=>$storage.removeItem(/*w/o prefix*/k)); |
| 134 | return this; |
| 135 | }, |
| 136 | /** Returns an array of all keys currently in the storage. */ |
| 137 | keys: ()=>Object.keys($storageHolder).filter((v)=>(v||'').startsWith(storageKeyPrefix)), |
| 138 | /** Returns true if this storage is transient (only available |
| 139 | until the page is reloaded), indicating that fileStorage |
| 140 | and sessionStorage are unavailable. */ |
| 141 | isTransient: ()=>$storageHolder!==$storage, |
| 142 | /** Returns a symbolic name for the current storage mechanism. */ |
| 143 |
| --- src/fossil.storage.js | |
| +++ src/fossil.storage.js | |
| @@ -82,24 +82,53 @@ | |
| 82 | )+'::' : ( |
| 83 | '' /* transient storage */ |
| 84 | ) |
| 85 | ); |
| 86 | |
| 87 | /** |
| 88 | Proxy for custom events. Created on demand. |
| 89 | */ |
| 90 | let events; |
| 91 | /** |
| 92 | A proxy for localStorage or sessionStorage or a |
| 93 | page-instance-local proxy, if neither one is availble. |
| 94 | |
| 95 | Which exact storage implementation is uses is unspecified, and |
| 96 | apps must not rely on it. |
| 97 | */ |
| 98 | F.storage = { |
| 99 | storageKeyPrefix: storageKeyPrefix, |
| 100 | addEventListener(...args){ |
| 101 | events ??= new EventTarget() |
| 102 | return events.addEventListener(...args); |
| 103 | }, |
| 104 | removeEventListener(...args){ |
| 105 | events ??= new EventTarget() |
| 106 | return events.removeEventListener(...args); |
| 107 | }, |
| 108 | /** Sets the storage key k to value v, implicitly converting |
| 109 | it to a string. |
| 110 | |
| 111 | Fires a 'set' CustomEvent with a detail value in the form |
| 112 | {key, value} with the new value. |
| 113 | */ |
| 114 | set: (k,v)=>{ |
| 115 | $storage.setItem(storageKeyPrefix+k,v); |
| 116 | if( events ){ |
| 117 | events.dispatchEvent( |
| 118 | new CustomEvent('set',{ |
| 119 | detail: F.nu({ |
| 120 | key: k, value: v |
| 121 | }) |
| 122 | }) |
| 123 | ); |
| 124 | } |
| 125 | }, |
| 126 | /** Sets storage key k to JSON.stringify(v). */ |
| 127 | setJSON: function(k,v){ |
| 128 | return this.set(k,JSON.stringify(v)); |
| 129 | }, |
| 130 | /** Returns the value for the given storage key, or |
| 131 | dflt if the key is not found in the storage. */ |
| 132 | get: (k,dflt)=>$storageHolder.hasOwnProperty( |
| 133 | storageKeyPrefix+k |
| 134 | ) ? $storage.getItem(storageKeyPrefix+k) : dflt, |
| @@ -121,22 +150,48 @@ | |
| 150 | catch(e){return dflt} |
| 151 | }, |
| 152 | /** Returns true if the storage contains the given key, |
| 153 | else false. */ |
| 154 | contains: (k)=>$storageHolder.hasOwnProperty(storageKeyPrefix+k), |
| 155 | /** |
| 156 | Removes the given key from the storage. Returns this. |
| 157 | |
| 158 | Fires a 'remove' CustomEvent with a detail value in the form |
| 159 | {key}. |
| 160 | */ |
| 161 | remove: function(k){ |
| 162 | const kk = storageKeyPrefix+k; |
| 163 | if( events ){ |
| 164 | const had = $storageHolder.hasOwnProperty(kk) |
| 165 | $storage.removeItem(kk); |
| 166 | if( had ){ |
| 167 | events.dispatchEvent( |
| 168 | new CustomEvent('remove',{ |
| 169 | detail: F.nu({key: k}) |
| 170 | }) |
| 171 | ); |
| 172 | } |
| 173 | }else{ |
| 174 | $storage.removeItem(kk); |
| 175 | } |
| 176 | return this; |
| 177 | }, |
| 178 | /** Clears ALL keys from the storage. Returns this. */ |
| 179 | clear: function(){ |
| 180 | this.keys().forEach((k)=>$storage.removeItem(/*w/o prefix*/k)); |
| 181 | return this; |
| 182 | }, |
| 183 | /** Returns an array of all keys currently in the storage. If full |
| 184 | is true then the keys include the storage key prefix, else |
| 185 | they don't. It should default to false but does not for |
| 186 | historical compatibility. */ |
| 187 | keys: function(full=true){ |
| 188 | const li = Object.keys($storageHolder).filter((v)=>(v||'').startsWith(storageKeyPrefix)); |
| 189 | if( full ) return li; |
| 190 | const n = this.storageKeyPrefix.length; |
| 191 | return li.map(v=>v.substring(n)); |
| 192 | }, |
| 193 | /** Returns true if this storage is transient (only available |
| 194 | until the page is reloaded), indicating that fileStorage |
| 195 | and sessionStorage are unavailable. */ |
| 196 | isTransient: ()=>$storageHolder!==$storage, |
| 197 | /** Returns a symbolic name for the current storage mechanism. */ |
| 198 |
+3
-2
| --- src/fossil.tabs.js | ||
| +++ src/fossil.tabs.js | ||
| @@ -7,11 +7,11 @@ | ||
| 7 | 7 | /** |
| 8 | 8 | Creates a TabManager. If passed a truthy first argument, it is |
| 9 | 9 | passed to init(). If passed a truthy second argument, it must be |
| 10 | 10 | an Object holding configuration options: |
| 11 | 11 | |
| 12 | - { | |
| 12 | + { | |
| 13 | 13 | tabAccessKeys: boolean (=true) |
| 14 | 14 | If true, tab buttons are assigned "accesskey" values |
| 15 | 15 | equal to their 1-based tab number. |
| 16 | 16 | } |
| 17 | 17 | */ |
| @@ -56,11 +56,11 @@ | ||
| 56 | 56 | /** |
| 57 | 57 | Initializes the tabs associated with the given tab container |
| 58 | 58 | (DOM element or selector for a single element). This must be |
| 59 | 59 | called once before using any other member functions of a given |
| 60 | 60 | instance, noting that the constructor will call this if it is |
| 61 | - passed an argument. | |
| 61 | + passed an argument. | |
| 62 | 62 | |
| 63 | 63 | The tab container must have an 'id' attribute. This function |
| 64 | 64 | looks through the DOM for all elements which have |
| 65 | 65 | data-tab-parent=thatId. For each one it creates a button to |
| 66 | 66 | switch to that tab and moves the element into this.e.tabs, |
| @@ -150,10 +150,11 @@ | ||
| 150 | 150 | e.target.$manager.switchToTab(e.target.$tab); |
| 151 | 151 | }; |
| 152 | 152 | } |
| 153 | 153 | tab = tabArg(tab); |
| 154 | 154 | tab.remove(); |
| 155 | + tab.classList.add('hidden'); | |
| 155 | 156 | D.append(this.e.tabs, D.addClass(tab,'tab-panel')); |
| 156 | 157 | const tabCount = this.e.tabBar.childNodes.length+1; |
| 157 | 158 | const lbl = tab.dataset.tabLabel || 'Tab #'+tabCount; |
| 158 | 159 | const btn = D.addClass(D.append(D.span(), lbl), 'tab-button'); |
| 159 | 160 | D.append(this.e.tabBar,btn); |
| 160 | 161 |
| --- src/fossil.tabs.js | |
| +++ src/fossil.tabs.js | |
| @@ -7,11 +7,11 @@ | |
| 7 | /** |
| 8 | Creates a TabManager. If passed a truthy first argument, it is |
| 9 | passed to init(). If passed a truthy second argument, it must be |
| 10 | an Object holding configuration options: |
| 11 | |
| 12 | { |
| 13 | tabAccessKeys: boolean (=true) |
| 14 | If true, tab buttons are assigned "accesskey" values |
| 15 | equal to their 1-based tab number. |
| 16 | } |
| 17 | */ |
| @@ -56,11 +56,11 @@ | |
| 56 | /** |
| 57 | Initializes the tabs associated with the given tab container |
| 58 | (DOM element or selector for a single element). This must be |
| 59 | called once before using any other member functions of a given |
| 60 | instance, noting that the constructor will call this if it is |
| 61 | passed an argument. |
| 62 | |
| 63 | The tab container must have an 'id' attribute. This function |
| 64 | looks through the DOM for all elements which have |
| 65 | data-tab-parent=thatId. For each one it creates a button to |
| 66 | switch to that tab and moves the element into this.e.tabs, |
| @@ -150,10 +150,11 @@ | |
| 150 | e.target.$manager.switchToTab(e.target.$tab); |
| 151 | }; |
| 152 | } |
| 153 | tab = tabArg(tab); |
| 154 | tab.remove(); |
| 155 | D.append(this.e.tabs, D.addClass(tab,'tab-panel')); |
| 156 | const tabCount = this.e.tabBar.childNodes.length+1; |
| 157 | const lbl = tab.dataset.tabLabel || 'Tab #'+tabCount; |
| 158 | const btn = D.addClass(D.append(D.span(), lbl), 'tab-button'); |
| 159 | D.append(this.e.tabBar,btn); |
| 160 |
| --- src/fossil.tabs.js | |
| +++ src/fossil.tabs.js | |
| @@ -7,11 +7,11 @@ | |
| 7 | /** |
| 8 | Creates a TabManager. If passed a truthy first argument, it is |
| 9 | passed to init(). If passed a truthy second argument, it must be |
| 10 | an Object holding configuration options: |
| 11 | |
| 12 | { |
| 13 | tabAccessKeys: boolean (=true) |
| 14 | If true, tab buttons are assigned "accesskey" values |
| 15 | equal to their 1-based tab number. |
| 16 | } |
| 17 | */ |
| @@ -56,11 +56,11 @@ | |
| 56 | /** |
| 57 | Initializes the tabs associated with the given tab container |
| 58 | (DOM element or selector for a single element). This must be |
| 59 | called once before using any other member functions of a given |
| 60 | instance, noting that the constructor will call this if it is |
| 61 | passed an argument. |
| 62 | |
| 63 | The tab container must have an 'id' attribute. This function |
| 64 | looks through the DOM for all elements which have |
| 65 | data-tab-parent=thatId. For each one it creates a button to |
| 66 | switch to that tab and moves the element into this.e.tabs, |
| @@ -150,10 +150,11 @@ | |
| 150 | e.target.$manager.switchToTab(e.target.$tab); |
| 151 | }; |
| 152 | } |
| 153 | tab = tabArg(tab); |
| 154 | tab.remove(); |
| 155 | tab.classList.add('hidden'); |
| 156 | D.append(this.e.tabs, D.addClass(tab,'tab-panel')); |
| 157 | const tabCount = this.e.tabBar.childNodes.length+1; |
| 158 | const lbl = tab.dataset.tabLabel || 'Tab #'+tabCount; |
| 159 | const btn = D.addClass(D.append(D.span(), lbl), 'tab-button'); |
| 160 | D.append(this.e.tabBar,btn); |
| 161 |
+101
-38
| --- src/info.c | ||
| +++ src/info.c | ||
| @@ -371,10 +371,21 @@ | ||
| 371 | 371 | pCfg->zLeftHash = 0; |
| 372 | 372 | blob_reset(&from); |
| 373 | 373 | blob_reset(&to); |
| 374 | 374 | } |
| 375 | 375 | |
| 376 | +/* | |
| 377 | +** The append_file_change_line() routine updates an array of counts | |
| 378 | +** for various kinds of changes. | |
| 379 | +*/ | |
| 380 | +#define FCHNG_NEW 0 | |
| 381 | +#define FCHNG_DELETE 1 | |
| 382 | +#define FCHNG_RENAME 2 | |
| 383 | +#define FCHNG_MODE 3 | |
| 384 | +#define FCHNG_EDIT 4 | |
| 385 | +#define N_FCHNG 5 | |
| 386 | + | |
| 376 | 387 | /* |
| 377 | 388 | ** Write a line of web-page output that shows changes that have occurred |
| 378 | 389 | ** to a file between two check-ins. |
| 379 | 390 | */ |
| 380 | 391 | static void append_file_change_line( |
| @@ -382,32 +393,38 @@ | ||
| 382 | 393 | const char *zName, /* Name of the file that has changed */ |
| 383 | 394 | const char *zOld, /* blob.uuid before change. NULL for added files */ |
| 384 | 395 | const char *zNew, /* blob.uuid after change. NULL for deletes */ |
| 385 | 396 | const char *zOldName, /* Prior name. NULL if no name change. */ |
| 386 | 397 | DiffConfig *pCfg, /* Flags for text_diff() or NULL to omit all */ |
| 387 | - int mperm /* executable or symlink permission for zNew */ | |
| 398 | + int mperm, /* executable or symlink permission for zNew */ | |
| 399 | + int *aChng /* Change count array */ | |
| 388 | 400 | ){ |
| 389 | 401 | @ <div class='file-change-line'><span> |
| 390 | 402 | /* Maintenance reminder: the extra level of SPAN is for |
| 391 | 403 | ** arranging new elements via JS. */ |
| 392 | 404 | if( !g.perm.Hyperlink ){ |
| 393 | 405 | if( zNew==0 ){ |
| 394 | 406 | @ Deleted %h(zName). |
| 407 | + aChng[FCHNG_DELETE]++; | |
| 395 | 408 | }else if( zOld==0 ){ |
| 396 | 409 | @ Added %h(zName). |
| 410 | + aChng[FCHNG_NEW]++; | |
| 397 | 411 | }else if( zOldName!=0 && fossil_strcmp(zName,zOldName)!=0 ){ |
| 398 | 412 | @ Name change from %h(zOldName) to %h(zName). |
| 413 | + aChng[FCHNG_RENAME]++; | |
| 399 | 414 | }else if( fossil_strcmp(zNew, zOld)==0 ){ |
| 400 | 415 | if( mperm==PERM_EXE ){ |
| 401 | 416 | @ %h(zName) became executable. |
| 402 | 417 | }else if( mperm==PERM_LNK ){ |
| 403 | 418 | @ %h(zName) became a symlink. |
| 404 | 419 | }else{ |
| 405 | 420 | @ %h(zName) became a regular file. |
| 406 | 421 | } |
| 422 | + aChng[FCHNG_MODE]++; | |
| 407 | 423 | }else{ |
| 408 | 424 | @ Changes to %h(zName). |
| 425 | + aChng[FCHNG_EDIT]++; | |
| 409 | 426 | } |
| 410 | 427 | @ </span></div> |
| 411 | 428 | if( pCfg ){ |
| 412 | 429 | append_diff(zOld, zNew, pCfg); |
| 413 | 430 | } |
| @@ -422,22 +439,25 @@ | ||
| 422 | 439 | @ %h(zOldName)</a> |
| 423 | 440 | @ %z(href("%R/artifact/%!S",zOld))[%S(zOld)]</a> |
| 424 | 441 | @ to %z(href("%R/finfo?name=%T&m=%!S&ci=%s",zName,zNew,zCkin2))\ |
| 425 | 442 | @ %h(zName)</a> |
| 426 | 443 | @ %z(href("%R/artifact/%!S",zNew))[%S(zNew)]</a>. |
| 444 | + aChng[FCHNG_RENAME]++; | |
| 427 | 445 | }else{ |
| 428 | 446 | @ Modified %z(href("%R/finfo?name=%T&m=%!S&ci=%s",zName,zNew,zCkin2))\ |
| 429 | 447 | @ %h(zName)</a> |
| 430 | 448 | @ from %z(href("%R/artifact/%!S",zOld))[%S(zOld)]</a> |
| 431 | 449 | @ to %z(href("%R/artifact/%!S",zNew))[%S(zNew)]</a>. |
| 432 | 450 | } |
| 451 | + aChng[FCHNG_EDIT]++; | |
| 433 | 452 | }else if( zOldName!=0 && fossil_strcmp(zName,zOldName)!=0 ){ |
| 434 | 453 | @ Name change |
| 435 | 454 | @ from %z(href("%R/finfo?name=%T&m=%!S&ci=%s",zOldName,zOld,zCkin2))\ |
| 436 | 455 | @ %h(zOldName)</a> |
| 437 | 456 | @ to %z(href("%R/finfo?name=%T&m=%!S&ci=%s",zName,zNew,zCkin2))\ |
| 438 | 457 | @ %h(zName)</a>. |
| 458 | + aChng[FCHNG_RENAME]++; | |
| 439 | 459 | }else{ |
| 440 | 460 | @ %z(href("%R/finfo?name=%T&m=%!S&ci=%s",zName,zNew,zCkin2))\ |
| 441 | 461 | @ %h(zName)</a> became |
| 442 | 462 | if( mperm==PERM_EXE ){ |
| 443 | 463 | @ executable with contents |
| @@ -445,17 +465,20 @@ | ||
| 445 | 465 | @ a symlink with target |
| 446 | 466 | }else{ |
| 447 | 467 | @ a regular file with contents |
| 448 | 468 | } |
| 449 | 469 | @ %z(href("%R/artifact/%!S",zNew))[%S(zNew)]</a>. |
| 470 | + aChng[FCHNG_MODE]++; | |
| 450 | 471 | } |
| 451 | 472 | }else if( zOld ){ |
| 452 | 473 | @ Deleted %z(href("%R/finfo?name=%T&m=%!S&ci=%s",zName,zOld,zCkin2))\ |
| 453 | 474 | @ %h(zName)</a> version %z(href("%R/artifact/%!S",zOld))[%S(zOld)]</a>. |
| 475 | + aChng[FCHNG_DELETE]++; | |
| 454 | 476 | }else{ |
| 455 | 477 | @ Added %z(href("%R/finfo?name=%T&m=%!S&ci=%s",zName,zNew,zCkin2))\ |
| 456 | 478 | @ %h(zName)</a> version %z(href("%R/artifact/%!S",zNew))[%S(zNew)]</a>. |
| 479 | + aChng[FCHNG_NEW]++; | |
| 457 | 480 | } |
| 458 | 481 | if( zOld && zNew && fossil_strcmp(zOld,zNew)!=0 ){ |
| 459 | 482 | if( pCfg ){ |
| 460 | 483 | @ </span></div> |
| 461 | 484 | append_diff(zOld, zNew, pCfg); |
| @@ -624,10 +647,58 @@ | ||
| 624 | 647 | www_print_timeline(&q, TIMELINE_DISJOINT|TIMELINE_GRAPH|TIMELINE_NOSCROLL, |
| 625 | 648 | &xtra); |
| 626 | 649 | db_finalize(&q); |
| 627 | 650 | style_finish_page(); |
| 628 | 651 | } |
| 652 | + | |
| 653 | +/* | |
| 654 | +** Generate JS code that will adjust the change counts in the title | |
| 655 | +** of the "changes_section" panel where "changes_section" is a JS id. | |
| 656 | +** | |
| 657 | +** The change counts are taken from g.diffCnt[] for edits, and from | |
| 658 | +** the aChng[] parameter for additions, deletions, and modifications. | |
| 659 | +** The aChng parameter may be NULL, in which case those factors are | |
| 660 | +** ignored. | |
| 661 | +*/ | |
| 662 | +static void adjust_changes_section_title( | |
| 663 | + int iLine, /* Souce code line number of caller */ | |
| 664 | + int *aChng /* Change categories */ | |
| 665 | +){ | |
| 666 | + sqlite3_str *pTxt = sqlite3_str_new(0); | |
| 667 | + if( g.diffCnt[0]>0 ){ | |
| 668 | + sqlite3_str_appendf(pTxt, "%d file%s edited [+%d -%d lines]", | |
| 669 | + g.diffCnt[0], g.diffCnt[0]==1 ? "" : "s", | |
| 670 | + g.diffCnt[1], g.diffCnt[2]); | |
| 671 | + } | |
| 672 | + if( aChng ){ | |
| 673 | + static const int aiType[] = | |
| 674 | + { FCHNG_NEW, FCHNG_DELETE, FCHNG_RENAME, FCHNG_MODE }; | |
| 675 | + static const char *azType[] = | |
| 676 | + { "added", "deleted", "renamed", "mode change"}; | |
| 677 | + int i; | |
| 678 | + for(i=0; i<4; i++){ | |
| 679 | + int j = aiType[i]; | |
| 680 | + if( aChng[j] ){ | |
| 681 | + const char *zFiles = ""; | |
| 682 | + if( sqlite3_str_length(pTxt)>0 ){ | |
| 683 | + sqlite3_str_append(pTxt,", ", 2); | |
| 684 | + }else{ | |
| 685 | + zFiles = i<3 && aChng[j]>1 ? " files" : " file"; | |
| 686 | + } | |
| 687 | + sqlite3_str_appendf(pTxt,"%d%s %s", aChng[j], zFiles, azType[i]); | |
| 688 | + if( i==3 && aChng[j]>1 ) sqlite3_str_appendf(pTxt, "s"); | |
| 689 | + } | |
| 690 | + } | |
| 691 | + } | |
| 692 | + if( sqlite3_str_length(pTxt)>0 ){ | |
| 693 | + @ <script nonce='%h(style_nonce())'>;/* info.c:%d(iLine) */ | |
| 694 | + @ document.getElementById('changes_section').textContent = \ | |
| 695 | + @ 'Changes (%h(sqlite3_str_value(pTxt)))' | |
| 696 | + @ </script> | |
| 697 | + } | |
| 698 | + sqlite3_str_free(pTxt); | |
| 699 | +} | |
| 629 | 700 | |
| 630 | 701 | /* |
| 631 | 702 | ** Render a web-page diff of the changes in the working check-out |
| 632 | 703 | */ |
| 633 | 704 | static void ckout_normal_diff(int vid){ |
| @@ -734,16 +805,11 @@ | ||
| 734 | 805 | blob_reset(&old); |
| 735 | 806 | blob_reset(&new); |
| 736 | 807 | } |
| 737 | 808 | } |
| 738 | 809 | db_finalize(&q); |
| 739 | - @ <script nonce='%h(style_nonce())'>;/* info.c:%d(__LINE__) */ | |
| 740 | - @ document.getElementById('changes_section').textContent = 'Changes ' + | |
| 741 | - @ '(%d(g.diffCnt[0]) file' + (%d(g.diffCnt[0])===1 ? '' : 's') + ': ' + | |
| 742 | - @ '+%d(g.diffCnt[1]) ' + | |
| 743 | - @ '−%d(g.diffCnt[2]))' | |
| 744 | - @ </script> | |
| 810 | + adjust_changes_section_title(__LINE__, 0); | |
| 745 | 811 | append_diff_javascript(diffType); |
| 746 | 812 | } |
| 747 | 813 | |
| 748 | 814 | /* |
| 749 | 815 | ** Render a web-page diff of the changes in the working check-out to |
| @@ -827,16 +893,11 @@ | ||
| 827 | 893 | } |
| 828 | 894 | fossil_free(zLhs); |
| 829 | 895 | fossil_free(zRhs); |
| 830 | 896 | } |
| 831 | 897 | db_finalize(&q); |
| 832 | - @ <script nonce='%h(style_nonce())'>;/* info.c:%d(__LINE__) */ | |
| 833 | - @ document.getElementById('changes_section').textContent = 'Changes ' + | |
| 834 | - @ '(%d(g.diffCnt[0]) file' + (%d(g.diffCnt[0])===1 ? '' : 's') + ': ' + | |
| 835 | - @ '+%d(g.diffCnt[1]) ' + | |
| 836 | - @ '−%d(g.diffCnt[2]))' | |
| 837 | - @ </script> | |
| 898 | + adjust_changes_section_title(__LINE__, 0); | |
| 838 | 899 | append_diff_javascript(diffType); |
| 839 | 900 | } |
| 840 | 901 | |
| 841 | 902 | /* |
| 842 | 903 | ** WEBPAGE: ckout |
| @@ -935,11 +996,13 @@ | ||
| 935 | 996 | ReCompiled *pRe = 0; /* regex */ |
| 936 | 997 | const char *zW; /* URL param for ignoring whitespace */ |
| 937 | 998 | const char *zPage = "vinfo"; /* Page that shows diffs */ |
| 938 | 999 | const char *zBrName; /* Branch name */ |
| 939 | 1000 | DiffConfig DCfg,*pCfg; /* Type of diff */ |
| 1001 | + int aChng[N_FCHNG]; /* Counts of change types */ | |
| 940 | 1002 | |
| 1003 | + memset(aChng, 0, sizeof(aChng)); | |
| 941 | 1004 | login_check_credentials(); |
| 942 | 1005 | if( !g.perm.Read ){ login_needed(g.anon.Read); return; } |
| 943 | 1006 | style_set_current_feature("vinfo"); |
| 944 | 1007 | zName = P("name"); |
| 945 | 1008 | rid = name_to_rid_www("name"); |
| @@ -1253,21 +1316,16 @@ | ||
| 1253 | 1316 | int mperm = db_column_int(&q3, 1); |
| 1254 | 1317 | const char *zOld = db_column_text(&q3,2); |
| 1255 | 1318 | const char *zNew = db_column_text(&q3,3); |
| 1256 | 1319 | const char *zOldName = db_column_text(&q3, 4); |
| 1257 | 1320 | append_file_change_line(zUuid, zName, zOld, zNew, zOldName, |
| 1258 | - pCfg,mperm); | |
| 1321 | + pCfg,mperm,aChng); | |
| 1259 | 1322 | } |
| 1260 | 1323 | db_finalize(&q3); |
| 1261 | 1324 | @ </div> |
| 1262 | 1325 | if( diffType!=0 ){ |
| 1263 | - @ <script nonce='%h(style_nonce())'>;/* info.c:%d(__LINE__) */ | |
| 1264 | - @ document.getElementById('changes_section').textContent = 'Changes ' + | |
| 1265 | - @ '(%d(g.diffCnt[0]) file' + (%d(g.diffCnt[0])===1 ? '' : 's') + ': ' + | |
| 1266 | - @ '+%d(g.diffCnt[1]) ' + | |
| 1267 | - @ '−%d(g.diffCnt[2]))' | |
| 1268 | - @ </script> | |
| 1326 | + adjust_changes_section_title(__LINE__, aChng); | |
| 1269 | 1327 | } |
| 1270 | 1328 | append_diff_javascript(diffType); |
| 1271 | 1329 | style_finish_page(); |
| 1272 | 1330 | } |
| 1273 | 1331 | |
| @@ -1449,11 +1507,13 @@ | ||
| 1449 | 1507 | DiffConfig DCfg, *pCfg = 0; |
| 1450 | 1508 | int graphFlags = 0; |
| 1451 | 1509 | Blob qp; /* non-glob= query parameters for generated links */ |
| 1452 | 1510 | Blob qpGlob; /* glob= query parameter for generated links */ |
| 1453 | 1511 | int bInvert = PB("inv"); |
| 1512 | + int aChng[N_FCHNG]; /* Count of versiou change types */ | |
| 1454 | 1513 | |
| 1514 | + memset(aChng, 0, sizeof(aChng)); | |
| 1455 | 1515 | login_check_credentials(); |
| 1456 | 1516 | if( !g.perm.Read ){ login_needed(g.anon.Read); return; } |
| 1457 | 1517 | if( robot_restrict("diff") ) return; |
| 1458 | 1518 | login_anonymous_available(); |
| 1459 | 1519 | fossil_nice_default(); |
| @@ -1594,18 +1654,18 @@ | ||
| 1594 | 1654 | cmp = fossil_strcmp(pFileFrom->zName, pFileTo->zName); |
| 1595 | 1655 | } |
| 1596 | 1656 | if( cmp<0 ){ |
| 1597 | 1657 | if( !pGlob || glob_match(pGlob, pFileFrom->zName) ){ |
| 1598 | 1658 | append_file_change_line(zFrom, pFileFrom->zName, |
| 1599 | - pFileFrom->zUuid, 0, 0, pCfg, 0); | |
| 1659 | + pFileFrom->zUuid, 0, 0, pCfg, 0,aChng); | |
| 1600 | 1660 | } |
| 1601 | 1661 | pFileFrom = manifest_file_next(pFrom, 0); |
| 1602 | 1662 | }else if( cmp>0 ){ |
| 1603 | 1663 | if( !pGlob || glob_match(pGlob, pFileTo->zName) ){ |
| 1604 | 1664 | append_file_change_line(zTo, pFileTo->zName, |
| 1605 | 1665 | 0, pFileTo->zUuid, 0, pCfg, |
| 1606 | - manifest_file_mperm(pFileTo)); | |
| 1666 | + manifest_file_mperm(pFileTo),aChng); | |
| 1607 | 1667 | } |
| 1608 | 1668 | pFileTo = manifest_file_next(pTo, 0); |
| 1609 | 1669 | }else if( fossil_strcmp(pFileFrom->zUuid, pFileTo->zUuid)==0 ){ |
| 1610 | 1670 | pFileFrom = manifest_file_next(pFrom, 0); |
| 1611 | 1671 | pFileTo = manifest_file_next(pTo, 0); |
| @@ -1613,11 +1673,11 @@ | ||
| 1613 | 1673 | if(!pGlob || (glob_match(pGlob, pFileFrom->zName) |
| 1614 | 1674 | || glob_match(pGlob, pFileTo->zName)) ){ |
| 1615 | 1675 | append_file_change_line(zFrom, pFileFrom->zName, |
| 1616 | 1676 | pFileFrom->zUuid, |
| 1617 | 1677 | pFileTo->zUuid, 0, pCfg, |
| 1618 | - manifest_file_mperm(pFileTo)); | |
| 1678 | + manifest_file_mperm(pFileTo),aChng); | |
| 1619 | 1679 | } |
| 1620 | 1680 | pFileFrom = manifest_file_next(pFrom, 0); |
| 1621 | 1681 | pFileTo = manifest_file_next(pTo, 0); |
| 1622 | 1682 | } |
| 1623 | 1683 | } |
| @@ -1871,40 +1931,43 @@ | ||
| 1871 | 1931 | @ Also attachment "%h(zFilename)" to |
| 1872 | 1932 | }else{ |
| 1873 | 1933 | @ Attachment "%h(zFilename)" to |
| 1874 | 1934 | } |
| 1875 | 1935 | objType |= OBJTYPE_ATTACHMENT; |
| 1876 | - if( fossil_is_artifact_hash(zTarget) ){ | |
| 1877 | - if ( db_exists("SELECT 1 FROM tag WHERE tagname='tkt-%q'", | |
| 1878 | - zTarget) | |
| 1879 | - ){ | |
| 1936 | + switch( attachment_target_type(zTarget, 1) ){ | |
| 1937 | + case CFTYPE_FORUM: | |
| 1938 | + if( g.perm.Hyperlink && g.anon.RdForum ){ | |
| 1939 | + @ forum post [%z(href("%R/forumpost/%!S",zTarget))%S(zTarget)</a>] | |
| 1940 | + }else{ | |
| 1941 | + @ forum post [%S(zTarget)] | |
| 1942 | + } | |
| 1943 | + break; | |
| 1944 | + case CFTYPE_TICKET: | |
| 1880 | 1945 | if( g.perm.Hyperlink && g.anon.RdTkt ){ |
| 1881 | 1946 | @ ticket [%z(href("%R/tktview?name=%!S",zTarget))%S(zTarget)</a>] |
| 1882 | 1947 | }else{ |
| 1883 | 1948 | @ ticket [%S(zTarget)] |
| 1884 | 1949 | } |
| 1885 | - }else if( db_exists("SELECT 1 FROM tag WHERE tagname='event-%q'", | |
| 1886 | - zTarget) | |
| 1887 | - ){ | |
| 1950 | + break; | |
| 1951 | + case CFTYPE_EVENT: | |
| 1888 | 1952 | if( g.perm.Hyperlink && g.anon.RdWiki ){ |
| 1889 | 1953 | @ tech note [%z(href("%R/technote/%h",zTarget))%S(zTarget)</a>] |
| 1890 | 1954 | }else{ |
| 1891 | 1955 | @ tech note [%S(zTarget)] |
| 1892 | 1956 | } |
| 1893 | - }else{ | |
| 1957 | + break; | |
| 1958 | + case CFTYPE_WIKI: | |
| 1894 | 1959 | if( g.perm.Hyperlink && g.anon.RdWiki ){ |
| 1895 | 1960 | @ wiki page [%z(href("%R/wiki?name=%t",zTarget))%h(zTarget)</a>] |
| 1896 | 1961 | }else{ |
| 1897 | 1962 | @ wiki page [%h(zTarget)] |
| 1898 | 1963 | } |
| 1899 | - } | |
| 1900 | - }else{ | |
| 1901 | - if( g.perm.Hyperlink && g.anon.RdWiki ){ | |
| 1902 | - @ wiki page [%z(href("%R/wiki?name=%t",zTarget))%h(zTarget)</a>] | |
| 1903 | - }else{ | |
| 1904 | - @ wiki page [%h(zTarget)] | |
| 1905 | - } | |
| 1964 | + break; | |
| 1965 | + default: | |
| 1966 | + /* historical behavior is to assume wiki, but we can end up | |
| 1967 | + ** showing bogus links that way to stale attachments. */ | |
| 1968 | + @ unknown artifact %h(zTarget) | |
| 1906 | 1969 | } |
| 1907 | 1970 | @ added by |
| 1908 | 1971 | hyperlink_to_user(zUser,zDate," on"); |
| 1909 | 1972 | hyperlink_to_date(zDate,"."); |
| 1910 | 1973 | cnt++; |
| 1911 | 1974 |
| --- src/info.c | |
| +++ src/info.c | |
| @@ -371,10 +371,21 @@ | |
| 371 | pCfg->zLeftHash = 0; |
| 372 | blob_reset(&from); |
| 373 | blob_reset(&to); |
| 374 | } |
| 375 | |
| 376 | /* |
| 377 | ** Write a line of web-page output that shows changes that have occurred |
| 378 | ** to a file between two check-ins. |
| 379 | */ |
| 380 | static void append_file_change_line( |
| @@ -382,32 +393,38 @@ | |
| 382 | const char *zName, /* Name of the file that has changed */ |
| 383 | const char *zOld, /* blob.uuid before change. NULL for added files */ |
| 384 | const char *zNew, /* blob.uuid after change. NULL for deletes */ |
| 385 | const char *zOldName, /* Prior name. NULL if no name change. */ |
| 386 | DiffConfig *pCfg, /* Flags for text_diff() or NULL to omit all */ |
| 387 | int mperm /* executable or symlink permission for zNew */ |
| 388 | ){ |
| 389 | @ <div class='file-change-line'><span> |
| 390 | /* Maintenance reminder: the extra level of SPAN is for |
| 391 | ** arranging new elements via JS. */ |
| 392 | if( !g.perm.Hyperlink ){ |
| 393 | if( zNew==0 ){ |
| 394 | @ Deleted %h(zName). |
| 395 | }else if( zOld==0 ){ |
| 396 | @ Added %h(zName). |
| 397 | }else if( zOldName!=0 && fossil_strcmp(zName,zOldName)!=0 ){ |
| 398 | @ Name change from %h(zOldName) to %h(zName). |
| 399 | }else if( fossil_strcmp(zNew, zOld)==0 ){ |
| 400 | if( mperm==PERM_EXE ){ |
| 401 | @ %h(zName) became executable. |
| 402 | }else if( mperm==PERM_LNK ){ |
| 403 | @ %h(zName) became a symlink. |
| 404 | }else{ |
| 405 | @ %h(zName) became a regular file. |
| 406 | } |
| 407 | }else{ |
| 408 | @ Changes to %h(zName). |
| 409 | } |
| 410 | @ </span></div> |
| 411 | if( pCfg ){ |
| 412 | append_diff(zOld, zNew, pCfg); |
| 413 | } |
| @@ -422,22 +439,25 @@ | |
| 422 | @ %h(zOldName)</a> |
| 423 | @ %z(href("%R/artifact/%!S",zOld))[%S(zOld)]</a> |
| 424 | @ to %z(href("%R/finfo?name=%T&m=%!S&ci=%s",zName,zNew,zCkin2))\ |
| 425 | @ %h(zName)</a> |
| 426 | @ %z(href("%R/artifact/%!S",zNew))[%S(zNew)]</a>. |
| 427 | }else{ |
| 428 | @ Modified %z(href("%R/finfo?name=%T&m=%!S&ci=%s",zName,zNew,zCkin2))\ |
| 429 | @ %h(zName)</a> |
| 430 | @ from %z(href("%R/artifact/%!S",zOld))[%S(zOld)]</a> |
| 431 | @ to %z(href("%R/artifact/%!S",zNew))[%S(zNew)]</a>. |
| 432 | } |
| 433 | }else if( zOldName!=0 && fossil_strcmp(zName,zOldName)!=0 ){ |
| 434 | @ Name change |
| 435 | @ from %z(href("%R/finfo?name=%T&m=%!S&ci=%s",zOldName,zOld,zCkin2))\ |
| 436 | @ %h(zOldName)</a> |
| 437 | @ to %z(href("%R/finfo?name=%T&m=%!S&ci=%s",zName,zNew,zCkin2))\ |
| 438 | @ %h(zName)</a>. |
| 439 | }else{ |
| 440 | @ %z(href("%R/finfo?name=%T&m=%!S&ci=%s",zName,zNew,zCkin2))\ |
| 441 | @ %h(zName)</a> became |
| 442 | if( mperm==PERM_EXE ){ |
| 443 | @ executable with contents |
| @@ -445,17 +465,20 @@ | |
| 445 | @ a symlink with target |
| 446 | }else{ |
| 447 | @ a regular file with contents |
| 448 | } |
| 449 | @ %z(href("%R/artifact/%!S",zNew))[%S(zNew)]</a>. |
| 450 | } |
| 451 | }else if( zOld ){ |
| 452 | @ Deleted %z(href("%R/finfo?name=%T&m=%!S&ci=%s",zName,zOld,zCkin2))\ |
| 453 | @ %h(zName)</a> version %z(href("%R/artifact/%!S",zOld))[%S(zOld)]</a>. |
| 454 | }else{ |
| 455 | @ Added %z(href("%R/finfo?name=%T&m=%!S&ci=%s",zName,zNew,zCkin2))\ |
| 456 | @ %h(zName)</a> version %z(href("%R/artifact/%!S",zNew))[%S(zNew)]</a>. |
| 457 | } |
| 458 | if( zOld && zNew && fossil_strcmp(zOld,zNew)!=0 ){ |
| 459 | if( pCfg ){ |
| 460 | @ </span></div> |
| 461 | append_diff(zOld, zNew, pCfg); |
| @@ -624,10 +647,58 @@ | |
| 624 | www_print_timeline(&q, TIMELINE_DISJOINT|TIMELINE_GRAPH|TIMELINE_NOSCROLL, |
| 625 | &xtra); |
| 626 | db_finalize(&q); |
| 627 | style_finish_page(); |
| 628 | } |
| 629 | |
| 630 | /* |
| 631 | ** Render a web-page diff of the changes in the working check-out |
| 632 | */ |
| 633 | static void ckout_normal_diff(int vid){ |
| @@ -734,16 +805,11 @@ | |
| 734 | blob_reset(&old); |
| 735 | blob_reset(&new); |
| 736 | } |
| 737 | } |
| 738 | db_finalize(&q); |
| 739 | @ <script nonce='%h(style_nonce())'>;/* info.c:%d(__LINE__) */ |
| 740 | @ document.getElementById('changes_section').textContent = 'Changes ' + |
| 741 | @ '(%d(g.diffCnt[0]) file' + (%d(g.diffCnt[0])===1 ? '' : 's') + ': ' + |
| 742 | @ '+%d(g.diffCnt[1]) ' + |
| 743 | @ '−%d(g.diffCnt[2]))' |
| 744 | @ </script> |
| 745 | append_diff_javascript(diffType); |
| 746 | } |
| 747 | |
| 748 | /* |
| 749 | ** Render a web-page diff of the changes in the working check-out to |
| @@ -827,16 +893,11 @@ | |
| 827 | } |
| 828 | fossil_free(zLhs); |
| 829 | fossil_free(zRhs); |
| 830 | } |
| 831 | db_finalize(&q); |
| 832 | @ <script nonce='%h(style_nonce())'>;/* info.c:%d(__LINE__) */ |
| 833 | @ document.getElementById('changes_section').textContent = 'Changes ' + |
| 834 | @ '(%d(g.diffCnt[0]) file' + (%d(g.diffCnt[0])===1 ? '' : 's') + ': ' + |
| 835 | @ '+%d(g.diffCnt[1]) ' + |
| 836 | @ '−%d(g.diffCnt[2]))' |
| 837 | @ </script> |
| 838 | append_diff_javascript(diffType); |
| 839 | } |
| 840 | |
| 841 | /* |
| 842 | ** WEBPAGE: ckout |
| @@ -935,11 +996,13 @@ | |
| 935 | ReCompiled *pRe = 0; /* regex */ |
| 936 | const char *zW; /* URL param for ignoring whitespace */ |
| 937 | const char *zPage = "vinfo"; /* Page that shows diffs */ |
| 938 | const char *zBrName; /* Branch name */ |
| 939 | DiffConfig DCfg,*pCfg; /* Type of diff */ |
| 940 | |
| 941 | login_check_credentials(); |
| 942 | if( !g.perm.Read ){ login_needed(g.anon.Read); return; } |
| 943 | style_set_current_feature("vinfo"); |
| 944 | zName = P("name"); |
| 945 | rid = name_to_rid_www("name"); |
| @@ -1253,21 +1316,16 @@ | |
| 1253 | int mperm = db_column_int(&q3, 1); |
| 1254 | const char *zOld = db_column_text(&q3,2); |
| 1255 | const char *zNew = db_column_text(&q3,3); |
| 1256 | const char *zOldName = db_column_text(&q3, 4); |
| 1257 | append_file_change_line(zUuid, zName, zOld, zNew, zOldName, |
| 1258 | pCfg,mperm); |
| 1259 | } |
| 1260 | db_finalize(&q3); |
| 1261 | @ </div> |
| 1262 | if( diffType!=0 ){ |
| 1263 | @ <script nonce='%h(style_nonce())'>;/* info.c:%d(__LINE__) */ |
| 1264 | @ document.getElementById('changes_section').textContent = 'Changes ' + |
| 1265 | @ '(%d(g.diffCnt[0]) file' + (%d(g.diffCnt[0])===1 ? '' : 's') + ': ' + |
| 1266 | @ '+%d(g.diffCnt[1]) ' + |
| 1267 | @ '−%d(g.diffCnt[2]))' |
| 1268 | @ </script> |
| 1269 | } |
| 1270 | append_diff_javascript(diffType); |
| 1271 | style_finish_page(); |
| 1272 | } |
| 1273 | |
| @@ -1449,11 +1507,13 @@ | |
| 1449 | DiffConfig DCfg, *pCfg = 0; |
| 1450 | int graphFlags = 0; |
| 1451 | Blob qp; /* non-glob= query parameters for generated links */ |
| 1452 | Blob qpGlob; /* glob= query parameter for generated links */ |
| 1453 | int bInvert = PB("inv"); |
| 1454 | |
| 1455 | login_check_credentials(); |
| 1456 | if( !g.perm.Read ){ login_needed(g.anon.Read); return; } |
| 1457 | if( robot_restrict("diff") ) return; |
| 1458 | login_anonymous_available(); |
| 1459 | fossil_nice_default(); |
| @@ -1594,18 +1654,18 @@ | |
| 1594 | cmp = fossil_strcmp(pFileFrom->zName, pFileTo->zName); |
| 1595 | } |
| 1596 | if( cmp<0 ){ |
| 1597 | if( !pGlob || glob_match(pGlob, pFileFrom->zName) ){ |
| 1598 | append_file_change_line(zFrom, pFileFrom->zName, |
| 1599 | pFileFrom->zUuid, 0, 0, pCfg, 0); |
| 1600 | } |
| 1601 | pFileFrom = manifest_file_next(pFrom, 0); |
| 1602 | }else if( cmp>0 ){ |
| 1603 | if( !pGlob || glob_match(pGlob, pFileTo->zName) ){ |
| 1604 | append_file_change_line(zTo, pFileTo->zName, |
| 1605 | 0, pFileTo->zUuid, 0, pCfg, |
| 1606 | manifest_file_mperm(pFileTo)); |
| 1607 | } |
| 1608 | pFileTo = manifest_file_next(pTo, 0); |
| 1609 | }else if( fossil_strcmp(pFileFrom->zUuid, pFileTo->zUuid)==0 ){ |
| 1610 | pFileFrom = manifest_file_next(pFrom, 0); |
| 1611 | pFileTo = manifest_file_next(pTo, 0); |
| @@ -1613,11 +1673,11 @@ | |
| 1613 | if(!pGlob || (glob_match(pGlob, pFileFrom->zName) |
| 1614 | || glob_match(pGlob, pFileTo->zName)) ){ |
| 1615 | append_file_change_line(zFrom, pFileFrom->zName, |
| 1616 | pFileFrom->zUuid, |
| 1617 | pFileTo->zUuid, 0, pCfg, |
| 1618 | manifest_file_mperm(pFileTo)); |
| 1619 | } |
| 1620 | pFileFrom = manifest_file_next(pFrom, 0); |
| 1621 | pFileTo = manifest_file_next(pTo, 0); |
| 1622 | } |
| 1623 | } |
| @@ -1871,40 +1931,43 @@ | |
| 1871 | @ Also attachment "%h(zFilename)" to |
| 1872 | }else{ |
| 1873 | @ Attachment "%h(zFilename)" to |
| 1874 | } |
| 1875 | objType |= OBJTYPE_ATTACHMENT; |
| 1876 | if( fossil_is_artifact_hash(zTarget) ){ |
| 1877 | if ( db_exists("SELECT 1 FROM tag WHERE tagname='tkt-%q'", |
| 1878 | zTarget) |
| 1879 | ){ |
| 1880 | if( g.perm.Hyperlink && g.anon.RdTkt ){ |
| 1881 | @ ticket [%z(href("%R/tktview?name=%!S",zTarget))%S(zTarget)</a>] |
| 1882 | }else{ |
| 1883 | @ ticket [%S(zTarget)] |
| 1884 | } |
| 1885 | }else if( db_exists("SELECT 1 FROM tag WHERE tagname='event-%q'", |
| 1886 | zTarget) |
| 1887 | ){ |
| 1888 | if( g.perm.Hyperlink && g.anon.RdWiki ){ |
| 1889 | @ tech note [%z(href("%R/technote/%h",zTarget))%S(zTarget)</a>] |
| 1890 | }else{ |
| 1891 | @ tech note [%S(zTarget)] |
| 1892 | } |
| 1893 | }else{ |
| 1894 | if( g.perm.Hyperlink && g.anon.RdWiki ){ |
| 1895 | @ wiki page [%z(href("%R/wiki?name=%t",zTarget))%h(zTarget)</a>] |
| 1896 | }else{ |
| 1897 | @ wiki page [%h(zTarget)] |
| 1898 | } |
| 1899 | } |
| 1900 | }else{ |
| 1901 | if( g.perm.Hyperlink && g.anon.RdWiki ){ |
| 1902 | @ wiki page [%z(href("%R/wiki?name=%t",zTarget))%h(zTarget)</a>] |
| 1903 | }else{ |
| 1904 | @ wiki page [%h(zTarget)] |
| 1905 | } |
| 1906 | } |
| 1907 | @ added by |
| 1908 | hyperlink_to_user(zUser,zDate," on"); |
| 1909 | hyperlink_to_date(zDate,"."); |
| 1910 | cnt++; |
| 1911 |
| --- src/info.c | |
| +++ src/info.c | |
| @@ -371,10 +371,21 @@ | |
| 371 | pCfg->zLeftHash = 0; |
| 372 | blob_reset(&from); |
| 373 | blob_reset(&to); |
| 374 | } |
| 375 | |
| 376 | /* |
| 377 | ** The append_file_change_line() routine updates an array of counts |
| 378 | ** for various kinds of changes. |
| 379 | */ |
| 380 | #define FCHNG_NEW 0 |
| 381 | #define FCHNG_DELETE 1 |
| 382 | #define FCHNG_RENAME 2 |
| 383 | #define FCHNG_MODE 3 |
| 384 | #define FCHNG_EDIT 4 |
| 385 | #define N_FCHNG 5 |
| 386 | |
| 387 | /* |
| 388 | ** Write a line of web-page output that shows changes that have occurred |
| 389 | ** to a file between two check-ins. |
| 390 | */ |
| 391 | static void append_file_change_line( |
| @@ -382,32 +393,38 @@ | |
| 393 | const char *zName, /* Name of the file that has changed */ |
| 394 | const char *zOld, /* blob.uuid before change. NULL for added files */ |
| 395 | const char *zNew, /* blob.uuid after change. NULL for deletes */ |
| 396 | const char *zOldName, /* Prior name. NULL if no name change. */ |
| 397 | DiffConfig *pCfg, /* Flags for text_diff() or NULL to omit all */ |
| 398 | int mperm, /* executable or symlink permission for zNew */ |
| 399 | int *aChng /* Change count array */ |
| 400 | ){ |
| 401 | @ <div class='file-change-line'><span> |
| 402 | /* Maintenance reminder: the extra level of SPAN is for |
| 403 | ** arranging new elements via JS. */ |
| 404 | if( !g.perm.Hyperlink ){ |
| 405 | if( zNew==0 ){ |
| 406 | @ Deleted %h(zName). |
| 407 | aChng[FCHNG_DELETE]++; |
| 408 | }else if( zOld==0 ){ |
| 409 | @ Added %h(zName). |
| 410 | aChng[FCHNG_NEW]++; |
| 411 | }else if( zOldName!=0 && fossil_strcmp(zName,zOldName)!=0 ){ |
| 412 | @ Name change from %h(zOldName) to %h(zName). |
| 413 | aChng[FCHNG_RENAME]++; |
| 414 | }else if( fossil_strcmp(zNew, zOld)==0 ){ |
| 415 | if( mperm==PERM_EXE ){ |
| 416 | @ %h(zName) became executable. |
| 417 | }else if( mperm==PERM_LNK ){ |
| 418 | @ %h(zName) became a symlink. |
| 419 | }else{ |
| 420 | @ %h(zName) became a regular file. |
| 421 | } |
| 422 | aChng[FCHNG_MODE]++; |
| 423 | }else{ |
| 424 | @ Changes to %h(zName). |
| 425 | aChng[FCHNG_EDIT]++; |
| 426 | } |
| 427 | @ </span></div> |
| 428 | if( pCfg ){ |
| 429 | append_diff(zOld, zNew, pCfg); |
| 430 | } |
| @@ -422,22 +439,25 @@ | |
| 439 | @ %h(zOldName)</a> |
| 440 | @ %z(href("%R/artifact/%!S",zOld))[%S(zOld)]</a> |
| 441 | @ to %z(href("%R/finfo?name=%T&m=%!S&ci=%s",zName,zNew,zCkin2))\ |
| 442 | @ %h(zName)</a> |
| 443 | @ %z(href("%R/artifact/%!S",zNew))[%S(zNew)]</a>. |
| 444 | aChng[FCHNG_RENAME]++; |
| 445 | }else{ |
| 446 | @ Modified %z(href("%R/finfo?name=%T&m=%!S&ci=%s",zName,zNew,zCkin2))\ |
| 447 | @ %h(zName)</a> |
| 448 | @ from %z(href("%R/artifact/%!S",zOld))[%S(zOld)]</a> |
| 449 | @ to %z(href("%R/artifact/%!S",zNew))[%S(zNew)]</a>. |
| 450 | } |
| 451 | aChng[FCHNG_EDIT]++; |
| 452 | }else if( zOldName!=0 && fossil_strcmp(zName,zOldName)!=0 ){ |
| 453 | @ Name change |
| 454 | @ from %z(href("%R/finfo?name=%T&m=%!S&ci=%s",zOldName,zOld,zCkin2))\ |
| 455 | @ %h(zOldName)</a> |
| 456 | @ to %z(href("%R/finfo?name=%T&m=%!S&ci=%s",zName,zNew,zCkin2))\ |
| 457 | @ %h(zName)</a>. |
| 458 | aChng[FCHNG_RENAME]++; |
| 459 | }else{ |
| 460 | @ %z(href("%R/finfo?name=%T&m=%!S&ci=%s",zName,zNew,zCkin2))\ |
| 461 | @ %h(zName)</a> became |
| 462 | if( mperm==PERM_EXE ){ |
| 463 | @ executable with contents |
| @@ -445,17 +465,20 @@ | |
| 465 | @ a symlink with target |
| 466 | }else{ |
| 467 | @ a regular file with contents |
| 468 | } |
| 469 | @ %z(href("%R/artifact/%!S",zNew))[%S(zNew)]</a>. |
| 470 | aChng[FCHNG_MODE]++; |
| 471 | } |
| 472 | }else if( zOld ){ |
| 473 | @ Deleted %z(href("%R/finfo?name=%T&m=%!S&ci=%s",zName,zOld,zCkin2))\ |
| 474 | @ %h(zName)</a> version %z(href("%R/artifact/%!S",zOld))[%S(zOld)]</a>. |
| 475 | aChng[FCHNG_DELETE]++; |
| 476 | }else{ |
| 477 | @ Added %z(href("%R/finfo?name=%T&m=%!S&ci=%s",zName,zNew,zCkin2))\ |
| 478 | @ %h(zName)</a> version %z(href("%R/artifact/%!S",zNew))[%S(zNew)]</a>. |
| 479 | aChng[FCHNG_NEW]++; |
| 480 | } |
| 481 | if( zOld && zNew && fossil_strcmp(zOld,zNew)!=0 ){ |
| 482 | if( pCfg ){ |
| 483 | @ </span></div> |
| 484 | append_diff(zOld, zNew, pCfg); |
| @@ -624,10 +647,58 @@ | |
| 647 | www_print_timeline(&q, TIMELINE_DISJOINT|TIMELINE_GRAPH|TIMELINE_NOSCROLL, |
| 648 | &xtra); |
| 649 | db_finalize(&q); |
| 650 | style_finish_page(); |
| 651 | } |
| 652 | |
| 653 | /* |
| 654 | ** Generate JS code that will adjust the change counts in the title |
| 655 | ** of the "changes_section" panel where "changes_section" is a JS id. |
| 656 | ** |
| 657 | ** The change counts are taken from g.diffCnt[] for edits, and from |
| 658 | ** the aChng[] parameter for additions, deletions, and modifications. |
| 659 | ** The aChng parameter may be NULL, in which case those factors are |
| 660 | ** ignored. |
| 661 | */ |
| 662 | static void adjust_changes_section_title( |
| 663 | int iLine, /* Souce code line number of caller */ |
| 664 | int *aChng /* Change categories */ |
| 665 | ){ |
| 666 | sqlite3_str *pTxt = sqlite3_str_new(0); |
| 667 | if( g.diffCnt[0]>0 ){ |
| 668 | sqlite3_str_appendf(pTxt, "%d file%s edited [+%d -%d lines]", |
| 669 | g.diffCnt[0], g.diffCnt[0]==1 ? "" : "s", |
| 670 | g.diffCnt[1], g.diffCnt[2]); |
| 671 | } |
| 672 | if( aChng ){ |
| 673 | static const int aiType[] = |
| 674 | { FCHNG_NEW, FCHNG_DELETE, FCHNG_RENAME, FCHNG_MODE }; |
| 675 | static const char *azType[] = |
| 676 | { "added", "deleted", "renamed", "mode change"}; |
| 677 | int i; |
| 678 | for(i=0; i<4; i++){ |
| 679 | int j = aiType[i]; |
| 680 | if( aChng[j] ){ |
| 681 | const char *zFiles = ""; |
| 682 | if( sqlite3_str_length(pTxt)>0 ){ |
| 683 | sqlite3_str_append(pTxt,", ", 2); |
| 684 | }else{ |
| 685 | zFiles = i<3 && aChng[j]>1 ? " files" : " file"; |
| 686 | } |
| 687 | sqlite3_str_appendf(pTxt,"%d%s %s", aChng[j], zFiles, azType[i]); |
| 688 | if( i==3 && aChng[j]>1 ) sqlite3_str_appendf(pTxt, "s"); |
| 689 | } |
| 690 | } |
| 691 | } |
| 692 | if( sqlite3_str_length(pTxt)>0 ){ |
| 693 | @ <script nonce='%h(style_nonce())'>;/* info.c:%d(iLine) */ |
| 694 | @ document.getElementById('changes_section').textContent = \ |
| 695 | @ 'Changes (%h(sqlite3_str_value(pTxt)))' |
| 696 | @ </script> |
| 697 | } |
| 698 | sqlite3_str_free(pTxt); |
| 699 | } |
| 700 | |
| 701 | /* |
| 702 | ** Render a web-page diff of the changes in the working check-out |
| 703 | */ |
| 704 | static void ckout_normal_diff(int vid){ |
| @@ -734,16 +805,11 @@ | |
| 805 | blob_reset(&old); |
| 806 | blob_reset(&new); |
| 807 | } |
| 808 | } |
| 809 | db_finalize(&q); |
| 810 | adjust_changes_section_title(__LINE__, 0); |
| 811 | append_diff_javascript(diffType); |
| 812 | } |
| 813 | |
| 814 | /* |
| 815 | ** Render a web-page diff of the changes in the working check-out to |
| @@ -827,16 +893,11 @@ | |
| 893 | } |
| 894 | fossil_free(zLhs); |
| 895 | fossil_free(zRhs); |
| 896 | } |
| 897 | db_finalize(&q); |
| 898 | adjust_changes_section_title(__LINE__, 0); |
| 899 | append_diff_javascript(diffType); |
| 900 | } |
| 901 | |
| 902 | /* |
| 903 | ** WEBPAGE: ckout |
| @@ -935,11 +996,13 @@ | |
| 996 | ReCompiled *pRe = 0; /* regex */ |
| 997 | const char *zW; /* URL param for ignoring whitespace */ |
| 998 | const char *zPage = "vinfo"; /* Page that shows diffs */ |
| 999 | const char *zBrName; /* Branch name */ |
| 1000 | DiffConfig DCfg,*pCfg; /* Type of diff */ |
| 1001 | int aChng[N_FCHNG]; /* Counts of change types */ |
| 1002 | |
| 1003 | memset(aChng, 0, sizeof(aChng)); |
| 1004 | login_check_credentials(); |
| 1005 | if( !g.perm.Read ){ login_needed(g.anon.Read); return; } |
| 1006 | style_set_current_feature("vinfo"); |
| 1007 | zName = P("name"); |
| 1008 | rid = name_to_rid_www("name"); |
| @@ -1253,21 +1316,16 @@ | |
| 1316 | int mperm = db_column_int(&q3, 1); |
| 1317 | const char *zOld = db_column_text(&q3,2); |
| 1318 | const char *zNew = db_column_text(&q3,3); |
| 1319 | const char *zOldName = db_column_text(&q3, 4); |
| 1320 | append_file_change_line(zUuid, zName, zOld, zNew, zOldName, |
| 1321 | pCfg,mperm,aChng); |
| 1322 | } |
| 1323 | db_finalize(&q3); |
| 1324 | @ </div> |
| 1325 | if( diffType!=0 ){ |
| 1326 | adjust_changes_section_title(__LINE__, aChng); |
| 1327 | } |
| 1328 | append_diff_javascript(diffType); |
| 1329 | style_finish_page(); |
| 1330 | } |
| 1331 | |
| @@ -1449,11 +1507,13 @@ | |
| 1507 | DiffConfig DCfg, *pCfg = 0; |
| 1508 | int graphFlags = 0; |
| 1509 | Blob qp; /* non-glob= query parameters for generated links */ |
| 1510 | Blob qpGlob; /* glob= query parameter for generated links */ |
| 1511 | int bInvert = PB("inv"); |
| 1512 | int aChng[N_FCHNG]; /* Count of versiou change types */ |
| 1513 | |
| 1514 | memset(aChng, 0, sizeof(aChng)); |
| 1515 | login_check_credentials(); |
| 1516 | if( !g.perm.Read ){ login_needed(g.anon.Read); return; } |
| 1517 | if( robot_restrict("diff") ) return; |
| 1518 | login_anonymous_available(); |
| 1519 | fossil_nice_default(); |
| @@ -1594,18 +1654,18 @@ | |
| 1654 | cmp = fossil_strcmp(pFileFrom->zName, pFileTo->zName); |
| 1655 | } |
| 1656 | if( cmp<0 ){ |
| 1657 | if( !pGlob || glob_match(pGlob, pFileFrom->zName) ){ |
| 1658 | append_file_change_line(zFrom, pFileFrom->zName, |
| 1659 | pFileFrom->zUuid, 0, 0, pCfg, 0,aChng); |
| 1660 | } |
| 1661 | pFileFrom = manifest_file_next(pFrom, 0); |
| 1662 | }else if( cmp>0 ){ |
| 1663 | if( !pGlob || glob_match(pGlob, pFileTo->zName) ){ |
| 1664 | append_file_change_line(zTo, pFileTo->zName, |
| 1665 | 0, pFileTo->zUuid, 0, pCfg, |
| 1666 | manifest_file_mperm(pFileTo),aChng); |
| 1667 | } |
| 1668 | pFileTo = manifest_file_next(pTo, 0); |
| 1669 | }else if( fossil_strcmp(pFileFrom->zUuid, pFileTo->zUuid)==0 ){ |
| 1670 | pFileFrom = manifest_file_next(pFrom, 0); |
| 1671 | pFileTo = manifest_file_next(pTo, 0); |
| @@ -1613,11 +1673,11 @@ | |
| 1673 | if(!pGlob || (glob_match(pGlob, pFileFrom->zName) |
| 1674 | || glob_match(pGlob, pFileTo->zName)) ){ |
| 1675 | append_file_change_line(zFrom, pFileFrom->zName, |
| 1676 | pFileFrom->zUuid, |
| 1677 | pFileTo->zUuid, 0, pCfg, |
| 1678 | manifest_file_mperm(pFileTo),aChng); |
| 1679 | } |
| 1680 | pFileFrom = manifest_file_next(pFrom, 0); |
| 1681 | pFileTo = manifest_file_next(pTo, 0); |
| 1682 | } |
| 1683 | } |
| @@ -1871,40 +1931,43 @@ | |
| 1931 | @ Also attachment "%h(zFilename)" to |
| 1932 | }else{ |
| 1933 | @ Attachment "%h(zFilename)" to |
| 1934 | } |
| 1935 | objType |= OBJTYPE_ATTACHMENT; |
| 1936 | switch( attachment_target_type(zTarget, 1) ){ |
| 1937 | case CFTYPE_FORUM: |
| 1938 | if( g.perm.Hyperlink && g.anon.RdForum ){ |
| 1939 | @ forum post [%z(href("%R/forumpost/%!S",zTarget))%S(zTarget)</a>] |
| 1940 | }else{ |
| 1941 | @ forum post [%S(zTarget)] |
| 1942 | } |
| 1943 | break; |
| 1944 | case CFTYPE_TICKET: |
| 1945 | if( g.perm.Hyperlink && g.anon.RdTkt ){ |
| 1946 | @ ticket [%z(href("%R/tktview?name=%!S",zTarget))%S(zTarget)</a>] |
| 1947 | }else{ |
| 1948 | @ ticket [%S(zTarget)] |
| 1949 | } |
| 1950 | break; |
| 1951 | case CFTYPE_EVENT: |
| 1952 | if( g.perm.Hyperlink && g.anon.RdWiki ){ |
| 1953 | @ tech note [%z(href("%R/technote/%h",zTarget))%S(zTarget)</a>] |
| 1954 | }else{ |
| 1955 | @ tech note [%S(zTarget)] |
| 1956 | } |
| 1957 | break; |
| 1958 | case CFTYPE_WIKI: |
| 1959 | if( g.perm.Hyperlink && g.anon.RdWiki ){ |
| 1960 | @ wiki page [%z(href("%R/wiki?name=%t",zTarget))%h(zTarget)</a>] |
| 1961 | }else{ |
| 1962 | @ wiki page [%h(zTarget)] |
| 1963 | } |
| 1964 | break; |
| 1965 | default: |
| 1966 | /* historical behavior is to assume wiki, but we can end up |
| 1967 | ** showing bogus links that way to stale attachments. */ |
| 1968 | @ unknown artifact %h(zTarget) |
| 1969 | } |
| 1970 | @ added by |
| 1971 | hyperlink_to_user(zUser,zDate," on"); |
| 1972 | hyperlink_to_date(zDate,"."); |
| 1973 | cnt++; |
| 1974 |
+3
-1
| --- src/login.c | ||
| +++ src/login.c | ||
| @@ -1708,11 +1708,12 @@ | ||
| 1708 | 1708 | p->NewTkt = p->Password = p->RdAddr = |
| 1709 | 1709 | p->TktFmt = p->Attach = p->ApndTkt = |
| 1710 | 1710 | p->ModWiki = p->ModTkt = |
| 1711 | 1711 | p->RdForum = p->WrForum = p->ModForum = |
| 1712 | 1712 | p->WrTForum = p->AdminForum = p->Chat = |
| 1713 | - p->EmailAlert = p->Announce = p->Debug = 1; | |
| 1713 | + p->EmailAlert = p->Announce = p->AttachForum = | |
| 1714 | + p->Debug = 1; | |
| 1714 | 1715 | /* Fall thru into Read/Write */ |
| 1715 | 1716 | case 'i': p->Read = p->Write = 1; break; |
| 1716 | 1717 | case 'o': p->Read = 1; break; |
| 1717 | 1718 | case 'z': p->Zip = 1; break; |
| 1718 | 1719 | |
| @@ -1744,10 +1745,11 @@ | ||
| 1744 | 1745 | case '3': p->WrForum = 1; |
| 1745 | 1746 | case '2': p->RdForum = 1; break; |
| 1746 | 1747 | |
| 1747 | 1748 | case '7': p->EmailAlert = 1; break; |
| 1748 | 1749 | case 'A': p->Announce = 1; break; |
| 1750 | + case 'B': p->AttachForum = 1; break; | |
| 1749 | 1751 | case 'C': p->Chat = 1; break; |
| 1750 | 1752 | case 'D': p->Debug = 1; break; |
| 1751 | 1753 | |
| 1752 | 1754 | /* The "u" privilege recursively |
| 1753 | 1755 | ** inherits all privileges of the user named "reader" */ |
| 1754 | 1756 |
| --- src/login.c | |
| +++ src/login.c | |
| @@ -1708,11 +1708,12 @@ | |
| 1708 | p->NewTkt = p->Password = p->RdAddr = |
| 1709 | p->TktFmt = p->Attach = p->ApndTkt = |
| 1710 | p->ModWiki = p->ModTkt = |
| 1711 | p->RdForum = p->WrForum = p->ModForum = |
| 1712 | p->WrTForum = p->AdminForum = p->Chat = |
| 1713 | p->EmailAlert = p->Announce = p->Debug = 1; |
| 1714 | /* Fall thru into Read/Write */ |
| 1715 | case 'i': p->Read = p->Write = 1; break; |
| 1716 | case 'o': p->Read = 1; break; |
| 1717 | case 'z': p->Zip = 1; break; |
| 1718 | |
| @@ -1744,10 +1745,11 @@ | |
| 1744 | case '3': p->WrForum = 1; |
| 1745 | case '2': p->RdForum = 1; break; |
| 1746 | |
| 1747 | case '7': p->EmailAlert = 1; break; |
| 1748 | case 'A': p->Announce = 1; break; |
| 1749 | case 'C': p->Chat = 1; break; |
| 1750 | case 'D': p->Debug = 1; break; |
| 1751 | |
| 1752 | /* The "u" privilege recursively |
| 1753 | ** inherits all privileges of the user named "reader" */ |
| 1754 |
| --- src/login.c | |
| +++ src/login.c | |
| @@ -1708,11 +1708,12 @@ | |
| 1708 | p->NewTkt = p->Password = p->RdAddr = |
| 1709 | p->TktFmt = p->Attach = p->ApndTkt = |
| 1710 | p->ModWiki = p->ModTkt = |
| 1711 | p->RdForum = p->WrForum = p->ModForum = |
| 1712 | p->WrTForum = p->AdminForum = p->Chat = |
| 1713 | p->EmailAlert = p->Announce = p->AttachForum = |
| 1714 | p->Debug = 1; |
| 1715 | /* Fall thru into Read/Write */ |
| 1716 | case 'i': p->Read = p->Write = 1; break; |
| 1717 | case 'o': p->Read = 1; break; |
| 1718 | case 'z': p->Zip = 1; break; |
| 1719 | |
| @@ -1744,10 +1745,11 @@ | |
| 1745 | case '3': p->WrForum = 1; |
| 1746 | case '2': p->RdForum = 1; break; |
| 1747 | |
| 1748 | case '7': p->EmailAlert = 1; break; |
| 1749 | case 'A': p->Announce = 1; break; |
| 1750 | case 'B': p->AttachForum = 1; break; |
| 1751 | case 'C': p->Chat = 1; break; |
| 1752 | case 'D': p->Debug = 1; break; |
| 1753 | |
| 1754 | /* The "u" privilege recursively |
| 1755 | ** inherits all privileges of the user named "reader" */ |
| 1756 |
+2
-1
| --- src/main.c | ||
| +++ src/main.c | ||
| @@ -97,11 +97,11 @@ | ||
| 97 | 97 | char RdTkt; /* r: view tickets via web */ |
| 98 | 98 | char NewTkt; /* n: create new tickets */ |
| 99 | 99 | char ApndTkt; /* c: append to tickets via the web */ |
| 100 | 100 | char WrTkt; /* w: make changes to tickets via web */ |
| 101 | 101 | char ModTkt; /* q: approve and publish ticket changes (Moderator) */ |
| 102 | - char Attach; /* b: add attachments */ | |
| 102 | + char Attach; /* b: add attachments to wiki or tickets */ | |
| 103 | 103 | char TktFmt; /* t: create new ticket report formats */ |
| 104 | 104 | char RdAddr; /* e: read email addresses or other private data */ |
| 105 | 105 | char Zip; /* z: download zipped artifact via /zip URL */ |
| 106 | 106 | char Private; /* x: can send and receive private content */ |
| 107 | 107 | char WrUnver; /* y: can push unversioned content */ |
| @@ -110,10 +110,11 @@ | ||
| 110 | 110 | char WrTForum; /* 4: Post to forums not subject to moderation */ |
| 111 | 111 | char ModForum; /* 5: Moderate (approve or reject) forum posts */ |
| 112 | 112 | char AdminForum; /* 6: Grant capability 4 to other users */ |
| 113 | 113 | char EmailAlert; /* 7: Sign up for email notifications */ |
| 114 | 114 | char Announce; /* A: Send announcements */ |
| 115 | + char AttachForum; /* B: add attachments to forum */ | |
| 115 | 116 | char Chat; /* C: read or write the chatroom */ |
| 116 | 117 | char Debug; /* D: show extra Fossil debugging features */ |
| 117 | 118 | /* These last two are included to block infinite recursion */ |
| 118 | 119 | char XReader; /* u: Inherit all privileges of "reader" */ |
| 119 | 120 | char XDeveloper; /* v: Inherit all privileges of "developer" */ |
| 120 | 121 |
| --- src/main.c | |
| +++ src/main.c | |
| @@ -97,11 +97,11 @@ | |
| 97 | char RdTkt; /* r: view tickets via web */ |
| 98 | char NewTkt; /* n: create new tickets */ |
| 99 | char ApndTkt; /* c: append to tickets via the web */ |
| 100 | char WrTkt; /* w: make changes to tickets via web */ |
| 101 | char ModTkt; /* q: approve and publish ticket changes (Moderator) */ |
| 102 | char Attach; /* b: add attachments */ |
| 103 | char TktFmt; /* t: create new ticket report formats */ |
| 104 | char RdAddr; /* e: read email addresses or other private data */ |
| 105 | char Zip; /* z: download zipped artifact via /zip URL */ |
| 106 | char Private; /* x: can send and receive private content */ |
| 107 | char WrUnver; /* y: can push unversioned content */ |
| @@ -110,10 +110,11 @@ | |
| 110 | char WrTForum; /* 4: Post to forums not subject to moderation */ |
| 111 | char ModForum; /* 5: Moderate (approve or reject) forum posts */ |
| 112 | char AdminForum; /* 6: Grant capability 4 to other users */ |
| 113 | char EmailAlert; /* 7: Sign up for email notifications */ |
| 114 | char Announce; /* A: Send announcements */ |
| 115 | char Chat; /* C: read or write the chatroom */ |
| 116 | char Debug; /* D: show extra Fossil debugging features */ |
| 117 | /* These last two are included to block infinite recursion */ |
| 118 | char XReader; /* u: Inherit all privileges of "reader" */ |
| 119 | char XDeveloper; /* v: Inherit all privileges of "developer" */ |
| 120 |
| --- src/main.c | |
| +++ src/main.c | |
| @@ -97,11 +97,11 @@ | |
| 97 | char RdTkt; /* r: view tickets via web */ |
| 98 | char NewTkt; /* n: create new tickets */ |
| 99 | char ApndTkt; /* c: append to tickets via the web */ |
| 100 | char WrTkt; /* w: make changes to tickets via web */ |
| 101 | char ModTkt; /* q: approve and publish ticket changes (Moderator) */ |
| 102 | char Attach; /* b: add attachments to wiki or tickets */ |
| 103 | char TktFmt; /* t: create new ticket report formats */ |
| 104 | char RdAddr; /* e: read email addresses or other private data */ |
| 105 | char Zip; /* z: download zipped artifact via /zip URL */ |
| 106 | char Private; /* x: can send and receive private content */ |
| 107 | char WrUnver; /* y: can push unversioned content */ |
| @@ -110,10 +110,11 @@ | |
| 110 | char WrTForum; /* 4: Post to forums not subject to moderation */ |
| 111 | char ModForum; /* 5: Moderate (approve or reject) forum posts */ |
| 112 | char AdminForum; /* 6: Grant capability 4 to other users */ |
| 113 | char EmailAlert; /* 7: Sign up for email notifications */ |
| 114 | char Announce; /* A: Send announcements */ |
| 115 | char AttachForum; /* B: add attachments to forum */ |
| 116 | char Chat; /* C: read or write the chatroom */ |
| 117 | char Debug; /* D: show extra Fossil debugging features */ |
| 118 | /* These last two are included to block infinite recursion */ |
| 119 | char XReader; /* u: Inherit all privileges of "reader" */ |
| 120 | char XDeveloper; /* v: Inherit all privileges of "developer" */ |
| 121 |
+6
-1
| --- src/main.mk | ||
| +++ src/main.mk | ||
| @@ -11,11 +11,11 @@ | ||
| 11 | 11 | # |
| 12 | 12 | |
| 13 | 13 | XBCC = $(BCC) $(BCCFLAGS) |
| 14 | 14 | XTCC = $(TCC) $(CFLAGS_INCLUDE) -I$(OBJDIR) $(TCCFLAGS) |
| 15 | 15 | |
| 16 | -TESTFLAGS := -quiet | |
| 16 | +TESTFLAGS = -quiet | |
| 17 | 17 | |
| 18 | 18 | SRC = \ |
| 19 | 19 | $(SRCDIR)/add.c \ |
| 20 | 20 | $(SRCDIR)/ajax.c \ |
| 21 | 21 | $(SRCDIR)/alerts.c \ |
| @@ -225,10 +225,11 @@ | ||
| 225 | 225 | $(SRCDIR)/copybtn.js \ |
| 226 | 226 | $(SRCDIR)/default.css \ |
| 227 | 227 | $(SRCDIR)/diff.js \ |
| 228 | 228 | $(SRCDIR)/diff.tcl \ |
| 229 | 229 | $(SRCDIR)/forum.js \ |
| 230 | + $(SRCDIR)/fossil.attach.js \ | |
| 230 | 231 | $(SRCDIR)/fossil.bootstrap.js \ |
| 231 | 232 | $(SRCDIR)/fossil.confirmer.js \ |
| 232 | 233 | $(SRCDIR)/fossil.copybutton.js \ |
| 233 | 234 | $(SRCDIR)/fossil.diff.js \ |
| 234 | 235 | $(SRCDIR)/fossil.dom.js \ |
| @@ -275,10 +276,11 @@ | ||
| 275 | 276 | $(SRCDIR)/sounds/e.wav \ |
| 276 | 277 | $(SRCDIR)/sounds/f.wav \ |
| 277 | 278 | $(SRCDIR)/style.admin_log.css \ |
| 278 | 279 | $(SRCDIR)/style.chat.css \ |
| 279 | 280 | $(SRCDIR)/style.fileedit.css \ |
| 281 | + $(SRCDIR)/style.forum.css \ | |
| 280 | 282 | $(SRCDIR)/style.pikchrshow.css \ |
| 281 | 283 | $(SRCDIR)/style.uvlist.css \ |
| 282 | 284 | $(SRCDIR)/style.wikiedit.css \ |
| 283 | 285 | $(SRCDIR)/tree.js \ |
| 284 | 286 | $(SRCDIR)/useredit.js \ |
| @@ -2142,16 +2144,19 @@ | ||
| 2142 | 2144 | $(XTCC) -o $(OBJDIR)/zip.o -c $(OBJDIR)/zip_.c |
| 2143 | 2145 | |
| 2144 | 2146 | $(OBJDIR)/zip.h: $(OBJDIR)/headers |
| 2145 | 2147 | |
| 2146 | 2148 | $(SQLITE3_OBJ): $(SQLITE3_SRC) |
| 2149 | + -mkdir -p $(OBJDIR) | |
| 2147 | 2150 | $(XTCC) $(SQLITE_OPTIONS) $(SQLITE_CFLAGS) $(SEE_FLAGS) \ |
| 2148 | 2151 | -c $(SQLITE3_SRC) -o $@ |
| 2149 | 2152 | $(OBJDIR)/shell.o: $(SQLITE3_SHELL_SRC) $(SRCDIR_extsrc)/sqlite3.h |
| 2153 | + -mkdir -p $(OBJDIR) | |
| 2150 | 2154 | $(XTCC) $(SHELL_OPTIONS) $(SHELL_CFLAGS) $(SEE_FLAGS) $(LINENOISE_DEF.$(USE_LINENOISE)) -c $(SQLITE3_SHELL_SRC) -o $@ |
| 2151 | 2155 | |
| 2152 | 2156 | $(OBJDIR)/linenoise.o: $(SRCDIR_extsrc)/linenoise.c $(SRCDIR_extsrc)/linenoise.h |
| 2157 | + -mkdir -p $(OBJDIR) | |
| 2153 | 2158 | $(XTCC) -c $(SRCDIR_extsrc)/linenoise.c -o $@ |
| 2154 | 2159 | |
| 2155 | 2160 | $(OBJDIR)/th.o: $(SRCDIR)/th.c |
| 2156 | 2161 | -mkdir -p $(OBJDIR) |
| 2157 | 2162 | |
| 2158 | 2163 |
| --- src/main.mk | |
| +++ src/main.mk | |
| @@ -11,11 +11,11 @@ | |
| 11 | # |
| 12 | |
| 13 | XBCC = $(BCC) $(BCCFLAGS) |
| 14 | XTCC = $(TCC) $(CFLAGS_INCLUDE) -I$(OBJDIR) $(TCCFLAGS) |
| 15 | |
| 16 | TESTFLAGS := -quiet |
| 17 | |
| 18 | SRC = \ |
| 19 | $(SRCDIR)/add.c \ |
| 20 | $(SRCDIR)/ajax.c \ |
| 21 | $(SRCDIR)/alerts.c \ |
| @@ -225,10 +225,11 @@ | |
| 225 | $(SRCDIR)/copybtn.js \ |
| 226 | $(SRCDIR)/default.css \ |
| 227 | $(SRCDIR)/diff.js \ |
| 228 | $(SRCDIR)/diff.tcl \ |
| 229 | $(SRCDIR)/forum.js \ |
| 230 | $(SRCDIR)/fossil.bootstrap.js \ |
| 231 | $(SRCDIR)/fossil.confirmer.js \ |
| 232 | $(SRCDIR)/fossil.copybutton.js \ |
| 233 | $(SRCDIR)/fossil.diff.js \ |
| 234 | $(SRCDIR)/fossil.dom.js \ |
| @@ -275,10 +276,11 @@ | |
| 275 | $(SRCDIR)/sounds/e.wav \ |
| 276 | $(SRCDIR)/sounds/f.wav \ |
| 277 | $(SRCDIR)/style.admin_log.css \ |
| 278 | $(SRCDIR)/style.chat.css \ |
| 279 | $(SRCDIR)/style.fileedit.css \ |
| 280 | $(SRCDIR)/style.pikchrshow.css \ |
| 281 | $(SRCDIR)/style.uvlist.css \ |
| 282 | $(SRCDIR)/style.wikiedit.css \ |
| 283 | $(SRCDIR)/tree.js \ |
| 284 | $(SRCDIR)/useredit.js \ |
| @@ -2142,16 +2144,19 @@ | |
| 2142 | $(XTCC) -o $(OBJDIR)/zip.o -c $(OBJDIR)/zip_.c |
| 2143 | |
| 2144 | $(OBJDIR)/zip.h: $(OBJDIR)/headers |
| 2145 | |
| 2146 | $(SQLITE3_OBJ): $(SQLITE3_SRC) |
| 2147 | $(XTCC) $(SQLITE_OPTIONS) $(SQLITE_CFLAGS) $(SEE_FLAGS) \ |
| 2148 | -c $(SQLITE3_SRC) -o $@ |
| 2149 | $(OBJDIR)/shell.o: $(SQLITE3_SHELL_SRC) $(SRCDIR_extsrc)/sqlite3.h |
| 2150 | $(XTCC) $(SHELL_OPTIONS) $(SHELL_CFLAGS) $(SEE_FLAGS) $(LINENOISE_DEF.$(USE_LINENOISE)) -c $(SQLITE3_SHELL_SRC) -o $@ |
| 2151 | |
| 2152 | $(OBJDIR)/linenoise.o: $(SRCDIR_extsrc)/linenoise.c $(SRCDIR_extsrc)/linenoise.h |
| 2153 | $(XTCC) -c $(SRCDIR_extsrc)/linenoise.c -o $@ |
| 2154 | |
| 2155 | $(OBJDIR)/th.o: $(SRCDIR)/th.c |
| 2156 | -mkdir -p $(OBJDIR) |
| 2157 | |
| 2158 |
| --- src/main.mk | |
| +++ src/main.mk | |
| @@ -11,11 +11,11 @@ | |
| 11 | # |
| 12 | |
| 13 | XBCC = $(BCC) $(BCCFLAGS) |
| 14 | XTCC = $(TCC) $(CFLAGS_INCLUDE) -I$(OBJDIR) $(TCCFLAGS) |
| 15 | |
| 16 | TESTFLAGS = -quiet |
| 17 | |
| 18 | SRC = \ |
| 19 | $(SRCDIR)/add.c \ |
| 20 | $(SRCDIR)/ajax.c \ |
| 21 | $(SRCDIR)/alerts.c \ |
| @@ -225,10 +225,11 @@ | |
| 225 | $(SRCDIR)/copybtn.js \ |
| 226 | $(SRCDIR)/default.css \ |
| 227 | $(SRCDIR)/diff.js \ |
| 228 | $(SRCDIR)/diff.tcl \ |
| 229 | $(SRCDIR)/forum.js \ |
| 230 | $(SRCDIR)/fossil.attach.js \ |
| 231 | $(SRCDIR)/fossil.bootstrap.js \ |
| 232 | $(SRCDIR)/fossil.confirmer.js \ |
| 233 | $(SRCDIR)/fossil.copybutton.js \ |
| 234 | $(SRCDIR)/fossil.diff.js \ |
| 235 | $(SRCDIR)/fossil.dom.js \ |
| @@ -275,10 +276,11 @@ | |
| 276 | $(SRCDIR)/sounds/e.wav \ |
| 277 | $(SRCDIR)/sounds/f.wav \ |
| 278 | $(SRCDIR)/style.admin_log.css \ |
| 279 | $(SRCDIR)/style.chat.css \ |
| 280 | $(SRCDIR)/style.fileedit.css \ |
| 281 | $(SRCDIR)/style.forum.css \ |
| 282 | $(SRCDIR)/style.pikchrshow.css \ |
| 283 | $(SRCDIR)/style.uvlist.css \ |
| 284 | $(SRCDIR)/style.wikiedit.css \ |
| 285 | $(SRCDIR)/tree.js \ |
| 286 | $(SRCDIR)/useredit.js \ |
| @@ -2142,16 +2144,19 @@ | |
| 2144 | $(XTCC) -o $(OBJDIR)/zip.o -c $(OBJDIR)/zip_.c |
| 2145 | |
| 2146 | $(OBJDIR)/zip.h: $(OBJDIR)/headers |
| 2147 | |
| 2148 | $(SQLITE3_OBJ): $(SQLITE3_SRC) |
| 2149 | -mkdir -p $(OBJDIR) |
| 2150 | $(XTCC) $(SQLITE_OPTIONS) $(SQLITE_CFLAGS) $(SEE_FLAGS) \ |
| 2151 | -c $(SQLITE3_SRC) -o $@ |
| 2152 | $(OBJDIR)/shell.o: $(SQLITE3_SHELL_SRC) $(SRCDIR_extsrc)/sqlite3.h |
| 2153 | -mkdir -p $(OBJDIR) |
| 2154 | $(XTCC) $(SHELL_OPTIONS) $(SHELL_CFLAGS) $(SEE_FLAGS) $(LINENOISE_DEF.$(USE_LINENOISE)) -c $(SQLITE3_SHELL_SRC) -o $@ |
| 2155 | |
| 2156 | $(OBJDIR)/linenoise.o: $(SRCDIR_extsrc)/linenoise.c $(SRCDIR_extsrc)/linenoise.h |
| 2157 | -mkdir -p $(OBJDIR) |
| 2158 | $(XTCC) -c $(SRCDIR_extsrc)/linenoise.c -o $@ |
| 2159 | |
| 2160 | $(OBJDIR)/th.o: $(SRCDIR)/th.c |
| 2161 | -mkdir -p $(OBJDIR) |
| 2162 | |
| 2163 |
+98
-53
| --- src/manifest.c | ||
| +++ src/manifest.c | ||
| @@ -1128,20 +1128,16 @@ | ||
| 1128 | 1128 | md5sum_init(); |
| 1129 | 1129 | if( !isRepeat ) g.parseCnt[p->type]++; |
| 1130 | 1130 | return p; |
| 1131 | 1131 | |
| 1132 | 1132 | manifest_syntax_error: |
| 1133 | - { | |
| 1134 | - char *zUuid = rid_to_uuid(rid); | |
| 1133 | + if(pErr!=0){ | |
| 1134 | + char *zUuid = rid>0 ? rid_to_uuid(rid) : 0; | |
| 1135 | 1135 | if( zUuid ){ |
| 1136 | - if(pErr!=0){ | |
| 1137 | - blob_appendf(pErr, "artifact [%s] ", zUuid); | |
| 1138 | - } | |
| 1136 | + blob_appendf(pErr, "artifact [%s] ", zUuid); | |
| 1139 | 1137 | fossil_free(zUuid); |
| 1140 | 1138 | } |
| 1141 | - } | |
| 1142 | - if(pErr!=0){ | |
| 1143 | 1139 | if( zErr ){ |
| 1144 | 1140 | blob_appendf(pErr, "line %d: %s", lineNo, zErr); |
| 1145 | 1141 | }else{ |
| 1146 | 1142 | blob_appendf(pErr, "unknown error on line %d", lineNo); |
| 1147 | 1143 | } |
| @@ -2630,26 +2626,11 @@ | ||
| 2630 | 2626 | db_finalize(&qatt); |
| 2631 | 2627 | } |
| 2632 | 2628 | if( p->type==CFTYPE_ATTACHMENT ){ |
| 2633 | 2629 | char *zComment = 0; |
| 2634 | 2630 | const char isAdd = (p->zAttachSrc && p->zAttachSrc[0]) ? 1 : 0; |
| 2635 | - /* We assume that we're attaching to a wiki page until we | |
| 2636 | - ** prove otherwise (which could on a later artifact if we | |
| 2637 | - ** process the attachment artifact before the artifact to | |
| 2638 | - ** which it is attached!) */ | |
| 2639 | - char attachToType = 'w'; | |
| 2640 | - if( fossil_is_artifact_hash(p->zAttachTarget) ){ | |
| 2641 | - if( db_exists("SELECT 1 FROM tag WHERE tagname='tkt-%q'", | |
| 2642 | - p->zAttachTarget) | |
| 2643 | - ){ | |
| 2644 | - attachToType = 't'; /* Attaching to known ticket */ | |
| 2645 | - }else if( db_exists("SELECT 1 FROM tag WHERE tagname='event-%q'", | |
| 2646 | - p->zAttachTarget) | |
| 2647 | - ){ | |
| 2648 | - attachToType = 'e'; /* Attaching to known tech note */ | |
| 2649 | - } | |
| 2650 | - } | |
| 2631 | + char attachToType = 0; | |
| 2651 | 2632 | db_multi_exec( |
| 2652 | 2633 | "INSERT INTO attachment(attachid, mtime, src, target," |
| 2653 | 2634 | "filename, comment, user)" |
| 2654 | 2635 | "VALUES(%d,%.17g,%Q,%Q,%Q,%Q,%Q);", |
| 2655 | 2636 | rid, p->rDate, p->zAttachSrc, p->zAttachTarget, p->zAttachName, |
| @@ -2661,40 +2642,82 @@ | ||
| 2661 | 2642 | " WHERE target=%Q AND filename=%Q))" |
| 2662 | 2643 | " WHERE target=%Q AND filename=%Q", |
| 2663 | 2644 | p->zAttachTarget, p->zAttachName, |
| 2664 | 2645 | p->zAttachTarget, p->zAttachName |
| 2665 | 2646 | ); |
| 2666 | - if( 'w' == attachToType ){ | |
| 2667 | - if( isAdd ){ | |
| 2668 | - zComment = mprintf( | |
| 2669 | - "Add attachment [/artifact/%!S|%h] to wiki page [%h]", | |
| 2670 | - p->zAttachSrc, p->zAttachName, p->zAttachTarget); | |
| 2671 | - }else{ | |
| 2672 | - zComment = mprintf("Delete attachment \"%h\" from wiki page [%h]", | |
| 2673 | - p->zAttachName, p->zAttachTarget); | |
| 2674 | - } | |
| 2675 | - }else if( 'e' == attachToType ){ | |
| 2676 | - if( isAdd ){ | |
| 2677 | - zComment = mprintf( | |
| 2678 | - "Add attachment [/artifact/%!S|%h] to tech note [/technote/%!S|%S]", | |
| 2679 | - p->zAttachSrc, p->zAttachName, p->zAttachTarget, p->zAttachTarget); | |
| 2680 | - }else{ | |
| 2681 | - zComment = mprintf( | |
| 2682 | - "Delete attachment \"/artifact/%!S|%h\" from" | |
| 2683 | - " tech note [/technote/%!S|%S]", | |
| 2684 | - p->zAttachName, p->zAttachName, | |
| 2685 | - p->zAttachTarget,p->zAttachTarget); | |
| 2686 | - } | |
| 2687 | - }else{ | |
| 2688 | - if( isAdd ){ | |
| 2689 | - zComment = mprintf( | |
| 2690 | - "Add attachment [/artifact/%!S|%h] to ticket [%!S|%S]", | |
| 2691 | - p->zAttachSrc, p->zAttachName, p->zAttachTarget, p->zAttachTarget); | |
| 2692 | - }else{ | |
| 2693 | - zComment = mprintf("Delete attachment \"%h\" from ticket [%!S|%S]", | |
| 2694 | - p->zAttachName, p->zAttachTarget, p->zAttachTarget); | |
| 2695 | - } | |
| 2647 | + switch( attachment_target_type(p->zAttachTarget, 1) ){ | |
| 2648 | + case 0: | |
| 2649 | + /* It is possible that p->zAttachTarget is not yet in this | |
| 2650 | + ** copy of the repository. If we cannot identify it yet, | |
| 2651 | + ** generate a generic /artifact link to it instead of a | |
| 2652 | + ** type-specific link or an error message. */ | |
| 2653 | + attachToType = 'a'; | |
| 2654 | + if( isAdd ){ | |
| 2655 | + zComment = mprintf( | |
| 2656 | + "Add attachment [/artifact/%!S|%h] to [/artifact/%!S|%h]", | |
| 2657 | + p->zAttachSrc, p->zAttachName, | |
| 2658 | + p->zAttachTarget, p->zAttachTarget); | |
| 2659 | + }else{ | |
| 2660 | + zComment = mprintf("Delete attachment \"%h\" from " | |
| 2661 | + "[/artifact/%!S|%h", | |
| 2662 | + p->zAttachName, p->zAttachTarget, | |
| 2663 | + p->zAttachTarget); | |
| 2664 | + } | |
| 2665 | + break; | |
| 2666 | + case CFTYPE_WIKI: | |
| 2667 | + attachToType = 'w'; | |
| 2668 | + if( isAdd ){ | |
| 2669 | + zComment = mprintf( | |
| 2670 | + "Add attachment [/artifact/%!S|%h] to wiki page [%h]", | |
| 2671 | + p->zAttachSrc, p->zAttachName, p->zAttachTarget); | |
| 2672 | + }else{ | |
| 2673 | + zComment = mprintf("Delete attachment \"%h\" from " | |
| 2674 | + "wiki page [%h]", | |
| 2675 | + p->zAttachName, p->zAttachTarget); | |
| 2676 | + } | |
| 2677 | + break; | |
| 2678 | + case CFTYPE_EVENT: | |
| 2679 | + attachToType = 'e'; | |
| 2680 | + if( isAdd ){ | |
| 2681 | + zComment = mprintf( | |
| 2682 | + "Add attachment [/artifact/%!S|%h] to tech note " | |
| 2683 | + "[/technote/%!S|%S]", | |
| 2684 | + p->zAttachSrc, p->zAttachName, p->zAttachTarget, p->zAttachTarget); | |
| 2685 | + }else{ | |
| 2686 | + zComment = mprintf( | |
| 2687 | + "Delete attachment \"/artifact/%!S|%h\" from" | |
| 2688 | + " tech note [/technote/%!S|%S]", | |
| 2689 | + p->zAttachName, p->zAttachName, | |
| 2690 | + p->zAttachTarget,p->zAttachTarget); | |
| 2691 | + } | |
| 2692 | + break; | |
| 2693 | + case CFTYPE_TICKET: | |
| 2694 | + attachToType = 't'; | |
| 2695 | + if( isAdd ){ | |
| 2696 | + zComment = mprintf( | |
| 2697 | + "Add attachment [/artifact/%!S|%h] to ticket [%!S|%S]", | |
| 2698 | + p->zAttachSrc, p->zAttachName, p->zAttachTarget, p->zAttachTarget); | |
| 2699 | + }else{ | |
| 2700 | + zComment = mprintf( | |
| 2701 | + "Delete attachment \"%h\" from ticket [%!S|%S]", | |
| 2702 | + p->zAttachName, p->zAttachTarget, p->zAttachTarget); | |
| 2703 | + } | |
| 2704 | + break; | |
| 2705 | + case CFTYPE_FORUM: | |
| 2706 | + attachToType = 'f'; | |
| 2707 | + if( isAdd ){ | |
| 2708 | + zComment = mprintf( | |
| 2709 | + "Add attachment [/artifact/%!S|%h] to forum post " | |
| 2710 | + "[/forumpost/%!S|%S]", | |
| 2711 | + p->zAttachSrc, p->zAttachName, p->zAttachTarget, p->zAttachTarget); | |
| 2712 | + }else{ | |
| 2713 | + zComment = mprintf( | |
| 2714 | + "Delete attachment \"%h\" from forum post " | |
| 2715 | + "[/forumpost/%!S|%S]", | |
| 2716 | + p->zAttachName, p->zAttachTarget, p->zAttachTarget); | |
| 2717 | + } | |
| 2718 | + break; | |
| 2696 | 2719 | } |
| 2697 | 2720 | assert( manifest_event_triggers_are_enabled ); |
| 2698 | 2721 | db_multi_exec( |
| 2699 | 2722 | "REPLACE INTO event(type,mtime,objid,user,comment)" |
| 2700 | 2723 | "VALUES('%c',%.17g,%d,%Q,%Q)", |
| @@ -3205,5 +3228,27 @@ | ||
| 3205 | 3228 | db_finalize(&q); |
| 3206 | 3229 | if( nErr ){ |
| 3207 | 3230 | fossil_warning("Error count: %d", nErr); |
| 3208 | 3231 | } |
| 3209 | 3232 | } |
| 3233 | + | |
| 3234 | +/* | |
| 3235 | +** Given the RID of an artifact, if that artifact type supports | |
| 3236 | +** P-cards then this returns the root-most RID of the P-card chain by | |
| 3237 | +** traversing the plink table, considering only primary parents. If | |
| 3238 | +** rid refers to anything other than such an artifact, or if the | |
| 3239 | +** artifact has no primary parent, rid is returned as-is. | |
| 3240 | +*/ | |
| 3241 | +int rid_root_parent(int rid){ | |
| 3242 | + Stmt q; | |
| 3243 | + db_prepare( | |
| 3244 | + &q, "SELECT pid FROM plink WHERE isprim AND cid=:cid" | |
| 3245 | + ); | |
| 3246 | + db_bind_int(&q, ":cid", rid); | |
| 3247 | + while( SQLITE_ROW==db_step(&q) ){ | |
| 3248 | + rid = db_column_int(&q, 0); | |
| 3249 | + db_reset(&q); | |
| 3250 | + db_bind_int(&q, ":cid", rid); | |
| 3251 | + } | |
| 3252 | + db_finalize(&q); | |
| 3253 | + return rid; | |
| 3254 | +} | |
| 3210 | 3255 |
| --- src/manifest.c | |
| +++ src/manifest.c | |
| @@ -1128,20 +1128,16 @@ | |
| 1128 | md5sum_init(); |
| 1129 | if( !isRepeat ) g.parseCnt[p->type]++; |
| 1130 | return p; |
| 1131 | |
| 1132 | manifest_syntax_error: |
| 1133 | { |
| 1134 | char *zUuid = rid_to_uuid(rid); |
| 1135 | if( zUuid ){ |
| 1136 | if(pErr!=0){ |
| 1137 | blob_appendf(pErr, "artifact [%s] ", zUuid); |
| 1138 | } |
| 1139 | fossil_free(zUuid); |
| 1140 | } |
| 1141 | } |
| 1142 | if(pErr!=0){ |
| 1143 | if( zErr ){ |
| 1144 | blob_appendf(pErr, "line %d: %s", lineNo, zErr); |
| 1145 | }else{ |
| 1146 | blob_appendf(pErr, "unknown error on line %d", lineNo); |
| 1147 | } |
| @@ -2630,26 +2626,11 @@ | |
| 2630 | db_finalize(&qatt); |
| 2631 | } |
| 2632 | if( p->type==CFTYPE_ATTACHMENT ){ |
| 2633 | char *zComment = 0; |
| 2634 | const char isAdd = (p->zAttachSrc && p->zAttachSrc[0]) ? 1 : 0; |
| 2635 | /* We assume that we're attaching to a wiki page until we |
| 2636 | ** prove otherwise (which could on a later artifact if we |
| 2637 | ** process the attachment artifact before the artifact to |
| 2638 | ** which it is attached!) */ |
| 2639 | char attachToType = 'w'; |
| 2640 | if( fossil_is_artifact_hash(p->zAttachTarget) ){ |
| 2641 | if( db_exists("SELECT 1 FROM tag WHERE tagname='tkt-%q'", |
| 2642 | p->zAttachTarget) |
| 2643 | ){ |
| 2644 | attachToType = 't'; /* Attaching to known ticket */ |
| 2645 | }else if( db_exists("SELECT 1 FROM tag WHERE tagname='event-%q'", |
| 2646 | p->zAttachTarget) |
| 2647 | ){ |
| 2648 | attachToType = 'e'; /* Attaching to known tech note */ |
| 2649 | } |
| 2650 | } |
| 2651 | db_multi_exec( |
| 2652 | "INSERT INTO attachment(attachid, mtime, src, target," |
| 2653 | "filename, comment, user)" |
| 2654 | "VALUES(%d,%.17g,%Q,%Q,%Q,%Q,%Q);", |
| 2655 | rid, p->rDate, p->zAttachSrc, p->zAttachTarget, p->zAttachName, |
| @@ -2661,40 +2642,82 @@ | |
| 2661 | " WHERE target=%Q AND filename=%Q))" |
| 2662 | " WHERE target=%Q AND filename=%Q", |
| 2663 | p->zAttachTarget, p->zAttachName, |
| 2664 | p->zAttachTarget, p->zAttachName |
| 2665 | ); |
| 2666 | if( 'w' == attachToType ){ |
| 2667 | if( isAdd ){ |
| 2668 | zComment = mprintf( |
| 2669 | "Add attachment [/artifact/%!S|%h] to wiki page [%h]", |
| 2670 | p->zAttachSrc, p->zAttachName, p->zAttachTarget); |
| 2671 | }else{ |
| 2672 | zComment = mprintf("Delete attachment \"%h\" from wiki page [%h]", |
| 2673 | p->zAttachName, p->zAttachTarget); |
| 2674 | } |
| 2675 | }else if( 'e' == attachToType ){ |
| 2676 | if( isAdd ){ |
| 2677 | zComment = mprintf( |
| 2678 | "Add attachment [/artifact/%!S|%h] to tech note [/technote/%!S|%S]", |
| 2679 | p->zAttachSrc, p->zAttachName, p->zAttachTarget, p->zAttachTarget); |
| 2680 | }else{ |
| 2681 | zComment = mprintf( |
| 2682 | "Delete attachment \"/artifact/%!S|%h\" from" |
| 2683 | " tech note [/technote/%!S|%S]", |
| 2684 | p->zAttachName, p->zAttachName, |
| 2685 | p->zAttachTarget,p->zAttachTarget); |
| 2686 | } |
| 2687 | }else{ |
| 2688 | if( isAdd ){ |
| 2689 | zComment = mprintf( |
| 2690 | "Add attachment [/artifact/%!S|%h] to ticket [%!S|%S]", |
| 2691 | p->zAttachSrc, p->zAttachName, p->zAttachTarget, p->zAttachTarget); |
| 2692 | }else{ |
| 2693 | zComment = mprintf("Delete attachment \"%h\" from ticket [%!S|%S]", |
| 2694 | p->zAttachName, p->zAttachTarget, p->zAttachTarget); |
| 2695 | } |
| 2696 | } |
| 2697 | assert( manifest_event_triggers_are_enabled ); |
| 2698 | db_multi_exec( |
| 2699 | "REPLACE INTO event(type,mtime,objid,user,comment)" |
| 2700 | "VALUES('%c',%.17g,%d,%Q,%Q)", |
| @@ -3205,5 +3228,27 @@ | |
| 3205 | db_finalize(&q); |
| 3206 | if( nErr ){ |
| 3207 | fossil_warning("Error count: %d", nErr); |
| 3208 | } |
| 3209 | } |
| 3210 |
| --- src/manifest.c | |
| +++ src/manifest.c | |
| @@ -1128,20 +1128,16 @@ | |
| 1128 | md5sum_init(); |
| 1129 | if( !isRepeat ) g.parseCnt[p->type]++; |
| 1130 | return p; |
| 1131 | |
| 1132 | manifest_syntax_error: |
| 1133 | if(pErr!=0){ |
| 1134 | char *zUuid = rid>0 ? rid_to_uuid(rid) : 0; |
| 1135 | if( zUuid ){ |
| 1136 | blob_appendf(pErr, "artifact [%s] ", zUuid); |
| 1137 | fossil_free(zUuid); |
| 1138 | } |
| 1139 | if( zErr ){ |
| 1140 | blob_appendf(pErr, "line %d: %s", lineNo, zErr); |
| 1141 | }else{ |
| 1142 | blob_appendf(pErr, "unknown error on line %d", lineNo); |
| 1143 | } |
| @@ -2630,26 +2626,11 @@ | |
| 2626 | db_finalize(&qatt); |
| 2627 | } |
| 2628 | if( p->type==CFTYPE_ATTACHMENT ){ |
| 2629 | char *zComment = 0; |
| 2630 | const char isAdd = (p->zAttachSrc && p->zAttachSrc[0]) ? 1 : 0; |
| 2631 | char attachToType = 0; |
| 2632 | db_multi_exec( |
| 2633 | "INSERT INTO attachment(attachid, mtime, src, target," |
| 2634 | "filename, comment, user)" |
| 2635 | "VALUES(%d,%.17g,%Q,%Q,%Q,%Q,%Q);", |
| 2636 | rid, p->rDate, p->zAttachSrc, p->zAttachTarget, p->zAttachName, |
| @@ -2661,40 +2642,82 @@ | |
| 2642 | " WHERE target=%Q AND filename=%Q))" |
| 2643 | " WHERE target=%Q AND filename=%Q", |
| 2644 | p->zAttachTarget, p->zAttachName, |
| 2645 | p->zAttachTarget, p->zAttachName |
| 2646 | ); |
| 2647 | switch( attachment_target_type(p->zAttachTarget, 1) ){ |
| 2648 | case 0: |
| 2649 | /* It is possible that p->zAttachTarget is not yet in this |
| 2650 | ** copy of the repository. If we cannot identify it yet, |
| 2651 | ** generate a generic /artifact link to it instead of a |
| 2652 | ** type-specific link or an error message. */ |
| 2653 | attachToType = 'a'; |
| 2654 | if( isAdd ){ |
| 2655 | zComment = mprintf( |
| 2656 | "Add attachment [/artifact/%!S|%h] to [/artifact/%!S|%h]", |
| 2657 | p->zAttachSrc, p->zAttachName, |
| 2658 | p->zAttachTarget, p->zAttachTarget); |
| 2659 | }else{ |
| 2660 | zComment = mprintf("Delete attachment \"%h\" from " |
| 2661 | "[/artifact/%!S|%h", |
| 2662 | p->zAttachName, p->zAttachTarget, |
| 2663 | p->zAttachTarget); |
| 2664 | } |
| 2665 | break; |
| 2666 | case CFTYPE_WIKI: |
| 2667 | attachToType = 'w'; |
| 2668 | if( isAdd ){ |
| 2669 | zComment = mprintf( |
| 2670 | "Add attachment [/artifact/%!S|%h] to wiki page [%h]", |
| 2671 | p->zAttachSrc, p->zAttachName, p->zAttachTarget); |
| 2672 | }else{ |
| 2673 | zComment = mprintf("Delete attachment \"%h\" from " |
| 2674 | "wiki page [%h]", |
| 2675 | p->zAttachName, p->zAttachTarget); |
| 2676 | } |
| 2677 | break; |
| 2678 | case CFTYPE_EVENT: |
| 2679 | attachToType = 'e'; |
| 2680 | if( isAdd ){ |
| 2681 | zComment = mprintf( |
| 2682 | "Add attachment [/artifact/%!S|%h] to tech note " |
| 2683 | "[/technote/%!S|%S]", |
| 2684 | p->zAttachSrc, p->zAttachName, p->zAttachTarget, p->zAttachTarget); |
| 2685 | }else{ |
| 2686 | zComment = mprintf( |
| 2687 | "Delete attachment \"/artifact/%!S|%h\" from" |
| 2688 | " tech note [/technote/%!S|%S]", |
| 2689 | p->zAttachName, p->zAttachName, |
| 2690 | p->zAttachTarget,p->zAttachTarget); |
| 2691 | } |
| 2692 | break; |
| 2693 | case CFTYPE_TICKET: |
| 2694 | attachToType = 't'; |
| 2695 | if( isAdd ){ |
| 2696 | zComment = mprintf( |
| 2697 | "Add attachment [/artifact/%!S|%h] to ticket [%!S|%S]", |
| 2698 | p->zAttachSrc, p->zAttachName, p->zAttachTarget, p->zAttachTarget); |
| 2699 | }else{ |
| 2700 | zComment = mprintf( |
| 2701 | "Delete attachment \"%h\" from ticket [%!S|%S]", |
| 2702 | p->zAttachName, p->zAttachTarget, p->zAttachTarget); |
| 2703 | } |
| 2704 | break; |
| 2705 | case CFTYPE_FORUM: |
| 2706 | attachToType = 'f'; |
| 2707 | if( isAdd ){ |
| 2708 | zComment = mprintf( |
| 2709 | "Add attachment [/artifact/%!S|%h] to forum post " |
| 2710 | "[/forumpost/%!S|%S]", |
| 2711 | p->zAttachSrc, p->zAttachName, p->zAttachTarget, p->zAttachTarget); |
| 2712 | }else{ |
| 2713 | zComment = mprintf( |
| 2714 | "Delete attachment \"%h\" from forum post " |
| 2715 | "[/forumpost/%!S|%S]", |
| 2716 | p->zAttachName, p->zAttachTarget, p->zAttachTarget); |
| 2717 | } |
| 2718 | break; |
| 2719 | } |
| 2720 | assert( manifest_event_triggers_are_enabled ); |
| 2721 | db_multi_exec( |
| 2722 | "REPLACE INTO event(type,mtime,objid,user,comment)" |
| 2723 | "VALUES('%c',%.17g,%d,%Q,%Q)", |
| @@ -3205,5 +3228,27 @@ | |
| 3228 | db_finalize(&q); |
| 3229 | if( nErr ){ |
| 3230 | fossil_warning("Error count: %d", nErr); |
| 3231 | } |
| 3232 | } |
| 3233 | |
| 3234 | /* |
| 3235 | ** Given the RID of an artifact, if that artifact type supports |
| 3236 | ** P-cards then this returns the root-most RID of the P-card chain by |
| 3237 | ** traversing the plink table, considering only primary parents. If |
| 3238 | ** rid refers to anything other than such an artifact, or if the |
| 3239 | ** artifact has no primary parent, rid is returned as-is. |
| 3240 | */ |
| 3241 | int rid_root_parent(int rid){ |
| 3242 | Stmt q; |
| 3243 | db_prepare( |
| 3244 | &q, "SELECT pid FROM plink WHERE isprim AND cid=:cid" |
| 3245 | ); |
| 3246 | db_bind_int(&q, ":cid", rid); |
| 3247 | while( SQLITE_ROW==db_step(&q) ){ |
| 3248 | rid = db_column_int(&q, 0); |
| 3249 | db_reset(&q); |
| 3250 | db_bind_int(&q, ":cid", rid); |
| 3251 | } |
| 3252 | db_finalize(&q); |
| 3253 | return rid; |
| 3254 | } |
| 3255 |
+39
-3
| --- src/markdown.md | ||
| +++ src/markdown.md | ||
| @@ -184,16 +184,52 @@ | ||
| 184 | 184 | >``` |
| 185 | 185 | > Character **^** is not part of a label, it is part of the syntax. |
| 186 | 186 | > Both a footnote's text and a fragment to which a footnote applies |
| 187 | 187 | > are subject to further interpretation as Markdown sources. |
| 188 | 188 | |
| 189 | +## Safe HTML ## | |
| 190 | + | |
| 191 | +> Markdown documents may contain raw HTML, filtered to allow the following: | |
| 192 | +> | |
| 193 | +> <a> <abbr> <address> <article> <aside> | |
| 194 | +> <b> <big> <blockquote> <br> <caption> | |
| 195 | +> <center> <cite> <code> <col> <colgroup> | |
| 196 | +> <dd> <del> <details> <dfn> <div> <dl> | |
| 197 | +> <dt> <em> <figcaption> <figure> <font> | |
| 198 | +> <footer> <h1> <h2> <h3> <h4> <h5> | |
| 199 | +> <h6> <header> <hr> <i> <img> <ins> | |
| 200 | +> <kbd> <label> <li> <mark> <meter> <nav> | |
| 201 | +> <nobr> <nowiki> <ol> <p> <picture> <pre> | |
| 202 | +> <progress> <q> <s> <samp> <section> <small> | |
| 203 | +> <source> <span> <strike> <strong> <sub> | |
| 204 | +> <summary> <sup> <table> <tbody> <td> | |
| 205 | +> <tfoot> <th> <thead> <time> <title> <tr> | |
| 206 | +> <tt> <u> <ul> <var> <wbr> <verbatim> | |
| 207 | +> | |
| 208 | +> Any other tag is sent through to the output in a way that causes it to be | |
| 209 | +> visibly called out as disallowed. This is the same whitelist as for | |
| 210 | +> [Fossil Wiki](/wiki_rules) markup. | |
| 211 | +> | |
| 212 | +> Fossil-specific elements **<nowiki>** and **<verbatim>** disable | |
| 213 | +> wiki and Markdown processing within their spans; see | |
| 214 | +> [Wiki formatting rules](/wiki_rules) for details. | |
| 215 | +> | |
| 216 | +> Only a fixed set of attributes is permitted (for example **id**, | |
| 217 | +> **class**, **style**, **href**, **src**, **srcset**, **alt**, **type**, | |
| 218 | +> **datetime**, and **value**). Event handlers, **javascript:** URLs, and | |
| 219 | +> similar constructs are stripped. | |
| 220 | +> | |
| 221 | +> Repository administrators may allow additional unsafe HTML (such as | |
| 222 | +> **<script>** and **<form>**) in some contexts using the | |
| 223 | +> [safe-html setting](/help/safe-html) on the Admin/Wiki page. | |
| 224 | + | |
| 189 | 225 | ## Miscellaneous ## |
| 190 | 226 | |
| 191 | 227 | > * In-line images are made using **\!\[alt-text\]\(image-URL\)**. |
| 192 | -> * Use HTML for advanced formatting such as forms, noting that certain | |
| 193 | -> tags are [disallowed in some contexts](/help/safe-html). | |
| 194 | -> * **\<!--** HTML-style comments **-->** are supported. | |
| 228 | +> * Use HTML for advanced formatting; see [Safe HTML](#safe-html) above. | |
| 229 | +> * **\<!--** HTML-style comments **-->** are allowed through only when | |
| 230 | +> the safe-HTML rules are bypassed. | |
| 195 | 231 | > * Escape special characters (ex: **\[** **\(** **\|** **\***) |
| 196 | 232 | > using backslash (ex: **\\\[** **\\\(** **\\\|** **\\\***). |
| 197 | 233 | > * A line consisting of **---**, **\*\*\***, or **\_\_\_** is a horizontal |
| 198 | 234 | > rule. Spaces and extra **-**/**\***/**_** are allowed. |
| 199 | 235 | > * Paragraphs enclosed in **\<html\>...\</html\>** is passed through unchanged. |
| 200 | 236 |
| --- src/markdown.md | |
| +++ src/markdown.md | |
| @@ -184,16 +184,52 @@ | |
| 184 | >``` |
| 185 | > Character **^** is not part of a label, it is part of the syntax. |
| 186 | > Both a footnote's text and a fragment to which a footnote applies |
| 187 | > are subject to further interpretation as Markdown sources. |
| 188 | |
| 189 | ## Miscellaneous ## |
| 190 | |
| 191 | > * In-line images are made using **\!\[alt-text\]\(image-URL\)**. |
| 192 | > * Use HTML for advanced formatting such as forms, noting that certain |
| 193 | > tags are [disallowed in some contexts](/help/safe-html). |
| 194 | > * **\<!--** HTML-style comments **-->** are supported. |
| 195 | > * Escape special characters (ex: **\[** **\(** **\|** **\***) |
| 196 | > using backslash (ex: **\\\[** **\\\(** **\\\|** **\\\***). |
| 197 | > * A line consisting of **---**, **\*\*\***, or **\_\_\_** is a horizontal |
| 198 | > rule. Spaces and extra **-**/**\***/**_** are allowed. |
| 199 | > * Paragraphs enclosed in **\<html\>...\</html\>** is passed through unchanged. |
| 200 |
| --- src/markdown.md | |
| +++ src/markdown.md | |
| @@ -184,16 +184,52 @@ | |
| 184 | >``` |
| 185 | > Character **^** is not part of a label, it is part of the syntax. |
| 186 | > Both a footnote's text and a fragment to which a footnote applies |
| 187 | > are subject to further interpretation as Markdown sources. |
| 188 | |
| 189 | ## Safe HTML ## |
| 190 | |
| 191 | > Markdown documents may contain raw HTML, filtered to allow the following: |
| 192 | > |
| 193 | > <a> <abbr> <address> <article> <aside> |
| 194 | > <b> <big> <blockquote> <br> <caption> |
| 195 | > <center> <cite> <code> <col> <colgroup> |
| 196 | > <dd> <del> <details> <dfn> <div> <dl> |
| 197 | > <dt> <em> <figcaption> <figure> <font> |
| 198 | > <footer> <h1> <h2> <h3> <h4> <h5> |
| 199 | > <h6> <header> <hr> <i> <img> <ins> |
| 200 | > <kbd> <label> <li> <mark> <meter> <nav> |
| 201 | > <nobr> <nowiki> <ol> <p> <picture> <pre> |
| 202 | > <progress> <q> <s> <samp> <section> <small> |
| 203 | > <source> <span> <strike> <strong> <sub> |
| 204 | > <summary> <sup> <table> <tbody> <td> |
| 205 | > <tfoot> <th> <thead> <time> <title> <tr> |
| 206 | > <tt> <u> <ul> <var> <wbr> <verbatim> |
| 207 | > |
| 208 | > Any other tag is sent through to the output in a way that causes it to be |
| 209 | > visibly called out as disallowed. This is the same whitelist as for |
| 210 | > [Fossil Wiki](/wiki_rules) markup. |
| 211 | > |
| 212 | > Fossil-specific elements **<nowiki>** and **<verbatim>** disable |
| 213 | > wiki and Markdown processing within their spans; see |
| 214 | > [Wiki formatting rules](/wiki_rules) for details. |
| 215 | > |
| 216 | > Only a fixed set of attributes is permitted (for example **id**, |
| 217 | > **class**, **style**, **href**, **src**, **srcset**, **alt**, **type**, |
| 218 | > **datetime**, and **value**). Event handlers, **javascript:** URLs, and |
| 219 | > similar constructs are stripped. |
| 220 | > |
| 221 | > Repository administrators may allow additional unsafe HTML (such as |
| 222 | > **<script>** and **<form>**) in some contexts using the |
| 223 | > [safe-html setting](/help/safe-html) on the Admin/Wiki page. |
| 224 | |
| 225 | ## Miscellaneous ## |
| 226 | |
| 227 | > * In-line images are made using **\!\[alt-text\]\(image-URL\)**. |
| 228 | > * Use HTML for advanced formatting; see [Safe HTML](#safe-html) above. |
| 229 | > * **\<!--** HTML-style comments **-->** are allowed through only when |
| 230 | > the safe-HTML rules are bypassed. |
| 231 | > * Escape special characters (ex: **\[** **\(** **\|** **\***) |
| 232 | > using backslash (ex: **\\\[** **\\\(** **\\\|** **\\\***). |
| 233 | > * A line consisting of **---**, **\*\*\***, or **\_\_\_** is a horizontal |
| 234 | > rule. Spaces and extra **-**/**\***/**_** are allowed. |
| 235 | > * Paragraphs enclosed in **\<html\>...\</html\>** is passed through unchanged. |
| 236 |
+61
-21
| --- src/merge.c | ||
| +++ src/merge.c | ||
| @@ -300,10 +300,11 @@ | ||
| 300 | 300 | ** lines are shown |
| 301 | 301 | ** -c|--context N Show N lines of context around each change, |
| 302 | 302 | ** with negative N meaning show all content. Only |
| 303 | 303 | ** meaningful in combination with --tcl or --tk. |
| 304 | 304 | ** --dark Use dark mode for the Tcl/Tk-based GUI |
| 305 | +** -v|--verbose Show extra information about each merge operation | |
| 305 | 306 | ** --tk Bring up a Tcl/Tk GUI that shows the changes |
| 306 | 307 | ** associated with the most recent merge. |
| 307 | 308 | ** |
| 308 | 309 | ** Options used internally by --tk: |
| 309 | 310 | ** --diff12 FILE Bring up a separate --tk diff for just the baseline |
| @@ -323,10 +324,11 @@ | ||
| 323 | 324 | const char *zCnt; |
| 324 | 325 | const char *zTcl; |
| 325 | 326 | int bTk; |
| 326 | 327 | int bDark; |
| 327 | 328 | int bAll; |
| 329 | + int bDetail; | |
| 328 | 330 | int nContext; |
| 329 | 331 | Stmt q; |
| 330 | 332 | const char *zWhere; |
| 331 | 333 | int cnt = 0; |
| 332 | 334 | const char *zDiff2 = 0; |
| @@ -336,10 +338,11 @@ | ||
| 336 | 338 | bTk = find_option("tk", 0, 0)!=0; |
| 337 | 339 | zTcl = find_option("tcl", 0, 1); |
| 338 | 340 | zCnt = find_option("context", "c", 1); |
| 339 | 341 | bDark = find_option("dark", 0, 0)!=0; |
| 340 | 342 | bAll = find_option("all", "a", 0)!=0; |
| 343 | + bDetail = find_option("verbose", "v", 0)!=0; | |
| 341 | 344 | if( (zDiff2 = find_option("diff12", 0, 1))!=0 ){ |
| 342 | 345 | diffMode = 12; |
| 343 | 346 | }else |
| 344 | 347 | if( (zDiff2 = find_option("diff13", 0, 1))!=0 ){ |
| 345 | 348 | diffMode = 13; |
| @@ -388,31 +391,68 @@ | ||
| 388 | 391 | if( bAll ){ |
| 389 | 392 | zWhere = ""; |
| 390 | 393 | }else{ |
| 391 | 394 | zWhere = "WHERE op IN ('MERGE','CONFLICT','ERROR')"; |
| 392 | 395 | } |
| 393 | - db_prepare(&q, | |
| 394 | - "WITH priority(op,pri) AS (VALUES('CONFLICT',0),('ERROR',0)," | |
| 395 | - "('MERGE',1),('ADDED',2),('UPDATE',2))" | |
| 396 | - | |
| 397 | - /* 0 1 2 */ | |
| 398 | - "SELECT op, coalesce(fnr,fn), msg" | |
| 399 | - " FROM mergestat JOIN priority USING(op)" | |
| 400 | - " %s" | |
| 401 | - " ORDER BY pri, coalesce(fnr,fn)", | |
| 402 | - zWhere /*safe-for-%s*/ | |
| 403 | - ); | |
| 404 | - while( db_step(&q)==SQLITE_ROW ){ | |
| 405 | - const char *zOp = db_column_text(&q, 0); | |
| 406 | - const char *zName = db_column_text(&q, 1); | |
| 407 | - const char *zErr = db_column_text(&q, 2); | |
| 408 | - if( zErr && fossil_strcmp(zOp,"CONFLICT")!=0 ){ | |
| 409 | - fossil_print("%-9s %s (%s)\n", zOp, zName, zErr); | |
| 410 | - }else{ | |
| 411 | - fossil_print("%-9s %s\n", zOp, zName); | |
| 412 | - } | |
| 413 | - cnt++; | |
| 396 | + if( !bDetail ){ | |
| 397 | + db_prepare(&q, | |
| 398 | + "WITH priority(op,pri) AS (VALUES('CONFLICT',0),('ERROR',0)," | |
| 399 | + "('MERGE',1),('ADDED',2),('UPDATE',2))" | |
| 400 | + | |
| 401 | + /* 0 1 2 */ | |
| 402 | + "SELECT op, coalesce(fnr,fn), msg" | |
| 403 | + " FROM mergestat JOIN priority USING(op)" | |
| 404 | + " %s" | |
| 405 | + " ORDER BY pri, coalesce(fnr,fn)", | |
| 406 | + zWhere /*safe-for-%s*/ | |
| 407 | + ); | |
| 408 | + while( db_step(&q)==SQLITE_ROW ){ | |
| 409 | + const char *zOp = db_column_text(&q, 0); | |
| 410 | + const char *zName = db_column_text(&q, 1); | |
| 411 | + const char *zErr = db_column_text(&q, 2); | |
| 412 | + if( zErr && fossil_strcmp(zOp,"CONFLICT")!=0 ){ | |
| 413 | + fossil_print("%-9s %s (%s)\n", zOp, zName, zErr); | |
| 414 | + }else{ | |
| 415 | + fossil_print("%-9s %s\n", zOp, zName); | |
| 416 | + } | |
| 417 | + cnt++; | |
| 418 | + } | |
| 419 | + }else{ | |
| 420 | + fossil_print( | |
| 421 | + " Status Local Pivot Merge-in Filename\n" | |
| 422 | + "--------- ---------- ---------- ---------- ----------------\n"); | |
| 423 | + db_prepare(&q, | |
| 424 | + "WITH priority(op,pri) AS (VALUES('CONFLICT',0),('ERROR',0)," | |
| 425 | + "('MERGE',1),('ADDED',2),('UPDATE',2))" | |
| 426 | + | |
| 427 | + /* 0 1 2 */ | |
| 428 | + "SELECT op, coalesce(fnr,fn), msg," | |
| 429 | + " (SELECT uuid FROM blob WHERE blob.rid=mergestat.ridv)," /* 3: local */ | |
| 430 | + " (SELECT uuid FROM blob WHERE blob.rid=mergestat.ridp)," /* 4: pivot */ | |
| 431 | + " (SELECT uuid FROM blob WHERE blob.rid=mergestat.ridm)" /* 5: mergein*/ | |
| 432 | + " FROM mergestat JOIN priority USING(op)" | |
| 433 | + " %s" | |
| 434 | + " ORDER BY pri, coalesce(fnr,fn)", | |
| 435 | + zWhere /*safe-for-%s*/ | |
| 436 | + ); | |
| 437 | + while( db_step(&q)==SQLITE_ROW ){ | |
| 438 | + const char *zOp = db_column_text(&q, 0); | |
| 439 | + const char *zName = db_column_text(&q, 1); | |
| 440 | + const char *zErr = db_column_text(&q, 2); | |
| 441 | + const char *zLocal = db_column_text(&q, 3); | |
| 442 | + const char *zPivot = db_column_text(&q, 4); | |
| 443 | + const char *zMergein = db_column_text(&q, 5); | |
| 444 | + if( zLocal==0 ) zLocal = ""; | |
| 445 | + if( zErr && fossil_strcmp(zOp,"CONFLICT")!=0 ){ | |
| 446 | + fossil_print("%-9s %10.10s %10.10s %10.10s %s (%s)\n", | |
| 447 | + zOp, zLocal, zPivot, zMergein, zName, zErr); | |
| 448 | + }else{ | |
| 449 | + fossil_print("%-9s %10.10s %10.10s %10.10s %s\n", | |
| 450 | + zOp, zLocal, zPivot, zMergein, zName); | |
| 451 | + } | |
| 452 | + cnt++; | |
| 453 | + } | |
| 414 | 454 | } |
| 415 | 455 | db_finalize(&q); |
| 416 | 456 | if( !bAll && cnt==0 ){ |
| 417 | 457 | fossil_print( |
| 418 | 458 | "No interesting changes in this merge. Use --all to see everything.\n" |
| 419 | 459 |
| --- src/merge.c | |
| +++ src/merge.c | |
| @@ -300,10 +300,11 @@ | |
| 300 | ** lines are shown |
| 301 | ** -c|--context N Show N lines of context around each change, |
| 302 | ** with negative N meaning show all content. Only |
| 303 | ** meaningful in combination with --tcl or --tk. |
| 304 | ** --dark Use dark mode for the Tcl/Tk-based GUI |
| 305 | ** --tk Bring up a Tcl/Tk GUI that shows the changes |
| 306 | ** associated with the most recent merge. |
| 307 | ** |
| 308 | ** Options used internally by --tk: |
| 309 | ** --diff12 FILE Bring up a separate --tk diff for just the baseline |
| @@ -323,10 +324,11 @@ | |
| 323 | const char *zCnt; |
| 324 | const char *zTcl; |
| 325 | int bTk; |
| 326 | int bDark; |
| 327 | int bAll; |
| 328 | int nContext; |
| 329 | Stmt q; |
| 330 | const char *zWhere; |
| 331 | int cnt = 0; |
| 332 | const char *zDiff2 = 0; |
| @@ -336,10 +338,11 @@ | |
| 336 | bTk = find_option("tk", 0, 0)!=0; |
| 337 | zTcl = find_option("tcl", 0, 1); |
| 338 | zCnt = find_option("context", "c", 1); |
| 339 | bDark = find_option("dark", 0, 0)!=0; |
| 340 | bAll = find_option("all", "a", 0)!=0; |
| 341 | if( (zDiff2 = find_option("diff12", 0, 1))!=0 ){ |
| 342 | diffMode = 12; |
| 343 | }else |
| 344 | if( (zDiff2 = find_option("diff13", 0, 1))!=0 ){ |
| 345 | diffMode = 13; |
| @@ -388,31 +391,68 @@ | |
| 388 | if( bAll ){ |
| 389 | zWhere = ""; |
| 390 | }else{ |
| 391 | zWhere = "WHERE op IN ('MERGE','CONFLICT','ERROR')"; |
| 392 | } |
| 393 | db_prepare(&q, |
| 394 | "WITH priority(op,pri) AS (VALUES('CONFLICT',0),('ERROR',0)," |
| 395 | "('MERGE',1),('ADDED',2),('UPDATE',2))" |
| 396 | |
| 397 | /* 0 1 2 */ |
| 398 | "SELECT op, coalesce(fnr,fn), msg" |
| 399 | " FROM mergestat JOIN priority USING(op)" |
| 400 | " %s" |
| 401 | " ORDER BY pri, coalesce(fnr,fn)", |
| 402 | zWhere /*safe-for-%s*/ |
| 403 | ); |
| 404 | while( db_step(&q)==SQLITE_ROW ){ |
| 405 | const char *zOp = db_column_text(&q, 0); |
| 406 | const char *zName = db_column_text(&q, 1); |
| 407 | const char *zErr = db_column_text(&q, 2); |
| 408 | if( zErr && fossil_strcmp(zOp,"CONFLICT")!=0 ){ |
| 409 | fossil_print("%-9s %s (%s)\n", zOp, zName, zErr); |
| 410 | }else{ |
| 411 | fossil_print("%-9s %s\n", zOp, zName); |
| 412 | } |
| 413 | cnt++; |
| 414 | } |
| 415 | db_finalize(&q); |
| 416 | if( !bAll && cnt==0 ){ |
| 417 | fossil_print( |
| 418 | "No interesting changes in this merge. Use --all to see everything.\n" |
| 419 |
| --- src/merge.c | |
| +++ src/merge.c | |
| @@ -300,10 +300,11 @@ | |
| 300 | ** lines are shown |
| 301 | ** -c|--context N Show N lines of context around each change, |
| 302 | ** with negative N meaning show all content. Only |
| 303 | ** meaningful in combination with --tcl or --tk. |
| 304 | ** --dark Use dark mode for the Tcl/Tk-based GUI |
| 305 | ** -v|--verbose Show extra information about each merge operation |
| 306 | ** --tk Bring up a Tcl/Tk GUI that shows the changes |
| 307 | ** associated with the most recent merge. |
| 308 | ** |
| 309 | ** Options used internally by --tk: |
| 310 | ** --diff12 FILE Bring up a separate --tk diff for just the baseline |
| @@ -323,10 +324,11 @@ | |
| 324 | const char *zCnt; |
| 325 | const char *zTcl; |
| 326 | int bTk; |
| 327 | int bDark; |
| 328 | int bAll; |
| 329 | int bDetail; |
| 330 | int nContext; |
| 331 | Stmt q; |
| 332 | const char *zWhere; |
| 333 | int cnt = 0; |
| 334 | const char *zDiff2 = 0; |
| @@ -336,10 +338,11 @@ | |
| 338 | bTk = find_option("tk", 0, 0)!=0; |
| 339 | zTcl = find_option("tcl", 0, 1); |
| 340 | zCnt = find_option("context", "c", 1); |
| 341 | bDark = find_option("dark", 0, 0)!=0; |
| 342 | bAll = find_option("all", "a", 0)!=0; |
| 343 | bDetail = find_option("verbose", "v", 0)!=0; |
| 344 | if( (zDiff2 = find_option("diff12", 0, 1))!=0 ){ |
| 345 | diffMode = 12; |
| 346 | }else |
| 347 | if( (zDiff2 = find_option("diff13", 0, 1))!=0 ){ |
| 348 | diffMode = 13; |
| @@ -388,31 +391,68 @@ | |
| 391 | if( bAll ){ |
| 392 | zWhere = ""; |
| 393 | }else{ |
| 394 | zWhere = "WHERE op IN ('MERGE','CONFLICT','ERROR')"; |
| 395 | } |
| 396 | if( !bDetail ){ |
| 397 | db_prepare(&q, |
| 398 | "WITH priority(op,pri) AS (VALUES('CONFLICT',0),('ERROR',0)," |
| 399 | "('MERGE',1),('ADDED',2),('UPDATE',2))" |
| 400 | |
| 401 | /* 0 1 2 */ |
| 402 | "SELECT op, coalesce(fnr,fn), msg" |
| 403 | " FROM mergestat JOIN priority USING(op)" |
| 404 | " %s" |
| 405 | " ORDER BY pri, coalesce(fnr,fn)", |
| 406 | zWhere /*safe-for-%s*/ |
| 407 | ); |
| 408 | while( db_step(&q)==SQLITE_ROW ){ |
| 409 | const char *zOp = db_column_text(&q, 0); |
| 410 | const char *zName = db_column_text(&q, 1); |
| 411 | const char *zErr = db_column_text(&q, 2); |
| 412 | if( zErr && fossil_strcmp(zOp,"CONFLICT")!=0 ){ |
| 413 | fossil_print("%-9s %s (%s)\n", zOp, zName, zErr); |
| 414 | }else{ |
| 415 | fossil_print("%-9s %s\n", zOp, zName); |
| 416 | } |
| 417 | cnt++; |
| 418 | } |
| 419 | }else{ |
| 420 | fossil_print( |
| 421 | " Status Local Pivot Merge-in Filename\n" |
| 422 | "--------- ---------- ---------- ---------- ----------------\n"); |
| 423 | db_prepare(&q, |
| 424 | "WITH priority(op,pri) AS (VALUES('CONFLICT',0),('ERROR',0)," |
| 425 | "('MERGE',1),('ADDED',2),('UPDATE',2))" |
| 426 | |
| 427 | /* 0 1 2 */ |
| 428 | "SELECT op, coalesce(fnr,fn), msg," |
| 429 | " (SELECT uuid FROM blob WHERE blob.rid=mergestat.ridv)," /* 3: local */ |
| 430 | " (SELECT uuid FROM blob WHERE blob.rid=mergestat.ridp)," /* 4: pivot */ |
| 431 | " (SELECT uuid FROM blob WHERE blob.rid=mergestat.ridm)" /* 5: mergein*/ |
| 432 | " FROM mergestat JOIN priority USING(op)" |
| 433 | " %s" |
| 434 | " ORDER BY pri, coalesce(fnr,fn)", |
| 435 | zWhere /*safe-for-%s*/ |
| 436 | ); |
| 437 | while( db_step(&q)==SQLITE_ROW ){ |
| 438 | const char *zOp = db_column_text(&q, 0); |
| 439 | const char *zName = db_column_text(&q, 1); |
| 440 | const char *zErr = db_column_text(&q, 2); |
| 441 | const char *zLocal = db_column_text(&q, 3); |
| 442 | const char *zPivot = db_column_text(&q, 4); |
| 443 | const char *zMergein = db_column_text(&q, 5); |
| 444 | if( zLocal==0 ) zLocal = ""; |
| 445 | if( zErr && fossil_strcmp(zOp,"CONFLICT")!=0 ){ |
| 446 | fossil_print("%-9s %10.10s %10.10s %10.10s %s (%s)\n", |
| 447 | zOp, zLocal, zPivot, zMergein, zName, zErr); |
| 448 | }else{ |
| 449 | fossil_print("%-9s %10.10s %10.10s %10.10s %s\n", |
| 450 | zOp, zLocal, zPivot, zMergein, zName); |
| 451 | } |
| 452 | cnt++; |
| 453 | } |
| 454 | } |
| 455 | db_finalize(&q); |
| 456 | if( !bAll && cnt==0 ){ |
| 457 | fossil_print( |
| 458 | "No interesting changes in this merge. Use --all to see everything.\n" |
| 459 |
+128
-1
| --- src/moderate.c | ||
| +++ src/moderate.c | ||
| @@ -65,11 +65,25 @@ | ||
| 65 | 65 | ** false without generating any output. |
| 66 | 66 | */ |
| 67 | 67 | int moderation_pending_www(int rid){ |
| 68 | 68 | int pending = moderation_pending(rid); |
| 69 | 69 | if( pending ){ |
| 70 | - @ <span class="modpending">(Awaiting Moderator Approval)</span> | |
| 70 | +#if 0 | |
| 71 | + if( moderation_user_could(rid, 1, 0) ){ | |
| 72 | + /* It would be nice to emit a link to the appropriate page to | |
| 73 | + ** approve/reject the moderation, but for that we need | |
| 74 | + ** artifact-type-dependent info and links. That's complicated by | |
| 75 | + ** the fact that deriving whether rid refers to an attachment or | |
| 76 | + ** an attachment target is apparently tricky because of how | |
| 77 | + ** attachments are recorded in the event table. */ | |
| 78 | + @ <span class="modpending">(<a href="%R/WHAT_GOES_HERE?">\ | |
| 79 | + @Awaiting Moderator Approval</a>)</span> | |
| 80 | + }else | |
| 81 | +#endif | |
| 82 | + { | |
| 83 | + @ <span class="modpending">(Awaiting Moderator Approval)</span> | |
| 84 | + } | |
| 71 | 85 | } |
| 72 | 86 | return pending; |
| 73 | 87 | } |
| 74 | 88 | |
| 75 | 89 | |
| @@ -225,5 +239,118 @@ | ||
| 225 | 239 | } |
| 226 | 240 | db_finalize(&q); |
| 227 | 241 | setup_incr_cfgcnt(); |
| 228 | 242 | db_end_transaction(0); |
| 229 | 243 | } |
| 244 | + | |
| 245 | +/* | |
| 246 | +** Returns true if the current user could ostensibly moderate the blob | |
| 247 | +** refered to by rid, irrespective of whether that object is currently | |
| 248 | +** pending moderation. If rid is not an event.objid value then this | |
| 249 | +** returns 0. | |
| 250 | +** | |
| 251 | +** If bMayDeny is true then a matching user is permitted to moderate a | |
| 252 | +** decline by not an approval. Pass 1 here if true should be returned | |
| 253 | +** if the current user matches the artifact. When passing false, it | |
| 254 | +** will only return true for users who have explicit moderation | |
| 255 | +** permissions. The purpose of this is to exclude pending-moderation | |
| 256 | +** from the current user in some contexts but not others. | |
| 257 | +** | |
| 258 | +** zWho is an optional user name to consider for ownership of an | |
| 259 | +** artifact, as compared to the artifact's matching event.(euser,user) | |
| 260 | +** fields. If 0 then it defaults to login_name(). This is strictly a | |
| 261 | +** name comparison - it does not inspect zWho's repo-level | |
| 262 | +** permissions. | |
| 263 | +** | |
| 264 | +** Design issue: since this gets its info from the event table, it | |
| 265 | +** cannot unambiguously distinguish between an attachment-capable | |
| 266 | +** artifact type and attachments to one. Attachment events are encoded | |
| 267 | +** with type=X, where X is the same as the artifact type to which the | |
| 268 | +** attachment was applied. | |
| 269 | +** | |
| 270 | +** The moderation rules applied here are: | |
| 271 | +** | |
| 272 | +** - Admins may always moderate. This is a fast path which bypasses | |
| 273 | +** artifact lookup. For non-admins, we look for a record in the | |
| 274 | +** event table. | |
| 275 | +** | |
| 276 | +** - Forum, Wiki, and Ticket moderators may always moderate a matching | |
| 277 | +** artifact. If bMayDeny is true then an artifact's owner, even if | |
| 278 | +** not a moderator, may moderate it. i.e. a non-moderator owner can | |
| 279 | +** reject their pending-moderation objects but they may not approve | |
| 280 | +** them. | |
| 281 | +** | |
| 282 | +** - Returns 0 for all other artifact types except that it will always | |
| 283 | +** return true for admins because that check skips looking at the | |
| 284 | +** db. | |
| 285 | +** | |
| 286 | + */ | |
| 287 | +int moderation_user_could(int rid, int bMayDeny, const char *zWho){ | |
| 288 | + static Stmt q; | |
| 289 | + int rc = 0; | |
| 290 | + if( g.perm.Admin ) return g.perm.Admin; | |
| 291 | + if( !q.pStmt ){ | |
| 292 | + db_static_prepare( | |
| 293 | + &q, | |
| 294 | + "SELECT coalesce(euser,user)=:user, type FROM event " | |
| 295 | + "WHERE objid=:rid" | |
| 296 | + ); | |
| 297 | + } | |
| 298 | + db_bind_int(&q, ":rid", rid); | |
| 299 | + db_bind_text(&q, ":user", zWho ? zWho : login_name()); | |
| 300 | + if( SQLITE_ROW==db_step(&q) ){ | |
| 301 | + const int bIsOwner = db_column_int(&q, 0); | |
| 302 | + const char *zType = db_column_text(&q, 1); | |
| 303 | + switch( zType ? zType[0] : 0 ){ | |
| 304 | + case 'f': rc = g.perm.ModForum || (bIsOwner && bMayDeny); break; | |
| 305 | + case 't': rc = g.perm.ModTkt || (bIsOwner && bMayDeny); break; | |
| 306 | + case 'w': rc = g.perm.ModWiki || (bIsOwner && bMayDeny); break; | |
| 307 | + /* case 'e': Technotes and their attachments are not subject | |
| 308 | + ** to moderation. */ | |
| 309 | + default: break; | |
| 310 | + } | |
| 311 | + } | |
| 312 | + db_reset(&q); | |
| 313 | + return rc; | |
| 314 | +} | |
| 315 | + | |
| 316 | + | |
| 317 | +/* | |
| 318 | +** COMMAND: test-user-could-moderate | |
| 319 | +** | |
| 320 | +** Usage: %fossil test-user-could-moderate ?-deny? user-name ...artifactNames | |
| 321 | +** | |
| 322 | +** Tests whether a given user would have the ability to moderate | |
| 323 | +** the given artifacts. The -deny flag indicates that the check should | |
| 324 | +** permit moderation if the artifact is owned by the same user. | |
| 325 | +*/ | |
| 326 | +void test_moderation_user_could_cmd(void){ | |
| 327 | + const char *zWho; | |
| 328 | + const int bMayDeny = find_option("deny",0,0) != 0; | |
| 329 | + char * zCap; | |
| 330 | + int i; | |
| 331 | + db_find_and_open_repository(0,0); | |
| 332 | + verify_all_options(); | |
| 333 | + if( g.argc<4 ){ | |
| 334 | + usage("user-name artifact-names..."); | |
| 335 | + } | |
| 336 | + zWho = g.zLogin = g.argv[2]; | |
| 337 | + zCap = db_text( | |
| 338 | + 0, "SELECT cap FROM user WHERE login=%Q", zWho | |
| 339 | + ); | |
| 340 | + if( !zCap ){ | |
| 341 | + fossil_fatal("Cannot determine capabilities of user %s", zWho); | |
| 342 | + } | |
| 343 | + login_set_capabilities(zCap, 0); | |
| 344 | + fossil_print("User: %s\nCaps: %s\n", zWho, zCap); | |
| 345 | + fossil_free(zCap); | |
| 346 | + for( i = 3; i < g.argc; ++i ){ | |
| 347 | + const char * zArg = g.argv[i]; | |
| 348 | + int rid = symbolic_name_to_rid(zArg, "*"); | |
| 349 | + int may; | |
| 350 | + if( rid<=0 ){ | |
| 351 | + fossil_fatal("Cannot resolve name: %s", zArg); | |
| 352 | + } | |
| 353 | + may = moderation_user_could(rid, bMayDeny, zWho); | |
| 354 | + fossil_print("%s\t\t=> %d\t=> %s\n", zArg, rid, may ? "yes" : "no"); | |
| 355 | + } | |
| 356 | +} | |
| 230 | 357 |
| --- src/moderate.c | |
| +++ src/moderate.c | |
| @@ -65,11 +65,25 @@ | |
| 65 | ** false without generating any output. |
| 66 | */ |
| 67 | int moderation_pending_www(int rid){ |
| 68 | int pending = moderation_pending(rid); |
| 69 | if( pending ){ |
| 70 | @ <span class="modpending">(Awaiting Moderator Approval)</span> |
| 71 | } |
| 72 | return pending; |
| 73 | } |
| 74 | |
| 75 | |
| @@ -225,5 +239,118 @@ | |
| 225 | } |
| 226 | db_finalize(&q); |
| 227 | setup_incr_cfgcnt(); |
| 228 | db_end_transaction(0); |
| 229 | } |
| 230 |
| --- src/moderate.c | |
| +++ src/moderate.c | |
| @@ -65,11 +65,25 @@ | |
| 65 | ** false without generating any output. |
| 66 | */ |
| 67 | int moderation_pending_www(int rid){ |
| 68 | int pending = moderation_pending(rid); |
| 69 | if( pending ){ |
| 70 | #if 0 |
| 71 | if( moderation_user_could(rid, 1, 0) ){ |
| 72 | /* It would be nice to emit a link to the appropriate page to |
| 73 | ** approve/reject the moderation, but for that we need |
| 74 | ** artifact-type-dependent info and links. That's complicated by |
| 75 | ** the fact that deriving whether rid refers to an attachment or |
| 76 | ** an attachment target is apparently tricky because of how |
| 77 | ** attachments are recorded in the event table. */ |
| 78 | @ <span class="modpending">(<a href="%R/WHAT_GOES_HERE?">\ |
| 79 | @Awaiting Moderator Approval</a>)</span> |
| 80 | }else |
| 81 | #endif |
| 82 | { |
| 83 | @ <span class="modpending">(Awaiting Moderator Approval)</span> |
| 84 | } |
| 85 | } |
| 86 | return pending; |
| 87 | } |
| 88 | |
| 89 | |
| @@ -225,5 +239,118 @@ | |
| 239 | } |
| 240 | db_finalize(&q); |
| 241 | setup_incr_cfgcnt(); |
| 242 | db_end_transaction(0); |
| 243 | } |
| 244 | |
| 245 | /* |
| 246 | ** Returns true if the current user could ostensibly moderate the blob |
| 247 | ** refered to by rid, irrespective of whether that object is currently |
| 248 | ** pending moderation. If rid is not an event.objid value then this |
| 249 | ** returns 0. |
| 250 | ** |
| 251 | ** If bMayDeny is true then a matching user is permitted to moderate a |
| 252 | ** decline by not an approval. Pass 1 here if true should be returned |
| 253 | ** if the current user matches the artifact. When passing false, it |
| 254 | ** will only return true for users who have explicit moderation |
| 255 | ** permissions. The purpose of this is to exclude pending-moderation |
| 256 | ** from the current user in some contexts but not others. |
| 257 | ** |
| 258 | ** zWho is an optional user name to consider for ownership of an |
| 259 | ** artifact, as compared to the artifact's matching event.(euser,user) |
| 260 | ** fields. If 0 then it defaults to login_name(). This is strictly a |
| 261 | ** name comparison - it does not inspect zWho's repo-level |
| 262 | ** permissions. |
| 263 | ** |
| 264 | ** Design issue: since this gets its info from the event table, it |
| 265 | ** cannot unambiguously distinguish between an attachment-capable |
| 266 | ** artifact type and attachments to one. Attachment events are encoded |
| 267 | ** with type=X, where X is the same as the artifact type to which the |
| 268 | ** attachment was applied. |
| 269 | ** |
| 270 | ** The moderation rules applied here are: |
| 271 | ** |
| 272 | ** - Admins may always moderate. This is a fast path which bypasses |
| 273 | ** artifact lookup. For non-admins, we look for a record in the |
| 274 | ** event table. |
| 275 | ** |
| 276 | ** - Forum, Wiki, and Ticket moderators may always moderate a matching |
| 277 | ** artifact. If bMayDeny is true then an artifact's owner, even if |
| 278 | ** not a moderator, may moderate it. i.e. a non-moderator owner can |
| 279 | ** reject their pending-moderation objects but they may not approve |
| 280 | ** them. |
| 281 | ** |
| 282 | ** - Returns 0 for all other artifact types except that it will always |
| 283 | ** return true for admins because that check skips looking at the |
| 284 | ** db. |
| 285 | ** |
| 286 | */ |
| 287 | int moderation_user_could(int rid, int bMayDeny, const char *zWho){ |
| 288 | static Stmt q; |
| 289 | int rc = 0; |
| 290 | if( g.perm.Admin ) return g.perm.Admin; |
| 291 | if( !q.pStmt ){ |
| 292 | db_static_prepare( |
| 293 | &q, |
| 294 | "SELECT coalesce(euser,user)=:user, type FROM event " |
| 295 | "WHERE objid=:rid" |
| 296 | ); |
| 297 | } |
| 298 | db_bind_int(&q, ":rid", rid); |
| 299 | db_bind_text(&q, ":user", zWho ? zWho : login_name()); |
| 300 | if( SQLITE_ROW==db_step(&q) ){ |
| 301 | const int bIsOwner = db_column_int(&q, 0); |
| 302 | const char *zType = db_column_text(&q, 1); |
| 303 | switch( zType ? zType[0] : 0 ){ |
| 304 | case 'f': rc = g.perm.ModForum || (bIsOwner && bMayDeny); break; |
| 305 | case 't': rc = g.perm.ModTkt || (bIsOwner && bMayDeny); break; |
| 306 | case 'w': rc = g.perm.ModWiki || (bIsOwner && bMayDeny); break; |
| 307 | /* case 'e': Technotes and their attachments are not subject |
| 308 | ** to moderation. */ |
| 309 | default: break; |
| 310 | } |
| 311 | } |
| 312 | db_reset(&q); |
| 313 | return rc; |
| 314 | } |
| 315 | |
| 316 | |
| 317 | /* |
| 318 | ** COMMAND: test-user-could-moderate |
| 319 | ** |
| 320 | ** Usage: %fossil test-user-could-moderate ?-deny? user-name ...artifactNames |
| 321 | ** |
| 322 | ** Tests whether a given user would have the ability to moderate |
| 323 | ** the given artifacts. The -deny flag indicates that the check should |
| 324 | ** permit moderation if the artifact is owned by the same user. |
| 325 | */ |
| 326 | void test_moderation_user_could_cmd(void){ |
| 327 | const char *zWho; |
| 328 | const int bMayDeny = find_option("deny",0,0) != 0; |
| 329 | char * zCap; |
| 330 | int i; |
| 331 | db_find_and_open_repository(0,0); |
| 332 | verify_all_options(); |
| 333 | if( g.argc<4 ){ |
| 334 | usage("user-name artifact-names..."); |
| 335 | } |
| 336 | zWho = g.zLogin = g.argv[2]; |
| 337 | zCap = db_text( |
| 338 | 0, "SELECT cap FROM user WHERE login=%Q", zWho |
| 339 | ); |
| 340 | if( !zCap ){ |
| 341 | fossil_fatal("Cannot determine capabilities of user %s", zWho); |
| 342 | } |
| 343 | login_set_capabilities(zCap, 0); |
| 344 | fossil_print("User: %s\nCaps: %s\n", zWho, zCap); |
| 345 | fossil_free(zCap); |
| 346 | for( i = 3; i < g.argc; ++i ){ |
| 347 | const char * zArg = g.argv[i]; |
| 348 | int rid = symbolic_name_to_rid(zArg, "*"); |
| 349 | int may; |
| 350 | if( rid<=0 ){ |
| 351 | fossil_fatal("Cannot resolve name: %s", zArg); |
| 352 | } |
| 353 | may = moderation_user_could(rid, bMayDeny, zWho); |
| 354 | fossil_print("%s\t\t=> %d\t=> %s\n", zArg, rid, may ? "yes" : "no"); |
| 355 | } |
| 356 | } |
| 357 |
+251
-58
| --- src/name.c | ||
| +++ src/name.c | ||
| @@ -1143,10 +1143,40 @@ | ||
| 1143 | 1143 | case CFTYPE_CONTROL: zType = "Tag-change"; break; |
| 1144 | 1144 | default: break; |
| 1145 | 1145 | } |
| 1146 | 1146 | return zType; |
| 1147 | 1147 | } |
| 1148 | + | |
| 1149 | +/* | |
| 1150 | +** This is the output routine for whatis_rid(). If pOut is NULL | |
| 1151 | +** then write zKey and zValue on fossil_print(). But if pOut is | |
| 1152 | +** not NULL, append the key and value as a term of a JSON object. | |
| 1153 | +*/ | |
| 1154 | +static void whatis_line( | |
| 1155 | + sqlite3_str *pOut, | |
| 1156 | + const char *zKey, | |
| 1157 | + const char *zValue, | |
| 1158 | + ... | |
| 1159 | +){ | |
| 1160 | + char *zArg; | |
| 1161 | + va_list ap; | |
| 1162 | + va_start(ap, zValue); | |
| 1163 | + zArg = sqlite3_vmprintf(zValue,ap); | |
| 1164 | + va_end(ap); | |
| 1165 | + if( pOut ){ | |
| 1166 | + int n = sqlite3_str_length(pOut); | |
| 1167 | + if( n>1 && sqlite3_str_value(pOut)[n-1]!='{' ){ | |
| 1168 | + sqlite3_str_append(pOut, ",", 1); | |
| 1169 | + } | |
| 1170 | + sqlite3_str_appendf(pOut, "%J:%J", zKey, zArg); | |
| 1171 | + }else{ | |
| 1172 | + int n = 11 - (int)strlen(zKey); | |
| 1173 | + if( n<=0 ) n = 0; | |
| 1174 | + fossil_print("%s:%*s%s\n",zKey,n,"",zArg); | |
| 1175 | + } | |
| 1176 | + sqlite3_free(zArg); | |
| 1177 | +} | |
| 1148 | 1178 | |
| 1149 | 1179 | /* |
| 1150 | 1180 | ** Flag values for whatis_rid(). |
| 1151 | 1181 | */ |
| 1152 | 1182 | #if INTERFACE |
| @@ -1153,18 +1183,25 @@ | ||
| 1153 | 1183 | #define WHATIS_VERBOSE 0x01 /* Extra output */ |
| 1154 | 1184 | #define WHATIS_BRIEF 0x02 /* Omit unnecessary output */ |
| 1155 | 1185 | #define WHATIS_REPO 0x04 /* Show repository name */ |
| 1156 | 1186 | #define WHATIS_OMIT_UNK 0x08 /* Do not show "unknown" lines */ |
| 1157 | 1187 | #define WHATIS_HASHONLY 0x10 /* Show only the hash */ |
| 1188 | +#define WHATIS_JSON 0x20 /* Render as JSON */ | |
| 1158 | 1189 | #endif |
| 1159 | 1190 | |
| 1160 | 1191 | /* |
| 1161 | -** Generate a description of artifact "rid" | |
| 1192 | +** Generate a description of artifact "rid". | |
| 1193 | +** | |
| 1194 | +** Send results to stdout using fossil_print() if pOut==0 or if | |
| 1195 | +** WHATIS_HASHONLY is set. But without WHATIS_HASHONLY and if | |
| 1196 | +** pOut!=0, then write a JSON description of the object into pOut. | |
| 1162 | 1197 | */ |
| 1163 | -void whatis_rid(int rid, int flags){ | |
| 1198 | +void whatis_rid(int rid, int flags, sqlite3_str *pOut){ | |
| 1164 | 1199 | Stmt q; |
| 1165 | 1200 | int cnt; |
| 1201 | + | |
| 1202 | + if( pOut ) sqlite3_str_appendf(pOut, "{\"rid\":%d", rid); | |
| 1166 | 1203 | |
| 1167 | 1204 | /* Basic information about the object. */ |
| 1168 | 1205 | db_prepare(&q, |
| 1169 | 1206 | "SELECT uuid, size, datetime(mtime,toLocal()), ipaddr" |
| 1170 | 1207 | " FROM blob, rcvfrom" |
| @@ -1173,19 +1210,21 @@ | ||
| 1173 | 1210 | rid); |
| 1174 | 1211 | if( db_step(&q)==SQLITE_ROW ){ |
| 1175 | 1212 | if( flags & WHATIS_HASHONLY ){ |
| 1176 | 1213 | fossil_print("%s\n", db_column_text(&q,0)); |
| 1177 | 1214 | }else if( flags & WHATIS_VERBOSE ){ |
| 1178 | - fossil_print("artifact: %s (%d)\n", db_column_text(&q,0), rid); | |
| 1179 | - fossil_print("size: %d bytes\n", db_column_int(&q,1)); | |
| 1180 | - fossil_print("received: %s from %s\n", | |
| 1215 | + whatis_line(pOut, "artifact", "%s (%d)", db_column_text(&q,0), rid); | |
| 1216 | + whatis_line(pOut, "size", "%d bytes", db_column_int(&q,1)); | |
| 1217 | + whatis_line(pOut, "received", "%s from %s", | |
| 1181 | 1218 | db_column_text(&q, 2), |
| 1182 | 1219 | db_column_text(&q, 3)); |
| 1183 | 1220 | }else{ |
| 1184 | - fossil_print("artifact: %s\n", db_column_text(&q,0)); | |
| 1185 | - fossil_print("size: %d bytes\n", db_column_int(&q,1)); | |
| 1221 | + whatis_line(pOut, "artifact","%s", db_column_text(&q,0)); | |
| 1222 | + whatis_line(pOut, "size", "%d bytes", db_column_int(&q,1)); | |
| 1186 | 1223 | } |
| 1224 | + }else if( pOut ){ | |
| 1225 | + sqlite3_str_appendf(pOut, ",\"artifact\":null"); | |
| 1187 | 1226 | } |
| 1188 | 1227 | db_finalize(&q); |
| 1189 | 1228 | if( flags & WHATIS_HASHONLY ) return; |
| 1190 | 1229 | |
| 1191 | 1230 | /* Report any symbolic tags on this artifact */ |
| @@ -1198,14 +1237,27 @@ | ||
| 1198 | 1237 | " ORDER BY 1", |
| 1199 | 1238 | rid |
| 1200 | 1239 | ); |
| 1201 | 1240 | cnt = 0; |
| 1202 | 1241 | while( db_step(&q)==SQLITE_ROW ){ |
| 1203 | - const char *zPrefix = cnt++ ? ", " : "tags: "; | |
| 1204 | - fossil_print("%s%s", zPrefix, db_column_text(&q,0)); | |
| 1242 | + const char *zTag = (const char*)db_column_text(&q,0); | |
| 1243 | + if( pOut ){ | |
| 1244 | + const char *zSep = cnt==0 ? ",tags:[" : ","; | |
| 1245 | + sqlite3_str_appendf(pOut, "%s%J", zSep, zTag); | |
| 1246 | + }else{ | |
| 1247 | + const char *zPrefix = cnt ? ", " : "tags: "; | |
| 1248 | + fossil_print("%s%s", zPrefix, db_column_text(&q,0)); | |
| 1249 | + } | |
| 1250 | + cnt++; | |
| 1205 | 1251 | } |
| 1206 | - if( cnt ) fossil_print("\n"); | |
| 1252 | + if( cnt ){ | |
| 1253 | + if( pOut ){ | |
| 1254 | + sqlite3_str_append(pOut, "]", 1); | |
| 1255 | + }else{ | |
| 1256 | + fossil_print("\n"); | |
| 1257 | + } | |
| 1258 | + } | |
| 1207 | 1259 | db_finalize(&q); |
| 1208 | 1260 | |
| 1209 | 1261 | /* Report any HIDDEN, PRIVATE, CLUSTER, or CLOSED tags on this artifact */ |
| 1210 | 1262 | db_prepare(&q, |
| 1211 | 1263 | "SELECT tagname" |
| @@ -1215,36 +1267,63 @@ | ||
| 1215 | 1267 | " ORDER BY 1", |
| 1216 | 1268 | rid |
| 1217 | 1269 | ); |
| 1218 | 1270 | cnt = 0; |
| 1219 | 1271 | while( db_step(&q)==SQLITE_ROW ){ |
| 1220 | - const char *zPrefix = cnt++ ? ", " : "raw-tags: "; | |
| 1221 | - fossil_print("%s%s", zPrefix, db_column_text(&q,0)); | |
| 1272 | + const char *zTag = (const char*)db_column_text(&q,0); | |
| 1273 | + if( pOut ){ | |
| 1274 | + const char *zSep = cnt==0 ? ",\"raw-tags\":[" : ","; | |
| 1275 | + sqlite3_str_appendf(pOut, "%s%J", zSep, zTag); | |
| 1276 | + }else{ | |
| 1277 | + const char *zPrefix = cnt ? ", " : "raw-tags: "; | |
| 1278 | + fossil_print("%s%s", zPrefix, db_column_text(&q,0)); | |
| 1279 | + } | |
| 1280 | + cnt++; | |
| 1222 | 1281 | } |
| 1223 | - if( cnt ) fossil_print("\n"); | |
| 1282 | + if( cnt ){ | |
| 1283 | + if( pOut ){ | |
| 1284 | + sqlite3_str_append(pOut, "]", 1); | |
| 1285 | + }else{ | |
| 1286 | + fossil_print("\n"); | |
| 1287 | + } | |
| 1288 | + } | |
| 1224 | 1289 | db_finalize(&q); |
| 1225 | 1290 | |
| 1226 | 1291 | /* Check for entries on the timeline that reference this object */ |
| 1227 | 1292 | db_prepare(&q, |
| 1228 | - "SELECT type, datetime(mtime,toLocal())," | |
| 1229 | - " coalesce(euser,user), coalesce(ecomment,comment)" | |
| 1230 | - " FROM event WHERE objid=%d", rid); | |
| 1293 | + "SELECT" | |
| 1294 | + " type," | |
| 1295 | + " datetime(mtime,toLocal())," | |
| 1296 | + " coalesce(euser,user)," | |
| 1297 | + " coalesce(ecomment,comment)," | |
| 1298 | + " if(type='t',(SELECT substr(tagname,5) FROM tag" | |
| 1299 | + " WHERE tag.tagid=event.tagid))" | |
| 1300 | + "FROM event WHERE objid=%d", | |
| 1301 | + rid); | |
| 1231 | 1302 | if( db_step(&q)==SQLITE_ROW ){ |
| 1232 | 1303 | const char *zType; |
| 1233 | - switch( db_column_text(&q,0)[0] ){ | |
| 1304 | + char eType = db_column_text(&q,0)[0]; | |
| 1305 | + switch( eType ){ | |
| 1234 | 1306 | case 'c': zType = "Check-in"; break; |
| 1235 | 1307 | case 'w': zType = "Wiki-edit"; break; |
| 1236 | 1308 | case 'e': zType = "Technote"; break; |
| 1237 | 1309 | case 'f': zType = "Forum-post"; break; |
| 1238 | 1310 | case 't': zType = "Ticket-change"; break; |
| 1239 | 1311 | case 'g': zType = "Tag-change"; break; |
| 1240 | 1312 | default: zType = "Unknown"; break; |
| 1241 | 1313 | } |
| 1242 | - fossil_print("type: %s by %s on %s\n", zType, db_column_text(&q,2), | |
| 1314 | + whatis_line(pOut, "type", "%s by %s on %s", zType, db_column_text(&q,2), | |
| 1243 | 1315 | db_column_text(&q, 1)); |
| 1244 | - fossil_print("comment: "); | |
| 1245 | - comment_print(db_column_text(&q,3), 0, 12, -1, get_comment_format()); | |
| 1316 | + if( eType=='t' && db_column_type(&q,4)==SQLITE_TEXT ){ | |
| 1317 | + whatis_line(pOut, "ticket-id", "%s", db_column_text(&q,4)); | |
| 1318 | + } | |
| 1319 | + if( pOut ){ | |
| 1320 | + sqlite3_str_appendf(pOut, ",\"comment\":%J", db_column_text(&q,3)); | |
| 1321 | + }else{ | |
| 1322 | + fossil_print("comment: "); | |
| 1323 | + comment_print(db_column_text(&q,3), 0, 12, -1, get_comment_format()); | |
| 1324 | + } | |
| 1246 | 1325 | cnt++; |
| 1247 | 1326 | } |
| 1248 | 1327 | db_finalize(&q); |
| 1249 | 1328 | |
| 1250 | 1329 | /* Check to see if this object is used as a file in a check-in */ |
| @@ -1261,20 +1340,25 @@ | ||
| 1261 | 1340 | " ORDER BY event.mtime %s /*sort*/", |
| 1262 | 1341 | TAG_BRANCH, rid, |
| 1263 | 1342 | (flags & WHATIS_BRIEF) ? "LIMIT 1" : "DESC"); |
| 1264 | 1343 | while( db_step(&q)==SQLITE_ROW ){ |
| 1265 | 1344 | if( flags & WHATIS_BRIEF ){ |
| 1266 | - fossil_print("mtime: %s\n", db_column_text(&q,2)); | |
| 1267 | - } | |
| 1268 | - fossil_print("file: %s\n", db_column_text(&q,0)); | |
| 1269 | - fossil_print(" part of [%S] on branch %s by %s on %s\n", | |
| 1270 | - db_column_text(&q, 1), | |
| 1271 | - db_column_text(&q, 5), | |
| 1272 | - db_column_text(&q, 3), | |
| 1273 | - db_column_text(&q, 2)); | |
| 1274 | - fossil_print(" "); | |
| 1275 | - comment_print(db_column_text(&q,4), 0, 12, -1, get_comment_format()); | |
| 1345 | + whatis_line(pOut, "mtime","%s", db_column_text(&q,2)); | |
| 1346 | + } | |
| 1347 | + if( pOut ){ | |
| 1348 | + whatis_line(pOut,"file","%s", db_column_text(&q,0)); | |
| 1349 | + whatis_line(pOut,"part-of","%s", db_column_text(&q,1)); | |
| 1350 | + }else{ | |
| 1351 | + fossil_print("file: %s\n", db_column_text(&q,0)); | |
| 1352 | + fossil_print(" part of [%S] on branch %s by %s on %s\n", | |
| 1353 | + db_column_text(&q, 1), | |
| 1354 | + db_column_text(&q, 5), | |
| 1355 | + db_column_text(&q, 3), | |
| 1356 | + db_column_text(&q, 2)); | |
| 1357 | + fossil_print(" "); | |
| 1358 | + comment_print(db_column_text(&q,4), 0, 12, -1, get_comment_format()); | |
| 1359 | + } | |
| 1276 | 1360 | cnt++; |
| 1277 | 1361 | } |
| 1278 | 1362 | db_finalize(&q); |
| 1279 | 1363 | |
| 1280 | 1364 | /* Check to see if this object is used as an attachment */ |
| @@ -1293,30 +1377,36 @@ | ||
| 1293 | 1377 | " FROM attachment JOIN blob ON attachment.src=blob.uuid" |
| 1294 | 1378 | " WHERE blob.rid=%d", |
| 1295 | 1379 | rid |
| 1296 | 1380 | ); |
| 1297 | 1381 | while( db_step(&q)==SQLITE_ROW ){ |
| 1298 | - fossil_print("attachment: %s\n", db_column_text(&q,0)); | |
| 1299 | - fossil_print(" attached to %s %s\n", | |
| 1300 | - db_column_text(&q,5), db_column_text(&q,4)); | |
| 1301 | - if( flags & WHATIS_VERBOSE ){ | |
| 1302 | - fossil_print(" via %s (%d)\n", | |
| 1303 | - db_column_text(&q,7), db_column_int(&q,6)); | |
| 1382 | + if( pOut ){ | |
| 1383 | + whatis_line(pOut, "attachment", "%s", db_column_text(&q,0)); | |
| 1384 | + whatis_line(pOut, "attached-to", "%s %s", | |
| 1385 | + db_column_text(&q,5), db_column_text(&q,4)); | |
| 1304 | 1386 | }else{ |
| 1305 | - fossil_print(" via %s\n", | |
| 1306 | - db_column_text(&q,7)); | |
| 1387 | + fossil_print("attachment: %s\n", db_column_text(&q,0)); | |
| 1388 | + fossil_print(" attached to %s %s\n", | |
| 1389 | + db_column_text(&q,5), db_column_text(&q,4)); | |
| 1390 | + if( flags & WHATIS_VERBOSE ){ | |
| 1391 | + fossil_print(" via %s (%d)\n", | |
| 1392 | + db_column_text(&q,7), db_column_int(&q,6)); | |
| 1393 | + }else{ | |
| 1394 | + fossil_print(" via %s\n", | |
| 1395 | + db_column_text(&q,7)); | |
| 1396 | + } | |
| 1397 | + fossil_print(" by user %s on %s\n", | |
| 1398 | + db_column_text(&q,2), db_column_text(&q,3)); | |
| 1399 | + fossil_print(" "); | |
| 1400 | + comment_print(db_column_text(&q,1), 0, 12, -1, get_comment_format()); | |
| 1307 | 1401 | } |
| 1308 | - fossil_print(" by user %s on %s\n", | |
| 1309 | - db_column_text(&q,2), db_column_text(&q,3)); | |
| 1310 | - fossil_print(" "); | |
| 1311 | - comment_print(db_column_text(&q,1), 0, 12, -1, get_comment_format()); | |
| 1312 | 1402 | cnt++; |
| 1313 | 1403 | } |
| 1314 | 1404 | db_finalize(&q); |
| 1315 | 1405 | |
| 1316 | 1406 | /* If other information available, try to describe the object */ |
| 1317 | - if( cnt==0 ){ | |
| 1407 | + if( cnt==0 && pOut==0 ){ | |
| 1318 | 1408 | char *zWhere = mprintf("=%d", rid); |
| 1319 | 1409 | char *zDesc; |
| 1320 | 1410 | describe_artifacts(zWhere); |
| 1321 | 1411 | free(zWhere); |
| 1322 | 1412 | zDesc = db_text(0, |
| @@ -1323,61 +1413,124 @@ | ||
| 1323 | 1413 | "SELECT printf('%%-12s%%s %%s',type||':',summary,substr(ref,1,16))" |
| 1324 | 1414 | " FROM description WHERE rid=%d", rid); |
| 1325 | 1415 | fossil_print("%s\n", zDesc); |
| 1326 | 1416 | fossil_free(zDesc); |
| 1327 | 1417 | } |
| 1418 | + | |
| 1419 | + if( pOut ) sqlite3_str_append(pOut, "}", 1); | |
| 1328 | 1420 | } |
| 1329 | 1421 | |
| 1330 | 1422 | /* |
| 1331 | 1423 | ** Generate a description of artifact from it symbolic name. |
| 1332 | 1424 | */ |
| 1333 | 1425 | void whatis_artifact( |
| 1334 | - const char *zName, /* Symbolic name or full hash */ | |
| 1335 | - const char *zFileName,/* Optional: original filename (in file mode) */ | |
| 1336 | - const char *zType, /* Artifact type filter */ | |
| 1337 | - int mFlags /* WHATIS_* flags */ | |
| 1426 | + const char *zName, /* Symbolic name or full hash */ | |
| 1427 | + const char *zFileName,/* Optional: original filename (in file mode) */ | |
| 1428 | + const char *zType, /* Artifact type filter */ | |
| 1429 | + int mFlags, /* WHATIS_* flags */ | |
| 1430 | + sqlite3_str *pOut /* Write JSON here, if not NULL */ | |
| 1338 | 1431 | ){ |
| 1339 | 1432 | int rid = symbolic_name_to_rid(zName, zType); |
| 1433 | + size_t nName; | |
| 1434 | + char *zC = 0; | |
| 1435 | + int nTkt = 0; | |
| 1436 | + | |
| 1437 | + if( pOut ){ | |
| 1438 | + mFlags &= ~(WHATIS_HASHONLY|WHATIS_REPO); | |
| 1439 | + zFileName = 0; | |
| 1440 | + } | |
| 1441 | + if( (nName = strlen(zName))>=4 && validate16(zName,nName) ){ | |
| 1442 | + zC = fossil_strdup(zName); | |
| 1443 | + canonical16(zC, nName); | |
| 1444 | + nTkt = db_int(0,"SELECT count(*) FROM tag WHERE tagname GLOB 'tkt-%q*'",zC); | |
| 1445 | + if( nTkt>0 ){ | |
| 1446 | + if( rid==0 ){ | |
| 1447 | + rid = db_int(0, | |
| 1448 | + "SELECT srcid FROM tag, tagxref" | |
| 1449 | + " WHERE tag.tagname GLOB 'tkt-%q*'" | |
| 1450 | + " AND tagxref.tagid=tag.tagid" | |
| 1451 | + " AND tagxref.tagtype=1" | |
| 1452 | + " ORDER BY tagxref.mtime", | |
| 1453 | + zC | |
| 1454 | + ); | |
| 1455 | + }else{ | |
| 1456 | + rid = -1; | |
| 1457 | + } | |
| 1458 | + } | |
| 1459 | + } | |
| 1340 | 1460 | if( rid<0 ){ |
| 1341 | 1461 | Stmt q; |
| 1342 | 1462 | int cnt = 0; |
| 1343 | 1463 | if( mFlags & WHATIS_REPO ){ |
| 1344 | 1464 | fossil_print("\nrepository: %s\n", g.zRepositoryName); |
| 1345 | 1465 | } |
| 1346 | 1466 | if( zFileName ){ |
| 1347 | 1467 | fossil_print("%-12s%s\n", "name:", zFileName); |
| 1348 | 1468 | } |
| 1349 | - fossil_print("%-12s%s (ambiguous)\n", "hash:", zName); | |
| 1469 | + if( pOut ){ | |
| 1470 | + sqlite3_str_appendall(pOut, "{\"ambiguous\":["); | |
| 1471 | + }else{ | |
| 1472 | + fossil_print("%-12s%s (ambiguous)\n", "hash:", zName); | |
| 1473 | + } | |
| 1350 | 1474 | db_prepare(&q, |
| 1351 | 1475 | "SELECT rid FROM blob WHERE uuid>=lower(%Q) AND uuid<(lower(%Q)||'z')", |
| 1352 | 1476 | zName, zName |
| 1353 | - ); | |
| 1477 | + ); | |
| 1354 | 1478 | while( db_step(&q)==SQLITE_ROW ){ |
| 1355 | - if( cnt++ ) fossil_print("%12s---- meaning #%d ----\n", " ", cnt); | |
| 1356 | - whatis_rid(db_column_int(&q, 0), mFlags); | |
| 1479 | + if( cnt++ ){ | |
| 1480 | + if( pOut ){ | |
| 1481 | + sqlite3_str_append(pOut, ",", 1); | |
| 1482 | + }else{ | |
| 1483 | + fossil_print("%12s---- meaning #%d ----\n", " ", cnt); | |
| 1484 | + } | |
| 1485 | + } | |
| 1486 | + whatis_rid(db_column_int(&q, 0), mFlags, pOut); | |
| 1357 | 1487 | } |
| 1358 | 1488 | db_finalize(&q); |
| 1489 | + if( nTkt>0 ){ | |
| 1490 | + db_prepare(&q, | |
| 1491 | + "SELECT (SELECT srcid FROM tagxref" | |
| 1492 | + " WHERE tagxref.tagid=tag.tagid" | |
| 1493 | + " AND tagxref.tagtype=1" | |
| 1494 | + " ORDER BY mtime LIMIT 1)" | |
| 1495 | + " FROM tag WHERE tagname GLOB 'tkt-%q*'", | |
| 1496 | + zC | |
| 1497 | + ); | |
| 1498 | + while( db_step(&q)==SQLITE_ROW ){ | |
| 1499 | + if( pOut ){ | |
| 1500 | + sqlite3_str_append(pOut, ",", 1); | |
| 1501 | + }else{ | |
| 1502 | + fossil_print("%12s---- meaning #%d ----\n", " ", cnt); | |
| 1503 | + } | |
| 1504 | + whatis_rid(db_column_int(&q, 0), mFlags, pOut); | |
| 1505 | + } | |
| 1506 | + db_finalize(&q); | |
| 1507 | + } | |
| 1508 | + if( pOut ) sqlite3_str_append(pOut, "]}", 2); | |
| 1359 | 1509 | }else if( rid==0 ){ |
| 1360 | 1510 | if( (mFlags & (WHATIS_OMIT_UNK|WHATIS_HASHONLY))==0 ){ |
| 1361 | 1511 | /* 0123456789 12 */ |
| 1362 | 1512 | if( zFileName ){ |
| 1363 | 1513 | fossil_print("%-12s%s\n", "name:", zFileName); |
| 1364 | 1514 | } |
| 1365 | - fossil_print("unknown: %s\n", zName); | |
| 1515 | + if( pOut ) sqlite3_str_append(pOut, "{", 1); | |
| 1516 | + whatis_line(pOut, "unknown", "%s", zName); | |
| 1517 | + if( pOut ) sqlite3_str_append(pOut, "}", 1); | |
| 1366 | 1518 | } |
| 1367 | 1519 | }else{ |
| 1368 | 1520 | if( mFlags & WHATIS_REPO ){ |
| 1369 | 1521 | fossil_print("\nrepository: %s\n", g.zRepositoryName); |
| 1370 | 1522 | } |
| 1371 | 1523 | if( zFileName ){ |
| 1372 | 1524 | zName = zFileName; |
| 1373 | 1525 | } |
| 1374 | - if( (mFlags & WHATIS_HASHONLY)==0 ){ | |
| 1375 | - fossil_print("%-12s%s\n", "name:", zName); | |
| 1526 | + if( (mFlags & WHATIS_HASHONLY)==0 && pOut==0 ){ | |
| 1527 | + whatis_line(pOut, "name", "%s", zName); | |
| 1376 | 1528 | } |
| 1377 | - whatis_rid(rid, mFlags); | |
| 1529 | + whatis_rid(rid, mFlags, pOut); | |
| 1378 | 1530 | } |
| 1531 | + fossil_free(zC); | |
| 1379 | 1532 | } |
| 1380 | 1533 | |
| 1381 | 1534 | /* |
| 1382 | 1535 | ** COMMAND: whatis* |
| 1383 | 1536 | ** |
| @@ -1401,10 +1554,11 @@ | ||
| 1401 | 1554 | void whatis_cmd(void){ |
| 1402 | 1555 | int mFlags = 0; |
| 1403 | 1556 | int fileFlag; |
| 1404 | 1557 | int i; |
| 1405 | 1558 | const char *zType = 0; |
| 1559 | + sqlite3_str *pOut = 0; | |
| 1406 | 1560 | db_find_and_open_repository(0,0); |
| 1407 | 1561 | if( find_option("verbose","v",0)!=0 ){ |
| 1408 | 1562 | mFlags |= WHATIS_VERBOSE; |
| 1409 | 1563 | } |
| 1410 | 1564 | if( find_option("hash","h",0)!=0 ){ |
| @@ -1413,10 +1567,14 @@ | ||
| 1413 | 1567 | if( g.fQuiet ){ |
| 1414 | 1568 | mFlags |= WHATIS_OMIT_UNK | WHATIS_REPO; |
| 1415 | 1569 | } |
| 1416 | 1570 | fileFlag = find_option("file","f",0)!=0; |
| 1417 | 1571 | zType = find_option("type",0,1); |
| 1572 | + | |
| 1573 | + if( find_option("json",0,0)!=0 ){ /* undocumented test option */ | |
| 1574 | + pOut = sqlite3_str_new(0); | |
| 1575 | + } | |
| 1418 | 1576 | |
| 1419 | 1577 | /* We should be done with options.. */ |
| 1420 | 1578 | verify_all_options(); |
| 1421 | 1579 | |
| 1422 | 1580 | if( g.argc<3 ) usage("NAME ..."); |
| @@ -1439,17 +1597,52 @@ | ||
| 1439 | 1597 | ** the primary hash name. */ |
| 1440 | 1598 | blob_reset(&hash); |
| 1441 | 1599 | hname_hash(&in, 0, &hash); |
| 1442 | 1600 | zHash = (const char*)blob_str(&hash); |
| 1443 | 1601 | } |
| 1444 | - whatis_artifact(zHash, zName, zType, mFlags); | |
| 1602 | + whatis_artifact(zHash, zName, zType, mFlags, pOut); | |
| 1445 | 1603 | blob_reset(&hash); |
| 1446 | 1604 | }else{ |
| 1447 | - whatis_artifact(zName, 0, zType, mFlags); | |
| 1605 | + whatis_artifact(zName, 0, zType, mFlags, pOut); | |
| 1606 | + } | |
| 1607 | + if( pOut ){ | |
| 1608 | + fossil_print("%s\n", sqlite3_str_value(pOut)); | |
| 1609 | + sqlite3_str_truncate(pOut, 0); | |
| 1448 | 1610 | } |
| 1449 | 1611 | } |
| 1612 | + if( pOut ) sqlite3_str_free(pOut); | |
| 1613 | +} | |
| 1614 | + | |
| 1615 | +/* | |
| 1616 | +** This is an SQL function that does the rough equivalent of the | |
| 1617 | +** "whatis" command. The argument can be a text identifier, or a | |
| 1618 | +** integer RID. | |
| 1619 | +*/ | |
| 1620 | +void whatis_sql_function( | |
| 1621 | + sqlite3_context *context, | |
| 1622 | + int argc, | |
| 1623 | + sqlite3_value **argv | |
| 1624 | +){ | |
| 1625 | + sqlite3_str *pOut = sqlite3_str_new(0); | |
| 1626 | + int n; | |
| 1627 | + assert( argc==1 ); | |
| 1628 | + if( sqlite3_value_type(argv[0])==SQLITE_INTEGER ){ | |
| 1629 | + int rid = sqlite3_value_int(argv[0]); | |
| 1630 | + whatis_rid(rid, 0, pOut); | |
| 1631 | + }else if( sqlite3_value_type(argv[0])==SQLITE_TEXT ){ | |
| 1632 | + const char *zName = (const char*)sqlite3_value_text(argv[0]); | |
| 1633 | + whatis_artifact(zName, 0, 0, 0, pOut); | |
| 1634 | + }else{ | |
| 1635 | + sqlite3_str_free(pOut); | |
| 1636 | + return; | |
| 1637 | + } | |
| 1638 | + n = sqlite3_str_length(pOut); | |
| 1639 | + sqlite3_result_text64(context, sqlite3_str_finish(pOut), n, | |
| 1640 | + sqlite3_free, SQLITE_UTF8); | |
| 1641 | + sqlite3_result_subtype(context, 'J'); | |
| 1450 | 1642 | } |
| 1643 | + | |
| 1451 | 1644 | |
| 1452 | 1645 | /* |
| 1453 | 1646 | ** COMMAND: test-whatis-all |
| 1454 | 1647 | ** |
| 1455 | 1648 | ** Usage: %fossil test-whatis-all |
| @@ -1461,11 +1654,11 @@ | ||
| 1461 | 1654 | int cnt = 0; |
| 1462 | 1655 | db_find_and_open_repository(0,0); |
| 1463 | 1656 | db_prepare(&q, "SELECT rid FROM blob ORDER BY rid"); |
| 1464 | 1657 | while( db_step(&q)==SQLITE_ROW ){ |
| 1465 | 1658 | if( cnt++ ) fossil_print("%.79c\n", '-'); |
| 1466 | - whatis_rid(db_column_int(&q,0), 1); | |
| 1659 | + whatis_rid(db_column_int(&q,0), 1, 0); | |
| 1467 | 1660 | } |
| 1468 | 1661 | db_finalize(&q); |
| 1469 | 1662 | } |
| 1470 | 1663 | |
| 1471 | 1664 | |
| 1472 | 1665 |
| --- src/name.c | |
| +++ src/name.c | |
| @@ -1143,10 +1143,40 @@ | |
| 1143 | case CFTYPE_CONTROL: zType = "Tag-change"; break; |
| 1144 | default: break; |
| 1145 | } |
| 1146 | return zType; |
| 1147 | } |
| 1148 | |
| 1149 | /* |
| 1150 | ** Flag values for whatis_rid(). |
| 1151 | */ |
| 1152 | #if INTERFACE |
| @@ -1153,18 +1183,25 @@ | |
| 1153 | #define WHATIS_VERBOSE 0x01 /* Extra output */ |
| 1154 | #define WHATIS_BRIEF 0x02 /* Omit unnecessary output */ |
| 1155 | #define WHATIS_REPO 0x04 /* Show repository name */ |
| 1156 | #define WHATIS_OMIT_UNK 0x08 /* Do not show "unknown" lines */ |
| 1157 | #define WHATIS_HASHONLY 0x10 /* Show only the hash */ |
| 1158 | #endif |
| 1159 | |
| 1160 | /* |
| 1161 | ** Generate a description of artifact "rid" |
| 1162 | */ |
| 1163 | void whatis_rid(int rid, int flags){ |
| 1164 | Stmt q; |
| 1165 | int cnt; |
| 1166 | |
| 1167 | /* Basic information about the object. */ |
| 1168 | db_prepare(&q, |
| 1169 | "SELECT uuid, size, datetime(mtime,toLocal()), ipaddr" |
| 1170 | " FROM blob, rcvfrom" |
| @@ -1173,19 +1210,21 @@ | |
| 1173 | rid); |
| 1174 | if( db_step(&q)==SQLITE_ROW ){ |
| 1175 | if( flags & WHATIS_HASHONLY ){ |
| 1176 | fossil_print("%s\n", db_column_text(&q,0)); |
| 1177 | }else if( flags & WHATIS_VERBOSE ){ |
| 1178 | fossil_print("artifact: %s (%d)\n", db_column_text(&q,0), rid); |
| 1179 | fossil_print("size: %d bytes\n", db_column_int(&q,1)); |
| 1180 | fossil_print("received: %s from %s\n", |
| 1181 | db_column_text(&q, 2), |
| 1182 | db_column_text(&q, 3)); |
| 1183 | }else{ |
| 1184 | fossil_print("artifact: %s\n", db_column_text(&q,0)); |
| 1185 | fossil_print("size: %d bytes\n", db_column_int(&q,1)); |
| 1186 | } |
| 1187 | } |
| 1188 | db_finalize(&q); |
| 1189 | if( flags & WHATIS_HASHONLY ) return; |
| 1190 | |
| 1191 | /* Report any symbolic tags on this artifact */ |
| @@ -1198,14 +1237,27 @@ | |
| 1198 | " ORDER BY 1", |
| 1199 | rid |
| 1200 | ); |
| 1201 | cnt = 0; |
| 1202 | while( db_step(&q)==SQLITE_ROW ){ |
| 1203 | const char *zPrefix = cnt++ ? ", " : "tags: "; |
| 1204 | fossil_print("%s%s", zPrefix, db_column_text(&q,0)); |
| 1205 | } |
| 1206 | if( cnt ) fossil_print("\n"); |
| 1207 | db_finalize(&q); |
| 1208 | |
| 1209 | /* Report any HIDDEN, PRIVATE, CLUSTER, or CLOSED tags on this artifact */ |
| 1210 | db_prepare(&q, |
| 1211 | "SELECT tagname" |
| @@ -1215,36 +1267,63 @@ | |
| 1215 | " ORDER BY 1", |
| 1216 | rid |
| 1217 | ); |
| 1218 | cnt = 0; |
| 1219 | while( db_step(&q)==SQLITE_ROW ){ |
| 1220 | const char *zPrefix = cnt++ ? ", " : "raw-tags: "; |
| 1221 | fossil_print("%s%s", zPrefix, db_column_text(&q,0)); |
| 1222 | } |
| 1223 | if( cnt ) fossil_print("\n"); |
| 1224 | db_finalize(&q); |
| 1225 | |
| 1226 | /* Check for entries on the timeline that reference this object */ |
| 1227 | db_prepare(&q, |
| 1228 | "SELECT type, datetime(mtime,toLocal())," |
| 1229 | " coalesce(euser,user), coalesce(ecomment,comment)" |
| 1230 | " FROM event WHERE objid=%d", rid); |
| 1231 | if( db_step(&q)==SQLITE_ROW ){ |
| 1232 | const char *zType; |
| 1233 | switch( db_column_text(&q,0)[0] ){ |
| 1234 | case 'c': zType = "Check-in"; break; |
| 1235 | case 'w': zType = "Wiki-edit"; break; |
| 1236 | case 'e': zType = "Technote"; break; |
| 1237 | case 'f': zType = "Forum-post"; break; |
| 1238 | case 't': zType = "Ticket-change"; break; |
| 1239 | case 'g': zType = "Tag-change"; break; |
| 1240 | default: zType = "Unknown"; break; |
| 1241 | } |
| 1242 | fossil_print("type: %s by %s on %s\n", zType, db_column_text(&q,2), |
| 1243 | db_column_text(&q, 1)); |
| 1244 | fossil_print("comment: "); |
| 1245 | comment_print(db_column_text(&q,3), 0, 12, -1, get_comment_format()); |
| 1246 | cnt++; |
| 1247 | } |
| 1248 | db_finalize(&q); |
| 1249 | |
| 1250 | /* Check to see if this object is used as a file in a check-in */ |
| @@ -1261,20 +1340,25 @@ | |
| 1261 | " ORDER BY event.mtime %s /*sort*/", |
| 1262 | TAG_BRANCH, rid, |
| 1263 | (flags & WHATIS_BRIEF) ? "LIMIT 1" : "DESC"); |
| 1264 | while( db_step(&q)==SQLITE_ROW ){ |
| 1265 | if( flags & WHATIS_BRIEF ){ |
| 1266 | fossil_print("mtime: %s\n", db_column_text(&q,2)); |
| 1267 | } |
| 1268 | fossil_print("file: %s\n", db_column_text(&q,0)); |
| 1269 | fossil_print(" part of [%S] on branch %s by %s on %s\n", |
| 1270 | db_column_text(&q, 1), |
| 1271 | db_column_text(&q, 5), |
| 1272 | db_column_text(&q, 3), |
| 1273 | db_column_text(&q, 2)); |
| 1274 | fossil_print(" "); |
| 1275 | comment_print(db_column_text(&q,4), 0, 12, -1, get_comment_format()); |
| 1276 | cnt++; |
| 1277 | } |
| 1278 | db_finalize(&q); |
| 1279 | |
| 1280 | /* Check to see if this object is used as an attachment */ |
| @@ -1293,30 +1377,36 @@ | |
| 1293 | " FROM attachment JOIN blob ON attachment.src=blob.uuid" |
| 1294 | " WHERE blob.rid=%d", |
| 1295 | rid |
| 1296 | ); |
| 1297 | while( db_step(&q)==SQLITE_ROW ){ |
| 1298 | fossil_print("attachment: %s\n", db_column_text(&q,0)); |
| 1299 | fossil_print(" attached to %s %s\n", |
| 1300 | db_column_text(&q,5), db_column_text(&q,4)); |
| 1301 | if( flags & WHATIS_VERBOSE ){ |
| 1302 | fossil_print(" via %s (%d)\n", |
| 1303 | db_column_text(&q,7), db_column_int(&q,6)); |
| 1304 | }else{ |
| 1305 | fossil_print(" via %s\n", |
| 1306 | db_column_text(&q,7)); |
| 1307 | } |
| 1308 | fossil_print(" by user %s on %s\n", |
| 1309 | db_column_text(&q,2), db_column_text(&q,3)); |
| 1310 | fossil_print(" "); |
| 1311 | comment_print(db_column_text(&q,1), 0, 12, -1, get_comment_format()); |
| 1312 | cnt++; |
| 1313 | } |
| 1314 | db_finalize(&q); |
| 1315 | |
| 1316 | /* If other information available, try to describe the object */ |
| 1317 | if( cnt==0 ){ |
| 1318 | char *zWhere = mprintf("=%d", rid); |
| 1319 | char *zDesc; |
| 1320 | describe_artifacts(zWhere); |
| 1321 | free(zWhere); |
| 1322 | zDesc = db_text(0, |
| @@ -1323,61 +1413,124 @@ | |
| 1323 | "SELECT printf('%%-12s%%s %%s',type||':',summary,substr(ref,1,16))" |
| 1324 | " FROM description WHERE rid=%d", rid); |
| 1325 | fossil_print("%s\n", zDesc); |
| 1326 | fossil_free(zDesc); |
| 1327 | } |
| 1328 | } |
| 1329 | |
| 1330 | /* |
| 1331 | ** Generate a description of artifact from it symbolic name. |
| 1332 | */ |
| 1333 | void whatis_artifact( |
| 1334 | const char *zName, /* Symbolic name or full hash */ |
| 1335 | const char *zFileName,/* Optional: original filename (in file mode) */ |
| 1336 | const char *zType, /* Artifact type filter */ |
| 1337 | int mFlags /* WHATIS_* flags */ |
| 1338 | ){ |
| 1339 | int rid = symbolic_name_to_rid(zName, zType); |
| 1340 | if( rid<0 ){ |
| 1341 | Stmt q; |
| 1342 | int cnt = 0; |
| 1343 | if( mFlags & WHATIS_REPO ){ |
| 1344 | fossil_print("\nrepository: %s\n", g.zRepositoryName); |
| 1345 | } |
| 1346 | if( zFileName ){ |
| 1347 | fossil_print("%-12s%s\n", "name:", zFileName); |
| 1348 | } |
| 1349 | fossil_print("%-12s%s (ambiguous)\n", "hash:", zName); |
| 1350 | db_prepare(&q, |
| 1351 | "SELECT rid FROM blob WHERE uuid>=lower(%Q) AND uuid<(lower(%Q)||'z')", |
| 1352 | zName, zName |
| 1353 | ); |
| 1354 | while( db_step(&q)==SQLITE_ROW ){ |
| 1355 | if( cnt++ ) fossil_print("%12s---- meaning #%d ----\n", " ", cnt); |
| 1356 | whatis_rid(db_column_int(&q, 0), mFlags); |
| 1357 | } |
| 1358 | db_finalize(&q); |
| 1359 | }else if( rid==0 ){ |
| 1360 | if( (mFlags & (WHATIS_OMIT_UNK|WHATIS_HASHONLY))==0 ){ |
| 1361 | /* 0123456789 12 */ |
| 1362 | if( zFileName ){ |
| 1363 | fossil_print("%-12s%s\n", "name:", zFileName); |
| 1364 | } |
| 1365 | fossil_print("unknown: %s\n", zName); |
| 1366 | } |
| 1367 | }else{ |
| 1368 | if( mFlags & WHATIS_REPO ){ |
| 1369 | fossil_print("\nrepository: %s\n", g.zRepositoryName); |
| 1370 | } |
| 1371 | if( zFileName ){ |
| 1372 | zName = zFileName; |
| 1373 | } |
| 1374 | if( (mFlags & WHATIS_HASHONLY)==0 ){ |
| 1375 | fossil_print("%-12s%s\n", "name:", zName); |
| 1376 | } |
| 1377 | whatis_rid(rid, mFlags); |
| 1378 | } |
| 1379 | } |
| 1380 | |
| 1381 | /* |
| 1382 | ** COMMAND: whatis* |
| 1383 | ** |
| @@ -1401,10 +1554,11 @@ | |
| 1401 | void whatis_cmd(void){ |
| 1402 | int mFlags = 0; |
| 1403 | int fileFlag; |
| 1404 | int i; |
| 1405 | const char *zType = 0; |
| 1406 | db_find_and_open_repository(0,0); |
| 1407 | if( find_option("verbose","v",0)!=0 ){ |
| 1408 | mFlags |= WHATIS_VERBOSE; |
| 1409 | } |
| 1410 | if( find_option("hash","h",0)!=0 ){ |
| @@ -1413,10 +1567,14 @@ | |
| 1413 | if( g.fQuiet ){ |
| 1414 | mFlags |= WHATIS_OMIT_UNK | WHATIS_REPO; |
| 1415 | } |
| 1416 | fileFlag = find_option("file","f",0)!=0; |
| 1417 | zType = find_option("type",0,1); |
| 1418 | |
| 1419 | /* We should be done with options.. */ |
| 1420 | verify_all_options(); |
| 1421 | |
| 1422 | if( g.argc<3 ) usage("NAME ..."); |
| @@ -1439,17 +1597,52 @@ | |
| 1439 | ** the primary hash name. */ |
| 1440 | blob_reset(&hash); |
| 1441 | hname_hash(&in, 0, &hash); |
| 1442 | zHash = (const char*)blob_str(&hash); |
| 1443 | } |
| 1444 | whatis_artifact(zHash, zName, zType, mFlags); |
| 1445 | blob_reset(&hash); |
| 1446 | }else{ |
| 1447 | whatis_artifact(zName, 0, zType, mFlags); |
| 1448 | } |
| 1449 | } |
| 1450 | } |
| 1451 | |
| 1452 | /* |
| 1453 | ** COMMAND: test-whatis-all |
| 1454 | ** |
| 1455 | ** Usage: %fossil test-whatis-all |
| @@ -1461,11 +1654,11 @@ | |
| 1461 | int cnt = 0; |
| 1462 | db_find_and_open_repository(0,0); |
| 1463 | db_prepare(&q, "SELECT rid FROM blob ORDER BY rid"); |
| 1464 | while( db_step(&q)==SQLITE_ROW ){ |
| 1465 | if( cnt++ ) fossil_print("%.79c\n", '-'); |
| 1466 | whatis_rid(db_column_int(&q,0), 1); |
| 1467 | } |
| 1468 | db_finalize(&q); |
| 1469 | } |
| 1470 | |
| 1471 | |
| 1472 |
| --- src/name.c | |
| +++ src/name.c | |
| @@ -1143,10 +1143,40 @@ | |
| 1143 | case CFTYPE_CONTROL: zType = "Tag-change"; break; |
| 1144 | default: break; |
| 1145 | } |
| 1146 | return zType; |
| 1147 | } |
| 1148 | |
| 1149 | /* |
| 1150 | ** This is the output routine for whatis_rid(). If pOut is NULL |
| 1151 | ** then write zKey and zValue on fossil_print(). But if pOut is |
| 1152 | ** not NULL, append the key and value as a term of a JSON object. |
| 1153 | */ |
| 1154 | static void whatis_line( |
| 1155 | sqlite3_str *pOut, |
| 1156 | const char *zKey, |
| 1157 | const char *zValue, |
| 1158 | ... |
| 1159 | ){ |
| 1160 | char *zArg; |
| 1161 | va_list ap; |
| 1162 | va_start(ap, zValue); |
| 1163 | zArg = sqlite3_vmprintf(zValue,ap); |
| 1164 | va_end(ap); |
| 1165 | if( pOut ){ |
| 1166 | int n = sqlite3_str_length(pOut); |
| 1167 | if( n>1 && sqlite3_str_value(pOut)[n-1]!='{' ){ |
| 1168 | sqlite3_str_append(pOut, ",", 1); |
| 1169 | } |
| 1170 | sqlite3_str_appendf(pOut, "%J:%J", zKey, zArg); |
| 1171 | }else{ |
| 1172 | int n = 11 - (int)strlen(zKey); |
| 1173 | if( n<=0 ) n = 0; |
| 1174 | fossil_print("%s:%*s%s\n",zKey,n,"",zArg); |
| 1175 | } |
| 1176 | sqlite3_free(zArg); |
| 1177 | } |
| 1178 | |
| 1179 | /* |
| 1180 | ** Flag values for whatis_rid(). |
| 1181 | */ |
| 1182 | #if INTERFACE |
| @@ -1153,18 +1183,25 @@ | |
| 1183 | #define WHATIS_VERBOSE 0x01 /* Extra output */ |
| 1184 | #define WHATIS_BRIEF 0x02 /* Omit unnecessary output */ |
| 1185 | #define WHATIS_REPO 0x04 /* Show repository name */ |
| 1186 | #define WHATIS_OMIT_UNK 0x08 /* Do not show "unknown" lines */ |
| 1187 | #define WHATIS_HASHONLY 0x10 /* Show only the hash */ |
| 1188 | #define WHATIS_JSON 0x20 /* Render as JSON */ |
| 1189 | #endif |
| 1190 | |
| 1191 | /* |
| 1192 | ** Generate a description of artifact "rid". |
| 1193 | ** |
| 1194 | ** Send results to stdout using fossil_print() if pOut==0 or if |
| 1195 | ** WHATIS_HASHONLY is set. But without WHATIS_HASHONLY and if |
| 1196 | ** pOut!=0, then write a JSON description of the object into pOut. |
| 1197 | */ |
| 1198 | void whatis_rid(int rid, int flags, sqlite3_str *pOut){ |
| 1199 | Stmt q; |
| 1200 | int cnt; |
| 1201 | |
| 1202 | if( pOut ) sqlite3_str_appendf(pOut, "{\"rid\":%d", rid); |
| 1203 | |
| 1204 | /* Basic information about the object. */ |
| 1205 | db_prepare(&q, |
| 1206 | "SELECT uuid, size, datetime(mtime,toLocal()), ipaddr" |
| 1207 | " FROM blob, rcvfrom" |
| @@ -1173,19 +1210,21 @@ | |
| 1210 | rid); |
| 1211 | if( db_step(&q)==SQLITE_ROW ){ |
| 1212 | if( flags & WHATIS_HASHONLY ){ |
| 1213 | fossil_print("%s\n", db_column_text(&q,0)); |
| 1214 | }else if( flags & WHATIS_VERBOSE ){ |
| 1215 | whatis_line(pOut, "artifact", "%s (%d)", db_column_text(&q,0), rid); |
| 1216 | whatis_line(pOut, "size", "%d bytes", db_column_int(&q,1)); |
| 1217 | whatis_line(pOut, "received", "%s from %s", |
| 1218 | db_column_text(&q, 2), |
| 1219 | db_column_text(&q, 3)); |
| 1220 | }else{ |
| 1221 | whatis_line(pOut, "artifact","%s", db_column_text(&q,0)); |
| 1222 | whatis_line(pOut, "size", "%d bytes", db_column_int(&q,1)); |
| 1223 | } |
| 1224 | }else if( pOut ){ |
| 1225 | sqlite3_str_appendf(pOut, ",\"artifact\":null"); |
| 1226 | } |
| 1227 | db_finalize(&q); |
| 1228 | if( flags & WHATIS_HASHONLY ) return; |
| 1229 | |
| 1230 | /* Report any symbolic tags on this artifact */ |
| @@ -1198,14 +1237,27 @@ | |
| 1237 | " ORDER BY 1", |
| 1238 | rid |
| 1239 | ); |
| 1240 | cnt = 0; |
| 1241 | while( db_step(&q)==SQLITE_ROW ){ |
| 1242 | const char *zTag = (const char*)db_column_text(&q,0); |
| 1243 | if( pOut ){ |
| 1244 | const char *zSep = cnt==0 ? ",tags:[" : ","; |
| 1245 | sqlite3_str_appendf(pOut, "%s%J", zSep, zTag); |
| 1246 | }else{ |
| 1247 | const char *zPrefix = cnt ? ", " : "tags: "; |
| 1248 | fossil_print("%s%s", zPrefix, db_column_text(&q,0)); |
| 1249 | } |
| 1250 | cnt++; |
| 1251 | } |
| 1252 | if( cnt ){ |
| 1253 | if( pOut ){ |
| 1254 | sqlite3_str_append(pOut, "]", 1); |
| 1255 | }else{ |
| 1256 | fossil_print("\n"); |
| 1257 | } |
| 1258 | } |
| 1259 | db_finalize(&q); |
| 1260 | |
| 1261 | /* Report any HIDDEN, PRIVATE, CLUSTER, or CLOSED tags on this artifact */ |
| 1262 | db_prepare(&q, |
| 1263 | "SELECT tagname" |
| @@ -1215,36 +1267,63 @@ | |
| 1267 | " ORDER BY 1", |
| 1268 | rid |
| 1269 | ); |
| 1270 | cnt = 0; |
| 1271 | while( db_step(&q)==SQLITE_ROW ){ |
| 1272 | const char *zTag = (const char*)db_column_text(&q,0); |
| 1273 | if( pOut ){ |
| 1274 | const char *zSep = cnt==0 ? ",\"raw-tags\":[" : ","; |
| 1275 | sqlite3_str_appendf(pOut, "%s%J", zSep, zTag); |
| 1276 | }else{ |
| 1277 | const char *zPrefix = cnt ? ", " : "raw-tags: "; |
| 1278 | fossil_print("%s%s", zPrefix, db_column_text(&q,0)); |
| 1279 | } |
| 1280 | cnt++; |
| 1281 | } |
| 1282 | if( cnt ){ |
| 1283 | if( pOut ){ |
| 1284 | sqlite3_str_append(pOut, "]", 1); |
| 1285 | }else{ |
| 1286 | fossil_print("\n"); |
| 1287 | } |
| 1288 | } |
| 1289 | db_finalize(&q); |
| 1290 | |
| 1291 | /* Check for entries on the timeline that reference this object */ |
| 1292 | db_prepare(&q, |
| 1293 | "SELECT" |
| 1294 | " type," |
| 1295 | " datetime(mtime,toLocal())," |
| 1296 | " coalesce(euser,user)," |
| 1297 | " coalesce(ecomment,comment)," |
| 1298 | " if(type='t',(SELECT substr(tagname,5) FROM tag" |
| 1299 | " WHERE tag.tagid=event.tagid))" |
| 1300 | "FROM event WHERE objid=%d", |
| 1301 | rid); |
| 1302 | if( db_step(&q)==SQLITE_ROW ){ |
| 1303 | const char *zType; |
| 1304 | char eType = db_column_text(&q,0)[0]; |
| 1305 | switch( eType ){ |
| 1306 | case 'c': zType = "Check-in"; break; |
| 1307 | case 'w': zType = "Wiki-edit"; break; |
| 1308 | case 'e': zType = "Technote"; break; |
| 1309 | case 'f': zType = "Forum-post"; break; |
| 1310 | case 't': zType = "Ticket-change"; break; |
| 1311 | case 'g': zType = "Tag-change"; break; |
| 1312 | default: zType = "Unknown"; break; |
| 1313 | } |
| 1314 | whatis_line(pOut, "type", "%s by %s on %s", zType, db_column_text(&q,2), |
| 1315 | db_column_text(&q, 1)); |
| 1316 | if( eType=='t' && db_column_type(&q,4)==SQLITE_TEXT ){ |
| 1317 | whatis_line(pOut, "ticket-id", "%s", db_column_text(&q,4)); |
| 1318 | } |
| 1319 | if( pOut ){ |
| 1320 | sqlite3_str_appendf(pOut, ",\"comment\":%J", db_column_text(&q,3)); |
| 1321 | }else{ |
| 1322 | fossil_print("comment: "); |
| 1323 | comment_print(db_column_text(&q,3), 0, 12, -1, get_comment_format()); |
| 1324 | } |
| 1325 | cnt++; |
| 1326 | } |
| 1327 | db_finalize(&q); |
| 1328 | |
| 1329 | /* Check to see if this object is used as a file in a check-in */ |
| @@ -1261,20 +1340,25 @@ | |
| 1340 | " ORDER BY event.mtime %s /*sort*/", |
| 1341 | TAG_BRANCH, rid, |
| 1342 | (flags & WHATIS_BRIEF) ? "LIMIT 1" : "DESC"); |
| 1343 | while( db_step(&q)==SQLITE_ROW ){ |
| 1344 | if( flags & WHATIS_BRIEF ){ |
| 1345 | whatis_line(pOut, "mtime","%s", db_column_text(&q,2)); |
| 1346 | } |
| 1347 | if( pOut ){ |
| 1348 | whatis_line(pOut,"file","%s", db_column_text(&q,0)); |
| 1349 | whatis_line(pOut,"part-of","%s", db_column_text(&q,1)); |
| 1350 | }else{ |
| 1351 | fossil_print("file: %s\n", db_column_text(&q,0)); |
| 1352 | fossil_print(" part of [%S] on branch %s by %s on %s\n", |
| 1353 | db_column_text(&q, 1), |
| 1354 | db_column_text(&q, 5), |
| 1355 | db_column_text(&q, 3), |
| 1356 | db_column_text(&q, 2)); |
| 1357 | fossil_print(" "); |
| 1358 | comment_print(db_column_text(&q,4), 0, 12, -1, get_comment_format()); |
| 1359 | } |
| 1360 | cnt++; |
| 1361 | } |
| 1362 | db_finalize(&q); |
| 1363 | |
| 1364 | /* Check to see if this object is used as an attachment */ |
| @@ -1293,30 +1377,36 @@ | |
| 1377 | " FROM attachment JOIN blob ON attachment.src=blob.uuid" |
| 1378 | " WHERE blob.rid=%d", |
| 1379 | rid |
| 1380 | ); |
| 1381 | while( db_step(&q)==SQLITE_ROW ){ |
| 1382 | if( pOut ){ |
| 1383 | whatis_line(pOut, "attachment", "%s", db_column_text(&q,0)); |
| 1384 | whatis_line(pOut, "attached-to", "%s %s", |
| 1385 | db_column_text(&q,5), db_column_text(&q,4)); |
| 1386 | }else{ |
| 1387 | fossil_print("attachment: %s\n", db_column_text(&q,0)); |
| 1388 | fossil_print(" attached to %s %s\n", |
| 1389 | db_column_text(&q,5), db_column_text(&q,4)); |
| 1390 | if( flags & WHATIS_VERBOSE ){ |
| 1391 | fossil_print(" via %s (%d)\n", |
| 1392 | db_column_text(&q,7), db_column_int(&q,6)); |
| 1393 | }else{ |
| 1394 | fossil_print(" via %s\n", |
| 1395 | db_column_text(&q,7)); |
| 1396 | } |
| 1397 | fossil_print(" by user %s on %s\n", |
| 1398 | db_column_text(&q,2), db_column_text(&q,3)); |
| 1399 | fossil_print(" "); |
| 1400 | comment_print(db_column_text(&q,1), 0, 12, -1, get_comment_format()); |
| 1401 | } |
| 1402 | cnt++; |
| 1403 | } |
| 1404 | db_finalize(&q); |
| 1405 | |
| 1406 | /* If other information available, try to describe the object */ |
| 1407 | if( cnt==0 && pOut==0 ){ |
| 1408 | char *zWhere = mprintf("=%d", rid); |
| 1409 | char *zDesc; |
| 1410 | describe_artifacts(zWhere); |
| 1411 | free(zWhere); |
| 1412 | zDesc = db_text(0, |
| @@ -1323,61 +1413,124 @@ | |
| 1413 | "SELECT printf('%%-12s%%s %%s',type||':',summary,substr(ref,1,16))" |
| 1414 | " FROM description WHERE rid=%d", rid); |
| 1415 | fossil_print("%s\n", zDesc); |
| 1416 | fossil_free(zDesc); |
| 1417 | } |
| 1418 | |
| 1419 | if( pOut ) sqlite3_str_append(pOut, "}", 1); |
| 1420 | } |
| 1421 | |
| 1422 | /* |
| 1423 | ** Generate a description of artifact from it symbolic name. |
| 1424 | */ |
| 1425 | void whatis_artifact( |
| 1426 | const char *zName, /* Symbolic name or full hash */ |
| 1427 | const char *zFileName,/* Optional: original filename (in file mode) */ |
| 1428 | const char *zType, /* Artifact type filter */ |
| 1429 | int mFlags, /* WHATIS_* flags */ |
| 1430 | sqlite3_str *pOut /* Write JSON here, if not NULL */ |
| 1431 | ){ |
| 1432 | int rid = symbolic_name_to_rid(zName, zType); |
| 1433 | size_t nName; |
| 1434 | char *zC = 0; |
| 1435 | int nTkt = 0; |
| 1436 | |
| 1437 | if( pOut ){ |
| 1438 | mFlags &= ~(WHATIS_HASHONLY|WHATIS_REPO); |
| 1439 | zFileName = 0; |
| 1440 | } |
| 1441 | if( (nName = strlen(zName))>=4 && validate16(zName,nName) ){ |
| 1442 | zC = fossil_strdup(zName); |
| 1443 | canonical16(zC, nName); |
| 1444 | nTkt = db_int(0,"SELECT count(*) FROM tag WHERE tagname GLOB 'tkt-%q*'",zC); |
| 1445 | if( nTkt>0 ){ |
| 1446 | if( rid==0 ){ |
| 1447 | rid = db_int(0, |
| 1448 | "SELECT srcid FROM tag, tagxref" |
| 1449 | " WHERE tag.tagname GLOB 'tkt-%q*'" |
| 1450 | " AND tagxref.tagid=tag.tagid" |
| 1451 | " AND tagxref.tagtype=1" |
| 1452 | " ORDER BY tagxref.mtime", |
| 1453 | zC |
| 1454 | ); |
| 1455 | }else{ |
| 1456 | rid = -1; |
| 1457 | } |
| 1458 | } |
| 1459 | } |
| 1460 | if( rid<0 ){ |
| 1461 | Stmt q; |
| 1462 | int cnt = 0; |
| 1463 | if( mFlags & WHATIS_REPO ){ |
| 1464 | fossil_print("\nrepository: %s\n", g.zRepositoryName); |
| 1465 | } |
| 1466 | if( zFileName ){ |
| 1467 | fossil_print("%-12s%s\n", "name:", zFileName); |
| 1468 | } |
| 1469 | if( pOut ){ |
| 1470 | sqlite3_str_appendall(pOut, "{\"ambiguous\":["); |
| 1471 | }else{ |
| 1472 | fossil_print("%-12s%s (ambiguous)\n", "hash:", zName); |
| 1473 | } |
| 1474 | db_prepare(&q, |
| 1475 | "SELECT rid FROM blob WHERE uuid>=lower(%Q) AND uuid<(lower(%Q)||'z')", |
| 1476 | zName, zName |
| 1477 | ); |
| 1478 | while( db_step(&q)==SQLITE_ROW ){ |
| 1479 | if( cnt++ ){ |
| 1480 | if( pOut ){ |
| 1481 | sqlite3_str_append(pOut, ",", 1); |
| 1482 | }else{ |
| 1483 | fossil_print("%12s---- meaning #%d ----\n", " ", cnt); |
| 1484 | } |
| 1485 | } |
| 1486 | whatis_rid(db_column_int(&q, 0), mFlags, pOut); |
| 1487 | } |
| 1488 | db_finalize(&q); |
| 1489 | if( nTkt>0 ){ |
| 1490 | db_prepare(&q, |
| 1491 | "SELECT (SELECT srcid FROM tagxref" |
| 1492 | " WHERE tagxref.tagid=tag.tagid" |
| 1493 | " AND tagxref.tagtype=1" |
| 1494 | " ORDER BY mtime LIMIT 1)" |
| 1495 | " FROM tag WHERE tagname GLOB 'tkt-%q*'", |
| 1496 | zC |
| 1497 | ); |
| 1498 | while( db_step(&q)==SQLITE_ROW ){ |
| 1499 | if( pOut ){ |
| 1500 | sqlite3_str_append(pOut, ",", 1); |
| 1501 | }else{ |
| 1502 | fossil_print("%12s---- meaning #%d ----\n", " ", cnt); |
| 1503 | } |
| 1504 | whatis_rid(db_column_int(&q, 0), mFlags, pOut); |
| 1505 | } |
| 1506 | db_finalize(&q); |
| 1507 | } |
| 1508 | if( pOut ) sqlite3_str_append(pOut, "]}", 2); |
| 1509 | }else if( rid==0 ){ |
| 1510 | if( (mFlags & (WHATIS_OMIT_UNK|WHATIS_HASHONLY))==0 ){ |
| 1511 | /* 0123456789 12 */ |
| 1512 | if( zFileName ){ |
| 1513 | fossil_print("%-12s%s\n", "name:", zFileName); |
| 1514 | } |
| 1515 | if( pOut ) sqlite3_str_append(pOut, "{", 1); |
| 1516 | whatis_line(pOut, "unknown", "%s", zName); |
| 1517 | if( pOut ) sqlite3_str_append(pOut, "}", 1); |
| 1518 | } |
| 1519 | }else{ |
| 1520 | if( mFlags & WHATIS_REPO ){ |
| 1521 | fossil_print("\nrepository: %s\n", g.zRepositoryName); |
| 1522 | } |
| 1523 | if( zFileName ){ |
| 1524 | zName = zFileName; |
| 1525 | } |
| 1526 | if( (mFlags & WHATIS_HASHONLY)==0 && pOut==0 ){ |
| 1527 | whatis_line(pOut, "name", "%s", zName); |
| 1528 | } |
| 1529 | whatis_rid(rid, mFlags, pOut); |
| 1530 | } |
| 1531 | fossil_free(zC); |
| 1532 | } |
| 1533 | |
| 1534 | /* |
| 1535 | ** COMMAND: whatis* |
| 1536 | ** |
| @@ -1401,10 +1554,11 @@ | |
| 1554 | void whatis_cmd(void){ |
| 1555 | int mFlags = 0; |
| 1556 | int fileFlag; |
| 1557 | int i; |
| 1558 | const char *zType = 0; |
| 1559 | sqlite3_str *pOut = 0; |
| 1560 | db_find_and_open_repository(0,0); |
| 1561 | if( find_option("verbose","v",0)!=0 ){ |
| 1562 | mFlags |= WHATIS_VERBOSE; |
| 1563 | } |
| 1564 | if( find_option("hash","h",0)!=0 ){ |
| @@ -1413,10 +1567,14 @@ | |
| 1567 | if( g.fQuiet ){ |
| 1568 | mFlags |= WHATIS_OMIT_UNK | WHATIS_REPO; |
| 1569 | } |
| 1570 | fileFlag = find_option("file","f",0)!=0; |
| 1571 | zType = find_option("type",0,1); |
| 1572 | |
| 1573 | if( find_option("json",0,0)!=0 ){ /* undocumented test option */ |
| 1574 | pOut = sqlite3_str_new(0); |
| 1575 | } |
| 1576 | |
| 1577 | /* We should be done with options.. */ |
| 1578 | verify_all_options(); |
| 1579 | |
| 1580 | if( g.argc<3 ) usage("NAME ..."); |
| @@ -1439,17 +1597,52 @@ | |
| 1597 | ** the primary hash name. */ |
| 1598 | blob_reset(&hash); |
| 1599 | hname_hash(&in, 0, &hash); |
| 1600 | zHash = (const char*)blob_str(&hash); |
| 1601 | } |
| 1602 | whatis_artifact(zHash, zName, zType, mFlags, pOut); |
| 1603 | blob_reset(&hash); |
| 1604 | }else{ |
| 1605 | whatis_artifact(zName, 0, zType, mFlags, pOut); |
| 1606 | } |
| 1607 | if( pOut ){ |
| 1608 | fossil_print("%s\n", sqlite3_str_value(pOut)); |
| 1609 | sqlite3_str_truncate(pOut, 0); |
| 1610 | } |
| 1611 | } |
| 1612 | if( pOut ) sqlite3_str_free(pOut); |
| 1613 | } |
| 1614 | |
| 1615 | /* |
| 1616 | ** This is an SQL function that does the rough equivalent of the |
| 1617 | ** "whatis" command. The argument can be a text identifier, or a |
| 1618 | ** integer RID. |
| 1619 | */ |
| 1620 | void whatis_sql_function( |
| 1621 | sqlite3_context *context, |
| 1622 | int argc, |
| 1623 | sqlite3_value **argv |
| 1624 | ){ |
| 1625 | sqlite3_str *pOut = sqlite3_str_new(0); |
| 1626 | int n; |
| 1627 | assert( argc==1 ); |
| 1628 | if( sqlite3_value_type(argv[0])==SQLITE_INTEGER ){ |
| 1629 | int rid = sqlite3_value_int(argv[0]); |
| 1630 | whatis_rid(rid, 0, pOut); |
| 1631 | }else if( sqlite3_value_type(argv[0])==SQLITE_TEXT ){ |
| 1632 | const char *zName = (const char*)sqlite3_value_text(argv[0]); |
| 1633 | whatis_artifact(zName, 0, 0, 0, pOut); |
| 1634 | }else{ |
| 1635 | sqlite3_str_free(pOut); |
| 1636 | return; |
| 1637 | } |
| 1638 | n = sqlite3_str_length(pOut); |
| 1639 | sqlite3_result_text64(context, sqlite3_str_finish(pOut), n, |
| 1640 | sqlite3_free, SQLITE_UTF8); |
| 1641 | sqlite3_result_subtype(context, 'J'); |
| 1642 | } |
| 1643 | |
| 1644 | |
| 1645 | /* |
| 1646 | ** COMMAND: test-whatis-all |
| 1647 | ** |
| 1648 | ** Usage: %fossil test-whatis-all |
| @@ -1461,11 +1654,11 @@ | |
| 1654 | int cnt = 0; |
| 1655 | db_find_and_open_repository(0,0); |
| 1656 | db_prepare(&q, "SELECT rid FROM blob ORDER BY rid"); |
| 1657 | while( db_step(&q)==SQLITE_ROW ){ |
| 1658 | if( cnt++ ) fossil_print("%.79c\n", '-'); |
| 1659 | whatis_rid(db_column_int(&q,0), 1, 0); |
| 1660 | } |
| 1661 | db_finalize(&q); |
| 1662 | } |
| 1663 | |
| 1664 | |
| 1665 |
+2
-2
| --- src/schema.c | ||
| +++ src/schema.c | ||
| @@ -277,11 +277,11 @@ | ||
| 277 | 277 | @ CREATE INDEX mlink_i1 ON mlink(mid); |
| 278 | 278 | @ CREATE INDEX mlink_i2 ON mlink(fnid); |
| 279 | 279 | @ CREATE INDEX mlink_i3 ON mlink(fid); |
| 280 | 280 | @ CREATE INDEX mlink_i4 ON mlink(pid); |
| 281 | 281 | @ |
| 282 | -@ -- Parent/child linkages between check-ins | |
| 282 | +@ -- Parent/child linkages between artifacts with P-cards. | |
| 283 | 283 | @ -- |
| 284 | 284 | @ CREATE TABLE plink( |
| 285 | 285 | @ pid INTEGER REFERENCES blob, -- Parent manifest |
| 286 | 286 | @ cid INTEGER REFERENCES blob, -- Child manifest |
| 287 | 287 | @ isprim BOOLEAN, -- pid is the primary parent of cid |
| @@ -427,11 +427,11 @@ | ||
| 427 | 427 | @ CREATE TABLE attachment( |
| 428 | 428 | @ attachid INTEGER PRIMARY KEY, -- Local id for this attachment |
| 429 | 429 | @ isLatest BOOLEAN DEFAULT 0, -- True if this is the one to use |
| 430 | 430 | @ mtime TIMESTAMP, -- Last changed. Julian day. |
| 431 | 431 | @ src TEXT, -- Hash of the attachment. NULL to delete |
| 432 | -@ target TEXT, -- Object attached to. Wikiname or Tkt hash | |
| 432 | +@ target TEXT, -- Object attached to. Wikiname or Tkt/Event/Forum post ID | |
| 433 | 433 | @ filename TEXT, -- Filename for the attachment |
| 434 | 434 | @ comment TEXT, -- Comment associated with this attachment |
| 435 | 435 | @ user TEXT -- Name of user adding attachment |
| 436 | 436 | @ ); |
| 437 | 437 | @ CREATE INDEX attachment_idx1 ON attachment(target, filename, mtime); |
| 438 | 438 |
| --- src/schema.c | |
| +++ src/schema.c | |
| @@ -277,11 +277,11 @@ | |
| 277 | @ CREATE INDEX mlink_i1 ON mlink(mid); |
| 278 | @ CREATE INDEX mlink_i2 ON mlink(fnid); |
| 279 | @ CREATE INDEX mlink_i3 ON mlink(fid); |
| 280 | @ CREATE INDEX mlink_i4 ON mlink(pid); |
| 281 | @ |
| 282 | @ -- Parent/child linkages between check-ins |
| 283 | @ -- |
| 284 | @ CREATE TABLE plink( |
| 285 | @ pid INTEGER REFERENCES blob, -- Parent manifest |
| 286 | @ cid INTEGER REFERENCES blob, -- Child manifest |
| 287 | @ isprim BOOLEAN, -- pid is the primary parent of cid |
| @@ -427,11 +427,11 @@ | |
| 427 | @ CREATE TABLE attachment( |
| 428 | @ attachid INTEGER PRIMARY KEY, -- Local id for this attachment |
| 429 | @ isLatest BOOLEAN DEFAULT 0, -- True if this is the one to use |
| 430 | @ mtime TIMESTAMP, -- Last changed. Julian day. |
| 431 | @ src TEXT, -- Hash of the attachment. NULL to delete |
| 432 | @ target TEXT, -- Object attached to. Wikiname or Tkt hash |
| 433 | @ filename TEXT, -- Filename for the attachment |
| 434 | @ comment TEXT, -- Comment associated with this attachment |
| 435 | @ user TEXT -- Name of user adding attachment |
| 436 | @ ); |
| 437 | @ CREATE INDEX attachment_idx1 ON attachment(target, filename, mtime); |
| 438 |
| --- src/schema.c | |
| +++ src/schema.c | |
| @@ -277,11 +277,11 @@ | |
| 277 | @ CREATE INDEX mlink_i1 ON mlink(mid); |
| 278 | @ CREATE INDEX mlink_i2 ON mlink(fnid); |
| 279 | @ CREATE INDEX mlink_i3 ON mlink(fid); |
| 280 | @ CREATE INDEX mlink_i4 ON mlink(pid); |
| 281 | @ |
| 282 | @ -- Parent/child linkages between artifacts with P-cards. |
| 283 | @ -- |
| 284 | @ CREATE TABLE plink( |
| 285 | @ pid INTEGER REFERENCES blob, -- Parent manifest |
| 286 | @ cid INTEGER REFERENCES blob, -- Child manifest |
| 287 | @ isprim BOOLEAN, -- pid is the primary parent of cid |
| @@ -427,11 +427,11 @@ | |
| 427 | @ CREATE TABLE attachment( |
| 428 | @ attachid INTEGER PRIMARY KEY, -- Local id for this attachment |
| 429 | @ isLatest BOOLEAN DEFAULT 0, -- True if this is the one to use |
| 430 | @ mtime TIMESTAMP, -- Last changed. Julian day. |
| 431 | @ src TEXT, -- Hash of the attachment. NULL to delete |
| 432 | @ target TEXT, -- Object attached to. Wikiname or Tkt/Event/Forum post ID |
| 433 | @ filename TEXT, -- Filename for the attachment |
| 434 | @ comment TEXT, -- Comment associated with this attachment |
| 435 | @ user TEXT -- Name of user adding attachment |
| 436 | @ ); |
| 437 | @ CREATE INDEX attachment_idx1 ON attachment(target, filename, mtime); |
| 438 |
+1
-1
| --- src/setup.c | ||
| +++ src/setup.c | ||
| @@ -2245,11 +2245,11 @@ | ||
| 2245 | 2245 | create_admin_log_table(); |
| 2246 | 2246 | limit = atoi(PD("n","200")); |
| 2247 | 2247 | ofst = atoi(PD("x","0")); |
| 2248 | 2248 | fLogEnabled = db_get_boolean("admin-log", 1); |
| 2249 | 2249 | @ <div>Admin logging is %s(fLogEnabled?"on":"off"). |
| 2250 | - @ (Change this on the <a href="setup_settings">settings</a> page.)</div> | |
| 2250 | + @ (Change this on the <a href="setup_settings?all">settings</a> page.)</div> | |
| 2251 | 2251 | |
| 2252 | 2252 | if( ofst>0 ){ |
| 2253 | 2253 | int prevx = ofst - limit; |
| 2254 | 2254 | if( prevx<0 ) prevx = 0; |
| 2255 | 2255 | @ <p><a href="admin_log?n=%d(limit)&x=%d(prevx)">[Newer]</a></p> |
| 2256 | 2256 |
| --- src/setup.c | |
| +++ src/setup.c | |
| @@ -2245,11 +2245,11 @@ | |
| 2245 | create_admin_log_table(); |
| 2246 | limit = atoi(PD("n","200")); |
| 2247 | ofst = atoi(PD("x","0")); |
| 2248 | fLogEnabled = db_get_boolean("admin-log", 1); |
| 2249 | @ <div>Admin logging is %s(fLogEnabled?"on":"off"). |
| 2250 | @ (Change this on the <a href="setup_settings">settings</a> page.)</div> |
| 2251 | |
| 2252 | if( ofst>0 ){ |
| 2253 | int prevx = ofst - limit; |
| 2254 | if( prevx<0 ) prevx = 0; |
| 2255 | @ <p><a href="admin_log?n=%d(limit)&x=%d(prevx)">[Newer]</a></p> |
| 2256 |
| --- src/setup.c | |
| +++ src/setup.c | |
| @@ -2245,11 +2245,11 @@ | |
| 2245 | create_admin_log_table(); |
| 2246 | limit = atoi(PD("n","200")); |
| 2247 | ofst = atoi(PD("x","0")); |
| 2248 | fLogEnabled = db_get_boolean("admin-log", 1); |
| 2249 | @ <div>Admin logging is %s(fLogEnabled?"on":"off"). |
| 2250 | @ (Change this on the <a href="setup_settings?all">settings</a> page.)</div> |
| 2251 | |
| 2252 | if( ofst>0 ){ |
| 2253 | int prevx = ofst - limit; |
| 2254 | if( prevx<0 ) prevx = 0; |
| 2255 | @ <p><a href="admin_log?n=%d(limit)&x=%d(prevx)">[Newer]</a></p> |
| 2256 |
+4
| --- src/setupuser.c | ||
| +++ src/setupuser.c | ||
| @@ -821,10 +821,12 @@ | ||
| 821 | 821 | @ Check-Out%s(B('o'))</label> |
| 822 | 822 | @ <li><label><input type="checkbox" name="ah"%s(oa['h'])> |
| 823 | 823 | @ Hyperlinks%s(B('h'))</label> |
| 824 | 824 | @ <li><label><input type="checkbox" name="ab"%s(oa['b'])> |
| 825 | 825 | @ Attachments%s(B('b'))</label> |
| 826 | + @ <li><label><input type="checkbox" name="aB"%s(oa['B'])> | |
| 827 | + @ Forum Attachments%s(B('B'))</label> | |
| 826 | 828 | @ <li><label><input type="checkbox" name="ag"%s(oa['g'])> |
| 827 | 829 | @ Clone%s(B('g'))</label> |
| 828 | 830 | @ <li><label><input type="checkbox" name="aj"%s(oa['j'])> |
| 829 | 831 | @ Read Wiki%s(B('j'))</label> |
| 830 | 832 | @ <li><label><input type="checkbox" name="af"%s(oa['f'])> |
| @@ -857,10 +859,12 @@ | ||
| 857 | 859 | @ Read Forum%s(B('2'))</label> |
| 858 | 860 | @ <li><label><input type="checkbox" name="a3"%s(oa['3'])> |
| 859 | 861 | @ Write Forum%s(B('3'))</label> |
| 860 | 862 | @ <li><label><input type="checkbox" name="a4"%s(oa['4'])> |
| 861 | 863 | @ WriteTrusted Forum%s(B('4'))</label> |
| 864 | + @ <li><label><input type="checkbox" name="aB"%s(oa['B'])> | |
| 865 | + @ Attach to Forum%s(B('B'))</label> | |
| 862 | 866 | @ <li><label><input type="checkbox" name="a5"%s(oa['5'])> |
| 863 | 867 | @ Moderate Forum%s(B('5'))</label> |
| 864 | 868 | @ <li><label><input type="checkbox" name="a6"%s(oa['6'])> |
| 865 | 869 | @ Supervise Forum%s(B('6'))</label> |
| 866 | 870 | @ <li><label><input type="checkbox" name="a7"%s(oa['7'])> |
| 867 | 871 |
| --- src/setupuser.c | |
| +++ src/setupuser.c | |
| @@ -821,10 +821,12 @@ | |
| 821 | @ Check-Out%s(B('o'))</label> |
| 822 | @ <li><label><input type="checkbox" name="ah"%s(oa['h'])> |
| 823 | @ Hyperlinks%s(B('h'))</label> |
| 824 | @ <li><label><input type="checkbox" name="ab"%s(oa['b'])> |
| 825 | @ Attachments%s(B('b'))</label> |
| 826 | @ <li><label><input type="checkbox" name="ag"%s(oa['g'])> |
| 827 | @ Clone%s(B('g'))</label> |
| 828 | @ <li><label><input type="checkbox" name="aj"%s(oa['j'])> |
| 829 | @ Read Wiki%s(B('j'))</label> |
| 830 | @ <li><label><input type="checkbox" name="af"%s(oa['f'])> |
| @@ -857,10 +859,12 @@ | |
| 857 | @ Read Forum%s(B('2'))</label> |
| 858 | @ <li><label><input type="checkbox" name="a3"%s(oa['3'])> |
| 859 | @ Write Forum%s(B('3'))</label> |
| 860 | @ <li><label><input type="checkbox" name="a4"%s(oa['4'])> |
| 861 | @ WriteTrusted Forum%s(B('4'))</label> |
| 862 | @ <li><label><input type="checkbox" name="a5"%s(oa['5'])> |
| 863 | @ Moderate Forum%s(B('5'))</label> |
| 864 | @ <li><label><input type="checkbox" name="a6"%s(oa['6'])> |
| 865 | @ Supervise Forum%s(B('6'))</label> |
| 866 | @ <li><label><input type="checkbox" name="a7"%s(oa['7'])> |
| 867 |
| --- src/setupuser.c | |
| +++ src/setupuser.c | |
| @@ -821,10 +821,12 @@ | |
| 821 | @ Check-Out%s(B('o'))</label> |
| 822 | @ <li><label><input type="checkbox" name="ah"%s(oa['h'])> |
| 823 | @ Hyperlinks%s(B('h'))</label> |
| 824 | @ <li><label><input type="checkbox" name="ab"%s(oa['b'])> |
| 825 | @ Attachments%s(B('b'))</label> |
| 826 | @ <li><label><input type="checkbox" name="aB"%s(oa['B'])> |
| 827 | @ Forum Attachments%s(B('B'))</label> |
| 828 | @ <li><label><input type="checkbox" name="ag"%s(oa['g'])> |
| 829 | @ Clone%s(B('g'))</label> |
| 830 | @ <li><label><input type="checkbox" name="aj"%s(oa['j'])> |
| 831 | @ Read Wiki%s(B('j'))</label> |
| 832 | @ <li><label><input type="checkbox" name="af"%s(oa['f'])> |
| @@ -857,10 +859,12 @@ | |
| 859 | @ Read Forum%s(B('2'))</label> |
| 860 | @ <li><label><input type="checkbox" name="a3"%s(oa['3'])> |
| 861 | @ Write Forum%s(B('3'))</label> |
| 862 | @ <li><label><input type="checkbox" name="a4"%s(oa['4'])> |
| 863 | @ WriteTrusted Forum%s(B('4'))</label> |
| 864 | @ <li><label><input type="checkbox" name="aB"%s(oa['B'])> |
| 865 | @ Attach to Forum%s(B('B'))</label> |
| 866 | @ <li><label><input type="checkbox" name="a5"%s(oa['5'])> |
| 867 | @ Moderate Forum%s(B('5'))</label> |
| 868 | @ <li><label><input type="checkbox" name="a6"%s(oa['6'])> |
| 869 | @ Supervise Forum%s(B('6'))</label> |
| 870 | @ <li><label><input type="checkbox" name="a7"%s(oa['7'])> |
| 871 |
+4
| --- src/sqlcmd.c | ||
| +++ src/sqlcmd.c | ||
| @@ -142,10 +142,12 @@ | ||
| 142 | 142 | } |
| 143 | 143 | |
| 144 | 144 | /* |
| 145 | 145 | ** Add the content(), compress(), decompress(), and |
| 146 | 146 | ** gather_artifact_stats() SQL functions to database connection db. |
| 147 | +** | |
| 148 | +** Also add whatis(). | |
| 147 | 149 | */ |
| 148 | 150 | int add_content_sql_commands(sqlite3 *db){ |
| 149 | 151 | sqlite3_create_function(db, "content", 1, SQLITE_UTF8, 0, |
| 150 | 152 | sqlcmd_content, 0, 0); |
| 151 | 153 | sqlite3_create_function(db, "compress", 1, SQLITE_UTF8, 0, |
| @@ -152,10 +154,12 @@ | ||
| 152 | 154 | sqlcmd_compress, 0, 0); |
| 153 | 155 | sqlite3_create_function(db, "decompress", 1, SQLITE_UTF8, 0, |
| 154 | 156 | sqlcmd_decompress, 0, 0); |
| 155 | 157 | sqlite3_create_function(db, "gather_artifact_stats", 0, SQLITE_UTF8, 0, |
| 156 | 158 | sqlcmd_gather_artifact_stats, 0, 0); |
| 159 | + sqlite3_create_function(db, "whatis", 1, SQLITE_UTF8|SQLITE_RESULT_SUBTYPE, 0, | |
| 160 | + whatis_sql_function, 0, 0); | |
| 157 | 161 | return SQLITE_OK; |
| 158 | 162 | } |
| 159 | 163 | |
| 160 | 164 | /* |
| 161 | 165 | ** Undocumented test SQL functions: |
| 162 | 166 |
| --- src/sqlcmd.c | |
| +++ src/sqlcmd.c | |
| @@ -142,10 +142,12 @@ | |
| 142 | } |
| 143 | |
| 144 | /* |
| 145 | ** Add the content(), compress(), decompress(), and |
| 146 | ** gather_artifact_stats() SQL functions to database connection db. |
| 147 | */ |
| 148 | int add_content_sql_commands(sqlite3 *db){ |
| 149 | sqlite3_create_function(db, "content", 1, SQLITE_UTF8, 0, |
| 150 | sqlcmd_content, 0, 0); |
| 151 | sqlite3_create_function(db, "compress", 1, SQLITE_UTF8, 0, |
| @@ -152,10 +154,12 @@ | |
| 152 | sqlcmd_compress, 0, 0); |
| 153 | sqlite3_create_function(db, "decompress", 1, SQLITE_UTF8, 0, |
| 154 | sqlcmd_decompress, 0, 0); |
| 155 | sqlite3_create_function(db, "gather_artifact_stats", 0, SQLITE_UTF8, 0, |
| 156 | sqlcmd_gather_artifact_stats, 0, 0); |
| 157 | return SQLITE_OK; |
| 158 | } |
| 159 | |
| 160 | /* |
| 161 | ** Undocumented test SQL functions: |
| 162 |
| --- src/sqlcmd.c | |
| +++ src/sqlcmd.c | |
| @@ -142,10 +142,12 @@ | |
| 142 | } |
| 143 | |
| 144 | /* |
| 145 | ** Add the content(), compress(), decompress(), and |
| 146 | ** gather_artifact_stats() SQL functions to database connection db. |
| 147 | ** |
| 148 | ** Also add whatis(). |
| 149 | */ |
| 150 | int add_content_sql_commands(sqlite3 *db){ |
| 151 | sqlite3_create_function(db, "content", 1, SQLITE_UTF8, 0, |
| 152 | sqlcmd_content, 0, 0); |
| 153 | sqlite3_create_function(db, "compress", 1, SQLITE_UTF8, 0, |
| @@ -152,10 +154,12 @@ | |
| 154 | sqlcmd_compress, 0, 0); |
| 155 | sqlite3_create_function(db, "decompress", 1, SQLITE_UTF8, 0, |
| 156 | sqlcmd_decompress, 0, 0); |
| 157 | sqlite3_create_function(db, "gather_artifact_stats", 0, SQLITE_UTF8, 0, |
| 158 | sqlcmd_gather_artifact_stats, 0, 0); |
| 159 | sqlite3_create_function(db, "whatis", 1, SQLITE_UTF8|SQLITE_RESULT_SUBTYPE, 0, |
| 160 | whatis_sql_function, 0, 0); |
| 161 | return SQLITE_OK; |
| 162 | } |
| 163 | |
| 164 | /* |
| 165 | ** Undocumented test SQL functions: |
| 166 |
+13
-3
| --- src/stash.c | ||
| +++ src/stash.c | ||
| @@ -447,24 +447,34 @@ | ||
| 447 | 447 | } |
| 448 | 448 | }else{ |
| 449 | 449 | Blob delta; |
| 450 | 450 | int isOrigLink = file_islink(zOPath); |
| 451 | 451 | db_ephemeral_blob(&q, 6, &delta); |
| 452 | - if( !bWebpage ) fossil_print("CHANGED %s\n", zNew); | |
| 453 | 452 | if( !isOrigLink != !isLink ){ |
| 453 | + if( !bWebpage ) fossil_print("CHANGED %s\n", zNew); | |
| 454 | 454 | diff_print_index(zNew, pCfg, 0); |
| 455 | 455 | diff_print_filenames(zOrig, zNew, pCfg, 0); |
| 456 | 456 | printf(DIFF_CANNOT_COMPUTE_SYMLINK); |
| 457 | 457 | }else{ |
| 458 | + int isChanged = 0; | |
| 458 | 459 | content_get(rid, &a); |
| 459 | 460 | blob_delta_apply(&a, &delta, &b); |
| 460 | 461 | if( fBaseline ){ |
| 461 | - diff_file_mem(&a, &b, zNew, pCfg); | |
| 462 | - }else{ | |
| 462 | + if( blob_compare(&a, &b) ){ | |
| 463 | + isChanged = 1; | |
| 464 | + if( !bWebpage ) fossil_print("CHANGED %s\n", zNew); | |
| 465 | + diff_file_mem(&a, &b, zNew, pCfg); | |
| 466 | + } | |
| 467 | + }else if( !file_same_as_blob(&b, zOPath) ){ | |
| 468 | + isChanged = 1; | |
| 469 | + if( !bWebpage ) fossil_print("CHANGED %s\n", zNew); | |
| 463 | 470 | pCfg->diffFlags ^= DIFF_INVERT; |
| 464 | 471 | diff_file(&b, zOPath, zNew, pCfg, 0); |
| 465 | 472 | pCfg->diffFlags ^= DIFF_INVERT; |
| 473 | + } | |
| 474 | + if( !bWebpage && !isChanged && pCfg->diffFlags & DIFF_VERBOSE ){ | |
| 475 | + fossil_print("UNCHANGED %s\n", zNew); | |
| 466 | 476 | } |
| 467 | 477 | blob_reset(&a); |
| 468 | 478 | blob_reset(&b); |
| 469 | 479 | } |
| 470 | 480 | blob_reset(&delta); |
| 471 | 481 |
| --- src/stash.c | |
| +++ src/stash.c | |
| @@ -447,24 +447,34 @@ | |
| 447 | } |
| 448 | }else{ |
| 449 | Blob delta; |
| 450 | int isOrigLink = file_islink(zOPath); |
| 451 | db_ephemeral_blob(&q, 6, &delta); |
| 452 | if( !bWebpage ) fossil_print("CHANGED %s\n", zNew); |
| 453 | if( !isOrigLink != !isLink ){ |
| 454 | diff_print_index(zNew, pCfg, 0); |
| 455 | diff_print_filenames(zOrig, zNew, pCfg, 0); |
| 456 | printf(DIFF_CANNOT_COMPUTE_SYMLINK); |
| 457 | }else{ |
| 458 | content_get(rid, &a); |
| 459 | blob_delta_apply(&a, &delta, &b); |
| 460 | if( fBaseline ){ |
| 461 | diff_file_mem(&a, &b, zNew, pCfg); |
| 462 | }else{ |
| 463 | pCfg->diffFlags ^= DIFF_INVERT; |
| 464 | diff_file(&b, zOPath, zNew, pCfg, 0); |
| 465 | pCfg->diffFlags ^= DIFF_INVERT; |
| 466 | } |
| 467 | blob_reset(&a); |
| 468 | blob_reset(&b); |
| 469 | } |
| 470 | blob_reset(&delta); |
| 471 |
| --- src/stash.c | |
| +++ src/stash.c | |
| @@ -447,24 +447,34 @@ | |
| 447 | } |
| 448 | }else{ |
| 449 | Blob delta; |
| 450 | int isOrigLink = file_islink(zOPath); |
| 451 | db_ephemeral_blob(&q, 6, &delta); |
| 452 | if( !isOrigLink != !isLink ){ |
| 453 | if( !bWebpage ) fossil_print("CHANGED %s\n", zNew); |
| 454 | diff_print_index(zNew, pCfg, 0); |
| 455 | diff_print_filenames(zOrig, zNew, pCfg, 0); |
| 456 | printf(DIFF_CANNOT_COMPUTE_SYMLINK); |
| 457 | }else{ |
| 458 | int isChanged = 0; |
| 459 | content_get(rid, &a); |
| 460 | blob_delta_apply(&a, &delta, &b); |
| 461 | if( fBaseline ){ |
| 462 | if( blob_compare(&a, &b) ){ |
| 463 | isChanged = 1; |
| 464 | if( !bWebpage ) fossil_print("CHANGED %s\n", zNew); |
| 465 | diff_file_mem(&a, &b, zNew, pCfg); |
| 466 | } |
| 467 | }else if( !file_same_as_blob(&b, zOPath) ){ |
| 468 | isChanged = 1; |
| 469 | if( !bWebpage ) fossil_print("CHANGED %s\n", zNew); |
| 470 | pCfg->diffFlags ^= DIFF_INVERT; |
| 471 | diff_file(&b, zOPath, zNew, pCfg, 0); |
| 472 | pCfg->diffFlags ^= DIFF_INVERT; |
| 473 | } |
| 474 | if( !bWebpage && !isChanged && pCfg->diffFlags & DIFF_VERBOSE ){ |
| 475 | fossil_print("UNCHANGED %s\n", zNew); |
| 476 | } |
| 477 | blob_reset(&a); |
| 478 | blob_reset(&b); |
| 479 | } |
| 480 | blob_reset(&delta); |
| 481 |
+34
| --- src/stat.c | ||
| +++ src/stat.c | ||
| @@ -872,21 +872,55 @@ | ||
| 872 | 872 | ** Show relative sizes of tables in the repository database. |
| 873 | 873 | */ |
| 874 | 874 | void repo_tabsize_page(void){ |
| 875 | 875 | int nPageFree; |
| 876 | 876 | sqlite3_int64 fsize; |
| 877 | + int bDetail = 0; | |
| 877 | 878 | char zBuf[100]; |
| 878 | 879 | |
| 879 | 880 | login_check_credentials(); |
| 880 | 881 | if( !g.perm.Read ){ login_needed(g.anon.Read); return; } |
| 881 | 882 | cgi_check_for_malice(); |
| 883 | +#if defined(SQLITE_VERSION_NUMBER) && SQLITE_VERSION_NUMBER>=3054000 | |
| 884 | + if( g.perm.Admin && (bDetail = atoi(PD("detail","0")))!=0 ){ | |
| 885 | + extern int sqlite3_diskused_init( | |
| 886 | + sqlite3*, | |
| 887 | + char**, | |
| 888 | + const sqlite3_api_routines* | |
| 889 | + ); | |
| 890 | + sqlite3_diskused_init(g.db,0,0); | |
| 891 | + } | |
| 892 | +#endif | |
| 882 | 893 | style_set_current_feature("stat"); |
| 883 | 894 | style_header("Repository Table Sizes"); |
| 884 | 895 | style_adunit_config(ADUNIT_RIGHT_OK); |
| 885 | 896 | style_submenu_element("Stat", "stat"); |
| 897 | + if( bDetail ){ | |
| 898 | + const char *zFName; | |
| 899 | + Stmt q; | |
| 900 | + zFName = sqlite3_db_filename(g.db, "repository"); | |
| 901 | + @ <h1>%h(zFName)</h1> | |
| 902 | + db_prepare(&q, "SELECT diskused('repository')"); | |
| 903 | + if( db_step(&q)==SQLITE_ROW ){ | |
| 904 | + @ <pre>%h(db_column_text(&q,0))</pre> | |
| 905 | + } | |
| 906 | + db_finalize(&q); | |
| 907 | + if( g.localOpen ){ | |
| 908 | + zFName = sqlite3_db_filename(g.db, "localdb"); | |
| 909 | + @ <h1>%h(zFName)</h1> | |
| 910 | + db_prepare(&q, "SELECT diskused('localdb')"); | |
| 911 | + if( db_step(&q)==SQLITE_ROW ){ | |
| 912 | + @ <pre>%h(db_column_text(&q,0))</pre> | |
| 913 | + } | |
| 914 | + db_finalize(&q); | |
| 915 | + } | |
| 916 | + style_finish_page(); | |
| 917 | + return; | |
| 918 | + } | |
| 886 | 919 | if( g.perm.Admin ){ |
| 887 | 920 | style_submenu_element("Schema", "repo_schema"); |
| 921 | + style_submenu_element("Details", "repo-tabsize?detail=1"); | |
| 888 | 922 | } |
| 889 | 923 | db_multi_exec( |
| 890 | 924 | "CREATE TEMP TABLE trans(name TEXT PRIMARY KEY,tabname TEXT)WITHOUT ROWID;" |
| 891 | 925 | "INSERT INTO trans(name,tabname)" |
| 892 | 926 | " SELECT name, tbl_name FROM repository.sqlite_schema;" |
| 893 | 927 |
| --- src/stat.c | |
| +++ src/stat.c | |
| @@ -872,21 +872,55 @@ | |
| 872 | ** Show relative sizes of tables in the repository database. |
| 873 | */ |
| 874 | void repo_tabsize_page(void){ |
| 875 | int nPageFree; |
| 876 | sqlite3_int64 fsize; |
| 877 | char zBuf[100]; |
| 878 | |
| 879 | login_check_credentials(); |
| 880 | if( !g.perm.Read ){ login_needed(g.anon.Read); return; } |
| 881 | cgi_check_for_malice(); |
| 882 | style_set_current_feature("stat"); |
| 883 | style_header("Repository Table Sizes"); |
| 884 | style_adunit_config(ADUNIT_RIGHT_OK); |
| 885 | style_submenu_element("Stat", "stat"); |
| 886 | if( g.perm.Admin ){ |
| 887 | style_submenu_element("Schema", "repo_schema"); |
| 888 | } |
| 889 | db_multi_exec( |
| 890 | "CREATE TEMP TABLE trans(name TEXT PRIMARY KEY,tabname TEXT)WITHOUT ROWID;" |
| 891 | "INSERT INTO trans(name,tabname)" |
| 892 | " SELECT name, tbl_name FROM repository.sqlite_schema;" |
| 893 |
| --- src/stat.c | |
| +++ src/stat.c | |
| @@ -872,21 +872,55 @@ | |
| 872 | ** Show relative sizes of tables in the repository database. |
| 873 | */ |
| 874 | void repo_tabsize_page(void){ |
| 875 | int nPageFree; |
| 876 | sqlite3_int64 fsize; |
| 877 | int bDetail = 0; |
| 878 | char zBuf[100]; |
| 879 | |
| 880 | login_check_credentials(); |
| 881 | if( !g.perm.Read ){ login_needed(g.anon.Read); return; } |
| 882 | cgi_check_for_malice(); |
| 883 | #if defined(SQLITE_VERSION_NUMBER) && SQLITE_VERSION_NUMBER>=3054000 |
| 884 | if( g.perm.Admin && (bDetail = atoi(PD("detail","0")))!=0 ){ |
| 885 | extern int sqlite3_diskused_init( |
| 886 | sqlite3*, |
| 887 | char**, |
| 888 | const sqlite3_api_routines* |
| 889 | ); |
| 890 | sqlite3_diskused_init(g.db,0,0); |
| 891 | } |
| 892 | #endif |
| 893 | style_set_current_feature("stat"); |
| 894 | style_header("Repository Table Sizes"); |
| 895 | style_adunit_config(ADUNIT_RIGHT_OK); |
| 896 | style_submenu_element("Stat", "stat"); |
| 897 | if( bDetail ){ |
| 898 | const char *zFName; |
| 899 | Stmt q; |
| 900 | zFName = sqlite3_db_filename(g.db, "repository"); |
| 901 | @ <h1>%h(zFName)</h1> |
| 902 | db_prepare(&q, "SELECT diskused('repository')"); |
| 903 | if( db_step(&q)==SQLITE_ROW ){ |
| 904 | @ <pre>%h(db_column_text(&q,0))</pre> |
| 905 | } |
| 906 | db_finalize(&q); |
| 907 | if( g.localOpen ){ |
| 908 | zFName = sqlite3_db_filename(g.db, "localdb"); |
| 909 | @ <h1>%h(zFName)</h1> |
| 910 | db_prepare(&q, "SELECT diskused('localdb')"); |
| 911 | if( db_step(&q)==SQLITE_ROW ){ |
| 912 | @ <pre>%h(db_column_text(&q,0))</pre> |
| 913 | } |
| 914 | db_finalize(&q); |
| 915 | } |
| 916 | style_finish_page(); |
| 917 | return; |
| 918 | } |
| 919 | if( g.perm.Admin ){ |
| 920 | style_submenu_element("Schema", "repo_schema"); |
| 921 | style_submenu_element("Details", "repo-tabsize?detail=1"); |
| 922 | } |
| 923 | db_multi_exec( |
| 924 | "CREATE TEMP TABLE trans(name TEXT PRIMARY KEY,tabname TEXT)WITHOUT ROWID;" |
| 925 | "INSERT INTO trans(name,tabname)" |
| 926 | " SELECT name, tbl_name FROM repository.sqlite_schema;" |
| 927 |
+17
-2
| --- src/statrep.c | ||
| +++ src/statrep.c | ||
| @@ -76,10 +76,15 @@ | ||
| 76 | 76 | case 'f': |
| 77 | 77 | case 'F': |
| 78 | 78 | zRealType = "f"; |
| 79 | 79 | rc = *zRealType; |
| 80 | 80 | break; |
| 81 | + case 'h': | |
| 82 | + case 'H': | |
| 83 | + zRealType = "h"; | |
| 84 | + rc = *zRealType; | |
| 85 | + break; | |
| 81 | 86 | case 'g': |
| 82 | 87 | case 'G': |
| 83 | 88 | zRealType = "g"; |
| 84 | 89 | rc = *zRealType; |
| 85 | 90 | break; |
| @@ -117,10 +122,16 @@ | ||
| 117 | 122 | } |
| 118 | 123 | if( zRealType==0 ){ |
| 119 | 124 | statsReportTimelineYFlag = "a"; |
| 120 | 125 | db_multi_exec("CREATE TEMP VIEW v_reports AS " |
| 121 | 126 | "SELECT * FROM event WHERE %s", zTimeSpan/*safe-for-%s*/); |
| 127 | + }else if( rc=='h' ){ | |
| 128 | + statsReportTimelineYFlag = zRealType; | |
| 129 | + db_multi_exec("CREATE TEMP VIEW v_reports AS " | |
| 130 | + "SELECT * FROM event WHERE (type='f') " | |
| 131 | + " AND (comment GLOB 'Post:*') AND %s", | |
| 132 | + zTimeSpan/*safe-for-%s*/); | |
| 122 | 133 | }else if( rc!='n' && rc!='m' ){ |
| 123 | 134 | statsReportTimelineYFlag = zRealType; |
| 124 | 135 | db_multi_exec("CREATE TEMP VIEW v_reports AS " |
| 125 | 136 | "SELECT * FROM event WHERE (type GLOB %Q) AND %s", |
| 126 | 137 | zRealType, zTimeSpan/*safe-for-%s*/); |
| @@ -154,10 +165,12 @@ | ||
| 154 | 165 | return "non-merge check-ins"; |
| 155 | 166 | case 'e': |
| 156 | 167 | return "technotes"; |
| 157 | 168 | case 'f': |
| 158 | 169 | return "forum posts"; |
| 170 | + case 'h': | |
| 171 | + return "forum threads"; | |
| 159 | 172 | case 'w': |
| 160 | 173 | return "wiki changes"; |
| 161 | 174 | case 't': |
| 162 | 175 | return "ticket changes"; |
| 163 | 176 | case 'g': |
| @@ -855,16 +868,17 @@ | ||
| 855 | 868 | ** * all (everything), |
| 856 | 869 | ** * ci (check-in) |
| 857 | 870 | ** * m (merge check-in), |
| 858 | 871 | ** * n (non-merge check-in) |
| 859 | 872 | ** * f (forum post) |
| 873 | +** * h (forum thread) | |
| 860 | 874 | ** * w (wiki page change) |
| 861 | 875 | ** * t (ticket change) |
| 862 | 876 | ** * g (tag added or removed) |
| 863 | 877 | ** Defaulting to all event types. |
| 864 | -** from=DATETIME Consider only events after this timestamp (requires to) | |
| 865 | -** to=DATETIME Consider only events before this timestamp (requires from) | |
| 878 | +** from=DATETIME Consider only events after this time (requires to) | |
| 879 | +** to=DATETIME Consider only events before this time (requires from) | |
| 866 | 880 | ** |
| 867 | 881 | ** |
| 868 | 882 | ** The view-specific query parameters include: |
| 869 | 883 | ** |
| 870 | 884 | ** view=byweek: |
| @@ -894,10 +908,11 @@ | ||
| 894 | 908 | }; |
| 895 | 909 | static const char *const azType[] = { |
| 896 | 910 | "a", "All Changes", |
| 897 | 911 | "ci", "Check-ins", |
| 898 | 912 | "f", "Forum Posts", |
| 913 | + "h", "Forum Threads", | |
| 899 | 914 | "m", "Merge check-ins", |
| 900 | 915 | "n", "Non-merge check-ins", |
| 901 | 916 | "g", "Tags", |
| 902 | 917 | "e", "Tech Notes", |
| 903 | 918 | "t", "Tickets", |
| 904 | 919 |
| --- src/statrep.c | |
| +++ src/statrep.c | |
| @@ -76,10 +76,15 @@ | |
| 76 | case 'f': |
| 77 | case 'F': |
| 78 | zRealType = "f"; |
| 79 | rc = *zRealType; |
| 80 | break; |
| 81 | case 'g': |
| 82 | case 'G': |
| 83 | zRealType = "g"; |
| 84 | rc = *zRealType; |
| 85 | break; |
| @@ -117,10 +122,16 @@ | |
| 117 | } |
| 118 | if( zRealType==0 ){ |
| 119 | statsReportTimelineYFlag = "a"; |
| 120 | db_multi_exec("CREATE TEMP VIEW v_reports AS " |
| 121 | "SELECT * FROM event WHERE %s", zTimeSpan/*safe-for-%s*/); |
| 122 | }else if( rc!='n' && rc!='m' ){ |
| 123 | statsReportTimelineYFlag = zRealType; |
| 124 | db_multi_exec("CREATE TEMP VIEW v_reports AS " |
| 125 | "SELECT * FROM event WHERE (type GLOB %Q) AND %s", |
| 126 | zRealType, zTimeSpan/*safe-for-%s*/); |
| @@ -154,10 +165,12 @@ | |
| 154 | return "non-merge check-ins"; |
| 155 | case 'e': |
| 156 | return "technotes"; |
| 157 | case 'f': |
| 158 | return "forum posts"; |
| 159 | case 'w': |
| 160 | return "wiki changes"; |
| 161 | case 't': |
| 162 | return "ticket changes"; |
| 163 | case 'g': |
| @@ -855,16 +868,17 @@ | |
| 855 | ** * all (everything), |
| 856 | ** * ci (check-in) |
| 857 | ** * m (merge check-in), |
| 858 | ** * n (non-merge check-in) |
| 859 | ** * f (forum post) |
| 860 | ** * w (wiki page change) |
| 861 | ** * t (ticket change) |
| 862 | ** * g (tag added or removed) |
| 863 | ** Defaulting to all event types. |
| 864 | ** from=DATETIME Consider only events after this timestamp (requires to) |
| 865 | ** to=DATETIME Consider only events before this timestamp (requires from) |
| 866 | ** |
| 867 | ** |
| 868 | ** The view-specific query parameters include: |
| 869 | ** |
| 870 | ** view=byweek: |
| @@ -894,10 +908,11 @@ | |
| 894 | }; |
| 895 | static const char *const azType[] = { |
| 896 | "a", "All Changes", |
| 897 | "ci", "Check-ins", |
| 898 | "f", "Forum Posts", |
| 899 | "m", "Merge check-ins", |
| 900 | "n", "Non-merge check-ins", |
| 901 | "g", "Tags", |
| 902 | "e", "Tech Notes", |
| 903 | "t", "Tickets", |
| 904 |
| --- src/statrep.c | |
| +++ src/statrep.c | |
| @@ -76,10 +76,15 @@ | |
| 76 | case 'f': |
| 77 | case 'F': |
| 78 | zRealType = "f"; |
| 79 | rc = *zRealType; |
| 80 | break; |
| 81 | case 'h': |
| 82 | case 'H': |
| 83 | zRealType = "h"; |
| 84 | rc = *zRealType; |
| 85 | break; |
| 86 | case 'g': |
| 87 | case 'G': |
| 88 | zRealType = "g"; |
| 89 | rc = *zRealType; |
| 90 | break; |
| @@ -117,10 +122,16 @@ | |
| 122 | } |
| 123 | if( zRealType==0 ){ |
| 124 | statsReportTimelineYFlag = "a"; |
| 125 | db_multi_exec("CREATE TEMP VIEW v_reports AS " |
| 126 | "SELECT * FROM event WHERE %s", zTimeSpan/*safe-for-%s*/); |
| 127 | }else if( rc=='h' ){ |
| 128 | statsReportTimelineYFlag = zRealType; |
| 129 | db_multi_exec("CREATE TEMP VIEW v_reports AS " |
| 130 | "SELECT * FROM event WHERE (type='f') " |
| 131 | " AND (comment GLOB 'Post:*') AND %s", |
| 132 | zTimeSpan/*safe-for-%s*/); |
| 133 | }else if( rc!='n' && rc!='m' ){ |
| 134 | statsReportTimelineYFlag = zRealType; |
| 135 | db_multi_exec("CREATE TEMP VIEW v_reports AS " |
| 136 | "SELECT * FROM event WHERE (type GLOB %Q) AND %s", |
| 137 | zRealType, zTimeSpan/*safe-for-%s*/); |
| @@ -154,10 +165,12 @@ | |
| 165 | return "non-merge check-ins"; |
| 166 | case 'e': |
| 167 | return "technotes"; |
| 168 | case 'f': |
| 169 | return "forum posts"; |
| 170 | case 'h': |
| 171 | return "forum threads"; |
| 172 | case 'w': |
| 173 | return "wiki changes"; |
| 174 | case 't': |
| 175 | return "ticket changes"; |
| 176 | case 'g': |
| @@ -855,16 +868,17 @@ | |
| 868 | ** * all (everything), |
| 869 | ** * ci (check-in) |
| 870 | ** * m (merge check-in), |
| 871 | ** * n (non-merge check-in) |
| 872 | ** * f (forum post) |
| 873 | ** * h (forum thread) |
| 874 | ** * w (wiki page change) |
| 875 | ** * t (ticket change) |
| 876 | ** * g (tag added or removed) |
| 877 | ** Defaulting to all event types. |
| 878 | ** from=DATETIME Consider only events after this time (requires to) |
| 879 | ** to=DATETIME Consider only events before this time (requires from) |
| 880 | ** |
| 881 | ** |
| 882 | ** The view-specific query parameters include: |
| 883 | ** |
| 884 | ** view=byweek: |
| @@ -894,10 +908,11 @@ | |
| 908 | }; |
| 909 | static const char *const azType[] = { |
| 910 | "a", "All Changes", |
| 911 | "ci", "Check-ins", |
| 912 | "f", "Forum Posts", |
| 913 | "h", "Forum Threads", |
| 914 | "m", "Merge check-ins", |
| 915 | "n", "Non-merge check-ins", |
| 916 | "g", "Tags", |
| 917 | "e", "Tech Notes", |
| 918 | "t", "Tickets", |
| 919 |
+22
-3
| --- src/style.c | ||
| +++ src/style.c | ||
| @@ -384,10 +384,11 @@ | ||
| 384 | 384 | |
| 385 | 385 | /* Use this for the $current_page variable if it is not NULL. If it |
| 386 | 386 | ** is NULL then use g.zPath. |
| 387 | 387 | */ |
| 388 | 388 | static char *local_zCurrentPage = 0; |
| 389 | +static char *local_zCurrentFeature = 0; | |
| 389 | 390 | |
| 390 | 391 | /* |
| 391 | 392 | ** Set the desired $current_page to something other than g.zPath |
| 392 | 393 | */ |
| 393 | 394 | void style_set_current_page(const char *zFormat, ...){ |
| @@ -419,12 +420,13 @@ | ||
| 419 | 420 | |
| 420 | 421 | /* Initialize the URL to its baseline */ |
| 421 | 422 | url = empty_blob; |
| 422 | 423 | blob_appendf(&url, "%R/style.css"); |
| 423 | 424 | |
| 424 | - /* If page-specific CSS exists for the current page, then append | |
| 425 | - ** the pathname for the page-specific CSS. The default CSS is | |
| 425 | + /* If page- or feature-specific CSS exists for the current page, | |
| 426 | + ** then append the pathname for the page-specific CSS. The default | |
| 427 | + ** CSS is | |
| 426 | 428 | ** |
| 427 | 429 | ** /style.css |
| 428 | 430 | ** |
| 429 | 431 | ** But for the "/wikiedit" page (to name but one example), we |
| 430 | 432 | ** append a path as follows: |
| @@ -432,14 +434,25 @@ | ||
| 432 | 434 | ** /style.css/wikiedit |
| 433 | 435 | ** |
| 434 | 436 | ** The /style.css page (implemented below) will detect this extra "wikiedit" |
| 435 | 437 | ** path information and include the page-specific CSS along with the |
| 436 | 438 | ** default CSS when it delivers the page. |
| 439 | + ** | |
| 440 | + ** Prior to 2026-06-06, this only looked at zPage but /forum and | |
| 441 | + ** friends need a per-feature style, so it now falls back to | |
| 442 | + ** local_zCurrentFeature. The current mechanism cannot support both | |
| 443 | + ** concurrently in a single request. | |
| 437 | 444 | */ |
| 438 | 445 | zBuiltin = mprintf("style.%s.css", zPage); |
| 439 | 446 | if( builtin_file(zBuiltin,0)!=0 ){ |
| 440 | - blob_appendf(&url, "/%s", zPage); | |
| 447 | + blob_appendf(&url, "/%t", zPage); | |
| 448 | + }else if( local_zCurrentFeature ){ | |
| 449 | + fossil_free(zBuiltin); | |
| 450 | + zBuiltin = mprintf("style.%s.css", local_zCurrentFeature); | |
| 451 | + if( builtin_file(zBuiltin,0)!=0 ){ | |
| 452 | + blob_appendf(&url, "/%t", local_zCurrentFeature); | |
| 453 | + } | |
| 441 | 454 | } |
| 442 | 455 | fossil_free(zBuiltin); |
| 443 | 456 | |
| 444 | 457 | /* Add query parameters that will change whenever the skin changes |
| 445 | 458 | ** or after any updates to the CSS files |
| @@ -727,10 +740,12 @@ | ||
| 727 | 740 | ** style_init_th1_vars() because that uses Th_MaybeStore() instead to |
| 728 | 741 | ** allow webpage implementations to call this before style_header() |
| 729 | 742 | ** to override that "maybe" default with something better. |
| 730 | 743 | */ |
| 731 | 744 | void style_set_current_feature(const char* zFeature){ |
| 745 | + fossil_free( local_zCurrentFeature ); | |
| 746 | + local_zCurrentFeature = fossil_strdup(zFeature); | |
| 732 | 747 | Th_Store("current_feature", zFeature); |
| 733 | 748 | } |
| 734 | 749 | |
| 735 | 750 | /* |
| 736 | 751 | ** Returns the current mainmenu value from either the --mainmenu flag |
| @@ -1258,10 +1273,11 @@ | ||
| 1258 | 1273 | "** Page-specific CSS for \"%s\"\n" |
| 1259 | 1274 | "***********************************************************/\n", |
| 1260 | 1275 | zPage); |
| 1261 | 1276 | blob_append(pOut, zBuiltin, nFile); |
| 1262 | 1277 | fossil_free(zFile); |
| 1278 | + zFile = 0; | |
| 1263 | 1279 | return; |
| 1264 | 1280 | } |
| 1265 | 1281 | /* Potential TODO: check for aliases/page groups. e.g. group all |
| 1266 | 1282 | ** /forumXYZ CSS into one file, all /setupXYZ into another, etc. As |
| 1267 | 1283 | ** of this writing, doing so would only shave a few kb from |
| @@ -1418,10 +1434,13 @@ | ||
| 1418 | 1434 | ** For administators, or if the test_env_enable setting is true, then |
| 1419 | 1435 | ** details of the request environment are displayed. Otherwise, just |
| 1420 | 1436 | ** the error message is shown. |
| 1421 | 1437 | ** |
| 1422 | 1438 | ** If zFormat is an empty string, then this is the /test-env page. |
| 1439 | +** | |
| 1440 | +** If the resulting formatted error message is not empty then this | |
| 1441 | +** function does not return. | |
| 1423 | 1442 | */ |
| 1424 | 1443 | void webpage_error(const char *zFormat, ...){ |
| 1425 | 1444 | int showAll = 0; |
| 1426 | 1445 | char *zErr = 0; |
| 1427 | 1446 | int isAuth = 0; |
| 1428 | 1447 | |
| 1429 | 1448 | ADDED src/style.forum.css |
| --- src/style.c | |
| +++ src/style.c | |
| @@ -384,10 +384,11 @@ | |
| 384 | |
| 385 | /* Use this for the $current_page variable if it is not NULL. If it |
| 386 | ** is NULL then use g.zPath. |
| 387 | */ |
| 388 | static char *local_zCurrentPage = 0; |
| 389 | |
| 390 | /* |
| 391 | ** Set the desired $current_page to something other than g.zPath |
| 392 | */ |
| 393 | void style_set_current_page(const char *zFormat, ...){ |
| @@ -419,12 +420,13 @@ | |
| 419 | |
| 420 | /* Initialize the URL to its baseline */ |
| 421 | url = empty_blob; |
| 422 | blob_appendf(&url, "%R/style.css"); |
| 423 | |
| 424 | /* If page-specific CSS exists for the current page, then append |
| 425 | ** the pathname for the page-specific CSS. The default CSS is |
| 426 | ** |
| 427 | ** /style.css |
| 428 | ** |
| 429 | ** But for the "/wikiedit" page (to name but one example), we |
| 430 | ** append a path as follows: |
| @@ -432,14 +434,25 @@ | |
| 432 | ** /style.css/wikiedit |
| 433 | ** |
| 434 | ** The /style.css page (implemented below) will detect this extra "wikiedit" |
| 435 | ** path information and include the page-specific CSS along with the |
| 436 | ** default CSS when it delivers the page. |
| 437 | */ |
| 438 | zBuiltin = mprintf("style.%s.css", zPage); |
| 439 | if( builtin_file(zBuiltin,0)!=0 ){ |
| 440 | blob_appendf(&url, "/%s", zPage); |
| 441 | } |
| 442 | fossil_free(zBuiltin); |
| 443 | |
| 444 | /* Add query parameters that will change whenever the skin changes |
| 445 | ** or after any updates to the CSS files |
| @@ -727,10 +740,12 @@ | |
| 727 | ** style_init_th1_vars() because that uses Th_MaybeStore() instead to |
| 728 | ** allow webpage implementations to call this before style_header() |
| 729 | ** to override that "maybe" default with something better. |
| 730 | */ |
| 731 | void style_set_current_feature(const char* zFeature){ |
| 732 | Th_Store("current_feature", zFeature); |
| 733 | } |
| 734 | |
| 735 | /* |
| 736 | ** Returns the current mainmenu value from either the --mainmenu flag |
| @@ -1258,10 +1273,11 @@ | |
| 1258 | "** Page-specific CSS for \"%s\"\n" |
| 1259 | "***********************************************************/\n", |
| 1260 | zPage); |
| 1261 | blob_append(pOut, zBuiltin, nFile); |
| 1262 | fossil_free(zFile); |
| 1263 | return; |
| 1264 | } |
| 1265 | /* Potential TODO: check for aliases/page groups. e.g. group all |
| 1266 | ** /forumXYZ CSS into one file, all /setupXYZ into another, etc. As |
| 1267 | ** of this writing, doing so would only shave a few kb from |
| @@ -1418,10 +1434,13 @@ | |
| 1418 | ** For administators, or if the test_env_enable setting is true, then |
| 1419 | ** details of the request environment are displayed. Otherwise, just |
| 1420 | ** the error message is shown. |
| 1421 | ** |
| 1422 | ** If zFormat is an empty string, then this is the /test-env page. |
| 1423 | */ |
| 1424 | void webpage_error(const char *zFormat, ...){ |
| 1425 | int showAll = 0; |
| 1426 | char *zErr = 0; |
| 1427 | int isAuth = 0; |
| 1428 | |
| 1429 | DDED src/style.forum.css |
| --- src/style.c | |
| +++ src/style.c | |
| @@ -384,10 +384,11 @@ | |
| 384 | |
| 385 | /* Use this for the $current_page variable if it is not NULL. If it |
| 386 | ** is NULL then use g.zPath. |
| 387 | */ |
| 388 | static char *local_zCurrentPage = 0; |
| 389 | static char *local_zCurrentFeature = 0; |
| 390 | |
| 391 | /* |
| 392 | ** Set the desired $current_page to something other than g.zPath |
| 393 | */ |
| 394 | void style_set_current_page(const char *zFormat, ...){ |
| @@ -419,12 +420,13 @@ | |
| 420 | |
| 421 | /* Initialize the URL to its baseline */ |
| 422 | url = empty_blob; |
| 423 | blob_appendf(&url, "%R/style.css"); |
| 424 | |
| 425 | /* If page- or feature-specific CSS exists for the current page, |
| 426 | ** then append the pathname for the page-specific CSS. The default |
| 427 | ** CSS is |
| 428 | ** |
| 429 | ** /style.css |
| 430 | ** |
| 431 | ** But for the "/wikiedit" page (to name but one example), we |
| 432 | ** append a path as follows: |
| @@ -432,14 +434,25 @@ | |
| 434 | ** /style.css/wikiedit |
| 435 | ** |
| 436 | ** The /style.css page (implemented below) will detect this extra "wikiedit" |
| 437 | ** path information and include the page-specific CSS along with the |
| 438 | ** default CSS when it delivers the page. |
| 439 | ** |
| 440 | ** Prior to 2026-06-06, this only looked at zPage but /forum and |
| 441 | ** friends need a per-feature style, so it now falls back to |
| 442 | ** local_zCurrentFeature. The current mechanism cannot support both |
| 443 | ** concurrently in a single request. |
| 444 | */ |
| 445 | zBuiltin = mprintf("style.%s.css", zPage); |
| 446 | if( builtin_file(zBuiltin,0)!=0 ){ |
| 447 | blob_appendf(&url, "/%t", zPage); |
| 448 | }else if( local_zCurrentFeature ){ |
| 449 | fossil_free(zBuiltin); |
| 450 | zBuiltin = mprintf("style.%s.css", local_zCurrentFeature); |
| 451 | if( builtin_file(zBuiltin,0)!=0 ){ |
| 452 | blob_appendf(&url, "/%t", local_zCurrentFeature); |
| 453 | } |
| 454 | } |
| 455 | fossil_free(zBuiltin); |
| 456 | |
| 457 | /* Add query parameters that will change whenever the skin changes |
| 458 | ** or after any updates to the CSS files |
| @@ -727,10 +740,12 @@ | |
| 740 | ** style_init_th1_vars() because that uses Th_MaybeStore() instead to |
| 741 | ** allow webpage implementations to call this before style_header() |
| 742 | ** to override that "maybe" default with something better. |
| 743 | */ |
| 744 | void style_set_current_feature(const char* zFeature){ |
| 745 | fossil_free( local_zCurrentFeature ); |
| 746 | local_zCurrentFeature = fossil_strdup(zFeature); |
| 747 | Th_Store("current_feature", zFeature); |
| 748 | } |
| 749 | |
| 750 | /* |
| 751 | ** Returns the current mainmenu value from either the --mainmenu flag |
| @@ -1258,10 +1273,11 @@ | |
| 1273 | "** Page-specific CSS for \"%s\"\n" |
| 1274 | "***********************************************************/\n", |
| 1275 | zPage); |
| 1276 | blob_append(pOut, zBuiltin, nFile); |
| 1277 | fossil_free(zFile); |
| 1278 | zFile = 0; |
| 1279 | return; |
| 1280 | } |
| 1281 | /* Potential TODO: check for aliases/page groups. e.g. group all |
| 1282 | ** /forumXYZ CSS into one file, all /setupXYZ into another, etc. As |
| 1283 | ** of this writing, doing so would only shave a few kb from |
| @@ -1418,10 +1434,13 @@ | |
| 1434 | ** For administators, or if the test_env_enable setting is true, then |
| 1435 | ** details of the request environment are displayed. Otherwise, just |
| 1436 | ** the error message is shown. |
| 1437 | ** |
| 1438 | ** If zFormat is an empty string, then this is the /test-env page. |
| 1439 | ** |
| 1440 | ** If the resulting formatted error message is not empty then this |
| 1441 | ** function does not return. |
| 1442 | */ |
| 1443 | void webpage_error(const char *zFormat, ...){ |
| 1444 | int showAll = 0; |
| 1445 | char *zErr = 0; |
| 1446 | int isAuth = 0; |
| 1447 | |
| 1448 | DDED src/style.forum.css |
+33
| --- a/src/style.forum.css | ||
| +++ b/src/style.forum.css | ||
| @@ -0,0 +1,33 @@ | ||
| 1 | +/* Styles specific to the forum family of pages */ | |
| 2 | + | |
| 3 | +fieldset.forum-status-selection { | |
| 4 | + max-width: max-content; | |
| 5 | + border-radius: 0.5em; | |
| 6 | + padding: 0 0.5em; | |
| 7 | + margin-bottom: 0.35em; | |
| 8 | +} | |
| 9 | + | |
| 10 | +body.forum .forumpost-single-controls button.draft:after { | |
| 11 | + /* Reply/Edit buttons on posts which have local draft edits. */ | |
| 12 | + content: " [draft]"; | |
| 13 | +} | |
| 14 | + | |
| 15 | +/* .ForumPostEditor is the top container element used by the JS | |
| 16 | + ForumPostEditor class in fossil.page.forumpost.js. */ | |
| 17 | +.ForumPostEditor { | |
| 18 | + display: flex; | |
| 19 | + flex-direction: column; | |
| 20 | + gap: 1em; | |
| 21 | + padding: 0.5em; | |
| 22 | +} | |
| 23 | +.ForumPostEditor > .tab-bar{ | |
| 24 | +} | |
| 25 | +.ForumPostEditor > .tab-container { | |
| 26 | +} | |
| 27 | +.ForumPostEditor > .tab-container > .tabs { | |
| 28 | + /*min-height: 10em;*/ | |
| 29 | +} | |
| 30 | +.ForumPostEditor > .tab-container > .tabs > .tab-panel.debug { | |
| 31 | + display: flex; | |
| 32 | + flex-direction: column; | |
| 33 | + gap: 0 |
| --- a/src/style.forum.css | |
| +++ b/src/style.forum.css | |
| @@ -0,0 +1,33 @@ | |
| --- a/src/style.forum.css | |
| +++ b/src/style.forum.css | |
| @@ -0,0 +1,33 @@ | |
| 1 | /* Styles specific to the forum family of pages */ |
| 2 | |
| 3 | fieldset.forum-status-selection { |
| 4 | max-width: max-content; |
| 5 | border-radius: 0.5em; |
| 6 | padding: 0 0.5em; |
| 7 | margin-bottom: 0.35em; |
| 8 | } |
| 9 | |
| 10 | body.forum .forumpost-single-controls button.draft:after { |
| 11 | /* Reply/Edit buttons on posts which have local draft edits. */ |
| 12 | content: " [draft]"; |
| 13 | } |
| 14 | |
| 15 | /* .ForumPostEditor is the top container element used by the JS |
| 16 | ForumPostEditor class in fossil.page.forumpost.js. */ |
| 17 | .ForumPostEditor { |
| 18 | display: flex; |
| 19 | flex-direction: column; |
| 20 | gap: 1em; |
| 21 | padding: 0.5em; |
| 22 | } |
| 23 | .ForumPostEditor > .tab-bar{ |
| 24 | } |
| 25 | .ForumPostEditor > .tab-container { |
| 26 | } |
| 27 | .ForumPostEditor > .tab-container > .tabs { |
| 28 | /*min-height: 10em;*/ |
| 29 | } |
| 30 | .ForumPostEditor > .tab-container > .tabs > .tab-panel.debug { |
| 31 | display: flex; |
| 32 | flex-direction: column; |
| 33 | gap: 0 |
+107
-27
| --- src/tag.c | ||
| +++ src/tag.c | ||
| @@ -384,10 +384,30 @@ | ||
| 384 | 384 | || strncmp(zTag,"tkt-",4)==0 |
| 385 | 385 | || strncmp(zTag,"event-",6)==0)){ |
| 386 | 386 | fossil_fatal("Invalid prefix for tag name: %s", zTag); |
| 387 | 387 | } |
| 388 | 388 | } |
| 389 | + | |
| 390 | +/* | |
| 391 | +** Internal helper for the tag command. Fetches rid_root_parent(rid) | |
| 392 | +** and if it differs from the input, assigns *zSym to the root object's | |
| 393 | +** UUID (intentionally leaking it). | |
| 394 | +*/ | |
| 395 | +static int tag_cmd_root(int rid, char const **zSym, int bVerbose){ | |
| 396 | + const int origRid = rid; | |
| 397 | + rid = rid_root_parent(rid); | |
| 398 | + assert( rid>0 ); | |
| 399 | + if( origRid!=rid ){ | |
| 400 | + char const *zOrig = *zSym; | |
| 401 | + *zSym = rid_to_uuid(rid)/*intentional leak*/; | |
| 402 | + if( bVerbose ){ | |
| 403 | + fossil_print("Redirecting tag from %!S to root ancestor %!S.\n", | |
| 404 | + zOrig, *zSym); | |
| 405 | + } | |
| 406 | + } | |
| 407 | + return rid; | |
| 408 | +} | |
| 389 | 409 | |
| 390 | 410 | /* |
| 391 | 411 | ** COMMAND: tag |
| 392 | 412 | ** |
| 393 | 413 | ** Usage: %fossil tag SUBCOMMAND ... |
| @@ -409,19 +429,30 @@ | ||
| 409 | 429 | ** actually insert it into the database |
| 410 | 430 | ** --propagate Propagating tag |
| 411 | 431 | ** --raw Raw tag name. Ignored for |
| 412 | 432 | ** non-CHECK-IN artifacts. |
| 413 | 433 | ** --user-override USER Name USER when adding the tag |
| 434 | +** --root If ARTIFACT-ID refers to an artifact | |
| 435 | +** with a P-card, it gets translated to the | |
| 436 | +** oldest parent of that artifact and | |
| 437 | +** --propagate is assumed. This is | |
| 438 | +** most useful with forum posts, wiki | |
| 439 | +** pages, and tech notes, where tags are | |
| 440 | +** most easliy managed via their initial | |
| 441 | +** version. | |
| 414 | 442 | ** |
| 415 | 443 | ** The --date-override and --user-override options support |
| 416 | 444 | ** importing history from other SCM systems. DATETIME has |
| 417 | 445 | ** the form 'YYYY-MM-DD HH:MM:SS'. |
| 418 | 446 | ** |
| 419 | 447 | ** Note that fossil uses some tag prefixes internally and this |
| 420 | 448 | ** command will reject tags with these prefixes to avoid |
| 421 | 449 | ** causing problems or confusion: "wiki-", "tkt-", "event-". |
| 422 | 450 | ** |
| 451 | +** When tagging forum posts, the ARTIFACT-ID is translated to | |
| 452 | +** the initial version of that post and --propagate is implied. | |
| 453 | +** | |
| 423 | 454 | ** > fossil tag cancel ?--raw? TAGNAME ARTIFACT-ID |
| 424 | 455 | ** |
| 425 | 456 | ** Remove the tag TAGNAME from the artifact referenced by |
| 426 | 457 | ** ARTIFACT-ID, and also remove the propagation of the tag to |
| 427 | 458 | ** any descendants. Use the -n|--dry-run option to see |
| @@ -433,10 +464,11 @@ | ||
| 433 | 464 | ** -n|--dry-run Display the control artifact, but do |
| 434 | 465 | ** not insert it into the database |
| 435 | 466 | ** --raw Raw tag name. Ignored for |
| 436 | 467 | ** non-CHECK-IN artifacts. |
| 437 | 468 | ** --user-override USER Name USER when deleting the tag |
| 469 | +** --root As described for 'add'. | |
| 438 | 470 | ** |
| 439 | 471 | ** > fossil tag find ?OPTIONS? TAGNAME |
| 440 | 472 | ** |
| 441 | 473 | ** List all objects that use TAGNAME. |
| 442 | 474 | ** |
| @@ -452,12 +484,11 @@ | ||
| 452 | 484 | ** if --raw is used. |
| 453 | 485 | ** |
| 454 | 486 | ** > fossil tag list|ls ?OPTIONS? ?ARTIFACT-ID? |
| 455 | 487 | ** |
| 456 | 488 | ** List all tags or, if ARTIFACT-ID is supplied, all tags and |
| 457 | -** their values for that artifact. The tagtype option accepts | |
| 458 | -** one of: propagated, singleton, cancel. For historical | |
| 489 | +** their values for that artifact. For historical | |
| 459 | 490 | ** scripting compatibility, the internal tag types "wiki-", |
| 460 | 491 | ** "tkt-", and "event-" (technote) are elided by default |
| 461 | 492 | ** unless the --raw or --prefix options are used. |
| 462 | 493 | ** |
| 463 | 494 | ** Options: |
| @@ -475,10 +506,12 @@ | ||
| 475 | 506 | ** be one of: cancel, singleton, propagated |
| 476 | 507 | ** --values List tag values |
| 477 | 508 | ** If --sep is supplied, list all values of a tag on |
| 478 | 509 | ** the same line, separated by SEP; otherwise list |
| 479 | 510 | ** each value on its own line. |
| 511 | +** --root As described for 'add' and only if ARTIFACT-ID is | |
| 512 | +** provided. | |
| 480 | 513 | ** |
| 481 | 514 | ** The option --raw allows the manipulation of all types of tags |
| 482 | 515 | ** used for various internal purposes in fossil. It also shows |
| 483 | 516 | ** "cancel" tags for the "find" and "list" subcommands. You should |
| 484 | 517 | ** not use this option to make changes unless you are sure what |
| @@ -512,34 +545,38 @@ | ||
| 512 | 545 | |
| 513 | 546 | if( strncmp(g.argv[2],"add",n)==0 ){ |
| 514 | 547 | char *zValue; |
| 515 | 548 | int dryRun = 0; |
| 516 | 549 | int fRaw = find_option("raw","",0)!=0; |
| 517 | - const char *zPrefix = ""; | |
| 518 | 550 | int fPropagate = find_option("propagate","",0)!=0; |
| 551 | + int fRoot = find_option("root","",0)!=0; | |
| 552 | + int objType; | |
| 553 | + int rid; | |
| 554 | + const char *zPrefix = ""; | |
| 519 | 555 | const char *zDateOvrd = find_option("date-override",0,1); |
| 520 | 556 | const char *zUserOvrd = find_option("user-override",0,1); |
| 521 | 557 | const char *zTag; |
| 522 | 558 | const char *zObjId; |
| 523 | - int objType; | |
| 524 | 559 | if( find_option("dry-run","n",0)!=0 ) dryRun = TAG_ADD_DRYRUN; |
| 525 | 560 | if( g.argc!=5 && g.argc!=6 ){ |
| 526 | 561 | usage("add ?options? TAGNAME ARTIFACT-ID ?VALUE?"); |
| 527 | 562 | } |
| 528 | 563 | zTag = g.argv[3]; |
| 529 | 564 | tag_cmd_tagname_check(zTag); |
| 530 | 565 | zObjId = g.argv[4]; |
| 531 | 566 | zValue = g.argc==6 ? g.argv[5] : 0; |
| 532 | - objType = whatis_rid_type(symbolic_name_to_rid(zObjId, 0)); | |
| 533 | - switch(objType){ | |
| 534 | - case 0: | |
| 535 | - fossil_fatal("Cannot resolve artifact ID: %s", zObjId); | |
| 536 | - break; | |
| 537 | - case CFTYPE_MANIFEST: | |
| 538 | - zPrefix = fRaw ? "" : "sym-"; | |
| 539 | - break; | |
| 540 | - default: break; | |
| 567 | + rid = symbolic_name_to_rid(zObjId, 0); | |
| 568 | + if( rid<=0 ){ | |
| 569 | + fossil_fatal("Cannot resolve artifact ID: %s", zObjId); | |
| 570 | + } | |
| 571 | + if( fRoot ){ | |
| 572 | + rid = tag_cmd_root(rid, &zObjId, dryRun); | |
| 573 | + fPropagate = 1; | |
| 574 | + } | |
| 575 | + objType = whatis_rid_type(rid); | |
| 576 | + if( CFTYPE_MANIFEST==objType ){ | |
| 577 | + zPrefix = fRaw ? "" : "sym-"; | |
| 541 | 578 | } |
| 542 | 579 | db_begin_transaction(); |
| 543 | 580 | tag_add_artifact(zPrefix, zTag, zObjId, zValue, |
| 544 | 581 | 1+fPropagate+dryRun,zDateOvrd,zUserOvrd); |
| 545 | 582 | db_end_transaction(0); |
| @@ -551,32 +588,35 @@ | ||
| 551 | 588 | }else |
| 552 | 589 | |
| 553 | 590 | if( strncmp(g.argv[2],"cancel",n)==0 ){ |
| 554 | 591 | int dryRun = 0; |
| 555 | 592 | int fRaw = find_option("raw","",0)!=0; |
| 593 | + int fRoot = find_option("root","",0)!=0; | |
| 594 | + int objType; | |
| 595 | + int rid; | |
| 556 | 596 | const char *zPrefix = ""; |
| 557 | 597 | const char *zDateOvrd = find_option("date-override",0,1); |
| 558 | 598 | const char *zUserOvrd = find_option("user-override",0,1); |
| 559 | 599 | const char *zTag; |
| 560 | 600 | const char *zObjId; |
| 561 | - int objType; | |
| 562 | 601 | if( find_option("dry-run","n",0)!=0 ) dryRun = TAG_ADD_DRYRUN; |
| 563 | 602 | if( g.argc!=5 ){ |
| 564 | 603 | usage("cancel ?options? TAGNAME ARTIFACT-ID"); |
| 565 | 604 | } |
| 566 | 605 | zTag = g.argv[3]; |
| 567 | 606 | tag_cmd_tagname_check(zTag); |
| 568 | 607 | zObjId = g.argv[4]; |
| 569 | - objType = whatis_rid_type(symbolic_name_to_rid(zObjId, 0)); | |
| 570 | - switch(objType){ | |
| 571 | - case 0: | |
| 572 | - fossil_fatal("Cannot resolve artifact ID: %s", zObjId); | |
| 573 | - break; | |
| 574 | - case CFTYPE_MANIFEST: | |
| 575 | - zPrefix = fRaw ? "" : "sym-"; | |
| 576 | - break; | |
| 577 | - default: break; | |
| 608 | + rid = symbolic_name_to_rid(zObjId, 0); | |
| 609 | + if( rid<=0 ){ | |
| 610 | + fossil_fatal("Cannot resolve artifact ID: %s", zObjId); | |
| 611 | + } | |
| 612 | + if( fRoot ){ | |
| 613 | + rid = tag_cmd_root(rid, &zObjId, dryRun); | |
| 614 | + } | |
| 615 | + objType = whatis_rid_type(rid); | |
| 616 | + if( CFTYPE_MANIFEST==objType ){ | |
| 617 | + zPrefix = fRaw ? "" : "sym-"; | |
| 578 | 618 | } |
| 579 | 619 | db_begin_transaction(); |
| 580 | 620 | tag_add_artifact(zPrefix, zTag, zObjId, 0, dryRun, |
| 581 | 621 | zDateOvrd, zUserOvrd); |
| 582 | 622 | db_end_transaction(0); |
| @@ -639,10 +679,11 @@ | ||
| 639 | 679 | const char *zTagType = find_option("tagtype","t",1); |
| 640 | 680 | const int fInverse = find_option("inverse","v",0)!=0; |
| 641 | 681 | const char *zTagPrefix = find_option("prefix","",1); |
| 642 | 682 | int nTagType = fRaw ? -1 : 0; |
| 643 | 683 | int fValues = find_option("values","",0)!=0; |
| 684 | + int fRoot = find_option("root","",0)!=0; | |
| 644 | 685 | const char *zSep = find_option("sep","",1); |
| 645 | 686 | |
| 646 | 687 | |
| 647 | 688 | if( zTagType!=0 ){ |
| 648 | 689 | int l = strlen(zTagType); |
| @@ -712,15 +753,19 @@ | ||
| 712 | 753 | } |
| 713 | 754 | } |
| 714 | 755 | db_finalize(&q); |
| 715 | 756 | }else if( g.argc==4 ){ |
| 716 | 757 | char const *zObjId = g.argv[3]; |
| 717 | - const int rid = name_to_rid(zObjId); | |
| 718 | - const int objType = whatis_rid_type(rid); | |
| 758 | + int rid = name_to_rid(zObjId); | |
| 759 | + int objType; | |
| 719 | 760 | int nTagOffset = 0; |
| 720 | 761 | |
| 762 | + if( fRoot ){ | |
| 763 | + rid = tag_cmd_root(rid, &zObjId, 0); | |
| 764 | + } | |
| 721 | 765 | zTagPrefix = 0; |
| 766 | + objType = rid>=0 ? whatis_rid_type(rid) : 0; | |
| 722 | 767 | if(objType<=0){ |
| 723 | 768 | fossil_fatal("Cannot resolve artifact ID: %s", zObjId); |
| 724 | 769 | }else if(fRaw==0){ |
| 725 | 770 | /* Figure out the tag prefix to strip */ |
| 726 | 771 | switch(objType){ |
| @@ -958,16 +1003,51 @@ | ||
| 958 | 1003 | " AND tagxref.tagid=tag.tagid", |
| 959 | 1004 | rid, tagId |
| 960 | 1005 | ); |
| 961 | 1006 | } |
| 962 | 1007 | |
| 1008 | + | |
| 1009 | +/* | |
| 1010 | +** If the given blob.rid value has the given tag applied to it, | |
| 1011 | +** returns true and sets *pOut to a copy of its value (or NULL if it | |
| 1012 | +** has no value). Else returns false and sets *pOut to 0. A truthy | |
| 1013 | +** value returned is the associated tag.tagid value. | |
| 1014 | +** | |
| 1015 | +** Ownership of *pOut is transfered to the caller, who must eventually | |
| 1016 | +** fossil_free() it. | |
| 1017 | +*/ | |
| 1018 | +int rid_has_tag2(int rid, const char *zTag, char **pOut){ | |
| 1019 | + static Stmt q; | |
| 1020 | + int rc = 0; | |
| 1021 | + if( !q.pStmt ){ | |
| 1022 | + db_prepare( | |
| 1023 | + &q, "SELECT t.tagid, x.value" | |
| 1024 | + " FROM tagxref x, tag t" | |
| 1025 | + " WHERE x.rid=:rid" | |
| 1026 | + " AND x.tagtype>0" | |
| 1027 | + " AND x.tagid=t.tagid" | |
| 1028 | + " AND t.tagname=:name" | |
| 1029 | + " ORDER BY mtime DESC" | |
| 1030 | + ); | |
| 1031 | + } | |
| 1032 | + *pOut = 0; | |
| 1033 | + db_bind_int(&q, ":rid", rid); | |
| 1034 | + db_bind_text(&q, ":name", zTag); | |
| 1035 | + if( SQLITE_ROW==db_step(&q) ){ | |
| 1036 | + rc = db_column_int(&q, 0); | |
| 1037 | + *pOut = fossil_strdup(db_column_text(&q, 1)); | |
| 1038 | + } | |
| 1039 | + db_reset(&q); | |
| 1040 | + return rc; | |
| 1041 | +} | |
| 1042 | + | |
| 963 | 1043 | |
| 964 | 1044 | /* |
| 965 | 1045 | ** Returns tagxref.rowid if the given blob.rid has a tagxref.rid entry |
| 966 | 1046 | ** of an active (non-cancelled) tag matching the given rid and tag |
| 967 | -** name string, else returns 0. Note that this function does not | |
| 968 | -** distinguish between a non-existent tag and a cancelled tag. | |
| 1047 | +** name string, else returns 0. This function does not distinguish | |
| 1048 | +** between a non-existent tag and a cancelled tag. | |
| 969 | 1049 | ** |
| 970 | 1050 | ** Design note: the return value is the tagxref.rowid because that |
| 971 | 1051 | ** gives us an easy way to fetch the value of the tag later on, if |
| 972 | 1052 | ** needed. |
| 973 | 1053 | */ |
| 974 | 1054 |
| --- src/tag.c | |
| +++ src/tag.c | |
| @@ -384,10 +384,30 @@ | |
| 384 | || strncmp(zTag,"tkt-",4)==0 |
| 385 | || strncmp(zTag,"event-",6)==0)){ |
| 386 | fossil_fatal("Invalid prefix for tag name: %s", zTag); |
| 387 | } |
| 388 | } |
| 389 | |
| 390 | /* |
| 391 | ** COMMAND: tag |
| 392 | ** |
| 393 | ** Usage: %fossil tag SUBCOMMAND ... |
| @@ -409,19 +429,30 @@ | |
| 409 | ** actually insert it into the database |
| 410 | ** --propagate Propagating tag |
| 411 | ** --raw Raw tag name. Ignored for |
| 412 | ** non-CHECK-IN artifacts. |
| 413 | ** --user-override USER Name USER when adding the tag |
| 414 | ** |
| 415 | ** The --date-override and --user-override options support |
| 416 | ** importing history from other SCM systems. DATETIME has |
| 417 | ** the form 'YYYY-MM-DD HH:MM:SS'. |
| 418 | ** |
| 419 | ** Note that fossil uses some tag prefixes internally and this |
| 420 | ** command will reject tags with these prefixes to avoid |
| 421 | ** causing problems or confusion: "wiki-", "tkt-", "event-". |
| 422 | ** |
| 423 | ** > fossil tag cancel ?--raw? TAGNAME ARTIFACT-ID |
| 424 | ** |
| 425 | ** Remove the tag TAGNAME from the artifact referenced by |
| 426 | ** ARTIFACT-ID, and also remove the propagation of the tag to |
| 427 | ** any descendants. Use the -n|--dry-run option to see |
| @@ -433,10 +464,11 @@ | |
| 433 | ** -n|--dry-run Display the control artifact, but do |
| 434 | ** not insert it into the database |
| 435 | ** --raw Raw tag name. Ignored for |
| 436 | ** non-CHECK-IN artifacts. |
| 437 | ** --user-override USER Name USER when deleting the tag |
| 438 | ** |
| 439 | ** > fossil tag find ?OPTIONS? TAGNAME |
| 440 | ** |
| 441 | ** List all objects that use TAGNAME. |
| 442 | ** |
| @@ -452,12 +484,11 @@ | |
| 452 | ** if --raw is used. |
| 453 | ** |
| 454 | ** > fossil tag list|ls ?OPTIONS? ?ARTIFACT-ID? |
| 455 | ** |
| 456 | ** List all tags or, if ARTIFACT-ID is supplied, all tags and |
| 457 | ** their values for that artifact. The tagtype option accepts |
| 458 | ** one of: propagated, singleton, cancel. For historical |
| 459 | ** scripting compatibility, the internal tag types "wiki-", |
| 460 | ** "tkt-", and "event-" (technote) are elided by default |
| 461 | ** unless the --raw or --prefix options are used. |
| 462 | ** |
| 463 | ** Options: |
| @@ -475,10 +506,12 @@ | |
| 475 | ** be one of: cancel, singleton, propagated |
| 476 | ** --values List tag values |
| 477 | ** If --sep is supplied, list all values of a tag on |
| 478 | ** the same line, separated by SEP; otherwise list |
| 479 | ** each value on its own line. |
| 480 | ** |
| 481 | ** The option --raw allows the manipulation of all types of tags |
| 482 | ** used for various internal purposes in fossil. It also shows |
| 483 | ** "cancel" tags for the "find" and "list" subcommands. You should |
| 484 | ** not use this option to make changes unless you are sure what |
| @@ -512,34 +545,38 @@ | |
| 512 | |
| 513 | if( strncmp(g.argv[2],"add",n)==0 ){ |
| 514 | char *zValue; |
| 515 | int dryRun = 0; |
| 516 | int fRaw = find_option("raw","",0)!=0; |
| 517 | const char *zPrefix = ""; |
| 518 | int fPropagate = find_option("propagate","",0)!=0; |
| 519 | const char *zDateOvrd = find_option("date-override",0,1); |
| 520 | const char *zUserOvrd = find_option("user-override",0,1); |
| 521 | const char *zTag; |
| 522 | const char *zObjId; |
| 523 | int objType; |
| 524 | if( find_option("dry-run","n",0)!=0 ) dryRun = TAG_ADD_DRYRUN; |
| 525 | if( g.argc!=5 && g.argc!=6 ){ |
| 526 | usage("add ?options? TAGNAME ARTIFACT-ID ?VALUE?"); |
| 527 | } |
| 528 | zTag = g.argv[3]; |
| 529 | tag_cmd_tagname_check(zTag); |
| 530 | zObjId = g.argv[4]; |
| 531 | zValue = g.argc==6 ? g.argv[5] : 0; |
| 532 | objType = whatis_rid_type(symbolic_name_to_rid(zObjId, 0)); |
| 533 | switch(objType){ |
| 534 | case 0: |
| 535 | fossil_fatal("Cannot resolve artifact ID: %s", zObjId); |
| 536 | break; |
| 537 | case CFTYPE_MANIFEST: |
| 538 | zPrefix = fRaw ? "" : "sym-"; |
| 539 | break; |
| 540 | default: break; |
| 541 | } |
| 542 | db_begin_transaction(); |
| 543 | tag_add_artifact(zPrefix, zTag, zObjId, zValue, |
| 544 | 1+fPropagate+dryRun,zDateOvrd,zUserOvrd); |
| 545 | db_end_transaction(0); |
| @@ -551,32 +588,35 @@ | |
| 551 | }else |
| 552 | |
| 553 | if( strncmp(g.argv[2],"cancel",n)==0 ){ |
| 554 | int dryRun = 0; |
| 555 | int fRaw = find_option("raw","",0)!=0; |
| 556 | const char *zPrefix = ""; |
| 557 | const char *zDateOvrd = find_option("date-override",0,1); |
| 558 | const char *zUserOvrd = find_option("user-override",0,1); |
| 559 | const char *zTag; |
| 560 | const char *zObjId; |
| 561 | int objType; |
| 562 | if( find_option("dry-run","n",0)!=0 ) dryRun = TAG_ADD_DRYRUN; |
| 563 | if( g.argc!=5 ){ |
| 564 | usage("cancel ?options? TAGNAME ARTIFACT-ID"); |
| 565 | } |
| 566 | zTag = g.argv[3]; |
| 567 | tag_cmd_tagname_check(zTag); |
| 568 | zObjId = g.argv[4]; |
| 569 | objType = whatis_rid_type(symbolic_name_to_rid(zObjId, 0)); |
| 570 | switch(objType){ |
| 571 | case 0: |
| 572 | fossil_fatal("Cannot resolve artifact ID: %s", zObjId); |
| 573 | break; |
| 574 | case CFTYPE_MANIFEST: |
| 575 | zPrefix = fRaw ? "" : "sym-"; |
| 576 | break; |
| 577 | default: break; |
| 578 | } |
| 579 | db_begin_transaction(); |
| 580 | tag_add_artifact(zPrefix, zTag, zObjId, 0, dryRun, |
| 581 | zDateOvrd, zUserOvrd); |
| 582 | db_end_transaction(0); |
| @@ -639,10 +679,11 @@ | |
| 639 | const char *zTagType = find_option("tagtype","t",1); |
| 640 | const int fInverse = find_option("inverse","v",0)!=0; |
| 641 | const char *zTagPrefix = find_option("prefix","",1); |
| 642 | int nTagType = fRaw ? -1 : 0; |
| 643 | int fValues = find_option("values","",0)!=0; |
| 644 | const char *zSep = find_option("sep","",1); |
| 645 | |
| 646 | |
| 647 | if( zTagType!=0 ){ |
| 648 | int l = strlen(zTagType); |
| @@ -712,15 +753,19 @@ | |
| 712 | } |
| 713 | } |
| 714 | db_finalize(&q); |
| 715 | }else if( g.argc==4 ){ |
| 716 | char const *zObjId = g.argv[3]; |
| 717 | const int rid = name_to_rid(zObjId); |
| 718 | const int objType = whatis_rid_type(rid); |
| 719 | int nTagOffset = 0; |
| 720 | |
| 721 | zTagPrefix = 0; |
| 722 | if(objType<=0){ |
| 723 | fossil_fatal("Cannot resolve artifact ID: %s", zObjId); |
| 724 | }else if(fRaw==0){ |
| 725 | /* Figure out the tag prefix to strip */ |
| 726 | switch(objType){ |
| @@ -958,16 +1003,51 @@ | |
| 958 | " AND tagxref.tagid=tag.tagid", |
| 959 | rid, tagId |
| 960 | ); |
| 961 | } |
| 962 | |
| 963 | |
| 964 | /* |
| 965 | ** Returns tagxref.rowid if the given blob.rid has a tagxref.rid entry |
| 966 | ** of an active (non-cancelled) tag matching the given rid and tag |
| 967 | ** name string, else returns 0. Note that this function does not |
| 968 | ** distinguish between a non-existent tag and a cancelled tag. |
| 969 | ** |
| 970 | ** Design note: the return value is the tagxref.rowid because that |
| 971 | ** gives us an easy way to fetch the value of the tag later on, if |
| 972 | ** needed. |
| 973 | */ |
| 974 |
| --- src/tag.c | |
| +++ src/tag.c | |
| @@ -384,10 +384,30 @@ | |
| 384 | || strncmp(zTag,"tkt-",4)==0 |
| 385 | || strncmp(zTag,"event-",6)==0)){ |
| 386 | fossil_fatal("Invalid prefix for tag name: %s", zTag); |
| 387 | } |
| 388 | } |
| 389 | |
| 390 | /* |
| 391 | ** Internal helper for the tag command. Fetches rid_root_parent(rid) |
| 392 | ** and if it differs from the input, assigns *zSym to the root object's |
| 393 | ** UUID (intentionally leaking it). |
| 394 | */ |
| 395 | static int tag_cmd_root(int rid, char const **zSym, int bVerbose){ |
| 396 | const int origRid = rid; |
| 397 | rid = rid_root_parent(rid); |
| 398 | assert( rid>0 ); |
| 399 | if( origRid!=rid ){ |
| 400 | char const *zOrig = *zSym; |
| 401 | *zSym = rid_to_uuid(rid)/*intentional leak*/; |
| 402 | if( bVerbose ){ |
| 403 | fossil_print("Redirecting tag from %!S to root ancestor %!S.\n", |
| 404 | zOrig, *zSym); |
| 405 | } |
| 406 | } |
| 407 | return rid; |
| 408 | } |
| 409 | |
| 410 | /* |
| 411 | ** COMMAND: tag |
| 412 | ** |
| 413 | ** Usage: %fossil tag SUBCOMMAND ... |
| @@ -409,19 +429,30 @@ | |
| 429 | ** actually insert it into the database |
| 430 | ** --propagate Propagating tag |
| 431 | ** --raw Raw tag name. Ignored for |
| 432 | ** non-CHECK-IN artifacts. |
| 433 | ** --user-override USER Name USER when adding the tag |
| 434 | ** --root If ARTIFACT-ID refers to an artifact |
| 435 | ** with a P-card, it gets translated to the |
| 436 | ** oldest parent of that artifact and |
| 437 | ** --propagate is assumed. This is |
| 438 | ** most useful with forum posts, wiki |
| 439 | ** pages, and tech notes, where tags are |
| 440 | ** most easliy managed via their initial |
| 441 | ** version. |
| 442 | ** |
| 443 | ** The --date-override and --user-override options support |
| 444 | ** importing history from other SCM systems. DATETIME has |
| 445 | ** the form 'YYYY-MM-DD HH:MM:SS'. |
| 446 | ** |
| 447 | ** Note that fossil uses some tag prefixes internally and this |
| 448 | ** command will reject tags with these prefixes to avoid |
| 449 | ** causing problems or confusion: "wiki-", "tkt-", "event-". |
| 450 | ** |
| 451 | ** When tagging forum posts, the ARTIFACT-ID is translated to |
| 452 | ** the initial version of that post and --propagate is implied. |
| 453 | ** |
| 454 | ** > fossil tag cancel ?--raw? TAGNAME ARTIFACT-ID |
| 455 | ** |
| 456 | ** Remove the tag TAGNAME from the artifact referenced by |
| 457 | ** ARTIFACT-ID, and also remove the propagation of the tag to |
| 458 | ** any descendants. Use the -n|--dry-run option to see |
| @@ -433,10 +464,11 @@ | |
| 464 | ** -n|--dry-run Display the control artifact, but do |
| 465 | ** not insert it into the database |
| 466 | ** --raw Raw tag name. Ignored for |
| 467 | ** non-CHECK-IN artifacts. |
| 468 | ** --user-override USER Name USER when deleting the tag |
| 469 | ** --root As described for 'add'. |
| 470 | ** |
| 471 | ** > fossil tag find ?OPTIONS? TAGNAME |
| 472 | ** |
| 473 | ** List all objects that use TAGNAME. |
| 474 | ** |
| @@ -452,12 +484,11 @@ | |
| 484 | ** if --raw is used. |
| 485 | ** |
| 486 | ** > fossil tag list|ls ?OPTIONS? ?ARTIFACT-ID? |
| 487 | ** |
| 488 | ** List all tags or, if ARTIFACT-ID is supplied, all tags and |
| 489 | ** their values for that artifact. For historical |
| 490 | ** scripting compatibility, the internal tag types "wiki-", |
| 491 | ** "tkt-", and "event-" (technote) are elided by default |
| 492 | ** unless the --raw or --prefix options are used. |
| 493 | ** |
| 494 | ** Options: |
| @@ -475,10 +506,12 @@ | |
| 506 | ** be one of: cancel, singleton, propagated |
| 507 | ** --values List tag values |
| 508 | ** If --sep is supplied, list all values of a tag on |
| 509 | ** the same line, separated by SEP; otherwise list |
| 510 | ** each value on its own line. |
| 511 | ** --root As described for 'add' and only if ARTIFACT-ID is |
| 512 | ** provided. |
| 513 | ** |
| 514 | ** The option --raw allows the manipulation of all types of tags |
| 515 | ** used for various internal purposes in fossil. It also shows |
| 516 | ** "cancel" tags for the "find" and "list" subcommands. You should |
| 517 | ** not use this option to make changes unless you are sure what |
| @@ -512,34 +545,38 @@ | |
| 545 | |
| 546 | if( strncmp(g.argv[2],"add",n)==0 ){ |
| 547 | char *zValue; |
| 548 | int dryRun = 0; |
| 549 | int fRaw = find_option("raw","",0)!=0; |
| 550 | int fPropagate = find_option("propagate","",0)!=0; |
| 551 | int fRoot = find_option("root","",0)!=0; |
| 552 | int objType; |
| 553 | int rid; |
| 554 | const char *zPrefix = ""; |
| 555 | const char *zDateOvrd = find_option("date-override",0,1); |
| 556 | const char *zUserOvrd = find_option("user-override",0,1); |
| 557 | const char *zTag; |
| 558 | const char *zObjId; |
| 559 | if( find_option("dry-run","n",0)!=0 ) dryRun = TAG_ADD_DRYRUN; |
| 560 | if( g.argc!=5 && g.argc!=6 ){ |
| 561 | usage("add ?options? TAGNAME ARTIFACT-ID ?VALUE?"); |
| 562 | } |
| 563 | zTag = g.argv[3]; |
| 564 | tag_cmd_tagname_check(zTag); |
| 565 | zObjId = g.argv[4]; |
| 566 | zValue = g.argc==6 ? g.argv[5] : 0; |
| 567 | rid = symbolic_name_to_rid(zObjId, 0); |
| 568 | if( rid<=0 ){ |
| 569 | fossil_fatal("Cannot resolve artifact ID: %s", zObjId); |
| 570 | } |
| 571 | if( fRoot ){ |
| 572 | rid = tag_cmd_root(rid, &zObjId, dryRun); |
| 573 | fPropagate = 1; |
| 574 | } |
| 575 | objType = whatis_rid_type(rid); |
| 576 | if( CFTYPE_MANIFEST==objType ){ |
| 577 | zPrefix = fRaw ? "" : "sym-"; |
| 578 | } |
| 579 | db_begin_transaction(); |
| 580 | tag_add_artifact(zPrefix, zTag, zObjId, zValue, |
| 581 | 1+fPropagate+dryRun,zDateOvrd,zUserOvrd); |
| 582 | db_end_transaction(0); |
| @@ -551,32 +588,35 @@ | |
| 588 | }else |
| 589 | |
| 590 | if( strncmp(g.argv[2],"cancel",n)==0 ){ |
| 591 | int dryRun = 0; |
| 592 | int fRaw = find_option("raw","",0)!=0; |
| 593 | int fRoot = find_option("root","",0)!=0; |
| 594 | int objType; |
| 595 | int rid; |
| 596 | const char *zPrefix = ""; |
| 597 | const char *zDateOvrd = find_option("date-override",0,1); |
| 598 | const char *zUserOvrd = find_option("user-override",0,1); |
| 599 | const char *zTag; |
| 600 | const char *zObjId; |
| 601 | if( find_option("dry-run","n",0)!=0 ) dryRun = TAG_ADD_DRYRUN; |
| 602 | if( g.argc!=5 ){ |
| 603 | usage("cancel ?options? TAGNAME ARTIFACT-ID"); |
| 604 | } |
| 605 | zTag = g.argv[3]; |
| 606 | tag_cmd_tagname_check(zTag); |
| 607 | zObjId = g.argv[4]; |
| 608 | rid = symbolic_name_to_rid(zObjId, 0); |
| 609 | if( rid<=0 ){ |
| 610 | fossil_fatal("Cannot resolve artifact ID: %s", zObjId); |
| 611 | } |
| 612 | if( fRoot ){ |
| 613 | rid = tag_cmd_root(rid, &zObjId, dryRun); |
| 614 | } |
| 615 | objType = whatis_rid_type(rid); |
| 616 | if( CFTYPE_MANIFEST==objType ){ |
| 617 | zPrefix = fRaw ? "" : "sym-"; |
| 618 | } |
| 619 | db_begin_transaction(); |
| 620 | tag_add_artifact(zPrefix, zTag, zObjId, 0, dryRun, |
| 621 | zDateOvrd, zUserOvrd); |
| 622 | db_end_transaction(0); |
| @@ -639,10 +679,11 @@ | |
| 679 | const char *zTagType = find_option("tagtype","t",1); |
| 680 | const int fInverse = find_option("inverse","v",0)!=0; |
| 681 | const char *zTagPrefix = find_option("prefix","",1); |
| 682 | int nTagType = fRaw ? -1 : 0; |
| 683 | int fValues = find_option("values","",0)!=0; |
| 684 | int fRoot = find_option("root","",0)!=0; |
| 685 | const char *zSep = find_option("sep","",1); |
| 686 | |
| 687 | |
| 688 | if( zTagType!=0 ){ |
| 689 | int l = strlen(zTagType); |
| @@ -712,15 +753,19 @@ | |
| 753 | } |
| 754 | } |
| 755 | db_finalize(&q); |
| 756 | }else if( g.argc==4 ){ |
| 757 | char const *zObjId = g.argv[3]; |
| 758 | int rid = name_to_rid(zObjId); |
| 759 | int objType; |
| 760 | int nTagOffset = 0; |
| 761 | |
| 762 | if( fRoot ){ |
| 763 | rid = tag_cmd_root(rid, &zObjId, 0); |
| 764 | } |
| 765 | zTagPrefix = 0; |
| 766 | objType = rid>=0 ? whatis_rid_type(rid) : 0; |
| 767 | if(objType<=0){ |
| 768 | fossil_fatal("Cannot resolve artifact ID: %s", zObjId); |
| 769 | }else if(fRaw==0){ |
| 770 | /* Figure out the tag prefix to strip */ |
| 771 | switch(objType){ |
| @@ -958,16 +1003,51 @@ | |
| 1003 | " AND tagxref.tagid=tag.tagid", |
| 1004 | rid, tagId |
| 1005 | ); |
| 1006 | } |
| 1007 | |
| 1008 | |
| 1009 | /* |
| 1010 | ** If the given blob.rid value has the given tag applied to it, |
| 1011 | ** returns true and sets *pOut to a copy of its value (or NULL if it |
| 1012 | ** has no value). Else returns false and sets *pOut to 0. A truthy |
| 1013 | ** value returned is the associated tag.tagid value. |
| 1014 | ** |
| 1015 | ** Ownership of *pOut is transfered to the caller, who must eventually |
| 1016 | ** fossil_free() it. |
| 1017 | */ |
| 1018 | int rid_has_tag2(int rid, const char *zTag, char **pOut){ |
| 1019 | static Stmt q; |
| 1020 | int rc = 0; |
| 1021 | if( !q.pStmt ){ |
| 1022 | db_prepare( |
| 1023 | &q, "SELECT t.tagid, x.value" |
| 1024 | " FROM tagxref x, tag t" |
| 1025 | " WHERE x.rid=:rid" |
| 1026 | " AND x.tagtype>0" |
| 1027 | " AND x.tagid=t.tagid" |
| 1028 | " AND t.tagname=:name" |
| 1029 | " ORDER BY mtime DESC" |
| 1030 | ); |
| 1031 | } |
| 1032 | *pOut = 0; |
| 1033 | db_bind_int(&q, ":rid", rid); |
| 1034 | db_bind_text(&q, ":name", zTag); |
| 1035 | if( SQLITE_ROW==db_step(&q) ){ |
| 1036 | rc = db_column_int(&q, 0); |
| 1037 | *pOut = fossil_strdup(db_column_text(&q, 1)); |
| 1038 | } |
| 1039 | db_reset(&q); |
| 1040 | return rc; |
| 1041 | } |
| 1042 | |
| 1043 | |
| 1044 | /* |
| 1045 | ** Returns tagxref.rowid if the given blob.rid has a tagxref.rid entry |
| 1046 | ** of an active (non-cancelled) tag matching the given rid and tag |
| 1047 | ** name string, else returns 0. This function does not distinguish |
| 1048 | ** between a non-existent tag and a cancelled tag. |
| 1049 | ** |
| 1050 | ** Design note: the return value is the tagxref.rowid because that |
| 1051 | ** gives us an easy way to fetch the value of the tag later on, if |
| 1052 | ** needed. |
| 1053 | */ |
| 1054 |
+18
| --- src/timeline.c | ||
| +++ src/timeline.c | ||
| @@ -3538,10 +3538,21 @@ | ||
| 3538 | 3538 | zFree = mprintf("[%S] Edit to wiki page \"%s\" (user: %s)", |
| 3539 | 3539 | zId, zComShort+1, zUserShort); |
| 3540 | 3540 | } |
| 3541 | 3541 | }else{ |
| 3542 | 3542 | zFree = mprintf("[%S] %s%s", zId, zPrefix, zCom); |
| 3543 | + | |
| 3544 | + if( get_comment_format() & COMMENT_PRINT_SUMMARY ){ | |
| 3545 | + char *z, *t; | |
| 3546 | + for(z=zFree; *z!='\0'; z++){ | |
| 3547 | + if( *z=='\n' ){ | |
| 3548 | + for(t=z+1; *t!='\0' && *t!='\n' && fossil_isspace(*t); t++){} | |
| 3549 | + if( *t=='\n' ) break; | |
| 3550 | + } | |
| 3551 | + } | |
| 3552 | + *z = '\0'; | |
| 3553 | + } | |
| 3543 | 3554 | } |
| 3544 | 3555 | |
| 3545 | 3556 | if( zFormat ){ |
| 3546 | 3557 | char *zEntry; |
| 3547 | 3558 | int nEntryLine = 0; |
| @@ -3766,10 +3777,11 @@ | ||
| 3766 | 3777 | ** PATH can be a file or a subdirectory. |
| 3767 | 3778 | ** -q|--quiet Do not print notifications at the end of the timeline. |
| 3768 | 3779 | ** -r|--reverse Show items in chronological order. |
| 3769 | 3780 | ** -R REPO_FILE Specifies the repository db to use. Default is |
| 3770 | 3781 | ** the current check-out's repository. |
| 3782 | +** -s|--summmary Truncate comments after the first blank line. | |
| 3771 | 3783 | ** --sql Show the SQL used to generate the timeline |
| 3772 | 3784 | ** -t|--type TYPE Output items from the given types only, such as: |
| 3773 | 3785 | ** ci = file commits only |
| 3774 | 3786 | ** e = technical notes only |
| 3775 | 3787 | ** f = forum posts only |
| @@ -3804,10 +3816,12 @@ | ||
| 3804 | 3816 | const char *zFilePattern = 0; |
| 3805 | 3817 | const char *zFormat = 0; |
| 3806 | 3818 | const char *zBr = 0; |
| 3807 | 3819 | Blob treeName; |
| 3808 | 3820 | int showSql = 0; |
| 3821 | + int bCommentGitStyle = 0; | |
| 3822 | + int oldComFmtFlags = get_comment_format(); | |
| 3809 | 3823 | |
| 3810 | 3824 | verboseFlag = find_option("verbose","v", 0)!=0; |
| 3811 | 3825 | if( !verboseFlag){ |
| 3812 | 3826 | verboseFlag = find_option("showfiles","f", 0)!=0; /* deprecated */ |
| 3813 | 3827 | } |
| @@ -3816,10 +3830,13 @@ | ||
| 3816 | 3830 | zWidth = find_option("width","W",1); |
| 3817 | 3831 | zType = find_option("type","t",1); |
| 3818 | 3832 | zUser = find_option("for-user","u",1); |
| 3819 | 3833 | zFilePattern = find_option("path","p",1); |
| 3820 | 3834 | zFormat = find_option("format","F",1); |
| 3835 | + if( (bCommentGitStyle = (find_option("summary","s",0))!=0) ){ | |
| 3836 | + g.comFmtFlags |= COMMENT_PRINT_SUMMARY; | |
| 3837 | + } | |
| 3821 | 3838 | zBr = find_option("branch","b",1); |
| 3822 | 3839 | if( find_option("current-branch","c",0)!=0 ){ |
| 3823 | 3840 | if( !g.localOpen ){ |
| 3824 | 3841 | fossil_fatal("not within an open check-out"); |
| 3825 | 3842 | }else{ |
| @@ -4030,10 +4047,11 @@ | ||
| 4030 | 4047 | } |
| 4031 | 4048 | db_prepare_blob(&q, &sql); |
| 4032 | 4049 | blob_reset(&sql); |
| 4033 | 4050 | print_timeline(&q, n, width, zFormat, verboseFlag); |
| 4034 | 4051 | db_finalize(&q); |
| 4052 | + g.comFmtFlags = oldComFmtFlags; | |
| 4035 | 4053 | } |
| 4036 | 4054 | |
| 4037 | 4055 | /* |
| 4038 | 4056 | ** WEBPAGE: thisdayinhistory |
| 4039 | 4057 | ** |
| 4040 | 4058 |
| --- src/timeline.c | |
| +++ src/timeline.c | |
| @@ -3538,10 +3538,21 @@ | |
| 3538 | zFree = mprintf("[%S] Edit to wiki page \"%s\" (user: %s)", |
| 3539 | zId, zComShort+1, zUserShort); |
| 3540 | } |
| 3541 | }else{ |
| 3542 | zFree = mprintf("[%S] %s%s", zId, zPrefix, zCom); |
| 3543 | } |
| 3544 | |
| 3545 | if( zFormat ){ |
| 3546 | char *zEntry; |
| 3547 | int nEntryLine = 0; |
| @@ -3766,10 +3777,11 @@ | |
| 3766 | ** PATH can be a file or a subdirectory. |
| 3767 | ** -q|--quiet Do not print notifications at the end of the timeline. |
| 3768 | ** -r|--reverse Show items in chronological order. |
| 3769 | ** -R REPO_FILE Specifies the repository db to use. Default is |
| 3770 | ** the current check-out's repository. |
| 3771 | ** --sql Show the SQL used to generate the timeline |
| 3772 | ** -t|--type TYPE Output items from the given types only, such as: |
| 3773 | ** ci = file commits only |
| 3774 | ** e = technical notes only |
| 3775 | ** f = forum posts only |
| @@ -3804,10 +3816,12 @@ | |
| 3804 | const char *zFilePattern = 0; |
| 3805 | const char *zFormat = 0; |
| 3806 | const char *zBr = 0; |
| 3807 | Blob treeName; |
| 3808 | int showSql = 0; |
| 3809 | |
| 3810 | verboseFlag = find_option("verbose","v", 0)!=0; |
| 3811 | if( !verboseFlag){ |
| 3812 | verboseFlag = find_option("showfiles","f", 0)!=0; /* deprecated */ |
| 3813 | } |
| @@ -3816,10 +3830,13 @@ | |
| 3816 | zWidth = find_option("width","W",1); |
| 3817 | zType = find_option("type","t",1); |
| 3818 | zUser = find_option("for-user","u",1); |
| 3819 | zFilePattern = find_option("path","p",1); |
| 3820 | zFormat = find_option("format","F",1); |
| 3821 | zBr = find_option("branch","b",1); |
| 3822 | if( find_option("current-branch","c",0)!=0 ){ |
| 3823 | if( !g.localOpen ){ |
| 3824 | fossil_fatal("not within an open check-out"); |
| 3825 | }else{ |
| @@ -4030,10 +4047,11 @@ | |
| 4030 | } |
| 4031 | db_prepare_blob(&q, &sql); |
| 4032 | blob_reset(&sql); |
| 4033 | print_timeline(&q, n, width, zFormat, verboseFlag); |
| 4034 | db_finalize(&q); |
| 4035 | } |
| 4036 | |
| 4037 | /* |
| 4038 | ** WEBPAGE: thisdayinhistory |
| 4039 | ** |
| 4040 |
| --- src/timeline.c | |
| +++ src/timeline.c | |
| @@ -3538,10 +3538,21 @@ | |
| 3538 | zFree = mprintf("[%S] Edit to wiki page \"%s\" (user: %s)", |
| 3539 | zId, zComShort+1, zUserShort); |
| 3540 | } |
| 3541 | }else{ |
| 3542 | zFree = mprintf("[%S] %s%s", zId, zPrefix, zCom); |
| 3543 | |
| 3544 | if( get_comment_format() & COMMENT_PRINT_SUMMARY ){ |
| 3545 | char *z, *t; |
| 3546 | for(z=zFree; *z!='\0'; z++){ |
| 3547 | if( *z=='\n' ){ |
| 3548 | for(t=z+1; *t!='\0' && *t!='\n' && fossil_isspace(*t); t++){} |
| 3549 | if( *t=='\n' ) break; |
| 3550 | } |
| 3551 | } |
| 3552 | *z = '\0'; |
| 3553 | } |
| 3554 | } |
| 3555 | |
| 3556 | if( zFormat ){ |
| 3557 | char *zEntry; |
| 3558 | int nEntryLine = 0; |
| @@ -3766,10 +3777,11 @@ | |
| 3777 | ** PATH can be a file or a subdirectory. |
| 3778 | ** -q|--quiet Do not print notifications at the end of the timeline. |
| 3779 | ** -r|--reverse Show items in chronological order. |
| 3780 | ** -R REPO_FILE Specifies the repository db to use. Default is |
| 3781 | ** the current check-out's repository. |
| 3782 | ** -s|--summmary Truncate comments after the first blank line. |
| 3783 | ** --sql Show the SQL used to generate the timeline |
| 3784 | ** -t|--type TYPE Output items from the given types only, such as: |
| 3785 | ** ci = file commits only |
| 3786 | ** e = technical notes only |
| 3787 | ** f = forum posts only |
| @@ -3804,10 +3816,12 @@ | |
| 3816 | const char *zFilePattern = 0; |
| 3817 | const char *zFormat = 0; |
| 3818 | const char *zBr = 0; |
| 3819 | Blob treeName; |
| 3820 | int showSql = 0; |
| 3821 | int bCommentGitStyle = 0; |
| 3822 | int oldComFmtFlags = get_comment_format(); |
| 3823 | |
| 3824 | verboseFlag = find_option("verbose","v", 0)!=0; |
| 3825 | if( !verboseFlag){ |
| 3826 | verboseFlag = find_option("showfiles","f", 0)!=0; /* deprecated */ |
| 3827 | } |
| @@ -3816,10 +3830,13 @@ | |
| 3830 | zWidth = find_option("width","W",1); |
| 3831 | zType = find_option("type","t",1); |
| 3832 | zUser = find_option("for-user","u",1); |
| 3833 | zFilePattern = find_option("path","p",1); |
| 3834 | zFormat = find_option("format","F",1); |
| 3835 | if( (bCommentGitStyle = (find_option("summary","s",0))!=0) ){ |
| 3836 | g.comFmtFlags |= COMMENT_PRINT_SUMMARY; |
| 3837 | } |
| 3838 | zBr = find_option("branch","b",1); |
| 3839 | if( find_option("current-branch","c",0)!=0 ){ |
| 3840 | if( !g.localOpen ){ |
| 3841 | fossil_fatal("not within an open check-out"); |
| 3842 | }else{ |
| @@ -4030,10 +4047,11 @@ | |
| 4047 | } |
| 4048 | db_prepare_blob(&q, &sql); |
| 4049 | blob_reset(&sql); |
| 4050 | print_timeline(&q, n, width, zFormat, verboseFlag); |
| 4051 | db_finalize(&q); |
| 4052 | g.comFmtFlags = oldComFmtFlags; |
| 4053 | } |
| 4054 | |
| 4055 | /* |
| 4056 | ** WEBPAGE: thisdayinhistory |
| 4057 | ** |
| 4058 |
+11
-6
| --- src/tkt.c | ||
| +++ src/tkt.c | ||
| @@ -749,13 +749,16 @@ | ||
| 749 | 749 | } |
| 750 | 750 | } |
| 751 | 751 | if( g.anon.NewTkt ){ |
| 752 | 752 | style_submenu_element("New Ticket", "%R/tktnew"); |
| 753 | 753 | } |
| 754 | + zFullName = db_text(0, | |
| 755 | + "SELECT tkt_uuid FROM ticket" | |
| 756 | + " WHERE tkt_uuid GLOB '%q*'", zUuid); | |
| 754 | 757 | if( g.anon.ApndTkt && g.anon.Attach ){ |
| 755 | - style_submenu_element("Attach", "%R/attachadd?tkt=%T&from=%R/tktview/%t", | |
| 756 | - zUuid, zUuid); | |
| 758 | + style_submenu_element("Attach", "%R/attachadd?target=%T&from=%R/tktview/%t", | |
| 759 | + zFullName, zUuid); | |
| 757 | 760 | } |
| 758 | 761 | if( P("plaintext") ){ |
| 759 | 762 | style_submenu_element("Formatted", "%R/tktview/%s", zUuid); |
| 760 | 763 | }else{ |
| 761 | 764 | style_submenu_element("Plaintext", "%R/tktview/%s?plaintext", zUuid); |
| @@ -773,13 +776,10 @@ | ||
| 773 | 776 | } |
| 774 | 777 | } |
| 775 | 778 | if( !showTimeline && g.perm.Hyperlink ){ |
| 776 | 779 | style_submenu_element("Timeline", "%R/info/%T", zUuid); |
| 777 | 780 | } |
| 778 | - zFullName = db_text(0, | |
| 779 | - "SELECT tkt_uuid FROM ticket" | |
| 780 | - " WHERE tkt_uuid GLOB '%q*'", zUuid); | |
| 781 | 781 | if( g.thTrace ) Th_Trace("BEGIN_TKTVIEW<br>\n", -1); |
| 782 | 782 | ticket_init(); |
| 783 | 783 | initializeVariablesFromCGI(); |
| 784 | 784 | getAllTicketFields(); |
| 785 | 785 | initializeVariablesFromDb(); |
| @@ -789,11 +789,16 @@ | ||
| 789 | 789 | safe_html_context(DOCSRC_TICKET); |
| 790 | 790 | Th_Render(zScript); |
| 791 | 791 | if( g.thTrace ) Th_Trace("END_TKTVIEW<br>\n", -1); |
| 792 | 792 | |
| 793 | 793 | if( zFullName ){ |
| 794 | - attachment_list(zFullName, "<h2>Attachments:</h2>", 1); | |
| 794 | + char * z = mprintf( | |
| 795 | + "<h2><a href='%R/attachlist?tkt=%t'>Attachments</a>:</h2>", | |
| 796 | + zFullName | |
| 797 | + ); | |
| 798 | + attachment_list(zFullName, z, 1); | |
| 799 | + fossil_free(z); | |
| 795 | 800 | } |
| 796 | 801 | |
| 797 | 802 | builtin_fossil_js_bundle_or("dom", "storage", NULL); |
| 798 | 803 | builtin_request_js("fossil.page.ticket.js"); |
| 799 | 804 | builtin_fulfill_js_requests(); |
| 800 | 805 |
| --- src/tkt.c | |
| +++ src/tkt.c | |
| @@ -749,13 +749,16 @@ | |
| 749 | } |
| 750 | } |
| 751 | if( g.anon.NewTkt ){ |
| 752 | style_submenu_element("New Ticket", "%R/tktnew"); |
| 753 | } |
| 754 | if( g.anon.ApndTkt && g.anon.Attach ){ |
| 755 | style_submenu_element("Attach", "%R/attachadd?tkt=%T&from=%R/tktview/%t", |
| 756 | zUuid, zUuid); |
| 757 | } |
| 758 | if( P("plaintext") ){ |
| 759 | style_submenu_element("Formatted", "%R/tktview/%s", zUuid); |
| 760 | }else{ |
| 761 | style_submenu_element("Plaintext", "%R/tktview/%s?plaintext", zUuid); |
| @@ -773,13 +776,10 @@ | |
| 773 | } |
| 774 | } |
| 775 | if( !showTimeline && g.perm.Hyperlink ){ |
| 776 | style_submenu_element("Timeline", "%R/info/%T", zUuid); |
| 777 | } |
| 778 | zFullName = db_text(0, |
| 779 | "SELECT tkt_uuid FROM ticket" |
| 780 | " WHERE tkt_uuid GLOB '%q*'", zUuid); |
| 781 | if( g.thTrace ) Th_Trace("BEGIN_TKTVIEW<br>\n", -1); |
| 782 | ticket_init(); |
| 783 | initializeVariablesFromCGI(); |
| 784 | getAllTicketFields(); |
| 785 | initializeVariablesFromDb(); |
| @@ -789,11 +789,16 @@ | |
| 789 | safe_html_context(DOCSRC_TICKET); |
| 790 | Th_Render(zScript); |
| 791 | if( g.thTrace ) Th_Trace("END_TKTVIEW<br>\n", -1); |
| 792 | |
| 793 | if( zFullName ){ |
| 794 | attachment_list(zFullName, "<h2>Attachments:</h2>", 1); |
| 795 | } |
| 796 | |
| 797 | builtin_fossil_js_bundle_or("dom", "storage", NULL); |
| 798 | builtin_request_js("fossil.page.ticket.js"); |
| 799 | builtin_fulfill_js_requests(); |
| 800 |
| --- src/tkt.c | |
| +++ src/tkt.c | |
| @@ -749,13 +749,16 @@ | |
| 749 | } |
| 750 | } |
| 751 | if( g.anon.NewTkt ){ |
| 752 | style_submenu_element("New Ticket", "%R/tktnew"); |
| 753 | } |
| 754 | zFullName = db_text(0, |
| 755 | "SELECT tkt_uuid FROM ticket" |
| 756 | " WHERE tkt_uuid GLOB '%q*'", zUuid); |
| 757 | if( g.anon.ApndTkt && g.anon.Attach ){ |
| 758 | style_submenu_element("Attach", "%R/attachadd?target=%T&from=%R/tktview/%t", |
| 759 | zFullName, zUuid); |
| 760 | } |
| 761 | if( P("plaintext") ){ |
| 762 | style_submenu_element("Formatted", "%R/tktview/%s", zUuid); |
| 763 | }else{ |
| 764 | style_submenu_element("Plaintext", "%R/tktview/%s?plaintext", zUuid); |
| @@ -773,13 +776,10 @@ | |
| 776 | } |
| 777 | } |
| 778 | if( !showTimeline && g.perm.Hyperlink ){ |
| 779 | style_submenu_element("Timeline", "%R/info/%T", zUuid); |
| 780 | } |
| 781 | if( g.thTrace ) Th_Trace("BEGIN_TKTVIEW<br>\n", -1); |
| 782 | ticket_init(); |
| 783 | initializeVariablesFromCGI(); |
| 784 | getAllTicketFields(); |
| 785 | initializeVariablesFromDb(); |
| @@ -789,11 +789,16 @@ | |
| 789 | safe_html_context(DOCSRC_TICKET); |
| 790 | Th_Render(zScript); |
| 791 | if( g.thTrace ) Th_Trace("END_TKTVIEW<br>\n", -1); |
| 792 | |
| 793 | if( zFullName ){ |
| 794 | char * z = mprintf( |
| 795 | "<h2><a href='%R/attachlist?tkt=%t'>Attachments</a>:</h2>", |
| 796 | zFullName |
| 797 | ); |
| 798 | attachment_list(zFullName, z, 1); |
| 799 | fossil_free(z); |
| 800 | } |
| 801 | |
| 802 | builtin_fossil_js_bundle_or("dom", "storage", NULL); |
| 803 | builtin_request_js("fossil.page.ticket.js"); |
| 804 | builtin_fulfill_js_requests(); |
| 805 |
+2
-2
| --- src/util.c | ||
| +++ src/util.c | ||
| @@ -917,12 +917,12 @@ | ||
| 917 | 917 | unsigned char zStr[37]; |
| 918 | 918 | unsigned char *p = zStr; |
| 919 | 919 | int i, k; |
| 920 | 920 | |
| 921 | 921 | sqlite3_randomness(16, aBlob); |
| 922 | - aBlob[6] = (aBlob[6]&0x0f) + 0x40; /* Version byte: 0100 xxxx */ | |
| 923 | - aBlob[8] = (aBlob[8]&0x3f) + 0x80; /* Variant byte: 10xx xxxx */ | |
| 922 | + aBlob[6] = (aBlob[6]&0x0f) | 0x40; /* Version byte: 0100 xxxx */ | |
| 923 | + aBlob[8] = (aBlob[8]&0x3f) | 0x80; /* Variant byte: 10xx xxxx */ | |
| 924 | 924 | |
| 925 | 925 | for(i=0, k=0x550; i<16; i++, k=k>>1){ |
| 926 | 926 | if( k&1 ){ |
| 927 | 927 | *p++ = '-'; /* Add a dash after byte 4, 6, 8, and 12 */ |
| 928 | 928 | } |
| 929 | 929 |
| --- src/util.c | |
| +++ src/util.c | |
| @@ -917,12 +917,12 @@ | |
| 917 | unsigned char zStr[37]; |
| 918 | unsigned char *p = zStr; |
| 919 | int i, k; |
| 920 | |
| 921 | sqlite3_randomness(16, aBlob); |
| 922 | aBlob[6] = (aBlob[6]&0x0f) + 0x40; /* Version byte: 0100 xxxx */ |
| 923 | aBlob[8] = (aBlob[8]&0x3f) + 0x80; /* Variant byte: 10xx xxxx */ |
| 924 | |
| 925 | for(i=0, k=0x550; i<16; i++, k=k>>1){ |
| 926 | if( k&1 ){ |
| 927 | *p++ = '-'; /* Add a dash after byte 4, 6, 8, and 12 */ |
| 928 | } |
| 929 |
| --- src/util.c | |
| +++ src/util.c | |
| @@ -917,12 +917,12 @@ | |
| 917 | unsigned char zStr[37]; |
| 918 | unsigned char *p = zStr; |
| 919 | int i, k; |
| 920 | |
| 921 | sqlite3_randomness(16, aBlob); |
| 922 | aBlob[6] = (aBlob[6]&0x0f) | 0x40; /* Version byte: 0100 xxxx */ |
| 923 | aBlob[8] = (aBlob[8]&0x3f) | 0x80; /* Variant byte: 10xx xxxx */ |
| 924 | |
| 925 | for(i=0, k=0x550; i<16; i++, k=k>>1){ |
| 926 | if( k&1 ){ |
| 927 | *p++ = '-'; /* Add a dash after byte 4, 6, 8, and 12 */ |
| 928 | } |
| 929 |
+11
-39
| --- src/wiki.c | ||
| +++ src/wiki.c | ||
| @@ -670,10 +670,14 @@ | ||
| 670 | 670 | style_submenu_element("Edit", "%R/wikiappend?name=%T", zPageName); |
| 671 | 671 | } |
| 672 | 672 | if( g.perm.Hyperlink ){ |
| 673 | 673 | style_submenu_element("History", "%R/whistory?name=%T", zPageName); |
| 674 | 674 | } |
| 675 | + if( rid>0 && attach_user_may(rid, CFTYPE_WIKI) ){ | |
| 676 | + style_submenu_element("Attach", "%R/attachadd?target=%T", | |
| 677 | + zPageName); | |
| 678 | + } | |
| 675 | 679 | } |
| 676 | 680 | if( !isPopup ){ |
| 677 | 681 | style_set_current_page("%T?name=%T", g.zPath, zPageName); |
| 678 | 682 | wiki_page_header(WIKITYPE_UNKNOWN, zPageName, ""); |
| 679 | 683 | if( !noSubmenu ){ |
| @@ -870,49 +874,15 @@ | ||
| 870 | 874 | ** mtime order. |
| 871 | 875 | */ |
| 872 | 876 | static void wiki_ajax_emit_page_attachments(Manifest * pWiki, |
| 873 | 877 | int latestOnly, |
| 874 | 878 | int nullIfEmpty){ |
| 875 | - int i = 0; | |
| 876 | - Stmt q = empty_Stmt; | |
| 877 | - db_prepare(&q, | |
| 878 | - "SELECT datetime(mtime), src, target, filename, isLatest," | |
| 879 | - " (SELECT uuid FROM blob WHERE rid=attachid) uuid" | |
| 880 | - " FROM attachment" | |
| 881 | - " WHERE target=%Q" | |
| 882 | - " AND (isLatest OR %d)" | |
| 883 | - " ORDER BY target, isLatest DESC, mtime DESC", | |
| 884 | - pWiki->zWikiTitle, !latestOnly | |
| 885 | - ); | |
| 886 | - while(SQLITE_ROW == db_step(&q)){ | |
| 887 | - const char * zTime = db_column_text(&q, 0); | |
| 888 | - const char * zSrc = db_column_text(&q, 1); | |
| 889 | - const char * zTarget = db_column_text(&q, 2); | |
| 890 | - const char * zName = db_column_text(&q, 3); | |
| 891 | - const int isLatest = db_column_int(&q, 4); | |
| 892 | - const char * zUuid = db_column_text(&q, 5); | |
| 893 | - if(!i++){ | |
| 894 | - CX("["); | |
| 895 | - }else{ | |
| 896 | - CX(","); | |
| 897 | - } | |
| 898 | - CX("{"); | |
| 899 | - CX("\"uuid\": %!j, \"src\": %!j, \"target\": %!j, " | |
| 900 | - "\"filename\": %!j, \"mtime\": %!j, \"isLatest\": %s}", | |
| 901 | - zUuid, zSrc, zTarget, | |
| 902 | - zName, zTime, isLatest ? "true" : "false"); | |
| 903 | - } | |
| 904 | - db_finalize(&q); | |
| 905 | - if(!i){ | |
| 906 | - if(nullIfEmpty){ | |
| 907 | - CX("null"); | |
| 908 | - }else{ | |
| 909 | - CX("[]"); | |
| 910 | - } | |
| 911 | - }else{ | |
| 912 | - CX("]"); | |
| 913 | - } | |
| 879 | + Blob b = BLOB_INITIALIZER; | |
| 880 | + attachments_to_json(pWiki, &b, latestOnly, | |
| 881 | + nullIfEmpty ? -1 : 1); | |
| 882 | + CX("%b", &b); | |
| 883 | + blob_reset(&b); | |
| 914 | 884 | } |
| 915 | 885 | |
| 916 | 886 | /* |
| 917 | 887 | ** Proxy for wiki_ajax_emit_page_attachments() which attempts to load |
| 918 | 888 | ** the given wiki page artifact. Returns true if it can load the given |
| @@ -1183,10 +1153,12 @@ | ||
| 1183 | 1153 | ** |
| 1184 | 1154 | ** URL params: |
| 1185 | 1155 | ** |
| 1186 | 1156 | ** mimetype = the wiki page mimetype (determines rendering style) |
| 1187 | 1157 | ** content = the wiki page content |
| 1158 | +** | |
| 1159 | +** Responds with a partial HTML document. | |
| 1188 | 1160 | */ |
| 1189 | 1161 | static void wiki_ajax_route_preview(void){ |
| 1190 | 1162 | const char * zContent = P("content"); |
| 1191 | 1163 | |
| 1192 | 1164 | if( zContent==0 ){ |
| 1193 | 1165 |
| --- src/wiki.c | |
| +++ src/wiki.c | |
| @@ -670,10 +670,14 @@ | |
| 670 | style_submenu_element("Edit", "%R/wikiappend?name=%T", zPageName); |
| 671 | } |
| 672 | if( g.perm.Hyperlink ){ |
| 673 | style_submenu_element("History", "%R/whistory?name=%T", zPageName); |
| 674 | } |
| 675 | } |
| 676 | if( !isPopup ){ |
| 677 | style_set_current_page("%T?name=%T", g.zPath, zPageName); |
| 678 | wiki_page_header(WIKITYPE_UNKNOWN, zPageName, ""); |
| 679 | if( !noSubmenu ){ |
| @@ -870,49 +874,15 @@ | |
| 870 | ** mtime order. |
| 871 | */ |
| 872 | static void wiki_ajax_emit_page_attachments(Manifest * pWiki, |
| 873 | int latestOnly, |
| 874 | int nullIfEmpty){ |
| 875 | int i = 0; |
| 876 | Stmt q = empty_Stmt; |
| 877 | db_prepare(&q, |
| 878 | "SELECT datetime(mtime), src, target, filename, isLatest," |
| 879 | " (SELECT uuid FROM blob WHERE rid=attachid) uuid" |
| 880 | " FROM attachment" |
| 881 | " WHERE target=%Q" |
| 882 | " AND (isLatest OR %d)" |
| 883 | " ORDER BY target, isLatest DESC, mtime DESC", |
| 884 | pWiki->zWikiTitle, !latestOnly |
| 885 | ); |
| 886 | while(SQLITE_ROW == db_step(&q)){ |
| 887 | const char * zTime = db_column_text(&q, 0); |
| 888 | const char * zSrc = db_column_text(&q, 1); |
| 889 | const char * zTarget = db_column_text(&q, 2); |
| 890 | const char * zName = db_column_text(&q, 3); |
| 891 | const int isLatest = db_column_int(&q, 4); |
| 892 | const char * zUuid = db_column_text(&q, 5); |
| 893 | if(!i++){ |
| 894 | CX("["); |
| 895 | }else{ |
| 896 | CX(","); |
| 897 | } |
| 898 | CX("{"); |
| 899 | CX("\"uuid\": %!j, \"src\": %!j, \"target\": %!j, " |
| 900 | "\"filename\": %!j, \"mtime\": %!j, \"isLatest\": %s}", |
| 901 | zUuid, zSrc, zTarget, |
| 902 | zName, zTime, isLatest ? "true" : "false"); |
| 903 | } |
| 904 | db_finalize(&q); |
| 905 | if(!i){ |
| 906 | if(nullIfEmpty){ |
| 907 | CX("null"); |
| 908 | }else{ |
| 909 | CX("[]"); |
| 910 | } |
| 911 | }else{ |
| 912 | CX("]"); |
| 913 | } |
| 914 | } |
| 915 | |
| 916 | /* |
| 917 | ** Proxy for wiki_ajax_emit_page_attachments() which attempts to load |
| 918 | ** the given wiki page artifact. Returns true if it can load the given |
| @@ -1183,10 +1153,12 @@ | |
| 1183 | ** |
| 1184 | ** URL params: |
| 1185 | ** |
| 1186 | ** mimetype = the wiki page mimetype (determines rendering style) |
| 1187 | ** content = the wiki page content |
| 1188 | */ |
| 1189 | static void wiki_ajax_route_preview(void){ |
| 1190 | const char * zContent = P("content"); |
| 1191 | |
| 1192 | if( zContent==0 ){ |
| 1193 |
| --- src/wiki.c | |
| +++ src/wiki.c | |
| @@ -670,10 +670,14 @@ | |
| 670 | style_submenu_element("Edit", "%R/wikiappend?name=%T", zPageName); |
| 671 | } |
| 672 | if( g.perm.Hyperlink ){ |
| 673 | style_submenu_element("History", "%R/whistory?name=%T", zPageName); |
| 674 | } |
| 675 | if( rid>0 && attach_user_may(rid, CFTYPE_WIKI) ){ |
| 676 | style_submenu_element("Attach", "%R/attachadd?target=%T", |
| 677 | zPageName); |
| 678 | } |
| 679 | } |
| 680 | if( !isPopup ){ |
| 681 | style_set_current_page("%T?name=%T", g.zPath, zPageName); |
| 682 | wiki_page_header(WIKITYPE_UNKNOWN, zPageName, ""); |
| 683 | if( !noSubmenu ){ |
| @@ -870,49 +874,15 @@ | |
| 874 | ** mtime order. |
| 875 | */ |
| 876 | static void wiki_ajax_emit_page_attachments(Manifest * pWiki, |
| 877 | int latestOnly, |
| 878 | int nullIfEmpty){ |
| 879 | Blob b = BLOB_INITIALIZER; |
| 880 | attachments_to_json(pWiki, &b, latestOnly, |
| 881 | nullIfEmpty ? -1 : 1); |
| 882 | CX("%b", &b); |
| 883 | blob_reset(&b); |
| 884 | } |
| 885 | |
| 886 | /* |
| 887 | ** Proxy for wiki_ajax_emit_page_attachments() which attempts to load |
| 888 | ** the given wiki page artifact. Returns true if it can load the given |
| @@ -1183,10 +1153,12 @@ | |
| 1153 | ** |
| 1154 | ** URL params: |
| 1155 | ** |
| 1156 | ** mimetype = the wiki page mimetype (determines rendering style) |
| 1157 | ** content = the wiki page content |
| 1158 | ** |
| 1159 | ** Responds with a partial HTML document. |
| 1160 | */ |
| 1161 | static void wiki_ajax_route_preview(void){ |
| 1162 | const char * zContent = P("content"); |
| 1163 | |
| 1164 | if( zContent==0 ){ |
| 1165 |
+11
-39
| --- src/wiki.c | ||
| +++ src/wiki.c | ||
| @@ -670,10 +670,14 @@ | ||
| 670 | 670 | style_submenu_element("Edit", "%R/wikiappend?name=%T", zPageName); |
| 671 | 671 | } |
| 672 | 672 | if( g.perm.Hyperlink ){ |
| 673 | 673 | style_submenu_element("History", "%R/whistory?name=%T", zPageName); |
| 674 | 674 | } |
| 675 | + if( rid>0 && attach_user_may(rid, CFTYPE_WIKI) ){ | |
| 676 | + style_submenu_element("Attach", "%R/attachadd?target=%T", | |
| 677 | + zPageName); | |
| 678 | + } | |
| 675 | 679 | } |
| 676 | 680 | if( !isPopup ){ |
| 677 | 681 | style_set_current_page("%T?name=%T", g.zPath, zPageName); |
| 678 | 682 | wiki_page_header(WIKITYPE_UNKNOWN, zPageName, ""); |
| 679 | 683 | if( !noSubmenu ){ |
| @@ -870,49 +874,15 @@ | ||
| 870 | 874 | ** mtime order. |
| 871 | 875 | */ |
| 872 | 876 | static void wiki_ajax_emit_page_attachments(Manifest * pWiki, |
| 873 | 877 | int latestOnly, |
| 874 | 878 | int nullIfEmpty){ |
| 875 | - int i = 0; | |
| 876 | - Stmt q = empty_Stmt; | |
| 877 | - db_prepare(&q, | |
| 878 | - "SELECT datetime(mtime), src, target, filename, isLatest," | |
| 879 | - " (SELECT uuid FROM blob WHERE rid=attachid) uuid" | |
| 880 | - " FROM attachment" | |
| 881 | - " WHERE target=%Q" | |
| 882 | - " AND (isLatest OR %d)" | |
| 883 | - " ORDER BY target, isLatest DESC, mtime DESC", | |
| 884 | - pWiki->zWikiTitle, !latestOnly | |
| 885 | - ); | |
| 886 | - while(SQLITE_ROW == db_step(&q)){ | |
| 887 | - const char * zTime = db_column_text(&q, 0); | |
| 888 | - const char * zSrc = db_column_text(&q, 1); | |
| 889 | - const char * zTarget = db_column_text(&q, 2); | |
| 890 | - const char * zName = db_column_text(&q, 3); | |
| 891 | - const int isLatest = db_column_int(&q, 4); | |
| 892 | - const char * zUuid = db_column_text(&q, 5); | |
| 893 | - if(!i++){ | |
| 894 | - CX("["); | |
| 895 | - }else{ | |
| 896 | - CX(","); | |
| 897 | - } | |
| 898 | - CX("{"); | |
| 899 | - CX("\"uuid\": %!j, \"src\": %!j, \"target\": %!j, " | |
| 900 | - "\"filename\": %!j, \"mtime\": %!j, \"isLatest\": %s}", | |
| 901 | - zUuid, zSrc, zTarget, | |
| 902 | - zName, zTime, isLatest ? "true" : "false"); | |
| 903 | - } | |
| 904 | - db_finalize(&q); | |
| 905 | - if(!i){ | |
| 906 | - if(nullIfEmpty){ | |
| 907 | - CX("null"); | |
| 908 | - }else{ | |
| 909 | - CX("[]"); | |
| 910 | - } | |
| 911 | - }else{ | |
| 912 | - CX("]"); | |
| 913 | - } | |
| 879 | + Blob b = BLOB_INITIALIZER; | |
| 880 | + attachments_to_json(pWiki, &b, latestOnly, | |
| 881 | + nullIfEmpty ? -1 : 1); | |
| 882 | + CX("%b", &b); | |
| 883 | + blob_reset(&b); | |
| 914 | 884 | } |
| 915 | 885 | |
| 916 | 886 | /* |
| 917 | 887 | ** Proxy for wiki_ajax_emit_page_attachments() which attempts to load |
| 918 | 888 | ** the given wiki page artifact. Returns true if it can load the given |
| @@ -1183,10 +1153,12 @@ | ||
| 1183 | 1153 | ** |
| 1184 | 1154 | ** URL params: |
| 1185 | 1155 | ** |
| 1186 | 1156 | ** mimetype = the wiki page mimetype (determines rendering style) |
| 1187 | 1157 | ** content = the wiki page content |
| 1158 | +** | |
| 1159 | +** Responds with a partial HTML document. | |
| 1188 | 1160 | */ |
| 1189 | 1161 | static void wiki_ajax_route_preview(void){ |
| 1190 | 1162 | const char * zContent = P("content"); |
| 1191 | 1163 | |
| 1192 | 1164 | if( zContent==0 ){ |
| 1193 | 1165 |
| --- src/wiki.c | |
| +++ src/wiki.c | |
| @@ -670,10 +670,14 @@ | |
| 670 | style_submenu_element("Edit", "%R/wikiappend?name=%T", zPageName); |
| 671 | } |
| 672 | if( g.perm.Hyperlink ){ |
| 673 | style_submenu_element("History", "%R/whistory?name=%T", zPageName); |
| 674 | } |
| 675 | } |
| 676 | if( !isPopup ){ |
| 677 | style_set_current_page("%T?name=%T", g.zPath, zPageName); |
| 678 | wiki_page_header(WIKITYPE_UNKNOWN, zPageName, ""); |
| 679 | if( !noSubmenu ){ |
| @@ -870,49 +874,15 @@ | |
| 870 | ** mtime order. |
| 871 | */ |
| 872 | static void wiki_ajax_emit_page_attachments(Manifest * pWiki, |
| 873 | int latestOnly, |
| 874 | int nullIfEmpty){ |
| 875 | int i = 0; |
| 876 | Stmt q = empty_Stmt; |
| 877 | db_prepare(&q, |
| 878 | "SELECT datetime(mtime), src, target, filename, isLatest," |
| 879 | " (SELECT uuid FROM blob WHERE rid=attachid) uuid" |
| 880 | " FROM attachment" |
| 881 | " WHERE target=%Q" |
| 882 | " AND (isLatest OR %d)" |
| 883 | " ORDER BY target, isLatest DESC, mtime DESC", |
| 884 | pWiki->zWikiTitle, !latestOnly |
| 885 | ); |
| 886 | while(SQLITE_ROW == db_step(&q)){ |
| 887 | const char * zTime = db_column_text(&q, 0); |
| 888 | const char * zSrc = db_column_text(&q, 1); |
| 889 | const char * zTarget = db_column_text(&q, 2); |
| 890 | const char * zName = db_column_text(&q, 3); |
| 891 | const int isLatest = db_column_int(&q, 4); |
| 892 | const char * zUuid = db_column_text(&q, 5); |
| 893 | if(!i++){ |
| 894 | CX("["); |
| 895 | }else{ |
| 896 | CX(","); |
| 897 | } |
| 898 | CX("{"); |
| 899 | CX("\"uuid\": %!j, \"src\": %!j, \"target\": %!j, " |
| 900 | "\"filename\": %!j, \"mtime\": %!j, \"isLatest\": %s}", |
| 901 | zUuid, zSrc, zTarget, |
| 902 | zName, zTime, isLatest ? "true" : "false"); |
| 903 | } |
| 904 | db_finalize(&q); |
| 905 | if(!i){ |
| 906 | if(nullIfEmpty){ |
| 907 | CX("null"); |
| 908 | }else{ |
| 909 | CX("[]"); |
| 910 | } |
| 911 | }else{ |
| 912 | CX("]"); |
| 913 | } |
| 914 | } |
| 915 | |
| 916 | /* |
| 917 | ** Proxy for wiki_ajax_emit_page_attachments() which attempts to load |
| 918 | ** the given wiki page artifact. Returns true if it can load the given |
| @@ -1183,10 +1153,12 @@ | |
| 1183 | ** |
| 1184 | ** URL params: |
| 1185 | ** |
| 1186 | ** mimetype = the wiki page mimetype (determines rendering style) |
| 1187 | ** content = the wiki page content |
| 1188 | */ |
| 1189 | static void wiki_ajax_route_preview(void){ |
| 1190 | const char * zContent = P("content"); |
| 1191 | |
| 1192 | if( zContent==0 ){ |
| 1193 |
| --- src/wiki.c | |
| +++ src/wiki.c | |
| @@ -670,10 +670,14 @@ | |
| 670 | style_submenu_element("Edit", "%R/wikiappend?name=%T", zPageName); |
| 671 | } |
| 672 | if( g.perm.Hyperlink ){ |
| 673 | style_submenu_element("History", "%R/whistory?name=%T", zPageName); |
| 674 | } |
| 675 | if( rid>0 && attach_user_may(rid, CFTYPE_WIKI) ){ |
| 676 | style_submenu_element("Attach", "%R/attachadd?target=%T", |
| 677 | zPageName); |
| 678 | } |
| 679 | } |
| 680 | if( !isPopup ){ |
| 681 | style_set_current_page("%T?name=%T", g.zPath, zPageName); |
| 682 | wiki_page_header(WIKITYPE_UNKNOWN, zPageName, ""); |
| 683 | if( !noSubmenu ){ |
| @@ -870,49 +874,15 @@ | |
| 874 | ** mtime order. |
| 875 | */ |
| 876 | static void wiki_ajax_emit_page_attachments(Manifest * pWiki, |
| 877 | int latestOnly, |
| 878 | int nullIfEmpty){ |
| 879 | Blob b = BLOB_INITIALIZER; |
| 880 | attachments_to_json(pWiki, &b, latestOnly, |
| 881 | nullIfEmpty ? -1 : 1); |
| 882 | CX("%b", &b); |
| 883 | blob_reset(&b); |
| 884 | } |
| 885 | |
| 886 | /* |
| 887 | ** Proxy for wiki_ajax_emit_page_attachments() which attempts to load |
| 888 | ** the given wiki page artifact. Returns true if it can load the given |
| @@ -1183,10 +1153,12 @@ | |
| 1153 | ** |
| 1154 | ** URL params: |
| 1155 | ** |
| 1156 | ** mimetype = the wiki page mimetype (determines rendering style) |
| 1157 | ** content = the wiki page content |
| 1158 | ** |
| 1159 | ** Responds with a partial HTML document. |
| 1160 | */ |
| 1161 | static void wiki_ajax_route_preview(void){ |
| 1162 | const char * zContent = P("content"); |
| 1163 | |
| 1164 | if( zContent==0 ){ |
| 1165 |
+16
-15
| --- src/wiki.wiki | ||
| +++ src/wiki.wiki | ||
| @@ -55,25 +55,26 @@ | ||
| 55 | 55 | <nowiki>[#anchor-name],</nowiki> providing you have added the necessary |
| 56 | 56 | "<a name='anchor-name'></a>" tag to your wiki page. |
| 57 | 57 | |
| 58 | 58 | 6. <b>HTML.</b> |
| 59 | 59 | The following standard HTML elements may be used: |
| 60 | - <a> <address> <article> <aside> <b> | |
| 61 | - <big> <blockquote> <br> <center> <cite> | |
| 62 | - <code> <col> <colgroup> <dd> | |
| 63 | - <del> <dfn> | |
| 64 | - <div> <dl> <dt> <em> <font> <footer> | |
| 65 | - <ins> | |
| 66 | - <h1> <h2> <h3> <h4> <h5> <h6> | |
| 67 | - <header> <hr> <i> <img> <kbd> <li> | |
| 68 | - <nav> <nobr> <nowiki> <ol> <p> <pre> | |
| 69 | - <s> <samp> <section> <small> <span> | |
| 70 | - <strike> <strong> <sub> <sup> <table> | |
| 71 | - <tbody> <td> <tfoot> <th> <thead> | |
| 72 | - <title> <tr> <tt> <u> <ul> <var> | |
| 73 | - <verbatim>. There are two non-standard elements available: | |
| 74 | - <verbatim> and <nowiki>. No other elements are allowed. | |
| 60 | + <a> <abbr> <address> <article> <aside> | |
| 61 | + <b> <big> <blockquote> <br> <caption> | |
| 62 | + <center> <cite> <code> <col> <colgroup> | |
| 63 | + <dd> <del> <details> <dfn> <div> <dl> | |
| 64 | + <dt> <em> <figcaption> <figure> <font> | |
| 65 | + <footer> <h1> <h2> <h3> <h4> <h5> | |
| 66 | + <h6> <header> <hr> <i> <img> <ins> | |
| 67 | + <kbd> <label> <li> <mark> <meter> <nav> | |
| 68 | + <nobr> <nowiki> <ol> <p> <picture> <pre> | |
| 69 | + <progress> <q> <s> <samp> <section> <small> | |
| 70 | + <source> <span> <strike> <strong> <sub> | |
| 71 | + <summary> <sup> <table> <tbody> <td> | |
| 72 | + <tfoot> <th> <thead> <time> <title> <tr> | |
| 73 | + <tt> <u> <ul> <var> <wbr> <verbatim>. | |
| 74 | + There are two non-standard elements available: <verbatim> and | |
| 75 | + <nowiki>. No other elements are allowed. | |
| 75 | 76 | All attributes are checked and only a few benign attributes are |
| 76 | 77 | allowed on each element. In particular, any attributes that specify |
| 77 | 78 | javascript or CSS are elided. |
| 78 | 79 | |
| 79 | 80 | 7. <b>Special Markup.</b> |
| 80 | 81 |
| --- src/wiki.wiki | |
| +++ src/wiki.wiki | |
| @@ -55,25 +55,26 @@ | |
| 55 | <nowiki>[#anchor-name],</nowiki> providing you have added the necessary |
| 56 | "<a name='anchor-name'></a>" tag to your wiki page. |
| 57 | |
| 58 | 6. <b>HTML.</b> |
| 59 | The following standard HTML elements may be used: |
| 60 | <a> <address> <article> <aside> <b> |
| 61 | <big> <blockquote> <br> <center> <cite> |
| 62 | <code> <col> <colgroup> <dd> |
| 63 | <del> <dfn> |
| 64 | <div> <dl> <dt> <em> <font> <footer> |
| 65 | <ins> |
| 66 | <h1> <h2> <h3> <h4> <h5> <h6> |
| 67 | <header> <hr> <i> <img> <kbd> <li> |
| 68 | <nav> <nobr> <nowiki> <ol> <p> <pre> |
| 69 | <s> <samp> <section> <small> <span> |
| 70 | <strike> <strong> <sub> <sup> <table> |
| 71 | <tbody> <td> <tfoot> <th> <thead> |
| 72 | <title> <tr> <tt> <u> <ul> <var> |
| 73 | <verbatim>. There are two non-standard elements available: |
| 74 | <verbatim> and <nowiki>. No other elements are allowed. |
| 75 | All attributes are checked and only a few benign attributes are |
| 76 | allowed on each element. In particular, any attributes that specify |
| 77 | javascript or CSS are elided. |
| 78 | |
| 79 | 7. <b>Special Markup.</b> |
| 80 |
| --- src/wiki.wiki | |
| +++ src/wiki.wiki | |
| @@ -55,25 +55,26 @@ | |
| 55 | <nowiki>[#anchor-name],</nowiki> providing you have added the necessary |
| 56 | "<a name='anchor-name'></a>" tag to your wiki page. |
| 57 | |
| 58 | 6. <b>HTML.</b> |
| 59 | The following standard HTML elements may be used: |
| 60 | <a> <abbr> <address> <article> <aside> |
| 61 | <b> <big> <blockquote> <br> <caption> |
| 62 | <center> <cite> <code> <col> <colgroup> |
| 63 | <dd> <del> <details> <dfn> <div> <dl> |
| 64 | <dt> <em> <figcaption> <figure> <font> |
| 65 | <footer> <h1> <h2> <h3> <h4> <h5> |
| 66 | <h6> <header> <hr> <i> <img> <ins> |
| 67 | <kbd> <label> <li> <mark> <meter> <nav> |
| 68 | <nobr> <nowiki> <ol> <p> <picture> <pre> |
| 69 | <progress> <q> <s> <samp> <section> <small> |
| 70 | <source> <span> <strike> <strong> <sub> |
| 71 | <summary> <sup> <table> <tbody> <td> |
| 72 | <tfoot> <th> <thead> <time> <title> <tr> |
| 73 | <tt> <u> <ul> <var> <wbr> <verbatim>. |
| 74 | There are two non-standard elements available: <verbatim> and |
| 75 | <nowiki>. No other elements are allowed. |
| 76 | All attributes are checked and only a few benign attributes are |
| 77 | allowed on each element. In particular, any attributes that specify |
| 78 | javascript or CSS are elided. |
| 79 | |
| 80 | 7. <b>Special Markup.</b> |
| 81 |
+115
-43
| --- src/wikiformat.c | ||
| +++ src/wikiformat.c | ||
| @@ -68,25 +68,37 @@ | ||
| 68 | 68 | ATTR_ALT, |
| 69 | 69 | ATTR_BGCOLOR, |
| 70 | 70 | ATTR_BORDER, |
| 71 | 71 | ATTR_CELLPADDING, |
| 72 | 72 | ATTR_CELLSPACING, |
| 73 | + ATTR_CITE, | |
| 73 | 74 | ATTR_CLASS, |
| 74 | 75 | ATTR_CLEAR, |
| 75 | 76 | ATTR_COLOR, |
| 76 | 77 | ATTR_COLSPAN, |
| 77 | 78 | ATTR_COMPACT, |
| 79 | + ATTR_DATETIME, | |
| 78 | 80 | ATTR_FACE, |
| 81 | + ATTR_FOR, | |
| 79 | 82 | ATTR_HEIGHT, |
| 83 | + ATTR_HIGH, | |
| 80 | 84 | ATTR_HREF, |
| 81 | 85 | ATTR_HSPACE, |
| 82 | 86 | ATTR_ID, |
| 83 | 87 | ATTR_LINKS, |
| 88 | + ATTR_LOW, | |
| 89 | + ATTR_MAX, | |
| 90 | + ATTR_MEDIA, | |
| 91 | + ATTR_MIN, | |
| 84 | 92 | ATTR_NAME, |
| 93 | + ATTR_OPEN, | |
| 94 | + ATTR_OPTIMUM, | |
| 85 | 95 | ATTR_ROWSPAN, |
| 86 | 96 | ATTR_SIZE, |
| 97 | + ATTR_SIZES, | |
| 87 | 98 | ATTR_SRC, |
| 99 | + ATTR_SRCSET, | |
| 88 | 100 | ATTR_START, |
| 89 | 101 | ATTR_STYLE, |
| 90 | 102 | ATTR_TARGET, |
| 91 | 103 | ATTR_TITLE, |
| 92 | 104 | ATTR_TYPE, |
| @@ -94,46 +106,48 @@ | ||
| 94 | 106 | ATTR_VALUE, |
| 95 | 107 | ATTR_VSPACE, |
| 96 | 108 | ATTR_WIDTH |
| 97 | 109 | }; |
| 98 | 110 | |
| 99 | -enum amsk_t { | |
| 100 | - AMSK_ALIGN = 0x00000001, | |
| 101 | - AMSK_ALT = 0x00000002, | |
| 102 | - AMSK_BGCOLOR = 0x00000004, | |
| 103 | - AMSK_BORDER = 0x00000008, | |
| 104 | - AMSK_CELLPADDING = 0x00000010, | |
| 105 | - AMSK_CELLSPACING = 0x00000020, | |
| 106 | - AMSK_CLASS = 0x00000040, | |
| 107 | - AMSK_CLEAR = 0x00000080, | |
| 108 | - AMSK_COLOR = 0x00000100, | |
| 109 | - AMSK_COLSPAN = 0x00000200, | |
| 110 | - AMSK_COMPACT = 0x00000400, | |
| 111 | - AMSK_FACE = 0x00000800, | |
| 112 | - AMSK_HEIGHT = 0x00001000, | |
| 113 | - AMSK_HREF = 0x00002000, | |
| 114 | - AMSK_HSPACE = 0x00004000, | |
| 115 | - AMSK_ID = 0x00008000, | |
| 116 | - AMSK_LINKS = 0x00010000, | |
| 117 | - AMSK_NAME = 0x00020000, | |
| 118 | - AMSK_ROWSPAN = 0x00040000, | |
| 119 | - AMSK_SIZE = 0x00080000, | |
| 120 | - AMSK_SRC = 0x00100000, | |
| 121 | - AMSK_START = 0x00200000, | |
| 122 | - AMSK_STYLE = 0x00400000, | |
| 123 | - AMSK_TARGET = 0x00800000, | |
| 124 | - AMSK_TITLE = 0x01000000, | |
| 125 | - AMSK_TYPE = 0x02000000, | |
| 126 | - AMSK_VALIGN = 0x04000000, | |
| 127 | - AMSK_VALUE = 0x08000000, | |
| 128 | - AMSK_VSPACE = 0x10000000, | |
| 129 | - AMSK_WIDTH = 0x20000000 | |
| 130 | -}; | |
| 111 | +typedef uint64_t amsk_t; | |
| 112 | +#define AMSK_ALIGN ((amsk_t)1 << 0) | |
| 113 | +#define AMSK_ALT ((amsk_t)1 << 1) | |
| 114 | +#define AMSK_BGCOLOR ((amsk_t)1 << 2) | |
| 115 | +#define AMSK_BORDER ((amsk_t)1 << 3) | |
| 116 | +#define AMSK_CELLPADDING ((amsk_t)1 << 4) | |
| 117 | +#define AMSK_CELLSPACING ((amsk_t)1 << 5) | |
| 118 | +#define AMSK_CLASS ((amsk_t)1 << 6) | |
| 119 | +#define AMSK_CLEAR ((amsk_t)1 << 7) | |
| 120 | +#define AMSK_COLOR ((amsk_t)1 << 8) | |
| 121 | +#define AMSK_COLSPAN ((amsk_t)1 << 9) | |
| 122 | +#define AMSK_COMPACT ((amsk_t)1 << 10) | |
| 123 | +#define AMSK_FACE ((amsk_t)1 << 11) | |
| 124 | +#define AMSK_HEIGHT ((amsk_t)1 << 12) | |
| 125 | +#define AMSK_HREF ((amsk_t)1 << 13) | |
| 126 | +#define AMSK_HSPACE ((amsk_t)1 << 14) | |
| 127 | +#define AMSK_ID ((amsk_t)1 << 15) | |
| 128 | +#define AMSK_LINKS ((amsk_t)1 << 16) | |
| 129 | +#define AMSK_NAME ((amsk_t)1 << 17) | |
| 130 | +#define AMSK_OPEN ((amsk_t)1 << 18) | |
| 131 | +#define AMSK_ROWSPAN ((amsk_t)1 << 19) | |
| 132 | +#define AMSK_SIZE ((amsk_t)1 << 20) | |
| 133 | +#define AMSK_SRC ((amsk_t)1 << 21) | |
| 134 | +#define AMSK_START ((amsk_t)1 << 22) | |
| 135 | +#define AMSK_STYLE ((amsk_t)1 << 23) | |
| 136 | +#define AMSK_TARGET ((amsk_t)1 << 24) | |
| 137 | +#define AMSK_TITLE ((amsk_t)1 << 25) | |
| 138 | +#define AMSK_TYPE ((amsk_t)1 << 26) | |
| 139 | +#define AMSK_VALIGN ((amsk_t)1 << 27) | |
| 140 | +#define AMSK_VALUE ((amsk_t)1 << 28) | |
| 141 | +#define AMSK_VSPACE ((amsk_t)1 << 29) | |
| 142 | +#define AMSK_WIDTH ((amsk_t)1 << 30) | |
| 143 | +#define AMSK_CITE ((amsk_t)1 << 31) | |
| 144 | +#define AMSK_DATETIME ((amsk_t)1 << 32) | |
| 131 | 145 | |
| 132 | 146 | static const struct AllowedAttribute { |
| 133 | 147 | const char *zName; |
| 134 | - unsigned int iMask; | |
| 148 | + amsk_t iMask; | |
| 135 | 149 | } aAttribute[] = { |
| 136 | 150 | /* These indexes MUST line up with their |
| 137 | 151 | corresponding allowed_attr_t enum values. |
| 138 | 152 | */ |
| 139 | 153 | { 0, 0 }, |
| @@ -141,25 +155,37 @@ | ||
| 141 | 155 | { "alt", AMSK_ALT }, |
| 142 | 156 | { "bgcolor", AMSK_BGCOLOR }, |
| 143 | 157 | { "border", AMSK_BORDER }, |
| 144 | 158 | { "cellpadding", AMSK_CELLPADDING }, |
| 145 | 159 | { "cellspacing", AMSK_CELLSPACING }, |
| 160 | + { "cite", AMSK_CITE }, | |
| 146 | 161 | { "class", AMSK_CLASS }, |
| 147 | 162 | { "clear", AMSK_CLEAR }, |
| 148 | 163 | { "color", AMSK_COLOR }, |
| 149 | 164 | { "colspan", AMSK_COLSPAN }, |
| 150 | 165 | { "compact", AMSK_COMPACT }, |
| 166 | + { "datetime", AMSK_DATETIME }, | |
| 151 | 167 | { "face", AMSK_FACE }, |
| 168 | + { "for", 0 }, | |
| 152 | 169 | { "height", AMSK_HEIGHT }, |
| 170 | + { "high", 0 }, | |
| 153 | 171 | { "href", AMSK_HREF }, |
| 154 | 172 | { "hspace", AMSK_HSPACE }, |
| 155 | 173 | { "id", AMSK_ID }, |
| 156 | 174 | { "links", AMSK_LINKS }, |
| 175 | + { "low", 0 }, | |
| 176 | + { "max", 0 }, | |
| 177 | + { "media", 0 }, | |
| 178 | + { "min", 0 }, | |
| 157 | 179 | { "name", AMSK_NAME }, |
| 180 | + { "open", AMSK_OPEN }, | |
| 181 | + { "optimum", 0 }, | |
| 158 | 182 | { "rowspan", AMSK_ROWSPAN }, |
| 159 | 183 | { "size", AMSK_SIZE }, |
| 184 | + { "sizes", 0 }, | |
| 160 | 185 | { "src", AMSK_SRC }, |
| 186 | + { "srcset", 0 }, | |
| 161 | 187 | { "start", AMSK_START }, |
| 162 | 188 | { "style", AMSK_STYLE }, |
| 163 | 189 | { "target", AMSK_TARGET }, |
| 164 | 190 | { "title", AMSK_TITLE }, |
| 165 | 191 | { "type", AMSK_TYPE }, |
| @@ -209,10 +235,11 @@ | ||
| 209 | 235 | MARKUP_HTML5_ASIDE, |
| 210 | 236 | MARKUP_B, |
| 211 | 237 | MARKUP_BIG, |
| 212 | 238 | MARKUP_BLOCKQUOTE, |
| 213 | 239 | MARKUP_BR, |
| 240 | + MARKUP_CAPTION, | |
| 214 | 241 | MARKUP_CENTER, |
| 215 | 242 | MARKUP_CITE, |
| 216 | 243 | MARKUP_CODE, |
| 217 | 244 | MARKUP_COL, |
| 218 | 245 | MARKUP_COLGROUP, |
| @@ -222,10 +249,12 @@ | ||
| 222 | 249 | MARKUP_DFN, |
| 223 | 250 | MARKUP_DIV, |
| 224 | 251 | MARKUP_DL, |
| 225 | 252 | MARKUP_DT, |
| 226 | 253 | MARKUP_EM, |
| 254 | + MARKUP_FIGCAPTION, | |
| 255 | + MARKUP_FIGURE, | |
| 227 | 256 | MARKUP_FONT, |
| 228 | 257 | MARKUP_HTML5_FOOTER, |
| 229 | 258 | MARKUP_H1, |
| 230 | 259 | MARKUP_H2, |
| 231 | 260 | MARKUP_H3, |
| @@ -236,21 +265,28 @@ | ||
| 236 | 265 | MARKUP_HR, |
| 237 | 266 | MARKUP_I, |
| 238 | 267 | MARKUP_IMG, |
| 239 | 268 | MARKUP_INS, |
| 240 | 269 | MARKUP_KBD, |
| 270 | + MARKUP_LABEL, | |
| 241 | 271 | MARKUP_LI, |
| 272 | + MARKUP_MARK, | |
| 273 | + MARKUP_METER, | |
| 242 | 274 | MARKUP_HTML5_NAV, |
| 243 | 275 | MARKUP_NOBR, |
| 244 | 276 | MARKUP_NOWIKI, |
| 245 | 277 | MARKUP_OL, |
| 246 | 278 | MARKUP_P, |
| 279 | + MARKUP_PICTURE, | |
| 247 | 280 | MARKUP_PRE, |
| 281 | + MARKUP_PROGRESS, | |
| 282 | + MARKUP_Q, | |
| 248 | 283 | MARKUP_S, |
| 249 | 284 | MARKUP_SAMP, |
| 250 | 285 | MARKUP_HTML5_SECTION, |
| 251 | 286 | MARKUP_SMALL, |
| 287 | + MARKUP_SOURCE, | |
| 252 | 288 | MARKUP_SPAN, |
| 253 | 289 | MARKUP_STRIKE, |
| 254 | 290 | MARKUP_STRONG, |
| 255 | 291 | MARKUP_SUB, |
| 256 | 292 | MARKUP_SUMMARY, |
| @@ -259,16 +295,18 @@ | ||
| 259 | 295 | MARKUP_TBODY, |
| 260 | 296 | MARKUP_TD, |
| 261 | 297 | MARKUP_TFOOT, |
| 262 | 298 | MARKUP_TH, |
| 263 | 299 | MARKUP_THEAD, |
| 300 | + MARKUP_TIME, | |
| 264 | 301 | MARKUP_TITLE, |
| 265 | 302 | MARKUP_TR, |
| 266 | 303 | MARKUP_TT, |
| 267 | 304 | MARKUP_U, |
| 268 | 305 | MARKUP_UL, |
| 269 | 306 | MARKUP_VAR, |
| 307 | + MARKUP_WBR, | |
| 270 | 308 | MARKUP_VERBATIM |
| 271 | 309 | }; |
| 272 | 310 | |
| 273 | 311 | /* |
| 274 | 312 | ** The various markup is divided into the following types: |
| @@ -299,11 +337,11 @@ | ||
| 299 | 337 | |
| 300 | 338 | static const struct AllowedMarkup { |
| 301 | 339 | const char *zName; /* Name of the markup */ |
| 302 | 340 | char iCode; /* The MARKUP_* code */ |
| 303 | 341 | short int iType; /* The MUTYPE_* code */ |
| 304 | - int allowedAttr; /* Allowed attributes on this markup */ | |
| 342 | + amsk_t allowedAttr; /* Allowed attributes on this markup */ | |
| 305 | 343 | } aMarkup[] = { |
| 306 | 344 | { 0, MARKUP_INVALID, 0, 0 }, |
| 307 | 345 | { "a", MARKUP_A, MUTYPE_HYPERLINK, |
| 308 | 346 | AMSK_HREF|AMSK_NAME|AMSK_CLASS|AMSK_TARGET|AMSK_STYLE| |
| 309 | 347 | AMSK_TITLE}, |
| @@ -316,10 +354,12 @@ | ||
| 316 | 354 | AMSK_ID|AMSK_CLASS|AMSK_STYLE }, |
| 317 | 355 | { "b", MARKUP_B, MUTYPE_FONT, AMSK_STYLE }, |
| 318 | 356 | { "big", MARKUP_BIG, MUTYPE_FONT, AMSK_STYLE }, |
| 319 | 357 | { "blockquote", MARKUP_BLOCKQUOTE, MUTYPE_BLOCK, AMSK_STYLE }, |
| 320 | 358 | { "br", MARKUP_BR, MUTYPE_SINGLE, AMSK_CLEAR }, |
| 359 | + { "caption", MARKUP_CAPTION, MUTYPE_BLOCK, | |
| 360 | + AMSK_ID|AMSK_CLASS|AMSK_STYLE }, | |
| 321 | 361 | { "center", MARKUP_CENTER, MUTYPE_BLOCK, AMSK_STYLE }, |
| 322 | 362 | { "cite", MARKUP_CITE, MUTYPE_FONT, AMSK_STYLE }, |
| 323 | 363 | { "code", MARKUP_CODE, MUTYPE_FONT, AMSK_STYLE }, |
| 324 | 364 | { "col", MARKUP_COL, MUTYPE_SINGLE, |
| 325 | 365 | AMSK_ALIGN|AMSK_CLASS|AMSK_COLSPAN|AMSK_WIDTH|AMSK_STYLE }, |
| @@ -326,18 +366,22 @@ | ||
| 326 | 366 | { "colgroup", MARKUP_COLGROUP, MUTYPE_BLOCK, |
| 327 | 367 | AMSK_ALIGN|AMSK_CLASS|AMSK_COLSPAN|AMSK_WIDTH|AMSK_STYLE}, |
| 328 | 368 | { "dd", MARKUP_DD, MUTYPE_LI, AMSK_STYLE }, |
| 329 | 369 | { "del", MARKUP_DEL, MUTYPE_FONT, AMSK_STYLE }, |
| 330 | 370 | { "details", MARKUP_DETAILS, MUTYPE_BLOCK, |
| 331 | - AMSK_ID|AMSK_CLASS|AMSK_STYLE }, | |
| 371 | + AMSK_ID|AMSK_CLASS|AMSK_STYLE|AMSK_OPEN }, | |
| 332 | 372 | { "dfn", MARKUP_DFN, MUTYPE_FONT, AMSK_STYLE }, |
| 333 | 373 | { "div", MARKUP_DIV, MUTYPE_BLOCK, |
| 334 | 374 | AMSK_ID|AMSK_CLASS|AMSK_STYLE }, |
| 335 | 375 | { "dl", MARKUP_DL, MUTYPE_LIST, |
| 336 | 376 | AMSK_COMPACT|AMSK_STYLE }, |
| 337 | 377 | { "dt", MARKUP_DT, MUTYPE_LI, AMSK_STYLE }, |
| 338 | 378 | { "em", MARKUP_EM, MUTYPE_FONT, AMSK_STYLE }, |
| 379 | + { "figcaption", MARKUP_FIGCAPTION, MUTYPE_BLOCK, | |
| 380 | + AMSK_ID|AMSK_CLASS|AMSK_STYLE }, | |
| 381 | + { "figure", MARKUP_FIGURE, MUTYPE_BLOCK, | |
| 382 | + AMSK_ID|AMSK_CLASS|AMSK_STYLE }, | |
| 339 | 383 | { "font", MARKUP_FONT, MUTYPE_FONT, |
| 340 | 384 | AMSK_COLOR|AMSK_FACE|AMSK_SIZE|AMSK_STYLE }, |
| 341 | 385 | { "footer", MARKUP_HTML5_FOOTER, MUTYPE_BLOCK, |
| 342 | 386 | AMSK_ID|AMSK_CLASS|AMSK_STYLE }, |
| 343 | 387 | { "h1", MARKUP_H1, MUTYPE_BLOCK, |
| @@ -358,29 +402,43 @@ | ||
| 358 | 402 | AMSK_ALIGN|AMSK_COLOR|AMSK_SIZE|AMSK_WIDTH| |
| 359 | 403 | AMSK_STYLE|AMSK_CLASS }, |
| 360 | 404 | { "i", MARKUP_I, MUTYPE_FONT, AMSK_STYLE }, |
| 361 | 405 | { "img", MARKUP_IMG, MUTYPE_SINGLE, |
| 362 | 406 | AMSK_ALIGN|AMSK_ALT|AMSK_BORDER|AMSK_HEIGHT| |
| 363 | - AMSK_HSPACE|AMSK_SRC|AMSK_VSPACE|AMSK_WIDTH|AMSK_STYLE }, | |
| 407 | + AMSK_HSPACE|AMSK_SRC|AMSK_VSPACE|AMSK_WIDTH|AMSK_STYLE }, | |
| 364 | 408 | { "ins", MARKUP_INS, MUTYPE_FONT, AMSK_STYLE }, |
| 365 | 409 | { "kbd", MARKUP_KBD, MUTYPE_FONT, AMSK_STYLE }, |
| 410 | + { "label", MARKUP_LABEL, MUTYPE_FONT, | |
| 411 | + AMSK_ID|AMSK_CLASS|AMSK_STYLE }, | |
| 366 | 412 | { "li", MARKUP_LI, MUTYPE_LI, |
| 367 | 413 | AMSK_TYPE|AMSK_VALUE|AMSK_STYLE }, |
| 414 | + { "mark", MARKUP_MARK, MUTYPE_FONT, | |
| 415 | + AMSK_ID|AMSK_CLASS|AMSK_STYLE }, | |
| 416 | + { "meter", MARKUP_METER, MUTYPE_FONT, | |
| 417 | + AMSK_ID|AMSK_CLASS|AMSK_STYLE|AMSK_VALUE }, | |
| 368 | 418 | { "nav", MARKUP_HTML5_NAV, MUTYPE_BLOCK, |
| 369 | 419 | AMSK_ID|AMSK_CLASS|AMSK_STYLE }, |
| 370 | 420 | { "nobr", MARKUP_NOBR, MUTYPE_FONT, 0 }, |
| 371 | 421 | { "nowiki", MARKUP_NOWIKI, MUTYPE_SPECIAL, 0 }, |
| 372 | 422 | { "ol", MARKUP_OL, MUTYPE_LIST, |
| 373 | 423 | AMSK_START|AMSK_TYPE|AMSK_COMPACT|AMSK_STYLE }, |
| 374 | 424 | { "p", MARKUP_P, MUTYPE_BLOCK, |
| 375 | 425 | AMSK_ALIGN|AMSK_CLASS|AMSK_STYLE }, |
| 426 | + { "picture", MARKUP_PICTURE, MUTYPE_BLOCK, | |
| 427 | + AMSK_ID|AMSK_CLASS|AMSK_STYLE }, | |
| 376 | 428 | { "pre", MARKUP_PRE, MUTYPE_BLOCK, AMSK_STYLE }, |
| 429 | + { "progress", MARKUP_PROGRESS, MUTYPE_FONT, | |
| 430 | + AMSK_ID|AMSK_CLASS|AMSK_STYLE|AMSK_VALUE }, | |
| 431 | + { "q", MARKUP_Q, MUTYPE_FONT, | |
| 432 | + AMSK_CLASS|AMSK_STYLE|AMSK_CITE }, | |
| 377 | 433 | { "s", MARKUP_S, MUTYPE_FONT, AMSK_STYLE }, |
| 378 | 434 | { "samp", MARKUP_SAMP, MUTYPE_FONT, AMSK_STYLE }, |
| 379 | 435 | { "section", MARKUP_HTML5_SECTION, MUTYPE_BLOCK, |
| 380 | 436 | AMSK_ID|AMSK_CLASS|AMSK_STYLE }, |
| 381 | 437 | { "small", MARKUP_SMALL, MUTYPE_FONT, AMSK_STYLE }, |
| 438 | + { "source", MARKUP_SOURCE, MUTYPE_SINGLE, | |
| 439 | + AMSK_TYPE|AMSK_ID|AMSK_CLASS|AMSK_STYLE }, | |
| 382 | 440 | { "span", MARKUP_SPAN, MUTYPE_BLOCK, |
| 383 | 441 | AMSK_ALIGN|AMSK_CLASS|AMSK_STYLE }, |
| 384 | 442 | { "strike", MARKUP_STRIKE, MUTYPE_FONT, AMSK_STYLE }, |
| 385 | 443 | { "strong", MARKUP_STRONG, MUTYPE_FONT, AMSK_STYLE }, |
| 386 | 444 | { "sub", MARKUP_SUB, MUTYPE_FONT, AMSK_STYLE }, |
| @@ -401,18 +459,21 @@ | ||
| 401 | 459 | { "th", MARKUP_TH, MUTYPE_TD, |
| 402 | 460 | AMSK_ALIGN|AMSK_BGCOLOR|AMSK_COLSPAN| |
| 403 | 461 | AMSK_ROWSPAN|AMSK_VALIGN|AMSK_CLASS|AMSK_STYLE }, |
| 404 | 462 | { "thead", MARKUP_THEAD, MUTYPE_BLOCK, |
| 405 | 463 | AMSK_ALIGN|AMSK_CLASS|AMSK_STYLE }, |
| 464 | + { "time", MARKUP_TIME, MUTYPE_FONT, | |
| 465 | + AMSK_DATETIME|AMSK_ID|AMSK_CLASS|AMSK_STYLE|AMSK_TITLE }, | |
| 406 | 466 | { "title", MARKUP_TITLE, MUTYPE_BLOCK, 0 }, |
| 407 | 467 | { "tr", MARKUP_TR, MUTYPE_TR, |
| 408 | 468 | AMSK_ALIGN|AMSK_BGCOLOR|AMSK_VALIGN|AMSK_CLASS|AMSK_STYLE }, |
| 409 | 469 | { "tt", MARKUP_TT, MUTYPE_FONT, AMSK_STYLE }, |
| 410 | 470 | { "u", MARKUP_U, MUTYPE_FONT, AMSK_STYLE }, |
| 411 | 471 | { "ul", MARKUP_UL, MUTYPE_LIST, |
| 412 | 472 | AMSK_TYPE|AMSK_COMPACT|AMSK_STYLE }, |
| 413 | 473 | { "var", MARKUP_VAR, MUTYPE_FONT, AMSK_STYLE }, |
| 474 | + { "wbr", MARKUP_WBR, MUTYPE_SINGLE, 0 }, | |
| 414 | 475 | { "verbatim", MARKUP_VERBATIM, MUTYPE_SPECIAL, |
| 415 | 476 | AMSK_ID|AMSK_TYPE }, |
| 416 | 477 | }; |
| 417 | 478 | |
| 418 | 479 | void show_allowed_wiki_markup( void ){ |
| @@ -816,23 +877,34 @@ | ||
| 816 | 877 | unsigned char iACode; /* ATTR_* */ |
| 817 | 878 | char *zValue; /* Argument to this attribute. Might be NULL */ |
| 818 | 879 | char cTerm; /* Original argument termination character */ |
| 819 | 880 | } aAttr[10]; |
| 820 | 881 | }; |
| 882 | + | |
| 883 | +/* | |
| 884 | +** Return true if attribute iACode has already been parsed into p. | |
| 885 | +*/ | |
| 886 | +static int markupHasAttr(const ParsedMarkup *p, int iACode){ | |
| 887 | + int i; | |
| 888 | + for(i=0; i<p->nAttr; i++){ | |
| 889 | + if( p->aAttr[i].iACode==iACode ) return 1; | |
| 890 | + } | |
| 891 | + return 0; | |
| 892 | +} | |
| 821 | 893 | |
| 822 | 894 | /* |
| 823 | 895 | ** z[] is an HTML markup element - something that begins with '<'. |
| 824 | 896 | ** Parse this element into the p structure. |
| 825 | 897 | ** |
| 826 | 898 | ** The content of z[] might be modified by converting characters |
| 827 | 899 | ** to lowercase and by inserting some "\000" characters. |
| 828 | 900 | */ |
| 829 | -static int parseMarkup(ParsedMarkup *p, char *z){ | |
| 901 | +static amsk_t parseMarkup(ParsedMarkup *p, char *z){ | |
| 830 | 902 | int i, j, c; |
| 831 | 903 | int iACode; |
| 832 | 904 | char *zValue; |
| 833 | - int seen = 0; | |
| 905 | + amsk_t seen = 0; | |
| 834 | 906 | char zTag[100]; |
| 835 | 907 | |
| 836 | 908 | if( z[1]=='/' ){ |
| 837 | 909 | p->endTag = 1; |
| 838 | 910 | i = 2; |
| @@ -868,11 +940,11 @@ | ||
| 868 | 940 | if( j<(int)sizeof(zTag)-1 ) zTag[j++] = fossil_tolower(z[i]); |
| 869 | 941 | i++; |
| 870 | 942 | } |
| 871 | 943 | zTag[j] = 0; |
| 872 | 944 | p->aAttr[p->nAttr].iACode = iACode = findAttr(zTag); |
| 873 | - attrOk = iACode!=0 && (seen & aAttribute[iACode].iMask)==0; | |
| 945 | + attrOk = iACode!=0 && !markupHasAttr(p, iACode); | |
| 874 | 946 | while( fossil_isspace(z[i]) ){ z++; } |
| 875 | 947 | if( z[i]!='=' ){ |
| 876 | 948 | p->aAttr[p->nAttr].zValue = 0; |
| 877 | 949 | p->aAttr[p->nAttr].cTerm = 0; |
| 878 | 950 | c = 0; |
| @@ -904,11 +976,11 @@ | ||
| 904 | 976 | } |
| 905 | 977 | } |
| 906 | 978 | i++; |
| 907 | 979 | } |
| 908 | 980 | if( attrOk ){ |
| 909 | - seen |= aAttribute[iACode].iMask; | |
| 981 | + if( aAttribute[iACode].iMask ) seen |= aAttribute[iACode].iMask; | |
| 910 | 982 | p->nAttr++; |
| 911 | 983 | } |
| 912 | 984 | while( fossil_isspace(z[i]) ){ i++; } |
| 913 | 985 | if( z[i]==0 || z[i]=='>' || (z[i]=='/' && z[i+1]=='>') ) break; |
| 914 | 986 | } |
| @@ -1712,17 +1784,17 @@ | ||
| 1712 | 1784 | break; |
| 1713 | 1785 | } |
| 1714 | 1786 | case TOKEN_MARKUP: { |
| 1715 | 1787 | const char *zId; |
| 1716 | 1788 | int iDiv; |
| 1717 | - int mAttr = parseMarkup(&markup, z); | |
| 1789 | + (void)parseMarkup(&markup, z); | |
| 1718 | 1790 | |
| 1719 | 1791 | /* Convert <title> to <h1 align='center'> */ |
| 1720 | 1792 | if( markup.iCode==MARKUP_TITLE && !p->inVerbatim ){ |
| 1721 | 1793 | markup.iCode = MARKUP_H1; |
| 1722 | 1794 | markup.nAttr = 1; |
| 1723 | - markup.aAttr[0].iACode = AMSK_ALIGN; | |
| 1795 | + markup.aAttr[0].iACode = ATTR_ALIGN; | |
| 1724 | 1796 | markup.aAttr[0].zValue = "center"; |
| 1725 | 1797 | markup.aAttr[0].cTerm = 0; |
| 1726 | 1798 | } |
| 1727 | 1799 | |
| 1728 | 1800 | /* Markup of the form </div id=ID> where there is a matching |
| @@ -1801,11 +1873,11 @@ | ||
| 1801 | 1873 | popStackToTag(p, markup.iCode); |
| 1802 | 1874 | }else |
| 1803 | 1875 | |
| 1804 | 1876 | /* Push <div> markup onto the stack together with the id=ID attribute. |
| 1805 | 1877 | */ |
| 1806 | - if( markup.iCode==MARKUP_DIV && (mAttr & ATTR_ID)!=0 ){ | |
| 1878 | + if( markup.iCode==MARKUP_DIV && attributeValue(&markup, ATTR_ID)!=0 ){ | |
| 1807 | 1879 | pushStackWithId(p, markup.iCode, markupId(&markup), |
| 1808 | 1880 | (p->state & ALLOW_WIKI)!=0); |
| 1809 | 1881 | }else |
| 1810 | 1882 | |
| 1811 | 1883 | /* Enter <verbatim> processing. With verbatim enabled, all other |
| 1812 | 1884 |
| --- src/wikiformat.c | |
| +++ src/wikiformat.c | |
| @@ -68,25 +68,37 @@ | |
| 68 | ATTR_ALT, |
| 69 | ATTR_BGCOLOR, |
| 70 | ATTR_BORDER, |
| 71 | ATTR_CELLPADDING, |
| 72 | ATTR_CELLSPACING, |
| 73 | ATTR_CLASS, |
| 74 | ATTR_CLEAR, |
| 75 | ATTR_COLOR, |
| 76 | ATTR_COLSPAN, |
| 77 | ATTR_COMPACT, |
| 78 | ATTR_FACE, |
| 79 | ATTR_HEIGHT, |
| 80 | ATTR_HREF, |
| 81 | ATTR_HSPACE, |
| 82 | ATTR_ID, |
| 83 | ATTR_LINKS, |
| 84 | ATTR_NAME, |
| 85 | ATTR_ROWSPAN, |
| 86 | ATTR_SIZE, |
| 87 | ATTR_SRC, |
| 88 | ATTR_START, |
| 89 | ATTR_STYLE, |
| 90 | ATTR_TARGET, |
| 91 | ATTR_TITLE, |
| 92 | ATTR_TYPE, |
| @@ -94,46 +106,48 @@ | |
| 94 | ATTR_VALUE, |
| 95 | ATTR_VSPACE, |
| 96 | ATTR_WIDTH |
| 97 | }; |
| 98 | |
| 99 | enum amsk_t { |
| 100 | AMSK_ALIGN = 0x00000001, |
| 101 | AMSK_ALT = 0x00000002, |
| 102 | AMSK_BGCOLOR = 0x00000004, |
| 103 | AMSK_BORDER = 0x00000008, |
| 104 | AMSK_CELLPADDING = 0x00000010, |
| 105 | AMSK_CELLSPACING = 0x00000020, |
| 106 | AMSK_CLASS = 0x00000040, |
| 107 | AMSK_CLEAR = 0x00000080, |
| 108 | AMSK_COLOR = 0x00000100, |
| 109 | AMSK_COLSPAN = 0x00000200, |
| 110 | AMSK_COMPACT = 0x00000400, |
| 111 | AMSK_FACE = 0x00000800, |
| 112 | AMSK_HEIGHT = 0x00001000, |
| 113 | AMSK_HREF = 0x00002000, |
| 114 | AMSK_HSPACE = 0x00004000, |
| 115 | AMSK_ID = 0x00008000, |
| 116 | AMSK_LINKS = 0x00010000, |
| 117 | AMSK_NAME = 0x00020000, |
| 118 | AMSK_ROWSPAN = 0x00040000, |
| 119 | AMSK_SIZE = 0x00080000, |
| 120 | AMSK_SRC = 0x00100000, |
| 121 | AMSK_START = 0x00200000, |
| 122 | AMSK_STYLE = 0x00400000, |
| 123 | AMSK_TARGET = 0x00800000, |
| 124 | AMSK_TITLE = 0x01000000, |
| 125 | AMSK_TYPE = 0x02000000, |
| 126 | AMSK_VALIGN = 0x04000000, |
| 127 | AMSK_VALUE = 0x08000000, |
| 128 | AMSK_VSPACE = 0x10000000, |
| 129 | AMSK_WIDTH = 0x20000000 |
| 130 | }; |
| 131 | |
| 132 | static const struct AllowedAttribute { |
| 133 | const char *zName; |
| 134 | unsigned int iMask; |
| 135 | } aAttribute[] = { |
| 136 | /* These indexes MUST line up with their |
| 137 | corresponding allowed_attr_t enum values. |
| 138 | */ |
| 139 | { 0, 0 }, |
| @@ -141,25 +155,37 @@ | |
| 141 | { "alt", AMSK_ALT }, |
| 142 | { "bgcolor", AMSK_BGCOLOR }, |
| 143 | { "border", AMSK_BORDER }, |
| 144 | { "cellpadding", AMSK_CELLPADDING }, |
| 145 | { "cellspacing", AMSK_CELLSPACING }, |
| 146 | { "class", AMSK_CLASS }, |
| 147 | { "clear", AMSK_CLEAR }, |
| 148 | { "color", AMSK_COLOR }, |
| 149 | { "colspan", AMSK_COLSPAN }, |
| 150 | { "compact", AMSK_COMPACT }, |
| 151 | { "face", AMSK_FACE }, |
| 152 | { "height", AMSK_HEIGHT }, |
| 153 | { "href", AMSK_HREF }, |
| 154 | { "hspace", AMSK_HSPACE }, |
| 155 | { "id", AMSK_ID }, |
| 156 | { "links", AMSK_LINKS }, |
| 157 | { "name", AMSK_NAME }, |
| 158 | { "rowspan", AMSK_ROWSPAN }, |
| 159 | { "size", AMSK_SIZE }, |
| 160 | { "src", AMSK_SRC }, |
| 161 | { "start", AMSK_START }, |
| 162 | { "style", AMSK_STYLE }, |
| 163 | { "target", AMSK_TARGET }, |
| 164 | { "title", AMSK_TITLE }, |
| 165 | { "type", AMSK_TYPE }, |
| @@ -209,10 +235,11 @@ | |
| 209 | MARKUP_HTML5_ASIDE, |
| 210 | MARKUP_B, |
| 211 | MARKUP_BIG, |
| 212 | MARKUP_BLOCKQUOTE, |
| 213 | MARKUP_BR, |
| 214 | MARKUP_CENTER, |
| 215 | MARKUP_CITE, |
| 216 | MARKUP_CODE, |
| 217 | MARKUP_COL, |
| 218 | MARKUP_COLGROUP, |
| @@ -222,10 +249,12 @@ | |
| 222 | MARKUP_DFN, |
| 223 | MARKUP_DIV, |
| 224 | MARKUP_DL, |
| 225 | MARKUP_DT, |
| 226 | MARKUP_EM, |
| 227 | MARKUP_FONT, |
| 228 | MARKUP_HTML5_FOOTER, |
| 229 | MARKUP_H1, |
| 230 | MARKUP_H2, |
| 231 | MARKUP_H3, |
| @@ -236,21 +265,28 @@ | |
| 236 | MARKUP_HR, |
| 237 | MARKUP_I, |
| 238 | MARKUP_IMG, |
| 239 | MARKUP_INS, |
| 240 | MARKUP_KBD, |
| 241 | MARKUP_LI, |
| 242 | MARKUP_HTML5_NAV, |
| 243 | MARKUP_NOBR, |
| 244 | MARKUP_NOWIKI, |
| 245 | MARKUP_OL, |
| 246 | MARKUP_P, |
| 247 | MARKUP_PRE, |
| 248 | MARKUP_S, |
| 249 | MARKUP_SAMP, |
| 250 | MARKUP_HTML5_SECTION, |
| 251 | MARKUP_SMALL, |
| 252 | MARKUP_SPAN, |
| 253 | MARKUP_STRIKE, |
| 254 | MARKUP_STRONG, |
| 255 | MARKUP_SUB, |
| 256 | MARKUP_SUMMARY, |
| @@ -259,16 +295,18 @@ | |
| 259 | MARKUP_TBODY, |
| 260 | MARKUP_TD, |
| 261 | MARKUP_TFOOT, |
| 262 | MARKUP_TH, |
| 263 | MARKUP_THEAD, |
| 264 | MARKUP_TITLE, |
| 265 | MARKUP_TR, |
| 266 | MARKUP_TT, |
| 267 | MARKUP_U, |
| 268 | MARKUP_UL, |
| 269 | MARKUP_VAR, |
| 270 | MARKUP_VERBATIM |
| 271 | }; |
| 272 | |
| 273 | /* |
| 274 | ** The various markup is divided into the following types: |
| @@ -299,11 +337,11 @@ | |
| 299 | |
| 300 | static const struct AllowedMarkup { |
| 301 | const char *zName; /* Name of the markup */ |
| 302 | char iCode; /* The MARKUP_* code */ |
| 303 | short int iType; /* The MUTYPE_* code */ |
| 304 | int allowedAttr; /* Allowed attributes on this markup */ |
| 305 | } aMarkup[] = { |
| 306 | { 0, MARKUP_INVALID, 0, 0 }, |
| 307 | { "a", MARKUP_A, MUTYPE_HYPERLINK, |
| 308 | AMSK_HREF|AMSK_NAME|AMSK_CLASS|AMSK_TARGET|AMSK_STYLE| |
| 309 | AMSK_TITLE}, |
| @@ -316,10 +354,12 @@ | |
| 316 | AMSK_ID|AMSK_CLASS|AMSK_STYLE }, |
| 317 | { "b", MARKUP_B, MUTYPE_FONT, AMSK_STYLE }, |
| 318 | { "big", MARKUP_BIG, MUTYPE_FONT, AMSK_STYLE }, |
| 319 | { "blockquote", MARKUP_BLOCKQUOTE, MUTYPE_BLOCK, AMSK_STYLE }, |
| 320 | { "br", MARKUP_BR, MUTYPE_SINGLE, AMSK_CLEAR }, |
| 321 | { "center", MARKUP_CENTER, MUTYPE_BLOCK, AMSK_STYLE }, |
| 322 | { "cite", MARKUP_CITE, MUTYPE_FONT, AMSK_STYLE }, |
| 323 | { "code", MARKUP_CODE, MUTYPE_FONT, AMSK_STYLE }, |
| 324 | { "col", MARKUP_COL, MUTYPE_SINGLE, |
| 325 | AMSK_ALIGN|AMSK_CLASS|AMSK_COLSPAN|AMSK_WIDTH|AMSK_STYLE }, |
| @@ -326,18 +366,22 @@ | |
| 326 | { "colgroup", MARKUP_COLGROUP, MUTYPE_BLOCK, |
| 327 | AMSK_ALIGN|AMSK_CLASS|AMSK_COLSPAN|AMSK_WIDTH|AMSK_STYLE}, |
| 328 | { "dd", MARKUP_DD, MUTYPE_LI, AMSK_STYLE }, |
| 329 | { "del", MARKUP_DEL, MUTYPE_FONT, AMSK_STYLE }, |
| 330 | { "details", MARKUP_DETAILS, MUTYPE_BLOCK, |
| 331 | AMSK_ID|AMSK_CLASS|AMSK_STYLE }, |
| 332 | { "dfn", MARKUP_DFN, MUTYPE_FONT, AMSK_STYLE }, |
| 333 | { "div", MARKUP_DIV, MUTYPE_BLOCK, |
| 334 | AMSK_ID|AMSK_CLASS|AMSK_STYLE }, |
| 335 | { "dl", MARKUP_DL, MUTYPE_LIST, |
| 336 | AMSK_COMPACT|AMSK_STYLE }, |
| 337 | { "dt", MARKUP_DT, MUTYPE_LI, AMSK_STYLE }, |
| 338 | { "em", MARKUP_EM, MUTYPE_FONT, AMSK_STYLE }, |
| 339 | { "font", MARKUP_FONT, MUTYPE_FONT, |
| 340 | AMSK_COLOR|AMSK_FACE|AMSK_SIZE|AMSK_STYLE }, |
| 341 | { "footer", MARKUP_HTML5_FOOTER, MUTYPE_BLOCK, |
| 342 | AMSK_ID|AMSK_CLASS|AMSK_STYLE }, |
| 343 | { "h1", MARKUP_H1, MUTYPE_BLOCK, |
| @@ -358,29 +402,43 @@ | |
| 358 | AMSK_ALIGN|AMSK_COLOR|AMSK_SIZE|AMSK_WIDTH| |
| 359 | AMSK_STYLE|AMSK_CLASS }, |
| 360 | { "i", MARKUP_I, MUTYPE_FONT, AMSK_STYLE }, |
| 361 | { "img", MARKUP_IMG, MUTYPE_SINGLE, |
| 362 | AMSK_ALIGN|AMSK_ALT|AMSK_BORDER|AMSK_HEIGHT| |
| 363 | AMSK_HSPACE|AMSK_SRC|AMSK_VSPACE|AMSK_WIDTH|AMSK_STYLE }, |
| 364 | { "ins", MARKUP_INS, MUTYPE_FONT, AMSK_STYLE }, |
| 365 | { "kbd", MARKUP_KBD, MUTYPE_FONT, AMSK_STYLE }, |
| 366 | { "li", MARKUP_LI, MUTYPE_LI, |
| 367 | AMSK_TYPE|AMSK_VALUE|AMSK_STYLE }, |
| 368 | { "nav", MARKUP_HTML5_NAV, MUTYPE_BLOCK, |
| 369 | AMSK_ID|AMSK_CLASS|AMSK_STYLE }, |
| 370 | { "nobr", MARKUP_NOBR, MUTYPE_FONT, 0 }, |
| 371 | { "nowiki", MARKUP_NOWIKI, MUTYPE_SPECIAL, 0 }, |
| 372 | { "ol", MARKUP_OL, MUTYPE_LIST, |
| 373 | AMSK_START|AMSK_TYPE|AMSK_COMPACT|AMSK_STYLE }, |
| 374 | { "p", MARKUP_P, MUTYPE_BLOCK, |
| 375 | AMSK_ALIGN|AMSK_CLASS|AMSK_STYLE }, |
| 376 | { "pre", MARKUP_PRE, MUTYPE_BLOCK, AMSK_STYLE }, |
| 377 | { "s", MARKUP_S, MUTYPE_FONT, AMSK_STYLE }, |
| 378 | { "samp", MARKUP_SAMP, MUTYPE_FONT, AMSK_STYLE }, |
| 379 | { "section", MARKUP_HTML5_SECTION, MUTYPE_BLOCK, |
| 380 | AMSK_ID|AMSK_CLASS|AMSK_STYLE }, |
| 381 | { "small", MARKUP_SMALL, MUTYPE_FONT, AMSK_STYLE }, |
| 382 | { "span", MARKUP_SPAN, MUTYPE_BLOCK, |
| 383 | AMSK_ALIGN|AMSK_CLASS|AMSK_STYLE }, |
| 384 | { "strike", MARKUP_STRIKE, MUTYPE_FONT, AMSK_STYLE }, |
| 385 | { "strong", MARKUP_STRONG, MUTYPE_FONT, AMSK_STYLE }, |
| 386 | { "sub", MARKUP_SUB, MUTYPE_FONT, AMSK_STYLE }, |
| @@ -401,18 +459,21 @@ | |
| 401 | { "th", MARKUP_TH, MUTYPE_TD, |
| 402 | AMSK_ALIGN|AMSK_BGCOLOR|AMSK_COLSPAN| |
| 403 | AMSK_ROWSPAN|AMSK_VALIGN|AMSK_CLASS|AMSK_STYLE }, |
| 404 | { "thead", MARKUP_THEAD, MUTYPE_BLOCK, |
| 405 | AMSK_ALIGN|AMSK_CLASS|AMSK_STYLE }, |
| 406 | { "title", MARKUP_TITLE, MUTYPE_BLOCK, 0 }, |
| 407 | { "tr", MARKUP_TR, MUTYPE_TR, |
| 408 | AMSK_ALIGN|AMSK_BGCOLOR|AMSK_VALIGN|AMSK_CLASS|AMSK_STYLE }, |
| 409 | { "tt", MARKUP_TT, MUTYPE_FONT, AMSK_STYLE }, |
| 410 | { "u", MARKUP_U, MUTYPE_FONT, AMSK_STYLE }, |
| 411 | { "ul", MARKUP_UL, MUTYPE_LIST, |
| 412 | AMSK_TYPE|AMSK_COMPACT|AMSK_STYLE }, |
| 413 | { "var", MARKUP_VAR, MUTYPE_FONT, AMSK_STYLE }, |
| 414 | { "verbatim", MARKUP_VERBATIM, MUTYPE_SPECIAL, |
| 415 | AMSK_ID|AMSK_TYPE }, |
| 416 | }; |
| 417 | |
| 418 | void show_allowed_wiki_markup( void ){ |
| @@ -816,23 +877,34 @@ | |
| 816 | unsigned char iACode; /* ATTR_* */ |
| 817 | char *zValue; /* Argument to this attribute. Might be NULL */ |
| 818 | char cTerm; /* Original argument termination character */ |
| 819 | } aAttr[10]; |
| 820 | }; |
| 821 | |
| 822 | /* |
| 823 | ** z[] is an HTML markup element - something that begins with '<'. |
| 824 | ** Parse this element into the p structure. |
| 825 | ** |
| 826 | ** The content of z[] might be modified by converting characters |
| 827 | ** to lowercase and by inserting some "\000" characters. |
| 828 | */ |
| 829 | static int parseMarkup(ParsedMarkup *p, char *z){ |
| 830 | int i, j, c; |
| 831 | int iACode; |
| 832 | char *zValue; |
| 833 | int seen = 0; |
| 834 | char zTag[100]; |
| 835 | |
| 836 | if( z[1]=='/' ){ |
| 837 | p->endTag = 1; |
| 838 | i = 2; |
| @@ -868,11 +940,11 @@ | |
| 868 | if( j<(int)sizeof(zTag)-1 ) zTag[j++] = fossil_tolower(z[i]); |
| 869 | i++; |
| 870 | } |
| 871 | zTag[j] = 0; |
| 872 | p->aAttr[p->nAttr].iACode = iACode = findAttr(zTag); |
| 873 | attrOk = iACode!=0 && (seen & aAttribute[iACode].iMask)==0; |
| 874 | while( fossil_isspace(z[i]) ){ z++; } |
| 875 | if( z[i]!='=' ){ |
| 876 | p->aAttr[p->nAttr].zValue = 0; |
| 877 | p->aAttr[p->nAttr].cTerm = 0; |
| 878 | c = 0; |
| @@ -904,11 +976,11 @@ | |
| 904 | } |
| 905 | } |
| 906 | i++; |
| 907 | } |
| 908 | if( attrOk ){ |
| 909 | seen |= aAttribute[iACode].iMask; |
| 910 | p->nAttr++; |
| 911 | } |
| 912 | while( fossil_isspace(z[i]) ){ i++; } |
| 913 | if( z[i]==0 || z[i]=='>' || (z[i]=='/' && z[i+1]=='>') ) break; |
| 914 | } |
| @@ -1712,17 +1784,17 @@ | |
| 1712 | break; |
| 1713 | } |
| 1714 | case TOKEN_MARKUP: { |
| 1715 | const char *zId; |
| 1716 | int iDiv; |
| 1717 | int mAttr = parseMarkup(&markup, z); |
| 1718 | |
| 1719 | /* Convert <title> to <h1 align='center'> */ |
| 1720 | if( markup.iCode==MARKUP_TITLE && !p->inVerbatim ){ |
| 1721 | markup.iCode = MARKUP_H1; |
| 1722 | markup.nAttr = 1; |
| 1723 | markup.aAttr[0].iACode = AMSK_ALIGN; |
| 1724 | markup.aAttr[0].zValue = "center"; |
| 1725 | markup.aAttr[0].cTerm = 0; |
| 1726 | } |
| 1727 | |
| 1728 | /* Markup of the form </div id=ID> where there is a matching |
| @@ -1801,11 +1873,11 @@ | |
| 1801 | popStackToTag(p, markup.iCode); |
| 1802 | }else |
| 1803 | |
| 1804 | /* Push <div> markup onto the stack together with the id=ID attribute. |
| 1805 | */ |
| 1806 | if( markup.iCode==MARKUP_DIV && (mAttr & ATTR_ID)!=0 ){ |
| 1807 | pushStackWithId(p, markup.iCode, markupId(&markup), |
| 1808 | (p->state & ALLOW_WIKI)!=0); |
| 1809 | }else |
| 1810 | |
| 1811 | /* Enter <verbatim> processing. With verbatim enabled, all other |
| 1812 |
| --- src/wikiformat.c | |
| +++ src/wikiformat.c | |
| @@ -68,25 +68,37 @@ | |
| 68 | ATTR_ALT, |
| 69 | ATTR_BGCOLOR, |
| 70 | ATTR_BORDER, |
| 71 | ATTR_CELLPADDING, |
| 72 | ATTR_CELLSPACING, |
| 73 | ATTR_CITE, |
| 74 | ATTR_CLASS, |
| 75 | ATTR_CLEAR, |
| 76 | ATTR_COLOR, |
| 77 | ATTR_COLSPAN, |
| 78 | ATTR_COMPACT, |
| 79 | ATTR_DATETIME, |
| 80 | ATTR_FACE, |
| 81 | ATTR_FOR, |
| 82 | ATTR_HEIGHT, |
| 83 | ATTR_HIGH, |
| 84 | ATTR_HREF, |
| 85 | ATTR_HSPACE, |
| 86 | ATTR_ID, |
| 87 | ATTR_LINKS, |
| 88 | ATTR_LOW, |
| 89 | ATTR_MAX, |
| 90 | ATTR_MEDIA, |
| 91 | ATTR_MIN, |
| 92 | ATTR_NAME, |
| 93 | ATTR_OPEN, |
| 94 | ATTR_OPTIMUM, |
| 95 | ATTR_ROWSPAN, |
| 96 | ATTR_SIZE, |
| 97 | ATTR_SIZES, |
| 98 | ATTR_SRC, |
| 99 | ATTR_SRCSET, |
| 100 | ATTR_START, |
| 101 | ATTR_STYLE, |
| 102 | ATTR_TARGET, |
| 103 | ATTR_TITLE, |
| 104 | ATTR_TYPE, |
| @@ -94,46 +106,48 @@ | |
| 106 | ATTR_VALUE, |
| 107 | ATTR_VSPACE, |
| 108 | ATTR_WIDTH |
| 109 | }; |
| 110 | |
| 111 | typedef uint64_t amsk_t; |
| 112 | #define AMSK_ALIGN ((amsk_t)1 << 0) |
| 113 | #define AMSK_ALT ((amsk_t)1 << 1) |
| 114 | #define AMSK_BGCOLOR ((amsk_t)1 << 2) |
| 115 | #define AMSK_BORDER ((amsk_t)1 << 3) |
| 116 | #define AMSK_CELLPADDING ((amsk_t)1 << 4) |
| 117 | #define AMSK_CELLSPACING ((amsk_t)1 << 5) |
| 118 | #define AMSK_CLASS ((amsk_t)1 << 6) |
| 119 | #define AMSK_CLEAR ((amsk_t)1 << 7) |
| 120 | #define AMSK_COLOR ((amsk_t)1 << 8) |
| 121 | #define AMSK_COLSPAN ((amsk_t)1 << 9) |
| 122 | #define AMSK_COMPACT ((amsk_t)1 << 10) |
| 123 | #define AMSK_FACE ((amsk_t)1 << 11) |
| 124 | #define AMSK_HEIGHT ((amsk_t)1 << 12) |
| 125 | #define AMSK_HREF ((amsk_t)1 << 13) |
| 126 | #define AMSK_HSPACE ((amsk_t)1 << 14) |
| 127 | #define AMSK_ID ((amsk_t)1 << 15) |
| 128 | #define AMSK_LINKS ((amsk_t)1 << 16) |
| 129 | #define AMSK_NAME ((amsk_t)1 << 17) |
| 130 | #define AMSK_OPEN ((amsk_t)1 << 18) |
| 131 | #define AMSK_ROWSPAN ((amsk_t)1 << 19) |
| 132 | #define AMSK_SIZE ((amsk_t)1 << 20) |
| 133 | #define AMSK_SRC ((amsk_t)1 << 21) |
| 134 | #define AMSK_START ((amsk_t)1 << 22) |
| 135 | #define AMSK_STYLE ((amsk_t)1 << 23) |
| 136 | #define AMSK_TARGET ((amsk_t)1 << 24) |
| 137 | #define AMSK_TITLE ((amsk_t)1 << 25) |
| 138 | #define AMSK_TYPE ((amsk_t)1 << 26) |
| 139 | #define AMSK_VALIGN ((amsk_t)1 << 27) |
| 140 | #define AMSK_VALUE ((amsk_t)1 << 28) |
| 141 | #define AMSK_VSPACE ((amsk_t)1 << 29) |
| 142 | #define AMSK_WIDTH ((amsk_t)1 << 30) |
| 143 | #define AMSK_CITE ((amsk_t)1 << 31) |
| 144 | #define AMSK_DATETIME ((amsk_t)1 << 32) |
| 145 | |
| 146 | static const struct AllowedAttribute { |
| 147 | const char *zName; |
| 148 | amsk_t iMask; |
| 149 | } aAttribute[] = { |
| 150 | /* These indexes MUST line up with their |
| 151 | corresponding allowed_attr_t enum values. |
| 152 | */ |
| 153 | { 0, 0 }, |
| @@ -141,25 +155,37 @@ | |
| 155 | { "alt", AMSK_ALT }, |
| 156 | { "bgcolor", AMSK_BGCOLOR }, |
| 157 | { "border", AMSK_BORDER }, |
| 158 | { "cellpadding", AMSK_CELLPADDING }, |
| 159 | { "cellspacing", AMSK_CELLSPACING }, |
| 160 | { "cite", AMSK_CITE }, |
| 161 | { "class", AMSK_CLASS }, |
| 162 | { "clear", AMSK_CLEAR }, |
| 163 | { "color", AMSK_COLOR }, |
| 164 | { "colspan", AMSK_COLSPAN }, |
| 165 | { "compact", AMSK_COMPACT }, |
| 166 | { "datetime", AMSK_DATETIME }, |
| 167 | { "face", AMSK_FACE }, |
| 168 | { "for", 0 }, |
| 169 | { "height", AMSK_HEIGHT }, |
| 170 | { "high", 0 }, |
| 171 | { "href", AMSK_HREF }, |
| 172 | { "hspace", AMSK_HSPACE }, |
| 173 | { "id", AMSK_ID }, |
| 174 | { "links", AMSK_LINKS }, |
| 175 | { "low", 0 }, |
| 176 | { "max", 0 }, |
| 177 | { "media", 0 }, |
| 178 | { "min", 0 }, |
| 179 | { "name", AMSK_NAME }, |
| 180 | { "open", AMSK_OPEN }, |
| 181 | { "optimum", 0 }, |
| 182 | { "rowspan", AMSK_ROWSPAN }, |
| 183 | { "size", AMSK_SIZE }, |
| 184 | { "sizes", 0 }, |
| 185 | { "src", AMSK_SRC }, |
| 186 | { "srcset", 0 }, |
| 187 | { "start", AMSK_START }, |
| 188 | { "style", AMSK_STYLE }, |
| 189 | { "target", AMSK_TARGET }, |
| 190 | { "title", AMSK_TITLE }, |
| 191 | { "type", AMSK_TYPE }, |
| @@ -209,10 +235,11 @@ | |
| 235 | MARKUP_HTML5_ASIDE, |
| 236 | MARKUP_B, |
| 237 | MARKUP_BIG, |
| 238 | MARKUP_BLOCKQUOTE, |
| 239 | MARKUP_BR, |
| 240 | MARKUP_CAPTION, |
| 241 | MARKUP_CENTER, |
| 242 | MARKUP_CITE, |
| 243 | MARKUP_CODE, |
| 244 | MARKUP_COL, |
| 245 | MARKUP_COLGROUP, |
| @@ -222,10 +249,12 @@ | |
| 249 | MARKUP_DFN, |
| 250 | MARKUP_DIV, |
| 251 | MARKUP_DL, |
| 252 | MARKUP_DT, |
| 253 | MARKUP_EM, |
| 254 | MARKUP_FIGCAPTION, |
| 255 | MARKUP_FIGURE, |
| 256 | MARKUP_FONT, |
| 257 | MARKUP_HTML5_FOOTER, |
| 258 | MARKUP_H1, |
| 259 | MARKUP_H2, |
| 260 | MARKUP_H3, |
| @@ -236,21 +265,28 @@ | |
| 265 | MARKUP_HR, |
| 266 | MARKUP_I, |
| 267 | MARKUP_IMG, |
| 268 | MARKUP_INS, |
| 269 | MARKUP_KBD, |
| 270 | MARKUP_LABEL, |
| 271 | MARKUP_LI, |
| 272 | MARKUP_MARK, |
| 273 | MARKUP_METER, |
| 274 | MARKUP_HTML5_NAV, |
| 275 | MARKUP_NOBR, |
| 276 | MARKUP_NOWIKI, |
| 277 | MARKUP_OL, |
| 278 | MARKUP_P, |
| 279 | MARKUP_PICTURE, |
| 280 | MARKUP_PRE, |
| 281 | MARKUP_PROGRESS, |
| 282 | MARKUP_Q, |
| 283 | MARKUP_S, |
| 284 | MARKUP_SAMP, |
| 285 | MARKUP_HTML5_SECTION, |
| 286 | MARKUP_SMALL, |
| 287 | MARKUP_SOURCE, |
| 288 | MARKUP_SPAN, |
| 289 | MARKUP_STRIKE, |
| 290 | MARKUP_STRONG, |
| 291 | MARKUP_SUB, |
| 292 | MARKUP_SUMMARY, |
| @@ -259,16 +295,18 @@ | |
| 295 | MARKUP_TBODY, |
| 296 | MARKUP_TD, |
| 297 | MARKUP_TFOOT, |
| 298 | MARKUP_TH, |
| 299 | MARKUP_THEAD, |
| 300 | MARKUP_TIME, |
| 301 | MARKUP_TITLE, |
| 302 | MARKUP_TR, |
| 303 | MARKUP_TT, |
| 304 | MARKUP_U, |
| 305 | MARKUP_UL, |
| 306 | MARKUP_VAR, |
| 307 | MARKUP_WBR, |
| 308 | MARKUP_VERBATIM |
| 309 | }; |
| 310 | |
| 311 | /* |
| 312 | ** The various markup is divided into the following types: |
| @@ -299,11 +337,11 @@ | |
| 337 | |
| 338 | static const struct AllowedMarkup { |
| 339 | const char *zName; /* Name of the markup */ |
| 340 | char iCode; /* The MARKUP_* code */ |
| 341 | short int iType; /* The MUTYPE_* code */ |
| 342 | amsk_t allowedAttr; /* Allowed attributes on this markup */ |
| 343 | } aMarkup[] = { |
| 344 | { 0, MARKUP_INVALID, 0, 0 }, |
| 345 | { "a", MARKUP_A, MUTYPE_HYPERLINK, |
| 346 | AMSK_HREF|AMSK_NAME|AMSK_CLASS|AMSK_TARGET|AMSK_STYLE| |
| 347 | AMSK_TITLE}, |
| @@ -316,10 +354,12 @@ | |
| 354 | AMSK_ID|AMSK_CLASS|AMSK_STYLE }, |
| 355 | { "b", MARKUP_B, MUTYPE_FONT, AMSK_STYLE }, |
| 356 | { "big", MARKUP_BIG, MUTYPE_FONT, AMSK_STYLE }, |
| 357 | { "blockquote", MARKUP_BLOCKQUOTE, MUTYPE_BLOCK, AMSK_STYLE }, |
| 358 | { "br", MARKUP_BR, MUTYPE_SINGLE, AMSK_CLEAR }, |
| 359 | { "caption", MARKUP_CAPTION, MUTYPE_BLOCK, |
| 360 | AMSK_ID|AMSK_CLASS|AMSK_STYLE }, |
| 361 | { "center", MARKUP_CENTER, MUTYPE_BLOCK, AMSK_STYLE }, |
| 362 | { "cite", MARKUP_CITE, MUTYPE_FONT, AMSK_STYLE }, |
| 363 | { "code", MARKUP_CODE, MUTYPE_FONT, AMSK_STYLE }, |
| 364 | { "col", MARKUP_COL, MUTYPE_SINGLE, |
| 365 | AMSK_ALIGN|AMSK_CLASS|AMSK_COLSPAN|AMSK_WIDTH|AMSK_STYLE }, |
| @@ -326,18 +366,22 @@ | |
| 366 | { "colgroup", MARKUP_COLGROUP, MUTYPE_BLOCK, |
| 367 | AMSK_ALIGN|AMSK_CLASS|AMSK_COLSPAN|AMSK_WIDTH|AMSK_STYLE}, |
| 368 | { "dd", MARKUP_DD, MUTYPE_LI, AMSK_STYLE }, |
| 369 | { "del", MARKUP_DEL, MUTYPE_FONT, AMSK_STYLE }, |
| 370 | { "details", MARKUP_DETAILS, MUTYPE_BLOCK, |
| 371 | AMSK_ID|AMSK_CLASS|AMSK_STYLE|AMSK_OPEN }, |
| 372 | { "dfn", MARKUP_DFN, MUTYPE_FONT, AMSK_STYLE }, |
| 373 | { "div", MARKUP_DIV, MUTYPE_BLOCK, |
| 374 | AMSK_ID|AMSK_CLASS|AMSK_STYLE }, |
| 375 | { "dl", MARKUP_DL, MUTYPE_LIST, |
| 376 | AMSK_COMPACT|AMSK_STYLE }, |
| 377 | { "dt", MARKUP_DT, MUTYPE_LI, AMSK_STYLE }, |
| 378 | { "em", MARKUP_EM, MUTYPE_FONT, AMSK_STYLE }, |
| 379 | { "figcaption", MARKUP_FIGCAPTION, MUTYPE_BLOCK, |
| 380 | AMSK_ID|AMSK_CLASS|AMSK_STYLE }, |
| 381 | { "figure", MARKUP_FIGURE, MUTYPE_BLOCK, |
| 382 | AMSK_ID|AMSK_CLASS|AMSK_STYLE }, |
| 383 | { "font", MARKUP_FONT, MUTYPE_FONT, |
| 384 | AMSK_COLOR|AMSK_FACE|AMSK_SIZE|AMSK_STYLE }, |
| 385 | { "footer", MARKUP_HTML5_FOOTER, MUTYPE_BLOCK, |
| 386 | AMSK_ID|AMSK_CLASS|AMSK_STYLE }, |
| 387 | { "h1", MARKUP_H1, MUTYPE_BLOCK, |
| @@ -358,29 +402,43 @@ | |
| 402 | AMSK_ALIGN|AMSK_COLOR|AMSK_SIZE|AMSK_WIDTH| |
| 403 | AMSK_STYLE|AMSK_CLASS }, |
| 404 | { "i", MARKUP_I, MUTYPE_FONT, AMSK_STYLE }, |
| 405 | { "img", MARKUP_IMG, MUTYPE_SINGLE, |
| 406 | AMSK_ALIGN|AMSK_ALT|AMSK_BORDER|AMSK_HEIGHT| |
| 407 | AMSK_HSPACE|AMSK_SRC|AMSK_VSPACE|AMSK_WIDTH|AMSK_STYLE }, |
| 408 | { "ins", MARKUP_INS, MUTYPE_FONT, AMSK_STYLE }, |
| 409 | { "kbd", MARKUP_KBD, MUTYPE_FONT, AMSK_STYLE }, |
| 410 | { "label", MARKUP_LABEL, MUTYPE_FONT, |
| 411 | AMSK_ID|AMSK_CLASS|AMSK_STYLE }, |
| 412 | { "li", MARKUP_LI, MUTYPE_LI, |
| 413 | AMSK_TYPE|AMSK_VALUE|AMSK_STYLE }, |
| 414 | { "mark", MARKUP_MARK, MUTYPE_FONT, |
| 415 | AMSK_ID|AMSK_CLASS|AMSK_STYLE }, |
| 416 | { "meter", MARKUP_METER, MUTYPE_FONT, |
| 417 | AMSK_ID|AMSK_CLASS|AMSK_STYLE|AMSK_VALUE }, |
| 418 | { "nav", MARKUP_HTML5_NAV, MUTYPE_BLOCK, |
| 419 | AMSK_ID|AMSK_CLASS|AMSK_STYLE }, |
| 420 | { "nobr", MARKUP_NOBR, MUTYPE_FONT, 0 }, |
| 421 | { "nowiki", MARKUP_NOWIKI, MUTYPE_SPECIAL, 0 }, |
| 422 | { "ol", MARKUP_OL, MUTYPE_LIST, |
| 423 | AMSK_START|AMSK_TYPE|AMSK_COMPACT|AMSK_STYLE }, |
| 424 | { "p", MARKUP_P, MUTYPE_BLOCK, |
| 425 | AMSK_ALIGN|AMSK_CLASS|AMSK_STYLE }, |
| 426 | { "picture", MARKUP_PICTURE, MUTYPE_BLOCK, |
| 427 | AMSK_ID|AMSK_CLASS|AMSK_STYLE }, |
| 428 | { "pre", MARKUP_PRE, MUTYPE_BLOCK, AMSK_STYLE }, |
| 429 | { "progress", MARKUP_PROGRESS, MUTYPE_FONT, |
| 430 | AMSK_ID|AMSK_CLASS|AMSK_STYLE|AMSK_VALUE }, |
| 431 | { "q", MARKUP_Q, MUTYPE_FONT, |
| 432 | AMSK_CLASS|AMSK_STYLE|AMSK_CITE }, |
| 433 | { "s", MARKUP_S, MUTYPE_FONT, AMSK_STYLE }, |
| 434 | { "samp", MARKUP_SAMP, MUTYPE_FONT, AMSK_STYLE }, |
| 435 | { "section", MARKUP_HTML5_SECTION, MUTYPE_BLOCK, |
| 436 | AMSK_ID|AMSK_CLASS|AMSK_STYLE }, |
| 437 | { "small", MARKUP_SMALL, MUTYPE_FONT, AMSK_STYLE }, |
| 438 | { "source", MARKUP_SOURCE, MUTYPE_SINGLE, |
| 439 | AMSK_TYPE|AMSK_ID|AMSK_CLASS|AMSK_STYLE }, |
| 440 | { "span", MARKUP_SPAN, MUTYPE_BLOCK, |
| 441 | AMSK_ALIGN|AMSK_CLASS|AMSK_STYLE }, |
| 442 | { "strike", MARKUP_STRIKE, MUTYPE_FONT, AMSK_STYLE }, |
| 443 | { "strong", MARKUP_STRONG, MUTYPE_FONT, AMSK_STYLE }, |
| 444 | { "sub", MARKUP_SUB, MUTYPE_FONT, AMSK_STYLE }, |
| @@ -401,18 +459,21 @@ | |
| 459 | { "th", MARKUP_TH, MUTYPE_TD, |
| 460 | AMSK_ALIGN|AMSK_BGCOLOR|AMSK_COLSPAN| |
| 461 | AMSK_ROWSPAN|AMSK_VALIGN|AMSK_CLASS|AMSK_STYLE }, |
| 462 | { "thead", MARKUP_THEAD, MUTYPE_BLOCK, |
| 463 | AMSK_ALIGN|AMSK_CLASS|AMSK_STYLE }, |
| 464 | { "time", MARKUP_TIME, MUTYPE_FONT, |
| 465 | AMSK_DATETIME|AMSK_ID|AMSK_CLASS|AMSK_STYLE|AMSK_TITLE }, |
| 466 | { "title", MARKUP_TITLE, MUTYPE_BLOCK, 0 }, |
| 467 | { "tr", MARKUP_TR, MUTYPE_TR, |
| 468 | AMSK_ALIGN|AMSK_BGCOLOR|AMSK_VALIGN|AMSK_CLASS|AMSK_STYLE }, |
| 469 | { "tt", MARKUP_TT, MUTYPE_FONT, AMSK_STYLE }, |
| 470 | { "u", MARKUP_U, MUTYPE_FONT, AMSK_STYLE }, |
| 471 | { "ul", MARKUP_UL, MUTYPE_LIST, |
| 472 | AMSK_TYPE|AMSK_COMPACT|AMSK_STYLE }, |
| 473 | { "var", MARKUP_VAR, MUTYPE_FONT, AMSK_STYLE }, |
| 474 | { "wbr", MARKUP_WBR, MUTYPE_SINGLE, 0 }, |
| 475 | { "verbatim", MARKUP_VERBATIM, MUTYPE_SPECIAL, |
| 476 | AMSK_ID|AMSK_TYPE }, |
| 477 | }; |
| 478 | |
| 479 | void show_allowed_wiki_markup( void ){ |
| @@ -816,23 +877,34 @@ | |
| 877 | unsigned char iACode; /* ATTR_* */ |
| 878 | char *zValue; /* Argument to this attribute. Might be NULL */ |
| 879 | char cTerm; /* Original argument termination character */ |
| 880 | } aAttr[10]; |
| 881 | }; |
| 882 | |
| 883 | /* |
| 884 | ** Return true if attribute iACode has already been parsed into p. |
| 885 | */ |
| 886 | static int markupHasAttr(const ParsedMarkup *p, int iACode){ |
| 887 | int i; |
| 888 | for(i=0; i<p->nAttr; i++){ |
| 889 | if( p->aAttr[i].iACode==iACode ) return 1; |
| 890 | } |
| 891 | return 0; |
| 892 | } |
| 893 | |
| 894 | /* |
| 895 | ** z[] is an HTML markup element - something that begins with '<'. |
| 896 | ** Parse this element into the p structure. |
| 897 | ** |
| 898 | ** The content of z[] might be modified by converting characters |
| 899 | ** to lowercase and by inserting some "\000" characters. |
| 900 | */ |
| 901 | static amsk_t parseMarkup(ParsedMarkup *p, char *z){ |
| 902 | int i, j, c; |
| 903 | int iACode; |
| 904 | char *zValue; |
| 905 | amsk_t seen = 0; |
| 906 | char zTag[100]; |
| 907 | |
| 908 | if( z[1]=='/' ){ |
| 909 | p->endTag = 1; |
| 910 | i = 2; |
| @@ -868,11 +940,11 @@ | |
| 940 | if( j<(int)sizeof(zTag)-1 ) zTag[j++] = fossil_tolower(z[i]); |
| 941 | i++; |
| 942 | } |
| 943 | zTag[j] = 0; |
| 944 | p->aAttr[p->nAttr].iACode = iACode = findAttr(zTag); |
| 945 | attrOk = iACode!=0 && !markupHasAttr(p, iACode); |
| 946 | while( fossil_isspace(z[i]) ){ z++; } |
| 947 | if( z[i]!='=' ){ |
| 948 | p->aAttr[p->nAttr].zValue = 0; |
| 949 | p->aAttr[p->nAttr].cTerm = 0; |
| 950 | c = 0; |
| @@ -904,11 +976,11 @@ | |
| 976 | } |
| 977 | } |
| 978 | i++; |
| 979 | } |
| 980 | if( attrOk ){ |
| 981 | if( aAttribute[iACode].iMask ) seen |= aAttribute[iACode].iMask; |
| 982 | p->nAttr++; |
| 983 | } |
| 984 | while( fossil_isspace(z[i]) ){ i++; } |
| 985 | if( z[i]==0 || z[i]=='>' || (z[i]=='/' && z[i+1]=='>') ) break; |
| 986 | } |
| @@ -1712,17 +1784,17 @@ | |
| 1784 | break; |
| 1785 | } |
| 1786 | case TOKEN_MARKUP: { |
| 1787 | const char *zId; |
| 1788 | int iDiv; |
| 1789 | (void)parseMarkup(&markup, z); |
| 1790 | |
| 1791 | /* Convert <title> to <h1 align='center'> */ |
| 1792 | if( markup.iCode==MARKUP_TITLE && !p->inVerbatim ){ |
| 1793 | markup.iCode = MARKUP_H1; |
| 1794 | markup.nAttr = 1; |
| 1795 | markup.aAttr[0].iACode = ATTR_ALIGN; |
| 1796 | markup.aAttr[0].zValue = "center"; |
| 1797 | markup.aAttr[0].cTerm = 0; |
| 1798 | } |
| 1799 | |
| 1800 | /* Markup of the form </div id=ID> where there is a matching |
| @@ -1801,11 +1873,11 @@ | |
| 1873 | popStackToTag(p, markup.iCode); |
| 1874 | }else |
| 1875 | |
| 1876 | /* Push <div> markup onto the stack together with the id=ID attribute. |
| 1877 | */ |
| 1878 | if( markup.iCode==MARKUP_DIV && attributeValue(&markup, ATTR_ID)!=0 ){ |
| 1879 | pushStackWithId(p, markup.iCode, markupId(&markup), |
| 1880 | (p->state & ALLOW_WIKI)!=0); |
| 1881 | }else |
| 1882 | |
| 1883 | /* Enter <verbatim> processing. With verbatim enabled, all other |
| 1884 |
+4
-1
| --- tools/makemake.tcl | ||
| +++ tools/makemake.tcl | ||
| @@ -346,11 +346,11 @@ | ||
| 346 | 346 | # |
| 347 | 347 | |
| 348 | 348 | XBCC = $(BCC) $(BCCFLAGS) |
| 349 | 349 | XTCC = $(TCC) $(CFLAGS_INCLUDE) -I$(OBJDIR) $(TCCFLAGS) |
| 350 | 350 | |
| 351 | -TESTFLAGS := -quiet | |
| 351 | +TESTFLAGS = -quiet | |
| 352 | 352 | } |
| 353 | 353 | writeln -nonewline "SRC =" |
| 354 | 354 | foreach s [lsort $src] { |
| 355 | 355 | writeln -nonewline " \\\n \$(SRCDIR)/$s.c" |
| 356 | 356 | } |
| @@ -549,17 +549,20 @@ | ||
| 549 | 549 | writeln "\t\$(XTCC) -o \$(OBJDIR)/$s.o -c \$(OBJDIR)/${s}_.c\n" |
| 550 | 550 | writeln "\$(OBJDIR)/$s.h:\t\$(OBJDIR)/headers\n" |
| 551 | 551 | } |
| 552 | 552 | |
| 553 | 553 | writeln "\$(SQLITE3_OBJ):\t\$(SQLITE3_SRC)" |
| 554 | +writeln "\t-mkdir -p \$(OBJDIR)" | |
| 554 | 555 | writeln "\t\$(XTCC) \$(SQLITE_OPTIONS) \$(SQLITE_CFLAGS) \$(SEE_FLAGS) \\" |
| 555 | 556 | writeln "\t\t-c \$(SQLITE3_SRC) -o \$@" |
| 556 | 557 | |
| 557 | 558 | writeln "\$(OBJDIR)/shell.o:\t\$(SQLITE3_SHELL_SRC) \$(SRCDIR_extsrc)/sqlite3.h" |
| 559 | +writeln "\t-mkdir -p \$(OBJDIR)" | |
| 558 | 560 | writeln "\t\$(XTCC) \$(SHELL_OPTIONS) \$(SHELL_CFLAGS) \$(SEE_FLAGS) \$(LINENOISE_DEF.\$(USE_LINENOISE)) -c \$(SQLITE3_SHELL_SRC) -o \$@\n" |
| 559 | 561 | |
| 560 | 562 | writeln "\$(OBJDIR)/linenoise.o:\t\$(SRCDIR_extsrc)/linenoise.c \$(SRCDIR_extsrc)/linenoise.h" |
| 563 | +writeln "\t-mkdir -p \$(OBJDIR)" | |
| 561 | 564 | writeln "\t\$(XTCC) -c \$(SRCDIR_extsrc)/linenoise.c -o \$@\n" |
| 562 | 565 | |
| 563 | 566 | writeln "\$(OBJDIR)/th.o:\t\$(SRCDIR)/th.c" |
| 564 | 567 | writeln "\t-mkdir -p \$(OBJDIR)\n" |
| 565 | 568 | writeln "\t\$(XTCC) -c \$(SRCDIR)/th.c -o \$@\n" |
| 566 | 569 |
| --- tools/makemake.tcl | |
| +++ tools/makemake.tcl | |
| @@ -346,11 +346,11 @@ | |
| 346 | # |
| 347 | |
| 348 | XBCC = $(BCC) $(BCCFLAGS) |
| 349 | XTCC = $(TCC) $(CFLAGS_INCLUDE) -I$(OBJDIR) $(TCCFLAGS) |
| 350 | |
| 351 | TESTFLAGS := -quiet |
| 352 | } |
| 353 | writeln -nonewline "SRC =" |
| 354 | foreach s [lsort $src] { |
| 355 | writeln -nonewline " \\\n \$(SRCDIR)/$s.c" |
| 356 | } |
| @@ -549,17 +549,20 @@ | |
| 549 | writeln "\t\$(XTCC) -o \$(OBJDIR)/$s.o -c \$(OBJDIR)/${s}_.c\n" |
| 550 | writeln "\$(OBJDIR)/$s.h:\t\$(OBJDIR)/headers\n" |
| 551 | } |
| 552 | |
| 553 | writeln "\$(SQLITE3_OBJ):\t\$(SQLITE3_SRC)" |
| 554 | writeln "\t\$(XTCC) \$(SQLITE_OPTIONS) \$(SQLITE_CFLAGS) \$(SEE_FLAGS) \\" |
| 555 | writeln "\t\t-c \$(SQLITE3_SRC) -o \$@" |
| 556 | |
| 557 | writeln "\$(OBJDIR)/shell.o:\t\$(SQLITE3_SHELL_SRC) \$(SRCDIR_extsrc)/sqlite3.h" |
| 558 | writeln "\t\$(XTCC) \$(SHELL_OPTIONS) \$(SHELL_CFLAGS) \$(SEE_FLAGS) \$(LINENOISE_DEF.\$(USE_LINENOISE)) -c \$(SQLITE3_SHELL_SRC) -o \$@\n" |
| 559 | |
| 560 | writeln "\$(OBJDIR)/linenoise.o:\t\$(SRCDIR_extsrc)/linenoise.c \$(SRCDIR_extsrc)/linenoise.h" |
| 561 | writeln "\t\$(XTCC) -c \$(SRCDIR_extsrc)/linenoise.c -o \$@\n" |
| 562 | |
| 563 | writeln "\$(OBJDIR)/th.o:\t\$(SRCDIR)/th.c" |
| 564 | writeln "\t-mkdir -p \$(OBJDIR)\n" |
| 565 | writeln "\t\$(XTCC) -c \$(SRCDIR)/th.c -o \$@\n" |
| 566 |
| --- tools/makemake.tcl | |
| +++ tools/makemake.tcl | |
| @@ -346,11 +346,11 @@ | |
| 346 | # |
| 347 | |
| 348 | XBCC = $(BCC) $(BCCFLAGS) |
| 349 | XTCC = $(TCC) $(CFLAGS_INCLUDE) -I$(OBJDIR) $(TCCFLAGS) |
| 350 | |
| 351 | TESTFLAGS = -quiet |
| 352 | } |
| 353 | writeln -nonewline "SRC =" |
| 354 | foreach s [lsort $src] { |
| 355 | writeln -nonewline " \\\n \$(SRCDIR)/$s.c" |
| 356 | } |
| @@ -549,17 +549,20 @@ | |
| 549 | writeln "\t\$(XTCC) -o \$(OBJDIR)/$s.o -c \$(OBJDIR)/${s}_.c\n" |
| 550 | writeln "\$(OBJDIR)/$s.h:\t\$(OBJDIR)/headers\n" |
| 551 | } |
| 552 | |
| 553 | writeln "\$(SQLITE3_OBJ):\t\$(SQLITE3_SRC)" |
| 554 | writeln "\t-mkdir -p \$(OBJDIR)" |
| 555 | writeln "\t\$(XTCC) \$(SQLITE_OPTIONS) \$(SQLITE_CFLAGS) \$(SEE_FLAGS) \\" |
| 556 | writeln "\t\t-c \$(SQLITE3_SRC) -o \$@" |
| 557 | |
| 558 | writeln "\$(OBJDIR)/shell.o:\t\$(SQLITE3_SHELL_SRC) \$(SRCDIR_extsrc)/sqlite3.h" |
| 559 | writeln "\t-mkdir -p \$(OBJDIR)" |
| 560 | writeln "\t\$(XTCC) \$(SHELL_OPTIONS) \$(SHELL_CFLAGS) \$(SEE_FLAGS) \$(LINENOISE_DEF.\$(USE_LINENOISE)) -c \$(SQLITE3_SHELL_SRC) -o \$@\n" |
| 561 | |
| 562 | writeln "\$(OBJDIR)/linenoise.o:\t\$(SRCDIR_extsrc)/linenoise.c \$(SRCDIR_extsrc)/linenoise.h" |
| 563 | writeln "\t-mkdir -p \$(OBJDIR)" |
| 564 | writeln "\t\$(XTCC) -c \$(SRCDIR_extsrc)/linenoise.c -o \$@\n" |
| 565 | |
| 566 | writeln "\$(OBJDIR)/th.o:\t\$(SRCDIR)/th.c" |
| 567 | writeln "\t-mkdir -p \$(OBJDIR)\n" |
| 568 | writeln "\t\$(XTCC) -c \$(SRCDIR)/th.c -o \$@\n" |
| 569 |
+2
| --- win/Makefile.mingw | ||
| +++ win/Makefile.mingw | ||
| @@ -611,10 +611,11 @@ | ||
| 611 | 611 | $(SRCDIR)/copybtn.js \ |
| 612 | 612 | $(SRCDIR)/default.css \ |
| 613 | 613 | $(SRCDIR)/diff.js \ |
| 614 | 614 | $(SRCDIR)/diff.tcl \ |
| 615 | 615 | $(SRCDIR)/forum.js \ |
| 616 | + $(SRCDIR)/fossil.attach.js \ | |
| 616 | 617 | $(SRCDIR)/fossil.bootstrap.js \ |
| 617 | 618 | $(SRCDIR)/fossil.confirmer.js \ |
| 618 | 619 | $(SRCDIR)/fossil.copybutton.js \ |
| 619 | 620 | $(SRCDIR)/fossil.diff.js \ |
| 620 | 621 | $(SRCDIR)/fossil.dom.js \ |
| @@ -661,10 +662,11 @@ | ||
| 661 | 662 | $(SRCDIR)/sounds/e.wav \ |
| 662 | 663 | $(SRCDIR)/sounds/f.wav \ |
| 663 | 664 | $(SRCDIR)/style.admin_log.css \ |
| 664 | 665 | $(SRCDIR)/style.chat.css \ |
| 665 | 666 | $(SRCDIR)/style.fileedit.css \ |
| 667 | + $(SRCDIR)/style.forum.css \ | |
| 666 | 668 | $(SRCDIR)/style.pikchrshow.css \ |
| 667 | 669 | $(SRCDIR)/style.uvlist.css \ |
| 668 | 670 | $(SRCDIR)/style.wikiedit.css \ |
| 669 | 671 | $(SRCDIR)/tree.js \ |
| 670 | 672 | $(SRCDIR)/useredit.js \ |
| 671 | 673 |
| --- win/Makefile.mingw | |
| +++ win/Makefile.mingw | |
| @@ -611,10 +611,11 @@ | |
| 611 | $(SRCDIR)/copybtn.js \ |
| 612 | $(SRCDIR)/default.css \ |
| 613 | $(SRCDIR)/diff.js \ |
| 614 | $(SRCDIR)/diff.tcl \ |
| 615 | $(SRCDIR)/forum.js \ |
| 616 | $(SRCDIR)/fossil.bootstrap.js \ |
| 617 | $(SRCDIR)/fossil.confirmer.js \ |
| 618 | $(SRCDIR)/fossil.copybutton.js \ |
| 619 | $(SRCDIR)/fossil.diff.js \ |
| 620 | $(SRCDIR)/fossil.dom.js \ |
| @@ -661,10 +662,11 @@ | |
| 661 | $(SRCDIR)/sounds/e.wav \ |
| 662 | $(SRCDIR)/sounds/f.wav \ |
| 663 | $(SRCDIR)/style.admin_log.css \ |
| 664 | $(SRCDIR)/style.chat.css \ |
| 665 | $(SRCDIR)/style.fileedit.css \ |
| 666 | $(SRCDIR)/style.pikchrshow.css \ |
| 667 | $(SRCDIR)/style.uvlist.css \ |
| 668 | $(SRCDIR)/style.wikiedit.css \ |
| 669 | $(SRCDIR)/tree.js \ |
| 670 | $(SRCDIR)/useredit.js \ |
| 671 |
| --- win/Makefile.mingw | |
| +++ win/Makefile.mingw | |
| @@ -611,10 +611,11 @@ | |
| 611 | $(SRCDIR)/copybtn.js \ |
| 612 | $(SRCDIR)/default.css \ |
| 613 | $(SRCDIR)/diff.js \ |
| 614 | $(SRCDIR)/diff.tcl \ |
| 615 | $(SRCDIR)/forum.js \ |
| 616 | $(SRCDIR)/fossil.attach.js \ |
| 617 | $(SRCDIR)/fossil.bootstrap.js \ |
| 618 | $(SRCDIR)/fossil.confirmer.js \ |
| 619 | $(SRCDIR)/fossil.copybutton.js \ |
| 620 | $(SRCDIR)/fossil.diff.js \ |
| 621 | $(SRCDIR)/fossil.dom.js \ |
| @@ -661,10 +662,11 @@ | |
| 662 | $(SRCDIR)/sounds/e.wav \ |
| 663 | $(SRCDIR)/sounds/f.wav \ |
| 664 | $(SRCDIR)/style.admin_log.css \ |
| 665 | $(SRCDIR)/style.chat.css \ |
| 666 | $(SRCDIR)/style.fileedit.css \ |
| 667 | $(SRCDIR)/style.forum.css \ |
| 668 | $(SRCDIR)/style.pikchrshow.css \ |
| 669 | $(SRCDIR)/style.uvlist.css \ |
| 670 | $(SRCDIR)/style.wikiedit.css \ |
| 671 | $(SRCDIR)/tree.js \ |
| 672 | $(SRCDIR)/useredit.js \ |
| 673 |
+4
| --- win/Makefile.msc | ||
| +++ win/Makefile.msc | ||
| @@ -576,10 +576,11 @@ | ||
| 576 | 576 | "$(SRCDIR)\copybtn.js" \ |
| 577 | 577 | "$(SRCDIR)\default.css" \ |
| 578 | 578 | "$(SRCDIR)\diff.js" \ |
| 579 | 579 | "$(SRCDIR)\diff.tcl" \ |
| 580 | 580 | "$(SRCDIR)\forum.js" \ |
| 581 | + "$(SRCDIR)\fossil.attach.js" \ | |
| 581 | 582 | "$(SRCDIR)\fossil.bootstrap.js" \ |
| 582 | 583 | "$(SRCDIR)\fossil.confirmer.js" \ |
| 583 | 584 | "$(SRCDIR)\fossil.copybutton.js" \ |
| 584 | 585 | "$(SRCDIR)\fossil.diff.js" \ |
| 585 | 586 | "$(SRCDIR)\fossil.dom.js" \ |
| @@ -626,10 +627,11 @@ | ||
| 626 | 627 | "$(SRCDIR)\sounds\e.wav" \ |
| 627 | 628 | "$(SRCDIR)\sounds\f.wav" \ |
| 628 | 629 | "$(SRCDIR)\style.admin_log.css" \ |
| 629 | 630 | "$(SRCDIR)\style.chat.css" \ |
| 630 | 631 | "$(SRCDIR)\style.fileedit.css" \ |
| 632 | + "$(SRCDIR)\style.forum.css" \ | |
| 631 | 633 | "$(SRCDIR)\style.pikchrshow.css" \ |
| 632 | 634 | "$(SRCDIR)\style.uvlist.css" \ |
| 633 | 635 | "$(SRCDIR)\style.wikiedit.css" \ |
| 634 | 636 | "$(SRCDIR)\tree.js" \ |
| 635 | 637 | "$(SRCDIR)\useredit.js" \ |
| @@ -1214,10 +1216,11 @@ | ||
| 1214 | 1216 | echo "$(SRCDIR)\copybtn.js" >> $@ |
| 1215 | 1217 | echo "$(SRCDIR)\default.css" >> $@ |
| 1216 | 1218 | echo "$(SRCDIR)\diff.js" >> $@ |
| 1217 | 1219 | echo "$(SRCDIR)\diff.tcl" >> $@ |
| 1218 | 1220 | echo "$(SRCDIR)\forum.js" >> $@ |
| 1221 | + echo "$(SRCDIR)\fossil.attach.js" >> $@ | |
| 1219 | 1222 | echo "$(SRCDIR)\fossil.bootstrap.js" >> $@ |
| 1220 | 1223 | echo "$(SRCDIR)\fossil.confirmer.js" >> $@ |
| 1221 | 1224 | echo "$(SRCDIR)\fossil.copybutton.js" >> $@ |
| 1222 | 1225 | echo "$(SRCDIR)\fossil.diff.js" >> $@ |
| 1223 | 1226 | echo "$(SRCDIR)\fossil.dom.js" >> $@ |
| @@ -1264,10 +1267,11 @@ | ||
| 1264 | 1267 | echo "$(SRCDIR)\sounds/e.wav" >> $@ |
| 1265 | 1268 | echo "$(SRCDIR)\sounds/f.wav" >> $@ |
| 1266 | 1269 | echo "$(SRCDIR)\style.admin_log.css" >> $@ |
| 1267 | 1270 | echo "$(SRCDIR)\style.chat.css" >> $@ |
| 1268 | 1271 | echo "$(SRCDIR)\style.fileedit.css" >> $@ |
| 1272 | + echo "$(SRCDIR)\style.forum.css" >> $@ | |
| 1269 | 1273 | echo "$(SRCDIR)\style.pikchrshow.css" >> $@ |
| 1270 | 1274 | echo "$(SRCDIR)\style.uvlist.css" >> $@ |
| 1271 | 1275 | echo "$(SRCDIR)\style.wikiedit.css" >> $@ |
| 1272 | 1276 | echo "$(SRCDIR)\tree.js" >> $@ |
| 1273 | 1277 | echo "$(SRCDIR)\useredit.js" >> $@ |
| 1274 | 1278 |
| --- win/Makefile.msc | |
| +++ win/Makefile.msc | |
| @@ -576,10 +576,11 @@ | |
| 576 | "$(SRCDIR)\copybtn.js" \ |
| 577 | "$(SRCDIR)\default.css" \ |
| 578 | "$(SRCDIR)\diff.js" \ |
| 579 | "$(SRCDIR)\diff.tcl" \ |
| 580 | "$(SRCDIR)\forum.js" \ |
| 581 | "$(SRCDIR)\fossil.bootstrap.js" \ |
| 582 | "$(SRCDIR)\fossil.confirmer.js" \ |
| 583 | "$(SRCDIR)\fossil.copybutton.js" \ |
| 584 | "$(SRCDIR)\fossil.diff.js" \ |
| 585 | "$(SRCDIR)\fossil.dom.js" \ |
| @@ -626,10 +627,11 @@ | |
| 626 | "$(SRCDIR)\sounds\e.wav" \ |
| 627 | "$(SRCDIR)\sounds\f.wav" \ |
| 628 | "$(SRCDIR)\style.admin_log.css" \ |
| 629 | "$(SRCDIR)\style.chat.css" \ |
| 630 | "$(SRCDIR)\style.fileedit.css" \ |
| 631 | "$(SRCDIR)\style.pikchrshow.css" \ |
| 632 | "$(SRCDIR)\style.uvlist.css" \ |
| 633 | "$(SRCDIR)\style.wikiedit.css" \ |
| 634 | "$(SRCDIR)\tree.js" \ |
| 635 | "$(SRCDIR)\useredit.js" \ |
| @@ -1214,10 +1216,11 @@ | |
| 1214 | echo "$(SRCDIR)\copybtn.js" >> $@ |
| 1215 | echo "$(SRCDIR)\default.css" >> $@ |
| 1216 | echo "$(SRCDIR)\diff.js" >> $@ |
| 1217 | echo "$(SRCDIR)\diff.tcl" >> $@ |
| 1218 | echo "$(SRCDIR)\forum.js" >> $@ |
| 1219 | echo "$(SRCDIR)\fossil.bootstrap.js" >> $@ |
| 1220 | echo "$(SRCDIR)\fossil.confirmer.js" >> $@ |
| 1221 | echo "$(SRCDIR)\fossil.copybutton.js" >> $@ |
| 1222 | echo "$(SRCDIR)\fossil.diff.js" >> $@ |
| 1223 | echo "$(SRCDIR)\fossil.dom.js" >> $@ |
| @@ -1264,10 +1267,11 @@ | |
| 1264 | echo "$(SRCDIR)\sounds/e.wav" >> $@ |
| 1265 | echo "$(SRCDIR)\sounds/f.wav" >> $@ |
| 1266 | echo "$(SRCDIR)\style.admin_log.css" >> $@ |
| 1267 | echo "$(SRCDIR)\style.chat.css" >> $@ |
| 1268 | echo "$(SRCDIR)\style.fileedit.css" >> $@ |
| 1269 | echo "$(SRCDIR)\style.pikchrshow.css" >> $@ |
| 1270 | echo "$(SRCDIR)\style.uvlist.css" >> $@ |
| 1271 | echo "$(SRCDIR)\style.wikiedit.css" >> $@ |
| 1272 | echo "$(SRCDIR)\tree.js" >> $@ |
| 1273 | echo "$(SRCDIR)\useredit.js" >> $@ |
| 1274 |
| --- win/Makefile.msc | |
| +++ win/Makefile.msc | |
| @@ -576,10 +576,11 @@ | |
| 576 | "$(SRCDIR)\copybtn.js" \ |
| 577 | "$(SRCDIR)\default.css" \ |
| 578 | "$(SRCDIR)\diff.js" \ |
| 579 | "$(SRCDIR)\diff.tcl" \ |
| 580 | "$(SRCDIR)\forum.js" \ |
| 581 | "$(SRCDIR)\fossil.attach.js" \ |
| 582 | "$(SRCDIR)\fossil.bootstrap.js" \ |
| 583 | "$(SRCDIR)\fossil.confirmer.js" \ |
| 584 | "$(SRCDIR)\fossil.copybutton.js" \ |
| 585 | "$(SRCDIR)\fossil.diff.js" \ |
| 586 | "$(SRCDIR)\fossil.dom.js" \ |
| @@ -626,10 +627,11 @@ | |
| 627 | "$(SRCDIR)\sounds\e.wav" \ |
| 628 | "$(SRCDIR)\sounds\f.wav" \ |
| 629 | "$(SRCDIR)\style.admin_log.css" \ |
| 630 | "$(SRCDIR)\style.chat.css" \ |
| 631 | "$(SRCDIR)\style.fileedit.css" \ |
| 632 | "$(SRCDIR)\style.forum.css" \ |
| 633 | "$(SRCDIR)\style.pikchrshow.css" \ |
| 634 | "$(SRCDIR)\style.uvlist.css" \ |
| 635 | "$(SRCDIR)\style.wikiedit.css" \ |
| 636 | "$(SRCDIR)\tree.js" \ |
| 637 | "$(SRCDIR)\useredit.js" \ |
| @@ -1214,10 +1216,11 @@ | |
| 1216 | echo "$(SRCDIR)\copybtn.js" >> $@ |
| 1217 | echo "$(SRCDIR)\default.css" >> $@ |
| 1218 | echo "$(SRCDIR)\diff.js" >> $@ |
| 1219 | echo "$(SRCDIR)\diff.tcl" >> $@ |
| 1220 | echo "$(SRCDIR)\forum.js" >> $@ |
| 1221 | echo "$(SRCDIR)\fossil.attach.js" >> $@ |
| 1222 | echo "$(SRCDIR)\fossil.bootstrap.js" >> $@ |
| 1223 | echo "$(SRCDIR)\fossil.confirmer.js" >> $@ |
| 1224 | echo "$(SRCDIR)\fossil.copybutton.js" >> $@ |
| 1225 | echo "$(SRCDIR)\fossil.diff.js" >> $@ |
| 1226 | echo "$(SRCDIR)\fossil.dom.js" >> $@ |
| @@ -1264,10 +1267,11 @@ | |
| 1267 | echo "$(SRCDIR)\sounds/e.wav" >> $@ |
| 1268 | echo "$(SRCDIR)\sounds/f.wav" >> $@ |
| 1269 | echo "$(SRCDIR)\style.admin_log.css" >> $@ |
| 1270 | echo "$(SRCDIR)\style.chat.css" >> $@ |
| 1271 | echo "$(SRCDIR)\style.fileedit.css" >> $@ |
| 1272 | echo "$(SRCDIR)\style.forum.css" >> $@ |
| 1273 | echo "$(SRCDIR)\style.pikchrshow.css" >> $@ |
| 1274 | echo "$(SRCDIR)\style.uvlist.css" >> $@ |
| 1275 | echo "$(SRCDIR)\style.wikiedit.css" >> $@ |
| 1276 | echo "$(SRCDIR)\tree.js" >> $@ |
| 1277 | echo "$(SRCDIR)\useredit.js" >> $@ |
| 1278 |
+45
-36
| --- www/caps/ref.html | ||
| +++ www/caps/ref.html | ||
| @@ -56,28 +56,29 @@ | ||
| 56 | 56 | Admin users have <em>all</em> of the capabilities below except for |
| 57 | 57 | <a href="#s">setup</a>, <a herf="#x">Private</a>, and <a href="#y">WrUnver</a>. |
| 58 | 58 | See <a href="admin-v-setup.md">Admin vs. Setup</a> for a more |
| 59 | 59 | nuanced discussion. Mnemonic: <b>a</b>dministrate. |
| 60 | 60 | </td> |
| 61 | - </tr> | |
| 61 | + </tr> | |
| 62 | 62 | |
| 63 | 63 | <tr id="b"> |
| 64 | 64 | <th>b</th> |
| 65 | 65 | <th>Attach</th> |
| 66 | 66 | <td> |
| 67 | - Add attachments to wiki articles or tickets. Mnemonics: <b>b</b>ind, | |
| 68 | - <b>b</b>utton, <b>b</b>ond, or <b>b</b>olt. | |
| 67 | + Add attachments to wiki articles, technotes, or tickets. | |
| 68 | + Mnemonics: <b>b</b>ind, <b>b</b>utton, <b>b</b>ond, or <b>b</b>olt. | |
| 69 | + See also: <a href='#B'>B</a>. | |
| 69 | 70 | </td> |
| 70 | - </tr> | |
| 71 | + </tr> | |
| 71 | 72 | |
| 72 | 73 | <tr id="c"> |
| 73 | 74 | <th>c</th> |
| 74 | 75 | <th>ApndTkt</th> |
| 75 | 76 | <td> |
| 76 | 77 | Append comments to existing tickets. Mnemonic: <b>c</b>omment. |
| 77 | 78 | </td> |
| 78 | - </tr> | |
| 79 | + </tr> | |
| 79 | 80 | |
| 80 | 81 | <tr id="d"> |
| 81 | 82 | <th>d</th> |
| 82 | 83 | <th>n/a</th> |
| 83 | 84 | <td> |
| @@ -100,21 +101,21 @@ | ||
| 100 | 101 | identifying information</a> (PII) about other users such as email |
| 101 | 102 | addresses. Mnemonics: show <b>e</b>mail addresses; or |
| 102 | 103 | <b>E</b>urope, home of <a |
| 103 | 104 | href="https://en.wikipedia.org/wiki/General_Data_Protection_Regulation">GDPR</a>. |
| 104 | 105 | </td> |
| 105 | - </tr> | |
| 106 | + </tr> | |
| 106 | 107 | |
| 107 | 108 | <tr id="f"> |
| 108 | 109 | <th>f</th> |
| 109 | 110 | <th>NewWiki</th> |
| 110 | 111 | <td> |
| 111 | 112 | Create new wiki articles. Mnemonic: <b>f</b>ast, English |
| 112 | 113 | translation of the Hawaiian word <a |
| 113 | 114 | href="https://en.wikipedia.org/wiki/History_of_wikis#WikiWikiWeb,_the_first_wiki"><i>wiki</i></a>. |
| 114 | 115 | </td> |
| 115 | - </tr> | |
| 116 | + </tr> | |
| 116 | 117 | |
| 117 | 118 | <tr id="g"> |
| 118 | 119 | <th>g</th> |
| 119 | 120 | <th>Clone</th> |
| 120 | 121 | <td> |
| @@ -121,11 +122,11 @@ | ||
| 121 | 122 | Clone the repository. Note that this is distinct from <a |
| 122 | 123 | href="#o">check-out capability, <b>o</b></a>; and that upon cloning |
| 123 | 124 | not just files, but also tickets, wikis, technotes and forum posts |
| 124 | 125 | are tranferred. Mnemonic: <b>g</b>et. |
| 125 | 126 | </td> |
| 126 | - </tr> | |
| 127 | + </tr> | |
| 127 | 128 | |
| 128 | 129 | <tr id="h"> |
| 129 | 130 | <th>h</th> |
| 130 | 131 | <th>Hyperlink</th> |
| 131 | 132 | <td> |
| @@ -134,11 +135,11 @@ | ||
| 134 | 135 | “nobody” category, to <a href="../antibot.wiki">prevent bots from |
| 135 | 136 | wandering around aimlessly</a> in the site’s hyperlink web, <a |
| 136 | 137 | href="../loadmgmt.md">chewing up server resources</a> to little |
| 137 | 138 | good purpose. Mnemonic: <b>h</b>yperlink. |
| 138 | 139 | </td> |
| 139 | - </tr> | |
| 140 | + </tr> | |
| 140 | 141 | |
| 141 | 142 | <tr id="i"> |
| 142 | 143 | <th>i</th> |
| 143 | 144 | <th>Write</th> |
| 144 | 145 | <td> |
| @@ -149,20 +150,20 @@ | ||
| 149 | 150 | Also note that not just files, but also tickets, wikis, technotes |
| 150 | 151 | and forum posts will be accepted from clones upon syncronization. |
| 151 | 152 | Granting this capability also grants <b>o (Read)</b> Mnemonics: |
| 152 | 153 | <b>i</b>nput, check <b>i</b>n changes. |
| 153 | 154 | </td> |
| 154 | - </tr> | |
| 155 | + </tr> | |
| 155 | 156 | |
| 156 | 157 | <tr id="j"> |
| 157 | 158 | <th>j</th> |
| 158 | 159 | <th>RdWiki</th> |
| 159 | 160 | <td> |
| 160 | 161 | View wiki articles. Mnemonic: in<b>j</b>est page content. (All |
| 161 | 162 | right, you critics, you do better, then.) |
| 162 | 163 | </td> |
| 163 | - </tr> | |
| 164 | + </tr> | |
| 164 | 165 | |
| 165 | 166 | <tr id="k"> |
| 166 | 167 | <th>k</th> |
| 167 | 168 | <th>WrWiki</th> |
| 168 | 169 | <td> |
| @@ -169,11 +170,11 @@ | ||
| 169 | 170 | Edit wiki articles. Granting this capability also grants <a |
| 170 | 171 | href="#j"><b>RdWiki</b></a> and <a href="#m"><b>ApndWiki</b></a>, |
| 171 | 172 | but it does <em>not</em> grant <a href="#f"><b>NewWiki</b></a>! |
| 172 | 173 | Mnemonic: <b>k</b>ontribute. |
| 173 | 174 | </td> |
| 174 | - </tr> | |
| 175 | + </tr> | |
| 175 | 176 | |
| 176 | 177 | <tr id="l"> |
| 177 | 178 | <th>l</th> |
| 178 | 179 | <th>ModWiki</th> |
| 179 | 180 | <td> |
| @@ -180,63 +181,63 @@ | ||
| 180 | 181 | Moderate <a href="#m">wiki article appends</a>. Appends do not get |
| 181 | 182 | saved permanently to the receiving repo’s block chain until <a |
| 182 | 183 | href="#s">Setup</a> or someone with this cap approves it. |
| 183 | 184 | Mnemonic: a<b>l</b>low. |
| 184 | 185 | </td> |
| 185 | - </tr> | |
| 186 | + </tr> | |
| 186 | 187 | |
| 187 | 188 | <tr id="m"> |
| 188 | 189 | <th>m</th> |
| 189 | 190 | <th>ApndWiki</th> |
| 190 | 191 | <td> |
| 191 | 192 | Append content to existing wiki articles. Mnemonic: a<b>m</b>end |
| 192 | 193 | wiki |
| 193 | 194 | </td> |
| 194 | - </tr> | |
| 195 | + </tr> | |
| 195 | 196 | |
| 196 | 197 | <tr id="n"> |
| 197 | 198 | <th>n</th> |
| 198 | 199 | <th>NewTkt</th> |
| 199 | 200 | <td> |
| 200 | 201 | File new tickets. Mnemonic: <b>n</b>ew ticket. |
| 201 | 202 | </td> |
| 202 | - </tr> | |
| 203 | + </tr> | |
| 203 | 204 | |
| 204 | 205 | <tr id="o"> |
| 205 | 206 | <th>o</th> |
| 206 | 207 | <th>Read</th> |
| 207 | 208 | <td> |
| 208 | 209 | Read content and history of files from a remote Fossil instance over |
| 209 | 210 | HTTP. See <a href="index.md#read-v-clone">Reading vs. |
| 210 | 211 | Cloning</a>. Mnemonic: check <b>o</b>ut remote repo contents. |
| 211 | 212 | </td> |
| 212 | - </tr> | |
| 213 | + </tr> | |
| 213 | 214 | |
| 214 | 215 | <tr id="p"> |
| 215 | 216 | <th>p</th> |
| 216 | 217 | <th>Password</th> |
| 217 | 218 | <td> |
| 218 | 219 | Change one’s own password. Mnemonic: <b>p</b>assword. |
| 219 | 220 | </td> |
| 220 | - </tr> | |
| 221 | + </tr> | |
| 221 | 222 | |
| 222 | 223 | <tr id="q"> |
| 223 | 224 | <th>q</th> |
| 224 | 225 | <th>ModTkt</th> |
| 225 | 226 | <td> |
| 226 | 227 | Moderate tickets: delete comments appended to tickets. Mnemonic: |
| 227 | 228 | <b>q</b>uash noise commentary. |
| 228 | 229 | </td> |
| 229 | - </tr> | |
| 230 | + </tr> | |
| 230 | 231 | |
| 231 | 232 | <tr id="r"> |
| 232 | 233 | <th>r</th> |
| 233 | 234 | <th>RdTkt</th> |
| 234 | 235 | <td> |
| 235 | 236 | View existing tickets. Mnemonic: <b>r</b>ead tickets. |
| 236 | 237 | </td> |
| 237 | - </tr> | |
| 238 | + </tr> | |
| 238 | 239 | |
| 239 | 240 | <tr id="s"> |
| 240 | 241 | <th>s</th> |
| 241 | 242 | <th>Setup</th> |
| 242 | 243 | <td> |
| @@ -256,41 +257,41 @@ | ||
| 256 | 257 | because it is internally restricted to read-only queries on the |
| 257 | 258 | tickets table only. (This restriction is done with an SQLite |
| 258 | 259 | authorization hook, not by any method so weak as SQL text |
| 259 | 260 | filtering.) Mnemonic: new <b>t</b>icket report. |
| 260 | 261 | </td> |
| 261 | - </tr> | |
| 262 | + </tr> | |
| 262 | 263 | |
| 263 | 264 | <tr id="u"> |
| 264 | 265 | <th>u</th> |
| 265 | 266 | <th>n/a</th> |
| 266 | 267 | <td> |
| 267 | 268 | Inherit all capabilities of the “reader” user category; does not |
| 268 | 269 | have a dedicated flag internally within Fossil. Mnemonic: |
| 269 | 270 | <a href="./index.md#ucat"><b>u</b>ser</a> |
| 270 | 271 | </td> |
| 271 | - </tr> | |
| 272 | + </tr> | |
| 272 | 273 | |
| 273 | 274 | <tr id="v"> |
| 274 | 275 | <th>v</th> |
| 275 | 276 | <th>n/a</th> |
| 276 | 277 | <td> |
| 277 | 278 | Inherit all capabilities of the “developer” user category; does |
| 278 | 279 | not have a dedicated flag internally within Fossil. Mnemonic: |
| 279 | 280 | de<b>v</b>eloper. |
| 280 | 281 | </td> |
| 281 | - </tr> | |
| 282 | + </tr> | |
| 282 | 283 | |
| 283 | 284 | <tr id="w"> |
| 284 | 285 | <th>w</th> |
| 285 | 286 | <th>WrTkt</th> |
| 286 | 287 | <td> |
| 287 | 288 | Edit existing tickets. Granting this capability also grants <a |
| 288 | 289 | href="#r"><b>RdTkt</b></a>, <a href="#c"><b>ApndTkt</b></a>, and |
| 289 | 290 | <a href="#n"><b>NewTkt</b></a>. Mnemonic: <b>w</b>rite to ticket. |
| 290 | 291 | </td> |
| 291 | - </tr> | |
| 292 | + </tr> | |
| 292 | 293 | |
| 293 | 294 | <tr id="x"> |
| 294 | 295 | <th>x</th> |
| 295 | 296 | <th>Private</th> |
| 296 | 297 | <td> |
| @@ -298,21 +299,21 @@ | ||
| 298 | 299 | Mnemonic: e<b>x</b>clusivity; “x” connotes unknown material in |
| 299 | 300 | many Western languages due to its <a |
| 300 | 301 | href="https://en.wikipedia.org/wiki/La_Géométrie#The_text">traditional |
| 301 | 302 | use in mathematics</a>. |
| 302 | 303 | </td> |
| 303 | - </tr> | |
| 304 | + </tr> | |
| 304 | 305 | |
| 305 | 306 | <tr id="y"> |
| 306 | 307 | <th>y</th> |
| 307 | 308 | <th>WrUnver</th> |
| 308 | 309 | <td> |
| 309 | 310 | Push <a href="../unvers.wiki">unversioned content</a>. Mnemonic: |
| 310 | 311 | <b>y</b>ield, <a href="https://en.wiktionary.org/wiki/yield">sense |
| 311 | 312 | 4</a>: “hand over.” |
| 312 | 313 | </td> |
| 313 | - </tr> | |
| 314 | + </tr> | |
| 314 | 315 | |
| 315 | 316 | <tr id="z"> |
| 316 | 317 | <th>z</th> |
| 317 | 318 | <th>Zip</th> |
| 318 | 319 | <td> |
| @@ -323,20 +324,20 @@ | ||
| 323 | 324 | expensive capability to grant, because creating such archives can |
| 324 | 325 | put a large load on <a href="../server/">a Fossil server</a> which |
| 325 | 326 | you may then need to <a href="../loadmgmt.md">manage</a>. |
| 326 | 327 | Mnemonic: <b>z</b>ip file download. |
| 327 | 328 | </td> |
| 328 | - </tr> | |
| 329 | + </tr> | |
| 329 | 330 | |
| 330 | 331 | <tr id="2"> |
| 331 | 332 | <th>2</th> |
| 332 | 333 | <th>RdForum</th> |
| 333 | 334 | <td> |
| 334 | 335 | Read <a href="../forum.wiki">forum posts</a> by other users. |
| 335 | 336 | Mnemonic: from thee <b>2</b> me. |
| 336 | 337 | </td> |
| 337 | - </tr> | |
| 338 | + </tr> | |
| 338 | 339 | |
| 339 | 340 | <tr id="3"> |
| 340 | 341 | <th>3</th> |
| 341 | 342 | <th>WrForum</th> |
| 342 | 343 | <td> |
| @@ -346,20 +347,20 @@ | ||
| 346 | 347 | not appear in repo clones or syncs. Granting this capability also |
| 347 | 348 | grants <a href="#2"><b>RdForum</b></a>. Mnemonic: post for |
| 348 | 349 | <b>3</b> audiences: me, <a href="#5">the mods</a>, and <a |
| 349 | 350 | href="https://en.wikipedia.org/wiki/The_Man">the Man</a>. |
| 350 | 351 | </td> |
| 351 | - </tr> | |
| 352 | + </tr> | |
| 352 | 353 | |
| 353 | 354 | <tr id="4"> |
| 354 | 355 | <th>4</th> |
| 355 | 356 | <th>WrTForum</th> |
| 356 | 357 | <td> |
| 357 | 358 | Extends <a href="#3"><b>WrForum</b></a>, bypassing the moderation |
| 358 | 359 | and sync restrictions. Mnemonic: post <b>4</b> immediate release. |
| 359 | 360 | </td> |
| 360 | - </tr> | |
| 361 | + </tr> | |
| 361 | 362 | |
| 362 | 363 | <tr id="5"> |
| 363 | 364 | <th>5</th> |
| 364 | 365 | <th>ModForum</th> |
| 365 | 366 | <td> |
| @@ -368,11 +369,11 @@ | ||
| 368 | 369 | href="#4"><b>WrTForum</b></a> and <a href="#2"><b>RdForum</b></a>, |
| 369 | 370 | so a user with this cap never has to moderate their own posts. |
| 370 | 371 | Mnemonic: “May I have <b>5</b> seconds of your time, honored |
| 371 | 372 | Gatekeeper?” |
| 372 | 373 | </td> |
| 373 | - </tr> | |
| 374 | + </tr> | |
| 374 | 375 | |
| 375 | 376 | <tr id="6"> |
| 376 | 377 | <th>6</th> |
| 377 | 378 | <th>AdminForum</th> |
| 378 | 379 | <td> |
| @@ -387,46 +388,54 @@ | ||
| 387 | 388 | currently revoke granted caps. Granting this capability also |
| 388 | 389 | grants <a href="#5"><b>ModForum</b></a> and those it in turn |
| 389 | 390 | grants. Mnemonic: “I’m <b>6</b> [sick] of hitting Approve on your |
| 390 | 391 | posts!” |
| 391 | 392 | </td> |
| 392 | - </tr> | |
| 393 | + </tr> | |
| 393 | 394 | |
| 394 | 395 | <tr id="7"> |
| 395 | 396 | <th>7</th> |
| 396 | 397 | <th>EmailAlert</th> |
| 397 | 398 | <td> |
| 398 | 399 | User can sign up for <a href="../alerts.md">email alerts</a>. |
| 399 | 400 | Mnemonic: <a href="https://en.wikipedia.org/wiki/Heaven_Can_Wait">Seven can |
| 400 | 401 | wait</a>, I’ve got email to read now. |
| 401 | 402 | </td> |
| 402 | - </tr> | |
| 403 | + </tr> | |
| 403 | 404 | |
| 404 | 405 | <tr id="A"> |
| 405 | 406 | <th>A</th> |
| 406 | 407 | <th>Announce</th> |
| 407 | 408 | <td> |
| 408 | 409 | Send email announcements to users <a href="#7">signed up to |
| 409 | 410 | receive them</a>. Mnemonic: <b>a</b>nnounce. |
| 410 | 411 | </td> |
| 411 | - </tr> | |
| 412 | + </tr> | |
| 413 | + | |
| 414 | + <tr id="B"> | |
| 415 | + <th>B</th> | |
| 416 | + <th>Attach to Forum</th> | |
| 417 | + <td> | |
| 418 | + Add attachments to forum posts. See also: <a href='#b'>b</a>. | |
| 419 | + </td> | |
| 420 | + </tr> | |
| 412 | 421 | |
| 413 | 422 | <tr id="C"> |
| 414 | 423 | <th>C</th> |
| 415 | 424 | <th>Chat</th> |
| 416 | 425 | <td> |
| 417 | 426 | Allow access to the <tt>/chat</tt> room. |
| 418 | 427 | </td> |
| 419 | - </tr> | |
| 428 | + </tr> | |
| 420 | 429 | |
| 421 | 430 | <tr id="D"> |
| 422 | 431 | <th>D</th> |
| 423 | 432 | <th>Debug</th> |
| 424 | 433 | <td> |
| 425 | 434 | Enable debugging features. Mnemonic: <b>d</b>ebug. |
| 426 | 435 | </td> |
| 427 | - </tr> | |
| 436 | + </tr> | |
| 428 | 437 | |
| 429 | 438 | <tr id="L"> |
| 430 | 439 | <th>L</th> |
| 431 | 440 | <th>Is-logged-in</th> |
| 432 | 441 | <td> |
| @@ -433,13 +442,13 @@ | ||
| 433 | 442 | This is not a real capability, but is used in certain capability |
| 434 | 443 | checks, e.g. via <a href="../th1.md#capexpr">capexpr</a>. It |
| 435 | 444 | resolves to true if the current user is logged in. |
| 436 | 445 | Mnemonic: <b>L</b>ogged in. |
| 437 | 446 | </td> |
| 438 | - </tr> | |
| 447 | + </tr> | |
| 439 | 448 | |
| 440 | 449 | </table> |
| 441 | 450 | |
| 442 | 451 | <hr/> |
| 443 | 452 | |
| 444 | 453 | <p id="backlink"><a href="./"><em>Back to Administering User |
| 445 | 454 | Capabilities</em></a></p> |
| 446 | 455 |
| --- www/caps/ref.html | |
| +++ www/caps/ref.html | |
| @@ -56,28 +56,29 @@ | |
| 56 | Admin users have <em>all</em> of the capabilities below except for |
| 57 | <a href="#s">setup</a>, <a herf="#x">Private</a>, and <a href="#y">WrUnver</a>. |
| 58 | See <a href="admin-v-setup.md">Admin vs. Setup</a> for a more |
| 59 | nuanced discussion. Mnemonic: <b>a</b>dministrate. |
| 60 | </td> |
| 61 | </tr> |
| 62 | |
| 63 | <tr id="b"> |
| 64 | <th>b</th> |
| 65 | <th>Attach</th> |
| 66 | <td> |
| 67 | Add attachments to wiki articles or tickets. Mnemonics: <b>b</b>ind, |
| 68 | <b>b</b>utton, <b>b</b>ond, or <b>b</b>olt. |
| 69 | </td> |
| 70 | </tr> |
| 71 | |
| 72 | <tr id="c"> |
| 73 | <th>c</th> |
| 74 | <th>ApndTkt</th> |
| 75 | <td> |
| 76 | Append comments to existing tickets. Mnemonic: <b>c</b>omment. |
| 77 | </td> |
| 78 | </tr> |
| 79 | |
| 80 | <tr id="d"> |
| 81 | <th>d</th> |
| 82 | <th>n/a</th> |
| 83 | <td> |
| @@ -100,21 +101,21 @@ | |
| 100 | identifying information</a> (PII) about other users such as email |
| 101 | addresses. Mnemonics: show <b>e</b>mail addresses; or |
| 102 | <b>E</b>urope, home of <a |
| 103 | href="https://en.wikipedia.org/wiki/General_Data_Protection_Regulation">GDPR</a>. |
| 104 | </td> |
| 105 | </tr> |
| 106 | |
| 107 | <tr id="f"> |
| 108 | <th>f</th> |
| 109 | <th>NewWiki</th> |
| 110 | <td> |
| 111 | Create new wiki articles. Mnemonic: <b>f</b>ast, English |
| 112 | translation of the Hawaiian word <a |
| 113 | href="https://en.wikipedia.org/wiki/History_of_wikis#WikiWikiWeb,_the_first_wiki"><i>wiki</i></a>. |
| 114 | </td> |
| 115 | </tr> |
| 116 | |
| 117 | <tr id="g"> |
| 118 | <th>g</th> |
| 119 | <th>Clone</th> |
| 120 | <td> |
| @@ -121,11 +122,11 @@ | |
| 121 | Clone the repository. Note that this is distinct from <a |
| 122 | href="#o">check-out capability, <b>o</b></a>; and that upon cloning |
| 123 | not just files, but also tickets, wikis, technotes and forum posts |
| 124 | are tranferred. Mnemonic: <b>g</b>et. |
| 125 | </td> |
| 126 | </tr> |
| 127 | |
| 128 | <tr id="h"> |
| 129 | <th>h</th> |
| 130 | <th>Hyperlink</th> |
| 131 | <td> |
| @@ -134,11 +135,11 @@ | |
| 134 | “nobody” category, to <a href="../antibot.wiki">prevent bots from |
| 135 | wandering around aimlessly</a> in the site’s hyperlink web, <a |
| 136 | href="../loadmgmt.md">chewing up server resources</a> to little |
| 137 | good purpose. Mnemonic: <b>h</b>yperlink. |
| 138 | </td> |
| 139 | </tr> |
| 140 | |
| 141 | <tr id="i"> |
| 142 | <th>i</th> |
| 143 | <th>Write</th> |
| 144 | <td> |
| @@ -149,20 +150,20 @@ | |
| 149 | Also note that not just files, but also tickets, wikis, technotes |
| 150 | and forum posts will be accepted from clones upon syncronization. |
| 151 | Granting this capability also grants <b>o (Read)</b> Mnemonics: |
| 152 | <b>i</b>nput, check <b>i</b>n changes. |
| 153 | </td> |
| 154 | </tr> |
| 155 | |
| 156 | <tr id="j"> |
| 157 | <th>j</th> |
| 158 | <th>RdWiki</th> |
| 159 | <td> |
| 160 | View wiki articles. Mnemonic: in<b>j</b>est page content. (All |
| 161 | right, you critics, you do better, then.) |
| 162 | </td> |
| 163 | </tr> |
| 164 | |
| 165 | <tr id="k"> |
| 166 | <th>k</th> |
| 167 | <th>WrWiki</th> |
| 168 | <td> |
| @@ -169,11 +170,11 @@ | |
| 169 | Edit wiki articles. Granting this capability also grants <a |
| 170 | href="#j"><b>RdWiki</b></a> and <a href="#m"><b>ApndWiki</b></a>, |
| 171 | but it does <em>not</em> grant <a href="#f"><b>NewWiki</b></a>! |
| 172 | Mnemonic: <b>k</b>ontribute. |
| 173 | </td> |
| 174 | </tr> |
| 175 | |
| 176 | <tr id="l"> |
| 177 | <th>l</th> |
| 178 | <th>ModWiki</th> |
| 179 | <td> |
| @@ -180,63 +181,63 @@ | |
| 180 | Moderate <a href="#m">wiki article appends</a>. Appends do not get |
| 181 | saved permanently to the receiving repo’s block chain until <a |
| 182 | href="#s">Setup</a> or someone with this cap approves it. |
| 183 | Mnemonic: a<b>l</b>low. |
| 184 | </td> |
| 185 | </tr> |
| 186 | |
| 187 | <tr id="m"> |
| 188 | <th>m</th> |
| 189 | <th>ApndWiki</th> |
| 190 | <td> |
| 191 | Append content to existing wiki articles. Mnemonic: a<b>m</b>end |
| 192 | wiki |
| 193 | </td> |
| 194 | </tr> |
| 195 | |
| 196 | <tr id="n"> |
| 197 | <th>n</th> |
| 198 | <th>NewTkt</th> |
| 199 | <td> |
| 200 | File new tickets. Mnemonic: <b>n</b>ew ticket. |
| 201 | </td> |
| 202 | </tr> |
| 203 | |
| 204 | <tr id="o"> |
| 205 | <th>o</th> |
| 206 | <th>Read</th> |
| 207 | <td> |
| 208 | Read content and history of files from a remote Fossil instance over |
| 209 | HTTP. See <a href="index.md#read-v-clone">Reading vs. |
| 210 | Cloning</a>. Mnemonic: check <b>o</b>ut remote repo contents. |
| 211 | </td> |
| 212 | </tr> |
| 213 | |
| 214 | <tr id="p"> |
| 215 | <th>p</th> |
| 216 | <th>Password</th> |
| 217 | <td> |
| 218 | Change one’s own password. Mnemonic: <b>p</b>assword. |
| 219 | </td> |
| 220 | </tr> |
| 221 | |
| 222 | <tr id="q"> |
| 223 | <th>q</th> |
| 224 | <th>ModTkt</th> |
| 225 | <td> |
| 226 | Moderate tickets: delete comments appended to tickets. Mnemonic: |
| 227 | <b>q</b>uash noise commentary. |
| 228 | </td> |
| 229 | </tr> |
| 230 | |
| 231 | <tr id="r"> |
| 232 | <th>r</th> |
| 233 | <th>RdTkt</th> |
| 234 | <td> |
| 235 | View existing tickets. Mnemonic: <b>r</b>ead tickets. |
| 236 | </td> |
| 237 | </tr> |
| 238 | |
| 239 | <tr id="s"> |
| 240 | <th>s</th> |
| 241 | <th>Setup</th> |
| 242 | <td> |
| @@ -256,41 +257,41 @@ | |
| 256 | because it is internally restricted to read-only queries on the |
| 257 | tickets table only. (This restriction is done with an SQLite |
| 258 | authorization hook, not by any method so weak as SQL text |
| 259 | filtering.) Mnemonic: new <b>t</b>icket report. |
| 260 | </td> |
| 261 | </tr> |
| 262 | |
| 263 | <tr id="u"> |
| 264 | <th>u</th> |
| 265 | <th>n/a</th> |
| 266 | <td> |
| 267 | Inherit all capabilities of the “reader” user category; does not |
| 268 | have a dedicated flag internally within Fossil. Mnemonic: |
| 269 | <a href="./index.md#ucat"><b>u</b>ser</a> |
| 270 | </td> |
| 271 | </tr> |
| 272 | |
| 273 | <tr id="v"> |
| 274 | <th>v</th> |
| 275 | <th>n/a</th> |
| 276 | <td> |
| 277 | Inherit all capabilities of the “developer” user category; does |
| 278 | not have a dedicated flag internally within Fossil. Mnemonic: |
| 279 | de<b>v</b>eloper. |
| 280 | </td> |
| 281 | </tr> |
| 282 | |
| 283 | <tr id="w"> |
| 284 | <th>w</th> |
| 285 | <th>WrTkt</th> |
| 286 | <td> |
| 287 | Edit existing tickets. Granting this capability also grants <a |
| 288 | href="#r"><b>RdTkt</b></a>, <a href="#c"><b>ApndTkt</b></a>, and |
| 289 | <a href="#n"><b>NewTkt</b></a>. Mnemonic: <b>w</b>rite to ticket. |
| 290 | </td> |
| 291 | </tr> |
| 292 | |
| 293 | <tr id="x"> |
| 294 | <th>x</th> |
| 295 | <th>Private</th> |
| 296 | <td> |
| @@ -298,21 +299,21 @@ | |
| 298 | Mnemonic: e<b>x</b>clusivity; “x” connotes unknown material in |
| 299 | many Western languages due to its <a |
| 300 | href="https://en.wikipedia.org/wiki/La_Géométrie#The_text">traditional |
| 301 | use in mathematics</a>. |
| 302 | </td> |
| 303 | </tr> |
| 304 | |
| 305 | <tr id="y"> |
| 306 | <th>y</th> |
| 307 | <th>WrUnver</th> |
| 308 | <td> |
| 309 | Push <a href="../unvers.wiki">unversioned content</a>. Mnemonic: |
| 310 | <b>y</b>ield, <a href="https://en.wiktionary.org/wiki/yield">sense |
| 311 | 4</a>: “hand over.” |
| 312 | </td> |
| 313 | </tr> |
| 314 | |
| 315 | <tr id="z"> |
| 316 | <th>z</th> |
| 317 | <th>Zip</th> |
| 318 | <td> |
| @@ -323,20 +324,20 @@ | |
| 323 | expensive capability to grant, because creating such archives can |
| 324 | put a large load on <a href="../server/">a Fossil server</a> which |
| 325 | you may then need to <a href="../loadmgmt.md">manage</a>. |
| 326 | Mnemonic: <b>z</b>ip file download. |
| 327 | </td> |
| 328 | </tr> |
| 329 | |
| 330 | <tr id="2"> |
| 331 | <th>2</th> |
| 332 | <th>RdForum</th> |
| 333 | <td> |
| 334 | Read <a href="../forum.wiki">forum posts</a> by other users. |
| 335 | Mnemonic: from thee <b>2</b> me. |
| 336 | </td> |
| 337 | </tr> |
| 338 | |
| 339 | <tr id="3"> |
| 340 | <th>3</th> |
| 341 | <th>WrForum</th> |
| 342 | <td> |
| @@ -346,20 +347,20 @@ | |
| 346 | not appear in repo clones or syncs. Granting this capability also |
| 347 | grants <a href="#2"><b>RdForum</b></a>. Mnemonic: post for |
| 348 | <b>3</b> audiences: me, <a href="#5">the mods</a>, and <a |
| 349 | href="https://en.wikipedia.org/wiki/The_Man">the Man</a>. |
| 350 | </td> |
| 351 | </tr> |
| 352 | |
| 353 | <tr id="4"> |
| 354 | <th>4</th> |
| 355 | <th>WrTForum</th> |
| 356 | <td> |
| 357 | Extends <a href="#3"><b>WrForum</b></a>, bypassing the moderation |
| 358 | and sync restrictions. Mnemonic: post <b>4</b> immediate release. |
| 359 | </td> |
| 360 | </tr> |
| 361 | |
| 362 | <tr id="5"> |
| 363 | <th>5</th> |
| 364 | <th>ModForum</th> |
| 365 | <td> |
| @@ -368,11 +369,11 @@ | |
| 368 | href="#4"><b>WrTForum</b></a> and <a href="#2"><b>RdForum</b></a>, |
| 369 | so a user with this cap never has to moderate their own posts. |
| 370 | Mnemonic: “May I have <b>5</b> seconds of your time, honored |
| 371 | Gatekeeper?” |
| 372 | </td> |
| 373 | </tr> |
| 374 | |
| 375 | <tr id="6"> |
| 376 | <th>6</th> |
| 377 | <th>AdminForum</th> |
| 378 | <td> |
| @@ -387,46 +388,54 @@ | |
| 387 | currently revoke granted caps. Granting this capability also |
| 388 | grants <a href="#5"><b>ModForum</b></a> and those it in turn |
| 389 | grants. Mnemonic: “I’m <b>6</b> [sick] of hitting Approve on your |
| 390 | posts!” |
| 391 | </td> |
| 392 | </tr> |
| 393 | |
| 394 | <tr id="7"> |
| 395 | <th>7</th> |
| 396 | <th>EmailAlert</th> |
| 397 | <td> |
| 398 | User can sign up for <a href="../alerts.md">email alerts</a>. |
| 399 | Mnemonic: <a href="https://en.wikipedia.org/wiki/Heaven_Can_Wait">Seven can |
| 400 | wait</a>, I’ve got email to read now. |
| 401 | </td> |
| 402 | </tr> |
| 403 | |
| 404 | <tr id="A"> |
| 405 | <th>A</th> |
| 406 | <th>Announce</th> |
| 407 | <td> |
| 408 | Send email announcements to users <a href="#7">signed up to |
| 409 | receive them</a>. Mnemonic: <b>a</b>nnounce. |
| 410 | </td> |
| 411 | </tr> |
| 412 | |
| 413 | <tr id="C"> |
| 414 | <th>C</th> |
| 415 | <th>Chat</th> |
| 416 | <td> |
| 417 | Allow access to the <tt>/chat</tt> room. |
| 418 | </td> |
| 419 | </tr> |
| 420 | |
| 421 | <tr id="D"> |
| 422 | <th>D</th> |
| 423 | <th>Debug</th> |
| 424 | <td> |
| 425 | Enable debugging features. Mnemonic: <b>d</b>ebug. |
| 426 | </td> |
| 427 | </tr> |
| 428 | |
| 429 | <tr id="L"> |
| 430 | <th>L</th> |
| 431 | <th>Is-logged-in</th> |
| 432 | <td> |
| @@ -433,13 +442,13 @@ | |
| 433 | This is not a real capability, but is used in certain capability |
| 434 | checks, e.g. via <a href="../th1.md#capexpr">capexpr</a>. It |
| 435 | resolves to true if the current user is logged in. |
| 436 | Mnemonic: <b>L</b>ogged in. |
| 437 | </td> |
| 438 | </tr> |
| 439 | |
| 440 | </table> |
| 441 | |
| 442 | <hr/> |
| 443 | |
| 444 | <p id="backlink"><a href="./"><em>Back to Administering User |
| 445 | Capabilities</em></a></p> |
| 446 |
| --- www/caps/ref.html | |
| +++ www/caps/ref.html | |
| @@ -56,28 +56,29 @@ | |
| 56 | Admin users have <em>all</em> of the capabilities below except for |
| 57 | <a href="#s">setup</a>, <a herf="#x">Private</a>, and <a href="#y">WrUnver</a>. |
| 58 | See <a href="admin-v-setup.md">Admin vs. Setup</a> for a more |
| 59 | nuanced discussion. Mnemonic: <b>a</b>dministrate. |
| 60 | </td> |
| 61 | </tr> |
| 62 | |
| 63 | <tr id="b"> |
| 64 | <th>b</th> |
| 65 | <th>Attach</th> |
| 66 | <td> |
| 67 | Add attachments to wiki articles, technotes, or tickets. |
| 68 | Mnemonics: <b>b</b>ind, <b>b</b>utton, <b>b</b>ond, or <b>b</b>olt. |
| 69 | See also: <a href='#B'>B</a>. |
| 70 | </td> |
| 71 | </tr> |
| 72 | |
| 73 | <tr id="c"> |
| 74 | <th>c</th> |
| 75 | <th>ApndTkt</th> |
| 76 | <td> |
| 77 | Append comments to existing tickets. Mnemonic: <b>c</b>omment. |
| 78 | </td> |
| 79 | </tr> |
| 80 | |
| 81 | <tr id="d"> |
| 82 | <th>d</th> |
| 83 | <th>n/a</th> |
| 84 | <td> |
| @@ -100,21 +101,21 @@ | |
| 101 | identifying information</a> (PII) about other users such as email |
| 102 | addresses. Mnemonics: show <b>e</b>mail addresses; or |
| 103 | <b>E</b>urope, home of <a |
| 104 | href="https://en.wikipedia.org/wiki/General_Data_Protection_Regulation">GDPR</a>. |
| 105 | </td> |
| 106 | </tr> |
| 107 | |
| 108 | <tr id="f"> |
| 109 | <th>f</th> |
| 110 | <th>NewWiki</th> |
| 111 | <td> |
| 112 | Create new wiki articles. Mnemonic: <b>f</b>ast, English |
| 113 | translation of the Hawaiian word <a |
| 114 | href="https://en.wikipedia.org/wiki/History_of_wikis#WikiWikiWeb,_the_first_wiki"><i>wiki</i></a>. |
| 115 | </td> |
| 116 | </tr> |
| 117 | |
| 118 | <tr id="g"> |
| 119 | <th>g</th> |
| 120 | <th>Clone</th> |
| 121 | <td> |
| @@ -121,11 +122,11 @@ | |
| 122 | Clone the repository. Note that this is distinct from <a |
| 123 | href="#o">check-out capability, <b>o</b></a>; and that upon cloning |
| 124 | not just files, but also tickets, wikis, technotes and forum posts |
| 125 | are tranferred. Mnemonic: <b>g</b>et. |
| 126 | </td> |
| 127 | </tr> |
| 128 | |
| 129 | <tr id="h"> |
| 130 | <th>h</th> |
| 131 | <th>Hyperlink</th> |
| 132 | <td> |
| @@ -134,11 +135,11 @@ | |
| 135 | “nobody” category, to <a href="../antibot.wiki">prevent bots from |
| 136 | wandering around aimlessly</a> in the site’s hyperlink web, <a |
| 137 | href="../loadmgmt.md">chewing up server resources</a> to little |
| 138 | good purpose. Mnemonic: <b>h</b>yperlink. |
| 139 | </td> |
| 140 | </tr> |
| 141 | |
| 142 | <tr id="i"> |
| 143 | <th>i</th> |
| 144 | <th>Write</th> |
| 145 | <td> |
| @@ -149,20 +150,20 @@ | |
| 150 | Also note that not just files, but also tickets, wikis, technotes |
| 151 | and forum posts will be accepted from clones upon syncronization. |
| 152 | Granting this capability also grants <b>o (Read)</b> Mnemonics: |
| 153 | <b>i</b>nput, check <b>i</b>n changes. |
| 154 | </td> |
| 155 | </tr> |
| 156 | |
| 157 | <tr id="j"> |
| 158 | <th>j</th> |
| 159 | <th>RdWiki</th> |
| 160 | <td> |
| 161 | View wiki articles. Mnemonic: in<b>j</b>est page content. (All |
| 162 | right, you critics, you do better, then.) |
| 163 | </td> |
| 164 | </tr> |
| 165 | |
| 166 | <tr id="k"> |
| 167 | <th>k</th> |
| 168 | <th>WrWiki</th> |
| 169 | <td> |
| @@ -169,11 +170,11 @@ | |
| 170 | Edit wiki articles. Granting this capability also grants <a |
| 171 | href="#j"><b>RdWiki</b></a> and <a href="#m"><b>ApndWiki</b></a>, |
| 172 | but it does <em>not</em> grant <a href="#f"><b>NewWiki</b></a>! |
| 173 | Mnemonic: <b>k</b>ontribute. |
| 174 | </td> |
| 175 | </tr> |
| 176 | |
| 177 | <tr id="l"> |
| 178 | <th>l</th> |
| 179 | <th>ModWiki</th> |
| 180 | <td> |
| @@ -180,63 +181,63 @@ | |
| 181 | Moderate <a href="#m">wiki article appends</a>. Appends do not get |
| 182 | saved permanently to the receiving repo’s block chain until <a |
| 183 | href="#s">Setup</a> or someone with this cap approves it. |
| 184 | Mnemonic: a<b>l</b>low. |
| 185 | </td> |
| 186 | </tr> |
| 187 | |
| 188 | <tr id="m"> |
| 189 | <th>m</th> |
| 190 | <th>ApndWiki</th> |
| 191 | <td> |
| 192 | Append content to existing wiki articles. Mnemonic: a<b>m</b>end |
| 193 | wiki |
| 194 | </td> |
| 195 | </tr> |
| 196 | |
| 197 | <tr id="n"> |
| 198 | <th>n</th> |
| 199 | <th>NewTkt</th> |
| 200 | <td> |
| 201 | File new tickets. Mnemonic: <b>n</b>ew ticket. |
| 202 | </td> |
| 203 | </tr> |
| 204 | |
| 205 | <tr id="o"> |
| 206 | <th>o</th> |
| 207 | <th>Read</th> |
| 208 | <td> |
| 209 | Read content and history of files from a remote Fossil instance over |
| 210 | HTTP. See <a href="index.md#read-v-clone">Reading vs. |
| 211 | Cloning</a>. Mnemonic: check <b>o</b>ut remote repo contents. |
| 212 | </td> |
| 213 | </tr> |
| 214 | |
| 215 | <tr id="p"> |
| 216 | <th>p</th> |
| 217 | <th>Password</th> |
| 218 | <td> |
| 219 | Change one’s own password. Mnemonic: <b>p</b>assword. |
| 220 | </td> |
| 221 | </tr> |
| 222 | |
| 223 | <tr id="q"> |
| 224 | <th>q</th> |
| 225 | <th>ModTkt</th> |
| 226 | <td> |
| 227 | Moderate tickets: delete comments appended to tickets. Mnemonic: |
| 228 | <b>q</b>uash noise commentary. |
| 229 | </td> |
| 230 | </tr> |
| 231 | |
| 232 | <tr id="r"> |
| 233 | <th>r</th> |
| 234 | <th>RdTkt</th> |
| 235 | <td> |
| 236 | View existing tickets. Mnemonic: <b>r</b>ead tickets. |
| 237 | </td> |
| 238 | </tr> |
| 239 | |
| 240 | <tr id="s"> |
| 241 | <th>s</th> |
| 242 | <th>Setup</th> |
| 243 | <td> |
| @@ -256,41 +257,41 @@ | |
| 257 | because it is internally restricted to read-only queries on the |
| 258 | tickets table only. (This restriction is done with an SQLite |
| 259 | authorization hook, not by any method so weak as SQL text |
| 260 | filtering.) Mnemonic: new <b>t</b>icket report. |
| 261 | </td> |
| 262 | </tr> |
| 263 | |
| 264 | <tr id="u"> |
| 265 | <th>u</th> |
| 266 | <th>n/a</th> |
| 267 | <td> |
| 268 | Inherit all capabilities of the “reader” user category; does not |
| 269 | have a dedicated flag internally within Fossil. Mnemonic: |
| 270 | <a href="./index.md#ucat"><b>u</b>ser</a> |
| 271 | </td> |
| 272 | </tr> |
| 273 | |
| 274 | <tr id="v"> |
| 275 | <th>v</th> |
| 276 | <th>n/a</th> |
| 277 | <td> |
| 278 | Inherit all capabilities of the “developer” user category; does |
| 279 | not have a dedicated flag internally within Fossil. Mnemonic: |
| 280 | de<b>v</b>eloper. |
| 281 | </td> |
| 282 | </tr> |
| 283 | |
| 284 | <tr id="w"> |
| 285 | <th>w</th> |
| 286 | <th>WrTkt</th> |
| 287 | <td> |
| 288 | Edit existing tickets. Granting this capability also grants <a |
| 289 | href="#r"><b>RdTkt</b></a>, <a href="#c"><b>ApndTkt</b></a>, and |
| 290 | <a href="#n"><b>NewTkt</b></a>. Mnemonic: <b>w</b>rite to ticket. |
| 291 | </td> |
| 292 | </tr> |
| 293 | |
| 294 | <tr id="x"> |
| 295 | <th>x</th> |
| 296 | <th>Private</th> |
| 297 | <td> |
| @@ -298,21 +299,21 @@ | |
| 299 | Mnemonic: e<b>x</b>clusivity; “x” connotes unknown material in |
| 300 | many Western languages due to its <a |
| 301 | href="https://en.wikipedia.org/wiki/La_Géométrie#The_text">traditional |
| 302 | use in mathematics</a>. |
| 303 | </td> |
| 304 | </tr> |
| 305 | |
| 306 | <tr id="y"> |
| 307 | <th>y</th> |
| 308 | <th>WrUnver</th> |
| 309 | <td> |
| 310 | Push <a href="../unvers.wiki">unversioned content</a>. Mnemonic: |
| 311 | <b>y</b>ield, <a href="https://en.wiktionary.org/wiki/yield">sense |
| 312 | 4</a>: “hand over.” |
| 313 | </td> |
| 314 | </tr> |
| 315 | |
| 316 | <tr id="z"> |
| 317 | <th>z</th> |
| 318 | <th>Zip</th> |
| 319 | <td> |
| @@ -323,20 +324,20 @@ | |
| 324 | expensive capability to grant, because creating such archives can |
| 325 | put a large load on <a href="../server/">a Fossil server</a> which |
| 326 | you may then need to <a href="../loadmgmt.md">manage</a>. |
| 327 | Mnemonic: <b>z</b>ip file download. |
| 328 | </td> |
| 329 | </tr> |
| 330 | |
| 331 | <tr id="2"> |
| 332 | <th>2</th> |
| 333 | <th>RdForum</th> |
| 334 | <td> |
| 335 | Read <a href="../forum.wiki">forum posts</a> by other users. |
| 336 | Mnemonic: from thee <b>2</b> me. |
| 337 | </td> |
| 338 | </tr> |
| 339 | |
| 340 | <tr id="3"> |
| 341 | <th>3</th> |
| 342 | <th>WrForum</th> |
| 343 | <td> |
| @@ -346,20 +347,20 @@ | |
| 347 | not appear in repo clones or syncs. Granting this capability also |
| 348 | grants <a href="#2"><b>RdForum</b></a>. Mnemonic: post for |
| 349 | <b>3</b> audiences: me, <a href="#5">the mods</a>, and <a |
| 350 | href="https://en.wikipedia.org/wiki/The_Man">the Man</a>. |
| 351 | </td> |
| 352 | </tr> |
| 353 | |
| 354 | <tr id="4"> |
| 355 | <th>4</th> |
| 356 | <th>WrTForum</th> |
| 357 | <td> |
| 358 | Extends <a href="#3"><b>WrForum</b></a>, bypassing the moderation |
| 359 | and sync restrictions. Mnemonic: post <b>4</b> immediate release. |
| 360 | </td> |
| 361 | </tr> |
| 362 | |
| 363 | <tr id="5"> |
| 364 | <th>5</th> |
| 365 | <th>ModForum</th> |
| 366 | <td> |
| @@ -368,11 +369,11 @@ | |
| 369 | href="#4"><b>WrTForum</b></a> and <a href="#2"><b>RdForum</b></a>, |
| 370 | so a user with this cap never has to moderate their own posts. |
| 371 | Mnemonic: “May I have <b>5</b> seconds of your time, honored |
| 372 | Gatekeeper?” |
| 373 | </td> |
| 374 | </tr> |
| 375 | |
| 376 | <tr id="6"> |
| 377 | <th>6</th> |
| 378 | <th>AdminForum</th> |
| 379 | <td> |
| @@ -387,46 +388,54 @@ | |
| 388 | currently revoke granted caps. Granting this capability also |
| 389 | grants <a href="#5"><b>ModForum</b></a> and those it in turn |
| 390 | grants. Mnemonic: “I’m <b>6</b> [sick] of hitting Approve on your |
| 391 | posts!” |
| 392 | </td> |
| 393 | </tr> |
| 394 | |
| 395 | <tr id="7"> |
| 396 | <th>7</th> |
| 397 | <th>EmailAlert</th> |
| 398 | <td> |
| 399 | User can sign up for <a href="../alerts.md">email alerts</a>. |
| 400 | Mnemonic: <a href="https://en.wikipedia.org/wiki/Heaven_Can_Wait">Seven can |
| 401 | wait</a>, I’ve got email to read now. |
| 402 | </td> |
| 403 | </tr> |
| 404 | |
| 405 | <tr id="A"> |
| 406 | <th>A</th> |
| 407 | <th>Announce</th> |
| 408 | <td> |
| 409 | Send email announcements to users <a href="#7">signed up to |
| 410 | receive them</a>. Mnemonic: <b>a</b>nnounce. |
| 411 | </td> |
| 412 | </tr> |
| 413 | |
| 414 | <tr id="B"> |
| 415 | <th>B</th> |
| 416 | <th>Attach to Forum</th> |
| 417 | <td> |
| 418 | Add attachments to forum posts. See also: <a href='#b'>b</a>. |
| 419 | </td> |
| 420 | </tr> |
| 421 | |
| 422 | <tr id="C"> |
| 423 | <th>C</th> |
| 424 | <th>Chat</th> |
| 425 | <td> |
| 426 | Allow access to the <tt>/chat</tt> room. |
| 427 | </td> |
| 428 | </tr> |
| 429 | |
| 430 | <tr id="D"> |
| 431 | <th>D</th> |
| 432 | <th>Debug</th> |
| 433 | <td> |
| 434 | Enable debugging features. Mnemonic: <b>d</b>ebug. |
| 435 | </td> |
| 436 | </tr> |
| 437 | |
| 438 | <tr id="L"> |
| 439 | <th>L</th> |
| 440 | <th>Is-logged-in</th> |
| 441 | <td> |
| @@ -433,13 +442,13 @@ | |
| 442 | This is not a real capability, but is used in certain capability |
| 443 | checks, e.g. via <a href="../th1.md#capexpr">capexpr</a>. It |
| 444 | resolves to true if the current user is logged in. |
| 445 | Mnemonic: <b>L</b>ogged in. |
| 446 | </td> |
| 447 | </tr> |
| 448 | |
| 449 | </table> |
| 450 | |
| 451 | <hr/> |
| 452 | |
| 453 | <p id="backlink"><a href="./"><em>Back to Administering User |
| 454 | Capabilities</em></a></p> |
| 455 |
+26
| --- www/changes.wiki | ||
| +++ www/changes.wiki | ||
| @@ -1,6 +1,32 @@ | ||
| 1 | 1 | <title>Change Log</title> |
| 2 | + | |
| 3 | +<h2 id='v2_29'>Changes for version 2.29 (pending)</h2><ol> | |
| 4 | + <li> Enhance the [/help/www/ci_edit|/ci_edit] web page to show more | |
| 5 | + context of the check-in being edited. | |
| 6 | + <li> Honor the NO_COLOR environment variable in the | |
| 7 | + "[/help/system|fossil sys ls]" command. | |
| 8 | + <li> On the [/help/www/info|/info webpage] (and similar) put a | |
| 9 | + "copy" button before the date. | |
| 10 | + <li> Add the ".m4a" and ".otf" mimetypes. | |
| 11 | + <li> When doing a "fossil update", if a file under management needs to | |
| 12 | + overwrite an unmanaged file, display the name of the backup that | |
| 13 | + is made of the unmanaged file, and use file_delete() to delete | |
| 14 | + the unmanaged file, even if that unmanaged file is read-only. | |
| 15 | + <li> Improve the default prompts used by the | |
| 16 | + "[/help/sqlite3|fossil sql]" command. | |
| 17 | + <li> The captcha now uses light-gray boxes as the background, instead of | |
| 18 | + spaces, to work around width inconsistencies in some fonts. | |
| 19 | + <li> Forum post editing and replying was overhauled with a new UI. Clients | |
| 20 | + with JavaScript disabled will still see the older forms. | |
| 21 | + <li> Forum posts may now have attachments if their poster has the new "B" | |
| 22 | + capability. | |
| 23 | + <li> Add the "[/help/attachment-size-limit|attachment-size-limit]" setting | |
| 24 | + to limit the size of file attachments to wiki pages, tech notes, | |
| 25 | + tickets, and forum posts. | |
| 26 | + <li> Addded several HTML5 tags deemed harmless to the MD/wiki allowlists. | |
| 27 | +</ol> | |
| 2 | 28 | |
| 3 | 29 | <h2 id='v2_28'>Changes for version 2.28 (2026-03-11)</h2><ol> |
| 4 | 30 | <li> Improvements to [./antibot.wiki|anti-robot defenses]:<ol type="a"> |
| 5 | 31 | <li> The default configuration now allows robots to download any tarball |
| 6 | 32 | or similar, to better support of automated build systems. |
| 7 | 33 |
| --- www/changes.wiki | |
| +++ www/changes.wiki | |
| @@ -1,6 +1,32 @@ | |
| 1 | <title>Change Log</title> |
| 2 | |
| 3 | <h2 id='v2_28'>Changes for version 2.28 (2026-03-11)</h2><ol> |
| 4 | <li> Improvements to [./antibot.wiki|anti-robot defenses]:<ol type="a"> |
| 5 | <li> The default configuration now allows robots to download any tarball |
| 6 | or similar, to better support of automated build systems. |
| 7 |
| --- www/changes.wiki | |
| +++ www/changes.wiki | |
| @@ -1,6 +1,32 @@ | |
| 1 | <title>Change Log</title> |
| 2 | |
| 3 | <h2 id='v2_29'>Changes for version 2.29 (pending)</h2><ol> |
| 4 | <li> Enhance the [/help/www/ci_edit|/ci_edit] web page to show more |
| 5 | context of the check-in being edited. |
| 6 | <li> Honor the NO_COLOR environment variable in the |
| 7 | "[/help/system|fossil sys ls]" command. |
| 8 | <li> On the [/help/www/info|/info webpage] (and similar) put a |
| 9 | "copy" button before the date. |
| 10 | <li> Add the ".m4a" and ".otf" mimetypes. |
| 11 | <li> When doing a "fossil update", if a file under management needs to |
| 12 | overwrite an unmanaged file, display the name of the backup that |
| 13 | is made of the unmanaged file, and use file_delete() to delete |
| 14 | the unmanaged file, even if that unmanaged file is read-only. |
| 15 | <li> Improve the default prompts used by the |
| 16 | "[/help/sqlite3|fossil sql]" command. |
| 17 | <li> The captcha now uses light-gray boxes as the background, instead of |
| 18 | spaces, to work around width inconsistencies in some fonts. |
| 19 | <li> Forum post editing and replying was overhauled with a new UI. Clients |
| 20 | with JavaScript disabled will still see the older forms. |
| 21 | <li> Forum posts may now have attachments if their poster has the new "B" |
| 22 | capability. |
| 23 | <li> Add the "[/help/attachment-size-limit|attachment-size-limit]" setting |
| 24 | to limit the size of file attachments to wiki pages, tech notes, |
| 25 | tickets, and forum posts. |
| 26 | <li> Addded several HTML5 tags deemed harmless to the MD/wiki allowlists. |
| 27 | </ol> |
| 28 | |
| 29 | <h2 id='v2_28'>Changes for version 2.28 (2026-03-11)</h2><ol> |
| 30 | <li> Improvements to [./antibot.wiki|anti-robot defenses]:<ol type="a"> |
| 31 | <li> The default configuration now allows robots to download any tarball |
| 32 | or similar, to better support of automated build systems. |
| 33 |
+2
-2
| --- www/customskin.md | ||
| +++ www/customskin.md | ||
| @@ -342,16 +342,16 @@ | ||
| 342 | 342 | section for more information on the two possible variable formats. |
| 343 | 343 | |
| 344 | 344 | For example, first few lines of a typical Skin Header will look |
| 345 | 345 | like this: |
| 346 | 346 | |
| 347 | - <div class="header"> | |
| 347 | + <header> | |
| 348 | 348 | <div class="title"><h1>$<project_name></h1>$<title>/div> |
| 349 | 349 | |
| 350 | 350 | After variables are substituted by TH1, that will look more like this: |
| 351 | 351 | |
| 352 | - <div class="header"> | |
| 352 | + <header> | |
| 353 | 353 | <div class="title"><h1>Project Name</h1>Page Title</div> |
| 354 | 354 | |
| 355 | 355 | As you can see, two TH1 variable substitutions were done. |
| 356 | 356 | |
| 357 | 357 | The same TH1 interpreter is used for both the header and the footer |
| 358 | 358 |
| --- www/customskin.md | |
| +++ www/customskin.md | |
| @@ -342,16 +342,16 @@ | |
| 342 | section for more information on the two possible variable formats. |
| 343 | |
| 344 | For example, first few lines of a typical Skin Header will look |
| 345 | like this: |
| 346 | |
| 347 | <div class="header"> |
| 348 | <div class="title"><h1>$<project_name></h1>$<title>/div> |
| 349 | |
| 350 | After variables are substituted by TH1, that will look more like this: |
| 351 | |
| 352 | <div class="header"> |
| 353 | <div class="title"><h1>Project Name</h1>Page Title</div> |
| 354 | |
| 355 | As you can see, two TH1 variable substitutions were done. |
| 356 | |
| 357 | The same TH1 interpreter is used for both the header and the footer |
| 358 |
| --- www/customskin.md | |
| +++ www/customskin.md | |
| @@ -342,16 +342,16 @@ | |
| 342 | section for more information on the two possible variable formats. |
| 343 | |
| 344 | For example, first few lines of a typical Skin Header will look |
| 345 | like this: |
| 346 | |
| 347 | <header> |
| 348 | <div class="title"><h1>$<project_name></h1>$<title>/div> |
| 349 | |
| 350 | After variables are substituted by TH1, that will look more like this: |
| 351 | |
| 352 | <header> |
| 353 | <div class="title"><h1>Project Name</h1>Page Title</div> |
| 354 | |
| 355 | As you can see, two TH1 variable substitutions were done. |
| 356 | |
| 357 | The same TH1 interpreter is used for both the header and the footer |
| 358 |
+28
-10
| --- www/fileformat.wiki | ||
| +++ www/fileformat.wiki | ||
| @@ -424,14 +424,13 @@ | ||
| 424 | 424 | [/artifact/91f1ec6af053 | here]. |
| 425 | 425 | |
| 426 | 426 | <h3 id="attachment">2.6 Attachments</h3> |
| 427 | 427 | |
| 428 | 428 | An attachment artifact associates some other artifact that is the |
| 429 | -attachment (the source artifact) with a ticket or wiki page or | |
| 430 | -technical note to which | |
| 431 | -the attachment is connected (the target artifact). | |
| 432 | -The following cards are allowed on an attachment artifact: | |
| 429 | +attachment (the source artifact) with a ticket, wiki page, technical | |
| 430 | +note, or forum post to which the attachment is connected (the target | |
| 431 | +artifact). The following cards are allowed on an attachment artifact: | |
| 433 | 432 | |
| 434 | 433 | <div class="indent"> |
| 435 | 434 | <b>A</b> <i>filename target</i> ?<i>source</i>?<br /> |
| 436 | 435 | <b>C</b> <i>comment</i><br /> |
| 437 | 436 | <b>D</b> <i>time-and-date-stamp</i><br /> |
| @@ -438,16 +437,19 @@ | ||
| 438 | 437 | <b>N</b> <i>mimetype</i><br /> |
| 439 | 438 | <b>U</b> <i>user-name</i><br /> |
| 440 | 439 | <b>Z</b> <i>checksum</i> |
| 441 | 440 | </div> |
| 442 | 441 | |
| 443 | -The <b>A</b> card specifies a filename for the attachment in its first argument. | |
| 444 | -The second argument to the <b>A</b> card is the name of the wiki page or | |
| 445 | -ticket or technical note to which the attachment is connected. The | |
| 446 | -third argument is either missing or else it is the lower-case artifact | |
| 447 | -ID of the attachment itself. A missing third argument means that the | |
| 448 | -attachment should be deleted. | |
| 442 | +The <b>A</b> card specifies a filename for the attachment in its first | |
| 443 | +argument. The second argument to the <b>A</b> card is the name of the | |
| 444 | +wiki page, ticket, technical note, or full hash of a forum post to | |
| 445 | +which the attachment is connected. The third argument is either | |
| 446 | +missing or else it is the lower-case artifact ID of the attachment | |
| 447 | +itself. A missing third argument means that the attachment should be | |
| 448 | +deleted. If <i>target</i> is a forum post, the hash provided should | |
| 449 | +generally be that of the first version of the post for reasons | |
| 450 | +[#forumpost-tag|explained elsewhere]. | |
| 449 | 451 | |
| 450 | 452 | The <b>C</b> card is an optional comment describing what the attachment is about. |
| 451 | 453 | The <b>C</b> card is optional, but there can only be one. |
| 452 | 454 | |
| 453 | 455 | A single <b>D</b> card is required to give the date and time when the attachment |
| @@ -602,10 +604,26 @@ | ||
| 602 | 604 | The format of the <b>W</b> card is exactly the same as for a |
| 603 | 605 | [#wikichng | wiki artifact]. |
| 604 | 606 | |
| 605 | 607 | The <b>Z</b> card is the required checksum over the rest of the artifact. |
| 606 | 608 | |
| 609 | +<a name="forumpost-tag"></a> | |
| 610 | +<h4>2.8.1 Tags and Attachments on Forum Posts</h4> | |
| 611 | + | |
| 612 | +When adding [#ctrl|tags] or [#attachment|attachments] to [#forum|forum | |
| 613 | +posts] it is generally up to the application to tag, or attach to, | |
| 614 | +only the first version of any given post. For example, if post X has | |
| 615 | +two edits then a tag applied, or attachment added, by the user to post | |
| 616 | +X+2 should generally be applied to version X instead. Though this | |
| 617 | +complicates the app logic for applying tags, it simplifies the app's | |
| 618 | +location of tags for purposes of applying tag-/attachment-dependent | |
| 619 | +logic. As of this writing (May 2026), no current Fossil use cases | |
| 620 | +would be improved by tagging specific subsequent versions of posts, | |
| 621 | +e.g. the hypothetical X+1. | |
| 622 | + | |
| 623 | +Forum posts, because they have a P-card, support propagating tags. | |
| 624 | + | |
| 607 | 625 | |
| 608 | 626 | <h2 id="summary">3.0 Card Summary</h2> |
| 609 | 627 | |
| 610 | 628 | The following table summarizes the various kinds of cards that appear |
| 611 | 629 | on Fossil artifacts. A blank entry means that combination of card and |
| 612 | 630 |
| --- www/fileformat.wiki | |
| +++ www/fileformat.wiki | |
| @@ -424,14 +424,13 @@ | |
| 424 | [/artifact/91f1ec6af053 | here]. |
| 425 | |
| 426 | <h3 id="attachment">2.6 Attachments</h3> |
| 427 | |
| 428 | An attachment artifact associates some other artifact that is the |
| 429 | attachment (the source artifact) with a ticket or wiki page or |
| 430 | technical note to which |
| 431 | the attachment is connected (the target artifact). |
| 432 | The following cards are allowed on an attachment artifact: |
| 433 | |
| 434 | <div class="indent"> |
| 435 | <b>A</b> <i>filename target</i> ?<i>source</i>?<br /> |
| 436 | <b>C</b> <i>comment</i><br /> |
| 437 | <b>D</b> <i>time-and-date-stamp</i><br /> |
| @@ -438,16 +437,19 @@ | |
| 438 | <b>N</b> <i>mimetype</i><br /> |
| 439 | <b>U</b> <i>user-name</i><br /> |
| 440 | <b>Z</b> <i>checksum</i> |
| 441 | </div> |
| 442 | |
| 443 | The <b>A</b> card specifies a filename for the attachment in its first argument. |
| 444 | The second argument to the <b>A</b> card is the name of the wiki page or |
| 445 | ticket or technical note to which the attachment is connected. The |
| 446 | third argument is either missing or else it is the lower-case artifact |
| 447 | ID of the attachment itself. A missing third argument means that the |
| 448 | attachment should be deleted. |
| 449 | |
| 450 | The <b>C</b> card is an optional comment describing what the attachment is about. |
| 451 | The <b>C</b> card is optional, but there can only be one. |
| 452 | |
| 453 | A single <b>D</b> card is required to give the date and time when the attachment |
| @@ -602,10 +604,26 @@ | |
| 602 | The format of the <b>W</b> card is exactly the same as for a |
| 603 | [#wikichng | wiki artifact]. |
| 604 | |
| 605 | The <b>Z</b> card is the required checksum over the rest of the artifact. |
| 606 | |
| 607 | |
| 608 | <h2 id="summary">3.0 Card Summary</h2> |
| 609 | |
| 610 | The following table summarizes the various kinds of cards that appear |
| 611 | on Fossil artifacts. A blank entry means that combination of card and |
| 612 |
| --- www/fileformat.wiki | |
| +++ www/fileformat.wiki | |
| @@ -424,14 +424,13 @@ | |
| 424 | [/artifact/91f1ec6af053 | here]. |
| 425 | |
| 426 | <h3 id="attachment">2.6 Attachments</h3> |
| 427 | |
| 428 | An attachment artifact associates some other artifact that is the |
| 429 | attachment (the source artifact) with a ticket, wiki page, technical |
| 430 | note, or forum post to which the attachment is connected (the target |
| 431 | artifact). The following cards are allowed on an attachment artifact: |
| 432 | |
| 433 | <div class="indent"> |
| 434 | <b>A</b> <i>filename target</i> ?<i>source</i>?<br /> |
| 435 | <b>C</b> <i>comment</i><br /> |
| 436 | <b>D</b> <i>time-and-date-stamp</i><br /> |
| @@ -438,16 +437,19 @@ | |
| 437 | <b>N</b> <i>mimetype</i><br /> |
| 438 | <b>U</b> <i>user-name</i><br /> |
| 439 | <b>Z</b> <i>checksum</i> |
| 440 | </div> |
| 441 | |
| 442 | The <b>A</b> card specifies a filename for the attachment in its first |
| 443 | argument. The second argument to the <b>A</b> card is the name of the |
| 444 | wiki page, ticket, technical note, or full hash of a forum post to |
| 445 | which the attachment is connected. The third argument is either |
| 446 | missing or else it is the lower-case artifact ID of the attachment |
| 447 | itself. A missing third argument means that the attachment should be |
| 448 | deleted. If <i>target</i> is a forum post, the hash provided should |
| 449 | generally be that of the first version of the post for reasons |
| 450 | [#forumpost-tag|explained elsewhere]. |
| 451 | |
| 452 | The <b>C</b> card is an optional comment describing what the attachment is about. |
| 453 | The <b>C</b> card is optional, but there can only be one. |
| 454 | |
| 455 | A single <b>D</b> card is required to give the date and time when the attachment |
| @@ -602,10 +604,26 @@ | |
| 604 | The format of the <b>W</b> card is exactly the same as for a |
| 605 | [#wikichng | wiki artifact]. |
| 606 | |
| 607 | The <b>Z</b> card is the required checksum over the rest of the artifact. |
| 608 | |
| 609 | <a name="forumpost-tag"></a> |
| 610 | <h4>2.8.1 Tags and Attachments on Forum Posts</h4> |
| 611 | |
| 612 | When adding [#ctrl|tags] or [#attachment|attachments] to [#forum|forum |
| 613 | posts] it is generally up to the application to tag, or attach to, |
| 614 | only the first version of any given post. For example, if post X has |
| 615 | two edits then a tag applied, or attachment added, by the user to post |
| 616 | X+2 should generally be applied to version X instead. Though this |
| 617 | complicates the app logic for applying tags, it simplifies the app's |
| 618 | location of tags for purposes of applying tag-/attachment-dependent |
| 619 | logic. As of this writing (May 2026), no current Fossil use cases |
| 620 | would be improved by tagging specific subsequent versions of posts, |
| 621 | e.g. the hypothetical X+1. |
| 622 | |
| 623 | Forum posts, because they have a P-card, support propagating tags. |
| 624 | |
| 625 | |
| 626 | <h2 id="summary">3.0 Card Summary</h2> |
| 627 | |
| 628 | The following table summarizes the various kinds of cards that appear |
| 629 | on Fossil artifacts. A blank entry means that combination of card and |
| 630 |
+193
-1
| --- www/forum.wiki | ||
| +++ www/forum.wiki | ||
| @@ -369,11 +369,11 @@ | ||
| 369 | 369 | actions are durable and have no undo. Be careful!</li> |
| 370 | 370 | </ol> |
| 371 | 371 | |
| 372 | 372 | <h2 id="close-post">Closing Forum Posts</h2> |
| 373 | 373 | |
| 374 | -As of version 2.23, the forum interface supports the notion of | |
| 374 | +As of version 2.23 the forum interface supports the notion of | |
| 375 | 375 | "closing" posts. By default, only users with the [./caps/index.md|'s' |
| 376 | 376 | and 'a' capabilities] may close or re-open posts, or reply to closed |
| 377 | 377 | posts. If the [/help/forum-close-policy|forum-close-policy |
| 378 | 378 | configuration option] is enabled then users with |
| 379 | 379 | [./caps/index.md|forum-moderator permissions] may also perform those |
| @@ -407,5 +407,197 @@ | ||
| 407 | 407 | not permitted, without appropriate permissions, to close their own |
| 408 | 408 | posts. This is intentional, as closing one's own post can be used to |
| 409 | 409 | antagonize other forum users. For example, by posting something |
| 410 | 410 | trollish or highly controversial in nature and closing the post to |
| 411 | 411 | further responses. |
| 412 | + | |
| 413 | +<h2 id="status">Setting Post Statuses</h2> | |
| 414 | + | |
| 415 | +As of version 2.29 forum posts may be tagged with a status. The | |
| 416 | +setting <tt>forum-statuses</tt> controls whether this feature is is | |
| 417 | +enabled. If it is not set, is not valid JSON5, or has only a single | |
| 418 | +entry, then status are not shown in the forum. | |
| 419 | + | |
| 420 | +<tt>forum-statuses</tt> is a JSON5-format array of objects in the | |
| 421 | +following format: | |
| 422 | + | |
| 423 | +<verbatim> | |
| 424 | +[ | |
| 425 | + {label:"Open", value:"open"}, | |
| 426 | + {label:"Resolved", value:"resolved"} | |
| 427 | + ... | |
| 428 | +]</verbatim> | |
| 429 | + | |
| 430 | +The list defines the legal statuses for forum posts and syncs with | |
| 431 | +other project-level settings. All "label" and "value" members must be | |
| 432 | +unique within the scope of that list. | |
| 433 | + | |
| 434 | +The "value" values must be legal for use as HTML "dataset" members so | |
| 435 | +that they can be used for with CSS selectors to apply per-status | |
| 436 | +styling. | |
| 437 | + | |
| 438 | +If the list is valid JSON5 and has two or more entries then the forum | |
| 439 | +behavior changes in the following ways: | |
| 440 | + | |
| 441 | + * Each TR element of the main <tt>/forum</tt> view table gets a | |
| 442 | + <tt>data-status="X"</tt> member, where "X" is the value part from | |
| 443 | + the associated status. This can be used to style the statuses | |
| 444 | + in the site skin using CSS selectors such as<br> | |
| 445 | + <tt>body.cpage-forum div.forumPosts tr[data-status="open"]</tt><br> | |
| 446 | + Because there is no default status list, no predefined styles | |
| 447 | + are applied. | |
| 448 | + * The forum list shows the "label" value of the current status and | |
| 449 | + a selection list of available filters. It elides the status column | |
| 450 | + when filtering on a specific status. | |
| 451 | + * The root of each thread, when selected, gets a new UI control for | |
| 452 | + displaying or editing the status, depending on permissions. | |
| 453 | + * A drop-down selection list is added to the <tt>/forum</tt> page | |
| 454 | + for filtering based on the status. | |
| 455 | + | |
| 456 | +A list with only a single entry is treated as empty, the justification | |
| 457 | +being that if there is only one option then the UI does not need to be | |
| 458 | +cluttered with it. | |
| 459 | + | |
| 460 | +This setting is applied via a <tt>status</tt> tag on the first version | |
| 461 | +of a legal post. That tag may be set to any value from the "values" | |
| 462 | +members of the <tt>forum-statuses</tt> list. | |
| 463 | + | |
| 464 | +Status tag rules: | |
| 465 | + | |
| 466 | + * <tt>status</tt> is only observed on the root of each thread. The UI | |
| 467 | + does nothing with that tag on responses. | |
| 468 | + * The first list entry is considered to be the default status. Any post | |
| 469 | + which has no <tt>status</tt> tag, or has a <tt>status</tt> tag value | |
| 470 | + which is not in that list, is assumed for most purposes to have the | |
| 471 | + value of the first entry in the list. | |
| 472 | + * The tag is applied only to the first version of any given post. The | |
| 473 | + UI ensures that the tag is applied to the proper post, even when | |
| 474 | + rendering a newer version. | |
| 475 | + | |
| 476 | +Caveat: a "closed" status is not recommended because it's easy to confuse with | |
| 477 | +the <a href='#close-post'>"closed" tag feature</a>, which behaves considerably | |
| 478 | +differently and predates that "status" tag support by about three years. The | |
| 479 | +"closed" semantics cannot be trivially consolidated with those of "status" | |
| 480 | +but we reserve the right to do so at some point. | |
| 481 | + | |
| 482 | +<h2 id="attachments">Attachments</h2> | |
| 483 | + | |
| 484 | +As of version 2.29 users with the [./caps/index.md|'B' capability] may | |
| 485 | +attach files to forum posts. Files may not be attached until a forum | |
| 486 | +post is saved for the first time, after which an "Attach" button will | |
| 487 | +appear in the post when it is selected. Attached files undergo | |
| 488 | +moderation exactly like forum posts do. When a moderator accepts a | |
| 489 | +pending-moderation posts, all files attached to it which are also | |
| 490 | +pending approval are also approved. Similarly, when a moderator | |
| 491 | +rejects a pending-moderation post, all files attached to it which are | |
| 492 | +also pending approval are rejected. | |
| 493 | + | |
| 494 | +Developer notes regarding the save-before-attach limitation: | |
| 495 | + | |
| 496 | + * We cannot add the attachment form to the current post editor | |
| 497 | + because (A) the Preview option would upload the files each time | |
| 498 | + (B) we cannot pre-populate file selection elements so could not | |
| 499 | + restore them when rendering the preview's response. | |
| 500 | + * To work around that we need to reimplement the forum editor | |
| 501 | + using AJAX-friendly APIs. That would allow us to render a preview | |
| 502 | + without reloading the page, to attach multiple files at once, | |
| 503 | + to support pasting a screenshot as an attachment, and to submit both | |
| 504 | + a new post and its attachments at the same time. | |
| 505 | + * We have AJAX-capable preview code in /wiki and /fileedit. | |
| 506 | + * We have paste-screenshot code in /chat but integrating it here will | |
| 507 | + require adding a "paste" button to the attachment UI. | |
| 508 | + | |
| 509 | +Developer notes regarding automatic acceptance/rejection of | |
| 510 | +attachments: | |
| 511 | + | |
| 512 | + * There is a race condition here where an admin may approve | |
| 513 | + attachments they have not yet seen: user creates posts, admin gets | |
| 514 | + notified, admin reads post, user attaches a file at that time, | |
| 515 | + admin approves post. | |
| 516 | + | |
| 517 | +TBD is whether to accept that case or to remove automatic approval of | |
| 518 | +attached files. | |
| 519 | + | |
| 520 | +<h2 id="drafts">Draft Edits</h2> | |
| 521 | + | |
| 522 | +The forum uses, if available, JavaScript's <code>localStorage</code> | |
| 523 | +or <code>sessionStorage</code> to store local drafts of new | |
| 524 | +posts, replies, and edits to existing posts. Each time an editor | |
| 525 | +input field loses focus, the draft is saved. When viewing a forum | |
| 526 | +thread, the Edit and Reply buttons get clearly marked if they | |
| 527 | +have an associated local draft. | |
| 528 | + | |
| 529 | +Local drafts for replies and responses (but not new posts) are | |
| 530 | +automatically purged at semi-random intervals. Every Nth visit to a | |
| 531 | +forum page has a small chance to run the cleanup, and drafts older | |
| 532 | +than 10 days old are purged. | |
| 533 | + | |
| 534 | +If neither <code>localStorage</code> nor <code>sessionStorage</code> | |
| 535 | +are available, it uses a transient storage object which is recreated | |
| 536 | +on each page-load, so it cannot store drafts outside of a single | |
| 537 | +thread at a time. | |
| 538 | + | |
| 539 | +Beware: Each draft is keyed to the post it is editing or replied to, | |
| 540 | +which means that editing or replying to the same post from different | |
| 541 | +tabs will cause collisions. The editor to most recently lose the focus | |
| 542 | +will save the draft, overwriting the other. | |
| 543 | + | |
| 544 | +In browsers which support Web Locks, attempts to edit resp. reply to a | |
| 545 | +post which is already being edited resp. replied to in another tab | |
| 546 | +will show an error for the second and subsequent tabs. The first tab | |
| 547 | +to use the edit/reply buttons will hold a separate Web Lock for each | |
| 548 | +and forbid edit/reply access to the post in other tabs until the | |
| 549 | +locking tab is closed. | |
| 550 | + | |
| 551 | + | |
| 552 | +<h2 id="padding">Curious Extra Page Padding</h2> | |
| 553 | + | |
| 554 | +Users may notice that the forum pages get a bunch of padding added to | |
| 555 | +the bottom of the page when an editor widget is opened. This is not a | |
| 556 | +bug, but a workaround to help avoid the UI jumping around when | |
| 557 | +rendering a preview wildly resizes the widget. The effect is | |
| 558 | +especially helpful when working on posts while the bottom footer of | |
| 559 | +the page is in the viewport, as the footer is a hard boundary against | |
| 560 | +scrolling. With the extra padding, the editor widget's top edge shifts | |
| 561 | +around less when the preview is shown and hidden. | |
| 562 | + | |
| 563 | +<h2 id="fork">Forked Edits</h2> | |
| 564 | + | |
| 565 | +It is possible to "fork" forum messages, in the same way that any | |
| 566 | +given check-in may cause a fork. This can happen when a message is | |
| 567 | +edited concurrently from two or more browser tabs or via two or more | |
| 568 | +fossil instances which subsequently sync with each other. | |
| 569 | + | |
| 570 | +When a forum post is forked, the UI currently behaves as it does for | |
| 571 | +concurrent wiki page edits, showing only the most recent | |
| 572 | +edit. Currently (2026-06) the UI is incapable of showing the older | |
| 573 | +forked copies but (A) the data are still part of the SCM history and | |
| 574 | +(B) there are plans to improve the UI to show such forks. | |
| 575 | + | |
| 576 | +For trivia's sake, here's a query which finds posts which have | |
| 577 | +forks: | |
| 578 | + | |
| 579 | +<pre><verbatim> | |
| 580 | +SELECT bp.rid AS parentRid, bp.uuid parentUuid, count(f.fprev) forkCount | |
| 581 | +FROM blob b, blob bp, forumpost f | |
| 582 | +WHERE b.rid=f.fpid | |
| 583 | +AND f.fprev=bp.rid | |
| 584 | +GROUP BY f.fprev | |
| 585 | +HAVING forkCount>1; | |
| 586 | +</verbatim></pre> | |
| 587 | + | |
| 588 | +And here's one which lists forked posts: | |
| 589 | + | |
| 590 | +<pre><verbatim> | |
| 591 | +WITH multiparent(mpid) AS ( | |
| 592 | + SELECT fprev FROM forumpost f | |
| 593 | + GROUP BY fprev | |
| 594 | + HAVING count(fprev)>1 | |
| 595 | +) | |
| 596 | +SELECT datetime(fmtime), forumpost.* | |
| 597 | +FROM forumpost, multiparent | |
| 598 | +WHERE fprev=mpid | |
| 599 | +ORDER BY mpid, fpid, fmtime; | |
| 600 | +</verbatim></pre> | |
| 601 | + | |
| 602 | +The telling part is the <code>fprev</code> column: those with matching | |
| 603 | +values forked from the post referred to by <code>fprev</code>. | |
| 412 | 604 |
| --- www/forum.wiki | |
| +++ www/forum.wiki | |
| @@ -369,11 +369,11 @@ | |
| 369 | actions are durable and have no undo. Be careful!</li> |
| 370 | </ol> |
| 371 | |
| 372 | <h2 id="close-post">Closing Forum Posts</h2> |
| 373 | |
| 374 | As of version 2.23, the forum interface supports the notion of |
| 375 | "closing" posts. By default, only users with the [./caps/index.md|'s' |
| 376 | and 'a' capabilities] may close or re-open posts, or reply to closed |
| 377 | posts. If the [/help/forum-close-policy|forum-close-policy |
| 378 | configuration option] is enabled then users with |
| 379 | [./caps/index.md|forum-moderator permissions] may also perform those |
| @@ -407,5 +407,197 @@ | |
| 407 | not permitted, without appropriate permissions, to close their own |
| 408 | posts. This is intentional, as closing one's own post can be used to |
| 409 | antagonize other forum users. For example, by posting something |
| 410 | trollish or highly controversial in nature and closing the post to |
| 411 | further responses. |
| 412 |
| --- www/forum.wiki | |
| +++ www/forum.wiki | |
| @@ -369,11 +369,11 @@ | |
| 369 | actions are durable and have no undo. Be careful!</li> |
| 370 | </ol> |
| 371 | |
| 372 | <h2 id="close-post">Closing Forum Posts</h2> |
| 373 | |
| 374 | As of version 2.23 the forum interface supports the notion of |
| 375 | "closing" posts. By default, only users with the [./caps/index.md|'s' |
| 376 | and 'a' capabilities] may close or re-open posts, or reply to closed |
| 377 | posts. If the [/help/forum-close-policy|forum-close-policy |
| 378 | configuration option] is enabled then users with |
| 379 | [./caps/index.md|forum-moderator permissions] may also perform those |
| @@ -407,5 +407,197 @@ | |
| 407 | not permitted, without appropriate permissions, to close their own |
| 408 | posts. This is intentional, as closing one's own post can be used to |
| 409 | antagonize other forum users. For example, by posting something |
| 410 | trollish or highly controversial in nature and closing the post to |
| 411 | further responses. |
| 412 | |
| 413 | <h2 id="status">Setting Post Statuses</h2> |
| 414 | |
| 415 | As of version 2.29 forum posts may be tagged with a status. The |
| 416 | setting <tt>forum-statuses</tt> controls whether this feature is is |
| 417 | enabled. If it is not set, is not valid JSON5, or has only a single |
| 418 | entry, then status are not shown in the forum. |
| 419 | |
| 420 | <tt>forum-statuses</tt> is a JSON5-format array of objects in the |
| 421 | following format: |
| 422 | |
| 423 | <verbatim> |
| 424 | [ |
| 425 | {label:"Open", value:"open"}, |
| 426 | {label:"Resolved", value:"resolved"} |
| 427 | ... |
| 428 | ]</verbatim> |
| 429 | |
| 430 | The list defines the legal statuses for forum posts and syncs with |
| 431 | other project-level settings. All "label" and "value" members must be |
| 432 | unique within the scope of that list. |
| 433 | |
| 434 | The "value" values must be legal for use as HTML "dataset" members so |
| 435 | that they can be used for with CSS selectors to apply per-status |
| 436 | styling. |
| 437 | |
| 438 | If the list is valid JSON5 and has two or more entries then the forum |
| 439 | behavior changes in the following ways: |
| 440 | |
| 441 | * Each TR element of the main <tt>/forum</tt> view table gets a |
| 442 | <tt>data-status="X"</tt> member, where "X" is the value part from |
| 443 | the associated status. This can be used to style the statuses |
| 444 | in the site skin using CSS selectors such as<br> |
| 445 | <tt>body.cpage-forum div.forumPosts tr[data-status="open"]</tt><br> |
| 446 | Because there is no default status list, no predefined styles |
| 447 | are applied. |
| 448 | * The forum list shows the "label" value of the current status and |
| 449 | a selection list of available filters. It elides the status column |
| 450 | when filtering on a specific status. |
| 451 | * The root of each thread, when selected, gets a new UI control for |
| 452 | displaying or editing the status, depending on permissions. |
| 453 | * A drop-down selection list is added to the <tt>/forum</tt> page |
| 454 | for filtering based on the status. |
| 455 | |
| 456 | A list with only a single entry is treated as empty, the justification |
| 457 | being that if there is only one option then the UI does not need to be |
| 458 | cluttered with it. |
| 459 | |
| 460 | This setting is applied via a <tt>status</tt> tag on the first version |
| 461 | of a legal post. That tag may be set to any value from the "values" |
| 462 | members of the <tt>forum-statuses</tt> list. |
| 463 | |
| 464 | Status tag rules: |
| 465 | |
| 466 | * <tt>status</tt> is only observed on the root of each thread. The UI |
| 467 | does nothing with that tag on responses. |
| 468 | * The first list entry is considered to be the default status. Any post |
| 469 | which has no <tt>status</tt> tag, or has a <tt>status</tt> tag value |
| 470 | which is not in that list, is assumed for most purposes to have the |
| 471 | value of the first entry in the list. |
| 472 | * The tag is applied only to the first version of any given post. The |
| 473 | UI ensures that the tag is applied to the proper post, even when |
| 474 | rendering a newer version. |
| 475 | |
| 476 | Caveat: a "closed" status is not recommended because it's easy to confuse with |
| 477 | the <a href='#close-post'>"closed" tag feature</a>, which behaves considerably |
| 478 | differently and predates that "status" tag support by about three years. The |
| 479 | "closed" semantics cannot be trivially consolidated with those of "status" |
| 480 | but we reserve the right to do so at some point. |
| 481 | |
| 482 | <h2 id="attachments">Attachments</h2> |
| 483 | |
| 484 | As of version 2.29 users with the [./caps/index.md|'B' capability] may |
| 485 | attach files to forum posts. Files may not be attached until a forum |
| 486 | post is saved for the first time, after which an "Attach" button will |
| 487 | appear in the post when it is selected. Attached files undergo |
| 488 | moderation exactly like forum posts do. When a moderator accepts a |
| 489 | pending-moderation posts, all files attached to it which are also |
| 490 | pending approval are also approved. Similarly, when a moderator |
| 491 | rejects a pending-moderation post, all files attached to it which are |
| 492 | also pending approval are rejected. |
| 493 | |
| 494 | Developer notes regarding the save-before-attach limitation: |
| 495 | |
| 496 | * We cannot add the attachment form to the current post editor |
| 497 | because (A) the Preview option would upload the files each time |
| 498 | (B) we cannot pre-populate file selection elements so could not |
| 499 | restore them when rendering the preview's response. |
| 500 | * To work around that we need to reimplement the forum editor |
| 501 | using AJAX-friendly APIs. That would allow us to render a preview |
| 502 | without reloading the page, to attach multiple files at once, |
| 503 | to support pasting a screenshot as an attachment, and to submit both |
| 504 | a new post and its attachments at the same time. |
| 505 | * We have AJAX-capable preview code in /wiki and /fileedit. |
| 506 | * We have paste-screenshot code in /chat but integrating it here will |
| 507 | require adding a "paste" button to the attachment UI. |
| 508 | |
| 509 | Developer notes regarding automatic acceptance/rejection of |
| 510 | attachments: |
| 511 | |
| 512 | * There is a race condition here where an admin may approve |
| 513 | attachments they have not yet seen: user creates posts, admin gets |
| 514 | notified, admin reads post, user attaches a file at that time, |
| 515 | admin approves post. |
| 516 | |
| 517 | TBD is whether to accept that case or to remove automatic approval of |
| 518 | attached files. |
| 519 | |
| 520 | <h2 id="drafts">Draft Edits</h2> |
| 521 | |
| 522 | The forum uses, if available, JavaScript's <code>localStorage</code> |
| 523 | or <code>sessionStorage</code> to store local drafts of new |
| 524 | posts, replies, and edits to existing posts. Each time an editor |
| 525 | input field loses focus, the draft is saved. When viewing a forum |
| 526 | thread, the Edit and Reply buttons get clearly marked if they |
| 527 | have an associated local draft. |
| 528 | |
| 529 | Local drafts for replies and responses (but not new posts) are |
| 530 | automatically purged at semi-random intervals. Every Nth visit to a |
| 531 | forum page has a small chance to run the cleanup, and drafts older |
| 532 | than 10 days old are purged. |
| 533 | |
| 534 | If neither <code>localStorage</code> nor <code>sessionStorage</code> |
| 535 | are available, it uses a transient storage object which is recreated |
| 536 | on each page-load, so it cannot store drafts outside of a single |
| 537 | thread at a time. |
| 538 | |
| 539 | Beware: Each draft is keyed to the post it is editing or replied to, |
| 540 | which means that editing or replying to the same post from different |
| 541 | tabs will cause collisions. The editor to most recently lose the focus |
| 542 | will save the draft, overwriting the other. |
| 543 | |
| 544 | In browsers which support Web Locks, attempts to edit resp. reply to a |
| 545 | post which is already being edited resp. replied to in another tab |
| 546 | will show an error for the second and subsequent tabs. The first tab |
| 547 | to use the edit/reply buttons will hold a separate Web Lock for each |
| 548 | and forbid edit/reply access to the post in other tabs until the |
| 549 | locking tab is closed. |
| 550 | |
| 551 | |
| 552 | <h2 id="padding">Curious Extra Page Padding</h2> |
| 553 | |
| 554 | Users may notice that the forum pages get a bunch of padding added to |
| 555 | the bottom of the page when an editor widget is opened. This is not a |
| 556 | bug, but a workaround to help avoid the UI jumping around when |
| 557 | rendering a preview wildly resizes the widget. The effect is |
| 558 | especially helpful when working on posts while the bottom footer of |
| 559 | the page is in the viewport, as the footer is a hard boundary against |
| 560 | scrolling. With the extra padding, the editor widget's top edge shifts |
| 561 | around less when the preview is shown and hidden. |
| 562 | |
| 563 | <h2 id="fork">Forked Edits</h2> |
| 564 | |
| 565 | It is possible to "fork" forum messages, in the same way that any |
| 566 | given check-in may cause a fork. This can happen when a message is |
| 567 | edited concurrently from two or more browser tabs or via two or more |
| 568 | fossil instances which subsequently sync with each other. |
| 569 | |
| 570 | When a forum post is forked, the UI currently behaves as it does for |
| 571 | concurrent wiki page edits, showing only the most recent |
| 572 | edit. Currently (2026-06) the UI is incapable of showing the older |
| 573 | forked copies but (A) the data are still part of the SCM history and |
| 574 | (B) there are plans to improve the UI to show such forks. |
| 575 | |
| 576 | For trivia's sake, here's a query which finds posts which have |
| 577 | forks: |
| 578 | |
| 579 | <pre><verbatim> |
| 580 | SELECT bp.rid AS parentRid, bp.uuid parentUuid, count(f.fprev) forkCount |
| 581 | FROM blob b, blob bp, forumpost f |
| 582 | WHERE b.rid=f.fpid |
| 583 | AND f.fprev=bp.rid |
| 584 | GROUP BY f.fprev |
| 585 | HAVING forkCount>1; |
| 586 | </verbatim></pre> |
| 587 | |
| 588 | And here's one which lists forked posts: |
| 589 | |
| 590 | <pre><verbatim> |
| 591 | WITH multiparent(mpid) AS ( |
| 592 | SELECT fprev FROM forumpost f |
| 593 | GROUP BY fprev |
| 594 | HAVING count(fprev)>1 |
| 595 | ) |
| 596 | SELECT datetime(fmtime), forumpost.* |
| 597 | FROM forumpost, multiparent |
| 598 | WHERE fprev=mpid |
| 599 | ORDER BY mpid, fpid, fmtime; |
| 600 | </verbatim></pre> |
| 601 | |
| 602 | The telling part is the <code>fprev</code> column: those with matching |
| 603 | values forked from the post referred to by <code>fprev</code>. |
| 604 |
+142
-119
| --- www/fossil-v-git.wiki | ||
| +++ www/fossil-v-git.wiki | ||
| @@ -20,12 +20,12 @@ | ||
| 20 | 20 | In this document, we set all of that similarity and interoperability |
| 21 | 21 | aside and focus on the important differences between the two, especially |
| 22 | 22 | those that impact the user experience. |
| 23 | 23 | |
| 24 | 24 | Keep in mind that you are reading this on a Fossil website, and though |
| 25 | -we try to be fair, the information here | |
| 26 | -might be biased in favor of Fossil, if only because we spend most of our | |
| 25 | +we try to be fair, the information here will inevitably | |
| 26 | +be biased in favor of Fossil purely because we spend most of our | |
| 27 | 27 | time using Fossil, not Git. Ask around for second opinions from |
| 28 | 28 | people who have used <em>both</em> Fossil and Git. |
| 29 | 29 | |
| 30 | 30 | If you want a more practical, less philosophical guide to moving from |
| 31 | 31 | Git to Fossil, see our [./gitusers.md | Git to Fossil Translation Guide]. |
| @@ -178,36 +178,40 @@ | ||
| 178 | 178 | This policy is particularly useful when running Fossil inside a |
| 179 | 179 | restrictive container, anything from [./chroot.md | classic chroot |
| 180 | 180 | jails] to modern [https://en.wikipedia.org/wiki/OS-level_virtualization |
| 181 | 181 | | OS-level virtualization mechanisms] such as |
| 182 | 182 | [https://en.wikipedia.org/wiki/Docker_(software) | Docker]. |
| 183 | -Our [./containers.md | stock container image] is under 8 MB when | |
| 184 | -uncompressed and running. It contains nothing but a single | |
| 183 | +Our [./containers.md | stock container image] is under 11 MB when | |
| 184 | +uncompressed and running because it contains nothing but a single | |
| 185 | 185 | statically-linked binary. |
| 186 | 186 | |
| 187 | -If you build a dynamically linked binary instead, Fossil's on-disk size | |
| 188 | -drops to around 6 MB, and it's dependent only on widespread | |
| 187 | +If you build a dynamically linked binary instead, a Linux | |
| 188 | +x86_64 build of Fossil drops to under 5 MB on-disk, stripped. | |
| 189 | +It will depend only on widespread | |
| 189 | 190 | platform libraries with stable ABIs such as glibc, zlib, and openssl. |
| 190 | 191 | |
| 191 | -Full static linking is easier on Windows, so our precompiled Windows | |
| 192 | -binaries are just a ZIP archive | |
| 193 | -containing only "<tt>fossil.exe</tt>". There is no "<tt>setup.exe</tt>" | |
| 194 | -to run. | |
| 192 | +Much the same is true on Windows, where our precompiled static binaries | |
| 193 | +are distributed inside a ZIP archive containing "<tt>fossil.exe</tt>" | |
| 194 | +and not a thing else, with a size on-par that of the Linux container | |
| 195 | +build. There is no "<tt>setup.exe</tt>" to run; just copy it into your | |
| 196 | +<tt>%PATH%</tt>. | |
| 195 | 197 | |
| 196 | 198 | Fossil is easy to build from sources. Just run |
| 197 | 199 | "<tt>./configure && make</tt>" on POSIX systems and |
| 198 | 200 | "<tt>nmake /f Makefile.msc</tt>" on Windows. |
| 199 | 201 | |
| 200 | -Contrast a basic installation of Git, which takes up about | |
| 201 | -15 MiB on Debian 10 across 230 files, not counting the contents of | |
| 202 | -<tt>/usr/share/doc</tt> or <tt>/usr/share/locale</tt>. If you need to | |
| 203 | -deploy to any platform where you cannot count on facilities like the POSIX | |
| 204 | -shell, Perl interpreter, and Tcl/Tk platform needed to fully use Git | |
| 205 | -as part of the base platform, the full footprint of a Git installation | |
| 206 | -extends to more like 45 MiB and thousands of files. This complicates | |
| 207 | -several common scenarios: Git for Windows, chrooted Git servers, | |
| 208 | -Docker images... | |
| 202 | +Git, by contrast, takes 25 MiB on Ubuntu 26.04 across 940 files. | |
| 203 | +That doesn't count platform facilities like the POSIX shell and script | |
| 204 | +interpreters its full feature set requires. A fairer comparison to | |
| 205 | +Fossil's single static binary container is the Docker Hardened Image for | |
| 206 | +[https://hub.docker.com/hardened-images/catalog/dhi/git |Git 2.x on | |
| 207 | +Alpine], which presently weighs in at 36.3 megs unpacked and 607 files, | |
| 208 | +if you count all the <tt>busybox</tt> symlinks which would otherwise be | |
| 209 | +separate binaries on a more traditional Linux system. Worst of all are | |
| 210 | +the "Git for Windows" packages where they end up needing to ship a large | |
| 211 | +yet nerfed Linux-like userland to support Git's many loosely coupled | |
| 212 | +pieces, approaching a hundred megs and thousands of files. | |
| 209 | 213 | |
| 210 | 214 | Some say that Git more closely adheres to the Unix philosophy, |
| 211 | 215 | summarized as "many small tools, loosely joined," but we have many |
| 212 | 216 | examples of other successful Unix software that violates that principle |
| 213 | 217 | to good effect, from Apache to Python to ZFS. We can infer from that |
| @@ -216,26 +220,47 @@ | ||
| 216 | 220 | matters is effectiveness and efficiency. We believe Fossil achieves |
| 217 | 221 | this. |
| 218 | 222 | |
| 219 | 223 | The above size comparisons aren't apples-to-apples anyway. We've |
| 220 | 224 | compared the size of Fossil with all of its [#features | many built-in |
| 221 | -features] to a fairly minimal Git installation. You must add a lot of | |
| 222 | -third-party software to Git to give it a Fossil-equivalent feature set. | |
| 223 | -Consider [https://about.gitlab.com/|GitLab], a third-party extension to | |
| 224 | -Git wrapping it in many features, making it roughly Fossil-equivalent, | |
| 225 | -though [https://docs.gitlab.com/ee/install/requirements.html|much more | |
| 226 | -resource hungry] and hence more costly to run than the equivalent Fossil | |
| 227 | -setup. [https://hub.docker.com/r/gitlab/gitlab-ce/ | The official GitLab | |
| 228 | -Community Edition container] currently clocks in at 2.66 GiB! | |
| 229 | - | |
| 230 | -GitLab's requirements are easy to accept when you're dedicating | |
| 231 | -a local rack server or blade to it, since its minimum requirements are | |
| 232 | -more or less a description of the smallest | |
| 233 | -thing you could call a "server" these days, but when you go to host that | |
| 234 | -in the cloud, you can expect to pay about 8 times as much to comfortably host | |
| 235 | -GitLab as for Fossil.³ This difference is largely due to basic | |
| 236 | -technology choices: Ruby and PostgreSQL vs C and SQLite. | |
| 225 | +features] to a relatively bare-bones Git installation. You must add a | |
| 226 | +lot of third-party software to Git to give it a Fossil-equivalent | |
| 227 | +feature set. | |
| 228 | + | |
| 229 | +Consider [https://about.gitlab.com/|GitLab], which wraps Git in enough | |
| 230 | +features to bring it to a rough (very rough) parity with Fossil. While | |
| 231 | +it is certainly ahead in some areas — automation comes to mind — it must | |
| 232 | +be noted that GitLab's own forums are on Discourse, not self-hosted as | |
| 233 | +with Fossil. You may then argue that Discourse is superior to the Fossil | |
| 234 | +forum feature, but this merely brings us back to another of Fossil's | |
| 235 | +advantages: when the posts are part of the repo, you can migrate your | |
| 236 | +entire project to another host merely by standing that repo back up on | |
| 237 | +other hardware. Choosing to assemble your project hosting from multiple | |
| 238 | +pieces requires each to have their own backups, their own management | |
| 239 | +processes, and their own migration strategies. | |
| 240 | + | |
| 241 | +Even then, these disparate services do not cooperate at the same level | |
| 242 | +as in Fossil, where the ability to have a forum post linking to a wiki | |
| 243 | +article linking to a trouble ticket linking to a commit falls out of the | |
| 244 | +model nearly for free. These are all internal links, mind, potentially | |
| 245 | +using nothing but repository artifact hashes, all backed by SQLite's | |
| 246 | +referential integrity. With something like GitLab, its "internal | |
| 247 | +references" are tacked on after the fact, not Git repo hashes at all, | |
| 248 | +and when it comes to external services like Discourse, history tells us | |
| 249 | +you're storing up tech debt which will come due at some future point in | |
| 250 | +the form of piles of broken links when one piece or the other needs | |
| 251 | +changing out. | |
| 252 | + | |
| 253 | +Furthermore, GitLab is far more resource hungry even in its | |
| 254 | +[https://docs.gitlab.com/omnibus/settings/memory_constrained_envs/ | | |
| 255 | +minimal configuration], hence more costly to run than the equivalent | |
| 256 | +Fossil setup. [https://hub.docker.com/r/gitlab/gitlab-ce/ | The | |
| 257 | +official GitLab Community Edition container] currently clocks in at | |
| 258 | +3.44 GiB, independent of add-ons like Discourse. You can expect it to | |
| 259 | +cost around 8× as much to host it on a cloud service. Even pared down | |
| 260 | +to the minimum, there remain the consequences from the difference in | |
| 261 | +basic technology choices: Ruby and PostgreSQL vs C and SQLite. | |
| 237 | 262 | |
| 238 | 263 | The Fossil project itself is [./selfhost.wiki|hosted on a small and |
| 239 | 264 | inexpensive VPS]. A bare-bones $5/month VPS or a |
| 240 | 265 | spare Raspberry Pi is sufficient to run a full-up project |
| 241 | 266 | site, complete with tickets, wiki, chat, and forum, in addition to |
| @@ -255,33 +280,34 @@ | ||
| 255 | 280 | <tt>.git</tt> folder or compressed into bespoke key/value |
| 256 | 281 | [https://git-scm.com/book/en/v2/Git-Internals-Packfiles|pack-files], |
| 257 | 282 | whereas Fossil stores its objects in a [https://www.sqlite.org/|SQLite] |
| 258 | 283 | database file which provides ACID transactions and a high-level query |
| 259 | 284 | language. |
| 260 | -This difference is more than an implementation detail. It has important | |
| 285 | + | |
| 286 | +This difference is more than an implementation detail; it has important | |
| 261 | 287 | practical consequences. |
| 262 | 288 | |
| 263 | -One notable consequence is that it is difficult to find the descendants | |
| 289 | +One notable example is that it is difficult to find the descendants | |
| 264 | 290 | of check-ins in Git. |
| 265 | 291 | One can easily locate the ancestors of a particular Git check-in |
| 266 | -by following the pointers embedded in the check-in object, but it is | |
| 267 | -difficult to go the other direction and locate the descendants of a | |
| 268 | -check-in. It is so difficult, in fact, that neither native Git nor | |
| 269 | -GitHub provide this capability short of crawling the | |
| 270 | -[https://www.git-scm.com/docs/git-log|commit log]. With Fossil, | |
| 271 | -on the other hand, finding descendants is a simple SQL query. | |
| 272 | -It is common in Fossil to ask to see | |
| 273 | -[/timeline?df=release&y=ci|all check-ins since the last release]. | |
| 274 | -Git lets you see "what came before". Fossil makes it just as | |
| 275 | -easy to also see "what came after". | |
| 292 | +by following the pointers embedded in the check-in object, but | |
| 293 | +going the other direction is difficult enough | |
| 294 | +that neither native Git nor the big "forge" facilities | |
| 295 | +like GitHub and GitLab provide this capability short of crawling the | |
| 296 | +[https://www.git-scm.com/docs/git-log|commit log]. In Fossil, | |
| 297 | +we can find descendants using a simple SQL query, which then allows | |
| 298 | +us to see [/timeline?df=release&y=ci|all check-ins since the last release], | |
| 299 | +as but one example. | |
| 300 | +Git lets you see "what came before," but Fossil makes it just as | |
| 301 | +easy to also see "what came after." | |
| 276 | 302 | |
| 277 | 303 | Leaf check-ins in Git that lack a "ref" become "detached," making them |
| 278 | 304 | difficult to locate and subject to garbage collection. This |
| 279 | 305 | [https://stackoverflow.com/q/3965676 | detached head |
| 280 | 306 | state] problem has caused grief for |
| 281 | -[https://www.google.com/search?q=git+detached+head+state | many | |
| 282 | -Git users]. With | |
| 307 | +[https://www.google.com/search?q=git+detached+head+state | | |
| 308 | +untold millions of Git users]. With | |
| 283 | 309 | Fossil, detached heads are simply impossible because we can always find |
| 284 | 310 | our way back into the Merkle tree using one or more of the relations |
| 285 | 311 | in the SQL database. |
| 286 | 312 | |
| 287 | 313 | The SQL query capabilities of Fossil make it easier to track the |
| @@ -288,34 +314,27 @@ | ||
| 288 | 314 | changes for one particular file within a project. For example, |
| 289 | 315 | you can easily find |
| 290 | 316 | [/finfo/www/fossil-v-git.wiki|the complete edit history of this one document], |
| 291 | 317 | or even |
| 292 | 318 | [/finfo/www/fossil-v-git.wiki?ubg|the same history color-coded by committer], |
| 293 | -Both questions are simple SQL query in Fossil, with procedural code | |
| 319 | +Both come down to simple SQL queries in Fossil, with procedural code | |
| 294 | 320 | only being used to format the result for display. |
| 295 | 321 | The same result could be obtained from Git, but because the data is |
| 296 | 322 | in a key/value store, much more procedural code has to be written to |
| 297 | -walk the data and compute the result. And since that is a lot more | |
| 298 | -work, the question is seldom asked. | |
| 323 | +walk the data and compute the result. | |
| 299 | 324 | |
| 300 | 325 | The ease of querying Fossil data using SQL means that status or |
| 301 | 326 | history information about the project under management is easier |
| 302 | -to obtain. Being easier means that it is more likely to happen. | |
| 327 | +to obtain, hence more likely to happen, giving its developers better | |
| 328 | +situational awareness. | |
| 303 | 329 | Fossil reports tend to be more detailed and useful. |
| 304 | 330 | Compare [/timeline?c=6df7a853ec16865b|this Fossil timeline] |
| 305 | 331 | to |
| 306 | 332 | [https://github.com/drhsqlite/fossil-mirror/commits/master?after=f720c106d297ca1f61bccb30c5c191b88a626d01+34 | |
| 307 | -its closest equivalent in GitHub]. Judge for yourself: which of those | |
| 333 | +its closest equivalent in the GitHub mirror]. Judge for yourself: which of those | |
| 308 | 334 | reports is more useful to a developer trying to understand what happened? |
| 309 | 335 | |
| 310 | -The bottom line is that even though Fossil and Git are built around | |
| 311 | -the same low-level data structure, the use of SQL | |
| 312 | -to query this data makes the data more accessible in Fossil, resulting | |
| 313 | -in more detailed information being available to the user. This | |
| 314 | -improves situational awareness and makes working on the project | |
| 315 | -easier. | |
| 316 | - | |
| 317 | 336 | <h3 id="portable">2.4 Portable</h3> |
| 318 | 337 | |
| 319 | 338 | Fossil is largely written in ISO C, almost purely conforming to the |
| 320 | 339 | original 1989 standard. We make very little use of |
| 321 | 340 | [https://en.wikipedia.org/wiki/C99|C99], and we do not knowingly make |
| @@ -326,11 +345,11 @@ | ||
| 326 | 345 | facilities Fossil needs to do its thing. (Network sockets, file locking, |
| 327 | 346 | etc.) There are certainly well-known platforms Fossil hasn't been ported |
| 328 | 347 | to yet, but that's most likely due to lack of interest rather than |
| 329 | 348 | inherent difficulties in doing the port. We believe the most stringent |
| 330 | 349 | limit on its portability is that it assumes at least a 32-bit CPU and |
| 331 | -several megs of flat-addressed memory.⁴ Fossil isn't quite as | |
| 350 | +several megs of flat-addressed memory.³ Fossil isn't quite as | |
| 332 | 351 | [https://www.sqlite.org/custombuild.html|portable as SQLite], but it's |
| 333 | 352 | close. |
| 334 | 353 | |
| 335 | 354 | Over half of the C code in Fossil is actually an embedded copy of the |
| 336 | 355 | current version of SQLite. Much of what is Fossil-specific after you set |
| @@ -344,20 +363,20 @@ | ||
| 344 | 363 | necessary]. The server-side |
| 345 | 364 | UI scripting uses a custom minimal |
| 346 | 365 | [https://en.wikipedia.org/wiki/Tcl|Tcl] dialect called |
| 347 | 366 | [./th1.md|TH1], which is |
| 348 | 367 | embedded into Fossil itself. Fossil's build system and test suite are |
| 349 | -largely based on Tcl.⁵ All of this is quite portable. | |
| 368 | +largely based on Tcl.⁴ All of this is quite portable. | |
| 350 | 369 | |
| 351 | 370 | About half of Git's code is POSIX C, and about a third is POSIX shell |
| 352 | 371 | code. This is largely why the so-called "Git for Windows" distributions |
| 353 | 372 | (both [https://git-scm.com/download/win|first-party] and |
| 354 | 373 | [https://gitforwindows.org/|third-party]) are actually an |
| 355 | 374 | [https://www.msys2.org/wiki/Home/|MSYS POSIX portability environment] bundled |
| 356 | 375 | with all of the Git stuff, because it would be too painful to port Git |
| 357 | 376 | natively to Windows. Git is a foreign citizen on Windows, speaking to it |
| 358 | -only through a translator.⁶ | |
| 377 | +only through a translator.⁵ | |
| 359 | 378 | |
| 360 | 379 | While Fossil does lean toward POSIX norms when given a choice — LF-only |
| 361 | 380 | line endings are treated as first-class citizens over CR+LF, for example |
| 362 | 381 | — the Windows build of Fossil is truly native. |
| 363 | 382 | |
| @@ -444,11 +463,11 @@ | ||
| 444 | 463 | [https://www.git-scm.com/docs/git-request-pull|pull requests] offer |
| 445 | 464 | a low-friction path to accepting |
| 446 | 465 | [https://www.jonobacon.com/2012/07/25/building-strong-community-structural-integrity/|drive-by |
| 447 | 466 | contributions]. Fossil's closest equivalents are its unique |
| 448 | 467 | [/help/bundle|bundle] and [/help/patch|patch] features, which require higher engagement |
| 449 | - than firing off a PR.⁷ This difference comes directly from the | |
| 468 | + than firing off a PR.⁶ This difference comes directly from the | |
| 450 | 469 | initial designed purpose for each tool: the SQLite project doesn't |
| 451 | 470 | accept outside contributions from previously-unknown developers, but |
| 452 | 471 | the Linux kernel does. |
| 453 | 472 | |
| 454 | 473 | * <b>No rebasing:</b> When your local repo clone syncs changes |
| @@ -500,16 +519,16 @@ | ||
| 500 | 519 | that everyone — especially the project leader — can maintain a better |
| 501 | 520 | mental picture of what is happening, leading to better situational |
| 502 | 521 | awareness. |
| 503 | 522 | |
| 504 | 523 | By contrast, "…[https://docs.github.com/en/get-started/quickstart/contributing-to-projects|forking is |
| 505 | -at the core of social coding at GitHub]". As of January 2022, | |
| 506 | -[https://github.com/search?q=is:public|Github hosts 47 million distinct | |
| 524 | +at the core of social coding at GitHub]". As of June 2026, | |
| 525 | +[https://github.com/search?q=is:public|Github hosts 324 million distinct | |
| 507 | 526 | software projects], most of which were created by forking a |
| 508 | 527 | previously-existing project. Since this is |
| 509 | -[https://evansdata.com/reports/viewRelease.php?reportID=9 | roughly | |
| 510 | -twice the number of developers in the world], it beggars belief that | |
| 528 | +[https://www.griddynamics.com/blog/number-software-developers-world | | |
| 529 | +~11× the number of developers in the world], it beggars belief that | |
| 511 | 530 | most of these forks are still under active development. The vast bulk |
| 512 | 531 | of these must be abandoned one-off efforts. This is part of the nature |
| 513 | 532 | of bazaar style development. |
| 514 | 533 | |
| 515 | 534 | You can think about this difference in terms of |
| @@ -533,18 +552,18 @@ | ||
| 533 | 552 | <h4 id="scale">2.5.2 Scale</h4> |
| 534 | 553 | |
| 535 | 554 | The Linux kernel has a far bigger developer community than that of |
| 536 | 555 | SQLite: there are thousands and thousands of contributors to Linux, most |
| 537 | 556 | of whom do not know each other's names. These thousands are responsible |
| 538 | -for producing roughly 89× more code than is in SQLite. (10.7 | |
| 539 | -[https://en.wikipedia.org/wiki/Source_lines_of_code|MLOC] vs. 0.12 MLOC | |
| 540 | -according to [https://dwheeler.com/sloccount/|SLOCCount].) The Linux | |
| 557 | +for producing roughly 73× more code than is in SQLite. (32.0 | |
| 558 | +[https://en.wikipedia.org/wiki/Source_lines_of_code|MLOC] vs. 0.44 MLOC | |
| 559 | +according to [https://github.com/boyter/scc | scc].) The Linux | |
| 541 | 560 | kernel and its development process were already uncommonly large back in |
| 542 | 561 | 2005 when Git was designed, specifically to support the consequences of |
| 543 | 562 | having such a large set of developers working on such a large code base. |
| 544 | 563 | |
| 545 | -95% of the code in SQLite comes from just four programmers, and 64% of | |
| 564 | +95% of the code in SQLite comes from just six programmers, and 62% of | |
| 546 | 565 | it is from the lead developer alone. The SQLite developers know each |
| 547 | 566 | other well and interact daily. Fossil was designed for this development |
| 548 | 567 | model. |
| 549 | 568 | |
| 550 | 569 | When choosing your DVCS, we think you should ask yourself whether the |
| @@ -564,35 +583,33 @@ | ||
| 564 | 583 | |
| 565 | 584 | Both Fossil and Git store history as a directed acyclic graph (DAG) |
| 566 | 585 | of changes, but Git tends to focus more on individual branches of |
| 567 | 586 | the DAG, whereas Fossil puts more emphasis on the entire DAG. |
| 568 | 587 | |
| 569 | -For example, the default behavior in Git is to only synchronize | |
| 570 | -a single branch, whereas with Fossil the only sync option is to | |
| 571 | -sync the entire DAG. Git commands, | |
| 588 | +While a common usage pattern in Git is to only synchronize | |
| 589 | +a single branch — <tt>git pull upstream feature/branch</tt> — instead | |
| 590 | +of all refs, Fossil does not give you a choice; it | |
| 591 | +syncs the entire DAG or nothing. Git commands, | |
| 572 | 592 | GitHub, and GitLab tend to show only a single branch at |
| 573 | 593 | a time, whereas Fossil usually shows all parallel branches at |
| 574 | 594 | once. Git has commands like "rebase" that help keep all relevant |
| 575 | 595 | changes on a single branch, whereas Fossil encourages a style of |
| 576 | 596 | many concurrent branches constantly springing into existence, |
| 577 | 597 | undergoing active development in parallel for a few days or weeks, then |
| 578 | 598 | merging back into the main line and disappearing. |
| 579 | 599 | |
| 580 | 600 | This difference in emphasis arises from the different purposes of |
| 581 | -the two systems. Git focuses on individual branches, because that | |
| 601 | +the two systems. Git's focus on individual branches | |
| 582 | 602 | is exactly what you want for a highly-distributed bazaar-style project |
| 583 | 603 | such as Linux. Linus Torvalds does not want to see every check-in |
| 584 | 604 | by every contributor to Linux: such extreme visibility does not scale |
| 585 | 605 | well. Contrast Fossil, which was written for the cathedral-style SQLite project |
| 586 | 606 | and its handful of active committers. Seeing all |
| 587 | 607 | changes on all branches all at once helps keep the whole team |
| 588 | 608 | up-to-date with what everybody else is doing, resulting in a more |
| 589 | 609 | tightly focused and cohesive implementation. |
| 590 | 610 | |
| 591 | -Parts of this section are [https://fossil-scm.org/forum/forumpost/5961e969fa|disputed] | |
| 592 | -by [https://github.com/olorin37|Jakub A. G.]. | |
| 593 | - | |
| 594 | 611 | |
| 595 | 612 | <h3 id="checkouts">2.6 One vs. Many Check-outs per Repository</h3> |
| 596 | 613 | |
| 597 | 614 | Because Git commingles the repository data with the initial checkout of |
| 598 | 615 | that repository, the default mode of operation in Git is to stick to that |
| @@ -612,20 +629,28 @@ | ||
| 612 | 629 | standard advice is to use a switch-in-place workflow in Fossil when |
| 613 | 630 | the disturbance from switching branches is small, and to use multiple |
| 614 | 631 | checkouts when you have long-lived working branches that are different |
| 615 | 632 | enough that switching in place is disruptive. |
| 616 | 633 | |
| 617 | -While you can [./gitusers.md#worktree | use Git in the Fossil style], | |
| 618 | -Git's default tie between working directory and | |
| 619 | -repository means the standard method for working with a Git repo is to | |
| 620 | -have one working directory only. Most Git tutorials teach this style, so | |
| 621 | -it is how most people learn to use Git. Because relatively few people | |
| 622 | -use Git with multiple working directories per repository, there are | |
| 634 | +While you can [./gitusers.md#worktree | use Git in the Fossil style] via | |
| 635 | +its worktree feature, tutorials continue to teach the style of having | |
| 636 | +one working directory only. Git can even fight you on this, as when | |
| 637 | +working with a forked repository; it is best to have independent clones | |
| 638 | +of the upstream and your fork, to allow separate "remote" lists and | |
| 639 | +such. This can result in two working directories but each having a | |
| 640 | +captive repo clone each, which isn't in the spirit of <tt>git | |
| 641 | +worktree</tt> at all. Yet, it beats the alternative, which then | |
| 642 | +highlights a gap in the model of diverging and re-converging forks. | |
| 643 | +Ideally, Git would let you create one of these forks as a worktree while | |
| 644 | +maintaining a strong separation between your fork and the upstream repo, | |
| 645 | +but it ends up being too much hassle to bother with. | |
| 646 | + | |
| 647 | +There are | |
| 623 | 648 | [https://duckduckgo.com/?q=git+worktree+problem | several known |
| 624 | -problems] with that way of working, problems which don't happen in Fossil because of | |
| 625 | -the clear [./ckout-workflows.md | separation] between a Fossil repository and | |
| 626 | -each working directory. | |
| 649 | +problems] with the single worktree style, ones which don't happen in | |
| 650 | +Fossil because of the clear [./ckout-workflows.md | separation] between | |
| 651 | +a Fossil repository and each working directory. | |
| 627 | 652 | |
| 628 | 653 | This distinction matters because switching branches inside a single working directory loses local context |
| 629 | 654 | on each switch. |
| 630 | 655 | |
| 631 | 656 | For instance, in any software project where the runnable program must be |
| @@ -658,13 +683,10 @@ | ||
| 658 | 683 | |
| 659 | 684 | Plus, |
| 660 | 685 | <tt>cd</tt> is faster to type than <tt>git checkout</tt> or <tt>fossil |
| 661 | 686 | update</tt>. |
| 662 | 687 | |
| 663 | -Parts of this section are [https://fossil-scm.org/forum/forumpost/5961e969fa|disputed] | |
| 664 | -by [https://github.com/olorin37|Jakub A. G.]. | |
| 665 | - | |
| 666 | 688 | <h3 id="history">2.7 What you should have done vs. What you actually did</h3> |
| 667 | 689 | |
| 668 | 690 | Git puts a lot of emphasis on maintaining |
| 669 | 691 | a "clean" check-in history. Extraneous and experimental branches by |
| 670 | 692 | individual developers often never make it into the main repository. |
| @@ -822,14 +844,14 @@ | ||
| 822 | 844 | concepts to keep track of in your mental model of Fossil's internal |
| 823 | 845 | operation. |
| 824 | 846 | |
| 825 | 847 | Fossil's implementation of the feature is also simpler to describe. The |
| 826 | 848 | brief online help for <tt>[/help/merge | fossil merge]</tt> is |
| 827 | -currently 41 lines long, to which you want to add the 600 lines of | |
| 849 | +currently 50 lines long, to which you want to add the ~800 lines of | |
| 828 | 850 | [./branching.wiki | the branching document]. The equivalent |
| 829 | 851 | documentation in Git is the aggregation of the man pages for the above |
| 830 | -three commands, which is over 1000 lines, much of it mutually redundant. | |
| 852 | +three commands, which is approaching 1400 lines as of this writing, much of it mutually redundant. | |
| 831 | 853 | (e.g. Git's <tt>--edit</tt> and <tt>--no-commit</tt> options get |
| 832 | 854 | described three times, each time differently.) Fossil's |
| 833 | 855 | documentation is not only more concise, it gives a nice split of brief |
| 834 | 856 | online help and full online documentation. |
| 835 | 857 | |
| @@ -852,35 +874,42 @@ | ||
| 852 | 874 | This not |
| 853 | 875 | only solves the SHAttered problem, it should prevent a reoccurrence of |
| 854 | 876 | similar problems for the foreseeable future. |
| 855 | 877 | |
| 856 | 878 | Meanwhile, the Git community took until August 2018 to publish |
| 857 | -[https://git-scm.com/docs/hash-function-transition/|their first plan] | |
| 858 | -for solving the same problem by moving to SHA-256, a variant of the | |
| 859 | -[https://en.wikipedia.org/wiki/SHA-2 | older SHA-2 algorithm]. As of | |
| 860 | -this writing in February 2020, that plan hasn't been implemented, as far | |
| 861 | -as this author is aware, but there is now | |
| 862 | -[https://lwn.net/ml/git/[email protected]/ | |
| 863 | -| a competing SHA-256 based plan] which requires complete repository | |
| 864 | -conversion from SHA-1 to SHA-256, breaking all public hashes in the | |
| 865 | -repo. One way to characterize such a massive upheaval in Git terms is a | |
| 866 | -whole-project rebase, which violates the | |
| 867 | -[https://www.atlassian.com/git/tutorials/merging-vs-rebasing#the-golden-rule-of-rebasing|Golden Rule of Rebasing]. | |
| 868 | - | |
| 869 | -Regardless of the eventual implementation details, we fully expect Git | |
| 870 | -to move off SHA-1 eventually and for the changes to take years more to | |
| 871 | -percolate through the community. | |
| 872 | - | |
| 879 | +[https://git-scm.com/docs/hash-function-transition/ | their plan] for | |
| 880 | +solving the same problem by moving to SHA-256, a variant of the | |
| 881 | +[https://en.wikipedia.org/wiki/SHA-2 | older SHA-2 algorithm]. That is | |
| 882 | +now technically implemented in the sense that <tt>git init | |
| 883 | +--object-format=sha256</tt> exists, but note well: this is not only an | |
| 884 | +optional setting, Git forge support is mixed, most notably | |
| 885 | +[https://github.com/GitoxideLabs/gitoxide/issues/281 | lacking in | |
| 886 | +GitHub], plus also BitBucket and others. This is doubtless because of | |
| 887 | +this warning in the latest ([https://git-scm.com/docs/git-init/2.54.0 | | |
| 888 | +as of this writing]) <tt>git init</tt> docs: | |
| 889 | + | |
| 890 | +<blockquote>Note: At present, there is no interoperability between | |
| 891 | +SHA-256 repositories and SHA-1 repositories.</blockquote> | |
| 892 | + | |
| 893 | +Although we are now in the <i>tenth year</i> of this situation, there | |
| 894 | +remains hope that Git will manage to make the transition without taking | |
| 895 | +the full decade: the | |
| 896 | +[https://www.deployhq.com/blog/git-3-0-on-the-horizon-what-git-users-need-to-know-about-the-next-major-release | |
| 897 | +| latest plan] is that Git 3.0 will finally <i>(finally!)</i> switch to | |
| 898 | +SHA256 by default, forcing the issue. Given the track record, we are | |
| 899 | +taking a "show me" stance on this claim. | |
| 900 | + | |
| 901 | +Always remember, attacks only get better, never worse. | |
| 873 | 902 | Almost three years after Fossil solved this problem, the |
| 874 | 903 | [https://sha-mbles.github.io/ | SHAmbles attack] was published, further |
| 875 | 904 | weakening the case for continuing to use SHA-1. |
| 876 | 905 | |
| 877 | 906 | The practical impact of attacks like SHAttered and SHAmbles on the |
| 878 | 907 | Git and Fossil Merkle trees isn't clear, but you want to have your repositories |
| 879 | -moved over to a stronger hash algorithm before someone figures out how | |
| 880 | -to make use of the weaknesses in the old one. Fossil has had this covered | |
| 881 | -for years now, so that the solution is now almost universally deployed. | |
| 908 | +moved over to a stronger hash algorithm <i>before</i> someone figures out how | |
| 909 | +to make use of the weaknesses in the old one. Fossil's solution is long | |
| 910 | +since [https://repology.org/project/fossil/versions | universally deployed]. | |
| 882 | 911 | |
| 883 | 912 | <hr/> |
| 884 | 913 | |
| 885 | 914 | <h3>Asides and Digressions</h3> |
| 886 | 915 | |
| @@ -910,16 +939,10 @@ | ||
| 910 | 939 | lightweight web server, |
| 911 | 940 | <tt>[https://sqlite.org/althttpd/|althttpd]</tt>, |
| 912 | 941 | which is configured as a front end to Fossil running in CGI mode on |
| 913 | 942 | these sites. |
| 914 | 943 | |
| 915 | - <li><p>That estimate is based on pricing at Digital Ocean in | |
| 916 | - mid-2019: Fossil will run just fine on the smallest instance they | |
| 917 | - offer, at US $5/month, but the closest match to GitLab's minimum | |
| 918 | - requirements among Digital Ocean's offerings currently costs | |
| 919 | - $40/month. | |
| 920 | - | |
| 921 | 944 | <li><p>This means you can give up waiting for Fossil to be ported to |
| 922 | 945 | the PDP-11, but we remain hopeful that someone may eventually port |
| 923 | 946 | it to [https://en.wikipedia.org/wiki/Z/OS|z/OS]. |
| 924 | 947 | |
| 925 | 948 | <li><p>"Why is there all this Tcl in and around Fossil?" you may |
| 926 | 949 |
| --- www/fossil-v-git.wiki | |
| +++ www/fossil-v-git.wiki | |
| @@ -20,12 +20,12 @@ | |
| 20 | In this document, we set all of that similarity and interoperability |
| 21 | aside and focus on the important differences between the two, especially |
| 22 | those that impact the user experience. |
| 23 | |
| 24 | Keep in mind that you are reading this on a Fossil website, and though |
| 25 | we try to be fair, the information here |
| 26 | might be biased in favor of Fossil, if only because we spend most of our |
| 27 | time using Fossil, not Git. Ask around for second opinions from |
| 28 | people who have used <em>both</em> Fossil and Git. |
| 29 | |
| 30 | If you want a more practical, less philosophical guide to moving from |
| 31 | Git to Fossil, see our [./gitusers.md | Git to Fossil Translation Guide]. |
| @@ -178,36 +178,40 @@ | |
| 178 | This policy is particularly useful when running Fossil inside a |
| 179 | restrictive container, anything from [./chroot.md | classic chroot |
| 180 | jails] to modern [https://en.wikipedia.org/wiki/OS-level_virtualization |
| 181 | | OS-level virtualization mechanisms] such as |
| 182 | [https://en.wikipedia.org/wiki/Docker_(software) | Docker]. |
| 183 | Our [./containers.md | stock container image] is under 8 MB when |
| 184 | uncompressed and running. It contains nothing but a single |
| 185 | statically-linked binary. |
| 186 | |
| 187 | If you build a dynamically linked binary instead, Fossil's on-disk size |
| 188 | drops to around 6 MB, and it's dependent only on widespread |
| 189 | platform libraries with stable ABIs such as glibc, zlib, and openssl. |
| 190 | |
| 191 | Full static linking is easier on Windows, so our precompiled Windows |
| 192 | binaries are just a ZIP archive |
| 193 | containing only "<tt>fossil.exe</tt>". There is no "<tt>setup.exe</tt>" |
| 194 | to run. |
| 195 | |
| 196 | Fossil is easy to build from sources. Just run |
| 197 | "<tt>./configure && make</tt>" on POSIX systems and |
| 198 | "<tt>nmake /f Makefile.msc</tt>" on Windows. |
| 199 | |
| 200 | Contrast a basic installation of Git, which takes up about |
| 201 | 15 MiB on Debian 10 across 230 files, not counting the contents of |
| 202 | <tt>/usr/share/doc</tt> or <tt>/usr/share/locale</tt>. If you need to |
| 203 | deploy to any platform where you cannot count on facilities like the POSIX |
| 204 | shell, Perl interpreter, and Tcl/Tk platform needed to fully use Git |
| 205 | as part of the base platform, the full footprint of a Git installation |
| 206 | extends to more like 45 MiB and thousands of files. This complicates |
| 207 | several common scenarios: Git for Windows, chrooted Git servers, |
| 208 | Docker images... |
| 209 | |
| 210 | Some say that Git more closely adheres to the Unix philosophy, |
| 211 | summarized as "many small tools, loosely joined," but we have many |
| 212 | examples of other successful Unix software that violates that principle |
| 213 | to good effect, from Apache to Python to ZFS. We can infer from that |
| @@ -216,26 +220,47 @@ | |
| 216 | matters is effectiveness and efficiency. We believe Fossil achieves |
| 217 | this. |
| 218 | |
| 219 | The above size comparisons aren't apples-to-apples anyway. We've |
| 220 | compared the size of Fossil with all of its [#features | many built-in |
| 221 | features] to a fairly minimal Git installation. You must add a lot of |
| 222 | third-party software to Git to give it a Fossil-equivalent feature set. |
| 223 | Consider [https://about.gitlab.com/|GitLab], a third-party extension to |
| 224 | Git wrapping it in many features, making it roughly Fossil-equivalent, |
| 225 | though [https://docs.gitlab.com/ee/install/requirements.html|much more |
| 226 | resource hungry] and hence more costly to run than the equivalent Fossil |
| 227 | setup. [https://hub.docker.com/r/gitlab/gitlab-ce/ | The official GitLab |
| 228 | Community Edition container] currently clocks in at 2.66 GiB! |
| 229 | |
| 230 | GitLab's requirements are easy to accept when you're dedicating |
| 231 | a local rack server or blade to it, since its minimum requirements are |
| 232 | more or less a description of the smallest |
| 233 | thing you could call a "server" these days, but when you go to host that |
| 234 | in the cloud, you can expect to pay about 8 times as much to comfortably host |
| 235 | GitLab as for Fossil.³ This difference is largely due to basic |
| 236 | technology choices: Ruby and PostgreSQL vs C and SQLite. |
| 237 | |
| 238 | The Fossil project itself is [./selfhost.wiki|hosted on a small and |
| 239 | inexpensive VPS]. A bare-bones $5/month VPS or a |
| 240 | spare Raspberry Pi is sufficient to run a full-up project |
| 241 | site, complete with tickets, wiki, chat, and forum, in addition to |
| @@ -255,33 +280,34 @@ | |
| 255 | <tt>.git</tt> folder or compressed into bespoke key/value |
| 256 | [https://git-scm.com/book/en/v2/Git-Internals-Packfiles|pack-files], |
| 257 | whereas Fossil stores its objects in a [https://www.sqlite.org/|SQLite] |
| 258 | database file which provides ACID transactions and a high-level query |
| 259 | language. |
| 260 | This difference is more than an implementation detail. It has important |
| 261 | practical consequences. |
| 262 | |
| 263 | One notable consequence is that it is difficult to find the descendants |
| 264 | of check-ins in Git. |
| 265 | One can easily locate the ancestors of a particular Git check-in |
| 266 | by following the pointers embedded in the check-in object, but it is |
| 267 | difficult to go the other direction and locate the descendants of a |
| 268 | check-in. It is so difficult, in fact, that neither native Git nor |
| 269 | GitHub provide this capability short of crawling the |
| 270 | [https://www.git-scm.com/docs/git-log|commit log]. With Fossil, |
| 271 | on the other hand, finding descendants is a simple SQL query. |
| 272 | It is common in Fossil to ask to see |
| 273 | [/timeline?df=release&y=ci|all check-ins since the last release]. |
| 274 | Git lets you see "what came before". Fossil makes it just as |
| 275 | easy to also see "what came after". |
| 276 | |
| 277 | Leaf check-ins in Git that lack a "ref" become "detached," making them |
| 278 | difficult to locate and subject to garbage collection. This |
| 279 | [https://stackoverflow.com/q/3965676 | detached head |
| 280 | state] problem has caused grief for |
| 281 | [https://www.google.com/search?q=git+detached+head+state | many |
| 282 | Git users]. With |
| 283 | Fossil, detached heads are simply impossible because we can always find |
| 284 | our way back into the Merkle tree using one or more of the relations |
| 285 | in the SQL database. |
| 286 | |
| 287 | The SQL query capabilities of Fossil make it easier to track the |
| @@ -288,34 +314,27 @@ | |
| 288 | changes for one particular file within a project. For example, |
| 289 | you can easily find |
| 290 | [/finfo/www/fossil-v-git.wiki|the complete edit history of this one document], |
| 291 | or even |
| 292 | [/finfo/www/fossil-v-git.wiki?ubg|the same history color-coded by committer], |
| 293 | Both questions are simple SQL query in Fossil, with procedural code |
| 294 | only being used to format the result for display. |
| 295 | The same result could be obtained from Git, but because the data is |
| 296 | in a key/value store, much more procedural code has to be written to |
| 297 | walk the data and compute the result. And since that is a lot more |
| 298 | work, the question is seldom asked. |
| 299 | |
| 300 | The ease of querying Fossil data using SQL means that status or |
| 301 | history information about the project under management is easier |
| 302 | to obtain. Being easier means that it is more likely to happen. |
| 303 | Fossil reports tend to be more detailed and useful. |
| 304 | Compare [/timeline?c=6df7a853ec16865b|this Fossil timeline] |
| 305 | to |
| 306 | [https://github.com/drhsqlite/fossil-mirror/commits/master?after=f720c106d297ca1f61bccb30c5c191b88a626d01+34 | |
| 307 | its closest equivalent in GitHub]. Judge for yourself: which of those |
| 308 | reports is more useful to a developer trying to understand what happened? |
| 309 | |
| 310 | The bottom line is that even though Fossil and Git are built around |
| 311 | the same low-level data structure, the use of SQL |
| 312 | to query this data makes the data more accessible in Fossil, resulting |
| 313 | in more detailed information being available to the user. This |
| 314 | improves situational awareness and makes working on the project |
| 315 | easier. |
| 316 | |
| 317 | <h3 id="portable">2.4 Portable</h3> |
| 318 | |
| 319 | Fossil is largely written in ISO C, almost purely conforming to the |
| 320 | original 1989 standard. We make very little use of |
| 321 | [https://en.wikipedia.org/wiki/C99|C99], and we do not knowingly make |
| @@ -326,11 +345,11 @@ | |
| 326 | facilities Fossil needs to do its thing. (Network sockets, file locking, |
| 327 | etc.) There are certainly well-known platforms Fossil hasn't been ported |
| 328 | to yet, but that's most likely due to lack of interest rather than |
| 329 | inherent difficulties in doing the port. We believe the most stringent |
| 330 | limit on its portability is that it assumes at least a 32-bit CPU and |
| 331 | several megs of flat-addressed memory.⁴ Fossil isn't quite as |
| 332 | [https://www.sqlite.org/custombuild.html|portable as SQLite], but it's |
| 333 | close. |
| 334 | |
| 335 | Over half of the C code in Fossil is actually an embedded copy of the |
| 336 | current version of SQLite. Much of what is Fossil-specific after you set |
| @@ -344,20 +363,20 @@ | |
| 344 | necessary]. The server-side |
| 345 | UI scripting uses a custom minimal |
| 346 | [https://en.wikipedia.org/wiki/Tcl|Tcl] dialect called |
| 347 | [./th1.md|TH1], which is |
| 348 | embedded into Fossil itself. Fossil's build system and test suite are |
| 349 | largely based on Tcl.⁵ All of this is quite portable. |
| 350 | |
| 351 | About half of Git's code is POSIX C, and about a third is POSIX shell |
| 352 | code. This is largely why the so-called "Git for Windows" distributions |
| 353 | (both [https://git-scm.com/download/win|first-party] and |
| 354 | [https://gitforwindows.org/|third-party]) are actually an |
| 355 | [https://www.msys2.org/wiki/Home/|MSYS POSIX portability environment] bundled |
| 356 | with all of the Git stuff, because it would be too painful to port Git |
| 357 | natively to Windows. Git is a foreign citizen on Windows, speaking to it |
| 358 | only through a translator.⁶ |
| 359 | |
| 360 | While Fossil does lean toward POSIX norms when given a choice — LF-only |
| 361 | line endings are treated as first-class citizens over CR+LF, for example |
| 362 | — the Windows build of Fossil is truly native. |
| 363 | |
| @@ -444,11 +463,11 @@ | |
| 444 | [https://www.git-scm.com/docs/git-request-pull|pull requests] offer |
| 445 | a low-friction path to accepting |
| 446 | [https://www.jonobacon.com/2012/07/25/building-strong-community-structural-integrity/|drive-by |
| 447 | contributions]. Fossil's closest equivalents are its unique |
| 448 | [/help/bundle|bundle] and [/help/patch|patch] features, which require higher engagement |
| 449 | than firing off a PR.⁷ This difference comes directly from the |
| 450 | initial designed purpose for each tool: the SQLite project doesn't |
| 451 | accept outside contributions from previously-unknown developers, but |
| 452 | the Linux kernel does. |
| 453 | |
| 454 | * <b>No rebasing:</b> When your local repo clone syncs changes |
| @@ -500,16 +519,16 @@ | |
| 500 | that everyone — especially the project leader — can maintain a better |
| 501 | mental picture of what is happening, leading to better situational |
| 502 | awareness. |
| 503 | |
| 504 | By contrast, "…[https://docs.github.com/en/get-started/quickstart/contributing-to-projects|forking is |
| 505 | at the core of social coding at GitHub]". As of January 2022, |
| 506 | [https://github.com/search?q=is:public|Github hosts 47 million distinct |
| 507 | software projects], most of which were created by forking a |
| 508 | previously-existing project. Since this is |
| 509 | [https://evansdata.com/reports/viewRelease.php?reportID=9 | roughly |
| 510 | twice the number of developers in the world], it beggars belief that |
| 511 | most of these forks are still under active development. The vast bulk |
| 512 | of these must be abandoned one-off efforts. This is part of the nature |
| 513 | of bazaar style development. |
| 514 | |
| 515 | You can think about this difference in terms of |
| @@ -533,18 +552,18 @@ | |
| 533 | <h4 id="scale">2.5.2 Scale</h4> |
| 534 | |
| 535 | The Linux kernel has a far bigger developer community than that of |
| 536 | SQLite: there are thousands and thousands of contributors to Linux, most |
| 537 | of whom do not know each other's names. These thousands are responsible |
| 538 | for producing roughly 89× more code than is in SQLite. (10.7 |
| 539 | [https://en.wikipedia.org/wiki/Source_lines_of_code|MLOC] vs. 0.12 MLOC |
| 540 | according to [https://dwheeler.com/sloccount/|SLOCCount].) The Linux |
| 541 | kernel and its development process were already uncommonly large back in |
| 542 | 2005 when Git was designed, specifically to support the consequences of |
| 543 | having such a large set of developers working on such a large code base. |
| 544 | |
| 545 | 95% of the code in SQLite comes from just four programmers, and 64% of |
| 546 | it is from the lead developer alone. The SQLite developers know each |
| 547 | other well and interact daily. Fossil was designed for this development |
| 548 | model. |
| 549 | |
| 550 | When choosing your DVCS, we think you should ask yourself whether the |
| @@ -564,35 +583,33 @@ | |
| 564 | |
| 565 | Both Fossil and Git store history as a directed acyclic graph (DAG) |
| 566 | of changes, but Git tends to focus more on individual branches of |
| 567 | the DAG, whereas Fossil puts more emphasis on the entire DAG. |
| 568 | |
| 569 | For example, the default behavior in Git is to only synchronize |
| 570 | a single branch, whereas with Fossil the only sync option is to |
| 571 | sync the entire DAG. Git commands, |
| 572 | GitHub, and GitLab tend to show only a single branch at |
| 573 | a time, whereas Fossil usually shows all parallel branches at |
| 574 | once. Git has commands like "rebase" that help keep all relevant |
| 575 | changes on a single branch, whereas Fossil encourages a style of |
| 576 | many concurrent branches constantly springing into existence, |
| 577 | undergoing active development in parallel for a few days or weeks, then |
| 578 | merging back into the main line and disappearing. |
| 579 | |
| 580 | This difference in emphasis arises from the different purposes of |
| 581 | the two systems. Git focuses on individual branches, because that |
| 582 | is exactly what you want for a highly-distributed bazaar-style project |
| 583 | such as Linux. Linus Torvalds does not want to see every check-in |
| 584 | by every contributor to Linux: such extreme visibility does not scale |
| 585 | well. Contrast Fossil, which was written for the cathedral-style SQLite project |
| 586 | and its handful of active committers. Seeing all |
| 587 | changes on all branches all at once helps keep the whole team |
| 588 | up-to-date with what everybody else is doing, resulting in a more |
| 589 | tightly focused and cohesive implementation. |
| 590 | |
| 591 | Parts of this section are [https://fossil-scm.org/forum/forumpost/5961e969fa|disputed] |
| 592 | by [https://github.com/olorin37|Jakub A. G.]. |
| 593 | |
| 594 | |
| 595 | <h3 id="checkouts">2.6 One vs. Many Check-outs per Repository</h3> |
| 596 | |
| 597 | Because Git commingles the repository data with the initial checkout of |
| 598 | that repository, the default mode of operation in Git is to stick to that |
| @@ -612,20 +629,28 @@ | |
| 612 | standard advice is to use a switch-in-place workflow in Fossil when |
| 613 | the disturbance from switching branches is small, and to use multiple |
| 614 | checkouts when you have long-lived working branches that are different |
| 615 | enough that switching in place is disruptive. |
| 616 | |
| 617 | While you can [./gitusers.md#worktree | use Git in the Fossil style], |
| 618 | Git's default tie between working directory and |
| 619 | repository means the standard method for working with a Git repo is to |
| 620 | have one working directory only. Most Git tutorials teach this style, so |
| 621 | it is how most people learn to use Git. Because relatively few people |
| 622 | use Git with multiple working directories per repository, there are |
| 623 | [https://duckduckgo.com/?q=git+worktree+problem | several known |
| 624 | problems] with that way of working, problems which don't happen in Fossil because of |
| 625 | the clear [./ckout-workflows.md | separation] between a Fossil repository and |
| 626 | each working directory. |
| 627 | |
| 628 | This distinction matters because switching branches inside a single working directory loses local context |
| 629 | on each switch. |
| 630 | |
| 631 | For instance, in any software project where the runnable program must be |
| @@ -658,13 +683,10 @@ | |
| 658 | |
| 659 | Plus, |
| 660 | <tt>cd</tt> is faster to type than <tt>git checkout</tt> or <tt>fossil |
| 661 | update</tt>. |
| 662 | |
| 663 | Parts of this section are [https://fossil-scm.org/forum/forumpost/5961e969fa|disputed] |
| 664 | by [https://github.com/olorin37|Jakub A. G.]. |
| 665 | |
| 666 | <h3 id="history">2.7 What you should have done vs. What you actually did</h3> |
| 667 | |
| 668 | Git puts a lot of emphasis on maintaining |
| 669 | a "clean" check-in history. Extraneous and experimental branches by |
| 670 | individual developers often never make it into the main repository. |
| @@ -822,14 +844,14 @@ | |
| 822 | concepts to keep track of in your mental model of Fossil's internal |
| 823 | operation. |
| 824 | |
| 825 | Fossil's implementation of the feature is also simpler to describe. The |
| 826 | brief online help for <tt>[/help/merge | fossil merge]</tt> is |
| 827 | currently 41 lines long, to which you want to add the 600 lines of |
| 828 | [./branching.wiki | the branching document]. The equivalent |
| 829 | documentation in Git is the aggregation of the man pages for the above |
| 830 | three commands, which is over 1000 lines, much of it mutually redundant. |
| 831 | (e.g. Git's <tt>--edit</tt> and <tt>--no-commit</tt> options get |
| 832 | described three times, each time differently.) Fossil's |
| 833 | documentation is not only more concise, it gives a nice split of brief |
| 834 | online help and full online documentation. |
| 835 | |
| @@ -852,35 +874,42 @@ | |
| 852 | This not |
| 853 | only solves the SHAttered problem, it should prevent a reoccurrence of |
| 854 | similar problems for the foreseeable future. |
| 855 | |
| 856 | Meanwhile, the Git community took until August 2018 to publish |
| 857 | [https://git-scm.com/docs/hash-function-transition/|their first plan] |
| 858 | for solving the same problem by moving to SHA-256, a variant of the |
| 859 | [https://en.wikipedia.org/wiki/SHA-2 | older SHA-2 algorithm]. As of |
| 860 | this writing in February 2020, that plan hasn't been implemented, as far |
| 861 | as this author is aware, but there is now |
| 862 | [https://lwn.net/ml/git/[email protected]/ |
| 863 | | a competing SHA-256 based plan] which requires complete repository |
| 864 | conversion from SHA-1 to SHA-256, breaking all public hashes in the |
| 865 | repo. One way to characterize such a massive upheaval in Git terms is a |
| 866 | whole-project rebase, which violates the |
| 867 | [https://www.atlassian.com/git/tutorials/merging-vs-rebasing#the-golden-rule-of-rebasing|Golden Rule of Rebasing]. |
| 868 | |
| 869 | Regardless of the eventual implementation details, we fully expect Git |
| 870 | to move off SHA-1 eventually and for the changes to take years more to |
| 871 | percolate through the community. |
| 872 | |
| 873 | Almost three years after Fossil solved this problem, the |
| 874 | [https://sha-mbles.github.io/ | SHAmbles attack] was published, further |
| 875 | weakening the case for continuing to use SHA-1. |
| 876 | |
| 877 | The practical impact of attacks like SHAttered and SHAmbles on the |
| 878 | Git and Fossil Merkle trees isn't clear, but you want to have your repositories |
| 879 | moved over to a stronger hash algorithm before someone figures out how |
| 880 | to make use of the weaknesses in the old one. Fossil has had this covered |
| 881 | for years now, so that the solution is now almost universally deployed. |
| 882 | |
| 883 | <hr/> |
| 884 | |
| 885 | <h3>Asides and Digressions</h3> |
| 886 | |
| @@ -910,16 +939,10 @@ | |
| 910 | lightweight web server, |
| 911 | <tt>[https://sqlite.org/althttpd/|althttpd]</tt>, |
| 912 | which is configured as a front end to Fossil running in CGI mode on |
| 913 | these sites. |
| 914 | |
| 915 | <li><p>That estimate is based on pricing at Digital Ocean in |
| 916 | mid-2019: Fossil will run just fine on the smallest instance they |
| 917 | offer, at US $5/month, but the closest match to GitLab's minimum |
| 918 | requirements among Digital Ocean's offerings currently costs |
| 919 | $40/month. |
| 920 | |
| 921 | <li><p>This means you can give up waiting for Fossil to be ported to |
| 922 | the PDP-11, but we remain hopeful that someone may eventually port |
| 923 | it to [https://en.wikipedia.org/wiki/Z/OS|z/OS]. |
| 924 | |
| 925 | <li><p>"Why is there all this Tcl in and around Fossil?" you may |
| 926 |
| --- www/fossil-v-git.wiki | |
| +++ www/fossil-v-git.wiki | |
| @@ -20,12 +20,12 @@ | |
| 20 | In this document, we set all of that similarity and interoperability |
| 21 | aside and focus on the important differences between the two, especially |
| 22 | those that impact the user experience. |
| 23 | |
| 24 | Keep in mind that you are reading this on a Fossil website, and though |
| 25 | we try to be fair, the information here will inevitably |
| 26 | be biased in favor of Fossil purely because we spend most of our |
| 27 | time using Fossil, not Git. Ask around for second opinions from |
| 28 | people who have used <em>both</em> Fossil and Git. |
| 29 | |
| 30 | If you want a more practical, less philosophical guide to moving from |
| 31 | Git to Fossil, see our [./gitusers.md | Git to Fossil Translation Guide]. |
| @@ -178,36 +178,40 @@ | |
| 178 | This policy is particularly useful when running Fossil inside a |
| 179 | restrictive container, anything from [./chroot.md | classic chroot |
| 180 | jails] to modern [https://en.wikipedia.org/wiki/OS-level_virtualization |
| 181 | | OS-level virtualization mechanisms] such as |
| 182 | [https://en.wikipedia.org/wiki/Docker_(software) | Docker]. |
| 183 | Our [./containers.md | stock container image] is under 11 MB when |
| 184 | uncompressed and running because it contains nothing but a single |
| 185 | statically-linked binary. |
| 186 | |
| 187 | If you build a dynamically linked binary instead, a Linux |
| 188 | x86_64 build of Fossil drops to under 5 MB on-disk, stripped. |
| 189 | It will depend only on widespread |
| 190 | platform libraries with stable ABIs such as glibc, zlib, and openssl. |
| 191 | |
| 192 | Much the same is true on Windows, where our precompiled static binaries |
| 193 | are distributed inside a ZIP archive containing "<tt>fossil.exe</tt>" |
| 194 | and not a thing else, with a size on-par that of the Linux container |
| 195 | build. There is no "<tt>setup.exe</tt>" to run; just copy it into your |
| 196 | <tt>%PATH%</tt>. |
| 197 | |
| 198 | Fossil is easy to build from sources. Just run |
| 199 | "<tt>./configure && make</tt>" on POSIX systems and |
| 200 | "<tt>nmake /f Makefile.msc</tt>" on Windows. |
| 201 | |
| 202 | Git, by contrast, takes 25 MiB on Ubuntu 26.04 across 940 files. |
| 203 | That doesn't count platform facilities like the POSIX shell and script |
| 204 | interpreters its full feature set requires. A fairer comparison to |
| 205 | Fossil's single static binary container is the Docker Hardened Image for |
| 206 | [https://hub.docker.com/hardened-images/catalog/dhi/git |Git 2.x on |
| 207 | Alpine], which presently weighs in at 36.3 megs unpacked and 607 files, |
| 208 | if you count all the <tt>busybox</tt> symlinks which would otherwise be |
| 209 | separate binaries on a more traditional Linux system. Worst of all are |
| 210 | the "Git for Windows" packages where they end up needing to ship a large |
| 211 | yet nerfed Linux-like userland to support Git's many loosely coupled |
| 212 | pieces, approaching a hundred megs and thousands of files. |
| 213 | |
| 214 | Some say that Git more closely adheres to the Unix philosophy, |
| 215 | summarized as "many small tools, loosely joined," but we have many |
| 216 | examples of other successful Unix software that violates that principle |
| 217 | to good effect, from Apache to Python to ZFS. We can infer from that |
| @@ -216,26 +220,47 @@ | |
| 220 | matters is effectiveness and efficiency. We believe Fossil achieves |
| 221 | this. |
| 222 | |
| 223 | The above size comparisons aren't apples-to-apples anyway. We've |
| 224 | compared the size of Fossil with all of its [#features | many built-in |
| 225 | features] to a relatively bare-bones Git installation. You must add a |
| 226 | lot of third-party software to Git to give it a Fossil-equivalent |
| 227 | feature set. |
| 228 | |
| 229 | Consider [https://about.gitlab.com/|GitLab], which wraps Git in enough |
| 230 | features to bring it to a rough (very rough) parity with Fossil. While |
| 231 | it is certainly ahead in some areas — automation comes to mind — it must |
| 232 | be noted that GitLab's own forums are on Discourse, not self-hosted as |
| 233 | with Fossil. You may then argue that Discourse is superior to the Fossil |
| 234 | forum feature, but this merely brings us back to another of Fossil's |
| 235 | advantages: when the posts are part of the repo, you can migrate your |
| 236 | entire project to another host merely by standing that repo back up on |
| 237 | other hardware. Choosing to assemble your project hosting from multiple |
| 238 | pieces requires each to have their own backups, their own management |
| 239 | processes, and their own migration strategies. |
| 240 | |
| 241 | Even then, these disparate services do not cooperate at the same level |
| 242 | as in Fossil, where the ability to have a forum post linking to a wiki |
| 243 | article linking to a trouble ticket linking to a commit falls out of the |
| 244 | model nearly for free. These are all internal links, mind, potentially |
| 245 | using nothing but repository artifact hashes, all backed by SQLite's |
| 246 | referential integrity. With something like GitLab, its "internal |
| 247 | references" are tacked on after the fact, not Git repo hashes at all, |
| 248 | and when it comes to external services like Discourse, history tells us |
| 249 | you're storing up tech debt which will come due at some future point in |
| 250 | the form of piles of broken links when one piece or the other needs |
| 251 | changing out. |
| 252 | |
| 253 | Furthermore, GitLab is far more resource hungry even in its |
| 254 | [https://docs.gitlab.com/omnibus/settings/memory_constrained_envs/ | |
| 255 | minimal configuration], hence more costly to run than the equivalent |
| 256 | Fossil setup. [https://hub.docker.com/r/gitlab/gitlab-ce/ | The |
| 257 | official GitLab Community Edition container] currently clocks in at |
| 258 | 3.44 GiB, independent of add-ons like Discourse. You can expect it to |
| 259 | cost around 8× as much to host it on a cloud service. Even pared down |
| 260 | to the minimum, there remain the consequences from the difference in |
| 261 | basic technology choices: Ruby and PostgreSQL vs C and SQLite. |
| 262 | |
| 263 | The Fossil project itself is [./selfhost.wiki|hosted on a small and |
| 264 | inexpensive VPS]. A bare-bones $5/month VPS or a |
| 265 | spare Raspberry Pi is sufficient to run a full-up project |
| 266 | site, complete with tickets, wiki, chat, and forum, in addition to |
| @@ -255,33 +280,34 @@ | |
| 280 | <tt>.git</tt> folder or compressed into bespoke key/value |
| 281 | [https://git-scm.com/book/en/v2/Git-Internals-Packfiles|pack-files], |
| 282 | whereas Fossil stores its objects in a [https://www.sqlite.org/|SQLite] |
| 283 | database file which provides ACID transactions and a high-level query |
| 284 | language. |
| 285 | |
| 286 | This difference is more than an implementation detail; it has important |
| 287 | practical consequences. |
| 288 | |
| 289 | One notable example is that it is difficult to find the descendants |
| 290 | of check-ins in Git. |
| 291 | One can easily locate the ancestors of a particular Git check-in |
| 292 | by following the pointers embedded in the check-in object, but |
| 293 | going the other direction is difficult enough |
| 294 | that neither native Git nor the big "forge" facilities |
| 295 | like GitHub and GitLab provide this capability short of crawling the |
| 296 | [https://www.git-scm.com/docs/git-log|commit log]. In Fossil, |
| 297 | we can find descendants using a simple SQL query, which then allows |
| 298 | us to see [/timeline?df=release&y=ci|all check-ins since the last release], |
| 299 | as but one example. |
| 300 | Git lets you see "what came before," but Fossil makes it just as |
| 301 | easy to also see "what came after." |
| 302 | |
| 303 | Leaf check-ins in Git that lack a "ref" become "detached," making them |
| 304 | difficult to locate and subject to garbage collection. This |
| 305 | [https://stackoverflow.com/q/3965676 | detached head |
| 306 | state] problem has caused grief for |
| 307 | [https://www.google.com/search?q=git+detached+head+state | |
| 308 | untold millions of Git users]. With |
| 309 | Fossil, detached heads are simply impossible because we can always find |
| 310 | our way back into the Merkle tree using one or more of the relations |
| 311 | in the SQL database. |
| 312 | |
| 313 | The SQL query capabilities of Fossil make it easier to track the |
| @@ -288,34 +314,27 @@ | |
| 314 | changes for one particular file within a project. For example, |
| 315 | you can easily find |
| 316 | [/finfo/www/fossil-v-git.wiki|the complete edit history of this one document], |
| 317 | or even |
| 318 | [/finfo/www/fossil-v-git.wiki?ubg|the same history color-coded by committer], |
| 319 | Both come down to simple SQL queries in Fossil, with procedural code |
| 320 | only being used to format the result for display. |
| 321 | The same result could be obtained from Git, but because the data is |
| 322 | in a key/value store, much more procedural code has to be written to |
| 323 | walk the data and compute the result. |
| 324 | |
| 325 | The ease of querying Fossil data using SQL means that status or |
| 326 | history information about the project under management is easier |
| 327 | to obtain, hence more likely to happen, giving its developers better |
| 328 | situational awareness. |
| 329 | Fossil reports tend to be more detailed and useful. |
| 330 | Compare [/timeline?c=6df7a853ec16865b|this Fossil timeline] |
| 331 | to |
| 332 | [https://github.com/drhsqlite/fossil-mirror/commits/master?after=f720c106d297ca1f61bccb30c5c191b88a626d01+34 | |
| 333 | its closest equivalent in the GitHub mirror]. Judge for yourself: which of those |
| 334 | reports is more useful to a developer trying to understand what happened? |
| 335 | |
| 336 | <h3 id="portable">2.4 Portable</h3> |
| 337 | |
| 338 | Fossil is largely written in ISO C, almost purely conforming to the |
| 339 | original 1989 standard. We make very little use of |
| 340 | [https://en.wikipedia.org/wiki/C99|C99], and we do not knowingly make |
| @@ -326,11 +345,11 @@ | |
| 345 | facilities Fossil needs to do its thing. (Network sockets, file locking, |
| 346 | etc.) There are certainly well-known platforms Fossil hasn't been ported |
| 347 | to yet, but that's most likely due to lack of interest rather than |
| 348 | inherent difficulties in doing the port. We believe the most stringent |
| 349 | limit on its portability is that it assumes at least a 32-bit CPU and |
| 350 | several megs of flat-addressed memory.³ Fossil isn't quite as |
| 351 | [https://www.sqlite.org/custombuild.html|portable as SQLite], but it's |
| 352 | close. |
| 353 | |
| 354 | Over half of the C code in Fossil is actually an embedded copy of the |
| 355 | current version of SQLite. Much of what is Fossil-specific after you set |
| @@ -344,20 +363,20 @@ | |
| 363 | necessary]. The server-side |
| 364 | UI scripting uses a custom minimal |
| 365 | [https://en.wikipedia.org/wiki/Tcl|Tcl] dialect called |
| 366 | [./th1.md|TH1], which is |
| 367 | embedded into Fossil itself. Fossil's build system and test suite are |
| 368 | largely based on Tcl.⁴ All of this is quite portable. |
| 369 | |
| 370 | About half of Git's code is POSIX C, and about a third is POSIX shell |
| 371 | code. This is largely why the so-called "Git for Windows" distributions |
| 372 | (both [https://git-scm.com/download/win|first-party] and |
| 373 | [https://gitforwindows.org/|third-party]) are actually an |
| 374 | [https://www.msys2.org/wiki/Home/|MSYS POSIX portability environment] bundled |
| 375 | with all of the Git stuff, because it would be too painful to port Git |
| 376 | natively to Windows. Git is a foreign citizen on Windows, speaking to it |
| 377 | only through a translator.⁵ |
| 378 | |
| 379 | While Fossil does lean toward POSIX norms when given a choice — LF-only |
| 380 | line endings are treated as first-class citizens over CR+LF, for example |
| 381 | — the Windows build of Fossil is truly native. |
| 382 | |
| @@ -444,11 +463,11 @@ | |
| 463 | [https://www.git-scm.com/docs/git-request-pull|pull requests] offer |
| 464 | a low-friction path to accepting |
| 465 | [https://www.jonobacon.com/2012/07/25/building-strong-community-structural-integrity/|drive-by |
| 466 | contributions]. Fossil's closest equivalents are its unique |
| 467 | [/help/bundle|bundle] and [/help/patch|patch] features, which require higher engagement |
| 468 | than firing off a PR.⁶ This difference comes directly from the |
| 469 | initial designed purpose for each tool: the SQLite project doesn't |
| 470 | accept outside contributions from previously-unknown developers, but |
| 471 | the Linux kernel does. |
| 472 | |
| 473 | * <b>No rebasing:</b> When your local repo clone syncs changes |
| @@ -500,16 +519,16 @@ | |
| 519 | that everyone — especially the project leader — can maintain a better |
| 520 | mental picture of what is happening, leading to better situational |
| 521 | awareness. |
| 522 | |
| 523 | By contrast, "…[https://docs.github.com/en/get-started/quickstart/contributing-to-projects|forking is |
| 524 | at the core of social coding at GitHub]". As of June 2026, |
| 525 | [https://github.com/search?q=is:public|Github hosts 324 million distinct |
| 526 | software projects], most of which were created by forking a |
| 527 | previously-existing project. Since this is |
| 528 | [https://www.griddynamics.com/blog/number-software-developers-world | |
| 529 | ~11× the number of developers in the world], it beggars belief that |
| 530 | most of these forks are still under active development. The vast bulk |
| 531 | of these must be abandoned one-off efforts. This is part of the nature |
| 532 | of bazaar style development. |
| 533 | |
| 534 | You can think about this difference in terms of |
| @@ -533,18 +552,18 @@ | |
| 552 | <h4 id="scale">2.5.2 Scale</h4> |
| 553 | |
| 554 | The Linux kernel has a far bigger developer community than that of |
| 555 | SQLite: there are thousands and thousands of contributors to Linux, most |
| 556 | of whom do not know each other's names. These thousands are responsible |
| 557 | for producing roughly 73× more code than is in SQLite. (32.0 |
| 558 | [https://en.wikipedia.org/wiki/Source_lines_of_code|MLOC] vs. 0.44 MLOC |
| 559 | according to [https://github.com/boyter/scc | scc].) The Linux |
| 560 | kernel and its development process were already uncommonly large back in |
| 561 | 2005 when Git was designed, specifically to support the consequences of |
| 562 | having such a large set of developers working on such a large code base. |
| 563 | |
| 564 | 95% of the code in SQLite comes from just six programmers, and 62% of |
| 565 | it is from the lead developer alone. The SQLite developers know each |
| 566 | other well and interact daily. Fossil was designed for this development |
| 567 | model. |
| 568 | |
| 569 | When choosing your DVCS, we think you should ask yourself whether the |
| @@ -564,35 +583,33 @@ | |
| 583 | |
| 584 | Both Fossil and Git store history as a directed acyclic graph (DAG) |
| 585 | of changes, but Git tends to focus more on individual branches of |
| 586 | the DAG, whereas Fossil puts more emphasis on the entire DAG. |
| 587 | |
| 588 | While a common usage pattern in Git is to only synchronize |
| 589 | a single branch — <tt>git pull upstream feature/branch</tt> — instead |
| 590 | of all refs, Fossil does not give you a choice; it |
| 591 | syncs the entire DAG or nothing. Git commands, |
| 592 | GitHub, and GitLab tend to show only a single branch at |
| 593 | a time, whereas Fossil usually shows all parallel branches at |
| 594 | once. Git has commands like "rebase" that help keep all relevant |
| 595 | changes on a single branch, whereas Fossil encourages a style of |
| 596 | many concurrent branches constantly springing into existence, |
| 597 | undergoing active development in parallel for a few days or weeks, then |
| 598 | merging back into the main line and disappearing. |
| 599 | |
| 600 | This difference in emphasis arises from the different purposes of |
| 601 | the two systems. Git's focus on individual branches |
| 602 | is exactly what you want for a highly-distributed bazaar-style project |
| 603 | such as Linux. Linus Torvalds does not want to see every check-in |
| 604 | by every contributor to Linux: such extreme visibility does not scale |
| 605 | well. Contrast Fossil, which was written for the cathedral-style SQLite project |
| 606 | and its handful of active committers. Seeing all |
| 607 | changes on all branches all at once helps keep the whole team |
| 608 | up-to-date with what everybody else is doing, resulting in a more |
| 609 | tightly focused and cohesive implementation. |
| 610 | |
| 611 | |
| 612 | <h3 id="checkouts">2.6 One vs. Many Check-outs per Repository</h3> |
| 613 | |
| 614 | Because Git commingles the repository data with the initial checkout of |
| 615 | that repository, the default mode of operation in Git is to stick to that |
| @@ -612,20 +629,28 @@ | |
| 629 | standard advice is to use a switch-in-place workflow in Fossil when |
| 630 | the disturbance from switching branches is small, and to use multiple |
| 631 | checkouts when you have long-lived working branches that are different |
| 632 | enough that switching in place is disruptive. |
| 633 | |
| 634 | While you can [./gitusers.md#worktree | use Git in the Fossil style] via |
| 635 | its worktree feature, tutorials continue to teach the style of having |
| 636 | one working directory only. Git can even fight you on this, as when |
| 637 | working with a forked repository; it is best to have independent clones |
| 638 | of the upstream and your fork, to allow separate "remote" lists and |
| 639 | such. This can result in two working directories but each having a |
| 640 | captive repo clone each, which isn't in the spirit of <tt>git |
| 641 | worktree</tt> at all. Yet, it beats the alternative, which then |
| 642 | highlights a gap in the model of diverging and re-converging forks. |
| 643 | Ideally, Git would let you create one of these forks as a worktree while |
| 644 | maintaining a strong separation between your fork and the upstream repo, |
| 645 | but it ends up being too much hassle to bother with. |
| 646 | |
| 647 | There are |
| 648 | [https://duckduckgo.com/?q=git+worktree+problem | several known |
| 649 | problems] with the single worktree style, ones which don't happen in |
| 650 | Fossil because of the clear [./ckout-workflows.md | separation] between |
| 651 | a Fossil repository and each working directory. |
| 652 | |
| 653 | This distinction matters because switching branches inside a single working directory loses local context |
| 654 | on each switch. |
| 655 | |
| 656 | For instance, in any software project where the runnable program must be |
| @@ -658,13 +683,10 @@ | |
| 683 | |
| 684 | Plus, |
| 685 | <tt>cd</tt> is faster to type than <tt>git checkout</tt> or <tt>fossil |
| 686 | update</tt>. |
| 687 | |
| 688 | <h3 id="history">2.7 What you should have done vs. What you actually did</h3> |
| 689 | |
| 690 | Git puts a lot of emphasis on maintaining |
| 691 | a "clean" check-in history. Extraneous and experimental branches by |
| 692 | individual developers often never make it into the main repository. |
| @@ -822,14 +844,14 @@ | |
| 844 | concepts to keep track of in your mental model of Fossil's internal |
| 845 | operation. |
| 846 | |
| 847 | Fossil's implementation of the feature is also simpler to describe. The |
| 848 | brief online help for <tt>[/help/merge | fossil merge]</tt> is |
| 849 | currently 50 lines long, to which you want to add the ~800 lines of |
| 850 | [./branching.wiki | the branching document]. The equivalent |
| 851 | documentation in Git is the aggregation of the man pages for the above |
| 852 | three commands, which is approaching 1400 lines as of this writing, much of it mutually redundant. |
| 853 | (e.g. Git's <tt>--edit</tt> and <tt>--no-commit</tt> options get |
| 854 | described three times, each time differently.) Fossil's |
| 855 | documentation is not only more concise, it gives a nice split of brief |
| 856 | online help and full online documentation. |
| 857 | |
| @@ -852,35 +874,42 @@ | |
| 874 | This not |
| 875 | only solves the SHAttered problem, it should prevent a reoccurrence of |
| 876 | similar problems for the foreseeable future. |
| 877 | |
| 878 | Meanwhile, the Git community took until August 2018 to publish |
| 879 | [https://git-scm.com/docs/hash-function-transition/ | their plan] for |
| 880 | solving the same problem by moving to SHA-256, a variant of the |
| 881 | [https://en.wikipedia.org/wiki/SHA-2 | older SHA-2 algorithm]. That is |
| 882 | now technically implemented in the sense that <tt>git init |
| 883 | --object-format=sha256</tt> exists, but note well: this is not only an |
| 884 | optional setting, Git forge support is mixed, most notably |
| 885 | [https://github.com/GitoxideLabs/gitoxide/issues/281 | lacking in |
| 886 | GitHub], plus also BitBucket and others. This is doubtless because of |
| 887 | this warning in the latest ([https://git-scm.com/docs/git-init/2.54.0 | |
| 888 | as of this writing]) <tt>git init</tt> docs: |
| 889 | |
| 890 | <blockquote>Note: At present, there is no interoperability between |
| 891 | SHA-256 repositories and SHA-1 repositories.</blockquote> |
| 892 | |
| 893 | Although we are now in the <i>tenth year</i> of this situation, there |
| 894 | remains hope that Git will manage to make the transition without taking |
| 895 | the full decade: the |
| 896 | [https://www.deployhq.com/blog/git-3-0-on-the-horizon-what-git-users-need-to-know-about-the-next-major-release |
| 897 | | latest plan] is that Git 3.0 will finally <i>(finally!)</i> switch to |
| 898 | SHA256 by default, forcing the issue. Given the track record, we are |
| 899 | taking a "show me" stance on this claim. |
| 900 | |
| 901 | Always remember, attacks only get better, never worse. |
| 902 | Almost three years after Fossil solved this problem, the |
| 903 | [https://sha-mbles.github.io/ | SHAmbles attack] was published, further |
| 904 | weakening the case for continuing to use SHA-1. |
| 905 | |
| 906 | The practical impact of attacks like SHAttered and SHAmbles on the |
| 907 | Git and Fossil Merkle trees isn't clear, but you want to have your repositories |
| 908 | moved over to a stronger hash algorithm <i>before</i> someone figures out how |
| 909 | to make use of the weaknesses in the old one. Fossil's solution is long |
| 910 | since [https://repology.org/project/fossil/versions | universally deployed]. |
| 911 | |
| 912 | <hr/> |
| 913 | |
| 914 | <h3>Asides and Digressions</h3> |
| 915 | |
| @@ -910,16 +939,10 @@ | |
| 939 | lightweight web server, |
| 940 | <tt>[https://sqlite.org/althttpd/|althttpd]</tt>, |
| 941 | which is configured as a front end to Fossil running in CGI mode on |
| 942 | these sites. |
| 943 | |
| 944 | <li><p>This means you can give up waiting for Fossil to be ported to |
| 945 | the PDP-11, but we remain hopeful that someone may eventually port |
| 946 | it to [https://en.wikipedia.org/wiki/Z/OS|z/OS]. |
| 947 | |
| 948 | <li><p>"Why is there all this Tcl in and around Fossil?" you may |
| 949 |
+6
-6
| --- www/javascript.md | ||
| +++ www/javascript.md | ||
| @@ -66,11 +66,11 @@ | ||
| 66 | 66 | Most JavaScript-based Fossil pages use less code than that. |
| 67 | 67 | |
| 68 | 68 | Atop that, Fossil sends HTTP headers to the browser that allow it |
| 69 | 69 | to perform aggressive caching so that typical page loads will skip |
| 70 | 70 | re-loading this content on subsequent loads. These features are |
| 71 | - currently optional: you must either set the new | |
| 71 | + currently optional: you must either set the | |
| 72 | 72 | [`fossil server --jsmode bundle` option][fsrv] or the corresponding |
| 73 | 73 | `jsmode` control line |
| 74 | 74 | in your [`fossil cgi`][fcgi] script when setting up your |
| 75 | 75 | [Fossil server][fshome]. That done, Fossil’s JavaScript files will |
| 76 | 76 | load almost instantly from the browser’s cache after the initial |
| @@ -100,11 +100,11 @@ | ||
| 100 | 100 | Ajax partial page updates are faster than |
| 101 | 101 | the no-JS alternative, a full HTTP POST round-trip to submit new |
| 102 | 102 | data to the remote server, retrieve an entire new HTML document, |
| 103 | 103 | and re-render the whole thing client-side. |
| 104 | 104 | |
| 105 | -3. <a id="3pjs"></a>“**Third-party JavaScript cannot be trusted.**” | |
| 105 | +3. “<a id="3pjs"></a>**Third-party JavaScript cannot be trusted.**” | |
| 106 | 106 | |
| 107 | 107 | Fossil does not use any third-party JavaScript libraries, not even |
| 108 | 108 | very common ones like jQuery. Every bit of JavaScript served by the |
| 109 | 109 | stock version of Fossil was written specifically for the Fossil |
| 110 | 110 | project and is stored [in its code repository][fsrc]. |
| @@ -113,11 +113,11 @@ | ||
| 113 | 113 | Fossil and mechanisms like [skin editing][cskin] don’t suffice for your |
| 114 | 114 | purposes, you can hack on the JavaScript in your local instance |
| 115 | 115 | directly, just as you can hack on its C, SQL, and Tcl code. Fossil |
| 116 | 116 | is free and open source software, under [a single license][2cbsd]. |
| 117 | 117 | |
| 118 | -4. <a id="snoop"></a>“**JavaScript and cookies are used to snoop on web users.**” | |
| 118 | +4. “<a id="snoop"></a>**JavaScript and cookies are used to snoop on web users.**” | |
| 119 | 119 | |
| 120 | 120 | There is no tracking or other snooping technology in Fossil other than |
| 121 | 121 | that necessary for basic security, such as IP address logging on |
| 122 | 122 | check-ins. (This is in part why we have no [comprehensive user |
| 123 | 123 | statistics](#stats)!) |
| @@ -184,11 +184,11 @@ | ||
| 184 | 184 | The no-JS case is a [minority position](#stats), so those that want |
| 185 | 185 | Fossil to have no-JS alternatives and graceful fallbacks will need |
| 186 | 186 | to get involved with the development if they want this state of |
| 187 | 187 | affairs to continue. |
| 188 | 188 | |
| 189 | -8. <a id="stats"></a>“**A large number of users run without JavaScript enabled.**” | |
| 189 | +8. “<a id="stats"></a>**A large number of users run without JavaScript enabled.**” | |
| 190 | 190 | |
| 191 | 191 | That’s not what web audience measurements say: |
| 192 | 192 | |
| 193 | 193 | * [What percentage of browsers with javascript disabled?][s1] |
| 194 | 194 | * [How many people are missing out on JavaScript enhancement?][s2] |
| @@ -207,11 +207,11 @@ | ||
| 207 | 207 | run [powerful conditional blocking plugins](#block) in their |
| 208 | 208 | browsers, rather than block JavaScript entirely. We suspect that |
| 209 | 209 | between these two forces, the number of no-JS purists among Fossil’s |
| 210 | 210 | user base is still a tiny minority. |
| 211 | 211 | |
| 212 | -9. <a id="block"></a>“**I block JavaScript entirely in my browser. That breaks Fossil.**” | |
| 212 | +9. “<a id="block"></a>**I block JavaScript entirely in my browser. That breaks Fossil.**” | |
| 213 | 213 | |
| 214 | 214 | First, see our philosophy statements above. Briefly, we intend that |
| 215 | 215 | there always be some other way to get any given result without using |
| 216 | 216 | JavaScript, developer interest willing. |
| 217 | 217 | |
| @@ -237,11 +237,11 @@ | ||
| 237 | 237 | a few of these part-timers are responsible for the bulk of the code |
| 238 | 238 | in Fossil. If you want Fossil to support such niche use cases, then |
| 239 | 239 | you will have to [get involved with its development][cg]: it’s |
| 240 | 240 | *your* uncommon itch. |
| 241 | 241 | |
| 242 | -11. <a id="compat"></a>“**Fossil’s JavaScript code isn’t compatible with my browser.**” | |
| 242 | +11. “<a id="compat"></a>**Fossil’s JavaScript code isn’t compatible with my browser.**” | |
| 243 | 243 | |
| 244 | 244 | The Fossil project’s developers aim to remain compatible with |
| 245 | 245 | the largest portions of the client-side browser base. We use only |
| 246 | 246 | standards-defined JavaScript features which are known to work in the |
| 247 | 247 | overwhelmingly vast majority of browsers going back approximately 5 |
| 248 | 248 |
| --- www/javascript.md | |
| +++ www/javascript.md | |
| @@ -66,11 +66,11 @@ | |
| 66 | Most JavaScript-based Fossil pages use less code than that. |
| 67 | |
| 68 | Atop that, Fossil sends HTTP headers to the browser that allow it |
| 69 | to perform aggressive caching so that typical page loads will skip |
| 70 | re-loading this content on subsequent loads. These features are |
| 71 | currently optional: you must either set the new |
| 72 | [`fossil server --jsmode bundle` option][fsrv] or the corresponding |
| 73 | `jsmode` control line |
| 74 | in your [`fossil cgi`][fcgi] script when setting up your |
| 75 | [Fossil server][fshome]. That done, Fossil’s JavaScript files will |
| 76 | load almost instantly from the browser’s cache after the initial |
| @@ -100,11 +100,11 @@ | |
| 100 | Ajax partial page updates are faster than |
| 101 | the no-JS alternative, a full HTTP POST round-trip to submit new |
| 102 | data to the remote server, retrieve an entire new HTML document, |
| 103 | and re-render the whole thing client-side. |
| 104 | |
| 105 | 3. <a id="3pjs"></a>“**Third-party JavaScript cannot be trusted.**” |
| 106 | |
| 107 | Fossil does not use any third-party JavaScript libraries, not even |
| 108 | very common ones like jQuery. Every bit of JavaScript served by the |
| 109 | stock version of Fossil was written specifically for the Fossil |
| 110 | project and is stored [in its code repository][fsrc]. |
| @@ -113,11 +113,11 @@ | |
| 113 | Fossil and mechanisms like [skin editing][cskin] don’t suffice for your |
| 114 | purposes, you can hack on the JavaScript in your local instance |
| 115 | directly, just as you can hack on its C, SQL, and Tcl code. Fossil |
| 116 | is free and open source software, under [a single license][2cbsd]. |
| 117 | |
| 118 | 4. <a id="snoop"></a>“**JavaScript and cookies are used to snoop on web users.**” |
| 119 | |
| 120 | There is no tracking or other snooping technology in Fossil other than |
| 121 | that necessary for basic security, such as IP address logging on |
| 122 | check-ins. (This is in part why we have no [comprehensive user |
| 123 | statistics](#stats)!) |
| @@ -184,11 +184,11 @@ | |
| 184 | The no-JS case is a [minority position](#stats), so those that want |
| 185 | Fossil to have no-JS alternatives and graceful fallbacks will need |
| 186 | to get involved with the development if they want this state of |
| 187 | affairs to continue. |
| 188 | |
| 189 | 8. <a id="stats"></a>“**A large number of users run without JavaScript enabled.**” |
| 190 | |
| 191 | That’s not what web audience measurements say: |
| 192 | |
| 193 | * [What percentage of browsers with javascript disabled?][s1] |
| 194 | * [How many people are missing out on JavaScript enhancement?][s2] |
| @@ -207,11 +207,11 @@ | |
| 207 | run [powerful conditional blocking plugins](#block) in their |
| 208 | browsers, rather than block JavaScript entirely. We suspect that |
| 209 | between these two forces, the number of no-JS purists among Fossil’s |
| 210 | user base is still a tiny minority. |
| 211 | |
| 212 | 9. <a id="block"></a>“**I block JavaScript entirely in my browser. That breaks Fossil.**” |
| 213 | |
| 214 | First, see our philosophy statements above. Briefly, we intend that |
| 215 | there always be some other way to get any given result without using |
| 216 | JavaScript, developer interest willing. |
| 217 | |
| @@ -237,11 +237,11 @@ | |
| 237 | a few of these part-timers are responsible for the bulk of the code |
| 238 | in Fossil. If you want Fossil to support such niche use cases, then |
| 239 | you will have to [get involved with its development][cg]: it’s |
| 240 | *your* uncommon itch. |
| 241 | |
| 242 | 11. <a id="compat"></a>“**Fossil’s JavaScript code isn’t compatible with my browser.**” |
| 243 | |
| 244 | The Fossil project’s developers aim to remain compatible with |
| 245 | the largest portions of the client-side browser base. We use only |
| 246 | standards-defined JavaScript features which are known to work in the |
| 247 | overwhelmingly vast majority of browsers going back approximately 5 |
| 248 |
| --- www/javascript.md | |
| +++ www/javascript.md | |
| @@ -66,11 +66,11 @@ | |
| 66 | Most JavaScript-based Fossil pages use less code than that. |
| 67 | |
| 68 | Atop that, Fossil sends HTTP headers to the browser that allow it |
| 69 | to perform aggressive caching so that typical page loads will skip |
| 70 | re-loading this content on subsequent loads. These features are |
| 71 | currently optional: you must either set the |
| 72 | [`fossil server --jsmode bundle` option][fsrv] or the corresponding |
| 73 | `jsmode` control line |
| 74 | in your [`fossil cgi`][fcgi] script when setting up your |
| 75 | [Fossil server][fshome]. That done, Fossil’s JavaScript files will |
| 76 | load almost instantly from the browser’s cache after the initial |
| @@ -100,11 +100,11 @@ | |
| 100 | Ajax partial page updates are faster than |
| 101 | the no-JS alternative, a full HTTP POST round-trip to submit new |
| 102 | data to the remote server, retrieve an entire new HTML document, |
| 103 | and re-render the whole thing client-side. |
| 104 | |
| 105 | 3. “<a id="3pjs"></a>**Third-party JavaScript cannot be trusted.**” |
| 106 | |
| 107 | Fossil does not use any third-party JavaScript libraries, not even |
| 108 | very common ones like jQuery. Every bit of JavaScript served by the |
| 109 | stock version of Fossil was written specifically for the Fossil |
| 110 | project and is stored [in its code repository][fsrc]. |
| @@ -113,11 +113,11 @@ | |
| 113 | Fossil and mechanisms like [skin editing][cskin] don’t suffice for your |
| 114 | purposes, you can hack on the JavaScript in your local instance |
| 115 | directly, just as you can hack on its C, SQL, and Tcl code. Fossil |
| 116 | is free and open source software, under [a single license][2cbsd]. |
| 117 | |
| 118 | 4. “<a id="snoop"></a>**JavaScript and cookies are used to snoop on web users.**” |
| 119 | |
| 120 | There is no tracking or other snooping technology in Fossil other than |
| 121 | that necessary for basic security, such as IP address logging on |
| 122 | check-ins. (This is in part why we have no [comprehensive user |
| 123 | statistics](#stats)!) |
| @@ -184,11 +184,11 @@ | |
| 184 | The no-JS case is a [minority position](#stats), so those that want |
| 185 | Fossil to have no-JS alternatives and graceful fallbacks will need |
| 186 | to get involved with the development if they want this state of |
| 187 | affairs to continue. |
| 188 | |
| 189 | 8. “<a id="stats"></a>**A large number of users run without JavaScript enabled.**” |
| 190 | |
| 191 | That’s not what web audience measurements say: |
| 192 | |
| 193 | * [What percentage of browsers with javascript disabled?][s1] |
| 194 | * [How many people are missing out on JavaScript enhancement?][s2] |
| @@ -207,11 +207,11 @@ | |
| 207 | run [powerful conditional blocking plugins](#block) in their |
| 208 | browsers, rather than block JavaScript entirely. We suspect that |
| 209 | between these two forces, the number of no-JS purists among Fossil’s |
| 210 | user base is still a tiny minority. |
| 211 | |
| 212 | 9. “<a id="block"></a>**I block JavaScript entirely in my browser. That breaks Fossil.**” |
| 213 | |
| 214 | First, see our philosophy statements above. Briefly, we intend that |
| 215 | there always be some other way to get any given result without using |
| 216 | JavaScript, developer interest willing. |
| 217 | |
| @@ -237,11 +237,11 @@ | |
| 237 | a few of these part-timers are responsible for the bulk of the code |
| 238 | in Fossil. If you want Fossil to support such niche use cases, then |
| 239 | you will have to [get involved with its development][cg]: it’s |
| 240 | *your* uncommon itch. |
| 241 | |
| 242 | 11. “<a id="compat"></a>**Fossil’s JavaScript code isn’t compatible with my browser.**” |
| 243 | |
| 244 | The Fossil project’s developers aim to remain compatible with |
| 245 | the largest portions of the client-side browser base. We use only |
| 246 | standards-defined JavaScript features which are known to work in the |
| 247 | overwhelmingly vast majority of browsers going back approximately 5 |
| 248 |
+3
-1
| --- www/server/any/cgi.md | ||
| +++ www/server/any/cgi.md | ||
| @@ -38,11 +38,13 @@ | ||
| 38 | 38 | (This might differ from the user the web server normally runs |
| 39 | 39 | under.) The directory holding the repository file(s) needs to be |
| 40 | 40 | writable so that SQLite can write its journal files. When using |
| 41 | 41 | another access control system, such as AppArmor or SELinux, it may |
| 42 | 42 | be necessary to explicitly permit that account to read and write |
| 43 | - the necessary files. | |
| 43 | + the necessary files. Also verify a possible _systemd_ sandboxing of | |
| 44 | + the web server service, especially the combination of _ProtectSystem_, | |
| 45 | + _ProtectHome_, and _ReadWriteDirectories_/_ReadWritePaths_. | |
| 44 | 46 | |
| 45 | 47 | * Fossil must be able to create temporary files in a |
| 46 | 48 | [directory that varies by host OS](../../env-opts.md#temp). When the |
| 47 | 49 | CGI process is operating [within a chroot](../../chroot.md), |
| 48 | 50 | ensure that this directory exists and is readable/writeable by the |
| 49 | 51 |
| --- www/server/any/cgi.md | |
| +++ www/server/any/cgi.md | |
| @@ -38,11 +38,13 @@ | |
| 38 | (This might differ from the user the web server normally runs |
| 39 | under.) The directory holding the repository file(s) needs to be |
| 40 | writable so that SQLite can write its journal files. When using |
| 41 | another access control system, such as AppArmor or SELinux, it may |
| 42 | be necessary to explicitly permit that account to read and write |
| 43 | the necessary files. |
| 44 | |
| 45 | * Fossil must be able to create temporary files in a |
| 46 | [directory that varies by host OS](../../env-opts.md#temp). When the |
| 47 | CGI process is operating [within a chroot](../../chroot.md), |
| 48 | ensure that this directory exists and is readable/writeable by the |
| 49 |
| --- www/server/any/cgi.md | |
| +++ www/server/any/cgi.md | |
| @@ -38,11 +38,13 @@ | |
| 38 | (This might differ from the user the web server normally runs |
| 39 | under.) The directory holding the repository file(s) needs to be |
| 40 | writable so that SQLite can write its journal files. When using |
| 41 | another access control system, such as AppArmor or SELinux, it may |
| 42 | be necessary to explicitly permit that account to read and write |
| 43 | the necessary files. Also verify a possible _systemd_ sandboxing of |
| 44 | the web server service, especially the combination of _ProtectSystem_, |
| 45 | _ProtectHome_, and _ReadWriteDirectories_/_ReadWritePaths_. |
| 46 | |
| 47 | * Fossil must be able to create temporary files in a |
| 48 | [directory that varies by host OS](../../env-opts.md#temp). When the |
| 49 | CGI process is operating [within a chroot](../../chroot.md), |
| 50 | ensure that this directory exists and is readable/writeable by the |
| 51 |
+3
-3
| --- www/sync.wiki | ||
| +++ www/sync.wiki | ||
| @@ -242,15 +242,15 @@ | ||
| 242 | 242 | |
| 243 | 243 | As of version 2.27, Fossil supports transfering of the login card |
| 244 | 244 | externally to the request payload via a Cookie HTTP header: |
| 245 | 245 | |
| 246 | 246 | <verbatim> |
| 247 | - Cookie: x-f-x-l=... | |
| 247 | + Cookie: x-f-l-c=... | |
| 248 | 248 | </verbatim> |
| 249 | 249 | |
| 250 | -Where "..." is the URL-encoded login cookie. <code>x-f-x-l</code> is | |
| 251 | -short for X-Fossil-Xfer-Login. | |
| 250 | +Where "..." is the URL-encoded login cookie. <code>x-f-l-c</code> is | |
| 251 | +short for X-Fossil-Login-Cookie. | |
| 252 | 252 | |
| 253 | 253 | |
| 254 | 254 | <h3 id="file">3.3 File Cards</h3> |
| 255 | 255 | |
| 256 | 256 | Artifacts are transferred using either "file" cards, or "cfile" |
| 257 | 257 |
| --- www/sync.wiki | |
| +++ www/sync.wiki | |
| @@ -242,15 +242,15 @@ | |
| 242 | |
| 243 | As of version 2.27, Fossil supports transfering of the login card |
| 244 | externally to the request payload via a Cookie HTTP header: |
| 245 | |
| 246 | <verbatim> |
| 247 | Cookie: x-f-x-l=... |
| 248 | </verbatim> |
| 249 | |
| 250 | Where "..." is the URL-encoded login cookie. <code>x-f-x-l</code> is |
| 251 | short for X-Fossil-Xfer-Login. |
| 252 | |
| 253 | |
| 254 | <h3 id="file">3.3 File Cards</h3> |
| 255 | |
| 256 | Artifacts are transferred using either "file" cards, or "cfile" |
| 257 |
| --- www/sync.wiki | |
| +++ www/sync.wiki | |
| @@ -242,15 +242,15 @@ | |
| 242 | |
| 243 | As of version 2.27, Fossil supports transfering of the login card |
| 244 | externally to the request payload via a Cookie HTTP header: |
| 245 | |
| 246 | <verbatim> |
| 247 | Cookie: x-f-l-c=... |
| 248 | </verbatim> |
| 249 | |
| 250 | Where "..." is the URL-encoded login cookie. <code>x-f-l-c</code> is |
| 251 | short for X-Fossil-Login-Cookie. |
| 252 | |
| 253 | |
| 254 | <h3 id="file">3.3 File Cards</h3> |
| 255 | |
| 256 | Artifacts are transferred using either "file" cards, or "cfile" |
| 257 |