예제 #1
0
/*----------------------------------------------------------------------*
                             rtp_wfile_gfirst
 *----------------------------------------------------------------------*/
int rtp_wfile_gfirst (void ** dirobj, unsigned short * name)
{
	unsigned char realName[32];
	
	map_unicode_to_ascii((unsigned char *)realName,(unsigned char *) name);	
	return(rtp_file_gfirst (dirobj, realName));
}
예제 #2
0
파일: psmbfile.c 프로젝트: layerfsd/cifssmb
BBOOL rtplatform_gfirst(PSMBDSTAT dirobj, char RTSMB_FAR * name_in)
{
char slashstar [] = {'\\', '*', '\0'};
char dotstar [] = {'.', '*', '\0'};
char name [SMBF_FILENAMESIZE + 1];
rtsmb_size len;
int rv;
void * rtp_dirobj;

    /* translate "*" to "*.*" becaues some file systems don't like "*" */
    len = (rtsmb_size) tc_strlen (name_in);
    tc_strcpy (name, name_in);
    if (len > 1 && len < SMBF_FILENAMESIZE - 2 && tc_strcmp (&name[len - 2], slashstar) == 0)
    {
       tc_strcat  (name, dotstar);
    }

    rv = rtp_file_gfirst(&rtp_dirobj, name);
    if (rv < 0)
    {
        dirobj->rtp_dirobj = (void*)0;
        return FALSE;
    }

    rtp_file_get_name(rtp_dirobj, dirobj->filename, SMBF_FILENAMESIZE);
    dirobj->filename[SMBF_FILENAMESIZE] = '\0';

    /*translate rtplatform dstat to smb dstat */
    rtplatform_translate_dstat (dirobj, rtp_dirobj);
    dirobj->unicode = 0;

    return TRUE;
}
예제 #3
0
파일: psmbfile.c 프로젝트: layerfsd/cifssmb
BBOOL rtplatform_stat(char RTSMB_FAR * name, PSMBFSTAT vstat)
{
void * rtp_dirobj;

    if (rtp_file_gfirst(&rtp_dirobj, name) < 0)
    {
        rtp_dirobj = (void *)0;
        return FALSE;
    }

    rtplatform_translate_fstat(vstat, rtp_dirobj);
    rtp_file_gdone(rtp_dirobj);
    return TRUE;
}
예제 #4
0
/*---------------------------------------------------------------------------*/
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);
}