Back to index

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

Go to the source code of this file.

Classes

struct  maildir_newshared_enum_cb
struct  maildir_shindex_cache
struct  maildir_shindex_record

Functions

int maildir_newshared_open (const char *indexfile, struct maildir_newshared_enum_cb *info)
int maildir_newshared_next (struct maildir_newshared_enum_cb *info, int *eof, int(*cb_func)(struct maildir_newshared_enum_cb *), void *cb_arg)
int maildir_newshared_nextAt (struct maildir_newshared_enum_cb *info, int *eof, int(*cb_func)(struct maildir_newshared_enum_cb *), void *cb_arg)
void maildir_newshared_close (struct maildir_newshared_enum_cb *info)
int maildir_newshared_enum (const char *indexfile, int(*cb_func)(struct maildir_newshared_enum_cb *), void *cb_arg)
const char * maildir_shared_index_file ()
struct maildir_shindex_cachemaildir_shared_cache_read (struct maildir_shindex_cache *parent, const char *indexfile, const char *subhierarchy)

Variables

int maildir_newshared_disabled

Class Documentation

struct maildir_newshared_enum_cb

Definition at line 62 of file maildirnewshared.h.

Class Members
void * cb_arg
FILE * fp
gid_t gid
const char * homedir
const char * indexfile
size_t linenum
const char * maildir
const char * name
off_t startingpos
uid_t uid
struct maildir_shindex_cache

Definition at line 133 of file maildirnewshared.h.

Collaboration diagram for maildir_shindex_cache:
Class Members
char * hierarchy
struct maildir_shindex_cache * next
size_t nrecords
struct maildir_shindex_record * records
struct maildir_shindex_record

Definition at line 144 of file maildirnewshared.h.

Class Members
char * name
off_t offset

Function Documentation

Definition at line 35 of file maildirnewshared.c.

{
       if (info->fp)
              fclose(info->fp);
       info->fp=NULL;
}

Here is the caller graph for this function:

int maildir_newshared_enum ( const char *  indexfile,
int(*)(struct maildir_newshared_enum_cb *)  cb_func,
void *  cb_arg 
)

Definition at line 180 of file maildirnewshared.c.

