Skip to content

Commit

Permalink
Fix some warnings, add dbus method to set network options
Browse files Browse the repository at this point in the history
Signed-off-by: Philippe De Swert <philippedeswert@gmail.com>
  • Loading branch information
philippedeswert committed Nov 19, 2012
1 parent 4a69943 commit 1b6ee42
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/usb_moded-config-private.h
Expand Up @@ -25,3 +25,4 @@

const char * get_mode_setting(void);
int set_mode_setting(const char *mode);
int set_network_setting(const char *config, const char *setting);
35 changes: 34 additions & 1 deletion src/usb_moded-config.c
Expand Up @@ -133,7 +133,7 @@ const char * get_network_gateway(void)
static void create_conf_file(void)
{
GKeyFile *settingsfile;
gchar **keys, *keyfile;
gchar *keyfile;

settingsfile = g_key_file_new();

Expand Down Expand Up @@ -240,6 +240,39 @@ int set_mode_setting(const char *mode)
return(!ret);
}

int set_network_setting(const char *config, const char *setting)
{
GKeyFile *settingsfile;
gboolean test = FALSE;
int ret = 0;
gchar *keyfile;

settingsfile = g_key_file_new();
test = g_key_file_load_from_file(settingsfile, FS_MOUNT_CONFIG_FILE, G_KEY_FILE_NONE, NULL);
if(!test)
{
log_debug("No conffile. Creating.\n");
create_conf_file();
}

if(!strcmp(config, NETWORK_IP_KEY) || !strcmp(config, NETWORK_INTERFACE_KEY) || !strcmp(config, NETWORK_GATEWAY_KEY))
{
g_key_file_set_string(settingsfile, NETWORK_ENTRY, config, setting);
keyfile = g_key_file_to_data (settingsfile, NULL, NULL);
/* free the settingsfile before writing things out to be sure
the contents will be correctly written to file afterwards.
Just a precaution. */
g_key_file_free(settingsfile);
ret = g_file_set_contents(FS_MOUNT_CONFIG_FILE, keyfile, -1, NULL);
}
else
{
g_key_file_free(settingsfile);
return(1);
}
/* g_file_set_contents returns 1 on succes, since set_mode_settings returns 0 on succes we return the ! value */
return(!ret);
}

#endif

20 changes: 20 additions & 0 deletions src/usb_moded-dbus.c
Expand Up @@ -126,6 +126,26 @@ static DBusHandlerResult msg_handler(DBusConnection *const connection, DBusMessa
}
dbus_error_free(&err);
}
else if(!strcmp(member, USB_MODE_NETWORK_SET))
{
char *config = 0, *setting = 0;
DBusError err = DBUS_ERROR_INIT;

if(!dbus_message_get_args(msg, &err, DBUS_TYPE_STRING, &config, DBUS_TYPE_STRING, &setting, DBUS_TYPE_INVALID))
reply = dbus_message_new_error(msg, DBUS_ERROR_INVALID_ARGS, member);
else
{
/* error checking is done when setting the GConf key */
if(!set_network_setting(config, 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);
}
else
reply = dbus_message_new_error(msg, DBUS_ERROR_INVALID_ARGS, config);
}
dbus_error_free(&err);
}
else
{
/*unknown methods are handled here */
Expand Down
1 change: 1 addition & 0 deletions src/usb_moded-dbus.h
Expand Up @@ -35,6 +35,7 @@
**/
#define USB_MODE_STATE_SET "set_mode"
#define USB_MODE_CONFIG_SET "set_config"
#define USB_MODE_NETWORK_SET "net_config"

/* state definitions for signals and method parameters */
#define USB_CONNECTED "USB connected"
Expand Down
2 changes: 0 additions & 2 deletions src/usb_moded-network.c
Expand Up @@ -100,8 +100,6 @@ int usb_network_up(void)
system(command);
}

end:

return(0);
#endif /* CONNMAN */
}
Expand Down

0 comments on commit 1b6ee42

Please sign in to comment.