当前位置: 首页>>代码示例>>C++>>正文


C++ g_strsplit函数代码示例

本文整理汇总了C++中g_strsplit函数的典型用法代码示例。如果您正苦于以下问题:C++ g_strsplit函数的具体用法?C++ g_strsplit怎么用?C++ g_strsplit使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了g_strsplit函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: ip4_process_dhcpcd_rfc3442_routes

static gboolean
ip4_process_dhcpcd_rfc3442_routes (const char *str,
                                   NMIP4Config *ip4_config,
                                   guint32 *gwaddr)
{
	char **routes, **r;
	gboolean have_routes = FALSE;

	routes = g_strsplit (str, " ", 0);
	if (g_strv_length (routes) == 0)
		goto out;

	if ((g_strv_length (routes) % 2) != 0) {
		nm_log_warn (LOGD_DHCP4, "  classless static routes provided, but invalid");
		goto out;
	}

	for (r = routes; *r; r += 2) {
		char *slash;
		NMIP4Route *route;
		int rt_cidr = 32;
		struct in_addr rt_addr;
		struct in_addr rt_route;

		slash = strchr(*r, '/');
		if (slash) {
			*slash = '\0';
			errno = 0;
			rt_cidr = strtol (slash + 1, NULL, 10);
			if ((errno == EINVAL) || (errno == ERANGE)) {
				nm_log_warn (LOGD_DHCP4, "DHCP provided invalid classless static route cidr: '%s'", slash + 1);
				continue;
			}
		}
		if (inet_pton (AF_INET, *r, &rt_addr) <= 0) {
			nm_log_warn (LOGD_DHCP4, "DHCP provided invalid classless static route address: '%s'", *r);
			continue;
		}
		if (inet_pton (AF_INET, *(r + 1), &rt_route) <= 0) {
			nm_log_warn (LOGD_DHCP4, "DHCP provided invalid classless static route gateway: '%s'", *(r + 1));
			continue;
		}

		have_routes = TRUE;
		if (rt_cidr == 0 && rt_addr.s_addr == 0) {
			/* FIXME: how to handle multiple routers? */
			*gwaddr = rt_route.s_addr;
		} else {
			route = nm_ip4_route_new ();
			nm_ip4_route_set_dest (route, (guint32) rt_addr.s_addr);
			nm_ip4_route_set_prefix (route, rt_cidr);
			nm_ip4_route_set_next_hop (route, (guint32) rt_route.s_addr);

			nm_ip4_config_take_route (ip4_config, route);
			nm_log_info (LOGD_DHCP4, "  classless static route %s/%d gw %s", *r, rt_cidr, *(r + 1));
		}
	}

out:
	g_strfreev (routes);
	return have_routes;
}
开发者ID:eugeni,项目名称:NetworkManager-mdv,代码行数:62,代码来源:nm-dhcp-client.c

示例2: end_element

static void
end_element (GMarkupParseContext  *context,
	     const gchar          *element_name,
	     gpointer              user_data,
	     GError              **error)
{
  ParseState *state = user_data;
  GError *my_error = NULL;

  if (strcmp (element_name, "gresource") == 0)
    {
      g_free (state->prefix);
      state->prefix = NULL;
    }

  else if (strcmp (element_name, "file") == 0)
    {
      gchar *file, *real_file;
      gchar *key;
      FileData *data;
      char *tmp_file = NULL;
      char *tmp_file2 = NULL;

      file = state->string->str;
      key = file;
      if (state->alias)
	key = state->alias;

      if (state->prefix)
	key = g_build_path ("/", "/", state->prefix, key, NULL);
      else
	key = g_build_path ("/", "/", key, NULL);

      if (g_hash_table_lookup (state->table, key) != NULL)
	{
	  g_set_error (error, G_MARKUP_ERROR, G_MARKUP_ERROR_INVALID_CONTENT,
		       _("File %s appears multiple times in the resource"),
		       key);
	  return;
	}

      data = g_new0 (FileData, 1);

      if (sourcedirs != NULL)
        {
	  real_file = find_file (file);
	  if (real_file == NULL)
	    {
		g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
			     _("Failed to locate '%s' in any source directory"), file);
		return;
	    }
	}
      else
        {
	  gboolean exists;
	  exists = g_file_test (file, G_FILE_TEST_EXISTS);
	  if (!exists)
	    {
	      g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
			   _("Failed to locate '%s' in current directory"), file);
	      return;
	    }
	  real_file = g_strdup (file);
	}

      data->filename = g_strdup (real_file);
      if (!state->collect_data)
        goto done;

      if (state->preproc_options)
        {
          gchar **options;
          guint i;
          gboolean xml_stripblanks = FALSE;
          gboolean to_pixdata = FALSE;

          options = g_strsplit (state->preproc_options, ",", -1);

          for (i = 0; options[i]; i++)
            {
              if (!strcmp (options[i], "xml-stripblanks"))
                xml_stripblanks = TRUE;
              else if (!strcmp (options[i], "to-pixdata"))
                to_pixdata = TRUE;
              else
                {
                  g_set_error (error, G_MARKUP_ERROR, G_MARKUP_ERROR_INVALID_CONTENT,
                               _("Unknown processing option \"%s\""), options[i]);
                  g_strfreev (options);
                  goto cleanup;
                }
            }
          g_strfreev (options);

          if (xml_stripblanks && xmllint != NULL)
            {
              int fd;
	      GSubprocess *proc;

//.........这里部分代码省略.........
开发者ID:QuentinFiard,项目名称:glib,代码行数:101,代码来源:glib-compile-resources.c

示例3: daemon_helpers_typehelper_ParseHostAndPort

void daemon_helpers_typehelper_ParseHostAndPort (const gchar* input, gchar** host, guint16** port, GError** error) {
	gchar* _host = NULL;
	guint16* _port = NULL;
	gchar** _tmp0_;
	gchar** _tmp1_ = NULL;
	gchar** parts;
	gint parts_length1;
	gint _parts_size_;
	gchar* _tmp3_ = NULL;
	gint _tmp4_;
	GError * _inner_error_ = NULL;
	g_return_if_fail (input != NULL);
	_tmp1_ = _tmp0_ = g_strsplit (input, ":", 0);
	parts = _tmp1_;
	parts_length1 = _vala_array_length (_tmp0_);
	_parts_size_ = _vala_array_length (_tmp0_);
	if (parts_length1 > 2) {
		GError* _tmp2_ = NULL;
		_tmp2_ = g_error_new_literal (DAEMON_HELPERS_DAEMON_ERROR, DAEMON_HELPERS_DAEMON_ERROR_ParseFailed, "Invalid host");
		_inner_error_ = _tmp2_;
		if (_inner_error_->domain == DAEMON_HELPERS_DAEMON_ERROR) {
			g_propagate_error (error, _inner_error_);
			parts = (_vala_array_free (parts, parts_length1, (GDestroyNotify) g_free), NULL);
			return;
		} else {
			parts = (_vala_array_free (parts, parts_length1, (GDestroyNotify) g_free), NULL);
			g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
			g_clear_error (&_inner_error_);
			return;
		}
	}
	_tmp3_ = string_strip (parts[0]);
	_g_free0 (_host);
	_host = _tmp3_;
	_tmp4_ = strlen (_host);
	if (_tmp4_ == 0) {
		GError* _tmp5_ = NULL;
		_tmp5_ = g_error_new_literal (DAEMON_HELPERS_DAEMON_ERROR, DAEMON_HELPERS_DAEMON_ERROR_ParseFailed, "Invalid host");
		_inner_error_ = _tmp5_;
		if (_inner_error_->domain == DAEMON_HELPERS_DAEMON_ERROR) {
			g_propagate_error (error, _inner_error_);
			parts = (_vala_array_free (parts, parts_length1, (GDestroyNotify) g_free), NULL);
			return;
		} else {
			parts = (_vala_array_free (parts, parts_length1, (GDestroyNotify) g_free), NULL);
			g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
			g_clear_error (&_inner_error_);
			return;
		}
	}
	if (parts_length1 == 2) {
		guint16* _tmp6_ = NULL;
		_tmp6_ = daemon_helpers_typehelper_ParsePort (parts[1]);
		_g_free0 (_port);
		_port = _tmp6_;
		if (_port == NULL) {
			GError* _tmp7_ = NULL;
			_tmp7_ = g_error_new_literal (DAEMON_HELPERS_DAEMON_ERROR, DAEMON_HELPERS_DAEMON_ERROR_ParseFailed, "Could not parse port");
			_inner_error_ = _tmp7_;
			if (_inner_error_->domain == DAEMON_HELPERS_DAEMON_ERROR) {
				g_propagate_error (error, _inner_error_);
				parts = (_vala_array_free (parts, parts_length1, (GDestroyNotify) g_free), NULL);
				return;
			} else {
				parts = (_vala_array_free (parts, parts_length1, (GDestroyNotify) g_free), NULL);
				g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
				g_clear_error (&_inner_error_);
				return;
			}
		}
	}
	parts = (_vala_array_free (parts, parts_length1, (GDestroyNotify) g_free), NULL);
	if (host) {
		*host = _host;
	} else {
		_g_free0 (_host);
	}
	if (port) {
		*port = _port;
	} else {
		_g_free0 (_port);
	}
}
开发者ID:SBFh,项目名称:SemesterLeistung,代码行数:83,代码来源:TypeHelper.c

示例4: handle_line

static void handle_line(const struct sr_dev_inst *sdi)
{
	struct dev_context *devc;
	struct sr_serial_dev_inst *serial;
	struct sr_datafeed_packet packet;
	struct sr_datafeed_analog_old *analog;
	int num_tokens, n, i;
	char cmd[16], **tokens;

	devc = sdi->priv;
	serial = sdi->conn;
	sr_spew("Received line '%s' (%d).", devc->buf, devc->buflen);

	if (devc->buflen == 1) {
		if (devc->buf[0] != '0') {
			/* Not just a CMD_ACK from the query command. */
			sr_dbg("Got CMD_ACK '%c'.", devc->buf[0]);
			devc->expect_response = FALSE;
		}
		devc->buflen = 0;
		return;
	}

	analog = NULL;
	tokens = g_strsplit(devc->buf, ",", 0);
	if (tokens[0]) {
		if (devc->profile->model == FLUKE_187 || devc->profile->model == FLUKE_189) {
			devc->expect_response = FALSE;
			analog = handle_qm_18x(sdi, tokens);
		} else if (devc->profile->model == FLUKE_287) {
			devc->expect_response = FALSE;
			analog = handle_qm_28x(sdi, tokens);
		} else if (devc->profile->model == FLUKE_190) {
			devc->expect_response = FALSE;
			for (num_tokens = 0; tokens[num_tokens]; num_tokens++);
			if (num_tokens >= 7) {
				/* Response to QM: this is a comma-separated list of
				 * fields with metadata about the measurement. This
				 * format can return multiple sets of metadata,
				 * split into sets of 7 tokens each. */
				devc->meas_type = 0;
				for (i = 0; i < num_tokens; i += 7)
					handle_qm_19x_meta(sdi, tokens + i);
				if (devc->meas_type) {
					/* Slip the request in now, before the main
					 * timer loop asks for metadata again. */
					n = sprintf(cmd, "QM %d\r", devc->meas_type);
					if (serial_write_blocking(serial, cmd, n, SERIAL_WRITE_TIMEOUT_MS) < 0)
						sr_err("Unable to send QM (measurement).");
				}
			} else {
				/* Response to QM <n> measurement request. */
				handle_qm_19x_data(sdi, tokens);
			}
		}
	}
	g_strfreev(tokens);
	devc->buflen = 0;

	if (analog) {
		/* Got a measurement. */
		packet.type = SR_DF_ANALOG_OLD;
		packet.payload = analog;
		sr_session_send(devc->cb_data, &packet);
		devc->num_samples++;
		g_free(analog->data);
		g_free(analog);
	}

}
开发者ID:aurelj,项目名称:libsigrok,代码行数:70,代码来源:fluke.c

示例5: gs_plugin_add_updates_historical

/**
 * gs_plugin_add_updates_historical:
 */
gboolean
gs_plugin_add_updates_historical (GsPlugin *plugin,
				  GList **list,
				  GCancellable *cancellable,
				  GError **error)
{
	gboolean ret;
	guint i;
	_cleanup_strv_free_ gchar **package_ids = NULL;
	_cleanup_free_ gchar *error_details = NULL;
	_cleanup_free_ gchar *packages = NULL;
	_cleanup_keyfile_unref_ GKeyFile *key_file = NULL;

	/* was any offline update attempted */
	if (!g_file_test (PK_OFFLINE_UPDATE_RESULTS_FILENAME, G_FILE_TEST_EXISTS))
		return TRUE;

	/* open the file */
	key_file = g_key_file_new ();
	ret = g_key_file_load_from_file (key_file,
					 PK_OFFLINE_UPDATE_RESULTS_FILENAME,
					 G_KEY_FILE_NONE,
					 error);
	if (!ret)
		return FALSE;

	/* only return results if successful */
	ret = g_key_file_get_boolean (key_file,
				      PK_OFFLINE_UPDATE_RESULTS_GROUP,
				      "Success",
				      NULL);
	if (!ret) {
		error_details = g_key_file_get_string (key_file,
						       PK_OFFLINE_UPDATE_RESULTS_GROUP,
						       "ErrorDetails",
						       error);
		if (error_details == NULL)
			return FALSE;
		g_set_error_literal (error,
				     GS_PLUGIN_ERROR,
				     GS_PLUGIN_ERROR_FAILED,
				     error_details);
		return FALSE;
	}

	/* get list of package-ids */
	packages = g_key_file_get_string (key_file,
					  PK_OFFLINE_UPDATE_RESULTS_GROUP,
					  "Packages",
					  NULL);
	if (packages == NULL) {
		g_set_error (error,
			     GS_PLUGIN_ERROR,
			     GS_PLUGIN_ERROR_NOT_SUPPORTED,
			     "No 'Packages' in %s",
			     PK_OFFLINE_UPDATE_RESULTS_FILENAME);
		return FALSE;
	}
	package_ids = g_strsplit (packages, ",", -1);
	for (i = 0; package_ids[i] != NULL; i++) {
		_cleanup_object_unref_ GsApp *app = NULL;
		_cleanup_strv_free_ gchar **split = NULL;
		app = gs_app_new (NULL);
		split = g_strsplit (package_ids[i], ";", 4);
		gs_app_add_source (app, split[0]);
		gs_app_set_update_version (app, split[1]);
		gs_app_set_management_plugin (app, "PackageKit");
		gs_app_add_source_id (app, package_ids[i]);
		gs_app_set_state (app, AS_APP_STATE_UPDATABLE);
		gs_app_set_kind (app, GS_APP_KIND_PACKAGE);
		gs_plugin_add_app (list, app);
	}
	return TRUE;
}
开发者ID:bhurtelashish,项目名称:gnome-software,代码行数:77,代码来源:gs-plugin-packagekit-offline.c

示例6: _tgentransfer_readCommand

static void _tgentransfer_readCommand(TGenTransfer* transfer) {
    TGEN_ASSERT(transfer);

    if(_tgentransfer_getLine(transfer)) {
        /* we have read the entire command from the other end */
        gboolean hasError = FALSE;
        transfer->time.command = g_get_monotonic_time();

        gchar* line = g_string_free(transfer->readBuffer, FALSE);
        transfer->readBuffer = NULL;

        gchar** parts = g_strsplit(line, " ", 0);
        if(parts[0] == NULL || parts[1] == NULL || parts[2] == NULL || parts[3] == NULL) {
            tgen_critical("error parsing command '%s'", transfer->readBuffer->str);
            hasError = TRUE;
        } else {
            g_assert(!transfer->remoteName);
            transfer->remoteName = g_strdup(parts[0]);

            transfer->remoteID = (gsize)g_ascii_strtoull(parts[1], NULL, 10);
            if(transfer->remoteID == 0) {
                tgen_critical("error parsing command ID '%s'", parts[1]);
                hasError = TRUE;
            }

            if(!g_ascii_strncasecmp(parts[2], "GET", 3)) {
                /* they are trying to GET, then we need to PUT to them */
                transfer->type = TGEN_TYPE_PUT;
                /* we read command, but now need to write payload */
                transfer->events |= TGEN_EVENT_WRITE;
            } else if(!g_ascii_strncasecmp(parts[2], "PUT", 3)) {
                /* they want to PUT, so we will GET from them */
                transfer->type = TGEN_TYPE_GET;
            } else {
                tgen_critical("error parsing command type '%s'", parts[2]);
                hasError = TRUE;
            }

            transfer->size = (gsize)g_ascii_strtoull(parts[3], NULL, 10);
            if(transfer->size == 0) {
                tgen_critical("error parsing command size '%s'", parts[3]);
                hasError = TRUE;
            }
        }

        g_strfreev(parts);
        g_free(line);

        /* payload phase is next unless there was an error parsing */
        if(hasError) {
            _tgentransfer_changeState(transfer, TGEN_XFER_ERROR);
            _tgentransfer_changeError(transfer, TGEN_XFER_ERR_READ);
        } else {
            /* we need to update our string with the new command info */
            _tgentransfer_resetString(transfer);
            _tgentransfer_changeState(transfer, TGEN_XFER_RESPONSE);
            transfer->events |= TGEN_EVENT_WRITE;
        }
    } else {
        /* unable to receive entire command, wait for next chance to read */
    }
}
开发者ID:Javex,项目名称:shadow,代码行数:62,代码来源:shd-tgen-transfer.c

示例7: main

int
main(int argc, char ** argv)
{
	HC_PROC_INIT(argv,GRID_LOGLVL_INFO);

	int rc = 1;
	service_info_t *service = NULL;
	setenv("GS_DEBUG_ENABLE", "0", TRUE);

	supervisor_children_init();

	do {
		GError *err = NULL;
		regex_tag = g_regex_new("((stat|tag)\\.([^.=\\s]+))\\s*=\\s*(.*)",
				G_REGEX_CASELESS|G_REGEX_EXTENDED, 0, &err);
		if (!regex_tag) {
			FATAL("Cannot compile tag regex: %s", err->message);
			g_clear_error(&err);
			exit(-1);
		}
		regex_svc = g_regex_new("([^|]*)\\|([^|]*)\\|(.*)",
				G_REGEX_CASELESS, 0, &err);
		if (!regex_svc) {
			FATAL("Cannot compile svc regex: %s", err->message);
			g_clear_error(&err);
			exit(-1);
		}
	} while (0);

	static struct option long_options[] = {
		{"svc-id", 1, 0, 'i'},
		{"monitor", 1, 0, 'm'},
		{"svc-cmd", 1, 0, 'c'},
		{"syslog-id", 1, 0, 's'},
		{"auto-restart-children", 0, 0, 'a'},
		{"monitor-period", 1, 0, 'p'},
		{"no-tcp-check", 0, 0, 'n'},
		{"tag", 1, 0, 't'},
		{0, 0, 0, 0}
	};

	int c;
	int option_index = 0;
	gchar *optarg2 = NULL;
	gchar **kv = NULL;
	while (-1 != (c = getopt_long(argc, argv, "ac:i:m:np:s:t:",
			long_options, &option_index))) {
		switch (c) {
		case 'i':
			g_strlcpy(svc_id, optarg, sizeof(svc_id)-1);
			break;
		case 'm':
			g_strlcpy(svc_mon, optarg, sizeof(svc_mon)-1);
			break;
		case 'c':
			g_strlcpy(svc_cmd, optarg, sizeof(svc_cmd)-1);
			break;
		case 'n':
			kv = g_malloc0(3 * sizeof(gchar*));
			kv[0] = g_strdup("tag.agent_check");
			kv[1] = g_strdup("false");
			custom_tags = g_slist_prepend(custom_tags, kv);
			break;
		case 'a':
			auto_restart_children = TRUE;
			break;
		case 'p':
			monitor_period = strtoll(optarg, NULL, 10);
			break;
		case 's':
			g_strlcpy(syslog_id, optarg, sizeof(syslog_id)-1);
			break;
		case 't':
			if (!g_str_has_prefix(optarg, "tag."))
				optarg2 = g_strdup_printf("tag.%s", optarg);
			else
				optarg2 = g_strdup(optarg);
			kv = g_strsplit(optarg2, "=", 2);
			if (kv && g_strv_length(kv) == 2) {
				custom_tags = g_slist_prepend(custom_tags, kv);
			} else {
				g_printerr("Invalid tag, must contain '=': %s", optarg);
				g_strfreev(kv);
				kv = NULL;
			}
			g_free(optarg2);
			optarg2 = NULL;
			break;
		default:
			g_printerr("Unexpected option: %c\n", c);
			break;
		}
		option_index = 0;
	}

	if (argc <= 1 || strlen(svc_id) == 0 || strlen(svc_cmd) == 0) {
		g_printerr("Usage: %s\n", argv[0]);
		g_printerr("Mandatory options:\n");
		g_printerr("\t-i\t--svc-id <NS|type|ip:port>\n"
				"\t-c\t--svc-cmd </service/cmd/to/launch>\n\n"
//.........这里部分代码省略.........
开发者ID:korween,项目名称:oio-sds,代码行数:101,代码来源:main.c

示例8: system_stat

static gchar * system_stat ()
{
        gchar *std_out, *p, **pp1, **pp2, model_name[128], *result;
        gint count;
        GError *err = NULL;

        /* cpu mode */
        result = g_strdup ("{\n");
        if (!g_file_get_contents ("/proc/cpuinfo", &p, NULL, &err)) {
                GST_ERROR ("read /proc/cpuinfo failure: %s", err->message);
                g_free (result);
                result = g_strdup_printf ("{\n    \"result\": \"failure\",\n    \"reason\": \"%s\"\n}", err->message);
                g_error_free (err);
                return result;
        }

        pp1 = pp2 = g_strsplit (p, "\n", 0);
        g_free (p);
        while (*pp1 != NULL) {
                if (!g_str_has_prefix (*pp1, "model name")) {
                        pp1++;
                        continue;
                }
                sscanf (*pp1, "%*[^:]: %[^\n]$", model_name);
                break;
        }
        g_strfreev (pp2);
        p = result;
        result = g_strdup_printf ("%s    \"CPU_Model\": \"%s\"", p, model_name);
        g_free (p);

        if (!g_spawn_command_line_sync ("lscpu", &std_out, NULL, NULL, &err)) {
                GST_ERROR ("invoke lscpu failure: %s", err->message);
                g_free (result);
                result = g_strdup_printf ("{\n    \"result\": \"failure\",\n    \"reason\": \"%s\"\n}", err->message);
                g_error_free (err);
                return result;
        }
        pp1 = pp2 = g_strsplit (std_out, "\n", 0);
        while (*pp1 != NULL) {
                if (g_str_has_prefix (*pp1, "CPU(s)")) {
                        sscanf (*pp1, "CPU(s):%*[ ]%d", &count);
                        p = result;
                        result = g_strdup_printf ("%s,\n    \"CPU_Count\": %d", p, count);
                        g_free (p);

                } else if (g_str_has_prefix (*pp1, "Thread(s) per core")) {
                        sscanf (*pp1, "Thread(s) per core:%*[ ]%d", &count);
                        p = result;
                        result = g_strdup_printf ("%s,\n    \"Threads_per_Core\": %d", p, count);
                        g_free (p);

                } else if (g_str_has_prefix (*pp1, "Core(s) per socket")) {
                        sscanf (*pp1, "Core(s) per socket:%*[ ]%d", &count);
                        p = result;
                        result = g_strdup_printf ("%s,\n    \"Core_per_Socket\": %d", p, count);
                        g_free (p);

                } else if (g_str_has_prefix (*pp1, "Socket(s)")) {
                        sscanf (*pp1, "Socket(s):%*[ ]%d", &count);
                        p = result;
                        result = g_strdup_printf ("%s,\n    \"Sockets_Count\": %d", p, count);
                        g_free (p);

                } else if (g_str_has_prefix (*pp1, "CPU MHz")){
                        sscanf (*pp1, "CPU MHz:%*[ ]%d", &count);
                        p = result;
                        result = g_strdup_printf ("%s,\n    \"CPU_MHz\": %d", p, count);
                        g_free (p);
                }
                pp1++;
        }
        g_strfreev (pp2);
        g_free (std_out);

        p = result;
        result = g_strdup_printf ("%s\n}", p);
        g_free (p);

        return result;
}
开发者ID:csdanping,项目名称:gstreamill,代码行数:81,代码来源:httpmgmt.c

示例9: plugin_dlopen_module

static GModule *
plugin_dlopen_module(const gchar *module_name, const gchar *module_path)
{
  gchar *plugin_module_name = NULL;
  gchar **module_path_dirs, *p, *dot;
  GModule *mod;
  gint i;

  module_path_dirs = g_strsplit(module_path, G_SEARCHPATH_SEPARATOR_S, 0);
  i = 0;
  while (module_path_dirs && module_path_dirs[i])
    {
      plugin_module_name = g_module_build_path(module_path_dirs[i], module_name);
      if (is_file_regular(plugin_module_name))
        break;

      /* also check if a libtool archive exists (for example in the build directory) */
#ifndef _AIX
      dot = strrchr(plugin_module_name, '.');
      if (dot)
        {
          *dot = 0;
          p = g_strdup_printf("%s.la", plugin_module_name);
          g_free(plugin_module_name);
          plugin_module_name = p;
        }
      if (is_file_regular(plugin_module_name))
        break;

      /* On AIX the modules in .a files */
#else
      dot = strrchr(plugin_module_name, '.');
      if (dot)
        {
          *dot = 0;
          p = g_strdup_printf("%s.a", plugin_module_name);
          g_free(plugin_module_name);
          plugin_module_name = p;
        }
      if (is_file_regular(plugin_module_name))
        break;
#endif

      g_free(plugin_module_name);
      plugin_module_name = NULL;
      i++;
    }
  g_strfreev(module_path_dirs);
  if (!plugin_module_name)
    {
      msg_error("Plugin module not found in 'module-path'",
                evt_tag_str("module-path", module_path),
                evt_tag_str("module", module_name),
                NULL);
      return NULL;
    }
  msg_trace("Trying to open module",
            evt_tag_str("module", module_name),
            evt_tag_str("filename", plugin_module_name),
            NULL);

  mod = g_module_open(plugin_module_name, G_MODULE_BIND_LAZY);
  g_free(plugin_module_name);
  if (!mod)
    {
      msg_error("Error opening plugin module",
                evt_tag_str("module", module_name),
                evt_tag_str("error", g_module_error()),
                NULL);
      return NULL;
    }
  return mod;
}
开发者ID:algernon,项目名称:syslog-ng,代码行数:73,代码来源:plugin.c

示例10: init_host_kb

/**
 * @brief Inits or loads the knowledge base for a single host.
 *
 * Fills the knowledge base with host-specific login information for local
 * checks if defined.
 *
 * @param globals     Global preference arglist.
 * @param hostname    Name of the host.
 * @param new_kb[out] TRUE if the kb is new and shall be saved.
 *
 * @return A knowledge base.
 *
 * @see fill_host_kb_ssh_credentials
 */
static kb_t
init_host_kb (struct arglist *globals, char *hostname,
              struct arglist *hostinfos, gboolean * new_kb)
{
  kb_t kb, network_kb;
  (*new_kb) = FALSE;
  gchar *vhosts;
  struct kb_item *host_network_results = NULL;
  struct kb_item *result_iter;

  gchar *network_scan_status = (gchar *) arg_get_value (globals, "network_scan_status");
  if (network_scan_status != NULL)
    {
      if (g_ascii_strcasecmp (network_scan_status, "done") == 0)
        {
          gchar *hostname_pattern = g_strdup_printf ("%s/*", hostname);
          network_kb = save_kb_load_kb (globals, "network");
          host_network_results = kb_item_get_pattern (network_kb, hostname_pattern);
        }
      if (g_ascii_strcasecmp (network_scan_status, "busy") == 0)
        {
          arg_add_value (globals, "CURRENTLY_TESTED_HOST", ARG_STRING,
                         strlen ("network"), "network");
          save_kb_new (globals, "network");
          kb = kb_new ();
          (*new_kb) = TRUE;
          return kb;
        }
    }

  // Check if kb should be saved.
  if (save_kb (globals))
    {
      // Check if a saved kb exists and we shall restore it.
      if (save_kb_exists (hostname) != 0)
        {
          save_kb_backup (hostname);
          kb = save_kb_load_kb (globals, hostname);
        }
      else
        {
          // We shall not or cannot restore.
          save_kb_new (globals, hostname);
          kb = kb_new ();
          (*new_kb) = TRUE;
        }
 
      arg_add_value (globals, "CURRENTLY_TESTED_HOST", ARG_STRING,
                     strlen (hostname), hostname);
    }
  else                          /* save_kb(globals) */
    {
      kb = kb_new ();
    }

  /* Add local check (SSH)- related knowledge base items. */
  fill_host_kb_ssh_credentials (kb, globals, hostname);

  /* If vhosts is set, split it and put it in the KB. */
  vhosts = (gchar *)arg_get_value (hostinfos, "VHOSTS");
  if (vhosts)
    {
      gchar **vhosts_array = g_strsplit (vhosts, ",", 0);
      guint i = 0;
      while (vhosts_array[i] != NULL)
        {
          kb_item_add_str (kb, "hostinfos/vhosts", vhosts_array[i]);
          save_kb_write_str (globals, hostname, "hostinfos/vhosts", vhosts_array[i]);
          i++;
        }
      g_strfreev (vhosts_array);
    }

  result_iter = host_network_results;
  while (result_iter != NULL)
    {
      char *newname = strstr (result_iter->name, "/") + 1;
      if (result_iter->type == KB_TYPE_STR)
        {
          kb_item_add_str (kb, newname, result_iter->v.v_str);
          save_kb_write_str (globals, hostname, newname, result_iter->v.v_str);
        }
      else if (result_iter->type == KB_TYPE_INT)
        {
          kb_item_add_int (kb, newname, result_iter->v.v_int);
          save_kb_write_int (globals, hostname, newname, result_iter->v.v_int);
//.........这里部分代码省略.........
开发者ID:manfredgithub,项目名称:Openvas-Source,代码行数:101,代码来源:attack.c

示例11: _g_dbus_address_parse_entry

gboolean
_g_dbus_address_parse_entry (const gchar  *address_entry,
                             gchar       **out_transport_name,
                             GHashTable  **out_key_value_pairs,
                             GError      **error)
{
  gboolean ret;
  GHashTable *key_value_pairs;
  gchar *transport_name;
  gchar **kv_pairs;
  const gchar *s;
  guint n;

  ret = FALSE;
  kv_pairs = NULL;
  transport_name = NULL;
  key_value_pairs = NULL;

  s = strchr (address_entry, ':');
  if (s == NULL)
    {
      g_set_error (error,
                   G_IO_ERROR,
                   G_IO_ERROR_INVALID_ARGUMENT,
                   _("Address element `%s', does not contain a colon (:)"),
                   address_entry);
      goto out;
    }

  transport_name = g_strndup (address_entry, s - address_entry);
  key_value_pairs = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);

  kv_pairs = g_strsplit (s + 1, ",", 0);
  for (n = 0; kv_pairs != NULL && kv_pairs[n] != NULL; n++)
    {
      const gchar *kv_pair = kv_pairs[n];
      gchar *key;
      gchar *value;

      s = strchr (kv_pair, '=');
      if (s == NULL)
        {
          g_set_error (error,
                       G_IO_ERROR,
                       G_IO_ERROR_INVALID_ARGUMENT,
                       _("Key/Value pair %d, `%s', in address element `%s', does not contain an equal sign"),
                       n,
                       kv_pair,
                       address_entry);
          goto out;
        }

      /* TODO: actually validate that no illegal characters are present before and after then '=' sign */
      key = g_uri_unescape_segment (kv_pair, s, NULL);
      value = g_uri_unescape_segment (s + 1, kv_pair + strlen (kv_pair), NULL);
      g_hash_table_insert (key_value_pairs, key, value);
    }

  ret = TRUE;

out:
  g_strfreev (kv_pairs);
  if (ret)
    {
      if (out_transport_name != NULL)
        *out_transport_name = transport_name;
      else
        g_free (transport_name);
      if (out_key_value_pairs != NULL)
        *out_key_value_pairs = key_value_pairs;
      else if (key_value_pairs != NULL)
        g_hash_table_unref (key_value_pairs);
    }
  else
    {
      g_free (transport_name);
      if (key_value_pairs != NULL)
        g_hash_table_unref (key_value_pairs);
    }
  return ret;
}
开发者ID:nikolatesla,项目名称:BitchXMPP,代码行数:81,代码来源:gdbusaddress.c

示例12: on_glade_drop

static void
on_glade_drop (IAnjutaEditor* editor,
               IAnjutaIterable* iterator,
               const gchar* signal_data,
               PythonPlugin* lang_plugin)
{
	GSignalQuery query;
	GType type;
	guint id;
	
	const gchar* widget;
	const gchar* signal;
	const gchar* handler;
	const gchar* user_data;
	gboolean swapped;
	GList* names = NULL;
	GString* str = g_string_new (NULL);
	int i;
	IAnjutaIterable* start, * end;
	
	GStrv data = g_strsplit(signal_data, ":", 5);
	
	widget = data[0];
	signal = data[1];
	handler = data[2];
	user_data = data[3];
	swapped = g_str_equal (data[4], "1");
	
	type = g_type_from_name (widget);
	id = g_signal_lookup (signal, type);

	g_signal_query (id, &query);

	g_string_append_printf (str, "\ndef %s (self", handler);
	for (i = 0; i < query.n_params; i++)
	{
		const gchar* type_name = g_type_name (query.param_types[i]);
		const gchar* param_name = language_support_get_signal_parameter (type_name,
		                                                                 &names);

		g_string_append_printf (str, ", %s", param_name);
	}
	g_string_append (str, "):\n");

	ianjuta_editor_insert (editor, iterator,
	                       str->str, -1, NULL);

	/* Indent code correctly */
	start = iterator;
	end = ianjuta_iterable_clone (iterator, NULL);
	ianjuta_iterable_set_position (end, 
	                               ianjuta_iterable_get_position (iterator, NULL)
	                           		+ g_utf8_strlen (str->str, -1),
	                               NULL);
	ianjuta_indenter_indent (IANJUTA_INDENTER (lang_plugin),
	                         start, end, NULL);
	g_object_unref (end);

	g_string_free (str, TRUE);
	anjuta_util_glist_strings_free (names);
	
	g_strfreev (data);
}
开发者ID:rosedu,项目名称:anjuta,代码行数:63,代码来源:plugin.c

示例13: register_pds

/* Register the given PDs for this session.
 * Accepts a string of the form: "spi:sck=3:sdata=4,spi:sck=3:sdata=5"
 * That will instantiate two SPI decoders on the clock but different data
 * lines.
 */
static int register_pds(struct sr_dev *dev, const char *pdstring)
{
	GHashTable *pd_opthash;
	struct srd_decoder_inst *di;
	int ret;
	char **pdtokens, **pdtok, *pd_name;

	/* Avoid compiler warnings. */
	(void)dev;

	ret = 0;
	pd_ann_visible = g_hash_table_new_full(g_str_hash, g_int_equal,
			g_free, NULL);
	pd_name = NULL;
	pd_opthash = NULL;
	pdtokens = g_strsplit(pdstring, ",", 0);
	for (pdtok = pdtokens; *pdtok; pdtok++) {
		if (!(pd_opthash = parse_generic_arg(*pdtok))) {
			g_critical("Invalid protocol decoder option '%s'.", *pdtok);
			goto err_out;
		}

		pd_name = g_strdup(g_hash_table_lookup(pd_opthash, "sigrok_key"));
		g_hash_table_remove(pd_opthash, "sigrok_key");
		if (srd_decoder_load(pd_name) != SRD_OK) {
			g_critical("Failed to load protocol decoder %s.", pd_name);
			ret = 1;
			goto err_out;
		}
		if (!(di = srd_inst_new(pd_name, pd_opthash))) {
			g_critical("Failed to instantiate protocol decoder %s.", pd_name);
			ret = 1;
			goto err_out;
		}

		/* If no annotation list was specified, add them all in now.
		 * This will be pared down later to leave only the last PD
		 * in the stack.
		 */
		if (!opt_pd_annotations)
			g_hash_table_insert(pd_ann_visible,
					    g_strdup(di->inst_id), NULL);

		/* Any keys left in the options hash are probes, where the key
		 * is the probe name as specified in the decoder class, and the
		 * value is the probe number i.e. the order in which the PD's
		 * incoming samples are arranged. */
		if (srd_inst_probe_set_all(di, pd_opthash) != SRD_OK) {
			ret = 1;
			goto err_out;
		}
		g_hash_table_destroy(pd_opthash);
		pd_opthash = NULL;
	}

err_out:
	g_strfreev(pdtokens);
	if (pd_opthash)
		g_hash_table_destroy(pd_opthash);
	if (pd_name)
		g_free(pd_name);

	return ret;
}
开发者ID:jeras,项目名称:sigrok,代码行数:69,代码来源:sigrok-cli.c

示例14: ip4_options_to_config

/* Given a table of DHCP options from the client, convert into an IP4Config */
static NMIP4Config *
ip4_options_to_config (NMDHCPClient *self)
{
	NMDHCPClientPrivate *priv;
	NMIP4Config *ip4_config = NULL;
	struct in_addr tmp_addr;
	NMIP4Address *addr = NULL;
	char *str = NULL;
	guint32 gwaddr = 0, prefix = 0;

	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (NM_IS_DHCP_CLIENT (self), NULL);

	priv = NM_DHCP_CLIENT_GET_PRIVATE (self);
	g_return_val_if_fail (priv->options != NULL, NULL);

	ip4_config = nm_ip4_config_new ();
	if (!ip4_config) {
		nm_log_warn (LOGD_DHCP4, "(%s): couldn't allocate memory for an IP4Config!", priv->iface);
		return NULL;
	}

	addr = nm_ip4_address_new ();
	if (!addr) {
		nm_log_warn (LOGD_DHCP4, "(%s): couldn't allocate memory for an IP4 Address!", priv->iface);
		goto error;
	}

	str = g_hash_table_lookup (priv->options, "new_ip_address");
	if (str && (inet_pton (AF_INET, str, &tmp_addr) > 0)) {
		nm_ip4_address_set_address (addr, tmp_addr.s_addr);
		nm_log_info (LOGD_DHCP4, "  address %s", str);
	} else
		goto error;

	str = g_hash_table_lookup (priv->options, "new_subnet_mask");
	if (str && (inet_pton (AF_INET, str, &tmp_addr) > 0)) {
		prefix = nm_utils_ip4_netmask_to_prefix (tmp_addr.s_addr);
		nm_log_info (LOGD_DHCP4, "  prefix %d (%s)", prefix, str);
	} else {
		/* Get default netmask for the IP according to appropriate class. */
		prefix = nm_utils_ip4_get_default_prefix (nm_ip4_address_get_address (addr));
		nm_log_info (LOGD_DHCP4, "  prefix %d (default)", prefix);
	}
	nm_ip4_address_set_prefix (addr, prefix);

	/* Routes: if the server returns classless static routes, we MUST ignore
	 * the 'static_routes' option.
	 */
	if (!ip4_process_classless_routes (priv->options, ip4_config, &gwaddr))
		process_classful_routes (priv->options, ip4_config);

	if (gwaddr) {
		char buf[INET_ADDRSTRLEN + 1];

		inet_ntop (AF_INET, &gwaddr, buf, sizeof (buf));
		nm_log_info (LOGD_DHCP4, "  gateway %s", buf);
		nm_ip4_address_set_gateway (addr, gwaddr);
	} else {
		/* If the gateway wasn't provided as a classless static route with a
		 * subnet length of 0, try to find it using the old-style 'routers' option.
		 */
		str = g_hash_table_lookup (priv->options, "new_routers");
		if (str) {
			char **routers = g_strsplit (str, " ", 0);
			char **s;

			for (s = routers; *s; s++) {
				/* FIXME: how to handle multiple routers? */
				if (inet_pton (AF_INET, *s, &tmp_addr) > 0) {
					nm_ip4_address_set_gateway (addr, tmp_addr.s_addr);
					nm_log_info (LOGD_DHCP4, "  gateway %s", *s);
					break;
				} else
					nm_log_warn (LOGD_DHCP4, "ignoring invalid gateway '%s'", *s);
			}
			g_strfreev (routers);
		}
	}

	nm_ip4_config_take_address (ip4_config, addr);
	addr = NULL;

	str = g_hash_table_lookup (priv->options, "new_host_name");
	if (str)
		nm_log_info (LOGD_DHCP4, "  hostname '%s'", str);

	str = g_hash_table_lookup (priv->options, "new_domain_name_servers");
	if (str) {
		char **searches = g_strsplit (str, " ", 0);
		char **s;

		for (s = searches; *s; s++) {
			if (inet_pton (AF_INET, *s, &tmp_addr) > 0) {
				nm_ip4_config_add_nameserver (ip4_config, tmp_addr.s_addr);
				nm_log_info (LOGD_DHCP4, "  nameserver '%s'", *s);
			} else
				nm_log_warn (LOGD_DHCP4, "ignoring invalid nameserver '%s'", *s);
		}
//.........这里部分代码省略.........
开发者ID:eugeni,项目名称:NetworkManager-mdv,代码行数:101,代码来源:nm-dhcp-client.c

示例15: ltable_insert

static void
ltable_insert(LTable* lt, const gchar* where, Listener* l)
{
  gchar** dirnames;
  guint i;
  GNode* cur;
  GNode* found = NULL;
  LTableEntry* lte;
  const gchar* noroot_where = where + 1;

  g_return_if_fail(mateconf_valid_key(where, NULL));
  
  if (lt->tree == NULL)
    {
      lte = ltable_entry_new(NULL, 0);
      
      lt->tree = g_node_new(lte);

      lte = NULL; /* paranoia */
    }
  
  /* Add to the tree */
  dirnames = g_strsplit(noroot_where, "/", -1);
  
  cur = lt->tree;
  i = 0;
  while (dirnames[i])
    {
      LTableEntry* ne;
      GNode* across;

      /* Find this dirname on this level, or add it. */
      g_assert (cur != NULL);        

      found = NULL;

      across = cur->children;

      while (across != NULL)
        {
          int cmp;

          lte = across->data;

          cmp = strcmp(lte->name, dirnames[i]);

          if (cmp == 0)
            {
              found = across;
              break;
            }
          else if (cmp > 0)
            {
              /* Past it */
              break;
            }
          else 
            {
              across = g_node_next_sibling(across);
            }
        }

      if (found == NULL)
        {
          ne = ltable_entry_new(dirnames, i);
              
          if (across != NULL) /* Across is at the one past */
            found = g_node_insert_data_before(cur, across, ne);
          else                /* Never went past, append - could speed this up by saving last visited */
            found = g_node_append_data(cur, ne);
        }

      g_assert(found != NULL);

      cur = found;

      ++i;
    }

  /* cur is still the root node ("/") if where was "/" since nothing
     was returned from g_strsplit */
  lte = cur->data;

  lte->listeners = g_list_prepend(lte->listeners, l);

  g_strfreev(dirnames);

  /* Add tree node to the flat table */
  g_ptr_array_set_size(lt->listeners, MAX(CNXN_ID_INDEX(lt->next_cnxn), CNXN_ID_INDEX(l->cnxn)));
  g_ptr_array_index(lt->listeners, CNXN_ID_INDEX(l->cnxn)) = cur;

  lt->active_listeners += 1;

#ifdef DEBUG_LISTENERS
  g_print ("Added %u at %s, spewing:\n",
	   l->cnxn, where);
  ltable_spew(lt);
#endif
}
开发者ID:fatman2021,项目名称:Mate-Extra,代码行数:99,代码来源:mateconf-listeners.c


注:本文中的g_strsplit函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。