summaryrefslogtreecommitdiffstats
path: root/avahi-common/domain.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2005-10-11 00:58:04 +0000
committerLennart Poettering <lennart@poettering.net>2005-10-11 00:58:04 +0000
commitf56d3a4e5dec3aa75d25fae761a0642e6ebd7c3c (patch)
tree5ef56fa5e9815da6ec06ce6f83fe07a7a3453758 /avahi-common/domain.c
parentc530608ec993bf73e3d22d070a8d1ecd1f302ee4 (diff)
* rename avahi_is_valid_service_type() to avahi_is_valid_service_type_generic()
* add avahi_is_valid_service_type_strict() which doesn't allow subtypes and other strange things to pass * fix protocol validity checks in server.c * add new API function avahi_get_type_from_subtype() git-svn-id: file:///home/lennart/svn/public/avahi/trunk@716 941a03a8-eaeb-0310-b9a0-b1bbd8fe43fe
Diffstat (limited to 'avahi-common/domain.c')
-rw-r--r--avahi-common/domain.c99
1 files changed, 97 insertions, 2 deletions
diff --git a/avahi-common/domain.c b/avahi-common/domain.c
index b72a898..f2e4395 100644
--- a/avahi-common/domain.c
+++ b/avahi-common/domain.c
@@ -293,7 +293,7 @@ int avahi_binary_domain_cmp(const char *a, const char *b) {
}
}
-int avahi_is_valid_service_type(const char *t) {
+int avahi_is_valid_service_type_generic(const char *t) {
assert(t);
if (strlen(t) >= AVAHI_DOMAIN_NAME_MAX || !*t)
@@ -313,6 +313,101 @@ int avahi_is_valid_service_type(const char *t) {
return 1;
}
+int avahi_is_valid_service_type_strict(const char *t) {
+ char label[AVAHI_LABEL_MAX];
+ assert(t);
+
+ if (strlen(t) >= AVAHI_DOMAIN_NAME_MAX || !*t)
+ return 0;
+
+ /* Application name */
+
+ if (!(avahi_unescape_label(&t, label, sizeof(label))))
+ return 0;
+
+ if (strlen(label) <= 2 || label[0] != '_')
+ return 0;
+
+ if (!*t)
+ return 0;
+
+ /* _tcp or _udp boilerplate */
+
+ if (!(avahi_unescape_label(&t, label, sizeof(label))))
+ return 0;
+
+ if (strcasecmp(label, "_tcp") && strcasecmp(label, "_udp"))
+ return 0;
+
+ if (*t)
+ return 0;
+
+ return 1;
+}
+
+const char *avahi_get_type_from_subtype(const char *t) {
+ char label[AVAHI_LABEL_MAX];
+ const char *ret;
+ assert(t);
+
+ if (strlen(t) >= AVAHI_DOMAIN_NAME_MAX || !*t)
+ return NULL;
+
+ /* Subtype name */
+
+ if (!(avahi_unescape_label(&t, label, sizeof(label))))
+ return NULL;
+
+ if (strlen(label) <= 2 || label[0] != '_')
+ return NULL;
+
+ if (!*t)
+ return NULL;
+
+ /* String "_sub" */
+
+ if (!(avahi_unescape_label(&t, label, sizeof(label))))
+ return NULL;
+
+ if (strcasecmp(label, "_sub"))
+ return NULL;
+
+ if (!*t)
+ return NULL;
+
+ ret = t;
+
+ /* Application name */
+
+ if (!(avahi_unescape_label(&t, label, sizeof(label))))
+ return NULL;
+
+ if (strlen(label) <= 2 || label[0] != '_')
+ return NULL;
+
+ if (!*t)
+ return NULL;
+
+ /* _tcp or _udp boilerplate */
+
+ if (!(avahi_unescape_label(&t, label, sizeof(label))))
+ return NULL;
+
+ if (strcasecmp(label, "_tcp") && strcasecmp(label, "_udp"))
+ return NULL;
+
+ if (*t)
+ return NULL;
+
+ return ret;
+}
+
+int avahi_is_valid_service_subtype(const char *t) {
+ assert(t);
+
+ return !!avahi_get_type_from_subtype(t);
+}
+
int avahi_is_valid_domain_name(const char *t) {
assert(t);
@@ -407,7 +502,7 @@ int avahi_service_name_join(char *p, size_t size, const char *name, const char *
if ((name && !avahi_is_valid_service_name(name)))
return AVAHI_ERR_INVALID_SERVICE_NAME;
- if (!avahi_is_valid_service_type(type))
+ if (!avahi_is_valid_service_type_generic(type))
return AVAHI_ERR_INVALID_SERVICE_TYPE;
if (!avahi_is_valid_domain_name(domain))