NetSurf
Data Structures | Macros | Functions | Variables
file.c File Reference

file scheme URL handling. More...

#include "utils/config.h"
#include <stdlib.h>
#include <ctype.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
#include <stdbool.h>
#include <string.h>
#include <strings.h>
#include <time.h>
#include <stdio.h>
#include <stdarg.h>
#include <libwapcaplet/libwapcaplet.h>
#include "netsurf/inttypes.h"
#include "utils/nsurl.h"
#include "utils/dirent.h"
#include "utils/corestrings.h"
#include "utils/messages.h"
#include "utils/utils.h"
#include "utils/log.h"
#include "utils/ring.h"
#include "utils/file.h"
#include "netsurf/fetch.h"
#include "desktop/gui_internal.h"
#include "content/fetch.h"
#include "content/fetchers.h"
#include "dirlist.h"
#include "file.h"
Include dependency graph for file.c:

Go to the source code of this file.

Data Structures

struct  fetch_file_context
 Context for a fetch. More...
 

Macros

#define FETCH_FILE_MAX_BUF_SIZE   (1024 * 1024)
 

Functions

static bool fetch_file_send_callback (const fetch_msg *msg, struct fetch_file_context *ctx)
 issue fetch callbacks with locking More...
 
static bool fetch_file_send_header (struct fetch_file_context *ctx, const char *fmt,...)
 
static bool fetch_file_initialise (lwc_string *scheme)
 callback to initialise the file fetcher. More...
 
static void fetch_file_finalise (lwc_string *scheme)
 callback to initialise the file fetcher. More...
 
static bool fetch_file_can_fetch (const nsurl *url)
 
static void * fetch_file_setup (struct fetch *fetchh, nsurl *url, bool only_2xx, bool downgrade_tls, const char *post_urlenc, const struct fetch_multipart_data *post_multipart, const char **headers)
 callback to set up a file fetch context. More...
 
static void fetch_file_free (void *ctx)
 callback to free a file fetch More...
 
static bool fetch_file_start (void *ctx)
 callback to start a file fetch More...
 
static void fetch_file_abort (void *ctx)
 callback to abort a file fetch More...
 
static int fetch_file_errno_to_http_code (int error_no)
 
static void fetch_file_process_error (struct fetch_file_context *ctx, int code)
 
static void fetch_file_process_plain (struct fetch_file_context *ctx, struct stat *fdstat)
 Process object as a regular file. More...
 
static char * gen_nice_title (char *path)
 
static nserror process_dir_ent (struct fetch_file_context *ctx, struct dirent *ent, bool even, char *buffer, size_t buffer_len)
 Generate an output row of the directory listing. More...
 
static int dir_sort_alpha (const struct dirent **d1, const struct dirent **d2)
 Comparison function for sorting directories. More...
 
static void fetch_file_process_dir (struct fetch_file_context *ctx, struct stat *fdstat)
 
static void fetch_file_process (struct fetch_file_context *ctx)
 
static void fetch_file_poll (lwc_string *scheme)
 callback to poll for additional file fetch contents More...
 
nserror fetch_file_register (void)
 Register file scheme handler. More...
 

Variables

static struct fetch_file_contextring = NULL
 

Detailed Description

file scheme URL handling.

Based on the data fetcher by Rob Kendrick

output dates and directory ordering are affected by the current locale

Definition in file file.c.

Macro Definition Documentation

◆ FETCH_FILE_MAX_BUF_SIZE

#define FETCH_FILE_MAX_BUF_SIZE   (1024 * 1024)

Definition at line 66 of file file.c.

Function Documentation

◆ dir_sort_alpha()

static int dir_sort_alpha ( const struct dirent **  d1,
const struct dirent **  d2 
)
static

Comparison function for sorting directories.

Correctly orders non zero-padded numerical parts. ie. produces "file1, file2, file10" rather than "file1, file10, file2".

