Beispiel #1
0
static int cdbus_del_snap_unpack(DBusConnection *conn,
				 DBusMessage *rsp_msg)
{
	int msg_type;
	const char *sig;

	msg_type = dbus_message_get_type(rsp_msg);
	if (msg_type == DBUS_MESSAGE_TYPE_ERROR) {
		fprintf(stderr, "del snap error response: %s\n",
			dbus_message_get_error_name(rsp_msg));
		return -EINVAL;
	}

	if (msg_type != DBUS_MESSAGE_TYPE_METHOD_RETURN) {
		fprintf(stderr, "unexpected del snap ret type: %d\n",
			msg_type);
		return -EINVAL;
	}

	sig = dbus_message_get_signature(rsp_msg);
	if ((sig == NULL)
	 || (strcmp(sig, CDBUS_SIG_DEL_SNAPS_RSP) != 0)) {
		fprintf(stderr, "bad del snap response sig: %s, "
				"expected: %s\n",
			(sig ? sig : "NULL"), CDBUS_SIG_DEL_SNAPS_RSP);
		return -EINVAL;
	}

	/* no parameters in response */

	return 0;
}
static DBusMessage * properties_get(DBusMessage *message,
				    const struct wpa_dbus_property_desc *dsc,
				    void *user_data)
{
	DBusMessage *reply;
	DBusMessageIter iter;
	DBusError error;

	if (os_strcmp(dbus_message_get_signature(message), "ss")) {
		return dbus_message_new_error(message, DBUS_ERROR_INVALID_ARGS,
					      NULL);
	}

	if (dsc->getter == NULL) {
		return dbus_message_new_error(message, DBUS_ERROR_INVALID_ARGS,
					      "Property is write-only");
	}

	reply = dbus_message_new_method_return(message);
	dbus_message_iter_init_append(reply, &iter);

	dbus_error_init(&error);
	if (dsc->getter(&iter, &error, user_data) == FALSE) {
		dbus_message_unref(reply);
		reply = wpas_dbus_reply_new_from_error(
			message, &error, DBUS_ERROR_FAILED,
			"Failed to read property");
		dbus_error_free(&error);
	}

	return reply;
}
static DBusHandlerResult
default_message_filter 
(   DBusConnection     *connection,
    DBusMessage        *message,
    void               *p
)
{
    DBusConnectionState *cs = p;
    uint32_t type  =dbus_message_get_type( message ),
	   serial  =dbus_message_get_serial( message );
    uint8_t  reply =dbus_message_get_no_reply( message )==0;
    const char 
	*path =    dbus_message_get_path( message ),
	*dest =    dbus_message_get_destination( message ),
	*member =  dbus_message_get_member( message ),
	*interface=dbus_message_get_interface( message ),
	*sender   =dbus_message_get_sender( message ),
	*signature=dbus_message_get_signature( message );
    connection = connection;
    if(cs->mf)
	return
	(*(cs->mf))( cs, type, reply, serial, dest, path, member, interface, 0L,
		    sender, signature, message, 0L, 0L, 0L, cs->def_mf_obj
	          ) ;
    return HANDLED;
}
Beispiel #4
0
static gboolean connection_added(DBusConnection *conn, DBusMessage *message,
				void *user_data)
{
	DBusMessageIter iter, properties;
	const char *path;
	const char *signature = DBUS_TYPE_OBJECT_PATH_AS_STRING
		DBUS_TYPE_ARRAY_AS_STRING
		DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
		DBUS_TYPE_STRING_AS_STRING
		DBUS_TYPE_VARIANT_AS_STRING
		DBUS_DICT_ENTRY_END_CHAR_AS_STRING;

	if (dbus_message_has_signature(message, signature) == FALSE) {
		connman_error("vpn ConnectionAdded signature \"%s\" does not "
						"match expected \"%s\"",
			dbus_message_get_signature(message), signature);
		return TRUE;
	}

	DBG("");

	if (dbus_message_iter_init(message, &iter) == FALSE)
		return TRUE;

	dbus_message_iter_get_basic(&iter, &path);

	dbus_message_iter_next(&iter);
	dbus_message_iter_recurse(&iter, &properties);

	add_connection(path, &properties, user_data);

	return TRUE;
}
static GPtrArray *
get_object_array_and_unref (DBusMessage *reply)
{
  DBusMessageIter iter, iter_array;
  GPtrArray *array;

  if (!reply)
    return NULL;

  if (strcmp (dbus_message_get_signature (reply), "(so)") != 0)
  {
    dbus_message_unref (reply);
    return NULL;
  }

  array = g_ptr_array_new ();

  dbus_message_iter_init (reply, &iter);
  dbus_message_iter_recurse (&iter, &iter_array);
  while (dbus_message_iter_get_arg_type (&iter_array) != DBUS_TYPE_INVALID)
  {
    AtspiAccessible *accessible = _atspi_dbus_return_accessible_from_iter (&iter_array);
    g_ptr_array_add (array, accessible);
  }
  dbus_message_unref (reply);
  return array;
}
Beispiel #6
0
static DBusHandlerResult
signal_handler(lua_State *S, DBusMessage *msg)
{
	lua_State *T;
	const char *path = dbus_message_get_path(msg);
	const char *interface = dbus_message_get_interface(msg);
	const char *member = dbus_message_get_member(msg);

	lem_debug("received signal\n  %s\n  %s\n  %s(%s)",
	          path, interface, member,
	          dbus_message_get_signature(msg));

	/* NOTE: this magic string representation of an
	 * incoming signal must match the one in the Lua code */
	lua_pushfstring(S, "%s\n%s\n%s",
	                path      ? path      : "",
	                interface ? interface : "",
	                member    ? member    : "");

	lua_rawget(S, LEM_DBUS_SIGNAL_TABLE);
	if (lua_type(S, -1) != LUA_TFUNCTION) {
		lua_settop(S, LEM_DBUS_TOP);
		return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
	}

	/* create new thread */
	T = lem_newthread();
	lua_xmove(S, T, 1);

	lem_queue(T, lem_dbus_push_arguments(T, msg));

	return DBUS_HANDLER_RESULT_HANDLED;
}
/**
 * wpas_dbus_iface_select_network - Attempt association with a configured network
 * @message: Pointer to incoming dbus message
 * @wpa_s: wpa_supplicant structure for a network interface
 * Returns: A dbus message containing a UINT32 indicating success (1) or
 *          failure (0)
 *
 * Handler function for "selectNetwork" method call of network interface.
 */
