Fossil

Diff
Login

Diff

Differences From Artifact [5f3ee02255]:

To Artifact [af84f115c8]:


1124
1125
1126
1127
1128
1129
1130




















































1131
1132
1133
1134
1135
1136
1137
1138
1139
1140

1141
1142
1143
1144
1145
1146
1147







1148


1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163

1164
1165

1166
1167
1168
1169
1170
1171
1172
  image_url_var("logo");
  image_url_var("background");
  Th_Render(blob_str(&css));

  /* Tell CGI that the content returned by this page is considered cacheable */
  g.isConst = 1;
}





















































/*
** WEBPAGE: builtin
** URL:  builtin/FILENAME
**
** Return the built-in text given by FILENAME.  This is used internally 
** by many Fossil web pages to load built-in javascript files.
**
** 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 page_builtin_text(void){
  Blob out;
  const char *zName = P("name");
  const char *zTxt = 0;
  const char *zId = P("id");
  int nId;







  if( zName ) zTxt = builtin_text(zName);


  if( zTxt==0 ){
    cgi_set_status(404, "Not Found");
    @ File "%h(zName)" not found
    return;
  }
  if( sqlite3_strglob("*.js", zName)==0 ){
    cgi_set_content_type("application/javascript");
  }else{
    cgi_set_content_type("text/plain");
  }
  if( zId && (nId = (int)strlen(zId))>=8 && strncmp(zId,MANIFEST_UUID,nId)==0 ){
    g.isConst = 1;
  }else{
    etag_check(0,0);
  }

  blob_init(&out, zTxt, -1);
  cgi_set_content(&out);

}

/*
** All possible capabilities
*/
static const char allCap[] = 
  "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKL";







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








|
|
>





|

>
>
>
>
>
>
>
|
>
>















>
|
|
>







1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
  image_url_var("logo");
  image_url_var("background");
  Th_Render(blob_str(&css));

  /* Tell CGI that the content returned by this page is considered cacheable */
  g.isConst = 1;
}

/*
** Maps a "bundle" name to a callback which emits the text of that
** bundle. For use in consolidating scripts for certain pages into a
** single cacheable request.
*/
typedef struct {
  const char * zName; /* Name of the bundle (maps to /builtin/:NAME) */
  void (*xEmit)(void); /* Emits amalgamated text output for this
                          bundle */
} BundleEmitter;
/*
** Map each required bundle here...
*/
static const BundleEmitter BundleEmitters[] = {
/* Keep these sorted for bsearch() */
{"fileedit.js", fileedit_emit_js_bundle},
{"forum.js", forum_emit_js_bundle},
{"wikiedit.js", wikiedit_emit_js_bundle}
};

/*
** Comparison function for bsearch() for searching a BundleEmitter
** list for a matching name.
*/
static int cmp_builtin_bundle_name(const void *a, const void *b){
  const BundleEmitter * rA = (const BundleEmitter*)a;
  const BundleEmitter * rB = (const BundleEmitter*)b;
  return fossil_strcmp(rA->zName, rB->zName);
}

/*
** Internal helper for /builtin/FILENAME for dispatching "bundles"
** of amalgamated text (primarily JS) code.
**
** Returns true if it finds a bundle matcing the given name, else
** false. On success it outputs the amalgamated bundle without any
** sort of wrapper, e.g. SCRIPT tag
*/
static int page_builtin_text_bundle(const char * zFilename){
  const BundleEmitter * pBH;
  BundleEmitter needle = {zFilename, 0};

  pBH = (const BundleEmitter *)bsearch(&needle, BundleEmitters,
                                       count(BundleEmitters),
                                       sizeof BundleEmitters[0],
                                       cmp_builtin_bundle_name);
  if(pBH!=0){
    pBH->xEmit();
  }
  return pBH!=0;
}

/*
** WEBPAGE: builtin
** URL:  builtin/FILENAME
**
** Return the built-in text given by FILENAME.  This is used internally 
** by many Fossil web pages to load built-in javascript files.
**
** If the id= or cache= query parameter is present, then Fossil
** assumes that the result is immutable and sets a very large cache
** retention time (1 year).
*/
void page_builtin_text(void){
  Blob out;
  const char *zName = P("name");
  const char *zTxt = 0;
  const char *zId = PD("id",P("cache"));
  int nId;
  int isBundle = 0;

  if( zName ){
    if(':'==zName[0]){
      isBundle = 1;
      zTxt = page_builtin_text_bundle(zName+1) ? "" : NULL;
    }else{
      zTxt = builtin_text(zName);
    }
  }
  if( zTxt==0 ){
    cgi_set_status(404, "Not Found");
    @ File "%h(zName)" not found
    return;
  }
  if( sqlite3_strglob("*.js", zName)==0 ){
    cgi_set_content_type("application/javascript");
  }else{
    cgi_set_content_type("text/plain");
  }
  if( zId && (nId = (int)strlen(zId))>=8 && strncmp(zId,MANIFEST_UUID,nId)==0 ){
    g.isConst = 1;
  }else{
    etag_check(0,0);
  }
  if(isBundle==0){
    blob_init(&out, zTxt, -1);
    cgi_set_content(&out);
  }
}

/*
** All possible capabilities
*/
static const char allCap[] = 
  "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKL";
1638
1639
1640
1641
1642
1643
1644



1645



1646
1647
1648
1649
1650
1651
1652
** If it is false, a script tag loading it via
** src=builtin/{{zName}}?cache=XYZ is emitted, where XYZ is a
** build-time-dependent cache-buster value.
*/
void style_emit_script_builtin(int asInline, int addScripTag,
                               char const * zName){
  if(asInline){



    CX("%s", builtin_text(zName));



  }else{
    char * zFullName = mprintf("builtin/%s",zName);
    const char * zHash = fossil_exe_id();
    CX("<script src='%R/%T?cache=%.8s'></script>\n",
       zFullName, zHash);
    fossil_free(zFullName);
  }







>
>
>

>
>
>







1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
** If it is false, a script tag loading it via
** src=builtin/{{zName}}?cache=XYZ is emitted, where XYZ is a
** build-time-dependent cache-buster value.
*/
void style_emit_script_builtin(int asInline, int addScripTag,
                               char const * zName){
  if(asInline){
    if(addScripTag){
      style_emit_script_tag(0,0);
    }
    CX("%s", builtin_text(zName));
    if(addScripTag){
      style_emit_script_tag(1,0);
    }
  }else{
    char * zFullName = mprintf("builtin/%s",zName);
    const char * zHash = fossil_exe_id();
    CX("<script src='%R/%T?cache=%.8s'></script>\n",
       zFullName, zHash);
    fossil_free(zFullName);
  }