Parameters
d1first directory entry
d2second directory entry

Definition at line 632 of file file.c.

Referenced by fetch_file_process_dir().

Here is the caller graph for this function:

◆ fetch_file_abort()

static void fetch_file_abort ( void *  ctx)
static

callback to abort a file fetch

Definition at line 208 of file file.c.

References fetch_file_context::aborted.

Referenced by fetch_file_register().

Here is the caller graph for this function:

◆ fetch_file_can_fetch()

static bool fetch_file_can_fetch ( const nsurl url)
static

Definition at line 130 of file file.c.

Referenced by fetch_file_register().

Here is the caller graph for this function:

◆ fetch_file_errno_to_http_code()

static int fetch_file_errno_to_http_code ( int  error_no)
static

Definition at line 219 of file file.c.

Referenced by fetch_file_process(), fetch_file_process_dir(), and fetch_file_process_plain().

Here is the caller graph for this function:

◆ fetch_file_finalise()

static void fetch_file_finalise ( lwc_string *  scheme)
static

callback to initialise the file fetcher.

Definition at line 126 of file file.c.

Referenced by fetch_file_register().

Here is the caller graph for this function:

◆ fetch_file_free()

static void fetch_file_free ( void *  ctx)
static

callback to free a file fetch

Definition at line 193 of file file.c.

References nsurl_unref(), fetch_file_context::path, and fetch_file_context::url.

Referenced by fetch_file_register().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ fetch_file_initialise()

static bool fetch_file_initialise ( lwc_string *  scheme)
static

callback to initialise the file fetcher.

Definition at line 120 of file file.c.

Referenced by fetch_file_register().

Here is the caller graph for this function:

◆ fetch_file_poll()

static void fetch_file_poll ( lwc_string *  scheme)
static

callback to poll for additional file fetch contents

Definition at line 801 of file file.c.

References fetch_file_context::aborted, fetch_file_process(), fetch_free(), fetch_remove_from_queues(), fetch_file_context::fetchh, fetch_file_context::locked, ring, RING_INSERT, and RING_REMOVE.

Referenced by fetch_file_register().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ fetch_file_process()

static void fetch_file_process ( struct fetch_file_context ctx)
static

< The objects stat

Definition at line 773 of file file.c.

References fetch_file_errno_to_http_code(), fetch_file_process_dir(), fetch_file_process_error(), fetch_file_process_plain(), and fetch_file_context::path.

Referenced by fetch_file_poll().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ fetch_file_process_dir()

static void fetch_file_process_dir ( struct fetch_file_context ctx,
struct stat *  fdstat 
)
static

◆ fetch_file_process_error()

static void fetch_file_process_error ( struct fetch_file_context ctx,
int  code 
)
static

Definition at line 235 of file file.c.

References fetch_msg::buf, buffer, fetch_msg::data, FETCH_DATA, fetch_file_send_callback(), fetch_file_send_header(), FETCH_FINISHED, fetch_set_http_code(), fetch_file_context::fetchh, fetch_msg::header_or_data, fetch_msg::len, messages_get(), nsurl_access(), fetch_msg::type, and fetch_file_context::url.

Referenced by fetch_file_process(), fetch_file_process_dir(), and fetch_file_process_plain().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ fetch_file_process_plain()

static void fetch_file_process_plain ( struct fetch_file_context ctx,
struct stat *  fdstat 
)
static

Process object as a regular file.

Definition at line 282 of file file.c.

References fetch_file_context::aborted, fetch_msg::buf, fetch_msg::data, fetch_msg::error, netsurf_table::fetch, FETCH_DATA, FETCH_ERROR, fetch_file_errno_to_http_code(), FETCH_FILE_MAX_BUF_SIZE, fetch_file_process_error(), fetch_file_send_callback(), fetch_file_send_header(), FETCH_FINISHED, FETCH_NOTMODIFIED, fetch_set_http_code(), fetch_file_context::fetchh, fetch_file_context::file_etag, gui_fetch_table::filetype, guit, fetch_msg::header_or_data, fetch_msg::len, fetch_file_context::path, PRId64, PRIsizet, and fetch_msg::type.

Referenced by fetch_file_process().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ fetch_file_register()

nserror fetch_file_register ( void  )

Register file scheme handler.

Returns
NSERROR_OK on successful registration or error code on failure.

Definition at line 839 of file file.c.

References fetch_file_abort(), fetch_file_can_fetch(), fetch_file_finalise(), fetch_file_free(), fetch_file_initialise(), fetch_file_poll(), fetch_file_setup(), fetch_file_start(), fetcher_add(), and fetcher_operation_table::initialise.

Referenced by fetcher_init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ fetch_file_send_callback()

static bool fetch_file_send_callback ( const fetch_msg msg,
struct fetch_file_context ctx 
)
inlinestatic

issue fetch callbacks with locking

Definition at line 86 of file file.c.

References fetch_file_context::aborted, fetch_send_callback(), fetch_file_context::fetchh, and fetch_file_context::locked.

Referenced by fetch_file_process_dir(), fetch_file_process_error(), fetch_file_process_plain(), and fetch_file_send_header().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ fetch_file_send_header()

static bool fetch_file_send_header ( struct fetch_file_context ctx,
const char *  fmt,
  ... 
)
static

Definition at line 96 of file file.c.

References fetch_msg::buf, fetch_msg::data, fetch_file_send_callback(), FETCH_HEADER, fetch_msg::header_or_data, fetch_msg::len, and fetch_msg::type.

Referenced by fetch_file_process_dir(), fetch_file_process_error(), and fetch_file_process_plain().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ fetch_file_setup()

static void * fetch_file_setup ( struct fetch fetchh,
nsurl url,
bool  only_2xx,
bool  downgrade_tls,
const char *  post_urlenc,
const struct fetch_multipart_data post_multipart,
const char **  headers 
)
static

callback to set up a file fetch context.

Definition at line 137 of file file.c.

References fetch_file_context::fetchh, netsurf_table::file, fetch_file_context::file_etag, guit, nsc_snptimet(), NSERROR_OK, NSLOG, nsurl_ref(), gui_file_table::nsurl_to_path, fetch_file_context::path, ring, RING_INSERT, SLEN, and fetch_file_context::url.

Referenced by fetch_file_register().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ fetch_file_start()

static bool fetch_file_start ( void *  ctx)
static

callback to start a file fetch

Definition at line 202 of file file.c.

Referenced by fetch_file_register().

Here is the caller graph for this function:

◆ gen_nice_title()

static char * gen_nice_title ( char *  path)
static

Definition at line 470 of file file.c.

References messages_get(), path(), and SLEN.

Referenced by fetch_file_process_dir().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ process_dir_ent()

static nserror process_dir_ent ( struct fetch_file_context ctx,
struct dirent *  ent,
bool  even,
char *  buffer,
size_t  buffer_len 
)
static

Generate an output row of the directory listing.

Parameters
ctxThe file fetching context.
entcurrent directory entry.
evenis the row an even row.
bufferThe output buffer.
buffer_lenThe space available in the output buffer.
Returns
NSERROR_OK or error code on faliure.

Definition at line 534 of file file.c.

References buffer, dirlist_generate_row(), netsurf_table::fetch, netsurf_table::file, gui_fetch_table::filetype, guit, messages_get(), netsurf_mkpath(), NSERROR_BAD_PARAMETER, NSERROR_OK, nsurl_unref(), fetch_file_context::path, and gui_file_table::path_to_nsurl.

Referenced by fetch_file_process_dir().

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ ring

struct fetch_file_context* ring = NULL
static

Definition at line 83 of file file.c.

Referenced by fetch_file_poll(), and fetch_file_setup().