Synchronet now requires the libarchive development package (e.g. libarchive-dev on Debian-based Linux distros, libarchive.org for more info) to build successfully.

Commit 8bb72401 authored by rswindell's avatar rswindell

Added DLL-export C version of timestr() for use in logging, etc.

parent 8ccc53b1
......@@ -142,3 +142,43 @@ char* DLLCALL hhmmtostr(scfg_t* cfg, struct tm* tm, char* str)
return(str);
}
/****************************************************************************/
/* Generates a 24 character ASCII string that represents the time_t pointer */
/* Used as a replacement for ctime() */
/****************************************************************************/
char* DLLCALL timestr(scfg_t* cfg, time_t *intime, char* str)
{
char* mer;
uchar hour;
struct tm* gm;
gm=localtime(intime);
if(gm==NULL) {
strcpy(str,"Invalid Time");
return(str);
}
if(cfg->sys_misc&SM_MILITARY) {
sprintf(str,"%s %s %02u %4u %02u:%02u:%02u"
,wday[gm->tm_wday],mon[gm->tm_mon],gm->tm_mday,1900+gm->tm_year
,gm->tm_hour,gm->tm_min,gm->tm_sec);
return(str);
}
if(gm->tm_hour>=12) {
if(gm->tm_hour==12)
hour=12;
else
hour=gm->tm_hour-12;
mer="pm";
} else {
if(gm->tm_hour==0)
hour=12;
else
hour=gm->tm_hour;
mer="am";
}
sprintf(str,"%s %s %02u %4u %02u:%02u %s"
,wday[gm->tm_wday],mon[gm->tm_mon],gm->tm_mday,1900+gm->tm_year
,hour,gm->tm_min,mer);
return(str);
}
......@@ -40,6 +40,7 @@
extern "C" BOOL DLLCALL hacklog(scfg_t* cfg, char* prot, char* user, char* text, char* host, SOCKADDR_IN* addr)
{
char hdr[512];
char tstr[64];
char fname[MAX_PATH+1];
int file;
time_t now=time(NULL);
......@@ -52,7 +53,7 @@ extern "C" BOOL DLLCALL hacklog(scfg_t* cfg, char* prot, char* user, char* text,
sprintf(hdr,"SUSPECTED %s HACK ATTEMPT from %s on %.24s\r\nUsing port %u at %s [%s]\r\nDetails: "
,prot
,user
,ctime(&now)
,timestr(cfg,&now,tstr)
,addr->sin_port
,host
,inet_ntoa(addr->sin_addr)
......@@ -69,6 +70,7 @@ extern "C" BOOL DLLCALL hacklog(scfg_t* cfg, char* prot, char* user, char* text,
extern "C" BOOL DLLCALL spamlog(scfg_t* cfg, char* prot, char* reason, char* host, char* ip_addr)
{
char hdr[512];
char tstr[64];
char fname[MAX_PATH+1];
int file;
time_t now=time(NULL);
......@@ -80,7 +82,7 @@ extern "C" BOOL DLLCALL spamlog(scfg_t* cfg, char* prot, char* reason, char* hos
sprintf(hdr,"SUSPECTED %s SPAM REJECTED on %.24s\r\nFrom: %s [%s]\r\nReason: "
,prot
,ctime(&now)
,timestr(cfg,&now,tstr)
,host
,ip_addr
);
......
......@@ -1517,7 +1517,7 @@ static void smtp_thread(void* arg)
if(usernum) {
sprintf(str,"\7\1n\1hOn %.24s\r\n\1m%s \1n\1msent you e-mail from: "
"\1h%s\1n\r\n"
,ctime((const time_t*)&newmsg.hdr.when_imported.time)
,timestr(&scfg,(time_t*)&newmsg.hdr.when_imported.time,tmp)
,sender,sender_addr);
if(!newmsg.idx.to) { /* Forwarding */
strcat(str,"\1mand it was automatically forwaded to: \1h");
......
......@@ -375,7 +375,7 @@ public:
bool gettimeleft_inside;
/* str.cpp */
char * timestr(time_t* intime); /* ASCII representation of time_t */
char* timestr(time_t *intime);
char timestr_output[60];
void userlist(char subonly);
size_t gettmplt(char *outstr, char *tmplt, long mode);
......@@ -773,7 +773,6 @@ extern "C" {
DLLEXPORT char * DLLCALL prep_dir(char* base, char* dir);
/* date_str.c */
/* ASCII date (MM/DD/YY) to unix conversion */
DLLEXPORT time_t DLLCALL dstrtounix(scfg_t*, char *str);
/* Unix time to ASCII date */
......@@ -782,6 +781,9 @@ extern "C" {
DLLEXPORT char * DLLCALL sectostr(uint sec, char *str);
/* struct tm to HH:MMa/p */
DLLEXPORT char * DLLCALL hhmmtostr(scfg_t* cfg, struct tm* tm, char* str);
/* time_t to ctime()-like string */
DLLEXPORT char * DLLCALL timestr(scfg_t* cfg, time_t *intime, char* str);
/* logfile.cpp */
DLLEXPORT BOOL DLLCALL hacklog(scfg_t* cfg, char* prot, char* user, char* text
......
......@@ -839,39 +839,7 @@ bool sbbs_t::trashcan(char *insearch, char *name)
return(result);
}
/****************************************************************************/
/* Generates a 24 character ASCII string that represents the time_t pointer */
/* Used as a replacement for ctime() */
/****************************************************************************/
char * sbbs_t::timestr(time_t *intime)
char* sbbs_t::timestr(time_t *intime)
{
char mer[3],hour;
struct tm *gm;
gm=localtime(intime);
if(gm==NULL) {
strcpy(timestr_output,"Invalid Time");
return(timestr_output); }
if(cfg.sys_misc&SM_MILITARY) {
sprintf(timestr_output,"%s %s %02d %4d %02d:%02d:%02d"
,wday[gm->tm_wday],mon[gm->tm_mon],gm->tm_mday,1900+gm->tm_year
,gm->tm_hour,gm->tm_min,gm->tm_sec);
return(timestr_output); }
if(gm->tm_hour>=12) {
if(gm->tm_hour==12)
hour=12;
else
hour=gm->tm_hour-12;
strcpy(mer,"pm"); }
else {
if(gm->tm_hour==0)
hour=12;
else
hour=gm->tm_hour;
strcpy(mer,"am"); }
sprintf(timestr_output,"%s %s %02d %4d %02d:%02d %s"
,wday[gm->tm_wday],mon[gm->tm_mon],gm->tm_mday,1900+gm->tm_year
,hour,gm->tm_min,mer);
return(timestr_output);
}
return(::timestr(&cfg,intime,timestr_output));
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment