ant-http/libs/utils.h

110 lines
3.3 KiB
C
Raw Normal View History

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
2015-10-22 11:39:11 +02:00
#include <stdio.h>
#include <stdarg.h>
#include <unistd.h>
#include <strings.h>
#include <string.h>
#include <stdlib.h>
#include <dirent.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <ctype.h>
#include <regex.h>
#include <time.h>
2016-10-31 22:18:24 +01:00
#include <stdint.h>
2018-02-10 11:22:41 +01:00
#ifdef USE_OPENSSL
#include <openssl/sha.h>
#else
2016-11-01 18:30:45 +01:00
#include "sha1.h"
2018-02-10 11:22:41 +01:00
#endif
#include "base64.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))
#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
#ifdef DEBUG
#define LOG(a,...) printf("%s:%d: " a, __FILE__, \
__LINE__, ##__VA_ARGS__)
#else
#define LOG(a,...) do{}while(0)
#endif
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
#define DHASHSIZE 50
#define RPC_TYPE_ARRAY 601//hash("array")
#define RPC_TYPE_BASE64 335//hash("base64")
#define RPC_TYPE_BOOL 40//hash("boolean")
#define RPC_TYPE_DOUBLE 977//hash("double")
#define RPC_TYPE_DATE 49//hash("dateTime.iso8601")
#define RPC_TYPE_INT 1007//hash("int")
#define RPC_TYPE_I4 235//hash("i4")
#define RPC_TYPE_STRING 17//hash("string")
#define RPC_TYPE_NIL 529//hash("nil")
2016-12-17 12:28:05 +01:00
typedef struct{
const char* type;
const char** ext;
int bin;
} mime_t;
2015-10-22 11:39:11 +02:00
char* __s(const char*,...);
void trim(char*,const char);
void removeAll(const char* path,int mode);
char* __time(time_t time);
char* server_time();
char* ext(const char*);
char* mime(const char*);
int is_bin(const char*);
int match_int(const char*);
int match_float(const char*);
int regex_match(const char*,const char*, int, regmatch_t*);
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 *);
2015-11-24 17:58:32 +01:00
#endif