void rtplatform_translate_fstat (PSMBFSTAT fstat, void * rtp_dirobj) { RTP_DATE adate = {0,0,0,0,0,0,0,0,0}; RTP_DATE wdate = {0,0,0,0,0,0,0,0,0}; RTP_DATE cdate = {0,0,0,0,0,0,0,0,0}; RTP_DATE hdate = {0,0,0,0,0,0,0,0,0}; TIME atime = {0,0}; TIME wtime = {0,0}; TIME ctime = {0,0}; TIME htime = {0,0}; rtp_file_get_time(rtp_dirobj, &adate, &wdate, &cdate, &hdate); if (adate.year != 0) atime = rtsmb_util_time_rtp_date_to_ms(adate); if (wdate.year != 0) wtime = rtsmb_util_time_rtp_date_to_ms(wdate); if (cdate.year != 0) ctime = rtsmb_util_time_rtp_date_to_ms(cdate); if (hdate.year != 0) htime = rtsmb_util_time_rtp_date_to_ms(hdate); rtp_file_get_size(rtp_dirobj, &fstat->f_size); /* file size, in bytes */ fstat->f_atime64 = atime; fstat->f_ctime64 = ctime; fstat->f_wtime64 = wtime; fstat->f_htime64 = htime; rtp_file_get_attrib(rtp_dirobj, &fstat->f_attributes); }
void rtplatform_translate_dstat (PSMBDSTAT dstat, void * rtp_dirobj) { RTP_DATE adate = {0,0,0,0,0,0,0,0,0}; RTP_DATE wdate = {0,0,0,0,0,0,0,0,0}; RTP_DATE cdate = {0,0,0,0,0,0,0,0,0}; RTP_DATE hdate = {0,0,0,0,0,0,0,0,0}; TIME atime = {0,0}; TIME wtime = {0,0}; TIME ctime = {0,0}; TIME htime = {0,0}; dstat->fs_api = prtsmb_filesys; rtp_file_get_attrib(rtp_dirobj, &dstat->fattributes); rtp_file_get_time(rtp_dirobj, &adate, &wdate, &cdate, &hdate ); if (adate.year != 0) atime = rtsmb_util_time_rtp_date_to_ms(adate); if (wdate.year != 0) wtime = rtsmb_util_time_rtp_date_to_ms(wdate); if (cdate.year != 0) ctime = rtsmb_util_time_rtp_date_to_ms(cdate); if (hdate.year != 0) htime = rtsmb_util_time_rtp_date_to_ms(hdate); dstat->fctime64.low_time = ctime.low_time; dstat->fctime64.high_time = ctime.high_time; dstat->fwtime64.low_time = wtime.low_time; dstat->fwtime64.high_time = wtime.high_time; dstat->fatime64.low_time = atime.low_time; dstat->fatime64.high_time = atime.high_time; dstat->fhtime64.low_time = htime.low_time; dstat->fhtime64.high_time = htime.high_time; rtp_file_get_size(rtp_dirobj, &dstat->fsize); dstat->rtp_dirobj = rtp_dirobj; }
/*---------------------------------------------------------------------------*/ static int __HTTP_ServerHandleRequest (HTTPServerRequestContext *ctx, HTTPSession *session, HTTPRequest *request, RTP_NET_ADDR *clientAddr, HTTPVirtualFileInfo *vfile) { HTTP_CHAR fsPath[HTTP_SERVER_PATH_LEN]; HTTPServerContext *server = ctx->server; switch (request->methodType) { case HTTP_METHOD_GET: { HTTPResponse response; RTP_FILE fd; HTTP_INT32 bytesRead, bufferSize = 1024; HTTP_INT32 bytesleft=0; HTTP_UINT8 buffer[1024]; FileContentType contentType; unsigned chunked = 0; unsigned found = 0; const HTTP_UINT8 *pdata; if (vfile) { pdata=vfile->data; bytesleft = vfile->size; } if (vfile) { HTTP_ServerReadHeaders( ctx, session, _HTTP_VirtualFileProcessHeader, 0, buffer, bufferSize ); found = 1; } else { _HTTP_ServerReadHeaders(ctx, session, 0, 0, buffer, bufferSize); _HTTP_ConstructLocalPath(server, fsPath, (HTTP_CHAR *) request->target, HTTP_SERVER_PATH_LEN); if (rtp_file_open(&fd, fsPath, RTP_FILE_O_BINARY|RTP_FILE_O_RDONLY, RTP_FILE_S_IREAD) < 0) { if ((server->defaultFile) && (server->defaultFile[0]) && (fsPath[0]=='\0'||(fsPath[rtp_strlen(fsPath)-1] == '\\') || (fsPath[rtp_strlen(fsPath)-1] == '/'))) { if ((HTTP_SERVER_PATH_LEN - rtp_strlen(server->defaultFile)) > rtp_strlen(server->defaultFile)) { rtp_strcat(fsPath, server->defaultFile); if (rtp_file_open(&fd, fsPath, RTP_FILE_O_BINARY|RTP_FILE_O_RDONLY, RTP_FILE_S_IREAD) >= 0) { found = 1; } } } } else found = 1; } if (!found) { _HTTP_ServerSendError(ctx, session, 404, "Not Found"); return (0); } _HTTP_ServerInitResponse(ctx, session, &response, 200, "OK"); _HTTP_ServerSetDefaultHeaders(ctx, &response); if (vfile) { HTTP_SetResponseHeaderStr(&response, "Content-Type", vfile->contentType); if (vfile->contentEncoding) { HTTP_SetResponseHeaderStr(&response, "Content-Encoding", vfile->contentEncoding); } HTTP_SetResponseHeaderTime(&response, "Last-Modified", &vfile->creationTime); } else { contentType = GetFileTypeByExtension(fsPath); if (contentType != FILE_TYPE_UNKNOWN) { HTTP_SetResponseHeaderStr(&response, "Content-Type", FileContentTypeToStr(contentType)); } } if (ctx->keepAlive) { if (request->httpMajorVersion > 1 || (request->httpMajorVersion == 1 && request->httpMinorVersion >= 1)) { HTTP_SetResponseHeaderStr(&response, "Transfer-Encoding", "chunked"); chunked = 1; } else { void* dirobj; unsigned long fileSize; if (vfile) { fileSize = vfile->size; } else { if (rtp_file_gfirst(&dirobj, fsPath) < 0) { _HTTP_ServerSendError(ctx, session, 500, "Internal Server Error"); HTTP_FreeResponse(&response); rtp_file_close(fd); return (-1); } if (rtp_file_get_size(dirobj, &fileSize) < 0) { _HTTP_ServerSendError(ctx, session, 500, "Internal Server Error"); HTTP_FreeResponse(&response); rtp_file_gdone(dirobj); rtp_file_close(fd); return (-1); } rtp_file_gdone(dirobj); } HTTP_SetResponseHeaderInt(&response, "Content-Length", fileSize); } } HTTP_WriteResponse(session, &response); HTTP_FreeResponse(&response); do { #define EBSMIN(X,Y) ((X)<(Y)?(X):(Y)) if (vfile) { bytesRead=EBSMIN(bufferSize,bytesleft); rtp_memcpy(buffer,pdata,bytesRead); bytesleft -= bytesRead; pdata += bytesRead; } else bytesRead = rtp_file_read(fd, buffer, bufferSize); if (bytesRead > 0) { if (chunked) { if (HTTP_WriteChunkStart(session, bytesRead) < 0) { break; } } if (HTTP_Write(session, buffer, bytesRead) < bytesRead) { break; } if (chunked) { if (HTTP_WriteChunkEnd(session) < 0) { break; } } } } while (bytesRead > 0); /* this tells the client the transfer is complete */ if (chunked) { HTTP_WriteChunkStart(session, 0); HTTP_WriteChunkEnd(session); } HTTP_WriteFlush(session); if (!vfile) rtp_file_close(fd); break; } default: break; } return (0); }