コード例 #1
0
/**
 * wpas_dbus_global_add_interface - Request registration of a network interface
 * @message: Pointer to incoming dbus message
 * @global: %wpa_supplicant global data structure
 * Returns: The object path of the new interface object,
 *          or a dbus error message with more information
 *
 * Handler function for "addInterface" method call. Handles requests
 * by dbus clients to register a network interface that wpa_supplicant
 * will manage.
 */
DBusMessage * wpas_dbus_global_add_interface(DBusMessage *message,
					     struct wpa_global *global)
{
	char *ifname = NULL;
	char *driver = NULL;
	char *driver_param = NULL;
	char *confname = NULL;
	char *bridge_ifname = NULL;
	DBusMessage *reply = NULL;
	DBusMessageIter iter;

	dbus_message_iter_init(message, &iter);

	/* First argument: interface name (DBUS_TYPE_STRING)
	 *    Required; must be non-zero length
	 */
	if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING)
		goto error;
	dbus_message_iter_get_basic(&iter, &ifname);
	if (!os_strlen(ifname))
		goto error;

	/* Second argument: dict of options */
	if (dbus_message_iter_next(&iter)) {
		DBusMessageIter iter_dict;
		struct wpa_dbus_dict_entry entry;

		if (!wpa_dbus_dict_open_read(&iter, &iter_dict))
			goto error;
		while (wpa_dbus_dict_has_dict_entry(&iter_dict)) {
			if (!wpa_dbus_dict_get_entry(&iter_dict, &entry))
				goto error;
			if (!strcmp(entry.key, "driver") &&
			    (entry.type == DBUS_TYPE_STRING)) {
				driver = os_strdup(entry.str_value);
				wpa_dbus_dict_entry_clear(&entry);
				if (driver == NULL)
					goto error;
			} else if (!strcmp(entry.key, "driver-params") &&
				   (entry.type == DBUS_TYPE_STRING)) {
				driver_param = os_strdup(entry.str_value);
				wpa_dbus_dict_entry_clear(&entry);
				if (driver_param == NULL)
					goto error;
			} else if (!strcmp(entry.key, "config-file") &&
				   (entry.type == DBUS_TYPE_STRING)) {
				confname = os_strdup(entry.str_value);
				wpa_dbus_dict_entry_clear(&entry);
				if (confname == NULL)
					goto error;
			} else if (!strcmp(entry.key, "bridge-ifname") &&
				   (entry.type == DBUS_TYPE_STRING)) {
				bridge_ifname = os_strdup(entry.str_value);
				wpa_dbus_dict_entry_clear(&entry);
				if (bridge_ifname == NULL)
					goto error;
			} else {
				wpa_dbus_dict_entry_clear(&entry);
				goto error;
			}
		}
	}

	/*
	 * Try to get the wpa_supplicant record for this iface, return
	 * an error if we already control it.
	 */
	if (wpa_supplicant_get_iface(global, ifname) != NULL) {
		reply = dbus_message_new_error(message,
					       WPAS_ERROR_EXISTS_ERROR,
					       "wpa_supplicant already "
					       "controls this interface.");
	} else {
		struct wpa_supplicant *wpa_s;
		struct wpa_interface iface;
		os_memset(&iface, 0, sizeof(iface));
		iface.ifname = ifname;
		iface.driver = driver;
		iface.driver_param = driver_param;
		iface.confname = confname;
		iface.bridge_ifname = bridge_ifname;
		/* Otherwise, have wpa_supplicant attach to it. */
		if ((wpa_s = wpa_supplicant_add_iface(global, &iface))) {
			const char *path = wpa_s->dbus_path;
			reply = dbus_message_new_method_return(message);
			dbus_message_append_args(reply, DBUS_TYPE_OBJECT_PATH,
			                         &path, DBUS_TYPE_INVALID);
		} else {
			reply = dbus_message_new_error(message,
						       WPAS_ERROR_ADD_ERROR,
						       "wpa_supplicant "
						       "couldn't grab this "
						       "interface.");
		}
	}

out:
	os_free(driver);
	os_free(driver_param);
	os_free(confname);
	os_free(bridge_ifname);
	return reply;

