blob: a81fbb36b5b817688d7da133b6c33b4d78e2f1ac [file] [log] [blame]
Jeff Thompsonf1ba9bd2013-08-12 17:43:08 -07001/**
Jeff Thompson7687dc02013-09-13 11:54:07 -07002 * Copyright (C) 2013 Regents of the University of California.
3 * @author: Jeff Thompson <jefft0@remap.ucla.edu>
Jeff Thompsonf1ba9bd2013-08-12 17:43:08 -07004 * See COPYING for copyright and distribution information.
5 */
6
7#include "util/ndn_memory.h"
8#include "name.h"
9
10int ndn_Name_match(struct ndn_Name *self, struct ndn_Name *name)
11{
12 // This name is longer than the name we are checking it against.
13 if (self->nComponents > name->nComponents)
14 return 0;
15
16 // Check if at least one of given components doesn't match.
Jeff Thompson97223af2013-09-24 17:01:27 -070017 size_t i;
Jeff Thompsonf1ba9bd2013-08-12 17:43:08 -070018 for (i = 0; i < self->nComponents; ++i) {
19 struct ndn_NameComponent *selfComponent = self->components + i;
20 struct ndn_NameComponent *nameComponent = name->components + i;
21
Jeff Thompson93034532013-10-08 11:52:43 -070022 if (selfComponent->value.length != nameComponent->value.length ||
23 ndn_memcmp(selfComponent->value.value, nameComponent->value.value, selfComponent->value.length) != 0)
Jeff Thompsonf1ba9bd2013-08-12 17:43:08 -070024 return 0;
25 }
26
27 return 1;
28}