Exemple #1
0
	FLUT_API std::pair< string, string > to_key_value( const string& s, const string& sep_char )
	{
		auto pos = s.find_first_of( sep_char.c_str() );
		if ( pos == string::npos )
			return make_pair( trim_str( s ), string("") );
		else return make_pair( trim_str( left_str( s, pos ) ), trim_str( mid_str( s, pos + 1 ) ) );
	}
Exemple #2
0
  ConfigParser::Entry* ConfigParser::parse_line(const char* line) {
    char* var = strdup(line);
    char* equals = strchr(var, '=');

    if(equals) {
      /* Split the string. */
      *equals++ = 0;
    }

    std::string variable = std::string(trim_str(var));

    std::string value;
    // Just the variable name means true, as in enable
    if(equals) {
      value = std::string(trim_str(equals));
    } else {
      value = std::string("true");
    }

    if(process_internal(variable, value)) {
      free(var);
      return NULL;
    }

    Entry* entry = new ConfigParser::Entry();
    entry->variable = variable;
    entry->value = value;

    free(var);

    return entry;
  }
Exemple #3
0
int UsrAccConfig::get_key_value(const std::string &line, const int &pos, std::string &key, std::string &value) {
	key = line.substr(0,pos);
	value = line.substr(pos+1);

	trim_str(key);
	trim_str(value);
	return 0;
}
Exemple #4
0
void MealFactory::ParseFromFile(const String & filePath, MealMgr & mealMgr)
{
	Meal meal;
	std::ifstream infile(filePath);

	// skip ahead to the report details section
	std::string line;
	do
	{
		std::getline(infile, line);
		trim_str(line);
		if (0 == line.compare("# Report Details"))
		{
			break;
		}
	} 
	while (false == infile.eof());

	// parse meals
	while (false == infile.eof())
	{
		if (ParseMeal(infile, meal))
		{
			mealMgr.AddMeal(meal);
		}
	}
}
Exemple #5
0
/**
 * parse_stream - Parse a text stream for cheats.
 * @list: list to add cheats to
 * @stream: stream to read cheats from
 * @return: 0: success, -1: error
 */
int parse_stream(gamelist_t *list, FILE *stream)
{
	parser_ctx_t ctx;
	char line[LINE_MAX + 1];
	int nl = 1;

	if (list == NULL || stream == NULL)
		return -1;

	init_parser(&ctx);

	while (fgets(line, sizeof(line), stream) != NULL) { /* Scanner */
		if (!is_empty_str(line)) {
			/* Screener */
			term_str(line, is_cmt_str);
			trim_str(line);

			/* Parser */
			if (strlen(line) > 0 && parse_line(line, nl, &ctx, list) < 0)
				return -1;
		}
		nl++;
	}

	return 0;
}
Exemple #6
0
	bool parse_ini_conf_file(const std::string& path, INIProperties& result,
			const char* sep)
	{
		char buf[kConfigLineMax + 1];
		FILE *fp;
		if ((fp = fopen(path.c_str(), "r")) == NULL)
		{
			return false;
		}
		uint32 lineno = 1;
		std::string current_tag = "";
		while (fgets(buf, kConfigLineMax, fp) != NULL)
		{
			char* line = trim_str(buf, "\r\n\t ");
			if (line[0] == '#' || line[0] == '\0')
			{
				lineno++;
				continue;
			}
			if (line[0] == '[' && line[strlen(line) - 1] == ']')
			{
				current_tag = std::string(line + 1, strlen(line) - 2);
				lineno++;
				continue;
			}
			std::vector<char*> sp_ret = split_str(line, sep);
			if (sp_ret.size() != 2)
			{
				ERROR_LOG("Invalid config line at line:%u", lineno);
				fclose(fp);
				return false;
			}
			char* key = trim_str(sp_ret[0], "\r\n\t ");
			char* value = trim_str(sp_ret[1], "\r\n\t ");
			Properties& current_prop = result[current_tag];
			if (current_prop.find(key) != current_prop.end())
			{
				ERROR_LOG("Duplicate key:%s in config.", key);
				fclose(fp);
				return false;
			}
			current_prop[key] = value;
			lineno++;
		}
		fclose(fp);
		return true;
	}
Exemple #7
0
static char * test_name_from_signature(const char * s){
    char * slice = slice_str(4, strlen(s), s);
    char * fn    = upto_char(slice, '(');
    char * fn_tr = trim_str(fn);
    free(slice);
    free(fn);
    return fn_tr;
};
Exemple #8
0
short
str_to_state(char *boolstr) {
   trim_str(boolstr);
   if (strcmp(boolstr, "TRUE") == 0)
      return STATE_SELECTED;
   else if (strcmp(boolstr, "FALSE") == 0)
      return STATE_NOT_SELECTED;
   else
      return ERROR_CORRUPT_RC_FILE;
}
Exemple #9
0
/** Some kind of general conv_param routine,
 * to ensure the parameter is nick!user@host.
 * most of the code is just copied from clean_ban_mask.
 */
char *extban_conv_param_nuh(char *para)
{
char *cp, *user, *host, *mask, *ret = NULL;
static char retbuf[USERLEN + NICKLEN + HOSTLEN + 32];
char tmpbuf[USERLEN + NICKLEN + HOSTLEN + 32];
char pfix[8];

	strncpyzt(tmpbuf, para, sizeof(retbuf));
	mask = tmpbuf + 3;
	strncpyzt(pfix, tmpbuf, mask - tmpbuf + 1);

	if ((*mask == '~') && !strchr(mask, '@'))
		return NULL; /* not a user@host ban, too confusing. */
	if ((user = index((cp = mask), '!')))
		*user++ = '\0';
	if ((host = rindex(user ? user : cp, '@')))
	{
		*host++ = '\0';
		if (!user)
			ret = make_nick_user_host(NULL, trim_str(cp,USERLEN), trim_str(host,HOSTLEN));
	}
	else if (!user && index(cp, '.'))
		ret = make_nick_user_host(NULL, NULL, trim_str(cp,HOSTLEN));
	if (!ret)
		ret = make_nick_user_host(trim_str(cp,NICKLEN), trim_str(user,USERLEN), trim_str(host,HOSTLEN));

	ircsprintf(retbuf, "%s%s", pfix, ret);
	return retbuf;
}
Exemple #10
0
	bool parse_conf_file(const std::string& path, Properties& result,
			const char* sep)
	{
		char buf[kConfigLineMax + 1];
		FILE *fp;
		if ((fp = fopen(path.c_str(), "r")) == NULL)
		{
			return false;
		}
		uint32 lineno = 1;
		while (fgets(buf, kConfigLineMax, fp) != NULL)
		{
			char* line = trim_str(buf, "\r\n\t ");
			if (line[0] == '#' || line[0] == '\0')
			{
				lineno++;
				continue;
			}
			std::vector<char*> sp_ret = split_str(line, sep);
			if (sp_ret.size() != 2)
			{
				ERROR_LOG("Invalid config line at line:%u", lineno);
				fclose(fp);
				return false;
			}
			char* key = trim_str(sp_ret[0], "\r\n\t ");
			char* value = trim_str(sp_ret[1], "\r\n\t ");
			if (result.find(key) != result.end())
			{
				ERROR_LOG("Duplicate key:%s in config.", key);
				fclose(fp);
				return false;
			}
			result[key] = value;
			lineno++;
		}
		fclose(fp);
		return true;
	}
Exemple #11
0
/* ###TODO: allow extra values for every key separated by a delimeter */
int
parse_conf_file (void)
{
  char line[512];
  char *path = NULL, *user_home = NULL;
  char *val, *c;
  FILE *file;
  int key = 0;

  if (conf.iconfigfile != NULL)
    path = alloc_string (conf.iconfigfile);
  else {
    user_home = getenv ("HOME");
    if (user_home == NULL)
      return 1;

    path = xmalloc (snprintf (NULL, 0, "%s/.goaccessrc", user_home) + 1);
    sprintf (path, "%s/.goaccessrc", user_home);
  }
  file = fopen (path, "r");

  /* could not open conf file, if so prompt conf dialog */
  if (file == NULL) {
    free (path);
    return 1;
  }

  while (fgets (line, sizeof line, file) != NULL) {
    unsigned int i;
    for (i = 0; i < ARRAY_SIZE (keywords); i++) {
      if (strstr (line, keywords[i].keyword) != NULL)
        key = keywords[i].key_id;
    }
    if ((val = strchr (line, ' ')) == NULL) {
      free (path);
      return 1;
    }
    for (c = val; *c; c++) {
      /* get everything after the space */
      if (!isspace (c[0])) {
        set_conf_vars (key, trim_str (c));
        break;
      }
    }
  }
  fclose (file);
  free (path);
  return 0;
}
Exemple #12
0
/* Process keyphrases from Google search, cache, and translate.
 * Note that the referer hasn't been decoded at the entry point
 * since there could be '&' within the search query. */
static int
process_keyphrases (char *ref)
{
  char *r, *ptr, *pch, *referer;
  int encoded = 0;

  if (!(strstr (ref, "http://www.google.")) &&
      !(strstr (ref, "http://webcache.googleusercontent.com/")) &&
      !(strstr (ref, "http://translate.googleusercontent.com/")))
    return 1;

  /* webcache.googleusercontent */
  if ((r = strstr (ref, "/+&")) != NULL)
    return 1;
  /* webcache.googleusercontent */
  else if ((r = strstr (ref, "/+")) != NULL)
    r += 2;
  /* webcache.googleusercontent */
  else if ((r = strstr (ref, "q=cache:")) != NULL) {
    pch = strchr (r, '+');
    if (pch)
      r += pch - r + 1;
  }
  /* www.google.* or translate.googleusercontent */
  else if ((r = strstr (ref, "&q=")) != NULL ||
           (r = strstr (ref, "?q=")) != NULL)
    r += 3;
  else if ((r = strstr (ref, "%26q%3D")) != NULL ||
           (r = strstr (ref, "%3Fq%3D")) != NULL)
    encoded = 1, r += 7;
  else
    return 1;

  if (!encoded && (ptr = strchr (r, '&')) != NULL)
    *ptr = '\0';
  else if (encoded && (ptr = strstr (r, "%26")) != NULL)
    *ptr = '\0';

  referer = decode_url (r);
  if (referer == NULL || *referer == '\0')
    return 1;

  referer = char_replace (referer, '+', ' ');
  process_generic_data (ht_keyphrases, trim_str (referer));
  free (referer);

  return 0;
}
Exemple #13
0
int RDFParser::read_conditions(stringstream & stream) {

	int ret=0;
	string condlist, cond;
	read_str(stream, "{");	
	getline(stream, condlist, '}');
	
	trim_str(condlist);

	istringstream ss(condlist);
	while (getline(ss, cond, ';')) {
		ret = add_cond(cond);
		if (ret < 0)
			return ret;		
	}
	return 0;
}
void send_outgoing_command(char* user_msg, int server_sock) {
	int bytes_sent = -1; 
  	char to_send[BUFFER_SIZE];
	char msg_copy[BUFFER_SIZE]; //strtok modifies the data in the argument. So use this copy. 
	strcpy(msg_copy, user_msg); 

	trim_str(user_msg);
	char* token = strtok(user_msg, " ");

	if (token == NULL || strlen(token) <= 0) { //Do nothing if user sends bad / empty command
		return; 
	}

	if (strcmp(token, MSG_CMD) == 0 || strcmp(token, JOIN_CMD) == 0 || 
		strcmp(token, LIST_CMD) == 0 || strcmp(token, CONNECT_CMD) == 0 || 
		strcmp(token, HELP_CMD) == 0 || strcmp(token, ROOMS_CMD) == 0 || //If user typed a valid command, send as-is 
		strcmp(token, LIST_ALL_CMD) == 0 ) { //If user typed a valid command, send as-is 
		strcpy(to_send, msg_copy); 
	}	
	else if (strcmp(token, QUIT_CMD) == 0) { //Quit command: send quit message to notify server, then exit program
		endwin(); 
		printf("%s", QUIT_MSG); 
		send(server_sock, msg_copy, strlen(msg_copy) + 1, MSG_MORE);
		close(server_sock); 
		exit(EXIT_SUCCESS); 
	}
	else if (strcmp(token, SLEEP_CMD) == 0) {
		usleep(500); 
	}
	else { //Else we assume client is just chatting, prepend +MSG to string
		sprintf(to_send, "%s %s", MSG_CMD, msg_copy); 
	}

	if ((bytes_sent = send(server_sock, to_send, strlen(to_send) + 1, MSG_MORE)) < 0) { 
		add_msg_to_scrn("Error writing to server socket. Attempting again.\n"); 
	}
	else if (bytes_sent == 0) {
		endwin(); 
		printf("Failed to write bytes to server socket. Exiting program...\n"); 
		exit(EXIT_FAILURE); 
	}

}
Exemple #15
0
char *read_file (char *fname)
{
  int fd = open(fname, O_RDONLY);
  if ( fd == -1 )
    {
      if ( errno == ENOENT )
        return NULL;
      else
        error("Failed to open file: %s: %s", fname, error_msg());
    }
  struct stat attribs;
  if ( fstat(fd, &attribs) == -1 )
    error("Failed to access file attributes: %s: %s", fname, error_msg());
  int len = attribs.st_size;
  char *content = (char *)malloc(len+1);
  if ( content == NULL )
    error("Failed to allocate memory for content: %s", error_msg());
  read_cmpl_chk(fd, content, len);
  content[len] = 0;
  return trim_str(content);
}
Exemple #16
0
static char *
parse_string (char **str, char end, int cnt)
{
  int idx = 0;
  char *pch = *str, *p;
  do {
    if (*pch == end)
      idx++;
    if ((*pch == end && cnt == idx) || *pch == '\0') {
      size_t len = (pch - *str + 1);
      p = xmalloc (len);
      memcpy (p, *str, (len - 1));
      p[len - 1] = '\0';
      *str += len - 1;
      return trim_str (p);
    }
    /* advance to the first unescaped delim */
    if (*pch == '\\')
      pch++;
  } while (*pch++);
  return NULL;
}
Exemple #17
0
/* returns the color of an associated string,
   -1 if color could not be indicated,
   this is a helper function for parse_rc_file */
short
str_to_color(char *clrstr) {
   trim_str(clrstr);
   if (strcmp(clrstr, "BLACK") == 0)
      return COLOR_BLACK;
   else if (strcmp(clrstr, "RED") == 0)
      return COLOR_RED;
   else if (strcmp(clrstr, "GREEN") == 0)
      return COLOR_GREEN;
   else if (strcmp(clrstr, "YELLOW") == 0)
      return COLOR_YELLOW;
   else if (strcmp(clrstr, "BLUE") == 0)
      return COLOR_BLUE;
   else if (strcmp(clrstr, "MAGENTA") == 0)
      return COLOR_MAGENTA;
   else if (strcmp(clrstr, "CYAN") == 0)
      return COLOR_CYAN;
   else if (strcmp(clrstr, "WHITE") == 0)
      return COLOR_WHITE;
   else
      return ERROR_CORRUPT_RC_FILE; /* error */
}
Exemple #18
0
static char *
decode_url (char *url)
{
  char *out, *ptr;
  const char *c;

  if ((url == NULL) || (*url == '\0'))
    return NULL;

  out = ptr = xstrdup (url);
  for (c = url; *c; c++) {
    if (*c != '%' || !isxdigit (c[1]) || !isxdigit (c[2]))
      *ptr++ = *c;
    else {
      *ptr++ = (BASE16_TO_10 (c[1]) * 16) + (BASE16_TO_10 (c[2]));
      c += 2;
    }
  }
  *ptr = 0;
  strip_newlines (out);

  return trim_str (out);
}
Exemple #19
0
/**
 * parse_buf - Parse a text buffer for cheats.
 * @list: list to add cheats to
 * @buf: buffer holding text (must be NUL-terminated!)
 * @return: 0: success, -1: error
 */
int parse_buf(gamelist_t *list, const char *buf)
{
	parser_ctx_t ctx;
	char line[LINE_MAX + 1];
	int nl = 1;

	if (list == NULL || buf == NULL)
		return -1;

	init_parser(&ctx);

	while (*buf) {
		/* Scanner */
		int len = chr_idx(buf, LF);
		if (len < 0)
			len = strlen(line);
		else if (len > LINE_MAX)
			len = LINE_MAX;

		if (!is_empty_substr(buf, len)) {
			strncpy(line, buf, len);
			line[len] = NUL;

			/* Screener */
			term_str(line, is_cmt_str);
			trim_str(line);

			/* Parser */
			if (strlen(line) > 0 && parse_line(line, nl, &ctx, list) < 0)
				return -1;
		}
		nl++;
		buf += len + 1;
	}

	return 0;
}
/*FUNC-************************************************************************/
int process_config(void)
{
  FILE *in;
  char line[1024];
  char *ptr;
  char *key;
  int line_num;
  int ret;

  in = fopen(dnswld.proc.config_file, "r");
  if (in == NULL)
  {
    PUTS_OSYS(LOG_INFO, "  Failed to open [%s]", dnswld.proc.config_file);
    ret = RET_FILE_OPEN_ERROR;
    goto EXIT;
  }

  line_num = 0;
  while (TRUE)
  {
    line_num++;
    ptr = fgets(line, sizeof(line), in);
    if (!ptr)
    {
      break;
    }

    ptr = trim_str(ptr);

    if ((!strlen(ptr)) || (is_comment(ptr)))
    {
      continue;
    }

    key = strsep(&ptr, ":");
    if (ptr == NULL)
    {
      PUTS_OSYS(LOG_INFO, "Unrecognized statement at line: [%d]", line_num);
      ret = RET_INVALID_CONFIG;
      goto EXIT;
    }

    key = trim_str(key);
    ptr = trim_str(ptr);

    if ((!key) || (!ptr) || (!strlen(key)) || (!strlen(ptr)))
    {
      PUTS_OSYS(LOG_INFO, "Empty keyword/value at line: [%d]", line_num);
      ret = RET_INVALID_CONFIG;
      goto EXIT;
    }

    if (!strcasecmp(key, CFG_BIND))
    {
    }
    else if (!strcasecmp(key, CFG_WHITELIST))
    {
      ret = parse_add_whitelist_entries(ptr);
    }
    else if (!strcasecmp(key, CFG_CHAINS))
    {
      ret = parse_add_chains(ptr);
    }
    else if (!strcasecmp(key, CFG_IPTABLES_PATH))
    {
      strncpy(dnswld.fw.iptables_path, ptr, FILENAME_MAX_LEN - 1);
    }
    else
    {
      PUTS_OSYS(LOG_INFO, "Invalid keyword at line: [%d]", line_num);
      ret = RET_INVALID_CONFIG;
      goto EXIT;
    }
  }

  ret = RET_OK;

  EXIT:

  if (in)
  {
    fclose(in);
  }

  return(ret);
}
Exemple #21
0
static char *standardize_str(char *str)
{
    return strcpy_lower(trim_str(str));
}
Exemple #22
0
static char *
parse_req (char *line, GLogItem * glog)
{
  const char *lookfor = NULL;
  char *req, *request, *req_l = NULL, *req_r = NULL;
  char *method = NULL, *protocol = NULL;
  ptrdiff_t req_len;

  if ((lookfor = "OPTIONS ", req_l = strstr (line, lookfor)) != NULL ||
      (lookfor = "GET ", req_l = strstr (line, lookfor)) != NULL ||
      (lookfor = "HEAD ", req_l = strstr (line, lookfor)) != NULL ||
      (lookfor = "POST ", req_l = strstr (line, lookfor)) != NULL ||
      (lookfor = "PUT ", req_l = strstr (line, lookfor)) != NULL ||
      (lookfor = "DELETE ", req_l = strstr (line, lookfor)) != NULL ||
      (lookfor = "TRACE ", req_l = strstr (line, lookfor)) != NULL ||
      (lookfor = "CONNECT ", req_l = strstr (line, lookfor)) != NULL ||
      (lookfor = "PATCH", req_l = strstr (line, lookfor)) != NULL ||
      (lookfor = "options ", req_l = strstr (line, lookfor)) != NULL ||
      (lookfor = "get ", req_l = strstr (line, lookfor)) != NULL ||
      (lookfor = "head ", req_l = strstr (line, lookfor)) != NULL ||
      (lookfor = "post ", req_l = strstr (line, lookfor)) != NULL ||
      (lookfor = "put ", req_l = strstr (line, lookfor)) != NULL ||
      (lookfor = "delete ", req_l = strstr (line, lookfor)) != NULL ||
      (lookfor = "trace ", req_l = strstr (line, lookfor)) != NULL ||
      (lookfor = "connect ", req_l = strstr (line, lookfor)) != NULL ||
      (lookfor = "patch", req_l = strstr (line, lookfor)) != NULL) {
    /* didn't find it - weird  */
    if ((req_r = strstr (line, " HTTP/1.0")) == NULL &&
        (req_r = strstr (line, " HTTP/1.1")) == NULL)
      return alloc_string ("-");

    req_l += strlen (lookfor);
    req_len = req_r - req_l;

    /* make sure we don't have some weird requests */
    if (req_len <= 0)
      return alloc_string ("-");

    req = xmalloc (req_len + 1);
    strncpy (req, req_l, req_len);
    req[req_len] = 0;

    if (conf.append_method) {
      method = trim_str (xstrdup (lookfor));
      str_to_upper (method);
      glog->method = method;
    }

    if (conf.append_protocol) {
      protocol = xstrdup (++req_r);
      str_to_upper (protocol);
      glog->protocol = protocol;
    }
  } else
    req = alloc_string (line);

  request = decode_url (req);
  if (request != NULL && *request != '\0') {
    free (req);
    return request;
  }

  return req;
}
/* clean_ban_mask:	makes a proper banmask
 * RETURNS: pointer to correct banmask or NULL in case of error
 * NOTES:
 * - A pointer is returned to a static buffer, which is overwritten
 *   on next clean_ban_mask or make_nick_user_host call.
 * - mask is fragged in some cases, this could be bad.
 */
char *clean_ban_mask(char *mask, int what, aClient *cptr)
{
	char *cp;
	char *user;
	char *host;
	Extban *p;

	cp = index(mask, ' ');
	if (cp)
		*cp = '\0';

	/* Strip any ':' at beginning coz that desynchs clients/banlists */
	for (; (*mask && (*mask == ':')); mask++);
	if (!*mask)
		return NULL;

	/* Extended ban? */
	if ((*mask == '~') && mask[1] && (mask[2] == ':'))
	{
		if (RESTRICT_EXTENDEDBANS && MyClient(cptr) && !IsAnOper(cptr))
		{
			if (!strcmp(RESTRICT_EXTENDEDBANS, "*"))
			{
				sendnotice(cptr, "Setting/removing of extended bans has been disabled");
				return NULL;
			}
			if (strchr(RESTRICT_EXTENDEDBANS, mask[1]))
			{
				sendnotice(cptr, "Setting/removing of extended bantypes '%s' has been disabled",
					RESTRICT_EXTENDEDBANS);
				return NULL;
			}
		}
		p = findmod_by_bantype(mask[1]);
		if (!p)
		{
			/* extended bantype not supported, what to do?
			 * Here are the rules:
			 * - if from a remote client/server: allow it (easy upgrading,
			 *   no desynch)
			 * - if from a local client trying to REMOVE the extban,
			 *   allow it too (so you don't get "unremovable" extbans).
			 */
			if (!MyClient(cptr) || (what == MODE_DEL))
				return mask; /* allow it */
			return NULL; /* reject */
		}
		if (p->conv_param)
			return p->conv_param(mask);
		/* else, do some basic sanity checks and cut it off at 80 bytes */
		if ((cp[1] != ':') || (cp[2] == '\0'))
		    return NULL; /* require a ":<char>" after extban type */
		if (strlen(mask) > 80)
			mask[80] = '\0';
		return mask;
	}

	if ((*mask == '~') && !strchr(mask, '@'))
		return NULL; /* not an extended ban and not a ~user@host ban either. */

	if ((user = index((cp = mask), '!')))
		*user++ = '\0';
	if ((host = rindex(user ? user : cp, '@')))
	{
		*host++ = '\0';

		if (!user)
			return make_nick_user_host(NULL, trim_str(cp,USERLEN), 
				trim_str(host,HOSTLEN));
	}
	else if (!user && index(cp, '.'))
		return make_nick_user_host(NULL, NULL, trim_str(cp,HOSTLEN));
	return make_nick_user_host(trim_str(cp,NICKLEN), trim_str(user,USERLEN), 
		trim_str(host,HOSTLEN));
}
Exemple #24
0
/* parses configuration file to feed getopt_long */
int
parse_conf_file (int *argc, char ***argv)
{
  char line[MAX_LINE_CONF + 1];
  char *path = NULL, *val, *opt, *p;
  FILE *file;
  int i;
  size_t idx;

  /* assumes program name is on argv[0], though, it is not guaranteed */
  append_to_argv (&nargc, &nargv, xstrdup ((char *) *argv[0]));

  /* determine which config file to open, default or custom */
  path = get_config_file_path ();
  if (path == NULL)
    return ENOENT;

  /* could not open conf file, if so prompt conf dialog */
  if ((file = fopen (path, "r")) == NULL) {
    free (path);
    return ENOENT;
  }

  while (fgets (line, sizeof line, file) != NULL) {
    if (line[0] == '\n' || line[0] == '\r' || line[0] == '#')
      continue;

    /* key */
    idx = strcspn (line, " \t");
    if (strlen (line) == idx)
      FATAL ("Malformed config key at line: %s", line);

    line[idx] = '\0';

    /* make old config options backwards compatible by
     * substituting underscores with dashes */
    while ((p = strpbrk (line, "_")) != NULL)
      *p = '-';

    /* Ignore the following options when reading the config file */
    if (in_ignore_cmd_opts (line))
      continue;

    /* value */
    val = line + (idx + 1);
    idx = strspn (val, " \t");
    if (strlen (line) == idx)
      FATAL ("Malformed config value at line: %s", line);
    val = val + idx;
    val = trim_str (val);

    if (strcmp ("false", val) == 0)
      continue;

    /* set it as command line options */
    opt = xmalloc (snprintf (NULL, 0, "--%s", line) + 1);
    sprintf (opt, "--%s", line);

    append_to_argv (&nargc, &nargv, opt);
    if (strcmp ("true", val) != 0)
      append_to_argv (&nargc, &nargv, xstrdup (val));
  }

  /* give priority to command line arguments */
  for (i = 1; i < *argc; i++)
    append_to_argv (&nargc, &nargv, xstrdup ((char *) (*argv)[i]));

  *argc = nargc;
  *argv = (char **) nargv;

  fclose (file);

  if (conf.iconfigfile == NULL)
    conf.iconfigfile = xstrdup (path);

  free (path);
  return 0;
}
Exemple #25
0
bool ParseMeal(std::ifstream & infile, Meal & meal)
{
	if (true == infile.eof())
	{
		return false;
	}

	const int MAX_TOKEN = 256;
	std::string line;
	std::string tokenBuf(MAX_TOKEN, '\0');

	const char * delim = ",\n";
	
	do
	{
		// read line
		std::getline(infile, line);

		// grab first token
		char * token = nullptr;
		char * nextToken = nullptr;
		token = strtok_s(&line[0], delim, &nextToken);

		bool mealTypeParsed = false;
		bool caloriesParsed = false;

		// locals for meal header row
		MealType mealType = MealType::MEAL_BREAKFAST;
		float calories;

		// walk the line
		while (token != nullptr && nextToken != nullptr)
		{
			// valid meal type?
			std::string tokTrimmed = token;
			trim_str(tokTrimmed);

			String tokStr(ConvertStringToWString(tokTrimmed));

			if (true == StringToMealType(tokStr, mealType))
			{
				mealTypeParsed = true;
			}
			else if (true == mealTypeParsed)
			{
				calories = (float)atof(token);

				// if calories column is empty or whitespace, or an invalid number, skip this meal
				if (calories > 0)
				{
					caloriesParsed = true;
					break;
				}
			}

			// next token plz
			token = strtok_s(nullptr, delim, &nextToken);
		}

		// if we didn't parse a meal line, fail
		if (false == mealTypeParsed || false == caloriesParsed)
		{
			// try the next line
			continue;
		}

		assert(true == IsValidMealType(mealType) && calories > 0);

		// parse as many food items are below the meal line
		Meal workingMeal(mealType, calories);

		FoodItem foodItem;
		while (false == infile.eof() && true == ParseFoodItem(infile, foodItem))
		{
			workingMeal.AddFoodItem(foodItem);

			// make sure this line isn't starting a new meal
			std::string peekFirstToken;
			if (false == PeekString(infile, delim, peekFirstToken))
			{
				// couldn't read a token, done with this meal
				return true;
			}

			trim_str(peekFirstToken);
			String strFirstToken(ConvertStringToWString(peekFirstToken));
			MealType nextTokMealType;
			if (true == StringToMealType(strFirstToken, nextTokMealType))
			{
				// next token is a meal type, so we're done with this meal
				break;
			}
		}

		// meal is valid
		meal = workingMeal;
		
		break;
	} 
	while (false == infile.eof());

	return true;
}
Exemple #26
0
struct amf_cluster *amf_config_read (char **error_string)
{
	char buf[1024];
	char *line;
	FILE *fp;
	const char *filename;
	amf_object_type_t current_parse = AMF_NONE;
	int line_number = 0;
	char *loc;
	int i;
	struct amf_cluster       *cluster;
	struct amf_application   *app = 0;
	struct amf_node          *node = 0;
	struct amf_sg            *sg = 0;
	struct amf_su            *su = 0;
	struct amf_comp          *comp = 0;
	struct amf_si            *si = 0;
	struct amf_si_ranked_su  *si_ranked_su = 0;
	struct amf_si_dependency *si_dependency = 0;
	struct amf_healthcheck   *healthcheck = 0;
	struct amf_csi           *csi = 0;
	struct amf_csi_attribute *attribute = 0;
	SaStringT                 env_var;
	int                       su_cnt = 0;
	int                       sg_cnt = 0;
	int                       comp_env_var_cnt = 0;
	int                       comp_cs_type_cnt = 0;
	int                       csi_attr_cnt = 0;
	int                       csi_dependencies_cnt = 0;
	const char                *error_reason = NULL;
	char                     *value;
	filename = getenv ("COROSYNC_AMF_CONFIG_FILE");
	if (!filename) {
		filename = COROSYSCONFDIR "/amf.conf";
	}

