src/dbus/address.c
/**
 * address_from_string() - initialize address from string representation
 * @address:            address to operate on
 * @string:             string to use
 *
 * This initializes @address from the string representation of an address,
 * given as @string. On return, @address->type will contain the type of the
 * address that was given as @string. Note that this might be
 * ADDRESS_TYPE_OTHER, in case the parser couldn't detect the address type.
 *
 * Note that @string is *NOT* copied into @address, but might be referenced
 * from it. Hence, the lifetime of @address is bound to @string.
 *
 * This function does not fully validate the address! All it does is to detect
 * the type of address, but the address might still be invalid. In other words,
 * this function correctly assigns a type to all valid addresses. However, in
 * case of invalid addresses, it might give false positives. That is, for the
 * sake of distinguishing addresses, this is sufficient. However, for the sake
 * of data validation when creating/acquiring names, you need to further verify
 * the validity of the name.
 */
initialize address from string representation
@address:            address to operate on
@string:             string to use

This initializes @address from the string representation of an address,
given as @string. On return, @address->type will contain the type of the
address that was given as @string. Note that this might be
ADDRESS_TYPE_OTHER, in case the parser couldn't detect the address type.

Note that @string is *NOT* copied into @address, but might be referenced
from it. Hence, the lifetime of @address is bound to @string.

This function does not fully validate the address. All it does is to detect
the type of address, but the address might still be invalid. In other words,
this function correctly assigns a type to all valid addresses. However, in
case of invalid addresses, it might give false positives. That is, for the
sake of distinguishing addresses, this is sufficient. However, for the sake
of data validation when creating/acquiring names, you need to further verify
the validity of the name.
initialize address from string representation @address : address to operate on @string : string to use This initializes @address from the string representation of an address given as @string . On return @address - > type will contain the type of the address that was given as @string . Note that this might be ADDRESS_TYPE_OTHER in case the parser couldn ' t detect the address type . Note that @string is * NOT * copied into @address but might be referenced from it . Hence the lifetime of @address is bound to @string . This function does not fully validate the address . All it does is to detect the type of address but the address might still be invalid . In other words this function correctly assigns a type to all valid addresses . However in case of invalid addresses it might give false positives . That is for the sake of distinguishing addresses this is sufficient . However for the sake of data validation when creating / acquiring names you need to further verify the validity of the name .
void address_from_string(Address *address, const char *string) {
        uint64_t id;
        char *end;
        address->type = ADDRESS_TYPE_OTHER;
        if (!string[0]) {
                return;
        } else if (string[0] == ':') {
                if (strncmp(string, ":1.", strlen(":1.")))
                        return;
                string += strlen(":1.");
                errno = 0;
                id = strtoull(string, &end, 10);
                if (end == string || *end || errno || id == ULLONG_MAX)
                        return;
                address->type = ADDRESS_TYPE_ID;
                address->id = id;
        } else {
                address->type = ADDRESS_TYPE_NAME;
                address->name = string;
        }
}
void address_from_string ( Address * address , const char * string ) { uint64_t id ; char * end ; address -> type = ADDRESS_TYPE_OTHER ; if ( ! string [ 0 ] ) { return ; } else if ( string [ 0 ] == ' ' ) { if ( strncmp ( string , " " , strlen ( " " ) ) ) return ; string += strlen ( " " ) ; errno = 0 ; id = strtoull ( string , & end , 10 ) ; if ( end == string || * end || errno || id == ULLONG_MAX ) return ; address -> type = ADDRESS_TYPE_ID ; address -> id = id ; } else { address -> type = ADDRESS_TYPE_NAME ; address -> name = string ; } }
address_from_string() - initialize address from string representation
 @address:            address to operate on
 @string:             string to use
address_from_string () - initialize address from string representation @address : address to operate on @string : string to use