ReactOS 0.4.15-dev-7788-g1ad9096
parse.c File Reference
#include "internal.h"
Include dependency graph for parse.c:

Go to the source code of this file.

Functions

int vbuf__append_quoted1035 (vbuf *vb, const byte *buf, int len)
 
void adns__findlabel_start (findlabel_state *fls, adns_state ads, int serv, adns_query qu, const byte *dgram, int dglen, int max, int dmbegin, int *dmend_rlater)
 
adns_status adns__findlabel_next (findlabel_state *fls, int *lablen_r, int *labstart_r)
 
adns_status adns__parse_domain (adns_state ads, int serv, adns_query qu, vbuf *vb, adns_queryflags flags, const byte *dgram, int dglen, int *cbyte_io, int max)
 
adns_status adns__parse_domain_more (findlabel_state *fls, adns_state ads, adns_query qu, vbuf *vb, parsedomain_flags flags, const byte *dgram)
 
adns_status adns__findrr_anychk (adns_query qu, int serv, const byte *dgram, int dglen, int *cbyte_io, int *type_r, int *class_r, unsigned long *ttl_r, int *rdlen_r, int *rdstart_r, const byte *eo_dgram, int eo_dglen, int eo_cbyte, int *eo_matched_r)
 
adns_status adns__findrr (adns_query qu, int serv, const byte *dgram, int dglen, int *cbyte_io, int *type_r, int *class_r, unsigned long *ttl_r, int *rdlen_r, int *rdstart_r, int *ownermatchedquery_r)
 

Function Documentation

◆ adns__findlabel_next()

adns_status adns__findlabel_next ( findlabel_state fls,
int lablen_r,
int labstart_r 
)

Definition at line 74 of file parse.c.

75 {
76 int lablen, jumpto;
77 const char *dgram;
78
79 dgram= (char*)fls->dgram;
80 for (;;) {
81 if (fls->cbyte >= fls->dglen) goto x_truncated;
82 if (fls->cbyte >= fls->max) goto x_badresponse;
83 GET_B(fls->cbyte,lablen);
84 if (!(lablen & 0x0c0)) break;
85 if ((lablen & 0x0c0) != 0x0c0) return adns_s_unknownformat;
86 if (fls->cbyte >= fls->dglen) goto x_truncated;
87 if (fls->cbyte >= fls->max) goto x_badresponse;
88 GET_B(fls->cbyte,jumpto);
89 jumpto |= (lablen&0x3f)<<8;
90 if (fls->dmend_r) *(fls->dmend_r)= fls->cbyte;
91 fls->cbyte= jumpto;
92 fls->dmend_r= 0; fls->max= fls->dglen+1;
93 }
94 if (labstart_r) *labstart_r= fls->cbyte;
95 if (lablen) {
96 if (fls->namelen) fls->namelen++;
97 fls->namelen+= lablen;
98 if (fls->namelen > DNS_MAXDOMAIN) return adns_s_answerdomaintoolong;
99 fls->cbyte+= lablen;
100 if (fls->cbyte > fls->dglen) goto x_truncated;
101 if (fls->cbyte > fls->max) goto x_badresponse;
102 } else {
103 if (fls->dmend_r) *(fls->dmend_r)= fls->cbyte;
104 }
105 *lablen_r= lablen;
106 return adns_s_ok;
107
108 x_truncated:
109 *lablen_r= -1;
110 return adns_s_ok;
111
112 x_badresponse:
113 adns__diag(fls->ads,fls->serv,fls->qu,"label in domain runs beyond end of domain");
115}
@ adns_s_answerdomaintoolong
Definition: adns.h:247
@ adns_s_ok
Definition: adns.h:216
@ adns_s_unknownformat
Definition: adns.h:230
@ adns_s_invalidresponse
Definition: adns.h:229
static int fls(int x)
Definition: bitops.h:157
#define for
Definition: utility.h:88
void adns__diag(adns_state ads, int serv, adns_query qu, const char *fmt,...)
Definition: general.c:102
#define DNS_MAXDOMAIN
Definition: internal.h:75
#define GET_B(cb, tv)
Definition: internal.h:716

Referenced by adns__findrr_anychk(), adns__mkquery_frdgram(), adns__parse_domain_more(), pa_ptr(), and pap_mailbox822().

◆ adns__findlabel_start()

void adns__findlabel_start ( findlabel_state fls,
adns_state  ads,
int  serv,
adns_query  qu,
const byte dgram,
int  dglen,
int  max,
int  dmbegin,
int dmend_rlater 
)

Definition at line 59 of file parse.c.

62 {
63 fls->ads= ads;
64 fls->qu= qu;
65 fls->serv= serv;
66 fls->dgram= dgram;
67 fls->dglen= dglen;
68 fls->max= max;
69 fls->cbyte= dmbegin;
70 fls->namelen= 0;
71 fls->dmend_r= dmend_rlater;
72}
adns_state ads
Definition: adh-query.c:35
#define max(a, b)
Definition: svc.c:63