DBusMessage * wpas_dbus_iface_select_network(DBusMessage *message,
					     struct wpa_supplicant *wpa_s)
{
	DBusMessage *reply = NULL;
	const char *op;
	struct wpa_ssid *ssid;
	char *iface_obj_path = NULL;
	char *network = NULL;

	if (os_strlen(dbus_message_get_signature(message)) == 0) {
		/* Any network */
		ssid = NULL;
	} else {
		int nid;

		if (!dbus_message_get_args(message, NULL,
					   DBUS_TYPE_OBJECT_PATH, &op,
					   DBUS_TYPE_INVALID)) {
			reply = wpas_dbus_new_invalid_opts_error(message,
								 NULL);
			goto out;
		}

		/* Extract the network number */
		iface_obj_path = wpas_dbus_decompose_object_path(op,
								 &network,
								 NULL);
		if (iface_obj_path == NULL) {
			reply = wpas_dbus_new_invalid_iface_error(message);
			goto out;
		}
		/* Ensure the object path really points to this interface */
		if (os_strcmp(iface_obj_path, wpa_s->dbus_path) != 0) {
			reply = wpas_dbus_new_invalid_network_error(message);
			goto out;
		}

		nid = strtoul(network, NULL, 10);
		if (errno == EINVAL) {
			reply = wpas_dbus_new_invalid_network_error(message);
			goto out;
		}

		ssid = wpa_config_get_network(wpa_s->conf, nid);
		if (ssid == NULL) {
			reply = wpas_dbus_new_invalid_network_error(message);
			goto out;
		}
	}

	/* Finally, associate with the network */
	wpa_supplicant_select_network(wpa_s, ssid);

