Пример #1
0
	void filter_config_object::read(boost::shared_ptr<nscapi::settings_proxy> proxy, bool oneliner, bool is_sample) {
		if (!get_value().empty())
			filter.filter_string = get_value();
		std::string alias;
		bool is_default = parent::is_default();

		nscapi::settings_helper::settings_registry settings(proxy);
		nscapi::settings_helper::path_extension root_path = settings.path(get_path());
		if (is_sample)
			root_path.set_sample();

		if (oneliner)
			return;

		root_path.add_path()
			("Real time filter: " + get_alias(), "Definition for real time filter: " + get_alias())
			;

		root_path.add_key()
			("log", sh::string_fun_key(boost::bind(&filter_config_object::set_file, this, _1)),
				"FILE", "The eventlog record to filter on (if set to 'all' means all enabled logs)", false)

			("logs", sh::string_fun_key(boost::bind(&filter_config_object::set_files, this, _1)),
				"FILES", "The eventlog record to filter on (if set to 'all' means all enabled logs)", true)

			("truncate", sh::int_fun_key(boost::bind(&filter_config_object::set_truncate, this, _1)),
				"Truncate", "Truncate the eventlog messages, if set to 0 (default) messages will not be truncated", true)

			;

		filter.read_object(root_path, is_default);

		settings.register_all();
		settings.notify();
	}
Пример #2
0
void freeze_moves(rga_node * u){
	rga_move_map * map = moveList[u->id];
	rga_node * x, * y, * v;
	while(map != 0){
		if(map->move->set == RGA_ACTIVE_MOVES){
			x = map->move->a;
			y = map->move->b;
			if(get_alias(y) == get_alias(u)){
				v = get_alias(x);
			}else{
				v = get_alias(y);
			}
			#ifdef DEBUG_MODE
			printf("\tMove from v%u to v%u has been frozen\n", u->id, v->id);
			#endif
			rga_move_list_remove(activeMoves, map->move);
			rga_move_list_push(frozenMoves, map->move);
			map->move->set = RGA_FROZEN_MOVES;
			if(num_node_moves(v) == 0 && degree[v->id] < num_registers && v->set != RGA_PRECOLOURED){
				rga_node_list_remove(freezeWorklist, v);
				rga_node_list_push(simplifyWorklist, v);
				v->set = RGA_SIMPLIFY_WORKLIST;
			}
		}
		map = map->prev;
	}
}
Пример #3
0
void rga_move_list_show(rga_move_list * list, unsigned int set){
	rga_move * move = list->end;
	while(move != 0){
		printf(" (v%u (v%u) v%u (v%u))", move->a->id, get_alias(move->a)->id, move->b->id, get_alias(move->b)->id);
		if(move->set != set){
			printf("(disagree:%u)", move->set);
		}
		move = move->prev;
	}
	puts("");
}
Пример #4
0
void init()
{
	if(signal_(SIGINT, intHandler) == SIG_ERR)
	{
		cout << "Signal_ Error!" << endl;
		exit(1);
	}
	getIfDetach() = false;
	get_stdin_fd() = dup(STDIN_FILENO);
	getPrefix() = updatePrefix();
	get_alias()["ls"] = "ls --color=auto";
	get_alias()["grep"] = "grep --color=auto";
}
Пример #5
0
		virtual void read(boost::shared_ptr<nscapi::settings_proxy> proxy, bool oneliner, bool is_sample) {
			parent::read(proxy, oneliner, is_sample);
			set_alias(boost::algorithm::to_lower_copy(get_alias()));
			set_command(get_value());

			nscapi::settings_helper::settings_registry settings(proxy);
			nscapi::settings_helper::path_extension root_path = settings.path(get_path());
			if (is_sample)
				root_path.set_sample();

			if (!oneliner) {
				root_path.add_path()
					("script: " + get_alias(), "The configuration section for the  " + get_alias() + " script.")
					;

				root_path.add_key()
					("command", sh::string_fun_key(boost::bind(&command_object::set_command, this, _1)),
						"COMMAND", "Command to execute")

					("user", nscapi::settings_helper::string_key(&user),
						"USER", "The user to run the command as", true)

					("domain", nscapi::settings_helper::string_key(&domain),
						"DOMAIN", "The user to run the command as", true)

					("password", nscapi::settings_helper::string_key(&password),
						"PASSWORD", "The user to run the command as", true)

					("session", nscapi::settings_helper::string_key(&session),
						"SESSION", "Session you want to invoke the client in either the number of current for the one with a UI", true)

					("display", nscapi::settings_helper::bool_key(&display),
						"DISPLAY", "Set to true if you want to display the resulting window or not", true)

					("encoding", nscapi::settings_helper::string_key(&encoding),
						"ENCODING", "The encoding to parse the command as", true)

					("ignore perfdata", nscapi::settings_helper::bool_key(&ignore_perf),
						"IGNORE PERF DATA", "Do not parse performance data from the output", false)

					("capture output", nscapi::settings_helper::bool_key(&no_fork),
						"CAPTURE OUTPUT", "This should be set to false if you want to run commands which never terminates (i.e. relinquish control from NSClient++). The effect of this is that the command output will not be captured. The main use is to protect from socket reuse issues", true)

					;

				settings.register_all();
				settings.notify();
			}
		}
Пример #6
0
		std::string to_string() const {
			std::stringstream ss;
			ss << get_alias() << "[" << get_alias() << "] = "
				<< "{tpl: " << parent::to_string();
			if (!user.empty()) {
				ss << ", user: "******", domain: " << domain
					<< ", password: "******", session: " << session
					<< ", display: " << display
					<< ", no_fork: " << no_fork;
			}
			ss << "}";
			return ss.str();
		}
