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); }
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; }
unsigned long HFPMsgCallBack(HFPEVENT event, void* lpParam, unsigned long param) { printf("HFPMsgCallBack:%d\n",event); switch (event) { case RING_EVENT: { return 1; } break; case SMS_SUCCESS: { printf("send sms success\n"); system("dbus-send / com.asianux.sms.succesd "); system("dbus-send / com.asianux.fom.succesd "); } break; case SMS_FAILED: { system("dbus-send / com.asianux.sms.failed "); system("dbus-send / com.asianux.fom.failed "); printf("sms sms filed\n"); } break; case PHONESTATUS_EVENT: { PHONESTATUS status = (PHONESTATUS)param; switch (status) { case CALLINCOMING: { printf("-----call in -----\n"); return 0; } break; case CALLOUTGOING: { printf("-----call out -----\n"); usleep(1200); send_panel_message(); // app_agent_set_play(appAgent); is_calling = TRUE; } break; case CALLACTIVE: { printf("-----call active-----\n"); DBusMessage *message; dbus_uint32_t serial = 0; message = dbus_message_new_signal("/","com.asianux.notification","begin"); if (!dbus_connection_send(dbus_conn,message,&serial)) { exit(1); } dbus_connection_flush(dbus_conn); dbus_message_unref(message); // app_agent_set_play(appAgent); send_panel_message(); is_calling = TRUE; } break; case CALLINACTIVE: { printf("-----call end-----\n"); if(is_calling == TRUE) { printf("-----end---\n\n"); DBusMessage *msg; dbus_uint32_t serial_1 = 0; msg = dbus_message_new_signal("/","com.asianux.notification","end"); if (!dbus_connection_send(dbus_conn,msg,&serial_1)) { printf("-----send end notification failed-----\n"); exit(1); } dbus_connection_flush(dbus_conn); dbus_message_unref(msg); } else { printf("----hook----\n\n"); DBusMessage *msg2; dbus_uint32_t serial_2 =0; msg2 = dbus_message_new_signal("/","com.asianux.notification","hook"); if(!dbus_connection_send(dbus_conn,msg2,&serial_2)) { printf("-------send hook notification failed-----\n"); exit(1); } dbus_connection_flush(dbus_conn); dbus_message_unref(msg2); } // app_agent_set_stop(appAgent); is_calling = FALSE; is_new = FALSE; // printf("##############################end\n"); } break; } } break; case CALLERNUMBER_EVENT: //呼叫着电话号码 { char number[512]; sprintf(number," dbus-send / com.asianux.notification.notify string:dial string:%s string: string: ",param); if (!is_new) { system(number); is_new = TRUE; } return 1; } break; case SMMT_EVENT: { printf("----param is %s-----\n",param); const char *pconstChar =(const char *)param; char test[1024]; sprintf(test,"%s",pconstChar); printf("****************%s\n",test); int length = strlen(pconstChar); if (length == 0) { return 1; } char *sms =(char *)malloc(sizeof(char)*(length+1)); strcpy(sms,pconstChar); printf("------%s--------------%s\n",sms,pconstChar); char *pchar[3]; pchar[0] = pchar[1] = pchar[2]=0; int pos=0; pchar[0] = sms; int itmp = 1; pos = strcspn(sms,";"); while (pos<length) { pchar[itmp-1][pos] ='\0'; pchar[itmp] = pchar[itmp-1]+pos+1; length-=(pos)+1; } pos = strcspn(pchar[itmp],";"); pchar[itmp][pos]='\0'; pchar[itmp+1]=pchar[itmp]+pos+1; printf("收到短信(rev sm):%s ## %s ## %s %s\n", pchar[0],pchar[1],pchar[2],sms); char *sms_fom =(char *)malloc(512); sms_fom = strdup(pchar[2]); int index = 0; char *sms_str[3]; sms_str[0] = sms_str[1] = sms_str[2]=0; sms_str[0] =sms_fom; index = strcspn(sms_fom,":"); if (index == 3) { sms_str[0][index] = '\0'; sms_str[1] =sms_str[0]+index+1; if (strcmp(sms_str[0],"tas") == 0) { char *number = (char *)malloc(64); strncpy(number,sms_str[1],3); char *message = (char *)malloc(1024); sprintf(message,"dbus-send / com.asianux.smsterm.sms string:\"%s\"",strdup(test)); printf("==============%s\n",message); system(message); free(message); message = NULL; free(number); number = NULL; return 1; } else { char *errMsg = NULL; char sql[500]; int ret = sqlite3_open("/root/.sms.db",&db); if (ret == SQLITE_OK) { } else { // printf("open database failed\n"); } time(&sms_time); char *number =(char *) malloc(50); char *time = (char *)malloc(50); char *text = (char *)malloc(1024); char *content = (char *)malloc(1024); char *filter_number = (char *)malloc(50); char *filter_sms = (char *)malloc(1024); number = strdup(pchar[0]); time = strdup(pchar[1]); text = strdup(pchar[2]); int i=0; int j = 0; for (; i<strlen(text); i++) { if (text[i] =='\n' || text[i] =='\r') { content[j]=' '; } else if (text[i] == '\'') { content[j] =='\''; j++; content[j]='\''; } else { content[j]=text[i]; } j++; } content[j] = '\0'; int m=0; int n=0; for (; n<strlen(text); n++) { if (text[n] =='\n' || text[n] =='\r') { filter_sms[m]=' '; } else if (text[n] == '\'' || text[n] == '\"') { filter_sms[m]=' '; } else { filter_sms[m]=text[n]; } m++; } filter_sms[m]='\0'; char *str= NULL; str = strstr(number,"+86"); if (str) { int j=3; int m = 0; for (; number[j] != '\0'; j++) { filter_number[m]=number[j]; m++; } filter_number[m]='\0'; } else { filter_number = strdup(number); } sprintf(sql,"INSERT INTO \"sms\" VALUES(NULL,1,'%s',NULL,'%s\n','%s',1,%ld);",filter_number,content,time,sms_time); ret = sqlite3_exec(db,sql,0,0,&errMsg); if (ret == SQLITE_OK) { sqlite3_close(db); free(sms); sms = NULL; char *send = (char *)malloc((1024)*sizeof(char)); sprintf(send,"dbus-send / com.asianux.notification.notify string:\"sms\" string:\"%s\" string:\"%s\" string:\"%s\"",number,filter_sms,time); system(send); free(send); send = NULL; free(number); free(time); free(text); free(content); free(filter_number); free(filter_sms); number = NULL; time = NULL; text = NULL; content = NULL; filter_number = NULL; filter_sms = NULL; return 1; } else { sqlite3_close(db); free(sms); sms = NULL; free(number); free(time); free(text); free(content); free(filter_number); free(filter_sms); number = NULL; time = NULL; text = NULL; content = NULL; filter_number = NULL; filter_sms = NULL; return 0; } } } else { char *errMsg = NULL; char sql[500]; int ret = sqlite3_open("/root/.sms.db",&db); if (ret == SQLITE_OK) { } else { } time(&sms_time); char *number =(char *) malloc(50); char *time = (char *)malloc(50); char *text = (char *)malloc(1024); char *content = (char *)malloc(1024); char *filter_number = (char *)malloc(50); char *filter_sms = (char *)malloc(1024); number = strdup(pchar[0]); time = strdup(pchar[1]); text = strdup(pchar[2]); int i=0; int j=0; for (; i<strlen(text); i++) { if (text[i] =='\n' || text[i] =='\r') { content[j]=' '; } else if (text[i] == '\'') { content[j]='\''; j++; content[j] = '\''; } else { content[j]=text[i]; } j++; } content[j]='\0'; int m=0; int n=0; for (; n<strlen(text); n++) { if (text[n] =='\n' || text[n] =='\r') { filter_sms[m]=' '; } else if (text[n] == '\'' || text[n] == '\"') { filter_sms[m]=' '; } else { filter_sms[m]=text[n]; } m++; } filter_sms[m]='\0'; char *str= NULL; str = strstr(number,"+86"); if (str) { int j=3; int m = 0; for (; number[j] != '\0'; j++) { filter_number[m]=number[j]; m++; } filter_number[m]='\0'; } else { filter_number = strdup(number); } sprintf(sql,"INSERT INTO \"sms\" VALUES(NULL,1,'%s',NULL,'%s\n','%s',1,%ld);",filter_number,content,time,sms_time); ret = sqlite3_exec(db,sql,0,0,&errMsg); if (ret == SQLITE_OK) { sqlite3_close(db); free(sms); sms = NULL; char *send = (char *)malloc((1024)*sizeof(char)); sprintf(send,"dbus-send / com.asianux.notification.notify string:sms string:\"%s\" string:\"%s\" string:\"%s\"",number,filter_sms,time); system(send); free(send); send = NULL; free(number); free(time); free(text); free(content); free(filter_number); free(filter_sms); number = NULL; time = NULL; text = NULL; content = NULL; filter_number = NULL; filter_sms = NULL; return 1; } else { sqlite3_close(db); free(sms); sms = NULL; free(number); free(time); free(text); free(content); free(filter_number); free(filter_sms); number = NULL; time = NULL; text = NULL; content = NULL; filter_number = NULL; filter_sms = NULL; return 0; } } free(sms_fom); sms_fom = NULL; } break; } }
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; }
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; }
static void unmount_childs (LibHalContext *ctx, const char *udi) { int num_volumes; char **volumes; DBusError error; /* need to force unmount all partitions */ dbus_error_init (&error); if ((volumes = libhal_manager_find_device_string_match (ctx, "block.storage_device", udi, &num_volumes, &error)) != NULL) { int i; for (i = 0; i < num_volumes; i++) { char *vol_udi; vol_udi = volumes[i]; LIBHAL_FREE_DBUS_ERROR (&error); if (libhal_device_get_property_bool (ctx, vol_udi, "block.is_volume", &error)) { dbus_bool_t is_crypto; /* unmount all cleartext devices associated with us */ is_crypto = unmount_cleartext_devices (ctx, vol_udi); LIBHAL_FREE_DBUS_ERROR (&error); if (libhal_device_get_property_bool (ctx, vol_udi, "volume.is_mounted", &error)) { HAL_DEBUG (("Forcing unmount of child '%s'", vol_udi)); force_unmount (ctx, vol_udi); } /* teardown crypto */ if (is_crypto) { DBusMessage *msg = NULL; DBusMessage *reply = NULL; /* tear down mapping */ HAL_DEBUG (("Teardown crypto for '%s'", vol_udi)); msg = dbus_message_new_method_call ("org.freedesktop.Hal", vol_udi, "org.freedesktop.Hal.Device.Volume.Crypto", "Teardown"); if (msg == NULL) { HAL_ERROR (("Could not create dbus message for %s", vol_udi)); goto teardown_failed; } LIBHAL_FREE_DBUS_ERROR (&error); if (!(reply = dbus_connection_send_with_reply_and_block ( libhal_ctx_get_dbus_connection (ctx), msg, -1, &error)) || dbus_error_is_set (&error)) { HAL_DEBUG (("Teardown failed for %s: %s : %s\n", udi, error.name, error.message)); dbus_error_free (&error); } teardown_failed: if (msg != NULL) dbus_message_unref (msg); if (reply != NULL) dbus_message_unref (reply); } } } libhal_free_string_array (volumes); } LIBHAL_FREE_DBUS_ERROR (&error); }
static void test_session_connect_free_ride_notify(struct test_session *session) { struct test_session *session0 = get_session(session, 0); struct test_session *session1 = get_session(session, 1); enum test_session_state state = get_session_state(session); enum test_session_state next_state = state; DBusMessage *msg; LOG("state %d session %p %s online %d", state, session, session->notify_path, session->info->online); switch (state) { case TEST_SESSION_STATE_0: if (session0->info->online == FALSE && session1->info->online == FALSE) { next_state = TEST_SESSION_STATE_1; } break; case TEST_SESSION_STATE_1: if (session0->info->online == TRUE && session1->info->online == TRUE) { next_state = TEST_SESSION_STATE_2; } break; case TEST_SESSION_STATE_2: if (session0->info->online == FALSE && session1->info->online == FALSE) { next_state = TEST_SESSION_STATE_3; } break; case TEST_SESSION_STATE_3: return; } if (state == next_state) return; set_session_state(session, next_state); LOG("next_state %d", next_state); switch (next_state) { case TEST_SESSION_STATE_0: return; case TEST_SESSION_STATE_1: msg = session_connect(session0->connection, session0); g_assert(msg != NULL); dbus_message_unref(msg); return; case TEST_SESSION_STATE_2: msg = session_disconnect(session0->connection, session0); g_assert(msg != NULL); dbus_message_unref(msg); return; case TEST_SESSION_STATE_3: util_session_cleanup(session0); util_session_cleanup(session1); util_idle_call(session0->fix, util_quit_loop, util_session_destroy); return; } }
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); }
void notify(DBusMessage * dmsg) { DBusMessage *reply; DBusMessageIter args; DBusMessageIter hints; DBusMessageIter hint; char *hint_name; int i; int id; const char *appname = NULL; const char *summary = NULL; const char *body = NULL; const char *icon = NULL; const char *fgcolor = NULL; const char *bgcolor = NULL; int urgency = 1; int progress = -1; notification *n = malloc(sizeof(notification)); dbus_uint32_t replaces_id = 0; dbus_int32_t expires = -1; dbus_serial++; dbus_message_iter_init(dmsg, &args); _extract_basic(DBUS_TYPE_STRING, &args, &appname); dbus_message_iter_next(&args); _extract_basic(DBUS_TYPE_UINT32, &args, &replaces_id); dbus_message_iter_next(&args); _extract_basic(DBUS_TYPE_STRING, &args, &icon); dbus_message_iter_next(&args); _extract_basic(DBUS_TYPE_STRING, &args, &summary); dbus_message_iter_next(&args); _extract_basic(DBUS_TYPE_STRING, &args, &body); dbus_message_iter_next(&args); dbus_message_iter_next(&args); dbus_message_iter_recurse(&args, &hints); dbus_message_iter_next(&args); _extract_basic(DBUS_TYPE_INT32, &args, &expires); while (dbus_message_iter_get_arg_type(&hints) != DBUS_TYPE_INVALID) { dbus_message_iter_recurse(&hints, &hint); while (dbus_message_iter_get_arg_type(&hint) != DBUS_TYPE_INVALID) { if (dbus_message_iter_get_arg_type(&hint) != DBUS_TYPE_STRING) { dbus_message_iter_next(&hint); continue; } dbus_message_iter_get_basic(&hint, &hint_name); _extract_hint(DBUS_TYPE_BYTE, "urgency", hint_name, &hint, &urgency); _extract_hint(DBUS_TYPE_STRING, "fgcolor", hint_name, &hint, &fgcolor); _extract_hint(DBUS_TYPE_STRING, "bgcolor", hint_name, &hint, &bgcolor); _extract_hint(DBUS_TYPE_INT32, "value", hint_name, &hint, &progress); if (!progress) _extract_hint(DBUS_TYPE_UINT32, "value", hint_name, &hint, &progress); dbus_message_iter_next(&hint); } dbus_message_iter_next(&hints); } if (expires > 0) { /* do some rounding */ expires = (expires + 500) / 1000; if (expires < 1) { expires = 1; } } n->appname = appname != NULL ? strdup(appname) : ""; n->summary = summary != NULL ? strdup(summary) : ""; n->body = body != NULL ? strdup(body) : ""; n->icon = icon != NULL ? strdup(icon) : ""; n->timeout = expires; n->progress = (progress < 0 || progress > 100) ? 0 : progress + 1; n->urgency = urgency; n->dbus_client = strdup(dbus_message_get_sender(dmsg)); for (i = 0; i < ColLast; i++) { n->color_strings[i] = NULL; } n->color_strings[ColFG] = fgcolor == NULL ? NULL : strdup(fgcolor); n->color_strings[ColBG] = bgcolor == NULL ? NULL : strdup(bgcolor); id = init_notification(n, replaces_id); if (id > 0) map_win(); reply = dbus_message_new_method_return(dmsg); dbus_message_iter_init_append(reply, &args); dbus_message_iter_append_basic(&args, DBUS_TYPE_UINT32, &id); dbus_connection_send(dbus_conn, reply, &dbus_serial); dbus_message_unref(reply); }
/** * wpa_supplicant_dbus_notify_state_change - Send a state change signal * @wpa_s: %wpa_supplicant network interface data * @new_state: new state wpa_supplicant is entering * @old_state: old state wpa_supplicant is leaving * Returns: 0 on success, -1 on failure * * Notify listeners that wpa_supplicant has changed state */ void wpa_supplicant_dbus_notify_state_change(struct wpa_supplicant *wpa_s, wpa_states new_state, wpa_states old_state) { struct ctrl_iface_dbus_priv *iface; DBusMessage *signal = NULL; const char *path; const char *new_state_str, *old_state_str; /* Do nothing if the control interface is not turned on */ if (wpa_s->global == NULL) return; iface = wpa_s->global->dbus_ctrl_iface; if (iface == NULL) return; /* Only send signal if state really changed */ if (new_state == old_state) return; path = wpa_supplicant_get_dbus_path(wpa_s); if (path == NULL) { perror("wpa_supplicant_dbus_notify_state_change[dbus]: " "interface didn't have a dbus path"); wpa_printf(MSG_ERROR, "wpa_supplicant_dbus_notify_state_change[dbus]: " "interface didn't have a dbus path; can't send " "signal."); return; } signal = dbus_message_new_signal(path, WPAS_DBUS_IFACE_INTERFACE, "StateChange"); if (signal == NULL) { perror("wpa_supplicant_dbus_notify_state_change[dbus]: " "couldn't create dbus signal; likely out of memory"); wpa_printf(MSG_ERROR, "wpa_supplicant_dbus_notify_state_change[dbus]: " "couldn't create dbus signal; likely out of " "memory."); return; } new_state_str = wpa_supplicant_state_txt(new_state); old_state_str = wpa_supplicant_state_txt(old_state); if (new_state_str == NULL || old_state_str == NULL) { perror("wpa_supplicant_dbus_notify_state_change[dbus]: " "couldn't convert state strings"); wpa_printf(MSG_ERROR, "wpa_supplicant_dbus_notify_state_change[dbus]: " "couldn't convert state strings."); goto out; } if (!dbus_message_append_args(signal, DBUS_TYPE_STRING, &new_state_str, DBUS_TYPE_STRING, &old_state_str, DBUS_TYPE_INVALID)) { perror("wpa_supplicant_dbus_notify_state_change[dbus]: " "not enough memory to construct state change signal."); wpa_printf(MSG_ERROR, "wpa_supplicant_dbus_notify_state_change[dbus]: " "not enough memory to construct state change " "signal."); goto out; } dbus_connection_send(iface->con, signal, NULL); out: dbus_message_unref(signal); }
int /* O - Exit status */ main(int argc, /* I - Number of command-line args */ char *argv[]) /* I - Command-line arguments */ { ipp_t *msg; /* Event message from scheduler */ ipp_state_t state; /* IPP event state */ struct sigaction action; /* POSIX sigaction data */ DBusConnection *con = NULL; /* Connection to DBUS server */ DBusError error; /* Error, if any */ DBusMessage *message; /* Message to send */ DBusMessageIter iter; /* Iterator for message data */ int lock_fd = -1; /* Lock file descriptor */ /* * Don't buffer stderr... */ setbuf(stderr, NULL); /* * Ignore SIGPIPE signals... */ memset(&action, 0, sizeof(action)); action.sa_handler = SIG_IGN; sigaction(SIGPIPE, &action, NULL); /* * Validate command-line options... */ if (argc != 3) { fputs("Usage: dbus dbus:/// notify-user-data\n", stderr); return (1); } if (strncmp(argv[1], "dbus:", 5)) { fprintf(stderr, "ERROR: Bad URI \"%s\"!\n", argv[1]); return (1); } /* * Loop forever until we run out of events... */ for (;;) { ipp_attribute_t *attr; /* Current attribute */ const char *event; /* Event name */ const char *signame = NULL;/* DBUS signal name */ char *printer_reasons = NULL; /* Printer reasons string */ char *job_reasons = NULL; /* Job reasons string */ const char *nul = ""; /* Empty string value */ int no = 0; /* Boolean "no" value */ int params = PARAMS_NONE; /* What parameters to include? */ /* * Get the next event... */ msg = ippNew(); while ((state = ippReadFile(0, msg)) != IPP_DATA) { if (state <= IPP_IDLE) break; } fprintf(stderr, "DEBUG: state=%d\n", state); if (state == IPP_ERROR) fputs("DEBUG: ippReadFile() returned IPP_ERROR!\n", stderr); if (state <= IPP_IDLE) { /* * Out of messages, free memory and then exit... */ ippDelete(msg); break; } /* * Verify connection to DBUS server... */ if (con && !dbus_connection_get_is_connected(con)) { dbus_connection_unref(con); con = NULL; } if (!con) { dbus_error_init(&error); con = dbus_bus_get(DBUS_BUS_SYSTEM, &error); if (!con) dbus_error_free(&error); else fputs("DEBUG: Connected to D-BUS\n", stderr); } if (!con) continue; if (lock_fd == -1 && acquire_lock(&lock_fd, lock_filename, sizeof(lock_filename))) continue; attr = ippFindAttribute(msg, "notify-subscribed-event", IPP_TAG_KEYWORD); if (!attr) continue; event = ippGetString(attr, 0, NULL); if (!strncmp(event, "server-", 7)) { const char *word2 = event + 7; /* Second word */ if (!strcmp(word2, "restarted")) signame = "ServerRestarted"; else if (!strcmp(word2, "started")) signame = "ServerStarted"; else if (!strcmp(word2, "stopped")) signame = "ServerStopped"; else if (!strcmp(word2, "audit")) signame = "ServerAudit"; else continue; } else if (!strncmp(event, "printer-", 8)) { const char *word2 = event + 8; /* Second word */ params = PARAMS_PRINTER; if (!strcmp(word2, "restarted")) signame = "PrinterRestarted"; else if (!strcmp(word2, "shutdown")) signame = "PrinterShutdown"; else if (!strcmp(word2, "stopped")) signame = "PrinterStopped"; else if (!strcmp(word2, "state-changed")) signame = "PrinterStateChanged"; else if (!strcmp(word2, "finishings-changed")) signame = "PrinterFinishingsChanged"; else if (!strcmp(word2, "media-changed")) signame = "PrinterMediaChanged"; else if (!strcmp(word2, "added")) signame = "PrinterAdded"; else if (!strcmp(word2, "deleted")) signame = "PrinterDeleted"; else if (!strcmp(word2, "modified")) signame = "PrinterModified"; else continue; } else if (!strncmp(event, "job-", 4)) { const char *word2 = event + 4; /* Second word */ params = PARAMS_JOB; if (!strcmp(word2, "state-changed")) signame = "JobState"; else if (!strcmp(word2, "created")) signame = "JobCreated"; else if (!strcmp(word2, "completed")) signame = "JobCompleted"; else if (!strcmp(word2, "stopped")) signame = "JobStopped"; else if (!strcmp(word2, "config-changed")) signame = "JobConfigChanged"; else if (!strcmp(word2, "progress")) signame = "JobProgress"; else continue; } else continue; /* * Create and send the new message... */ fprintf(stderr, "DEBUG: %s\n", signame); message = dbus_message_new_signal("/org/cups/cupsd/Notifier", "org.cups.cupsd.Notifier", signame); dbus_message_append_iter_init(message, &iter); attr = ippFindAttribute(msg, "notify-text", IPP_TAG_TEXT); if (attr) { const char *val = ippGetString(attr, 0, NULL); if (!dbus_message_iter_append_string(&iter, &val)) goto bail; } else goto bail; if (params >= PARAMS_PRINTER) { char *p; /* Pointer into printer_reasons */ size_t reasons_length; /* Required size of printer_reasons */ int i; /* Looping var */ int have_printer_params = 1;/* Do we have printer URI? */ /* STRING printer-uri or "" */ attr = ippFindAttribute(msg, "notify-printer-uri", IPP_TAG_URI); if (attr) { const char *val = ippGetString(attr, 0, NULL); if (!dbus_message_iter_append_string(&iter, &val)) goto bail; } else { have_printer_params = 0; dbus_message_iter_append_string(&iter, &nul); } /* STRING printer-name */ if (have_printer_params) { attr = ippFindAttribute(msg, "printer-name", IPP_TAG_NAME); if (attr) { const char *val = ippGetString(attr, 0, NULL); if (!dbus_message_iter_append_string(&iter, &val)) goto bail; } else goto bail; } else dbus_message_iter_append_string(&iter, &nul); /* UINT32 printer-state */ if (have_printer_params) { attr = ippFindAttribute(msg, "printer-state", IPP_TAG_ENUM); if (attr) { dbus_uint32_t val = (dbus_uint32_t)ippGetInteger(attr, 0); dbus_message_iter_append_uint32(&iter, &val); } else goto bail; } else dbus_message_iter_append_uint32(&iter, &no); /* STRING printer-state-reasons */ if (have_printer_params) { attr = ippFindAttribute(msg, "printer-state-reasons", IPP_TAG_KEYWORD); if (attr) { int num_values = ippGetCount(attr); for (reasons_length = 0, i = 0; i < num_values; i++) /* All need commas except the last, which needs a nul byte. */ reasons_length += 1 + strlen(ippGetString(attr, i, NULL)); printer_reasons = malloc(reasons_length); if (!printer_reasons) goto bail; p = printer_reasons; for (i = 0; i < num_values; i++) { if (i) *p++ = ','; strlcpy(p, ippGetString(attr, i, NULL), reasons_length - (size_t)(p - printer_reasons)); p += strlen(p); } if (!dbus_message_iter_append_string(&iter, &printer_reasons)) goto bail; } else goto bail; } else dbus_message_iter_append_string(&iter, &nul); /* BOOL printer-is-accepting-jobs */ if (have_printer_params) { attr = ippFindAttribute(msg, "printer-is-accepting-jobs", IPP_TAG_BOOLEAN); if (attr) { dbus_bool_t val = (dbus_bool_t)ippGetBoolean(attr, 0); dbus_message_iter_append_boolean(&iter, &val); } else goto bail; } else dbus_message_iter_append_boolean(&iter, &no); } if (params >= PARAMS_JOB) { char *p; /* Pointer into job_reasons */ size_t reasons_length; /* Required size of job_reasons */ int i; /* Looping var */ /* UINT32 job-id */ attr = ippFindAttribute(msg, "notify-job-id", IPP_TAG_INTEGER); if (attr) { dbus_uint32_t val = (dbus_uint32_t)ippGetInteger(attr, 0); dbus_message_iter_append_uint32(&iter, &val); } else goto bail; /* UINT32 job-state */ attr = ippFindAttribute(msg, "job-state", IPP_TAG_ENUM); if (attr) { dbus_uint32_t val = (dbus_uint32_t)ippGetInteger(attr, 0); dbus_message_iter_append_uint32(&iter, &val); } else goto bail; /* STRING job-state-reasons */ attr = ippFindAttribute(msg, "job-state-reasons", IPP_TAG_KEYWORD); if (attr) { int num_values = ippGetCount(attr); for (reasons_length = 0, i = 0; i < num_values; i++) /* All need commas except the last, which needs a nul byte. */ reasons_length += 1 + strlen(ippGetString(attr, i, NULL)); job_reasons = malloc(reasons_length); if (!job_reasons) goto bail; p = job_reasons; for (i = 0; i < num_values; i++) { if (i) *p++ = ','; strlcpy(p, ippGetString(attr, i, NULL), reasons_length - (size_t)(p - job_reasons)); p += strlen(p); } if (!dbus_message_iter_append_string(&iter, &job_reasons)) goto bail; } else goto bail; /* STRING job-name or "" */ attr = ippFindAttribute(msg, "job-name", IPP_TAG_NAME); if (attr) { const char *val = ippGetString(attr, 0, NULL); if (!dbus_message_iter_append_string(&iter, &val)) goto bail; } else dbus_message_iter_append_string(&iter, &nul); /* UINT32 job-impressions-completed */ attr = ippFindAttribute(msg, "job-impressions-completed", IPP_TAG_INTEGER); if (attr) { dbus_uint32_t val = (dbus_uint32_t)ippGetInteger(attr, 0); dbus_message_iter_append_uint32(&iter, &val); } else goto bail; } dbus_connection_send(con, message, NULL); dbus_connection_flush(con); /* * Cleanup... */ bail: dbus_message_unref(message); if (printer_reasons) free(printer_reasons); if (job_reasons) free(job_reasons); ippDelete(msg); } /* * Remove lock file... */ if (lock_fd >= 0) { close(lock_fd); release_lock(); } return (0); }
/** * wpas_iface_message_handler - Dispatch messages for interfaces or networks * @connection: Connection to the system message bus * @message: An incoming dbus message * @user_data: A pointer to a dbus control interface data structure * Returns: Whether or not the message was handled * * This function dispatches all incoming dbus messages for network interfaces, * or objects owned by them, such as scanned BSSIDs and configured networks. */ static DBusHandlerResult wpas_iface_message_handler(DBusConnection *connection, DBusMessage *message, void *user_data) { struct wpa_supplicant *wpa_s = user_data; const char *method = dbus_message_get_member(message); const char *path = dbus_message_get_path(message); const char *msg_interface = dbus_message_get_interface(message); char *iface_obj_path = NULL; char *network = NULL; char *bssid = NULL; DBusMessage *reply = NULL; /* Caller must specify a message interface */ if (!msg_interface) goto out; iface_obj_path = wpas_dbus_decompose_object_path(path, &network, &bssid); if (iface_obj_path == NULL) { reply = wpas_dbus_new_invalid_iface_error(message); goto out; } /* Make sure the message's object path actually refers to the * wpa_supplicant structure it's supposed to (which is wpa_s) */ if (wpa_supplicant_get_iface_by_dbus_path(wpa_s->global, iface_obj_path) != wpa_s) { reply = wpas_dbus_new_invalid_iface_error(message); goto out; } if (network && !strcmp(msg_interface, WPAS_DBUS_IFACE_NETWORK)) { /* A method for one of this interface's configured networks */ int nid = strtoul(network, NULL, 10); if (errno != EINVAL) reply = wpas_dispatch_network_method(message, wpa_s, nid); else reply = wpas_dbus_new_invalid_network_error(message); } else if (bssid && !strcmp(msg_interface, WPAS_DBUS_IFACE_BSSID)) { /* A method for one of this interface's scanned BSSIDs */ reply = wpas_dispatch_bssid_method(message, wpa_s, bssid); } else if (!strcmp(msg_interface, WPAS_DBUS_IFACE_INTERFACE)) { /* A method for an interface only. */ if (!strcmp(method, "scan")) reply = wpas_dbus_iface_scan(message, wpa_s); else if (!strcmp(method, "scanResults")) reply = wpas_dbus_iface_scan_results(message, wpa_s); else if (!strcmp(method, "addNetwork")) reply = wpas_dbus_iface_add_network(message, wpa_s); else if (!strcmp(method, "removeNetwork")) reply = wpas_dbus_iface_remove_network(message, wpa_s); else if (!strcmp(method, "selectNetwork")) reply = wpas_dbus_iface_select_network(message, wpa_s); else if (!strcmp(method, "capabilities")) reply = wpas_dbus_iface_capabilities(message, wpa_s); else if (!strcmp(method, "disconnect")) reply = wpas_dbus_iface_disconnect(message, wpa_s); else if (!strcmp(method, "setAPScan")) reply = wpas_dbus_iface_set_ap_scan(message, wpa_s); else if (!strcmp(method, "state")) reply = wpas_dbus_iface_get_state(message, wpa_s); else if (!strcmp(method, "setBlobs")) reply = wpas_dbus_iface_set_blobs(message, wpa_s); else if (!strcmp(method, "removeBlobs")) reply = wpas_dbus_iface_remove_blobs(message, wpa_s); } /* If the message was handled, send back the reply */ if (reply) { dbus_connection_send(connection, reply, NULL); dbus_message_unref(reply); } out: free(iface_obj_path); free(network); free(bssid); return reply ? DBUS_HANDLER_RESULT_HANDLED : DBUS_HANDLER_RESULT_NOT_YET_HANDLED; }
int main (int argc, char *argv[]) { DBusMessage *method; DBusConnection *conn; DBusError error; DBusMutex *mutex1, *dispatch_mutex1, *io_path_mutex1; DBusCondVar *dispatch_cond1, *io_path_cond1; DBusMutex *mutex2, *dispatch_mutex2, *io_path_mutex2; DBusCondVar *dispatch_cond2, *io_path_cond2; printf ("*** Testing late thread init\n"); dbus_error_init (&error); conn = dbus_bus_get (DBUS_BUS_SESSION, &error); _dbus_connection_test_get_locks (conn, &mutex1, &dispatch_mutex1, &io_path_mutex1, &dispatch_cond1, &io_path_cond1); _run_iteration (conn); _dbus_connection_test_get_locks (conn, &mutex2, &dispatch_mutex2, &io_path_mutex2, &dispatch_cond2, &io_path_cond2); check_mutex_lock (mutex1, mutex2, TRUE); check_mutex_lock (dispatch_mutex1, dispatch_mutex2, TRUE); check_mutex_lock (io_path_mutex1, io_path_mutex2, TRUE); check_condvar_lock (dispatch_cond1, dispatch_cond2, TRUE); check_condvar_lock (io_path_cond1, io_path_cond2, TRUE); dbus_threads_init_default (); _dbus_connection_test_get_locks (conn, &mutex1, &dispatch_mutex1, &io_path_mutex1, &dispatch_cond1, &io_path_cond1); _run_iteration (conn); _dbus_connection_test_get_locks (conn, &mutex2, &dispatch_mutex2, &io_path_mutex2, &dispatch_cond2, &io_path_cond2); check_mutex_lock (mutex1, mutex2, TRUE); check_mutex_lock (dispatch_mutex1, dispatch_mutex2, TRUE); check_mutex_lock (io_path_mutex1, io_path_mutex2, TRUE); check_condvar_lock (dispatch_cond1, dispatch_cond2, TRUE); check_condvar_lock (io_path_cond1, io_path_cond2, TRUE); method = dbus_message_new_method_call ("org.freedesktop.TestSuiteEchoService", "/org/freedesktop/TestSuite", "org.freedesktop.TestSuite", "Exit"); dbus_connection_send (conn, method, NULL); dbus_message_unref (method); printf ("Success ***\n"); exit (0); }
static void modem_unregister(struct ofono_modem *modem) { DBusConnection *conn = ofono_dbus_get_connection(); DBG("%p", modem); if (modem->powered == TRUE) set_powered(modem, FALSE); __ofono_watchlist_free(modem->atom_watches); modem->atom_watches = NULL; __ofono_watchlist_free(modem->online_watches); modem->online_watches = NULL; __ofono_watchlist_free(modem->powered_watches); modem->powered_watches = NULL; modem->sim_watch = 0; modem->sim_ready_watch = 0; g_slist_foreach(modem->interface_list, (GFunc) g_free, NULL); g_slist_free(modem->interface_list); modem->interface_list = NULL; g_slist_foreach(modem->feature_list, (GFunc) g_free, NULL); g_slist_free(modem->feature_list); modem->feature_list = NULL; if (modem->timeout) { g_source_remove(modem->timeout); modem->timeout = 0; } if (modem->pending) { dbus_message_unref(modem->pending); modem->pending = NULL; } if (modem->interface_update) { g_source_remove(modem->interface_update); modem->interface_update = 0; } if (modem->lock_watch) { lockdown_remove(modem); ofono_dbus_signal_property_changed(conn, modem->path, OFONO_MODEM_INTERFACE, "Lockdown", DBUS_TYPE_BOOLEAN, &modem->lockdown); } g_dbus_unregister_interface(conn, modem->path, OFONO_MODEM_INTERFACE); if (modem->driver && modem->driver->remove) modem->driver->remove(modem); g_hash_table_destroy(modem->properties); modem->properties = NULL; modem->driver = NULL; emit_modem_removed(modem); call_modemwatches(modem, FALSE); }
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; }
static void push_data(DBusConnection *bus) { char **l_set = NULL, **l_unset = NULL, **t; int c_set = 0, c_unset = 0, p; DBusError error; DBusMessage *m = NULL, *reply = NULL; DBusMessageIter iter, sub; dbus_error_init(&error); assert(bus); l_set = new0(char*, _PROP_MAX); l_unset = new0(char*, _PROP_MAX); if (!l_set || !l_unset) { log_oom(); goto finish; } for (p = 0; p < _PROP_MAX; p++) { assert(names[p]); if (isempty(data[p])) l_unset[c_set++] = (char*) names[p]; else { char *s; if (asprintf(&s, "%s=%s", names[p], data[p]) < 0) { log_oom(); goto finish; } l_set[c_unset++] = s; } } assert(c_set + c_unset == _PROP_MAX); m = dbus_message_new_method_call("org.freedesktop.systemd1", "/org/freedesktop/systemd1", "org.freedesktop.systemd1.Manager", "UnsetAndSetEnvironment"); if (!m) { log_error("Could not allocate message."); goto finish; } dbus_message_iter_init_append(m, &iter); if (!dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY, "s", &sub)) { log_oom(); goto finish; } STRV_FOREACH(t, l_unset) if (!dbus_message_iter_append_basic(&sub, DBUS_TYPE_STRING, t)) { log_oom(); goto finish; } if (!dbus_message_iter_close_container(&iter, &sub) || !dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY, "s", &sub)) { log_oom(); goto finish; } STRV_FOREACH(t, l_set) if (!dbus_message_iter_append_basic(&sub, DBUS_TYPE_STRING, t)) { log_oom(); goto finish; } if (!dbus_message_iter_close_container(&iter, &sub)) { log_oom(); goto finish; } reply = dbus_connection_send_with_reply_and_block(bus, m, -1, &error); if (!reply) { log_error("Failed to set locale information: %s", bus_error_message(&error)); goto finish; } finish: if (m) dbus_message_unref(m); if (reply) dbus_message_unref(reply); dbus_error_free(&error); strv_free(l_set); free(l_unset); }
/** * thunar_dbus_client_bulk_rename: * @working_directory : the default working directory for the bulk rename dialog. * @filenames : the list of files that should be displayed by default or * the empty list to start with an empty bulk rename dialog. * @standalone : whether to run the bulk renamer in standalone mode. * @screen : the #GdkScreen on which to display the dialog or %NULL to * use the default #GdkScreen. * @error : return location for errors or %NULL. * * Tries to invoke the BulkRename() method on a running Thunar instance, that is * registered with the current D-BUS session bus. Returns %TRUE if the method was * successfully invoked, else %FALSE. * * If %TRUE is returned, the current process may afterwards just terminate, as * all @filenames will be handled by the remote instance. * * Return value: %TRUE on success, else %FALSE. **/ gboolean thunar_dbus_client_bulk_rename (const gchar *working_directory, gchar **filenames, gboolean standalone, GdkScreen *screen, GError **error) { DBusConnection *connection; DBusMessage *message; DBusMessage *result; DBusError derror; gchar *display_name; _thunar_return_val_if_fail (screen == NULL || GDK_IS_SCREEN (screen), FALSE); _thunar_return_val_if_fail (g_path_is_absolute (working_directory), FALSE); _thunar_return_val_if_fail (error == NULL || *error == NULL, FALSE); _thunar_return_val_if_fail (filenames != NULL, FALSE); /* initialize the DBusError struct */ dbus_error_init (&derror); /* fallback to default screen if no other is specified */ if (G_LIKELY (screen == NULL)) screen = gdk_screen_get_default (); /* try to connect to the session bus */ connection = dbus_bus_get (DBUS_BUS_SESSION, &derror); if (G_UNLIKELY (connection == NULL)) { dbus_set_g_error (error, &derror); dbus_error_free (&derror); return FALSE; } /* determine the display name for the screen */ display_name = gdk_screen_make_display_name (screen); /* generate the BulkRename() method (disable activation!) */ message = dbus_message_new_method_call ("org.xfce.Thunar", "/org/xfce/FileManager", "org.xfce.Thunar", "BulkRename"); dbus_message_set_auto_start (message, FALSE); dbus_message_append_args (message, DBUS_TYPE_STRING, &working_directory, DBUS_TYPE_ARRAY, DBUS_TYPE_STRING, &filenames, g_strv_length (filenames), DBUS_TYPE_BOOLEAN, &standalone, DBUS_TYPE_STRING, &display_name, DBUS_TYPE_INVALID); /* release the display name */ g_free (display_name); /* send the message and release our references on connection and message */ result = dbus_connection_send_with_reply_and_block (connection, message, -1, &derror); dbus_message_unref (message); /* check if no reply was received */ if (G_UNLIKELY (result == NULL)) { dbus_set_g_error (error, &derror); dbus_error_free (&derror); return FALSE; } /* but maybe we received an error */ if (dbus_message_get_type (result) == DBUS_MESSAGE_TYPE_ERROR) { dbus_set_error_from_message (&derror, result); dbus_set_g_error (error, &derror); dbus_message_unref (result); dbus_error_free (&derror); return FALSE; } /* let's asume that it worked */ dbus_message_unref (result); return TRUE; }
static int convert_vconsole_to_x11(DBusConnection *connection) { bool modified = false; assert(connection); if (isempty(state.vc_keymap)) { modified = !isempty(state.x11_layout) || !isempty(state.x11_model) || !isempty(state.x11_variant) || !isempty(state.x11_options); free_data_x11(); } else { FILE *f; unsigned n = 0; f = fopen(SYSTEMD_KBD_MODEL_MAP, "re"); if (!f) return -errno; for (;;) { char **a; int r; r = read_next_mapping(f, &n, &a); if (r < 0) { fclose(f); return r; } if (r == 0) break; if (!streq(state.vc_keymap, a[0])) { strv_free(a); continue; } if (!streq_ptr(state.x11_layout, strnulldash(a[1])) || !streq_ptr(state.x11_model, strnulldash(a[2])) || !streq_ptr(state.x11_variant, strnulldash(a[3])) || !streq_ptr(state.x11_options, strnulldash(a[4]))) { if (free_and_set(&state.x11_layout, strnulldash(a[1])) < 0 || free_and_set(&state.x11_model, strnulldash(a[2])) < 0 || free_and_set(&state.x11_variant, strnulldash(a[3])) < 0 || free_and_set(&state.x11_options, strnulldash(a[4])) < 0) { strv_free(a); fclose(f); return -ENOMEM; } modified = true; } strv_free(a); break; } fclose(f); } if (modified) { dbus_bool_t b; DBusMessage *changed; int r; r = write_data_x11(); if (r < 0) log_error("Failed to set X11 keyboard layout: %s", strerror(-r)); changed = bus_properties_changed_new( "/org/freedesktop/locale1", "org.freedesktop.locale1", "X11Layout\0" "X11Model\0" "X11Variant\0" "X11Options\0"); if (!changed) return -ENOMEM; b = dbus_connection_send(connection, changed, NULL); dbus_message_unref(changed); if (!b) return -ENOMEM; } return 0; }
static void force_unmount (LibHalContext *ctx, const char *udi) { DBusError error; DBusMessage *msg = NULL; DBusMessage *reply = NULL; char **options = NULL; unsigned int num_options = 0; DBusConnection *dbus_connection; char *device_file; dbus_connection = libhal_ctx_get_dbus_connection (ctx); msg = dbus_message_new_method_call ("org.freedesktop.Hal", udi, "org.freedesktop.Hal.Device.Volume", "Unmount"); if (msg == NULL) { HAL_ERROR (("Could not create dbus message for %s", udi)); goto out; } options = calloc (1, sizeof (char *)); if (options == NULL) { HAL_ERROR (("Could not allocate options array")); goto out; } options[0] = "lazy"; num_options = 1; device_file = libhal_device_get_property_string (ctx, udi, "block.device", NULL); if (device_file != NULL) { HAL_INFO(("forcibly attempting to lazy unmount %s as media was removed", device_file)); libhal_free_string (device_file); } if (!dbus_message_append_args (msg, DBUS_TYPE_ARRAY, DBUS_TYPE_STRING, &options, num_options, DBUS_TYPE_INVALID)) { HAL_ERROR (("Could not append args to dbus message for %s", udi)); goto out; } dbus_error_init (&error); if (!(reply = dbus_connection_send_with_reply_and_block (dbus_connection, msg, -1, &error))) { HAL_ERROR (("Unmount failed for %s: %s : %s\n", udi, error.name, error.message)); dbus_error_free (&error); goto out; } if (dbus_error_is_set (&error)) { HAL_ERROR (("Unmount failed for %s\n%s : %s\n", udi, error.name, error.message)); dbus_error_free (&error); goto out; } HAL_DEBUG (("Succesfully unmounted udi '%s'", udi)); out: if (options != NULL) free (options); if (msg != NULL) dbus_message_unref (msg); if (reply != NULL) dbus_message_unref (reply); }
static int convert_x11_to_vconsole(DBusConnection *connection) { bool modified = false; assert(connection); if (isempty(state.x11_layout)) { modified = !isempty(state.vc_keymap) || !isempty(state.vc_keymap_toggle); free_data_x11(); } else { FILE *f; unsigned n = 0; unsigned best_matching = 0; char *new_keymap = NULL; f = fopen(SYSTEMD_KBD_MODEL_MAP, "re"); if (!f) return -errno; for (;;) { char **a; unsigned matching = 0; int r; r = read_next_mapping(f, &n, &a); if (r < 0) { fclose(f); return r; } if (r == 0) break; /* Determine how well matching this entry is */ if (streq_ptr(state.x11_layout, a[1])) /* If we got an exact match, this is best */ matching = 10; else { size_t x; x = strcspn(state.x11_layout, ","); /* We have multiple X layouts, look * for an entry that matches our key * with the everything but the first * layout stripped off. */ if (x > 0 && strlen(a[1]) == x && strneq(state.x11_layout, a[1], x)) matching = 5; else { size_t w; /* If that didn't work, strip * off the other layouts from * the entry, too */ w = strcspn(a[1], ","); if (x > 0 && x == w && memcmp(state.x11_layout, a[1], x) == 0) matching = 1; } } if (matching > 0 && streq_ptr(state.x11_model, a[2])) { matching++; if (streq_ptr(state.x11_variant, a[3])) { matching++; if (streq_ptr(state.x11_options, a[4])) matching++; } } /* The best matching entry so far, then let's * save that */ if (matching > best_matching) { best_matching = matching; free(new_keymap); new_keymap = strdup(a[0]); if (!new_keymap) { strv_free(a); fclose(f); return -ENOMEM; } } strv_free(a); } fclose(f); if (!streq_ptr(state.vc_keymap, new_keymap)) { free(state.vc_keymap); state.vc_keymap = new_keymap; free(state.vc_keymap_toggle); state.vc_keymap_toggle = NULL; modified = true; } else free(new_keymap); } if (modified) { dbus_bool_t b; DBusMessage *changed; int r; r = write_data_vconsole(); if (r < 0) log_error("Failed to set virtual console keymap: %s", strerror(-r)); changed = bus_properties_changed_new( "/org/freedesktop/locale1", "org.freedesktop.locale1", "VConsoleKeymap\0" "VConsoleKeymapToggle\0"); if (!changed) return -ENOMEM; b = dbus_connection_send(connection, changed, NULL); dbus_message_unref(changed); if (!b) return -ENOMEM; return load_vconsole_keymap(connection, NULL); } return 0; }
static vlc_keystore_entry* kwallet_read_password_list( vlc_keystore* p_keystore, char* psz_entry_name, unsigned int* pi_count ) { vlc_keystore_sys* p_sys = p_keystore->p_sys; DBusMessage* msg = NULL; DBusMessage* repmsg = NULL; DBusMessageIter args; DBusMessageIter sub_iter; DBusMessageIter dict_iter; DBusMessageIter var_iter; vlc_keystore_entry* p_entries = NULL; size_t i_size; uint8_t* p_secret_decoded; char* p_reply; char* p_secret; int i = 0; /* init */ *pi_count = 0; if ( !( msg = vlc_dbus_new_method( p_keystore, "readPasswordList" ) ) ) { msg_Err( p_keystore, "kwallet_read_password_list : vlc_dbus_new_method failed" ); goto error; } /* 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 error; /* sending message */ if ( !( repmsg = vlc_dbus_send_message( p_keystore, msg ) ) ) { msg_Err( p_keystore, "kwallet_read_password_list : vlc_dbus_send_message failed" ); goto error; } /* handling reply */ if ( !dbus_message_iter_init( repmsg, &args ) ) { msg_Err( p_keystore, "kwallet_read_password_list : Message has no arguments" ); goto error; } else if ( dbus_message_iter_get_arg_type(&args) != DBUS_TYPE_ARRAY ) { msg_Err( p_keystore, "kwallet_read_password_list : Wrong reply type" ); goto error; } else { /* calculating p_entries's size */ dbus_message_iter_recurse( &args, &sub_iter ); do { if ( dbus_message_iter_get_arg_type( &sub_iter ) != DBUS_TYPE_DICT_ENTRY ) continue; dbus_message_iter_recurse( &sub_iter, &dict_iter ); if ( dbus_message_iter_get_arg_type( &dict_iter ) != DBUS_TYPE_STRING ) continue; dbus_message_iter_next(&dict_iter); if ( dbus_message_iter_get_arg_type( &dict_iter ) != DBUS_TYPE_VARIANT ) continue; ++( *pi_count ); } while ( dbus_message_iter_next( &sub_iter ) ); if ( *pi_count == 0 ) goto error; if ( !( p_entries = calloc( *pi_count, sizeof( vlc_keystore_entry ) ) ) ) goto error; dbus_message_iter_init( repmsg, &args ); /* recurse into the reply array */ dbus_message_iter_recurse( &args, &sub_iter ); do { if ( dbus_message_iter_get_arg_type( &sub_iter ) != DBUS_TYPE_DICT_ENTRY ) { msg_Err( p_keystore, "Wrong type not DBUS_TYPE_DICT_ENTRY" ); continue; } /* recurse into the dict-entry in the array */ dbus_message_iter_recurse( &sub_iter, &dict_iter ); if ( dbus_message_iter_get_arg_type( &dict_iter ) != DBUS_TYPE_STRING ) { msg_Err( p_keystore, "First type of Dict-Entry is not a string" ); continue; } dbus_message_iter_get_basic( &dict_iter, &p_reply ); dbus_message_iter_next(&dict_iter); if ( dbus_message_iter_get_arg_type( &dict_iter ) != DBUS_TYPE_VARIANT ) { msg_Err( p_keystore, "Second type of Dict-Entry is not a variant" ); continue; } /* recurse into the variant in the dict-entry */ dbus_message_iter_recurse( &dict_iter, &var_iter ); dbus_message_iter_get_basic( &var_iter, &p_secret ); i_size = vlc_b64_decode_binary( &p_secret_decoded, p_secret); if ( key2values( p_reply, &p_entries[i] ) ) goto error; if ( ( vlc_keystore_entry_set_secret( &p_entries[i], p_secret_decoded, i_size ) ) ) goto error; free(p_secret_decoded); i += 1; } while ( dbus_message_iter_next( &sub_iter ) ); } dbus_message_unref( msg ); dbus_message_unref( repmsg ); return p_entries; error: *pi_count = 0; vlc_keystore_release_entries( p_entries, i ); if ( msg ) dbus_message_unref( msg ); if ( repmsg ) dbus_message_unref( repmsg ); return NULL; }
/* * Bus:call_method() * * argument 1: bus object * argument 2: destination * argument 3: path * argument 4: interface * argument 5: method * argument 6: signature (optional) * ... */ static int bus_call_method(lua_State *T) { DBusConnection *conn; const char *destination; const char *path; const char *interface; const char *method; const char *signature; DBusMessage *msg; DBusPendingCall *pending; luaL_checktype(T, 1, LUA_TUSERDATA); destination = luaL_checkstring(T, 2); path = luaL_checkstring(T, 3); interface = luaL_checkstring(T, 4); method = luaL_checkstring(T, 5); signature = luaL_optstring(T, 6, NULL); conn = bus_unbox(T, 1); if (conn == NULL) { lua_pushnil(T); lua_pushliteral(T, "closed"); return 2; } if (interface && interface[0] == '\0') interface = NULL; lem_debug("calling\n %s\n %s\n %s\n %s(%s)", destination, path, interface ? interface : "(no interface)", method, signature ? signature : ""); /* create a new method call and check for errors */ msg = dbus_message_new_method_call(destination, path, interface, method); if (msg == NULL) goto oom; /* add arguments if a signature was provided */ if (signature && signature[0] != '\0' && lem_dbus_add_arguments(T, 7, signature, msg)) return luaL_error(T, "%s", lua_tostring(T, -1)); if (!dbus_connection_send_with_reply(conn, msg, &pending, -1)) goto oom; if (!dbus_pending_call_set_notify(pending, method_return_handler, T, NULL)) goto oom; dbus_message_unref(msg); return lua_yield(T, 0); oom: if (msg) dbus_message_unref(msg); lua_pushnil(T); lua_pushliteral(T, "out of memory"); return 2; }
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 man_portal_sta_get_by_ip(portal_user_info_s *station, unsigned int *next_addr) { int ret; DBusMessage *query, *reply; DBusMessageIter iter; DBusMessageIter iter_array; DBusError err; int index = 0; char BUSNAME[PATH_LEN]; char OBJPATH[PATH_LEN]; char INTERFACE[PATH_LEN]; char *ch; index = 0; ReInitDbusPath(index,ASD_DBUS_BUSNAME,BUSNAME); ReInitDbusPath(index,ASD_DBUS_SECURITY_OBJPATH,OBJPATH); ReInitDbusPath(index,ASD_DBUS_SECURITY_INTERFACE,INTERFACE); dbus_error_init(&err); query = dbus_message_new_method_call(BUSNAME,OBJPATH,INTERFACE,ASD_DBUS_SECURITY_METHOD_GET_PORTAL_STA); dbus_message_iter_init_append (query, &iter); dbus_message_iter_append_basic ( &iter, DBUS_TYPE_UINT32, &station->ipaddr); reply = dbus_connection_send_with_reply_and_block (dcli_dbus_connection,query,-1, &err); dbus_message_unref(query); if (NULL == reply) { if (dbus_error_is_set(&err)) { dbus_error_free(&err); } return CMD_FAILURE; } dbus_message_iter_init(reply,&iter); dbus_message_iter_get_basic(&iter,&ret); if(ret != CMD_SUCCESS){ return ret; } if(ASD_DBUS_SUCCESS == ret) { dbus_message_iter_next(&iter); dbus_message_iter_get_basic(&iter,&station->state); dbus_message_iter_next(&iter); dbus_message_iter_get_basic(&iter,&ch); memset(station->id, 0, NAME_LEN+1); strncpy(station->id, ch, NAME_LEN); dbus_message_iter_next(&iter); dbus_message_iter_get_basic(&iter,&(station->ipaddr)); dbus_message_iter_next(&iter); dbus_message_iter_get_basic(&iter,&(station->netif_index)); dbus_message_iter_next(&iter); dbus_message_iter_get_basic(&iter,next_addr); } return ret; }
static int request_cookie_input(struct vpn_provider *provider, struct oc_private_data *data) { DBusMessage *message; const char *path, *agent_sender, *agent_path; DBusMessageIter iter; DBusMessageIter dict; const char *str; int err; connman_agent_get_info(&agent_sender, &agent_path); if (provider == NULL || agent_path == NULL) return -ESRCH; message = dbus_message_new_method_call(agent_sender, agent_path, VPN_AGENT_INTERFACE, "RequestInput"); if (message == NULL) return -ENOMEM; dbus_message_iter_init_append(message, &iter); path = vpn_provider_get_path(provider); dbus_message_iter_append_basic(&iter, DBUS_TYPE_OBJECT_PATH, &path); connman_dbus_dict_open(&iter, &dict); str = vpn_provider_get_string(provider, "OpenConnect.CACert"); if (str != NULL) connman_dbus_dict_append_dict(&dict, "OpenConnect.CACert", request_input_append_informational, (void *)str); str = vpn_provider_get_string(provider, "OpenConnect.ClientCert"); if (str != NULL) connman_dbus_dict_append_dict(&dict, "OpenConnect.ClientCert", request_input_append_informational, (void *)str); connman_dbus_dict_append_dict(&dict, "OpenConnect.ServerCert", request_input_append_mandatory, NULL); connman_dbus_dict_append_dict(&dict, "OpenConnect.VPNHost", request_input_append_mandatory, NULL); connman_dbus_dict_append_dict(&dict, "OpenConnect.Cookie", request_input_append_mandatory, NULL); vpn_agent_append_host_and_name(&dict, provider); connman_dbus_dict_close(&iter, &dict); err = connman_agent_queue_message(provider, message, connman_timeout_input_request(), request_input_cookie_reply, data); if (err < 0 && err != -EBUSY) { DBG("error %d sending agent request", err); dbus_message_unref(message); return err; } dbus_message_unref(message); return -EINPROGRESS; }
int man_portal_conf_get(dcli_asd_portal_info *info) { int ret; DBusMessage *query, *reply; DBusMessageIter iter; DBusMessageIter iter_array; DBusError err; int num = 0, i; char *url; int index = 0; char BUSNAME[PATH_LEN]; char OBJPATH[PATH_LEN]; char INTERFACE[PATH_LEN]; index = 0; ReInitDbusPath(index,ASD_DBUS_BUSNAME,BUSNAME); ReInitDbusPath(index,ASD_DBUS_SECURITY_OBJPATH,OBJPATH); ReInitDbusPath(index,ASD_DBUS_SECURITY_INTERFACE,INTERFACE); dbus_error_init(&err); query = dbus_message_new_method_call(BUSNAME,OBJPATH,INTERFACE,ASD_DBUS_SECURITY_METHOD_GET_PORTAL); reply = dbus_connection_send_with_reply_and_block (dcli_dbus_connection,query,-1, &err); dbus_message_unref(query); if((ret =dcli_check_reply(reply, err))){ return ret; } dbus_message_iter_init(reply,&iter); dbus_message_iter_get_basic(&iter,&ret); if(ASD_RETURN_CODE_SUCCESS == ret) { dbus_message_iter_next(&iter); dbus_message_iter_get_basic(&iter,&info->enable); dbus_message_iter_next(&iter); dbus_message_iter_get_basic(&iter,&num); for(i=0;i<num;i++) { dbus_message_iter_next(&iter); dbus_message_iter_get_basic(&iter,&info->srv[i].enable); dbus_message_iter_next(&iter); dbus_message_iter_get_basic(&iter,&info->srv[i].ipaddr); dbus_message_iter_next(&iter); dbus_message_iter_get_basic(&iter,&info->srv[i].port); dbus_message_iter_next(&iter); dbus_message_iter_get_basic(&iter,&url); strncpy(info->srv[i].URL, url, 256); } } dbus_message_unref(reply); return ret; }
/******************************************************************************* * igmp_snp_dbus_message_handler * * DESCRIPTION: * handle the dbus mesage. * * INPUTS: * connection - dbusconnection * message - dbusmessage * user_data - dbus data * * OUTPUTS: * null * * RETURNS: * null * * COMMENTS: * ** ********************************************************************************/ static DBusHandlerResult igmp_snp_dbus_message_handler ( DBusConnection *connection, DBusMessage *message, void *user_data ) { DBusMessage *reply = NULL; igmp_snp_syslog_dbg ("IGMP>>entering igmp dbus message handler.\n"); if(strcmp(dbus_message_get_path(message),IGMP_DBUS_OBJPATH) == 0) { igmp_snp_syslog_dbg("IGMP>>igmp obj path:"IGMP_DBUS_OBJPATH"\n"); if (dbus_message_is_method_call(message,IGMP_DBUS_INTERFACE, \ IGMP_SNP_DBUS_METHOD_IGMP_SNP_DEBUG_ON)) { reply = igmp_snp_dbus_igmp_snp_debug_on(connection,message,user_data); } else if (dbus_message_is_method_call(message,IGMP_DBUS_INTERFACE, \ IGMP_SNP_DBUS_METHOD_IGMP_SNP_DEBUG_OFF)) { reply = igmp_snp_dbus_igmp_snp_debug_off(connection,message,user_data); } else if(dbus_message_is_method_call(message,IGMP_DBUS_INTERFACE, \ IGMP_SNP_DBUS_METHOD_IGMP_SNP_ENABLE)) { reply = igmp_snp_dbus_igmp_snp_enable(connection,message,user_data); } else if (dbus_message_is_method_call(message,IGMP_DBUS_INTERFACE, \ IGMP_SNP_DBUS_METHOD_IGMP_SNP_SET_TIMER)) { reply = igmp_snp_dbus_config_igmp_snp_timer(connection, message, user_data); } else if (dbus_message_is_method_call(message,IGMP_DBUS_INTERFACE, \ IGMP_SNP_DBUS_METHOD_IGMP_SNP_SHOW_TIMER)) { reply = igmp_snp_dbus_show_igmp_snp_time(connection,message,user_data); } else if (dbus_message_is_method_call(message,IGMP_DBUS_INTERFACE, \ IGMP_SNP_DBUS_METHOD_IGMP_SNP_TIME_PARAMETER_GET)) { reply = igmp_snp_dbus_igmp_snp_time_get(connection,message,user_data); } else if(dbus_message_is_method_call(message, IGMP_DBUS_INTERFACE, \ IGMP_SNP_DBUS_METHOD_IGMP_SNP_DEL_MCGROUP)) { reply = igmp_snp_dbus_mcgroup_del(connection,message,user_data); } else if (dbus_message_is_method_call(message,IGMP_DBUS_INTERFACE, \ IGMP_SNP_DBUS_METHOD_IGMP_SNP_DEL_MCGROUP_VLAN_ONE)) { reply = igmp_snp_dbus_del_one_mcgroup_vlan(connection, message, user_data); } else if (dbus_message_is_method_call(message,IGMP_DBUS_INTERFACE, \ IGMP_SNP_DBUS_METHOD_IGMP_SNP_DEL_MCGROUP_VLAN_ALL)) { reply = igmp_snp_dbus_mcgroup_vlan_del_all(connection,message,user_data); } /* else if (dbus_message_is_method_call(message,IGMP_DBUS_INTERFACE, \ IGMP_SNP_DBUS_METHOD_IGMP_SNP_ADD_DEL_MCROUTE_PORT)) { reply = igmp_snp_dbus_igmp_snp_add_mcroute_port(connection, message, user_data); } else if (dbus_message_is_method_call(message,IGMP_DBUS_INTERFACE, \ IGMP_SNP_DBUS_METHOD_IGMP_SNP_VLAN_EN_DIS)) { reply = igmp_snp_dbus_vlan_add_del_one(connection, message, user_data); } else if (dbus_message_is_method_call(message,IGMP_DBUS_INTERFACE, \ IGMP_SNP_DBUS_METHOD_IGMP_SNP_ETH_PORT_EN_DIS)) { reply = igmp_snp_dbus_port_add_del_one(connection, message, user_data); } else if (dbus_message_is_method_call(message,IGMP_DBUS_INTERFACE, \ IGMP_SNP_DBUS_METHOD_IGMP_SNP_VLAN_COUNT_SHOW)) { reply = igmp_snp_dbus_show_igmp_vlan_count(connection, message, user_data); } else if (dbus_message_is_method_call(message,IGMP_DBUS_INTERFACE, \ IGMP_SNP_DBUS_METHOD_IGMP_SNP_GROUP_COUNT_SHOW)) { reply = igmp_snp_dbus_show_igmp_mcgroup_count(connection, message, user_data); } */ else if (dbus_message_is_method_call(message,IGMP_DBUS_INTERFACE, \ IGMP_SNP_DBUS_METHOD_IGMP_SNP_TOTAL_GROUP_COUNT_SHOW)) { reply = igmp_snp_dbus_show_igmp_mcgroup_total_count(connection, message, user_data); } else if (dbus_message_is_method_call(message,IGMP_DBUS_INTERFACE, \ IGMP_SNP_DBUS_METHOD_IGMP_SNP_SHOW_ROUTE_PORT)) { reply = igmp_snp_dbus_show_route_port(connection, message, user_data); } else if (dbus_message_is_method_call(message,IGMP_DBUS_INTERFACE, \ IGMP_SNP_DBUS_METHOD_IGMP_SNP_SHOW_STATE)) { reply = igmp_snp_dbus_get_config_state(connection, message, user_data); } } if (reply) { //IGMP_DBUS_DEBUG(("here send reply to dcli.\n")); dbus_connection_send (connection, reply, NULL); dbus_connection_flush(connection); // TODO Maybe we should let main loop process the flush dbus_message_unref (reply); } // dbus_message_unref(message); //TODO who should unref the incoming message? return DBUS_HANDLER_RESULT_HANDLED ; }
/** * Process a message from D-Bus. */ static void cdbus_process(session_t *ps, DBusMessage *msg) { bool success = false; #define cdbus_m_ismethod(method) \ dbus_message_is_method_call(msg, CDBUS_INTERFACE_NAME, method) if (cdbus_m_ismethod("reset")) { ps->reset = true; if (!dbus_message_get_no_reply(msg)) cdbus_reply_bool(ps, msg, true); success = true; } else if (cdbus_m_ismethod("repaint")) { force_repaint(ps); if (!dbus_message_get_no_reply(msg)) cdbus_reply_bool(ps, msg, true); success = true; } else if (cdbus_m_ismethod("list_win")) { success = cdbus_process_list_win(ps, msg); } else if (cdbus_m_ismethod("win_get")) { success = cdbus_process_win_get(ps, msg); } else if (cdbus_m_ismethod("win_set")) { success = cdbus_process_win_set(ps, msg); } else if (cdbus_m_ismethod("find_win")) { success = cdbus_process_find_win(ps, msg); } else if (cdbus_m_ismethod("opts_get")) { success = cdbus_process_opts_get(ps, msg); } else if (cdbus_m_ismethod("opts_set")) { success = cdbus_process_opts_set(ps, msg); } #undef cdbus_m_ismethod else if (dbus_message_is_method_call(msg, "org.freedesktop.DBus.Introspectable", "Introspect")) { success = cdbus_process_introspect(ps, msg); } else if (dbus_message_is_method_call(msg, "org.freedesktop.DBus.Peer", "Ping")) { cdbus_reply(ps, msg, NULL, NULL); success = true; } else if (dbus_message_is_method_call(msg, "org.freedesktop.DBus.Peer", "GetMachineId")) { char *uuid = dbus_get_local_machine_id(); if (uuid) { cdbus_reply_string(ps, msg, uuid); dbus_free(uuid); success = true; } } else if (dbus_message_is_signal(msg, "org.freedesktop.DBus", "NameAcquired") || dbus_message_is_signal(msg, "org.freedesktop.DBus", "NameLost")) { success = true; } else { if (DBUS_MESSAGE_TYPE_ERROR == dbus_message_get_type(msg)) { printf_errf("(): Error message of path \"%s\" " "interface \"%s\", member \"%s\", error \"%s\"", dbus_message_get_path(msg), dbus_message_get_interface(msg), dbus_message_get_member(msg), dbus_message_get_error_name(msg)); } else { printf_errf("(): Illegal message of type \"%s\", path \"%s\" " "interface \"%s\", member \"%s\"", cdbus_repr_msgtype(msg), dbus_message_get_path(msg), dbus_message_get_interface(msg), dbus_message_get_member(msg)); } if (DBUS_MESSAGE_TYPE_METHOD_CALL == dbus_message_get_type(msg) && !dbus_message_get_no_reply(msg)) cdbus_reply_err(ps, msg, CDBUS_ERROR_BADMSG, CDBUS_ERROR_BADMSG_S); success = true; } // If the message could not be processed, and an reply is expected, return // an empty reply. if (!success && DBUS_MESSAGE_TYPE_METHOD_CALL == dbus_message_get_type(msg) && !dbus_message_get_no_reply(msg)) cdbus_reply_err(ps, msg, CDBUS_ERROR_UNKNOWN, CDBUS_ERROR_UNKNOWN_S); // Free the message dbus_message_unref(msg); }
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); }
int tool_cmd_leave(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(leave_option_list, argv[0], leave_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_LEAVE ); fprintf(stderr, "Leaving current WPAN. . .\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) { fprintf(stderr, "%s failed with error %d. %s\n", argv[0], ret, wpantund_status_to_cstr(ret)); print_error_diagnosis(ret); } } 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; }