	reply = wpas_dbus_new_success_reply(message);

out:
	os_free(iface_obj_path);
	os_free(network);
	return reply;
}
static int is_signature_correct(DBusMessage *message,
				const struct wpa_dbus_method_desc *method_dsc)
{
	/* According to DBus documentation max length of signature is 255 */
#define MAX_SIG_LEN 256
	char registered_sig[MAX_SIG_LEN], *pos;
	const char *sig = dbus_message_get_signature(message);
	int ret;
	const struct wpa_dbus_argument *arg;

	pos = registered_sig;
	*pos = '\0';

	for (arg = method_dsc->args; arg && arg->name; arg++) {
		if (arg->dir == ARG_IN) {
			size_t blen = registered_sig + MAX_SIG_LEN - pos;
			ret = os_snprintf(pos, blen, "%s", arg->type);
			if (ret < 0 || (size_t) ret >= blen)
				return 0;
			pos += ret;
		}
	}

	return !os_strncmp(registered_sig, sig, MAX_SIG_LEN);
}
Beispiel #9
0
gboolean g_dbus_emit_signal_valist(DBusConnection *connection,
				const char *path, const char *interface,
				const char *name, int type, va_list args)
{
	DBusMessage *signal;
	dbus_bool_t ret;
	const GDBusArgInfo *args_info;

	if (!check_signal(connection, path, interface, name, &args_info))
		return FALSE;

	signal = dbus_message_new_signal(path, interface, name);
	if (signal == NULL) {
		error("Unable to allocate new %s.%s signal", interface,  name);
		return FALSE;
	}

	ret = dbus_message_append_args_valist(signal, type, args);
	if (!ret)
		goto fail;

	if (g_dbus_args_have_signature(args_info, signal) == FALSE) {
		error("%s.%s: got unexpected signature '%s'", interface, name,
					dbus_message_get_signature(signal));
		ret = FALSE;
		goto fail;
	}

	return g_dbus_send_message(connection, signal);

fail:
	dbus_message_unref(signal);

	return ret;
}
Beispiel #10
0
static inline DBusMessage* FcitxXkbDBusUnknownMethod(DBusMessage *msg)
{
    DBusMessage* reply = dbus_message_new_error_printf(msg,
                                                       DBUS_ERROR_UNKNOWN_METHOD,
                                                       "No such method with signature (%s)",
                                                       dbus_message_get_signature(msg));
    return reply;
}
Beispiel #11
0
static int cdbus_list_confs_call(DBusConnection *conn)
{
	int ret;
	DBusMessage *req_msg;
	DBusMessage *rsp_msg;
	DBusPendingCall *pending;
	uint32_t num_confs = 0;
	struct config *confs = NULL;
	const char *sig;

	ret = cdbus_list_confs_pack(&req_msg);
	if (ret < 0) {
		fprintf(stderr, "failed to pack list confs request\n");
		return ret;
	}

	ret = cdbus_msg_send(conn, req_msg, &pending);
	if (ret < 0) {
		dbus_message_unref(req_msg);
		return ret;
	}

	ret = cdbus_msg_recv(conn, pending, &rsp_msg);
	if (ret < 0) {
		dbus_message_unref(req_msg);
		dbus_pending_call_unref(pending);
		return ret;
	}

	sig = dbus_message_get_signature(rsp_msg);
	if ((sig == NULL)
	 || (strcmp(sig, CDBUS_SIG_LIST_CONFS_RSP) != 0)) {
		fprintf(stderr, "bad list confs response sig: %s, "
				"expected: %s\n",
			(sig ? sig : "NULL"), CDBUS_SIG_LIST_CONFS_RSP);
		dbus_message_unref(req_msg);
		dbus_message_unref(rsp_msg);
		return -EINVAL;
	}

	ret = cdbus_list_confs_unpack(conn, rsp_msg,
				      &num_confs, &confs);
	if (ret < 0) {
		fprintf(stderr, "failed to unpack list confs response\n");
		dbus_message_unref(req_msg);
		dbus_message_unref(rsp_msg);
		return ret;
	}

	conf_array_print(num_confs, confs);

	conf_array_free(num_confs, confs);

	dbus_message_unref(req_msg);
	dbus_message_unref(rsp_msg);

	return 0;
}
Beispiel #12
0
static void pid_query_result(DBusPendingCall *pend,
				void *user_data)
{
	char path[32];
	struct access_check *check = user_data;
	DBusMessage *reply = NULL;
	DBusMessageIter iter;
	dbus_uint32_t pid;
	struct stat st;
	guint name_watch;

	DBG("query for busname %s", check->busname);

	reply = dbus_pending_call_steal_reply(pend);
	if (!reply)
		goto done;

	if (!gid_hash)
		goto done;

	if (dbus_message_get_type(reply) == DBUS_MESSAGE_TYPE_ERROR)
		goto done;

	if (g_strcmp0(dbus_message_get_signature(reply), "u"))
		goto done;

	dbus_message_iter_init(reply, &iter);
	dbus_message_iter_get_basic(&iter, &pid);

	snprintf(path, sizeof(path), "/proc/%u", pid);
	if (stat(path, &st) < 0)
		goto done;

	DBG("query done, pid %d has gid %d", pid, st.st_gid);

	name_watch = g_dbus_add_disconnect_watch(check->connection, 
						check->busname,
						busname_exit_callback,
						g_strdup(check->busname),
						g_free);

	g_hash_table_replace(watch_hash, g_strdup(check->busname),
				GUINT_TO_POINTER(name_watch));
	g_hash_table_replace(gid_hash, g_strdup(check->busname),
				GINT_TO_POINTER(st.st_gid));

	if (gid_is_authorized(st.st_gid)) {
		DBG("allowing access for pid %d, pending %u",
			pid, check->pending);
		g_dbus_pending_success(check->connection, check->pending);
		check->pending_unanswered = FALSE;
	}

done:
	if (reply)
		dbus_message_unref(reply);
	dbus_pending_call_unref(pend);
}
static DBusMessage * properties_get_all(DBusMessage *message, char *interface,
					struct wpa_dbus_object_desc *obj_dsc)
{
	if (os_strcmp(dbus_message_get_signature(message), "s") != 0)
		return dbus_message_new_error(message, DBUS_ERROR_INVALID_ARGS,
					      NULL);

	return get_all_properties(message, interface, obj_dsc);
}
Beispiel #14
0
bool
ladish_room_proxy_get_recent_projects(
    ladish_room_proxy_handle proxy,
    uint16_t max_items,
    void (* callback)(
        void * context,
        const char * project_name,
        const char * project_dir),
    void * context)
{
    DBusMessage * reply_ptr;
    const char * reply_signature;
    DBusMessageIter top_iter;
    DBusMessageIter struct_iter;
    DBusMessageIter array_iter;
    const char * project_dir;
    const char * project_name;

    if (!cdbus_call(0, proxy_ptr->service, proxy_ptr->object, IFACE_RECENT_ITEMS, "get", "q", &max_items, NULL, &reply_ptr))
    {
        log_error("GetStudioList() failed.");
        return false;
    }

    reply_signature = dbus_message_get_signature(reply_ptr);
    if (strcmp(reply_signature, "a(sa{sv})") != 0)
    {
        log_error("GetStudioList() reply signature mismatch. '%s'", reply_signature);
        dbus_message_unref(reply_ptr);
        return false;
    }

    dbus_message_iter_init(reply_ptr, &top_iter);
    for (dbus_message_iter_recurse(&top_iter, &array_iter);
            dbus_message_iter_get_arg_type(&array_iter) != DBUS_TYPE_INVALID;
            dbus_message_iter_next(&array_iter))
    {
        dbus_message_iter_recurse(&array_iter, &struct_iter);
        dbus_message_iter_get_basic(&struct_iter, &project_dir);
        dbus_message_iter_next(&struct_iter);

        if (!cdbus_iter_get_dict_entry_string(&struct_iter, "name", &project_name))
        {
            project_name = NULL;
        }

        callback(context, project_name != NULL ? project_name : project_dir, project_dir);

        dbus_message_iter_next(&struct_iter);
    }

    dbus_message_unref(reply_ptr);
    return true;
}
Beispiel #15
0
static int ldbus_message_get_signature(lua_State *L) {
	DBusMessage *message = check_DBusMessage(L, 1);

	const char * signature = dbus_message_get_signature(message);
	if (signature == NULL) {
		lua_pushnil(L);
	} else {
		lua_pushstring(L, signature);
	}

	return 1;
}
/**
 * message_handler - Handles incoming DBus messages
 * @connection: DBus connection on which message was received
 * @message: Received message
 * @user_data: pointer to description of object to which message was sent
 * Returns: Returns information whether message was handled or not
 *
 * Reads message interface and method name, then checks if they matches one
 * of the special cases i.e. introspection call or properties get/getall/set
 * methods and handles it. Else it iterates over registered methods list
 * and tries to match method's name and interface to those read from message
 * If appropriate method was found its handler function is called and
 * response is sent. Otherwise, the DBUS_ERROR_UNKNOWN_METHOD error message
 * will be sent.
 */
