Switch to the separate maildir module.
authorFrantišek Dvořák <valtri@civ.zcu.cz>
Tue, 1 Apr 2008 09:56:04 +0000 (09:56 +0000)
committerFrantišek Dvořák <valtri@civ.zcu.cz>
Tue, 1 Apr 2008 09:56:04 +0000 (09:56 +0000)
org.glite.lb.common/Makefile
org.glite.lb.common/interface/lb_maildir.h [deleted file]
org.glite.lb.common/src/lb_maildir.c [deleted file]
org.glite.lb.server/Makefile
org.glite.lb.server/src/bkserverd.c
org.glite.lb.server/src/db_store.c
org.glite.lb.utils/Makefile
org.glite.lb.utils/src/dump_exporter.c

index 4a7b782..fd46414 100644 (file)
@@ -80,19 +80,16 @@ INSTALL:=libtool --mode=install install
 OBJS:=${JOBID_OBJS} ${PERF_OBJS} lb_plain_io.o events.o mini_http.o query_rec.o \
        status.o xml_conversions.o xml_parse.o ulm_parse.o param.o \
        events_parse.o il_string.o il_int.o notifid.o \
-       il_log.o il_msg.o log_msg.o context.o lb_maildir.o \
+       il_log.o il_msg.o log_msg.o context.o \
        connpool.o 
 LOBJS:=${OBJS:.o=.lo}
 
-MAILDIR_OBJS:=lb_maildir.lo
-MAILDIR_LIB:=libglite_lb_maildir.la
-
 THROBJS:=${OBJS:.o=.thr.o}
 THRLOBJS:=${OBJS:.o=.thr.lo}
 
 HDRS:=context.h context-int.h lb_plain_io.h mini_http.h authz.h xml_parse.h \
        xml_conversions.h log_proto.h events_parse.h il_string.h il_msg.h \
-       ulm_parse.h lb_maildir.h connpool.h notifid.h notif_rec.h padstruct.h \
+       ulm_parse.h connpool.h notifid.h notif_rec.h padstruct.h \
        query_rec.h timeouts.h LoggingExceptions.h CountRef.h ${PERF_HDRS} 
 GEN_HDRS:=Event.h events.h jobstat.h common_version.h
 
@@ -122,7 +119,7 @@ generate: ${GEN_HDRS}
 common_version.h: ${top_srcdir}/project/version.properties
        echo "#define GLITE_LB_COMMON_VERSION \"${version}\"" >$@
 
-all compile: generate ${STATICLIB} ${LTLIB} ${THRSTATICLIB} ${THRLTLIB} ${MAILDIR_LIB}
+all compile: generate ${STATICLIB} ${LTLIB} ${THRSTATICLIB} ${THRLTLIB}
 
 # In order to use libtool versioning correcty, we must have:
 #
@@ -143,9 +140,6 @@ ${STATICLIB}: ${OBJS}
        ar crv $@ ${OBJS}
        ranlib $@
 
-${MAILDIR_LIB}: ${MAILDIR_OBJS}
-       ${LINK} ${version_info} -o $@ ${MAILDIR_OBJS}
-
 ${THRSTATICLIB}: ${THROBJS}
        ar crv $@ ${THROBJS}
        ranlib $@
@@ -207,7 +201,7 @@ olddoc: generate events.tex status.tex
 install: 
        mkdir -p ${PREFIX}/lib
        mkdir -p ${PREFIX}/share/doc/${package}-${version}
-       ${INSTALL} -m 644 ${LTLIB} ${THRLTLIB} ${MAILDIR_LIB} ${PREFIX}/lib
+       ${INSTALL} -m 644 ${LTLIB} ${THRLTLIB} ${PREFIX}/lib
        ${INSTALL} -m 644 ${top_srcdir}/LICENSE ${PREFIX}/share/doc/${package}-${version}
 #      cp -r C CPP ${PREFIX}/share/doc/${package}-${version}
        if [ x${DOSTAGE} = xyes ]; then \
diff --git a/org.glite.lb.common/interface/lb_maildir.h b/org.glite.lb.common/interface/lb_maildir.h
deleted file mode 100644 (file)
index 49c5175..0000000
+++ /dev/null
@@ -1,24 +0,0 @@
-#ifndef GLITE_LB_MAILDIR_H
-#define GLITE_LB_MAILDIR_H
-
-/*
- * Functions for reading and writing messages via
- * maildir protocol.
- * Used when registering job to the JP, i.e.
- */
-
-enum {
-       LBMD_TRANS_OK,
-       LBMD_TRANS_FAILED,
-       LBMD_TRANS_FAILED_RETRY,
-};
-       
-extern char lbm_errdesc[];
-
-extern int edg_wll_MaildirInit(const char *);
-extern int edg_wll_MaildirStoreMsg(const char *, const char *, const char *);
-extern int edg_wll_MaildirRetryTransStart(const char *, time_t, time_t, char **, char **);
-extern int edg_wll_MaildirTransStart(const char *, char **, char **);
-extern int edg_wll_MaildirTransEnd(const char *, char *, int);
-
-#endif /* GLITE_LB_MAILDIR_H */
diff --git a/org.glite.lb.common/src/lb_maildir.c b/org.glite.lb.common/src/lb_maildir.c
deleted file mode 100644 (file)
index 2784305..0000000
+++ /dev/null
@@ -1,394 +0,0 @@
-#include <stdio.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <dirent.h>
-#include <time.h>
-#include <fcntl.h>
-#include <sys/time.h>
-#include <errno.h>
-#include <string.h>
-
-#include "glite/lb/lb_maildir.h"
-
-#define DEFAULT_ROOT   "/tmp/lb_maildir"
-
-enum {
-       LBMD_DIR_TMP = 0,
-       LBMD_DIR_NEW,
-       LBMD_DIR_WORK,
-       LBMD_DIR_POST,
-       LBMD_DIR_UNDELIVERABLE
-};
-
-static const char *dirs[] = { "tmp", "new", "work", "post", "undeliverable" };
-
-
-#define MAX_ERR_LEN            1024
-char lbm_errdesc[MAX_ERR_LEN];
-
-
-static int check_mkdir(const char *dir)
-{
-       struct stat sbuf;
-
-       if ( stat(dir, &sbuf) ) {
-               if ( errno == ENOENT ) {
-                       if ( mkdir(dir, S_IRWXU) ) return 1;
-                       if ( stat(dir, &sbuf) )  return 1;
-               }
-               else return 1;
-       }
-
-       if (!S_ISDIR(sbuf.st_mode)) return 1;
-
-       if (access(dir, R_OK | W_OK)) return 1;
-
-       return 0;
-}
-
-
-int edg_wll_MaildirInit(
-       const char                 *dir)
-{
-       const char *root = dir? : DEFAULT_ROOT;
-       char            dirname[PATH_MAX];
-       int                     i;
-
-       if ( check_mkdir(root) ) {
-               snprintf(lbm_errdesc, MAX_ERR_LEN, "%s: %s\n", root, strerror(errno));
-               return 1;
-       }
-       
-       for ( i = 0; i < sizeof(dirs)/sizeof((dirs)[0]); i++ ) {
-               snprintf(dirname, PATH_MAX, "%s/%s", root, dirs[i]);
-               if ( check_mkdir(dirname) ) {
-                       snprintf(lbm_errdesc, MAX_ERR_LEN, "%s: %s\n", dirname, strerror(errno));
-                       return 1;
-               }
-       }
-
-       return 0;
-}
-
-
-int edg_wll_MaildirStoreMsg(
-       const char      *root,
-       const char      *srvname,
-       const char      *msg)
-{
-       char    fname[PATH_MAX],
-               newfname[PATH_MAX];
-       int     fhnd,
-               written,
-               msgsz,
-               ct, i;
-       struct  timeval  tv;
-
-
-       if ( !root ) root = DEFAULT_ROOT;
-
-       errno = 0;
-       i = 0;
-       while ( 1 ) {
-               if ( ++i > 10 ) {
-                       errno = ECANCELED;
-                       snprintf(lbm_errdesc, MAX_ERR_LEN, "Maximum tries limit reached with unsuccessful file creation");
-                       return -1;
-               }
-               gettimeofday(&tv, NULL);
-               snprintf(fname, PATH_MAX, "%s/%s/%ld_%ld.%s", root, dirs[LBMD_DIR_TMP], tv.tv_sec, tv.tv_usec, srvname);
-               if ( (fhnd = open(fname, O_CREAT|O_EXCL|O_WRONLY, 00600)) < 0 ) {
-                       if ( errno == EEXIST ) { usleep(1000); continue; }
-                       snprintf(lbm_errdesc, MAX_ERR_LEN, "Can't create file %s", fname);
-                       return -1;
-               }
-               break;
-       }
-
-       msgsz = strlen(msg);
-       written = 0;
-       while ( written < msgsz ) {
-               if ( (ct = write(fhnd, msg+written, msgsz-written)) < 0 ) {
-                       if ( errno == EINTR ) { errno = 0; continue; }
-                       snprintf(lbm_errdesc, MAX_ERR_LEN, "Can't write into file %s", fname);
-                       return -1;
-               }
-               written += msgsz;
-       }
-       if ( fsync(fhnd) ) {
-               snprintf(lbm_errdesc, MAX_ERR_LEN, "Can't fsync file %s", fname);
-               return -1;
-       }
-       if ( close(fhnd) ) {
-               snprintf(lbm_errdesc, MAX_ERR_LEN, "Can't close file %s", fname);
-               return -1;
-       }
-       snprintf(newfname, PATH_MAX, "%s/%s/%s", root, dirs[LBMD_DIR_NEW], strrchr(fname, '/')+1);
-       if ( link(fname, newfname) ) {
-               snprintf(lbm_errdesc, MAX_ERR_LEN, "Can't link new file %s", newfname);
-               return -1;
-       }
-
-       return 0;
-}
-
-
-int edg_wll_MaildirTransEnd(
-       const char                 *root,
-       char                       *fname,
-       int                                     tstate)
-{
-       char            workfname[PATH_MAX],
-                               newfname[PATH_MAX],
-                               origfname[PATH_MAX];
-       struct stat     st;
-
-
-       if ( !root ) root = DEFAULT_ROOT;
-
-       snprintf(workfname, PATH_MAX, "%s/%s/%s", root, dirs[LBMD_DIR_WORK], fname);
-       unlink(workfname);
-
-       snprintf(origfname, PATH_MAX, "%s/%s/%s", root, dirs[LBMD_DIR_TMP], fname);
-       if ( tstate == LBMD_TRANS_OK ) {
-               unlink(origfname);
-               return 0;
-       }
-
-       if ( tstate == LBMD_TRANS_FAILED ) return 0;
-
-       if ( stat(origfname, &st) ) {
-               snprintf(lbm_errdesc, MAX_ERR_LEN, "Can't stat file '%s'", origfname);
-               return -1;
-       }
-
-       snprintf(newfname, PATH_MAX, "%s/%s/%s", root, dirs[LBMD_DIR_POST], fname);
-       if ( link(origfname, newfname) ) {
-               snprintf(lbm_errdesc, MAX_ERR_LEN, "Can't link new file %s", newfname);
-               return -1;
-       }
-
-       return 0;
-}
-
-
-int edg_wll_MaildirRetryTransStart(
-       const char      *root,
-       time_t          retry,
-       time_t          remove,
-       char            **msg,
-       char            **fname)
-{
-       static DIR      *dir = NULL;
-       struct dirent   *ent;
-       time_t          tlimit_retry, tlimit_remove;
-       struct stat     st;
-       char            newfname[PATH_MAX],
-                       oldfname[PATH_MAX],
-                       *buf = NULL;
-       int             fhnd,
-                       toread, ct,
-                       bufsz, bufuse;
-
-
-       if ( !root ) root = DEFAULT_ROOT;
-
-       if ( !dir ) {
-               char    dirname[PATH_MAX];
-               snprintf(dirname, PATH_MAX, "%s/%s", root, dirs[LBMD_DIR_POST]);
-               if ( !(dir = opendir(dirname)) ) {
-                       snprintf(lbm_errdesc, MAX_ERR_LEN, "Can't open directory '%s'", root);
-                       goto err;
-               }
-       }
-
-       tlimit_retry = time(NULL) - retry;
-       tlimit_remove = time(NULL) - remove;
-       do {
-               errno = 0;
-               if ( !(ent = readdir(dir)) ) {
-                       if ( errno == EBADF ) {
-                               snprintf(lbm_errdesc, MAX_ERR_LEN, "Can't read directory '%s'", root);
-                               dir = NULL;
-                               goto err;
-                       } else {
-                               closedir(dir);
-                               dir = NULL;
-                               return 0;
-                       }
-               }
-               if ( ent->d_name[0] == '.' ) continue;
-
-               snprintf(oldfname, PATH_MAX, "%s/%s/%s", root, dirs[LBMD_DIR_POST], ent->d_name);
-               snprintf(newfname, PATH_MAX, "%s/%s/%s", root, dirs[LBMD_DIR_WORK], ent->d_name);
-
-               if ( stat(oldfname, &st) < 0 ) {
-                       snprintf(lbm_errdesc, MAX_ERR_LEN, "Can't stat file '%s'", oldfname);
-                       goto err;
-               }
-
-               /* if we cannot deliver the file for 'remove' time limit, */
-               /* it is moved to undeliverable folder and forgotten      */
-               if ( st.st_mtime < tlimit_remove ) {
-                       snprintf(newfname, PATH_MAX, "%s/%s/%s",
-                                root, dirs[LBMD_DIR_UNDELIVERABLE], ent->d_name);
-               }
-               /* try to deliver file every 'retry' seconds */
-               else if ( st.st_ctime > tlimit_retry ) continue;
-
-
-               if ( rename(oldfname, newfname) ) {
-                       if ( errno == ENOENT ) {
-                               /* maybe some other instance moved this file away... */
-                               continue;
-                       } else {
-                               snprintf(lbm_errdesc, MAX_ERR_LEN, "Can't move file '%s'", oldfname);
-                               goto err;
-                       }
-               } else {
-                       if (st.st_mtime < tlimit_remove) {
-                               /* we have moved undeliverable file to undeliverable folder */
-                               /* no other action needed */
-                               snprintf(oldfname, PATH_MAX, "%s/%s/%s", root, dirs[LBMD_DIR_TMP], ent->d_name);
-                               unlink(oldfname);
-                               continue;
-                       } else {
-                               /* we have found and moved the file  to work folder */
-                               /* going to process it */
-                               break;
-                       }
-               }
-       } while ( 1 );
-
-       if ( (fhnd = open(newfname, O_RDONLY)) < 0 ) {
-               snprintf(lbm_errdesc, MAX_ERR_LEN, "Can't open file '%s'", newfname);
-               goto err;
-       }
-
-       bufuse = bufsz = toread = ct = 0;
-       do {
-               errno = 0;
-               if ( bufuse == bufsz ) {
-                       char *tmp = realloc(buf, bufsz+BUFSIZ);
-                       if ( !tmp ) goto err;
-                       buf = tmp;
-                       bufsz += BUFSIZ;
-               }
-               toread = bufsz - bufuse;
-               if ( (ct = read(fhnd, buf+bufuse, toread)) < 0 ) {
-                       if ( errno == EINTR ) continue;
-                       snprintf(lbm_errdesc, MAX_ERR_LEN, "Can't read file '%s'", newfname);
-                       goto err;
-               }
-               if ( ct == 0 ) break;
-               bufuse += ct;
-       } while ( ct == toread );
-       close(fhnd);
-
-       if ( !(*fname = strdup(ent->d_name)) ) goto err;
-       buf[bufuse] = 0;
-       *msg = buf;
-       return 1;
-
-
-err:
-       if ( buf ) free(buf);
-
-       return -1;
-}
-
-
-int edg_wll_MaildirTransStart(
-       const char                 *root,
-       char              **msg,
-       char                      **fname)
-{
-       static DIR         *dir = NULL;
-       struct dirent  *ent;
-       char                    newfname[PATH_MAX],
-                                       oldfname[PATH_MAX],
-                                  *buf = NULL;
-       int                             fhnd,
-                                       toread, ct,
-                                       bufsz, bufuse;
-
-
-       if ( !root ) root = DEFAULT_ROOT;
-
-       if ( !dir ) {
-               char    dirname[PATH_MAX];
-               snprintf(dirname, PATH_MAX, "%s/%s", root, dirs[LBMD_DIR_NEW]);
-               if ( !(dir = opendir(dirname)) ) {
-                       snprintf(lbm_errdesc, MAX_ERR_LEN, "Can't open directory '%s'", root);
-                       goto err;
-               }
-       }
-
-       do {
-               errno = 0;
-               if ( !(ent = readdir(dir)) ) {
-                       if ( errno == EBADF ) {
-                               snprintf(lbm_errdesc, MAX_ERR_LEN, "Can't read directory '%s'", root);
-                               dir = NULL;
-                               goto err;
-                       } else {
-                               closedir(dir);
-                               dir = NULL;
-                               return 0;
-                       }
-               }
-               if ( ent->d_name[0] == '.' ) continue;
-               snprintf(newfname, PATH_MAX, "%s/%s/%s", root, dirs[LBMD_DIR_WORK], ent->d_name);
-               snprintf(oldfname, PATH_MAX, "%s/%s/%s", root, dirs[LBMD_DIR_NEW], ent->d_name);
-               if ( rename(oldfname, newfname) ) {
-                       if ( errno == ENOENT ) {
-                               /* maybe some other instance moved this file away... */
-                               continue;
-                       } else {
-                               snprintf(lbm_errdesc, MAX_ERR_LEN, "Can't move file '%s'", oldfname);
-                               goto err;
-                       }
-               } else {
-                       /* we have found and moved the file with which we will work now */
-                       break;
-               }
-       } while ( 1 );
-
-       if ( (fhnd = open(newfname, O_RDONLY)) < 0 ) {
-               snprintf(lbm_errdesc, MAX_ERR_LEN, "Can't open file '%s'", newfname);
-               goto err;
-       }
-
-       bufuse = bufsz = toread = ct = 0;
-       do {
-               errno = 0;
-               if ( bufuse == bufsz ) {
-                       char *tmp = realloc(buf, bufsz+BUFSIZ);
-                       if ( !tmp ) goto err;
-                       buf = tmp;
-                       bufsz += BUFSIZ;
-               }
-               toread = bufsz - bufuse;
-               if ( (ct = read(fhnd, buf+bufuse, toread)) < 0 ) {
-                       if ( errno == EINTR ) continue;
-                       snprintf(lbm_errdesc, MAX_ERR_LEN, "Can't read file '%s'", newfname);
-                       goto err;
-               }
-               if ( ct == 0 ) break;
-               bufuse += ct;
-       } while ( ct == toread );
-       close(fhnd);
-
-       if ( !(*fname = strdup(ent->d_name)) ) goto err;
-       buf[bufuse] = 0;
-       *msg = buf;
-       return 1;
-
-
-err:
-       if ( buf ) free(buf);
-
-       return -1;
-}
index 10d48c5..05a5c38 100644 (file)
@@ -156,7 +156,7 @@ EXT_LIBS:=  \
        ${classadslib} \
        ${VOMS_LIBS}
 
