Commit b92c102f authored by Dafydd Harries's avatar Dafydd Harries
Browse files

stun_message_find_attribute ()

darcs-hash:20070316024908-c9803-904bbc4e085072d1be34c7f131bb769dd838f6fd.gz
parent f80aa521
......@@ -25,7 +25,8 @@ check_PROGRAMS = \
test-message-pack \
test-message-dump \
test-message-dump-unknown \
test-message-unpack
test-message-unpack \
test-message-find-attribute
test_attribute_pack_LDADD = libstun.la
test_attribute_pack_unknown_LDADD = libstun.la
......@@ -38,6 +39,7 @@ test_message_pack_LDADD = libstun.la
test_message_dump_LDADD = libstun.la
test_message_dump_unknown_LDADD = libstun.la
test_message_unpack_LDADD = libstun.la
test_message_find_attribute_LDADD = libstun.la
TESTS = $(check_PROGRAMS)
......@@ -338,3 +338,17 @@ stun_message_dump (StunMessage *msg)
return g_string_free (tmp, FALSE);
}
StunAttribute *
stun_message_find_attribute (StunMessage *msg, StunAttributeType type)
{
StunAttribute **attr;
if (!msg->attributes)
return NULL;
for (attr = msg->attributes; *attr; attr++)
if ((*attr)->type == type)
return *attr;
return NULL;
}
......@@ -123,6 +123,9 @@ G_GNUC_WARN_UNUSED_RESULT
StunMessage *
stun_message_unpack (guint length, const gchar *s);
StunAttribute *
stun_message_find_attribute (StunMessage *msg, StunAttributeType type);
G_END_DECLS
#endif /* __STUN_H__ */
......
#include "stun.h"
int
main (void)
{
StunMessage *msg;
msg = stun_message_new (STUN_MESSAGE_BINDING_REQUEST, NULL, 1);
g_assert (NULL ==
stun_message_find_attribute (msg, STUN_ATTRIBUTE_MAPPED_ADDRESS));
msg->attributes[0] = stun_attribute_mapped_address_new (0x01020304, 1234);
g_assert (msg->attributes[0] ==
stun_message_find_attribute (msg, STUN_ATTRIBUTE_MAPPED_ADDRESS));
return 0;
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment