Dillo v3.1.1-99-gf3103cc4
Loading...
Searching...
No Matches
file.c File Reference
#include <ctype.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/select.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/time.h>
#include <sys/un.h>
#include <dirent.h>
#include <fcntl.h>
#include <time.h>
#include <signal.h>
#include <netinet/in.h>
#include "../dpip/dpip.h"
#include "dpiutil.h"
#include "d_size.h"
Include dependency graph for file.c:

Go to the source code of this file.

Macros

#define _MSG(...)
 
#define MSG(...)   printf("[file dpi]: " __VA_ARGS__)
 
#define _MSG_RAW(...)
 
#define MSG_RAW(...)   printf(__VA_ARGS__)
 
#define MAXNAMESIZE   30
 
#define HIDE_DOTFILES   TRUE
 
#define FILE_AUTH_OK   1 /* Authentication done */
 
#define FILE_READ   2 /* Waiting data */
 
#define FILE_WRITE   4 /* Sending data */
 
#define FILE_DONE   8 /* Operation done */
 
#define FILE_ERR   16 /* Operation error */
 
#define LBUF   16*1024
 

Enumerations

enum  FileState {
  st_start = 10 , st_dpip , st_http , st_content ,
  st_done , st_err
}
 

Functions

static const char * File_content_type (const char *filename)
 
static void File_close (int fd)
 
static const char * File_get_content_type_from_data (void *Data, size_t Size)
 
static int File_comp (const FileInfo *f1, const FileInfo *f2)
 
static DilloDir * File_dillodir_new (char *dirname)
 
static void File_dillodir_free (DilloDir *Ddir)
 
static void File_print_parent_dir (ClientInfo *client, const char *dirname)
 
static void File_print_mtime (ClientInfo *client, time_t mtime)
 
static void File_info2html (ClientInfo *client, FileInfo *finfo, int n)
 
static void File_send_dir (ClientInfo *client)
 
static const char * File_ext (const char *filename)
 
static void File_prepare_send_error_page (ClientInfo *client, int res, const char *orig_url)
 
static void File_send_error_page (ClientInfo *client)
 
static int File_prepare_send_dir (ClientInfo *client, const char *DirName, const char *orig_url)
 
static int File_prepare_send_file (ClientInfo *client, const char *filename, const char *orig_url)
 
static void File_get (ClientInfo *client, const char *filename, const char *orig_url)
 
static int File_send_file (ClientInfo *client)
 
static int File_parse_hex_octet (const char *s)
 
static char * File_normalize_path (const char *orig)
 
static void File_toggle_html_style (ClientInfo *client)
 
static void termination_handler (int signum)
 
static ClientInfo * File_add_client (int sock_fd)
 
static void File_remove_client (ClientInfo *client)
 
static void File_serve_client (void *data, int f_write)
 
static void File_serve_clients (void)
 
static int File_check_fds (uint_t seconds)
 
int main (void)
 

Variables

static int DPIBYE = 0
 
static int OLD_STYLE = 0
 
static DlistClients
 
fd_set read_set
 
fd_set write_set
 

Macro Definition Documentation

◆ _MSG

#define _MSG (   ...)

Definition at line 44 of file file.c.

◆ _MSG_RAW

#define _MSG_RAW (   ...)

Definition at line 46 of file file.c.

◆ FILE_AUTH_OK

#define FILE_AUTH_OK   1 /* Authentication done */

Definition at line 56 of file file.c.

◆ FILE_DONE

#define FILE_DONE   8 /* Operation done */

Definition at line 59 of file file.c.

◆ FILE_ERR

#define FILE_ERR   16 /* Operation error */

Definition at line 60 of file file.c.

◆ FILE_READ

#define FILE_READ   2 /* Waiting data */

Definition at line 57 of file file.c.

◆ FILE_WRITE

#define FILE_WRITE   4 /* Sending data */

Definition at line 58 of file file.c.

◆ HIDE_DOTFILES

#define HIDE_DOTFILES   TRUE

Definition at line 51 of file file.c.

◆ LBUF

#define LBUF   16*1024

◆ MAXNAMESIZE

#define MAXNAMESIZE   30

Definition at line 50 of file file.c.

◆ MSG

#define MSG (   ...)    printf("[file dpi]: " __VA_ARGS__)

Definition at line 45 of file file.c.

◆ MSG_RAW

#define MSG_RAW (   ...)    printf(__VA_ARGS__)

Definition at line 47 of file file.c.

Enumeration Type Documentation

◆ FileState

enum FileState
Enumerator
st_start 
st_dpip 
st_http 
st_content 
st_done 
st_err 

Definition at line 63 of file file.c.

Function Documentation

◆ File_add_client()

static ClientInfo * File_add_client ( int  sock_fd)
static

Definition at line 891 of file file.c.

References a_Dpip_dsh_new(), Clients, dList_append(), dNew, FILE_READ, and OLD_STYLE.

Referenced by main().

◆ File_check_fds()

static int File_check_fds ( uint_t  seconds)
static

Definition at line 1027 of file file.c.

References _MSG, Clients, dList_length(), dList_nth_data(), FILE_READ, FILE_WRITE, read_set, and write_set.