Пример #7
0
rga_node * get_alias(rga_node * node){
	if(node->set == RGA_COALESCED_NODES){
		return get_alias(alias[node->id]);
	}else{
		return node;
	}
}
//#@#@#@#@#@#@#@#@#@#@#@#@#@#@#@#@#@#@#@#@#@#@#@#@#@#@#@#@#@#@#@#@#@#@#@#@#@#@#@>
int ifaliasdown(std::vector<std::string> & parameters, std::string & response)
{
 std::vector<std::string> argc;
 int error = 0;
 unsigned int i = 0;

 response = "Taking alias interfaces down";
 error = errrpt(response);

 error = get_alias(argc);

 if (error)
 {
  response = "Abort reading current aliases on the interface.";
  return errrpt(response);
 }

 while (i < argc.size())
 {
  errrpt("pulling down (" + argc[i] + ")");
  error += simplesecuresysteml("/sbin/ifconfig",argc[i++].c_str(),"down",NULL);
 }

 response = "Successfully brought down alias interfaces.";

 if (error) response = "Abort while bringing down alias interfaces";

 return errrpt(response);
}
Пример #9
0
	void filter_config_object::read(boost::shared_ptr<nscapi::settings_proxy> proxy, bool oneliner, bool is_sample) {
		if (!get_value().empty())
			filter.filter_string = get_value();
		bool is_default = parent::is_default();

		nscapi::settings_helper::settings_registry settings(proxy);
		nscapi::settings_helper::path_extension root_path = settings.path(get_path());
		if (is_sample)
			root_path.set_sample();

		if (oneliner)
			return;

		root_path.add_path()
			("REAL TIME FILTER DEFENITION", "Definition for real time filter: " + get_alias())
			;

		root_path.add_key()
			("file", sh::string_fun_key<std::string>(boost::bind(&filter_config_object::set_file, this, _1)),
				"FILE", "The eventlog record to filter on (if set to 'all' means all enabled logs)", false)

			("files", sh::string_fun_key<std::string>(boost::bind(&filter_config_object::set_files, this, _1)),
				"FILES", "The eventlog record to filter on (if set to 'all' means all enabled logs)", true)

			("column split", nscapi::settings_helper::string_key(&column_split),
				"COLUMN SPLIT", "THe character(s) to use when splitting on column level", !is_default)

			;
		filter.read_object(root_path, is_default);

		settings.register_all();
		settings.notify();
	}
Пример #10
0
void coalesce(){
	rga_move * move = rga_move_list_pop(worklistMoves);
	rga_node * x = get_alias(move->a);
	rga_node * y = get_alias(move->b);
	rga_node * z;
	if(y->set == RGA_PRECOLOURED){
		z = x;
		x = y;
		y = z;
	}
	if(x == y){
		rga_move_list_push(coalescedMoves, move);
		move->set = RGA_COALESCED_MOVES;
		add_work_list(x);
	}else if(y->set == RGA_PRECOLOURED ||
		(bitset_check(adjSet[x->id], y->id) || bitset_check(adjSet[x->id], y->id))){

		#ifdef DEBUG_MODE
		printf("Move from v%u to v%u has been removed because it is constrained\n", x->id, y->id);
		#endif
		
		rga_move_list_push(constrainedMoves, move);
		move->set = RGA_CONSTRAINED_MOVES;
		add_work_list(x);
		add_work_list(y);
	}else if((x->set == RGA_PRECOLOURED && coalesce_ok(y,x)) ||
		(x->set != RGA_PRECOLOURED && coalesce_conservative(x,y))){

		#ifdef DEBUG_MODE
		printf("Move from v%u to v%u has been coalesced\n", x->id, y->id);
		#endif

		rga_move_list_push(coalescedMoves, move);
		move->set = RGA_COALESCED_MOVES;
		combine(x,y);
		add_work_list(x);
	}else{
		#ifdef DEBUG_MODE
		printf("Move from v%u to v%u is not ready\n", x->id, y->id);
		#endif

		rga_move_list_push(activeMoves, move);
		move->set = RGA_ACTIVE_MOVES;
	}
}
Пример #11
0
void rga_node_list_show(rga_node_list * list, unsigned int set){
	rga_node * node = list->end;
	while(node != 0){
		printf(" v%u (v%u)", node->id, get_alias(node)->id);
		if(node->set != set){
			printf("(disagree:%u)", node->set);
		}
		node = node->prev;
	}
	puts("");
}
Пример #12
0
void	replace_alias(char **expr, int **t_ind, int i, int len)
{
	char *s;

	(void)t_ind;
	s = get_alias(cpy_a_to_b((*expr), i, i + len));
	if (s != NULL)
	{
		inject_in_string(expr, s, i, len);
		decalage_intouchable(t_ind, i, ft_strlen(s) - len);
	}
}
Пример #13
0
void assign_colours(){
	rga_node * node;
	rga_node_map * map;
	rga_node * w;
	bitset * used_colours = bitset_new(num_registers);
	while(node = rga_node_list_pop(selectStack)){
		bitset_reset(used_colours);
		map = adjList[node->id];
		while(map != 0){
			w = get_alias(map->node);
			if(w->set == RGA_COLOURED_NODES || w->set == RGA_PRECOLOURED){
				bitset_set(used_colours, colour[w->id]-1);
			}
			map = map->prev;
		}
		if(bitset_all_on(used_colours)){
			rga_node_list_push(spilledNodes, node);
			#ifdef DEBUG_MODE
			printf("Node v%u has become an actual spill\n", node->id);
			#endif
			node->set = RGA_SPILLED_NODES;
		}else{
			rga_node_list_push(colouredNodes, node);
			node->set = RGA_COLOURED_NODES;
			colour[node->id] = bitset_first_off(used_colours, 0) + 1;
			#ifdef DEBUG_MODE
			printf("v%u = reg%u\n", node->id, colour[node->id]-1);
			#endif
		}
	}
	w = coalescedNodes->end;
	while(w != 0){
		colour[w->id] = colour[get_alias(w)->id];
		w = w->prev;
	}
}
Пример #14
0
		std::string to_string() const {
			std::stringstream ss;
			ss << get_alias() << "[" << id << "] = "
				<< "{tpl: " << parent::to_string()
				<< ", command: " << command
				<< ", channel: " << channel
				<< ", source_id: " << source_id
				<< ", target_id: " << target_id;
			if (duration) {
				ss << ", duration: " << (*duration).total_seconds() << "s, " << (randomness * 100) << "% randomness";
			}
			if (schedule)
				ss << ", schedule: " << *schedule;
			ss << "}";
			return ss.str();
		}