error:
	reply = wpas_dbus_new_invalid_opts_error(message, NULL);
	goto out;
}
コード例 #2
0
ファイル: radio-settings.c プロジェクト: jkangas/ofono-1
static DBusMessage *radio_set_property(DBusConnection *conn, DBusMessage *msg,
					void *data)
{
	struct ofono_radio_settings *rs = data;
	DBusMessageIter iter;
	DBusMessageIter var;
	const char *property;

	if (rs->pending)
		return __ofono_error_busy(msg);

	if (!dbus_message_iter_init(msg, &iter))
		return __ofono_error_invalid_args(msg);

	if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING)
		return __ofono_error_invalid_args(msg);

	dbus_message_iter_get_basic(&iter, &property);
	dbus_message_iter_next(&iter);

	if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_VARIANT)
		return __ofono_error_invalid_args(msg);

	dbus_message_iter_recurse(&iter, &var);

	if (g_strcmp0(property, "TechnologyPreference") == 0) {
		const char *value;
		enum ofono_radio_access_mode mode;

		if (rs->driver->set_rat_mode == NULL)
			return __ofono_error_not_implemented(msg);

		if (dbus_message_iter_get_arg_type(&var) != DBUS_TYPE_STRING)
			return __ofono_error_invalid_args(msg);

		dbus_message_iter_get_basic(&var, &value);
		if (radio_access_mode_from_string(value, &mode) == FALSE)
			return __ofono_error_invalid_args(msg);

		if (rs->mode == mode)
			return dbus_message_new_method_return(msg);

		rs->pending = dbus_message_ref(msg);
		rs->pending_mode = mode;

		rs->driver->set_rat_mode(rs, mode, radio_mode_set_callback, rs);

		return NULL;
	} else if (g_strcmp0(property, "GsmBand") == 0) {
		const char *value;
		enum ofono_radio_band_gsm band;

		if (rs->driver->set_band == NULL)
			return __ofono_error_not_implemented(msg);

		if (dbus_message_iter_get_arg_type(&var) != DBUS_TYPE_STRING)
			return __ofono_error_invalid_args(msg);

		dbus_message_iter_get_basic(&var, &value);
		if (radio_band_gsm_from_string(value, &band) == FALSE)
			return __ofono_error_invalid_args(msg);

		if (rs->band_gsm == band)
			return dbus_message_new_method_return(msg);

		rs->pending = dbus_message_ref(msg);
		rs->pending_band_gsm = band;

		rs->driver->set_band(rs, band, rs->band_umts,
					radio_band_set_callback, rs);

		return NULL;
	} else if (g_strcmp0(property, "UmtsBand") == 0) {
		const char *value;
		enum ofono_radio_band_umts band;

		if (rs->driver->set_band == NULL)
			return __ofono_error_not_implemented(msg);

		if (dbus_message_iter_get_arg_type(&var) != DBUS_TYPE_STRING)
			return __ofono_error_invalid_args(msg);

		dbus_message_iter_get_basic(&var, &value);
		if (radio_band_umts_from_string(value, &band) == FALSE)
			return __ofono_error_invalid_args(msg);

		if (rs->band_umts == band)
			return dbus_message_new_method_return(msg);

		rs->pending = dbus_message_ref(msg);
		rs->pending_band_umts = band;

		rs->driver->set_band(rs, rs->band_gsm, band,
					radio_band_set_callback, rs);

		return NULL;
	} else if (g_strcmp0(property, "FastDormancy") == 0) {
		dbus_bool_t value;
		int target;

		if (rs->driver->set_fast_dormancy == NULL)
			return __ofono_error_not_implemented(msg);

		if (dbus_message_iter_get_arg_type(&var) != DBUS_TYPE_BOOLEAN)
			return __ofono_error_invalid_args(msg);

		dbus_message_iter_get_basic(&var, &value);
		target = value;

		if (rs->fast_dormancy_pending == target)
			return dbus_message_new_method_return(msg);

		rs->pending = dbus_message_ref(msg);
		rs->fast_dormancy_pending = target;

		rs->driver->set_fast_dormancy(rs, target,
					radio_fast_dormancy_set_callback, rs);
		return NULL;
	}

	return __ofono_error_invalid_args(msg);
}
コード例 #3
0
static DBusHandlerResult
on_prompt_signal (DBusConnection *connection, DBusMessage *message, void *user_data)
{
	on_prompt_args *args = user_data;
	DBusMessageIter iter;
	dbus_bool_t dismissed;
	GkrOperation *op;
	const char *object_name;
	const char *new_owner;
	const char *old_owner;

	g_assert (args);

	if (!args->path || !args->op->prompting)
		return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;

	/* org.freedesktop.Secret.Prompt.Completed(BOOLEAN dismissed, VARIANT result) */
	if (dbus_message_has_path (message, args->path) &&
	    dbus_message_is_signal (message, PROMPT_INTERFACE, "Completed")) {

		/* Only one call, even if daemon decides to be strange */
		g_free (args->path);
		args->path = NULL;

		if (!dbus_message_iter_init (message, &iter) ||
		    dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_BOOLEAN)
			g_return_val_if_reached (BROKEN);
		dbus_message_iter_get_basic (&iter, &dismissed);

		op = gkr_operation_ref (args->op);

		if (dismissed)
			gkr_operation_complete (op, MATE_KEYRING_RESULT_CANCELLED);
		else
			callback_with_message (op, message);

		if (op->prompting)
			dbus_connection_remove_filter (args->op->conn, on_prompt_signal, args);
		gkr_operation_unref (op);

		return DBUS_HANDLER_RESULT_HANDLED;
	}

	/* org.freedesktop.DBus.NameOwnerChanged(STRING name, STRING old_owner, STRING new_owner) */
	if (dbus_message_is_signal (message, DBUS_INTERFACE_DBUS, "NameOwnerChanged") &&
	    dbus_message_get_args (message, NULL, DBUS_TYPE_STRING, &object_name,
	                           DBUS_TYPE_STRING, &old_owner, DBUS_TYPE_STRING, &new_owner,
	                           DBUS_TYPE_INVALID)) {

		/* See if it's the secret service going away */
		if (object_name && g_str_equal (gkr_service_name (), object_name) &&
		    new_owner && g_str_equal ("", new_owner)) {

			g_message ("Secret service disappeared while waiting for prompt");
			op = gkr_operation_ref (args->op);
			gkr_operation_complete (op, MATE_KEYRING_RESULT_IO_ERROR);
			if (op->prompting)
				dbus_connection_remove_filter (args->op->conn, on_prompt_signal, args);
			gkr_operation_unref (op);
		}

		return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
	}

	return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
}
コード例 #4
0
ファイル: qmi.c プロジェクト: roland-wilhelm/connman
/**
* @brief Signal handler for technology changed signal from qmi-dbus
*/
static gboolean
on_handle_technology_changed(DBusConnection *conn, DBusMessage *message, gpointer unused) {

	DBusMessageIter message_iter;
	GHashTableIter hash_iter;
	gpointer key, value;
	struct qmi_data *qmi = NULL;
	/* Get object path of this message */
	const gchar *object_path = dbus_message_get_path(message);;

	DBG("Object path %s", object_path);

	if(dbus_message_get_type(message) == DBUS_MESSAGE_TYPE_ERROR) {

		const char *dbus_error = dbus_message_get_error_name(message);

		connman_error("%s", dbus_error);
		return FALSE;

	}

	if(dbus_message_iter_init(message, &message_iter) == FALSE) {

		connman_error("Failure init ITER");

		return FALSE;
	}

	if(dbus_message_iter_get_arg_type(&message_iter) == DBUS_TYPE_INVALID) {

		connman_error("Invalid D-Bus type");

		return FALSE;
	}

	if(object_path) {
		/* Find qmi device data to object path */
		g_hash_table_iter_init (&hash_iter, qmi_hash);
		while (g_hash_table_iter_next (&hash_iter, &key, &value)) {

			qmi = (struct qmi_data *)value;

			if(g_strcmp0(object_path, qmi->object_path) == 0) {

				break;
			}
			else {

				qmi = NULL;
			}
		}
	}

	if(qmi == NULL) {

		connman_error("No qmi device to object path %s", object_path);

		return FALSE;
	}

	/* Update new property value */
	update_network(qmi, &message_iter);

	return TRUE;
}
コード例 #5
0
ファイル: receiver.c プロジェクト: xifeiwu/workcode
void listen_signal()
{
    DBusMessage * msg;
    DBusMessageIter arg;
    DBusConnection * connection;
    DBusError err;
    int ret;
    char * sigvalue;

     //步骤1:建立与D-Bus后台的连接 
    dbus_error_init(&err);
    connection = dbus_bus_get(DBUS_BUS_SESSION, &err);
    if(dbus_error_is_set(&err)){
        fprintf(stderr,"Connection Error %s/n",err.message);
        dbus_error_free(&err);
    }
    if(connection == NULL){
        printf("connection is NULL.\n");
        return;
    }

   //步骤2:给连接名分配一个可记忆名字test.singal.dest作为Bus name,这个步骤不是必须的,但推荐这样处理 
/*
    ret = dbus_bus_request_name(connection,"test.singal.dest",DBUS_NAME_FLAG_REPLACE_EXISTING,&err);
    if(dbus_error_is_set(&err)){
        fprintf(stderr,"Name Error %s/n",err.message);
        dbus_error_free(&err);
    }
    if(ret != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER){
        printf("dbus request name is not primary owner.\n");
        return;
    }
*/
    //步骤3:通知D-Bus daemon,希望监听来行接口test.signal.Type的信号 
    dbus_bus_add_match(connection,"type='signal',interface='test.signal.Type'",&err); 
    //实际需要发送东西给daemon来通知希望监听的内容,所以需要flush 
    dbus_connection_flush(connection); 
    if(dbus_error_is_set(&err)){
        fprintf(stderr,"Match Error %s/n",err.message);
        dbus_error_free(&err);
    }
    
    //步骤4:在循环中监听,每隔开1秒,就去试图自己的连接中获取这个信号。这里给出的是中连接中获取任何消息的方式,所以获取后去检查一下这个消息是否我们期望的信号,并获取内容。我们也可以通过这个方式来获取method call消息。 
    gint cnt = 0;
    while(1){
        dbus_connection_read_write(connection,0); 
        msg = dbus_connection_pop_message (connection);
        if(msg == NULL){
            sleep(1);
            //printf("cnt:%d\n", cnt++);
            continue;
        }
    printf("message type: %d\n", dbus_message_get_type(msg));
    printf("message member: %s\n", dbus_message_get_member(msg));

        if(dbus_message_is_signal(msg,"test.signal.Type","Test") ){
            if(!dbus_message_iter_init(msg,&arg) )
                fprintf(stderr,"Message Has no Param");
            else if(dbus_message_iter_get_arg_type(&arg) != DBUS_TYPE_STRING) 
                g_printerr("Param is not string");
            else
                dbus_message_iter_get_basic(&arg,&sigvalue); 
            printf("Got Singal with value : %s\n",sigvalue);
        }
        dbus_message_unref(msg);
    }//End of while
    printf("end of receiver.");
}
コード例 #6
0
ファイル: dbus.c プロジェクト: NieHao/wl500g
static DBusMessage* dbus_read_servers_ex(DBusMessage *message, int strings)
{
  DBusMessageIter iter, array_iter, string_iter;
  DBusMessage *error = NULL;
  const char *addr_err;
  char *dup = NULL;
  
  if (!dbus_message_iter_init(message, &iter))
    {
      return dbus_message_new_error(message, DBUS_ERROR_INVALID_ARGS,
                                    "Failed to initialize dbus message iter");
    }

  /* check that the message contains an array of arrays */
  if ((dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_ARRAY) ||
      (dbus_message_iter_get_element_type(&iter) != (strings ? DBUS_TYPE_STRING : DBUS_TYPE_ARRAY)))
    {
      return dbus_message_new_error(message, DBUS_ERROR_INVALID_ARGS,
                                    strings ? "Expected array of string" : "Expected array of string arrays");
     }
 
  mark_servers(SERV_FROM_DBUS);

  /* array_iter points to each "as" element in the outer array */
  dbus_message_iter_recurse(&iter, &array_iter);
  while (dbus_message_iter_get_arg_type(&array_iter) != DBUS_TYPE_INVALID)
    {
      const char *str = NULL;
      union  mysockaddr addr, source_addr;
      int flags = 0;
      char interface[IF_NAMESIZE];
      char *str_addr, *str_domain = NULL;

      if (strings)
	{
	  dbus_message_iter_get_basic(&array_iter, &str);
	  if (!str || !strlen (str))
	    {
	      error = dbus_message_new_error(message, DBUS_ERROR_INVALID_ARGS,
					     "Empty string");
	      break;
	    }
	  
	  /* dup the string because it gets modified during parsing */
	  if (dup)
	    free(dup);
	  if (!(dup = str_domain = whine_malloc(strlen(str)+1)))
	    break;
	  
	  strcpy(str_domain, str);

	  /* point to address part of old string for error message */
	  if ((str_addr = strrchr(str, '/')))
	    str = str_addr+1;
	  
	  if ((str_addr = strrchr(str_domain, '/')))
	    {
	      if (*str_domain != '/' || str_addr == str_domain)
		{
		  error = dbus_message_new_error_printf(message,
							DBUS_ERROR_INVALID_ARGS,
							"No domain terminator '%s'",
							str);
		  break;
		}
	      *str_addr++ = 0;
	      str_domain++;
	    }
	  else
	    {
	      str_addr = str_domain;
	      str_domain = NULL;
	    }

	  
	}
      else
	{
	  /* check the types of the struct and its elements */
	  if ((dbus_message_iter_get_arg_type(&array_iter) != DBUS_TYPE_ARRAY) ||
	      (dbus_message_iter_get_element_type(&array_iter) != DBUS_TYPE_STRING))
	    {
	      error = dbus_message_new_error(message, DBUS_ERROR_INVALID_ARGS,
					     "Expected inner array of strings");
	      break;
	    }
	  
	  /* string_iter points to each "s" element in the inner array */
	  dbus_message_iter_recurse(&array_iter, &string_iter);
	  if (dbus_message_iter_get_arg_type(&string_iter) != DBUS_TYPE_STRING)
	    {
	      /* no IP address given */
	      error = dbus_message_new_error(message, DBUS_ERROR_INVALID_ARGS,
					     "Expected IP address");
	      break;
	    }
	  
	  dbus_message_iter_get_basic(&string_iter, &str);
	  if (!str || !strlen (str))
	    {
	      error = dbus_message_new_error(message, DBUS_ERROR_INVALID_ARGS,
					     "Empty IP address");
	      break;
	    }
	  
	  /* dup the string because it gets modified during parsing */
	  if (dup)
	    free(dup);
	  if (!(dup = str_addr = whine_malloc(strlen(str)+1)))
	    break;
	  
	  strcpy(str_addr, str);
	}

      memset(&addr, 0, sizeof(addr));
      memset(&source_addr, 0, sizeof(source_addr));
      memset(&interface, 0, sizeof(interface));

      /* parse the IP address */
      if ((addr_err = parse_server(str_addr, &addr, &source_addr, (char *) &interface, &flags)))
	{
          error = dbus_message_new_error_printf(message, DBUS_ERROR_INVALID_ARGS,
                                                "Invalid IP address '%s': %s",
                                                str, addr_err);
          break;
        }
      
      /* 0.0.0.0 for server address == NULL, for Dbus */
      if (addr.in.sin_family == AF_INET &&
          addr.in.sin_addr.s_addr == 0)
        flags |= SERV_NO_ADDR;
      
      if (strings)
	{
	  char *p;
	  
	  do {
	    if (str_domain)
	      {
		if ((p = strchr(str_domain, '/')))
		  *p++ = 0;
	      }
	    else 
	      p = NULL;
	    
	    add_update_server(flags | SERV_FROM_DBUS, &addr, &source_addr, interface, str_domain);
	  } while ((str_domain = p));
	}
      else
	{
	  /* jump past the address to the domain list (if any) */
	  dbus_message_iter_next (&string_iter);
	  
	  /* parse domains and add each server/domain pair to the list */
	  do {
	    str = NULL;
	    if (dbus_message_iter_get_arg_type(&string_iter) == DBUS_TYPE_STRING)
	      dbus_message_iter_get_basic(&string_iter, &str);
	    dbus_message_iter_next (&string_iter);
	    
	    add_update_server(flags | SERV_FROM_DBUS, &addr, &source_addr, interface, str);
	  } while (dbus_message_iter_get_arg_type(&string_iter) == DBUS_TYPE_STRING);
	}
	 
      /* jump to next element in outer array */
      dbus_message_iter_next(&array_iter);
    }

  cleanup_servers();

  if (dup)
    free(dup);

  return error;
}
コード例 #7
0
ファイル: inhibit.c プロジェクト: adsr/systemd
static int print_inhibitors(DBusConnection *bus, DBusError *error) {
        DBusMessage *m, *reply;
        unsigned n = 0;
        DBusMessageIter iter, sub, sub2;
        int r;

        assert(bus);

        m = dbus_message_new_method_call(
                        "org.freedesktop.login1",
                        "/org/freedesktop/login1",
                        "org.freedesktop.login1.Manager",
                        "ListInhibitors");
        if (!m)
                return -ENOMEM;

        reply = dbus_connection_send_with_reply_and_block(bus, m, -1, error);
        if (!reply) {
                r = -EIO;
                goto finish;
        }

        if (!dbus_message_iter_init(reply, &iter)) {
                r = -ENOMEM;
                goto finish;
        }

        if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_ARRAY) {
                r = -EIO;
                goto finish;
        }
        dbus_message_iter_recurse(&iter, &sub);

        printf("%-21s %-20s %-20s %-5s %6s %6s\n",
               "WHAT",
               "WHO",
               "WHY",
               "MODE",
               "UID",
               "PID");


        while (dbus_message_iter_get_arg_type(&sub) != DBUS_TYPE_INVALID) {
                const char *what, *who, *why, *mode;
                char *ewho, *ewhy;
                dbus_uint32_t uid, pid;

                if (dbus_message_iter_get_arg_type(&sub) != DBUS_TYPE_STRUCT) {
                        r = -EIO;
                        goto finish;
                }

                dbus_message_iter_recurse(&sub, &sub2);

                if (bus_iter_get_basic_and_next(&sub2, DBUS_TYPE_STRING, &what, true) < 0 ||
                    bus_iter_get_basic_and_next(&sub2, DBUS_TYPE_STRING, &who, true) < 0 ||
                    bus_iter_get_basic_and_next(&sub2, DBUS_TYPE_STRING, &why, true) < 0 ||
                    bus_iter_get_basic_and_next(&sub2, DBUS_TYPE_STRING, &mode, true) < 0 ||
                    bus_iter_get_basic_and_next(&sub2, DBUS_TYPE_UINT32, &uid, true) < 0 ||
                    bus_iter_get_basic_and_next(&sub2, DBUS_TYPE_UINT32, &pid, false) < 0) {
                        r = -EIO;
                        goto finish;
                }

                ewho = ellipsize(who, 20, 66);
                ewhy = ellipsize(why, 20, 66);

                printf("%-21s %-20s %-20s %-5s %6lu %6lu\n",
                       what, ewho ? ewho : who, ewhy ? ewhy : why, mode, (unsigned long) uid, (unsigned long) pid);

                free(ewho);
                free(ewhy);

                dbus_message_iter_next(&sub);

                n++;
        }

        printf("\n%u inhibitors listed.\n", n);
        r = 0;

finish:
        if (m)
                dbus_message_unref(m);

        if (reply)
                dbus_message_unref(reply);

        return r;
}
コード例 #8
0
ファイル: call-volume.c プロジェクト: Conjuror/ofono
static DBusMessage *cv_set_property(DBusConnection *conn, DBusMessage *msg,
					void *data)
{
	struct ofono_call_volume *cv = data;
	DBusMessageIter iter;
	DBusMessageIter var;
	const char *property;

	if (cv->pending)
		return __ofono_error_busy(msg);

	if (!dbus_message_iter_init(msg, &iter))
		return __ofono_error_invalid_args(msg);

	if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING)
		return __ofono_error_invalid_args(msg);

	dbus_message_iter_get_basic(&iter, &property);
	dbus_message_iter_next(&iter);

	if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_VARIANT)
		return __ofono_error_invalid_args(msg);

	dbus_message_iter_recurse(&iter, &var);

	if (g_str_equal(property, "SpeakerVolume") == TRUE) {
		unsigned char percent;

		if (cv->driver->speaker_volume == NULL)
			return __ofono_error_not_implemented(msg);

		if (dbus_message_iter_get_arg_type(&var) != DBUS_TYPE_BYTE)
			return __ofono_error_invalid_args(msg);

		dbus_message_iter_get_basic(&var, &percent);

		if (percent > 100)
			return __ofono_error_invalid_format(msg);

		if (percent == cv->speaker_volume)
			return dbus_message_new_method_return(msg);

		cv->pending_volume = percent;
		cv->pending = dbus_message_ref(msg);
		cv->driver->speaker_volume(cv, percent, sv_set_callback, cv);

		return NULL;
	} else if (g_str_equal(property, "MicrophoneVolume") == TRUE) {
		unsigned char percent;

		if (cv->driver->microphone_volume == NULL)
			return __ofono_error_not_implemented(msg);

		if (dbus_message_iter_get_arg_type(&var) != DBUS_TYPE_BYTE)
			return __ofono_error_invalid_args(msg);

		dbus_message_iter_get_basic(&var, &percent);

		if (percent > 100)
			return __ofono_error_invalid_format(msg);

		if (percent == cv->microphone_volume)
			return dbus_message_new_method_return(msg);

		cv->pending_volume = percent;
		cv->pending = dbus_message_ref(msg);
		cv->driver->microphone_volume(cv, percent, mv_set_callback, cv);

		return NULL;
	} else if (g_str_equal(property, "Muted") == TRUE) {
		dbus_bool_t muted;

		if (cv->driver->mute == NULL)
			return __ofono_error_not_implemented(msg);

		if (dbus_message_iter_get_arg_type(&var) != DBUS_TYPE_BOOLEAN)
			return __ofono_error_invalid_args(msg);

		dbus_message_iter_get_basic(&var, &muted);

		if (muted == (dbus_bool_t) cv->muted)
			return dbus_message_new_method_return(msg);

		cv->muted_pending = muted;
		cv->pending = dbus_message_ref(msg);
		cv->driver->mute(cv, muted, muted_set_callback, cv);

		return NULL;
	}

	return __ofono_error_invalid_args(msg);
}
コード例 #9
0
ファイル: modem.c プロジェクト: ClementFan/ofono
static DBusMessage *modem_set_property(DBusConnection *conn,
					DBusMessage *msg, void *data)
{
	struct ofono_modem *modem = data;
	DBusMessageIter iter, var;
	const char *name;

	if (dbus_message_iter_init(msg, &iter) == FALSE)
		return __ofono_error_invalid_args(msg);

	if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING)
		return __ofono_error_invalid_args(msg);

	dbus_message_iter_get_basic(&iter, &name);
	dbus_message_iter_next(&iter);

	if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_VARIANT)
		return __ofono_error_invalid_args(msg);

	if (powering_down == TRUE)
		return __ofono_error_failed(msg);

	dbus_message_iter_recurse(&iter, &var);

	if (g_str_equal(name, "Online"))
		return set_property_online(modem, msg, &var);

	if (g_str_equal(name, "Powered") == TRUE) {
		ofono_bool_t powered;
		int err;

		if (dbus_message_iter_get_arg_type(&var) != DBUS_TYPE_BOOLEAN)
			return __ofono_error_invalid_args(msg);

		dbus_message_iter_get_basic(&var, &powered);

		if (modem->pending != NULL)
			return __ofono_error_busy(msg);

		if (modem->powered == powered)
			return dbus_message_new_method_return(msg);

		if (ofono_modem_get_emergency_mode(modem) == TRUE)
			return __ofono_error_emergency_active(msg);

		if (modem->lockdown)
			return __ofono_error_access_denied(msg);

		err = set_powered(modem, powered);
		if (err < 0) {
			if (err != -EINPROGRESS)
				return __ofono_error_failed(msg);

			modem->pending = dbus_message_ref(msg);
			modem->timeout = g_timeout_add_seconds(20,
						set_powered_timeout, modem);
			return NULL;
		}

		g_dbus_send_reply(conn, msg, DBUS_TYPE_INVALID);

		ofono_dbus_signal_property_changed(conn, modem->path,
						OFONO_MODEM_INTERFACE,
						"Powered", DBUS_TYPE_BOOLEAN,
						&powered);

		if (powered) {
			modem_change_state(modem, MODEM_STATE_PRE_SIM);

			/* Force SIM Ready for devies with no sim atom */
			if (modem_has_sim(modem) == FALSE)
				sim_state_watch(OFONO_SIM_STATE_READY, modem);
		} else {
			set_online(modem, FALSE);
			modem_change_state(modem, MODEM_STATE_POWER_OFF);
		}

		return NULL;
	}

	if (g_str_equal(name, "Lockdown"))
		return set_property_lockdown(modem, msg, &var);

	return __ofono_error_invalid_args(msg);
}
コード例 #10
0
char* get_entry_group_path()
{
    DBusMessage* msg;
    DBusMessageIter args;
    DBusConnection* conn;
    DBusError err;
    dbus_error_init(&err);
    DBusPendingCall* pending;
    char *entry_group_path;

   // initialiset the errors
    printf("Calling remote method: %s\n", "org.freedesktop.Avahi");

   // connect to the system bus and check for errors
    conn = dbus_bus_get(DBUS_BUS_SYSTEM, &err);
    if (dbus_error_is_set(&err)) { 
      fprintf(stderr, "Connection Error (%s)\n", err.message); 
      dbus_error_free(&err);
    }
    if (NULL == conn) { 
      exit(1);
    }

    msg = dbus_message_new_method_call("org.freedesktop.Avahi",// target for the method call
                                        "/", 							// object to call on
                                        "org.freedesktop.Avahi.Server",    // interface to call on
                                        "EntryGroupNew");             // method nameResolveHostName
    if (NULL == msg) 
     { 
      fprintf(stderr, "Message Null\n"); 
      exit(1); 
    }
   // send message and get a handle for a reply
    if (!dbus_connection_send_with_reply (conn, msg, &pending, -1)) { // -1 is default timeout
        fprintf(stderr, "Out Of Memory!\n"); 
        exit(1);
    }
    if (NULL == pending) { 
        fprintf(stderr, "Pending Call Null\n"); 
        exit(1); 
    }
    dbus_connection_flush(conn);
   
    printf("Request Sent\n");
   
    // free message
    dbus_message_unref(msg);
   
    // block until we recieve a reply
    dbus_pending_call_block(pending);

    // get the reply message
    msg = dbus_pending_call_steal_reply(pending);
    if (NULL == msg) {
        fprintf(stderr, "Reply Null\n"); 
        exit(1); 
    }
    if (dbus_message_get_type(msg) == DBUS_MESSAGE_TYPE_ERROR) {
			   fprintf("message returned error: %s", dbus_message_get_error_name(msg));
	}
    // free the pending message handle
    dbus_pending_call_unref(pending);

    // read the parameters
    if (!dbus_message_iter_init(msg, &args))
        fprintf(stderr, "Message has no arguments!\n"); 
    else if (DBUS_TYPE_OBJECT_PATH != dbus_message_iter_get_arg_type(&args)) 
        fprintf(stderr, "Argument is not DBUS_TYPE_OBJECT_PATH!\n"); 
    else
        dbus_message_iter_get_basic(&args, &entry_group_path);


    printf("Got Reply: %s\n", entry_group_path);
    dbus_message_unref(msg);  
    return entry_group_path;
}
コード例 #11
0
void method_GetState(char *path){
    DBusMessage* msg;
    DBusMessageIter args;
    DBusConnection* conn;
    DBusError err;
    dbus_error_init(&err);
    DBusPendingCall* pending;
    // connect to the system bus and check for errors
    conn = dbus_bus_get(DBUS_BUS_SYSTEM, &err);
    if (dbus_error_is_set(&err)) { 
      fprintf(stderr, "Connection Error (%s)\n", err.message); 
      dbus_error_free(&err);
     }
    if (NULL == conn) { 
       exit(1);
     }
    //char *path = malloc(sizeof(char) * strlen(mpath));
    //strcpy(path, mpath);
    //printf("*0mpath: %s / %s\n", path, mpath);
    msg = dbus_message_new_method_call("org.freedesktop.Avahi",// target for the method call
                                        path, 							// object to call on
                                        "org.freedesktop.Avahi.EntryGroup",    // interface to call on
                                        "GetState");             // method nameResolveHostName
    //printf("*1mpath: %s / %s\n", path, mpath);
    if (!dbus_connection_send_with_reply (conn, msg, &pending, -1)) { // -1 is default timeout
        fprintf(stderr, "Out Of Memory!\n"); 
        exit(1);
     }
    //printf("*2mpath: %s / %s\n", path, mpath);
    if (NULL == pending) { 
        fprintf(stderr, "Pending Call Null\n"); 
        exit(1); 
     }
     dbus_connection_flush(conn);

     printf("Request Sent\n");

     // free message
     dbus_message_unref(msg);
    
     // block until we recieve a reply
     dbus_pending_call_block(pending);

     // get the reply message
     msg = dbus_pending_call_steal_reply(pending);
     if (NULL == msg) {
         fprintf(stderr, "Reply Null\n"); 
         exit(1); 
     }
     // free the pending message handle
     dbus_pending_call_unref(pending);

     dbus_uint32_t m_state;
     if (!dbus_message_iter_init(msg, &args)){
         g_message("dbus_message_iter_init fail\n");
     }
     if(dbus_message_get_type(msg) == DBUS_MESSAGE_TYPE_ERROR){
         char *result;
         g_message("arg type: %d", dbus_message_iter_get_arg_type(&args));
         dbus_message_iter_get_basic(&args, &result);
         g_message("error:  %s", result);    	 
     }else{
         if (DBUS_TYPE_INT32 != dbus_message_iter_get_arg_type(&args)) 
             g_message("Argument is not DBUS_TYPE_INT32!\n"); 
         else{
             dbus_message_iter_get_basic(&args, &m_state);
             printf("m_state : %d\n", m_state);
         }
     }
     dbus_message_unref(msg);
}
コード例 #12
0
void signal_ServiceBrowser_item(char *path){
    DBusMessage* msg;
    DBusMessageIter args;
    DBusConnection* conn;
    DBusError err;
    dbus_error_init(&err);

    conn = dbus_bus_get(DBUS_BUS_SYSTEM, &err);
    if (dbus_error_is_set(&err)) { 
      fprintf(stderr, "Connection Error (%s)\n", err.message); 
      dbus_error_free(&err);
    }
    if (NULL == conn) { 
      exit(1);
    }

    gchar* filter_itemnew = g_new(gchar, strlen("type='signal',interface='org.freedesktop.Avahi.ServiceBrowser',member='ItemNew', path=''") + strlen(path) + 2);
    sprintf(filter_itemnew, "type='signal',interface='org.freedesktop.Avahi.ServiceBrowser',member='ItemNew', path='%s'", path);
    gchar* filter_itemremove = g_new(gchar, strlen("type='signal',interface='org.freedesktop.Avahi.ServiceBrowser',member='ItemRemove', path=''") + strlen(path) + 2);
    sprintf(filter_itemremove, "type='signal',interface='org.freedesktop.Avahi.ServiceBrowser',member='ItemRemove', path='%s'", path);
    //printf("signal_filter:%s", signal_filter);
    // add a rule for which messages we want to see
    dbus_bus_add_match(conn, filter_itemnew, &err);
    dbus_bus_add_match(conn, filter_itemremove, &err);

    dbus_connection_flush(conn);
    if (dbus_error_is_set(&err)) { 
        fprintf(stderr, "Match Error (%s)\n", err.message);
        exit(1); 
   }
    printf("Match rule sent\n");

    int interface;
    int protocol;
    char *name;
    char *stype;
    char *domain;
    unsigned int flags;
//int cnt = 0;
   // loop listening for signals being emmitted
    while (true) {
        // non blocking read of the next available message
        dbus_connection_read_write(conn, 0);
        msg = dbus_connection_pop_message(conn);
        // loop again if we haven't read a message
        if (NULL == msg) { 
//g_message("cnt: %d", cnt++);
           sleep(1);
           continue;
    }
    // check if the message is a signal from the correct interface and with the correct name
    if (dbus_message_is_signal(msg, "org.freedesktop.Avahi.ServiceBrowser", "ItemNew")) {
        // read the parameters
//g_message("is the message we need.%d", cnt++);
//g_message("Message Has No Parameters\n");

        if (!dbus_message_iter_init(msg, &args))
            g_message("dbus_message_iter_init fail\n");
        else
        { 
            if (DBUS_TYPE_INT32 != dbus_message_iter_get_arg_type(&args)) 
               g_message( "Argument is not error!\n"); 
            else
               dbus_message_iter_get_basic(&args, &interface);

            if (!dbus_message_iter_next(&args))
                g_message( "Message has too few arguments!\n"); 
            else if (DBUS_TYPE_INT32 != dbus_message_iter_get_arg_type(&args)) 
                g_message("Argument is not error!\n"); 
            else
                dbus_message_iter_get_basic(&args, &protocol);

            if (!dbus_message_iter_next(&args))
                g_message("Message has too few arguments!\n"); 
            else if (DBUS_TYPE_STRING != dbus_message_iter_get_arg_type(&args)) 
                g_message("Argument is not error!\n"); 
            else
               dbus_message_iter_get_basic(&args, &name);

            if (!dbus_message_iter_next(&args))
                g_message("Message has too few arguments!\n"); 
            else if (DBUS_TYPE_STRING != dbus_message_iter_get_arg_type(&args)) 
                g_message("Argument is not error!\n"); 
            else
               dbus_message_iter_get_basic(&args, &stype);

            if (!dbus_message_iter_next(&args))
                g_message("Message has too few arguments!\n"); 
            else if (DBUS_TYPE_STRING != dbus_message_iter_get_arg_type(&args)) 
                g_message("Argument is not error!\n"); 
            else
               dbus_message_iter_get_basic(&args, &domain);

            if (!dbus_message_iter_next(&args))
                g_message("Message has too few arguments!\n"); 
            else if (DBUS_TYPE_UINT32 != dbus_message_iter_get_arg_type(&args)) 
                g_message("Argument is not error!\n"); 
            else
                dbus_message_iter_get_basic(&args, &flags);
            printf("\n");
            printf("discovered:%d, %d, %s, %s, %s, %d.\n", interface, protocol, name, stype, domain, flags);
            resolve_service(interface, protocol, name, stype, domain);
        //printf("Got Signal with value %s\n", sigvalue);
        }
    }else if(dbus_message_is_signal(msg, "org.freedesktop.Avahi.ServiceBrowser", "ItemRemove")){
        if (!dbus_message_iter_init(msg, &args))
            g_message("dbus_message_iter_init fail\n");
        else
        { 
            if (DBUS_TYPE_INT32 != dbus_message_iter_get_arg_type(&args)) 
               g_message( "Argument is not error!\n"); 
            else
               dbus_message_iter_get_basic(&args, &interface);

            if (!dbus_message_iter_next(&args))
                g_message( "Message has too few arguments!\n"); 
            else if (DBUS_TYPE_INT32 != dbus_message_iter_get_arg_type(&args)) 
                g_message("Argument is not error!\n"); 
            else
                dbus_message_iter_get_basic(&args, &protocol);

            if (!dbus_message_iter_next(&args))
                g_message("Message has too few arguments!\n"); 
            else if (DBUS_TYPE_STRING != dbus_message_iter_get_arg_type(&args)) 
                g_message("Argument is not error!\n"); 
            else
               dbus_message_iter_get_basic(&args, &name);

            if (!dbus_message_iter_next(&args))
                g_message("Message has too few arguments!\n"); 
            else if (DBUS_TYPE_STRING != dbus_message_iter_get_arg_type(&args)) 
                g_message("Argument is not error!\n"); 
            else
               dbus_message_iter_get_basic(&args, &stype);

            if (!dbus_message_iter_next(&args))
                g_message("Message has too few arguments!\n"); 
            else if (DBUS_TYPE_STRING != dbus_message_iter_get_arg_type(&args)) 
                g_message("Argument is not error!\n"); 
            else
               dbus_message_iter_get_basic(&args, &domain);

            if (!dbus_message_iter_next(&args))
                g_message("Message has too few arguments!\n"); 
            else if (DBUS_TYPE_UINT32 != dbus_message_iter_get_arg_type(&args)) 
                g_message("Argument is not error!\n"); 
            else
                dbus_message_iter_get_basic(&args, &flags);
            printf("\n");
            printf("removed:%d, %d, %s, %s, %s, %d.\n", interface, protocol, name, stype, domain, flags);
            //resolve_service(interface, protocol, name, stype, domain);
        //printf("Got Signal with value %s\n", sigvalue);
        }
            }
    // free the message
    dbus_message_unref(msg);
    }
}
コード例 #13
0
char* resolve_service(int interface, int protocol, char *name, char *type, char *domain)
{
    DBusMessage* msg;
    DBusMessageIter args;
    DBusConnection* conn;
    DBusError err;
    dbus_error_init(&err);
    DBusPendingCall* pending;
    //dbus_int32_t interface = 2;
    //dbus_int32_t protocol = 1;
    //char *name = "TestService";
    //char *type = "_http._tcp";
    //char *domain = "local";
    dbus_int32_t aprotocol = -1;
    dbus_uint32_t flags = 0;
    printf ("parameter for ResolvesService:%d, %d, %s, %s, %s, %d, %d.\n", interface, protocol, name, type, domain, aprotocol, flags);

   // initialiset the errors
    printf("Calling remote method: %s\n", "org.freedesktop.Avahi");

   // connect to the system bus and check for errors
    conn = dbus_bus_get(DBUS_BUS_SYSTEM, &err);
    if (dbus_error_is_set(&err)) { 
      fprintf(stderr, "Connection Error (%s)\n", err.message); 
      dbus_error_free(&err);
    }
    if (NULL == conn) { 
      exit(1);
    }

    msg = dbus_message_new_method_call("org.freedesktop.Avahi",// target for the method call
                                        "/", 							// object to call on
                                        "org.freedesktop.Avahi.Server",    // interface to call on
                                        "ResolveService");             // method nameResolveHostName
    if (NULL == msg) 
     { 
      fprintf(stderr, "Message Null\n"); 
      exit(1); 
    }
   // append arguments
    dbus_message_iter_init_append(msg, &args);
    if (!dbus_message_iter_append_basic(&args, DBUS_TYPE_INT32, &interface))
    {
        fprintf(stderr, "Out Of Memory!\n"); 
        exit(1);
    }
    if (!dbus_message_iter_append_basic(&args, DBUS_TYPE_INT32, &protocol))
    {
        fprintf(stderr, "Out Of Memory!\n"); 
        exit(1);
    }
    if (!dbus_message_iter_append_basic(&args, DBUS_TYPE_STRING, &name))
    {
        fprintf(stderr, "Out Of Memory!\n"); 
        exit(1);
    }
    if (!dbus_message_iter_append_basic(&args, DBUS_TYPE_STRING, &type))
    {
        fprintf(stderr, "Out Of Memory!\n"); 
        exit(1);
    }
    if (!dbus_message_iter_append_basic(&args, DBUS_TYPE_STRING, &domain))
    {
        fprintf(stderr, "Out Of Memory!\n"); 
        exit(1);
    }
    if (!dbus_message_iter_append_basic(&args, DBUS_TYPE_INT32, &aprotocol))
    {
        fprintf(stderr, "Out Of Memory!\n"); 
        exit(1);
    }
    if (!dbus_message_iter_append_basic(&args, DBUS_TYPE_UINT32, &flags))
    {
        fprintf(stderr, "Out Of Memory!\n"); 
        exit(1);
    }
      
   // send message and get a handle for a reply
    if (!dbus_connection_send_with_reply (conn, msg, &pending, -1)) { // -1 is default timeout
        fprintf(stderr, "Out Of Memory!\n"); 
        exit(1);
    }
    if (NULL == pending) { 
        fprintf(stderr, "Pending Call Null\n"); 
        exit(1); 
    }
    dbus_connection_flush(conn);
   
    printf("Request Sent\n");

    // free message
    dbus_message_unref(msg);
   
    // block until we recieve a reply
    dbus_pending_call_block(pending);

    // get the reply message
    msg = dbus_pending_call_steal_reply(pending);
    if (NULL == msg) {
        fprintf(stderr, "Reply Null\n"); 
        exit(1); 
    }
    // free the pending message handle
    dbus_pending_call_unref(pending);


    char *address;
    char *host;
    dbus_uint16_t port;//gint16
    GPtrArray *byte_arraies;
    dbus_uint32_t m_flags;
    if (!dbus_message_iter_init(msg, &args))
        g_message("dbus_message_iter_init fail\n");
    else
    { 
//g_message("signature of container args: %s", dbus_message_iter_get_signature(&args));
//g_message("first type: %d", dbus_message_iter_get_arg_type(&args));
//g_message("DBUS_TYPE_INT32: %d", DBUS_TYPE_INT32);
//g_message("DBUS_TYPE_STRING: %d", DBUS_TYPE_STRING);
//char *value;
//dbus_message_iter_get_basic(&args, &value);
//g_message("DBUS_TYPE_STRING: %s", value);

        if (DBUS_TYPE_INT32 != dbus_message_iter_get_arg_type(&args)) 
            g_message( "Argument is not error!\n"); 
        else{
            dbus_message_iter_get_basic(&args, &interface);
            printf("interface : %d\n", interface); 
        }

        if (!dbus_message_iter_next(&args))
            g_message( "Message has too few arguments!\n"); 
        else if (DBUS_TYPE_INT32 != dbus_message_iter_get_arg_type(&args)) 
            g_message("Argument is not error!\n"); 
        else{
            dbus_message_iter_get_basic(&args, &protocol);
            printf("protocol : %d\n", protocol); 
        }

        if (!dbus_message_iter_next(&args))
            g_message("Message has too few arguments!\n"); 
        else if (DBUS_TYPE_STRING != dbus_message_iter_get_arg_type(&args)) 
            g_message("Argument is not error!\n"); 
        else{
           dbus_message_iter_get_basic(&args, &name);
            printf("name : %s\n", name); 
        }

        if (!dbus_message_iter_next(&args))
            g_message("Message has too few arguments!\n"); 
        else if (DBUS_TYPE_STRING != dbus_message_iter_get_arg_type(&args)) 
            g_message("Argument is not error!\n"); 
        else{
           dbus_message_iter_get_basic(&args, &type);
            printf("type : %s\n", type); 
        }

        if (!dbus_message_iter_next(&args))
            g_message("Message has too few arguments!\n"); 
        else if (DBUS_TYPE_STRING != dbus_message_iter_get_arg_type(&args)) 
            g_message("Argument is not error!\n"); 
        else{
            dbus_message_iter_get_basic(&args, &domain);
            printf("domain : %s\n", domain); 
        }

        if (!dbus_message_iter_next(&args))
            g_message("Message has too few arguments!\n"); 
        else if (DBUS_TYPE_STRING != dbus_message_iter_get_arg_type(&args)) 
            g_message("Argument is not error!\n"); 
        else{
            dbus_message_iter_get_basic(&args, &host);
            printf("host : %s\n", host); 
        }

        if (!dbus_message_iter_next(&args))
            g_message( "Message has too few arguments!\n"); 
        else if (DBUS_TYPE_INT32 != dbus_message_iter_get_arg_type(&args)) 
            g_message("Argument is not error!\n"); 
        else{
            dbus_message_iter_get_basic(&args, &aprotocol);
            printf("aprotocol : %d\n", aprotocol); 
        }

        if (!dbus_message_iter_next(&args))
            g_message("Message has too few arguments!\n"); 
        else if (DBUS_TYPE_STRING != dbus_message_iter_get_arg_type(&args)) 
            g_message("Argument is not error!\n"); 
        else{
           dbus_message_iter_get_basic(&args, &address);
            printf("address : %s\n", address); 
        }

        if (!dbus_message_iter_next(&args))
            g_message( "Message has too few arguments!\n"); 
        else if (DBUS_TYPE_UINT16 != dbus_message_iter_get_arg_type(&args)) 
            g_message("Argument is not error!\n"); 
        else{
            dbus_message_iter_get_basic(&args, &port);
            printf("port : %d\n", port); 
        }

        if (!dbus_message_iter_next(&args))
            g_message("Message has too few arguments!\n"); 
        else if (strcmp("aay", dbus_message_iter_get_signature(&args))) 
            g_message("Argument is not error!\n"); 
        else{
            DBusMessageIter container_ay, container_y;
            unsigned char *values;int size;
            //dbus_message_iter_get_basic(&args, &flags);
            //dbus_message_iter_open_container(&args, DBUS_TYPE_ARRAY, "ay", &container_ay);
            //dbus_message_iter_open_container(&container_ay, DBUS_TYPE_BYTE, "y", &container_y);

            dbus_message_iter_recurse(&args, &container_ay);

            dbus_message_iter_recurse(&container_ay, &container_y);
            dbus_message_iter_get_fixed_array(&container_y, &values, &size);
            g_message("size: %d, %s", size, values);
/*
g_message("container args: %s", dbus_message_iter_get_signature(&args));
g_message("container_ay: %s", dbus_message_iter_get_signature(&container_ay));
g_message("container_y: %s", dbus_message_iter_get_signature(&container_y));
g_message("type of container_y: %d", dbus_message_iter_get_arg_type(&container_y));
g_message("value of DBUS_TYPE_BYTE: %d", DBUS_TYPE_BYTE);
*/
// && strcmp("ay", dbus_message_iter_get_signature(&container_ay))
            while(dbus_message_iter_next(&container_ay)){
                dbus_message_iter_recurse(&container_ay, &container_y);
                dbus_message_iter_get_fixed_array(&container_y, &values, &size);
                g_message("size: %d, %s", size, values);
            }
        }
        if (!dbus_message_iter_next(&args))
            g_message( "Message has too few arguments!\n"); 
        else if (DBUS_TYPE_UINT32 != dbus_message_iter_get_arg_type(&args)) 
            g_message("Argument is not error!\n"); 
        else{
            dbus_message_iter_get_basic(&args, &m_flags);
            printf("m_flags : %d\n", m_flags); 
        }

/*
dbus_message_iter_next(&args);
g_message("g_message_iter_get_signature: %s", dbus_message_iter_get_signature(&args));
*/
/*
        if (!dbus_message_iter_next(&args))
            g_message("Message has too few arguments!\n"); 
        else if (DBUS_TYPE_UINT32 != dbus_message_iter_get_arg_type(&args)) 
            g_message("Argument is not error!\n"); 
        else
            dbus_message_iter_get_basic(&args, &flags);
*/
  //      printf("discovered:%d, %d, %s, %s, %s, %d.\n", interface, protocol, name, type, domain, flags);
    }
    dbus_message_unref(msg);  
}
コード例 #14
0
char* get_service_browser_path()
{
    DBusMessage* msg;
    DBusMessageIter args;
    DBusConnection* conn;
    DBusError err;
    dbus_error_init(&err);
    DBusPendingCall* pending;
    dbus_int32_t interface = -1;
    dbus_int32_t protocol = -1;
    char *type = "_http._tcp";
    char *domain = "local";
    dbus_uint32_t flags = 0;
    char *service_browser_path;

   // initialiset the errors
    printf("Calling remote method: %s\n", "org.freedesktop.Avahi");

   // connect to the system bus and check for errors
    conn = dbus_bus_get(DBUS_BUS_SYSTEM, &err);
    if (dbus_error_is_set(&err)) { 
      fprintf(stderr, "Connection Error (%s)\n", err.message); 
      dbus_error_free(&err);
    }
    if (NULL == conn) { 
      exit(1);
    }

    msg = dbus_message_new_method_call("org.freedesktop.Avahi",// target for the method call
                                        "/", 							// object to call on
                                        "org.freedesktop.Avahi.Server",    // interface to call on
                                        "ServiceBrowserNew");             // method nameResolveHostName
    if (NULL == msg) 
     { 
      fprintf(stderr, "Message Null\n"); 
      exit(1); 
    }
   // append arguments
    dbus_message_iter_init_append(msg, &args);
    if (!dbus_message_iter_append_basic(&args, DBUS_TYPE_INT32, &interface))
    {
        fprintf(stderr, "Out Of Memory!\n"); 
        exit(1);
    }
    if (!dbus_message_iter_append_basic(&args, DBUS_TYPE_INT32, &protocol))
    {
        fprintf(stderr, "Out Of Memory!\n"); 
        exit(1);
    }
    if (!dbus_message_iter_append_basic(&args, DBUS_TYPE_STRING, &type))
    {
        fprintf(stderr, "Out Of Memory!\n"); 
        exit(1);
    }
    if (!dbus_message_iter_append_basic(&args, DBUS_TYPE_STRING, &domain))
    {
        fprintf(stderr, "Out Of Memory!\n"); 
        exit(1);
    }
    if (!dbus_message_iter_append_basic(&args, DBUS_TYPE_UINT32, &flags))
    {
        fprintf(stderr, "Out Of Memory!\n"); 
        exit(1);
    }
      
   // send message and get a handle for a reply
    if (!dbus_connection_send_with_reply (conn, msg, &pending, -1)) { // -1 is default timeout
        fprintf(stderr, "Out Of Memory!\n"); 
        exit(1);
    }
    if (NULL == pending) { 
        fprintf(stderr, "Pending Call Null\n"); 
        exit(1); 
    }
    dbus_connection_flush(conn);
   
    printf("Request Sent\n");
   
    // free message
    dbus_message_unref(msg);
   
    // block until we recieve a reply
    dbus_pending_call_block(pending);

    // get the reply message
    msg = dbus_pending_call_steal_reply(pending);
    if (NULL == msg) {
        fprintf(stderr, "Reply Null\n"); 
        exit(1); 
    }
    // free the pending message handle
    dbus_pending_call_unref(pending);

    // read the parameters
    if (!dbus_message_iter_init(msg, &args))
        fprintf(stderr, "Message has no arguments!\n"); 
    else if (DBUS_TYPE_OBJECT_PATH != dbus_message_iter_get_arg_type(&args)) 
        fprintf(stderr, "Argument is not boolean!\n"); 
    else
        dbus_message_iter_get_basic(&args, &service_browser_path);


    printf("Got Reply: %s\n", service_browser_path);
    dbus_message_unref(msg);  
    return service_browser_path;
}
コード例 #15
0
static void
print_iter (DBusMessageIter *iter, dbus_bool_t literal, int depth)
{
  do
    {
      int type = dbus_message_iter_get_arg_type (iter);
      const char *str;
      dbus_uint32_t uint32;
      dbus_int32_t int32;
      double d;
      unsigned char byte;
      dbus_bool_t boolean;

      if (type == DBUS_TYPE_INVALID)
	break;

      while (depth-- > 0)
	putc (' ', stdout);

      switch (type)
	{
	case DBUS_TYPE_STRING:
          dbus_message_iter_get_basic (iter, &str);
	  if (!literal)
	    printf ("string \"");
	  printf ("%s", str);
	  if (!literal)
	    printf ("\"\n");
	  break;

	case DBUS_TYPE_INT32:
          dbus_message_iter_get_basic (iter, &int32);
	  printf ("int32 %d\n", int32);
	  break;

	case DBUS_TYPE_UINT32:
          dbus_message_iter_get_basic (iter, &uint32);
	  printf ("uint32 %u\n", uint32);
	  break;

	case DBUS_TYPE_DOUBLE:
	  dbus_message_iter_get_basic (iter, &d);
	  printf ("double %g\n", d);
	  break;

	case DBUS_TYPE_BYTE:
	  dbus_message_iter_get_basic (iter, &byte);
	  printf ("byte %d\n", byte);
	  break;

	case DBUS_TYPE_BOOLEAN:
          dbus_message_iter_get_basic (iter, &boolean);
	  printf ("boolean %s\n", boolean ? "true" : "false");
	  break;

	case DBUS_TYPE_VARIANT:
	  {
	    DBusMessageIter subiter;

	    dbus_message_iter_recurse (iter, &subiter);

	    printf ("variant:");
	    print_iter (&subiter, literal, depth);
	    break;
	  }
	case DBUS_TYPE_ARRAY:
	  {
	    int current_type;
	    DBusMessageIter subiter;

	    dbus_message_iter_recurse (iter, &subiter);

	    printf("[");
	    while ((current_type = dbus_message_iter_get_arg_type (&subiter)) != DBUS_TYPE_INVALID)
	      {
		print_iter (&subiter, literal, depth);
		dbus_message_iter_next (&subiter);
		if (dbus_message_iter_get_arg_type (&subiter) != DBUS_TYPE_INVALID)
		  printf (",");
	      }
	    printf("]");
	    break;
	  }
	case DBUS_TYPE_DICT_ENTRY:
	  {
	    DBusMessageIter subiter;

	    dbus_message_iter_recurse (iter, &subiter);

	    printf("{");
	    print_iter (&subiter, literal, depth);
	    dbus_message_iter_next (&subiter);
	    print_iter (&subiter, literal, depth);
	    printf("}");
	    break;
	  }
	    
	default:
	  printf (" (dbus-monitor too dumb to decipher arg type '%c')\n", type);
	  break;
	}
      
    } while (dbus_message_iter_next (iter));
}
コード例 #16
0
ファイル: modem.c プロジェクト: ClementFan/ofono
static DBusMessage *set_property_lockdown(struct ofono_modem *modem,
					DBusMessage *msg,
					DBusMessageIter *var)
{
	DBusConnection *conn = ofono_dbus_get_connection();
	ofono_bool_t lockdown;
	dbus_bool_t powered;
	const char *caller;
	int err;

	if (dbus_message_iter_get_arg_type(var) != DBUS_TYPE_BOOLEAN)
		return __ofono_error_invalid_args(msg);

	dbus_message_iter_get_basic(var, &lockdown);

	if (modem->pending != NULL)
		return __ofono_error_busy(msg);

	caller = dbus_message_get_sender(msg);

	if (modem->lockdown && g_strcmp0(caller, modem->lock_owner))
		return __ofono_error_access_denied(msg);

	if (modem->lockdown == lockdown)
		return dbus_message_new_method_return(msg);

	if (lockdown == FALSE) {
		lockdown_remove(modem);
		goto done;
	}

	if (ofono_modem_get_emergency_mode(modem) == TRUE)
		return __ofono_error_emergency_active(msg);

	modem->lock_owner = g_strdup(caller);

	modem->lock_watch = g_dbus_add_disconnect_watch(conn,
				modem->lock_owner, lockdown_disconnect,
				modem, NULL);

	if (modem->lock_watch == 0) {
		g_free(modem->lock_owner);
		modem->lock_owner = NULL;

		return __ofono_error_failed(msg);
	}

	modem->lockdown = lockdown;

	if (modem->powered == FALSE)
		goto done;

	err = set_powered(modem, FALSE);
	if (err < 0) {
		if (err != -EINPROGRESS) {
			lockdown_remove(modem);
			return __ofono_error_failed(msg);
		}

		modem->pending = dbus_message_ref(msg);
		modem->timeout = g_timeout_add_seconds(20,
						set_powered_timeout, modem);
		return NULL;
	}

	set_online(modem, FALSE);

	powered = FALSE;
	ofono_dbus_signal_property_changed(conn, modem->path,
					OFONO_MODEM_INTERFACE,
					"Powered", DBUS_TYPE_BOOLEAN,
					&powered);

done:
	g_dbus_send_reply(conn, msg, DBUS_TYPE_INVALID);

	ofono_dbus_signal_property_changed(conn, modem->path,
					OFONO_MODEM_INTERFACE,
					"Lockdown", DBUS_TYPE_BOOLEAN,
					&lockdown);

	return NULL;
}
コード例 #17
0
ファイル: dbus.c プロジェクト: NieHao/wl500g
static void dbus_read_servers(DBusMessage *message)
{
  DBusMessageIter iter;
  union  mysockaddr addr, source_addr;
  char *domain;
  
  dbus_message_iter_init(message, &iter);

  mark_servers(SERV_FROM_DBUS);
  
  while (1)
    {
      int skip = 0;

      if (dbus_message_iter_get_arg_type(&iter) == DBUS_TYPE_UINT32)
	{
	  u32 a;
	  
	  dbus_message_iter_get_basic(&iter, &a);
	  dbus_message_iter_next (&iter);
	  
#ifdef HAVE_SOCKADDR_SA_LEN
	  source_addr.in.sin_len = addr.in.sin_len = sizeof(struct sockaddr_in);
#endif
	  addr.in.sin_addr.s_addr = ntohl(a);
	  source_addr.in.sin_family = addr.in.sin_family = AF_INET;
	  addr.in.sin_port = htons(NAMESERVER_PORT);
	  source_addr.in.sin_addr.s_addr = INADDR_ANY;
	  source_addr.in.sin_port = htons(daemon->query_port);
	}
      else if (dbus_message_iter_get_arg_type(&iter) == DBUS_TYPE_BYTE)
	{
	  unsigned char p[sizeof(struct in6_addr)];
	  unsigned int i;

	  skip = 1;

	  for(i = 0; i < sizeof(struct in6_addr); i++)
	    {
	      dbus_message_iter_get_basic(&iter, &p[i]);
	      dbus_message_iter_next (&iter);
	      if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_BYTE)
		{
		  i++;
		  break;
		}
	    }

#ifndef HAVE_IPV6
	  my_syslog(LOG_WARNING, _("attempt to set an IPv6 server address via DBus - no IPv6 support"));
#else
	  if (i == sizeof(struct in6_addr))
	    {
	      memcpy(&addr.in6.sin6_addr, p, sizeof(struct in6_addr));
#ifdef HAVE_SOCKADDR_SA_LEN
              source_addr.in6.sin6_len = addr.in6.sin6_len = sizeof(struct sockaddr_in6);
#endif
              source_addr.in6.sin6_family = addr.in6.sin6_family = AF_INET6;
              addr.in6.sin6_port = htons(NAMESERVER_PORT);
              source_addr.in6.sin6_flowinfo = addr.in6.sin6_flowinfo = 0;
	      source_addr.in6.sin6_scope_id = addr.in6.sin6_scope_id = 0;
              source_addr.in6.sin6_addr = in6addr_any;
              source_addr.in6.sin6_port = htons(daemon->query_port);
	      skip = 0;
	    }
#endif
	}
      else
	/* At the end */
	break;
      
      /* process each domain */
      do {
	if (dbus_message_iter_get_arg_type(&iter) == DBUS_TYPE_STRING)
	  {
	    dbus_message_iter_get_basic(&iter, &domain);
	    dbus_message_iter_next (&iter);
	  }
	else
	  domain = NULL;
	
	if (!skip)
	  add_update_server(SERV_FROM_DBUS, &addr, &source_addr, NULL, domain);
     
      } while (dbus_message_iter_get_arg_type(&iter) == DBUS_TYPE_STRING); 
    }
   
  /* unlink and free anything still marked. */
  cleanup_servers();
}
コード例 #18
0
void *
unmarshal_device_get_all_properties(DBusMessage *msg, DBusError *err)
{
   E_Ukit_Get_All_Properties_Return *ret = NULL;
   DBusMessageIter iter, a_iter, s_iter, v_iter;
   int type;
   char *tmp;

   /* a{sv} = array of string+variants */
   if (!dbus_message_has_signature(msg, "a{sv}")) 
     {
        dbus_set_error(err, DBUS_ERROR_INVALID_SIGNATURE, "");
        return NULL;
     }

   ret = calloc(1, sizeof(E_Ukit_Get_All_Properties_Return));
   if (!ret) 
     {
         dbus_set_error(err, DBUS_ERROR_NO_MEMORY, "");
         return NULL;
     }

   ret->properties = eina_hash_string_small_new(EINA_FREE_CB(e_ukit_property_free));

   dbus_message_iter_init(msg, &iter);
   dbus_message_iter_recurse(&iter, &a_iter);
   while (dbus_message_iter_get_arg_type(&a_iter) != DBUS_TYPE_INVALID)
   {
      const char *name;
      E_Ukit_Property *prop = calloc(1, sizeof(E_Ukit_Property));
      dbus_message_iter_recurse(&a_iter, &s_iter);
      dbus_message_iter_get_basic(&s_iter, &name);
      dbus_message_iter_next(&s_iter);
      dbus_message_iter_recurse(&s_iter, &v_iter);
      
      type = dbus_message_iter_get_arg_type(&v_iter);
      switch(type)
        {
           case DBUS_TYPE_STRING:
             prop->type = E_UKIT_PROPERTY_TYPE_STRING;
             dbus_message_iter_get_basic(&v_iter, &tmp);
             prop->val.s = eina_stringshare_add(tmp);
             break;
           case DBUS_TYPE_INT32:
             prop->type = E_UKIT_PROPERTY_TYPE_INT;
             dbus_message_iter_get_basic(&v_iter, &(prop->val.i));
             break;
           case DBUS_TYPE_UINT32:
             prop->type = E_UKIT_PROPERTY_TYPE_UINT32;
             dbus_message_iter_get_basic(&v_iter, &(prop->val.u));
             break;
           case DBUS_TYPE_UINT64:
             prop->type = E_UKIT_PROPERTY_TYPE_UINT64;
             dbus_message_iter_get_basic(&v_iter, &(prop->val.t));
             break;
           case DBUS_TYPE_INT64:
             prop->type = E_UKIT_PROPERTY_TYPE_INT64;
             dbus_message_iter_get_basic(&v_iter, &(prop->val.x));
             break;
           case DBUS_TYPE_BOOLEAN:
             prop->type = E_UKIT_PROPERTY_TYPE_BOOL;
             dbus_message_iter_get_basic(&v_iter, &(prop->val.b));
             break;
           case DBUS_TYPE_DOUBLE:
             prop->type = E_UKIT_PROPERTY_TYPE_DOUBLE;
             dbus_message_iter_get_basic(&v_iter, &(prop->val.d));
             break;
           case DBUS_TYPE_ARRAY:
             prop->type = E_UKIT_PROPERTY_TYPE_STRLIST;
             {
                DBusMessageIter list_iter;
                prop->val.strlist = NULL;
                dbus_message_iter_recurse(&v_iter, &list_iter);
                while (dbus_message_iter_get_arg_type(&list_iter) != DBUS_TYPE_INVALID)
                {
                   char *str;
                   dbus_message_iter_get_basic(&list_iter, &str);
                   tmp = (char*)eina_stringshare_add(str);
                   prop->val.strlist = eina_list_append(prop->val.strlist, tmp);
                   dbus_message_iter_next(&list_iter);
                }
             }
             break;
           default:
             WARN("EUkit Error: unexpected property type (%s): %c", name, dbus_message_iter_get_arg_type(&v_iter));
             break;
        }
      eina_hash_add(ret->properties, name, prop);

      dbus_message_iter_next(&a_iter);
   }

   return ret;
}
コード例 #19
0
static void
_dbus_cb_tracklist_metadata(void *data, DBusMessage *reply, DBusError *error)
{
   DBusMessageIter array, item, iter, iter_val;
   Instance *inst = data;
   int type, cnt = 0;
   char *key, *tmp, *location = NULL;
   int title = 0;
   Evas_Object *empris = inst->empris;
   Evas_Object *o_popup = inst->o_popup;

   if (error)
     {
	if (!_dbus_check_msg(reply, error))
	  {
	     printf("dbus garbage!\n");
	     goto error;
	  }
     }

   edje_object_part_text_set (empris, "empris.artist", "");
   edje_object_part_text_set (o_popup, "empris.artist", "");
   
   edje_object_part_text_set (empris, "empris.title", "");
   edje_object_part_text_set (o_popup, "empris.title", "");

   edje_object_part_text_set (empris, "empris.album", "");
   edje_object_part_text_set (o_popup, "empris.album", "");


   dbus_message_iter_init(reply, &array);
   if(dbus_message_iter_get_arg_type(&array) == DBUS_TYPE_ARRAY)
     {
	dbus_message_iter_recurse(&array, &item);

	while(dbus_message_iter_get_arg_type(&item) == DBUS_TYPE_DICT_ENTRY)
	  {
	     dbus_message_iter_recurse(&item, &iter);
	     if (dbus_message_iter_get_arg_type(&iter) == DBUS_TYPE_STRING)
	       {
		  dbus_message_iter_get_basic(&iter, &key);
	       }
	     else
	       {
		  printf("not string{n");
		  goto error;
	       }
	  
	     dbus_message_iter_next(&iter);
	     if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_VARIANT)
	       {
		  printf("not variant\n");
		  goto error;
	       }
	  
	     if (!strcmp(key, "artist"))
	       {
		  dbus_message_iter_recurse (&iter, &iter_val);
		  dbus_message_iter_get_basic (&iter_val, &tmp);
		  if (tmp && tmp[0])
		    {
		       edje_object_part_text_set (empris, "empris.artist", tmp);
		       edje_object_part_text_set (o_popup, "empris.artist", tmp);
		    }
	       }
	     else if (!strcmp(key, "title"))
	       {
		  dbus_message_iter_recurse (&iter, &iter_val);
		  dbus_message_iter_get_basic (&iter_val, &tmp);
		  if (tmp && tmp[0])
		    {
		       edje_object_part_text_set (empris, "empris.title", tmp);
		       edje_object_part_text_set (o_popup, "empris.title", tmp);
		       title = 1;
		    }
	       }
	     else if (!strcmp(key, "location"))
	       {
		  dbus_message_iter_recurse (&iter, &iter_val);
		  dbus_message_iter_get_basic (&iter_val, &tmp);
		  if (tmp && tmp[0])
		    {
		       location = strdup(tmp);
		    }	     
	       }
	     else if (!strcmp(key, "album"))
	       {
		  dbus_message_iter_recurse (&iter, &iter_val);
		  dbus_message_iter_get_basic (&iter_val, &tmp);
		  if (tmp && tmp[0])
		    {
		       edje_object_part_text_set (empris, "empris.album", tmp);
		       edje_object_part_text_set (o_popup, "empris.album", tmp);		  
		    }
	       }
	     /* else if (!strcmp(key, "mtime"))
	      *   {
	      *     dbus_message_iter_recurse (&iter, &iter_val);
	      *     dbus_message_iter_get_basic (&iter_val, &(t->length));
	      *   } */
	     dbus_message_iter_next(&item);
	  }
     }

   if (!title && location)
     {
	char *tmp = _util_unescape(ecore_file_file_get(location), 0);

	if (tmp)
	  {
	     edje_object_part_text_set (empris, "empris.title", tmp);
	     edje_object_part_text_set (o_popup, "empris.title", tmp);
	     free(tmp);
	  }
	free(location);
     }
   
 error:
   return;
}
コード例 #20
0
void *
unmarshal_property(DBusMessage *msg, DBusError *err)
{
   E_Ukit_Get_Property_Return *ret = NULL;
   DBusMessageIter iter, a_iter;
   int type;
   char *tmp;

   if (!dbus_message_iter_init(msg, &iter)) return NULL; /* no params in message */

   ret = calloc(1, sizeof(E_Ukit_Get_Property_Return));
   if (!ret) 
     {
        dbus_set_error(err, DBUS_ERROR_NO_MEMORY, "");
        return NULL;
     }

   dbus_message_iter_recurse(&iter, &a_iter);
   if (dbus_message_iter_get_arg_type(&a_iter) != DBUS_TYPE_INVALID)
     {
        type = dbus_message_iter_get_arg_type(&a_iter);    

        switch(type)
          {
             case DBUS_TYPE_STRING:
               ret->type = E_UKIT_PROPERTY_TYPE_STRING;
               dbus_message_iter_get_basic(&a_iter, &tmp);
               ret->val.s = eina_stringshare_add(tmp);
               break;
             case DBUS_TYPE_INT32:
               ret->type = E_UKIT_PROPERTY_TYPE_INT;
               dbus_message_iter_get_basic(&a_iter, &(ret->val.i));
               break;
             case DBUS_TYPE_UINT32:
               ret->type = E_UKIT_PROPERTY_TYPE_UINT32;
               dbus_message_iter_get_basic(&a_iter, &(ret->val.u));
               break;
             case DBUS_TYPE_UINT64:
               ret->type = E_UKIT_PROPERTY_TYPE_UINT64;
               dbus_message_iter_get_basic(&a_iter, &(ret->val.t));
               break;
             case DBUS_TYPE_INT64:
               ret->type = E_UKIT_PROPERTY_TYPE_INT64;
               dbus_message_iter_get_basic(&a_iter, &(ret->val.x));
               break;
             case DBUS_TYPE_BOOLEAN:
               ret->type = E_UKIT_PROPERTY_TYPE_BOOL;
               dbus_message_iter_get_basic(&a_iter, &(ret->val.b));
               break;
             case DBUS_TYPE_DOUBLE:
               ret->type = E_UKIT_PROPERTY_TYPE_DOUBLE;
               dbus_message_iter_get_basic(&a_iter, &(ret->val.d));
               break;
             case DBUS_TYPE_ARRAY:
               ret->type = E_UKIT_PROPERTY_TYPE_STRLIST;
               {
                  DBusMessageIter list_iter;
                  ret->val.strlist = NULL;
                  dbus_message_iter_recurse(&a_iter, &list_iter);
                  while (dbus_message_iter_get_arg_type(&list_iter) != DBUS_TYPE_INVALID)
                    {
                       char *str;
                       dbus_message_iter_get_basic(&list_iter, &str);
                       tmp = (char*)eina_stringshare_add(str);
                       ret->val.strlist = eina_list_append(ret->val.strlist, tmp);
                       dbus_message_iter_next(&list_iter);
                    }
                }
                break;
             default:
               break;
          }
     }

   return ret;
}
コード例 #21
0
ファイル: qmi.c プロジェクト: roland-wilhelm/connman
/**
* @brief Callback qmi device open modem
*/
static void
open_modem_callback(DBusMessage *message, void *user_data) {

	DBusMessageIter iter;
	struct qmi_data *qmi = (struct qmi_data *)user_data;
	gchar *help;

	DBG("qmi data %p DBusmessage %p", qmi, message);

	if(qmi == NULL) {

		connman_error("No QMI device");
		qmi->modem_opening = FALSE;
		return;
	}

	if(dbus_message_get_type(message) == DBUS_MESSAGE_TYPE_ERROR) {
		const char *dbus_error = dbus_message_get_error_name(message);

		connman_error("%s", dbus_error);
		qmi->modem_opening = FALSE;
		return;

	}

	if((dbus_message_iter_init(message, &iter) == TRUE) &&
			(dbus_message_iter_get_arg_type(&iter) == DBUS_TYPE_OBJECT_PATH)) {

		dbus_message_iter_get_basic(&iter, &help);
		qmi->object_path = g_strdup(help);
	}
	else {

		connman_error("Return type invalid");
		qmi->modem_opening = FALSE;
		return;
	}

	DBG("Modem opened object path %s", qmi->object_path);

	if(!qmi->qmi_proxy_device) {

		qmi->qmi_proxy_device = g_dbus_proxy_new(	qmi_client,
												qmi->object_path,
												QMI_DEVICE_INTERFACE);
	}

	if(qmi->qmi_proxy_device == NULL) {

		connman_error("QMI proxy device not created");
		/* Just return, if failure we have a memory issue, then. */
		return;
	}

	g_dbus_proxy_method_call(	qmi->qmi_proxy_device,
								GET_PROPERTIES,
								NULL,
								open_modem_get_properties_callback,
								qmi,
								NULL);

}
コード例 #22
0
ファイル: technology.c プロジェクト: leinomii/connman
static DBusMessage *set_property(DBusConnection *conn,
					DBusMessage *msg, void *data)
{
	struct connman_technology *technology = data;
	DBusMessageIter iter, value;
	const char *name;
	int type;

	DBG("conn %p", conn);

	if (dbus_message_iter_init(msg, &iter) == FALSE)
		return __connman_error_invalid_arguments(msg);

	if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING)
		return __connman_error_invalid_arguments(msg);

	dbus_message_iter_get_basic(&iter, &name);
	dbus_message_iter_next(&iter);

	if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_VARIANT)
		return __connman_error_invalid_arguments(msg);

	dbus_message_iter_recurse(&iter, &value);

	type = dbus_message_iter_get_arg_type(&value);

	DBG("property %s", name);

	if (g_str_equal(name, "Tethering") == TRUE) {
		int err;
		connman_bool_t tethering;

		if (type != DBUS_TYPE_BOOLEAN)
			return __connman_error_invalid_arguments(msg);

		if (connman_technology_is_tethering_allowed(technology->type)
								== FALSE) {
			DBG("%s tethering not allowed by config file",
				__connman_service_type2string(technology->type));
			return __connman_error_not_supported(msg);
		}

		dbus_message_iter_get_basic(&value, &tethering);

		if (technology->tethering == tethering) {
			if (tethering == FALSE)
				return __connman_error_already_disabled(msg);
			else
				return __connman_error_already_enabled(msg);
		}

		err = set_tethering(technology, tethering);
		if (err < 0)
			return __connman_error_failed(msg, -err);

		technology->tethering_persistent = tethering;

		technology_save(technology);

	} else if (g_str_equal(name, "TetheringIdentifier") == TRUE) {
		const char *str;

		dbus_message_iter_get_basic(&value, &str);

		if (technology->type != CONNMAN_SERVICE_TYPE_WIFI)
			return __connman_error_not_supported(msg);

		if (strlen(str) < 1 || strlen(str) > 32)
			return __connman_error_invalid_arguments(msg);

		if (g_strcmp0(technology->tethering_ident, str) != 0) {
			g_free(technology->tethering_ident);
			technology->tethering_ident = g_strdup(str);
			technology_save(technology);

			connman_dbus_property_changed_basic(technology->path,
						CONNMAN_TECHNOLOGY_INTERFACE,
						"TetheringIdentifier",
						DBUS_TYPE_STRING,
						&technology->tethering_ident);
		}
	} else if (g_str_equal(name, "TetheringPassphrase") == TRUE) {
		const char *str;

		dbus_message_iter_get_basic(&value, &str);

		if (technology->type != CONNMAN_SERVICE_TYPE_WIFI)
			return __connman_error_not_supported(msg);

		if (strlen(str) < 8 || strlen(str) > 63)
			return __connman_error_passphrase_required(msg);

		if (g_strcmp0(technology->tethering_passphrase, str) != 0) {
			g_free(technology->tethering_passphrase);
			technology->tethering_passphrase = g_strdup(str);
			technology_save(technology);

			connman_dbus_property_changed_basic(technology->path,
					CONNMAN_TECHNOLOGY_INTERFACE,
					"TetheringPassphrase",
					DBUS_TYPE_STRING,
					&technology->tethering_passphrase);
		}
	} else if (g_str_equal(name, "Powered") == TRUE) {
		connman_bool_t enable;

		if (type != DBUS_TYPE_BOOLEAN)
			return __connman_error_invalid_arguments(msg);

		dbus_message_iter_get_basic(&value, &enable);

		return set_powered(technology, msg, enable);
	} else
		return __connman_error_invalid_property(msg);

	return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
}
コード例 #23
0
ファイル: qmi.c プロジェクト: roland-wilhelm/connman
/**
* @brief Set the newly replied key/ value properties
*/
static gboolean
update_network(struct qmi_data *qmi, DBusMessageIter *entry_iter) {

	DBusMessageIter variant_iter;
	gboolean updating_strength = FALSE;
	gboolean updating_others = FALSE;
	gchar *key;
	gchar *help;



	if(dbus_message_iter_get_arg_type(entry_iter) != DBUS_TYPE_STRING)
		return FALSE;

	dbus_message_iter_get_basic(entry_iter, &key);
	DBG("Property %s", key);
	if(key != NULL) {

		dbus_message_iter_next(entry_iter);

		if(dbus_message_iter_get_arg_type(entry_iter) != DBUS_TYPE_VARIANT)
			return FALSE;

		dbus_message_iter_recurse(entry_iter, &variant_iter);

		if(g_strcmp0(key, "IMSI") == 0) {
			/* Set new IMSI */
			if(dbus_message_iter_get_arg_type(&variant_iter) != DBUS_TYPE_STRING)
				return FALSE;

			dbus_message_iter_get_basic(&variant_iter, &help);
			if(qmi->imsi)
				g_free(qmi->imsi);
			qmi->imsi = g_strdup(help);

		}
		else if(g_strcmp0(key, "RSRQ") == 0) {
			/* Set new RSRQ */
			guint8 help = 0;

			if(qmi->network == NULL)
				return FALSE;

			if(dbus_message_iter_get_arg_type(&variant_iter) != DBUS_TYPE_INT32)
				return FALSE;

			dbus_message_iter_get_basic(&variant_iter, &qmi->rsrq);
			help = calculate_signal_strength(qmi->rsrq);
			if(help != qmi->strength) {

				qmi->strength = help;
				/* Set new calculated strength */

				connman_network_set_strength(qmi->network, qmi->strength);

				updating_strength = TRUE;
			}


		}
		else if(g_strcmp0(key, "PacketStatus") == 0) {
			/* Set new packet status */
			if(qmi->network == NULL)
				return FALSE;

			if(dbus_message_iter_get_arg_type(&variant_iter) != DBUS_TYPE_STRING)
				return FALSE;

			dbus_message_iter_get_basic(&variant_iter, &help);
			if(g_strcmp0(qmi->packet_status, help) != 0) {

				if(qmi->packet_status)
					g_free(qmi->packet_status);
				qmi->packet_status = g_strdup(help);

				/* Check new packet status and change network status if required */
				if(g_strcmp0(qmi->packet_status, "connected") == 0) {

					connman_network_set_connected(qmi->network, TRUE);
				}
				else {

					connman_network_set_connected(qmi->network, FALSE);
				}

			}


		}
		else if(g_strcmp0(key, "NetworkType") == 0) {
			/* Set new network type */
			if(dbus_message_iter_get_arg_type(&variant_iter) != DBUS_TYPE_STRING)
				return FALSE;

			dbus_message_iter_get_basic(&variant_iter, &help);
			if(g_strcmp0(qmi->network_type, help) != 0) {

				if(qmi->network_type)
					g_free(qmi->network_type);
				qmi->network_type = g_strdup(help);

				updating_others = TRUE;

			}


		}
		else if(g_strcmp0(key, "MCC") == 0) {
			/* Set new MCC */
			if(dbus_message_iter_get_arg_type(&variant_iter) != DBUS_TYPE_STRING)
				return FALSE;

			dbus_message_iter_get_basic(&variant_iter, &help);
			if(g_strcmp0(qmi->mcc, help) != 0) {

				if(qmi->mcc)
					g_free(qmi->mcc);
				qmi->mcc = g_strdup(help);

				updating_others = TRUE;

			}


		}
		else if(g_strcmp0(key, "MNC") == 0) {
			/* Set new MNC */
			if(dbus_message_iter_get_arg_type(&variant_iter) != DBUS_TYPE_STRING)
				return FALSE;

			dbus_message_iter_get_basic(&variant_iter, &help);
			if(g_strcmp0(qmi->mnc, help) != 0) {

				if(qmi->mnc)
					g_free(qmi->mnc);
				qmi->mnc = g_strdup(help);

				updating_others = TRUE;

			}


		}
		else if(g_strcmp0(key, "RAT") == 0) {
			/*Set new RAT */
			if(dbus_message_iter_get_arg_type(&variant_iter) != DBUS_TYPE_STRING)
				return FALSE;

			dbus_message_iter_get_basic(&variant_iter, &help);
			if(g_strcmp0(qmi->rat, help) != 0) {

				if(qmi->rat)
					g_free(qmi->rat);
				qmi->rat = g_strdup(help);

				updating_others = TRUE;

			}

		}

		/* Check whether network already exists, because some properties as IMSI or IMEI are set before network is added */
		if(qmi->network) {

			if(updating_strength == TRUE) {
				/* Just update new strength property */
				connman_network_update(qmi->network);
			}
			else if(updating_others == TRUE) {
				/* Build a new network name and update it */
				if(qmi->provider)
					g_free(qmi->provider);

				qmi->provider = g_strdup_printf("%s-%s-%s", qmi->mnc, qmi->mcc, qmi->rat);

				connman_network_set_name(qmi->network, qmi->provider);
				connman_network_update(qmi->network);

			}

		}

	}

	return TRUE;
}
コード例 #24
0
ファイル: systemd.c プロジェクト: urusha/pacemaker
GList *
systemd_unit_listall(void)
{
    int lpc = 0;
    GList *units = NULL;
    DBusMessageIter args;
    DBusMessageIter unit;
    DBusMessageIter elem;
    DBusMessage *msg = NULL;
    DBusMessage *reply = NULL;
    const char *method = "ListUnits";
    DBusError error;

    if (systemd_init() == FALSE) {
        return NULL;
    }

/*
        "  <method name=\"ListUnits\">\n"                               \
        "   <arg name=\"units\" type=\"a(ssssssouso)\" direction=\"out\"/>\n" \
        "  </method>\n"                                                 \
*/

    dbus_error_init(&error);
    msg = systemd_new_method(BUS_NAME".Manager", method);
    CRM_ASSERT(msg != NULL);

    reply = pcmk_dbus_send_recv(msg, systemd_proxy, &error);
    dbus_message_unref(msg);

    if(error.name) {
        crm_err("Call to %s failed: %s", method, error.name);
        return NULL;

    } else if (reply == NULL) {
        crm_err("Call to %s failed: Message has no reply", method);
        return NULL;

    } else if (!dbus_message_iter_init(reply, &args)) {
        crm_err("Call to %s failed: Message has no arguments", method);
        dbus_message_unref(reply);
        return NULL;
    }

    if(!pcmk_dbus_type_check(reply, &args, DBUS_TYPE_ARRAY, __FUNCTION__, __LINE__)) {
        crm_err("Call to %s failed: Message has invalid arguments", method);
        dbus_message_unref(reply);
        return NULL;
    }

    dbus_message_iter_recurse(&args, &unit);
    while (dbus_message_iter_get_arg_type (&unit) != DBUS_TYPE_INVALID) {
        DBusBasicValue value;

        if(!pcmk_dbus_type_check(reply, &unit, DBUS_TYPE_STRUCT, __FUNCTION__, __LINE__)) {
            continue;
        }

        dbus_message_iter_recurse(&unit, &elem);
        if(!pcmk_dbus_type_check(reply, &elem, DBUS_TYPE_STRING, __FUNCTION__, __LINE__)) {
            continue;
        }

        dbus_message_iter_get_basic(&elem, &value);
        crm_trace("Got: %s", value.str);
        if(value.str) {
            char *match = strstr(value.str, ".service");

            if (match) {
                lpc++;
                match[0] = 0;

                units = g_list_append(units, strdup(value.str));
            }
        }
        dbus_message_iter_next (&unit);
    }

    dbus_message_unref(reply);

    crm_trace("Found %d systemd services", lpc);
    return units;
}
コード例 #25
0
ファイル: powerkey.c プロジェクト: ClementFan/mce
/**
 * D-Bus callback for powerkey event triggering
 *
 * @param msg D-Bus message
 * @return TRUE on success, FALSE on failure
 */
