File tree Expand file tree Collapse file tree 1 file changed +19
-6
lines changed
Expand file tree Collapse file tree 1 file changed +19
-6
lines changed Original file line number Diff line number Diff line change 3535#include <ctype.h>
3636#include <errno.h>
3737#include <fcntl.h>
38+ #include <stdbool.h>
3839#include <stdint.h>
3940#include <stdio.h>
4041#include <stdlib.h>
@@ -167,7 +168,7 @@ encode_rfc1035(const char *src, uint8_t *dst)
167168 uint8_t * p ;
168169 uint8_t * lp ;
169170 size_t len ;
170- uint8_t has_dot ;
171+ bool has_dot , in_data , in_space ;
171172
172173 if (src == NULL || * src == '\0' )
173174 return 0 ;
@@ -181,23 +182,35 @@ encode_rfc1035(const char *src, uint8_t *dst)
181182 p = lp = NULL ;
182183
183184 len = 1 ;
184- has_dot = 0 ;
185+ has_dot = in_data = in_space = false ;
185186 for (; * src ; src ++ ) {
186187 if (* src == '\0' )
187188 break ;
188- if (* src == '.' ) {
189+ if (* src == '.' || * src == ' ' || * src == ',' ) {
190+ if (in_space )
191+ continue ;
189192 /* Skip the trailing . */
190193 if (src [1 ] == '\0' )
191194 break ;
192- has_dot = 1 ;
193- if (dst ) {
195+ has_dot = true ;
196+ if (in_data ) {
194197 * lp = (uint8_t )(p - lp - 1 );
195198 if (* lp == '\0' )
196199 return len ;
200+ if (* src == ' ' || * src == ',' )
201+ * p ++ = '\0' ;
197202 lp = p ++ ;
203+ in_data = false;
198204 }
199- } else if (dst )
205+ if (* src == ' ' || * src == ',' ) {
206+ in_space = true;
207+ len ++ ;
208+ }
209+ } else if (dst ) {
200210 * p ++ = (uint8_t )* src ;
211+ in_data = true;
212+ in_space = false;
213+ }
201214 len ++ ;
202215 }
203216
You can’t perform that action at this time.
0 commit comments