-COMMON_LIBS:= -L${stagedir}/lib  -lglite_lb_common_${nothrflavour} -lglite_security_gss_${nothrflavour} -lglite_lbu_trio
+COMMON_LIBS:= -L${stagedir}/lib  -lglite_lb_common_${nothrflavour} -lglite_security_gss_${nothrflavour} -lglite_lbu_trio -lglite_lbu_maildir
 
 BKSERVER_BASE_OBJS:= \
        bkserverd.o il_lbproxy.o get_events.o index.o jobstat.o jobstat_supp.o \
@@ -182,7 +182,8 @@ ifeq ($(GLITE_LB_SERVER_WITH_WS),yes)
                ${LB_UTILS_DB_LIB} \
                ${GSOAP_LIB} \
                ${EXT_LIBS} \
-               ${classadslib}
+               ${classadslib} \
+               -lglite_lbu_maildir
 else
        BKSERVER_OBJS:= ${BKSERVER_BASE_OBJS}
                
@@ -193,7 +194,8 @@ else
                ${LB_UTILS_DB_LIB} \
                -lglite_security_gss_${nothrflavour} \
                ${EXT_LIBS} \
-               ${classadslib}
+               ${classadslib} \
+               -lglite_lbu_maildir
 endif
 
 INDEX_OBJS:= index.o index_parse.o jobstat_supp.o openserver.o \