static gboolean trigger_powerkey_event_req_dbus_cb(DBusMessage *const msg)
{
	dbus_bool_t no_reply = dbus_message_get_no_reply(msg);
	DBusMessageIter iter;
	dbus_uint32_t uintval;
	dbus_bool_t boolval;
	gint argcount = 0;
	gint argtype;
	gboolean status = FALSE;
	DBusError error;

	/* Register error channel */
	dbus_error_init(&error);

	mce_log(LL_DEBUG, "Received [power] button trigger request");

	if (dbus_message_iter_init(msg, &iter) == FALSE) {
		// XXX: should we return an error instead?
		mce_log(LL_ERR,
			"Failed to initialise D-Bus message iterator; "
			"message has no arguments");
		goto EXIT;
	}

	argtype = dbus_message_iter_get_arg_type(&iter);
	argcount++;

	switch (argtype) {
	case DBUS_TYPE_BOOLEAN:
		dbus_message_iter_get_basic(&iter, &boolval);
		uintval = (boolval == TRUE) ? 1 : 0;
		break;

	case DBUS_TYPE_UINT32:
		dbus_message_iter_get_basic(&iter, &uintval);

		if (uintval > 2) {
			mce_log(LL_ERR,
				"Incorrect powerkey event passed to %s.%s; "
				"ignoring request",
				MCE_REQUEST_IF, MCE_TRIGGER_POWERKEY_EVENT_REQ);
			goto EXIT;
		}

		break;

	default:
		mce_log(LL_ERR,
			"Argument %d passed to %s.%s has incorrect type",
			argcount,
			MCE_REQUEST_IF, MCE_TRIGGER_POWERKEY_EVENT_REQ);
		goto EXIT;
	}

	while (dbus_message_iter_next(&iter) == TRUE)
		argcount++;

	if (argcount > 1) {
		mce_log(LL_WARN,
			"Too many arguments passed to %s.%s; "
			"got %d, expected %d -- ignoring extra arguments",
			MCE_REQUEST_IF, MCE_TRIGGER_POWERKEY_EVENT_REQ,
			argcount, 1);
	}

	mce_log(LL_DEBUG, "[power] button event trigger value: %d", uintval);

	cancel_powerkey_timeout();
	cancel_doublepress_timeout();

	switch (uintval) {
	default:
	case 0:
		/* short press */
		generic_powerkey_handler(shortpressaction,
					 shortpresssignal);
		break;

	case 1:
		/* long press */
		handle_longpress();
		break;

	case 2:
		/* double press */
		generic_powerkey_handler(doublepressaction,
					 doublepresssignal);
		break;
	}

	if (no_reply == FALSE) {
		DBusMessage *reply = dbus_new_method_reply(msg);

		status = dbus_send_message(reply);
	} else {
		status = TRUE;
	}

EXIT:
	return status;
}
コード例 #26
0
ファイル: signalrecv.c プロジェクト: Airead/excise
void listen_signal()
{
    DBusMessage *msg;
    DBusMessageIter arg;
    DBusConnection *connection;
    DBusError err;
    int ret;
    char *sigvalue;

    //step 1. connect DBus
    dbus_error_init(&err);
    connection = dbus_bus_get(DBUS_BUS_SESSION, &err);
    if (dbus_error_is_set(&err)) {
        fprintf(stderr, "Connection Error %s\n", err.message);
        dbus_error_free(&err);
    }
    if (connection == NULL) {
        return;
    }

    //step 2. [OPTION] Assign a known name for connection
    ret = dbus_bus_request_name(connection, "test.singal.dest", DBUS_NAME_FLAG_REPLACE_EXISTING, &err);
    if (dbus_error_is_set(&err)) {
        fprintf(stderr, "Name Error %s\n", err.message);
        dbus_error_free(&err);
    }
    if (ret != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) {
        return ;
    }

    //step 3. Notify DBus daemon, listen test.signal.Type signal
    dbus_bus_add_match(connection, "type='signal', interface='test.signal.Type'", &err);
    dbus_connection_flush(connection);
    if (dbus_error_is_set(&err)) {
        fprintf(stderr, "Match Error %s\n", err.message);
        dbus_error_free(&err);
    }

    //step 4. listen in loop per 1s.
    while (1) {
        dbus_connection_read_write(connection, 0);
        msg = dbus_connection_pop_message(connection);
        if (msg == NULL) {
            sleep(1);
            continue;
        }

        if (dbus_message_is_signal(msg, "test.signal.Type", "Test")) {
            if (!dbus_message_iter_init(msg, &arg)) {
                fprintf(stderr, "Message Has no Param");
            } else if (dbus_message_iter_get_arg_type(&arg) != DBUS_TYPE_STRING) {
                g_printerr("Param is not string");
            } else {
                dbus_message_iter_get_basic(&arg, &sigvalue);
                printf("Got singal with value: %s\n", sigvalue);
            }
        }
    
        dbus_message_unref(msg);

    }//End of while
}
コード例 #27
0
bool
ShouldA11yBeEnabled()
{
  static bool sChecked = false, sShouldEnable = false;
  if (sChecked)
    return sShouldEnable;

  sChecked = true;

  EPlatformDisabledState disabledState = PlatformDisabledState();
  if (disabledState == ePlatformIsDisabled)
    return sShouldEnable = false;

  // check if accessibility enabled/disabled by environment variable
  const char* envValue = PR_GetEnv(sAccEnv);
  if (envValue)
    return sShouldEnable = !!atoi(envValue);

#ifdef MOZ_ENABLE_DBUS
  PreInit();
  bool dbusSuccess = false;
  DBusMessage *reply = nullptr;
  if (!sPendingCall)
    goto dbus_done;

  dbus_pending_call_block(sPendingCall);
  reply = dbus_pending_call_steal_reply(sPendingCall);
  dbus_pending_call_unref(sPendingCall);
  sPendingCall = nullptr;
  if (!reply ||
      dbus_message_get_type(reply) != DBUS_MESSAGE_TYPE_METHOD_RETURN ||
      strcmp(dbus_message_get_signature (reply), DBUS_TYPE_VARIANT_AS_STRING))
    goto dbus_done;

  DBusMessageIter iter, iter_variant, iter_struct;
  dbus_bool_t dResult;
  dbus_message_iter_init(reply, &iter);
  dbus_message_iter_recurse (&iter, &iter_variant);
  switch (dbus_message_iter_get_arg_type(&iter_variant)) {
    case DBUS_TYPE_STRUCT:
      // at-spi2-core 2.2.0-2.2.1 had a bug where it returned a struct
      dbus_message_iter_recurse(&iter_variant, &iter_struct);
      if (dbus_message_iter_get_arg_type(&iter_struct) == DBUS_TYPE_BOOLEAN) {
        dbus_message_iter_get_basic(&iter_struct, &dResult);
        sShouldEnable = dResult;
        dbusSuccess = true;
      }

      break;
    case DBUS_TYPE_BOOLEAN:
      dbus_message_iter_get_basic(&iter_variant, &dResult);
      sShouldEnable = dResult;
      dbusSuccess = true;
      break;
    default:
      break;
  }

dbus_done:
  if (reply)
    dbus_message_unref(reply);

  if (dbusSuccess)
    return sShouldEnable;
#endif

  //check gconf-2 setting
static const char sGconfAccessibilityKey[] =
    "/desktop/gnome/interface/accessibility";
  nsresult rv = NS_OK;
  nsCOMPtr<nsIGConfService> gconf =
    do_GetService(NS_GCONFSERVICE_CONTRACTID, &rv);
  if (NS_SUCCEEDED(rv) && gconf)
    gconf->GetBool(NS_LITERAL_CSTRING(sGconfAccessibilityKey), &sShouldEnable);

  return sShouldEnable;
}
コード例 #28
0
ファイル: dbus.c プロジェクト: Mleaf/dnsmasq
static DBusMessage *dbus_add_lease(DBusMessage* message)
{
  struct dhcp_lease *lease;
  const char *ipaddr, *hwaddr, *hostname, *tmp;
  const unsigned char* clid;
  int clid_len, hostname_len, hw_len, hw_type;
  dbus_uint32_t expires, ia_id;
  dbus_bool_t is_temporary;
  struct all_addr addr;
  time_t now = dnsmasq_time();
  unsigned char dhcp_chaddr[DHCP_CHADDR_MAX];

  DBusMessageIter iter, array_iter;
  if (!dbus_message_iter_init(message, &iter))
    return dbus_message_new_error(message, DBUS_ERROR_INVALID_ARGS,
				  "Failed to initialize dbus message iter");

  if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING)
    return dbus_message_new_error(message, DBUS_ERROR_INVALID_ARGS,
				  "Expected string as first argument");

  dbus_message_iter_get_basic(&iter, &ipaddr);
  dbus_message_iter_next(&iter);

  if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING)
    return dbus_message_new_error(message, DBUS_ERROR_INVALID_ARGS,
				  "Expected string as second argument");
    
  dbus_message_iter_get_basic(&iter, &hwaddr);
  dbus_message_iter_next(&iter);

  if ((dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_ARRAY) ||
      (dbus_message_iter_get_element_type(&iter) != DBUS_TYPE_BYTE))
    return dbus_message_new_error(message, DBUS_ERROR_INVALID_ARGS,
				  "Expected byte array as third argument");
    
  dbus_message_iter_recurse(&iter, &array_iter);
  dbus_message_iter_get_fixed_array(&array_iter, &hostname, &hostname_len);
  tmp = memchr(hostname, '\0', hostname_len);
  if (tmp)
    {
      if (tmp == &hostname[hostname_len - 1])
	hostname_len--;
      else
	return dbus_message_new_error(message, DBUS_ERROR_INVALID_ARGS,
				      "Hostname contains an embedded NUL character");
    }
  dbus_message_iter_next(&iter);

  if ((dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_ARRAY) ||
      (dbus_message_iter_get_element_type(&iter) != DBUS_TYPE_BYTE))
    return dbus_message_new_error(message, DBUS_ERROR_INVALID_ARGS,
				  "Expected byte array as fourth argument");

  dbus_message_iter_recurse(&iter, &array_iter);
  dbus_message_iter_get_fixed_array(&array_iter, &clid, &clid_len);
  dbus_message_iter_next(&iter);

  if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_UINT32)
    return dbus_message_new_error(message, DBUS_ERROR_INVALID_ARGS,
				  "Expected uint32 as fifth argument");
    
  dbus_message_iter_get_basic(&iter, &expires);
  dbus_message_iter_next(&iter);

  if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_UINT32)
    return dbus_message_new_error(message, DBUS_ERROR_INVALID_ARGS,
                                    "Expected uint32 as sixth argument");
  
  dbus_message_iter_get_basic(&iter, &ia_id);
  dbus_message_iter_next(&iter);

  if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_BOOLEAN)
    return dbus_message_new_error(message, DBUS_ERROR_INVALID_ARGS,
				  "Expected uint32 as sixth argument");

  dbus_message_iter_get_basic(&iter, &is_temporary);

  if (inet_pton(AF_INET, ipaddr, &addr.addr.addr4))
    {
      if (ia_id != 0 || is_temporary)
	return dbus_message_new_error(message, DBUS_ERROR_INVALID_ARGS,
				      "ia_id and is_temporary must be zero for IPv4 lease");
      
      if (!(lease = lease_find_by_addr(addr.addr.addr4)))
    	lease = lease4_allocate(addr.addr.addr4);
    }
