Skip to content

Commit

Permalink
fsm: Add object_path parsing functions
Browse files Browse the repository at this point in the history
- __ni_fsm_dbus_objectpath_to_ifindex
- __ni_fsm_dbus_objectpath_to_name
  • Loading branch information
wipawel committed Jul 3, 2014
1 parent 742800a commit 8f87783
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions src/fsm.c
Expand Up @@ -593,6 +593,53 @@ ni_ifworker_array_remove_with_children(ni_ifworker_array_t *array, ni_ifworker_t
}
}

static unsigned int
__ni_fsm_dbus_objectpath_to_ifindex(const char *object_path)
{
ni_string_array_t nsa = NI_STRING_ARRAY_INIT;
unsigned int ifindex = 0;

if (ni_string_empty(object_path))
goto done;

if (!ni_string_split(&nsa, object_path, "/", 0)) {
ni_error("unable to parse object_path=%s", object_path);
goto done;
}

if (ni_parse_uint(nsa.data[nsa.count-1], &ifindex, 10) < 0) {
ni_error("wrong ifindex value in object_path=%s", object_path);
goto done;
}

done:
ni_string_array_destroy(&nsa);
return ifindex;
}

/*
* __ni_dbus_objectpath_to_name() allocates a string and return interface name
*/
static char *
__ni_fsm_dbus_objectpath_to_name(const char *object_path)
{
char buf[IF_NAMESIZE+1] = { 0 };
unsigned int ifindex;
char *ifname = NULL;

if (ni_string_empty(object_path))
return NULL;;

ifindex = __ni_fsm_dbus_objectpath_to_ifindex(object_path);
if (!if_indextoname(ifindex, buf)) {
ni_error("unable to get ifname from ifindex=%d", ifindex);
return NULL;
}

ni_string_dup(&ifname, buf);
return ifname;
}

ni_ifworker_t *
ni_fsm_ifworker_by_name(ni_fsm_t *fsm, ni_ifworker_type_t type, const char *ifname)
{
Expand Down

0 comments on commit 8f87783

Please sign in to comment.