Example #1
0
/** 
 * Beginning of the transform command, open a transformation switch 
 */
int			cmd_match()
{
  list_t		*list;
  revmexpr_t		*ind;

  PROFILER_IN(__FILE__, __FUNCTION__, __LINE__);

  /* The first time we enter this command, we have to fetch the params */
  list = (list_t *) world.curjob->iter[world.curjob->curloop].container;
  ind  = world.curjob->iter[world.curjob->curloop].curind;

  if (!list || !ind || strcmp(ind->label, world.curjob->curcmd->param[0]) || 
      list->type != ASPECT_TYPE_EXPR)
    {
      PROFILER_ERR(__FILE__, __FUNCTION__, __LINE__,
		   "Match/Rewrite only acts on iterated lists of expressions", -1);
    }

  /* We assume that the rewritten expression is the induction variable */
  world.curjob->recur[world.curjob->curscope].rwrt.matchexpr = ind;
  
  /* Create or flush the transformed expressions output list */
  list = elist_find("transformed");
  if (list)
    {
      elist_empty(list->name);
      world.curjob->recur[world.curjob->curscope].rwrt.transformed = list;
    }
  else
    {
      XALLOC(__FILE__, __FUNCTION__, __LINE__, 
	     world.curjob->recur[world.curjob->curscope].rwrt.transformed, 
	     sizeof(list_t), -1);
      elist_init(world.curjob->recur[world.curjob->curscope].rwrt.transformed, 
		 "transformed", ASPECT_TYPE_EXPR);
    }

  world.curjob->recur[world.curjob->curscope].rwrt.idloop = world.curjob->curloop;
  PROFILER_ROUT(__FILE__, __FUNCTION__, __LINE__, 0);
}
Example #2
0
/** 
 * @brief Set a list by its name (overwrite if existing ) 
 */
int		elist_register(list_t *list, char *name)
{
  list_t	*h;

  PROFILER_IN(__FILE__, __FUNCTION__, __LINE__);
  h = hash_get(hash_lists, name);
  if (h)
    {
      if (h->type == ASPECT_TYPE_UNKNOW)
	h->type = list->type;
      if (h->type != list->type)
	PROFILER_ERR(__FILE__, __FUNCTION__, __LINE__,
		     "Incompatible lists", -1);
      if (h->elmnbr)
	h = elist_empty(name);
      elist_merge(h, list);
      PROFILER_ROUT(__FILE__, __FUNCTION__, __LINE__, 0);
    }
  XALLOC(__FILE__, __FUNCTION__, __LINE__, h, sizeof(list_t), -1);
  elist_init(h, name, h->type);
  PROFILER_ROUT(__FILE__, __FUNCTION__, __LINE__, 0);
}
Example #3
0
/**
 * Empty a hash table 
 */
int		cmd_empty()
{
  char		buf[BUFSIZ];
  hash_t	*hash;
  list_t	*list;
  int		index;
  char		*name;

  PROFILER_IN(__FILE__, __FUNCTION__, __LINE__);
  for (index = 0; index < world.curjob->curcmd->argc; index++)
    {
      name = revm_lookup_key(world.curjob->curcmd->param[index]);
      hash = hash_find(name);
      if (!hash)
	{
	  list = elist_find(name);
	  if (!list)
	    {
	      snprintf(buf, sizeof(buf), " [W] Unknown list or hash table %s \n\n", name);
	      revm_output(buf);
	      continue;
	    }
	  snprintf(buf, sizeof(buf), "   .:: Empty list %s \n\n", name);
	  revm_output(buf);
	  elist_empty(name);
	}      
      else
	{
	  snprintf(buf, sizeof(buf), "   .:: Empty hash table %s \n\n", name);
	  revm_output(buf);
	  hash_empty(name);
	}
    }

  PROFILER_ROUT(__FILE__, __FUNCTION__, __LINE__, 0);
}
Example #4
0
void read_config(void)
{
	json_t *jcfg, *cred_expire;
	json_error_t err;
	const char *tmp_str, *rpcuser, *rpcpass;
	char *file_data;

	file_data = read_commented_file(srv.config);
	if (!file_data)
		exit(1);

	jcfg = json_loads(file_data, &err);

	free(file_data);

	if (!jcfg) {
		applog(LOG_ERR, "%s: JSON parse failed", srv.config);
		exit(1);
	}

	if (!json_is_object(jcfg)) {
		applog(LOG_ERR, "top-level JSON value not an object");
		exit(1);
	}

	parse_listen(json_object_get(jcfg, "listen"));
	parse_database(json_object_get(jcfg, "database"));
	parse_memcached(json_object_get(jcfg, "memcached"));

	if (elist_empty(&srv.listeners)) {
		applog(LOG_ERR, "error: no listen addresses specified");
		exit(1);
	}

	tmp_str = json_string_value(json_object_get(jcfg, "pid"));
	if (tmp_str)
		srv.pid_file = strdup(tmp_str);

	tmp_str = json_string_value(json_object_get(jcfg, "forcehost"));
	if (tmp_str)
		srv.ourhost = strdup(tmp_str);

	tmp_str = json_string_value(json_object_get(jcfg, "log.requests"));
	if (tmp_str) {
		srv.req_log = strdup(tmp_str);
		srv.req_fd = open(srv.req_log,
				  O_WRONLY | O_CREAT | O_APPEND, 0666);
		if (srv.req_fd < 0) {
			syslogerr(srv.req_log);
			exit(1);
		}
	}

	tmp_str = json_string_value(json_object_get(jcfg, "log.shares"));
	if (tmp_str) {
		srv.share_log = strdup(tmp_str);
		srv.share_fd = open(srv.share_log,
				  O_WRONLY | O_CREAT | O_APPEND, 0666);
		if (srv.share_fd < 0) {
			syslogerr(srv.share_log);
			exit(1);
		}
	}

	if (json_is_true(json_object_get(jcfg, "longpoll.disable")))
		srv.disable_lp = true;

	cred_expire = json_object_get(jcfg, "auth.cred_cache.expire");
	if (json_is_integer(cred_expire))
		srv.cred_expire = json_integer_value(cred_expire);

	tmp_str = json_string_value(json_object_get(jcfg, "rpc.url"));
	if (!tmp_str) {
		applog(LOG_ERR, "error: no RPC URL specified");
		exit(1);
	}
	srv.rpc_url = strdup(tmp_str);

	rpcuser = json_string_value(json_object_get(jcfg, "rpc.user"));
	rpcpass = json_string_value(json_object_get(jcfg, "rpc.pass"));
	if (!rpcuser || !rpcpass) {
		applog(LOG_ERR, "error: no RPC user and/or password specified");
		exit(1);
	}
	if (asprintf(&srv.rpc_userpass, "%s:%s", rpcuser, rpcpass) < 0) {
		applog(LOG_ERR, "OOM");
		exit(1);
	}

	if (json_is_true(json_object_get(jcfg, "rpc.target.rewrite")))
		srv.easy_target = json_string(EASY_TARGET);

	if (!srv.pid_file) {
		if (!(srv.pid_file = strdup("/var/run/pushpoold.pid"))) {
			applog(LOG_ERR, "no core");
			exit(1);
		}
	}

	json_decref(jcfg);
}