Skip to content

Commit

Permalink
Add dbus method to query network settings.
Browse files Browse the repository at this point in the history
Signed-off-by: Philippe De Swert <philippe.deswert@jollamobile.com>
  • Loading branch information
philippedeswert committed Aug 31, 2013
1 parent e4afe4c commit 5feb37d
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 3 deletions.
8 changes: 7 additions & 1 deletion debian/usb_moded.conf
Expand Up @@ -16,9 +16,15 @@
<allow send_destination="com.meego.usb_moded"
send_interface="com.meego.usb_moded" send_member="set_config"/>
<deny own="com.meego.usb_moded"/>
<allow send_destination="com.meego.usb_moded"
<allow send_destination="com.meego.usb_moded"
send_interface="com.meego.usb_moded" send_member="get_modes"/>
<deny own="com.meego.usb_moded"/>
<allow send_destination="com.meego.usb_moded"
send_interface="com.meego.usb_moded" send_member="net_config"/>
<deny own="com.meego.usb_moded"/>
<allow send_destination="com.meego.usb_moded"
send_interface="com.meego.usb_moded" send_member="get_net_config"/>
<deny own="com.meego.usb_moded"/>
</policy>
</busconfig>

3 changes: 2 additions & 1 deletion src/usb_moded-config-private.h
Expand Up @@ -18,11 +18,12 @@
02110-1301 USA
*/
/*
* Gets information from Gconf/ini file for the usb modes
* Gets/sets information for the usb modes from dbus
*/

/*============================================================================= */

const char * get_mode_setting(void);
int set_mode_setting(const char *mode);
int set_network_setting(const char *config, const char *setting);
const char *get_network_setting(const char *config);
25 changes: 25 additions & 0 deletions src/usb_moded-config.c
Expand Up @@ -383,6 +383,31 @@ int set_network_setting(const char *config, const char *setting)
return(!ret);
}

const char * get_network_setting(const char *config)
{
const char * ret = 0;

if(!strcmp(config, NETWORK_IP_KEY))
{
ret = get_network_ip();
if(!ret)
ret = strdup("192.168.2.15");
}
else if(!strcmp(config, NETWORK_INTERFACE_KEY))
{

ret = get_network_interface();
if(!ret)
ret = strdup("usb0");
}
else if(!strcmp(config, NETWORK_GATEWAY_KEY))
return(get_network_gateway());
else
/* no matching keys, return error */
return(NULL);
return(ret);
}

int conf_file_merge(void)
{
GDir *confdir;
Expand Down
25 changes: 24 additions & 1 deletion src/usb_moded-dbus.c
Expand Up @@ -137,7 +137,7 @@ static DBusHandlerResult msg_handler(DBusConnection *const connection, DBusMessa
reply = dbus_message_new_error(msg, DBUS_ERROR_INVALID_ARGS, member);
else
{
/* error checking is done when setting the GConf key */
/* error checking is done when setting configuration */
if(!set_network_setting(config, setting))
{
if((reply = dbus_message_new_method_return(msg)))
Expand All @@ -148,6 +148,29 @@ static DBusHandlerResult msg_handler(DBusConnection *const connection, DBusMessa
}
dbus_error_free(&err);
}
else if(!strcmp(member, USB_MODE_NETWORK_GET))
{
char *config = 0;
const char *setting = 0;
DBusError err = DBUS_ERROR_INIT;

if(!dbus_message_get_args(msg, &err, DBUS_TYPE_STRING, &config, DBUS_TYPE_INVALID))
{
reply = dbus_message_new_error(msg, DBUS_ERROR_INVALID_ARGS, member);
}
else
{
setting = get_network_setting(config);
if(setting)
{
if((reply = dbus_message_new_method_return(msg)))
dbus_message_append_args (reply, DBUS_TYPE_STRING, &config, DBUS_TYPE_STRING, &setting, DBUS_TYPE_INVALID);
free((void *)setting);
}
else
reply = dbus_message_new_error(msg, DBUS_ERROR_INVALID_ARGS, config);
}
}
else if(!strcmp(member, USB_MODE_CONFIG_GET))
{
const char *config = get_mode_setting();
Expand Down
1 change: 1 addition & 0 deletions src/usb_moded-dbus.h
Expand Up @@ -40,6 +40,7 @@
#define USB_MODE_STATE_SET "set_mode" /* set a mode (only works when connected) */
#define USB_MODE_CONFIG_SET "set_config" /* set the mode that needs to be activated in the config file */
#define USB_MODE_NETWORK_SET "net_config" /* set the network config in the config file */
#define USB_MODE_NETWORK_GET "get_net_config" /* get the network config from the config file */

/* state definitions for signals and method parameters */
#define USB_CONNECTED "USB connected"
Expand Down

0 comments on commit 5feb37d

Please sign in to comment.