Пример #15
0
void define_alias(char* key, char** cmd) {
  alias_t test;
  test = get_alias(key);
  if(test.valid_alias != -1) {
    //fprintf(stderr, "Alias already defined with key: %s\n", key);
    modify_alias(key, cmd);
    return;
  }
  alias_t a;
  a.key = key;
  a.cmd = malloc(sizeof(cmd));
  a.cmd = cmd;
  a.valid_alias = 1;
  aliases[alias_cc] = a;
  alias_cc++;
}
Пример #16
0
void		build_argv(t_vars *v)
{
  char		*alias;
  int		i;

  i = is_there_an_alias(v);
  if (i)
    {
      alias = get_alias(v, v->argv[i - 1]);
      v->argv = update_elem_in_tab(v->argv, alias, (i - 1));
      alias = my_xxfree(alias);
      v->prompt = my_xxfree(v->prompt);
      v->prompt = concat_tab_elems(v->argv, " ");
      v->argv = my_xfree_tab(v->argv);
      v->argc = get_argc(v->prompt);
      v->argv = get_argv(v->prompt);
    }
}
Пример #17
0
int main (int argc, char const *argv[]) {
  /* code */
  char** test = (char**) malloc(128 * sizeof(char*));
  test[0] = "ls";
  test[1] = "-lh";
  define_alias("test", test);
  alias_t testAlias = (alias_t) get_alias("test");
  //printf("%s\n", testAlias.cmd[1]);
  list_aliases();
  /*
  char* alias_key = (char*) get_alias_key(0);
  char** alias_cmd = (char**) get_alias_cmd(0);
  printf("%s\n", alias_cmd[1]);
  printf("%s\n", alias_key);
  shell_exec(alias_cmd[0], alias_cmd);
  */
  //shell_exec(testAlias.cmd[0], testAlias.cmd);
  return 0;
}
Пример #18
0
void * receiver(void *args)
{
	char word[SZ];
	int i;
	struct line *on;
	struct alias *a;
	while(1) {
		if(io_get_word(word) <= 0) {
			usleep(300000);
			continue;
		}

		// queue management
		ui_print("<-- %s\n", word);

		// trigger on event
		exec_on(word);

		if(strcmp(wait_queue_head(), "bin") == 0) {
			bin = atoi(word);
			for(i = 0;; ) {
				a = get_alias("bin", i++);
				if(!a) break;

				if(a->num == bin)
					a->arg++;
			}
			wait_queue_pop();
		} else if(strcmp(word, wait_queue_head()) == 0
			|| strcmp(wait_queue_head(), "X") == 0) {
			wait_queue_pop();
		}
	}

	return NULL;
}
Пример #19
0
/*!
 * \brief Processes the request and returns the result in the output parameters.
 *
 * \return
 * \li \c HTTP_BAD_REQUEST
 * \li \c HTTP_INTERNAL_SERVER_ERROR
 * \li \c HTTP_REQUEST_RANGE_NOT_SATISFIABLE
 * \li \c HTTP_FORBIDDEN
 * \li \c HTTP_NOT_FOUND
 * \li \c HTTP_NOT_ACCEPTABLE
 * \li \c HTTP_OK
 */
static int process_request(
	/*! [in] HTTP Request message. */
	http_message_t *req,
	/*! [out] Tpye of response. */
	enum resp_type *rtype,
	/*! [out] Headers. */
	membuffer *headers,
	/*! [out] Get filename from request document. */
	membuffer *filename,
	/*! [out] Xml alias document from the request document. */
	struct xml_alias_t *alias,
	/*! [out] Send Instruction object where the response is set up. */
	struct SendInstruction *RespInstr)
{
	int code;
	int err_code;

	char *request_doc;
	struct File_Info finfo;
	int using_alias;
	int using_virtual_dir;
	uri_type *url;
	const char *temp_str;
	int resp_major;
	int resp_minor;
	int alias_grabbed;
	size_t dummy;
	const char *extra_headers = NULL;

	print_http_headers(req);
	url = &req->uri;
	assert(req->method == HTTPMETHOD_GET ||
	       req->method == HTTPMETHOD_HEAD ||
	       req->method == HTTPMETHOD_POST ||
	       req->method == HTTPMETHOD_SIMPLEGET);
	/* init */
	memset(&finfo, 0, sizeof(finfo));
	request_doc = NULL;
	finfo.content_type = NULL;
	alias_grabbed = FALSE;
	err_code = HTTP_INTERNAL_SERVER_ERROR;	/* default error */
	using_virtual_dir = FALSE;
	using_alias = FALSE;

	http_CalcResponseVersion(req->major_version, req->minor_version,
				 &resp_major, &resp_minor);
	/* */
	/* remove dots */
	/* */
	request_doc = malloc(url->pathquery.size + 1);
	if (request_doc == NULL) {
		goto error_handler;	/* out of mem */
	}
	memcpy(request_doc, url->pathquery.buff, url->pathquery.size);
	request_doc[url->pathquery.size] = '\0';
	dummy = url->pathquery.size;
	remove_escaped_chars(request_doc, &dummy);
	code = remove_dots(request_doc, url->pathquery.size);
	if (code != 0) {
		err_code = HTTP_FORBIDDEN;
		goto error_handler;
	}
	if (*request_doc != '/') {
		/* no slash */
		err_code = HTTP_BAD_REQUEST;
		goto error_handler;
	}
	if (isFileInVirtualDir(request_doc)) {
		using_virtual_dir = TRUE;
		RespInstr->IsVirtualFile = 1;
		if (membuffer_assign_str(filename, request_doc) != 0) {
			goto error_handler;
		}
	} else {
		/* try using alias */
		if (is_valid_alias(&gAliasDoc)) {
			alias_grab(alias);
			alias_grabbed = TRUE;
			using_alias = get_alias(request_doc, alias, &finfo);
			if (using_alias == TRUE) {
				finfo.content_type =
				    ixmlCloneDOMString("text/xml");

				if (finfo.content_type == NULL) {
					goto error_handler;
				}
			}
		}
	}
	if (using_virtual_dir) {
		if (req->method != HTTPMETHOD_POST) {
			/* get file info */
			if (virtualDirCallback.
			    get_info(filename->buf, &finfo) != 0) {
				err_code = HTTP_NOT_FOUND;
				goto error_handler;
			}
			/* try index.html if req is a dir */
			if (finfo.is_directory) {
				if (filename->buf[filename->length - 1] == '/') {
					temp_str = "index.html";
				} else {
					temp_str = "/index.html";
				}
				if (membuffer_append_str(filename, temp_str) !=
				    0) {
					goto error_handler;
				}
				/* get info */
				if ((virtualDirCallback.
				     get_info(filename->buf,
					      &finfo) != UPNP_E_SUCCESS)
				    || finfo.is_directory) {
					err_code = HTTP_NOT_FOUND;
					goto error_handler;
				}
			}
			/* not readable */
			if (!finfo.is_readable) {
				err_code = HTTP_FORBIDDEN;
				goto error_handler;
			}
			/* finally, get content type */
			/* if ( get_content_type(filename->buf, &content_type) != 0 ) */
			/*{ */
			/*  goto error_handler; */
			/* } */
		}
	} else if (!using_alias) {
		if (gDocumentRootDir.length == 0) {
			goto error_handler;
		}
		/* */
		/* get file name */
		/* */

		/* filename str */
		if (membuffer_assign_str(filename, gDocumentRootDir.buf) != 0 ||
		    membuffer_append_str(filename, request_doc) != 0) {
			goto error_handler;	/* out of mem */
		}
		/* remove trailing slashes */
		while (filename->length > 0 &&
		       filename->buf[filename->length - 1] == '/') {
			membuffer_delete(filename, filename->length - 1, 1);
		}
		if (req->method != HTTPMETHOD_POST) {
			/* get info on file */
			if (get_file_info(filename->buf, &finfo) != 0) {
				err_code = HTTP_NOT_FOUND;
				goto error_handler;
			}
			/* try index.html if req is a dir */
			if (finfo.is_directory) {
				if (filename->buf[filename->length - 1] == '/') {
					temp_str = "index.html";
				} else {
					temp_str = "/index.html";
				}
				if (membuffer_append_str(filename, temp_str) !=
				    0) {
					goto error_handler;
				}
				/* get info */
				if (get_file_info(filename->buf, &finfo) != 0 ||
				    finfo.is_directory) {
					err_code = HTTP_NOT_FOUND;
					goto error_handler;
				}
			}
			/* not readable */
			if (!finfo.is_readable) {
				err_code = HTTP_FORBIDDEN;
				goto error_handler;
			}
		}
		/* finally, get content type */
		/*      if ( get_content_type(filename->buf, &content_type) != 0 ) */
		/*      { */
		/*          goto error_handler; */
		/*      } */
	}
	RespInstr->ReadSendSize = finfo.file_length;
	/* Check other header field. */
	if ((code =
	     CheckOtherHTTPHeaders(req, RespInstr,
				   finfo.file_length)) != HTTP_OK) {
		err_code = code;
		goto error_handler;
	}
	if (req->method == HTTPMETHOD_POST) {
		*rtype = RESP_POST;
		err_code = HTTP_OK;
		goto error_handler;
	}
	/*extra_headers = UpnpFileInfo_get_ExtraHeaders(finfo); */
	if (!extra_headers) {
		extra_headers = "";
	}

	/* Check if chunked encoding should be used. */
	if (using_virtual_dir && finfo.file_length == UPNP_USING_CHUNKED) {
		/* Chunked encoding is only supported by HTTP 1.1 clients */
		if (resp_major == 1 && resp_minor == 1) {
			RespInstr->IsChunkActive = 1;
		} else {
			/* The virtual callback indicates that we should use
			 * chunked encoding however the client doesn't support
			 * it. Return with an internal server error. */
			err_code = HTTP_NOT_ACCEPTABLE;
			goto error_handler;
		}
	}

	if (RespInstr->IsRangeActive && RespInstr->IsChunkActive) {
		/* Content-Range: bytes 222-3333/4000  HTTP_PARTIAL_CONTENT */
		/* Transfer-Encoding: chunked */
		if (http_MakeMessage(headers, resp_major, resp_minor,
		    "R" "T" "GKLD" "s" "tcS" "Xc" "sCc",
		    HTTP_PARTIAL_CONTENT,	/* status code */
		    finfo.content_type,	/* content type */
		    RespInstr,	/* range info */
		    RespInstr,	/* language info */
		    "LAST-MODIFIED: ",
		    &finfo.last_modified,
		    X_USER_AGENT, extra_headers) != 0) {
			goto error_handler;
		}
	} else if (RespInstr->IsRangeActive && !RespInstr->IsChunkActive) {
		/* Content-Range: bytes 222-3333/4000  HTTP_PARTIAL_CONTENT */
		if (http_MakeMessage(headers, resp_major, resp_minor,
		    "R" "N" "T" "GLD" "s" "tcS" "Xc" "sCc",
		    HTTP_PARTIAL_CONTENT,	/* status code */
		    RespInstr->ReadSendSize,	/* content length */
		    finfo.content_type,	/* content type */
		    RespInstr,	/* range info */
		    RespInstr,	/* language info */
		    "LAST-MODIFIED: ",
		    &finfo.last_modified,
		    X_USER_AGENT, extra_headers) != 0) {
			goto error_handler;
		}
	} else if (!RespInstr->IsRangeActive && RespInstr->IsChunkActive) {
		/* Transfer-Encoding: chunked */
		if (http_MakeMessage(headers, resp_major, resp_minor,
		    "RK" "TLD" "s" "tcS" "Xc" "sCc",
		    HTTP_OK,	/* status code */
		    finfo.content_type,	/* content type */
		    RespInstr,	/* language info */
		    "LAST-MODIFIED: ",
		    &finfo.last_modified,
		    X_USER_AGENT, extra_headers) != 0) {
			goto error_handler;
		}
	} else {
		/* !RespInstr->IsRangeActive && !RespInstr->IsChunkActive */
		if (RespInstr->ReadSendSize >= 0) {
			if (http_MakeMessage(headers, resp_major, resp_minor,
			    "R" "N" "TLD" "s" "tcS" "Xc" "sCc",
			    HTTP_OK,	/* status code */
			    RespInstr->ReadSendSize,	/* content length */
			    finfo.content_type,	/* content type */
			    RespInstr,	/* language info */
			    "LAST-MODIFIED: ",
			    &finfo.last_modified,
			    X_USER_AGENT,
			    extra_headers) != 0) {
				goto error_handler;
			}
		} else {
			if (http_MakeMessage(headers, resp_major, resp_minor,
			    "R" "TLD" "s" "tcS" "Xc" "sCc",
			    HTTP_OK,	/* status code */
			    finfo.content_type,	/* content type */
			    RespInstr,	/* language info */
			    "LAST-MODIFIED: ",
			    &finfo.last_modified,
			    X_USER_AGENT,
			    extra_headers) != 0) {
				goto error_handler;
			}
		}
	}
	if (req->method == HTTPMETHOD_HEAD) {
		*rtype = RESP_HEADERS;
	} else if (using_alias) {
		/* GET xml */
		*rtype = RESP_XMLDOC;
	} else if (using_virtual_dir) {
		*rtype = RESP_WEBDOC;
	} else {
		/* GET filename */
		*rtype = RESP_FILEDOC;
	}
	/* simple get http 0.9 as specified in http 1.0 */
	/* don't send headers */
	if (req->method == HTTPMETHOD_SIMPLEGET) {
		membuffer_destroy(headers);
	}
	err_code = HTTP_OK;

 error_handler:
	free(request_doc);
	ixmlFreeDOMString(finfo.content_type);
	if (err_code != HTTP_OK && alias_grabbed) {
		alias_release(alias);
	}

	return err_code;
}
Пример #20
0
rd_vlist * mem_alloc(rd_instr * code,
	rd_vlist * vlist,
	unsigned int match_types,
	unsigned int ret_type,
	unsigned int type_size){

	//start local variables
	flow_graph * graph;
	flow_node * node;

	rga_node * x, * y;
	rga_node_map * list;
	rga_move * move;

	rd_vlist * new_list;
	rd_instr * ins;
	rd_var * v;

	bitset * live;

	unsigned int def_pos, live_pos, set_size, last_id, i;

	bitset * used_colours;
	//end local variables
	
	//perform flow analysis
	graph = flow_generate_graph(code, vlist, 0, 0, match_types);

	//allocate space for node and move information
	initial          = rga_node_list_new();
	coalescedNodes   = rga_node_list_new();
	colouredNodes    = rga_node_list_new();

	coalescedMoves   = rga_move_list_new();
	constrainedMoves = rga_move_list_new();
	worklistMoves    = rga_move_list_new();
	
	nodes = new rga_node *[vlist->num_vars];
	adjSet = new bitset *[vlist->num_vars];
	adjList = new rga_node_map *[vlist->num_vars];
	alias = new rga_node *[vlist->num_vars];
	colour = new unsigned char[vlist->num_vars];

	//initialise memory variables
	for(i = 0; i < vlist->num_vars; i++){
		nodes[i] = rga_node_new(0);
		rga_node_list_push(initial, nodes[i]);
		nodes[i]->set = RGA_INITIAL;
		colour[i] = 0;
		adjList[i] = 0;
		adjSet[i] = bitset_new(vlist->num_vars);
		alias[i] = 0;
	}

	//build the graph
	node = graph->end;
	def_pos = live_pos = 0;
	while(node != 0){
		ins = node->data;
		live = bitset_copy(node->liveout);
		if(ins->type == RD_SET && ins->p1->type & match_types && ins->p2->type & match_types){
			bitset_sub(live, node->use);
			if(!rga_move_list_exists(worklistMoves, nodes[ins->p1->id], nodes[ins->p2->id])){
				move = rga_move_new(nodes[ins->p1->id], nodes[ins->p2->id]);
				rga_move_list_push(worklistMoves, move);
				move->set = RGA_WORKLIST_MOVES;
			}
		}
		bitset_or(live, node->def);
		while((def_pos = bitset_first_on(node->def, def_pos)) != ~0){
			while((live_pos = bitset_first_on(live, live_pos)) != ~0){
				mem_add_edge(nodes[live_pos], nodes[def_pos]);
				live_pos++;
			}
			live_pos = 0;
			def_pos++;
		}
		def_pos = 0;
		node = node->prev;
	}

	//coalesce phase
	while(!rga_move_list_isempty(worklistMoves)){
		move = rga_move_list_pop(worklistMoves);
		x = get_alias(move->a);
		y = get_alias(move->b);
		if(x == y){
			rga_move_list_push(coalescedMoves, move);
			move->set = RGA_COALESCED_MOVES;
		}else if(bitset_check(adjSet[x->id], y->id) || bitset_check(adjSet[x->id], y->id)){
			rga_move_list_push(constrainedMoves, move);
			move->set = RGA_CONSTRAINED_MOVES;
		}else{
			rga_move_list_push(coalescedMoves, move);
			move->set = RGA_COALESCED_MOVES;
			list = adjList[y->id];
			rga_node_list_remove(initial, y);
			rga_node_list_push(coalescedNodes, y);
			y->set = RGA_COALESCED_NODES;
			alias[y->id] = x;
			while(list != 0){
				if(list->node->set != RGA_COALESCED_NODES){
					mem_add_edge(list->node, x);
				}
				list = list->prev;
			}
		}
	}

	//simplify and select phase
	new_list = rd_varlist(0);
	set_size = 0;
	last_id = 0;
	used_colours = bitset_new(vlist->num_vars);
	while(x = rga_node_list_pop(initial)){
		bitset_reset(used_colours);
		list = adjList[x->id];
		while(list != 0){
			y = get_alias(list->node);
			if(y->set == RGA_COLOURED_NODES){
				bitset_set(used_colours, colour[y->id]);
			}
			list = list->prev;
		}
		rga_node_list_push(colouredNodes, x);
		x->set = RGA_COLOURED_NODES;
		colour[x->id] = bitset_first_off(used_colours, 0);
		if(rd_vlist_find(new_list, colour[x->id]) == 0){
			rd_vlist_add(new_list, colour[x->id], ret_type, 0, 0, type_size);
		}
		if(colour[x->id] > last_id){
			last_id = colour[x->id];
		}
		#ifdef DEBUG_MODE
		printf("mem%u gets %u\n", x->id, colour[x->id]);
		#endif
	}
	bitset_delete(used_colours);

	new_list->num_vars = last_id + 1;

	//set the colour of coalesced nodes
	x = coalescedNodes->end;
	while(x != 0){
		colour[x->id] = colour[get_alias(x)->id];
		//rd_vlist_add(new_list, colour[x->id], ret_type, 0, 0, type_size);
		#ifdef DEBUG_MODE		
		printf("mem%u gets %u\n", x->id, colour[x->id]);
		#endif
		x = x->prev;
	}

	node = graph->end;
	while(node != 0){
		if(node->data->p1 != 0){
			if(node->data->p1->type & match_types){
				v = rd_vlist_find(new_list, colour[node->data->p1->id]);
				if(v != 0){
					node->data->p1 = v;
				}
			}
		}
		if(node->data->p2 != 0){
			if(node->data->p2->type & match_types){
				v = rd_vlist_find(new_list, colour[node->data->p2->id]);
				if(v != 0){
					node->data->p2 = v;
				}
			}
		}
		if(node->data->p3 != 0){
			if(node->data->p3->type & match_types){
				v = rd_vlist_find(new_list, colour[node->data->p3->id]);
				if(v != 0){
					node->data->p3 = v;
				}
			}
		}
		node = node->prev;
	}

	//clean up
	delete initial;
	delete coalescedNodes;
	delete colouredNodes;

	delete coalescedMoves;
	delete constrainedMoves;
	delete worklistMoves;

	for(i = 0; i < vlist->num_vars; i++){
		delete nodes[i];
		if(adjList[i] != 0){
			delete adjList[i];
		}
		bitset_delete(adjSet[i]);
	}

	delete[] nodes;
	delete[] adjSet;
	delete[] adjList;
	delete[] alias;
	delete[] colour;

	rga_reset();

	return new_list;
}
Пример #21
0
	std::string filter_config_object::to_string() const {
		std::stringstream ss;
		ss << get_alias() << "[" << get_alias() << "] = "
			<< "{tpl: " << parent::to_string() << ", filter: " << filter.to_string() << "}";
		return ss.str();
	}
