sw_text_record_string_iterator

OVERVIEW

The sw_text_record_string_iterator functions is a simple class that abstracts away the underlying encoding scheme of stringified DNS text records. The functions allow developers to iterate through a text record simply, obtaining each constituent key/value string pair.

FUNCTION

sw_text_record_string_iterator_init

SYNOPSIS

sw_result
sw_text_record_string_iterator_init(
   sw_text_record_string_iterator * iterator,
   sw_const_string                  text_record_string)

DESCRIPTION

Creates a new iterator.

EXAMPLE

sw_result
my_resolve_func(
  sw_discovery_resolve_handler handler,
  sw_discovery                 discovery,
  sw_discovery_resolve_id      id,
  sw_const_string               name,
  sw_const_string               type,
  sw_const_string               domain,
  sw_ipv4_address               address,
  sw_port                       port,
  sw_const_string               text_record_string,
  sw_octets                     text_record,
  sw_ulong                      text_record_len,
  sw_opaque                     extra)
{
  sw_text_record_string_iterator it;

  if (sw_text_record_string_iterator_init(&it, text_record_string) != SW_OKAY)
  {
    fprintf(stderr, "init failed\n");
    return SW_E_FAIL;
  }

  ...
}

SEE ALSO

sw_text_record_string_iterator_fina


FUNCTION

sw_text_record_string_iterator_fina

SYNOPSIS

sw_result
sw_text_record_string_iterator_fina(
   sw_text_record_string_iterator  it)

DESCRIPTION

Release all memory resources associated with iterator. Use of the iterator after calling this function is guaranteed to do something unexpected and undesirable.

EXAMPLE

sw_result
my_resolve_func(
  sw_discovery_resolve_handler handler,
  sw_discovery                 discovery,
  sw_discovery_resolve_id      id,
  sw_const_string               name,
  sw_const_string               type,
  sw_const_string               domain,
  sw_ipv4_address               address,
  sw_port                       port,
  sw_const_string               text_record_string,
  sw_octets                     text_record,
  sw_ulong                      text_record_len,
  sw_opaque                     extra)
{
  sw_text_record_string_iterator it;

  if (sw_text_record_string_iterator_init(&it, text_record_string) != SW_OKAY)
  {
    fprintf(stderr, "init failed\n");
    return SW_E_FAIL;
  }

  ...

  sw_text_record_string_iterator_fina(it);

  ...
}

SEE ALSO

sw_text_record_string_iterator_init


FUNCTION

sw_text_record_string_iterator_next

SYNOPSIS

sw_result
sw_text_record_string_iterator_next(
   sw_text_record_string_iterator iterator,
   sw_char                        key[255],
   sw_char                        val[255])

DESCRIPTION

Get the next key/value duple in the text record. The value is returned as a null terminated UTF-8 string.

EXAMPLE

sw_result
my_resolve_func(
  sw_discovery_resolve_handler handler,
  sw_discovery                 discovery,
  sw_discovery_resolve_id      id,
  sw_const_string               name,
  sw_const_string               type,
  sw_const_string               domain,
  sw_ipv4_address               address,
  sw_port                       port,
  sw_const_string               text_record_string,
  sw_octets                     text_record,
  sw_ulong                      text_record_len,
  sw_opaque                     extra)
{
  sw_text_record_string_iterator it;
  sw_char                        key[255];
  sw_char                        val[255];
  
  if (sw_text_record_string_iterator_init(&it, text_record_string) != SW_OKAY)
  {
    fprintf(stderr, "init failed\n");
    return SW_E_FAIL;
  }

  while (sw_text_record_string_iterator_next(it, key, val) == SW_OKAY)
  {
    ...
  }

  sw_text_record_string_iterator_fina(it);

  ...
}

SEE ALSO

sw_text_record_string_iterator_init, sw_text_record_string_iterator_fina