	fp = fopen (filename, "r");
	if (fp == 0) {
		sprintf (buf, "Can't read %s file reason = (%s).\n",
			filename, strerror (errno));
		*error_string = buf;
		return NULL;
	}

	cluster = amf_cluster_new ();
	assert (cluster != NULL);

	while (fgets (buf, 255, fp)) {
		line_number += 1;
		line = buf;
		if (strlen(line) > 0) {
			line[strlen(line) - 1] = '\0';
		}
		/*
		 * Clear out comments and empty lines
		 */
		if (line[0] == '#' || line[0] == '\0' || line[0] == '\n') {
			continue;
		}

		/*
		 * Clear out white space and tabs
		 */
		for (i = strlen (line) - 1; i > -1; i--) {
			if (line[i] == '\t' || line[i] == ' ') {
				line[i] = '\0';
			} else {
				break;
			}
		}

		/* Trim whitespace from beginning of string */
		line = rm_beginning_ws(line);
		error_reason = line;
		error_reason = NULL;
		switch (current_parse) {
		case AMF_NONE:
			if ((loc = strstr_rs (line, "safAmfCluster=")) != 0) {
				setSaNameT (&cluster->name, trim_str (loc));
				current_parse = AMF_CLUSTER;
			} else {
				goto parse_error;
			}
			break;

		case AMF_CLUSTER:
			if ((loc = strstr_rs (line, "saAmfClusterClmCluster=")) != 0) {
				setSaNameT (&cluster->saAmfClusterClmCluster, loc);
			} else if ((loc = strstr_rs (line, "saAmfClusterStartupTimeout=")) != 0) {
				cluster->saAmfClusterStartupTimeout = atol(loc);
			} else if ((loc = strstr_rs (line, "safAmfNode=")) != 0) {
				node = amf_node_new (cluster, trim_str (loc));
				cluster->node_head = node;
				current_parse = AMF_NODE;
			} else if ((loc = strstr_rs (line, "safApp=")) != 0) {
				app = amf_application_new (cluster);
				setSaNameT (&app->name, trim_str (loc));
				current_parse = AMF_APPLICATION;
				sg_cnt = 0;
			} else if (strstr_rs (line, "}")) {
				if (cluster->saAmfClusterStartupTimeout == -1) {
					error_reason = "saAmfClusterStartupTimeout missing";
					goto parse_error;
				}
				/* spec: set to default value if zero */
				if (cluster->saAmfClusterStartupTimeout == 0) {
					cluster->saAmfClusterStartupTimeout = COROSYNC_CLUSTER_STARTUP_TIMEOUT;
				}
				current_parse = AMF_NONE;
			} else {
				goto parse_error;
			}
			break;

		case AMF_NODE:
			if ((loc = strstr_rs (line, "saAmfNodeSuFailOverProb=")) != 0) {
				node->saAmfNodeSuFailOverProb = atol(loc);
			} else if ((loc = strstr_rs (line, "saAmfNodeSuFailoverMax=")) != 0) {
				node->saAmfNodeSuFailoverMax = atol(loc);
			} else if ((loc = strstr_rs (line, "saAmfNodeClmNode=")) != 0) {
				setSaNameT (&node->saAmfNodeClmNode, trim_str (loc));
			} else if ((loc = strstr_rs (line, "saAmfNodeAutoRepair=")) != 0) {
				if (strcmp (loc, "true") == 0) {
					node->saAmfNodeAutoRepair = SA_TRUE;
				} else if (strcmp (loc, "false") == 0) {
					node->saAmfNodeAutoRepair = SA_FALSE;
				} else {
					goto parse_error;
				}
			} else if ((loc = strstr_rs (line, "saAmfNodeRebootOnTerminationFailure=")) != 0) {
				if (strcmp (loc, "true") == 0) {
					node->saAmfNodeRebootOnTerminationFailure = SA_TRUE;
				} else if (strcmp (loc, "false") == 0) {
					node->saAmfNodeRebootOnTerminationFailure = SA_FALSE;
				} else {
					goto parse_error;
				}
			} else if ((loc = strstr_rs (line, "saAmfNodeRebootOnInstantiationFailure=")) != 0) {
				if (strcmp (loc, "true") == 0) {
					node->saAmfNodeRebootOnInstantiationFailure = SA_TRUE;
				} else if (strcmp (loc, "false") == 0) {
					node->saAmfNodeRebootOnInstantiationFailure = SA_FALSE;
				} else {
					goto parse_error;
				}
			} else if (strstr_rs (line, "}")) {
				if (node->saAmfNodeSuFailOverProb == -1) {
					error_reason = "saAmfNodeSuFailOverProb missing";
					goto parse_error;
				}
				if (node->saAmfNodeSuFailoverMax == ~0) {
					error_reason = "saAmfNodeSuFailoverMax missing";
					goto parse_error;
				}
				if (node->saAmfNodeClmNode.length == 0) {
					error_reason = "saAmfNodeClmNode missing";
					goto parse_error;
				}
				current_parse = AMF_CLUSTER;
			} else {
				goto parse_error;
			}
			break;

		case AMF_APPLICATION:
			if ((loc = strstr_rs (line, "clccli_path=")) != 0) {
				app->clccli_path = amf_strdup(loc);
			} else if ((loc = strstr_rs (line, "safSg=")) != 0) {
				sg = amf_sg_new (app, trim_str (loc));
				sg_cnt++;
				sg->recovery_scope.comp = NULL;
				sg->recovery_scope.event_type = 0;
				sg->recovery_scope.node = NULL;
				sg->recovery_scope.sis = NULL;
				sg->recovery_scope.sus = NULL;
				current_parse = AMF_SG;
				su_cnt = 0;
			} else if ((loc = strstr_rs (line, "safSi=")) != 0) {
				si = amf_si_new (app, trim_str (loc));
				current_parse = AMF_SI;
			} else if ((loc = strstr_rs (line, "safCSType=")) != 0) {
				current_parse = AMF_CS_TYPE;
			} else if (strstr_rs (line, "}")) {
				if (sg_cnt == 1) {
					for (si = app->si_head; si != NULL; si = si->next) {
						memcpy (&si->saAmfSIProtectedbySG, &sg->name,
							sizeof (SaNameT));
					}
				} else {
					for (si = app->si_head; si != NULL; si = si->next) {
						if (si->saAmfSIProtectedbySG.length == 0) {
							error_reason = "saAmfSIProtectedbySG not set in SI"
								", needed when several SGs are specified.";
							goto parse_error;
						}
					}
				}
				current_parse = AMF_CLUSTER;
			} else {
				goto parse_error;
			}
			break;

		case AMF_SG:
			if ((loc = strstr_rs (line, "clccli_path=")) != 0) {
				sg->clccli_path = amf_strdup(loc);
			} else if ((loc = strstr_rs (line, "saAmfSGRedundancyModel=")) != 0) {
				if (strcmp (loc, "2n") == 0) {
					sg->saAmfSGRedundancyModel = SA_AMF_2N_REDUNDANCY_MODEL;
				} else if (strcmp (loc, "nplusm") == 0) {
					sg->saAmfSGRedundancyModel = SA_AMF_NPM_REDUNDANCY_MODEL;
				} else if (strcmp (loc, "nway") == 0) {
					error_reason = "nway redundancy model not supported";
					goto parse_error;
				} else if (strcmp (loc, "nwayactive") == 0) {
					error_reason = "nway active redundancy model not supported";
					goto parse_error;
				} else if (strcmp (loc, "noredundancy") == 0) {
					sg->saAmfSGRedundancyModel = SA_AMF_NO_REDUNDANCY_MODEL;
				} else {
					goto parse_error;
				}
			} else if ((loc = strstr_rs (line, "saAmfSGNumPrefActiveSUs=")) != 0) {
				sg->saAmfSGNumPrefActiveSUs = atoi (loc);
			} else if ((loc = strstr_rs (line, "saAmfSGNumPrefStandbySUs=")) != 0) {
				sg->saAmfSGNumPrefStandbySUs = atoi (loc);
			} else if ((loc = strstr_rs (line, "saAmfSGNumPrefInserviceSUs=")) != 0) {
				sg->saAmfSGNumPrefInserviceSUs = atoi (loc);
			} else if ((loc = strstr_rs (line, "saAmfSGNumPrefAssignedSUs=")) != 0) {
				sg->saAmfSGNumPrefAssignedSUs = atoi (loc);
			} else if ((loc = strstr_rs (line, "saAmfSGMaxActiveSIsperSUs=")) != 0) {
				sg->saAmfSGMaxActiveSIsperSUs = atoi (loc);
			} else if ((loc = strstr_rs (line, "saAmfSGMaxStandbySIsperSUs=")) != 0) {
				sg->saAmfSGMaxStandbySIsperSUs = atoi (loc);
			} else if ((loc = strstr_rs (line, "saAmfSGCompRestartProb=")) != 0) {
				sg->saAmfSGCompRestartProb = atoi (loc);
			} else if ((loc = strstr_rs (line, "saAmfSGCompRestartMax=")) != 0) {
				sg->saAmfSGCompRestartMax = atoi (loc);
			} else if ((loc = strstr_rs (line, "saAmfSGSuRestartProb=")) != 0) {
				sg->saAmfSGSuRestartProb = atoi (loc);
			} else if ((loc = strstr_rs (line, "saAmfSGSuRestartMax=")) != 0) {
				sg->saAmfSGSuRestartMax = atoi (loc);
			} else if ((loc = strstr_rs (line, "saAmfSGAutoAdjustProb=")) != 0) {
				sg->saAmfSGAutoAdjustProb = atoi (loc);
			} else if ((loc = strstr_rs (line, "saAmfSGAutoRepair=")) != 0) {
				sg->saAmfSGAutoRepair = atoi (loc);
			} else if ((loc = strstr_rs (line, "safSu=")) != 0) {
				su = amf_su_new (sg, trim_str (loc));
				su_cnt++;
				current_parse = AMF_SU;
			} else if (strstr_rs (line, "}")) {
				if (sg->saAmfSGRedundancyModel == 0) {
					error_reason = "saAmfSGRedundancyModel missing";
					goto parse_error;
				}
				if (sg->saAmfSGCompRestartProb == -1) {
					error_reason = "saAmfSGCompRestartProb missing";
					goto parse_error;
				}
				if (sg->saAmfSGCompRestartMax == ~0) {
					error_reason = "saAmfSGCompRestartMax missing";
					goto parse_error;
				}
				if (sg->saAmfSGSuRestartProb == -1) {
					error_reason = "saAmfSGSuRestartProb missing";
					goto parse_error;
				}
				if (sg->saAmfSGSuRestartMax == ~0) {
					error_reason = "saAmfSGSuRestartMax missing";
					goto parse_error;
				}
				if (sg->saAmfSGAutoAdjustProb == -1) {
					error_reason = "saAmfSGAutoAdjustProb missing";
					goto parse_error;
				}
				if (sg->saAmfSGAutoRepair > 1) {
					error_reason = "saAmfSGAutoRepair erroneous";
					goto parse_error;
				}
				if (sg->saAmfSGNumPrefInserviceSUs == ~0) {
					sg->saAmfSGNumPrefInserviceSUs = su_cnt;
				}
				if (sg->saAmfSGNumPrefAssignedSUs == ~0) {
					sg->saAmfSGNumPrefAssignedSUs =
						sg->saAmfSGNumPrefInserviceSUs;
				}
				current_parse = AMF_APPLICATION;
			} else {
				goto parse_error;
			}
			break;

		case AMF_SU:
			if ((loc = strstr_rs (line, "saAmfSUNumComponents=")) != 0) {
				su->saAmfSUNumComponents = atoi (loc);
			} else if ((loc = strstr_rs (line, "saAmfSUIsExternal=")) != 0) {
				su->saAmfSUIsExternal = atoi (loc);
			} else if ((loc = strstr_rs (line, "saAmfSUFailover=")) != 0) {
				su->saAmfSUFailover = atoi (loc);
			} else if ((loc = strstr_rs (line, "clccli_path=")) != 0) {
				su->clccli_path = amf_strdup(loc);
			} else if ((loc = strstr_rs (line, "saAmfSUHostedByNode=")) != 0) {
				setSaNameT (&su->saAmfSUHostedByNode, loc);
			} else if ((loc = strstr_rs (line, "safComp=")) != 0) {
				comp = amf_comp_new (su, trim_str (loc));
				comp_env_var_cnt = 0;
				comp_cs_type_cnt = 0;
				current_parse = AMF_COMP;
			} else if (strstr_rs (line, "}")) {
				if (su->saAmfSUNumComponents == 0) {
					error_reason = "saAmfSUNumComponents missing";
					goto parse_error;
				}
				if (su->saAmfSUIsExternal > 1) {
					error_reason = "saAmfSUIsExternal erroneous";
					goto parse_error;
				}
				if (su->saAmfSUFailover > 1) {
					error_reason = "saAmfSUFailover erroneous";
					goto parse_error;
				}
				if (strcmp ((char*)su->saAmfSUHostedByNode.value, "") == 0) {
					error_reason = "saAmfSUHostedByNode missing";
					goto parse_error;
				}
				current_parse = AMF_SG;
			} else {
				goto parse_error;
			}
			break;

		case AMF_COMP:
			if ((loc = strstr_rs (line, "clccli_path=")) != 0) {
				comp->clccli_path = amf_strdup(loc);
			} else if ((loc = strstr_rs (line, "saAmfCompCsTypes{")) != 0) {
				current_parse = AMF_COMP_CS_TYPE;
			} else if ((loc = strstr_rs(line, "saAmfCompCategory=")) != 0) {
				if (init_category(comp, loc) != 0) {
					error_reason = "unknown category";
					goto parse_error;
				}
			} else if ((loc = strstr_rs (line, "saAmfCompCapability=")) != 0) {
				if (init_capability(comp, loc) != 0) {
					error_reason = "unknown capability model";
					goto parse_error;
				}
			} else if ((loc = strstr_rs(line, "saAmfCompNumMaxActiveCsi=")) != 0) {
				comp->saAmfCompNumMaxActiveCsi = atol (loc);
			} else if ((loc = strstr_rs(line, "saAmfCompNumMaxStandbyCsi=")) != 0) {
				comp->saAmfCompNumMaxStandbyCsi = atol (loc);
			} else if ((loc = strstr_rs (line, "saAmfCompCmdEnv{")) != 0) {
				current_parse = AMF_COMP_ENV_VAR;
			} else if ((loc = strstr_rs(line, "saAmfCompDefaultClcCliTimeout=")) != 0) {
				comp->saAmfCompDefaultClcCliTimeout = atol (loc);
			} else if ((loc = strstr_rs(line, "saAmfCompDefaultCallbackTimeOut=")) != 0) {
				comp->saAmfCompDefaultCallbackTimeOut = atol (loc);
			} else if ((loc = strstr_rs (line, "saAmfCompInstantiateCmdArgv=")) != 0) {
				comp->saAmfCompInstantiateCmdArgv = amf_strdup(loc);
			} else if ((loc = strstr_rs ( line, "saAmfCompInstantiateCmd=")) != 0) {
				comp->saAmfCompInstantiateCmd = amf_strdup(loc);
			} else if ((loc = strstr_rs(line, "saAmfCompInstantiateTimeout=")) != 0) {
				comp->saAmfCompInstantiateTimeout = atol (loc);
			} else if ((loc = strstr_rs(line, "saAmfCompInstantiationLevel=")) != 0) {
				comp->saAmfCompInstantiationLevel = atol (loc);
			} else if ((loc = strstr_rs(line, "saAmfCompNumMaxInstantiateWithoutDelay=")) != 0) {
				comp->saAmfCompNumMaxInstantiateWithoutDelay = atol (loc);
			} else if ((loc = strstr_rs(line, "saAmfCompNumMaxInstantiateWithDelay=")) != 0) {
				comp->saAmfCompNumMaxInstantiateWithDelay = atol (loc);
			} else if ((loc = strstr_rs(line, "saAmfCompDelayBetweenInstantiateAttempts=")) != 0) {
				comp->saAmfCompDelayBetweenInstantiateAttempts = atol (loc);
			} else if ((loc = strstr_rs (line, "saAmfCompTerminateCmdArgv=")) != 0) {
				comp->saAmfCompTerminateCmdArgv = amf_strdup(loc);
			} else if ((loc = strstr_rs (line, "saAmfCompTerminateCmd=")) != 0) {
				comp->saAmfCompTerminateCmd = amf_strdup(loc);
			} else if ((loc = strstr_rs(line, "saAmfCompTerminateTimeout=")) != 0) {
				comp->saAmfCompTerminateTimeout = atol (loc);
			} else if ((loc = strstr_rs (line, "saAmfCompCleanupCmdArgv=")) != 0) {
				comp->saAmfCompCleanupCmdArgv = amf_strdup(loc);
			} else if ((loc = strstr_rs (line, "saAmfCompCleanupCmd=")) != 0) {
				comp->saAmfCompCleanupCmd = amf_strdup(loc);
			} else if ((loc = strstr_rs(line, "saAmfCompCleanupTimeout=")) != 0) {
				comp->saAmfCompCleanupTimeout = atol (loc);
			} else if ((loc = strstr_rs(line, "saAmfCompTerminateCallbackTimeout=")) != 0) {
				comp->saAmfCompTerminateCallbackTimeout = atol (loc);
			} else if ((loc = strstr_rs(line, "saAmfCompCSISetCallbackTimeout=")) != 0) {
				comp->saAmfCompCSISetCallbackTimeout = atol (loc);
			} else if ((loc = strstr_rs(line, "saAmfCompQuiescingCompleteTimeout=")) != 0) {
				comp->saAmfCompQuiescingCompleteTimeout = atol (loc);
			} else if ((loc = strstr_rs(line, "saAmfCompCSIRmvCallbackTimeout=")) != 0) {
				comp->saAmfCompCSIRmvCallbackTimeout = atol (loc);
			} else if ((loc = strstr_rs (line, "saAmfCompRecoveryOnError=")) != 0) {
				if (init_recovery_on_error (comp, loc) != 0) {
					error_reason = "bad value";
					goto parse_error;
				}
			} else if ((loc = strstr_rs (line, "saAmfCompDisableRestart=")) != 0) {
				if (strcmp (loc, "false") == 0) {
					comp->saAmfCompDisableRestart = SA_FALSE;
				} else if (strcmp (loc, "true") == 0) {
					comp->saAmfCompDisableRestart = SA_TRUE;
				} else {
					error_reason = "bad value";
					goto parse_error;
				}
			} else if ((loc = strstr_rs (line, "saAmfCompProxyCsi=")) != 0) {
				setSaNameT (&comp->saAmfCompProxyCsi, loc);
			} else if ((loc = strstr_rs (line, "safHealthcheckKey=")) != 0) {
				healthcheck = calloc (1, sizeof (struct amf_healthcheck));
				healthcheck->next = comp->healthcheck_head;
				comp->healthcheck_head = healthcheck;
				healthcheck->comp = comp;
				strcpy ((char *)healthcheck->safHealthcheckKey.key, trim_str (loc));
				healthcheck->safHealthcheckKey.keyLen = strlen (loc);
				current_parse = AMF_HEALTHCHECK;
			} else if (strstr_rs (line, "}")) {
				if (comp->saAmfCompCategory == 0) {
					error_reason = "category missing";
					goto parse_error;
				}
				if (comp->saAmfCompCapability == 0) {
					error_reason = "capability model missing";
					goto parse_error;
				}
				if (comp->saAmfCompCategory == SA_AMF_COMP_SA_AWARE) {
					comp->comptype = clc_component_sa_aware;
				} else if (comp->saAmfCompCategory == SA_AMF_COMP_PROXY) {
					if (comp->saAmfCompCapability == SA_AMF_COMP_NON_PRE_INSTANTIABLE) {
						comp->comptype = clc_component_proxied_non_pre;
					} else {
						comp->comptype = clc_component_proxied_pre;
					}
				} else if (comp->saAmfCompCategory == SA_AMF_COMP_LOCAL) {
					comp->comptype = clc_component_non_proxied_non_sa_aware;
				}
				if (comp->saAmfCompNumMaxActiveCsi == 0) {
					error_reason = "saAmfCompNumMaxActiveCsi missing";
					goto parse_error;
				}
				if (comp->saAmfCompNumMaxStandbyCsi == 0) {
					error_reason = "saAmfCompNumMaxStandbyCsi missing";
					goto parse_error;
				}
				if (comp->saAmfCompDefaultClcCliTimeout == 0) {
					error_reason = "saAmfCompDefaultClcCliTimeout missing or erroneous";
					goto parse_error;
				}
				if (comp->saAmfCompDefaultCallbackTimeOut == 0) {
					error_reason = "saAmfCompDefaultCallbackTimeOut missing or erroneous";
					goto parse_error;
				}
				if (comp->saAmfCompRecoveryOnError == 0) {
					error_reason = "saAmfCompRecoveryOnError missing";
					goto parse_error;
				}
				post_init_comp (comp);
				current_parse = AMF_SU;
			} else {
				error_reason = line;
				goto parse_error;
			}
			break;

		case AMF_COMP_CS_TYPE:
			if (strstr_rs (line, "}")) {
				current_parse = AMF_COMP;
			} else {
				comp_cs_type_cnt++;
				comp->saAmfCompCsTypes = realloc (comp->saAmfCompCsTypes,
					(comp_cs_type_cnt + 1) * sizeof(SaNameT));
				comp->saAmfCompCsTypes[comp_cs_type_cnt] = NULL;
				comp->saAmfCompCsTypes[comp_cs_type_cnt - 1] = amf_malloc (sizeof(SaNameT));
				setSaNameT (comp->saAmfCompCsTypes[comp_cs_type_cnt - 1], line);
			}
			break;

		case AMF_COMP_ENV_VAR:
			if (strstr_rs (line, "}")) {
				current_parse = AMF_COMP;
			} else if ((loc = strchr (line, '=')) != 0) {
				comp_env_var_cnt++;
				comp->saAmfCompCmdEnv = realloc (comp->saAmfCompCmdEnv,
					(comp_env_var_cnt + 1) * sizeof(SaStringT));
				comp->saAmfCompCmdEnv[comp_env_var_cnt] = NULL;
				env_var = comp->saAmfCompCmdEnv[comp_env_var_cnt - 1] = amf_strdup(line);
			} else {
				goto parse_error;
			}
			break;

		case AMF_HEALTHCHECK:
			if ((loc = strstr_rs (line, "saAmfHealthcheckPeriod=")) != 0) {
				healthcheck->saAmfHealthcheckPeriod = atoi (loc);
			} else if ((loc = strstr_rs (line, "saAmfHealthcheckMaxDuration=")) != 0) {
				healthcheck->saAmfHealthcheckMaxDuration = atoi (loc);
			} else if (strstr_rs (line, "}")) {
				current_parse = AMF_COMP;
			} else {
				goto parse_error;
			}
			break;

		case AMF_SI:
			if ((loc = strstr_rs (line, "safRankedSu=")) != 0) {
				si_ranked_su = calloc (1, sizeof(struct amf_si_ranked_su));
				si_ranked_su->si_next = si->ranked_sus;
				si->ranked_sus = si_ranked_su;
				si_ranked_su->si = si;
				setSaNameT (&si_ranked_su->name, trim_str (loc));
				current_parse = AMF_SI_RANKED_SU;
			} else if ((loc = strstr_rs (line, "safDepend=")) != 0) {
				si_dependency = calloc (1, sizeof(struct amf_si_dependency));
				si_dependency->next = si->depends_on;
				si->depends_on = si_dependency;
				setSaNameT (&si_dependency->name, trim_str (loc));
				current_parse = AMF_SI_DEPENDENCY;
			} else if ((loc = strstr_rs (line, "safCsi=")) != 0) {
				csi = calloc (1, sizeof(struct amf_csi));
				csi->next = si->csi_head;
				si->csi_head = csi;
				csi->si = si;
				setSaNameT (&csi->name, trim_str (loc));
				current_parse = AMF_CSI;
			} else if ((loc = strstr_rs (line, "saAmfSIProtectedbySG=")) != 0) {
				setSaNameT (&si->saAmfSIProtectedbySG, loc);
			} else if ((loc = strstr_rs (line, "saAmfSIRank=")) != 0) {
				si->saAmfSIRank = atoi (loc);
			} else if ((loc = strstr_rs (line, "saAmfSINumCSIs=")) != 0) {
				si->saAmfSINumCSIs = atoi (loc);
			} else if ((loc = strstr_rs (line, "saAmfSIPrefActiveAssignments=")) != 0) {
				si->saAmfSIPrefActiveAssignments = atoi (loc);
			} else if ((loc = strstr_rs (line, "saAmfSIPrefActiveAssignments=")) != 0) {
				si->saAmfSIPrefStandbyAssignments = atoi (loc);
			} else if (strstr_rs (line, "}")) {
				if (si->saAmfSINumCSIs == 0) {
					error_reason = "saAmfSINumCSIs missing";
					goto parse_error;
				}
				current_parse = AMF_APPLICATION;
			} else {
				goto parse_error;
			}
			break;

		case AMF_SI_RANKED_SU:
			if ((loc = strstr_rs (line, "saAmfRank=")) != 0) {
				si_ranked_su->saAmfRank = atoi (loc);
			} else if (strstr_rs (line, "}")) {
				current_parse = AMF_SI;
			} else {
				goto parse_error;
			}
			break;

		case AMF_SI_DEPENDENCY:
			if ((loc = strstr_rs (line, "saAmfToleranceTime=")) != 0) {
				si_dependency->saAmfToleranceTime = atoi (loc);
			} else if (strstr_rs (line, "}")) {
				current_parse = AMF_SI;
			} else {
				goto parse_error;
			}
			break;

		case AMF_CSI:
			if ((loc = strstr_rs (line, "saAmfCSTypeName=")) != 0) {
				setSaNameT (&csi->saAmfCSTypeName, loc);
			} else if ((loc = strstr_rs (line, "safCSIAttr=")) != 0) {
				attribute = calloc (1, sizeof(struct amf_csi_attribute));
				attribute->next = csi->attributes_head;
				csi->attributes_head = attribute;
				attribute->name = amf_strdup(loc);
				csi_attr_cnt = 1;
				current_parse = AMF_CSI_ATTRIBUTE;
			} else if ((loc = strstr_rs (line, "saAmfCsiDependencies{")) != 0) {
				csi_dependencies_cnt = 0;
				current_parse = AMF_CSI_DEPENDENCIES;
			} else if (strstr_rs (line, "}")) {
				if (strcmp(getSaNameT(&csi->saAmfCSTypeName), "") == 0) {
					error_reason = "saAmfCSTypeName missing";
					goto parse_error;
				}
				current_parse = AMF_SI;
			} else {
				goto parse_error;
			}
			break;

		case AMF_CSI_DEPENDENCIES:
			if (strstr_rs (line, "}")) {
				current_parse = AMF_CSI;
			} else if ((loc = strstr_rs (line, "saAmfCSIDependency=")) != 0) {
				csi_dependencies_cnt++;
				csi->saAmfCSIDependencies = realloc (csi->saAmfCSIDependencies,
					(csi_dependencies_cnt + 1) * sizeof(SaNameT));
				csi->saAmfCSIDependencies[csi_dependencies_cnt] = NULL;
				csi->saAmfCSIDependencies[csi_dependencies_cnt - 1] =
					amf_malloc (sizeof(SaNameT));
				setSaNameT (
					csi->saAmfCSIDependencies[csi_dependencies_cnt - 1], loc);
			} else {
				goto parse_error;
			}
			break;

		case AMF_CSI_ATTRIBUTE:
			if ((loc = strstr_rs (line, "}")) != 0) {
				current_parse = AMF_CSI;
			} else {
				value = rm_beginning_ws (line);
				attribute->value = realloc (attribute->value,
					sizeof (SaStringT) * (csi_attr_cnt + 1));
				attribute->value[csi_attr_cnt - 1] = amf_strdup(value);
				attribute->value[csi_attr_cnt] = NULL;
				csi_attr_cnt++;
			}
			break;

		case AMF_CS_TYPE:
			if ((loc = strstr_rs (line, "}")) != 0) {
				current_parse = AMF_APPLICATION;
			}
			break;

		default:
			error_reason = "Invalid state\n";
			goto parse_error;
			break;
		}
	}

	fclose (fp);

	sprintf (buf, "Successfully read AMF configuration file '%s'.\n", filename);
	*error_string = buf;

	return cluster;

parse_error:
	sprintf (buf, "parse error at %s: %d: %s\n",
		filename, line_number, error_reason);
	*error_string = buf;
	fclose (fp);
	return NULL;
}