Check-in [e07808cac6]
Overview
Comment:Added an "ADDR" var type (since it was already documented) Removed brain-dead (void *) to type casts in lc_handle_...()
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: e07808cac62ec432c68d1765ca4698ac59285a90
User & Date: rkeene on 2006-12-17 03:04:26
Other Links: manifest | tags
Context
2006-12-17
03:35
Added working addr and ipv4 conversion functions check-in: 525f68fcf8 user: rkeene tags: trunk
03:04
Added an "ADDR" var type (since it was already documented) Removed brain-dead (void *) to type casts in lc_handle_...() check-in: e07808cac6 user: rkeene tags: trunk
02:49
Exposed lc_handle_type() function to public (needs documentation) Updated lc_register_callback documentation check-in: c3d71a3b91 user: rkeene tags: trunk
Changes

Modified libconfig.c from [bc792aa0c5] to [a6cd32cb12].

    56     56   	return(0);
    57     57   }
    58     58   
    59     59   static int lc_process_var_cidr(void *data, const char *value, const char **endptr) {
    60     60   	return(-1);
    61     61   }
    62     62   
    63         -static int lc_process_var_hostname6(void *data, const char *value, const char **endptr) {
           63  +static int lc_process_var_addr4(uint32_t *data, const char *value, const char **endptr) {
           64  +	return(-1);
           65  +}
           66  +
           67  +static int lc_process_var_addr6(void *data, const char *value, const char **endptr) {
           68  +	return(-1);
           69  +}
           70  +
           71  +static int lc_process_var_hostname4(uint32_t *data, const char *value, const char **endptr) {
    64     72   	return(-1);
    65     73   }
    66     74   
    67         -static int lc_process_var_hostname4(void *data, const char *value, const char **endptr) {
           75  +static int lc_process_var_hostname6(void *data, const char *value, const char **endptr) {
    68     76   	return(-1);
    69     77   }
    70     78   
    71     79   static int lc_process_var_ip6(void *data, const char *value, const char **endptr) {
    72     80   	return(-1);
    73     81   }
    74     82   
    75         -static int lc_process_var_ip4(void *data, const char *value, const char **endptr) {
    76         -	uint32_t *dataval, retval = 0;
           83  +static int lc_process_var_ip4(uint32_t *data, const char *value, const char **endptr) {
    77     84   	const char *dotptr = NULL;
    78         -	int tmpval = -1;
    79         -//	int dotcount
    80         -
    81         -	dataval = data;
           85  +	int tmpval = -1, retval = 0;
    82     86   
    83     87   	dotptr = value;
    84     88   
    85     89   	while (1) {
    86     90   		tmpval = atoi(dotptr);
    87     91   		if (tmpval < 0) {
    88     92   			break;
................................................................................
    97    101   		}
    98    102   		if (*dotptr != '.') {
    99    103   			break;
   100    104   		}
   101    105   		dotptr++;
   102    106   	}
   103    107   
   104         -	*dataval = retval;
          108  +	*data = retval;
   105    109   
   106    110   	*endptr = (char *) dotptr;
   107    111   
   108    112   	return(0);
   109    113   }
   110    114   
   111         -static int lc_process_var_longlong(void *data, const char *value, const char **endptr) {
   112         -	long long *dataval;
          115  +static int lc_process_var_longlong(long long *data, const char *value, const char **endptr) {
          116  +	*data = strtoll(value, (char **) endptr, 10);
   113    117   
   114         -	dataval = data;
   115         -	*dataval = strtoll(value, (char **) endptr, 10);
          118  +	return(0);
          119  +}
          120  +
          121  +static int lc_process_var_long(long *data, const char *value, const char **endptr) {
          122  +	*data = strtoll(value, (char **) endptr, 10);
   116    123   
   117    124   	return(0);
   118    125   }
   119    126   
   120         -static int lc_process_var_long(void *data, const char *value, const char **endptr) {
   121         -	long *dataval;
   122         -
   123         -	dataval = data;
   124         -	*dataval = strtoll(value, (char **) endptr, 10);
          127  +static int lc_process_var_int(int *data, const char *value, const char **endptr) {
          128  +	*data = strtoll(value, (char **) endptr, 10);
   125    129   
   126    130   	return(0);
   127    131   }
   128    132   
   129         -static int lc_process_var_int(void *data, const char *value, const char **endptr) {
   130         -	int *dataval;
   131         -
   132         -	dataval = data;
   133         -	*dataval = strtoll(value, (char **) endptr, 10);
          133  +static int lc_process_var_short(short *data, const char *value, const char **endptr) {
          134  +	*data = strtoll(value, (char **) endptr, 10);
   134    135   
   135    136   	return(0);
   136    137   }
   137    138   
   138         -static int lc_process_var_short(void *data, const char *value, const char **endptr) {
   139         -	short *dataval;
   140         -
   141         -	dataval = data;
   142         -	*dataval = strtoll(value, (char **) endptr, 10);
   143         -
   144         -	return(0);
   145         -}
   146         -
   147         -static int lc_process_var_bool_byexistance(void *data, const char *value, const char **endptr) {
   148         -	int *dataval;
   149         -
   150         -	dataval = data;
   151         -
   152         -	*dataval = 1;
          139  +static int lc_process_var_bool_byexistance(int *data, const char *value, const char **endptr) {
          140  +	*data = 1;
   153    141   
   154    142   	*endptr = NULL;
   155    143   
   156    144   	return(0);
   157    145   }
   158    146   
   159         -static int lc_process_var_bool(void *data, const char *value, const char **endptr) {
          147  +static int lc_process_var_bool(int *data, const char *value, const char **endptr) {
   160    148   	char *trueval[] = {"enable", "true", "yes", "on", "y", "1"};
   161    149   	char *falseval[] = {"disable", "false", "no", "off", "n", "0"};
   162    150   	size_t chkvallen, vallen;
   163         -	int *dataval;
   164    151   	int i;
   165    152   
   166         -	dataval = data;
   167         -
   168         -	*dataval = -1;
          153  +	*data = -1;
   169    154   
   170    155   	vallen = strlen(value);
   171    156   
   172    157   	for (i = 0; i < (sizeof(trueval) / sizeof(*trueval)); i++) {
   173    158   		chkvallen = strlen(trueval[i]);
   174    159   
   175    160   		/*
................................................................................
   186    171   			continue;
   187    172   		}
   188    173   
   189    174   		if (value[chkvallen] == '\0' || value[chkvallen] == ',' || \
   190    175   		    value[chkvallen] == ' ') {
   191    176   			/* Declare a winner and set the next token. */
   192    177   			*endptr = value + chkvallen;
   193         -			*dataval = 1;
          178  +			*data = 1;
   194    179   			return(0);
   195    180   		}
   196    181   	}
   197    182   
   198    183   	for (i = 0; i < (sizeof(falseval) / sizeof(*falseval)); i++) {
   199    184   		chkvallen = strlen(falseval[i]);
   200    185   
................................................................................
   212    197   			continue;
   213    198   		}
   214    199   
   215    200   		if (value[chkvallen] == '\0' || value[chkvallen] == ',' || \
   216    201   		    value[chkvallen] == ' ') {
   217    202   			/* Declare a winner and set the next token. */
   218    203   			*endptr = value + chkvallen;
   219         -			*dataval = 0;
          204  +			*data = 0;
   220    205   			return(0);
   221    206   		}
   222    207   	}
   223    208   
   224    209   	lc_errno = LC_ERR_BADFORMAT;
   225    210   	return(-1);
   226    211   }
................................................................................
   251    236   				break;
   252    237   		}
   253    238   	}
   254    239   
   255    240   	return(retval);
   256    241   }
   257    242   
   258         -static int lc_process_var_sizelonglong(void *data, const char *value, const char **endptr) {
   259         -	long long *dataval;
          243  +static int lc_process_var_sizelonglong(long long *data, const char *value, const char **endptr) {
          244  +	*data = lc_process_size(value, endptr);
   260    245   
   261         -	dataval = data;
   262         -	*dataval = lc_process_size(value, endptr);
          246  +	return(0);
          247  +}
          248  +
          249  +static int lc_process_var_sizelong(long *data, const char *value, const char **endptr) {
          250  +	*data = lc_process_size(value, endptr);
   263    251   
   264    252   	return(0);
   265    253   }
   266    254   
   267         -static int lc_process_var_sizelong(void *data, const char *value, const char **endptr) {
   268         -	long *dataval;
   269         -
   270         -	dataval = data;
   271         -	*dataval = lc_process_size(value, endptr);
          255  +static int lc_process_var_sizeint(int *data, const char *value, const char **endptr) {
          256  +	*data = lc_process_size(value, endptr);
   272    257   
   273    258   	return(0);
   274    259   }
   275    260   
   276         -static int lc_process_var_sizeint(void *data, const char *value, const char **endptr) {
   277         -	int *dataval;
   278         -
   279         -	dataval = data;
   280         -	*dataval = lc_process_size(value, endptr);
          261  +static int lc_process_var_sizeshort(short *data, const char *value, const char **endptr) {
          262  +	*data = lc_process_size(value, endptr);
   281    263   
   282    264   	return(0);
   283    265   }
   284    266   
   285         -static int lc_process_var_sizeshort(void *data, const char *value, const char **endptr) {
   286         -	short *dataval;
   287         -
   288         -	dataval = data;
   289         -	*dataval = lc_process_size(value, endptr);
   290         -
   291         -	return(0);
   292         -}
   293         -
   294         -static int lc_process_var_sizesizet(void *data, const char *value, const char **endptr) {
   295         -	size_t *dataval;
   296         -
   297         -	dataval = data;
   298         -	*dataval = lc_process_size(value, endptr);
          267  +static int lc_process_var_sizesizet(size_t *data, const char *value, const char **endptr) {
          268  +	*data = lc_process_size(value, endptr);
   299    269   
   300    270   	return(0);
   301    271   }
   302    272   
   303    273   int lc_handle_type(lc_var_type_t type, const char *value, void *data) {
   304    274   	const char *next;
   305    275   	int is_list;
................................................................................
   350    320   		case LC_VAR_IP:
   351    321   		case LC_VAR_IP4:
   352    322   			return(lc_process_var_ip4(data, value, &next));
   353    323   			break;
   354    324   		case LC_VAR_IP6:
   355    325   			return(lc_process_var_ip6(data, value, &next));
   356    326   			break;
          327  +		case LC_VAR_ADDR:
          328  +		case LC_VAR_ADDR4:
          329  +			return(lc_process_var_addr4(data, value, &next));
          330  +		case LC_VAR_ADDR6:
          331  +			return(lc_process_var_addr6(data, value, &next));
          332  +		case LC_VAR_HOSTNAME:
   357    333   		case LC_VAR_HOSTNAME4:
   358    334   			return(lc_process_var_hostname4(data, value, &next));
   359    335   			break;
   360    336   		case LC_VAR_HOSTNAME6:
   361    337   			return(lc_process_var_hostname6(data, value, &next));
   362    338   			break;
   363    339   		case LC_VAR_CIDR:

Modified libconfig.h.in from [14f8a60094] to [1c13a21f8a].

    39     39           LC_VAR_SECTIONEND,
    40     40           LC_VAR_BOOL_BY_EXISTANCE,
    41     41           LC_VAR_SIZE_SIZE_T,
    42     42           LC_VAR_CIDR,
    43     43           LC_VAR_IP,
    44     44           LC_VAR_IP4,
    45     45           LC_VAR_IP6,
           46  +        LC_VAR_ADDR,
           47  +        LC_VAR_ADDR4,
           48  +        LC_VAR_ADDR6,
           49  +        LC_VAR_HOSTNAME,
    46     50           LC_VAR_HOSTNAME4,
    47     51           LC_VAR_HOSTNAME6,
    48     52           LC_VAR_LIST = 0x80
    49     53   } lc_var_type_t;
    50     54   
    51     55   __BLANK_LINE__
    52     56