sw_text_record_iterator

OVERVIEW

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

FUNCTION

sw_text_record_iterator_init

SYNOPSIS

sw_result
sw_text_record_iterator_init(
   sw_text_record_iterator * iterator)

DESCRIPTION

Creates a new text record 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_iterator it;

  if (sw_text_record_iterator_init(&it, text_record, text_record_len) != SW_OKAY)
  {
    fprintf(stderr, "init failed\n");
    return SW_E_FAIL;
  }
				
  ...
}

SEE ALSO

sw_text_record_iterator_fina


FUNCTION

sw_text_record_iterator_fina

SYNOPSIS

sw_result
sw_text_record_iterator_fina(
   sw_text_record_iterator  iterator)

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_iterator it;

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

  ...

  sw_text_record_iterator_fina(it);

  ...
}

SEE ALSO

sw_text_record_iterator_init


FUNCTION

sw_text_record_iterator_next

SYNOPSIS

sw_result
sw_text_record_iterator_next(
   sw_text_record_iterator iterator,
   sw_char                 key[255],
   sw_octet                val[255],
   sw_ulong              * val_len)

DESCRIPTION

Get the next key/value duple in the text record. The value is returned as an opaque data type with a length. It is up to the developer to handle any and all byte ordering issues.

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_iterator it;
  sw_char                 key[255];
  sw_octet                val[255];
  sw_ulong                val_len;

  if (sw_text_record_iterator_init(&it, text_record, text_record_len) !=- SW_OKAY)
  {
    fprintf(stderr, "init failed\n");
    return SW_E_FAIL;
  }

  while (sw_text_record_iterator_next(it, key, val, &val_len) == SW_OKAY)
  {
    ...
  }

  sw_text_record_iterator_fina(it);

  ...
}

SEE ALSO

sw_text_record_iterator_init, sw_text_record_iterator_fina