Add magimail (crashmail2 fork) to repo

This commit is contained in:
Andrew Pamment
2017-03-18 23:04:38 +10:00
parent 8fad85affc
commit 807574ccf4
98 changed files with 23583 additions and 7 deletions

View File

@@ -0,0 +1,34 @@
INCDIR = ../
CC = gcc $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) -Wall -I $(INCDIR) -DPLATFORM_LINUX -g
AR = ar -ru
RM = rm -f
OBJS = osfile.o osdir.o osmisc.o osmem.o ospattern.o os.o
oslib.a : $(OBJS)
$(AR) oslib.a $(OBJS)
# os
osfile.o : osfile.c
$(CC) -c osfile.c -o osfile.o
osmisc.o : osmisc.c
$(CC) -c osmisc.c -o osmisc.o
osdir.o : osdir.c
$(CC) -c osdir.c -o osdir.o
osmem.o : osmem.c
$(CC) -c osmem.c -o osmem.o
ospattern.o : ospattern.c
$(CC) -c ospattern.c -o ospattern.o
os.o : os.c
$(CC) -c os.c -o os.o
clean :
$(RM) *.o *.a

View File

@@ -0,0 +1,13 @@
#include <stdio.h>
#include <oslib/os.h>
bool osInit(void)
{
return(TRUE);
}
void osEnd(void)
{
}

View File

@@ -0,0 +1,33 @@
#include <stddef.h>
#include <stdint.h>
typedef uint16_t UINT16; /* Unsigned 16-bit integer */
#define OS_EXIT_ERROR 10
#define OS_EXIT_OK 0
#define OS_PLATFORM_NAME "Linux"
#define OS_PATH_CHARS "/"
#define OS_CURRENT_DIR "."
#define OS_CONFIG_NAME "crashmail.prefs"
#define OS_CONFIG_VAR "CMCONFIGFILE"
#define OS_HAS_SYSLOG
/*
OS_PATH_CHARS is used by MakeFullPath. If path doesn't end with one of these characters,
the first character will be appended to it.
Example:
OS_PATH_CHARS = "/:"
"inbound" + "file" --> "inbound/file"
"inbound/" + "file" --> "inbound/file"
"inbound:" + "file" --> "inbound/file"
*/
#define stricmp strcasecmp
#define strnicmp strncasecmp

View File

@@ -0,0 +1,100 @@
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <stdarg.h>
#include <stdio.h>
#include <time.h>
#include <dirent.h>
#include <sys/stat.h>
#include <shared/types.h>
#include <shared/jblist.h>
#include <shared/mystrncpy.h>
#include <shared/path.h>
#include <oslib/osmem.h>
#include <oslib/osdir.h>
bool osReadDir(char *dirname,struct jbList *filelist,bool (*acceptfunc)(char *filename))
{
DIR *dir;
struct dirent *dirent;
struct osFileEntry *tmp;
char buf[200];
jbNewList(filelist);
if(!(dir=opendir(dirname)))
return(FALSE);
while((dirent=readdir(dir)))
{
bool add;
if(!acceptfunc) add=TRUE;
else add=(*acceptfunc)(dirent->d_name);
if(add)
{
struct stat st;
MakeFullPath(dirname,dirent->d_name,buf,200);
if(stat(buf,&st) == 0)
{
if(!(tmp=(struct osFileEntry *)osAllocCleared(sizeof(struct osFileEntry))))
{
jbFreeList(filelist);
closedir(dir);
return(FALSE);
}
mystrncpy(tmp->Name,dirent->d_name,100);
tmp->Size=st.st_size;
tmp->Date=st.st_mtime;
jbAddNode(filelist,(struct jbNode *)tmp);
}
}
}
closedir(dir);
return(TRUE);
}
bool osScanDir(char *dirname,void (*func)(char *file))
{
DIR *dir;
struct dirent *dirent;
if(!(dir=opendir(dirname)))
return(FALSE);
while((dirent=readdir(dir)))
(*func)(dirent->d_name);
closedir(dir);
return(TRUE);
}
struct osFileEntry *osGetFileEntry(char *file)
{
struct stat st;
struct osFileEntry *tmp;
if(stat(file,&st) != 0)
return(FALSE);
if(!(tmp=(struct osFileEntry *)osAllocCleared(sizeof(struct osFileEntry))))
return(FALSE);
mystrncpy(tmp->Name,GetFilePart(file),100);
tmp->Size=st.st_size;
tmp->Date=st.st_mtime;
return(tmp);
}

View File

@@ -0,0 +1,143 @@
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <stdarg.h>
#include <stdio.h>
#include <shared/types.h>
#include <oslib/osfile.h>
osFile osOpen(char *name,uint32_t mode)
{
FILE *fh;
if(mode == MODE_NEWFILE)
{
fh=fopen(name,"wb");
}
else if(mode == MODE_OLDFILE)
{
fh=fopen(name,"rb");
}
else
{
if(!(fh=fopen(name,"r+b")))
fh=fopen(name,"w+b");
}
return (osFile) fh;
}
void osClose(osFile os)
{
fclose((FILE *)os);
}
int osGetChar(osFile os)
{
int c;
c=fgetc((FILE *)os);
if(c==EOF)
c=-1;
return(c);
}
uint32_t osRead(osFile os,void *buf,uint32_t bytes)
{
return fread(buf,1,bytes,(FILE *)os);
}
bool osPutChar(osFile os, char ch)
{
if(fputc(ch,(FILE *)os)==EOF)
return(FALSE);
return(TRUE);
}
bool osWrite(osFile os,const void *buf,uint32_t bytes)
{
if(fwrite(buf,1,bytes,(FILE *)os)!=bytes)
return(FALSE);
return(TRUE);
}
bool osPuts(osFile os,char *str)
{
if(fputs(str,(FILE *)os)==EOF)
return(FALSE);
return(TRUE);
}
uint32_t osFGets(osFile os,char *str,uint32_t max)
{
char *s;
s=fgets(str,max,(FILE *)os);
if(s)
{
if(strlen(s)>=2 && s[strlen(s)-1]==10 && s[strlen(s)-2]==13)
{
/* CRLF -> LF */
s[strlen(s)-2]=10;
s[strlen(s)-1]=0;
}
return (uint32_t)strlen(s);
}
return(0);
}
off_t osFTell(osFile os)
{
return ftello((FILE *)os);
}
bool osFPrintf(osFile os,char *fmt,...)
{
va_list args;
int res;
va_start(args, fmt);
res=vfprintf(os,fmt,args);
va_end(args);
if(!res)
return(FALSE);
return(TRUE);
}
bool osVFPrintf(osFile os,char *fmt,va_list args)
{
int res;
res=vfprintf(os,fmt,args);
if(!res)
return(FALSE);
return(TRUE);
}
void osSeek(osFile fh,off_t offset,short mode)
{
int md;
if(mode == OFFSET_BEGINNING)
md=SEEK_SET;
if(mode == OFFSET_END)
md=SEEK_END;
fseeko((FILE *)fh,offset,md);
}

View File

@@ -0,0 +1,19 @@
#include <stdlib.h>
#include <stdint.h>
#include <oslib/osmem.h>
void *osAlloc(uint32_t size)
{
return malloc((size_t)size);
}
void *osAllocCleared(uint32_t size)
{
return calloc((size_t)size,1);
}
void osFree(void *buf)
{
free(buf);
}

View File

@@ -0,0 +1,99 @@
#include <stdint.h>
#include <string.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <shared/types.h>
#include <shared/jblist.h>
#include <oslib/osmisc.h>
#include <sys/stat.h>
#include <sys/wait.h>
#include <unistd.h>
void osSetComment(char *file,char *comment)
{
/* Does not exist in this os */
}
/* Returns -1 if dir was not found and errorlevel otherwise */
int osChDirExecute(char *dir,char *cmd)
{
char olddir[300];
int res;
if(!getcwd(olddir,300))
return(-1);
if(chdir(dir) != 0)
return(-1);
res=osExecute(cmd);
chdir(olddir);
return(res);
}
int osExecute(char *cmd)
{
int res;
res=system(cmd);
return WEXITSTATUS(res);
}
bool osExists(char *file)
{
struct stat st;
if(stat(file,&st) == 0)
return(TRUE);
return(FALSE);
}
bool osMkDir(char *dir)
{
if(mkdir(dir,0777) != 0)
return(FALSE);
return(TRUE);
}
bool osRename(char *oldfile,char *newfile)
{
if(rename(oldfile,newfile) == 0)
return(TRUE);
return(FALSE);
}
bool osDelete(char *file)
{
if(remove(file) == 0)
return(TRUE);
return(FALSE);
}
void osSleep(int secs)
{
sleep(secs);
}
char *osErrorMsg(uint32_t errnum)
{
return (char *)strerror(errnum);
}
uint32_t osError(void)
{
return (uint32_t)errno;
}

View File

@@ -0,0 +1,40 @@
#include <string.h>
#include <ctype.h>
#include <oslib/os.h>
#include <oslib/ospattern.h>
bool osCheckPattern(char *pattern)
{
return(TRUE);
}
bool osMatchPattern(char *pattern,char *str)
{
int c;
for(c=0;pattern[c];c++)
{
if(pattern[c]=='*')
return(TRUE);
if(str[c] == 0)
return(FALSE);
if(pattern[c]!='?' && tolower(pattern[c])!=tolower(str[c]))
return(FALSE);
}
if(str[c]!=0)
return(FALSE);
return(TRUE);
}
bool osIsPattern(char *pat)
{
if(strchr(pat,'?') || strchr(pat,'*'))
return(TRUE);
return(FALSE);
}