Referenced by main().

◆ File_close()

static void File_close ( int  fd)
static

Definition at line 117 of file file.c.

Referenced by File_content_type(), and File_remove_client().

◆ File_comp()

static int File_comp ( const FileInfo *  f1,
const FileInfo *  f2 
)
static

Definition at line 188 of file file.c.

Referenced by File_dillodir_new().

◆ File_content_type()

static const char * File_content_type ( const char *  filename)
static

Definition at line 531 of file file.c.

References _MSG, File_close(), File_ext(), and File_get_content_type_from_data().

Referenced by File_info2html(), and File_send_file().

◆ File_dillodir_free()

static void File_dillodir_free ( DilloDir *  Ddir)
static

Definition at line 268 of file file.c.

References dFree(), dList_free(), dList_length(), dList_nth_data(), and dReturn_if.

Referenced by File_remove_client().

◆ File_dillodir_new()

static DilloDir * File_dillodir_new ( char *  dirname)
static

◆ File_ext()

static const char * File_ext ( const char *  filename)
static

Definition at line 497 of file file.c.

References dStrAsciiCasecmp().

Referenced by File_content_type().

◆ File_get()

static void File_get ( ClientInfo *  client,
const char *  filename,
const char *  orig_url 
)
static

◆ File_get_content_type_from_data()

static const char * File_get_content_type_from_data ( void *  Data,
size_t  Size 
)
static

Definition at line 131 of file file.c.

References _MSG, dIsspace, dStrnAsciiCasecmp(), and MIN.

Referenced by File_content_type().

◆ File_info2html()

static void File_info2html ( ClientInfo *  client,
FileInfo *  finfo,
int  n 
)
static

◆ File_normalize_path()

static char * File_normalize_path ( const char *  orig)
static

◆ File_parse_hex_octet()

static int File_parse_hex_octet ( const char *  s)
static

Definition at line 780 of file file.c.

Referenced by File_normalize_path().

◆ File_prepare_send_dir()

static int File_prepare_send_dir ( ClientInfo *  client,
const char *  DirName,
const char *  orig_url 
)
static

Definition at line 611 of file file.c.

References dStr_append(), dStr_free(), dStr_new(), dStrdup(), File_dillodir_new(), FILE_WRITE, Dstr::len, st_start, Dstr::str, and TRUE.

Referenced by File_get().

◆ File_prepare_send_error_page()

static void File_prepare_send_error_page ( ClientInfo *  client,
int  res,
const char *  orig_url 
)
static

Definition at line 559 of file file.c.

References dStrdup(), FILE_WRITE, and st_err.

Referenced by File_get().

◆ File_prepare_send_file()

static int File_prepare_send_file ( ClientInfo *  client,
const char *  filename,
const char *  orig_url 
)
static

Definition at line 640 of file file.c.

References dStrdup(), FILE_WRITE, and st_start.

Referenced by File_get().

◆ File_print_mtime()

static void File_print_mtime ( ClientInfo *  client,
time_t  mtime 
)
static

Definition at line 314 of file file.c.

References a_Dpip_dsh_printf.

Referenced by File_info2html().

◆ File_print_parent_dir()

static void File_print_parent_dir ( ClientInfo *  client,
const char *  dirname 
)
static

Definition at line 289 of file file.c.

References a_Dpip_dsh_printf, dFree(), dStrdup(), Escape_html_str(), and Escape_uri_str().

Referenced by File_send_dir().

◆ File_remove_client()

static void File_remove_client ( ClientInfo *  client)
static

◆ File_send_dir()

◆ File_send_error_page()

static void File_send_error_page ( ClientInfo *  client)
static

◆ File_send_file()

◆ File_serve_client()

◆ File_serve_clients()

static void File_serve_clients ( void  )
static

Definition at line 1003 of file file.c.

References Clients, dList_nth_data(), FILE_DONE, FILE_ERR, File_remove_client(), File_serve_client(), read_set, and write_set.

Referenced by main().

◆ File_toggle_html_style()

static void File_toggle_html_style ( ClientInfo *  client)
static

Definition at line 866 of file file.c.

References a_Dpip_build_cmd(), a_Dpip_dsh_write_str(), dFree(), and OLD_STYLE.

Referenced by File_serve_client().

◆ main()

◆ termination_handler()

static void termination_handler ( int  signum)
static

Definition at line 879 of file file.c.

References MSG.

Referenced by main().

Variable Documentation

◆ Clients

Dlist* Clients
static

Definition at line 109 of file file.c.

Referenced by File_add_client(), File_check_fds(), File_remove_client(), File_serve_clients(), and main().

◆ DPIBYE

int DPIBYE = 0
static

Definition at line 106 of file file.c.

Referenced by File_serve_client(), and main().

◆ OLD_STYLE

int OLD_STYLE = 0
static

Definition at line 107 of file file.c.

Referenced by File_add_client(), and File_toggle_html_style().

◆ read_set

fd_set read_set

Definition at line 111 of file file.c.

Referenced by File_check_fds(), File_serve_clients(), and main().

◆ write_set

fd_set write_set

Definition at line 111 of file file.c.

Referenced by File_check_fds(), File_serve_clients(), and main().