#ifdef HAVE_DHCP6
  else if (inet_pton(AF_INET6, ipaddr, &addr.addr.addr6))
    {
      if (!(lease = lease6_find_by_addr(&addr.addr.addr6, 128, 0)))
	lease = lease6_allocate(&addr.addr.addr6,
				is_temporary ? LEASE_TA : LEASE_NA);
      lease_set_iaid(lease, ia_id);
    }
#endif
  else
    return dbus_message_new_error_printf(message, DBUS_ERROR_INVALID_ARGS,
					 "Invalid IP address '%s'", ipaddr);
   
  hw_len = parse_hex((char*)hwaddr, dhcp_chaddr, DHCP_CHADDR_MAX, NULL,
		     &hw_type);
  if (hw_type == 0 && hw_len != 0)
    hw_type = ARPHRD_ETHER;

    lease_set_hwaddr(lease, dhcp_chaddr, clid, hw_len, hw_type,
                   clid_len, now, 0);
  lease_set_expires(lease, expires, now);
  if (hostname_len != 0)
    lease_set_hostname(lease, hostname, 0, get_domain(lease->addr), NULL);
    
  lease_update_file(now);
  lease_update_dns(0);

  return NULL;
}
/**
 * wpas_dbus_handler_wps_start - Start WPS configuration
 * @message: Pointer to incoming dbus message
 * @wpa_s: %wpa_supplicant data structure
 * Returns: DBus message dictionary on success or DBus error on failure
 *
 * Handler for "Start" method call. DBus dictionary argument contains
 * information about role (enrollee or registrar), authorization method
 * (pin or push button) and optionally pin and bssid. Returned message
 * has a dictionary argument which may contain newly generated pin (optional).
 */
