[avahi] about the scanf like function

Lennart Poettering lennart at poettering.de
Mon Aug 22 08:13:13 PDT 2005


On Mon, 22.08.05 13:42, Sebastien Estienne (sebastien.estienne at gmail.com) wrote:

> > You could have a list of *possible* values.
> > I thought of something like this: let's say you got a FooDevice
> > providing FooService of brand Bar. The specs say a FooDevice/FooService
> > should provide TXT fields A and B, so the device does that. Bar's
> > engineers decice it could be usefull to have an extra TXT record C, that
> > can be used by application developers, that's not in the spec. Now if
> > your app would poll every FooDevice providing FooService it discovers
> > whether it provides the C TXT record, that would not be nice (IMHO), as
> > another vendor might provide a D record, then your code will become
> > pretty ugly. If you can just iterate, the code will be (i think)
> > prettier.

> What will you do with the value of C and D TXT record if you don't
> know that they exist when you wrote your code? how can you guess their
> meaning?

Just ignore them!

Why should i guess their meaning? 

> anyway having an iterator is usefull :)

<snip>
for (p = list; p; p = p->next) {
    char *key, *value;

    if (avahi_string_list_get_pair(p, &key, &value) < 0) {
       fprintf(stder, "Not enough memory\n");
       abort();
    }

    if (strcmp(key, "bla") == 0) 
       printf("bla is %s!\n", value);
    else if (strcmp(key, "foo") == 0)
       printf("foo is %s!\n", value):

    /* Ignore other keys */
  
    avahi_free(key);
    avahi_free(value);
}
</snip>

Lennart

-- 
Lennart Poettering; lennart [at] poettering [dot] de
ICQ# 11060553; GPG 0x1A015CC4; http://0pointer.de/lennart/


More information about the avahi mailing list