summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHolger Hans Peter Freyther <zecke@selfish.org>2011-01-13 13:53:06 +0100
committerHolger Hans Peter Freyther <zecke@selfish.org>2011-01-13 13:53:26 +0100
commit9566027b0728684b3a6fbb76dacb03bda4a37bc7 (patch)
tree23407863ea278ef68f96c9d96ffacb8dcbc687e1
parentd9447ba5e6ed74fb60d8a945f9e329fab4380762 (diff)
m2ua: Implement to find a tag inside a message
-rw-r--r--include/m2ua/m2ua_msg.h2
-rw-r--r--src/m2ua_msg.c11
-rw-r--r--tests/m2ua/m2ua_test.c10
3 files changed, 23 insertions, 0 deletions
diff --git a/include/m2ua/m2ua_msg.h b/include/m2ua/m2ua_msg.h
index 49fe8cc..88eb8a1 100644
--- a/include/m2ua/m2ua_msg.h
+++ b/include/m2ua/m2ua_msg.h
@@ -48,6 +48,8 @@ void m2ua_msg_free(struct m2ua_msg *msg);
int m2ua_msg_add_data(struct m2ua_msg *msg, uint16_t tag, uint16_t len, uint8_t *dat);
+struct m2ua_msg_part *m2ua_msg_find_tag(struct m2ua_msg *msg, uint16_t tag);
+
struct m2ua_msg *m2ua_from_msg(uint16_t len, uint8_t *data);
struct msgb *m2ua_to_msg(struct m2ua_msg *msg);
diff --git a/src/m2ua_msg.c b/src/m2ua_msg.c
index c4115b6..9a82e59 100644
--- a/src/m2ua_msg.c
+++ b/src/m2ua_msg.c
@@ -73,6 +73,17 @@ int m2ua_msg_add_data(struct m2ua_msg *msg, uint16_t tag,
return 0;
}
+struct m2ua_msg_part *m2ua_msg_find_tag(struct m2ua_msg *m2ua, uint16_t tag)
+{
+ struct m2ua_msg_part *part;
+
+ llist_for_each_entry(part, &m2ua->headers, entry)
+ if (part->tag == tag)
+ return part;
+
+ return NULL;
+}
+
struct m2ua_msg *m2ua_from_msg(uint16_t len, uint8_t *data)
{
struct m2ua_parameter_hdr *par;
diff --git a/tests/m2ua/m2ua_test.c b/tests/m2ua/m2ua_test.c
index c257d82..848bd7a 100644
--- a/tests/m2ua/m2ua_test.c
+++ b/tests/m2ua/m2ua_test.c
@@ -37,8 +37,10 @@ static uint8_t asp_up[] = {
int main(int argc, char **argv)
{
+ struct m2ua_msg_part *part;
struct m2ua_msg *m2u = m2ua_from_msg(ARRAY_SIZE(asp_up), asp_up);
struct msgb *msg = m2ua_to_msg(m2u);
+ const uint8_t res[] = { 0xac, 0x10, 0x01, 0x51 };
if (msg->len != ARRAY_SIZE(asp_up)) {
printf("Got %d wanted %d\n", msg->len, ARRAY_SIZE(asp_up));
@@ -50,6 +52,14 @@ int main(int argc, char **argv)
FAIL("Wrong memory");
}
+ part = m2ua_msg_find_tag(m2u, 0x11);
+ if (!part)
+ FAIL("Could not find part");
+ if (part->len != 4)
+ FAIL("Part is not of length four\n");
+ if (memcmp(part->dat, res, 4) != 0)
+ FAIL("Wrong result for the tag\n");
+
m2ua_msg_free(m2u);
msgb_free(msg);