Back to index

courier  0.68.2
Classes | Functions
tlscache.h File Reference
#include "config.h"
#include <sys/types.h>
#include <unistd.h>
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  CACHE

Functions

struct CACHEtls_cache_open (const char *filename, off_t req_size)
void tls_cache_close (struct CACHE *p)
int tls_cache_add (struct CACHE *p, const char *val, size_t vallen)
int tls_cache_walk (struct CACHE *p, int(*walk_func)(void *rec, size_t recsize, int *doupdate, void *arg), void *arg)

Class Documentation

struct CACHE

Definition at line 33 of file tlscache.h.

Class Members
int fd
char * filename

Function Documentation

int tls_cache_add ( struct CACHE p,
const char *  val,
size_t  vallen 
)

Definition at line 186 of file tlscache.c.

{
       int rc;

       if (p->fd < 0)
              return (0);   /* Previous error invalidated obj */

       if (ll_lock_ex(p->fd) < 0)
       {
              close(p->fd);
              p->fd= -1;
              return (-1);
       }

       rc=doadd(p, val, vallen);

       if (rc < 0 && p->fd >= 0)
       {
              close(p->fd);
              p->fd= -1;
              unlink(p->filename); /* Blow it away, something's wrong */
              perror("ALERT: tlscache.c: ");
              fprintf(stderr, "ALERT: tlscache.c: removing %s\n",
                     p->filename);
       }

       if (p->fd >= 0 && ll_unlock_ex(p->fd) < 0)
       {
              close(p->fd);
              p->fd= -1;
              rc= -1;
       }

       if (rc != 0)
              rc= -1;

       return rc;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void tls_cache_close ( struct CACHE p)

Definition at line 110 of file tlscache.c.

{
       if (p->filename != NULL)
              free(p->filename);
       if (p->fd >= 0)
              close(p->fd);
       free(p);
}

Here is the caller graph for this function:

struct CACHE* tls_cache_open ( const char *  filename,
off_t  req_size 
) [read]

Definition at line 123 of file tlscache.c.

{
       struct CACHE *p=malloc(sizeof(struct CACHE));
       struct hdr h;
       int rc;

       if (!p) return NULL;

       if ((p->fd=open(filename, O_RDWR|O_CREAT, 0600)) < 0)
       {
              free(p);
              return NULL;
       }

       if ((p->filename=strdup(filename)) == NULL)
       {
              close(p->fd);
              free(p);
              return (NULL);
       }

       rc=my_read(p->fd, &h, sizeof(h));

       if (rc < 0)
       {
              tls_cache_close(p);
              return (NULL);
       }

       if (rc == 0 || h.filesize == 0)
       {
              /* Once again, but this time lock it */

              if (ll_lock_ex(p->fd) < 0 ||
                  lseek(p->fd, 0, SEEK_SET) < 0)
              {
                     tls_cache_close(p);
                     return (NULL);
              }

              rc=my_read(p->fd, &h, sizeof(h));

              if (rc < 0)
              {
                     tls_cache_close(p);
                     return (NULL);
              }

              if (rc == 0 || h.filesize == 0)
              {
                     if (init(p, req_size))
                     {
                            tls_cache_close(p);
                            return (NULL);
                     }
              }
              ll_unlock_ex(p->fd);
       }
       return p;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int tls_cache_walk ( struct CACHE p,
int(*)(void *rec, size_t recsize, int *doupdate, void *arg)  walk_func,
void *  arg 
)

Definition at line 494 of file tlscache.c.

{
       int rc;

       if (p->fd < 0)
              return (0);   /* Previous error invalidated obj */

       if (ll_lockfd(p->fd, ll_readlock||ll_whence_start|ll_wait, 0, 0) < 0)
       {
              /* Some locking methods don't support readonly locks */

              if (ll_lock_ex(p->fd) < 0)
              {
                     close(p->fd);
                     p->fd= -1;
                     return (-1);
              }
       }

       rc=dowalk(p, walk_func, arg);

       if (rc < 0 && p->fd >= 0)
       {
              close(p->fd);
              p->fd= -1;
              unlink(p->filename);
              perror("ALERT: tlscache.c: ");
              fprintf(stderr, "ALERT: tlscache.c: removing %s\n",
                     p->filename);
       }

       if (p->fd >= 0 && ll_unlock_ex(p->fd) < 0)
       {
              close(p->fd);
              p->fd= -1;
              rc= -1;
       }

       return rc;
}

Here is the call graph for this function:

Here is the caller graph for this function: