base
This commit is contained in:
+129
@@ -0,0 +1,129 @@
|
||||
#include "stdafx.h"
|
||||
|
||||
//#include "MFC64bitFix.h"
|
||||
|
||||
__int64 GetLength64(CFile &file)
|
||||
{
|
||||
DWORD low;
|
||||
DWORD high;
|
||||
low=GetFileSize((void *)file.m_hFile, &high);
|
||||
_int64 size=((_int64)high<<32)+low;
|
||||
return size;
|
||||
}
|
||||
|
||||
BOOL GetLength64(CString filename, _int64 &size)
|
||||
{
|
||||
WIN32_FIND_DATA findFileData;
|
||||
HANDLE hFind = FindFirstFile(filename, &findFileData);
|
||||
if (hFind == INVALID_HANDLE_VALUE)
|
||||
return FALSE;
|
||||
VERIFY(FindClose(hFind));
|
||||
|
||||
size=((_int64)findFileData.nFileSizeHigh<<32)+findFileData.nFileSizeLow;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
BOOL AFXAPI AfxFullPath(LPTSTR lpszPathOut, LPCTSTR lpszFileIn);
|
||||
|
||||
BOOL PASCAL GetStatus64(LPCTSTR lpszFileName, CFileStatus64& rStatus)
|
||||
{
|
||||
// attempt to fully qualify path first
|
||||
if (!AfxFullPath(rStatus.m_szFullName, lpszFileName))
|
||||
{
|
||||
rStatus.m_szFullName[0] = '\0';
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
WIN32_FIND_DATA findFileData;
|
||||
HANDLE hFind = FindFirstFile((LPTSTR)lpszFileName, &findFileData);
|
||||
if (hFind == INVALID_HANDLE_VALUE)
|
||||
return FALSE;
|
||||
VERIFY(FindClose(hFind));
|
||||
|
||||
// strip attribute of NORMAL bit, our API doesn't have a "normal" bit.
|
||||
rStatus.m_attribute = (BYTE)
|
||||
(findFileData.dwFileAttributes & ~FILE_ATTRIBUTE_NORMAL);
|
||||
|
||||
rStatus.m_size = ((_int64)findFileData.nFileSizeHigh<<32)+findFileData.nFileSizeLow;
|
||||
|
||||
// convert times as appropriate
|
||||
TRY
|
||||
{
|
||||
rStatus.m_ctime = CTime(findFileData.ftCreationTime);
|
||||
rStatus.m_has_ctime = true;
|
||||
}
|
||||
CATCH_ALL(e)
|
||||
{
|
||||
rStatus.m_has_ctime = false;
|
||||
}
|
||||
END_CATCH_ALL;
|
||||
|
||||
TRY
|
||||
{
|
||||
rStatus.m_atime = CTime(findFileData.ftLastAccessTime);
|
||||
rStatus.m_has_atime = true;
|
||||
}
|
||||
CATCH_ALL(e)
|
||||
{
|
||||
rStatus.m_has_atime = false;
|
||||
}
|
||||
END_CATCH_ALL;
|
||||
|
||||
TRY
|
||||
{
|
||||
rStatus.m_mtime = CTime(findFileData.ftLastWriteTime);
|
||||
rStatus.m_has_mtime = true;
|
||||
}
|
||||
CATCH_ALL(e)
|
||||
{
|
||||
rStatus.m_has_mtime = false;
|
||||
}
|
||||
END_CATCH_ALL;
|
||||
|
||||
if (!rStatus.m_has_ctime || rStatus.m_ctime.GetTime() == 0)
|
||||
{
|
||||
if (rStatus.m_has_mtime)
|
||||
{
|
||||
rStatus.m_ctime = rStatus.m_mtime;
|
||||
rStatus.m_has_ctime = true;
|
||||
}
|
||||
else
|
||||
rStatus.m_has_ctime = false;
|
||||
}
|
||||
|
||||
|
||||
if (!rStatus.m_has_atime || rStatus.m_atime.GetTime() == 0)
|
||||
{
|
||||
if (rStatus.m_has_mtime)
|
||||
{
|
||||
rStatus.m_atime = rStatus.m_mtime;
|
||||
rStatus.m_has_atime = true;
|
||||
}
|
||||
else
|
||||
rStatus.m_has_atime = false;
|
||||
}
|
||||
|
||||
if (!rStatus.m_has_mtime || rStatus.m_mtime.GetTime() == 0)
|
||||
{
|
||||
if (rStatus.m_has_ctime)
|
||||
{
|
||||
rStatus.m_mtime = rStatus.m_ctime;
|
||||
rStatus.m_has_mtime = true;
|
||||
}
|
||||
else
|
||||
rStatus.m_has_mtime = false;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
_int64 GetPosition64(CFile &file)
|
||||
{
|
||||
LONG low=0;
|
||||
LONG high=0;
|
||||
low=SetFilePointer((HANDLE)file.m_hFile, low, &high, FILE_CURRENT);
|
||||
if (low==0xFFFFFFFF && GetLastError!=NO_ERROR)
|
||||
CFileException::ThrowOsError((LONG)::GetLastError());
|
||||
return ((_int64)high<<32)+low;
|
||||
}
|
||||
+141
@@ -0,0 +1,141 @@
|
||||
/*
|
||||
HTTP-redirect support
|
||||
Copyright (C) 1999-2004, Joe Orton <joe@manyfish.co.uk>
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not, write to the Free
|
||||
Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
|
||||
MA 02111-1307, USA
|
||||
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#ifdef HAVE_STDLIB_H
|
||||
#include <stdlib.h>
|
||||
#endif
|
||||
#ifdef HAVE_STRING_H
|
||||
#include <string.h>
|
||||
#endif
|
||||
|
||||
#include "ne_session.h"
|
||||
#include "ne_request.h"
|
||||
#include "ne_alloc.h"
|
||||
#include "ne_uri.h"
|
||||
#include "ne_redirect.h"
|
||||
#include "ne_i18n.h"
|
||||
#include "ne_string.h"
|
||||
|
||||
#define REDIRECT_ID "http://www.webdav.org/neon/hooks/http-redirect"
|
||||
|
||||
struct redirect {
|
||||
char *requri;
|
||||
int valid; /* non-zero if .uri contains a redirect */
|
||||
ne_uri uri;
|
||||
ne_session *sess;
|
||||
};
|
||||
|
||||
static void
|
||||
create(ne_request *req, void *session, const char *method, const char *uri)
|
||||
{
|
||||
struct redirect *red = session;
|
||||
NE_FREE(red->requri);
|
||||
red->requri = ne_strdup(uri);
|
||||
}
|
||||
|
||||
#define REDIR(n) ((n) == 301 || (n) == 302 || (n) == 303 || \
|
||||
(n) == 307)
|
||||
|
||||
static int post_send(ne_request *req, void *private, const ne_status *status)
|
||||
{
|
||||
struct redirect *red = private;
|
||||
const char *location = ne_get_response_header(req, "Location");
|
||||
ne_buffer *path = NULL;
|
||||
int ret;
|
||||
|
||||
/* Don't do anything for non-redirect status or no Location header. */
|
||||
if (!REDIR(status->code) || location == NULL)
|
||||
return NE_OK;
|
||||
|
||||
if (strstr(location, "://") == NULL && location[0] != '/') {
|
||||
char *pnt;
|
||||
|
||||
path = ne_buffer_create();
|
||||
ne_buffer_zappend(path, red->requri);
|
||||
pnt = strrchr(path->data, '/');
|
||||
|
||||
if (pnt && pnt[1] != '\0') {
|
||||
/* Chop off last path segment. */
|
||||
pnt[1] = '\0';
|
||||
ne_buffer_altered(path);
|
||||
}
|
||||
ne_buffer_zappend(path, location);
|
||||
location = path->data;
|
||||
}
|
||||
|
||||
/* free last uri. */
|
||||
ne_uri_free(&red->uri);
|
||||
|
||||
/* Parse the Location header */
|
||||
if (ne_uri_parse(location, &red->uri) || red->uri.path == NULL) {
|
||||
red->valid = 0;
|
||||
ne_set_error(red->sess, _("Could not parse redirect location."));
|
||||
ret = NE_ERROR;
|
||||
} else {
|
||||
/* got a valid redirect. */
|
||||
red->valid = 1;
|
||||
ret = NE_REDIRECT;
|
||||
|
||||
if (!red->uri.host) {
|
||||
/* Not an absoluteURI: breaks 2616 but everybody does it. */
|
||||
ne_fill_server_uri(red->sess, &red->uri);
|
||||
}
|
||||
}
|
||||
|
||||
if (path) ne_buffer_destroy(path);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void free_redirect(void *cookie)
|
||||
{
|
||||
struct redirect *red = cookie;
|
||||
ne_uri_free(&red->uri);
|
||||
if (red->requri)
|
||||
ne_free(red->requri);
|
||||
ne_free(red);
|
||||
}
|
||||
|
||||
void ne_redirect_register(ne_session *sess)
|
||||
{
|
||||
struct redirect *red = ne_calloc(sizeof *red);
|
||||
|
||||
red->sess = sess;
|
||||
|
||||
ne_hook_create_request(sess, create, red);
|
||||
ne_hook_post_send(sess, post_send, red);
|
||||
ne_hook_destroy_session(sess, free_redirect, red);
|
||||
|
||||
ne_set_session_private(sess, REDIRECT_ID, red);
|
||||
}
|
||||
|
||||
const ne_uri *ne_redirect_location(ne_session *sess)
|
||||
{
|
||||
struct redirect *red = ne_get_session_private(sess, REDIRECT_ID);
|
||||
|
||||
if (red && red->valid)
|
||||
return &red->uri;
|
||||
else
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user