DBusMessage * wpas_dbus_handler_wps_start(DBusMessage *message,
					  struct wpa_supplicant *wpa_s)
{
	DBusMessage *reply = NULL;
	DBusMessageIter iter, dict_iter, entry_iter;
	struct wps_start_params params;
	char *key;
	char npin[9] = { '\0' };
	int ret;

	os_memset(&params, 0, sizeof(params));
	dbus_message_iter_init(message, &iter);

	dbus_message_iter_recurse(&iter, &dict_iter);
	while (dbus_message_iter_get_arg_type(&dict_iter) ==
	       DBUS_TYPE_DICT_ENTRY) {
		dbus_message_iter_recurse(&dict_iter, &entry_iter);

		dbus_message_iter_get_basic(&entry_iter, &key);
		dbus_message_iter_next(&entry_iter);

		if (wpas_dbus_handler_wps_start_entry(message, key,
						      &entry_iter,
						      &params, &reply))
			return reply;

		dbus_message_iter_next(&dict_iter);
	}

#ifdef CONFIG_AP
	if (wpa_s->ap_iface && params.type == 1) {
		if (params.pin == NULL) {
			wpa_printf(MSG_DEBUG,
				   "dbus: WPS.Start - Pin required for registrar role");
			return wpas_dbus_error_invalid_args(
				message, "Pin required for registrar role.");
		}
		ret = wpa_supplicant_ap_wps_pin(wpa_s,
						params.bssid,
						params.pin,
						npin, sizeof(npin), 0);
	} else if (wpa_s->ap_iface) {
		ret = wpa_supplicant_ap_wps_pbc(wpa_s,
						params.bssid,
						params.p2p_dev_addr);
	} else
#endif /* CONFIG_AP */
	if (params.role == 0) {
		wpa_printf(MSG_DEBUG, "dbus: WPS.Start - Role not specified");
		return wpas_dbus_error_invalid_args(message,
						    "Role not specified");
	} else if (params.role == 2) {
		if (params.pin == NULL) {
			wpa_printf(MSG_DEBUG,
				   "dbus: WPS.Start - Pin required for registrar role");
			return wpas_dbus_error_invalid_args(
				message, "Pin required for registrar role.");
		}
		ret = wpas_wps_start_reg(wpa_s, params.bssid, params.pin,
					 NULL);
	} else if (params.type == 0) {
		wpa_printf(MSG_DEBUG, "dbus: WPS.Start - Type not specified");
		return wpas_dbus_error_invalid_args(message,
						    "Type not specified");
	} else if (params.type == 1) {
		ret = wpas_wps_start_pin(wpa_s, params.bssid,
					 params.pin, 0,
					 DEV_PW_DEFAULT);
		if (ret > 0)
			os_snprintf(npin, sizeof(npin), "%08d", ret);
	} else {
		ret = wpas_wps_start_pbc(wpa_s, params.bssid, 0);
	}

