loadparm.c

ソースコードを見る。


データ構造

struct  enum_list
struct  parm_struct
struct  global
struct  service

型定義

typedef char pstring [1024]

列挙型

enum  parm_type {
  P_BOOL, P_BOOLREV, P_CHAR,
  P_INTEGER, P_OCTAL, P_PATH,
  P_STRING, P_GSTRING, P_ENUM,
  P_SEP
}
enum  parm_class {
  P_LOCAL, P_GLOBAL, P_SEPARATOR,
  P_NONE
}

関数

static void init_globals (void)
static void init_locals (void)
 FN_GLOBAL_STRING (lp_bind_address,&Globals.bind_address) FN_GLOBAL_STRING(lp_log_file
&Globals log_file FN_GLOBAL_STRING (lp_motd_file,&Globals.motd_file) FN_GLOBAL_STRING(lp_pid_file
&Globals log_file &Globals
pid_file 
FN_GLOBAL_STRING (lp_socket_options,&Globals.socket_options) FN_GLOBAL_INTEGER(lp_rsync_port
&Globals log_file &Globals
pid_file &Globals rsync_port 
FN_GLOBAL_INTEGER (lp_syslog_facility,&Globals.syslog_facility) FN_LOCAL_STRING(lp_auth_users
&Globals log_file &Globals
pid_file &Globals rsync_port
auth_users 
FN_LOCAL_STRING (lp_comment, comment)
static void string_set (char **s, const char *v)
 Assign a copy of v to *s.
static int add_a_service (service *pservice, char *name)
static int strwicmp (char *psz1, char *psz2)
static int map_parameter (char *parmname)
static BOOL set_boolean (BOOL *pb, char *parmvalue)
static int getservicebyname (char *name, service *pserviceDest)
static void copy_service (service *pserviceDest, service *pserviceSource)
static BOOL lp_do_parameter (int snum, char *parmname, char *parmvalue)
static BOOL do_parameter (char *parmname, char *parmvalue)
static BOOL do_section (char *sectionname)
BOOL lp_load (char *pszFname, int globals_only)
int lp_numservices (void)
int lp_number (char *name)

変数

static global Globals
static service sDefault
static service ** ServicePtrs = NULL
static int iNumServices = 0
static int iServiceIndex = 0
static BOOL bInGlobalSection = True
static struct enum_list enum_facilities []
static struct parm_struct parm_table []

型定義

typedef char pstring[1024]

loadparm.c57 行で定義されています。


列挙型

enum parm_type

列挙型の値:
P_BOOL 
P_BOOLREV 
P_CHAR 
P_INTEGER 
P_OCTAL 
P_PATH 
P_STRING 
P_GSTRING 
P_ENUM 
P_SEP 

loadparm.c61 行で定義されています。

enum parm_class

列挙型の値:
P_LOCAL 
P_GLOBAL 
P_SEPARATOR 
P_NONE 

loadparm.c67 行で定義されています。

00068 {
00069         P_LOCAL,P_GLOBAL,P_SEPARATOR,P_NONE
00070 } parm_class;


関数

static void init_globals ( void   )  [static]

loadparm.c335 行で定義されています。

参照先 Globals.

参照元 lp_load().

00336 {
00337         memset(&Globals, 0, sizeof Globals);
00338 #ifdef LOG_DAEMON
00339         Globals.syslog_facility = LOG_DAEMON;
00340 #endif
00341 }

static void init_locals ( void   )  [static]

loadparm.c346 行で定義されています。

参照元 do_section().

00347 {
00348 }

FN_GLOBAL_STRING ( lp_bind_address  ,
&Globals.  bind_address 
)

& Globals log_file FN_GLOBAL_STRING ( lp_motd_file  ,
&Globals.  motd_file 
)

& Globals log_file & Globals pid_file FN_GLOBAL_STRING ( lp_socket_options  ,
&Globals.  socket_options 
)

& Globals log_file & Globals pid_file & Globals rsync_port FN_GLOBAL_INTEGER ( lp_syslog_facility  ,
&Globals.  syslog_facility 
)

& Globals log_file & Globals pid_file & Globals rsync_port auth_users FN_LOCAL_STRING ( lp_comment  ,
comment   
)

loadparm.c385 行で定義されています。

参照先 copy_service()sDefault.

00435 {
00436         memset((char *)pservice,0,sizeof(service));
00437         copy_service(pservice,&sDefault);
00438 }

static void string_set ( char **  s,
const char *  v 
) [static]

Assign a copy of v to *s.

Handles NULL strings. *v must be initialized when this is called, either to NULL or a malloc'd string.

There is a small leak here in that sometimes the existing value will be dynamically allocated, and the old copy is lost. However, we can't always deallocate the old value, because in the case of sDefault, it points to a static string. It would be nice to have either all-strdup'd values, or to never need to free memory.

loadparm.c453 行で定義されています。

参照先 strdup().

参照元 add_a_service()copy_service()lp_do_parameter().

00454 {
00455         if (!v) {
00456                 *s = NULL;
00457                 return;
00458         }
00459         *s = strdup(v);
00460         if (!*s)
00461                 exit_cleanup(RERR_MALLOC);
00462 }

static int add_a_service ( service pservice,
char *  name 
) [static]

loadparm.c469 行で定義されています。

参照先 copy_service()getservicebyname()iNumServicesServicePtrsstring_set().

参照元 do_section().

00470 {
00471   int i;
00472   service tservice;
00473   int num_to_alloc = iNumServices+1;
00474 
00475   tservice = *pservice;
00476 
00477   /* it might already exist */
00478   if (name)
00479     {
00480       i = getservicebyname(name,NULL);
00481       if (i >= 0)
00482         return(i);
00483     }
00484 
00485   i = iNumServices;
00486 
00487   ServicePtrs = realloc_array(ServicePtrs, service *, num_to_alloc);
00488 
00489   if (ServicePtrs)
00490           pSERVICE(iNumServices) = new(service);
00491 
00492   if (!ServicePtrs || !pSERVICE(iNumServices))
00493           return(-1);
00494 
00495   iNumServices++;
00496 
00497   init_service(pSERVICE(i));
00498   copy_service(pSERVICE(i),&tservice);
00499   if (name)
00500     string_set(&iSERVICE(i).name,name);
00501 
00502   return(i);
00503 }

static int strwicmp ( char *  psz1,
char *  psz2 
) [static]

loadparm.c508 行で定義されています。

参照元 do_section()getservicebyname()map_parameter()set_boolean().

00509 {
00510    /* if BOTH strings are NULL, return TRUE, if ONE is NULL return */
00511    /* appropriate value. */
00512    if (psz1 == psz2)
00513       return (0);
00514    else
00515       if (psz1 == NULL)
00516          return (-1);
00517       else
00518           if (psz2 == NULL)
00519               return (1);
00520 
00521    /* sync the strings on first non-whitespace */
00522    while (1)
00523    {
00524       while (isspace(* (unsigned char *) psz1))
00525          psz1++;
00526       while (isspace(* (unsigned char *) psz2))
00527          psz2++;
00528       if (toupper(* (unsigned char *) psz1) != toupper(* (unsigned char *) psz2)
00529           || *psz1 == '\0' || *psz2 == '\0')
00530          break;
00531       psz1++;
00532       psz2++;
00533    }
00534    return (*psz1 - *psz2);
00535 }

static int map_parameter ( char *  parmname  )  [static]

loadparm.c541 行で定義されています。

参照先 FERRORparm_struct::labelparm_tablerprintf()strwicmp().

参照元 lp_do_parameter().

00542 {
00543    int iIndex;
00544 
00545    if (*parmname == '-')
00546      return(-1);
00547 
00548    for (iIndex = 0; parm_table[iIndex].label; iIndex++)
00549       if (strwicmp(parm_table[iIndex].label, parmname) == 0)
00550          return(iIndex);
00551 
00552    rprintf(FERROR, "Unknown Parameter encountered: \"%s\"\n", parmname);
00553    return(-1);
00554 }

static BOOL set_boolean ( BOOL *  pb,
char *  parmvalue 
) [static]

loadparm.c562 行で定義されています。

参照先 FERRORrprintf()strwicmp().

参照元 lp_do_parameter().

00563 {
00564    BOOL bRetval;
00565 
00566    bRetval = True;
00567    if (strwicmp(parmvalue, "yes") == 0 ||
00568        strwicmp(parmvalue, "true") == 0 ||
00569        strwicmp(parmvalue, "1") == 0)
00570       *pb = True;
00571    else
00572       if (strwicmp(parmvalue, "no") == 0 ||
00573           strwicmp(parmvalue, "False") == 0 ||
00574           strwicmp(parmvalue, "0") == 0)
00575          *pb = False;
00576       else
00577       {
00578          rprintf(FERROR, "Badly formed boolean in configuration file: \"%s\".\n",
00579                parmvalue);
00580          bRetval = False;
00581       }
00582    return (bRetval);
00583 }

static int getservicebyname ( char *  name,
service pserviceDest 
) [static]

loadparm.c588 行で定義されています。

参照先 copy_service()iNumServicesstrwicmp().

参照元 add_a_service().

00589 {
00590    int iService;
00591 
00592    for (iService = iNumServices - 1; iService >= 0; iService--)
00593       if (strwicmp(iSERVICE(iService).name, name) == 0)
00594       {
00595          if (pserviceDest != NULL)
00596            copy_service(pserviceDest, pSERVICE(iService));
00597          break;
00598       }
00599 
00600    return (iService);
00601 }

static void copy_service ( service pserviceDest,
service pserviceSource 
) [static]

loadparm.c609 行で定義されています。

参照先 parm_struct::labelP_BOOLP_BOOLREVP_CHARP_ENUMP_INTEGERP_LOCALP_OCTALP_PATHP_STRINGparm_tableparm_struct::ptrsDefaultstring_set()parm_struct::type.

参照元 add_a_service()FN_LOCAL_STRING()getservicebyname().

00611 {
00612   int i;
00613 
00614   for (i=0;parm_table[i].label;i++)
00615     if (parm_table[i].ptr && parm_table[i].class == P_LOCAL) {
00616         void *def_ptr = parm_table[i].ptr;
00617         void *src_ptr =
00618           ((char *)pserviceSource) + PTR_DIFF(def_ptr,&sDefault);
00619         void *dest_ptr =
00620           ((char *)pserviceDest) + PTR_DIFF(def_ptr,&sDefault);
00621 
00622         switch (parm_table[i].type)
00623           {
00624           case P_BOOL:
00625           case P_BOOLREV:
00626             *(BOOL *)dest_ptr = *(BOOL *)src_ptr;
00627             break;
00628 
00629           case P_INTEGER:
00630           case P_ENUM:
00631           case P_OCTAL:
00632             *(int *)dest_ptr = *(int *)src_ptr;
00633             break;
00634 
00635           case P_CHAR:
00636             *(char *)dest_ptr = *(char *)src_ptr;
00637             break;
00638 
00639           case P_PATH:
00640           case P_STRING:
00641             string_set(dest_ptr,*(char **)src_ptr);
00642             break;
00643 
00644           default:
00645             break;
00646           }
00647       }
00648 }

static BOOL lp_do_parameter ( int  snum,
char *  parmname,
char *  parmvalue 
) [static]

loadparm.c655 行で定義されています。

参照先 parm_struct::enum_listFERRORmap_parameter()nameenum_list::nameP_BOOLP_BOOLREVP_CHARP_ENUMP_GLOBALP_GSTRINGP_INTEGERP_OCTALP_PATHP_SEPP_STRINGparm_tableparm_struct::ptrrprintf()sDefaultset_boolean()string_set()strlcpy()parm_struct::typevalue.

参照元 do_parameter().

00656 {
00657    int parmnum, i;
00658    void *parm_ptr=NULL; /* where we are going to store the result */
00659    void *def_ptr=NULL;
00660    char *cp;
00661 
00662    parmnum = map_parameter(parmname);
00663 
00664    if (parmnum < 0)
00665      {
00666        rprintf(FERROR, "IGNORING unknown parameter \"%s\"\n", parmname);
00667        return(True);
00668      }
00669 
00670    def_ptr = parm_table[parmnum].ptr;
00671 
00672    /* we might point at a service, the default service or a global */
00673    if (snum < 0) {
00674      parm_ptr = def_ptr;
00675    } else {
00676        if (parm_table[parmnum].class == P_GLOBAL) {
00677            rprintf(FERROR, "Global parameter %s found in service section!\n",parmname);
00678            return(True);
00679          }
00680        parm_ptr = ((char *)pSERVICE(snum)) + PTR_DIFF(def_ptr,&sDefault);
00681    }
00682 
00683    /* now switch on the type of variable it is */
00684    switch (parm_table[parmnum].type)
00685      {
00686      case P_BOOL:
00687        set_boolean(parm_ptr,parmvalue);
00688        break;
00689 
00690      case P_BOOLREV:
00691        set_boolean(parm_ptr,parmvalue);
00692        *(BOOL *)parm_ptr = ! *(BOOL *)parm_ptr;
00693        break;
00694 
00695      case P_INTEGER:
00696        *(int *)parm_ptr = atoi(parmvalue);
00697        break;
00698 
00699      case P_CHAR:
00700        *(char *)parm_ptr = *parmvalue;
00701        break;
00702 
00703      case P_OCTAL:
00704        sscanf(parmvalue,"%o",(int *)parm_ptr);
00705        break;
00706 
00707      case P_PATH:
00708        string_set(parm_ptr,parmvalue);
00709        if ((cp = *(char**)parm_ptr) != NULL) {
00710            int len = strlen(cp);
00711            while (len > 1 && cp[len-1] == '/') len--;
00712            cp[len] = '\0';
00713        }
00714        break;
00715 
00716      case P_STRING:
00717        string_set(parm_ptr,parmvalue);
00718        break;
00719 
00720      case P_GSTRING:
00721        strlcpy((char *)parm_ptr,parmvalue,sizeof(pstring));
00722        break;
00723 
00724      case P_ENUM:
00725              for (i=0;parm_table[parmnum].enum_list[i].name;i++) {
00726                      if (strequal(parmvalue, parm_table[parmnum].enum_list[i].name)) {
00727                              *(int *)parm_ptr = parm_table[parmnum].enum_list[i].value;
00728                              break;
00729                      }
00730              }
00731              if (!parm_table[parmnum].enum_list[i].name) {
00732                      if (atoi(parmvalue) > 0)
00733                              *(int *)parm_ptr = atoi(parmvalue);
00734              }
00735              break;
00736      case P_SEP:
00737              break;
00738      }
00739 
00740    return(True);
00741 }

static BOOL do_parameter ( char *  parmname,
char *  parmvalue 
) [static]

loadparm.c746 行で定義されています。

参照先 bInGlobalSectioniServiceIndexlp_do_parameter().

参照元 lp_load().

00747 {
00748    return lp_do_parameter(bInGlobalSection?-2:iServiceIndex, parmname, parmvalue);
00749 }

static BOOL do_section ( char *  sectionname  )  [static]

loadparm.c756 行で定義されています。

参照先 add_a_service()bInGlobalSectionFERRORinit_locals()iServiceIndexrprintf()sDefaultstrwicmp().

参照元 lp_load().

00757 {
00758    BOOL bRetval;
00759    BOOL isglobal = (strwicmp(sectionname, GLOBAL_NAME) == 0);
00760    bRetval = False;
00761 
00762    /* if we were in a global section then do the local inits */
00763    if (bInGlobalSection && !isglobal)
00764      init_locals();
00765 
00766    /* if we've just struck a global section, note the fact. */
00767    bInGlobalSection = isglobal;
00768 
00769    /* check for multiple global sections */
00770    if (bInGlobalSection)
00771    {
00772      return(True);
00773    }
00774 
00775    /* if we have a current service, tidy it up before moving on */
00776    bRetval = True;
00777 
00778    if (iServiceIndex >= 0)
00779      bRetval = True;
00780 
00781    /* if all is still well, move to the next record in the services array */
00782    if (bRetval)
00783      {
00784        /* We put this here to avoid an odd message order if messages are */
00785        /* issued by the post-processing of a previous section. */
00786 
00787        if ((iServiceIndex=add_a_service(&sDefault,sectionname)) < 0)
00788          {
00789            rprintf(FERROR,"Failed to add a new service\n");
00790            return(False);
00791          }
00792      }
00793 
00794    return (bRetval);
00795 }

BOOL lp_load ( char *  pszFname,
int  globals_only 
)

loadparm.c802 行で定義されています。

参照先 am_rootam_serverbInGlobalSectiondo_parameter()do_section()init_globals()iServiceIndexpm_process().

参照元 daemon_main()start_daemon().

00803 {
00804         extern int am_server;
00805         extern int am_root;
00806         pstring n2;
00807         BOOL bRetval;
00808 
00809         bRetval = False;
00810 
00811         bInGlobalSection = True;
00812 
00813         init_globals();
00814 
00815         if (pszFname)
00816             pstrcpy(n2,pszFname);
00817         else if (am_server && !am_root)
00818             pstrcpy(n2,RSYNCD_USERCONF);
00819         else
00820             pstrcpy(n2,RSYNCD_SYSCONF);
00821 
00822         /* We get sections first, so have to start 'behind' to make up */
00823         iServiceIndex = -1;
00824         bRetval = pm_process(n2, globals_only?NULL:do_section, do_parameter);
00825 
00826         return (bRetval);
00827 }

int lp_numservices ( void   ) 

loadparm.c833 行で定義されています。

参照先 iNumServices.

参照元 send_listing().

00834 {
00835   return(iNumServices);
00836 }

int lp_number ( char *  name  ) 

loadparm.c844 行で定義されています。

参照先 iNumServiceslp_name().

参照元 start_daemon().

00845 {
00846    int iService;
00847 
00848    for (iService = iNumServices - 1; iService >= 0; iService--)
00849       if (strcmp(lp_name(iService), name) == 0)
00850          break;
00851 
00852    return (iService);
00853 }


変数

global Globals [static]

loadparm.c111 行で定義されています。

参照元 init_globals().

service sDefault [static]

loadparm.c164 行で定義されています。

参照元 copy_service()do_section()FN_LOCAL_STRING()lp_do_parameter().

service** ServicePtrs = NULL [static]

loadparm.c207 行で定義されています。

参照元 add_a_service().

int iNumServices = 0 [static]

loadparm.c208 行で定義されています。

参照元 add_a_service()getservicebyname()lp_number()lp_numservices().

int iServiceIndex = 0 [static]

loadparm.c209 行で定義されています。

参照元 do_parameter()do_section()lp_load().

BOOL bInGlobalSection = True [static]

loadparm.c210 行で定義されています。

参照元 do_parameter()do_section()lp_load().

struct enum_list enum_facilities[] [static]

loadparm.c214 行で定義されています。

struct parm_struct parm_table[] [static]

loadparm.c282 行で定義されています。

参照元 copy_service()lp_do_parameter()map_parameter().


rsyncに対してSat Dec 5 19:45:44 2009に生成されました。  doxygen 1.4.7