Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
| Comment: | Move the /builtin webpage from style.c over to builtin.c. Add the new "m=" query parameter enabling it to return multiple JS files in a single request. |
|---|---|
| Downloads: | Tarball | ZIP archive |
| Timelines: | family | ancestors | descendants | both | trunk |
| Files: | files | file ages | folders |
| SHA3-256: |
956d2f8db9534902a49eb3f29ea6e2e4 |
| User & Date: | drh 2020-07-31 16:06:13.113 |
Context
|
2020-07-31
| ||
| 21:51 | Permit the 'favicon.ico' image to be customized. ... (check-in: 37262b8387 user: mistachkin tags: trunk) | |
| 16:58 | Add routines for standardized loading of javascript resources. ... (check-in: 01d96c6b45 user: drh tags: refactor-js-handling) | |
| 16:06 | Move the /builtin webpage from style.c over to builtin.c. Add the new "m=" query parameter enabling it to return multiple JS files in a single request. ... (check-in: 956d2f8db9 user: drh tags: trunk) | |
| 14:20 | Always regenerate the VERSION.h file, and hence change the FOSSIL_BUILD_HASH value, every time "make" is run. ... (check-in: 01c03ca16a user: drh tags: trunk) | |
Changes
Changes to src/builtin.c.
| ︙ | ︙ | |||
26 27 28 29 30 31 32 | ** The resources provided by this file are packaged by the "mkbuiltin.c" ** utility program during the built process and stored in the ** builtin_data.h file. Include that information here: */ #include "builtin_data.h" /* | | > > | | > > | | | > > > > > > > > > | | > | | | > > | | 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
** The resources provided by this file are packaged by the "mkbuiltin.c"
** utility program during the built process and stored in the
** builtin_data.h file. Include that information here:
*/
#include "builtin_data.h"
/*
** Return the index in the aBuiltinFiles[] array for the file
** whose name is zFilename. Or return -1 if the file is not
** found.
*/
static int builtin_file_index(const char *zFilename){
int lwr, upr, i, c;
lwr = 0;
upr = count(aBuiltinFiles) - 1;
while( upr>=lwr ){
i = (upr+lwr)/2;
c = strcmp(aBuiltinFiles[i].zName,zFilename);
if( c<0 ){
lwr = i+1;
}else if( c>0 ){
upr = i-1;
}else{
return i;
}
}
return -1;
}
/*
** Return a pointer to built-in content
*/
const unsigned char *builtin_file(const char *zFilename, int *piSize){
int i = builtin_file_index(zFilename);
if( i>=0 ){
if( piSize ) *piSize = aBuiltinFiles[i].nByte;
return aBuiltinFiles[i].pData;
}else{
if( piSize ) *piSize = 0;
return 0;
}
}
const char *builtin_text(const char *zFilename){
return (char*)builtin_file(zFilename, 0);
}
/*
** COMMAND: test-builtin-list
**
** If -verbose is used, it outputs a line at the end
** with the total item count and size.
**
** List the names and sizes of all built-in resources.
*/
void test_builtin_list(void){
int i, size = 0;;
for(i=0; i<count(aBuiltinFiles); i++){
const int n = aBuiltinFiles[i].nByte;
fossil_print("%3d. %-45s %6d\n", i+1, aBuiltinFiles[i].zName,n);
size += n;
}
if(find_option("verbose","v",0)!=0){
fossil_print("%d entries totaling %d bytes\n", i, size);
}
}
/*
** WEBPAGE: test-builtin-files
**
** Show all built-in text files.
*/
void test_builtin_list_page(void){
int i;
style_header("Built-in Text Files");
@ <ol>
for(i=0; i<count(aBuiltinFiles); i++){
const char *z = aBuiltinFiles[i].zName;
char *zUrl = href("%R/builtin?name=%T&id=%.8s&mimetype=text/plain",
z,fossil_exe_id());
@ <li>%z(zUrl)%h(z)</a>
}
@ </ol>
style_footer();
}
/*
** COMMAND: test-builtin-get
**
** Usage: %fossil test-builtin-get NAME ?OUTPUT-FILE?
|
| ︙ | ︙ | |||
108 109 110 111 112 113 114 |
if( pData==0 ){
fossil_fatal("no such built-in file: [%s]", g.argv[2]);
}
blob_init(&x, (const char*)pData, nByte);
blob_write_to_file(&x, g.argc==4 ? g.argv[3] : "-");
blob_reset(&x);
}
| > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 |
if( pData==0 ){
fossil_fatal("no such built-in file: [%s]", g.argv[2]);
}
blob_init(&x, (const char*)pData, nByte);
blob_write_to_file(&x, g.argc==4 ? g.argv[3] : "-");
blob_reset(&x);
}
/*
** Input zList is a list of numeric identifiers for files in
** aBuiltinFiles[]. Return the concatenation of all of those
** files using mimetype zType, or as application/javascript if
** zType is 0.
*/
static void builtin_deliver_multiple_js_files(
const char *zList, /* List of numeric identifiers */
const char *zType /* Override mimetype */
){
Blob *pOut;
if( zType==0 ) zType = "application/javascript";
cgi_set_content_type(zType);
pOut = cgi_output_blob();
while( zList[0] ){
int i = atoi(zList);
if( i>0 && i<=count(aBuiltinFiles) ){
blob_append(pOut, (const char*)aBuiltinFiles[i-1].pData,
aBuiltinFiles[i-1].nByte);
}
while( fossil_isdigit(zList[0]) ) zList++;
if( zList[0]==',' ) zList++;
}
return;
}
/*
** WEBPAGE: builtin
**
** Return one of many built-in content files. Query parameters:
**
** name=FILENAME Return the single file whose name is FILENAME.
** mimetype=TYPE Override the mimetype in the returned file to
** be TYPE. If this query parameter is omitted
** (the usual case) then the mimetype is inferred
** from the suffix on FILENAME
** m=IDLIST IDLIST is a comma-separated list of integers
** that specify multiple javascript files to be
** concatenated and returned all at once.
** id=UNIQUEID Version number of the "builtin" files. Used
** for cache control only.
**
** At least one of the name= or m= query parameters must be present.
**
** If the id= query parameter is present, then Fossil assumes that the
** result is immutable and sets a very large cache retention time (1 year).
*/
void builtin_webpage(void){
Blob out;
const char *zName = P("name");
const char *zTxt = 0;
const char *zId = P("id");
const char *zType = P("mimetype");
int nId;
if( zName ) zTxt = builtin_text(zName);
if( zTxt==0 ){
const char *zM = P("m");
if( zM ){
builtin_deliver_multiple_js_files(zM, zType);
return;
}
cgi_set_status(404, "Not Found");
@ File "%h(zName)" not found
return;
}
if( zType==0 ){
if( sqlite3_strglob("*.js", zName)==0 ){
zType = "application/javascript";
}else{
zType = mimetype_from_name(zName);
}
}
cgi_set_content_type(zType);
if( zId
&& (nId = (int)strlen(zId))>=8
&& strncmp(zId,fossil_exe_id(),nId)==0
){
g.isConst = 1;
}else{
etag_check(0,0);
}
blob_init(&out, zTxt, -1);
cgi_set_content(&out);
}
|
Changes to src/doc.c.
| ︙ | ︙ | |||
145 146 147 148 149 150 151 |
{ "ips", 3, "application/x-ipscript" },
{ "ipx", 3, "application/x-ipix" },
{ "jad", 3, "text/vnd.sun.j2me.app-descriptor" },
{ "jar", 3, "application/java-archive" },
{ "jpe", 3, "image/jpeg" },
{ "jpeg", 4, "image/jpeg" },
{ "jpg", 3, "image/jpeg" },
| | | 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 |
{ "ips", 3, "application/x-ipscript" },
{ "ipx", 3, "application/x-ipix" },
{ "jad", 3, "text/vnd.sun.j2me.app-descriptor" },
{ "jar", 3, "application/java-archive" },
{ "jpe", 3, "image/jpeg" },
{ "jpeg", 4, "image/jpeg" },
{ "jpg", 3, "image/jpeg" },
{ "js", 2, "application/javascript" },
{ "kar", 3, "audio/midi" },
{ "latex", 5, "application/x-latex" },
{ "lha", 3, "application/octet-stream" },
{ "lsp", 3, "application/x-lisp" },
{ "lzh", 3, "application/octet-stream" },
{ "m", 1, "text/plain" },
{ "m3u", 3, "audio/x-mpegurl" },
|
| ︙ | ︙ |
Changes to src/style.c.
| ︙ | ︙ | |||
1125 1126 1127 1128 1129 1130 1131 |
image_url_var("background");
Th_Render(blob_str(&css));
/* Tell CGI that the content returned by this page is considered cacheable */
g.isConst = 1;
}
| < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < | 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 |
image_url_var("background");
Th_Render(blob_str(&css));
/* Tell CGI that the content returned by this page is considered cacheable */
g.isConst = 1;
}
/*
** All possible capabilities
*/
static const char allCap[] =
"abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKL";
/*
|
| ︙ | ︙ |