Пример #22
0
int exec_line(int argc, char *argv[])
{
	struct alias *al;
	int i;

	if(!argc) return 0;
	ui_print("do action: ");
	for(i = 0; i < argc; i++)
		ui_print("%s ", argv[i]);
	ui_print("\n");

	if(strcmp(argv[0], "load") == 0) {
		ui_animation(1);
	} else if(strcmp(argv[0], "unload") == 0) {
		ui_animation(3);
	} else if(strcmp(argv[0], "poweron") == 0) {
		power_state = 1;
	} else if(strcmp(argv[0], "poweroff") == 0) {
		power_state = 1;
	} else if(strcmp(argv[0], "putbin") == 0) {
		for(i = 0;;) {
			al = get_alias("bin", i++);
			if(al) ui_bin_update(i, al->arg);
			else break;
		}
		al = get_alias("timeout", 0);
		if(al) ui_bin_update(i, al->arg);
	} else if(strncmp(argv[0], "send", 4) == 0) {
		if(strcmp(argv[0], "send_txt") == 0) {
			io_send("\002");
			ui_print("--> <STX>\n");
		}
		for(i = 1; i < argc; i++) {
			const char *s = argv[i];
			if(strcmp(s, "power_state") == 0)
				s = power_state? "1": "NULL";
			al = get_alias(s, 0);
			ui_print("--> %s\n", al? al->str: s);
			io_send(al? al->str: s);
		}
		if(strcmp(argv[0], "send_txt") == 0) {
			io_send("\003");
			ui_print("--> <ETX>\n");
		}
	} else if(strcmp(argv[0], "wait") == 0) {
		for(i = 1; i < argc; i++)
			wait_queue_add_tail(argv[i]);

		for(;!wait_queue_empty(); ui_animation(2));
	} else if(strcmp(argv[0], "wait_timeout") == 0) {
		struct timeval a, b, d;
		int t;
		al = get_alias("timeout", 0);
		t = al? al->num: TIMEOUT;
		for(i = 1; i < argc; i++)
			wait_queue_add_tail(argv[i]);

		gettimeofday(&a, NULL);
		for(;!wait_queue_empty(); ui_animation(2)) {
			gettimeofday(&b, NULL);
			timersub(&b, &a, &d);
			if(d.tv_sec > t) {
				ui_print("timeout for waiting %s\n", wait_queue_head());
				al->arg++;
				return -1;
			}
		}
	} else if(strcmp(argv[0], "handshake") == 0) {
		char word[SZ];
		ui_print("--> %s\n", argv[1]);
		io_send(argv[1]);
		while(io_get_word(word) <= 0);
		ui_print("<-- %s\n", word);
		if(strcmp(word, argv[2]) != 0)
			return -1;
	}

	return 0;
}
Пример #23
0
int main()
{
	char buf[64], *v[SZ];
	struct alias *a;
	int n, i, r, skip_actions;
	FILE *f;
	pthread_t rv, ks;

	ui_init();
	ui_animation(0);

	f = fopen("commands.desc", "r");
	if(f == NULL) {
		ui_print("failed to open commands.desc\n");
		goto end;
	}

	// parse command list
	while(fgets(buf, 64, f)) {
		for(i = 0, v[i] = strtok(buf, " \n");
			 v[i]; v[++i] = strtok(0, " \n"));
		parse_line(i, v);
	}
	fclose(f);

	// init bin
	for(i = 0;; ) {
		a = get_alias("bin", i++);
		if(!a) break;
		ui_bin_add_tag(a->str);
	}
	ui_bin_add_tag("timeout");

	// init options tip
	ui_tip_update(1, "Press the corresponding key to perform that function:");
	ui_tip_update(3, "<S> Handler Speed");
	ui_tip_update(4, "<R> Reset");
	ui_tip_update(5, "<Q> Quit");

	// init io
	r = io_init();
	ptsname_r(r, buf, 64);
	ui_print("pts name is: %s (%d)\n", buf, r);

	// init wait queue
	wait_queue_init();

	// init receiver
	pthread_create(&rv, NULL, receiver, NULL);

	// init keyserver
	pthread_create(&ks, NULL, keyserver, NULL);

again:
	ui_print("\n\nnew routine:\n");
	skip_actions = 0;
	for(wait_queue_init(), i = 0;
	 i < lscount; i++) {
		if(skip_actions && (!strcmp(lines[i].argv[0], "send")
					  || !strcmp(lines[i].argv[0], "wait")))
			continue;
		if(exec_line(lines[i].argc, lines[i].argv) < 0)
			skip_actions = 1;
	}
	wait_queue_deinit();
	if(!stop) goto again;

end:
	ui_deinit();
	io_deinit();
}
Пример #24
0
		virtual void read(boost::shared_ptr<nscapi::settings_proxy> proxy, bool oneliner, bool is_sample) {
			parent::read(proxy, oneliner, is_sample);

			set_command(get_value());
			bool is_def = is_default();

			nscapi::settings_helper::settings_registry settings(proxy);
			nscapi::settings_helper::path_extension root_path = settings.path(get_path());
			if (is_sample)
				root_path.set_sample();
			if (oneliner)
				return;

			root_path.add_path()
				("SCHEDULE DEFENITION", "Schedule definition for: " + get_alias())
				;

			root_path.add_key()

				("command", sh::string_fun_key(boost::bind(&schedule_object::set_command, this, _1)),
					"SCHEDULE COMMAND", "Command to execute", is_def)

				("target", sh::string_key(&target_id),
					"TARGET", "The target to send the message to (will be resolved by the consumer)", true)
				("source", sh::string_key(&source_id),
					"SOURCE", "The name of the source system, will automatically use the remote system if a remote system is called. Almost most sending systems will replace this with current systems hostname if not present. So use this only if you need specific source systems for specific schedules and not calling remote systems.", true)

				;
			if (is_def) {
				root_path.add_key()

					("channel", sh::string_key(&channel, "NSCA"),
						"SCHEDULE CHANNEL", "Channel to send results on")

					("interval", sh::string_fun_key(boost::bind(&schedule_object::set_duration, this, _1)),
					"SCHEDULE INTERAVAL", "Time in seconds between each check")

					("randomness", sh::string_fun_key(boost::bind(&schedule_object::set_randomness, this, _1)),
						"RANDOMNESS", "% of the interval which should be random to prevent overloading server resources")

					("schedule", sh::string_fun_key(boost::bind(&schedule_object::set_schedule, this, _1)),
						"SCHEDULE", "Cron-like statement for when a task is run. Currently limited to only one number i.e. 1 * * * * or * * 1 * * but not 1 1 * * *")

					("report", sh::string_fun_key(boost::bind(&schedule_object::set_report, this, _1), "all"),
						"REPORT MODE", "What to report to the server (any of the following: all, critical, warning, unknown, ok)")

					;
			} else {
				root_path.add_key()
					("channel", sh::string_key(&channel),
						"SCHEDULE CHANNEL", "Channel to send results on")

					("interval", sh::string_fun_key(boost::bind(&schedule_object::set_duration, this, _1)),
						"SCHEDULE INTERAVAL", "Time in seconds between each check", true)

					("randomness", sh::string_fun_key(boost::bind(&schedule_object::set_randomness, this, _1)),
						"RANDOMNESS", "% of the interval which should be random to prevent overloading server resources")

					("schedule", sh::string_fun_key(boost::bind(&schedule_object::set_schedule, this, _1)),
						"SCHEDULE", "Cron-like statement for when a task is run. Currently limited to only one number i.e. 1 * * * * or * * 1 * * but not 1 1 * * *")

					("report", sh::string_fun_key(boost::bind(&schedule_object::set_report, this, _1)),
						"REPORT MODE", "What to report to the server (any of the following: all, critical, warning, unknown, ok)", true)

					;
			}

			settings.register_all();
			settings.notify();
		}
Пример #25
0
/*
 * Tries to mount an image.
 * if the fstype is not given try every supported types.
 */
int
fsu_mount(int *argc, char **argv[], int mode)
{
	fsu_fs_t *fst;
	struct fsu_fsalias_s *alias;
	struct mount_data_s mntd;
	int idx, fflag, rv, verbose;
	int ch, stopopts;
	char *mntopts, afsdev[PATH_MAX], *puffsexec, *specopts;
	char *tmp;
	char *fsdevice, *fstype;
	struct stat sb;
#ifdef WITH_SYSPUFFS
	const char options[] = GETOPT_PREFIX"f:o:p:s:t:v";
#else
	const char options[] = GETOPT_PREFIX"f:o:s:t:v";
#endif

	alias = NULL;
	fsdevice = fstype = mntopts = puffsexec = specopts = NULL;
	fst = NULL;
	verbose = fflag = 0;
	stopopts = 0;
	memset(&mntd, 0, sizeof(mntd));
	mntd.mntd_fsdevice = mntd.mntd_canon_dev;

	rump_init();
	opterr = 0;
	/*
	 * [-o mnt_args] [-t fstype] [-p puffsexec] fsdevice
	 */
	while ((ch = getopt(*argc, *argv, options)) != -1) {
		switch (ch) {
		case 'f':
			if (fsdevice == NULL)
				fsdevice = optarg;
			fflag = 1;
			break;
		case 'o':
			if (mntopts == NULL)
				mntopts = optarg;
			break;
#ifdef WITH_SYSPUFFS
		case 'p':
			if (puffsexec == NULL) {
				puffsexec = optarg;
				for (fst = fslist; fst->fs_name != NULL; ++fst)
					if (fst->fs_name == MOUNT_PUFFS)
						break;

				if (fstype == NULL)
					fstype = MOUNT_PUFFS;
				else if (strcmp(fstype, MOUNT_PUFFS) != 0) {
					warnx("-p is only for puffs");
					return -1;
				}
			}
			break;
#endif
		case 's':
			if (specopts == NULL)
				specopts = optarg;
			break;
		case 't':
			if (fstype == NULL)
				fstype = optarg;
			break;
		case 'v':
			++verbose;
			break;
		case '?':
		default:
			--optind;
			stopopts = 1;
			break;
		}
		if (stopopts)
			break;
	}
	idx = optind;
	optind = 1;
#ifdef HAVE_GETOPT_OPTRESET
	optreset = 1;
#endif
	if (mntopts == NULL)
		mntopts = getenv("FSU_MNTOPTS");

	if (mode == MOUNT_READONLY) {
		if (mntopts == NULL)
			mntopts = __UNCONST("ro");
		else {
			tmp = malloc(strlen(mntopts) + 4);
			if (tmp == NULL) {
				warn(NULL);
				opterr = 1;
				return -1;
			}
			snprintf(tmp, strlen(mntopts) + 4, "%s,ro", mntopts);
			mntopts = tmp;
		}
	}

	if (fstype == NULL)
		fstype = getenv("FSU_TYPE");

	if (fstype != NULL && fst == NULL) {
		for (fst = fslist; fst->fs_name != NULL; ++fst)
			if (strcmp(fstype, fst->fs_name) == 0)
				break;

		if (fst->fs_name == NULL) {
			fprintf(stderr, "%s: filesystem not supported\n",
			    fstype);
			opterr = 1;
			return -1;
		}
	}

	if (fsdevice == NULL) {
		fsdevice = getenv("FSU_DEVICE");
		if (fsdevice == NULL) {
			if (idx < *argc && strcmp((*argv)[idx], "--") != 0)
				fsdevice = (*argv)[idx++];
			else {
				errno = 0;
				opterr = 1;
				return -1;
			}
		}
	}

	rv = 0;
	if (!fflag) {
		rv = -1;
		build_alias_list();
		alias = get_alias(fsdevice);
		if (alias != NULL)
			rv = mount_alias(alias, mntopts, specopts, &mntd,
			    verbose);
		free_alias_list();
	}
	if (fflag || alias == NULL) {
		if (realpath(fsdevice, afsdev) != NULL)
			fsdevice = afsdev;
		rv = stat(fsdevice, &sb);
		if (rv == -1)
			warn("%s", fsdevice);
		else if (!(S_ISREG(sb.st_mode) || S_ISBLK(sb.st_mode))) {
			warnx("%s: Not a regular file or block device",
			    fsdevice);
			rv = -1;
		} else {
			rv = rump_pub_etfs_register(RUMPFSDEV, fsdevice,
			    RUMP_ETFS_BLK);
			if (rv != 0) {
				warnx("%s: rump_pub_etfs_register failed "
						"(error=%d)", fsdevice, rv);
			} else {
				mntd.mntd_fsdevice = fsdevice;
				fsdevice = strdup(RUMPFSDEV);
				rv = mount_fstype(fst, fsdevice, mntopts,
				    puffsexec, specopts, &mntd, verbose);
				if (rv == -1) {
					warnx("%s: "
					    "Invalid or unknown filesystem type"
					    ", retry with -v for details",
					    mntd.mntd_fsdevice);
				}
			}
		}
	}

	free(mntd.mntd_argv);
	mntd.mntd_argv = NULL;
	mntd.mntd_argv_size = 0;

	/* Remove the arguments used by fsu_mount and reset getopt*/
	if ((*argv)[idx] != NULL && strcmp((*argv)[idx], "--") == 0)
		++idx;

	if (--idx > 0) {
		(*argv)[idx] = (*argv)[0];
		*argv += idx;
		*argc -= idx;
		optind = 1;
#ifdef HAVE_GETOPT_OPTRESET
		optreset = 1;
#endif
	}

	optind = 1;
#ifdef HAVE_GETOPT_OPTRESET
	optreset = 1;
#endif
	opterr = 1;
	return rv;
}