1 /*- |
2 * Copyright (c) 2005-2009 Daniel Braniss <danny@cs.huji.ac.il> |
3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright --- 13 unchanged lines hidden (view full) --- 24 * SUCH DAMAGE. 25 * 26 */ 27/* 28 | $Id: config.c,v 2.1 2006/11/12 08:06:51 danny Exp danny $ 29 */ 30 31#include <sys/cdefs.h> |
32__FBSDID("$FreeBSD: head/sbin/iscontrol/config.c 211095 2010-08-09 12:36:36Z des $"); |
33 34#include <stdlib.h> 35#include <unistd.h> 36#include <stdio.h> 37#include <string.h> 38#include <errno.h> 39#include <fcntl.h> 40#include <time.h> 41#include <ctype.h> 42#include <camlib.h> 43 |
44#include <dev/iscsi/initiator/iscsi.h> |
45#include "iscontrol.h" 46 47/* 48 | ints 49 */ 50#define OPT_port 1 51#define OPT_tags 2 52 --- 36 unchanged lines hidden (view full) --- 89#define OPT_tgtChallengeLen 32 90/* 91 | private 92 */ 93#define OPT_maxluns 33 94#define OPT_iqn 34 95#define OPT_sockbufsize 35 96 |
97/* 98 | sentinel 99 */ 100#define OPT_end 0 101 |
102#define _OFF(v) ((int)&((isc_opt_t *)NULL)->v) 103#define _E(u, s, v) {.usage=u, .scope=s, .name=#v, .tokenID=OPT_##v} 104 105textkey_t keyMap[] = { 106 _E(U_PR, S_PR, port), 107 _E(U_PR, S_PR, tags), 108 _E(U_PR, S_PR, maxluns), 109 _E(U_PR, S_PR, sockbufsize), --- 35 unchanged lines hidden (view full) --- 145 _E(U_LO, S_SW, maxOutstandingR2T), 146 _E(U_LO, S_SW, dataPDUInOrder), 147 _E(U_LO, S_SW, dataSequenceInOrder), 148 149 _E(U_LO, S_SW, errorRecoveryLevel), 150 151 _E(U_LO, S_SW, sessionType), 152 |
153 _E(0, 0, end) |
154}; 155 156#define _OPT_INT(w) strtol((char *)w, NULL, 0) 157#define _OPT_STR(w) (char *)(w) 158 159static __inline int 160_OPT_BOOL(char *w) 161{ |
162 if(isalpha((unsigned char)*w)) |
163 return strcasecmp(w, "TRUE") == 0; 164 else 165 return _OPT_INT(w); 166} 167 168#define _CASE(k, v) case OPT_##k: op->k = v; break 169static void 170setOption(isc_opt_t *op, int which, void *rval) --- 73 unchanged lines hidden (view full) --- 244 245 ar = Ar; 246 if(key) 247 len = strlen(key); 248 else 249 len = 0; 250 state = 0; 251 while((lp = getline(fd)) != NULL) { |
252 for(; isspace((unsigned char)*lp); lp++) |
253 ; 254 switch(state) { 255 case 0: 256 if((p = strchr(lp, '{')) != NULL) { |
257 while((--p > lp) && *p && isspace((unsigned char)*p)); |
258 n = p - lp; 259 if(len && strncmp(lp, key, MAX(n, len)) == 0) 260 state = 2; 261 else 262 state = 1; 263 continue; 264 } 265 break; --- 6 unchanged lines hidden (view full) --- 272 case 2: 273 if(*lp == '}') 274 goto done; 275 276 break; 277 } 278 279 |
280 for(p = &lp[strlen(lp)-1]; isspace((unsigned char)*p); p--) |
281 *p = 0; 282 if((*nargs)-- > 0) 283 *ar++ = strdup(lp); 284 } 285 286 done: 287 if(*nargs > 0) 288 *ar = 0; --- 62 unchanged lines hidden (view full) --- 351 textkey_t *tk; 352 353 for(ar = args; nargs > 0; nargs--, ar++) { 354 p = strchr(*ar, '='); 355 if(p == NULL) 356 continue; 357 *p = 0; 358 v = p + 1; |
359 while(isspace((unsigned char)*--p)) |
360 *p = 0; |
361 while(isspace((unsigned char)*v)) |
362 v++; 363 if((tk = keyLookup(*ar)) == NULL) 364 continue; 365 setOption(op, tk->tokenID, v); 366 } 367} 368 369void 370parseConfig(FILE *fd, char *key, isc_opt_t *op) 371{ 372 char *Ar[256]; 373 int cc; 374 375 cc = 256; 376 if(getConfig(fd, key, Ar, &cc)) 377 parseArgs(cc, Ar, op); 378 if(vflag) 379 puke(op); 380} |