index 105ba26..2b59d98 100644 (file)
 #include "glite/jobid/cjobid.h"
 #include "glite/security/glite_gss.h"
 #include "glite/lbu/srvbones.h"
+#include "glite/lbu/maildir.h"
 #include "glite/lb/context.h"
 #include "glite/lb/mini_http.h"
 #include "glite/lb/context-int.h"
-#include "glite/lb/lb_maildir.h"
 
 #ifdef LB_PERF
 #include "glite/lb/lb_perftest.h"
@@ -528,9 +528,9 @@ int main(int argc, char *argv[])
                if (check_mkdir(dumpStorage)) exit(1);
                if (check_mkdir(purgeStorage)) exit(1);
                if ( jpreg ) {
-                       if ( edg_wll_MaildirInit(jpregDir) ) {
-                               dprintf(("[%d] edg_wll_MaildirInit failed: %s\n", getpid(), lbm_errdesc));
-                               if (!debug) syslog(LOG_CRIT, "edg_wll_MaildirInit failed: %s", lbm_errdesc);
+                       if ( glite_lbu_MaildirInit(jpregDir) ) {
+                               dprintf(("[%d] glite_lbu_MaildirInit failed: %s\n", getpid(), lbm_errdesc));
+                               if (!debug) syslog(LOG_CRIT, "glite_lbu_MaildirInit failed: %s", lbm_errdesc);
                                exit(1);
                        }
                }
index 87e3ca3..ff8ca8f 100644 (file)
@@ -6,10 +6,10 @@
 #include <stdlib.h>
 #include <assert.h>
 
+#include "glite/lbu/maildir.h"
 #include "glite/lb/context-int.h"
 #include "glite/lb/events.h"
 #include "glite/lb/events_parse.h"
-#include "glite/lb/lb_maildir.h"
 #include "purge.h"
 #include "store.h"
 #include "il_lbproxy.h"
@@ -197,7 +197,7 @@ static int register_to_JP(edg_wll_Context ctx, edg_wlc_JobId jobid, char *user)
        free(jids);
        strcat(msg, "\n");
        strcat(msg, user);
-       if ( edg_wll_MaildirStoreMsg(ctx->jpreg_dir, ctx->srvName, msg) ) {
+       if ( glite_lbu_MaildirStoreMsg(ctx->jpreg_dir, ctx->srvName, msg) ) {
                free(msg);
                return edg_wll_SetError(ctx, errno, lbm_errdesc);
        }
index eecefe6..d8aa330 100644 (file)
@@ -64,7 +64,7 @@ compile all: ${UTILS} ${MAN_GZ} statistics
        ${CC} ${CFLAGS} -c $<
 
 ${UTILS}: %: %.o
-       ${LINK} -o $@ $< ${COMMON_LIB} ${CLIENT_LIB} ${EXT_LIBS}
+       ${LINK} -o $@ $< ${COMMON_LIB} ${CLIENT_LIB} ${EXT_LIBS} -lglite_lbu_maildir
 
 statistics: statistics.o
        ${LINK} -rdynamic -o $@ $< ${COMMON_LIB} ${JP_LIBS} ${EXT_LIBS} 
index 97a63ab..428ad59 100644 (file)
 #include <sys/time.h>
 
 
+#include "glite/lbu/maildir.h"
 #include "glite/lb/context.h"
 #include "glite/lb/events.h"
 #include "glite/lb/events_parse.h"
-#include "glite/lb/lb_maildir.h"
 
 
 #define DUMP_FILE_STORE_PREFIX "/tmp"
@@ -110,7 +110,7 @@ int main(int argc, char **argv)
                }
        } else fhnd = 0;
 
-       if ( edg_wll_MaildirInit(lb_maildir) ) {
+       if ( glite_lbu_MaildirInit(lb_maildir) ) {
                perror(lbm_errdesc);
                exit(1);
        }
@@ -211,7 +211,7 @@ int main(int argc, char **argv)
                else 
                        sprintf(msg, "%s%s\n%s%s",
                                        KEYNAME_JOBID, st->job, KEYNAME_FILE, st->fname);
-               if ( edg_wll_MaildirStoreMsg(lb_maildir, "localhost", msg) < 0 ) {
+               if ( glite_lbu_MaildirStoreMsg(lb_maildir, "localhost", msg) < 0 ) {
                        perror(lbm_errdesc);
                        exit(1);
                }