2015-11-24 17:58:32 +01:00
|
|
|
/*
|
|
|
|
The MIT License (MIT)
|
|
|
|
|
|
|
|
Copyright (c) 2015 LE Xuan Sang xsang.le@gmail.com
|
|
|
|
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
|
|
in the Software without restriction, including without limitation the rights
|
|
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
|
|
furnished to do so, subject to the following conditions:
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
all copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
THE SOFTWARE.
|
|
|
|
*/
|
|
|
|
#ifndef UTILS_H
|
|
|
|
#define UTILS_H
|
2020-08-25 16:40:24 +02:00
|
|
|
|
2015-10-22 11:39:11 +02:00
|
|
|
#include <regex.h>
|
2020-02-12 12:08:36 +01:00
|
|
|
#include <syslog.h>
|
2020-08-25 16:40:24 +02:00
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdlib.h>
|
2021-01-01 13:21:26 +01:00
|
|
|
#include <time.h>
|
2021-01-01 13:26:51 +01:00
|
|
|
#include <sys/stat.h>
|
2020-08-25 16:40:24 +02:00
|
|
|
|
2019-12-15 12:10:06 +01:00
|
|
|
#include "dictionary.h"
|
2015-10-22 11:39:11 +02:00
|
|
|
|
2016-10-31 22:18:24 +01:00
|
|
|
#define LEFTROTATE(x, c) (((x) << (c)) | ((x) >> (32 - (c))))
|
2015-10-22 11:39:11 +02:00
|
|
|
#define EQU(a,b) (strcmp(a,b) == 0)
|
|
|
|
#define IEQU(a,b) (strcasecmp(a,b) == 0)
|
|
|
|
#define IS_INT(a) (match_int(a))
|
|
|
|
#define IS_FLOAT(a) (match_float(a))
|
2016-02-26 14:32:13 +01:00
|
|
|
#define FILE_OK(f) ( access( f, F_OK ) != -1 )
|
2015-10-22 11:39:11 +02:00
|
|
|
#define DIR_SEP "/"
|
|
|
|
#define true 1
|
|
|
|
#define false 0
|
2019-12-20 16:49:41 +01:00
|
|
|
|
2021-10-08 22:33:16 +02:00
|
|
|
#define LOG(a,...) syslog (LOG_NOTICE,"ANTD_LOG@[%s: %d]: " a "\n", __FILE__, \
|
2015-10-22 11:39:11 +02:00
|
|
|
__LINE__, ##__VA_ARGS__)
|
2020-02-12 12:27:12 +01:00
|
|
|
#define ERROR(a,...) syslog (LOG_ERR, "ANTD_ERROR@[%s: %d]: " a "\n", __FILE__, \
|
2019-12-11 23:17:42 +01:00
|
|
|
__LINE__, ##__VA_ARGS__)
|
2018-09-25 17:51:56 +02:00
|
|
|
// add this to the utils
|
|
|
|
#define UNUSED(x) (void)(x)
|
|
|
|
|
2015-11-24 17:58:32 +01:00
|
|
|
#define BUFFLEN 1024
|
|
|
|
#define HASHSIZE 1024
|
2016-12-17 12:28:05 +01:00
|
|
|
|
|
|
|
typedef struct{
|
|
|
|
const char* type;
|
2019-12-15 12:10:06 +01:00
|
|
|
const char* ext;
|
2016-12-17 12:28:05 +01:00
|
|
|
} mime_t;
|
|
|
|
|
2019-12-15 12:10:06 +01:00
|
|
|
dictionary_t __attribute__((weak)) mimes_list();
|
2015-10-22 11:39:11 +02:00
|
|
|
char* __s(const char*,...);
|
|
|
|
void trim(char*,const char);
|
|
|
|
void removeAll(const char* path,int mode);
|
2020-01-10 17:31:49 +01:00
|
|
|
void timestr(time_t time, char* buf,int len,char* format, int gmt);
|
|
|
|
void server_time(char* , int );
|
2015-10-22 11:39:11 +02:00
|
|
|
char* ext(const char*);
|
|
|
|
char* mime(const char*);
|
|
|
|
int match_int(const char*);
|
|
|
|
int match_float(const char*);
|
2018-02-04 19:46:47 +01:00
|
|
|
int regex_match(const char*,const char*, int, regmatch_t*);
|
2019-12-20 16:49:41 +01:00
|
|
|
int mkdirp(const char* path,mode_t mode);
|
2015-10-22 11:39:11 +02:00
|
|
|
char *url_decode(const char *str);
|
|
|
|
char *url_encode(const char *str);
|
|
|
|
char from_hex(char ch);
|
|
|
|
char to_hex(char code);
|
2016-12-17 12:28:05 +01:00
|
|
|
mime_t mime_from_type(const char* type);
|
|
|
|
mime_t mime_from_ext(const char* ex);
|
2015-11-24 17:58:32 +01:00
|
|
|
unsigned hash(const char*, int);
|
2016-10-31 17:34:20 +01:00
|
|
|
unsigned simple_hash(const char*);
|
2016-10-30 16:14:04 +01:00
|
|
|
int is_file(const char* f);
|
2016-12-15 14:46:50 +01:00
|
|
|
int is_dir(const char* f);
|
|
|
|
int _exist(const char* f);
|
2016-10-31 22:18:24 +01:00
|
|
|
void md5(uint8_t *, size_t , char*);
|
2016-11-01 18:30:45 +01:00
|
|
|
void sha1(const char*, char*);
|
2018-10-07 15:09:46 +02:00
|
|
|
void digest_to_hex(const uint8_t *, char *);
|
2020-01-09 12:18:59 +01:00
|
|
|
void verify_header(char* k);
|
2021-01-03 11:24:55 +01:00
|
|
|
int guard_read(int fd, void* buffer, size_t size);
|
|
|
|
int guard_write(int fd, void* buffer, size_t size);
|
2021-01-22 01:12:26 +01:00
|
|
|
int request_socket(const char *ip, int port);
|
|
|
|
char* ip_from_hostname(const char *hostname);
|
2015-11-24 17:58:32 +01:00
|
|
|
#endif
|