{
       struct maildir_newshared_enum_cb cb;
       int eof;
       int rc;

       if (maildir_newshared_open(indexfile, &cb) < 0)
              return -1;

       while ((rc=maildir_newshared_next(&cb, &eof, cb_func, cb_arg)) == 0)
       {
              if (eof)
              {
                     maildir_newshared_close(&cb);
                     return 0;
              }
       }

       maildir_newshared_close(&cb);
       return rc;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int maildir_newshared_next ( struct maildir_newshared_enum_cb info,
int *  eof,
int(*)(struct maildir_newshared_enum_cb *)  cb_func,
void *  cb_arg 
)

Definition at line 53 of file maildirnewshared.c.

{
       char linebuf[BUFSIZ];
       int rc;
       char *p;
       const char *name;
       const char *homedir;
       const char *maildir;
       uid_t uid;
       gid_t gid;
       off_t nbytes;

#define CB_INIT(name_,homedir_,maildir_,uid_,gid_) \
       info->name=name_; info->homedir=homedir_; info->maildir=maildir_; \
       info->uid=uid_; info->gid=gid_; info->cb_arg=cb_arg;

       *eof=0;

       while (fgets(linebuf, sizeof(linebuf), info->fp) != NULL)
       {
              nbytes=strlen(linebuf);

              if (nbytes && linebuf[nbytes-1] == '\n')
                     linebuf[nbytes-1]=0;

              p=strchr(linebuf, '#');
              if (p) *p=0;

              p=strchr(linebuf, '\t');
              ++info->linenum;
              if (p)
              {
                     name=linebuf;
                     *p++=0;

                     if (*p == '*')
                     {
                            p=strchr(p, '\t');
                            if (p)
                            {
                                   const char *q;
                                   size_t n;

                                   *p++=0;
                                   maildir=p;
                                   p=strchr(p, '\t');
                                   if (p) *p=0;

                                   q=strrchr(info->indexfile, '/');
                                   if (q)
                                          ++q;
                                   else q=info->indexfile;

                                   n=strlen(info->indexfile)-strlen(q);

                                   p=malloc(n+strlen(maildir)+1);
                                   if (!p)
                                          return -1;

                                   if (n)
                                          memcpy(p, info->indexfile, n);
                                   strcpy(p+n, maildir);


                                   CB_INIT(name, NULL, p, 0, 0);

                                   info->cb_arg=cb_arg;
                                   rc= (*cb_func)(info);

                                   free(p);
                                   info->startingpos += nbytes;
                                   return rc;
                            }
                     }
                     else
                     {
                            uid=libmail_atouid_t(p);
                            p=strchr(p, '\t');
                            if (uid && p)
                            {
                                   *p++=0;
                                   gid=libmail_atogid_t(p);
                                   p=strchr(p, '\t');
                                   if (gid && p)
                                   {
                                          *p++=0;
                                          homedir=p;
                                          p=strchr(p, '\t');
                                          maildir="./Maildir";

                                          if (p)
                                          {
                                                 *p++=0;
                                                 if (*p && *p != '\t')
                                                        maildir=p;
                                                 p=strchr(p, '\t');
                                                 if (p) *p=0;
                                          }

                                          CB_INIT(name, homedir,
                                                 maildir,
                                                 uid,
                                                 gid);

                                          info->cb_arg=cb_arg;
                                          rc=(*cb_func)(info);
                                          info->startingpos += nbytes;
                                          return rc;
                                   }
                            }
                     }
              }

              if (linebuf[0])
              {
                     fprintf(stderr, "ERR: %s(%d): syntax error.\n",
                            info->indexfile, (int)info->linenum);
              }
              info->startingpos += nbytes;
       }
       *eof=1;
       return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int maildir_newshared_nextAt ( struct maildir_newshared_enum_cb info,
int *  eof,
int(*)(struct maildir_newshared_enum_cb *)  cb_func,
void *  cb_arg 
)

Definition at line 42 of file maildirnewshared.c.

{
       if (fseek(info->fp, info->startingpos, SEEK_SET) < 0)
              return -1;
       info->linenum= -1;
       return maildir_newshared_next(info, eof, cb_func, cb_arg);
}

Here is the call graph for this function:

Here is the caller graph for this function:

int maildir_newshared_open ( const char *  indexfile,
struct maildir_newshared_enum_cb info 
)

Definition at line 23 of file maildirnewshared.c.

{
       info->indexfile=indexfile;
       if ((info->fp=fopen(maildir_newshared_disabled ?
                         "/dev/null":indexfile, "r")) == NULL)
              return -1;
       info->startingpos=0;
       info->linenum=0;
       return 0;
}

Here is the caller graph for this function:

struct maildir_shindex_cache* maildir_shared_cache_read ( struct maildir_shindex_cache parent,
const char *  indexfile,
const char *  subhierarchy 
) [read]

Definition at line 66 of file maildirnewshared2.c.

{
       struct maildir_shindex_cache *p;

       if (parent && parent->next && subhierarchy &&
           strcmp(parent->next->hierarchy, subhierarchy) == 0)
       {
              return parent->next; /* That was easy */
       }

       if (!parent && shared_cache)
       {
              return shared_cache;
       }

       if (!indexfile)
       {
              indexfile=maildir_shared_index_file();
              if (!indexfile)
                     return NULL;
              subhierarchy="";
       }


       if (!subhierarchy)
              return NULL;
       /* Should not happen, bad usage. subhierarchy allowed to be NULL only
       ** when indexfile is also NULL */

       p=do_shared_cache_read(indexfile, subhierarchy);

       if (!p)
              return NULL;

       if (!parent)
       {
              shared_cache_free(shared_cache);
              shared_cache=p;
       }
       else
       {
              shared_cache_free(parent->next);
              parent->next=p;
       }
       return p;
}

Here is the call graph for this function:

Here is the caller graph for this function:

const char* maildir_shared_index_file ( )

Definition at line 89 of file mailboxlist.c.

{
       static char *filenamep=NULL;

       if (filenamep == NULL)
       {
              const char *p=getenv("IMAP_SHAREDINDEXFILE");

              if (p && *p)
              {
                     const char *q=auth_getoptionenv("sharedgroup");

                     if (!q) q="";

                     filenamep=malloc(strlen(p)+strlen(q)+1);

                     if (!filenamep)
                            write_error_exit(0);

                     strcat(strcpy(filenamep, p), q);
              }
       }

       if (filenamep && !shared_index_err_reported) /* Bitch just once */
       {
              struct stat stat_buf;

              shared_index_err_reported=1;
              if (stat(filenamep, &stat_buf))
              {
                     fprintf(stderr, "ERR: ");
                     perror(filenamep);
              }
       }

       return filenamep;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

Definition at line 21 of file maildirnewshared.c.