	if (ret < 0) {
		wpa_printf(MSG_DEBUG,
			   "dbus: WPS.Start wpas_wps_failed in role %s and key %s",
			   (params.role == 1 ? "enrollee" : "registrar"),
			   (params.type == 0 ? "" :
			    (params.type == 1 ? "pin" : "pbc")));
		return wpas_dbus_error_unknown_error(message,
						     "WPS start failed");
	}

	reply = dbus_message_new_method_return(message);
	if (!reply)
		return wpas_dbus_error_no_memory(message);

	dbus_message_iter_init_append(reply, &iter);
	if (!wpa_dbus_dict_open_write(&iter, &dict_iter) ||
	    (os_strlen(npin) > 0 &&
	     !wpa_dbus_dict_append_string(&dict_iter, "Pin", npin)) ||
	    !wpa_dbus_dict_close_write(&iter, &dict_iter)) {
		dbus_message_unref(reply);
		return wpas_dbus_error_no_memory(message);
	}

	return reply;
}
コード例 #30
0
ファイル: timedatectl.c プロジェクト: felipec/udev-fc
static int show_status(DBusConnection *bus, char **args, unsigned n) {
        _cleanup_dbus_message_unref_ DBusMessage *reply = NULL;
        const char *interface = "";
        int r;
        DBusMessageIter iter, sub, sub2, sub3;
        StatusInfo info;

        assert(args);

        r = bus_method_call_with_reply(
                        bus,
                        "org.freedesktop.timedate1",
                        "/org/freedesktop/timedate1",
                        "org.freedesktop.DBus.Properties",
                        "GetAll",
                        &reply,
                        NULL,
                        DBUS_TYPE_STRING, &interface,
                        DBUS_TYPE_INVALID);
        if (r < 0)
                return r;

        if (!dbus_message_iter_init(reply, &iter) ||
            dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_ARRAY ||
            dbus_message_iter_get_element_type(&iter) != DBUS_TYPE_DICT_ENTRY)  {
                log_error("Failed to parse reply.");
                return -EIO;
        }

        zero(info);
        dbus_message_iter_recurse(&iter, &sub);

        while (dbus_message_iter_get_arg_type(&sub) != DBUS_TYPE_INVALID) {
                const char *name;

                if (dbus_message_iter_get_arg_type(&sub) != DBUS_TYPE_DICT_ENTRY) {
                        log_error("Failed to parse reply.");
                        return -EIO;
                }

                dbus_message_iter_recurse(&sub, &sub2);

                if (bus_iter_get_basic_and_next(&sub2, DBUS_TYPE_STRING, &name, true) < 0) {
                        log_error("Failed to parse reply.");
                        return -EIO;
                }

                if (dbus_message_iter_get_arg_type(&sub2) != DBUS_TYPE_VARIANT)  {
                        log_error("Failed to parse reply.");
                        return -EIO;
                }

                dbus_message_iter_recurse(&sub2, &sub3);

                r = status_property(name, &sub3, &info);
                if (r < 0) {
                        log_error("Failed to parse reply.");
                        return r;
                }

                dbus_message_iter_next(&sub);
        }

        print_status_info(&info);
        return 0;
}