/// Fetches contents of this file. String File::GetContents() { /// Contains the LastModified time when we last accessed this file. editTimeWhenReadLast; assert(LastModified(editTimeWhenReadLast)); return GetContents(path); }
/// Fetches contents from file in form of lines. (\r\n removed and used as tokenizers) List<String> File::GetLines() { String contents = GetContents(path); assert(LastModified(editTimeWhenReadLast)); List<String> lines = contents.GetLines(); return lines; }
//Construct Response Header char *constructHeader(char* FilePath) { FILE *fp; fp=fopen(FilePath+1,"r"); if(fp==NULL) return NULL; else { char *header =malloc(sizeof(char)*BUF_SIZE); memset(header,0,sizeof(char)*BUF_SIZE); strcpy(header,"HTTP/1.1 200 OK\nConnection: close\nDate: "); char *time = CurrentTime(); strcat(header,time); strcat(header,"Last-Modified: "); char *modtime = LastModified(FilePath); strcat(header,modtime); strcat(header,"Content-Length: "); int leng = Length(FilePath); char len[32]; sprintf(len,"%d",leng); strcat(header,len); strcat(header,"\nContent-Type: "); char *type = FileType(FilePath); strcat(header,type); strcat(header,"\r\n\r\n"); return header; free(header); } fclose(fp); }
/// Returns true if the last write time has changed compared to the last time that we extracted contents from this file. bool File::HasChanged() { Time lastEdit; assert(LastModified(lastEdit)); if (lastEdit == editTimeWhenReadLast) return false; return true; }