Referenced by adns__findrr_anychk(), adns__mkquery_frdgram(), adns__parse_domain(), pa_ptr(), and pap_mailbox822().

◆ adns__findrr()

adns_status adns__findrr ( adns_query  qu,
int  serv,
const byte dgram,
int  dglen,
int cbyte_io,
int type_r,
int class_r,
unsigned long ttl_r,
int rdlen_r,
int rdstart_r,
int ownermatchedquery_r 
)

Definition at line 227 of file parse.c.

231 {
232 if (!ownermatchedquery_r) {
233 return adns__findrr_anychk(qu,serv,
234 dgram,dglen,cbyte_io,
235 type_r,class_r,ttl_r,rdlen_r,rdstart_r,
236 0,0,0, 0);
237 } else if (!qu->cname_dgram) {
238 return adns__findrr_anychk(qu,serv,
239 dgram,dglen,cbyte_io,
240 type_r,class_r,ttl_r,rdlen_r,rdstart_r,
242 ownermatchedquery_r);
243 } else {
244 return adns__findrr_anychk(qu,serv,
245 dgram,dglen,cbyte_io,
246 type_r,class_r,ttl_r,rdlen_r,rdstart_r,
248 ownermatchedquery_r);
249 }
250}
#define DNS_HDRSIZE
Definition: internal.h:76
adns_status adns__findrr_anychk(adns_query qu, int serv, const byte *dgram, int dglen, int *cbyte_io, int *type_r, int *class_r, unsigned long *ttl_r, int *rdlen_r, int *rdstart_r, const byte *eo_dgram, int eo_dglen, int eo_cbyte, int *eo_matched_r)
Definition: parse.c:163
byte * query_dgram
Definition: internal.h:192
int query_dglen
Definition: internal.h:193
int cname_begin
Definition: internal.h:213
byte * cname_dgram
Definition: internal.h:212
int cname_dglen
Definition: internal.h:213

Referenced by adns__procdgram().

◆ adns__findrr_anychk()

adns_status adns__findrr_anychk ( adns_query  qu,
int  serv,
const byte dgram,
int  dglen,
int cbyte_io,
int type_r,
int class_r,
unsigned long ttl_r,
int rdlen_r,
int rdstart_r,
const byte eo_dgram,
int  eo_dglen,
int  eo_cbyte,
int eo_matched_r 
)

Definition at line 163 of file parse.c.

168 {
169 findlabel_state fls, eo_fls;
170 int cbyte;
171
172 int tmp, rdlen, mismatch;
173 unsigned long ttl;
174 int lablen, labstart, ch;
175 int eo_lablen, eo_labstart, eo_ch;
176 adns_status st;
177
178 cbyte= *cbyte_io;
179
180 adns__findlabel_start(&fls,qu->ads, serv,qu, dgram,dglen,dglen,cbyte,&cbyte);
181 if (eo_dgram) {
182 adns__findlabel_start(&eo_fls,qu->ads, -1,0, eo_dgram,eo_dglen,eo_dglen,eo_cbyte,0);
183 mismatch= 0;
184 } else {
185 mismatch= 1;
186 }
187
188 for (;;) {
189 st= adns__findlabel_next(&fls,&lablen,&labstart);
190 if (st) return st;
191 if (lablen<0) goto x_truncated;
192
193 if (!mismatch) {
194 st= adns__findlabel_next(&eo_fls,&eo_lablen,&eo_labstart);
195 assert(!st); assert(eo_lablen>=0);
196 if (lablen != eo_lablen) mismatch= 1;
197 while (!mismatch && eo_lablen-- > 0) {
198 ch= dgram[labstart++]; if (ctype_alpha(ch)) ch &= ~32;
199 eo_ch= eo_dgram[eo_labstart++]; if (ctype_alpha(eo_ch)) eo_ch &= ~32;
200 if (ch != eo_ch) mismatch= 1;
201 }
202 }
203 if (!lablen) break;
204 }
205 if (eo_matched_r) *eo_matched_r= !mismatch;
206
207 if (cbyte+10>dglen) goto x_truncated;
208 GET_W(cbyte,tmp); *type_r= tmp;
209 GET_W(cbyte,tmp); *class_r= tmp;
210
211 GET_L(cbyte,ttl);
212 if (ttl > MAXTTLBELIEVE) ttl= MAXTTLBELIEVE;
213 *ttl_r= ttl;
214
215 GET_W(cbyte,rdlen); if (rdlen_r) *rdlen_r= rdlen;
216 if (rdstart_r) *rdstart_r= cbyte;
217 cbyte+= rdlen;
218 if (cbyte>dglen) goto x_truncated;
219 *cbyte_io= cbyte;
220 return adns_s_ok;
221
222 x_truncated:
223 *type_r= -1;
224 return 0;
225}
_STLP_INLINE_LOOP _STLP_STD::pair< _InputIter1, _InputIter2 > mismatch(_InputIter1 __first1, _InputIter1 __last1, _InputIter2 __first2)
Definition: _algobase.h:522
adns_status
Definition: adns.h:215
static int cbyte
Definition: adnsresfilter.c:73
#define assert(x)
Definition: debug.h:53
#define GET_L(cb, tv)
Definition: internal.h:718
static int ctype_alpha(int c)
Definition: internal.h:699
#define MAXTTLBELIEVE
Definition: internal.h:70
#define GET_W(cb, tv)
Definition: internal.h:717
adns_status adns__findlabel_next(findlabel_state *fls, int *lablen_r, int *labstart_r)
Definition: parse.c:74
void adns__findlabel_start(findlabel_state *fls, adns_state ads, int serv, adns_query qu, const byte *dgram, int dglen, int max, int dmbegin, int *dmend_rlater)
Definition: parse.c:59
adns_state ads
Definition: internal.h:182

Referenced by adns__findrr(), and pap_findaddrs().

◆ adns__parse_domain()

adns_status adns__parse_domain ( adns_state  ads,
int  serv,
adns_query  qu,
vbuf vb,
adns_queryflags  flags,
const byte dgram,
int  dglen,
int cbyte_io,
int  max 
)

Definition at line 117 of file parse.c.

119 {
121
122 adns__findlabel_start(&fls,ads, serv,qu, dgram,dglen,max, *cbyte_io,cbyte_io);
123 vb->used= 0;
124 return adns__parse_domain_more(&fls,ads,qu, vb,flags,dgram);
125}
GLbitfield flags
Definition: glext.h:7161
adns_status adns__parse_domain_more(findlabel_state *fls, adns_state ads, adns_query qu, vbuf *vb, parsedomain_flags flags, const byte *dgram)
Definition: parse.c:127
int used
Definition: internal.h:111

Referenced by adns__diag_domain(), adns__procdgram(), and pap_domain().

◆ adns__parse_domain_more()

adns_status adns__parse_domain_more ( findlabel_state fls,
adns_state  ads,
adns_query  qu,
vbuf vb,
parsedomain_flags  flags,
const byte dgram 
)

Definition at line 127 of file parse.c.

129 {
130 int lablen, labstart, i, ch, first;
131 adns_status st;
132
133 first= 1;
134 for (;;) {
135 st= adns__findlabel_next(fls,&lablen,&labstart);
136 if (st) return st;
137 if (lablen<0) { vb->used=0; return adns_s_ok; }
138 if (!lablen) break;
139 if (first) {
140 first= 0;
141 } else {
142 if (!adns__vbuf_append(vb,(byte*)".",1)) return adns_s_nomemory;
143 }
144 if (flags & pdf_quoteok) {
145 if (!vbuf__append_quoted1035(vb,dgram+labstart,lablen))
146 return adns_s_nomemory;
147 } else {
148 ch= dgram[labstart];
149 if (!ctype_alpha(ch) && !ctype_digit(ch)) return adns_s_answerdomaininvalid;
150 for (i= labstart+1; i<labstart+lablen; i++) {
151 ch= dgram[i];
152 if (ch != '-' && !ctype_alpha(ch) && !ctype_digit(ch))
154 }
155 if (!adns__vbuf_append(vb,dgram+labstart,lablen))
156 return adns_s_nomemory;
157 }
158 }
159 if (!adns__vbuf_append(vb,(byte*)"",1)) return adns_s_nomemory;
160 return adns_s_ok;
161}
@ adns_s_answerdomaininvalid
Definition: adns.h:246
@ adns_s_nomemory
Definition: adns.h:219
const GLint * first
Definition: glext.h:5794
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
int adns__vbuf_append(vbuf *vb, const byte *data, int len)
Definition: general.c:131
static int ctype_digit(int c)
Definition: internal.h:698
@ pdf_quoteok
Definition: internal.h:578
int vbuf__append_quoted1035(vbuf *vb, const byte *buf, int len)
Definition: parse.c:34

Referenced by adns__parse_domain(), and pap_mailbox822().

◆ vbuf__append_quoted1035()

int vbuf__append_quoted1035 ( vbuf vb,
const byte buf,
int  len 
)

Definition at line 34 of file parse.c.

34 {
35 char qbuf[10];
36 int i, ch;
37
38 while (len) {
39 qbuf[0]= 0;
40 for (i=0; i<len; i++) {
41 ch= buf[i];
42 if (ch <= ' ' || ch >= 127) {
43 sprintf(qbuf,"\\%03o",ch);
44 break;
45 } else if (!ctype_domainunquoted(ch)) {
46 sprintf(qbuf,"\\%c",ch);
47 break;
48 }
49 }
50 if (!adns__vbuf_append(vb,buf,i) || !adns__vbuf_append(vb,(byte*)qbuf,(int) strlen(qbuf)))
51 return 0;
52 if (i<len) i++;
53 buf+= i;
54 len-= i;
55 }
56 return 1;
57}
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
GLenum GLsizei len
Definition: glext.h:6722
#define sprintf(buf, format,...)
Definition: sprintf.c:55
static int ctype_domainunquoted(int c)
Definition: internal.h:703

Referenced by adns__parse_domain_more().