Пример #1
0
static char *
get_ip6_next_hop (gchar * next_hop)
{
	gchar *tmp;

	if (!next_hop)
		return NULL;
	tmp = find_gateway_str (next_hop);
	if (!tmp) {
		nm_log_warn (LOGD_SETTINGS, "Couldn't obtain next_hop in \"%s\"", next_hop);
		return NULL;
	}
	tmp = g_strdup (tmp);
	strip_string (tmp, ' ');
	strip_string (tmp, '"');
	g_strstrip (tmp);
	if (!nm_utils_ipaddr_valid (AF_INET6, tmp))
		goto error;
	return tmp;
error:
	if (!is_ip4_address (tmp))
		nm_log_warn (LOGD_SETTINGS, "Can't handle IPv6 next_hop: %s", tmp);
	g_free (tmp);

	return NULL;
}
/* format IP and route for writing */
static void
format_ips (gchar * value, gchar ** out_line, gchar * key, gchar * name)
{
	gchar **ipset;
	guint length, i;
	GString *formated_string = g_string_new (NULL);

	strip_string (value, '(');
	strip_string (value, ')');
	strip_string (value, '"');
	ipset = g_strsplit (value, "\"", 0);
	length = g_strv_length (ipset);

	//only one line
	if (length < 2) {
		*out_line =
		    g_strdup_printf ("%s_%s=\"%s\"\n", key, name, value);
		goto done;
	}
	// Multiple lines
	g_string_append_printf (formated_string, "%s_%s=\"\n", key, name);
	for (i = 0; i < length; i++)
	{
		strip_string (ipset[i], ' ');
		if (ipset[i][0] != '\0')
			g_string_append_printf (formated_string,
						"%s\n", ipset[i]);
	}
	g_string_append (formated_string, "\"\n");
	*out_line = g_strdup (formated_string->str);
done:
	g_string_free (formated_string, TRUE);
	g_strfreev (ipset);
}
static guint32
get_ip4_gateway (gchar * gateway)
{
	gchar *tmp, *split;
	struct in_addr tmp_ip4_addr;

	if (!gateway)
		return 0;
	tmp = find_gateway_str (gateway);
	if (!tmp) {
		PLUGIN_WARN (IFNET_PLUGIN_NAME,
			     "Couldn't obtain gateway in \"%s\"", gateway);
		return 0;
	}
	tmp = g_strdup (tmp);
	strip_string (tmp, ' ');
	strip_string (tmp, '"');
	if ((split = strstr (tmp, "\"")) != NULL)
		*split = '\0';
	if (!inet_pton (AF_INET, tmp, &tmp_ip4_addr))
		goto error;
	g_free (tmp);
	return tmp_ip4_addr.s_addr;
      error:
	if (!is_ip6_address (tmp))
		PLUGIN_WARN (IFNET_PLUGIN_NAME, "Can't handle IPv4 gateway: %s",
			     tmp);
	g_free (tmp);
	return 0;
}
Пример #4
0
static void
add_key_value (GHashTable * network, gchar * line)
{
	gchar **key_value;

	if (g_str_has_prefix (line, "network={"))
		line += 9;
	strip_string (line, '{');
	strip_string (line, '}');
	if (line[0] == '\0')
		return;
	key_value = g_strsplit (line, "=", 2);
	if (g_strv_length (key_value) != 2) {
		g_strfreev (key_value);
		return;
	}
	g_strstrip (key_value[0]);
	g_strstrip (key_value[1]);

	/* Reserve quotes for psk, wep_key, ssid
	 * Quotes will determine whether they are hex format */
	if (strcmp (key_value[0], "psk") != 0
	    && !g_str_has_prefix (key_value[0], "wep_key")
	    && strcmp (key_value[0], "ssid") != 0)
		strip_string (key_value[1], '"');
	g_hash_table_insert (network, g_strdup (key_value[0]),
			     g_strdup (key_value[1]));
	g_strfreev (key_value);
}
Пример #5
0
static char *
get_ip4_gateway (gchar * gateway)
{
	gchar *tmp, *split;

	if (!gateway)
		return NULL;
	tmp = find_gateway_str (gateway);
	if (!tmp) {
		nm_log_warn (LOGD_SETTINGS, "Couldn't obtain gateway in \"%s\"", gateway);
		return NULL;
	}
	tmp = g_strdup (tmp);
	strip_string (tmp, ' ');
	strip_string (tmp, '"');

	// Only one gateway is selected
	if ((split = strstr (tmp, "\"")) != NULL)
		*split = '\0';

	if (!nm_utils_ipaddr_valid (AF_INET, tmp))
		goto error;
	return tmp;
error:
	if (!is_ip6_address (tmp))
		nm_log_warn (LOGD_SETTINGS, "Can't handle IPv4 gateway: %s", tmp);
	g_free (tmp);
	return NULL;
}
static struct in6_addr *
get_ip6_next_hop (gchar * next_hop)
{
	gchar *tmp;
	struct in6_addr *tmp_ip6_addr = g_slice_new0 (struct in6_addr);

	if (!next_hop)
		return 0;
	tmp = find_gateway_str (next_hop);
	if (!tmp) {
		PLUGIN_WARN (IFNET_PLUGIN_NAME,
			     "Couldn't obtain next_hop in \"%s\"", next_hop);
		return 0;
	}
	tmp = g_strdup (tmp);
	strip_string (tmp, ' ');
	strip_string (tmp, '"');
	g_strstrip (tmp);
	if (!inet_pton (AF_INET6, tmp, tmp_ip6_addr))
		goto error;
	g_free (tmp);
	return tmp_ip6_addr;
      error:
	if (!is_ip4_address (tmp))
		PLUGIN_WARN (IFNET_PLUGIN_NAME,
			     "Can't handle IPv6 next_hop: %s", tmp);
	g_free (tmp);
	g_slice_free (struct in6_addr, tmp_ip6_addr);

	return NULL;
}
/* Connection type is determined here */
static void
init_block_by_line (gchar * buf)
{
	gchar **key_value;
	gchar *pos;
	gchar *data;
	gchar *tmp;
	GHashTable *conn;

	key_value = g_strsplit (buf, "=", 2);
	if (g_strv_length (key_value) != 2) {
		nm_log_warn (LOGD_SETTINGS, "Can't handle this line: %s\n", buf);
		g_strfreev (key_value);
		return;
	}
	pos = g_strrstr (key_value[0], "_");
	if (pos == NULL || is_global_setting (key_value[0])) {
		/* global data */
		data = g_strdup (key_value[1]);
		tmp = strip_string (data, '"');
		strip_string (tmp, '\'');
		nm_log_info (LOGD_SETTINGS, "global:%s-%s\n", key_value[0], tmp);
		g_hash_table_insert (global_settings_table, g_strdup (key_value[0]), g_strdup (tmp));
		g_strfreev (key_value);
		g_free (data);
		return;
	}
	*pos++ = '\0';
	if ((conn = get_connection_config (pos)) == NULL) {
		if (g_ascii_strncasecmp (pos, "eth", 3) == 0
		    && strlen (pos) == 4)
			/* wired connection */
			conn = add_new_connection_config ("wired", pos);
		else if (g_ascii_strncasecmp (pos, "ppp", 3) == 0
			 && strlen (pos) == 4)
			/* pppoe connection */
			conn = add_new_connection_config ("ppp", pos);
		else if (ignore_connection_name (pos)) {
			/* ignored connection */
			conn = add_new_connection_config ("ignore", pos);
		} else {
			int ifindex = nm_platform_link_get_ifindex (NM_PLATFORM_GET, pos);

			if (ifindex && nm_platform_link_get_type (NM_PLATFORM_GET, ifindex) != NM_LINK_TYPE_WIFI)
				/* wired connection */
				conn = add_new_connection_config ("wired", pos);
			else
				/* wireless connection */
				conn = add_new_connection_config ("wireless", pos);
		}
	}
	data = g_strdup (key_value[1]);
	tmp = strip_string (data, '"');
	strip_string (tmp, '\'');
	if (conn)
		g_hash_table_insert (conn, strip_string (g_strdup (key_value[0]), ' '),
				     g_strdup (tmp));
	g_free (data);
	g_strfreev (key_value);
}
Пример #8
0
static void
test_strip_string ()
{
	gchar *str = "( \"default via     202.117.16.1\" )";
	gchar *result = g_strdup (str);
	gchar *result_b = result;

	result = strip_string (result, '(');
	result = strip_string (result, ')');
	result = strip_string (result, '"');
	ASSERT (strcmp (result, "default via     202.117.16.1") ==
		0, "strip_string",
		"string isn't stripped, result is: %s", result);
	g_free (result_b);
}
Пример #9
0
void
set_ip6_dns_servers (NMSettingIPConfig *s_ip6, const char *conn_name)
{
	const char *dns_servers;
	gchar **server_list, *stripped;
	guint length, i;
	struct in6_addr tmp_ip6_addr;

	dns_servers = ifnet_get_data (conn_name, "dns_servers");
	if (!dns_servers)
		return;

	stripped = g_strdup (dns_servers);
	strip_string (stripped, '"');
	server_list = g_strsplit (stripped, " ", 0);
	g_free (stripped);

	length = g_strv_length (server_list);
	if (length)
		g_object_set (s_ip6, NM_SETTING_IP_CONFIG_IGNORE_AUTO_DNS,
			      TRUE, NULL);
	for (i = 0; i < length; i++) {
		g_strstrip (server_list[i]);
		if (server_list[i][0] == '\0')
			continue;
		if (!inet_pton (AF_INET6, server_list[i], &tmp_ip6_addr)) {
			if (is_ip6_address (server_list[i]))
				nm_log_warn (LOGD_SETTINGS, "ignored dns: %s\n", server_list[i]);
			continue;
		}
		if (!nm_setting_ip_config_add_dns (s_ip6, server_list[i]))
			nm_log_warn (LOGD_SETTINGS, "warning: duplicate DNS server %s", server_list[i]);
	}
	g_strfreev (server_list);
}
Пример #10
0
ip_block *
convert_ip4_routes_block (const char *conn_name)
{
	gchar **ipset;
	guint length;
	guint i;
	gchar *ip;
	ip_block *start = NULL, *current = NULL, *iblock = NULL;

	g_return_val_if_fail (conn_name != NULL, NULL);

	ipset = split_routes (ifnet_get_data (conn_name, "routes"));
	length = ipset ? g_strv_length (ipset) : 0;
	for (i = 0; i < length; i++) {
		ip = ipset[i];
		if (find_default_gateway_str (ip) || strstr (ip, "::")
		    || !find_gateway_str (ip))
			continue;
		ip = strip_string (ip, '"');
		iblock = create_ip4_block (ip);
		if (iblock == NULL)
			continue;
		iblock->next_hop = get_ip4_gateway (ip);
		if (start == NULL)
			start = current = iblock;
		else {
			current->next = iblock;
			current = iblock;
		}
	}
	g_strfreev (ipset);
	return start;
}
Пример #11
0
/* If value is NULL, this method will delete old key value pair */
void
wpa_set_data (const char *ssid, const char *key, const char *value)
{
	gpointer old_key = NULL, old_value = NULL;
	GHashTable *security = g_hash_table_lookup (wsec_table, ssid);
	gchar * stripped = NULL;

	g_return_if_fail (security != NULL);

	if (value){
		stripped = g_strdup(value);
		if (strcmp (key, "ssid") != 0 && strcmp (key, "psk") != 0
			&& !g_str_has_prefix (key, "wep_key"))
			strip_string (stripped, '"');
	}

	/* Remove old key value pairs */
	if (g_hash_table_lookup_extended
	    (security, key, &old_key, &old_value)) {
		if (stripped && !strcmp(old_value, stripped)){
			g_free (stripped);
			return;
		}
		g_hash_table_remove (security, old_key);
		g_free (old_key);
		g_free (old_value);
	} else if (!value)
		return;

	/* Add new key value */
	if (stripped)
		g_hash_table_insert (security, g_strdup (key), stripped);
	wpa_parser_data_changed = TRUE;
}
Пример #12
0
static int
read_file( FILE *file, int *stacksiz)
{
	int  lineno = 1;
	char string[LINE_LENGTH+1];
	
	while( fgets( string, LINE_LENGTH, file) != NULL ) {
		char   *key, *value;
		var_t  *var;
		
		
		
		if( string[strlen(string)-1] != '\n' ) {
			printf( "Line %d: Line too long.\n", lineno);
			return -1;
		}
		
		key = strtok_r( string, ":", &value);
		if( !(var = get_var( key, varlist)) ) {
			printf( "Line %d: Key '%s' not found.\n", lineno, key);
			return -1;
		}
		
		var->stuff.prog = program_init();
		strip_string( value);
		if( parse_expression( value, var->stuff.prog, stacksiz, var->type, symbol_parser) == -1 ) {
			printf( "Line %d: %s\n", lineno, parse_error);
			return -1;
		}
		
		lineno++;
	}
	
	return 0;
};
/* format ip values for comparison */
static gchar*
format_ip_for_comparison (const gchar * value)
{
	gchar **ipset;
	guint length, i;
	GString *formated_string = g_string_new (NULL);
	gchar *formatted = NULL;

	ipset = g_strsplit (value, "\"", 0);
	length = g_strv_length (ipset);

	for (i = 0; i < length; i++)
	{
		strip_string (ipset[i], ' ');
		if (ipset[i][0] != '\0')
			g_string_append_printf (formated_string,
						"%s ", ipset[i]);
	}
	formatted = g_strdup (formated_string->str);
	formatted[formated_string->len - 1] = '\0';

	g_string_free (formated_string, TRUE);
	g_strfreev (ipset);

	return formatted;
}
gchar *
read_hostname (gchar * path)
{
	gchar *contents = NULL, *result = NULL, *tmp;
	gchar **all_lines = NULL;
	guint line_num, i;

	if (!g_file_get_contents (path, &contents, NULL, NULL))
		return NULL;
	all_lines = g_strsplit (contents, "\n", 0);
	line_num = g_strv_length (all_lines);
	for (i = 0; i < line_num; i++) {
		g_strstrip (all_lines[i]);
		if (all_lines[i][0] == '#' || all_lines[i][0] == '\0')
			continue;
		if (g_str_has_prefix (all_lines[i], "hostname")) {
			tmp = strstr (all_lines[i], "=");
			tmp++;
			tmp = strip_string (tmp, '"');
			result = g_strdup (tmp);
			break;
		}

	}
	g_strfreev (all_lines);
	g_free (contents);
	return result;
}
ip6_block *
convert_ip6_config_block (gchar * conn_name)
{
	gchar **ipset;
	guint length;
	guint i;
	gchar *ip;
	ip6_block *start = NULL, *current = NULL, *iblock = NULL;

	g_return_val_if_fail (conn_name != NULL, NULL);
	ipset = g_strsplit (ifnet_get_data (conn_name, "config"), "\" \"", 0);
	length = g_strv_length (ipset);
	for (i = 0; i < length; i++) {
		ip = ipset[i];
		ip = strip_string (ip, '"');
		iblock = create_ip6_block (ip);
		if (iblock == NULL)
			continue;
		if (start == NULL)
			start = current = iblock;
		else {
			current->next = iblock;
			current = iblock;
		}
	}
	g_strfreev (ipset);
	return start;
}
Пример #16
0
void wedit_save_to_disk()
{
  int counter;
  FILE *fp;
  struct wild_data *wild;

  sprintf(buf, "%s/%s.new", WILD_PREFIX, WILD_TABLE_FILE);

  if (!(fp = fopen(buf, "w+")))
    {
    mudlog("SYSERR: OLC: Cannot open wild table file!", BRF, LVL_BUILDER, TRUE);
    return;
    }

  for (counter = 0; counter <= top_of_wild_table; counter++)
    {
    wild = (wild_table + counter);

    /*
     * Remove the '\r\n' sequences from description.
     */
    strcpy(buf1, wild->description ? wild->description : "Empty");
    strip_string(buf1);

    /*
     * Forget making a buffer, lets just write the thing now.
     */
    fprintf(fp, "#%d\n%s~\n%s~\n%c %d %d\n%d %d %d\n%d %d\n",
            wild_table[counter].index,
            wild_table[counter].name,
            buf1,
            wild_table[counter].symbol,
            wild_table[counter].color,
            wild_table[counter].owner,
            wild_table[counter].move_cost,
            wild_table[counter].altitudine,
            wild_table[counter].can_enter,
            wild_table[counter].sector_type,
            wild_table[counter].room_flags);
    }

  /*
   * Write final line and close.
   */
  fprintf(fp, "$~\n");
  fclose(fp);

  sprintf(buf2, "%s/%s", WILD_PREFIX, WILD_TABLE_FILE);

  /*
   * We're fubar'd if we crash between the two lines below.
   */
  remove(buf2);
  rename(buf, buf2);
  for (counter=0; counter <= top_of_zone_table; counter++)
    wild_ascii_map_save_to_disk(counter);
  olc_remove_from_save_list(WILD_ZONE, OLC_SAVE_WILD);
}
Пример #17
0
static void strip_lower_string(GString *string)
{
    gchar *lower;
    strip_string(string);

    lower = g_ascii_strdown(string->str, -1);
    g_free(string->str);
    string->str = lower;
}
ip6_block *
convert_ip6_routes_block (gchar * conn_name)
{
	gchar **ipset;
	guint length;
	guint i;
	gchar *ip, *tmp_addr;
	gchar *routes;
	ip6_block *start = NULL, *current = NULL, *iblock = NULL;
	struct in6_addr *tmp_ip6_addr;

	g_return_val_if_fail (conn_name != NULL, NULL);
	routes = ifnet_get_data (conn_name, "routes");
	if (!routes)
		return NULL;
	ipset = g_strsplit (routes, "\" \"", 0);
	length = g_strv_length (ipset);
	for (i = 0; i < length; i++) {
		ip = ipset[i];
		ip = strip_string (ip, '"');
		if (ip[0] == '\0')
			continue;
		if ((tmp_addr = find_default_gateway_str (ip)) != NULL) {
			if (!is_ip6_address (tmp_addr))
				continue;
			else {
				tmp_ip6_addr = g_slice_new0 (struct in6_addr);

				if (inet_pton (AF_INET6, "::", tmp_ip6_addr)) {
					iblock = g_slice_new0 (ip6_block);
					iblock->ip = tmp_ip6_addr;
					iblock->prefix = 128;
				} else {
					g_slice_free (struct in6_addr,
						      tmp_ip6_addr);
					continue;
				}
			}
		} else
			iblock = create_ip6_block (ip);
		if (iblock == NULL)
			continue;
		iblock->next_hop = get_ip6_next_hop (ip);
		if (iblock->next_hop == NULL) {
			destroy_ip6_block (iblock);
			continue;
		}
		if (start == NULL)
			start = current = iblock;
		else {
			current->next = iblock;
			current = iblock;
		}
	}
Пример #19
0
int iniparser_get_octalint_at_position(Tiniparser *ip, const char *section, const char *key, long position) {
	char data[25];
	int buffer=0;
	memset(data, 0, 25);
	if (iniparser_get_string_at_position(ip, section, key, position, data, 25)==-1){
		return -1;
	}
	strip_string(data);	
	sscanf(data, "%o", &buffer);
	return buffer;
}
void
ifnet_set_data (const char *conn_name, const char *key, const char *value)
{
	gpointer old_key = NULL, old_value = NULL;
	GHashTable *conn = g_hash_table_lookup (conn_table, conn_name);
	gchar * stripped = NULL;

	if (!conn) {
		nm_log_warn (LOGD_SETTINGS, "%s does not exist!", conn_name);
		return;
	}
	if (value){
		stripped = g_strdup (value);
		strip_string (stripped, '"');
	}
	/* Remove existing key value pair */
	if (g_hash_table_lookup_extended (conn, key, &old_key, &old_value)) {

		/* This ugly hack is due to baselayout compatibility. We have to
		 * deal with different ip format. So sometimes we have the same ips
		 * but different strings.
		 */
		if (stripped &&
			(!strcmp (key, "config")
			|| !strcmp (key, "routes")
			|| !strcmp (key, "pppd")
			|| !strcmp (key, "chat")))
		{
			gchar *old_ips = format_ip_for_comparison (old_value);
			gchar *new_ips = format_ip_for_comparison (value);
			if(!strcmp (old_ips, new_ips))
			{
				g_free (stripped);
				g_free (old_ips);
				g_free (new_ips);
				return;
			}
			g_free (old_ips);
			g_free (new_ips);
		}

		if (stripped && !strcmp (old_value, stripped)) {
			g_free (stripped);
			return;
		}
		g_hash_table_remove (conn, old_key);
		g_free (old_key);
		g_free (old_value);
	} else if (!value)
		return;
	if (stripped)
		g_hash_table_insert (conn, g_strdup (key), stripped);
	net_parser_data_changed = TRUE;
}
Пример #21
0
/*
** Prompt the user to enter a single line of text.
*/
void prompt_user(const char *zPrompt, Blob *pIn){
  char *z;
  char zLine[1000];
  blob_zero(pIn);
  printf("%s", zPrompt);
  fflush(stdout);
  z = fgets(zLine, sizeof(zLine), stdin);
  if( z ){
    strip_string(pIn, z);
  }
}
Пример #22
0
float iniparser_get_float_at_position(Tiniparser *ip, const char *section, const char *key, long position) {
	float ret = 1.0;
	char data[25];
	memset(data, 0, 25);
	if (iniparser_get_string_at_position(ip, section, key, position, data, 25)==-1){
		DEBUG_MSG("iniparser_get_float_at_position, no string found\n");
		return 0.0;
	}
	strip_string(data);	
	sscanf(data, "%f", &ret);
	return ret;
}
Пример #23
0
int get_execution_line(void ** instruction_line) {

    t_list * instruction_addresses_list = armarDireccionesLogicasList(
            actual_pcb->instrucciones_serializado + actual_pcb->program_counter);
    if(get_instruction_line(instruction_addresses_list, instruction_line) != SUCCESS) {
        return ERROR;
    }
    strip_string(*instruction_line);
    printf(ANSI_COLOR_YELLOW);
    log_info(cpu_log, "Next execution line: %s", *instruction_line);
    printf(ANSI_COLOR_RESET);
    return SUCCESS;
}
Пример #24
0
static GHashTable *
add_security (GHashTable *security)
{
	GHashTable *oldsecurity;
	const char *ssid, *value;
	char *ssid_key;
	gboolean is_hex_ssid;

	/* Every security information should have a ssid */
	ssid = g_hash_table_lookup (security, "ssid");
	if (!ssid) {
		destroy_security (security);
		return NULL;
	}

	/* Hex format begins with " */
	is_hex_ssid = (ssid[0] != '"');
	if ((value = g_hash_table_lookup (security, "disabled")) != NULL) {
		if (strcmp (value, "1") == 0) {
			destroy_security (security);
			return NULL;
		}
	}

	/* Default priority is 1 */
	if (g_hash_table_lookup (security, "priority") == NULL)
		g_hash_table_insert (security, g_strdup ("priority"),
				     g_strdup ("1"));

	oldsecurity = g_hash_table_lookup (wsec_table, ssid);
	/* Security with lower priority will be ignored */
	if (oldsecurity != NULL) {
		if (wpa_get_long (oldsecurity, "priority") >=
		    wpa_get_long (security, "priority")) {
			destroy_security (security);
			return NULL;
		} else {
			g_hash_table_remove (wsec_table, ssid);
			destroy_security (oldsecurity);
		}
	}

	/* format ssid */
	ssid_key =
	    is_hex_ssid ? g_strdup_printf ("0x%s",
					   ssid) :
	    strip_string (g_strdup (ssid), '"');
	g_hash_table_insert (wsec_table, ssid_key, security);
	return security;
}
Пример #25
0
void tedit_string_cleanup(struct descriptor_data *d, int terminator)
{
  FILE *fl;
  char *storage = OLC_STORAGE(d);

  if (!storage)
    terminator = STRINGADD_ABORT;

  switch (terminator) {
  case STRINGADD_SAVE:
    if (OLC(d)->kill_on_empty && (!(*d->str) || **d->str == '\0')) {
      if (kill_file(storage)) {
        sprintf(buf, "SYSERR: Can't delete file '%s'.", storage);
        mudlog(buf, CMP, LVL_IMPL, TRUE);
      } else {
        sprintf(buf, "OLC: %s deletes '%s'.", GET_NAME(d->character), storage);
        mudlog(buf, CMP, LVL_GOD, TRUE);
        write_to_output(d, "Deleted.\r\n");
      }
    } else if (!(fl = fopen(storage, "w"))) {
      sprintf(buf, "SYSERR: Can't write file '%s'.", storage);
      mudlog(buf, CMP, LVL_IMPL, TRUE);
    } else {
      if (*d->str) {
        strip_string(*d->str);
        fputs(*d->str, fl);
      }
      fclose(fl);
      sprintf(buf, "OLC: %s saves '%s'.", GET_NAME(d->character), storage);
      mudlog(buf, CMP, LVL_GOD, TRUE);
      write_to_output(d, "Saved.\r\n");
    }
    break;
  case STRINGADD_ABORT:
    write_to_output(d, "Edit aborted.\r\n");
    act("$n stops editing some scrolls.", TRUE, d->character, 0, 0, TO_ROOM);
    break;
  default:
    log("SYSERR: tedit_string_cleanup: Unknown terminator status.");
    break;
  }

  /* Common cleanup code. */
  cleanup_olc(d, CLEANUP_ALL);
  STATE(d) = CON_PLAYING;
}
Пример #26
0
ip_block *
convert_ip6_routes_block (const char *conn_name)
{
	gchar **ipset;
	guint length;
	guint i;
	gchar *ip, *tmp_addr;
	ip_block *start = NULL, *current = NULL, *iblock = NULL;

	g_return_val_if_fail (conn_name != NULL, NULL);
	ipset = split_routes (ifnet_get_data (conn_name, "routes"));
	length = ipset ? g_strv_length (ipset) : 0;
	for (i = 0; i < length; i++) {
		ip = ipset[i];
		ip = strip_string (ip, '"');
		if (ip[0] == '\0')
			continue;
		if ((tmp_addr = find_default_gateway_str (ip)) != NULL) {
			if (!is_ip6_address (tmp_addr))
				continue;
			else {
				iblock = g_slice_new0 (ip_block);
				iblock->ip = g_strdup ("::");
				iblock->prefix = 128;
			}
		} else
			iblock = create_ip_block (ip);
		if (iblock == NULL)
			continue;
		iblock->next_hop = get_ip6_next_hop (ip);
		if (iblock->next_hop == NULL) {
			destroy_ip_block (iblock);
			continue;
		}
		if (start == NULL)
			start = current = iblock;
		else {
			current->next = iblock;
			current = iblock;
		}
	}
	g_strfreev (ipset);
	return start;
}
Пример #27
0
UiApi::Status UserInterface::exec_and_log(const string& c)
{
    if (strip_string(c).empty())
        return UiApi::kStatusOk;

    // we want to log the input before the output
    if (!ctx_->get_settings()->logfile.empty()) {
        FILE* f = fopen(ctx_->get_settings()->logfile.c_str(), "a");
        if (f) {
            fprintf(f, "%s\n", c.c_str());
            fclose(f);
        }
    }

    UiApi::Status r = this->exec_command(c);
    cmds_.push_back(Cmd(c, r));
    ++cmd_count_;
    return r;
}
Пример #28
0
static void set_file(chash * hash, char * email, char * filename)
{
  char * n;
  char buf[MAX_EMAIL_SIZE];
  chashdatum key;
  chashdatum data;

  strncpy(buf, email, sizeof(buf));
  buf[sizeof(buf) - 1] = '\0';
  for(n = buf ; * n != '\0' ; n ++)
    * n = toupper((unsigned char) * n);
  strip_string(buf);
  
  key.data = buf;
  key.len = strlen(buf);
  data.data = filename;
  data.len = strlen(filename) + 1;
  
  chash_set(hash, &key, &data, NULL);
}
Пример #29
0
ip_block *
convert_ip4_config_block (const char *conn_name)
{
	gchar **ipset;
	guint length;
	guint i;
	gchar *ip;
	char *def_gateway = NULL;
	const char *routes;
	ip_block *start = NULL, *current = NULL, *iblock = NULL;

	g_return_val_if_fail (conn_name != NULL, NULL);

	ipset = split_addresses (ifnet_get_data (conn_name, "config"));
	length = ipset ? g_strv_length (ipset) : 0;

	routes = ifnet_get_data (conn_name, "routes");
	if (routes)
		def_gateway = get_ip4_gateway (strstr (routes, "default"));

	for (i = 0; i < length; i++) {
		ip = ipset[i];
		ip = strip_string (ip, '"');
		iblock = create_ip4_block (ip);
		if (iblock == NULL)
			continue;
		if (!iblock->next_hop && def_gateway != NULL)
			iblock->next_hop = g_strdup (def_gateway);
		if (start == NULL)
			start = current = iblock;
		else {
			current->next = iblock;
			current = iblock;
		}
	}
	g_strfreev (ipset);
	g_free (def_gateway);
	return start;
}
Пример #30
0
static char * get_file(chash * hash, char * email)
{
  chashdatum key;
  chashdatum data;
  char buf[MAX_EMAIL_SIZE];
  char * n;
  int r;
  
  strncpy(buf, email, sizeof(buf));
  buf[sizeof(buf) - 1] = '\0';
  for(n = buf ; * n != '\0' ; n ++)
    * n = toupper((unsigned char) * n);
  
  strip_string(buf);
  key.data = buf;
  key.len = strlen(buf);
  r = chash_get(hash, &key, &data);
  if (r < 0)
    return NULL;
  
  return data.data;
}