Diff
Not logged in

Differences From Artifact [17e711cb39]:

To Artifact [d87a251ec5]:


908
909
910
911
912
913
914
915
916


917
918
919
920
921

922
923

924
925
926
927
928
929
930
908
909
910
911
912
913
914


915
916
917
918
919
920
921
922
923

924
925
926
927
928
929
930
931







-
-
+
+





+

-
+







** form:  "href='$ROOT/" or "action='$ROOT" has the $ROOT name expanded
** to the top-level of the repository.
*/
void doc_page(void){
  const char *zName = 0;            /* Argument to the /doc page */
  const char *zOrigName = "?";      /* Original document name */
  const char *zMime;                /* Document MIME type */
  char *zCheckin = "tip";           /* The check-in holding the document */
  char *zPathSuffix = "";           /* Text to append to g.zPath */
  const char *zCheckin = "tip";     /* The check-in holding the document */
  const char *zPathSuffix = "";     /* Text to append to g.zPath */
  int vid = 0;                      /* Artifact of check-in */
  int rid = 0;                      /* Artifact of file */
  int i;                            /* Loop counter */
  Blob filebody;                    /* Content of the documentation file */
  Blob title;                       /* Document title */
  Blob filehash = empty_blob;       /* Hashsum of the document's source */
  int nMiss = (-1);                 /* Failed attempts to find the document */
  int isUV = g.zPath[0]=='u';       /* True for /uv.  False for /doc */
  const int isUV = g.zPath[0]=='u'; /* True for /uv.  False for /doc */
  const char *zDfltTitle;
  static const char *const azSuffix[] = {
     "index.html", "index.wiki", "index.md"
#ifdef FOSSIL_ENABLE_TH1_DOCS
      , "index.th1"
#endif
  };
984
985
986
987
988
989
990
991

992
993
994
995


996

997
998
999
1000


1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016



1017
1018
1019
1020
1021



1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035





1036







1037
1038
1039
1040
1041
1042
1043
985
986
987
988
989
990
991

992
993
994
995
996
997
998

999
1000
1001
1002

1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065







-
+




+
+
-
+



-
+
+
















+
+
+





+
+
+














+
+
+
+
+

+
+
+
+
+
+
+







      }else{
        goto doc_not_found;
      }
    }
    if( isUV ){
      if( db_table_exists("repository","unversioned") ){
        rid = unversioned_content(zName, &filebody);
        if( rid==1 ){
        if( rid==1 ){ /* found by name */
          Stmt q;
          db_prepare(&q, "SELECT hash, mtime FROM unversioned"
                         " WHERE name=%Q", zName);
          if( db_step(&q)==SQLITE_ROW ){
            const char* hash = db_column_text(&q,0);
            blob_set_dynamic( &filehash, fossil_strdup( hash ));
            etag_check(ETAG_HASH, db_column_text(&q,0));
            etag_check(ETAG_HASH,hash);
            etag_last_modified(db_column_int64(&q,1));
          }
          db_finalize(&q);
        }else if( rid==2 ){
        }else if( rid==2 ){ /* found by hash */
          blob_set_dynamic( &filehash, fossil_strdup( zName ));
          zName = db_text(zName,
             "SELECT name FROM unversioned WHERE hash=%Q", zName);
          g.isConst = 1;
        }
        zDfltTitle = zName;
      }
    }else if( fossil_strcmp(zCheckin,"ckout")==0
           || fossil_strcmp(zCheckin,g.zCkoutAlias)==0
    ){
      /* Read from the local checkout */
      char *zFullpath;
      db_must_be_within_tree();
      zFullpath = mprintf("%s/%s", g.zLocalRoot, zName);
      if( file_isfile(zFullpath, RepoFILE)
       && blob_read_from_file(&filebody, zFullpath, RepoFILE)>0 ){
        rid = 1;  /* Fake RID just to get the loop to end */
        if(filebody.nUsed <= 256*1024){/* don't hash big files */
          hname_hash( &filebody, 0, &filehash );
        }
      }
      fossil_free(zFullpath);
    }else{
      vid = symbolic_name_to_rid(zCheckin, "ci");
      rid = vid>0 ? doc_load_content(vid, zName, &filebody) : 0;
      if( rid ){
        blob_set_dynamic( &filehash, rid_to_uuid(rid) );
      }
    }
  }
  g.zPath = mprintf("%s/%s", g.zPath, zPathSuffix);
  if( rid==0 ) goto doc_not_found;
  blob_to_utf8_no_bom(&filebody, 0);

  /* The file is now contained in the filebody blob.  Deliver the
  ** file to the user
  */
  zMime = nMiss==0 ? P("mimetype") : 0;
  if( zMime==0 ){
    zMime = mimetype_from_name(zName);
  }
  Th_Store("doc_name", zName);
  if( !blob_is_reset(&filehash) ){
    Th_Store(  "artifact_hashsum", blob_str(&filehash));
    Th_Store( isUV ? "uv_hashsum" : "doc_hashsum", blob_str(&filehash));
    blob_reset( &filehash );
  }
  if( vid ){
    /* FIXME: the following two Th1 variables seem misleading because
    **   1) variables' names imply a document while their
    **      values correspond to a check-in that is being served,
    **   2) truncation and mangling of `uuid` seems very unhelpful,
    **   3) the date's meaning seems ambiguous
    **      (expecially if check-in has been amended)
    */
    Th_Store("doc_version", db_text(0, "SELECT '[' || substr(uuid,1,10) || ']'"
                                       "  FROM blob WHERE rid=%d", vid));
    Th_Store("doc_date", db_text(0, "SELECT datetime(mtime) FROM event"
                                    " WHERE objid=%d AND type='ci'", vid));
  }
  document_render(&filebody, zMime, zDfltTitle, zName);
  if( nMiss>=count(azSuffix) ) cgi_set_status(404, "Not Found");