blob: ab190ce3491ba5bea28e2e0ec987257e51ff9494 [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
22 if (selfComponent->valueLength != nameComponent->valueLength ||
23 ndn_memcmp(selfComponent->value, nameComponent->value, selfComponent->valueLength) != 0)
24 return 0;
25 }
26
27 return 1;
28}