static DBusHandlerResult message_handler(DBusConnection *connection,
					 DBusMessage *message, void *user_data)
{
	struct wpa_dbus_object_desc *obj_dsc = user_data;
	const char *method;
	const char *path;
	const char *msg_interface;
	DBusMessage *reply;

	/* get method, interface and path the message is addressed to */
	method = dbus_message_get_member(message);
	path = dbus_message_get_path(message);
	msg_interface = dbus_message_get_interface(message);
	if (!method || !path || !msg_interface)
		return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;

	wpa_printf(MSG_MSGDUMP, "dbus: %s.%s (%s) [%s]",
		   msg_interface, method, path,
		   dbus_message_get_signature(message));

	/* if message is introspection method call */
	if (!os_strncmp(WPA_DBUS_INTROSPECTION_METHOD, method,
			WPAS_DBUS_METHOD_SIGNAL_PROP_MAX) &&
	    !os_strncmp(WPA_DBUS_INTROSPECTION_INTERFACE, msg_interface,
			WPAS_DBUS_INTERFACE_MAX)) {
#ifdef CONFIG_CTRL_IFACE_DBUS_INTRO
		reply = wpa_dbus_introspect(message, obj_dsc);
#else /* CONFIG_CTRL_IFACE_DBUS_INTRO */
		reply = dbus_message_new_error(
			message, DBUS_ERROR_UNKNOWN_METHOD,
			"wpa_supplicant was compiled without introspection support.");
#endif /* CONFIG_CTRL_IFACE_DBUS_INTRO */
	} else if (!os_strncmp(WPA_DBUS_PROPERTIES_INTERFACE, msg_interface,
			     WPAS_DBUS_INTERFACE_MAX)) {
		/* if message is properties method call */
		reply = properties_handler(message, obj_dsc);
	} else {
		reply = msg_method_handler(message, obj_dsc);
	}

	/* If handler succeed returning NULL, reply empty message */
	if (!reply)
		reply = dbus_message_new_method_return(message);
	if (reply) {
		if (!dbus_message_get_no_reply(message))
			dbus_connection_send(connection, reply, NULL);
		dbus_message_unref(reply);
	}

	wpa_dbus_flush_all_changed_properties(connection);

	return DBUS_HANDLER_RESULT_HANDLED;
}
Beispiel #17
0
const char *pa_dbus_get_error_message(DBusMessage *m) {
    const char *message;

    pa_assert(m);
    pa_assert(dbus_message_get_type(m) == DBUS_MESSAGE_TYPE_ERROR);

    if (dbus_message_get_signature(m)[0] != 's')
        return "<no explanation>";

    pa_assert_se(dbus_message_get_args(m, NULL, DBUS_TYPE_STRING, &message, DBUS_TYPE_INVALID));

    return message;
}
Beispiel #18
0
static DBusHandlerResult
method_call_handler(lua_State *S, DBusMessage *msg)
{
	lua_State *T;
	struct message_object *m;
	const char *path = dbus_message_get_path(msg);
	const char *interface = dbus_message_get_interface(msg);
	const char *member = dbus_message_get_member(msg);

	lem_debug("received call\n  %s\n  %s\n  %s(%s)",
	          path, interface, member,
		  dbus_message_get_signature(msg));

	lua_pushstring(S, path ? path : "");
	lua_rawget(S, LEM_DBUS_OBJECT_TABLE);
	if (lua_type(S, -1) != LUA_TTABLE) {
		lua_settop(S, LEM_DBUS_TOP);
		return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
	}

	lua_pushfstring(S, "%s.%s",
	                interface ? interface : "",
	                member    ? member    : "");
	lua_rawget(S, -2);
	if (lua_type(S, -1) != LUA_TFUNCTION) {
		lua_settop(S, LEM_DBUS_TOP);
		return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
	}

	/* create new thread */
	T = lem_newthread();
	lua_pushvalue(S, LEM_DBUS_BUS_OBJECT);
	lua_xmove(S, T, 2);
	lua_settop(S, LEM_DBUS_TOP);

	/* push the send_reply function */
	m = lua_newuserdata(T, sizeof(struct message_object));
	m->msg = msg;
	dbus_message_ref(msg);

	/* set metatable */
	lua_pushvalue(S, LEM_DBUS_MESSAGE_META);
	lua_xmove(S, T, 1);
	lua_setmetatable(T, -2);

	lua_pushcclosure(T, message_reply, 2);

	lem_queue(T, lem_dbus_push_arguments(T, msg) + 1);

	return DBUS_HANDLER_RESULT_HANDLED;
}
Beispiel #19
0
static int cdbus_list_confs_unpack(DBusConnection *conn,
				   DBusMessage *rsp_msg,
				   uint32_t *num_confs_out,
				   struct config **confs_out)
{
	int ret;
	DBusMessageIter iter;
	int msg_type;
	uint32_t num_confs;
	struct config *confs;
	const char *sig;

	msg_type = dbus_message_get_type(rsp_msg);
	if (msg_type == DBUS_MESSAGE_TYPE_ERROR) {
		fprintf(stderr, "list_confs error response: %s\n",
			dbus_message_get_error_name(rsp_msg));
		return -EINVAL;
	}

	if (msg_type != DBUS_MESSAGE_TYPE_METHOD_RETURN) {
		fprintf(stderr, "unexpected list_confs ret type: %d\n",
			msg_type);
		return -EINVAL;
	}

	sig = dbus_message_get_signature(rsp_msg);
	if ((sig == NULL)
	 || (strcmp(sig, CDBUS_SIG_LIST_CONFS_RSP) != 0)) {
		fprintf(stderr, "bad list confs response sig: %s, "
				"expected: %s\n",
			(sig ? sig : "NULL"), CDBUS_SIG_LIST_CONFS_RSP);
		return -EINVAL;
	}

	if (!dbus_message_iter_init(rsp_msg, &iter)) {
		/* FIXME return empty? */
		fprintf(stderr, "Message has no arguments!\n");
		return -EINVAL;
	}

	ret = conf_array_unpack(&iter, &num_confs, &confs);
	if (ret < 0) {
		fprintf(stderr, "failed to unpack conf array\n");
		return -EINVAL;
	}

	*num_confs_out = num_confs;
	*confs_out = confs;

	return 0;
}
Beispiel #20
0
DBusHandlerResult error_unknown_method(DBusConnection *conn, DBusMessage *msg)
{
	char error[128];
	const char *signature = dbus_message_get_signature(msg);
	const char *method = dbus_message_get_member(msg);
	const char *interface = dbus_message_get_interface(msg);

	snprintf(error, 128, "Method \"%s\" with signature \"%s\" on interface \"%s\" doesn't exist",
			method, signature, interface);

	return send_message_and_unref(conn,
		dbus_message_new_error(msg, ERROR_INTERFACE ".UnknownMethod",
							error));
}
Beispiel #21
0
static DBusMessage *oem_raw_make_request(DBusConnection *conn,
					 DBusMessage *msg, void *data)
{
	char *array; /* Byte array containing client request*/
	int array_len; /* Length of request byte array */
	DBusMessageIter iter;
	DBusMessageIter subiter;
	struct ofono_oem_raw_request *req;
	struct ofono_oem_raw *raw;
	raw = data;
	req = 0;

	if (raw && raw->driver->request == NULL)
		return __ofono_error_not_implemented(msg);

	dbus_message_iter_init(msg, &iter);

	if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_ARRAY)
		goto error_arg;

	if (dbus_message_iter_get_element_type(&iter) != DBUS_TYPE_BYTE) {
		DBG("Ignoring request because dbus request element type=%c",
		    dbus_message_iter_get_element_type(&iter));
		goto error_arg;
	}

	dbus_message_iter_recurse(&iter, &subiter);

	dbus_message_iter_get_fixed_array(&subiter, &array, &array_len);

	req = g_new0(struct ofono_oem_raw_request, 1);
	req->data = array;
	req->length = array_len;
	/* Store msg to request struct to allow multiple parallel requests */
	req->pending = dbus_message_ref(msg);
	raw->driver->request(raw, req, ofono_oem_raw_query_cb, req);

	return NULL;

