Back to index

courier  0.68.2
cfilename.c
Go to the documentation of this file.
00001 /*
00002 ** Copyright 1998 - 2012 Double Precision, Inc.
00003 ** See COPYING for distribution information.
00004 */
00005 
00006 #include      "courier.h"
00007 #include      "sysconfdir.h"
00008 
00009 #include      <stdlib.h>
00010 #include      <string.h>
00011 #include      <unistd.h>
00012 
00013 static const char *local_vhost=0;
00014 
00015 char   *config_localfilename(const char *p)
00016 {
00017        char   *c=courier_malloc(sizeof(SYSCONFDIR "/")+strlen(p)
00018                               + (local_vhost ? strlen(local_vhost)+2:0));
00019 
00020        char   *fn=strcat(strcpy(c, SYSCONFDIR "/"), p);
00021 
00022        if (local_vhost)
00023        {
00024               size_t l=strlen(fn);
00025 
00026               strcat(strcat(fn, "."), local_vhost);
00027 
00028               if (access(fn, 0) == 0)
00029                      return fn;
00030               fn[l]=0;
00031        }
00032        return fn;
00033 }
00034 
00035 int    config_has_vhost(const char *p)
00036 {
00037        char   *filename
00038               =courier_malloc(sizeof(SYSCONFDIR "/vhost.")+strlen(p));
00039        int exists;
00040 
00041        strcat(strcpy(filename, SYSCONFDIR "/vhost."), p);
00042        exists=access(filename, 0) == 0;
00043        free(filename);
00044        return exists;
00045 }
00046 
00047 void   config_set_local_vhost(const char *p)
00048 {
00049        local_vhost=p;
00050 }
00051 
00052 const char *config_get_local_vhost()
00053 {
00054        return local_vhost;
00055 }
00056