mirror of
https://github.com/servalproject/serval-dna.git
synced 2024-12-21 06:03:12 +00:00
1fbf7001d1
So that dataformats.o can be linked into executables that don't have log.o.
108 lines
2.5 KiB
C
108 lines
2.5 KiB
C
/*
|
|
Serval Distributed Numbering Architecture (DNA)
|
|
Copyright (C) 2010 Paul Gardner-Stephen
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
modify it under the terms of the GNU General Public License
|
|
as published by the Free Software Foundation; either version 2
|
|
of the License, or (at your option) any later version.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with this program; if not, write to the Free Software
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
*/
|
|
|
|
#include "serval.h"
|
|
#include "rhizome.h"
|
|
#include "str.h"
|
|
#include <ctype.h>
|
|
|
|
int str_is_subscriber_id(const char *sid)
|
|
{
|
|
size_t len = 0;
|
|
return strn_is_subscriber_id(sid, &len) && sid[len] == '\0';
|
|
}
|
|
|
|
int strn_is_subscriber_id(const char *sid, size_t *lenp)
|
|
{
|
|
if (strncasecmp(sid, "broadcast", 9) == 0) {
|
|
if (lenp)
|
|
*lenp = 9;
|
|
return 1;
|
|
}
|
|
if (is_xsubstring(sid, SID_STRLEN)) {
|
|
if (lenp)
|
|
*lenp = SID_STRLEN;
|
|
return 1;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
int rhizome_strn_is_manifest_id(const char *id)
|
|
{
|
|
return is_xsubstring(id, RHIZOME_MANIFEST_ID_STRLEN);
|
|
}
|
|
|
|
int rhizome_str_is_manifest_id(const char *id)
|
|
{
|
|
return is_xstring(id, RHIZOME_MANIFEST_ID_STRLEN);
|
|
}
|
|
|
|
int rhizome_strn_is_bundle_key(const char *key)
|
|
{
|
|
return is_xsubstring(key, RHIZOME_BUNDLE_KEY_STRLEN);
|
|
}
|
|
|
|
int rhizome_str_is_bundle_key(const char *key)
|
|
{
|
|
return is_xstring(key, RHIZOME_BUNDLE_KEY_STRLEN);
|
|
}
|
|
|
|
int rhizome_strn_is_bundle_crypt_key(const char *key)
|
|
{
|
|
return is_xsubstring(key, RHIZOME_CRYPT_KEY_STRLEN);
|
|
}
|
|
|
|
int rhizome_str_is_bundle_crypt_key(const char *key)
|
|
{
|
|
return is_xstring(key, RHIZOME_CRYPT_KEY_STRLEN);
|
|
}
|
|
|
|
int rhizome_strn_is_file_hash(const char *hash)
|
|
{
|
|
return is_xsubstring(hash, RHIZOME_FILEHASH_STRLEN);
|
|
}
|
|
|
|
int rhizome_str_is_file_hash(const char *hash)
|
|
{
|
|
return is_xstring(hash, RHIZOME_FILEHASH_STRLEN);
|
|
}
|
|
|
|
int str_is_did(const char *did)
|
|
{
|
|
size_t len = 0;
|
|
return strn_is_did(did, &len) && did[len] == '\0';
|
|
}
|
|
|
|
int is_didchar(char c)
|
|
{
|
|
return isdigit(c) || c == '*' || c == '#' || c == '+';
|
|
}
|
|
|
|
int strn_is_did(const char *did, size_t *lenp)
|
|
{
|
|
int i;
|
|
for (i = 0; i < DID_MAXSIZE && is_didchar(did[i]); ++i)
|
|
;
|
|
if (i < DID_MINSIZE)
|
|
return 0;
|
|
if (lenp)
|
|
*lenp = i;
|
|
return 1;
|
|
}
|