error_arg:
	DBG("DBus arg type=%c, msg signature: %s",
		dbus_message_iter_get_arg_type(&iter),
		dbus_message_get_signature(msg));
	return __ofono_error_invalid_args(msg);
}
Beispiel #22
0
static gboolean connection_removed(DBusConnection *conn, DBusMessage *message,
				void *user_data)
{
	const char *path;
	const char *signature = DBUS_TYPE_OBJECT_PATH_AS_STRING;

	if (dbus_message_has_signature(message, signature) == FALSE) {
		connman_error("vpn removed signature \"%s\" does not match "
							"expected \"%s\"",
			dbus_message_get_signature(message), signature);
		return TRUE;
	}

	dbus_message_get_args(message, NULL, DBUS_TYPE_OBJECT_PATH, &path,
				DBUS_TYPE_INVALID);
	remove_connection(conn, path);
	return TRUE;
}
Beispiel #23
0
static void
method_return_handler(DBusPendingCall *pending, void *data)
{
	lua_State *T = data;
	DBusMessage *msg = dbus_pending_call_steal_reply(pending);
	int nargs;

	dbus_pending_call_unref(pending);

	lem_debug("received return(%s)", dbus_message_get_signature(msg));

	if (msg == NULL) {
		lua_pushnil(T);
		lua_pushliteral(T, "null reply");
		nargs = 2;
	} else {
		switch (dbus_message_get_type(msg)) {
		case DBUS_MESSAGE_TYPE_METHOD_RETURN:
			nargs = lem_dbus_push_arguments(T, msg);
			break;

		case DBUS_MESSAGE_TYPE_ERROR:
			lua_pushnil(T);
			{
				DBusError err;

				dbus_error_init(&err);
				dbus_set_error_from_message(&err, msg);
				lua_pushstring(T, err.message);
				dbus_error_free(&err);
			}
			nargs = 2;
			break;

		default:
			lua_pushnil(T);
			lua_pushliteral(T, "unknown reply");
			nargs = 2;
		}
		dbus_message_unref(msg);
	}

	lem_queue(T, nargs);
}
/**
 * wpas_dbus_iface_flush - Clear BSS of old or all inactive entries
 * @message: Pointer to incoming dbus message
 * @wpa_s: %wpa_supplicant data structure
 * Returns: a dbus message containing a UINT32 indicating success (1) or
 *          failure (0), or returns a dbus error message with more information
 *
 * Handler function for "flush" method call. Handles requests for an
 * interface with an optional "age" parameter that specifies the minimum
 * age of a BSS to be flushed.
 */
DBusMessage * wpas_dbus_iface_flush(DBusMessage *message,
				    struct wpa_supplicant *wpa_s)
{
	int flush_age = 0;

	if (os_strlen(dbus_message_get_signature(message)) != 0 &&
	    !dbus_message_get_args(message, NULL,
				   DBUS_TYPE_INT32, &flush_age,
				   DBUS_TYPE_INVALID)) {
		return wpas_dbus_new_invalid_opts_error(message, NULL);
	}

	if (flush_age == 0)
		wpa_bss_flush(wpa_s);
	else
		wpa_bss_flush_by_age(wpa_s, flush_age);

