• Home
  • History
  • Annotate
  • Raw
  • Download
  • only in /netgear-R7000-V1.0.7.12_1.2.5/ap/gpl/iserver/avahi-0.6.25/avahi-common/

Lines Matching defs:*

0 /* $Id$ */
4 This file is part of avahi.
6 avahi is free software; you can redistribute it and/or modify it
7 under the terms of the GNU Lesser General Public License as
8 published by the Free Software Foundation; either version 2.1 of the
9 License, or (at your option) any later version.
11 avahi is distributed in the hope that it will be useful, but WITHOUT
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
14 Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with avahi; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19 USA.
22 #ifdef HAVE_CONFIG_H
23 #include <config.h>
24 #endif
26 #include <string.h>
27 #include <stdlib.h>
28 #include <ctype.h>
29 #include <assert.h>
31 #include "alternative.h"
32 #include "malloc.h"
33 #include "domain.h"
34 #include "utf8.h"
36 static void drop_incomplete_utf8(char *c) {
37 char *e;
39 e = strchr(c, 0) - 1;
41 while (e >= c) {
43 if (avahi_utf8_valid(c))
44 break;
46 assert(*e & 128);
47 *e = 0;
49 e--;
53 char *avahi_alternative_host_name(const char *s) {
54 const char *e;
55 char *r;
57 assert(s);
59 if (!avahi_is_valid_host_name(s))
60 return NULL;
62 if ((e = strrchr(s, '-'))) {
63 const char *p;
65 e++;
67 for (p = e; *p; p++)
68 if (!isdigit(*p)) {
69 e = NULL;
70 break;
73 if (e && (*e == '0' || *e == 0))
74 e = NULL;
77 if (e) {
78 char *c, *m;
79 size_t l;
80 int n;
82 n = atoi(e)+1;
83 if (!(m = avahi_strdup_printf("%i", n)))
84 return NULL;
86 l = e-s-1;
88 if (l >= AVAHI_LABEL_MAX-1-strlen(m)-1)
89 l = AVAHI_LABEL_MAX-1-strlen(m)-1;
91 if (!(c = avahi_strndup(s, l))) {
92 avahi_free(m);
93 return NULL;
96 drop_incomplete_utf8(c);
98 r = avahi_strdup_printf("%s-%s", c, m);
99 avahi_free(c);
100 avahi_free(m);
102 } else {
103 char *c;
105 if (!(c = avahi_strndup(s, AVAHI_LABEL_MAX-1-2)))
106 return NULL;
108 drop_incomplete_utf8(c);
110 r = avahi_strdup_printf("%s-2", c);
111 avahi_free(c);
114 assert(avahi_is_valid_host_name(r));
116 return r;
119 char *avahi_alternative_service_name(const char *s) {
120 const char *e;
121 char *r;
123 assert(s);
125 if (!avahi_is_valid_service_name(s))
126 return NULL;
128 if ((e = strstr(s, " #"))) {
129 const char *n, *p;
130 e += 2;
132 while ((n = strstr(e, " #")))
133 e = n + 2;
135 for (p = e; *p; p++)
136 if (!isdigit(*p)) {
137 e = NULL;
138 break;
141 if (e && (*e == '0' || *e == 0))
142 e = NULL;
145 if (e) {
146 char *c, *m;
147 size_t l;
148 int n;
150 n = atoi(e)+1;
151 if (!(m = avahi_strdup_printf("%i", n)))
152 return NULL;
154 l = e-s-2;
156 if (l >= AVAHI_LABEL_MAX-1-strlen(m)-2)
157 l = AVAHI_LABEL_MAX-1-strlen(m)-2;
159 if (!(c = avahi_strndup(s, l))) {
160 avahi_free(m);
161 return NULL;
164 drop_incomplete_utf8(c);
166 r = avahi_strdup_printf("%s #%s", c, m);
167 avahi_free(c);
168 avahi_free(m);
169 } else {
170 char *c;
172 if (!(c = avahi_strndup(s, AVAHI_LABEL_MAX-1-3)))
173 return NULL;
175 drop_incomplete_utf8(c);
177 r = avahi_strdup_printf("%s #2", c);
178 avahi_free(c);
181 assert(avahi_is_valid_service_name(r));
183 return r;