-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutil.h
More file actions
103 lines (70 loc) · 1.99 KB
/
util.h
File metadata and controls
103 lines (70 loc) · 1.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#ifndef UTIL_H
#define UTIL_H
#define ACK 10
#define SOCKETERROR -1
#define PACKET BUFSIZE + HEADER
#define BUFFER BUFSIZE * 2
#define BACKLOG 64
#define POOL_THREADS 20
#define DOCUMENT_ROOT "./www"
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
#include <pthread.h>
#include <signal.h>
#include <sys/stat.h>
#include "queue.h"
#include <curl/curl.h>
#include <stddef.h>
#include <string.h>
// #include <pthread_rwlock.h>
// typedef struct my_rwlock_t my_rwlock_t;
// #include "rwlock.h"
typedef struct {
pthread_mutex_t lock;
pthread_cond_t readers_cond;
pthread_cond_t writers_cond;
int readers;
int writers;
int waiting_writers;
} my_rwlock_t;
typedef struct {
int client_socket;
int status;
char *filename; // add const if breaking changes occur
const char *url;
CURL *curl;
int fp;
my_rwlock_t * lock;
} callback_data;
typedef struct FileRWLock {
char *filename;
my_rwlock_t rwlock;
struct FileRWLock *next;
} FileRWLock;
// GLOBAL VARS
extern volatile sig_atomic_t flag;
extern int expire;
extern pthread_mutex_t list_mutex;
extern FileRWLock * file_rwlock_list;
// FUNCTIONS
int sendall(int s, char *buf, int *len);
int get_fsize(const char* file, struct stat st);
int check(int stat, char* message);
void connect_and_send(int * client_socket_fd);
void * thread_function();
size_t check_and_write(char *ptr, size_t size, size_t nmemb, void *userdata);
size_t header_callback(char *buffer, size_t size, size_t nitems, void *userdata);
char *get_hashed_filename(const char *path);
int file_exists(const char *filepath);
char *get_file_url(const char *path);
int is_host_blocked(const char *host);
// RW_LOCK
void free_file_rwlock_list();
my_rwlock_t *get_file_rwlock(const char *filename);
void my_rwlock_unlock(my_rwlock_t *rwlock);
void my_rwlock_wrlock(my_rwlock_t *rwlock);
void my_rwlock_rdlock(my_rwlock_t *rwlock);
void my_rwlock_destroy(my_rwlock_t *rwlock);
void my_rwlock_init(my_rwlock_t *rwlock);
#endif