void rtplatform_gdone(PSMBDSTAT dirobj) { /* make sure it hasn't already been freed */ if (dirobj->rtp_dirobj != (void*)0) { rtp_file_gdone(dirobj->rtp_dirobj); } }
BBOOL rtplatform_wstat(unsigned short RTSMB_FAR * name, PSMBFSTAT vstat) { void * rtp_dirobj; if (rtp_wfile_gfirst(&rtp_dirobj, name) < 0) { rtp_dirobj = (void *)0; return FALSE; } rtplatform_translate_fstat(vstat, rtp_dirobj); rtp_file_gdone(rtp_dirobj); return TRUE; }
/*---------------------------------------------------------------------------*/ 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); }