mirror of
https://github.com/lxsang/ant-http
synced 2025-07-13 13:04:23 +02:00
add cache control to static file, remove unthread safe code
This commit is contained in:
31
lib/utils.c
31
lib/utils.c
@ -85,19 +85,26 @@ void removeAll(const char* path,int mode)
|
||||
|
||||
}
|
||||
|
||||
char* __time(time_t time)
|
||||
{
|
||||
struct tm *t = localtime(&time);
|
||||
char * buf = asctime(t);
|
||||
char* pos = strchr(buf,'\n');
|
||||
if(pos) *pos = '\0';
|
||||
return buf;
|
||||
}
|
||||
char* server_time()
|
||||
{
|
||||
return __time(time(NULL));
|
||||
}
|
||||
// WARNING:
|
||||
// TODO: remove it, this function is not thread-safe
|
||||
|
||||
void timestr(time_t time, char* buf,int len,char* format, int gmt)
|
||||
{
|
||||
struct tm t;
|
||||
if(gmt)
|
||||
{
|
||||
gmtime_r(&time, &t);
|
||||
}
|
||||
else
|
||||
{
|
||||
localtime_r(&time, &t);
|
||||
}
|
||||
strftime(buf, len, format, &t);
|
||||
}
|
||||
void server_time(char* buf, int len)
|
||||
{
|
||||
timestr(time(NULL), buf, len ,"%a, %d %b %Y %H:%M:%S", 0);
|
||||
}
|
||||
/**
|
||||
* Get extension of a file name
|
||||
* @param file The file name
|
||||
|
@ -56,12 +56,12 @@ THE SOFTWARE.
|
||||
#define false 0
|
||||
|
||||
#ifdef DEBUG
|
||||
#define LOG(a,...) server_log("%s: [%s: %d]: " a "\n",server_time(), __FILE__, \
|
||||
#define LOG(a,...) server_log(": [%s: %d]: " a "\n", __FILE__, \
|
||||
__LINE__, ##__VA_ARGS__)
|
||||
#else
|
||||
#define LOG(a,...) do{}while(0)
|
||||
#endif
|
||||
#define ERROR(a,...) error_log("%s: [%s: %d]: " a "\n", server_time() , __FILE__, \
|
||||
#define ERROR(a,...) error_log(": [%s: %d]: " a "\n", __FILE__, \
|
||||
__LINE__, ##__VA_ARGS__)
|
||||
// add this to the utils
|
||||
#define UNUSED(x) (void)(x)
|
||||
@ -83,8 +83,8 @@ dictionary_t __attribute__((weak)) mimes_list();
|
||||
char* __s(const char*,...);
|
||||
void trim(char*,const char);
|
||||
void removeAll(const char* path,int mode);
|
||||
char* __time(time_t time);
|
||||
char* server_time();
|
||||
void timestr(time_t time, char* buf,int len,char* format, int gmt);
|
||||
void server_time(char* , int );
|
||||
char* ext(const char*);
|
||||
char* mime(const char*);
|
||||
int match_int(const char*);
|
||||
|
Reference in New Issue
Block a user