bool a2j_proxy_map_jack_port( const char * jack_port_name, char ** alsa_client_name_ptr_ptr, char ** alsa_port_name_ptr_ptr, uint32_t * alsa_client_id_ptr) { DBusMessage * reply_ptr; dbus_uint32_t alsa_client_id; dbus_uint32_t alsa_port_id; const char * alsa_client_name; const char * alsa_port_name; if (!cdbus_call(0, A2J_SERVICE, A2J_OBJECT, A2J_IFACE_CONTROL, "map_jack_port_to_alsa", "s", &jack_port_name, NULL, &reply_ptr)) { log_error("a2j::map_jack_port_to_alsa() failed."); return false; } if (!dbus_message_get_args( reply_ptr, &cdbus_g_dbus_error, DBUS_TYPE_UINT32, &alsa_client_id, DBUS_TYPE_UINT32, &alsa_port_id, DBUS_TYPE_STRING, &alsa_client_name, DBUS_TYPE_STRING, &alsa_port_name, DBUS_TYPE_INVALID)) { dbus_message_unref(reply_ptr); dbus_error_free(&cdbus_g_dbus_error); log_error("decoding reply of map_jack_port_to_alsa failed."); return false; } *alsa_client_name_ptr_ptr = strdup(alsa_client_name); if (*alsa_client_name_ptr_ptr == NULL) { dbus_message_unref(reply_ptr); log_error("strdup() failed for a2j alsa client name string"); return false; } *alsa_port_name_ptr_ptr = strdup(alsa_port_name); if (*alsa_port_name_ptr_ptr == NULL) { dbus_message_unref(reply_ptr); log_error("strdup() failed for a2j alsa port name string"); free(*alsa_client_name_ptr_ptr); return false; } *alsa_client_id_ptr = alsa_client_id; dbus_message_unref(reply_ptr); return true; }
DBusHandlerResult avahi_service_resolver_event (AvahiClient *client, AvahiResolverEvent event, DBusMessage *message) { AvahiServiceResolver *r = NULL; DBusError error; const char *path; AvahiStringList *strlst = NULL; assert(client); assert(message); dbus_error_init (&error); if (!(path = dbus_message_get_path(message))) goto fail; for (r = client->service_resolvers; r; r = r->service_resolvers_next) if (strcmp (r->path, path) == 0) break; if (!r) goto fail; switch (event) { case AVAHI_RESOLVER_FOUND: { int j; int32_t interface, protocol, aprotocol; uint32_t flags; char *name, *type, *domain, *host, *address; uint16_t port; DBusMessageIter iter, sub; AvahiAddress a; if (!dbus_message_get_args( message, &error, DBUS_TYPE_INT32, &interface, DBUS_TYPE_INT32, &protocol, DBUS_TYPE_STRING, &name, DBUS_TYPE_STRING, &type, DBUS_TYPE_STRING, &domain, DBUS_TYPE_STRING, &host, DBUS_TYPE_INT32, &aprotocol, DBUS_TYPE_STRING, &address, DBUS_TYPE_UINT16, &port, DBUS_TYPE_INVALID) || dbus_error_is_set (&error)) { fprintf(stderr, "Failed to parse resolver event.\n"); goto fail; } dbus_message_iter_init(message, &iter); for (j = 0; j < 9; j++) 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_ARRAY) { fprintf(stderr, "Error parsing service resolving message\n"); goto fail; } strlst = NULL; dbus_message_iter_recurse(&iter, &sub); for (;;) { DBusMessageIter sub2; int at; const uint8_t *k; int n; if ((at = dbus_message_iter_get_arg_type(&sub)) == DBUS_TYPE_INVALID) break; assert(at == DBUS_TYPE_ARRAY); if (dbus_message_iter_get_element_type(&sub) != DBUS_TYPE_BYTE) { fprintf(stderr, "Error parsing service resolving message\n"); goto fail; } dbus_message_iter_recurse(&sub, &sub2); k = NULL; n = 0; dbus_message_iter_get_fixed_array(&sub2, &k, &n); if (k && n > 0) strlst = avahi_string_list_add_arbitrary(strlst, k, n); dbus_message_iter_next(&sub); } dbus_message_iter_next(&iter); if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_UINT32) { fprintf(stderr, "Failed to parse resolver event.\n"); goto fail; } dbus_message_iter_get_basic(&iter, &flags); assert(address); if (address[0] == 0) address = NULL; else avahi_address_parse(address, (AvahiProtocol) aprotocol, &a); r->callback(r, (AvahiIfIndex) interface, (AvahiProtocol) protocol, AVAHI_RESOLVER_FOUND, name, type, domain, host, address ? &a : NULL, port, strlst, (AvahiLookupResultFlags) flags, r->userdata); avahi_string_list_free(strlst); break; } case AVAHI_RESOLVER_FAILURE: { char *etxt; if (!dbus_message_get_args( message, &error, DBUS_TYPE_STRING, &etxt, DBUS_TYPE_INVALID) || dbus_error_is_set (&error)) { fprintf(stderr, "Failed to parse resolver event.\n"); goto fail; } avahi_client_set_errno(r->client, avahi_error_dbus_to_number(etxt)); r->callback(r, r->interface, r->protocol, event, r->name, r->type, r->domain, NULL, NULL, 0, NULL, 0, r->userdata); break; } } return DBUS_HANDLER_RESULT_HANDLED; fail: dbus_error_free (&error); avahi_string_list_free(strlst); return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; }
AvahiAddressResolver * avahi_address_resolver_new( AvahiClient *client, AvahiIfIndex interface, AvahiProtocol protocol, const AvahiAddress *a, AvahiLookupFlags flags, AvahiAddressResolverCallback callback, void *userdata) { DBusError error; AvahiAddressResolver *r = NULL; DBusMessage *message = NULL, *reply = NULL; int32_t i_interface, i_protocol; uint32_t u_flags; char *path; char addr[AVAHI_ADDRESS_STR_MAX], *address = addr; assert(client); assert(a); dbus_error_init (&error); if (!avahi_address_snprint (addr, sizeof(addr), a)) { avahi_client_set_errno(client, AVAHI_ERR_INVALID_ADDRESS); return NULL; } if (!avahi_client_is_connected(client)) { avahi_client_set_errno(client, AVAHI_ERR_BAD_STATE); goto fail; } if (!(r = avahi_new(AvahiAddressResolver, 1))) { avahi_client_set_errno(client, AVAHI_ERR_NO_MEMORY); goto fail; } r->client = client; r->callback = callback; r->userdata = userdata; r->path = NULL; r->interface = interface; r->protocol = protocol; r->address = *a; AVAHI_LLIST_PREPEND(AvahiAddressResolver, address_resolvers, client->address_resolvers, r); if (!(message = dbus_message_new_method_call(AVAHI_DBUS_NAME, AVAHI_DBUS_PATH_SERVER, AVAHI_DBUS_INTERFACE_SERVER, "AddressResolverNew"))) { avahi_client_set_errno(client, AVAHI_ERR_NO_MEMORY); goto fail; } i_interface = (int32_t) interface; i_protocol = (int32_t) protocol; u_flags = (uint32_t) flags; if (!(dbus_message_append_args( message, DBUS_TYPE_INT32, &i_interface, DBUS_TYPE_INT32, &i_protocol, DBUS_TYPE_STRING, &address, DBUS_TYPE_UINT32, &u_flags, DBUS_TYPE_INVALID))) { avahi_client_set_errno(client, AVAHI_ERR_NO_MEMORY); goto fail; } if (!(reply = dbus_connection_send_with_reply_and_block(client->bus, message, -1, &error)) || dbus_error_is_set(&error)) { avahi_client_set_errno(client, AVAHI_ERR_DBUS_ERROR); goto fail; } if (!dbus_message_get_args (reply, &error, DBUS_TYPE_OBJECT_PATH, &path, DBUS_TYPE_INVALID) || dbus_error_is_set(&error) || !path) { avahi_client_set_errno(client, AVAHI_ERR_DBUS_ERROR); goto fail; } if (!(r->path = avahi_strdup(path))) { /* FIXME: We don't remove the object on the server side */ avahi_client_set_errno(client, AVAHI_ERR_NO_MEMORY); goto fail; } dbus_message_unref(message); dbus_message_unref(reply); return r; fail: if (dbus_error_is_set(&error)) { avahi_client_set_dbus_error(client, &error); dbus_error_free(&error); } if (r) avahi_address_resolver_free(r); if (message) dbus_message_unref(message); if (reply) dbus_message_unref(reply); return NULL; }
int ccgi_dbus_eag_conf_vlanmaping(DBusConnection *conn, dbus_vlan_conf vlan_conf) { DBusMessage *query, *reply; DBusError err; int ret_vlan = -1; query = dbus_message_new_method_call( EAG_AURO_SERVER, EAG_AURO_CONF_OBJECT, INTERFACE_AURO_VLANMAPING, METHOD_VLANMAPING ); if (NULL == query) { fprintf(stderr, "dbus_eag_conf_vlanmaping:dbus_message_new_method_call==Null\n"); } dbus_error_init(&err); //fprintf(stderr,"eag_auto_conf v_wlan_begin_id=%d,v_wlan_end_id=%d,v_wtp_begin_id=%u,v_wtp_end_id=%u",\ // vlan_conf.v_wlan_begin_id,vlan_conf.v_wlan_end_id,vlan_conf.v_wtp_begin_id,vlan_conf.v_wtp_end_id); const char * tmp_wlan_begin_id = vlan_conf.v_wlan_begin_id; const char * tmp_wlan_end_id = vlan_conf.v_wlan_end_id; const char * tmp_wtp_begin_id = vlan_conf.v_wtp_begin_id; const char * tmp_wtp_end_id = vlan_conf.v_wtp_end_id; const char * nasportid = vlan_conf.nasportid; const char * tmp_attz = vlan_conf.v_attz; dbus_message_append_args( query, DBUS_TYPE_INT32, &vlan_conf.v_flag, DBUS_TYPE_INT32, &vlan_conf.v_strategy_id, DBUS_TYPE_STRING, &tmp_wlan_begin_id, DBUS_TYPE_STRING, &tmp_wlan_end_id, DBUS_TYPE_STRING, &tmp_wtp_begin_id, DBUS_TYPE_STRING, &tmp_wtp_end_id, DBUS_TYPE_STRING, &nasportid, DBUS_TYPE_STRING, &tmp_attz, DBUS_TYPE_INVALID ); reply = dbus_connection_send_with_reply_and_block ( conn, query, -1, &err ); dbus_message_unref(query); if ( NULL == reply ) { if (dbus_error_is_set(&err)) { //fprintf(stderr, "dbus_message_new_method_call Error:%s\n", err.message); dbus_error_free(&err); } ret_vlan = ERR_DBUS_REPLY_NULL; } else { dbus_message_get_args( reply, &err, DBUS_TYPE_INT32, &ret_vlan, DBUS_TYPE_INVALID ); dbus_message_unref(reply); } return ret_vlan; }
int tool_cmd_reset(int argc, char *argv[]) { int ret = 0; int c; int timeout = 10 * 1000; DBusConnection* connection = NULL; DBusMessage *message = NULL; DBusMessage *reply = NULL; DBusError error; dbus_error_init(&error); while (1) { static struct option long_options[] = { {"help", no_argument, 0, 'h'}, {"timeout", required_argument, 0, 't'}, {0, 0, 0, 0} }; int option_index = 0; c = getopt_long(argc, argv, "ht:", long_options, &option_index); if (c == -1) break; switch (c) { case 'h': print_arg_list_help(reset_option_list, argv[0], reset_cmd_syntax); ret = ERRORCODE_HELP; goto bail; case 't': timeout = strtol(optarg, NULL, 0); break; } } if (optind < argc) { fprintf(stderr, "%s: error: Unexpected extra argument: \"%s\"\n", argv[0], argv[optind]); ret = ERRORCODE_BADARG; goto bail; } if (gInterfaceName[0] == 0) { fprintf(stderr, "%s: error: No WPAN interface set (use the `cd` command, or the `-I` argument for `wpanctl`).\n", argv[0]); ret = ERRORCODE_BADARG; goto bail; } connection = dbus_bus_get(DBUS_BUS_STARTER, &error); if (!connection) { dbus_error_free(&error); dbus_error_init(&error); connection = dbus_bus_get(DBUS_BUS_SYSTEM, &error); } require_string(connection != NULL, bail, error.message); { DBusMessageIter iter; DBusMessageIter list_iter; char path[DBUS_MAXIMUM_NAME_LENGTH+1]; char interface_dbus_name[DBUS_MAXIMUM_NAME_LENGTH+1]; ret = lookup_dbus_name_from_interface(interface_dbus_name, gInterfaceName); if (ret != 0) { goto bail; } snprintf(path, sizeof(path), "%s/%s", WPANTUND_DBUS_PATH, gInterfaceName); message = dbus_message_new_method_call( interface_dbus_name, path, WPANTUND_DBUS_APIv1_INTERFACE, WPANTUND_IF_CMD_RESET ); fprintf(stderr, "Resetting NCP. . .\n"); reply = dbus_connection_send_with_reply_and_block( connection, message, timeout, &error ); if (!reply) { fprintf(stderr, "%s: error: %s\n", argv[0], error.message); ret = ERRORCODE_TIMEOUT; goto bail; } dbus_message_get_args(reply, &error, DBUS_TYPE_INT32, &ret, DBUS_TYPE_INVALID ); if (ret == 6) ret = 0; } bail: if (connection) dbus_connection_unref(connection); if (message) dbus_message_unref(message); if (reply) dbus_message_unref(reply); dbus_error_free(&error); return ret; }
static void check_hello_from_self_reply (DBusPendingCall *pcall, void *user_data) { DBusMessage *reply; DBusMessage *echo_message, *echo_reply = NULL; DBusError error; DBusConnection *connection; int type; dbus_error_init (&error); connection = dbus_bus_get (DBUS_BUS_STARTER, &error); if (connection == NULL) { fprintf (stderr, "*** Failed to open connection to activating message bus: %s\n", error.message); dbus_error_free (&error); die("no memory"); } echo_message = (DBusMessage *)user_data; reply = dbus_pending_call_steal_reply (pcall); type = dbus_message_get_type (reply); if (type == DBUS_MESSAGE_TYPE_METHOD_RETURN) { const char *s; printf ("Reply from HelloFromSelf received\n"); if (!dbus_message_get_args (echo_message, &error, DBUS_TYPE_STRING, &s, DBUS_TYPE_INVALID)) { echo_reply = dbus_message_new_error (echo_message, error.name, error.message); if (echo_reply == NULL) die ("No memory\n"); } else { echo_reply = dbus_message_new_method_return (echo_message); if (echo_reply == NULL) die ("No memory\n"); if (!dbus_message_append_args (echo_reply, DBUS_TYPE_STRING, &s, DBUS_TYPE_INVALID)) die ("No memory"); } if (!dbus_connection_send (connection, echo_reply, NULL)) die ("No memory\n"); dbus_message_unref (echo_reply); } else if (type == DBUS_MESSAGE_TYPE_ERROR) { dbus_set_error_from_message (&error, reply); printf ("Error type in reply: %s\n", error.message); if (strcmp (error.name, DBUS_ERROR_NO_MEMORY) != 0) { echo_reply = dbus_message_new_error (echo_reply, error.name, error.message); if (echo_reply == NULL) die ("No memory\n"); if (!dbus_connection_send (connection, echo_reply, NULL)) die ("No memory\n"); dbus_message_unref (echo_reply); } dbus_error_free (&error); } else _dbus_assert_not_reached ("Unexpected message received\n"); hello_from_self_reply_received = TRUE; dbus_message_unref (reply); dbus_message_unref (echo_message); dbus_pending_call_unref (pcall); dbus_connection_unref (connection); }
static DBusHandlerResult nds_filter_function(DBusConnection *connection, DBusMessage *message, void *user_data) { LibHalContext *ctx = user_data; DBusMessage *reply; DBusError error; const char *member = dbus_message_get_member(message); const char *path = dbus_message_get_path(message); int rc = -1; dbus_error_init(&error); HAL_DEBUG(("DBus message: %s, %s ", member, path)); if (dbus_message_is_method_call(message, DBUS_INTERFACE, "EnablePrinterScanningViaSNMP")) { int interval = -1; char *udi = getenv("UDI"); char *community = "public"; char *network = "0.0.0.0"; dbus_message_get_args(message, &error, DBUS_TYPE_INT32, &interval, DBUS_TYPE_STRING, &community, DBUS_TYPE_STRING, &network, DBUS_TYPE_INVALID); if (strcmp(network, "0.0.0.0") == 0) network = NULL; rc = nds_EnablePrinterScanningViaSNMP(ctx, udi, interval, community, network); } else if (dbus_message_is_method_call(message, DBUS_INTERFACE, "ScanForPrintersViaSNMP")) { int interval = -1; char *udi = getenv("UDI"); char *community = "public"; char *network = "0.0.0.0"; dbus_message_get_args(message, &error, DBUS_TYPE_STRING, &community, DBUS_TYPE_STRING, &network, DBUS_TYPE_INVALID); if (strcmp(network, "0.0.0.0") == 0) network = NULL; rc = nds_ScanForPrintersViaSNMP(ctx, udi, community, network); } else if (dbus_message_is_method_call(message, DBUS_INTERFACE, "DisablePrinterScanningViaSNMP")) { rc = nds_DisablePrinterScanningViaSNMP(ctx); } else { /* bypass not-handled messages */ HAL_WARNING(("Unknown DBus message: %s, %s ", member, path)); return (DBUS_HANDLER_RESULT_NOT_YET_HANDLED); } if (dbus_error_is_set(&error)) dbus_error_free(&error); if ((reply = dbus_message_new_method_return(message)) == NULL) { HAL_WARNING(("Could not allocate memory for the DBus reply")); return (FALSE); } dbus_message_append_args(reply, DBUS_TYPE_INT32, &rc, DBUS_TYPE_INVALID); if (!dbus_connection_send(connection, reply, NULL)) { HAL_WARNING(("Could not sent reply")); } dbus_connection_flush(connection); dbus_message_unref(reply); return (DBUS_HANDLER_RESULT_HANDLED); }
/** * Process a win_get D-Bus request. */ static bool cdbus_process_win_get(session_t *ps, DBusMessage *msg) { cdbus_window_t wid = None; const char *target = NULL; DBusError err = { }; if (!dbus_message_get_args(msg, &err, CDBUS_TYPE_WINDOW, &wid, DBUS_TYPE_STRING, &target, DBUS_TYPE_INVALID)) { printf_errf("(): Failed to parse argument of \"win_get\" (%s).", err.message); dbus_error_free(&err); return false; } win *w = find_win(ps, wid); if (!w) { printf_errf("(): Window %#010x not found.", wid); cdbus_reply_err(ps, msg, CDBUS_ERROR_BADWIN, CDBUS_ERROR_BADWIN_S, wid); return true; } #define cdbus_m_win_get_do(tgt, apdarg_func) \ if (!strcmp(MSTR(tgt), target)) { \ apdarg_func(ps, msg, w->tgt); \ return true; \ } cdbus_m_win_get_do(id, cdbus_reply_wid); // next if (!strcmp("next", target)) { cdbus_reply_wid(ps, msg, (w->next ? w->next->id: 0)); return true; } // map_state if (!strcmp("map_state", target)) { cdbus_reply_bool(ps, msg, w->a.map_state); return true; } cdbus_m_win_get_do(mode, cdbus_reply_enum); cdbus_m_win_get_do(client_win, cdbus_reply_wid); cdbus_m_win_get_do(damaged, cdbus_reply_bool); cdbus_m_win_get_do(destroyed, cdbus_reply_bool); cdbus_m_win_get_do(window_type, cdbus_reply_enum); cdbus_m_win_get_do(wmwin, cdbus_reply_bool); cdbus_m_win_get_do(leader, cdbus_reply_wid); // focused_real if (!strcmp("focused_real", target)) { cdbus_reply_bool(ps, msg, win_is_focused_real(ps, w)); return true; } cdbus_m_win_get_do(fade_force, cdbus_reply_enum); cdbus_m_win_get_do(shadow_force, cdbus_reply_enum); cdbus_m_win_get_do(focused_force, cdbus_reply_enum); cdbus_m_win_get_do(invert_color_force, cdbus_reply_enum); cdbus_m_win_get_do(name, cdbus_reply_string); cdbus_m_win_get_do(class_instance, cdbus_reply_string); cdbus_m_win_get_do(class_general, cdbus_reply_string); cdbus_m_win_get_do(role, cdbus_reply_string); cdbus_m_win_get_do(opacity, cdbus_reply_uint32); cdbus_m_win_get_do(frame_opacity, cdbus_reply_double); cdbus_m_win_get_do(left_width, cdbus_reply_uint32); cdbus_m_win_get_do(right_width, cdbus_reply_uint32); cdbus_m_win_get_do(top_width, cdbus_reply_uint32); cdbus_m_win_get_do(bottom_width, cdbus_reply_uint32); cdbus_m_win_get_do(shadow, cdbus_reply_bool); cdbus_m_win_get_do(fade, cdbus_reply_bool); cdbus_m_win_get_do(invert_color, cdbus_reply_bool); cdbus_m_win_get_do(blur_background, cdbus_reply_bool); #undef cdbus_m_win_get_do printf_errf("(): " CDBUS_ERROR_BADTGT_S, target); cdbus_reply_err(ps, msg, CDBUS_ERROR_BADTGT, CDBUS_ERROR_BADTGT_S, target); return true; }
/** * Process a win_set D-Bus request. */ static bool cdbus_process_win_set(session_t *ps, DBusMessage *msg) { cdbus_window_t wid = None; const char *target = NULL; DBusError err = { }; if (!dbus_message_get_args(msg, &err, CDBUS_TYPE_WINDOW, &wid, DBUS_TYPE_STRING, &target, DBUS_TYPE_INVALID)) { printf_errf("(): Failed to parse argument of \"win_set\" (%s).", err.message); dbus_error_free(&err); return false; } win *w = find_win(ps, wid); if (!w) { printf_errf("(): Window %#010x not found.", wid); cdbus_reply_err(ps, msg, CDBUS_ERROR_BADWIN, CDBUS_ERROR_BADWIN_S, wid); return true; } #define cdbus_m_win_set_do(tgt, type, real_type) \ if (!strcmp(MSTR(tgt), target)) { \ real_type val; \ if (!cdbus_msg_get_arg(msg, 2, type, &val)) \ return false; \ w->tgt = val; \ goto cdbus_process_win_set_success; \ } if (!strcmp("shadow_force", target)) { cdbus_enum_t val = UNSET; if (!cdbus_msg_get_arg(msg, 2, CDBUS_TYPE_ENUM, &val)) return false; win_set_shadow_force(ps, w, val); goto cdbus_process_win_set_success; } if (!strcmp("fade_force", target)) { cdbus_enum_t val = UNSET; if (!cdbus_msg_get_arg(msg, 2, CDBUS_TYPE_ENUM, &val)) return false; win_set_fade_force(ps, w, val); goto cdbus_process_win_set_success; } if (!strcmp("focused_force", target)) { cdbus_enum_t val = UNSET; if (!cdbus_msg_get_arg(msg, 2, CDBUS_TYPE_ENUM, &val)) return false; win_set_focused_force(ps, w, val); goto cdbus_process_win_set_success; } if (!strcmp("invert_color_force", target)) { cdbus_enum_t val = UNSET; if (!cdbus_msg_get_arg(msg, 2, CDBUS_TYPE_ENUM, &val)) return false; win_set_invert_color_force(ps, w, val); goto cdbus_process_win_set_success; } #undef cdbus_m_win_set_do printf_errf("(): " CDBUS_ERROR_BADTGT_S, target); cdbus_reply_err(ps, msg, CDBUS_ERROR_BADTGT, CDBUS_ERROR_BADTGT_S, target); return true; cdbus_process_win_set_success: if (!dbus_message_get_no_reply(msg)) cdbus_reply_bool(ps, msg, true); return true; }
bool dp_unpack_pam_request(DBusMessage *msg, TALLOC_CTX *mem_ctx, struct pam_data **new_pd, DBusError *dbus_error) { dbus_bool_t db_ret; int ret; struct pam_data pd; uint32_t authtok_type; int authtok_length; uint8_t *authtok_data; uint32_t new_authtok_type; int new_authtok_length; uint8_t *new_authtok_data; int32_t pd_cmd; int32_t pd_priv; memset(&pd, 0, sizeof(pd)); db_ret = dbus_message_get_args(msg, dbus_error, DBUS_TYPE_INT32, &pd_cmd, DBUS_TYPE_STRING, &(pd.user), DBUS_TYPE_STRING, &(pd.domain), DBUS_TYPE_STRING, &(pd.service), DBUS_TYPE_STRING, &(pd.tty), DBUS_TYPE_STRING, &(pd.ruser), DBUS_TYPE_STRING, &(pd.rhost), DBUS_TYPE_UINT32, &authtok_type, DBUS_TYPE_ARRAY, DBUS_TYPE_BYTE, &authtok_data, &authtok_length, DBUS_TYPE_UINT32, &new_authtok_type, DBUS_TYPE_ARRAY, DBUS_TYPE_BYTE, &new_authtok_data, &new_authtok_length, DBUS_TYPE_INT32, &pd_priv, DBUS_TYPE_UINT32, &(pd.cli_pid), DBUS_TYPE_INVALID); if (!db_ret) { DEBUG(SSSDBG_CRIT_FAILURE, "dbus_message_get_args failed.\n"); return false; } pd.cmd = pd_cmd; pd.priv = pd_priv; ret = copy_pam_data(mem_ctx, &pd, new_pd); if (ret != EOK) { DEBUG(SSSDBG_CRIT_FAILURE, "copy_pam_data failed.\n"); return false; } ret = sss_authtok_set((*new_pd)->authtok, authtok_type, authtok_data, authtok_length); if (ret) { DEBUG(SSSDBG_CRIT_FAILURE, "Failed to set auth token: %d [%s]\n", ret, strerror(ret)); return false; } ret = sss_authtok_set((*new_pd)->newauthtok, new_authtok_type, new_authtok_data, new_authtok_length); if (ret) { DEBUG(SSSDBG_CRIT_FAILURE, "Failed to set auth token: %d [%s]\n", ret, strerror(ret)); return false; } return true; }
static DBusHandlerResult handle_gps_fix (DBusMessage* message) { DBusError error; double temp_time; dbus_error_init (&error); dbus_message_get_args (message, &error, DBUS_TYPE_DOUBLE, &temp_time, DBUS_TYPE_INT32, &gpsfix.mode, DBUS_TYPE_DOUBLE, &gpsfix.ept, DBUS_TYPE_DOUBLE, &gpsfix.latitude, DBUS_TYPE_DOUBLE, &gpsfix.longitude, DBUS_TYPE_DOUBLE, &gpsfix.eph, DBUS_TYPE_DOUBLE, &gpsfix.altitude, DBUS_TYPE_DOUBLE, &gpsfix.epv, DBUS_TYPE_DOUBLE, &gpsfix.track, DBUS_TYPE_DOUBLE, &gpsfix.epd, DBUS_TYPE_DOUBLE, &gpsfix.speed, DBUS_TYPE_DOUBLE, &gpsfix.eps, DBUS_TYPE_DOUBLE, &gpsfix.climb, DBUS_TYPE_DOUBLE, &gpsfix.epc, DBUS_TYPE_INVALID); gpsfix.time = floor(temp_time); /* * we have a fix there - log the point */ if ((gpsfix.time!=gpsfix.old_time)&&gpsfix.mode>1) { struct tm time; /* Make new track if the jump in time is above * tracklimit. Handle jumps both forward and * backwards in time. The clock sometimes jump * backward when gpsd is submitting junk on the * dbus. */ if (fabs(gpsfix.time - gpsfix.old_time) > tracklimit && !first) { print_gpx_trk_end(); intrack = 0; } if (!intrack) { print_gpx_trk_start(); intrack = 1; if (first) first = 0; } gpsfix.old_time = gpsfix.time; fprintf (stdout, " <trkpt lat=\"%f\" lon=\"%f\">\n", gpsfix.latitude, gpsfix.longitude); fprintf (stdout, " <ele>%f</ele>\n", gpsfix.altitude); gmtime_r (&(gpsfix.time), &time); fprintf (stdout, " <time>%04d-%02d-%02dT%02d:%02d:%02dZ</time>\n", time.tm_year+1900, time.tm_mon+1, time.tm_mday, time.tm_hour, time.tm_min, time.tm_sec); if (gpsfix.mode==1) fprintf (stdout, " <fix>none</fix>\n"); else fprintf (stdout, " <fix>%dd</fix>\n", gpsfix.mode); fprintf (stdout, " </trkpt>\n"); fflush (stdout); } return DBUS_HANDLER_RESULT_HANDLED; }
void dp_id_callback(DBusPendingCall *pending, void *ptr) { DBusMessage *reply; DBusError dbus_error; dbus_bool_t ret; dbus_uint16_t dp_ver; int type; dbus_error_init(&dbus_error); reply = dbus_pending_call_steal_reply(pending); if (!reply) { /* reply should never be null. This function shouldn't be called * until reply is valid or timeout has occurred. If reply is NULL * here, something is seriously wrong and we should bail out. */ DEBUG(SSSDBG_FATAL_FAILURE, "Severe error. A reply callback was called but no" " reply was received and no timeout occurred\n"); /* FIXME: Destroy this connection ? */ goto done; } type = dbus_message_get_type(reply); switch (type) { case DBUS_MESSAGE_TYPE_METHOD_RETURN: ret = dbus_message_get_args(reply, &dbus_error, DBUS_TYPE_UINT16, &dp_ver, DBUS_TYPE_INVALID); if (!ret) { DEBUG(SSSDBG_CRIT_FAILURE, "Failed to parse message\n"); if (dbus_error_is_set(&dbus_error)) dbus_error_free(&dbus_error); /* FIXME: Destroy this connection ? */ goto done; } DEBUG(SSSDBG_CONF_SETTINGS, "Got id ack and version (%d) from DP\n", dp_ver); break; case DBUS_MESSAGE_TYPE_ERROR: DEBUG(SSSDBG_FATAL_FAILURE,"The Monitor returned an error [%s]\n", dbus_message_get_error_name(reply)); /* Falling through to default intentionally*/ default: /* * Timeout or other error occurred or something * unexpected happened. * It doesn't matter which, because either way we * know that this connection isn't trustworthy. * We'll destroy it now. */ /* FIXME: Destroy this connection ? */ break; } done: dbus_pending_call_unref(pending); dbus_message_unref(reply); }
static void endpoint_reply(DBusPendingCall *call, void *user_data) { struct endpoint_request *request = user_data; struct media_endpoint *endpoint = request->endpoint; DBusMessage *reply; DBusError err; gboolean value; void *ret = NULL; int size = -1; /* steal_reply will always return non-NULL since the callback * is only called after a reply has been received */ reply = dbus_pending_call_steal_reply(call); dbus_error_init(&err); if (dbus_set_error_from_message(&err, reply)) { error("Endpoint replied with an error: %s", err.name); /* Clear endpoint configuration in case of NO_REPLY error */ if (dbus_error_has_name(&err, DBUS_ERROR_NO_REPLY)) { if (request->cb) request->cb(endpoint, NULL, size, request->user_data); clear_endpoint(endpoint); dbus_message_unref(reply); dbus_error_free(&err); return; } dbus_error_free(&err); goto done; } if (dbus_message_is_method_call(request->msg, MEDIA_ENDPOINT_INTERFACE, "SelectConfiguration")) { DBusMessageIter args, array; uint8_t *configuration; dbus_message_iter_init(reply, &args); dbus_message_iter_recurse(&args, &array); dbus_message_iter_get_fixed_array(&array, &configuration, &size); ret = configuration; goto done; } else if (!dbus_message_get_args(reply, &err, DBUS_TYPE_INVALID)) { error("Wrong reply signature: %s", err.message); dbus_error_free(&err); goto done; } size = 1; value = TRUE; ret = &value; done: dbus_message_unref(reply); if (request->cb) request->cb(endpoint, ret, size, request->user_data); endpoint->requests = g_slist_remove(endpoint->requests, request); endpoint_request_free(request); }
OMXControlResult OMXControl::getEvent() { if (!bus) return KeyConfig::ACTION_BLANK; dispatch(); DBusMessage *m = dbus_connection_pop_message(bus); if (m == NULL) return KeyConfig::ACTION_BLANK; CLog::Log(LOGDEBUG, "Popped message member: %s interface: %s type: %d path: %s", dbus_message_get_member(m), dbus_message_get_interface(m), dbus_message_get_type(m), dbus_message_get_path(m) ); if (dbus_message_is_method_call(m, OMXPLAYER_DBUS_INTERFACE_ROOT, "Quit")) { dbus_respond_ok(m); return KeyConfig::ACTION_EXIT; } else if (dbus_message_is_method_call(m, DBUS_INTERFACE_PROPERTIES, "CanQuit") || dbus_message_is_method_call(m, DBUS_INTERFACE_PROPERTIES, "Fullscreen")) { dbus_respond_boolean(m, 1); return KeyConfig::ACTION_BLANK; } else if (dbus_message_is_method_call(m, DBUS_INTERFACE_PROPERTIES, "CanSetFullscreen") || dbus_message_is_method_call(m, DBUS_INTERFACE_PROPERTIES, "CanRaise") || dbus_message_is_method_call(m, DBUS_INTERFACE_PROPERTIES, "HasTrackList")) { dbus_respond_boolean(m, 0); return KeyConfig::ACTION_BLANK; } else if (dbus_message_is_method_call(m, DBUS_INTERFACE_PROPERTIES, "Identity")) { dbus_respond_string(m, "OMXPlayer"); return KeyConfig::ACTION_BLANK; } else if (dbus_message_is_method_call(m, DBUS_INTERFACE_PROPERTIES, "SupportedUriSchemes")) { const char *UriSchemes[] = {"file", "http"}; dbus_respond_array(m, UriSchemes, 2); // Array is of length 2 return KeyConfig::ACTION_BLANK; } else if (dbus_message_is_method_call(m, DBUS_INTERFACE_PROPERTIES, "SupportedMimeTypes")) { const char *MimeTypes[] = {}; // Needs supplying dbus_respond_array(m, MimeTypes, 0); return KeyConfig::ACTION_BLANK; } else if (dbus_message_is_method_call(m, DBUS_INTERFACE_PROPERTIES, "CanGoNext") || dbus_message_is_method_call(m, DBUS_INTERFACE_PROPERTIES, "CanGoPrevious")) { dbus_respond_boolean(m, 0); return KeyConfig::ACTION_BLANK; } else if (dbus_message_is_method_call(m, DBUS_INTERFACE_PROPERTIES, "CanSeek")) { dbus_respond_boolean(m, reader->CanSeek()); return KeyConfig::ACTION_BLANK; } else if (dbus_message_is_method_call(m, DBUS_INTERFACE_PROPERTIES, "CanControl") || dbus_message_is_method_call(m, DBUS_INTERFACE_PROPERTIES, "CanPlay") || dbus_message_is_method_call(m, DBUS_INTERFACE_PROPERTIES, "CanPause")) { dbus_respond_boolean(m, 1); } else if (dbus_message_is_method_call(m, OMXPLAYER_DBUS_INTERFACE_PLAYER, "Next")) { dbus_respond_ok(m); return KeyConfig::ACTION_NEXT_CHAPTER; } else if (dbus_message_is_method_call(m, OMXPLAYER_DBUS_INTERFACE_PLAYER, "Previous")) { dbus_respond_ok(m); return KeyConfig::ACTION_PREVIOUS_CHAPTER; } else if (dbus_message_is_method_call(m, OMXPLAYER_DBUS_INTERFACE_PLAYER, "Pause") || dbus_message_is_method_call(m, OMXPLAYER_DBUS_INTERFACE_PLAYER, "PlayPause")) { dbus_respond_ok(m); return KeyConfig::ACTION_PAUSE; } else if (dbus_message_is_method_call(m, OMXPLAYER_DBUS_INTERFACE_PLAYER, "Stop")) { dbus_respond_ok(m); return KeyConfig::ACTION_EXIT; } else if (dbus_message_is_method_call(m, OMXPLAYER_DBUS_INTERFACE_PLAYER, "Seek")) { DBusError error; dbus_error_init(&error); int64_t offset; dbus_message_get_args(m, &error, DBUS_TYPE_INT64, &offset, DBUS_TYPE_INVALID); // Make sure a value is sent for seeking if (dbus_error_is_set(&error)) { CLog::Log(LOGWARNING, "Seek D-Bus Error: %s", error.message ); dbus_error_free(&error); dbus_respond_ok(m); return KeyConfig::ACTION_BLANK; } else { dbus_respond_int64(m, offset); return OMXControlResult(KeyConfig::ACTION_SEEK_RELATIVE, offset); } } else if (dbus_message_is_method_call(m, OMXPLAYER_DBUS_INTERFACE_PLAYER, "SetPosition")) { DBusError error; dbus_error_init(&error); int64_t position; const char *oPath; // ignoring path right now because we don't have a playlist dbus_message_get_args(m, &error, DBUS_TYPE_OBJECT_PATH, &oPath, DBUS_TYPE_INT64, &position, DBUS_TYPE_INVALID); // Make sure a value is sent for setting position if (dbus_error_is_set(&error)) { CLog::Log(LOGWARNING, "SetPosition D-Bus Error: %s", error.message ); dbus_error_free(&error); dbus_respond_ok(m); return KeyConfig::ACTION_BLANK; } else { dbus_respond_int64(m, position); return OMXControlResult(KeyConfig::ACTION_SEEK_ABSOLUTE, position); } } else if (dbus_message_is_method_call(m, DBUS_INTERFACE_PROPERTIES, "PlaybackStatus")) { const char *status; if (clock->OMXIsPaused()) { status = "Paused"; } else { status = "Playing"; } dbus_respond_string(m, status); return KeyConfig::ACTION_BLANK; } else if (dbus_message_is_method_call(m, DBUS_INTERFACE_PROPERTIES, "Volume")) { DBusError error; dbus_error_init(&error); double volume; dbus_message_get_args(m, &error, DBUS_TYPE_DOUBLE, &volume, DBUS_TYPE_INVALID); if (dbus_error_is_set(&error)) { // i.e. Get current volume dbus_error_free(&error); dbus_respond_double(m, audio->GetVolume()); return KeyConfig::ACTION_BLANK; } else { audio->SetVolume(volume); dbus_respond_double(m, volume); return KeyConfig::ACTION_BLANK; } } else if (dbus_message_is_method_call(m, DBUS_INTERFACE_PROPERTIES, "Mute")) { audio->SetMute(true); dbus_respond_ok(m); return KeyConfig::ACTION_BLANK; } else if (dbus_message_is_method_call(m, DBUS_INTERFACE_PROPERTIES, "Unmute")) { audio->SetMute(false); dbus_respond_ok(m); return KeyConfig::ACTION_BLANK; } else if (dbus_message_is_method_call(m, DBUS_INTERFACE_PROPERTIES, "Position")) { // Returns the current position in microseconds int64_t pos = clock->OMXMediaTime(); dbus_respond_int64(m, pos); return KeyConfig::ACTION_BLANK; } else if (dbus_message_is_method_call(m, DBUS_INTERFACE_PROPERTIES, "Duration")) { // Returns the duration in microseconds int64_t dur = reader->GetStreamLength(); dur *= 1000; // ms -> us dbus_respond_int64(m, dur); return KeyConfig::ACTION_BLANK; } else if (dbus_message_is_method_call(m, DBUS_INTERFACE_PROPERTIES, "MinimumRate")) { dbus_respond_double(m, 0.0); return KeyConfig::ACTION_BLANK; } else if (dbus_message_is_method_call(m, DBUS_INTERFACE_PROPERTIES, "MaximumRate")) { dbus_respond_double(m, 1.125); return KeyConfig::ACTION_BLANK; // Implement extra OMXPlayer controls } else if (dbus_message_is_method_call(m, OMXPLAYER_DBUS_INTERFACE_PLAYER, "ListSubtitles")) { int count = reader->SubtitleStreamCount(); char** values = new char*[count]; for (int i=0; i < count; i++) { asprintf(&values[i], "%d:%s:%s:%s:%s", i, reader->GetStreamLanguage(OMXSTREAM_SUBTITLE, i).c_str(), reader->GetStreamName(OMXSTREAM_SUBTITLE, i).c_str(), reader->GetCodecName(OMXSTREAM_SUBTITLE, i).c_str(), ((int)subtitles->GetActiveStream() == i) ? "active" : ""); } dbus_respond_array(m, (const char**)values, count); // Cleanup for (int i=0; i < count; i++) { delete[] values[i]; } return KeyConfig::ACTION_BLANK; } else if (dbus_message_is_method_call(m, OMXPLAYER_DBUS_INTERFACE_PLAYER, "VideoPos")) { DBusError error; dbus_error_init(&error); const char *win; const char *oPath; // ignoring path right now because we don't have a playlist dbus_message_get_args(m, &error, DBUS_TYPE_OBJECT_PATH, &oPath, DBUS_TYPE_STRING, &win, DBUS_TYPE_INVALID); // Make sure a value is sent for setting VideoPos if (dbus_error_is_set(&error)) { CLog::Log(LOGWARNING, "VideoPos D-Bus Error: %s", error.message ); dbus_error_free(&error); dbus_respond_ok(m); return KeyConfig::ACTION_BLANK; } else { dbus_respond_string(m, win); return OMXControlResult(KeyConfig::ACTION_MOVE_VIDEO, win); } } else if (dbus_message_is_method_call(m, OMXPLAYER_DBUS_INTERFACE_PLAYER, "HideVideo")) { dbus_respond_ok(m); return KeyConfig::ACTION_HIDE_VIDEO; } else if (dbus_message_is_method_call(m, OMXPLAYER_DBUS_INTERFACE_PLAYER, "UnHideVideo")) { dbus_respond_ok(m); return KeyConfig::ACTION_UNHIDE_VIDEO; } else if (dbus_message_is_method_call(m, OMXPLAYER_DBUS_INTERFACE_PLAYER, "ListAudio")) { int count = reader->AudioStreamCount(); char** values = new char*[count]; for (int i=0; i < count; i++) { asprintf(&values[i], "%d:%s:%s:%s:%s", i, reader->GetStreamLanguage(OMXSTREAM_AUDIO, i).c_str(), reader->GetStreamName(OMXSTREAM_AUDIO, i).c_str(), reader->GetCodecName(OMXSTREAM_AUDIO, i).c_str(), (reader->GetAudioIndex() == i) ? "active" : ""); } dbus_respond_array(m, (const char**)values, count); // Cleanup for (int i=0; i < count; i++) { delete[] values[i]; } return KeyConfig::ACTION_BLANK; } else if (dbus_message_is_method_call(m, OMXPLAYER_DBUS_INTERFACE_PLAYER, "ListVideo")) { int count = reader->AudioStreamCount(); char** values = new char*[count]; for (int i=0; i < count; i++) { asprintf(&values[i], "%d:%s:%s:%s:%s", i, reader->GetStreamLanguage(OMXSTREAM_VIDEO, i).c_str(), reader->GetStreamName(OMXSTREAM_VIDEO, i).c_str(), reader->GetCodecName(OMXSTREAM_VIDEO, i).c_str(), (reader->GetVideoIndex() == i) ? "active" : ""); } dbus_respond_array(m, (const char**)values, count); // Cleanup for (int i=0; i < count; i++) { delete[] values[i]; } return KeyConfig::ACTION_BLANK; } else if (dbus_message_is_method_call(m, OMXPLAYER_DBUS_INTERFACE_PLAYER, "SelectSubtitle")) { DBusError error; dbus_error_init(&error); int index; dbus_message_get_args(m, &error, DBUS_TYPE_INT32, &index, DBUS_TYPE_INVALID); if (dbus_error_is_set(&error)) { dbus_error_free(&error); dbus_respond_boolean(m, 0); } else { if (reader->SetActiveStream(OMXSTREAM_SUBTITLE, index)) { subtitles->SetActiveStream(reader->GetSubtitleIndex()); dbus_respond_boolean(m, 1); } else { dbus_respond_boolean(m, 0); } } return KeyConfig::ACTION_BLANK; } else if (dbus_message_is_method_call(m, OMXPLAYER_DBUS_INTERFACE_PLAYER, "SelectAudio")) { DBusError error; dbus_error_init(&error); int index; dbus_message_get_args(m, &error, DBUS_TYPE_INT32, &index, DBUS_TYPE_INVALID); if (dbus_error_is_set(&error)) { dbus_error_free(&error); dbus_respond_boolean(m, 0); } else { if (reader->SetActiveStream(OMXSTREAM_AUDIO, index)) { dbus_respond_boolean(m, 1); } else { dbus_respond_boolean(m, 0); } } return KeyConfig::ACTION_BLANK; } // TODO: SelectVideo ??? else if (dbus_message_is_method_call(m, OMXPLAYER_DBUS_INTERFACE_PLAYER, "ShowSubtitles")) { subtitles->SetVisible(true); dbus_respond_ok(m); return KeyConfig::ACTION_BLANK; } else if (dbus_message_is_method_call(m, OMXPLAYER_DBUS_INTERFACE_PLAYER, "HideSubtitles")) { subtitles->SetVisible(false); dbus_respond_ok(m); return KeyConfig::ACTION_BLANK; } else if (dbus_message_is_method_call(m, OMXPLAYER_DBUS_INTERFACE_PLAYER, "Action")) { DBusError error; dbus_error_init(&error); int action; dbus_message_get_args(m, &error, DBUS_TYPE_INT32, &action, DBUS_TYPE_INVALID); if (dbus_error_is_set(&error)) { dbus_error_free(&error); dbus_respond_ok(m); return KeyConfig::ACTION_BLANK; } else { dbus_respond_ok(m); return action; // Directly return enum } } else { CLog::Log(LOGWARNING, "Unhandled dbus message, member: %s interface: %s type: %d path: %s", dbus_message_get_member(m), dbus_message_get_interface(m), dbus_message_get_type(m), dbus_message_get_path(m) ); } return KeyConfig::ACTION_BLANK; }
/******************************************************************************* * igmp_snp_dbus_igmp_snp_enable * * DESCRIPTION: * config IGMP snoop enable * * INPUTS: * conn - dbusconnection * msg - dbusmessage * user_data - dbus data * * OUTPUTS: * null * * RETURNS: * reply - * * COMMENTS: * ** ********************************************************************************/ DBusMessage * igmp_snp_dbus_igmp_snp_enable ( DBusConnection *conn, DBusMessage *msg, void *user_data ) { DBusMessage* reply; DBusMessageIter iter = {0}; DBusError err; unsigned int ret = IGMPSNP_RETURN_CODE_OK; unsigned char enable = 0,ismld =0; dbus_error_init( &err ); if( !(dbus_message_get_args( msg ,&err, \ DBUS_TYPE_BYTE, &enable, \ DBUS_TYPE_BYTE, &ismld,\ DBUS_TYPE_INVALID))) { igmp_snp_syslog_err("Unable to get input args\n"); if(dbus_error_is_set( &err )) { igmp_snp_syslog_err("%s raised:%s\n",err.name ,err.message); dbus_error_free( &err ); } return NULL; } /* here call igmp_snp or mld_snp api */ if(1 == ismld){/*mld enable or disable*/ if (0 == enable) { ret = mld_snp_set_disable_dbus(); } else if(1 == enable){ ret = mld_snp_set_enable_dbus(); } else { ret = IGMPSNP_RETURN_CODE_ERROR; } } else{/*igmp enable or disable*/ if (0 == enable) { ret = igmp_snp_set_disable_dbus(); } else if(1 == enable){ ret = igmp_snp_set_enable_dbus(); } else { ret = IGMPSNP_RETURN_CODE_ERROR; } } reply = dbus_message_new_method_return(msg); if(NULL==reply) { igmp_snp_syslog_dbg("dbus add vlan no reply resource error!\n"); return reply; } dbus_message_iter_init_append (reply, &iter); dbus_message_iter_append_basic (&iter,DBUS_TYPE_UINT32,&ret); return reply; }
DBusHandlerResult HippoDBusIpcProviderImpl::handleMethod(DBusMessage *message) { g_assert(connection_ != NULL); DBusMessage *reply = NULL; const char *sender = dbus_message_get_sender(message); const char *interface = dbus_message_get_interface(message); const char *member = dbus_message_get_member(message); const char *path = dbus_message_get_path(message); g_debug("method call from %s %s.%s on %s", sender ? sender : "NULL", interface ? interface : "NULL", member ? member : "NULL", path ? path : "NULL"); if (!path || strcmp(path, HIPPO_DBUS_STACKER_LISTENER_PATH) != 0) return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; if (!interface || strcmp(interface, HIPPO_DBUS_STACKER_LISTENER_INTERFACE) != 0) return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; if (strcmp(member, "UserJoin") == 0) { dbus_uint64_t endpoint; const char *chatId; const char *userId; dbus_bool_t participant; if (dbus_message_get_args(message, NULL, DBUS_TYPE_UINT64, &endpoint, DBUS_TYPE_STRING, &chatId, DBUS_TYPE_STRING, &userId, DBUS_TYPE_BOOLEAN, &participant, DBUS_TYPE_INVALID)) { if (listener_) listener_->onUserJoin(endpoint, chatId, userId, participant); } else { reply = dbus_message_new_error(message, DBUS_ERROR_INVALID_ARGS, _("Expected userJoin(uint64 endpoint, string chatId, string userId, boolean participant)")); } } else if (strcmp(member, "UserLeave") == 0) { dbus_uint64_t endpoint; const char *chatId; const char *userId; if (dbus_message_get_args(message, NULL, DBUS_TYPE_UINT64, &endpoint, DBUS_TYPE_STRING, &chatId, DBUS_TYPE_STRING, &userId, DBUS_TYPE_INVALID)) { if (listener_) listener_->onUserLeave(endpoint, chatId, userId); } else { reply = dbus_message_new_error(message, DBUS_ERROR_INVALID_ARGS, _("Expected userLeave(uint64 endpoint, string chatId, string userId)")); } } else if (strcmp(member, "Message") == 0) { dbus_uint64_t endpoint; const char *chatId; const char *userId; const char *text; dbus_int32_t sentiment; double timestamp; int serial; if (dbus_message_get_args(message, NULL, DBUS_TYPE_UINT64, &endpoint, DBUS_TYPE_STRING, &chatId, DBUS_TYPE_STRING, &userId, DBUS_TYPE_STRING, &text, DBUS_TYPE_INT32, &sentiment, DBUS_TYPE_DOUBLE, ×tamp, DBUS_TYPE_INT32, &serial, DBUS_TYPE_INVALID)) { if (listener_) listener_->onMessage(endpoint, chatId, userId, text, sentiment, timestamp, serial); } else { reply = dbus_message_new_error(message, DBUS_ERROR_INVALID_ARGS, _("Expected Messsage(uint64 endpoint, string chatId, string userId, string text, int32 sentiment, double timestamp, int32 serial)")); } } else if (strcmp(member, "UserInfo") == 0) { dbus_uint64_t endpoint; const char *userId; const char *name; const char *smallPhotoUrl; const char *currentSong; const char *currentArtist; dbus_bool_t musicPlaying; if (dbus_message_get_args(message, NULL, DBUS_TYPE_UINT64, &endpoint, DBUS_TYPE_STRING, &userId, DBUS_TYPE_STRING, &name, DBUS_TYPE_STRING, &smallPhotoUrl, DBUS_TYPE_STRING, ¤tSong, DBUS_TYPE_STRING, ¤tArtist, DBUS_TYPE_BOOLEAN, &musicPlaying, DBUS_TYPE_INVALID)) { if (listener_) listener_->userInfo(endpoint, userId, name, smallPhotoUrl, currentSong, currentArtist, musicPlaying); } else { reply = dbus_message_new_error(message, DBUS_ERROR_INVALID_ARGS, _("Expected UserInfo(uint64 endpoint, string userId, string name, string smallPhotoUrl, string currentSong, boolean musicPlaying)")); } } else if (strcmp(member, "ApplicationInfo") == 0) { dbus_uint64_t endpoint; const char *applicationId; dbus_bool_t canInstall; dbus_bool_t canRun; const char *version; if (dbus_message_get_args(message, NULL, DBUS_TYPE_UINT64, &endpoint, DBUS_TYPE_STRING, &applicationId, DBUS_TYPE_BOOLEAN, &canInstall, DBUS_TYPE_BOOLEAN, &canRun, DBUS_TYPE_STRING, &version, DBUS_TYPE_INVALID)) { if (listener_) listener_->applicationInfo(endpoint, applicationId, canInstall, canRun, version); } else { reply = dbus_message_new_error(message, DBUS_ERROR_INVALID_ARGS, _("Expected ApplicationInfo(uint64 endpoint, string applicationId, boolean canInstall, boolean canRun, string version)")); } } else { reply = dbus_message_new_error(message, DBUS_ERROR_UNKNOWN_METHOD, _("Unknown callback method")); } if (reply) { dbus_connection_send(connection_, reply, NULL); dbus_message_unref(reply); } return DBUS_HANDLER_RESULT_HANDLED; }
/******************************************************************************* * igmp_snp_dbus_igmp_snp_time_get * * DESCRIPTION: * get IGMP snooping Timer parammeters and each default values * * INPUTS: * conn - dbusconnection * msg - dbusmessage * user_data - dbus data * * OUTPUTS: * null * * RETURNS: * reply - * * COMMENTS: * ** ********************************************************************************/ DBusMessage * igmp_snp_dbus_igmp_snp_time_get ( DBusConnection *conn, DBusMessage *msg, void *user_data ) { DBusMessage* reply; DBusMessageIter iter = {0}; DBusError err; int length = 0; int state = 0; int rc = 0; int ret = 0; char *showStr = NULL; char *current = NULL; unsigned char Ismld = 0; int sw_config_flag = 0; dbus_error_init(&err); if( !(dbus_message_get_args( msg ,&err, \ DBUS_TYPE_BYTE, &Ismld, \ DBUS_TYPE_INVALID))) { igmp_snp_syslog_err("unable to get input args\n"); if(dbus_error_is_set( &err )) { igmp_snp_syslog_err("%s raised:%s\n",err.name ,err.message); dbus_error_free( &err ); } return NULL; } reply = dbus_message_new_method_return(msg); if(NULL == reply) { igmp_snp_syslog_dbg("dbus add igmp or mld snoop time no reply resource error!\n"); return reply; } /**************************************** * save config igmp snooping times information ***************************************/ showStr = (char*)malloc(IGMP_DBUS_RUNNING_CFG_MEM); if(NULL == showStr) { igmp_snp_syslog_dbg("memory malloc error.\n"); return NULL; } memset(showStr, 0, IGMP_DBUS_RUNNING_CFG_MEM); if ((igmp_snoop_enable == IGMP_SNOOP_YES) || (mld_snoop_enable == IGMP_SNOOP_YES)) { ret = 0; current = showStr; /* into igmp/mld sw-board config node */ if((igmp_vlanlife != IGMP_VLAN_LIFE_TIME)||(igmp_grouplife != IGMP_GROUP_LIFETIME) \ ||(igmp_robust_variable != IGMP_ROBUST_VARIABLE)||(igmp_query_interval != IGMP_V2_UNFORCED_QUERY_INTERVAL) \ ||(igmp_resp_interval != IGMP_V2_QUERY_RESP_INTERVAL)) { if ((length + 35) < IGMP_DBUS_RUNNING_CFG_MEM) { if((IGMP_SNOOP_YES == igmp_snoop_enable) && (ISIGMP == Ismld)){ length += sprintf(current, "config igmp-snooping sw-board %d\n", igmp_slot); sw_config_flag = 1; } else if((IGMP_SNOOP_YES == mld_snoop_enable) && (ISMLD == Ismld)){ length += sprintf(current, "config mld-snooping sw-board %d\n", igmp_slot); sw_config_flag = 1; } igmp_snp_syslog_dbg("%s\n", current); current = showStr + length; } } if (igmp_vlanlife != IGMP_VLAN_LIFE_TIME) { if ((length + 40) < IGMP_DBUS_RUNNING_CFG_MEM) { if((IGMP_SNOOP_YES == igmp_snoop_enable) && (ISIGMP == Ismld)){ length += sprintf(current, " config igmp-snooping vlan-lifetime %d\n", igmp_vlanlife); } if((IGMP_SNOOP_YES == mld_snoop_enable) && (ISMLD == Ismld)){ length += sprintf(current, " config mld-snooping vlan-lifetime %d\n", igmp_vlanlife); } igmp_snp_syslog_dbg("%s\n", current); current = showStr + length; } } if (igmp_grouplife != IGMP_GROUP_LIFETIME) { if ((length + 40) < IGMP_DBUS_RUNNING_CFG_MEM) { if((IGMP_SNOOP_YES == igmp_snoop_enable) && (ISIGMP == Ismld)){ length += sprintf(current, " config igmp-snooping group-lifetime %d\n", igmp_grouplife); } if((IGMP_SNOOP_YES == mld_snoop_enable) && (ISMLD == Ismld)){ length += sprintf(current, " config mld-snooping group-lifetime %d\n", igmp_grouplife); } igmp_snp_syslog_dbg("%s\n", current); current = showStr + length; } } if (igmp_robust_variable != IGMP_ROBUST_VARIABLE) { if ((length + 40) < IGMP_DBUS_RUNNING_CFG_MEM) { if((IGMP_SNOOP_YES == igmp_snoop_enable) && (ISIGMP == Ismld)){ length += sprintf(current, " config igmp-snooping robust %d\n", igmp_robust_variable); } if((IGMP_SNOOP_YES == mld_snoop_enable) && (ISMLD == Ismld)){ length += sprintf(current, " config mld-snooping robust %d\n", igmp_robust_variable); } igmp_snp_syslog_dbg("%s\n", current); current = showStr + length; } } if (igmp_query_interval != IGMP_V2_UNFORCED_QUERY_INTERVAL) { if ((length + 40) < IGMP_DBUS_RUNNING_CFG_MEM) { if((IGMP_SNOOP_YES == igmp_snoop_enable) && (ISIGMP == Ismld)){ length += sprintf(current, " config igmp-snooping query-interval %d\n", igmp_query_interval); } if((IGMP_SNOOP_YES == mld_snoop_enable) && (ISMLD == Ismld)){ length += sprintf(current, " config mld-snooping query-interval %d\n", igmp_query_interval); } igmp_snp_syslog_dbg("%s\n", current); current = showStr + length; } } if (igmp_resp_interval != IGMP_V2_QUERY_RESP_INTERVAL) { if ((length + 40) < IGMP_DBUS_RUNNING_CFG_MEM) { if((IGMP_SNOOP_YES == igmp_snoop_enable) && (ISIGMP == Ismld)){ length += sprintf(current, " config igmp-snooping response-interval %d\n", igmp_resp_interval); } if((IGMP_SNOOP_YES == mld_snoop_enable) && (ISMLD == Ismld)){ length += sprintf(current, " config mld-snooping response-interval %d\n", igmp_resp_interval); } igmp_snp_syslog_dbg("%s\n", current); current = showStr + length; } } /* exit conifg sw-board node */ if(sw_config_flag ==1) { /* exit distributed igmp sw-baord config node */ length += sprintf(current,"exit\n"); current = showStr + length; } } else { ret = -1; } dbus_message_iter_init_append(reply, &iter); dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &showStr); free(showStr); return reply; }
DBusHandlerResult HippoDBusIpcProviderImpl::handleSignal(DBusMessage *message) { g_assert(connection_ != NULL); const char *sender = dbus_message_get_sender(message); const char *interface = dbus_message_get_interface(message); const char *member = dbus_message_get_member(message); const char *path = dbus_message_get_path(message); g_debug("signal from %s %s.%s on %s", sender ? sender : "NULL", interface ? interface : "NULL", member ? member : "NULL", path ? path : "NULL"); if (dbus_message_has_sender(message, DBUS_SERVICE_DBUS) && dbus_message_is_signal(message, DBUS_INTERFACE_DBUS, "NameOwnerChanged")) { const char *name = NULL; const char *old_owner = NULL; const char *new_owner = NULL; if (dbus_message_get_args(message, NULL, DBUS_TYPE_STRING, &name, DBUS_TYPE_STRING, &old_owner, DBUS_TYPE_STRING, &new_owner, DBUS_TYPE_INVALID)) { g_debug("NameOwnerChanged %s '%s' -> '%s'", name, old_owner, new_owner); if (*old_owner == '\0') old_owner = NULL; if (*new_owner == '\0') new_owner = NULL; if (strcmp(name, busName_) == 0) { // this will notify about disconnection from old if (busUniqueName_ && old_owner && strcmp(busUniqueName_, old_owner) == 0) { setBusUniqueName(NULL); } // now notify about connection to something new if (new_owner) { setBusUniqueName(new_owner); } } } else { g_warning("NameOwnerChanged had wrong args???"); } } else if (dbus_message_is_signal(message, DBUS_INTERFACE_LOCAL, "Disconnected")) { forgetBusConnection(); } else if (busUniqueName_ && dbus_message_has_sender(message, busUniqueName_) && dbus_message_is_signal(message, HIPPO_DBUS_STACKER_LISTENER_INTERFACE, "Connected")) { clientConnected_ = true; notifyRegisterEndpointOpportunity(); } else if (busUniqueName_ && dbus_message_has_sender(message, busUniqueName_) && dbus_message_is_signal(message, HIPPO_DBUS_STACKER_LISTENER_INTERFACE, "Disconnected")) { clientConnected_ = false; notifyEndpointsInvalidated(); } /* we never want to "HANDLED" a signal really, doesn't make sense */ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; }
static dbus_bool_t dbus_bus_get_unix_process_id(DBusConnection* conn, const char* name, pid_t* pid) { DBusMessage* msg; DBusMessage* reply; DBusError err; dbus_uint32_t pid_arg; msg = dbus_message_new_method_call("org.freedesktop.DBus", "/org/freedesktop/DBus", "org.freedesktop.DBus", "GetConnectionUnixProcessID"); if (!msg) { dsme_log(LOG_DEBUG, "Unable to allocate new message"); return FALSE; } if (!dbus_message_append_args(msg, DBUS_TYPE_STRING, &name, DBUS_TYPE_INVALID)) { dsme_log(LOG_DEBUG, "Unable to append arguments to message"); dbus_message_unref(msg); return FALSE; } // TODO: it is risky that we are blocking dbus_error_init(&err); reply = dbus_connection_send_with_reply_and_block(conn, msg, -1, &err); if (dbus_error_is_set(&err)) { dsme_log(LOG_DEBUG, "Sending GetConnectionUnixProcessID failed: %s", err.message); dbus_error_free(&err); dbus_message_unref(msg); return FALSE; } dbus_error_init(&err); dbus_message_get_args(reply, &err, DBUS_TYPE_UINT32, &pid_arg, DBUS_TYPE_INVALID); if (dbus_error_is_set(&err)) { dsme_log(LOG_DEBUG, "Getting GetConnectionUnixProcessID args failed: %s", err.message); dbus_error_free(&err); dbus_message_unref(msg); dbus_message_unref(reply); return FALSE; } *pid = pid_arg; dbus_message_unref(msg); dbus_message_unref(reply); return TRUE; }
static int kwallet_create_folder( vlc_keystore* p_keystore, const char* psz_folder_name ) { vlc_keystore_sys* p_sys = p_keystore->p_sys; DBusMessage* msg = NULL; DBusMessage* repmsg = NULL; DBusError error; DBusMessageIter args; dbus_bool_t b_reply; int i_ret = VLC_EGENERIC; /* init */ msg = vlc_dbus_new_method( p_keystore, "createFolder" ); if ( !msg ) { msg_Err( p_keystore, "kwallet_create_folder : vlc_dbus_new_method failed" ); return VLC_EGENERIC; } /* argument init */ dbus_message_iter_init_append( msg, &args ); if ( !dbus_message_iter_append_basic( &args, DBUS_TYPE_INT32, &p_sys->i_handle ) || !dbus_message_iter_append_basic( &args, DBUS_TYPE_STRING, &psz_folder_name ) || !dbus_message_iter_append_basic( &args, DBUS_TYPE_STRING, &p_sys->psz_app_id ) ) goto end; /* sending message */ repmsg = vlc_dbus_send_message( p_keystore, msg ); if ( !repmsg ) { msg_Err( p_keystore, "kwallet_create_folder : vlc_dbus_send_message failed" ); goto end; } /* handling reply */ dbus_error_init( &error ); if ( !dbus_message_get_args( repmsg, &error, DBUS_TYPE_BOOLEAN, &b_reply, DBUS_TYPE_INVALID ) ) { msg_Err( p_keystore, "kwallet_create_folder :" " dbus_message_get_args failed\n%s", error.message ); dbus_error_free( &error ); goto end; } if ( !b_reply ) { msg_Err( p_keystore, "kwallet_create_folder : Could not create folder" ); goto end; } i_ret = VLC_SUCCESS; end: if ( msg ) dbus_message_unref( msg ); if ( repmsg ) dbus_message_unref( repmsg ); return i_ret; }
int ccgi_dbus_eag_conf_nas(DBusConnection *conn, dbus_nas_conf nas_conf) { DBusMessage *query, *reply; DBusError err; int ret_nas = -1; query = dbus_message_new_method_call( EAG_AURO_SERVER, EAG_AURO_CONF_OBJECT, INTERFACE_AURO_NAS, METHOD_NAS ); if (NULL == query) { fprintf(stderr, "ccgi_dbus_eag_conf_nas:Message Null\n"); } dbus_error_init(&err); const char * tmp_n_nastype = nas_conf.n_nastype; const char * tmp_n_start = nas_conf.n_start; const char * tmp_n_end = nas_conf.n_end; const char * tmp_n_nasid = nas_conf.n_nasid; const char * tmp_n_syntaxis = nas_conf.n_syntaxis; const char * tmp_n_attz = nas_conf.n_attz; //fprintf(stderr,"eag_auto_conf n_flag=%d,n_default=%d,n_plotid=%u,n_nastype=%s,n_start=%s,n_end=%s,n_nasid=%u,n_syntaxis=%u",\ // nas_conf.n_flag,nas_conf.n_default,nas_conf.n_plotid,tmp_n_nastype,tmp_n_start,tmp_n_end,nas_conf.n_nasid,nas_conf.n_syntaxis); dbus_message_append_args( query, DBUS_TYPE_INT32, &nas_conf.n_flag, DBUS_TYPE_INT32, &nas_conf.n_default, DBUS_TYPE_INT32, &nas_conf.n_plotid, DBUS_TYPE_STRING, &tmp_n_nastype, DBUS_TYPE_STRING, &tmp_n_start, DBUS_TYPE_STRING, &tmp_n_end, DBUS_TYPE_STRING, &tmp_n_nasid, DBUS_TYPE_STRING, &tmp_n_syntaxis, DBUS_TYPE_STRING, &tmp_n_attz, DBUS_TYPE_INVALID ); reply = dbus_connection_send_with_reply_and_block ( conn, query, -1, &err ); dbus_message_unref(query); if ( NULL == reply ) { if (dbus_error_is_set(&err)) { fprintf(stderr, "ccgi_dbus_eag_conf_nas:send_with_reply_and_block Error:(%s)\n", err.message); dbus_error_free(&err); } ret_nas = ERR_DBUS_REPLY_NULL; } else { dbus_message_get_args( reply, &err, DBUS_TYPE_INT32, &ret_nas, DBUS_TYPE_INVALID ); dbus_message_unref(reply); } return ret_nas; }
static int kwallet_open( vlc_keystore* p_keystore ) { vlc_keystore_sys* p_sys = p_keystore->p_sys; DBusMessage* msg = NULL; DBusMessage* repmsg = NULL; DBusMessageIter args; DBusError error; unsigned long long ull_win_id = 0; unsigned int ui_reply = 1; bool b_has_folder; int i_ret = VLC_EGENERIC; /* init */ msg = vlc_dbus_new_method( p_keystore, "open" ); if ( !msg ) { msg_Err( p_keystore, "kwallet_open : vlc_dbus_new_method failed"); return VLC_EGENERIC; } /* Init args */ dbus_message_iter_init_append(msg, &args); if ( !dbus_message_iter_append_basic( &args, DBUS_TYPE_STRING, &p_sys->psz_wallet ) || !dbus_message_iter_append_basic( &args, DBUS_TYPE_INT64, &ull_win_id ) || !dbus_message_iter_append_basic( &args, DBUS_TYPE_STRING, &p_sys->psz_app_id ) ) goto end; /* sending message */ repmsg = vlc_dbus_send_message( p_keystore, msg ); if ( !repmsg ) { msg_Err( p_keystore, "kwallet_open : vlc_dbus_send_message failed" ); goto end; } /* reply arguments */ dbus_error_init( &error ); if ( !dbus_message_get_args( repmsg, &error, DBUS_TYPE_INT32, &ui_reply, DBUS_TYPE_INVALID ) ) { msg_Err( p_keystore, "kwallet_open :" " dbus_message_get_args failed\n%s", error.message ); dbus_error_free( &error ); goto end; } p_sys->i_handle = ui_reply; /* opening the vlc password folder == VLC_KEYSTORE_NAME */ if ( kwallet_has_folder( p_keystore, psz_folder, &b_has_folder ) ) goto end; if ( !b_has_folder ) { if ( kwallet_create_folder( p_keystore, psz_folder ) ) { msg_Err( p_keystore, "kwallet_open : could not create folder %s", psz_folder ); goto end; } } i_ret = VLC_SUCCESS; end: if ( msg ) dbus_message_unref( msg ); if ( repmsg ) dbus_message_unref( repmsg ); return i_ret; }
int main (int argc, char* argv[]) { char *servicename = NULL; char *address = NULL; DBusMessage* message = NULL; DBusConnection* conn = NULL; int c; int ret = 1; int messageType = FCITX_DBUS_GET_CURRENT_STATE; char *imname = NULL; while ((c = getopt(argc, argv, "chortTeam:s:")) != -1) { switch (c) { case 'o': messageType = FCITX_DBUS_ACTIVATE; break; case 'c': messageType = FCITX_DBUS_INACTIVATE; break; case 'r': messageType = FCITX_DBUS_RELOAD_CONFIG; break; case 't': case 'T': messageType = FCITX_DBUS_TOGGLE; break; case 'e': messageType = FCITX_DBUS_EXIT; break; case 'm': messageType = FCITX_DBUS_GET_IM_ADDON; imname = strdup(optarg); break; case 's': messageType = FCITX_DBUS_SET_CURRENT_IM; imname = strdup(optarg); break; case 'a': address = _fcitx_get_address(); if (address) { printf("%s\n", address); return 0; } else return 1; break; case 'h': usage(stdout); return 0; default: usage(stderr); return 1; break; } } #define CASE(ENUMNAME, MESSAGENAME) \ case FCITX_DBUS_##ENUMNAME: \ message = dbus_message_new_method_call(servicename, FCITX_IM_DBUS_PATH, FCITX_IM_DBUS_INTERFACE, #MESSAGENAME); \ break; asprintf(&servicename, "%s-%d", FCITX_DBUS_SERVICE, fcitx_utils_get_display_number()); switch(messageType) { CASE(ACTIVATE, ActivateIM); CASE(INACTIVATE, InactivateIM); CASE(RELOAD_CONFIG, ReloadConfig); CASE(EXIT, Exit); CASE(TOGGLE, ToggleIM); CASE(GET_CURRENT_STATE, GetCurrentState); CASE(GET_IM_ADDON, GetIMAddon); CASE(SET_CURRENT_IM, SetCurrentIM); default: goto some_error; }; if (!message) { goto some_error; } address = _fcitx_get_address(); do { if (!address) break; conn = dbus_connection_open(address, NULL); if (!conn) break; if (!dbus_bus_register(conn, NULL)) { dbus_connection_unref(conn); conn = NULL; break; } } while(0); if (!conn) { conn = dbus_bus_get(DBUS_BUS_SESSION, NULL); if (!conn) { goto some_error; } dbus_connection_set_exit_on_disconnect(conn, FALSE); } if (messageType == FCITX_DBUS_GET_CURRENT_STATE) { DBusMessage* reply = dbus_connection_send_with_reply_and_block(conn, message, 1000, NULL); int result = 0; if (reply && dbus_message_get_args(reply, NULL, DBUS_TYPE_INT32, &result, DBUS_TYPE_INVALID)) { printf("%d\n", result); ret = 0; } else { fprintf(stderr, "Not get reply\n"); } } else if (messageType == FCITX_DBUS_GET_IM_ADDON) { do { if (!fcitx_utf8_check_string(imname)) break; dbus_message_append_args(message, DBUS_TYPE_STRING, &imname, DBUS_TYPE_INVALID); DBusMessage* reply = dbus_connection_send_with_reply_and_block(conn, message, 1000, NULL); char *result = NULL; if (reply && dbus_message_get_args(reply, NULL, DBUS_TYPE_STRING, &result, DBUS_TYPE_INVALID)) { printf("%s\n", result); ret = 0; } else { fprintf(stderr, "Not get reply\n"); } } while(0); } else if (messageType == FCITX_DBUS_SET_CURRENT_IM) { do { if (!fcitx_utf8_check_string(imname)) break; dbus_message_append_args(message, DBUS_TYPE_STRING, &imname, DBUS_TYPE_INVALID); dbus_connection_send(conn, message, NULL); dbus_connection_flush(conn); ret = 0; } while(0); } else { dbus_connection_send(conn, message, NULL); dbus_connection_flush(conn); ret = 0; } some_error: if (message) dbus_message_unref(message); if (conn) dbus_connection_unref(conn); fcitx_utils_free(address); fcitx_utils_free(servicename); fcitx_utils_free(imname); return ret; }
static int kwallet_remove_entry( vlc_keystore* p_keystore, char* psz_entry_name ) { vlc_keystore_sys* p_sys = p_keystore->p_sys; DBusMessage* msg = NULL; DBusMessage* repmsg = NULL; DBusError error; DBusMessageIter args; int i_reply; bool b_has_entry = false; int i_ret = VLC_EGENERIC; if ( kwallet_has_entry( p_keystore, psz_entry_name, &b_has_entry ) ) { msg_Err( p_keystore, "kwallet_remove_entry : kwallet_has_entry failed" ); return VLC_EGENERIC; } if ( !b_has_entry ) { msg_Err( p_keystore, "kwallet_remove_entry : there is no such entry :" "%s", psz_entry_name ); return VLC_EGENERIC; } /* init */ if ( !( msg = vlc_dbus_new_method( p_keystore, "removeEntry" ) ) ) { msg_Err( p_keystore, "kwallet_remove_entry : vlc_dbus_new_method failed" ); return VLC_EGENERIC; } /* argument init */ dbus_message_iter_init_append( msg, &args ); if ( !dbus_message_iter_append_basic( &args, DBUS_TYPE_INT32, &p_sys->i_handle ) || !dbus_message_iter_append_basic( &args, DBUS_TYPE_STRING, &psz_folder ) || !dbus_message_iter_append_basic( &args, DBUS_TYPE_STRING, &psz_entry_name ) || !dbus_message_iter_append_basic( &args, DBUS_TYPE_STRING, &p_sys->psz_app_id ) ) goto end; /* sending message */ if ( !( repmsg = vlc_dbus_send_message( p_keystore, msg ) ) ) { msg_Err( p_keystore, "kwallet_remove_entry : vlc_dbus_send_message failed" ); goto end; } /* handling reply */ dbus_error_init( &error ); if ( !dbus_message_get_args( repmsg, &error, DBUS_TYPE_INT32, &i_reply, DBUS_TYPE_INVALID ) ) { msg_Err( p_keystore, "kwallet_remove entry :" " dbus_message_get_args failed\n%s", error.message ); dbus_error_free( &error ); goto end; } i_ret = VLC_SUCCESS; end: if ( msg ) dbus_message_unref( msg ); if ( repmsg ) dbus_message_unref( repmsg ); return i_ret; }
AvahiServiceResolver * avahi_service_resolver_new( AvahiClient *client, AvahiIfIndex interface, AvahiProtocol protocol, const char *name, const char *type, const char *domain, AvahiProtocol aprotocol, AvahiLookupFlags flags, AvahiServiceResolverCallback callback, void *userdata) { DBusError error; AvahiServiceResolver *r = NULL; DBusMessage *message = NULL, *reply = NULL; int32_t i_interface, i_protocol, i_aprotocol; uint32_t u_flags; char *path; assert(client); assert(type); if (!domain) domain = ""; if (!name) name = ""; dbus_error_init (&error); if (!avahi_client_is_connected(client)) { avahi_client_set_errno(client, AVAHI_ERR_BAD_STATE); goto fail; } if (!(r = avahi_new(AvahiServiceResolver, 1))) { avahi_client_set_errno(client, AVAHI_ERR_NO_MEMORY); goto fail; } r->client = client; r->callback = callback; r->userdata = userdata; r->path = NULL; r->name = r->type = r->domain = NULL; r->interface = interface; r->protocol = protocol; AVAHI_LLIST_PREPEND(AvahiServiceResolver, service_resolvers, client->service_resolvers, r); if (name && name[0]) if (!(r->name = avahi_strdup(name))) { avahi_client_set_errno(client, AVAHI_ERR_NO_MEMORY); goto fail; } if (!(r->type = avahi_strdup(type))) { avahi_client_set_errno(client, AVAHI_ERR_NO_MEMORY); goto fail; } if (domain && domain[0]) if (!(r->domain = avahi_strdup(domain))) { avahi_client_set_errno(client, AVAHI_ERR_NO_MEMORY); goto fail; } if (!(message = dbus_message_new_method_call(AVAHI_DBUS_NAME, AVAHI_DBUS_PATH_SERVER, AVAHI_DBUS_INTERFACE_SERVER, "ServiceResolverNew"))) { avahi_client_set_errno(client, AVAHI_ERR_NO_MEMORY); goto fail; } i_interface = (int32_t) interface; i_protocol = (int32_t) protocol; i_aprotocol = (int32_t) aprotocol; u_flags = (uint32_t) flags; if (!(dbus_message_append_args( message, DBUS_TYPE_INT32, &i_interface, DBUS_TYPE_INT32, &i_protocol, DBUS_TYPE_STRING, &name, DBUS_TYPE_STRING, &type, DBUS_TYPE_STRING, &domain, DBUS_TYPE_INT32, &i_aprotocol, DBUS_TYPE_UINT32, &u_flags, DBUS_TYPE_INVALID))) { avahi_client_set_errno(client, AVAHI_ERR_NO_MEMORY); goto fail; } if (!(reply = dbus_connection_send_with_reply_and_block(client->bus, message, -1, &error)) || dbus_error_is_set(&error)) { avahi_client_set_errno(client, AVAHI_ERR_DBUS_ERROR); goto fail; } if (!dbus_message_get_args (reply, &error, DBUS_TYPE_OBJECT_PATH, &path, DBUS_TYPE_INVALID) || dbus_error_is_set(&error) || !path) { avahi_client_set_errno(client, AVAHI_ERR_DBUS_ERROR); goto fail; } if (!(r->path = avahi_strdup(path))) { /* FIXME: We don't remove the object on the server side */ avahi_client_set_errno(client, AVAHI_ERR_NO_MEMORY); goto fail; } dbus_message_unref(message); dbus_message_unref(reply); return r; fail: if (dbus_error_is_set(&error)) { avahi_client_set_dbus_error(client, &error); dbus_error_free(&error); } if (r) avahi_service_resolver_free(r); if (message) dbus_message_unref(message); if (reply) dbus_message_unref(reply); return NULL; }
nsresult GetDefaultAdapterPathInternal(nsCString& aAdapterPath) { DBusMessage *msg = NULL, *reply = NULL; DBusError err; const char *device_path = NULL; int attempt = 0; for (attempt = 0; attempt < 1000 && reply == NULL; attempt ++) { msg = dbus_message_new_method_call("org.bluez", "/", "org.bluez.Manager", "DefaultAdapter"); if (!msg) { LOG("%s: Can't allocate new method call for get_adapter_path!", __FUNCTION__); return NS_ERROR_FAILURE; } dbus_message_append_args(msg, DBUS_TYPE_INVALID); dbus_error_init(&err); reply = dbus_connection_send_with_reply_and_block( sDBusConnection->mConnection, msg, -1, &err); if (!reply) { if (dbus_error_is_set(&err)) { if (dbus_error_has_name(&err, "org.freedesktop.DBus.Error.ServiceUnknown")) { // bluetoothd is still down, retry LOG("Service unknown\n"); dbus_error_free(&err); //usleep(10000); // 10 ms continue; } else if (dbus_error_has_name(&err, "org.bluez.Error.NoSuchAdapter")) { LOG("No adapter found\n"); dbus_error_free(&err); goto failed; } else { // Some other error we weren't expecting LOG("other error\n"); dbus_error_free(&err); } } } } if (attempt == 1000) { LOG("timeout\n"); //printfE("Time out while trying to get Adapter path, is bluetoothd up ?"); goto failed; } if (!dbus_message_get_args(reply, &err, DBUS_TYPE_OBJECT_PATH, &device_path, DBUS_TYPE_INVALID) || !device_path) { if (dbus_error_is_set(&err)) { dbus_error_free(&err); } goto failed; } dbus_message_unref(msg); aAdapterPath = nsDependentCString(device_path); return NS_OK; failed: dbus_message_unref(msg); return NS_ERROR_FAILURE; }
DBusHandlerResult avahi_address_resolver_event (AvahiClient *client, AvahiResolverEvent event, DBusMessage *message) { AvahiAddressResolver *r = NULL; DBusError error; const char *path; assert(client); assert(message); dbus_error_init (&error); if (!(path = dbus_message_get_path(message))) goto fail; for (r = client->address_resolvers; r; r = r->address_resolvers_next) if (strcmp (r->path, path) == 0) break; if (!r) goto fail; switch (event) { case AVAHI_RESOLVER_FOUND: { int32_t interface, protocol, aprotocol; uint32_t flags; char *name, *address; AvahiAddress a; if (!dbus_message_get_args( message, &error, DBUS_TYPE_INT32, &interface, DBUS_TYPE_INT32, &protocol, DBUS_TYPE_INT32, &aprotocol, DBUS_TYPE_STRING, &address, DBUS_TYPE_STRING, &name, DBUS_TYPE_UINT32, &flags, DBUS_TYPE_INVALID) || dbus_error_is_set (&error)) { fprintf(stderr, "Failed to parse resolver event.\n"); goto fail; } assert(address); if (!avahi_address_parse(address, (AvahiProtocol) aprotocol, &a)) { fprintf(stderr, "Failed to parse address\n"); goto fail; } r->callback(r, (AvahiIfIndex) interface, (AvahiProtocol) protocol, AVAHI_RESOLVER_FOUND, &a, name, (AvahiLookupResultFlags) flags, r->userdata); break; } case AVAHI_RESOLVER_FAILURE: { char *etxt; if (!dbus_message_get_args( message, &error, DBUS_TYPE_STRING, &etxt, DBUS_TYPE_INVALID) || dbus_error_is_set (&error)) { fprintf(stderr, "Failed to parse resolver event.\n"); goto fail; } avahi_client_set_errno(r->client, avahi_error_dbus_to_number(etxt)); r->callback(r, r->interface, r->protocol, event, &r->address, NULL, 0, r->userdata); break; } } return DBUS_HANDLER_RESULT_HANDLED; fail: dbus_error_free (&error); return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; }
/******************************************************************************* * igmp_snp_dbus_show_route_port * * DESCRIPTION: * show multicast route-port. * * INPUTS: * conn - dbusconnection * msg - dbusmessage * user_data - dbus data * * OUTPUTS: * null * * RETURNS: * reply - * * COMMENTS: * ** ********************************************************************************/ DBusMessage *igmp_snp_dbus_show_route_port ( DBusConnection *conn, DBusMessage *msg, void *user_data ) { DBusMessage *reply; DBusMessageIter iter; DBusError err; DBusMessageIter iter_array; unsigned int i = 0; unsigned int count = 0; unsigned int ret = IGMPSNP_RETURN_CODE_OK; unsigned short vlanId = 0; long eth_g_index_array[IGMP_DBUS_MAX_ETHPORT_PER_BOARD * IGMP_DBUS_MAX_CHASSIS_SLOT_COUNT]; /* init routeArray */ for (i = 0; i < (IGMP_DBUS_MAX_ETHPORT_PER_BOARD * IGMP_DBUS_MAX_CHASSIS_SLOT_COUNT); i++) { eth_g_index_array[i] = -1; } dbus_error_init(&err); if (!(dbus_message_get_args(msg, &err, DBUS_TYPE_UINT16, &vlanId, DBUS_TYPE_INVALID))) { igmp_snp_syslog_err("Unable to get input args "); if (dbus_error_is_set(&err)) { igmp_snp_syslog_err("%s raised: %s", err.name, err.message); dbus_error_free(&err); } return NULL; } ret = igmp_snp_route_port_show(vlanId, &count, eth_g_index_array); for (i = 0; i < count; i++) { if (eth_g_index_array[i] != -1) { igmp_snp_syslog_dbg("eth_g_index_array[%d]=[%d]\n", i, eth_g_index_array[i]); } } reply = dbus_message_new_method_return(msg); dbus_message_iter_init_append(reply, &iter); dbus_message_iter_append_basic(&iter, DBUS_TYPE_UINT32, &ret); dbus_message_iter_append_basic(&iter, DBUS_TYPE_UINT32, &count); dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY, DBUS_STRUCT_BEGIN_CHAR_AS_STRING DBUS_TYPE_UINT32_AS_STRING DBUS_STRUCT_END_CHAR_AS_STRING, &iter_array); for (i = 0; i < count; i++) { DBusMessageIter iter_struct; dbus_message_iter_open_container(&iter_array, DBUS_TYPE_STRUCT, NULL, &iter_struct); dbus_message_iter_append_basic(&iter_struct, DBUS_TYPE_UINT32, &(eth_g_index_array[i])); dbus_message_iter_close_container(&iter_array, &iter_struct); } dbus_message_iter_close_container (&iter, &iter_array); return reply; }
/** * Connects to the D-Bus system bus daemon and issues the method call * OpenSession on the ConsoleKit manager interface. The * connection to the bus is private. * * Returns FALSE on OOM, if the system bus daemon is not running, if * the ConsoleKit daemon is not running or if the caller doesn't have * sufficient privileges. * * @returns #TRUE if the operation succeeds */ dbus_bool_t ck_connector_open_session (CkConnector *connector, DBusError *error) { DBusError local_error; DBusMessage *message; DBusMessage *reply; dbus_bool_t ret; char *cookie; _ck_return_val_if_fail (connector != NULL, FALSE); _ck_return_val_if_fail ((error) == NULL || !dbus_error_is_set ((error)), FALSE); reply = NULL; message = NULL; ret = FALSE; dbus_error_init (&local_error); connector->connection = dbus_bus_get_private (DBUS_BUS_SYSTEM, &local_error); if (connector->connection == NULL) { if (dbus_error_is_set (&local_error)) { dbus_set_error (error, CK_CONNECTOR_ERROR, "Unable to open session: %s", local_error.message); dbus_error_free (&local_error); } goto out; } dbus_connection_set_exit_on_disconnect (connector->connection, FALSE); message = dbus_message_new_method_call ("org.freedesktop.ConsoleKit", "/org/freedesktop/ConsoleKit/Manager", "org.freedesktop.ConsoleKit.Manager", "OpenSession"); if (message == NULL) { goto out; } dbus_error_init (&local_error); reply = dbus_connection_send_with_reply_and_block (connector->connection, message, -1, &local_error); if (reply == NULL) { if (dbus_error_is_set (&local_error)) { dbus_set_error (error, CK_CONNECTOR_ERROR, "Unable to open session: %s", local_error.message); dbus_error_free (&local_error); goto out; } } dbus_error_init (&local_error); if (! dbus_message_get_args (reply, &local_error, DBUS_TYPE_STRING, &cookie, DBUS_TYPE_INVALID)) { if (dbus_error_is_set (&local_error)) { dbus_set_error (error, CK_CONNECTOR_ERROR, "Unable to open session: %s", local_error.message); dbus_error_free (&local_error); goto out; } } connector->cookie = strdup (cookie); if (connector->cookie == NULL) { goto out; } connector->session_created = TRUE; ret = TRUE; out: if (reply != NULL) { dbus_message_unref (reply); } if (message != NULL) { dbus_message_unref (message); } return ret; }
bool dbus_proc_property(const char *method, DBusMessage *msg, DBusMessage *reply, DBusError *error, struct gsh_dbus_interface **interfaces) { const char *interface; const char *prop_name; bool retval = false; struct gsh_dbus_interface **iface; struct gsh_dbus_prop **prop; DBusMessageIter reply_iter; dbus_message_iter_init_append(reply, &reply_iter); if (strcmp(method, "GetAll") == 0) { DBusMessageIter getall_dict, dict_entry, val_iter; if (!dbus_message_get_args (msg, error, DBUS_TYPE_STRING, &interface, DBUS_TYPE_INVALID)) goto err_out; iface = lookup_interface(interface, interfaces, error); if (*iface == NULL) goto err_out; if (!dbus_message_iter_open_container (&reply_iter, DBUS_TYPE_ARRAY, DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_VARIANT_AS_STRING DBUS_DICT_ENTRY_END_CHAR_AS_STRING, &getall_dict)) goto getall_err; for (prop = (*iface)->props; prop && *prop; prop++) { prop_name = (*prop)->name; if ((*prop)->access == DBUS_PROP_READ || (*prop)->access == DBUS_PROP_READWRITE) { if (!dbus_message_iter_open_container (&getall_dict, DBUS_TYPE_DICT_ENTRY, NULL, &dict_entry)) goto getall_err; if (!dbus_message_iter_append_basic (&dict_entry, DBUS_TYPE_STRING, &prop_name)) goto getall_err; if (!dbus_message_iter_open_container (&dict_entry, DBUS_TYPE_VARIANT, (*prop)->type, &val_iter)) goto getall_err; if (!(*prop)->get(&val_iter)) goto getall_err; if (!dbus_message_iter_close_container (&dict_entry, &val_iter)) goto getall_err; if (!dbus_message_iter_close_container (&getall_dict, &dict_entry)) goto getall_err; } else { dbus_set_error(error, DBUS_ERROR_PROPERTY_READ_ONLY, "%s of %s from %s (write only?)", method, prop_name, interface); /** @todo@ check does write only make sense?? */ goto err_out; } } if (!dbus_message_iter_close_container (&reply_iter, &getall_dict)) goto getall_err; return true; /* DONE! */ } else if (strcmp(method, "Get") == 0) { if (!dbus_message_get_args (msg, error, DBUS_TYPE_STRING, &interface, DBUS_TYPE_STRING, &prop_name, DBUS_TYPE_INVALID)) goto err_out; iface = lookup_interface(interface, interfaces, error); if (*iface == NULL) goto err_out; prop = lookup_property(prop_name, iface, error); if (*prop == NULL) goto err_out; if ((*prop)->access == DBUS_PROP_READ || (*prop)->access == DBUS_PROP_READWRITE) { DBusMessageIter variant_iter; if (!dbus_message_iter_open_container (&reply_iter, DBUS_TYPE_VARIANT, (*prop)->type, &variant_iter)) { dbus_set_error_const(error, DBUS_ERROR_FAILED, "Couldn't open Get container"); goto err_out; } retval = (*prop)->get(&variant_iter); if (retval == false || !dbus_message_iter_close_container(&reply_iter, &variant_iter)) { dbus_set_error_const(error, DBUS_ERROR_FAILED, "Couldn't close Get container"); goto err_out; } } else { dbus_set_error(error, DBUS_ERROR_PROPERTY_READ_ONLY, "%s of %s from %s (write only?)", method, prop_name, interface); /** @todo@ check does write only make sense?? */ goto err_out; } return true; /* DONE! */ } else if (strcmp(method, "Set") == 0) { DBusMessageIter iter_args; if (!dbus_message_iter_init(msg, &iter_args) || dbus_message_iter_get_arg_type(&iter_args) != DBUS_TYPE_STRING) { goto invalid_args; } dbus_message_iter_get_basic(&iter_args, &interface); if (!dbus_message_iter_next(&iter_args) || dbus_message_iter_get_arg_type(&iter_args) != DBUS_TYPE_STRING) { goto invalid_args; } dbus_message_iter_get_basic(&iter_args, &prop_name); if (!dbus_message_iter_next(&iter_args) || dbus_message_iter_get_arg_type(&iter_args) != DBUS_TYPE_VARIANT || dbus_message_iter_has_next(&iter_args)) { goto invalid_args; } iface = lookup_interface(interface, interfaces, error); if (*iface == NULL) goto err_out; prop = lookup_property(prop_name, iface, error); if (*prop == NULL) goto err_out; if ((*prop)->access == DBUS_PROP_WRITE || (*prop)->access == DBUS_PROP_READWRITE) { DBusMessageIter arg; dbus_message_iter_recurse(&iter_args, &arg); return (*prop)->set(&arg); /* DONE! */ } else { dbus_set_error(error, DBUS_ERROR_PROPERTY_READ_ONLY, "%s of %s from %s", method, prop_name, interface); goto err_out; } } else { dbus_set_error(error, DBUS_ERROR_UNKNOWN_METHOD, "Requested method: %s", method); } return retval; getall_err: dbus_set_error(error, DBUS_ERROR_FAILED, "GetAll container failure"); goto err_out; invalid_args: dbus_set_error(error, DBUS_ERROR_INVALID_ARGS, "Method %s", method); err_out: return retval; }