	return wpas_dbus_new_success_reply(message);
}
Beispiel #25
0
static bool check_reply_has_dict(DBusMessage *reply)
{
	const char *signature = DBUS_TYPE_ARRAY_AS_STRING
		DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
		DBUS_TYPE_STRING_AS_STRING
		DBUS_TYPE_VARIANT_AS_STRING
		DBUS_DICT_ENTRY_END_CHAR_AS_STRING;

	if (dbus_message_has_signature(reply, signature))
		return true;

	connman_warn("Reply %s to %s from %s has wrong signature %s",
			signature,
			dbus_message_get_interface(reply),
			dbus_message_get_sender(reply),
			dbus_message_get_signature(reply));

	return false;
}
Beispiel #26
0
static int cdbus_create_snap_unpack(DBusConnection *conn,
				    DBusMessage *rsp_msg,
				    uint32_t *snap_id_out)
{
	DBusMessageIter iter;
	int msg_type;
	const char *sig;

	msg_type = dbus_message_get_type(rsp_msg);
	if (msg_type == DBUS_MESSAGE_TYPE_ERROR) {
		fprintf(stderr, "create snap error response: %s\n",
			dbus_message_get_error_name(rsp_msg));
		return -EINVAL;
	}

	if (msg_type != DBUS_MESSAGE_TYPE_METHOD_RETURN) {
		fprintf(stderr, "unexpected create snap ret type: %d\n",
			msg_type);
		return -EINVAL;
	}

	sig = dbus_message_get_signature(rsp_msg);
	if ((sig == NULL)
	 || (strcmp(sig, CDBUS_SIG_CREATE_SNAP_RSP) != 0)) {
		fprintf(stderr, "bad create snap response sig: %s, "
				"expected: %s\n",
			(sig ? sig : "NULL"), CDBUS_SIG_CREATE_SNAP_RSP);
		return -EINVAL;
	}

	/* read the parameters */
	if (!dbus_message_iter_init(rsp_msg, &iter)) {
		fprintf(stderr, "Message has no arguments!\n");
		return -EINVAL;
	}

	if (cdbus_type_check_get(&iter, DBUS_TYPE_UINT32, snap_id_out)) {
		return -EINVAL;
	}

	return 0;
}
Beispiel #27
0
static void
atspi_plug_component_get_extents (AtkComponent *component, gint *x, gint *y,
                                  gint *width, gint *height,
                                  AtkCoordType coord_type)
{
  DBusMessage *message = new_socket_call_message (component, "GetExtents");
  DBusMessage *reply;
  dbus_uint32_t coord_type_dbus = coord_type;
  DBusError error;
  const char *signature;
  DBusMessageIter iter, iter_struct;
  dbus_int32_t tmp;

  dbus_error_init (&error);
  dbus_message_append_args (message, DBUS_TYPE_UINT32, &coord_type_dbus, DBUS_TYPE_INVALID);
  reply = dbus_connection_send_with_reply_and_block (spi_global_app_data->bus,
                                                     message, -1, &error);
  dbus_message_unref (message);
  if (!reply)
    return;
  signature = dbus_message_get_signature (reply);
  if (g_strcmp0 (signature, "(iiii)") != 0)
  {
    g_warning ("Got unexpected signature %s from GetExtents\n", signature);
    dbus_message_unref (reply);
    return;
  }
  dbus_message_iter_init (reply, &iter);
  dbus_message_iter_recurse (&iter, &iter_struct);
  dbus_message_iter_get_basic (&iter_struct, &tmp);
  *x = tmp;
  dbus_message_iter_next (&iter_struct);
  dbus_message_iter_get_basic (&iter_struct, &tmp);
  *y = tmp;
  dbus_message_iter_next (&iter_struct);
  dbus_message_iter_get_basic (&iter_struct, &tmp);
  *width = tmp;
  dbus_message_iter_next (&iter_struct);
  dbus_message_iter_get_basic (&iter_struct, &tmp);
  *height = tmp;
  dbus_message_unref (reply);
}
Beispiel #28
0
static gboolean g_dbus_args_have_signature(const GDBusArgInfo *args,
							DBusMessage *message)
{
	const char *sig = dbus_message_get_signature(message);
	const char *p = NULL;

	for (; args && args->signature && *sig; args++) {
		p = args->signature;

		for (; *sig && *p; sig++, p++) {
			if (*p != *sig)
				return FALSE;
		}
	}

	if (*sig || (p && *p) || (args && args->signature))
		return FALSE;

	return TRUE;
}
Beispiel #29
0
static dbus_bool_t emit_signal_valist(DBusConnection *conn,
						const char *path,
						const char *interface,
						const char *name,
						int first,
						va_list var_args)
{
	DBusMessage *signal;
	dbus_bool_t ret;
	const char *signature, *args;

	if (!check_signal(conn, path, interface, name, &args))
		return FALSE;

	signal = dbus_message_new_signal(path, interface, name);
	if (signal == NULL) {
		error("Unable to allocate new %s.%s signal", interface,  name);
		return FALSE;
	}

	ret = dbus_message_append_args_valist(signal, first, var_args);
	if (!ret)
		goto fail;

	signature = dbus_message_get_signature(signal);
	if (strcmp(args, signature) != 0) {
		error("%s.%s: expected signature'%s' but got '%s'",
				interface, name, args, signature);
		ret = FALSE;
		goto fail;
	}

	ret = dbus_connection_send(conn, signal, NULL);

fail:
	dbus_message_unref(signal);

	return ret;
}
Beispiel #30
0
bool control_proxy_get_room_template_list(void (* callback)(void * context, const char * template_name), void * context)
{
  DBusMessage * reply_ptr;
  const char * reply_signature;
  DBusMessageIter top_iter;
  DBusMessageIter struct_iter;
  DBusMessageIter array_iter;
  const char * name;

  if (!cdbus_call(0, SERVICE_NAME, CONTROL_OBJECT_PATH, IFACE_CONTROL, "GetRoomTemplateList", "", NULL, &reply_ptr))
  {
    log_error("GetRoomTemplateList() failed.");
    return false;
  }

  reply_signature = dbus_message_get_signature(reply_ptr);
  if (strcmp(reply_signature, "a(sa{sv})") != 0)
  {
    log_error("GetRoomTemplateList() reply signature mismatch. '%s'", reply_signature);
    dbus_message_unref(reply_ptr);
    return false;
  }

  dbus_message_iter_init(reply_ptr, &top_iter);
  for (dbus_message_iter_recurse(&top_iter, &array_iter);
       dbus_message_iter_get_arg_type(&array_iter) != DBUS_TYPE_INVALID;
       dbus_message_iter_next(&array_iter))
  {
    dbus_message_iter_recurse(&array_iter, &struct_iter);
    dbus_message_iter_get_basic(&struct_iter, &name);
    callback(context, name);
    dbus_message_iter_next(&struct_iter);
    dbus_message_iter_next(&struct_iter);
  }

  dbus_message_unref(reply_ptr);
  return true;
}