mirror of
https://github.com/netsurf-browser/netsurf
synced 2024-12-24 04:56:50 +03:00
Use core file fetcher
svn path=/trunk/netsurf/; revision=10759
This commit is contained in:
parent
90b7aca965
commit
c0332c4394
@ -93,7 +93,7 @@ S_AMIGA := compat.c gui.c tree.c history.c hotlist.c schedule.c \
|
||||
thumbnail.c misc.c bitmap.c font.c filetype.c utf8.c login.c \
|
||||
plotters.c object.c menu.c save_pdf.c arexx.c version.c \
|
||||
cookies.c context_menu.c clipboard.c save_complete.c \
|
||||
fetch_file.c fetch_mailto.c search.c history_local.c \
|
||||
fetch_mailto.c search.c history_local.c \
|
||||
download.c iff_dr2d.c sslcert.c gui_options.c print.c \
|
||||
theme.c \
|
||||
stringview/stringview.c stringview/urlhistory.c
|
||||
|
@ -1,354 +0,0 @@
|
||||
/*
|
||||
* Copyright 2008 Chris Young <chris@unsatisfactorysoftware.co.uk>
|
||||
*
|
||||
* This file is part of NetSurf, http://www.netsurf-browser.org/
|
||||
*
|
||||
* NetSurf is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; version 2 of the License.
|
||||
*
|
||||
* NetSurf 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/** \file
|
||||
* Fetching of data from a file (implementation).
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include "content/fetch.h"
|
||||
#include "utils/log.h"
|
||||
#include "utils/url.h"
|
||||
#include <proto/dos.h>
|
||||
#include <proto/exec.h>
|
||||
#include "amiga/object.h"
|
||||
#include <malloc.h>
|
||||
#include "content/content.h"
|
||||
#include <time.h>
|
||||
#include <proto/utility.h>
|
||||
#include "utils/messages.h"
|
||||
|
||||
static struct MinList *ami_file_fetcher_list = NULL;
|
||||
static UBYTE *ami_file_fetcher_buffer = NULL;
|
||||
|
||||
/** Information for a single fetch. */
|
||||
struct ami_file_fetch_info {
|
||||
struct fetch *fetch_handle; /**< The fetch handle we're parented by. */
|
||||
BPTR fh; /** File handle */
|
||||
bool only_2xx; /**< Only HTTP 2xx responses acceptable. */
|
||||
char *path;
|
||||
char *url; /**< URL of this fetch. */
|
||||
bool aborted;
|
||||
bool locked;
|
||||
bool is_dir;
|
||||
struct nsObject *obj;
|
||||
int httpcode;
|
||||
int64 len;
|
||||
char *mimetype;
|
||||
};
|
||||
|
||||
static bool ami_fetch_file_initialise(const char *scheme);
|
||||
static void ami_fetch_file_finalise(const char *scheme);
|
||||
static void * ami_fetch_file_setup(struct fetch *parent_fetch, const char *url,
|
||||
bool only_2xx, const char *post_urlenc,
|
||||
struct fetch_multipart_data *post_multipart,
|
||||
const char **headers);
|
||||
static bool ami_fetch_file_start(void *vfetch);
|
||||
static void ami_fetch_file_abort(void *vf);
|
||||
static void ami_fetch_file_free(void *f);
|
||||
static void ami_fetch_file_poll(const char *scheme_ignored);
|
||||
|
||||
/**
|
||||
* Initialise the fetcher.
|
||||
*
|
||||
* Must be called once before any other function.
|
||||
*/
|
||||
|
||||
void ami_fetch_file_register(void)
|
||||
{
|
||||
if (!fetch_add_fetcher("file",
|
||||
ami_fetch_file_initialise,
|
||||
ami_fetch_file_setup,
|
||||
ami_fetch_file_start,
|
||||
ami_fetch_file_abort,
|
||||
ami_fetch_file_free,
|
||||
ami_fetch_file_poll,
|
||||
ami_fetch_file_finalise)) {
|
||||
LOG(("Unable to register Amiga fetcher for file:"));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Initialise a cURL fetcher.
|
||||
*/
|
||||
|
||||
bool ami_fetch_file_initialise(const char *scheme)
|
||||
{
|
||||
LOG(("Initialise Amiga fetcher for %s", scheme));
|
||||
ami_file_fetcher_list = NewObjList();
|
||||
ami_file_fetcher_buffer = AllocVec(1024,MEMF_PRIVATE);
|
||||
|
||||
if(ami_file_fetcher_list && ami_file_fetcher_buffer) return true;
|
||||
else return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Finalise a cURL fetcher
|
||||
*/
|
||||
|
||||
void ami_fetch_file_finalise(const char *scheme)
|
||||
{
|
||||
LOG(("Finalise Amiga fetcher %s", scheme));
|
||||
FreeObjList(ami_file_fetcher_list);
|
||||
FreeVec(ami_file_fetcher_buffer);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Start fetching data for the given URL.
|
||||
*
|
||||
* The function returns immediately. The fetch may be queued for later
|
||||
* processing.
|
||||
*
|
||||
* A pointer to an opaque struct curl_fetch_info is returned, which can be passed to
|
||||
* fetch_abort() to abort the fetch at any time. Returns 0 if memory is
|
||||
* exhausted (or some other fatal error occurred).
|
||||
*
|
||||
* The caller must supply a callback function which is called when anything
|
||||
* interesting happens. The callback function is first called with msg
|
||||
* FETCH_HEADER, with the header in data, then one or more times
|
||||
* with FETCH_DATA with some data for the url, and finally with
|
||||
* FETCH_FINISHED. Alternatively, FETCH_ERROR indicates an error occurred:
|
||||
* data contains an error message. FETCH_REDIRECT may replace the FETCH_HEADER,
|
||||
* FETCH_DATA, FETCH_FINISHED sequence if the server sends a replacement URL.
|
||||
*
|
||||
* Some private data can be passed as the last parameter to fetch_start, and
|
||||
* callbacks will contain this.
|
||||
*/
|
||||
|
||||
void * ami_fetch_file_setup(struct fetch *parent_fetch, const char *url,
|
||||
bool only_2xx, const char *post_urlenc,
|
||||
struct fetch_multipart_data *post_multipart,
|
||||
const char **headers)
|
||||
{
|
||||
struct ami_file_fetch_info *fetch;
|
||||
|
||||
fetch = AllocVec(sizeof (*fetch),MEMF_PRIVATE | MEMF_CLEAR);
|
||||
if (!fetch)
|
||||
return 0;
|
||||
|
||||
fetch->fetch_handle = parent_fetch;
|
||||
|
||||
/* construct a new fetch structure */
|
||||
fetch->fh = 0;
|
||||
fetch->only_2xx = only_2xx;
|
||||
// fetch->url = strdup(url);
|
||||
fetch->path = url_to_path(url);
|
||||
|
||||
LOG(("fetch %p, url '%s', path '%s'", fetch, url,fetch->path));
|
||||
|
||||
fetch->obj = AddObject(ami_file_fetcher_list,AMINS_FETCHER);
|
||||
fetch->obj->objstruct = fetch;
|
||||
|
||||
return fetch;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Dispatch a single job
|
||||
*/
|
||||
bool ami_fetch_file_start(void *vfetch)
|
||||
{
|
||||
struct ami_file_fetch_info *fetch = (struct ami_file_fetch_info*)vfetch;
|
||||
|
||||
/* LOG(("ami file fetcher start")); */
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void ami_fetch_file_abort(void *vf)
|
||||
{
|
||||
struct ami_file_fetch_info *fetch = (struct ami_file_fetch_info*)vf;
|
||||
|
||||
/* LOG(("ami file fetcher abort")); */
|
||||
|
||||
if (fetch->fh) {
|
||||
FClose(fetch->fh);
|
||||
fetch->fh = 0;
|
||||
}
|
||||
fetch->aborted = true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Free a fetch structure and associated resources.
|
||||
*/
|
||||
|
||||
void ami_fetch_file_free(void *vf)
|
||||
{
|
||||
struct ami_file_fetch_info *fetch = (struct ami_file_fetch_info*)vf;
|
||||
/* LOG(("ami file fetcher free %lx",fetch)); */
|
||||
|
||||
if(fetch->fh) FClose(fetch->fh);
|
||||
if(fetch->mimetype) free(fetch->mimetype);
|
||||
if(fetch->path) free(fetch->path);
|
||||
|
||||
DelObject(fetch->obj); // delobject frees fetch
|
||||
}
|
||||
|
||||
static void ami_fetch_file_send_callback(fetch_msg msg,
|
||||
struct ami_file_fetch_info *fetch, const void *data,
|
||||
unsigned long size, fetch_error_code errorcode)
|
||||
{
|
||||
fetch->locked = true;
|
||||
/* LOG(("ami file fetcher callback %ld",msg)); */
|
||||
fetch_send_callback(msg,fetch->fetch_handle,data,size,errorcode);
|
||||
fetch->locked = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Do some work on current fetches.
|
||||
*
|
||||
* Must be called regularly to make progress on fetches.
|
||||
*/
|
||||
|
||||
void ami_fetch_file_poll(const char *scheme_ignored)
|
||||
{
|
||||
struct nsObject *node;
|
||||
struct nsObject *nnode;
|
||||
struct ami_file_fetch_info *fetch;
|
||||
fetch_error_code errorcode;
|
||||
|
||||
if(IsMinListEmpty(ami_file_fetcher_list)) return;
|
||||
|
||||
node = (struct nsObject *)GetHead((struct List *)ami_file_fetcher_list);
|
||||
|
||||
do
|
||||
{
|
||||
errorcode = FETCH_ERROR_NO_ERROR;
|
||||
nnode=(struct nsObject *)GetSucc((struct Node *)node);
|
||||
|
||||
fetch = (struct ami_file_fetch_info *)node->objstruct;
|
||||
|
||||
if(fetch->locked) continue;
|
||||
|
||||
if(!fetch->aborted)
|
||||
{
|
||||
if(fetch->fh)
|
||||
{
|
||||
ULONG len;
|
||||
|
||||
len = FRead(fetch->fh,ami_file_fetcher_buffer,1,1024);
|
||||
|
||||
if (len == (ULONG)-1)
|
||||
errorcode = FETCH_ERROR_MISC;
|
||||
else if (len > 0)
|
||||
ami_fetch_file_send_callback(
|
||||
FETCH_DATA, fetch,
|
||||
ami_file_fetcher_buffer,
|
||||
len, errorcode);
|
||||
|
||||
if((len<1024) && (!fetch->aborted))
|
||||
{
|
||||
ami_fetch_file_send_callback(FETCH_FINISHED,
|
||||
fetch, NULL, 0,
|
||||
errorcode);
|
||||
|
||||
fetch->aborted = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
fetch->fh = FOpen(fetch->path,MODE_OLDFILE,0);
|
||||
|
||||
if(fetch->fh)
|
||||
{
|
||||
char header[64];
|
||||
struct ExamineData *fib;
|
||||
if(fib = ExamineObjectTags(EX_FileHandleInput,fetch->fh,TAG_DONE))
|
||||
{
|
||||
fetch->len = fib->FileSize;
|
||||
FreeDosObject(DOS_EXAMINEDATA,fib);
|
||||
}
|
||||
|
||||
fetch_set_http_code(fetch->fetch_handle,200);
|
||||
fetch->mimetype = fetch_mimetype(fetch->path);
|
||||
LOG(("mimetype %s len %ld",fetch->mimetype,fetch->len));
|
||||
|
||||
snprintf(header, sizeof header,
|
||||
"Content-Type: %s",
|
||||
fetch->mimetype);
|
||||
ami_fetch_file_send_callback(FETCH_HEADER,
|
||||
fetch, header, strlen(header), errorcode);
|
||||
|
||||
snprintf(header, sizeof header,
|
||||
"Content-Length: %ld",
|
||||
fetch->len);
|
||||
ami_fetch_file_send_callback(FETCH_HEADER,
|
||||
fetch, header, strlen(header), errorcode);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
char header[64];
|
||||
STRPTR errorstring;
|
||||
struct ExamineData *fib;
|
||||
if(fib = ExamineObjectTags(EX_StringNameInput,fetch->path,TAG_DONE))
|
||||
{
|
||||
if(EXD_IS_DIRECTORY(fib)) fetch->is_dir = true;
|
||||
FreeDosObject(DOS_EXAMINEDATA,fib);
|
||||
}
|
||||
|
||||
if(fetch->is_dir == true)
|
||||
{
|
||||
fetch_set_http_code(fetch->fetch_handle, 200);
|
||||
fetch->mimetype = fetch_mimetype(fetch->path);
|
||||
LOG(("mimetype %s", fetch->mimetype));
|
||||
|
||||
snprintf(header, sizeof header,
|
||||
"Content-Type: %s",
|
||||
fetch->mimetype);
|
||||
ami_fetch_file_send_callback(FETCH_HEADER,
|
||||
fetch, header, strlen(header), errorcode);
|
||||
|
||||
ami_fetch_file_send_callback(
|
||||
FETCH_DATA, fetch,
|
||||
fetch->path,
|
||||
strlen(fetch->path), errorcode);
|
||||
|
||||
ami_fetch_file_send_callback(FETCH_FINISHED,
|
||||
fetch, NULL, 0,
|
||||
errorcode);
|
||||
|
||||
fetch->aborted = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
errorstring = ASPrintf("%s %s",messages_get("FileError"),fetch->path);
|
||||
fetch_set_http_code(fetch->fetch_handle,404);
|
||||
|
||||
errorcode = FETCH_ERROR_HTTP_NOT2;
|
||||
ami_fetch_file_send_callback(FETCH_ERROR, fetch,
|
||||
errorstring, 0, errorcode);
|
||||
fetch->aborted = true;
|
||||
FreeVec(errorstring);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(fetch && fetch->aborted)
|
||||
{
|
||||
fetch_remove_from_queues(fetch->fetch_handle);
|
||||
fetch_free(fetch->fetch_handle);
|
||||
return;
|
||||
}
|
||||
}while(node=nnode);
|
||||
}
|
@ -1,27 +0,0 @@
|
||||
/*
|
||||
* Copyright 2008 Chris Young <chris@unsatisfactorysoftware.co.uk>
|
||||
*
|
||||
* This file is part of NetSurf.
|
||||
*
|
||||
* NetSurf is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; version 2 of the License.
|
||||
*
|
||||
* NetSurf 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/** \file
|
||||
* Fetching of data from a URL (Registration).
|
||||
*/
|
||||
|
||||
#ifndef AMIGA_FETCH_FILE_H
|
||||
#define AMIGA_FETCH_FILE_H
|
||||
|
||||
void ami_fetch_file_register(void);
|
||||
#endif
|
@ -40,7 +40,6 @@
|
||||
#include "amiga/context_menu.h"
|
||||
#include "amiga/cookies.h"
|
||||
#include "amiga/download.h"
|
||||
#include "amiga/fetch_file.h"
|
||||
#include "amiga/fetch_mailto.h"
|
||||
#include "amiga/font.h"
|
||||
#include "amiga/gui.h"
|
||||
@ -570,7 +569,6 @@ static void gui_init2(int argc, char** argv)
|
||||
};
|
||||
|
||||
notalreadyrunning = ami_arexx_init();
|
||||
ami_fetch_file_register();
|
||||
|
||||
search_web_provider_details(option_search_provider);
|
||||
|
||||
|
13
amiga/misc.c
13
amiga/misc.c
@ -23,7 +23,6 @@
|
||||
#include <proto/dos.h>
|
||||
#include "utils/messages.h"
|
||||
#include <stdlib.h>
|
||||
#include <curl/curl.h>
|
||||
#include "utils/utils.h"
|
||||
#include "utils/url.h"
|
||||
|
||||
@ -60,7 +59,6 @@ void die(const char *error)
|
||||
char *url_to_path(const char *url)
|
||||
{
|
||||
char *tmps, *unesc, *slash, *colon, *url2;
|
||||
CURL *curl;
|
||||
|
||||
if (strncmp(url, "file://", SLEN("file://")) != 0)
|
||||
return NULL;
|
||||
@ -94,15 +92,8 @@ char *url_to_path(const char *url)
|
||||
}
|
||||
}
|
||||
|
||||
if(curl = curl_easy_init())
|
||||
{
|
||||
unesc = curl_easy_unescape(curl,url2,0,NULL);
|
||||
tmps = strdup(unesc);
|
||||
free(url2);
|
||||
curl_free(unesc);
|
||||
curl_easy_cleanup(curl);
|
||||
return tmps;
|
||||
}
|
||||
if(url_unescape(url2,&unesc) == URL_FUNC_OK)
|
||||
return unesc;
|
||||
|
||||
return (char *)url2;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user